CMS 3D CMS Logo

BTLElectronicsSim.cc
Go to the documentation of this file.
2 
4 
5 #include "CLHEP/Random/RandPoissonQ.h"
6 #include "CLHEP/Random/RandGaussQ.h"
7 
8 
9 using namespace mtd;
10 
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  adcLSB_MIP_( adcSaturation_MIP_/std::pow(2.,adcNbits_) ),
32  adcThreshold_MIP_( pset.getParameter<double>("adcThreshold_MIP") ),
33  toaLSB_ns_( pset.getParameter<double>("toaLSB_ns") ),
34  CorrCoeff_( pset.getParameter<double>("CorrelationCoefficient") ),
35  cosPhi_( 0.5*(sqrt(1.+CorrCoeff_)+sqrt(1.-CorrCoeff_)) ),
36  sinPhi_( 0.5*CorrCoeff_/cosPhi_ ),
37  ScintillatorDecayTime2_(ScintillatorDecayTime_*ScintillatorDecayTime_),
38  SPTR2_(SinglePhotonTimeResolution_*SinglePhotonTimeResolution_),
39  DCRxRiseTime_(DarkCountRate_*ScintillatorRiseTime_),
40  SigmaElectronicNoise2_(SigmaElectronicNoise_*SigmaElectronicNoise_),
41  SigmaClock2_(SigmaClock_*SigmaClock_) {
42 }
43 
44 
47  CLHEP::HepRandomEngine *hre) const {
48 
49  MTDSimHitData chargeColl, toa1, toa2;
50 
51  for(MTDSimHitDataAccumulator::const_iterator it=input.begin();
52  it!=input.end();
53  it++) {
54 
55  chargeColl.fill(0.f);
56  toa1.fill(0.f);
57  toa2.fill(0.f);
58  for(size_t i=0; i<it->second.hit_info[0].size(); i++) {
59 
60  // --- Fluctuate the total number of photo-electrons
61  float Npe = CLHEP::RandPoissonQ::shoot(hre, (it->second).hit_info[0][i]);
62  if ( Npe < EnergyThreshold_ ) continue;
63 
64 
65  // --- Get the time of arrival and add a channel time offset
66  float finalToA1 = (it->second).hit_info[1][i] + ChannelTimeOffset_;
67 
68  if ( smearChannelTimeOffset_ > 0. ){
69  float timeSmearing = CLHEP::RandGaussQ::shoot(hre, 0., smearChannelTimeOffset_);
70  finalToA1 += timeSmearing;
71  }
72 
73 
74  // --- Calculate and add the time walk: the time of arrival is read in correspondence
75  // with two thresholds on the signal pulse
76  std::array<float, 3> times = btlPulseShape_.timeAtThr(Npe/ReferencePulseNpe_,
78  TimeThreshold2_*Npe_to_V_);
79 
80 
81  // --- If the pulse amplitude is smaller than TimeThreshold2, the trigger does not fire
82  if (times[1] == 0.) continue;
83 
84  float finalToA2 = finalToA1 + times[1];
85  finalToA1 += times[0];
86 
87 
88  // --- Uncertainty due to the fluctuations of the n-th photon arrival time:
89  // the fluctuations due to the first TimeThreshold1_ p.e. are common to both times
90  float smearing_stat_thr1 = CLHEP::RandGaussQ::shoot(hre, 0.,
92  float smearing_stat_thr2 = CLHEP::RandGaussQ::shoot(hre, 0.,
94  finalToA1 += smearing_stat_thr1;
95  finalToA2 += smearing_stat_thr1 + smearing_stat_thr2;
96 
97 
98  // --- Add in quadrature the uncertainties due to the SiPM timing resolution, the SiPM DCR,
99  // the electronic noise and the clock distribution:
100  float slew2 = ScintillatorDecayTime2_/Npe/Npe;
101 
102  float sigma2_tot_thr1 = SPTR2_/TimeThreshold1_ + (DCRxRiseTime_ + SigmaElectronicNoise2_)*slew2 + SigmaClock2_;
103  float sigma2_tot_thr2 = SPTR2_/TimeThreshold2_ + (DCRxRiseTime_ + SigmaElectronicNoise2_)*slew2 + SigmaClock2_;
104 
105 
106  // --- Smear the arrival times using the correlated uncertainties:
107  float smearing_thr1_uncorr = CLHEP::RandGaussQ::shoot(hre, 0., sqrt(sigma2_tot_thr1));
108  float smearing_thr2_uncorr = CLHEP::RandGaussQ::shoot(hre, 0., sqrt(sigma2_tot_thr2));
109 
110  finalToA1 += cosPhi_*smearing_thr1_uncorr + sinPhi_*smearing_thr2_uncorr;
111  finalToA2 += sinPhi_*smearing_thr1_uncorr + cosPhi_*smearing_thr2_uncorr;
112 
113 
114  // --- Fill the time and charge arrays
115  const unsigned int ibucket = std::floor( finalToA1/bxTime_ );
116  if ( (i+ibucket) >= chargeColl.size() ) continue;
117 
118  chargeColl[i+ibucket] = Npe*Npe_to_pC_; // the p.e. number is here converted to pC
119 
120  if ( toa1[i+ibucket] == 0. || (finalToA1-ibucket*bxTime_) < toa1[i+ibucket] ){
121  toa1[i+ibucket] = finalToA1 - ibucket*bxTime_;
122  toa2[i+ibucket] = finalToA2 - ibucket*bxTime_;
123  }
124 
125  }
126 
127  //run the shaper to create a new data frame
128  BTLDataFrame rawDataFrame( it->first );
129  runTrivialShaper(rawDataFrame,chargeColl,toa1,toa2);
130  updateOutput(output,rawDataFrame);
131 
132  }
133 
134 }
135 
136 
138  const mtd::MTDSimHitData& chargeColl,
139  const mtd::MTDSimHitData& toa1,
140  const mtd::MTDSimHitData& toa2) const {
141  bool debug = debug_;
142 #ifdef EDM_ML_DEBUG
143  for(int it=0; it<(int)(chargeColl.size()); it++) debug |= (chargeColl[it]>adcThreshold_fC_);
144 #endif
145 
146  if(debug) edm::LogVerbatim("BTLElectronicsSim") << "[runTrivialShaper]" << std::endl;
147 
148  //set new ADCs
149  for(int it=0; it<(int)(chargeColl.size()); it++) {
150 
151  if ( chargeColl[it] == 0. ) continue;
152 
153  //brute force saturation, maybe could to better with an exponential like saturation
154  const uint32_t adc=std::floor( std::min(chargeColl[it],adcSaturation_MIP_) / adcLSB_MIP_ );
155  const uint32_t tdc_time1=std::floor( toa1[it] / toaLSB_ns_ );
156  const uint32_t tdc_time2=std::floor( toa2[it] / toaLSB_ns_ );
157  BTLSample newSample;
158  newSample.set(chargeColl[it] > adcThreshold_MIP_,false,tdc_time2,tdc_time1,adc);
159  dataFrame.setSample(it,newSample);
160 
161  if(debug) edm::LogVerbatim("BTLElectronicsSim") << adc << " ("
162  << chargeColl[it] << "/"
163  << adcLSB_MIP_ << ") ";
164  }
165 
166  if(debug) {
167  std::ostringstream msg;
168  dataFrame.print(msg);
169  edm::LogVerbatim("BTLElectronicsSim") << msg.str() << std::endl;
170  }
171 }
172 
174  const BTLDataFrame& rawDataFrame) const {
175  int itIdx(9);
176  if(rawDataFrame.size()<=itIdx+2) return;
177 
178  BTLDataFrame dataFrame( rawDataFrame.id() );
179  dataFrame.resize(dfSIZE);
180  bool putInEvent(false);
181  for(int it=0;it<dfSIZE; ++it) {
182  dataFrame.setSample(it, rawDataFrame[itIdx-2+it]);
183  if(it==2) putInEvent = rawDataFrame[itIdx-2+it].threshold();
184  }
185 
186  if(putInEvent) {
187  coll.push_back(dataFrame);
188  }
189 }
190 
191 float BTLElectronicsSim::sigma2_pe(const float& Q, const float& R) const {
192 
193  float OneOverR = 1./R;
194  float OneOverR2 = OneOverR*OneOverR;
195 
196  // --- This is Eq. (17) from Nucl. Instr. Meth. A 564 (2006) 185
197  float sigma2 = Q * OneOverR2 * ( 1. + 2.*(Q+1.)*OneOverR +
198  (Q+1.)*(6.*Q+11)*OneOverR2 +
199  (Q+1.)*(Q+2.)*(2.*Q+5.)*OneOverR2*OneOverR );
200 
201  return sigma2;
202 
203 }
204 
205 
206 
int adc(sample_type sample)
get the ADC sample (12 bits)
const float Npe_to_pC_
const float DCRxRiseTime_
const float adcThreshold_MIP_
const float adcSaturation_MIP_
float sigma2_pe(const float &Q, const float &R) const
void print(std::ostream &out=std::cout)
Definition: FTLDataFrameT.h:50
void push_back(T const &t)
const D & id() const
det id
Definition: FTLDataFrameT.h:32
std::array< MTDSimData_t, nSamples > MTDSimHitData
const float TimeThreshold2_
wrapper for a data word
Definition: BTLSample.h:13
const float adcLSB_MIP_
static std::string const input
Definition: EdmProvDump.cc:45
void updateOutput(BTLDigiCollection &coll, const BTLDataFrame &rawDataFrame) const
const float ScintillatorDecayTime2_
const float toaLSB_ns_
const BTLPulseShape btlPulseShape_
void resize(size_t s)
allow to set size
Definition: FTLDataFrameT.h:42
T sqrt(T t)
Definition: SSEVec.h:18
void run(const mtd::MTDSimHitDataAccumulator &input, BTLDigiCollection &output, CLHEP::HepRandomEngine *hre) const
void setSample(int i, const S &sample)
Definition: FTLDataFrameT.h:49
double f[11][100]
T min(T a, T b)
Definition: MathUtil.h:58
BTLElectronicsSim(const edm::ParameterSet &pset)
const float SigmaElectronicNoise2_
void set(bool thr, bool mode, uint16_t toa2, uint16_t toa, uint16_t data)
Definition: BTLSample.h:38
#define debug
Definition: HDRShower.cc:19
JetCorrectorParametersCollection coll
Definition: classes.h:10
const float EnergyThreshold_
int size() const
total number of samples in the digi
Definition: FTLDataFrameT.h:37
tuple msg
Definition: mps_check.py:278
std::array< float, 3 > timeAtThr(const float scale, const float threshold1, const float threshold2) const
Definition: MTDShapeBase.cc:15
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_
const float SigmaClock2_
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
const float ReferencePulseNpe_