5 #include "vdt/vdtMath.h" 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_);
82 for(
int it=0; it<(
int)(chargeColl.size()); it++)
88 dataFrame.setSample(it,newSample);
94 std::ostringstream
msg;
107 for(
int it=0; it<(
int)(chargeColl.size()); it++)
109 const float charge(chargeColl[it]);
110 if(charge==0.
f)
continue;
116 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t Redistributing SARS ADC" << charge <<
" @ " << it;
118 for(
int ipulse=-2; ipulse<(
int)(
adcPulse_.size())-2; ipulse++)
120 if(it+ipulse<0)
continue;
121 if(it+ipulse>=(
int)(dataFrame.size()))
continue;
122 const float chargeLeak=charge*
adcPulse_[(ipulse+2)];
125 if(debug)
edm::LogVerbatim(
"HGCFE") <<
" | " << it+ipulse <<
" " << chargeLeak;
138 dataFrame.setSample(it,newSample);
144 std::ostringstream
msg;
145 dataFrame.print(msg);
165 bool debug = debug_state;
169 for(
int it=0; it<(
int)(chargeColl.size()); ++it)
176 float charge = chargeColl[it];
183 float toa = toaColl[it];
186 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t q=" << charge <<
" fC with <toa>=" << toa <<
" ns, triggers ToT @ " << it << std::endl;
191 float totalCharge(charge), finalToA(toa), integTime(0);
196 float charge_offset = 0.f;
197 const float charge_kfC(totalCharge*1
e-3);
209 const float charge_mod = charge_kfC - charge_offset;
214 const int newBusyBxs=std::floor(newIntegTime/25.
f)+1;
218 integTime=newIntegTime;
219 if(newBusyBxs==busyBxs)
break;
224 if(busyBxs==0)
edm::LogVerbatim(
"HGCFE") <<
"\t Intial busy estimate="<< integTime <<
" ns = " << newBusyBxs <<
" bxs" << std::endl;
225 else edm::LogVerbatim(
"HGCFE") <<
"\t ...integrated charge overflows initial busy estimate, interating again" << std::endl;
236 for(
int jt=0; jt<it; ++jt)
238 const unsigned int deltaT=(it-jt);
241 const float leakCharge = chargeColl[jt]*
adcPulse_[deltaT+2];
242 totalCharge += leakCharge;
245 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t\t leaking " << chargeColl[jt] <<
" fC @ deltaT=-" << deltaT <<
" -> +" << leakCharge <<
" with avgT=" << pulseAvgT_[deltaT+2] << std::endl;
249 for(
int jt=it+1; jt<it+busyBxs && jt<dataFrame.size() ; ++jt)
255 const float extraCharge=chargeColl[jt];
256 if(extraCharge==0.
f)
continue;
257 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t\t adding " << extraCharge <<
" fC @ deltaT=+" << (jt-it) << std::endl;
259 totalCharge += extraCharge;
270 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t Final busy estimate="<< integTime <<
" ns = " << busyBxs <<
" bxs" << std::endl
271 <<
"\t Total integrated=" << totalCharge <<
" fC <toa>=" <<
toaFromToT[it] <<
" (raw=" << finalToA <<
") ns " << std::endl;
276 const float deltaT2nextBx((busyBxs*25-integTime));
279 <<
" fC, to be dissipated in " << deltaT2nextBx
281 <<
" ns, adds " << tdcOnsetLeakage <<
" fC @ " << it+busyBxs <<
" bx (first free bx)" << std::endl;
282 newCharge[it+busyBxs] += tdcOnsetLeakage;
287 auto runChargeSharing = [&]() {
289 for(
int it=0; it<(
int)(chargeColl.size()); ++it)
296 for(ipulse = start; ipulse < stop; ++ipulse) {
297 const int itoffset = it + ipulse - 2;
327 while(finalToA < 0.
f) finalToA+=25.f;
328 while(finalToA > 25.
f) finalToA-=25.f;
336 newSample.
set(
false,
true,0,0);
343 newSample.
set(newCharge[it]>adj_thresh,
false,(uint16_t)0,(uint16_t)(std::floor(saturatedCharge/
adcLSB_fC_)));
345 dataFrame.setSample(it,newSample);
349 std::ostringstream
msg;
350 dataFrame.print(msg);
int adc(sample_type sample)
get the ADC sample (12 bits)
T getParameter(std::string const &) const
void runSimpleShaper(DFr &dataFrame, hgc::HGCSimHitData &chargeColl, int thickness)
applies a shape to each time sample and propagates the tails to the subsequent time samples ...
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.
std::array< bool, hgc::nSamples > busyFlags
std::array< float, 6 > adcPulse_
void runTrivialShaper(DFr &dataFrame, hgc::HGCSimHitData &chargeColl, int thickness)
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)
void runShaperWithToT(DFr &dataFrame, hgc::HGCSimHitData &chargeColl, hgc::HGCSimHitData &toa, int thickness, CLHEP::HepRandomEngine *engine)
implements pulse shape and switch to time over threshold including deadtime