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];
210 if(timeToA >= 0.
f && timeToA <= 25.
f)
toaFlags[fireBX] =
true;
216 for(
int it=0; it<(
int)(chargeColl.size()); ++it)
223 float charge = chargeColl[it];
235 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t q=" << charge <<
" fC with <toa>=" << toa <<
" ns, triggers ToT @ " << it << std::endl;
240 float totalCharge(charge), finalToA(toa), integTime(0);
245 float charge_offset = 0.f;
246 const float charge_kfC(totalCharge*1
e-3);
258 const float charge_mod = charge_kfC - charge_offset;
263 const int newBusyBxs=std::floor(newIntegTime/25.
f)+1;
267 integTime=newIntegTime;
268 if(newBusyBxs==busyBxs)
break;
273 if(busyBxs==0)
edm::LogVerbatim(
"HGCFE") <<
"\t Intial busy estimate="<< integTime <<
" ns = " << newBusyBxs <<
" bxs" << std::endl;
274 else edm::LogVerbatim(
"HGCFE") <<
"\t ...integrated charge overflows initial busy estimate, interating again" << std::endl;
285 for(
int jt=0; jt<it; ++jt)
287 const unsigned int deltaT=(it-jt);
290 const float leakCharge = chargeColl[jt]*
adcPulse_[deltaT+2];
291 totalCharge += leakCharge;
294 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t\t leaking " << chargeColl[jt] <<
" fC @ deltaT=-" << deltaT <<
" -> +" << leakCharge <<
" with avgT=" << pulseAvgT_[deltaT+2] << std::endl;
298 for(
int jt=it+1; jt<it+busyBxs && jt<dataFrame.size() ; ++jt)
304 const float extraCharge=chargeColl[jt];
305 if(extraCharge==0.
f)
continue;
306 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t\t adding " << extraCharge <<
" fC @ deltaT=+" << (jt-it) << std::endl;
308 totalCharge += extraCharge;
318 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t Final busy estimate="<< integTime <<
" ns = " << busyBxs <<
" bxs" << std::endl
319 <<
"\t Total integrated=" << totalCharge <<
" fC <toa>=" <<
toaFromToT[it] <<
" (raw=" << finalToA <<
") ns " << std::endl;
324 const float deltaT2nextBx((busyBxs*25-integTime));
327 <<
" fC, to be dissipated in " << deltaT2nextBx
329 <<
" ns, adds " << tdcOnsetLeakage <<
" fC @ " << it+busyBxs <<
" bx (first free bx)" << std::endl;
330 newCharge[it+busyBxs] += tdcOnsetLeakage;
335 auto runChargeSharing = [&]() {
337 for(
int it=0; it<(
int)(chargeColl.size()); ++it)
344 for(ipulse = start; ipulse < stop; ++ipulse) {
345 const int itoffset = it + ipulse - 2;
399 newSample.
set(
false,
true,0,0);
407 newSample.
set(newCharge[it]>adj_thresh,
false, (uint16_t)(timeToA/
toaLSB_ns_), (uint16_t)(std::floor(saturatedCharge/
adcLSB_fC_)));
410 dataFrame.setSample(it,newSample);
414 std::ostringstream
msg;
415 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)