5 #include "CLHEP/Random/RandPoissonQ.h" 6 #include "CLHEP/Random/RandGaussQ.h" 12 debug_( pset.getUntrackedParameter<
bool>(
"debug",
false) ),
13 bxTime_( pset.getParameter<double>(
"bxTime") ),
14 testBeamMIPTimeRes_( pset.getParameter<double>(
"TestBeamMIPTimeRes") ),
15 ScintillatorRiseTime_( pset.getParameter<double>(
"ScintillatorRiseTime") ),
16 ScintillatorDecayTime_( pset.getParameter<double>(
"ScintillatorDecayTime") ),
17 ChannelTimeOffset_( pset.getParameter<double>(
"ChannelTimeOffset") ),
18 smearChannelTimeOffset_( pset.getParameter<double>(
"smearChannelTimeOffset") ),
19 EnergyThreshold_( pset.getParameter<double>(
"EnergyThreshold") ),
20 TimeThreshold1_( pset.getParameter<double>(
"TimeThreshold1") ),
21 TimeThreshold2_( pset.getParameter<double>(
"TimeThreshold2") ),
22 ReferencePulseNpe_( pset.getParameter<double>(
"ReferencePulseNpe") ),
23 SinglePhotonTimeResolution_( pset.getParameter<double>(
"SinglePhotonTimeResolution") ),
24 DarkCountRate_( pset.getParameter<double>(
"DarkCountRate") ),
25 SigmaElectronicNoise_( pset.getParameter<double>(
"SigmaElectronicNoise") ),
26 SigmaClock_( pset.getParameter<double>(
"SigmaClock")),
27 Npe_to_pC_( pset.getParameter<double>(
"Npe_to_pC") ),
28 Npe_to_V_( pset.getParameter<double>(
"Npe_to_V") ),
29 adcNbits_( pset.getParameter<uint32_t>(
"adcNbits") ),
30 tdcNbits_( pset.getParameter<uint32_t>(
"tdcNbits") ),
31 adcSaturation_MIP_( pset.getParameter<double>(
"adcSaturation_MIP") ),
32 adcBitSaturation_(
std::
pow(2,adcNbits_)-1 ),
33 adcLSB_MIP_( adcSaturation_MIP_/adcBitSaturation_ ),
34 adcThreshold_MIP_( pset.getParameter<double>(
"adcThreshold_MIP") ),
35 toaLSB_ns_( pset.getParameter<double>(
"toaLSB_ns") ),
36 tdcBitSaturation_(
std::
pow(2,tdcNbits_)-1 ),
37 CorrCoeff_( pset.getParameter<double>(
"CorrelationCoefficient") ),
38 cosPhi_( 0.5*(
sqrt(1.+CorrCoeff_)+
sqrt(1.-CorrCoeff_)) ),
39 sinPhi_( 0.5*CorrCoeff_/cosPhi_ ),
40 ScintillatorDecayTime2_(ScintillatorDecayTime_*ScintillatorDecayTime_),
41 SPTR2_(SinglePhotonTimeResolution_*SinglePhotonTimeResolution_),
42 DCRxRiseTime_(DarkCountRate_*ScintillatorRiseTime_),
43 SigmaElectronicNoise2_(SigmaElectronicNoise_*SigmaElectronicNoise_),
44 SigmaClock2_(SigmaClock_*SigmaClock_) {
50 CLHEP::HepRandomEngine *hre)
const {
54 for(MTDSimHitDataAccumulator::const_iterator it=input.begin();
61 for(
size_t i=0;
i<it->second.hit_info[0].size();
i++) {
64 float Npe = CLHEP::RandPoissonQ::shoot(hre, (it->second).hit_info[0][
i]);
85 if (times[1] == 0.)
continue;
87 float finalToA2 = finalToA1 + times[1];
88 finalToA1 += times[0];
96 float smearing_stat_thr1 = CLHEP::RandGaussQ::shoot(hre, 0., sigma);
97 float smearing_stat_thr2 = CLHEP::RandGaussQ::shoot(hre, 0., sigma);
99 finalToA1 += smearing_stat_thr1;
100 finalToA2 += smearing_stat_thr2;
106 float smearing_stat_thr1 = CLHEP::RandGaussQ::shoot(hre, 0.,
108 float smearing_stat_thr2 = CLHEP::RandGaussQ::shoot(hre, 0.,
110 finalToA1 += smearing_stat_thr1;
111 finalToA2 += smearing_stat_thr1 + smearing_stat_thr2;
124 float smearing_thr1_uncorr = CLHEP::RandGaussQ::shoot(hre, 0.,
sqrt(sigma2_tot_thr1));
125 float smearing_thr2_uncorr = CLHEP::RandGaussQ::shoot(hre, 0.,
sqrt(sigma2_tot_thr2));
127 finalToA1 +=
cosPhi_*smearing_thr1_uncorr +
sinPhi_*smearing_thr2_uncorr;
128 finalToA2 +=
sinPhi_*smearing_thr1_uncorr +
cosPhi_*smearing_thr2_uncorr;
139 runTrivialShaper(rawDataFrame,chargeColl,toa1,toa2,it->first.row_, it->first.column_);
151 const uint8_t row,
const uint8_t
col)
const {
154 for(
int it=0; it<(
int)(chargeColl.size()); it++) debug |= (chargeColl[it]>adcThreshold_fC_);
157 if(debug)
edm::LogVerbatim(
"BTLElectronicsSim") <<
"[runTrivialShaper]" << std::endl;
160 for(
int it=0; it<(
int)(chargeColl.size()); it++) {
163 newSample.
set(
false,
false,0,0,0,row,col);
171 tdc_time2,tdc_time1,adc,row,col);
175 << chargeColl[it] <<
"/" 180 std::ostringstream
msg;
181 dataFrame.
print(msg);
191 bool putInEvent(
false);
192 for(
int it=0;it<
dfSIZE; ++it) {
193 dataFrame.setSample(it, rawDataFrame[it]);
194 if(it==0) putInEvent = rawDataFrame[it].threshold();
204 float OneOverR = 1./
R;
205 float OneOverR2 = OneOverR*OneOverR;
208 float sigma2 = Q * OneOverR2 * ( 1. + 2.*(Q+1.)*OneOverR +
209 (Q+1.)*(6.*Q+11)*OneOverR2 +
210 (Q+1.)*(Q+2.)*(2.*Q+5.)*OneOverR2*OneOverR );
const float DCRxRiseTime_
const float adcThreshold_MIP_
float sigma2_pe(const float &Q, const float &R) const
void push_back(T const &t)
std::unordered_map< MTDCellId, MTDCellInfo > MTDSimHitDataAccumulator
std::array< MTDSimData_t, nSamples > MTDSimHitData
const float TimeThreshold2_
static std::string const input
void updateOutput(BTLDigiCollection &coll, const BTLDataFrame &rawDataFrame) const
const float ScintillatorDecayTime2_
const BTLPulseShape btlPulseShape_
void resize(size_t s)
allow to set size
void run(const mtd::MTDSimHitDataAccumulator &input, BTLDigiCollection &output, CLHEP::HepRandomEngine *hre) const
const uint32_t adcBitSaturation_
void setSample(int i, const S &sample)
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
BTLElectronicsSim(const edm::ParameterSet &pset)
const float SigmaElectronicNoise2_
const float EnergyThreshold_
const uint32_t tdcBitSaturation_
std::array< float, 3 > timeAtThr(const float scale, const float threshold1, const float threshold2) const
const float ScintillatorDecayTime_
const float TimeThreshold1_
void set(bool thr, bool mode, uint16_t toa2, uint16_t toa, uint16_t data, uint8_t row, uint8_t col)
const float ChannelTimeOffset_
const float testBeamMIPTimeRes_
void runTrivialShaper(BTLDataFrame &dataFrame, const mtd::MTDSimHitData &chargeColl, const mtd::MTDSimHitData &toa1, const mtd::MTDSimHitData &toa2, const uint8_t row, const uint8_t col) const
const float smearChannelTimeOffset_
void print(std::ostream &out=std::cout)
Power< A, B >::type pow(const A &a, const B &b)
const float ReferencePulseNpe_
const D & id() const
det id