Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:49:21

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: EcalEndcapNumberingScheme.cc
0003 // Description: Numbering scheme for endcap electromagnetic calorimeter
0004 ///////////////////////////////////////////////////////////////////////////////
0005 #include "Geometry/EcalCommonData/interface/EcalEndcapNumberingScheme.h"
0006 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0007 
0008 //#define EDM_ML_DEBUG
0009 
0010 EcalEndcapNumberingScheme::EcalEndcapNumberingScheme() : EcalNumberingScheme() {
0011   edm::LogVerbatim("EcalGeom") << "Creating EcalEndcapNumberingScheme";
0012 }
0013 
0014 EcalEndcapNumberingScheme::~EcalEndcapNumberingScheme() {
0015   edm::LogVerbatim("EcalGeom") << "Deleting EcalEndcapNumberingScheme";
0016 }
0017 uint32_t EcalEndcapNumberingScheme::getUnitID(const EcalBaseNumber& baseNumber) const {
0018   const uint32_t nLevels(baseNumber.getLevels());
0019 
0020 #ifdef EDM_ML_DEBUG
0021   edm::LogVerbatim("EcalGeom") << "ECalEndcapNumberingScheme geometry levels = " << nLevels;
0022   for (uint32_t k = 0; k < nLevels; ++k)
0023     edm::LogVerbatim("EcalGeom") << "[" << k << "] " << baseNumber.getLevelName(k) << ":"
0024                                  << baseNumber.getCopyNumber(k);
0025 #endif
0026   if (7 > nLevels) {
0027     edm::LogWarning("EcalGeom") << "ECalEndcapNumberingScheme::getUnitID(): "
0028                                 << "Not enough levels found in EcalBaseNumber ( " << nLevels << ") Returning 0";
0029     return 0;
0030   }
0031 
0032   if (nLevels <= 10) {
0033     // Static geometry
0034 
0035     if (baseNumber.getLevels() < 1) {
0036       edm::LogWarning("EcalGeom") << "EalEndcaplNumberingScheme::getUnitID: No "
0037                                   << "level found in EcalBaseNumber Returning 0";
0038       return 0;
0039     }
0040 
0041     int PVid = baseNumber.getCopyNumber(0);
0042     int MVid = 1;
0043     if (baseNumber.getLevels() > 1)
0044       MVid = baseNumber.getCopyNumber(1);
0045     else
0046       edm::LogWarning("EcalGeom") << "ECalEndcapNumberingScheme::getUnitID: Null"
0047                                   << " pointer to alveole ! Use default id=1";
0048 
0049     int zs = baseNumber.getCopyNumber("EREG");
0050     int zside = 2 * (1 - zs) + 1;
0051     int module_number = MVid;
0052     int crystal_number = PVid;
0053 
0054     uint32_t intindex = EEDetId(module_number, crystal_number, zside, EEDetId::SCCRYSTALMODE).rawId();
0055 
0056 #ifdef EDM_ML_DEBUG
0057     edm::LogVerbatim("EcalGeom") << "EcalEndcapNumberingScheme: zside = " << zs << ":" << zside
0058                                  << " super crystal = " << module_number << " crystal = " << crystal_number
0059                                  << " packed index = 0x" << std::hex << intindex << std::dec;
0060 #endif
0061     return intindex;
0062   } else {
0063     // algorithmic geometry
0064 
0065     const int ic(baseNumber.getCopyNumber(0) % 100);  // crystal #, 0-44
0066     const int icx(ic / 10);
0067     const int icy(ic % 5);
0068     const int is(baseNumber.getCopyNumber(2) % 100);  // supercrystal #, 0-99
0069     const int isx(is / 10);
0070     const int isy(is % 10);
0071 
0072     const int iq(3 - 2 * baseNumber.getCopyNumber(3));  // quadrant #, -1, +1
0073     const int id(3 - 2 * baseNumber.getCopyNumber(5));  // dee      #, -1, +1
0074 
0075     const int iz(3 - 2 * baseNumber.getCopyNumber(7));  // z: -1, +1
0076 
0077     const int ix(50 + id * iz * (5 * isx + icx + 1) - (id * iz - 1) / 2);  // x: 1-100
0078     const int iy(50 + id * iq * (5 * isy + icy + 1) - (id * iq - 1) / 2);  // y: 1-100
0079 
0080     const uint32_t idet(DetId(DetId::Ecal, EEDetId::Subdet) | (((0 < iz ? 0x4000 : 0)) + (ix << 7) + iy));
0081 
0082     //*************************** ERROR CHECKING **********************************
0083 
0084     if (0 > icx || 4 < icx || 0 > icy || 4 < icy) {
0085       edm::LogWarning("EcalGeom") << "ECalEndcapNumberingScheme::getUnitID(): "
0086                                   << "****************** Bad crystal number = " << ic
0087                                   << ", Volume Name = " << baseNumber.getLevelName(0);
0088       return 0;
0089     }
0090 
0091     if (0 > isx || 9 < isx || 0 > isy || 9 < isy) {
0092       edm::LogWarning("EcalGeom") << "ECalEndcapNumberingScheme::getUnitID(): "
0093                                   << "****************** Bad supercrystal number = " << is
0094                                   << ", Volume Name = " << baseNumber.getLevelName(3);
0095       return 0;
0096     }
0097 
0098     if (1 != iq && -1 != iq) {
0099       edm::LogWarning("EcalGeom") << "ECalEndcapNumberingScheme::getUnitID(): "
0100                                   << "****************** Bad quadrant number = " << iq
0101                                   << ", Volume Name = " << baseNumber.getLevelName(4);
0102       return 0;
0103     }
0104 
0105     if (1 != id && -1 != id) {
0106       edm::LogWarning("EcalGeom") << "ECalEndcapNumberingScheme::getUnitID(): "
0107                                   << "****************** Bad dee number = " << id
0108                                   << ", Volume Name = " << baseNumber.getLevelName(6);
0109       return 0;
0110     }
0111 
0112     if (-1 != iz && 1 != iz) {
0113       edm::LogWarning("EcalGeom") << "ECalEndcapNumberingScheme::getUnitID(): "
0114                                   << "****************** Bad z-end number = " << iz
0115                                   << ", Volume Name = " << baseNumber.getLevelName(8);
0116       return 0;
0117     }
0118 
0119     if (!EEDetId::validDetId(ix, iy, iz)) {
0120       edm::LogWarning("EcalGeom") << "ECalEndcapNumberingScheme::getUnitID(): "
0121                                   << "****************** Bad DetId numbers = " << ix << ", " << iy << ", " << iz;
0122       return 0;
0123     }
0124 
0125 #ifdef EDM_ML_DEBUG
0126     edm::LogVerbatim("EcalGeom") << "ECalEndcapNumberingScheme::getUnitID(): " << std::dec << ix << ", " << iy << ", "
0127                                  << iq << ", " << id << ", " << iz << ", " << std::hex << idet << std::dec;
0128     edm::LogVerbatim("EcalGeom") << "ECalEndcapNumberingScheme::EEDetId: " << EEDetId(idet);
0129 #endif
0130     return idet;
0131   }
0132 }