CMS 3D CMS Logo

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