CMS 3D CMS Logo

HcalDetId.h
Go to the documentation of this file.
1 #ifndef DATAFORMATS_HCALDETID_HCALDETID_H
2 #define DATAFORMATS_HCALDETID_HCALDETID_H 1
3 
4 #include <iosfwd>
8 
12 class HcalDetId : public DetId {
13 public:
14  static constexpr uint32_t kHcalPhiMask1 = 0x7F;
15  static constexpr uint32_t kHcalPhiMask2 = 0x3FF;
16  static constexpr uint32_t kHcalEtaOffset1 = 7;
17  static constexpr uint32_t kHcalEtaOffset2 = 10;
18  static constexpr uint32_t kHcalEtaMask1 = 0x3F;
19  static constexpr uint32_t kHcalEtaMask2 = 0x1FF;
20  static constexpr uint32_t kHcalZsideMask1 = 0x2000;
21  static constexpr uint32_t kHcalZsideMask2 = 0x80000;
22  static constexpr uint32_t kHcalDepthOffset1 = 14;
23  static constexpr uint32_t kHcalDepthOffset2 = 20;
24  static constexpr uint32_t kHcalDepthMask1 = 0x1F;
25  static constexpr uint32_t kHcalDepthMask2 = 0xF;
26  static constexpr uint32_t kHcalDepthSet1 = 0x1C000;
27  static constexpr uint32_t kHcalDepthSet2 = 0xF00000;
28  static constexpr uint32_t kHcalIdFormat2 = 0x1000000;
29  static constexpr uint32_t kHcalIdMask = 0xFE000000;
30 
31 public:
35  constexpr HcalDetId(uint32_t rawid) {
37  id_ = rawid;
38  } else {
40  if ((subdet == HcalBarrel) || (subdet == HcalEndcap) || (subdet == HcalOuter) || (subdet == HcalForward)) {
41  id_ = newForm(rawid);
42  } else {
43  id_ = rawid;
44  }
45  }
46  }
47 
49  constexpr HcalDetId(HcalSubdetector subdet, int tower_ieta, int tower_iphi, int depth) : DetId(Hcal, subdet) {
50  // (no checking at this point!)
51  id_ |=
53  ((tower_ieta > 0) ? (kHcalZsideMask2 | (tower_ieta << kHcalEtaOffset2)) : ((-tower_ieta) << kHcalEtaOffset2)) |
54  (tower_iphi & kHcalPhiMask2);
55  }
58  if (!gen.null()) {
59  HcalSubdetector subdet = (HcalSubdetector(gen.subdetId()));
60  if (gen.det() != Hcal || (subdet != HcalBarrel && subdet != HcalEndcap && subdet != HcalOuter &&
62  throw cms::Exception("Invalid DetId")
63  << "Cannot initialize HcalDetId from " << std::hex << gen.rawId() << std::dec;
64  }
65  if ((subdet == HcalBarrel) || (subdet == HcalEndcap) || (subdet == HcalOuter) || (subdet == HcalForward)) {
66  id_ = newForm(gen.rawId());
67  } else {
68  id_ = gen.rawId();
69  }
70  } else {
71  id_ = gen.rawId();
72  }
73  }
76  if (!gen.null()) {
77  HcalSubdetector subdet = (HcalSubdetector(gen.subdetId()));
78  if (gen.det() != Hcal || (subdet != HcalBarrel && subdet != HcalEndcap && subdet != HcalOuter &&
80  throw cms::Exception("Invalid DetId") << "Cannot assign HcalDetId from " << std::hex << gen.rawId() << std::dec;
81  }
82  if ((subdet == HcalBarrel) || (subdet == HcalEndcap) || (subdet == HcalOuter) || (subdet == HcalForward)) {
83  id_ = newForm(gen.rawId());
84  } else {
85  id_ = gen.rawId();
86  }
87  } else {
88  id_ = gen.rawId();
89  }
90  return (*this);
91  }
92 
94  constexpr bool operator==(DetId gen) const {
95  uint32_t rawid = gen.rawId();
96  if (rawid == id_)
97  return true;
98  int zsid{0}, eta{0}, phi{0}, dep{0};
99  unpackId(rawid, zsid, eta, phi, dep);
100  bool result = (((id_ & kHcalIdMask) == (rawid & kHcalIdMask)) && (zsid == zside()) && (eta == ietaAbs()) &&
101  (phi == iphi()) && (dep == depth()));
102  return result;
103  }
104 
106  uint32_t rawid = gen.rawId();
107  if (rawid == id_)
108  return false;
109  int zsid{0}, eta{0}, phi{0}, dep{0};
110  unpackId(rawid, zsid, eta, phi, dep);
111  bool result = (((id_ & kHcalIdMask) != (rawid & kHcalIdMask)) || (zsid != zside()) || (eta != ietaAbs()) ||
112  (phi != iphi()) || (dep != depth()));
113  return result;
114  }
115 
116  constexpr bool operator<(DetId gen) const {
117  uint32_t rawid = gen.rawId();
118  if ((rawid & kHcalIdFormat2) == (id_ & kHcalIdFormat2)) {
119  return id_ < rawid;
120  } else {
121  int zsid{0}, eta{0}, phi{0}, dep{0};
122  unpackId(rawid, zsid, eta, phi, dep);
123  rawid &= kHcalIdMask;
124  if (oldFormat()) {
125  rawid |= (((dep & kHcalDepthMask1) << kHcalDepthOffset1) |
126  ((zsid > 0) ? (kHcalZsideMask1 | (eta << kHcalEtaOffset1)) : ((eta) << kHcalEtaOffset1)) |
127  (phi & kHcalPhiMask1));
128  } else {
129  rawid |= ((kHcalIdFormat2) | ((dep & kHcalDepthMask2) << kHcalDepthOffset2) |
130  ((zsid > 0) ? (kHcalZsideMask2 | (eta << kHcalEtaOffset2)) : ((eta) << kHcalEtaOffset2)) |
131  (phi & kHcalPhiMask2));
132  }
133  return (id_ < rawid);
134  }
135  }
136 
139  constexpr bool oldFormat() const { return ((id_ & kHcalIdFormat2) == 0) ? (true) : (false); }
141  constexpr int zside() const {
142  if (oldFormat())
143  return (id_ & kHcalZsideMask1) ? (1) : (-1);
144  else
145  return (id_ & kHcalZsideMask2) ? (1) : (-1);
146  }
148  constexpr int ietaAbs() const {
149  if (oldFormat())
150  return (id_ >> kHcalEtaOffset1) & kHcalEtaMask1;
151  else
152  return (id_ >> kHcalEtaOffset2) & kHcalEtaMask2;
153  }
155  constexpr int ieta() const { return zside() * ietaAbs(); }
157  constexpr int iphi() const {
158  if (oldFormat())
159  return id_ & kHcalPhiMask1;
160  else
161  return id_ & kHcalPhiMask2;
162  }
164  constexpr int depth() const {
165  if (oldFormat())
166  return (id_ >> kHcalDepthOffset1) & kHcalDepthMask1;
167  else
168  return (id_ >> kHcalDepthOffset2) & kHcalDepthMask2;
169  }
171  constexpr int hfdepth() const {
172  int dep = depth();
173  if (subdet() == HcalForward) {
174  if (dep > 2)
175  dep -= 2;
176  }
177  return dep;
178  }
180  constexpr uint32_t maskDepth() const {
181  if (oldFormat())
182  return (id_ | kHcalDepthSet1);
183  else
184  return (id_ | kHcalDepthSet2);
185  }
187  constexpr uint32_t otherForm() const {
188  uint32_t rawid = (id_ & kHcalIdMask);
189  if (oldFormat()) {
190  rawid = newForm(id_);
191  } else {
192  rawid |= ((depth() & kHcalDepthMask1) << kHcalDepthOffset1) |
193  ((ieta() > 0) ? (kHcalZsideMask1 | (ieta() << kHcalEtaOffset1)) : ((-ieta()) << kHcalEtaOffset1)) |
194  (iphi() & kHcalPhiMask1);
195  }
196  return rawid;
197  }
199  constexpr uint32_t newForm() const { return newForm(id_); }
200  constexpr static int32_t newForm(const uint32_t& inpid) {
201  uint32_t rawid(inpid);
202  if ((rawid & kHcalIdFormat2) == 0) {
203  int zsid{0}, eta{0}, phi{0}, dep{0};
204  unpackId(rawid, zsid, eta, phi, dep);
205  rawid = inpid & kHcalIdMask;
206  rawid |= ((kHcalIdFormat2) | ((dep & kHcalDepthMask2) << kHcalDepthOffset2) |
207  ((zsid > 0) ? (kHcalZsideMask2 | (eta << kHcalEtaOffset2)) : ((eta) << kHcalEtaOffset2)) |
208  (phi & kHcalPhiMask2));
209  }
210  return rawid;
211  }
213  constexpr bool sameBaseDetId(const DetId& gen) const {
214  uint32_t rawid = gen.rawId();
215  if (rawid == id_)
216  return true;
217  int zsid{0}, eta{0}, phi{0}, dep{0};
218  if ((id_ & kHcalIdMask) != (rawid & kHcalIdMask))
219  return false;
220  unpackId(rawid, zsid, eta, phi, dep);
221  if (subdet() == HcalForward && dep > 2)
222  dep -= 2;
223  bool result = ((zsid == zside()) && (eta == ietaAbs()) && (phi == iphi()) && (dep == hfdepth()));
224  return result;
225  }
227  if (subdet() != HcalForward || depth() <= 2) {
228  return HcalDetId(id_);
229  } else {
230  int zsid{0}, eta{0}, phi{0}, dep{0};
231  unpackId(id_, zsid, eta, phi, dep);
232  dep -= 2;
233  uint32_t rawid = id_ & kHcalIdMask;
234  rawid |= (kHcalIdFormat2) | ((dep & kHcalDepthMask2) << kHcalDepthOffset2) |
235  ((zsid > 0) ? (kHcalZsideMask2 | (eta << kHcalEtaOffset2)) : ((eta) << kHcalEtaOffset2)) |
236  (phi & kHcalPhiMask2);
237  return HcalDetId(rawid);
238  }
239  }
242  if (subdet() != HcalForward || depth() > 2) {
243  return HcalDetId(id_);
244  } else {
245  int zsid{0}, eta{0}, phi{0}, dep{0};
246  unpackId(id_, zsid, eta, phi, dep);
247  dep += 2;
248  uint32_t rawid = id_ & kHcalIdMask;
249  rawid |= (kHcalIdFormat2) | ((dep & kHcalDepthMask2) << kHcalDepthOffset2) |
250  ((zsid > 0) ? (kHcalZsideMask2 | (eta << kHcalEtaOffset2)) : ((eta) << kHcalEtaOffset2)) |
251  (phi & kHcalPhiMask2);
252  return HcalDetId(rawid);
253  }
254  }
255 
257  constexpr int crystal_ieta_low() const { return ((ieta() - zside()) * 5) + zside(); }
259  constexpr int crystal_ieta_high() const { return ((ieta() - zside()) * 5) + 5 * zside(); }
262  int simple_iphi = ((iphi() - 1) * 5) + 1;
263  simple_iphi += 10;
264  return ((simple_iphi > 360) ? (simple_iphi - 360) : (simple_iphi));
265  }
268  int simple_iphi = ((iphi() - 1) * 5) + 5;
269  simple_iphi += 10;
270  return ((simple_iphi > 360) ? (simple_iphi - 360) : (simple_iphi));
271  }
272 
273  static const HcalDetId Undefined;
274 
275 private:
276  constexpr void newFromOld(const uint32_t& rawid) { id_ = newForm(rawid); }
277 
278  constexpr static void unpackId(const uint32_t& rawid, int& zsid, int& eta, int& phi, int& dep) {
279  if ((rawid & kHcalIdFormat2) == 0) {
280  zsid = (rawid & kHcalZsideMask1) ? (1) : (-1);
281  eta = (rawid >> kHcalEtaOffset1) & kHcalEtaMask1;
282  phi = rawid & kHcalPhiMask1;
283  dep = (rawid >> kHcalDepthOffset1) & kHcalDepthMask1;
284  } else {
285  zsid = (rawid & kHcalZsideMask2) ? (1) : (-1);
286  eta = (rawid >> kHcalEtaOffset2) & kHcalEtaMask2;
287  phi = rawid & kHcalPhiMask2;
288  dep = (rawid >> kHcalDepthOffset2) & kHcalDepthMask2;
289  }
290  }
291 };
292 
293 std::ostream& operator<<(std::ostream&, const HcalDetId& id);
294 
295 #endif
static const HcalDetId Undefined
Definition: HcalDetId.h:273
static constexpr uint32_t kHcalPhiMask2
Definition: HcalDetId.h:15
static constexpr uint32_t kHcalZsideMask1
Definition: HcalDetId.h:20
constexpr bool oldFormat() const
Definition: HcalDetId.h:139
constexpr HcalDetId baseDetId() const
Definition: HcalDetId.h:226
constexpr uint32_t maskDepth() const
get the tower depth
Definition: HcalDetId.h:180
constexpr HcalDetId(const DetId &gen)
Definition: HcalDetId.h:57
constexpr int zside() const
get the z-side of the cell (1/-1)
Definition: HcalDetId.h:141
constexpr int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:148
constexpr bool sameBaseDetId(const DetId &gen) const
base detId for HF dual channels
Definition: HcalDetId.h:213
static constexpr void unpackId(const uint32_t &rawid, int &zsid, int &eta, int &phi, int &dep)
Definition: HcalDetId.h:278
constexpr HcalDetId(uint32_t rawid)
Definition: HcalDetId.h:35
static constexpr uint32_t kHcalPhiMask1
Definition: HcalDetId.h:14
constexpr int hfdepth() const
get full depth information for HF
Definition: HcalDetId.h:171
constexpr int crystal_iphi_high() const
get the largest crystal_iphi of the crystal in front of this tower (HB and HE tower 17 only) ...
Definition: HcalDetId.h:267
constexpr HcalDetId & operator=(const DetId &gen)
Definition: HcalDetId.h:75
static const int kSubdetOffset
Definition: DetId.h:22
constexpr void newFromOld(const uint32_t &rawid)
Definition: HcalDetId.h:276
constexpr HcalDetId secondAnodeId() const
second PMT anode detId for HF dual channels
Definition: HcalDetId.h:241
constexpr bool operator==(DetId gen) const
Definition: HcalDetId.h:94
constexpr uint32_t newForm() const
Definition: HcalDetId.h:199
static constexpr uint32_t kHcalZsideMask2
Definition: HcalDetId.h:21
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
static constexpr uint32_t kHcalDepthSet1
Definition: HcalDetId.h:26
constexpr void changeForm()
Definition: HcalDetId.h:198
static const int kSubdetMask
Definition: DetId.h:20
std::ostream & operator<<(std::ostream &, const HcalDetId &id)
Definition: HcalDetId.cc:7
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
static constexpr uint32_t kHcalDepthSet2
Definition: HcalDetId.h:27
HcalSubdetector
Definition: HcalAssistant.h:31
constexpr HcalDetId(HcalSubdetector subdet, int tower_ieta, int tower_iphi, int depth)
Definition: HcalDetId.h:49
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
static constexpr uint32_t kHcalDepthMask1
Definition: HcalDetId.h:24
static constexpr uint32_t kHcalEtaMask2
Definition: HcalDetId.h:19
constexpr int crystal_ieta_high() const
get the largest crystal_ieta of the crystal in front of this tower (HB and HE tower 17 only) ...
Definition: HcalDetId.h:259
static constexpr uint32_t kHcalIdMask
Definition: HcalDetId.h:29
constexpr int crystal_ieta_low() const
get the smallest crystal_ieta of the crystal in front of this tower (HB and HE tower 17 only) ...
Definition: HcalDetId.h:257
Definition: DetId.h:17
static constexpr int32_t newForm(const uint32_t &inpid)
Definition: HcalDetId.h:200
static constexpr uint32_t kHcalDepthOffset2
Definition: HcalDetId.h:23
Detector
Definition: DetId.h:24
static constexpr uint32_t kHcalIdFormat2
Definition: HcalDetId.h:28
static const int kDetMask
Definition: DetId.h:19
uint32_t id_
Definition: DetId.h:69
static constexpr uint32_t kHcalEtaOffset1
Definition: HcalDetId.h:16
constexpr bool operator<(DetId gen) const
Definition: HcalDetId.h:116
static const int kDetOffset
Definition: DetId.h:21
constexpr bool operator!=(DetId gen) const
Definition: HcalDetId.h:105
static constexpr uint32_t kHcalEtaOffset2
Definition: HcalDetId.h:17
static constexpr uint32_t kHcalEtaMask1
Definition: HcalDetId.h:18
constexpr HcalDetId()
Definition: HcalDetId.h:33
constexpr uint32_t otherForm() const
change format
Definition: HcalDetId.h:187
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
constexpr int crystal_iphi_low() const
get the smallest crystal_iphi of the crystal in front of this tower (HB and HE tower 17 only) ...
Definition: HcalDetId.h:261
static constexpr uint32_t kHcalDepthMask2
Definition: HcalDetId.h:25
static constexpr uint32_t kHcalDepthOffset1
Definition: HcalDetId.h:22
constexpr int depth() const
get the tower depth
Definition: HcalDetId.h:164