Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef SimCalorimetry_HGCSimProducers_hgcdigitizerbase
0002 #define SimCalorimetry_HGCSimProducers_hgcdigitizerbase
0003 
0004 #include <array>
0005 #include <iostream>
0006 #include <vector>
0007 #include <memory>
0008 #include <unordered_map>
0009 #include <unordered_set>
0010 
0011 #include "DataFormats/HGCDigi/interface/HGCDigiCollections.h"
0012 #include "FWCore/Utilities/interface/EDMException.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/Framework/interface/ConsumesCollector.h"
0015 
0016 #include "SimCalorimetry/HGCalSimProducers/interface/HGCDigitizerTypes.h"
0017 
0018 #include "SimCalorimetry/HGCalSimProducers/interface/HGCFEElectronics.h"
0019 
0020 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0021 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0022 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0023 
0024 #include "SimCalorimetry/HGCalSimAlgos/interface/HGCalSiNoiseMap.h"
0025 
0026 namespace hgc = hgc_digi;
0027 
0028 namespace hgc_digi_utils {
0029   using hgc::HGCCellInfo;
0030 
0031   inline void addCellMetadata(HGCCellInfo& info, const HGCalGeometry* geom, const DetId& detid) {
0032     const auto& dddConst = geom->topology().dddConstants();
0033     bool isHalf = (((dddConst.geomMode() == HGCalGeometryMode::Hexagon) ||
0034                     (dddConst.geomMode() == HGCalGeometryMode::HexagonFull))
0035                        ? dddConst.isHalfCell(HGCalDetId(detid).wafer(), HGCalDetId(detid).cell())
0036                        : false);
0037     //base time samples for each DetId, initialized to 0
0038     info.size = (isHalf ? 0.5 : 1.0);
0039     info.thickness = 1 + dddConst.waferType(detid, false);
0040   }
0041 
0042   inline void addCellMetadata(HGCCellInfo& info, const CaloSubdetectorGeometry* geom, const DetId& detid) {
0043     if (DetId::Hcal == detid.det()) {
0044       const HcalGeometry* hc = static_cast<const HcalGeometry*>(geom);
0045       addCellMetadata(info, hc, detid);
0046     } else {
0047       const HGCalGeometry* hg = static_cast<const HGCalGeometry*>(geom);
0048       addCellMetadata(info, hg, detid);
0049     }
0050   }
0051 
0052 }  // namespace hgc_digi_utils
0053 
0054 class HGCDigitizerBase {
0055 public:
0056   typedef HGCalDataFrame DFr;
0057   typedef edm::SortedCollection<DFr> DColl;
0058 
0059   /**
0060      @short CTOR
0061   */
0062   HGCDigitizerBase(const edm::ParameterSet& ps);
0063   /**
0064      @short Gaussian Noise Generation Member Function
0065   */
0066   void GenerateGaussianNoise(CLHEP::HepRandomEngine* engine, const double NoiseMean, const double NoiseStd);
0067   /**
0068     @short steer digitization mode
0069  */
0070   void run(std::unique_ptr<DColl>& digiColl,
0071            hgc::HGCSimHitDataAccumulator& simData,
0072            const CaloSubdetectorGeometry* theGeom,
0073            const std::unordered_set<DetId>& validIds,
0074            uint32_t digitizationType,
0075            CLHEP::HepRandomEngine* engine);
0076 
0077   /**
0078      @short getters
0079   */
0080   float keV2fC() const { return keV2fC_; }
0081   bool toaModeByEnergy() const { return (myFEelectronics_->toaMode() == HGCFEElectronics<DFr>::WEIGHTEDBYE); }
0082   float tdcOnset() const { return myFEelectronics_->getTDCOnset(); }
0083   std::array<float, 3> tdcForToAOnset() const { return myFEelectronics_->getTDCForToAOnset(); }
0084   DetId::Detector det() const { return det_; }
0085   ForwardSubdetector subdet() const { return subdet_; }
0086 
0087   /**
0088      @short a trivial digitization: sum energies and digitize
0089    */
0090   void runSimple(std::unique_ptr<DColl>& coll,
0091                  hgc::HGCSimHitDataAccumulator& simData,
0092                  const CaloSubdetectorGeometry* theGeom,
0093                  const std::unordered_set<DetId>& validIds,
0094                  CLHEP::HepRandomEngine* engine);
0095 
0096   /**
0097      @short prepares the output according to the number of time samples to produce
0098   */
0099   void updateOutput(std::unique_ptr<DColl>& coll, const DFr& rawDataFrame);
0100 
0101   /**
0102      @short to be specialized by top class
0103   */
0104   virtual void runDigitizer(std::unique_ptr<DColl>& coll,
0105                             hgc::HGCSimHitDataAccumulator& simData,
0106                             const CaloSubdetectorGeometry* theGeom,
0107                             const std::unordered_set<DetId>& validIds,
0108                             CLHEP::HepRandomEngine* engine) = 0;
0109   /**
0110      @short DTOR
0111   */
0112   virtual ~HGCDigitizerBase(){};
0113 
0114 protected:
0115   //baseline configuration
0116   edm::ParameterSet myCfg_;
0117 
0118   //1keV in fC
0119   float keV2fC_;
0120 
0121   //noise level (used if scaleByDose=False)
0122   std::vector<float> noise_fC_;
0123 
0124   //charge collection efficiency (used if scaleByDose=False)
0125   std::vector<double> cce_;
0126 
0127   //determines if the dose map should be used instead
0128   bool scaleByDose_;
0129 
0130   //multiplicative fator to scale fluence map
0131   double scaleByDoseFactor_;
0132 
0133   //path to dose map
0134   std::string doseMapFile_;
0135 
0136   //noise maps (used if scaleByDose=True)
0137   HGCalSiNoiseMap<HGCSiliconDetId> scal_;
0138   HGCalSiNoiseMap<HFNoseDetId> scalHFNose_;
0139 
0140   //front-end electronics model
0141   std::unique_ptr<HGCFEElectronics<DFr> > myFEelectronics_;
0142 
0143   //bunch time
0144   double bxTime_;
0145 
0146   //if true will put both in time and out-of-time samples in the event
0147   bool doTimeSamples_;
0148 
0149   //if set to true, threshold will be computed based on the expected meap peak/2
0150   bool thresholdFollowsMIP_;
0151 
0152   // Identify the detector components, i.e. DetIds, that will be managed by
0153   // this digitizer. This information will be used to fetch the correct
0154   // geometry and the full list of detids for which a digitization is
0155   // requested.
0156   DetId::Detector det_;
0157 
0158   // Identify the subdetector components that will be managed by this
0159   // digitizer. This information will be used to fetch the correct geometry and
0160   // the full list of detids for which a digitization is requested.
0161   ForwardSubdetector subdet_;
0162 
0163   // New NoiseArray Parameters
0164 
0165   const double NoiseMean_, NoiseStd_;
0166   static const size_t NoiseArrayLength_ = 200000;
0167   static const size_t samplesize_ = 15;
0168   std::array<std::array<double, samplesize_>, NoiseArrayLength_> GaussianNoiseArray_;
0169   bool RandNoiseGenerationFlag_;
0170   // A parameter configurable from python configuration to decide which noise generation model to use
0171   bool NoiseGeneration_Method_;
0172 };
0173 
0174 #endif