Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:14

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 
0003 #include "Geometry/MTDCommonData/interface/BTLNumberingScheme.h"
0004 
0005 #include <iostream>
0006 #include <cstring>
0007 
0008 BTLNumberingScheme::BTLNumberingScheme() : MTDNumberingScheme() {
0009   LogDebug("MTDGeom") << "Creating BTLNumberingScheme";
0010 }
0011 
0012 BTLNumberingScheme::~BTLNumberingScheme() { LogDebug("MTDGeom") << "Deleting BTLNumberingScheme"; }
0013 
0014 uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const {
0015   uint32_t intindex(0);
0016   const uint32_t nLevels(baseNumber.getLevels());
0017 
0018   LogDebug("MTDGeom") << "BTLNumberingScheme geometry levels = " << nLevels;
0019 
0020   uint32_t zside(999), rodCopy(0), runitCopy(0), modCopy(0), modtyp(0), crystal(0);
0021 
0022   bool isDD4hepOK(false);
0023   if (nLevels == kBTLcrystalLevel + 1) {
0024     if (baseNumber.getLevelName(9) == "world_volume_1") {
0025       isDD4hepOK = true;
0026     }
0027   }
0028 
0029   auto bareBaseName = [&](std::string_view name) {
0030     size_t ipos = name.rfind('_');
0031     return (isDD4hepOK) ? name.substr(0, ipos) : name;
0032   };
0033 
0034   if (nLevels == kBTLcrystalLevel || isDD4hepOK) {
0035     LogDebug("MTDGeom") << bareBaseName(baseNumber.getLevelName(0)) << "[" << baseNumber.getCopyNumber(0) << "], "
0036                         << bareBaseName(baseNumber.getLevelName(1)) << "[" << baseNumber.getCopyNumber(1) << "], "
0037                         << bareBaseName(baseNumber.getLevelName(2)) << "[" << baseNumber.getCopyNumber(2) << "], "
0038                         << bareBaseName(baseNumber.getLevelName(3)) << "[" << baseNumber.getCopyNumber(3) << "], "
0039                         << bareBaseName(baseNumber.getLevelName(4)) << "[" << baseNumber.getCopyNumber(4) << "], "
0040                         << bareBaseName(baseNumber.getLevelName(5)) << "[" << baseNumber.getCopyNumber(5) << "], "
0041                         << bareBaseName(baseNumber.getLevelName(6)) << "[" << baseNumber.getCopyNumber(6) << "], "
0042                         << bareBaseName(baseNumber.getLevelName(7)) << "[" << baseNumber.getCopyNumber(7) << "], "
0043                         << bareBaseName(baseNumber.getLevelName(8)) << "[" << baseNumber.getCopyNumber(8) << "]";
0044 
0045     // barphiflat scenario
0046 
0047     if (baseNumber.getLevelName(0).find("Timingactive") != std::string_view::npos) {
0048       crystal = baseNumber.getCopyNumber(0);
0049 
0050       modCopy = baseNumber.getCopyNumber(2);
0051       rodCopy = baseNumber.getCopyNumber(3);
0052 
0053       const std::string_view& modName(baseNumber.getLevelName(2));  // name of module volume
0054       uint32_t pos = modName.find("Positive");
0055 
0056       zside = (pos <= modName.size() ? 1 : 0);
0057       std::string_view baseName = modName.substr(modName.find(':') + 1);
0058 
0059       modtyp = ::atoi(&baseName.at(7));
0060       if (modtyp == 17) {
0061         modtyp = 2;
0062       } else if (modtyp == 33) {
0063         modtyp = 3;
0064       }
0065 
0066       // error checking
0067 
0068       if (1 > crystal || 64 < crystal) {
0069         edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
0070                                    << "****************** Bad crystal number = " << crystal
0071                                    << ", Volume Number = " << baseNumber.getCopyNumber(0);
0072         return 0;
0073       }
0074 
0075       if (1 > modtyp || 3 < modtyp) {
0076         edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
0077                                    << "****************** Bad module name = " << modName
0078                                    << ", Volume Name = " << baseNumber.getLevelName(2);
0079         return 0;
0080       }
0081 
0082       if (1 > modCopy || 54 < modCopy) {
0083         edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
0084                                    << "****************** Bad module copy = " << modCopy
0085                                    << ", Volume Number = " << baseNumber.getCopyNumber(2);
0086         return 0;
0087       }
0088 
0089       if (1 > rodCopy || 36 < rodCopy) {
0090         edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
0091                                    << "****************** Bad rod copy = " << rodCopy
0092                                    << ", Volume Number = " << baseNumber.getCopyNumber(4);
0093         return 0;
0094       }
0095 
0096       if (1 < zside) {
0097         edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
0098                                    << "****************** Bad side = " << zside
0099                                    << ", Volume Name = " << baseNumber.getLevelName(2);
0100         return 0;
0101       }
0102     } else if (baseNumber.getLevelName(0).find("BTLCrystal") != std::string_view::npos) {
0103       // v2 or v3 scenario
0104 
0105       crystal = baseNumber.getCopyNumber(0);
0106       modCopy = baseNumber.getCopyNumber(1);
0107       runitCopy = baseNumber.getCopyNumber(2);
0108       rodCopy = baseNumber.getCopyNumber(3);
0109 
0110       const std::string_view& rodName(baseNumber.getLevelName(3));  // name of module volume
0111       uint32_t pos = rodName.find("Zpos");
0112       zside = (pos <= rodName.size() ? 1 : 0);
0113 
0114       // for negative side swap module numbers betwee sides of the tray, so as to keep the same number for the same phi angle
0115       // in the existing model. This introduces a misalignemtn between module number and volume copy for the negative side.
0116       if (zside == 0) {
0117         modCopy = negModCopy[modCopy - 1];
0118       }
0119 
0120       bool isV2(baseNumber.getLevelName(0).back() != 'l');
0121 
0122       if (isV2) {
0123         // V2: the type is embedded in crystal name
0124         modtyp = ::atoi(&bareBaseName(baseNumber.getLevelName(2)).back());
0125       } else {
0126         // V3: build type and RU number per type from global RU number
0127         modtyp = globalru2type[runitCopy - 1];
0128         runitCopy = globalru2ru[runitCopy - 1];
0129       }
0130 
0131       // error checking
0132 
0133       if (1 > crystal || BTLDetId::kCrystalsPerModuleV2 < crystal) {
0134         edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
0135                                    << "****************** Bad crystal number = " << crystal
0136                                    << ", Volume Number = " << baseNumber.getCopyNumber(0);
0137         return 0;
0138       }
0139 
0140       if (1 > modtyp || 3 < modtyp) {
0141         edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
0142                                    << "****************** Bad RU name, Volume Name = "
0143                                    << bareBaseName(baseNumber.getLevelName(2));
0144         return 0;
0145       }
0146 
0147       if (1 > modCopy || BTLDetId::kModulesPerRUV2 < modCopy) {
0148         edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
0149                                    << "****************** Bad module copy = " << modCopy
0150                                    << ", Volume Number = " << baseNumber.getCopyNumber(1);
0151         return 0;
0152       }
0153 
0154       if (1 > runitCopy || BTLDetId::kRUPerTypeV2 < runitCopy) {
0155         edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
0156                                    << "****************** Bad readout unit copy = " << runitCopy
0157                                    << ", Volume Number = " << baseNumber.getCopyNumber(2);
0158         return 0;
0159       }
0160 
0161       if (1 > rodCopy || BTLDetId::HALF_ROD < rodCopy) {
0162         edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
0163                                    << "****************** Bad rod copy = " << rodCopy
0164                                    << ", Volume Number = " << baseNumber.getCopyNumber(3);
0165         return 0;
0166       }
0167 
0168       if (1 < zside) {
0169         edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
0170                                    << "****************** Bad side = " << zside
0171                                    << ", Volume Name = " << baseNumber.getLevelName(3);
0172         return 0;
0173       }
0174     }
0175 
0176     // all inputs are fine. Go ahead and decode
0177 
0178     BTLDetId thisBTLdetid(zside, rodCopy, runitCopy, modCopy, modtyp, crystal);
0179     intindex = thisBTLdetid.rawId();
0180 
0181   } else if (nLevels == kBTLmoduleLevel && baseNumber.getLevelName(0).find("BTLModule") != std::string_view::npos) {
0182     // v2 scenario, geographicalId per module
0183     // for tracking navigation geometry
0184     LogDebug("MTDGeom") << bareBaseName(baseNumber.getLevelName(0)) << "[" << baseNumber.getCopyNumber(0) << "], "
0185                         << bareBaseName(baseNumber.getLevelName(1)) << "[" << baseNumber.getCopyNumber(1) << "], "
0186                         << bareBaseName(baseNumber.getLevelName(2)) << "[" << baseNumber.getCopyNumber(2) << "], "
0187                         << bareBaseName(baseNumber.getLevelName(3)) << "[" << baseNumber.getCopyNumber(3) << "], "
0188                         << bareBaseName(baseNumber.getLevelName(4)) << "[" << baseNumber.getCopyNumber(4) << "], "
0189                         << bareBaseName(baseNumber.getLevelName(5)) << "[" << baseNumber.getCopyNumber(5) << "], "
0190                         << bareBaseName(baseNumber.getLevelName(6)) << "[" << baseNumber.getCopyNumber(6) << "], "
0191                         << bareBaseName(baseNumber.getLevelName(7)) << "[" << baseNumber.getCopyNumber(7) << "]";
0192 
0193     modCopy = baseNumber.getCopyNumber(0);
0194     runitCopy = baseNumber.getCopyNumber(1);
0195     rodCopy = baseNumber.getCopyNumber(2);
0196 
0197     const std::string_view& rodName(baseNumber.getLevelName(2));  // name of module volume
0198     uint32_t pos = rodName.find("Zpos");
0199     zside = (pos <= rodName.size() ? 1 : 0);
0200 
0201     // for negative side swap module numbers betwee sides of the tray, so as to keep the same number for the same phi angle
0202     // in the existing model. This introduces a misalignemtn between module number and volume copy for the negative side.
0203     if (zside == 0) {
0204       modCopy = negModCopy[modCopy - 1];
0205     }
0206 
0207     bool isV2(baseNumber.getLevelName(0).back() != 'e');
0208 
0209     if (isV2) {
0210       // V2: the type is embedded in crystal name
0211       modtyp = ::atoi(&bareBaseName(baseNumber.getLevelName(1)).back());
0212     } else {
0213       // V3: build type and RU number per type from global RU number
0214       modtyp = globalru2type[runitCopy - 1];
0215       runitCopy = globalru2ru[runitCopy - 1];
0216     }
0217 
0218     // error checking
0219 
0220     if (1 > modtyp || 3 < modtyp) {
0221       edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
0222                                  << "****************** Bad RU name, Volume Name = "
0223                                  << bareBaseName(baseNumber.getLevelName(1));
0224       return 0;
0225     }
0226 
0227     if (1 > modCopy || BTLDetId::kModulesPerRUV2 < modCopy) {
0228       edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
0229                                  << "****************** Bad module copy = " << modCopy
0230                                  << ", Volume Number = " << baseNumber.getCopyNumber(0);
0231       return 0;
0232     }
0233 
0234     if (1 > runitCopy || BTLDetId::kRUPerTypeV2 < runitCopy) {
0235       edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
0236                                  << "****************** Bad readout unit copy = " << runitCopy
0237                                  << ", Volume Number = " << baseNumber.getCopyNumber(1);
0238       return 0;
0239     }
0240 
0241     if (1 > rodCopy || BTLDetId::HALF_ROD < rodCopy) {
0242       edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
0243                                  << "****************** Bad rod copy = " << rodCopy
0244                                  << ", Volume Number = " << baseNumber.getCopyNumber(2);
0245       return 0;
0246     }
0247 
0248     if (1 < zside) {
0249       edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
0250                                  << "****************** Bad side = " << zside
0251                                  << ", Volume Name = " << baseNumber.getLevelName(2);
0252       return 0;
0253     }
0254 
0255     // all inputs are fine. Go ahead and decode
0256 
0257     BTLDetId thisBTLdetid(zside, rodCopy, runitCopy, modCopy, modtyp, 0);
0258     intindex = thisBTLdetid.geographicalId(BTLDetId::CrysLayout::v2).rawId();
0259 
0260   } else {
0261     edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): "
0262                                << "Not enough levels found in MTDBaseNumber ( " << nLevels
0263                                << ") or not correct path. Returning 0";
0264     return 0;
0265   }
0266 
0267   LogDebug("MTDGeom") << "BTL Numbering scheme: "
0268                       << " zside = " << zside << " rod = " << rodCopy << " modtyp = " << modtyp << " RU = " << runitCopy
0269                       << " module = " << modCopy << " crystal = " << crystal << " Raw Id = " << intindex << "\n"
0270                       << BTLDetId(intindex);
0271 
0272   return intindex;
0273 }