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  smearTimeForOOTtails_(pset.getParameter<bool>("SmearTimeForOOTtails")),
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  ScintillatorDecayTimeInv_(1. / ScintillatorDecayTime_),
42  SPTR2_(SinglePhotonTimeResolution_ * SinglePhotonTimeResolution_),
43  DCRxRiseTime_(DarkCountRate_ * ScintillatorRiseTime_),
44  SigmaElectronicNoise2_(SigmaElectronicNoise_ * SigmaElectronicNoise_),
45  SigmaClock2_(SigmaClock_ * SigmaClock_) {}
46 
49  CLHEP::HepRandomEngine* hre) const {
50  MTDSimHitData chargeColl, toa1, toa2;
51 
52  for (MTDSimHitDataAccumulator::const_iterator it = input.begin(); it != input.end(); it++) {
53  // --- Digitize only the in-time bucket:
54  const unsigned int iBX = mtd_digitizer::kInTimeBX;
55 
56  chargeColl.fill(0.f);
57  toa1.fill(0.f);
58  toa2.fill(0.f);
59  for (size_t iside = 0; iside < 2; iside++) {
60  // --- Fluctuate the total number of photo-electrons
61  float Npe = CLHEP::RandPoissonQ::shoot(hre, (it->second).hit_info[2 * iside][iBX]);
62  if (Npe < EnergyThreshold_)
63  continue;
64 
65  // --- Get the time of arrival and add a channel time offset
66  float finalToA1 = (it->second).hit_info[1 + 2 * iside][iBX] + ChannelTimeOffset_;
67 
68  if (smearChannelTimeOffset_ > 0.) {
69  float timeSmearing = CLHEP::RandGaussQ::shoot(hre, 0., smearChannelTimeOffset_);
70  finalToA1 += timeSmearing;
71  }
72 
73  // --- Calculate and add the time walk: the time of arrival is read in correspondence
74  // with two thresholds on the signal pulse
75  std::array<float, 3> times =
77 
78  // --- If the pulse amplitude is smaller than TimeThreshold2, the trigger does not fire
79  if (times[1] == 0.)
80  continue;
81 
82  float finalToA2 = finalToA1 + times[1];
83  finalToA1 += times[0];
84 
85  // --- Estimate the time uncertainty due to photons from earlier OOT hits in the current BTL cell
87  float rate_oot = 0.;
88  // Loop on earlier OOT hits
89  for (int ibx = 0; ibx < mtd_digitizer::kInTimeBX; ++ibx) {
90  if ((it->second).hit_info[2 * iside][ibx] > 0.) {
91  float hit_time = (it->second).hit_info[1 + 2 * iside][ibx] + bxTime_ * (ibx - mtd_digitizer::kInTimeBX);
92  float npe_oot = CLHEP::RandPoissonQ::shoot(hre, (it->second).hit_info[2 * iside][ibx]);
93  rate_oot += npe_oot * exp(hit_time * ScintillatorDecayTimeInv_) * ScintillatorDecayTimeInv_;
94  }
95  } // ibx loop
96 
97  if (rate_oot > 0.) {
98  float sigma_oot = sqrt(rate_oot * ScintillatorRiseTime_) * ScintillatorDecayTime_ / Npe;
99  float smearing_oot = CLHEP::RandGaussQ::shoot(hre, 0., sigma_oot);
100  finalToA1 += smearing_oot;
101  finalToA2 += smearing_oot;
102  }
103  } // if smearTimeForOOTtails_
104 
105  // --- Uncertainty due to the fluctuations of the n-th photon arrival time:
106  if (testBeamMIPTimeRes_ > 0.) {
107  // In this case the time resolution is parametrized from the testbeam.
108  // The same parameterization is used for both thresholds.
109  float sigma = testBeamMIPTimeRes_ / sqrt(Npe);
110  float smearing_stat_thr1 = CLHEP::RandGaussQ::shoot(hre, 0., sigma);
111  float smearing_stat_thr2 = CLHEP::RandGaussQ::shoot(hre, 0., sigma);
112 
113  finalToA1 += smearing_stat_thr1;
114  finalToA2 += smearing_stat_thr2;
115 
116  } else {
117  // In this case the time resolution is taken from the literature.
118  // The fluctuations due to the first TimeThreshold1_ p.e. are common to both times
119  float smearing_stat_thr1 =
120  CLHEP::RandGaussQ::shoot(hre, 0., ScintillatorDecayTime_ * sqrt(sigma2_pe(TimeThreshold1_, Npe)));
121  float smearing_stat_thr2 = CLHEP::RandGaussQ::shoot(
123  finalToA1 += smearing_stat_thr1;
124  finalToA2 += smearing_stat_thr1 + smearing_stat_thr2;
125  }
126 
127  // --- Add in quadrature the uncertainties due to the SiPM timing resolution, the SiPM DCR,
128  // the electronic noise and the clock distribution:
129  float slew2 = ScintillatorDecayTime2_ / Npe / Npe;
130 
131  float sigma2_tot_thr1 =
133  float sigma2_tot_thr2 =
135 
136  // --- Smear the arrival times using the correlated uncertainties:
137  float smearing_thr1_uncorr = CLHEP::RandGaussQ::shoot(hre, 0., sqrt(sigma2_tot_thr1));
138  float smearing_thr2_uncorr = CLHEP::RandGaussQ::shoot(hre, 0., sqrt(sigma2_tot_thr2));
139 
140  finalToA1 += cosPhi_ * smearing_thr1_uncorr + sinPhi_ * smearing_thr2_uncorr;
141  finalToA2 += sinPhi_ * smearing_thr1_uncorr + cosPhi_ * smearing_thr2_uncorr;
142 
143  chargeColl[iside] = Npe * Npe_to_pC_; // the p.e. number is here converted to pC
144 
145  toa1[iside] = finalToA1;
146  toa2[iside] = finalToA2;
147 
148  } // iside loop
149 
150  //run the shaper to create a new data frame
151  BTLDataFrame rawDataFrame(it->first.detid_);
152  runTrivialShaper(rawDataFrame, chargeColl, toa1, toa2, it->first.row_, it->first.column_);
153  updateOutput(output, rawDataFrame);
154 
155  } // MTDSimHitDataAccumulator loop
156 }
157 
159  const mtd::MTDSimHitData& chargeColl,
160  const mtd::MTDSimHitData& toa1,
161  const mtd::MTDSimHitData& toa2,
162  const uint8_t row,
163  const uint8_t col) const {
164  bool debug = debug_;
165 #ifdef EDM_ML_DEBUG
166  for (int it = 0; it < (int)(chargeColl.size()); it++)
167  debug |= (chargeColl[it] > adcThreshold_MIP_);
168 #endif
169 
170  if (debug)
171  edm::LogVerbatim("BTLElectronicsSim") << "[runTrivialShaper]" << std::endl;
172 
173  //set new ADCs
174  for (int it = 0; it < (int)(chargeColl.size()); it++) {
175  BTLSample newSample;
176  newSample.set(false, false, 0, 0, 0, row, col);
177 
178  //brute force saturation, maybe could to better with an exponential like saturation
179  const uint32_t adc = std::min((uint32_t)std::floor(chargeColl[it] / adcLSB_MIP_), adcBitSaturation_);
180  const uint32_t tdc_time1 = std::min((uint32_t)std::floor(toa1[it] / toaLSB_ns_), tdcBitSaturation_);
181  const uint32_t tdc_time2 = std::min((uint32_t)std::floor(toa2[it] / toaLSB_ns_), tdcBitSaturation_);
182 
183  newSample.set(
184  chargeColl[it] > adcThreshold_MIP_, tdc_time1 == tdcBitSaturation_, tdc_time2, tdc_time1, adc, row, col);
185  dataFrame.setSample(it, newSample);
186 
187  if (debug)
188  edm::LogVerbatim("BTLElectronicsSim") << adc << " (" << chargeColl[it] << "/" << adcLSB_MIP_ << ") ";
189  }
190 
191  if (debug) {
192  std::ostringstream msg;
193  dataFrame.print(msg);
194  edm::LogVerbatim("BTLElectronicsSim") << msg.str() << std::endl;
195  }
196 }
197 
198 void BTLElectronicsSim::updateOutput(BTLDigiCollection& coll, const BTLDataFrame& rawDataFrame) const {
199  BTLDataFrame dataFrame(rawDataFrame.id());
200  dataFrame.resize(dfSIZE);
201  bool putInEvent(false);
202  for (int it = 0; it < dfSIZE; ++it) {
203  dataFrame.setSample(it, rawDataFrame[it]);
204  if (it == 0)
205  putInEvent = rawDataFrame[it].threshold();
206  }
207 
208  if (putInEvent) {
209  coll.push_back(dataFrame);
210  }
211 }
212 
213 float BTLElectronicsSim::sigma2_pe(const float& Q, const float& R) const {
214  float OneOverR = 1. / R;
215  float OneOverR2 = OneOverR * OneOverR;
216 
217  // --- This is Eq. (17) from Nucl. Instr. Meth. A 564 (2006) 185
218  float sigma2 = Q * OneOverR2 *
219  (1. + 2. * (Q + 1.) * OneOverR + (Q + 1.) * (6. * Q + 11) * OneOverR2 +
220  (Q + 1.) * (Q + 2.) * (2. * Q + 5.) * OneOverR2 * OneOverR);
221 
222  return sigma2;
223 }
FTLDataFrameT::print
void print(std::ostream &out=std::cout)
Definition: FTLDataFrameT.h:62
FTLDataFrameT::id
const D & id() const
det id
Definition: FTLDataFrameT.h:31
BTLElectronicsSim::smearTimeForOOTtails_
const bool smearTimeForOOTtails_
Definition: BTLElectronicsSim.h:63
BTLElectronicsSim::smearChannelTimeOffset_
const float smearChannelTimeOffset_
Definition: BTLElectronicsSim.h:52
BTLElectronicsSim::updateOutput
void updateOutput(BTLDigiCollection &coll, const BTLDataFrame &rawDataFrame) const
Definition: BTLElectronicsSim.cc:198
BTLSample::set
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
electrons_cff.bool
bool
Definition: electrons_cff.py:393
input
static const std::string input
Definition: EdmProvDump.cc:48
BTLElectronicsSim::SigmaClock2_
const float SigmaClock2_
Definition: BTLElectronicsSim.h:87
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
BTLElectronicsSim::adcThreshold_MIP_
const float adcThreshold_MIP_
Definition: BTLElectronicsSim.h:74
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
min
T min(T a, T b)
Definition: MathUtil.h:58
BTLElectronicsSim::Npe_to_pC_
const float Npe_to_pC_
Definition: BTLElectronicsSim.h:64
MTDShapeBase::timeAtThr
std::array< float, 3 > timeAtThr(const float scale, const float threshold1, const float threshold2) const
Definition: MTDShapeBase.cc:9
cuy.col
col
Definition: cuy.py:1010
BTLElectronicsSim::adcLSB_MIP_
const float adcLSB_MIP_
Definition: BTLElectronicsSim.h:73
BTLElectronicsSim::DCRxRiseTime_
const float DCRxRiseTime_
Definition: BTLElectronicsSim.h:85
BTLElectronicsSim::bxTime_
const float bxTime_
Definition: BTLElectronicsSim.h:47
edm::SortedCollection
Definition: SortedCollection.h:49
BTLElectronicsSim::sinPhi_
const float sinPhi_
Definition: BTLElectronicsSim.h:80
mps_check.msg
tuple msg
Definition: mps_check.py:285
hcalSimParameters_cfi.timeSmearing
timeSmearing
Definition: hcalSimParameters_cfi.py:52
BTLElectronicsSim::runTrivialShaper
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
Definition: BTLElectronicsSim.cc:158
BTLElectronicsSim::cosPhi_
const float cosPhi_
Definition: BTLElectronicsSim.h:79
edm::SortedCollection::push_back
void push_back(T const &t)
Definition: SortedCollection.h:188
class-composition.Q
Q
Definition: class-composition.py:82
BTLElectronicsSim::ScintillatorDecayTimeInv_
const float ScintillatorDecayTimeInv_
Definition: BTLElectronicsSim.h:83
ecalLiteDTU::adc
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
Definition: EcalLiteDTUSample.h:12
debug
#define debug
Definition: HDRShower.cc:19
mtd_digitizer::MTDSimHitData
std::array< MTDSimData_t, nSamples > MTDSimHitData
Definition: MTDDigitizerTypes.h:15
BTLElectronicsSim::dfSIZE
static constexpr int dfSIZE
Definition: BTLElectronicsSim.h:40
BTLElectronicsSim::ScintillatorDecayTime2_
const float ScintillatorDecayTime2_
Definition: BTLElectronicsSim.h:82
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
BTLSample
wrapper for a data word
Definition: BTLSample.h:13
FTLDataFrameT::setSample
void setSample(int i, const S &sample)
Definition: FTLDataFrameT.h:58
BTLElectronicsSim::TimeThreshold2_
const float TimeThreshold2_
Definition: BTLElectronicsSim.h:56
BTLElectronicsSim::Npe_to_V_
const float Npe_to_V_
Definition: BTLElectronicsSim.h:65
BTLElectronicsSim::sigma2_pe
float sigma2_pe(const float &Q, const float &R) const
Definition: BTLElectronicsSim.cc:213
BTLElectronicsSim::toaLSB_ns_
const float toaLSB_ns_
Definition: BTLElectronicsSim.h:75
edm::ParameterSet
Definition: ParameterSet.h:47
BTLElectronicsSim::SigmaElectronicNoise2_
const float SigmaElectronicNoise2_
Definition: BTLElectronicsSim.h:86
BTLElectronicsSim::debug_
const bool debug_
Definition: BTLElectronicsSim.h:45
BTLElectronicsSim::btlPulseShape_
const BTLPulseShape btlPulseShape_
Definition: BTLElectronicsSim.h:89
createfilelist.int
int
Definition: createfilelist.py:10
BTLElectronicsSim::adcBitSaturation_
const uint32_t adcBitSaturation_
Definition: BTLElectronicsSim.h:72
BTLElectronicsSim::BTLElectronicsSim
BTLElectronicsSim(const edm::ParameterSet &pset)
Definition: BTLElectronicsSim.cc:10
std
Definition: JetResolutionObject.h:76
BTLElectronicsSim::EnergyThreshold_
const float EnergyThreshold_
Definition: BTLElectronicsSim.h:54
FTLDataFrameT
Readout digi for HGC.
Definition: FTLDataFrameT.h:14
BTLElectronicsSim::TimeThreshold1_
const float TimeThreshold1_
Definition: BTLElectronicsSim.h:55
FTLDataFrameT::resize
void resize(size_t s)
allow to set size
Definition: FTLDataFrameT.h:51
BTLElectronicsSim::ChannelTimeOffset_
const float ChannelTimeOffset_
Definition: BTLElectronicsSim.h:51
BTLElectronicsSim::ScintillatorRiseTime_
const float ScintillatorRiseTime_
Definition: BTLElectronicsSim.h:49
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
mtd_digitizer::MTDSimHitDataAccumulator
std::unordered_map< MTDCellId, MTDCellInfo > MTDSimHitDataAccumulator
Definition: MTDDigitizerTypes.h:39
BTLElectronicsSim::ReferencePulseNpe_
const float ReferencePulseNpe_
Definition: BTLElectronicsSim.h:57
BTLElectronicsSim::tdcBitSaturation_
const uint32_t tdcBitSaturation_
Definition: BTLElectronicsSim.h:76
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
BTLElectronicsSim.h
mtd_digitizer
Definition: MTDDigitizer.h:35
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
mtd_digitizer::kInTimeBX
constexpr int kInTimeBX
Definition: MTDDigitizerTypes.h:42
BTLElectronicsSim::SPTR2_
const float SPTR2_
Definition: BTLElectronicsSim.h:84
dttmaxenums::R
Definition: DTTMax.h:29
BTLElectronicsSim::run
void run(const mtd::MTDSimHitDataAccumulator &input, BTLDigiCollection &output, CLHEP::HepRandomEngine *hre) const
Definition: BTLElectronicsSim.cc:47
BTLElectronicsSim::ScintillatorDecayTime_
const float ScintillatorDecayTime_
Definition: BTLElectronicsSim.h:50
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
BTLElectronicsSim::testBeamMIPTimeRes_
const float testBeamMIPTimeRes_
Definition: BTLElectronicsSim.h:48