6 #include "vdt/vdtMath.h" 17 adcSaturation_fC_{-1.0},
20 tdcSaturation_fC_{-1.0},
24 tdcResolutionInNs_{1
e-9},
25 targetMIPvalue_ADC_{},
27 jitterConstant2_ns_{},
29 toaMode_(WEIGHTEDBYE) {
30 edm::LogVerbatim(
"HGCFE") <<
"[HGCFEElectronics] running with version " << fwVersion_ << std::endl;
31 if (ps.exists(
"adcPulse")) {
32 auto temp = ps.getParameter<std::vector<double> >(
"adcPulse");
33 for (
unsigned i = 0;
i <
temp.size(); ++
i) {
37 for (
unsigned i = 0;
i < adcPulse_.size(); ++
i) {
38 adcPulse_[
i] = adcPulse_[
i] / adcPulse_[2];
40 temp = ps.getParameter<std::vector<double> >(
"pulseAvgT");
41 for (
unsigned i = 0;
i <
temp.size(); ++
i) {
45 if (ps.exists(
"adcNbits")) {
46 uint32_t
adcNbits = ps.getParameter<uint32_t>(
"adcNbits");
47 adcSaturation_fC_ = ps.getParameter<
double>(
"adcSaturation_fC");
50 <<
" with LSB=" << adcLSB_fC_ <<
" saturation to occur @ " << adcSaturation_fC_
54 if (ps.exists(
"tdcNbits")) {
55 tdcNbits_ = ps.getParameter<uint32_t>(
"tdcNbits");
56 setTDCfsc(ps.getParameter<
double>(
"tdcSaturation_fC"));
57 edm::LogVerbatim(
"HGCFE") <<
"[HGCFEElectronics] " << tdcNbits_ <<
" bit TDC defined with LSB=" << tdcLSB_fC_
58 <<
" saturation to occur @ " << tdcSaturation_fC_
59 <<
" (NB lowered by 1 part in a million)" << std::endl;
61 if (ps.exists(
"targetMIPvalue_ADC"))
62 targetMIPvalue_ADC_ = ps.getParameter<uint32_t>(
"targetMIPvalue_ADC");
63 if (ps.exists(
"adcThreshold_fC"))
64 adcThreshold_fC_ = ps.getParameter<
double>(
"adcThreshold_fC");
65 if (ps.exists(
"tdcOnset_fC"))
66 tdcOnset_fC_ = ps.getParameter<
double>(
"tdcOnset_fC");
67 if (ps.exists(
"tdcForToAOnset_fC")) {
68 auto temp = ps.getParameter<std::vector<double> >(
"tdcForToAOnset_fC");
69 if (
temp.size() == tdcForToAOnset_fC_.size()) {
70 std::copy_n(
temp.begin(),
temp.size(), tdcForToAOnset_fC_.begin());
72 throw cms::Exception(
"BadConfiguration") <<
" HGCFEElectronics wrong size for ToA thresholds ";
75 if (ps.exists(
"toaLSB_ns"))
76 toaLSB_ns_ = ps.getParameter<
double>(
"toaLSB_ns");
77 if (ps.exists(
"tdcChargeDrainParameterisation")) {
78 for (
auto val : ps.getParameter<std::vector<double> >(
"tdcChargeDrainParameterisation")) {
79 tdcChargeDrainParameterisation_.push_back((
float)
val);
82 if (ps.exists(
"tdcResolutionInPs"))
83 tdcResolutionInNs_ = ps.getParameter<
double>(
"tdcResolutionInPs") * 1
e-3;
84 if (ps.exists(
"toaMode"))
85 toaMode_ = ps.getParameter<uint32_t>(
"toaMode");
87 if (ps.exists(
"jitterNoise_ns")) {
88 auto temp = ps.getParameter<std::vector<double> >(
"jitterNoise_ns");
89 if (
temp.size() == jitterNoise2_ns_.size()) {
90 std::copy_n(
temp.begin(),
temp.size(), jitterNoise2_ns_.begin());
92 throw cms::Exception(
"BadConfiguration") <<
" HGCFEElectronics wrong size for ToA jitterNoise ";
95 if (ps.exists(
"jitterConstant_ns")) {
96 auto temp = ps.getParameter<std::vector<double> >(
"jitterConstant_ns");
97 if (
temp.size() == jitterConstant2_ns_.size()) {
98 std::copy_n(
temp.begin(),
temp.size(), jitterConstant2_ns_.begin());
100 throw cms::Exception(
"BadConfiguration") <<
" HGCFEElectronics wrong size for ToA jitterConstant ";
108 DFr& dataFrame,
HGCSimHitData& chargeColl, uint32_t thrADC,
float lsbADC, uint32_t gainIdx,
float maxADC) {
112 for (
int it = 0; it < (
int)(chargeColl.size()); it++)
113 debug |= (chargeColl[it] > adcThreshold_fC_);
125 maxADC = adcSaturation_fC_ * (1 - 1
e-6);
126 for (
int it = 0; it < (
int)(chargeColl.size()); it++) {
128 const uint32_t
adc = std::floor(
std::min(chargeColl[it], maxADC) / lsbADC);
130 newSample.
set(
adc > thrADC,
false, gainIdx, 0,
adc);
131 dataFrame.setSample(it, newSample);
138 std::ostringstream
msg;
139 dataFrame.print(
msg);
156 for (
int it = 0; it < (
int)(chargeColl.size()); it++) {
157 const float charge(chargeColl[it]);
168 for (
int ipulse = -2; ipulse < (
int)(
adcPulse.size()) - 2; ipulse++) {
171 if (it + ipulse >= (
int)(dataFrame.size()))
174 newCharge[it + ipulse] += chargeLeak;
184 for (
int it = 0; it < (
int)(newCharge.size()); it++) {
186 const uint32_t
adc = std::floor(
std::min(newCharge[it], maxADC) / lsbADC);
188 newSample.
set(
adc > thrADC,
false, gainIdx, 0,
adc);
189 dataFrame.setSample(it, newSample);
196 std::ostringstream
msg;
197 dataFrame.print(
msg);
207 CLHEP::HepRandomEngine* engine,
215 busyFlags.fill(
false);
216 totFlags.fill(
false);
217 toaFlags.fill(
false);
219 toaFromToT.fill(0.
f);
222 constexpr
bool debug_state(
true);
224 constexpr
bool debug_state(
false);
227 bool debug = debug_state;
234 maxADC = adcSaturation_fC_;
249 if (toaColl[fireBX] != 0.
f) {
250 timeToA = toaColl[fireBX];
251 float jitter = getTimeJitter(chargeColl[fireBX],
thickness);
253 timeToA = CLHEP::RandGaussQ::shoot(engine, timeToA, jitter);
254 else if (tdcResolutionInNs_ != 0)
255 timeToA = CLHEP::RandGaussQ::shoot(engine, timeToA, tdcResolutionInNs_);
256 if (timeToA >= 0.
f && timeToA <= 25.
f)
257 toaFlags[fireBX] =
true;
263 for (
int it = 0; it < (
int)(chargeColl.size()); ++it) {
269 if (tdcOnsetAuto < 0) {
270 tdcOnsetAuto = tdcOnset_fC_;
273 float charge = chargeColl[it];
285 edm::LogVerbatim(
"HGCFE") <<
"\t q=" <<
charge <<
" fC with <toa>=" << toa <<
" ns, triggers ToT @ " << it
291 float totalCharge(
charge), finalToA(toa), integTime(0);
296 float charge_offset = 0.f;
297 const float charge_kfC(totalCharge * 1
e-3);
298 if (charge_kfC < tdcChargeDrainParameterisation_[3]) {
300 }
else if (charge_kfC < tdcChargeDrainParameterisation_[7]) {
302 charge_offset = tdcChargeDrainParameterisation_[3];
306 charge_offset = tdcChargeDrainParameterisation_[7];
309 const float charge_mod = charge_kfC - charge_offset;
310 const float newIntegTime =
311 ((tdcChargeDrainParameterisation_[poffset] * charge_mod + tdcChargeDrainParameterisation_[poffset + 1]) *
313 tdcChargeDrainParameterisation_[poffset + 2]);
315 const int newBusyBxs = std::floor(newIntegTime / 25.
f) + 1;
319 integTime = newIntegTime;
320 if (newBusyBxs == busyBxs)
326 edm::LogVerbatim(
"HGCFE") <<
"\t Intial busy estimate=" << integTime <<
" ns = " << newBusyBxs <<
" bxs" 329 edm::LogVerbatim(
"HGCFE") <<
"\t ...integrated charge overflows initial busy estimate, interating again" 334 busyBxs = newBusyBxs;
338 if (toaMode_ == WEIGHTEDBYE)
342 for (
int jt = 0; jt < it; ++jt) {
343 const unsigned int deltaT = (it - jt);
344 if ((deltaT + 2) >=
adcPulse.size() || chargeColl[jt] == 0.f || totFlags[jt] || busyFlags[jt])
347 const float leakCharge = chargeColl[jt] *
adcPulse[deltaT + 2];
348 totalCharge += leakCharge;
349 if (toaMode_ == WEIGHTEDBYE)
350 finalToA += leakCharge * pulseAvgT_[deltaT + 2];
353 edm::LogVerbatim(
"HGCFE") <<
"\t\t leaking " << chargeColl[jt] <<
" fC @ deltaT=-" << deltaT <<
" -> +" 354 << leakCharge <<
" with avgT=" << pulseAvgT_[deltaT + 2] << std::endl;
358 for (
int jt = it + 1; jt < it + busyBxs && jt < dataFrame.size(); ++jt) {
361 busyFlags[jt] =
true;
363 const float extraCharge = chargeColl[jt];
364 if (extraCharge == 0.
f)
367 edm::LogVerbatim(
"HGCFE") <<
"\t\t adding " << extraCharge <<
" fC @ deltaT=+" << (jt - it) << std::endl;
369 totalCharge += extraCharge;
370 if (toaMode_ == WEIGHTEDBYE)
371 finalToA += extraCharge * toaColl[jt];
375 if (toaMode_ == WEIGHTEDBYE)
376 finalToA /= totalCharge;
379 newCharge[it] = (totalCharge -
tdcOnset);
382 edm::LogVerbatim(
"HGCFE") <<
"\t Final busy estimate=" << integTime <<
" ns = " << busyBxs <<
" bxs" << std::endl
383 <<
"\t Total integrated=" << totalCharge <<
" fC <toa>=" << toaFromToT[it]
384 <<
" (raw=" << finalToA <<
") ns " << std::endl;
387 if (it + busyBxs < (
int)(newCharge.size())) {
388 const float deltaT2nextBx((busyBxs * 25 - integTime));
389 const float tdcOnsetLeakage(
tdcOnset *
vdt::fast_expf(-deltaT2nextBx / tdcChargeDrainParameterisation_[11]));
392 << deltaT2nextBx <<
" DeltaT/tau=" << deltaT2nextBx <<
" / " 393 << tdcChargeDrainParameterisation_[11] <<
" ns, adds " << tdcOnsetLeakage <<
" fC @ " 394 << it + busyBxs <<
" bx (first free bx)" << std::endl;
395 newCharge[it + busyBxs] += tdcOnsetLeakage;
400 auto runChargeSharing = [&]() {
402 for (
int it = 0; it < (
int)(chargeColl.size()); ++it) {
405 if (!totFlags[it] & !busyFlags[it]) {
408 for (ipulse =
start; ipulse < stop; ++ipulse) {
409 const int itoffset = it + ipulse - 2;
413 if (!totFlags[itoffset] & !busyFlags[itoffset]) {
414 newCharge[itoffset] += chargeColl[it] *
adcPulse[ipulse];
446 for (
int it = 0; it < (
int)(newCharge.size()); it++) {
448 edm::LogVerbatim(
"HGCFE") << chargeColl[it] <<
" -> " << newCharge[it] <<
" ";
451 if (totFlags[it] || busyFlags[it]) {
454 const float saturatedCharge(
std::min(newCharge[it], tdcSaturation_fC_));
457 true,
true, gainIdx, (uint16_t)(timeToA / toaLSB_ns_), (uint16_t)(std::floor(saturatedCharge / tdcLSB_fC_)));
461 newSample.
set(
false,
true, gainIdx, 0, 0);
465 const uint16_t
adc = std::floor(
std::min(newCharge[it], maxADC) / lsbADC);
467 newSample.
set(
adc > thrADC,
false, gainIdx, (uint16_t)(timeToA / toaLSB_ns_),
adc);
471 dataFrame.setSample(it, newSample);
475 std::ostringstream
msg;
476 dataFrame.print(
msg);
Log< level::Info, true > LogVerbatim
T getParameter(std::string const &) const
void runShaperWithToT(DFr &dataFrame, hgc::HGCSimHitData &chargeColl, hgc::HGCSimHitData &toa, CLHEP::HepRandomEngine *engine, uint32_t thrADC, float lsbADC, uint32_t gainIdx, float maxADC, int thickness, float tdcOnsetAuto, const hgc_digi::FEADCPulseShape &adcPulse)
implements pulse shape and switch to time over threshold including deadtime
std::array< HGCSimData_t, nSamples > HGCSimHitData
HGCFEElectronics(const edm::ParameterSet &ps)
CTOR.
void setToAValid(bool toaFired)
void runSimpleShaper(DFr &dataFrame, hgc::HGCSimHitData &chargeColl, uint32_t thrADC, float lsbADC, uint32_t gainIdx, float maxADC, const hgc_digi::FEADCPulseShape &adcPulse)
applies a shape to each time sample and propagates the tails to the subsequent time samples ...
void runTrivialShaper(DFr &dataFrame, hgc::HGCSimHitData &chargeColl, uint32_t thrADC, float lsbADC, uint32_t gainIdx, float maxADC)
converts charge to digis without pulse shape
models the behavior of the front-end electronics
void set(bool thr, bool mode, uint16_t gain, uint16_t toa, uint16_t data)
Power< A, B >::type pow(const A &a, const B &b)
uint16_t *__restrict__ uint16_t const *__restrict__ adc
std::array< float, 6 > FEADCPulseShape