CMS 3D CMS Logo

DetId.h
Go to the documentation of this file.
1 #ifndef DATAFORMATS_DETID_H
2 #define DATAFORMATS_DETID_H
3 
4 //FIXME shall be removed and implemented where the operator is defined
5 #include <ostream>
6 
7 #include <cstdint>
17 class DetId {
18 public:
19  static const int kDetMask = 0xF;
20  static const int kSubdetMask = 0x7;
21  static const int kDetOffset = 28;
22  static const int kSubdetOffset = 25;
23 
24  enum Detector {
25  Tracker = 1,
26  Muon = 2,
27  Ecal = 3,
28  Hcal = 4,
29  Calo = 5,
30  Forward = 6,
32  HGCalEE = 8,
33  HGCalHSi = 9,
34  HGCalHSc = 10,
36  };
38  constexpr DetId() : id_(0) {}
40  constexpr DetId(uint32_t id) : id_(id) {}
42  constexpr DetId(Detector det, int subdet)
43  : id_(((det & kDetMask) << kDetOffset) | ((subdet & kSubdetMask) << kSubdetOffset)) {}
44 
46  constexpr Detector det() const { return Detector((id_ >> kDetOffset) & kDetMask); }
48  constexpr int subdetId() const {
49  return ((HGCalEE == det()) || (HGCalHSi == det()) || (HGCalHSc == det()) ? 0
50  : ((id_ >> kSubdetOffset) & kSubdetMask));
51  }
52 
53  constexpr uint32_t operator()() const { return id_; }
54  constexpr operator uint32_t() const { return id_; }
55 
57  constexpr uint32_t rawId() const { return id_; }
59  constexpr bool null() const { return id_ == 0; }
60 
62  constexpr bool operator==(DetId id) const { return id_ == id.id_; }
64  constexpr bool operator!=(DetId id) const { return id_ != id.id_; }
66  constexpr bool operator<(DetId id) const { return id_ < id.id_; }
67 
68 protected:
69  uint32_t id_;
70 };
71 
73 constexpr inline bool operator==(uint32_t i, DetId id) { return i == id(); }
74 constexpr inline bool operator==(DetId id, uint32_t i) { return i == id(); }
76 constexpr inline bool operator!=(uint32_t i, DetId id) { return i != id(); }
77 constexpr inline bool operator!=(DetId id, uint32_t i) { return i != id(); }
79 constexpr inline bool operator<(uint32_t i, DetId id) { return i < id(); }
80 constexpr inline bool operator<(DetId id, uint32_t i) { return id() < i; }
81 
82 //std::ostream& operator<<(std::ostream& s, const DetId& id);
83 
84 namespace std {
85  template <>
86  struct hash<DetId> {
88  typedef std::size_t result_type;
89  result_type operator()(argument_type const& id) const noexcept { return std::hash<uint32_t>()(id.rawId()); }
90  };
91 } // namespace std
92 
93 #endif
constexpr bool operator<(uint32_t i, DetId id)
comparison
Definition: DetId.h:79
constexpr bool operator==(DetId id) const
equality
Definition: DetId.h:62
std::size_t result_type
Definition: DetId.h:88
constexpr bool operator<(DetId id) const
comparison
Definition: DetId.h:66
static const int kSubdetOffset
Definition: DetId.h:22
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
constexpr bool operator!=(DetId id) const
inequality
Definition: DetId.h:64
constexpr bool null() const
is this a null id ?
Definition: DetId.h:59
Definition: Muon.py:1
static const int kSubdetMask
Definition: DetId.h:20
constexpr DetId(Detector det, int subdet)
Create an id, filling the detector and subdetector fields as specified.
Definition: DetId.h:42
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
constexpr bool operator!=(uint32_t i, DetId id)
inequality
Definition: DetId.h:76
Definition: DetId.h:17
constexpr DetId(uint32_t id)
Create an id from a raw number.
Definition: DetId.h:40
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
Detector
Definition: DetId.h:24
static const int kDetMask
Definition: DetId.h:19
result_type operator()(argument_type const &id) const noexcept
Definition: DetId.h:89
uint32_t id_
Definition: DetId.h:69
constexpr uint32_t operator()() const
Definition: DetId.h:53
static const int kDetOffset
Definition: DetId.h:21
constexpr bool operator==(uint32_t i, DetId id)
equality
Definition: DetId.h:73
DetId argument_type
Definition: DetId.h:87
constexpr DetId()
Create an empty or null id (also for persistence)
Definition: DetId.h:38