DetId.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef UTIL_DETID_H
  2. #define UTIL_DETID_H
  3. #include <stdint.h>
  4. /** \class DetId
  5. Parent class for all detector ids in CMS. The DetId is a 32-bit
  6. unsigned integer. The four most significant bits ([31:28]) identify
  7. the large-scale detector (e.g. Tracker or Ecal) while the next three
  8. bits ([27:25]) identify a part of the detector (such as HcalBarrel
  9. (HB) for Hcal).
  10. // Taken from cmssw_9_0_X:DataFormats/DetId/interface/DetId.h
  11. */
  12. class DetId {
  13. public:
  14. static const int kDetOffset = 28;
  15. static const int kSubdetOffset = 25;
  16. enum Detector { Tracker=1,Muon=2,Ecal=3,Hcal=4,Calo=5,Forward=6,VeryForward=7 };
  17. /// Create an empty or null id (also for persistence)
  18. DetId() : id_(0) { }
  19. /// Create an id from a raw number
  20. DetId(uint32_t id) : id_(id) { }
  21. /// Create an id, filling the detector and subdetector fields as specified
  22. DetId(Detector det, int subdet) {
  23. id_=((det&0xF)<<28)|((subdet&0x7)<<25);
  24. }
  25. /// get the detector field from this detid
  26. Detector det() const { return Detector((id_>>kDetOffset)&0xF); }
  27. /// get the contents of the subdetector field (not cast into any detector's numbering enum)
  28. int subdetId() const { return ((id_>>kSubdetOffset)&0x7); }
  29. uint32_t operator()() const { return id_; }
  30. operator uint32_t() const { return id_; }
  31. /// get the raw id
  32. uint32_t rawId() const { return id_; }
  33. /// is this a null id ?
  34. bool null() const { return id_==0; }
  35. /// equality
  36. bool operator==(DetId id) const { return id_==id.id_; }
  37. /// inequality
  38. bool operator!=(DetId id) const { return id_!=id.id_; }
  39. /// comparison
  40. bool operator<(DetId id) const { return id_<id.id_; }
  41. protected:
  42. uint32_t id_;
  43. };
  44. /// equality
  45. inline bool operator==(uint32_t i, DetId id) { return i==id(); }
  46. inline bool operator==(DetId id, uint32_t i) { return i==id(); }
  47. /// inequality
  48. inline bool operator!=(uint32_t i, DetId id) { return i!=id(); }
  49. inline bool operator!=(DetId id, uint32_t i) { return i!=id(); }
  50. /// comparison
  51. inline bool operator<(uint32_t i, DetId id) { return i<id(); }
  52. inline bool operator<(DetId id, uint32_t i) { return id()<i; }
  53. #endif