CMS 3D CMS Logo

HcalZDCDetId.h
Go to the documentation of this file.
1 #ifndef DataFormats_HcalDetId_HcalZDCDetId_h_included
2 #define DataFormats_HcalDetId_HcalZDCDetId_h_included 1
3 
4 #include <ostream>
7 
24 class HcalZDCDetId : public DetId {
25 public:
26  static constexpr uint32_t kZDCChannelMask1 = 0xF;
27  static constexpr uint32_t kZDCChannelMask2 = 0x7F;
28  static constexpr uint32_t kZDCSectionMask = 0x3;
29  static constexpr uint32_t kZDCSectionOffset = 4;
30  static constexpr uint32_t kZDCZsideMask = 0x40;
31  static constexpr uint32_t kZDCRPDMask = 0x80;
32  static constexpr uint32_t kZDCnewFormat = 0x100;
33  enum Section { Unknown = 0, EM = 1, HAD = 2, LUM = 3, RPD = 4 };
34 
35  static constexpr int32_t SubdetectorId = 2;
36 
38  constexpr HcalZDCDetId() : DetId() {}
40  constexpr HcalZDCDetId(uint32_t rawid) : DetId(rawid) {}
42  constexpr HcalZDCDetId(Section section, bool true_for_positive_eta, int32_t channel) {
43  id_ = packHcalZDCDetId(section, true_for_positive_eta, channel);
44  }
46  constexpr HcalZDCDetId(const DetId& gen) {
47  if (!gen.null() && (gen.det() != Calo || gen.subdetId() != SubdetectorId)) {
48  throw cms::Exception("Invalid DetId")
49  << "Cannot initialize ZDCDetId from " << std::hex << gen.rawId() << std::dec;
50  }
51  id_ = newForm(gen.rawId());
52  }
54  constexpr HcalZDCDetId& operator=(const DetId& gen) {
55  if (!gen.null() && (gen.det() != Calo || gen.subdetId() != SubdetectorId)) {
56  throw cms::Exception("Invalid DetId") << "Cannot assign ZDCDetId from " << std::hex << gen.rawId() << std::dec;
57  }
58  id_ = newForm(gen.rawId());
59  return *this;
60  }
62  constexpr bool operator==(DetId gen) const {
63  if (gen.rawId() == id_) {
64  return true;
65  } else {
66  uint32_t id1 = newForm(gen.rawId());
67  uint32_t id2 = newForm(id_);
68  return (id1 == id2);
69  }
70  }
71  constexpr bool operator!=(DetId gen) const {
72  if (gen.rawId() != id_) {
73  return true;
74  } else {
75  uint32_t id1 = newForm(gen.rawId());
76  uint32_t id2 = newForm(id_);
77  return (id1 != id2);
78  }
79  }
80 
82  constexpr int32_t zside() const { return ((id_ & kZDCZsideMask) ? (1) : (-1)); }
84  constexpr Section section() const {
85  uint32_t id = newForm(id_);
86  if (id & kZDCRPDMask)
87  return RPD;
88  else
89  return (Section)((id >> kZDCSectionOffset) & kZDCSectionMask);
90  }
92  constexpr int32_t depth() const {
93  const int se(section());
94  if (se == EM)
95  return 1;
96  else if (se == HAD)
97  return (channel() + 2);
98  else if (se == RPD)
99  return 2;
100  else
101  return channel();
102  }
104  constexpr int32_t channel() const {
105  const int32_t se(section());
106  uint32_t id = newForm(id_);
107  if (se == RPD)
108  return (1 + (id & kZDCChannelMask2));
109  else
110  return (id & kZDCChannelMask1);
111  }
112 
113  constexpr static bool newFormat(const uint32_t& di) { return (di & kZDCnewFormat); }
114  constexpr static uint32_t newForm(const uint32_t& di) {
115  uint32_t id(di);
116  if (!newFormat(id)) {
117  Section se(Unknown);
118  bool zside(true);
119  int32_t channel(0);
120  unpackHcalZDCDetId(id, se, zside, channel);
121  id = packHcalZDCDetId(se, zside, channel);
122  }
123  return id;
124  }
125 
126  constexpr uint32_t denseIndex() const {
127  const int32_t se(section());
128  uint32_t di =
129  (channel() - 1 +
130  (se == RPD ? 2 * kDepRun1 + (zside() < 0 ? 0 : kDepRPD)
131  : ((zside() < 0 ? 0 : kDepRun1) + (se == HAD ? kDepEM : (se == LUM ? kDepEM + kDepHAD : 0)))));
132  return di;
133  }
134 
135  constexpr static bool validDenseIndex(const uint32_t& di) { return (di < kSizeForDenseIndexing); }
136 
137  constexpr static HcalZDCDetId detIdFromDenseIndex(uint32_t di) {
138  if (validDenseIndex(di)) {
139  bool lz(false);
140  uint32_t dp(0);
141  Section se(Unknown);
142  if (di >= 2 * kDepRun1) {
143  lz = (di >= (kDepRun1 + kDepTot));
144  se = RPD;
145  dp = 1 + ((di - 2 * kDepRun1) % kDepRPD);
146  } else {
147  lz = (di >= kDepRun1);
148  uint32_t in = (di % kDepRun1);
149  se = (in < kDepEM ? EM : (in < kDepEM + kDepHAD ? HAD : LUM));
150  dp = (se == EM ? in + 1 : (se == HAD ? in - kDepEM + 1 : in - kDepEM - kDepHAD + 1));
151  }
152  return HcalZDCDetId(se, lz, dp);
153  } else {
154  return HcalZDCDetId();
155  }
156  }
157 
158  constexpr static bool validDetId(Section se, int32_t dp) {
159  bool flag = (dp >= 1 && (((se == EM) && (dp <= kDepEM)) || ((se == HAD) && (dp <= kDepHAD)) ||
160  ((se == LUM) && (dp <= kDepLUM)) || ((se == RPD) && (dp <= kDepRPD))));
161  return flag;
162  }
163 
164 private:
165  enum {
166  kDepEM = 5,
167  kDepHAD = 4,
168  kDepLUM = 2,
169  kDepRPD = 16,
173  };
174 
175  constexpr static uint32_t packHcalZDCDetId(const Section& se, const bool& zside, const int32_t& channel) {
176  uint32_t id = DetId(DetId::Calo, SubdetectorId);
177  id |= kZDCnewFormat;
178  if (se == RPD) {
179  id |= kZDCRPDMask;
180  id |= ((channel - 1) & kZDCChannelMask2);
181  } else {
182  id |= (se & kZDCSectionMask) << kZDCSectionOffset;
183  id |= (channel & kZDCChannelMask1);
184  }
185  if (zside)
186  id |= kZDCZsideMask;
187  return id;
188  }
189 
190  constexpr static void unpackHcalZDCDetId(const uint32_t& id, Section& se, bool& zside, int32_t& channel) {
191  if (id & kZDCnewFormat) {
192  se = (id & kZDCRPDMask) ? RPD : (Section)((id >> kZDCSectionOffset) & kZDCSectionMask);
193  channel = (se == RPD) ? (1 + (id & kZDCChannelMask2)) : (id & kZDCChannelMask1);
194  zside = (id & kZDCZsideMask);
195  } else {
196  se = (id & kZDCRPDMask) ? RPD : (Section)((id >> kZDCSectionOffset) & kZDCSectionMask);
197  channel = (se == RPD) ? (1 + (id & kZDCChannelMask1)) : (id & kZDCChannelMask1);
198  zside = (id & kZDCZsideMask);
199  }
200  }
201 
202 public:
203  constexpr static int32_t kSizeForDenseIndexingRun1 = 2 * kDepRun1;
204  constexpr static int32_t kSizeForDenseIndexingRun3 = 2 * kDepRun3;
206 };
207 
208 std::ostream& operator<<(std::ostream&, const HcalZDCDetId& id);
209 
210 #endif // DataFormats_HcalDetId_HcalZDCDetId_h_included
std::ostream & operator<<(std::ostream &, const HcalZDCDetId &id)
Definition: HcalZDCDetId.cc:3
static constexpr HcalZDCDetId detIdFromDenseIndex(uint32_t di)
Definition: HcalZDCDetId.h:137
constexpr uint32_t denseIndex() const
Definition: HcalZDCDetId.h:126
static constexpr uint32_t kZDCChannelMask2
Definition: HcalZDCDetId.h:27
static constexpr int32_t kSizeForDenseIndexingRun1
Definition: HcalZDCDetId.h:203
constexpr int32_t depth() const
get the depth (1 for EM, channel + 1 for HAD, 2 for RPD, not sure yet for LUM, leave as default) ...
Definition: HcalZDCDetId.h:92
static constexpr uint32_t packHcalZDCDetId(const Section &se, const bool &zside, const int32_t &channel)
Definition: HcalZDCDetId.h:175
static constexpr uint32_t kZDCRPDMask
Definition: HcalZDCDetId.h:31
static constexpr uint32_t newForm(const uint32_t &di)
Definition: HcalZDCDetId.h:114
constexpr HcalZDCDetId()
Definition: HcalZDCDetId.h:38
static constexpr uint32_t kZDCnewFormat
Definition: HcalZDCDetId.h:32
static constexpr uint32_t kZDCZsideMask
Definition: HcalZDCDetId.h:30
constexpr HcalZDCDetId(const DetId &gen)
Definition: HcalZDCDetId.h:46
static constexpr uint32_t kZDCSectionMask
Definition: HcalZDCDetId.h:28
constexpr HcalZDCDetId(uint32_t rawid)
Definition: HcalZDCDetId.h:40
static constexpr bool validDetId(Section se, int32_t dp)
Definition: HcalZDCDetId.h:158
constexpr bool operator!=(DetId gen) const
Definition: HcalZDCDetId.h:71
static constexpr void unpackHcalZDCDetId(const uint32_t &id, Section &se, bool &zside, int32_t &channel)
Definition: HcalZDCDetId.h:190
Definition: DetId.h:17
static constexpr uint32_t kZDCChannelMask1
Definition: HcalZDCDetId.h:26
uint32_t id_
Definition: DetId.h:69
constexpr Section section() const
get the section
Definition: HcalZDCDetId.h:84
constexpr HcalZDCDetId(Section section, bool true_for_positive_eta, int32_t channel)
Definition: HcalZDCDetId.h:42
static constexpr bool validDenseIndex(const uint32_t &di)
Definition: HcalZDCDetId.h:135
constexpr HcalZDCDetId & operator=(const DetId &gen)
Definition: HcalZDCDetId.h:54
constexpr bool operator==(DetId gen) const
Definition: HcalZDCDetId.h:62
static constexpr int32_t SubdetectorId
Definition: HcalZDCDetId.h:35
constexpr int32_t channel() const
get the channel
Definition: HcalZDCDetId.h:104
constexpr int32_t zside() const
get the z-side of the cell (1/-1)
Definition: HcalZDCDetId.h:82
static constexpr bool newFormat(const uint32_t &di)
Definition: HcalZDCDetId.h:113
static constexpr uint32_t kZDCSectionOffset
Definition: HcalZDCDetId.h:29
constexpr DetId()
Create an empty or null id (also for persistence)
Definition: DetId.h:38
static constexpr int32_t kSizeForDenseIndexingRun3
Definition: HcalZDCDetId.h:204