Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:32:34

0001 /* class CaloCellManager
0002  *
0003  * Simple eta-phi cell structure manager, mimic calorimetric tower structure
0004  *
0005  *
0006  */
0007 
0008 #include "Validation/EventGenerator/interface/CaloCellManager.h"
0009 
0010 #include "CLHEP/Units/defs.h"
0011 #include "CLHEP/Units/SystemOfUnits.h"
0012 
0013 #include <iomanip>
0014 
0015 CaloCellManager::CaloCellManager(const unsigned int theVerbosity) : verbosity(theVerbosity) {
0016   //initialize constants
0017 
0018   init();
0019 
0020   // build the calo cells identifiers
0021 
0022   builder();
0023 }
0024 
0025 CaloCellManager::~CaloCellManager() {
0026   for (unsigned int i = 0; i < theCellCollection.size(); i++) {
0027     delete theCellCollection[i];
0028   }
0029 }
0030 
0031 void CaloCellManager::init() {
0032   etaLim.reserve(nBarrelEta + nEndcapEta + nForwardEta + 1);
0033   phiLimBar.reserve(nBarrelEta + 1);
0034   phiLimEnd.reserve(nEndcapEta + 1);
0035   phiLimFor.reserve(nForwardEta + 1);
0036 
0037   // Barrel ranges
0038 
0039   double firstEta = 0.;
0040   double etaBarrelBin = 0.087;
0041   for (unsigned int ietabin = 0; ietabin <= nBarrelEta; ietabin++) {
0042     etaLim.push_back(firstEta + ietabin * etaBarrelBin);
0043   }
0044 
0045   double firstPhi = -180.;
0046   double phiBarrelBin = (double)360 / nBarrelPhi;
0047   for (unsigned int iphibin = 0; iphibin <= nBarrelPhi; iphibin++) {
0048     phiLimBar.push_back((firstPhi + iphibin * phiBarrelBin) * CLHEP::degree);
0049   }
0050 
0051   // Endcap ranges (compromise wrt real CMS)
0052 
0053   firstEta = etaBarrelBin * nBarrelEta;
0054   double etaEndcapBin = 0.131;
0055   for (unsigned int ietabin = 1; ietabin <= nEndcapEta; ietabin++) {
0056     etaLim.push_back(firstEta + ietabin * etaEndcapBin);
0057   }
0058   double phiEndcapBin = (double)360 / nEndcapPhi;
0059   for (unsigned int iphibin = 0; iphibin <= nEndcapPhi; iphibin++) {
0060     phiLimEnd.push_back((firstPhi + iphibin * phiEndcapBin) * CLHEP::degree);
0061   }
0062 
0063   // Forward ranges (compromise wrt real CMS)
0064 
0065   etaLim.push_back(3.139);
0066   etaLim.push_back(3.314);
0067   etaLim.push_back(3.489);
0068   etaLim.push_back(3.664);
0069   etaLim.push_back(3.839);
0070   etaLim.push_back(4.013);
0071   etaLim.push_back(4.191);
0072   etaLim.push_back(4.363);
0073   etaLim.push_back(4.538);
0074   etaLim.push_back(4.716);
0075   etaLim.push_back(4.889);
0076   etaLim.push_back(5.191);
0077 
0078   double phiForwardBin = (double)360 / nForwardPhi;
0079   for (unsigned int iphibin = 0; iphibin <= nForwardPhi; iphibin++) {
0080     phiLimFor.push_back((firstPhi + iphibin * phiForwardBin) * CLHEP::degree);
0081   }
0082 
0083   if (verbosity > 0) {
0084     std::cout << "Number of eta ranges = " << nBarrelEta + nEndcapEta + nForwardEta << std::endl;
0085     for (unsigned int i = 0; i < etaLim.size(); i++) {
0086       std::cout << "Eta range limit # " << i << " = " << etaLim[i] << std::endl;
0087     }
0088     for (unsigned int i = 0; i < phiLimBar.size(); i++) {
0089       std::cout << "Phi barrel range limit # " << i << " = " << phiLimBar[i] << std::endl;
0090     }
0091     for (unsigned int i = 0; i < phiLimEnd.size(); i++) {
0092       std::cout << "Phi endcap range limit # " << i << " = " << phiLimEnd[i] << std::endl;
0093     }
0094     for (unsigned int i = 0; i < phiLimFor.size(); i++) {
0095       std::cout << "Phi forward range limit # " << i << " = " << phiLimFor[i] << std::endl;
0096     }
0097   }
0098 }
0099 
0100 void CaloCellManager::builder() {
0101   theCellCollection.reserve(nCaloCell);
0102 
0103   // Barrel
0104 
0105   CaloCellId::System theSys = CaloCellId::Barrel;
0106 
0107   for (unsigned int iphi = 0; iphi < nBarrelPhi; iphi++) {
0108     for (unsigned int ieta = 0; ieta < nBarrelEta; ieta++) {
0109       CaloCellId* thisCell =
0110           new CaloCellId(etaLim[ieta], etaLim[ieta + 1], phiLimBar[iphi], phiLimBar[iphi + 1], theSys);
0111       theCellCollection.push_back(thisCell);
0112     }
0113     for (unsigned int ieta = 0; ieta < nBarrelEta; ieta++) {
0114       CaloCellId* thisCell =
0115           new CaloCellId(-1. * etaLim[ieta + 1], -1. * etaLim[ieta], phiLimBar[iphi], phiLimBar[iphi + 1], theSys);
0116       theCellCollection.push_back(thisCell);
0117     }
0118   }
0119 
0120   // Endcap
0121 
0122   theSys = CaloCellId::Endcap;
0123 
0124   for (unsigned int iphi = 0; iphi < nEndcapPhi; iphi++) {
0125     for (unsigned int ieta = nBarrelEta; ieta < nBarrelEta + nEndcapEta; ieta++) {
0126       CaloCellId* thisCell =
0127           new CaloCellId(etaLim[ieta], etaLim[ieta + 1], phiLimEnd[iphi], phiLimEnd[iphi + 1], theSys);
0128       theCellCollection.push_back(thisCell);
0129     }
0130     for (unsigned int ieta = nBarrelEta; ieta < nBarrelEta + nEndcapEta; ieta++) {
0131       CaloCellId* thisCell =
0132           new CaloCellId(-1. * etaLim[ieta + 1], -1. * etaLim[ieta], phiLimEnd[iphi], phiLimEnd[iphi + 1], theSys);
0133       theCellCollection.push_back(thisCell);
0134     }
0135   }
0136 
0137   // Forward
0138 
0139   theSys = CaloCellId::Forward;
0140 
0141   for (unsigned int iphi = 0; iphi < nForwardPhi; iphi++) {
0142     for (unsigned int ieta = nBarrelEta + nEndcapEta; ieta < nBarrelEta + nEndcapEta + nForwardEta; ieta++) {
0143       CaloCellId* thisCell =
0144           new CaloCellId(etaLim[ieta], etaLim[ieta + 1], phiLimFor[iphi], phiLimFor[iphi + 1], theSys);
0145       theCellCollection.push_back(thisCell);
0146     }
0147     for (unsigned int ieta = nBarrelEta + nEndcapEta; ieta < nBarrelEta + nEndcapEta + nForwardEta; ieta++) {
0148       CaloCellId* thisCell =
0149           new CaloCellId(-1. * etaLim[ieta + 1], -1. * etaLim[ieta], phiLimFor[iphi], phiLimFor[iphi + 1], theSys);
0150       theCellCollection.push_back(thisCell);
0151     }
0152   }
0153 
0154   if (verbosity > 0) {
0155     std::cout << "Number of cells = " << nCaloCell << std::endl;
0156     for (unsigned int i = 0; i < theCellCollection.size(); i++) {
0157       std::cout << "Cell # " << std::setfill(' ') << std::setw(4) << i << " = " << *(theCellCollection[i]) << std::endl;
0158     }
0159   }
0160 }
0161 
0162 unsigned int CaloCellManager::getCellIndexFromAngle(double eta, double phi) {
0163   unsigned int theIndex = 1000000;
0164   for (unsigned int i = 0; i < theCellCollection.size(); i++) {
0165     if (theCellCollection[i]->isInCell(eta, phi)) {
0166       theIndex = i;
0167       continue;
0168     }
0169   }
0170   return theIndex;
0171 }
0172 
0173 CaloCellId* CaloCellManager::getCellFromIndex(unsigned int id) {
0174   if (id < theCellCollection.size()) {
0175     return theCellCollection[id];
0176   }
0177   return nullptr;
0178 }
0179 
0180 std::vector<double> CaloCellManager::getEtaRanges() {
0181   std::vector<double> theEtaRanges(etaLim);
0182   return theEtaRanges;
0183 }