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
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 }
0053
0054 class HGCDigitizerBase {
0055 public:
0056 typedef HGCalDataFrame DFr;
0057 typedef edm::SortedCollection<DFr> DColl;
0058
0059
0060
0061
0062 HGCDigitizerBase(const edm::ParameterSet& ps);
0063
0064
0065
0066 void GenerateGaussianNoise(CLHEP::HepRandomEngine* engine, const double NoiseMean, const double NoiseStd);
0067
0068
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
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
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
0098
0099 void updateOutput(std::unique_ptr<DColl>& coll, const DFr& rawDataFrame);
0100
0101
0102
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
0111
0112 virtual ~HGCDigitizerBase(){};
0113
0114 protected:
0115
0116 edm::ParameterSet myCfg_;
0117
0118
0119 float keV2fC_;
0120
0121
0122 std::vector<float> noise_fC_;
0123
0124
0125 std::vector<double> cce_;
0126
0127
0128 bool scaleByDose_;
0129
0130
0131 double scaleByDoseFactor_;
0132
0133
0134 std::string doseMapFile_;
0135
0136
0137 HGCalSiNoiseMap<HGCSiliconDetId> scal_;
0138 HGCalSiNoiseMap<HFNoseDetId> scalHFNose_;
0139
0140
0141 std::unique_ptr<HGCFEElectronics<DFr> > myFEelectronics_;
0142
0143
0144 double bxTime_;
0145
0146
0147 bool doTimeSamples_;
0148
0149
0150 bool thresholdFollowsMIP_;
0151
0152
0153
0154
0155
0156 DetId::Detector det_;
0157
0158
0159
0160
0161 ForwardSubdetector subdet_;
0162
0163
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
0171 bool NoiseGeneration_Method_;
0172 };
0173
0174 #endif