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 ScintillatorRiseTime_( pset.getParameter<double>(
"ScintillatorRiseTime") ),
15 ScintillatorDecayTime_( pset.getParameter<double>(
"ScintillatorDecayTime") ),
16 ChannelTimeOffset_( pset.getParameter<double>(
"ChannelTimeOffset") ),
17 smearChannelTimeOffset_( pset.getParameter<double>(
"smearChannelTimeOffset") ),
18 EnergyThreshold_( pset.getParameter<double>(
"EnergyThreshold") ),
19 TimeThreshold1_( pset.getParameter<double>(
"TimeThreshold1") ),
20 TimeThreshold2_( pset.getParameter<double>(
"TimeThreshold2") ),
21 ReferencePulseNpe_( pset.getParameter<double>(
"ReferencePulseNpe") ),
22 SinglePhotonTimeResolution_( pset.getParameter<double>(
"SinglePhotonTimeResolution") ),
23 DarkCountRate_( pset.getParameter<double>(
"DarkCountRate") ),
24 SigmaElectronicNoise_( pset.getParameter<double>(
"SigmaElectronicNoise") ),
25 SigmaClock_( pset.getParameter<double>(
"SigmaClock")),
26 Npe_to_pC_( pset.getParameter<double>(
"Npe_to_pC") ),
27 Npe_to_V_( pset.getParameter<double>(
"Npe_to_V") ),
28 adcNbits_( pset.getParameter<uint32_t>(
"adcNbits") ),
29 tdcNbits_( pset.getParameter<uint32_t>(
"tdcNbits") ),
30 adcSaturation_MIP_( pset.getParameter<double>(
"adcSaturation_MIP") ),
31 adcBitSaturation_(
std::
pow(2,adcNbits_)-1 ),
32 adcLSB_MIP_( adcSaturation_MIP_/adcBitSaturation_ ),
33 adcThreshold_MIP_( pset.getParameter<double>(
"adcThreshold_MIP") ),
34 toaLSB_ns_( pset.getParameter<double>(
"toaLSB_ns") ),
35 tdcBitSaturation_(
std::
pow(2,tdcNbits_)-1 ),
36 CorrCoeff_( pset.getParameter<double>(
"CorrelationCoefficient") ),
37 cosPhi_( 0.5*(
sqrt(1.+CorrCoeff_)+
sqrt(1.-CorrCoeff_)) ),
38 sinPhi_( 0.5*CorrCoeff_/cosPhi_ ),
39 ScintillatorDecayTime2_(ScintillatorDecayTime_*ScintillatorDecayTime_),
40 SPTR2_(SinglePhotonTimeResolution_*SinglePhotonTimeResolution_),
41 DCRxRiseTime_(DarkCountRate_*ScintillatorRiseTime_),
42 SigmaElectronicNoise2_(SigmaElectronicNoise_*SigmaElectronicNoise_),
43 SigmaClock2_(SigmaClock_*SigmaClock_) {
49 CLHEP::HepRandomEngine *hre)
const {
53 for(MTDSimHitDataAccumulator::const_iterator it=input.begin();
60 for(
size_t i=0;
i<it->second.hit_info[0].size();
i++) {
63 float Npe = CLHEP::RandPoissonQ::shoot(hre, (it->second).hit_info[0][
i]);
84 if (times[1] == 0.)
continue;
86 float finalToA2 = finalToA1 + times[1];
87 finalToA1 += times[0];
92 float smearing_stat_thr1 = CLHEP::RandGaussQ::shoot(hre, 0.,
94 float smearing_stat_thr2 = CLHEP::RandGaussQ::shoot(hre, 0.,
96 finalToA1 += smearing_stat_thr1;
97 finalToA2 += smearing_stat_thr1 + smearing_stat_thr2;
109 float smearing_thr1_uncorr = CLHEP::RandGaussQ::shoot(hre, 0.,
sqrt(sigma2_tot_thr1));
110 float smearing_thr2_uncorr = CLHEP::RandGaussQ::shoot(hre, 0.,
sqrt(sigma2_tot_thr2));
112 finalToA1 +=
cosPhi_*smearing_thr1_uncorr +
sinPhi_*smearing_thr2_uncorr;
113 finalToA2 +=
sinPhi_*smearing_thr1_uncorr +
cosPhi_*smearing_thr2_uncorr;
117 const unsigned int ibucket = std::floor( finalToA1/
bxTime_ );
118 if ( (
i+ibucket) >= chargeColl.size() )
continue;
122 if ( toa1[
i+ibucket] == 0. || (finalToA1-ibucket*
bxTime_) < toa1[
i+ibucket] ){
123 toa1[
i+ibucket] = finalToA1 - ibucket*
bxTime_;
124 toa2[
i+ibucket] = finalToA2 - ibucket*
bxTime_;
145 for(
int it=0; it<(
int)(chargeColl.size()); it++) debug |= (chargeColl[it]>adcThreshold_fC_);
148 if(debug)
edm::LogVerbatim(
"BTLElectronicsSim") <<
"[runTrivialShaper]" << std::endl;
151 for(
int it=0; it<(
int)(chargeColl.size()); it++) {
163 << chargeColl[it] <<
"/" 168 std::ostringstream
msg;
169 dataFrame.
print(msg);
177 if(rawDataFrame.
size()<=itIdx+2)
return;
181 bool putInEvent(
false);
182 for(
int it=0;it<
dfSIZE; ++it) {
183 dataFrame.setSample(it, rawDataFrame[itIdx-2+it]);
184 if(it==2) putInEvent = rawDataFrame[itIdx-2+it].threshold();
194 float OneOverR = 1./
R;
195 float OneOverR2 = OneOverR*OneOverR;
198 float sigma2 = Q * OneOverR2 * ( 1. + 2.*(Q+1.)*OneOverR +
199 (Q+1.)*(6.*Q+11)*OneOverR2 +
200 (Q+1.)*(Q+2.)*(2.*Q+5.)*OneOverR2*OneOverR );
int adc(sample_type sample)
get the ADC sample (12 bits)
const float DCRxRiseTime_
const float adcThreshold_MIP_
float sigma2_pe(const float &Q, const float &R) const
void print(std::ostream &out=std::cout)
void push_back(T const &t)
const D & id() const
det id
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
void setSample(int i, const S &sample)
const uint32_t adcBitSaturation_
BTLElectronicsSim(const edm::ParameterSet &pset)
const float SigmaElectronicNoise2_
void set(bool thr, bool mode, uint16_t toa2, uint16_t toa, uint16_t data)
const float EnergyThreshold_
int size() const
total number of samples in the digi
const uint32_t tdcBitSaturation_
std::array< float, 3 > timeAtThr(const float scale, const float threshold1, const float threshold2) const
const float ScintillatorDecayTime_
std::unordered_map< uint32_t, MTDCellInfo > MTDSimHitDataAccumulator
const float TimeThreshold1_
const float ChannelTimeOffset_
void runTrivialShaper(BTLDataFrame &dataFrame, const mtd::MTDSimHitData &chargeColl, const mtd::MTDSimHitData &toa1, const mtd::MTDSimHitData &toa2) const
const float smearChannelTimeOffset_
Power< A, B >::type pow(const A &a, const B &b)
const float ReferencePulseNpe_