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
|
#ifndef DataFormats_HcalDetId_HcalZDCDetId_h_included
#define DataFormats_HcalDetId_HcalZDCDetId_h_included 1
#include <ostream>
#include "DataFormats/DetId/interface/DetId.h"
#include "FWCore/Utilities/interface/Exception.h"
/** \class HcalZDCDetId
*
* Contents of the HcalZDCDetId (Old):
* [7] Set for RPD
* [6] Z position (true for positive)
* [5:4] Section (EM/HAD/Lumi)
* [3:0] Channel
* Contents of the HcalZDCDetId (New):
* [8] Set to 1 for new format
* [7] Set for RPD
* [6] Z position (true for positive)
* [5:4] Section (EM/HAD/Lumi)
* [3:0] Chaneel for EM/HAD/Lumi
* [5:0] Channel for RPD
*
*/
class HcalZDCDetId : public DetId {
public:
static constexpr uint32_t kZDCChannelMask1 = 0xF;
static constexpr uint32_t kZDCChannelMask2 = 0x3F;
static constexpr uint32_t kZDCSectionMask = 0x3;
static constexpr uint32_t kZDCSectionOffset = 4;
static constexpr uint32_t kZDCZsideMask = 0x40;
static constexpr uint32_t kZDCRPDMask = 0x80;
static constexpr uint32_t kZDCnewFormat = 0x100;
enum Section { Unknown = 0, EM = 1, HAD = 2, LUM = 3, RPD = 4 };
static constexpr int32_t SubdetectorId = 2;
static constexpr int32_t kDepEM = 5;
static constexpr int32_t kDepHAD = 4;
static constexpr int32_t kDepLUM = 2;
static constexpr int32_t kDepRPD = 16;
static constexpr int32_t kDepRun1 = (kDepEM + kDepHAD + kDepLUM);
static constexpr int32_t kDepTot = (kDepRun1 + kDepRPD);
static constexpr int32_t kDepRun3 = kDepTot;
/** Create a null cellid*/
constexpr HcalZDCDetId() : DetId() {}
/** Create cellid from raw id (0=invalid tower id) */
constexpr HcalZDCDetId(uint32_t rawid) : DetId(rawid) {}
/** Constructor from section, eta sign, and channel */
constexpr HcalZDCDetId(Section section, bool true_for_positive_eta, int32_t channel) {
id_ = packHcalZDCDetId(section, true_for_positive_eta, channel);
}
/** Constructor from a generic cell id */
constexpr HcalZDCDetId(const DetId& gen) {
if (!gen.null() && (gen.det() != Calo || gen.subdetId() != SubdetectorId)) {
throw cms::Exception("Invalid DetId")
<< "Cannot initialize ZDCDetId from " << std::hex << gen.rawId() << std::dec;
}
id_ = newForm(gen.rawId());
}
/** Assignment from a generic cell id */
constexpr HcalZDCDetId& operator=(const DetId& gen) {
if (!gen.null() && (gen.det() != Calo || gen.subdetId() != SubdetectorId)) {
throw cms::Exception("Invalid DetId") << "Cannot assign ZDCDetId from " << std::hex << gen.rawId() << std::dec;
}
id_ = newForm(gen.rawId());
return *this;
}
/** Comparison operator */
constexpr bool operator==(DetId gen) const {
if (gen.rawId() == id_) {
return true;
} else {
uint32_t id1 = newForm(gen.rawId());
uint32_t id2 = newForm(id_);
return (id1 == id2);
}
}
constexpr bool operator!=(DetId gen) const {
if (gen.rawId() != id_) {
return true;
} else {
uint32_t id1 = newForm(gen.rawId());
uint32_t id2 = newForm(id_);
return (id1 != id2);
}
}
/// get the z-side of the cell (1/-1)
constexpr int32_t zside() const { return ((id_ & kZDCZsideMask) ? (1) : (-1)); }
/// get the section
constexpr Section section() const {
uint32_t id = newForm(id_);
if (id & kZDCRPDMask)
return RPD;
else
return (Section)((id >> kZDCSectionOffset) & kZDCSectionMask);
}
/// get the depth (1 for EM, channel + 1 for HAD, 2 for RPD, not sure yet for LUM, leave as default)
constexpr int32_t depth() const {
const int se(section());
if (se == EM)
return 1;
else if (se == HAD)
return (channel() + 2);
else if (se == RPD)
return 2;
else
return channel();
}
/// get the channel
constexpr int32_t channel() const {
const int32_t se(section());
uint32_t id = newForm(id_);
if (se == RPD)
return (1 + (id & kZDCChannelMask2));
else
return (id & kZDCChannelMask1);
}
constexpr static bool newFormat(const uint32_t& di) { return (di & kZDCnewFormat); }
constexpr static uint32_t newForm(const uint32_t& di) {
uint32_t id(di);
if (!newFormat(id)) {
Section se(Unknown);
bool zside(true);
int32_t channel(0);
unpackHcalZDCDetId(id, se, zside, channel);
id = packHcalZDCDetId(se, zside, channel);
}
return id;
}
constexpr uint32_t denseIndex() const {
const int32_t se(section());
uint32_t di =
(channel() - 1 +
(se == RPD ? 2 * kDepRun1 + (zside() < 0 ? 0 : kDepRPD)
: ((zside() < 0 ? 0 : kDepRun1) + (se == HAD ? kDepEM : (se == LUM ? kDepEM + kDepHAD : 0)))));
return di;
}
constexpr static bool validDenseIndex(const uint32_t& di) { return (di < kSizeForDenseIndexing); }
constexpr static HcalZDCDetId detIdFromDenseIndex(uint32_t di) {
if (validDenseIndex(di)) {
bool lz(false);
uint32_t dp(0);
Section se(Unknown);
if (di >= 2 * kDepRun1) {
lz = (di >= (kDepRun1 + kDepTot));
se = RPD;
dp = 1 + ((di - 2 * kDepRun1) % kDepRPD);
} else {
lz = (di >= kDepRun1);
uint32_t in = (di % kDepRun1);
se = (in < kDepEM ? EM : (in < kDepEM + kDepHAD ? HAD : LUM));
dp = (se == EM ? in + 1 : (se == HAD ? in - kDepEM + 1 : in - kDepEM - kDepHAD + 1));
}
return HcalZDCDetId(se, lz, dp);
} else {
return HcalZDCDetId();
}
}
constexpr static bool validDetId(Section se, int32_t dp) {
bool flag = (dp >= 1 && (((se == EM) && (dp <= kDepEM)) || ((se == HAD) && (dp <= kDepHAD)) ||
((se == LUM) && (dp <= kDepLUM)) || ((se == RPD) && (dp <= kDepRPD))));
return flag;
}
private:
constexpr static uint32_t packHcalZDCDetId(const Section& se, const bool& zside, const int32_t& channel) {
uint32_t id = DetId(DetId::Calo, SubdetectorId);
id |= kZDCnewFormat;
if (se == RPD) {
id |= kZDCRPDMask;
id |= ((channel - 1) & kZDCChannelMask2);
} else {
id |= (se & kZDCSectionMask) << kZDCSectionOffset;
id |= (channel & kZDCChannelMask1);
}
if (zside)
id |= kZDCZsideMask;
return id;
}
constexpr static void unpackHcalZDCDetId(const uint32_t& id, Section& se, bool& zside, int32_t& channel) {
if (id & kZDCnewFormat) {
se = (id & kZDCRPDMask) ? RPD : (Section)((id >> kZDCSectionOffset) & kZDCSectionMask);
channel = (se == RPD) ? (1 + (id & kZDCChannelMask2)) : (id & kZDCChannelMask1);
zside = (id & kZDCZsideMask);
} else {
se = (id & kZDCRPDMask) ? RPD : (Section)((id >> kZDCSectionOffset) & kZDCSectionMask);
channel = (se == RPD) ? (1 + (id & kZDCChannelMask1)) : (id & kZDCChannelMask1);
zside = (id & kZDCZsideMask);
}
}
public:
constexpr static int32_t kSizeForDenseIndexingRun1 = 2 * kDepRun1;
constexpr static int32_t kSizeForDenseIndexingRun3 = 2 * kDepRun3;
constexpr static int32_t kSizeForDenseIndexing = kSizeForDenseIndexingRun1;
};
std::ostream& operator<<(std::ostream&, const HcalZDCDetId& id);
#endif // DataFormats_HcalDetId_HcalZDCDetId_h_included
|