CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/Geometry/EcalCommonData/src/EcalEndcapNumberingScheme.cc

Go to the documentation of this file.
00001 
00002 // File: EcalEndcapNumberingScheme.cc
00003 // Description: Numbering scheme for endcap electromagnetic calorimeter
00005 #include "Geometry/EcalCommonData/interface/EcalEndcapNumberingScheme.h"
00006 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00007 
00008 #include <iostream>
00009 #include <iomanip>
00010 
00011 EcalEndcapNumberingScheme::EcalEndcapNumberingScheme() : 
00012   EcalNumberingScheme() {
00013   edm::LogInfo("EcalGeom") << "Creating EcalEndcapNumberingScheme";
00014 }
00015 
00016 EcalEndcapNumberingScheme::~EcalEndcapNumberingScheme() {
00017   edm::LogInfo("EcalGeom") << "Deleting EcalEndcapNumberingScheme";
00018 }
00019 uint32_t EcalEndcapNumberingScheme::getUnitID(const EcalBaseNumber& baseNumber) const {
00020 
00021 
00022    const uint32_t nLevels ( baseNumber.getLevels() ) ;
00023 
00024    //LogDebug("EcalGeom") << "ECalEndcapNumberingScheme geometry levels = " << nLevels;
00025   
00026    if( 7 > nLevels )
00027    {
00028       
00029       edm::LogWarning("EcalGeom") << "ECalEndcapNumberingScheme::getUnitID(): "
00030                                   << "Not enough levels found in EcalBaseNumber ( "
00031                                   <<  nLevels 
00032                                   << ") Returning 0" ;
00033       return 0;
00034    }
00035 
00036    if ( nLevels <= 10 ) 
00037    {
00038     
00039   
00040   // Static geometry
00041 
00042 
00043   if (baseNumber.getLevels()<1) {
00044     edm::LogWarning("EcalGeom") << "EalEndcaplNumberingScheme::getUnitID: No "
00045                                 << "level found in EcalBaseNumber Returning 0";
00046     return 0;
00047   }
00048 
00049   int PVid = baseNumber.getCopyNumber(0);
00050   int MVid = 1;
00051   if (baseNumber.getLevels() > 1) 
00052     MVid = baseNumber.getCopyNumber(1);
00053   else 
00054     edm::LogWarning("EcalGeom") << "ECalEndcapNumberingScheme::getUnitID: Null"
00055                                 << " pointer to alveole ! Use default id=1";
00056 
00057   int zside   = baseNumber.getCopyNumber("EREG");
00058   zside=2*(1-zside)+1;
00059   int module_number  = MVid;
00060   int crystal_number  = PVid;
00061 
00062   uint32_t intindex = EEDetId(module_number,crystal_number,zside,EEDetId::SCCRYSTALMODE).rawId();
00063   
00064 //LogDebug("EcalGeom") << "EcalEndcapNumberingScheme: zside = "  << zside 
00065 //                     << " super crystal = " << module_number << " crystal = "
00066 //                     << crystal_number << " packed index = 0x" << std::hex 
00067 //                     << intindex << std::dec;
00068 
00069 
00070   return intindex;
00071    }
00072    else
00073    {
00074       // algorithmic geometry
00075 
00076       const int ic  ( baseNumber.getCopyNumber(0)%100 ) ; // crystal #, 0-44
00077       const int icx ( ic/10 ) ;
00078       const int icy ( ic%5 ) ;
00079       const int is  ( baseNumber.getCopyNumber(2)%100 ) ; // supercrystal #, 0-99
00080       const int isx ( is/10 ) ;
00081       const int isy ( is%10 ) ;
00082 
00083       const int iq  ( 3 - 2*baseNumber.getCopyNumber(3) ) ; // quadrant #, -1, +1
00084       const int id  ( 3 - 2*baseNumber.getCopyNumber(5) ) ; // dee      #, -1, +1
00085 
00086       const int iz  ( 3 - 2*baseNumber.getCopyNumber(7) ) ; // z: -1, +1
00087 
00088       const int ix  ( 50 + id*iz*( 5*isx + icx + 1 ) - ( id*iz - 1 )/2 ) ; // x: 1-100
00089       const int iy  ( 50 + id*iq*( 5*isy + icy + 1 ) - ( id*iq - 1 )/2 ) ; // y: 1-100
00090 
00091       const uint32_t idet ( DetId( DetId::Ecal, EEDetId::Subdet ) | ( ( ( 0<iz ? 0x4000 : 0 ) ) + ( ix<<7 ) + iy ) ) ;
00092 
00093       //*************************** ERROR CHECKING **********************************
00094 
00095       if( 0 > icx ||
00096           4 < icx ||
00097           0 > icy ||
00098           4 < icy    )
00099       {
00100          edm::LogWarning("EdalGeom") << "ECalEndcapNumberingScheme::getUnitID(): "
00101                                      << "****************** Bad crystal number = " << ic 
00102                                      << ", Volume Name = " << baseNumber.getLevelName(0)              ;
00103          return 0 ;
00104       }
00105 
00106       if( 0 > isx ||
00107           9 < isx ||
00108           0 > isy ||
00109           9 < isy    )
00110       {
00111          edm::LogWarning("EdalGeom") << "ECalEndcapNumberingScheme::getUnitID(): "
00112                                      << "****************** Bad supercrystal number = " << is 
00113                                      << ", Volume Name = " << baseNumber.getLevelName(3)              ;
00114          return 0 ;
00115       }
00116 
00117       if( 1  != iq &&
00118           -1 != iq    )
00119       {
00120          edm::LogWarning("EdalGeom") << "ECalEndcapNumberingScheme::getUnitID(): "
00121                                      << "****************** Bad quadrant number = " << iq 
00122                                      << ", Volume Name = " << baseNumber.getLevelName(4)              ;
00123          return 0 ;
00124       }
00125 
00126       if( 1  != id &&
00127           -1 != id    )
00128       {
00129          edm::LogWarning("EdalGeom") << "ECalEndcapNumberingScheme::getUnitID(): "
00130                                      << "****************** Bad dee number = " << id
00131                                      << ", Volume Name = " << baseNumber.getLevelName(6)              ;
00132          return 0 ;
00133       }
00134       
00135       if( -1 != iz &&
00136            1 != iz    )
00137       {
00138          edm::LogWarning("EdalGeom") << "ECalEndcapNumberingScheme::getUnitID(): "
00139                                      << "****************** Bad z-end number = " << iz
00140                                      << ", Volume Name = " << baseNumber.getLevelName(8)              ;
00141          return 0 ;
00142       }
00143 
00144       if( !EEDetId::validDetId( ix, iy, iz ) )
00145       {
00146          edm::LogWarning("EdalGeom") << "ECalEndcapNumberingScheme::getUnitID(): "
00147                                      << "****************** Bad DetId numbers = " 
00148                                      << ix << ", " << iy << ", " << iz               ;
00149          return 0 ;
00150       }
00151 
00152       //*************************************************************************************
00153 /*
00154       edm::LogWarning("EdalGeom") << "ECalEndcapNumberingScheme::getUnitID(): "
00155                                   <<std::dec<< ix << ", " << iy << ", " <<iq << ", " << id << ", " << iz << ", " << std::hex << idet              ;
00156 
00157       edm::LogWarning("EdalGeom") << "ECalEndcapNumberingScheme::EEDetId: "
00158                                   << EEDetId(idet)              ;
00159 */
00160       return idet ;
00161    }
00162 }
00163