98 const float epsilon=0.001;
103 result.m_valid=
false;
104 result.m_converged=
false;
105 result.m_amplitude= 0;
107 result.m_quality = 0;
108 result.m_delay_final = delayIn;
109 result.m_peakSample_init = npeak;
110 result.m_peakSample_final = npeak;
111 result.m_chid = chID;
113 unsigned& kMax = result.m_peakSample_final;
114 float&
delay = result.m_delay_final;
115 float& q=result.m_quality;
116 unsigned& delayIdx=result.m_ofcIndex;
127 const unsigned nSamples=samples.size();
149 const unsigned nOFCPhase=dd_ofc->
nTimeBins(chID,usedGain);
150 float timeOffset = dd_ofc->
timeOffset(chID,usedGain);
160 timeMax=(nOFCPhase-1)*timeBinWidth;
163 timeMax = (nOFCPhase-1)*timeBinWidth;
164 if (timeBinWidth==0.) {
172 delayIdx=(unsigned)std::floor(0.5+
delay/timeBinWidth);
178 const unsigned ofcSize=this_OFC_a.size();
181 if ( ofcSize == 0 || this_OFC_b.size() == 0 ) {
182 ATH_MSG_DEBUG(
"OFC not found for channel " <<
m_lar_on_id->channel_name(chID) <<
", gain=" << usedGain <<
", delayIdx=" << delayIdx);
186 if ( this_OFC_a.size() != this_OFC_b.size() ) {
188 ")and b (" << this_OFC_b.size() <<
") are not the same size for channel 0x"
194 if (peak_low<2) peak_low=2;
195 if (peak_high>(nSamples+2-ofcSize)) peak_high=(nSamples+2-ofcSize);
196 if (peak_high<peak_low) {
198 <<
"Not enough ADC samples (" << nSamples <<
") to apply " << ofcSize <<
" OFCs." );
201 if(kMax<peak_low) kMax=peak_low;
202 if(kMax>peak_high) kMax=peak_high;
204 float amplitude_save=0.;
205 float tau_save= 99999.;
206 unsigned int kMax_save=0;
208 unsigned int delayIdx_save=0;
210 unsigned int mynIter = nIter;
233 for (
unsigned k=0 ; (k<ofcSize); k++ ) {
235 const float& this_sample = samples[kMax-2+k];
236 A += this_OFC_a.
at(k) * this_sample ;
237 At += this_OFC_b.
at(k) * this_sample ;
240 result.m_valid =
true;
243 result.m_amplitude=0;
247 result.m_amplitude=
A;
248 result.m_tau = At /
A ;
252 delay = delayIdx*timeBinWidth;
257 if (samples.size() == ofcSize && nOFCPhase<2) {
258 delay = delayIdx*timeBinWidth;
263 if (std::abs(result.m_tau) <= (0.5*timeBinWidth)) {
264 result.m_converged=
true;
265 delay = delayIdx*timeBinWidth;
269 if (kIter>=mynIter) {
270 delay = delayIdx*timeBinWidth;
271 if (result.m_converged) {
272 if (std::abs(tau_save) < std::abs(result.m_tau)) {
273 result.m_amplitude = amplitude_save;
274 result.m_tau = tau_save;
277 delayIdx = delayIdx_save;
280 if (std::abs(result.m_tau) <= timeBinWidth) result.m_converged=
true;
286 if (std::abs(result.m_tau) <= timeBinWidth) {
287 result.m_converged =
true;
289 amplitude_save = result.m_amplitude;
290 tau_save = result.m_tau;
292 delay_save = delayIdx*timeBinWidth;
293 delayIdx_save = delayIdx;
298 if(
delay<(-0.5*timeBinWidth)) {
303 if (
delay > timeMax )
delay = timeMax-epsilon;
309 if(
delay>(timeMax+0.5*timeBinWidth) ) {
314 if(
delay > timeMax )
delay = timeMax-epsilon;
317 delay = timeMax-epsilon;
322 delayIdx=(unsigned)floor(0.5+
delay/timeBinWidth);
323 if (delayIdx>=nOFCPhase) delayIdx = nOFCPhase-1;
325 this_OFC_a = dd_ofc->
OFC_a(chID,(
int)usedGain,delayIdx);
326 this_OFC_b = dd_ofc->
OFC_b(chID,(
int)usedGain,delayIdx);
345 if( thisShape.size() >= ofcSize ) {
346 for (
unsigned k=0 ; k<ofcSize ; k++ ) {
347 const float& this_sample = samples[kMax-2+k];
349 q += std::pow((result.m_amplitude*(thisShape[k]-result.m_tau*thisShapeDer[k]) - this_sample),2);
351 q += std::pow((result.m_amplitude*thisShape[k] - this_sample),2);
359 result.m_nIterPerf = kIter;
360 result.m_valid =
true;
virtual OFCRef_t OFC_a(const HWIdentifier &id, int gain, int tbin=0) const =0
access to OFCs by online ID, gain, and tbin (!=0 for testbeam)