96 {
97
100
101
102
108 result.m_delay_final = delayIn;
109 result.m_peakSample_init = npeak;
110 result.m_peakSample_final = npeak;
112
113 unsigned& kMax =
result.m_peakSample_final;
116 unsigned& delayIdx=
result.m_ofcIndex;
117
118 unsigned kIter=0;
119
120 double At=0;
122
123
124
125
126
127 const unsigned nSamples=samples.size();
128
129
130
131
132
133
134
139 }
140
141 const ILArOFC* dd_ofc=nullptr;
146 }
147
148
149 const unsigned nOFCPhase=dd_ofc->
nTimeBins(chID,usedGain);
150 float timeOffset = dd_ofc->
timeOffset(chID,usedGain);
151
152
154
155 float timeBinWidth;
156 float timeMax;
157 if (nOFCPhase<2) {
158 delayIdx=0;
159 timeBinWidth=25.;
160 timeMax=(nOFCPhase-1)*timeBinWidth;
161 } else {
163 timeMax = (nOFCPhase-1)*timeBinWidth;
164 if (timeBinWidth==0.) {
167 }
168
171
173 }
174
175
178 const unsigned ofcSize=this_OFC_a.size();
179
180
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);
184 }
185
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"
191 }
192
193
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." );
200 }
201 if(kMax<peak_low) kMax=peak_low;
202 if(kMax>peak_high) kMax=peak_high;
203
204 float amplitude_save=0.;
205 float tau_save= 99999.;
206 unsigned int kMax_save=0;
207 float delay_save=0.;
208 unsigned int delayIdx_save=0;
209
210 unsigned int mynIter = nIter;
211
212 do {
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
233 for (
unsigned k=0 ; (
k<ofcSize);
k++ ) {
234
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 ;
238 }
239
241 if ( A == 0 ) {
246 }
249
250
251 if (mynIter<=1) {
252 delay = delayIdx*timeBinWidth;
253 break;
254 }
255
256
257 if (samples.size() == ofcSize && nOFCPhase<2) {
258 delay = delayIdx*timeBinWidth;
259 break;
260 }
261
262
263 if (std::abs(
result.m_tau) <= (0.5*timeBinWidth)) {
265 delay = delayIdx*timeBinWidth;
266 break;
267 }
268
269 if (kIter>=mynIter) {
270 delay = delayIdx*timeBinWidth;
272 if (std::abs(tau_save) < std::abs(
result.m_tau)) {
273 result.m_amplitude = amplitude_save;
275 kMax = kMax_save;
277 delayIdx = delayIdx_save;
278 }
279 }
280 if (std::abs(
result.m_tau) <= timeBinWidth)
result.m_converged=
true;
281 break;
282 }
283
284
285
286 if (std::abs(
result.m_tau) <= timeBinWidth) {
287 result.m_converged =
true;
288 mynIter = kIter+1;
289 amplitude_save =
result.m_amplitude;
291 kMax_save = kMax;
292 delay_save = delayIdx*timeBinWidth;
293 delayIdx_save = delayIdx;
294 }
295
297
298 if(
delay<(-0.5*timeBinWidth)) {
299 if(kMax<peak_high){
300 kMax = kMax+1 ;
304 } else {
306 }
307 }
308 else
309 if(
delay>(timeMax+0.5*timeBinWidth) ) {
310 if(kMax>peak_low){
311 kMax = kMax-1 ;
315 } else {
316
318 }
319 }
320
321 kIter++;
323 if (delayIdx>=nOFCPhase) delayIdx = nOFCPhase-1;
324
325 this_OFC_a = dd_ofc->
OFC_a(chID,(
int)usedGain,delayIdx);
326 this_OFC_b = dd_ofc->
OFC_b(chID,(
int)usedGain,delayIdx);
327 }
328 while(1);
329
330
332
333
335 const ILArShape* dd_shape=nullptr;
340 }
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);
350 else
351 q += std::pow((
result.m_amplitude*thisShape[k] - this_sample),2);
352 }
353 }
354 else {
356 }
357 }
358
359 result.m_nIterPerf = kIter;
362}
double delay(std::size_t d)
virtual OFCRef_t OFC_b(const HWIdentifier &id, int gain, int tbin=0) const =0
virtual unsigned nTimeBins(const HWIdentifier &CellID, int gain) const =0
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)
virtual float timeBinWidth(const HWIdentifier &CellID, int gain) const =0
LArVectorProxy OFCRef_t
This class defines the interface for accessing Optimal Filtering coefficients for each channel provid...
virtual float timeOffset(const HWIdentifier &CellID, int gain) const =0
LArVectorProxy ShapeRef_t
This class defines the interface for accessing Shape (Nsample variable, Dt = 25 ns fixed) @stereotype...
virtual ShapeRef_t Shape(const HWIdentifier &id, int gain, int tbin=0, int mode=0) const =0
virtual ShapeRef_t ShapeDer(const HWIdentifier &id, int gain, int tbin=0, int mode=0) const =0
value_type get_compact() const
Get the compact id.
value_type at(size_t i) const
Vector indexing with bounds check.