CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/Validation/EventGenerator/src/CaloCellManager.cc

Go to the documentation of this file.
00001 /* class CaloCellManager
00002  *
00003  * Simple eta-phi cell structure manager, mimic calorimetric tower structure
00004  *
00005  * $Date: 2010/05/25 16:50:51 $
00006  * $Revision: 1.1 $
00007  *
00008  */
00009 
00010 #include "Validation/EventGenerator/interface/CaloCellManager.h"
00011 
00012 #include "CLHEP/Units/defs.h"
00013 #include "CLHEP/Units/SystemOfUnits.h"
00014 
00015 #include <iomanip>
00016 
00017 CaloCellManager::CaloCellManager(const unsigned int theVerbosity):
00018   verbosity(theVerbosity)
00019 {
00020 
00021   //initialize constants
00022 
00023   init();
00024 
00025   // build the calo cells identifiers
00026 
00027   builder();
00028 
00029 }
00030 
00031 CaloCellManager::~CaloCellManager(){
00032 
00033   for (unsigned int i = 0; i < theCellCollection.size(); i++) {
00034     delete theCellCollection[i];
00035   }
00036 
00037 }
00038 
00039 void CaloCellManager::init(){
00040 
00041   etaLim.reserve(nBarrelEta+nEndcapEta+nForwardEta+1);
00042   phiLimBar.reserve(nBarrelEta+1);
00043   phiLimEnd.reserve(nEndcapEta+1);
00044   phiLimFor.reserve(nForwardEta+1);
00045 
00046   // Barrel ranges
00047 
00048   double firstEta = 0.;
00049   double etaBarrelBin = 0.087;
00050   for (unsigned int ietabin = 0; ietabin <= nBarrelEta; ietabin++) {
00051     etaLim.push_back(firstEta+ietabin*etaBarrelBin);
00052   }
00053 
00054   double firstPhi = -180.;
00055   double phiBarrelBin = (double)360/nBarrelPhi;
00056   for (unsigned int iphibin = 0; iphibin <= nBarrelPhi; iphibin++) {
00057     phiLimBar.push_back((firstPhi+iphibin*phiBarrelBin)*CLHEP::degree);
00058   }
00059 
00060   // Endcap ranges (compromise wrt real CMS)
00061 
00062   firstEta = etaBarrelBin*nBarrelEta;
00063   double etaEndcapBin = 0.131;
00064   for (unsigned int ietabin = 1; ietabin <= nEndcapEta; ietabin++) {
00065     etaLim.push_back(firstEta+ietabin*etaEndcapBin);
00066   }
00067   double phiEndcapBin = (double)360/nEndcapPhi;
00068   for (unsigned int iphibin = 0; iphibin <= nEndcapPhi; iphibin++) {
00069     phiLimEnd.push_back((firstPhi+iphibin*phiEndcapBin)*CLHEP::degree);
00070   }
00071   
00072   // Forward ranges (compromise wrt real CMS)
00073 
00074   etaLim.push_back(3.139);
00075   etaLim.push_back(3.314);
00076   etaLim.push_back(3.489);
00077   etaLim.push_back(3.664);
00078   etaLim.push_back(3.839);
00079   etaLim.push_back(4.013);
00080   etaLim.push_back(4.191);
00081   etaLim.push_back(4.363);
00082   etaLim.push_back(4.538);
00083   etaLim.push_back(4.716);
00084   etaLim.push_back(4.889);
00085   etaLim.push_back(5.191);
00086 
00087   double phiForwardBin = (double)360/nForwardPhi;
00088   for (unsigned int iphibin = 0; iphibin <= nForwardPhi; iphibin++) {
00089     phiLimFor.push_back((firstPhi+iphibin*phiForwardBin)*CLHEP::degree);
00090   }
00091 
00092   if ( verbosity > 0 ) {
00093     std::cout << "Number of eta ranges = " << nBarrelEta+nEndcapEta+nForwardEta << std::endl;
00094     for (unsigned int i = 0; i < etaLim.size(); i++) {
00095       std::cout << "Eta range limit # " << i << " = " << etaLim[i] << std::endl;
00096     }
00097     for (unsigned int i = 0; i < phiLimBar.size(); i++) {
00098       std::cout << "Phi barrel range limit # " << i << " = " << phiLimBar[i] << std::endl;
00099     }
00100     for (unsigned int i = 0; i < phiLimEnd.size(); i++) {
00101       std::cout << "Phi endcap range limit # " << i << " = " << phiLimEnd[i] << std::endl;
00102     }
00103     for (unsigned int i = 0; i < phiLimFor.size(); i++) {
00104       std::cout << "Phi forward range limit # " << i << " = " << phiLimFor[i] << std::endl;
00105     }
00106   }
00107 
00108 }
00109 
00110 void CaloCellManager::builder(){
00111 
00112   theCellCollection.reserve(nCaloCell);
00113 
00114   // Barrel
00115 
00116   CaloCellId::System theSys = CaloCellId::Barrel;
00117 
00118   for (unsigned int iphi = 0; iphi < nBarrelPhi; iphi++) {
00119     for (unsigned int ieta = 0; ieta < nBarrelEta; ieta++) {
00120       CaloCellId* thisCell = new CaloCellId(etaLim[ieta],etaLim[ieta+1],phiLimBar[iphi],phiLimBar[iphi+1],theSys);
00121       theCellCollection.push_back(thisCell);
00122     }
00123     for (unsigned int ieta = 0; ieta < nBarrelEta; ieta++) {
00124       CaloCellId* thisCell = new CaloCellId(-1.*etaLim[ieta+1],-1.*etaLim[ieta],phiLimBar[iphi],phiLimBar[iphi+1],theSys);
00125       theCellCollection.push_back(thisCell);
00126     }
00127   }
00128 
00129   // Endcap
00130 
00131   theSys = CaloCellId::Endcap;
00132 
00133   for (unsigned int iphi = 0; iphi < nEndcapPhi; iphi++) {
00134     for (unsigned int ieta = nBarrelEta; ieta < nBarrelEta+nEndcapEta; ieta++) {
00135       CaloCellId* thisCell = new CaloCellId(etaLim[ieta],etaLim[ieta+1],phiLimEnd[iphi],phiLimEnd[iphi+1],theSys);
00136       theCellCollection.push_back(thisCell);
00137     }
00138     for (unsigned int ieta = nBarrelEta; ieta < nBarrelEta+nEndcapEta; ieta++) {
00139       CaloCellId* thisCell = new CaloCellId(-1.*etaLim[ieta+1],-1.*etaLim[ieta],phiLimEnd[iphi],phiLimEnd[iphi+1],theSys);
00140       theCellCollection.push_back(thisCell);
00141     }
00142   }
00143   
00144   // Forward
00145 
00146   theSys = CaloCellId::Forward;
00147 
00148   for (unsigned int iphi = 0; iphi < nForwardPhi; iphi++) {
00149     for (unsigned int ieta = nBarrelEta+nEndcapEta; ieta < nBarrelEta+nEndcapEta+nForwardEta; ieta++) {
00150       CaloCellId* thisCell = new CaloCellId(etaLim[ieta],etaLim[ieta+1],phiLimFor[iphi],phiLimFor[iphi+1],theSys);
00151       theCellCollection.push_back(thisCell);
00152     }
00153     for (unsigned int ieta = nBarrelEta+nEndcapEta; ieta < nBarrelEta+nEndcapEta+nForwardEta; ieta++) {
00154       CaloCellId* thisCell = new CaloCellId(-1.*etaLim[ieta+1],-1.*etaLim[ieta],phiLimFor[iphi],phiLimFor[iphi+1],theSys);
00155       theCellCollection.push_back(thisCell);
00156     }
00157   }
00158 
00159   if ( verbosity > 0 ) {
00160     std::cout << "Number of cells = " << nCaloCell << std::endl;
00161     for (unsigned int i = 0; i < theCellCollection.size(); i++) {
00162       std::cout << "Cell # " << std::setfill(' ') << std::setw(4) << i << " = " << *(theCellCollection[i]) << std::endl;
00163     }
00164   }
00165 
00166 }
00167 
00168 unsigned int CaloCellManager::getCellIndexFromAngle(double eta, double phi){
00169 
00170   unsigned int theIndex = 1000000;
00171   for ( unsigned int i = 0; i < theCellCollection.size(); i++) {
00172     if ( theCellCollection[i]->isInCell(eta, phi) ) { theIndex = i; continue; }
00173   }
00174   return theIndex;
00175 
00176 }
00177 
00178 CaloCellId* CaloCellManager::getCellFromIndex(unsigned int id){
00179 
00180   if ( id < theCellCollection.size() ) { return theCellCollection[id]; }
00181   return NULL; 
00182 
00183 }
00184 
00185 std::vector<double> CaloCellManager::getEtaRanges(){
00186 
00187   std::vector<double> theEtaRanges(etaLim); 
00188   return theEtaRanges;
00189 
00190 }