5 #include "vdt/vdtMath.h"
7 using namespace hgc_digi;
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") )
36 uint32_t adcNbits = ps.
getParameter<uint32_t>(
"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") )
48 uint32_t tdcNbits = ps.
getParameter<uint32_t>(
"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++)
85 const uint32_t
adc=std::floor(
std::min(chargeColl[it],adcSaturation_fC_) / adcLSB_fC_ );
87 newSample.
set(chargeColl[it]>thickness*adcThreshold_fC_,
false,0,adc);
88 dataFrame.setSample(it,newSample);
90 if(debug)
edm::LogVerbatim(
"HGCFE") << adc <<
" (" << chargeColl[it] <<
"/" << adcLSB_fC_ <<
") ";
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;
113 debug|=(charge>adcThreshold_fC_);
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)];
123 newCharge[it+ipulse]+= chargeLeak;
125 if(debug)
edm::LogVerbatim(
"HGCFE") <<
" | " << it+ipulse <<
" " << chargeLeak;
132 for(
int it=0; it<(int)(newCharge.size()); it++)
135 const float saturatedCharge(
std::min(newCharge[it],adcSaturation_fC_));
137 newSample.
set(newCharge[it]>thickness*adcThreshold_fC_,
false,0,floor(saturatedCharge/adcLSB_fC_));
138 dataFrame.setSample(it,newSample);
140 if(debug)
edm::LogVerbatim(
"HGCFE") << std::floor(saturatedCharge/adcLSB_fC_) <<
" (" << saturatedCharge <<
"/" << adcLSB_fC_ <<
" ) " ;
144 std::ostringstream
msg;
145 dataFrame.print(msg);
154 busyFlags.fill(
false);
155 totFlags.fill(
false);
156 newCharge.fill( 0.
f );
157 toaFromToT.fill( 0.
f );
165 bool debug = debug_state;
169 for(
int it=0; it<(int)(chargeColl.size()); ++it)
173 if(busyFlags[it])
continue;
176 float charge = chargeColl[it];
177 if(charge < tdcOnset_fC_) {
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);
198 if(charge_kfC<tdcChargeDrainParameterisation_[3]) {
200 }
else if(charge_kfC<tdcChargeDrainParameterisation_[7]) {
202 charge_offset = tdcChargeDrainParameterisation_[3];
206 charge_offset = tdcChargeDrainParameterisation_[7];
209 const float charge_mod = charge_kfC - charge_offset;
210 const float newIntegTime = ( ( tdcChargeDrainParameterisation_[poffset]*charge_mod +
211 tdcChargeDrainParameterisation_[poffset+1] )*charge_mod +
212 tdcChargeDrainParameterisation_[poffset+2] );
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;
233 if(toaMode_==WEIGHTEDBYE) finalToA=toa*
charge;
236 for(
int jt=0; jt<it; ++jt)
238 const unsigned int deltaT=(it-jt);
239 if((deltaT+2) >= adcPulse_.size() || chargeColl[jt]==0.f || totFlags[jt] || busyFlags[jt])
continue;
241 const float leakCharge = chargeColl[jt]*adcPulse_[deltaT+2];
242 totalCharge += leakCharge;
243 if(toaMode_==WEIGHTEDBYE) finalToA += leakCharge*pulseAvgT_[deltaT+2];
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;
260 if(toaMode_==WEIGHTEDBYE) finalToA += extraCharge*toaColl[jt];
264 if(toaMode_==WEIGHTEDBYE) finalToA /= totalCharge;
267 toaFromToT[it] = CLHEP::RandGaussQ::shoot(engine,finalToA,tdcResolutionInNs_);
268 newCharge[it] = (totalCharge-tdcOnset_fC_);
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;
274 if(it+busyBxs<(
int)(newCharge.size()))
276 const float deltaT2nextBx((busyBxs*25-integTime));
277 const float tdcOnsetLeakage(tdcOnset_fC_*
vdt::fast_expf(-deltaT2nextBx/tdcChargeDrainParameterisation_[11]));
278 if(debug)
edm::LogVerbatim(
"HGCFE") <<
"\t Leaking remainder of TDC onset " << tdcOnset_fC_
279 <<
" fC, to be dissipated in " << deltaT2nextBx
280 <<
" DeltaT/tau=" << deltaT2nextBx <<
" / " << tdcChargeDrainParameterisation_[11]
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)
293 if( !totFlags[it] & !busyFlags[it] ) {
295 const int stop =
std::min((
int)adcPulse_.size(),(int)newCharge.size()-it+2);
296 for(ipulse = start; ipulse < stop; ++ipulse) {
297 const int itoffset = it + ipulse - 2;
301 if( !totFlags[itoffset] & !busyFlags[itoffset] ) {
302 newCharge[itoffset] += chargeColl[it]*adcPulse_[ipulse];
316 const float adj_thresh = thickness*adcThreshold_fC_;
317 for(
int it=0; it<(int)(newCharge.size()); it++)
319 if(debug)
edm::LogVerbatim(
"HGCFE") << chargeColl[it] <<
" -> " << newCharge[it] <<
" ";
322 if(totFlags[it] || busyFlags[it])
326 float finalToA(toaFromToT[it]);
327 while(finalToA < 0.
f) finalToA+=25.f;
328 while(finalToA > 25.
f) finalToA-=25.f;
331 const float saturatedCharge(
std::min(newCharge[it],tdcSaturation_fC_));
332 newSample.
set(
true,
true,(uint16_t)(finalToA/toaLSB_ns_),(uint16_t)(std::floor(saturatedCharge/tdcLSB_fC_)));
336 newSample.
set(
false,
true,0,0);
342 const float saturatedCharge(
std::min(newCharge[it],adcSaturation_fC_));
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
std::array< HGCSimData_t, nSamples > HGCSimHitData
HGCFEElectronics(const edm::ParameterSet &ps)
CTOR.
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)
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