5 #include "vdt/vdtMath.h" 17 edm::LogVerbatim(
"HGCFE") <<
"[HGCFEElectronics] running with version " << fwVersion_ << std::endl;
18 if( ps.
exists(
"adcPulse") )
21 for(
unsigned i = 0;
i <
temp.size(); ++
i ) {
29 for(
unsigned i = 0;
i <
temp.size(); ++
i ) {
34 if( ps.
exists(
"adcNbits") )
40 <<
"[HGCFEElectronics] " << adcNbits <<
" bit ADC defined" 41 <<
" with LSB=" << adcLSB_fC_
42 <<
" saturation to occur @ " << adcSaturation_fC_ << std::endl;
46 if( ps.
exists(
"tdcNbits") )
52 <<
"[HGCFEElectronics] " << tdcNbits <<
" bit TDC defined with LSB=" 53 << tdcLSB_fC_ <<
" saturation to occur @ " << tdcSaturation_fC_ << std::endl;
57 if( ps.
exists(
"tdcForToAOnset_fC") ){
62 <<
" HGCFEElectronics wrong size for ToA thresholds ";
66 if( ps.
exists(
"tdcChargeDrainParameterisation") ) {
67 for(
auto val : ps.
getParameter< std::vector<double> >(
"tdcChargeDrainParameterisation") ) {
74 if( ps.
exists(
"jitterNoise_ns") ){
79 <<
" HGCFEElectronics wrong size for ToA jitterNoise ";
82 if( ps.
exists(
"jitterConstant_ns") ){
88 <<
" HGCFEElectronics wrong size for ToA jitterConstant ";
101 for(
int it=0; it<(
int)(chargeColl.size()); it++) debug |= (chargeColl[it]>
adcThreshold_fC_);
109 for(
int it=0; it<(
int)(chargeColl.size()); it++)
114 newSample.
set(chargeColl[it]>adj_thresh,
false,0,adc);
115 dataFrame.setSample(it,newSample);
121 std::ostringstream
msg;
122 dataFrame.print(msg);
134 for(
int it=0; it<(
int)(chargeColl.size()); it++)
136 const float charge(chargeColl[it]);
137 if(charge==0.
f)
continue;
143 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t Redistributing SARS ADC" << charge <<
" @ " << it;
145 for(
int ipulse=-2; ipulse<(
int)(
adcPulse_.size())-2; ipulse++)
147 if(it+ipulse<0)
continue;
148 if(it+ipulse>=(
int)(dataFrame.size()))
continue;
149 const float chargeLeak=charge*
adcPulse_[(ipulse+2)];
152 if(debug)
edm::LogVerbatim(
"HGCFE") <<
" | " << it+ipulse <<
" " << chargeLeak;
167 dataFrame.setSample(it,newSample);
173 std::ostringstream
msg;
174 dataFrame.print(msg);
195 bool debug = debug_state;
206 if(toaColl[fireBX] != 0.
f){
207 timeToA = toaColl[fireBX];
209 if(jitter != 0) timeToA = CLHEP::RandGaussQ::shoot(engine, timeToA, jitter);
211 if(timeToA >= 0.
f && timeToA <= 25.
f)
toaFlags[fireBX] =
true;
217 for(
int it=0; it<(
int)(chargeColl.size()); ++it)
224 float charge = chargeColl[it];
236 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t q=" << charge <<
" fC with <toa>=" << toa <<
" ns, triggers ToT @ " << it << std::endl;
241 float totalCharge(charge), finalToA(toa), integTime(0);
246 float charge_offset = 0.f;
247 const float charge_kfC(totalCharge*1
e-3);
259 const float charge_mod = charge_kfC - charge_offset;
264 const int newBusyBxs=std::floor(newIntegTime/25.
f)+1;
268 integTime=newIntegTime;
269 if(newBusyBxs==busyBxs)
break;
274 if(busyBxs==0)
edm::LogVerbatim(
"HGCFE") <<
"\t Intial busy estimate="<< integTime <<
" ns = " << newBusyBxs <<
" bxs" << std::endl;
275 else edm::LogVerbatim(
"HGCFE") <<
"\t ...integrated charge overflows initial busy estimate, interating again" << std::endl;
286 for(
int jt=0; jt<it; ++jt)
288 const unsigned int deltaT=(it-jt);
291 const float leakCharge = chargeColl[jt]*
adcPulse_[deltaT+2];
292 totalCharge += leakCharge;
295 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t\t leaking " << chargeColl[jt] <<
" fC @ deltaT=-" << deltaT <<
" -> +" << leakCharge <<
" with avgT=" << pulseAvgT_[deltaT+2] << std::endl;
299 for(
int jt=it+1; jt<it+busyBxs && jt<dataFrame.size() ; ++jt)
305 const float extraCharge=chargeColl[jt];
306 if(extraCharge==0.
f)
continue;
307 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t\t adding " << extraCharge <<
" fC @ deltaT=+" << (jt-it) << std::endl;
309 totalCharge += extraCharge;
319 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t Final busy estimate="<< integTime <<
" ns = " << busyBxs <<
" bxs" << std::endl
320 <<
"\t Total integrated=" << totalCharge <<
" fC <toa>=" <<
toaFromToT[it] <<
" (raw=" << finalToA <<
") ns " << std::endl;
325 const float deltaT2nextBx((busyBxs*25-integTime));
328 <<
" fC, to be dissipated in " << deltaT2nextBx
330 <<
" ns, adds " << tdcOnsetLeakage <<
" fC @ " << it+busyBxs <<
" bx (first free bx)" << std::endl;
331 newCharge[it+busyBxs] += tdcOnsetLeakage;
336 auto runChargeSharing = [&]() {
338 for(
int it=0; it<(
int)(chargeColl.size()); ++it)
345 for(ipulse = start; ipulse < stop; ++ipulse) {
346 const int itoffset = it + ipulse - 2;
400 newSample.
set(
false,
true,0,0);
408 newSample.
set(newCharge[it]>adj_thresh,
false, (uint16_t)(timeToA/
toaLSB_ns_), (uint16_t)(std::floor(saturatedCharge/
adcLSB_fC_)));
411 dataFrame.setSample(it,newSample);
415 std::ostringstream
msg;
416 dataFrame.print(msg);
int adc(sample_type sample)
get the ADC sample (12 bits)
T getParameter(std::string const &) const
std::array< float, 3 > tdcForToAOnset_fC_
void runShaperWithToT(DFr &dataFrame, hgc::HGCSimHitData &chargeColl, hgc::HGCSimHitData &toa, int thickness, CLHEP::HepRandomEngine *engine, float cce=1.0)
implements pulse shape and switch to time over threshold including deadtime
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::array< bool, hgc::nSamples > toaFlags
hgc::HGCSimHitData toaFromToT
std::array< bool, hgc::nSamples > totFlags
std::array< HGCSimData_t, nSamples > HGCSimHitData
float getTimeJitter(float totalCharge, int thickness)
HGCFEElectronics(const edm::ParameterSet &ps)
CTOR.
bool thresholdFollowsMIP_
std::array< bool, hgc::nSamples > busyFlags
void runSimpleShaper(DFr &dataFrame, hgc::HGCSimHitData &chargeColl, int thickness, float cce=1.0)
applies a shape to each time sample and propagates the tails to the subsequent time samples ...
void setToAValid(bool toaFired)
std::array< float, 6 > adcPulse_
std::array< float, 3 > jitterNoise2_ns_
void runTrivialShaper(DFr &dataFrame, hgc::HGCSimHitData &chargeColl, int thickness, float cce=1.0)
converts charge to digis without pulse shape
std::vector< float > tdcChargeDrainParameterisation_
models the behavior of the front-end electronics
std::array< float, 6 > pulseAvgT_
void set(bool thr, bool mode, uint16_t toa, uint16_t data)
hgc::HGCSimHitData newCharge
std::array< float, 3 > jitterConstant2_ns_
Power< A, B >::type pow(const A &a, const B &b)