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) : 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=(zsid==zside() && eta==ietaAbs() && phi==iphi() && dep==depth());
58  return result;
59 }
60 
62  uint32_t rawid = gen.rawId();
63  if (rawid == id_) return false;
64  int zsid, eta, phi, dep;
65  unpackId(rawid, zsid, eta, phi, dep);
66  bool result=(zsid!=zside() || eta!=ietaAbs() || phi!=iphi() || dep!=depth());
67  return result;
68 }
69 
71  uint32_t rawid = gen.rawId();
72  if ((rawid&kHcalIdFormat2)==(id_&kHcalIdFormat2)) {
73  return id_<rawid;
74  } else {
75  int zsid, eta, phi, dep;
76  unpackId(rawid, zsid, eta, phi, dep);
77  rawid &= kHcalIdMask;
78  if (oldFormat()) {
79  rawid |= ((dep&kHcalDepthMask1)<<kHcalDepthOffset1) |
80  ((zsid>0)?(kHcalZsideMask1|(eta<<kHcalEtaOffset1)):((eta)<<kHcalEtaOffset1)) |
81  (phi&kHcalPhiMask1);
82  } else {
83  rawid |= (kHcalIdFormat2) | ((dep&kHcalDepthMask2)<<kHcalDepthOffset2) |
84  ((zsid>0)?(kHcalZsideMask2|(eta<<kHcalEtaOffset2)):((eta)<<kHcalEtaOffset2)) |
85  (phi&kHcalPhiMask2);
86  }
87  return (id_<rawid);
88  }
89 }
90 
91 int HcalDetId::zside() const {
92  if (oldFormat()) return (id_&kHcalZsideMask1)?(1):(-1);
93  else return (id_&kHcalZsideMask2)?(1):(-1);
94 }
95 
96 int HcalDetId::ietaAbs() const {
97  if (oldFormat()) return (id_>>kHcalEtaOffset1)&kHcalEtaMask1;
98  else return (id_>>kHcalEtaOffset2)&kHcalEtaMask2;
99 }
100 
101 int HcalDetId::iphi() const {
102  if (oldFormat()) return id_&kHcalPhiMask1;
103  else return id_&kHcalPhiMask2;
104 }
105 
106 int HcalDetId::depth() const {
108  else return (id_>>kHcalDepthOffset2)&kHcalDepthMask2;
109 }
110 
111 int HcalDetId::hfdepth() const {
112  int dep = depth();
113  if (subdet() == HcalForward) {
114  if (dep > 2) dep -= 2;
115  }
116  return dep;
117 }
118 
119 uint32_t HcalDetId::maskDepth() const {
120  if (oldFormat()) return (id_|kHcalDepthSet1);
121  else return (id_|kHcalDepthSet2);
122 }
123 
124 uint32_t HcalDetId::otherForm() const {
125  uint32_t rawid = (id_&kHcalIdMask);
126  if (oldFormat()) {
127  rawid = newForm(id_);
128  } else {
129  rawid |= ((depth()&kHcalDepthMask1)<<kHcalDepthOffset1) |
131  (iphi()&kHcalPhiMask1);
132  }
133  return rawid;
134 }
135 
137  id_ = otherForm();
138 }
139 
140 uint32_t HcalDetId::newForm() const {
141  return newForm(id_);
142 }
143 
144 uint32_t HcalDetId::newForm(const uint32_t& inpid) {
145  uint32_t rawid(inpid);
146  if ((rawid&kHcalIdFormat2)==0) {
147  int zsid, eta, phi, dep;
148  unpackId(rawid, zsid, eta, phi, dep);
149  rawid = inpid&kHcalIdMask;
150  rawid |= (kHcalIdFormat2) | ((dep&kHcalDepthMask2)<<kHcalDepthOffset2) |
151  ((zsid>0)?(kHcalZsideMask2|(eta<<kHcalEtaOffset2)):((eta)<<kHcalEtaOffset2)) |
152  (phi&kHcalPhiMask2);
153  }
154  return rawid;
155 }
156 
158  int simple_iphi=((iphi()-1)*5)+1;
159  simple_iphi+=10;
160  return ((simple_iphi>360)?(simple_iphi-360):(simple_iphi));
161 }
162 
164  int simple_iphi=((iphi()-1)*5)+5;
165  simple_iphi+=10;
166  return ((simple_iphi>360)?(simple_iphi-360):(simple_iphi));
167 }
168 
169 void HcalDetId::newFromOld(const uint32_t& rawid) {
170  id_ = newForm(rawid);
171 }
172 
173 void HcalDetId::unpackId(const uint32_t& rawid, int& zsid, int& eta, int& phi,
174  int& dep) {
175  if ((rawid&kHcalIdFormat2)==0) {
176  zsid = (rawid&kHcalZsideMask1)?(1):(-1);
177  eta = (rawid>>kHcalEtaOffset1)&kHcalEtaMask1;
178  phi = rawid&kHcalPhiMask1;
179  dep = (rawid>>kHcalDepthOffset1)&kHcalDepthMask1;
180  } else {
181  zsid = (rawid&kHcalZsideMask2)?(1):(-1);
182  eta = (rawid>>kHcalEtaOffset2)&kHcalEtaMask2;
183  phi = rawid&kHcalPhiMask2;
184  dep = (rawid>>kHcalDepthOffset2)&kHcalDepthMask2;
185  }
186 }
187 
188 std::ostream& operator<<(std::ostream& s,const HcalDetId& id) {
189  switch (id.subdet()) {
190  case(HcalBarrel) : return s << "(HB " << id.ieta() << ',' << id.iphi() << ',' << id.depth() << ')';
191  case(HcalEndcap) : return s << "(HE " << id.ieta() << ',' << id.iphi() << ',' << id.depth() << ')';
192  case(HcalForward) : return s << "(HF " << id.ieta() << ',' << id.iphi() << ',' << id.depth() << ')';
193  case(HcalOuter) : return s << "(HO " << id.ieta() << ',' << id.iphi() << ')';
194  case(HcalTriggerTower) : return s << "(HT " << id.ieta() << ',' << id.iphi() << ')';
195  default : return s << id.rawId();
196  }
197 }
198 
199 
static const HcalDetId Undefined
Definition: HcalDetId.h:80
HcalDetId & operator=(const DetId &id)
Definition: HcalDetId.cc:36
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:91
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:157
static const int kHcalDepthMask1
Definition: HcalDetId.h:25
static const int kHcalDepthSet2
Definition: HcalDetId.h:28
static const int kHcalDepthSet1
Definition: HcalDetId.h:27
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
uint32_t maskDepth() const
get the tower depth
Definition: HcalDetId.cc:119
bool operator!=(DetId id) const
Definition: HcalDetId.cc:61
int hfdepth() const
get full depth information for HF
Definition: HcalDetId.cc:111
static const int kHcalDepthMask2
Definition: HcalDetId.h:26
tuple result
Definition: mps_fire.py:95
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:106
bool operator<(DetId id) const
Definition: HcalDetId.cc:70
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:169
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:96
int iphi() const
get the cell iphi
Definition: HcalDetId.cc:101
static const int kHcalPhiMask2
Definition: HcalDetId.h:16
Definition: DetId.h:18
uint32_t otherForm() const
change format
Definition: HcalDetId.cc:124
static const int kHcalIdFormat2
Definition: HcalDetId.h:29
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:140
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:52
static const int kHcalZsideMask2
Definition: HcalDetId.h:22
static const int kHcalEtaMask2
Definition: HcalDetId.h:20
void changeForm()
Definition: HcalDetId.cc:136
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:163
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:173
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