Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-12-13 03:12:19

0001 //#define EDM_ML_DEBUG
0002 
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 #include "Geometry/MTDCommonData/interface/ETLNumberingScheme.h"
0006 #include "DataFormats/ForwardDetId/interface/ETLDetId.h"
0007 
0008 #include <iostream>
0009 
0010 ETLNumberingScheme::ETLNumberingScheme() : MTDNumberingScheme() {
0011 #ifdef EDM_ML_DEBUG
0012   edm::LogInfo("MTDGeom") << "Creating ETLNumberingScheme";
0013 #endif
0014 }
0015 
0016 ETLNumberingScheme::~ETLNumberingScheme() {
0017 #ifdef EDM_ML_DEBUG
0018   edm::LogInfo("MTDGeom") << "Deleting ETLNumberingScheme";
0019 #endif
0020 }
0021 
0022 uint32_t ETLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const {
0023   const uint32_t nLevels(baseNumber.getLevels());
0024 
0025 #ifdef EDM_ML_DEBUG
0026   edm::LogInfo("MTDGeom") << "ETLNumberingScheme geometry levels = " << nLevels;
0027 #endif
0028 
0029   if (11 > nLevels) {
0030     edm::LogWarning("MTDGeom") << "ETLNumberingScheme::getUnitID(): "
0031                                << "Not enough levels found in MTDBaseNumber ( " << nLevels << ") Returning 0";
0032     return 0;
0033   }
0034 
0035   const bool prev8(baseNumber.getLevelName(2).find("Sensor") != std::string::npos);
0036 
0037   const uint32_t modCopy(baseNumber.getCopyNumber(2));
0038   uint32_t sensor = 0;
0039   if (!prev8) {
0040     sensor = baseNumber.getCopyNumber(1);
0041   }
0042 
0043   int modtyp(0);
0044 
0045   uint32_t discN, sectorS, sectorN;
0046   discN = (baseNumber.getLevelName(4).find("Disc1") != std::string::npos) ? 0 : 1;
0047   sectorS = (baseNumber.getLevelName(3).find("Front") != std::string::npos) ? 0 : 1;
0048   sectorN = baseNumber.getCopyNumber(3);
0049 
0050   ETLDetId tmpId;
0051   int ringCopy = static_cast<int>(tmpId.encodeSector(discN, sectorS, sectorN));
0052 
0053   modtyp = (baseNumber.getLevelName(2).find("_Left") != std::string::npos) ? 1 : 2;
0054 
0055   int nSide(7);
0056   const std::string_view& sideName(baseNumber.getLevelName(nSide));
0057   if (sideName.find("CALOECTSFront") != std::string::npos) {
0058     nSide = 8;
0059   } else {
0060     edm::LogWarning("MTDGeom") << "ETLNumberingScheme::getUnitID(): incorrect volume stack: \n"
0061                                << baseNumber.getLevelName(0) << ", " << baseNumber.getLevelName(1) << ", "
0062                                << baseNumber.getLevelName(2) << ", " << baseNumber.getLevelName(3) << ", "
0063                                << baseNumber.getLevelName(4) << ", " << baseNumber.getLevelName(5) << ", "
0064                                << baseNumber.getLevelName(6) << ", " << baseNumber.getLevelName(7) << ", "
0065                                << baseNumber.getLevelName(8) << ", " << baseNumber.getLevelName(9) << ", "
0066                                << baseNumber.getLevelName(10) << ", " << baseNumber.getLevelName(11) << "\nReturning 0";
0067     return 0;
0068   }
0069   const uint32_t sideCopy(baseNumber.getCopyNumber(nSide));
0070   const uint32_t zside(sideCopy == 1 ? 1 : 0);
0071 
0072 #ifdef EDM_ML_DEBUG
0073   edm::LogInfo("MTDGeom") << baseNumber.getLevelName(0) << ", " << baseNumber.getLevelName(1) << ", "
0074                           << baseNumber.getLevelName(2) << ", " << baseNumber.getLevelName(3) << ", "
0075                           << baseNumber.getLevelName(4) << ", " << baseNumber.getLevelName(5) << ", "
0076                           << baseNumber.getLevelName(6) << ", " << baseNumber.getLevelName(7) << ", "
0077                           << baseNumber.getLevelName(8) << ", " << baseNumber.getLevelName(9) << ", "
0078                           << baseNumber.getLevelName(10) << ", " << baseNumber.getLevelName(11);
0079 #endif
0080 
0081   // error checking
0082 
0083   if (modtyp == 0) {
0084     edm::LogWarning("MTDGeom") << "ETLNumberingScheme::getUnitID(): "
0085                                << "****************** Bad module name = " << modtyp
0086                                << ", Volume Name = " << baseNumber.getLevelName(4);
0087     return 0;
0088   }
0089 
0090   if (1 > modCopy || static_cast<unsigned>(std::max(ETLDetId::kETLv4maxModule, ETLDetId::kETLv5maxModule)) < modCopy) {
0091     edm::LogWarning("MTDGeom") << "ETLNumberingScheme::getUnitID(): "
0092                                << "****************** Bad module copy = " << modCopy
0093                                << ", Volume Number = " << baseNumber.getCopyNumber(4);
0094     return 0;
0095   }
0096 
0097   if (1 > ringCopy || ETLDetId::kETLv4maxRing < ringCopy) {
0098     edm::LogWarning("MTDGeom") << "ETLNumberingScheme::getUnitID(): "
0099                                << "****************** Bad ring copy = " << ringCopy
0100                                << ", Volume Number = " << baseNumber.getCopyNumber(3);
0101     return 0;
0102   }
0103 
0104   // all inputs are fine. Go ahead and decode
0105 
0106   // Different for v8 and pre v8 ETL geometries
0107   uint32_t intindex = 0;
0108   uint32_t altintindex = 0;
0109   if (prev8) {
0110     ETLDetId thisETLdetid(zside, ringCopy, modCopy, modtyp);
0111     intindex = thisETLdetid.rawId();
0112 #ifdef EDM_ML_DEBUG
0113     edm::LogInfo("MTDGeom") << "ETL Numbering scheme: "
0114                             << " ring = " << ringCopy << " zside = " << zside << " module = " << modCopy
0115                             << " modtyp = " << modtyp << " Raw Id = " << intindex;
0116 #endif
0117 
0118     ETLDetId altETLdetid(zside, discN, sectorS, sectorN, modCopy, modtyp);
0119     altintindex = altETLdetid.rawId();
0120 
0121   } else {
0122     ETLDetId thisETLdetid(zside, ringCopy, modCopy, modtyp, sensor);
0123     intindex = thisETLdetid.rawId();
0124 #ifdef EDM_ML_DEBUG
0125     edm::LogInfo("MTDGeom") << "ETL Numbering scheme: "
0126                             << " ring = " << ringCopy << " zside = " << zside << " module = " << modCopy
0127                             << " modtyp = " << modtyp << " sensor = " << sensor << " Raw Id = " << intindex;
0128 #endif
0129 
0130     ETLDetId altETLdetid(zside, discN, sectorS, sectorN, modCopy, modtyp, sensor);
0131     altintindex = altETLdetid.rawId();
0132   }
0133 
0134   if (intindex != altintindex) {
0135     edm::LogWarning("MTDGeom") << "Incorrect alternative construction \n"
0136                                << "disc = " << discN << " disc side = " << sectorS << " sector = " << sectorN << "\n";
0137   }
0138 
0139   return intindex;
0140 }