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