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:
33  constexpr HcalDetId() : DetId() {}
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  }
57  constexpr HcalDetId(const DetId& gen) {
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  }
75  constexpr HcalDetId& operator=(const DetId& gen) {
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 
105  constexpr bool operator!=(DetId gen) const {
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 
138  constexpr HcalSubdetector subdet() const { return (HcalSubdetector)(subdetId()); }
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  }
198  constexpr void changeForm() { id_ = otherForm(); }
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  }
226  constexpr HcalDetId baseDetId() const {
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  }
241  constexpr HcalDetId secondAnodeId() const {
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(); }
261  constexpr int crystal_iphi_low() const {
262  int simple_iphi = ((iphi() - 1) * 5) + 1;
263  simple_iphi += 10;
264  return ((simple_iphi > 360) ? (simple_iphi - 360) : (simple_iphi));
265  }
267  constexpr int crystal_iphi_high() const {
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
HcalOther
Definition: HcalAssistant.h:38
HcalDetId::crystal_ieta_high
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
HcalDetId::kHcalZsideMask2
static constexpr uint32_t kHcalZsideMask2
Definition: HcalDetId.h:21
HcalDetId::HcalDetId
constexpr HcalDetId(uint32_t rawid)
Definition: HcalDetId.h:35
HcalDetId::Undefined
static const HcalDetId Undefined
Definition: HcalDetId.h:273
HcalDetId::kHcalDepthOffset1
static constexpr uint32_t kHcalDepthOffset1
Definition: HcalDetId.h:22
HcalDetId::HcalDetId
constexpr HcalDetId(const DetId &gen)
Definition: HcalDetId.h:57
HcalDetId::iphi
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
HcalDetId::kHcalEtaOffset1
static constexpr uint32_t kHcalEtaOffset1
Definition: HcalDetId.h:16
HcalDetId::crystal_iphi_low
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
operator<<
std::ostream & operator<<(std::ostream &, const HcalDetId &id)
Definition: HcalDetId.cc:7
HcalDetId::hfdepth
constexpr int hfdepth() const
get full depth information for HF
Definition: HcalDetId.h:171
DetId::Hcal
Definition: DetId.h:28
HcalDetId::depth
constexpr int depth() const
get the tower depth
Definition: HcalDetId.h:164
HcalDetId::kHcalEtaOffset2
static constexpr uint32_t kHcalEtaOffset2
Definition: HcalDetId.h:17
HcalDetId::HcalDetId
constexpr HcalDetId()
Definition: HcalDetId.h:33
HcalDetId::sameBaseDetId
constexpr bool sameBaseDetId(const DetId &gen) const
base detId for HF dual channels
Definition: HcalDetId.h:213
HcalBarrel
Definition: HcalAssistant.h:33
HcalDetId::maskDepth
constexpr uint32_t maskDepth() const
get the tower depth
Definition: HcalDetId.h:180
DetId::kSubdetMask
static const int kSubdetMask
Definition: DetId.h:20
HcalDetId::changeForm
constexpr void changeForm()
Definition: HcalDetId.h:198
DetId::kSubdetOffset
static const int kSubdetOffset
Definition: DetId.h:22
DetId
Definition: DetId.h:17
PVValHelper::eta
Definition: PVValidationHelpers.h:69
HcalDetId::kHcalPhiMask2
static constexpr uint32_t kHcalPhiMask2
Definition: HcalDetId.h:15
HcalDetId::newForm
constexpr uint32_t newForm() const
Definition: HcalDetId.h:199
HcalOuter
Definition: HcalAssistant.h:35
gen
Definition: PythiaDecays.h:13
HcalDetId::kHcalIdFormat2
static constexpr uint32_t kHcalIdFormat2
Definition: HcalDetId.h:28
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
HcalDetId::kHcalDepthMask2
static constexpr uint32_t kHcalDepthMask2
Definition: HcalDetId.h:25
HcalDetId::ieta
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
HcalDetId::newFromOld
constexpr void newFromOld(const uint32_t &rawid)
Definition: HcalDetId.h:276
DetId::kDetMask
static const int kDetMask
Definition: DetId.h:19
HcalDetId::operator<
constexpr bool operator<(DetId gen) const
Definition: HcalDetId.h:116
HcalDetId::baseDetId
constexpr HcalDetId baseDetId() const
Definition: HcalDetId.h:226
HcalDetId::kHcalDepthSet2
static constexpr uint32_t kHcalDepthSet2
Definition: HcalDetId.h:27
DetId::id_
uint32_t id_
Definition: DetId.h:69
HcalDetId::unpackId
constexpr static void unpackId(const uint32_t &rawid, int &zsid, int &eta, int &phi, int &dep)
Definition: HcalDetId.h:278
HcalDetId::kHcalDepthMask1
static constexpr uint32_t kHcalDepthMask1
Definition: HcalDetId.h:24
HcalDetId::operator=
constexpr HcalDetId & operator=(const DetId &gen)
Definition: HcalDetId.h:75
HcalDetId::subdet
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
HcalDetId
Definition: HcalDetId.h:12
HcalDetId::kHcalZsideMask1
static constexpr uint32_t kHcalZsideMask1
Definition: HcalDetId.h:20
DetId::Detector
Detector
Definition: DetId.h:24
HcalSubdetector.h
HcalDetId::crystal_ieta_low
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
HcalDetId::otherForm
constexpr uint32_t otherForm() const
change format
Definition: HcalDetId.h:187
HcalDetId::oldFormat
constexpr bool oldFormat() const
Definition: HcalDetId.h:139
HcalDetId::kHcalDepthOffset2
static constexpr uint32_t kHcalDepthOffset2
Definition: HcalDetId.h:23
HcalSubdetector
HcalSubdetector
Definition: HcalAssistant.h:31
HcalForward
Definition: HcalAssistant.h:36
DDAxes::phi
DetId::kDetOffset
static const int kDetOffset
Definition: DetId.h:21
HcalEndcap
Definition: HcalAssistant.h:34
DetId.h
Exception
Definition: hltDiff.cc:246
HcalTriggerTower
Definition: HcalAssistant.h:37
HcalDetId::operator!=
constexpr bool operator!=(DetId gen) const
Definition: HcalDetId.h:105
Exception.h
HcalDetId::kHcalEtaMask1
static constexpr uint32_t kHcalEtaMask1
Definition: HcalDetId.h:18
HcalDetId::kHcalEtaMask2
static constexpr uint32_t kHcalEtaMask2
Definition: HcalDetId.h:19
mps_fire.result
result
Definition: mps_fire.py:303
HcalDetId::crystal_iphi_high
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
HcalDetId::kHcalIdMask
static constexpr uint32_t kHcalIdMask
Definition: HcalDetId.h:29
HcalDetId::ietaAbs
constexpr int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:148
HcalDetId::operator==
constexpr bool operator==(DetId gen) const
Definition: HcalDetId.h:94
HcalDetId::zside
constexpr int zside() const
get the z-side of the cell (1/-1)
Definition: HcalDetId.h:141
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
HcalDetId::newForm
constexpr static int32_t newForm(const uint32_t &inpid)
Definition: HcalDetId.h:200
HcalDetId::HcalDetId
constexpr HcalDetId(HcalSubdetector subdet, int tower_ieta, int tower_iphi, int depth)
Definition: HcalDetId.h:49
HcalDetId::kHcalDepthSet1
static constexpr uint32_t kHcalDepthSet1
Definition: HcalDetId.h:26
HcalDetId::secondAnodeId
constexpr HcalDetId secondAnodeId() const
second PMT anode detId for HF dual channels
Definition: HcalDetId.h:241
HcalDetId::kHcalPhiMask1
static constexpr uint32_t kHcalPhiMask1
Definition: HcalDetId.h:14