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
DetId::HGCalTrigger
Definition: DetId.h:35
mps_fire.i
i
Definition: mps_fire.py:428
std::hash< DetId >::result_type
std::size_t result_type
Definition: DetId.h:88
cond::hash
Definition: Time.h:19
DetId::operator==
constexpr bool operator==(DetId id) const
equality
Definition: DetId.h:62
operator<
constexpr bool operator<(uint32_t i, DetId id)
comparison
Definition: DetId.h:79
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
DetId::Hcal
Definition: DetId.h:28
DetId::VeryForward
Definition: DetId.h:31
DetId::Calo
Definition: DetId.h:29
DetId::kSubdetMask
static const int kSubdetMask
Definition: DetId.h:20
Muon
Definition: Muon.py:1
DetId::kSubdetOffset
static const int kSubdetOffset
Definition: DetId.h:22
DetId
Definition: DetId.h:17
DetId::HGCalHSi
Definition: DetId.h:33
DetId::HGCalEE
Definition: DetId.h:32
DetId::DetId
constexpr DetId(Detector det, int subdet)
Create an id, filling the detector and subdetector fields as specified.
Definition: DetId.h:42
DetId::operator<
constexpr bool operator<(DetId id) const
comparison
Definition: DetId.h:66
DetId::operator!=
constexpr bool operator!=(DetId id) const
inequality
Definition: DetId.h:64
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
DetId::DetId
constexpr DetId(uint32_t id)
Create an id from a raw number.
Definition: DetId.h:40
DetId::Tracker
Definition: DetId.h:25
DetId::kDetMask
static const int kDetMask
Definition: DetId.h:19
DetId::id_
uint32_t id_
Definition: DetId.h:69
std::hash< DetId >::operator()
result_type operator()(argument_type const &id) const noexcept
Definition: DetId.h:89
std::hash< DetId >::argument_type
DetId argument_type
Definition: DetId.h:87
operator!=
constexpr bool operator!=(uint32_t i, DetId id)
inequality
Definition: DetId.h:76
DetId::Detector
Detector
Definition: DetId.h:24
DetId::Ecal
Definition: DetId.h:27
DetId::kDetOffset
static const int kDetOffset
Definition: DetId.h:21
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
operator==
constexpr bool operator==(uint32_t i, DetId id)
equality
Definition: DetId.h:73
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
DetId::HGCalHSc
Definition: DetId.h:34
DetId::DetId
constexpr DetId()
Create an empty or null id (also for persistence)
Definition: DetId.h:38
DetId::operator()
constexpr uint32_t operator()() const
Definition: DetId.h:53
DetId::Forward
Definition: DetId.h:30