Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:03:39

0001 #include "SimCalorimetry/HcalSimAlgos/interface/HcalShapes.h"
0002 #include "SimCalorimetry/CaloSimAlgos/interface/CaloCachedShapeIntegrator.h"
0003 #include "CondFormats/HcalObjects/interface/HcalMCParam.h"
0004 #include "CondFormats/HcalObjects/interface/HcalMCParams.h"
0005 #include "CondFormats/DataRecord/interface/HcalMCParamsRcd.h"
0006 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0009 
0010 HcalShapes::HcalShapes() : theDbService(nullptr) {
0011   /*
0012          00 - not used (reserved)
0013         101 - regular HPD  HB/HE/HO shape
0014         102 - "special" HB HPD#14 long shape
0015         201 - SiPMs Zecotec shape   (HO)
0016         202 - SiPMs Hamamatsu shape (HO)
0017         203 - SiPMs Hamamatsu shape (HE 2017)
0018     205 - SiPMs from Data (HE data 2017)
0019     206 - SiPMs Hamamatsu shape (HE 2018)
0020     207 - SiPMs from Data (HE 2017)
0021         208 - SiPMs from Data, 2021 MC phase scan
0022         301 - regular HF PMT shape
0023         401 - regular ZDC shape
0024   */
0025 
0026   std::vector<int> theHcalShapeNums = {101, 102, 103, 104, 105, 123, 124, 125, 201, 202, 203, 205, 206, 207, 208, 301};
0027   // use resize so vector won't invalidate pointers by reallocating memory while filling
0028   theHcalShapes.resize(theHcalShapeNums.size());
0029   for (unsigned inum = 0; inum < theHcalShapeNums.size(); ++inum) {
0030     int num = theHcalShapeNums[inum];
0031     theHcalShapes[inum].setShape(num);
0032     theShapesPrecise[num] = &theHcalShapes[inum];
0033     theShapes[num] = new CaloCachedShapeIntegrator(&theHcalShapes[inum]);
0034   }
0035 
0036   // ZDC not yet defined in CalibCalorimetry/HcalAlgos/src/HcalPulseShapes.cc
0037   theShapesPrecise[ZDC] = &theZDCShape;
0038   theShapes[ZDC] = new CaloCachedShapeIntegrator(&theZDCShape);
0039 }
0040 
0041 HcalShapes::~HcalShapes() {
0042   for (auto& shapeItr : theShapes) {
0043     delete shapeItr.second;
0044   }
0045   theShapes.clear();
0046 }
0047 
0048 const CaloVShape* HcalShapes::shape(const DetId& detId, bool precise) const {
0049   if (!theDbService) {
0050     return defaultShape(detId);
0051   }
0052   int shapeType = theDbService->getHcalMCParam(detId)->signalShape();
0053   const auto& myShapes = getShapeMap(precise);
0054   auto shapeMapItr = myShapes.find(shapeType);
0055   if (shapeMapItr == myShapes.end()) {
0056     edm::LogWarning("HcalShapes") << "HcalShapes::shape - shapeType ?  = " << shapeType << std::endl;
0057     return defaultShape(detId, precise);
0058   } else {
0059     return shapeMapItr->second;
0060   }
0061 }
0062 
0063 const CaloVShape* HcalShapes::defaultShape(const DetId& detId, bool precise) const {
0064   // try to figure the appropriate shape
0065   const CaloVShape* result;
0066   const auto& myShapes = getShapeMap(precise);
0067   HcalGenericDetId::HcalGenericSubdetector subdet = HcalGenericDetId(detId).genericSubdet();
0068   if (subdet == HcalGenericDetId::HcalGenBarrel || subdet == HcalGenericDetId::HcalGenEndcap)
0069     result = myShapes.find(HPD)->second;
0070   else if (subdet == HcalGenericDetId::HcalGenOuter)
0071     result = myShapes.find(HPD)->second;
0072   else if (subdet == HcalGenericDetId::HcalGenForward)
0073     result = myShapes.find(HF)->second;
0074   else if (subdet == HcalGenericDetId::HcalGenZDC)
0075     result = myShapes.find(ZDC)->second;
0076   else
0077     result = nullptr;
0078 
0079   edm::LogWarning("HcalShapes") << "Cannot find HCAL MC Params, so the default one is taken for subdet " << subdet;
0080 
0081   return result;
0082 }
0083 
0084 const HcalShapes::ShapeMap& HcalShapes::getShapeMap(bool precise) const {
0085   return precise ? theShapesPrecise : theShapes;
0086 }