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