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;
58 if( ps.
exists(
"tdcChargeDrainParameterisation") ) {
59 for(
auto val : ps.
getParameter< std::vector<double> >(
"tdcChargeDrainParameterisation") ) {
75 for(
int it=0; it<(
int)(chargeColl.size()); it++) debug |= (chargeColl[it]>
adcThreshold_fC_);
83 for(
int it=0; it<(
int)(chargeColl.size()); it++)
88 newSample.
set(chargeColl[it]>adj_thresh,
false,0,adc);
89 dataFrame.setSample(it,newSample);
95 std::ostringstream
msg;
108 for(
int it=0; it<(
int)(chargeColl.size()); it++)
110 const float charge(chargeColl[it]);
111 if(charge==0.
f)
continue;
117 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t Redistributing SARS ADC" << charge <<
" @ " << it;
119 for(
int ipulse=-2; ipulse<(
int)(
adcPulse_.size())-2; ipulse++)
121 if(it+ipulse<0)
continue;
122 if(it+ipulse>=(
int)(dataFrame.size()))
continue;
123 const float chargeLeak=charge*
adcPulse_[(ipulse+2)];
126 if(debug)
edm::LogVerbatim(
"HGCFE") <<
" | " << it+ipulse <<
" " << chargeLeak;
141 dataFrame.setSample(it,newSample);
147 std::ostringstream
msg;
148 dataFrame.print(msg);
168 bool debug = debug_state;
172 for(
int it=0; it<(
int)(chargeColl.size()); ++it)
179 float charge = chargeColl[it];
186 float toa = toaColl[it];
189 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t q=" << charge <<
" fC with <toa>=" << toa <<
" ns, triggers ToT @ " << it << std::endl;
194 float totalCharge(charge), finalToA(toa), integTime(0);
199 float charge_offset = 0.f;
200 const float charge_kfC(totalCharge*1
e-3);
212 const float charge_mod = charge_kfC - charge_offset;
217 const int newBusyBxs=std::floor(newIntegTime/25.
f)+1;
221 integTime=newIntegTime;
222 if(newBusyBxs==busyBxs)
break;
227 if(busyBxs==0)
edm::LogVerbatim(
"HGCFE") <<
"\t Intial busy estimate="<< integTime <<
" ns = " << newBusyBxs <<
" bxs" << std::endl;
228 else edm::LogVerbatim(
"HGCFE") <<
"\t ...integrated charge overflows initial busy estimate, interating again" << std::endl;
239 for(
int jt=0; jt<it; ++jt)
241 const unsigned int deltaT=(it-jt);
244 const float leakCharge = chargeColl[jt]*
adcPulse_[deltaT+2];
245 totalCharge += leakCharge;
248 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t\t leaking " << chargeColl[jt] <<
" fC @ deltaT=-" << deltaT <<
" -> +" << leakCharge <<
" with avgT=" << pulseAvgT_[deltaT+2] << std::endl;
252 for(
int jt=it+1; jt<it+busyBxs && jt<dataFrame.size() ; ++jt)
258 const float extraCharge=chargeColl[jt];
259 if(extraCharge==0.
f)
continue;
260 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t\t adding " << extraCharge <<
" fC @ deltaT=+" << (jt-it) << std::endl;
262 totalCharge += extraCharge;
273 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t Final busy estimate="<< integTime <<
" ns = " << busyBxs <<
" bxs" << std::endl
274 <<
"\t Total integrated=" << totalCharge <<
" fC <toa>=" <<
toaFromToT[it] <<
" (raw=" << finalToA <<
") ns " << std::endl;
279 const float deltaT2nextBx((busyBxs*25-integTime));
282 <<
" fC, to be dissipated in " << deltaT2nextBx
284 <<
" ns, adds " << tdcOnsetLeakage <<
" fC @ " << it+busyBxs <<
" bx (first free bx)" << std::endl;
285 newCharge[it+busyBxs] += tdcOnsetLeakage;
290 auto runChargeSharing = [&]() {
292 for(
int it=0; it<(
int)(chargeColl.size()); ++it)
299 for(ipulse = start; ipulse < stop; ++ipulse) {
300 const int itoffset = it + ipulse - 2;
330 while(finalToA < 0.
f) finalToA+=25.f;
331 while(finalToA > 25.
f) finalToA-=25.f;
339 newSample.
set(
false,
true,0,0);
346 newSample.
set(newCharge[it]>adj_thresh,
false,(uint16_t)0,(uint16_t)(std::floor(saturatedCharge/
adcLSB_fC_)));
348 dataFrame.setSample(it,newSample);
352 std::ostringstream
msg;
353 dataFrame.print(msg);
int adc(sample_type sample)
get the ADC sample (12 bits)
T getParameter(std::string const &) const
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
hgc::HGCSimHitData toaFromToT
std::array< bool, hgc::nSamples > totFlags
std::array< HGCSimData_t, nSamples > HGCSimHitData
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 ...
std::array< float, 6 > adcPulse_
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
Power< A, B >::type pow(const A &a, const B &b)