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