CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
181  int simple_iphi=((iphi()-1)*5)+1;
182  simple_iphi+=10;
183  return ((simple_iphi>360)?(simple_iphi-360):(simple_iphi));
184 }
185 
187  int simple_iphi=((iphi()-1)*5)+5;
188  simple_iphi+=10;
189  return ((simple_iphi>360)?(simple_iphi-360):(simple_iphi));
190 }
191 
192 void HcalDetId::newFromOld(const uint32_t& rawid) {
193  id_ = newForm(rawid);
194 }
195 
196 void HcalDetId::unpackId(const uint32_t& rawid, int& zsid, int& eta, int& phi,
197  int& dep) {
198  if ((rawid&kHcalIdFormat2)==0) {
199  zsid = (rawid&kHcalZsideMask1)?(1):(-1);
200  eta = (rawid>>kHcalEtaOffset1)&kHcalEtaMask1;
201  phi = rawid&kHcalPhiMask1;
202  dep = (rawid>>kHcalDepthOffset1)&kHcalDepthMask1;
203  } else {
204  zsid = (rawid&kHcalZsideMask2)?(1):(-1);
205  eta = (rawid>>kHcalEtaOffset2)&kHcalEtaMask2;
206  phi = rawid&kHcalPhiMask2;
207  dep = (rawid>>kHcalDepthOffset2)&kHcalDepthMask2;
208  }
209 }
210 
211 std::ostream& operator<<(std::ostream& s,const HcalDetId& id) {
212  switch (id.subdet()) {
213  case(HcalBarrel) : return s << "(HB " << id.ieta() << ',' << id.iphi() << ',' << id.depth() << ')';
214  case(HcalEndcap) : return s << "(HE " << id.ieta() << ',' << id.iphi() << ',' << id.depth() << ')';
215  case(HcalForward) : return s << "(HF " << id.ieta() << ',' << id.iphi() << ',' << id.depth() << ')';
216  case(HcalOuter) : return s << "(HO " << id.ieta() << ',' << id.iphi() << ')';
217  case(HcalTriggerTower) : return s << "(HT " << id.ieta() << ',' << id.iphi() << ')';
218  default : return s << std::hex << id.rawId() << std::dec;
219  }
220 }
221 
222 
static const HcalDetId Undefined
Definition: HcalDetId.h:80
HcalDetId & operator=(const DetId &id)
Definition: HcalDetId.cc:52
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:180
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
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:188
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
tuple result
Definition: mps_fire.py:84
def gen
run2 Cosmic #### Run 256259 @ 0T 2015C### Run 272133 @ 3.8T 2016B###
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
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:192
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
Geom::Phi< T > phi() const
static const int kHcalEtaOffset2
Definition: HcalDetId.h:18
bool operator==(DetId id) const
Definition: HcalDetId.cc:73
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:186
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:196
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