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 const int kHcalPhiMask1 = 0x7F;
17  static const int kHcalPhiMask2 = 0x3FF;
18  static const int kHcalEtaOffset1 = 7;
19  static const int kHcalEtaOffset2 = 10;
20  static const int kHcalEtaMask1 = 0x3F;
21  static const int kHcalEtaMask2 = 0x1FF;
22  static const int kHcalZsideMask1 = 0x2000;
23  static const int kHcalZsideMask2 = 0x80000;
24  static const int kHcalDepthOffset1 = 14;
25  static const int kHcalDepthOffset2 = 20;
26  static const int kHcalDepthMask1 = 0x1F;
27  static const int kHcalDepthMask2 = 0xF;
28  static const int kHcalDepthSet1 = 0x1C000;
29  static const int kHcalDepthSet2 = 0xF00000;
30  static const int kHcalIdFormat2 = 0x1000000;
31  static const int 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)) && (zsid==zside())
108  && (eta==ietaAbs()) && (phi==iphi()) && (dep==depth()));
109  return result;
110  }
112  uint32_t rawid = gen.rawId();
113  if (rawid == id_) return false;
114  int zsid{0}, eta{0}, phi{0}, dep{0};
115  unpackId(rawid, zsid, eta, phi, dep);
116  bool result = (((id_&kHcalIdMask)!=(rawid&kHcalIdMask)) || (zsid!=zside())
117  || (eta!=ietaAbs()) || (phi!=iphi()) || (dep!=depth()));
118  return result;
119  }
120  constexpr bool operator<(DetId gen) const {
121  uint32_t rawid = gen.rawId();
122  if ((rawid&kHcalIdFormat2)==(id_&kHcalIdFormat2)) {
123  return id_<rawid;
124  } else {
125  int zsid{0}, eta{0}, phi{0}, dep{0};
126  unpackId(rawid, zsid, eta, phi, dep);
127  rawid &= kHcalIdMask;
128  if (oldFormat()) {
129  rawid |= ((dep&kHcalDepthMask1)<<kHcalDepthOffset1) |
130  ((zsid>0)?(kHcalZsideMask1|(eta<<kHcalEtaOffset1)):((eta)<<kHcalEtaOffset1)) |
131  (phi&kHcalPhiMask1);
132  } else {
133  rawid |= (kHcalIdFormat2) | ((dep&kHcalDepthMask2)<<kHcalDepthOffset2) |
134  ((zsid>0)?(kHcalZsideMask2|(eta<<kHcalEtaOffset2)):((eta)<<kHcalEtaOffset2)) |
135  (phi&kHcalPhiMask2);
136  }
137  return (id_<rawid);
138  }
139  }
140 
143  constexpr bool oldFormat() const { return ((id_&kHcalIdFormat2)==0)?(true):(false); }
145  constexpr int zside() const {
146  if (oldFormat()) return (id_&kHcalZsideMask1)?(1):(-1);
147  else return (id_&kHcalZsideMask2)?(1):(-1);
148  }
150  constexpr int ietaAbs() const {
151  if (oldFormat()) return (id_>>kHcalEtaOffset1)&kHcalEtaMask1;
152  else return (id_>>kHcalEtaOffset2)&kHcalEtaMask2;
153  }
155  constexpr int ieta() const { return zside()*ietaAbs(); }
157  constexpr int iphi() const {
158  if (oldFormat()) return id_&kHcalPhiMask1;
159  else return id_&kHcalPhiMask2;
160  }
162  constexpr int depth() const {
163  if (oldFormat()) return (id_>>kHcalDepthOffset1)&kHcalDepthMask1;
164  else return (id_>>kHcalDepthOffset2)&kHcalDepthMask2;
165  }
167  constexpr int hfdepth() const {
168  int dep = depth();
169  if (subdet() == HcalForward) {
170  if (dep > 2) dep -= 2;
171  }
172  return dep;
173  }
175  constexpr uint32_t maskDepth() const {
176  if (oldFormat()) return (id_|kHcalDepthSet1);
177  else return (id_|kHcalDepthSet2);
178  }
180  constexpr uint32_t otherForm() const {
181  uint32_t rawid = (id_&kHcalIdMask);
182  if (oldFormat()) {
183  rawid = newForm(id_);
184  } else {
185  rawid |= ((depth()&kHcalDepthMask1)<<kHcalDepthOffset1) |
186  ((ieta()>0)?(kHcalZsideMask1|(ieta()<<kHcalEtaOffset1)):((-ieta())<<kHcalEtaOffset1)) |
187  (iphi()&kHcalPhiMask1);
188  }
189  return rawid;
190  }
192  id_ = otherForm();
193  }
194  constexpr uint32_t newForm() const {
195  return newForm(id_);
196  }
197  constexpr static int32_t newForm(const uint32_t& inpid) {
198  uint32_t rawid(inpid);
199  if ((rawid&kHcalIdFormat2)==0) {
200  int zsid{0}, eta{0}, phi{0}, dep{0};
201  unpackId(rawid, zsid, eta, phi, dep);
202  rawid = inpid&kHcalIdMask;
203  rawid |= (kHcalIdFormat2) | ((dep&kHcalDepthMask2)<<kHcalDepthOffset2) |
204  ((zsid>0)?(kHcalZsideMask2|(eta<<kHcalEtaOffset2)):((eta)<<kHcalEtaOffset2)) |
205  (phi&kHcalPhiMask2);
206  }
207  return rawid;
208  }
210  constexpr bool sameBaseDetId(const DetId& gen) const {
211  uint32_t rawid = gen.rawId();
212  if (rawid == id_) return true;
213  int zsid{0}, eta{0}, phi{0}, dep{0};
214  if ((id_&kHcalIdMask) != (rawid&kHcalIdMask)) return false;
215  unpackId(rawid, zsid, eta, phi, dep);
216  if (subdet() == HcalForward && dep > 2) dep -= 2;
217  bool result = ((zsid==zside()) && (eta==ietaAbs()) && (phi==iphi()) &&
218  (dep==hfdepth()));
219  return result;
220  }
222  if (subdet() != HcalForward || depth() <= 2) {
223  return HcalDetId(id_);
224  } else {
225  int zsid{0}, eta{0}, phi{0}, dep{0};
226  unpackId(id_, zsid, eta, phi, dep);
227  dep -= 2;
228  uint32_t rawid = id_&kHcalIdMask;
229  rawid |= (kHcalIdFormat2) | ((dep&kHcalDepthMask2)<<kHcalDepthOffset2) |
230  ((zsid>0)?(kHcalZsideMask2|(eta<<kHcalEtaOffset2)):((eta)<<kHcalEtaOffset2)) |
231  (phi&kHcalPhiMask2);
232  return HcalDetId(rawid);
233  }
234  }
237  if (subdet() != HcalForward || depth() > 2) {
238  return HcalDetId(id_);
239  } else {
240  int zsid{0}, eta{0}, phi{0}, dep{0};
241  unpackId(id_, zsid, eta, phi, dep);
242  dep += 2;
243  uint32_t rawid = id_&kHcalIdMask;
244  rawid |= (kHcalIdFormat2) | ((dep&kHcalDepthMask2)<<kHcalDepthOffset2) |
245  ((zsid>0)?(kHcalZsideMask2|(eta<<kHcalEtaOffset2)):((eta)<<kHcalEtaOffset2)) |
246  (phi&kHcalPhiMask2);
247  return HcalDetId(rawid);
248  }
249  }
250 
252  constexpr int crystal_ieta_low() const { return ((ieta()-zside())*5)+zside(); }
254  constexpr int crystal_ieta_high() const { return ((ieta()-zside())*5)+5*zside(); }
257  int simple_iphi=((iphi()-1)*5)+1;
258  simple_iphi+=10;
259  return ((simple_iphi>360)?(simple_iphi-360):(simple_iphi));
260  }
263  int simple_iphi=((iphi()-1)*5)+5;
264  simple_iphi+=10;
265  return ((simple_iphi>360)?(simple_iphi-360):(simple_iphi));
266  }
267 
268  static const HcalDetId Undefined;
269 
270 private:
271 
272  constexpr void newFromOld(const uint32_t& rawid) {
273  id_ = newForm(rawid);
274  }
275 
276  constexpr static void unpackId(const uint32_t& rawid, int& zsid, int& eta, int& phi,
277  int& dep) {
278  if ((rawid&kHcalIdFormat2)==0) {
279  zsid = (rawid&kHcalZsideMask1)?(1):(-1);
280  eta = (rawid>>kHcalEtaOffset1)&kHcalEtaMask1;
281  phi = rawid&kHcalPhiMask1;
282  dep = (rawid>>kHcalDepthOffset1)&kHcalDepthMask1;
283  } else {
284  zsid = (rawid&kHcalZsideMask2)?(1):(-1);
285  eta = (rawid>>kHcalEtaOffset2)&kHcalEtaMask2;
286  phi = rawid&kHcalPhiMask2;
287  dep = (rawid>>kHcalDepthOffset2)&kHcalDepthMask2;
288  }
289  }
290 };
291 
292 std::ostream& operator<<(std::ostream&,const HcalDetId& id);
293 
294 #endif
static const HcalDetId Undefined
Definition: HcalDetId.h:268
HcalDetId(HcalSubdetector subdet, int tower_ieta, int tower_iphi, int depth)
Definition: HcalDetId.h:53
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:142
static int32_t newForm(const uint32_t &inpid)
Definition: HcalDetId.h:197
HcalDetId & operator=(const DetId &gen)
Definition: HcalDetId.h:80
constexpr bool null() const
is this a null id ?
Definition: DetId.h:49
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalDetId.h:145
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:256
static const int kHcalDepthMask1
Definition: HcalDetId.h:26
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:47
static const int kHcalDepthSet2
Definition: HcalDetId.h:29
static const int kHcalDepthSet1
Definition: HcalDetId.h:28
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:175
#define constexpr
int hfdepth() const
get full depth information for HF
Definition: HcalDetId.h:167
bool operator!=(DetId gen) const
Definition: HcalDetId.h:111
static const int kHcalDepthMask2
Definition: HcalDetId.h:27
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:210
int depth() const
get the tower depth
Definition: HcalDetId.h:162
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:252
std::ostream & operator<<(std::ostream &, const HcalDetId &id)
Definition: HcalDetId.cc:7
static void unpackId(const uint32_t &rawid, int &zsid, int &eta, int &phi, int &dep)
Definition: HcalDetId.h:276
int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
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:221
static const int kHcalDepthOffset1
Definition: HcalDetId.h:24
bool oldFormat() const
Definition: HcalDetId.h:143
static const int kHcalIdMask
Definition: HcalDetId.h:31
int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:150
int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
static const int kHcalPhiMask2
Definition: HcalDetId.h:17
Definition: DetId.h:18
uint32_t otherForm() const
change format
Definition: HcalDetId.h:180
static const int kHcalIdFormat2
Definition: HcalDetId.h:30
Detector
Definition: DetId.h:26
static const int kDetMask
Definition: DetId.h:20
uint32_t id_
Definition: DetId.h:59
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:254
uint32_t newForm() const
Definition: HcalDetId.h:194
static const int kHcalZsideMask1
Definition: HcalDetId.h:22
static const int kHcalEtaOffset2
Definition: HcalDetId.h:19
static const int kDetOffset
Definition: DetId.h:22
void newFromOld(const uint32_t &rawid)
Definition: HcalDetId.h:272
static const int kHcalZsideMask2
Definition: HcalDetId.h:23
static const int kHcalEtaMask2
Definition: HcalDetId.h:21
bool operator<(DetId gen) const
Definition: HcalDetId.h:120
void changeForm()
Definition: HcalDetId.h:191
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:262
HcalDetId secondAnodeId() const
second PMT anode detId for HF dual channels
Definition: HcalDetId.h:236
static const int kHcalEtaMask1
Definition: HcalDetId.h:20
static const int kHcalPhiMask1
Definition: HcalDetId.h:16
static const int kHcalDepthOffset2
Definition: HcalDetId.h:25
static const int kHcalEtaOffset1
Definition: HcalDetId.h:18
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39