6 #include "CLHEP/Random/RandPoissonQ.h" 7 #include "CLHEP/Random/RandGaussQ.h" 9 #include "Math/ChebyshevPol.h" 15 bxTime_(
pset.getParameter<double>(
"bxTime")),
16 testBeamMIPTimeRes_(
pset.getParameter<double>(
"TestBeamMIPTimeRes")),
17 ScintillatorRiseTime_(
pset.getParameter<double>(
"ScintillatorRiseTime")),
18 ScintillatorDecayTime_(
pset.getParameter<double>(
"ScintillatorDecayTime")),
19 ChannelTimeOffset_(
pset.getParameter<double>(
"ChannelTimeOffset")),
20 smearChannelTimeOffset_(
pset.getParameter<double>(
"smearChannelTimeOffset")),
21 EnergyThreshold_(
pset.getParameter<double>(
"EnergyThreshold")),
22 TimeThreshold1_(
pset.getParameter<double>(
"TimeThreshold1")),
23 TimeThreshold2_(
pset.getParameter<double>(
"TimeThreshold2")),
24 ReferencePulseNpe_(
pset.getParameter<double>(
"ReferencePulseNpe")),
25 SinglePhotonTimeResolution_(
pset.getParameter<double>(
"SinglePhotonTimeResolution")),
26 DarkCountRate_(
pset.getParameter<double>(
"DarkCountRate")),
27 SigmaElectronicNoise_(
pset.getParameter<double>(
"SigmaElectronicNoise")),
28 SigmaClock_(
pset.getParameter<double>(
"SigmaClock")),
29 smearTimeForOOTtails_(
pset.getParameter<
bool>(
"SmearTimeForOOTtails")),
30 Npe_to_pC_(
pset.getParameter<double>(
"Npe_to_pC")),
31 Npe_to_V_(
pset.getParameter<double>(
"Npe_to_V")),
32 sigmaRelTOFHIRenergy_(
pset.getParameter<
std::
vector<double>>(
"SigmaRelTOFHIRenergy")),
33 adcNbits_(
pset.getParameter<uint32_t>(
"adcNbits")),
34 tdcNbits_(
pset.getParameter<uint32_t>(
"tdcNbits")),
35 adcSaturation_MIP_(
pset.getParameter<double>(
"adcSaturation_MIP")),
36 adcBitSaturation_(
std::
pow(2, adcNbits_) - 1),
37 adcLSB_MIP_(adcSaturation_MIP_ / adcBitSaturation_),
38 adcThreshold_MIP_(
pset.getParameter<double>(
"adcThreshold_MIP")),
39 toaLSB_ns_(
pset.getParameter<double>(
"toaLSB_ns")),
40 tdcBitSaturation_(
std::
pow(2, tdcNbits_) - 1),
41 CorrCoeff_(
pset.getParameter<double>(
"CorrelationCoefficient")),
42 cosPhi_(0.5 * (
sqrt(1. + CorrCoeff_) +
sqrt(1. - CorrCoeff_))),
43 sinPhi_(0.5 * CorrCoeff_ / cosPhi_),
44 ScintillatorDecayTime2_(ScintillatorDecayTime_ * ScintillatorDecayTime_),
45 ScintillatorDecayTimeInv_(1. / ScintillatorDecayTime_),
46 SPTR2_(SinglePhotonTimeResolution_ * SinglePhotonTimeResolution_),
47 DCRxRiseTime_(DarkCountRate_ * ScintillatorRiseTime_),
48 SigmaElectronicNoise2_(SigmaElectronicNoise_ * SigmaElectronicNoise_),
49 SigmaClock2_(SigmaClock_ * SigmaClock_) {
51 float lightOutput = 4.2f *
pset.getParameter<
double>(
"LightYield") *
pset.getParameter<
double>(
"LightCollectionEff") *
52 pset.getParameter<
double>(
"PhotonDetectionEff");
58 LogDebug(
"BTLElectronicsSim") <<
" BTL time resolution model (ns, 1 SiPM), for an average light output of " 59 <<
std::fixed << std::setw(14) << lightOutput <<
" N_pe:" 60 <<
"\n sigma stochastic = " << std::setw(14) << s1
61 <<
"\n sigma DCR = " << std::setw(14) << s2
62 <<
"\n sigma electronics = " << std::setw(14) << s3
63 <<
"\n sigma sptr = " << std::setw(14) <<
s4 64 <<
"\n sigma clock = " << std::setw(14) << s5 <<
"\n ---------------------" 65 <<
"\n sigma total = " << std::setw(14)
66 <<
std::sqrt(s1 * s1 + s2 * s2 + s3 * s3 +
s4 *
s4 + s5 * s5);
72 CLHEP::HepRandomEngine* hre)
const {
75 for (MTDSimHitDataAccumulator::const_iterator
it =
input.begin();
it !=
input.end();
it++) {
82 for (
size_t iside = 0; iside < 2; iside++) {
84 float npe = CLHEP::RandPoissonQ::shoot(hre, (
it->second).hit_info[2 * iside][iBX]);
98 std::array<float, 3> times =
105 float finalToA2 = finalToA1 + times[1];
106 finalToA1 += times[0];
113 if ((
it->second).hit_info[2 * iside][ibx] > 0.) {
115 float npe_oot = CLHEP::RandPoissonQ::shoot(hre, (
it->second).hit_info[2 * iside][ibx]);
122 float smearing_oot = CLHEP::RandGaussQ::shoot(hre, 0., sigma_oot);
123 finalToA1 += smearing_oot;
124 finalToA2 += smearing_oot;
133 float smearing_stat_thr1 = CLHEP::RandGaussQ::shoot(hre, 0., sigma);
134 float smearing_stat_thr2 = CLHEP::RandGaussQ::shoot(hre, 0., sigma);
136 finalToA1 += smearing_stat_thr1;
137 finalToA2 += smearing_stat_thr2;
142 float smearing_stat_thr1 =
144 float smearing_stat_thr2 = CLHEP::RandGaussQ::shoot(
146 finalToA1 += smearing_stat_thr1;
147 finalToA2 += smearing_stat_thr1 + smearing_stat_thr2;
156 float smearing_thr1_uncorr = CLHEP::RandGaussQ::shoot(hre, 0.,
sqrt(sigma2_tot_thr1));
157 float smearing_thr2_uncorr = CLHEP::RandGaussQ::shoot(hre, 0.,
sqrt(sigma2_tot_thr2));
159 finalToA1 +=
cosPhi_ * smearing_thr1_uncorr +
sinPhi_ * smearing_thr2_uncorr;
160 finalToA2 +=
sinPhi_ * smearing_thr1_uncorr +
cosPhi_ * smearing_thr2_uncorr;
163 float tofhir_ampnoise_relsigma = ROOT::Math::Chebyshev4(npe,
169 float smearing_tofhir = CLHEP::RandGaussQ::shoot(hre, 0., tofhir_ampnoise_relsigma);
171 chargeColl[iside] = (
it->second).hit_info[2 * iside][iBX] *
Npe_to_pC_ *
172 (1. + smearing_tofhir);
174 toa1[iside] = finalToA1;
175 toa2[iside] = finalToA2;
192 const uint8_t
col)
const {
195 for (
int it = 0;
it < (
int)(chargeColl.size());
it++)
203 for (
int it = 0;
it < (
int)(chargeColl.size());
it++) {
205 newSample.
set(
false,
false, 0, 0, 0, row,
col);
221 std::ostringstream
msg;
230 bool putInEvent(
false);
232 dataFrame.setSample(
it, rawDataFrame[
it]);
234 putInEvent = rawDataFrame[
it].threshold();
243 float OneOverR = 1. /
R;
244 float OneOverR2 = OneOverR * OneOverR;
247 float sigma2 = Q * OneOverR2 *
248 (1. + 2. * (Q + 1.) * OneOverR + (Q + 1.) * (6. * Q + 11) * OneOverR2 +
249 (Q + 1.) * (Q + 2.) * (2. * Q + 5.) * OneOverR2 * OneOverR);
float sigma_stochastic(const float &npe) const
Log< level::Info, true > LogVerbatim
std::array< float, 3 > timeAtThr(const float scale, const float threshold1, const float threshold2) const
const float DCRxRiseTime_
const float adcThreshold_MIP_
std::array< MTDSimData_t, nSamples > MTDSimHitData
const bool smearTimeForOOTtails_
void updateOutput(BTLDigiCollection &coll, const BTLDataFrame &rawDataFrame) const
void push_back(T const &t)
std::unordered_map< MTDCellId, MTDCellInfo > MTDSimHitDataAccumulator
const float ScintillatorDecayTimeInv_
const float TimeThreshold2_
static constexpr int dfSIZE
static std::string const input
const float ScintillatorDecayTime2_
float sigma2_electronics(const float npe) const
const std::vector< double > sigmaRelTOFHIRenergy_
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
float sigma2_pe(const float &Q, const float &R) const
const BTLPulseShape btlPulseShape_
void resize(size_t s)
allow to set size
const D & id() const
det id
const uint32_t adcBitSaturation_
float sigma2_DCR(const float &npe) const
void setSample(int i, const S &sample)
const float SigmaElectronicNoise2_
const float EnergyThreshold_
BTLElectronicsSim(const edm::ParameterSet &pset, edm::ConsumesCollector iC)
const float SinglePhotonTimeResolution_
const uint32_t tdcBitSaturation_
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 ScintillatorRiseTime_
const float testBeamMIPTimeRes_
const float smearChannelTimeOffset_
void print(std::ostream &out=std::cout)
void run(const mtd::MTDSimHitDataAccumulator &input, BTLDigiCollection &output, CLHEP::HepRandomEngine *hre) const
Power< A, B >::type pow(const A &a, const B &b)
uint16_t *__restrict__ uint16_t const *__restrict__ adc
const float ReferencePulseNpe_