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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "Geometry/MTDCommonData/interface/BTLNumberingScheme.h"
#include <iostream>
#include <cstring>
BTLNumberingScheme::BTLNumberingScheme() : MTDNumberingScheme() {
LogDebug("MTDGeom") << "Creating BTLNumberingScheme";
}
BTLNumberingScheme::~BTLNumberingScheme() { LogDebug("MTDGeom") << "Deleting BTLNumberingScheme"; }
uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const {
uint32_t intindex(0);
const uint32_t nLevels(baseNumber.getLevels());
LogDebug("MTDGeom") << "BTLNumberingScheme geometry levels = " << nLevels;
uint32_t zside(999), rodCopy(0), runitCopy(0), modCopy(0), modtyp(0), crystal(0);
bool isDD4hepOK(false);
if (nLevels == kBTLcrystalLevel + 1) {
if (baseNumber.getLevelName(9) == "world_volume_1") {
isDD4hepOK = true;
}
}
#ifdef EDM_ML_DEBUG
LogDebug("MTDGeom") << "BTLNumberingScheme::getUnitID(): isDD4hep " << isDD4hepOK;
#endif
auto bareBaseName = [&](std::string_view name) {
size_t ipos = name.rfind('_');
return (isDD4hepOK) ? name.substr(0, ipos) : name;
};
if (nLevels == kBTLcrystalLevel || isDD4hepOK) {
LogDebug("MTDGeom") << bareBaseName(baseNumber.getLevelName(0)) << "[" << baseNumber.getCopyNumber(0) << "], "
<< bareBaseName(baseNumber.getLevelName(1)) << "[" << baseNumber.getCopyNumber(1) << "], "
<< bareBaseName(baseNumber.getLevelName(2)) << "[" << baseNumber.getCopyNumber(2) << "], "
<< bareBaseName(baseNumber.getLevelName(3)) << "[" << baseNumber.getCopyNumber(3) << "], "
<< bareBaseName(baseNumber.getLevelName(4)) << "[" << baseNumber.getCopyNumber(4) << "], "
<< bareBaseName(baseNumber.getLevelName(5)) << "[" << baseNumber.getCopyNumber(5) << "], "
<< bareBaseName(baseNumber.getLevelName(6)) << "[" << baseNumber.getCopyNumber(6) << "], "
<< bareBaseName(baseNumber.getLevelName(7)) << "[" << baseNumber.getCopyNumber(7) << "], "
<< bareBaseName(baseNumber.getLevelName(8)) << "[" << baseNumber.getCopyNumber(8) << "]";
// barphiflat scenario
if (baseNumber.getLevelName(0).find("Timingactive") != std::string_view::npos) {
crystal = baseNumber.getCopyNumber(0);
modCopy = baseNumber.getCopyNumber(2);
rodCopy = baseNumber.getCopyNumber(3);
const std::string_view& modName(baseNumber.getLevelName(2)); // name of module volume
uint32_t pos = modName.find("Positive");
zside = (pos <= modName.size() ? 1 : 0);
std::string_view baseName = modName.substr(modName.find(':') + 1);
modtyp = ::atoi(&baseName.at(7));
if (modtyp == 17) {
modtyp = 2;
} else if (modtyp == 33) {
modtyp = 3;
}
// error checking
if (1 > crystal || 64 < crystal) {
edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
<< "****************** Bad crystal number = " << crystal
<< ", Volume Number = " << baseNumber.getCopyNumber(0);
return 0;
}
if (1 > modtyp || 3 < modtyp) {
edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
<< "****************** Bad module name = " << modName
<< ", Volume Name = " << baseNumber.getLevelName(2);
return 0;
}
if (1 > modCopy || 54 < modCopy) {
edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
<< "****************** Bad module copy = " << modCopy
<< ", Volume Number = " << baseNumber.getCopyNumber(2);
return 0;
}
if (1 > rodCopy || 36 < rodCopy) {
edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
<< "****************** Bad rod copy = " << rodCopy
<< ", Volume Number = " << baseNumber.getCopyNumber(4);
return 0;
}
if (1 < zside) {
edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
<< "****************** Bad side = " << zside
<< ", Volume Name = " << baseNumber.getLevelName(2);
return 0;
}
} else if (baseNumber.getLevelName(0).find("BTLCrystal") != std::string_view::npos) {
// v2 or v3 scenario
crystal = baseNumber.getCopyNumber(0);
modCopy = baseNumber.getCopyNumber(1);
runitCopy = baseNumber.getCopyNumber(2);
rodCopy = baseNumber.getCopyNumber(3);
const std::string_view& rodName(baseNumber.getLevelName(3)); // name of module volume
uint32_t pos = rodName.find("Zpos");
zside = (pos <= rodName.size() ? 1 : 0);
// for negative side swap module numbers betwee sides of the tray, so as to keep the same number for the same phi angle
// in the existing model. This introduces a misalignemtn between module number and volume copy for the negative side.
if (zside == 0) {
modCopy = negModCopy[modCopy - 1];
}
bool isV2(bareBaseName(baseNumber.getLevelName(0)).back() != 'l');
#ifdef EDM_ML_DEBUG
LogDebug("MTDGeom") << "BTLNumberingScheme::getUnitID(): isV2 " << isV2;
#endif
if (isV2) {
// V2: the type is embedded in crystal name
modtyp = ::atoi(&bareBaseName(baseNumber.getLevelName(2)).back());
} else {
// V3: build type and RU number per type from global RU number
modtyp = globalru2type[runitCopy - 1];
runitCopy = globalru2ru[runitCopy - 1];
}
// error checking
if (1 > crystal || BTLDetId::kCrystalsPerModuleV2 < crystal) {
edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
<< "****************** Bad crystal number = " << crystal
<< ", Volume Number = " << baseNumber.getCopyNumber(0);
return 0;
}
if (1 > modtyp || 3 < modtyp) {
edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
<< "****************** Bad RU name, Volume Name = "
<< bareBaseName(baseNumber.getLevelName(2));
return 0;
}
if (1 > modCopy || BTLDetId::kModulesPerRUV2 < modCopy) {
edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
<< "****************** Bad module copy = " << modCopy
<< ", Volume Number = " << baseNumber.getCopyNumber(1);
return 0;
}
if (1 > runitCopy || BTLDetId::kRUPerTypeV2 < runitCopy) {
edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
<< "****************** Bad readout unit copy = " << runitCopy
<< ", Volume Number = " << baseNumber.getCopyNumber(2);
return 0;
}
if (1 > rodCopy || BTLDetId::HALF_ROD < rodCopy) {
edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
<< "****************** Bad rod copy = " << rodCopy
<< ", Volume Number = " << baseNumber.getCopyNumber(3);
return 0;
}
if (1 < zside) {
edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
<< "****************** Bad side = " << zside
<< ", Volume Name = " << baseNumber.getLevelName(3);
return 0;
}
}
// all inputs are fine. Go ahead and decode
BTLDetId thisBTLdetid(zside, rodCopy, runitCopy, modCopy, modtyp, crystal);
intindex = thisBTLdetid.rawId();
} else if (nLevels == kBTLmoduleLevel && baseNumber.getLevelName(0).find("BTLModule") != std::string_view::npos) {
// v2 scenario, geographicalId per module
// for tracking navigation geometry
LogDebug("MTDGeom") << bareBaseName(baseNumber.getLevelName(0)) << "[" << baseNumber.getCopyNumber(0) << "], "
<< bareBaseName(baseNumber.getLevelName(1)) << "[" << baseNumber.getCopyNumber(1) << "], "
<< bareBaseName(baseNumber.getLevelName(2)) << "[" << baseNumber.getCopyNumber(2) << "], "
<< bareBaseName(baseNumber.getLevelName(3)) << "[" << baseNumber.getCopyNumber(3) << "], "
<< bareBaseName(baseNumber.getLevelName(4)) << "[" << baseNumber.getCopyNumber(4) << "], "
<< bareBaseName(baseNumber.getLevelName(5)) << "[" << baseNumber.getCopyNumber(5) << "], "
<< bareBaseName(baseNumber.getLevelName(6)) << "[" << baseNumber.getCopyNumber(6) << "], "
<< bareBaseName(baseNumber.getLevelName(7)) << "[" << baseNumber.getCopyNumber(7) << "]";
modCopy = baseNumber.getCopyNumber(0);
runitCopy = baseNumber.getCopyNumber(1);
rodCopy = baseNumber.getCopyNumber(2);
const std::string_view& rodName(baseNumber.getLevelName(2)); // name of module volume
uint32_t pos = rodName.find("Zpos");
zside = (pos <= rodName.size() ? 1 : 0);
// for negative side swap module numbers betwee sides of the tray, so as to keep the same number for the same phi angle
// in the existing model. This introduces a misalignemtn between module number and volume copy for the negative side.
if (zside == 0) {
modCopy = negModCopy[modCopy - 1];
}
bool isV2(bareBaseName(baseNumber.getLevelName(0)).back() != 'e');
#ifdef EDM_ML_DEBUG
LogDebug("MTDGeom") << "BTLNumberingScheme::getUnitID(): isV2 " << isV2;
#endif
if (isV2) {
// V2: the type is embedded in crystal name
modtyp = ::atoi(&bareBaseName(baseNumber.getLevelName(1)).back());
} else {
// V3: build type and RU number per type from global RU number
modtyp = globalru2type[runitCopy - 1];
runitCopy = globalru2ru[runitCopy - 1];
}
// error checking
if (1 > modtyp || 3 < modtyp) {
edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
<< "****************** Bad RU name, Volume Name = "
<< bareBaseName(baseNumber.getLevelName(1));
return 0;
}
if (1 > modCopy || BTLDetId::kModulesPerRUV2 < modCopy) {
edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
<< "****************** Bad module copy = " << modCopy
<< ", Volume Number = " << baseNumber.getCopyNumber(0);
return 0;
}
if (1 > runitCopy || BTLDetId::kRUPerTypeV2 < runitCopy) {
edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
<< "****************** Bad readout unit copy = " << runitCopy
<< ", Volume Number = " << baseNumber.getCopyNumber(1);
return 0;
}
if (1 > rodCopy || BTLDetId::HALF_ROD < rodCopy) {
edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
<< "****************** Bad rod copy = " << rodCopy
<< ", Volume Number = " << baseNumber.getCopyNumber(2);
return 0;
}
if (1 < zside) {
edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
<< "****************** Bad side = " << zside
<< ", Volume Name = " << baseNumber.getLevelName(2);
return 0;
}
// all inputs are fine. Go ahead and decode
BTLDetId thisBTLdetid(zside, rodCopy, runitCopy, modCopy, modtyp, 0);
intindex = thisBTLdetid.geographicalId(BTLDetId::CrysLayout::v2).rawId();
} else {
edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
<< "Not enough levels found in MTDBaseNumber ( " << nLevels
<< ") or not correct path. Returning 0";
return 0;
}
LogDebug("MTDGeom") << "BTL Numbering scheme: "
<< " zside = " << zside << " rod = " << rodCopy << " modtyp = " << modtyp << " RU = " << runitCopy
<< " module = " << modCopy << " crystal = " << crystal << " Raw Id = " << intindex << "\n"
<< BTLDetId(intindex);
return intindex;
}
|