File indexing completed on 2024-04-06 12:29:38
0001 #ifndef _hgcfeelectronics_h_
0002 #define _hgcfeelectronics_h_
0003
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006
0007 #include "CLHEP/Random/RandGauss.h"
0008 #include "CLHEP/Random/RandGaussQ.h"
0009 #include "CLHEP/Random/RandFlat.h"
0010 #include "SimCalorimetry/HGCalSimProducers/interface/HGCDigitizerTypes.h"
0011
0012
0013
0014
0015
0016
0017 namespace hgc = hgc_digi;
0018
0019 namespace hgc_digi {
0020 typedef std::array<float, 6> FEADCPulseShape;
0021 }
0022
0023 template <class DFr>
0024 class HGCFEElectronics {
0025 public:
0026 enum HGCFEElectronicsFirmwareVersion { TRIVIAL, SIMPLE, WITHTOT };
0027 enum HGCFEElectronicsTOTMode { WEIGHTEDBYE, SIMPLETHRESHOLD };
0028
0029
0030
0031
0032 HGCFEElectronics(const edm::ParameterSet& ps);
0033
0034
0035
0036
0037 inline void runShaper(DFr& dataFrame,
0038 hgc::HGCSimHitData& chargeColl,
0039 hgc::HGCSimHitData& toa,
0040 const hgc_digi::FEADCPulseShape& adcPulse,
0041 CLHEP::HepRandomEngine* engine,
0042 uint32_t thrADC = 0,
0043 float lsbADC = -1,
0044 uint32_t gainIdx = 0,
0045 float maxADC = -1,
0046 int thickness = 1,
0047 float tdcOnsetAuto = -1,
0048 float noiseWidth = -1) {
0049 switch (fwVersion_) {
0050 case SIMPLE: {
0051 runSimpleShaper(dataFrame, chargeColl, thrADC, lsbADC, gainIdx, maxADC, adcPulse);
0052 break;
0053 }
0054 case WITHTOT: {
0055 runShaperWithToT(dataFrame,
0056 chargeColl,
0057 toa,
0058 engine,
0059 thrADC,
0060 lsbADC,
0061 gainIdx,
0062 maxADC,
0063 thickness,
0064 tdcOnsetAuto,
0065 noiseWidth,
0066 adcPulse);
0067 break;
0068 }
0069 default: {
0070 runTrivialShaper(dataFrame, chargeColl, thrADC, lsbADC, gainIdx, maxADC);
0071 break;
0072 }
0073 }
0074 }
0075 inline void runShaper(DFr& dataFrame,
0076 hgc::HGCSimHitData& chargeColl,
0077 hgc::HGCSimHitData& toa,
0078 CLHEP::HepRandomEngine* engine,
0079 uint32_t thrADC = 0,
0080 float lsbADC = -1,
0081 uint32_t gainIdx = 0,
0082 float maxADC = -1,
0083 int thickness = 1) {
0084 runShaper(dataFrame, chargeColl, toa, adcPulse_, engine, thrADC, lsbADC, gainIdx, maxADC, thickness);
0085 }
0086
0087 void SetNoiseValues(const std::vector<float>& noise_fC) {
0088 noise_fC_.insert(noise_fC_.end(), noise_fC.begin(), noise_fC.end());
0089 };
0090
0091 void generateTimeOffset(CLHEP::HepRandomEngine* engine) {
0092 for (int i = 0; i < 3; i++)
0093 eventTimeOffset_ns_[i] = CLHEP::RandGaussQ::shoot(engine, 0, jitterConstant_ns_[i]);
0094 };
0095
0096
0097
0098
0099 float getADClsb() { return adcLSB_fC_; }
0100 float getTDClsb() { return tdcLSB_fC_; }
0101 int getTargetMipValue() { return targetMIPvalue_ADC_; }
0102 float getADCThreshold() { return adcThreshold_fC_; }
0103 float getMaxADC() { return adcSaturation_fC_; }
0104 float getMaxTDC() { return tdcSaturation_fC_; }
0105 float getTDCOnset() { return tdcOnset_fC_; }
0106 std::array<float, 3> getTDCForToAOnset() { return tdcForToAOnset_fC_; }
0107 void setADClsb(float newLSB) { adcLSB_fC_ = newLSB; }
0108 void setTDCfsc(float newTDCfsc) {
0109 tdcSaturation_fC_ = newTDCfsc;
0110 tdcLSB_fC_ = tdcSaturation_fC_ / pow(2., tdcNbits_);
0111
0112
0113 tdcSaturation_fC_ *= (1. - 1e-6);
0114 }
0115
0116
0117
0118
0119 void runTrivialShaper(
0120 DFr& dataFrame, hgc::HGCSimHitData& chargeColl, uint32_t thrADC, float lsbADC, uint32_t gainIdx, float maxADC);
0121
0122
0123
0124
0125 void runSimpleShaper(DFr& dataFrame,
0126 hgc::HGCSimHitData& chargeColl,
0127 uint32_t thrADC,
0128 float lsbADC,
0129 uint32_t gainIdx,
0130 float maxADC,
0131 const hgc_digi::FEADCPulseShape& adcPulse);
0132 void runSimpleShaper(
0133 DFr& dataFrame, hgc::HGCSimHitData& chargeColl, uint32_t thrADC, float lsbADC, uint32_t gainIdx, float maxADC) {
0134 runSimpleShaper(dataFrame, chargeColl, thrADC, lsbADC, gainIdx, maxADC, adcPulse_);
0135 }
0136
0137
0138
0139
0140 void runShaperWithToT(DFr& dataFrame,
0141 hgc::HGCSimHitData& chargeColl,
0142 hgc::HGCSimHitData& toa,
0143 CLHEP::HepRandomEngine* engine,
0144 uint32_t thrADC,
0145 float lsbADC,
0146 uint32_t gainIdx,
0147 float maxADC,
0148 int thickness,
0149 float tdcOnsetAuto,
0150 float noiseWidth,
0151 const hgc_digi::FEADCPulseShape& adcPulse);
0152 void runShaperWithToT(DFr& dataFrame,
0153 hgc::HGCSimHitData& chargeColl,
0154 hgc::HGCSimHitData& toa,
0155 CLHEP::HepRandomEngine* engine,
0156 uint32_t thrADC,
0157 float lsbADC,
0158 uint32_t gainIdx,
0159 float maxADC,
0160 int thickness,
0161 float tdcOnsetAuto,
0162 float noiseWidth) {
0163 runShaperWithToT(dataFrame,
0164 chargeColl,
0165 toa,
0166 engine,
0167 thrADC,
0168 lsbADC,
0169 gainIdx,
0170 maxADC,
0171 thickness,
0172 tdcOnsetAuto,
0173 noiseWidth,
0174 adcPulse_);
0175 }
0176
0177
0178
0179
0180 uint32_t toaMode() const { return toaMode_; }
0181
0182
0183
0184
0185 hgc_digi::FEADCPulseShape& getDefaultADCPulse() { return adcPulse_; }
0186
0187
0188
0189
0190 ~HGCFEElectronics() {}
0191
0192 private:
0193
0194 uint32_t fwVersion_;
0195 hgc_digi::FEADCPulseShape adcPulse_, pulseAvgT_;
0196 std::array<float, 3> tdcForToAOnset_fC_;
0197 std::vector<float> tdcChargeDrainParameterisation_;
0198 float adcSaturation_fC_, adcLSB_fC_, tdcLSB_fC_, tdcSaturation_fC_, adcThreshold_fC_, tdcOnset_fC_, toaLSB_ns_,
0199 tdcResolutionInNs_;
0200 uint32_t targetMIPvalue_ADC_;
0201 std::array<float, 3> jitterNoise_ns_, jitterConstant_ns_, eventTimeOffset_ns_;
0202 std::vector<float> noise_fC_;
0203 uint32_t toaMode_;
0204 uint32_t tdcNbits_;
0205 bool thresholdFollowsMIP_;
0206
0207 std::array<bool, hgc::nSamples> busyFlags, totFlags, toaFlags;
0208 hgc::HGCSimHitData newCharge, toaFromToT;
0209 };
0210
0211 #endif