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 using namespace mtd;
9 
11  : debug_(pset.getUntrackedParameter<bool>("debug", false)),
12  bxTime_(pset.getParameter<double>("bxTime")),
13  testBeamMIPTimeRes_(pset.getParameter<double>("TestBeamMIPTimeRes")),
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_) {}
44 
47  CLHEP::HepRandomEngine* hre) const {
48  MTDSimHitData chargeColl, toa1, toa2;
49 
50  for (MTDSimHitDataAccumulator::const_iterator it = input.begin(); it != input.end(); it++) {
51  chargeColl.fill(0.f);
52  toa1.fill(0.f);
53  toa2.fill(0.f);
54  for (size_t i = 0; i < it->second.hit_info[0].size(); i++) {
55  // --- Fluctuate the total number of photo-electrons
56  float Npe = CLHEP::RandPoissonQ::shoot(hre, (it->second).hit_info[0][i]);
57  if (Npe < EnergyThreshold_)
58  continue;
59 
60  // --- Get the time of arrival and add a channel time offset
61  float finalToA1 = (it->second).hit_info[1][i] + ChannelTimeOffset_;
62 
63  if (smearChannelTimeOffset_ > 0.) {
64  float timeSmearing = CLHEP::RandGaussQ::shoot(hre, 0., smearChannelTimeOffset_);
65  finalToA1 += timeSmearing;
66  }
67 
68  // --- Calculate and add the time walk: the time of arrival is read in correspondence
69  // with two thresholds on the signal pulse
70  std::array<float, 3> times =
72 
73  // --- If the pulse amplitude is smaller than TimeThreshold2, the trigger does not fire
74  if (times[1] == 0.)
75  continue;
76 
77  float finalToA2 = finalToA1 + times[1];
78  finalToA1 += times[0];
79 
80  // --- Uncertainty due to the fluctuations of the n-th photon arrival time:
81  if (testBeamMIPTimeRes_ > 0.) {
82  // In this case the time resolution is parametrized from the testbeam.
83  // The same parameterization is used for both thresholds.
84  float sigma = testBeamMIPTimeRes_ / sqrt(Npe);
85  float smearing_stat_thr1 = CLHEP::RandGaussQ::shoot(hre, 0., sigma);
86  float smearing_stat_thr2 = CLHEP::RandGaussQ::shoot(hre, 0., sigma);
87 
88  finalToA1 += smearing_stat_thr1;
89  finalToA2 += smearing_stat_thr2;
90 
91  } else {
92  // In this case the time resolution is taken from the literature.
93  // The fluctuations due to the first TimeThreshold1_ p.e. are common to both times
94  float smearing_stat_thr1 =
95  CLHEP::RandGaussQ::shoot(hre, 0., ScintillatorDecayTime_ * sqrt(sigma2_pe(TimeThreshold1_, Npe)));
96  float smearing_stat_thr2 = CLHEP::RandGaussQ::shoot(
98  finalToA1 += smearing_stat_thr1;
99  finalToA2 += smearing_stat_thr1 + smearing_stat_thr2;
100  }
101 
102  // --- Add in quadrature the uncertainties due to the SiPM timing resolution, the SiPM DCR,
103  // the electronic noise and the clock distribution:
104  float slew2 = ScintillatorDecayTime2_ / Npe / Npe;
105 
106  float sigma2_tot_thr1 =
108  float sigma2_tot_thr2 =
110 
111  // --- Smear the arrival times using the correlated uncertainties:
112  float smearing_thr1_uncorr = CLHEP::RandGaussQ::shoot(hre, 0., sqrt(sigma2_tot_thr1));
113  float smearing_thr2_uncorr = CLHEP::RandGaussQ::shoot(hre, 0., sqrt(sigma2_tot_thr2));
114 
115  finalToA1 += cosPhi_ * smearing_thr1_uncorr + sinPhi_ * smearing_thr2_uncorr;
116  finalToA2 += sinPhi_ * smearing_thr1_uncorr + cosPhi_ * smearing_thr2_uncorr;
117 
118  chargeColl[i] = Npe * Npe_to_pC_; // the p.e. number is here converted to pC
119 
120  toa1[i] = finalToA1;
121  toa2[i] = finalToA2;
122  }
123 
124  //run the shaper to create a new data frame
125  BTLDataFrame rawDataFrame(it->first.detid_);
126  runTrivialShaper(rawDataFrame, chargeColl, toa1, toa2, it->first.row_, it->first.column_);
127  updateOutput(output, rawDataFrame);
128  }
129 }
130 
132  const mtd::MTDSimHitData& chargeColl,
133  const mtd::MTDSimHitData& toa1,
134  const mtd::MTDSimHitData& toa2,
135  const uint8_t row,
136  const uint8_t col) const {
137  bool debug = debug_;
138 #ifdef EDM_ML_DEBUG
139  for (int it = 0; it < (int)(chargeColl.size()); it++)
140  debug |= (chargeColl[it] > adcThreshold_fC_);
141 #endif
142 
143  if (debug)
144  edm::LogVerbatim("BTLElectronicsSim") << "[runTrivialShaper]" << std::endl;
145 
146  //set new ADCs
147  for (int it = 0; it < (int)(chargeColl.size()); it++) {
148  BTLSample newSample;
149  newSample.set(false, false, 0, 0, 0, row, col);
150 
151  //brute force saturation, maybe could to better with an exponential like saturation
152  const uint32_t adc = std::min((uint32_t)std::floor(chargeColl[it] / adcLSB_MIP_), adcBitSaturation_);
153  const uint32_t tdc_time1 = std::min((uint32_t)std::floor(toa1[it] / toaLSB_ns_), tdcBitSaturation_);
154  const uint32_t tdc_time2 = std::min((uint32_t)std::floor(toa2[it] / toaLSB_ns_), tdcBitSaturation_);
155 
156  newSample.set(
157  chargeColl[it] > adcThreshold_MIP_, tdc_time1 == tdcBitSaturation_, tdc_time2, tdc_time1, adc, row, col);
158  dataFrame.setSample(it, newSample);
159 
160  if (debug)
161  edm::LogVerbatim("BTLElectronicsSim") << adc << " (" << chargeColl[it] << "/" << adcLSB_MIP_ << ") ";
162  }
163 
164  if (debug) {
165  std::ostringstream msg;
166  dataFrame.print(msg);
167  edm::LogVerbatim("BTLElectronicsSim") << msg.str() << std::endl;
168  }
169 }
170 
172  BTLDataFrame dataFrame(rawDataFrame.id());
173  dataFrame.resize(dfSIZE);
174  bool putInEvent(false);
175  for (int it = 0; it < dfSIZE; ++it) {
176  dataFrame.setSample(it, rawDataFrame[it]);
177  if (it == 0)
178  putInEvent = rawDataFrame[it].threshold();
179  }
180 
181  if (putInEvent) {
182  coll.push_back(dataFrame);
183  }
184 }
185 
186 float BTLElectronicsSim::sigma2_pe(const float& Q, const float& R) const {
187  float OneOverR = 1. / R;
188  float OneOverR2 = OneOverR * OneOverR;
189 
190  // --- This is Eq. (17) from Nucl. Instr. Meth. A 564 (2006) 185
191  float sigma2 = Q * OneOverR2 *
192  (1. + 2. * (Q + 1.) * OneOverR + (Q + 1.) * (6. * Q + 11) * OneOverR2 +
193  (Q + 1.) * (Q + 2.) * (2. * Q + 5.) * OneOverR2 * OneOverR);
194 
195  return sigma2;
196 }
const float Npe_to_pC_
const float DCRxRiseTime_
const float adcThreshold_MIP_
std::array< MTDSimData_t, nSamples > MTDSimHitData
float sigma2_pe(const float &Q, const float &R) const
void push_back(T const &t)
std::unordered_map< MTDCellId, MTDCellInfo > MTDSimHitDataAccumulator
const float TimeThreshold2_
wrapper for a data word
Definition: BTLSample.h:13
const float adcLSB_MIP_
static std::string const input
Definition: EdmProvDump.cc:48
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:51
T sqrt(T t)
Definition: SSEVec.h:19
void run(const mtd::MTDSimHitDataAccumulator &input, BTLDigiCollection &output, CLHEP::HepRandomEngine *hre) const
const uint32_t adcBitSaturation_
double f[11][100]
void setSample(int i, const S &sample)
Definition: FTLDataFrameT.h:58
T min(T a, T b)
Definition: MathUtil.h:58
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
BTLElectronicsSim(const edm::ParameterSet &pset)
const float SigmaElectronicNoise2_
#define debug
Definition: HDRShower.cc:19
JetCorrectorParametersCollection coll
Definition: classes.h:10
const float EnergyThreshold_
tuple msg
Definition: mps_check.py:285
const uint32_t tdcBitSaturation_
std::array< float, 3 > timeAtThr(const float scale, const float threshold1, const float threshold2) const
Definition: MTDShapeBase.cc:9
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)
Definition: BTLSample.h:37
const float ChannelTimeOffset_
col
Definition: cuy.py:1010
Readout digi for HGC.
Definition: FTLDataFrameT.h:14
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)
Definition: FTLDataFrameT.h:62
const float SigmaClock2_
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
const float ReferencePulseNpe_
const D & id() const
det id
Definition: FTLDataFrameT.h:31