CMS 3D CMS Logo

BTLNumberingScheme.cc
Go to the documentation of this file.
2 
4 
5 #include <iostream>
6 #include <cstring>
7 
9  LogDebug("MTDGeom") << "Creating BTLNumberingScheme";
10 }
11 
12 BTLNumberingScheme::~BTLNumberingScheme() { LogDebug("MTDGeom") << "Deleting BTLNumberingScheme"; }
13 
14 uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const {
15  uint32_t intindex(0);
16  const uint32_t nLevels(baseNumber.getLevels());
17 
18  LogDebug("MTDGeom") << "BTLNumberingScheme geometry levels = " << nLevels;
19 
20  uint32_t zside(999), rodCopy(0), runitCopy(0), modCopy(0), modtyp(0), crystal(0);
21 
22  bool isDD4hepOK(false);
23  if (nLevels == kBTLcrystalLevel + 1) {
24  if (baseNumber.getLevelName(9) == "world_volume_1") {
25  isDD4hepOK = true;
26  }
27  }
28 
29  auto bareBaseName = [&](std::string_view name) {
30  size_t ipos = name.rfind('_');
31  return (isDD4hepOK) ? name.substr(0, ipos) : name;
32  };
33 
34  if (nLevels == kBTLcrystalLevel || isDD4hepOK) {
35  LogDebug("MTDGeom") << bareBaseName(baseNumber.getLevelName(0)) << "[" << baseNumber.getCopyNumber(0) << "], "
36  << bareBaseName(baseNumber.getLevelName(1)) << "[" << baseNumber.getCopyNumber(1) << "], "
37  << bareBaseName(baseNumber.getLevelName(2)) << "[" << baseNumber.getCopyNumber(2) << "], "
38  << bareBaseName(baseNumber.getLevelName(3)) << "[" << baseNumber.getCopyNumber(3) << "], "
39  << bareBaseName(baseNumber.getLevelName(4)) << "[" << baseNumber.getCopyNumber(4) << "], "
40  << bareBaseName(baseNumber.getLevelName(5)) << "[" << baseNumber.getCopyNumber(5) << "], "
41  << bareBaseName(baseNumber.getLevelName(6)) << "[" << baseNumber.getCopyNumber(6) << "], "
42  << bareBaseName(baseNumber.getLevelName(7)) << "[" << baseNumber.getCopyNumber(7) << "], "
43  << bareBaseName(baseNumber.getLevelName(8)) << "[" << baseNumber.getCopyNumber(8) << "]";
44 
45  // barphiflat scenario
46 
47  if (baseNumber.getLevelName(0).find("Timingactive") != std::string_view::npos) {
48  crystal = baseNumber.getCopyNumber(0);
49 
50  modCopy = baseNumber.getCopyNumber(2);
51  rodCopy = baseNumber.getCopyNumber(3);
52 
53  const std::string_view& modName(baseNumber.getLevelName(2)); // name of module volume
54  uint32_t pos = modName.find("Positive");
55 
56  zside = (pos <= modName.size() ? 1 : 0);
57  std::string_view baseName = modName.substr(modName.find(':') + 1);
58 
59  modtyp = ::atoi(&baseName.at(7));
60  if (modtyp == 17) {
61  modtyp = 2;
62  } else if (modtyp == 33) {
63  modtyp = 3;
64  }
65 
66  // error checking
67 
68  if (1 > crystal || 64 < crystal) {
69  edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
70  << "****************** Bad crystal number = " << crystal
71  << ", Volume Number = " << baseNumber.getCopyNumber(0);
72  return 0;
73  }
74 
75  if (1 > modtyp || 3 < modtyp) {
76  edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
77  << "****************** Bad module name = " << modName
78  << ", Volume Name = " << baseNumber.getLevelName(2);
79  return 0;
80  }
81 
82  if (1 > modCopy || 54 < modCopy) {
83  edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
84  << "****************** Bad module copy = " << modCopy
85  << ", Volume Number = " << baseNumber.getCopyNumber(2);
86  return 0;
87  }
88 
89  if (1 > rodCopy || 36 < rodCopy) {
90  edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
91  << "****************** Bad rod copy = " << rodCopy
92  << ", Volume Number = " << baseNumber.getCopyNumber(4);
93  return 0;
94  }
95 
96  if (1 < zside) {
97  edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
98  << "****************** Bad side = " << zside
99  << ", Volume Name = " << baseNumber.getLevelName(2);
100  return 0;
101  }
102  } else if (baseNumber.getLevelName(0).find("BTLCrystal") != std::string_view::npos) {
103  // v2 or v3 scenario
104 
105  crystal = baseNumber.getCopyNumber(0);
106  modCopy = baseNumber.getCopyNumber(1);
107  runitCopy = baseNumber.getCopyNumber(2);
108  rodCopy = baseNumber.getCopyNumber(3);
109 
110  const std::string_view& rodName(baseNumber.getLevelName(3)); // name of module volume
111  uint32_t pos = rodName.find("Zpos");
112  zside = (pos <= rodName.size() ? 1 : 0);
113 
114  // for negative side swap module numbers betwee sides of the tray, so as to keep the same number for the same phi angle
115  // in the existing model. This introduces a misalignemtn between module number and volume copy for the negative side.
116  if (zside == 0) {
117  modCopy = negModCopy[modCopy - 1];
118  }
119 
120  bool isV2(baseNumber.getLevelName(0).back() != 'l');
121 
122  if (isV2) {
123  // V2: the type is embedded in crystal name
124  modtyp = ::atoi(&bareBaseName(baseNumber.getLevelName(2)).back());
125  } else {
126  // V3: build type and RU number per type from global RU number
127  modtyp = globalru2type[runitCopy - 1];
128  runitCopy = globalru2ru[runitCopy - 1];
129  }
130 
131  // error checking
132 
133  if (1 > crystal || BTLDetId::kCrystalsPerModuleV2 < crystal) {
134  edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
135  << "****************** Bad crystal number = " << crystal
136  << ", Volume Number = " << baseNumber.getCopyNumber(0);
137  return 0;
138  }
139 
140  if (1 > modtyp || 3 < modtyp) {
141  edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
142  << "****************** Bad RU name, Volume Name = "
143  << bareBaseName(baseNumber.getLevelName(2));
144  return 0;
145  }
146 
147  if (1 > modCopy || BTLDetId::kModulesPerRUV2 < modCopy) {
148  edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
149  << "****************** Bad module copy = " << modCopy
150  << ", Volume Number = " << baseNumber.getCopyNumber(1);
151  return 0;
152  }
153 
154  if (1 > runitCopy || BTLDetId::kRUPerTypeV2 < runitCopy) {
155  edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
156  << "****************** Bad readout unit copy = " << runitCopy
157  << ", Volume Number = " << baseNumber.getCopyNumber(2);
158  return 0;
159  }
160 
161  if (1 > rodCopy || BTLDetId::HALF_ROD < rodCopy) {
162  edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
163  << "****************** Bad rod copy = " << rodCopy
164  << ", Volume Number = " << baseNumber.getCopyNumber(3);
165  return 0;
166  }
167 
168  if (1 < zside) {
169  edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
170  << "****************** Bad side = " << zside
171  << ", Volume Name = " << baseNumber.getLevelName(3);
172  return 0;
173  }
174  }
175 
176  // all inputs are fine. Go ahead and decode
177 
178  BTLDetId thisBTLdetid(zside, rodCopy, runitCopy, modCopy, modtyp, crystal);
179  intindex = thisBTLdetid.rawId();
180 
181  } else if (nLevels == kBTLmoduleLevel && baseNumber.getLevelName(0).find("BTLModule") != std::string_view::npos) {
182  // v2 scenario, geographicalId per module
183  // for tracking navigation geometry
184  LogDebug("MTDGeom") << bareBaseName(baseNumber.getLevelName(0)) << "[" << baseNumber.getCopyNumber(0) << "], "
185  << bareBaseName(baseNumber.getLevelName(1)) << "[" << baseNumber.getCopyNumber(1) << "], "
186  << bareBaseName(baseNumber.getLevelName(2)) << "[" << baseNumber.getCopyNumber(2) << "], "
187  << bareBaseName(baseNumber.getLevelName(3)) << "[" << baseNumber.getCopyNumber(3) << "], "
188  << bareBaseName(baseNumber.getLevelName(4)) << "[" << baseNumber.getCopyNumber(4) << "], "
189  << bareBaseName(baseNumber.getLevelName(5)) << "[" << baseNumber.getCopyNumber(5) << "], "
190  << bareBaseName(baseNumber.getLevelName(6)) << "[" << baseNumber.getCopyNumber(6) << "], "
191  << bareBaseName(baseNumber.getLevelName(7)) << "[" << baseNumber.getCopyNumber(7) << "]";
192 
193  modCopy = baseNumber.getCopyNumber(0);
194  runitCopy = baseNumber.getCopyNumber(1);
195  rodCopy = baseNumber.getCopyNumber(2);
196 
197  const std::string_view& rodName(baseNumber.getLevelName(2)); // name of module volume
198  uint32_t pos = rodName.find("Zpos");
199  zside = (pos <= rodName.size() ? 1 : 0);
200 
201  // for negative side swap module numbers betwee sides of the tray, so as to keep the same number for the same phi angle
202  // in the existing model. This introduces a misalignemtn between module number and volume copy for the negative side.
203  if (zside == 0) {
204  modCopy = negModCopy[modCopy - 1];
205  }
206 
207  bool isV2(baseNumber.getLevelName(0).back() != 'e');
208 
209  if (isV2) {
210  // V2: the type is embedded in crystal name
211  modtyp = ::atoi(&bareBaseName(baseNumber.getLevelName(1)).back());
212  } else {
213  // V3: build type and RU number per type from global RU number
214  modtyp = globalru2type[runitCopy - 1];
215  runitCopy = globalru2ru[runitCopy - 1];
216  }
217 
218  // error checking
219 
220  if (1 > modtyp || 3 < modtyp) {
221  edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
222  << "****************** Bad RU name, Volume Name = "
223  << bareBaseName(baseNumber.getLevelName(1));
224  return 0;
225  }
226 
227  if (1 > modCopy || BTLDetId::kModulesPerRUV2 < modCopy) {
228  edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
229  << "****************** Bad module copy = " << modCopy
230  << ", Volume Number = " << baseNumber.getCopyNumber(0);
231  return 0;
232  }
233 
234  if (1 > runitCopy || BTLDetId::kRUPerTypeV2 < runitCopy) {
235  edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
236  << "****************** Bad readout unit copy = " << runitCopy
237  << ", Volume Number = " << baseNumber.getCopyNumber(1);
238  return 0;
239  }
240 
241  if (1 > rodCopy || BTLDetId::HALF_ROD < rodCopy) {
242  edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
243  << "****************** Bad rod copy = " << rodCopy
244  << ", Volume Number = " << baseNumber.getCopyNumber(2);
245  return 0;
246  }
247 
248  if (1 < zside) {
249  edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
250  << "****************** Bad side = " << zside
251  << ", Volume Name = " << baseNumber.getLevelName(2);
252  return 0;
253  }
254 
255  // all inputs are fine. Go ahead and decode
256 
257  BTLDetId thisBTLdetid(zside, rodCopy, runitCopy, modCopy, modtyp, 0);
258  intindex = thisBTLdetid.geographicalId(BTLDetId::CrysLayout::v2).rawId();
259 
260  } else {
261  edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
262  << "Not enough levels found in MTDBaseNumber ( " << nLevels
263  << ") or not correct path. Returning 0";
264  return 0;
265  }
266 
267  LogDebug("MTDGeom") << "BTL Numbering scheme: "
268  << " zside = " << zside << " rod = " << rodCopy << " modtyp = " << modtyp << " RU = " << runitCopy
269  << " module = " << modCopy << " crystal = " << crystal << " Raw Id = " << intindex << "\n"
270  << BTLDetId(intindex);
271 
272  return intindex;
273 }
int getCopyNumber(int level) const
~BTLNumberingScheme() override
static constexpr std::array< uint32_t, BTLDetId::kRUPerTypeV2 *BTLDetId::kCrystalTypes > globalru2ru
static constexpr std::array< uint32_t, BTLDetId::kModulesPerRUV2 > negModCopy
int getLevels() const
int zside(DetId const &)
std::string_view const & getLevelName(int level) const
static constexpr uint32_t HALF_ROD
range constants, need two sets for the time being (one for tiles and one for bars) ...
Definition: BTLDetId.h:31
static constexpr uint32_t kModulesPerRUV2
Definition: BTLDetId.h:35
static constexpr uint32_t kBTLcrystalLevel
uint32_t getUnitID(const MTDBaseNumber &baseNumber) const override
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
static constexpr uint32_t kRUPerTypeV2
Definition: BTLDetId.h:34
Detector identifier class for the Barrel Timing Layer. The crystal count must start from 0...
Definition: BTLDetId.h:19
static constexpr uint32_t kCrystalsPerModuleV2
Definition: BTLDetId.h:36
static constexpr uint32_t kBTLmoduleLevel
Log< level::Warning, false > LogWarning
static constexpr std::array< uint32_t, BTLDetId::kRUPerTypeV2 *BTLDetId::kCrystalTypes > globalru2type
BTLDetId geographicalId(CrysLayout lay) const
Definition: BTLDetId.cc:3
#define LogDebug(id)