CMS 3D CMS Logo

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