Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: EcalBarrelNumberingScheme.cc
0003 // Description: Numbering scheme for barrel electromagnetic calorimeter
0004 ///////////////////////////////////////////////////////////////////////////////
0005 #include "Geometry/EcalCommonData/interface/EcalBarrelNumberingScheme.h"
0006 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0007 #include <sstream>
0008 
0009 //#define EDM_ML_DEBUG
0010 
0011 EcalBarrelNumberingScheme::EcalBarrelNumberingScheme() : EcalNumberingScheme() {
0012 #ifdef EDM_ML_DEBUG
0013   edm::LogVerbatim("EcalGeom") << "Creating EcalBarrelNumberingScheme";
0014 #endif
0015 }
0016 
0017 EcalBarrelNumberingScheme::~EcalBarrelNumberingScheme() {
0018 #ifdef EDM_ML_DEBUG
0019   edm::LogVerbatim("EcalGeom") << "Deleting EcalBarrelNumberingScheme";
0020 #endif
0021 }
0022 
0023 uint32_t EcalBarrelNumberingScheme::getUnitID(const EcalBaseNumber& baseNumber) const {
0024   const uint32_t nLevels(baseNumber.getLevels());
0025 
0026 #ifdef EDM_ML_DEBUG
0027   std::ostringstream st1;
0028   for (uint32_t k = 0; k < nLevels; ++k)
0029     st1 << ", " << baseNumber.getLevelName(k) << ":" << baseNumber.getCopyNumber(k);
0030   edm::LogVerbatim("EcalGeom") << "ECalBarrelNumberingScheme geometry levels = " << nLevels << st1.str();
0031 #endif
0032   if (11 > nLevels) {
0033     edm::LogWarning("EcalGeom") << "ECalBarrelNumberingScheme::getUnitID(): "
0034                                 << "Not enough levels found in EcalBaseNumber ( " << nLevels << ") Returning 0";
0035     return 0;
0036   }
0037 
0038   const std::string& cryName(baseNumber.getLevelName(0).substr(0, 7));  // name of crystal volume
0039 
0040   const int cryType(::atoi(cryName.c_str() + 5));
0041 
0042   uint32_t wallCopy(0), hawCopy(0), fawCopy(0), supmCopy(0);
0043   const int off(13 < nLevels ? 3 : 0);
0044 
0045   if ((nLevels != 11) && (nLevels != 14)) {
0046     wallCopy = baseNumber.getCopyNumber(3 + off);
0047     hawCopy = baseNumber.getCopyNumber(4 + off);
0048     fawCopy = baseNumber.getCopyNumber(5 + off);
0049     supmCopy = baseNumber.getCopyNumber(6 + off);
0050   } else {
0051     auto num1 = numbers(baseNumber.getLevelName(3 + off));
0052     wallCopy = num1.second;
0053     hawCopy = num1.first;
0054     auto num2 = numbers(baseNumber.getLevelName(4 + off));
0055     fawCopy = num2.second;
0056     supmCopy = num2.first;
0057   }
0058 #ifdef EDM_ML_DEBUG
0059   edm::LogVerbatim("EcalGeom") << nLevels << " off: " << off << " cryType: " << cryType << " wallCopy: " << wallCopy
0060                                << " hawCopy: " << hawCopy << " fawCopy: " << fawCopy << " supmCopy: " << supmCopy;
0061 #endif
0062   // error checking
0063 
0064   if (1 > cryType || 17 < cryType) {
0065     edm::LogWarning("EdalGeom") << "ECalBarrelNumberingScheme::getUnitID(): "
0066                                 << "****************** Bad crystal name = " << cryName
0067                                 << ", Volume Name = " << baseNumber.getLevelName(0);
0068     return 0;
0069   }
0070 
0071   if (1 > wallCopy || 5 < wallCopy) {
0072     edm::LogWarning("EcalGeom") << "ECalBarrelNumberingScheme::getUnitID(): "
0073                                 << "****************** Bad wall copy = " << wallCopy
0074                                 << ", Volume Name = " << baseNumber.getLevelName(3);
0075     return 0;
0076   }
0077 
0078   if (1 > hawCopy || 2 < hawCopy) {
0079     edm::LogWarning("EcalGeom") << "ECalBarrelNumberingScheme::getUnitID(): "
0080                                 << "****************** Bad haw copy = " << hawCopy
0081                                 << ", Volume Name = " << baseNumber.getLevelName(4);
0082     return 0;
0083   }
0084 
0085   if (1 > fawCopy || 10 < fawCopy) {
0086     edm::LogWarning("EcalGeom") << "ECalBarrelNumberingScheme::getUnitID(): "
0087                                 << "****************** Bad faw copy = " << fawCopy
0088                                 << ", Volume Name = " << baseNumber.getLevelName(5);
0089     return 0;
0090   }
0091 
0092   if (1 > supmCopy || 36 < supmCopy) {
0093     edm::LogWarning("EcalGeom") << "ECalBarrelNumberingScheme::getUnitID(): "
0094                                 << "****************** Bad supermodule copy = " << supmCopy
0095                                 << ", Volume Name = " << baseNumber.getLevelName(6);
0096     return 0;
0097   }
0098 
0099   // all inputs are fine. Go ahead and decode
0100 
0101   const int32_t zsign(18 < supmCopy ? -1 : 1);
0102 
0103   const int32_t eta(5 * (cryType - 1) + wallCopy);
0104 
0105   const int32_t phi(18 < supmCopy ? 20 * (supmCopy - 19) + 2 * (10 - fawCopy) + 3 - hawCopy
0106                                   : 20 * (supmCopy - 1) + 2 * (fawCopy - 1) + hawCopy);
0107 
0108   const int32_t intindex(EBDetId(zsign * eta, phi).rawId());
0109 
0110   /*
0111   static int count ( 1 ) ;
0112   if( 0==count%1000 )
0113   {
0114      edm::LogVerbatim("EcalGeom") << "************************** NLEVELS=" << nLevels
0115           << ", eta="<<eta<<", phi=" << phi << ", zsign=" << zsign;
0116   }
0117   ++count;
0118 */
0119 #ifdef EDM_ML_DEBUG
0120   edm::LogVerbatim("EcalGeom") << "EcalBarrelNumberingScheme: "
0121                                << "supmCopy = " << supmCopy << ", fawCopy = " << fawCopy << ", hawCopy = " << hawCopy
0122                                << ", wallCopy = " << wallCopy << ", cryType = " << cryType
0123                                << "\n           zsign = " << zsign << ", eta = " << eta << ", phi = " << phi
0124                                << ", packed index = 0x" << std::hex << intindex << std::dec;
0125 #endif
0126   return intindex;
0127 }
0128 
0129 std::pair<int, int> EcalBarrelNumberingScheme::numbers(const std::string& name) const {
0130   int num1(-1), num2(-1);
0131   if (name.find('#') != std::string::npos) {
0132     uint32_t ip1 = name.find('#');
0133     if (name.find('!') != std::string::npos) {
0134       uint32_t ip2 = name.find('!');
0135       num1 = ::atoi(name.substr(ip1 + 1, ip2 - ip1 - 1).c_str());
0136       if (name.find('#', ip2) != std::string::npos) {
0137         uint32_t ip3 = name.find('#', ip2);
0138         num2 = ::atoi(name.substr(ip3 + 1, name.size() - ip3 - 1).c_str());
0139       }
0140     }
0141   }
0142 #ifdef EDM_ML_DEBUG
0143   edm::LogVerbatim("EcalGeom") << "EcalBarrelNumberingScheme::Numbers from " << name << " are " << num1 << " and "
0144                                << num2;
0145 #endif
0146   return std::make_pair(num1, num2);
0147 }