LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
WaveformTools_tool.cc
Go to the documentation of this file.
1 
6 #include <cmath>
10 #include "cetlib_except/exception.h"
17 
19 
20 #include "TVirtualFFT.h"
21 
22 #include <fstream>
23 #include <iomanip>
24 
25 namespace reco_tool
26 {
27 
29 {
30 public:
31  explicit WaveformTools(const fhicl::ParameterSet& pset);
32 
34 
35  void configure(const fhicl::ParameterSet& pset) override;
36 
37  using PeakTuple = std::tuple<size_t,size_t,size_t>; // first bin, peak bin, last bin
38  using PeakTupleVec = std::vector<PeakTuple>;
39 
40  void triangleSmooth(const std::vector<float>&, std::vector<float>&, size_t = 0) const override;
41  void triangleSmooth(const std::vector<double>&, std::vector<double>&, size_t = 0) const override;
42  void medianSmooth( const std::vector<float>&, std::vector<float>&, size_t = 3) const override;
43  void medianSmooth( const std::vector<double>&, std::vector<double>&, size_t = 3) const override;
44  void getTruncatedMeanRMS(const std::vector<double>&, double&, double&, double&, int&) const override;
45  void getTruncatedMeanRMS(const std::vector<float>&, float&, float&, float&, int&) const override;
46  void firstDerivative(const std::vector<float>&, std::vector<float>&) const override;
47  void firstDerivative(const std::vector<double>&, std::vector<double>&) const override;
50  void getFFTPower(const std::vector<float>& inputVec, std::vector<float>& outputPowerVec) const override;
51  void getFFTPower(const std::vector<double>& inputVec, std::vector<double>& outputPowerVec) const override;
52 
54  int,
55  HistogramMap&,
59  Waveform<short>&) const override;
61  int,
62  HistogramMap&,
66  Waveform<float>&) const override;
68  int,
69  HistogramMap&,
73  Waveform<double>&) const override;
74 
78 
79 private:
80  template <typename T> void triangleSmooth(const std::vector<T>&, std::vector<T>&, size_t = 0) const;
81  template <typename T> void medianSmooth( const std::vector<T>&, std::vector<T>&, size_t = 3) const;
82  template <typename T> void getTruncatedMeanRMS(const std::vector<T>&, T&, T&, T&, int&) const;
83  template <typename T> void firstDerivative(const std::vector<T>&, std::vector<T>&) const;
84  template <typename T> void findPeaks(typename std::vector<T>::iterator, typename std::vector<T>::iterator, PeakTupleVec&, T, size_t) const;
85 
86  template <typename T> void getErosionDilationAverageDifference(const Waveform<T>&,
87  int,
88  HistogramMap&,
89  Waveform<T>&,
90  Waveform<T>&,
91  Waveform<T>&,
92  Waveform<T>&) const;
93 
94  template <typename T> void getOpeningAndClosing(const Waveform<T>&, const Waveform<T>&, int, HistogramMap&, Waveform<T>&, Waveform<T>&) const;
95 };
96 
97 //----------------------------------------------------------------------
98 // Constructor.
100 {
101  configure(pset);
102 }
103 
105 {
106  // Start by recovering the parameters
107 // fThisPlane = pset.get<size_t>("Plane");
108 
109  return;
110 }
111 
112 void WaveformTools::triangleSmooth(const std::vector<double>& inputVec, std::vector<double>& smoothVec, size_t lowestBin) const
113 {
114  triangleSmooth<double>(inputVec, smoothVec, lowestBin);
115 
116  return;
117 }
118 
119 void WaveformTools::triangleSmooth(const std::vector<float>& inputVec, std::vector<float>& smoothVec, size_t lowestBin) const
120 {
121  triangleSmooth<float>(inputVec, smoothVec, lowestBin);
122 
123  return;
124 }
125 
126 template <typename T> void WaveformTools::triangleSmooth(const std::vector<T>& inputVec, std::vector<T>& smoothVec, size_t lowestBin) const
127 {
128  if (inputVec.size() != smoothVec.size()) smoothVec.resize(inputVec.size());
129 
130  std::copy(inputVec.begin(), inputVec.begin() + 2 + lowestBin, smoothVec.begin());
131  std::copy(inputVec.end() - 2, inputVec.end(), smoothVec.end() - 2);
132 
133  typename std::vector<T>::iterator curItr = smoothVec.begin() + 2 + lowestBin;
134  typename std::vector<T>::const_iterator curInItr = inputVec.begin() + 1 + lowestBin;
135  typename std::vector<T>::const_iterator stopInItr = inputVec.end() - 3;
136 
137  while(curInItr++ != stopInItr)
138  {
139  // Take the weighted average of five consecutive points centered on current point
140  T newVal = (*(curInItr - 2) + 2. * *(curInItr - 1) + 3. * *curInItr + 2. * *(curInItr + 1) + *(curInItr + 2)) / 9.;
141 
142  *curItr++ = newVal;
143  }
144  return;
145 }
146 
147 void WaveformTools::medianSmooth(const std::vector<float>&inputVec, std::vector<float>& smoothVec, size_t nBins) const
148 {
149  medianSmooth<float>(inputVec, smoothVec, nBins);
150 
151  return;
152 }
153 
154 void WaveformTools::medianSmooth(const std::vector<double>& inputVec, std::vector<double>& smoothVec, size_t nBins) const
155 {
156  medianSmooth<double>(inputVec, smoothVec, nBins);
157 
158  return;
159 }
160 
161 template <typename T> void WaveformTools::medianSmooth(const std::vector<T>& inputVec, std::vector<T>& smoothVec, size_t nBins) const
162 {
163  // For our purposes, nBins must be odd
164  if (nBins % 2 == 0) nBins++;
165 
166  // Make sure the input vector is right sized
167  if (inputVec.size() != smoothVec.size()) smoothVec.resize(inputVec.size());
168 
169  // Basic set up
170  typename std::vector<T> medianVec(nBins);
171  typename std::vector<T>::const_iterator startItr = inputVec.begin();
172  typename std::vector<T>::const_iterator stopItr = startItr;
173 
174  std::advance(stopItr, inputVec.size() - nBins);
175 
176  size_t medianBin = nBins/2;
177  size_t smoothBin = medianBin;
178 
179  // First bins are not smoothed
180  std::copy(startItr, startItr + medianBin, smoothVec.begin());
181 
182  while(std::distance(startItr,stopItr) > 0)
183  {
184  std::copy(startItr,startItr+nBins,medianVec.begin());
185  std::sort(medianVec.begin(),medianVec.end());
186 
187  T medianVal = medianVec[medianBin];
188 
189  smoothVec[smoothBin++] = medianVal;
190 
191  startItr++;
192  }
193 
194  // Last bins are not smoothed
195  std::copy(startItr + medianBin, inputVec.end(), smoothVec.begin() + smoothBin);
196 
197  return;
198 }
199 
200 void WaveformTools::getTruncatedMeanRMS(const std::vector<double>& waveform, double& mean, double& rmsFull, double& rmsTrunc, int& nTrunc) const
201 {
202  getTruncatedMeanRMS<double>(waveform, mean, rmsFull, rmsTrunc, nTrunc);
203 }
204 
205 void WaveformTools::getTruncatedMeanRMS(const std::vector<float>& waveform, float& mean, float& rmsFull, float& rmsTrunc, int& nTrunc) const
206 {
207  getTruncatedMeanRMS<float>(waveform, mean, rmsFull, rmsTrunc, nTrunc);
208 }
209 
210 template <typename T> void WaveformTools::getTruncatedMeanRMS(const std::vector<T>& waveform, T& mean, T& rmsFull, T& rmsTrunc, int& nTrunc) const
211 {
212  // We need to get a reliable estimate of the mean and can't assume the input waveform will be ~zero mean...
213  // Basic idea is to find the most probable value in the ROI presented to us
214  // From that we can develop an average of the true baseline of the ROI.
215  // To do that we employ a map based scheme
216  std::map<int,int> frequencyMap;
217  int mpCount(0);
218  int mpVal(0);
219 
220  for(const auto& val : waveform)
221  {
222  int intVal = std::round(4.*val);
223 
224  frequencyMap[intVal]++;
225 
226  if (frequencyMap.at(intVal) > mpCount)
227  {
228  mpCount = frequencyMap.at(intVal);
229  mpVal = intVal;
230  }
231  }
232 
233  // take a weighted average of two neighbor bins
234  int meanCnt = 0;
235  int meanSum = 0;
236  int binRange = std::min(16, int(frequencyMap.size()/2 + 1));
237 
238  for(int idx = -binRange; idx <= binRange; idx++)
239  {
240  std::map<int,int>::iterator neighborItr = frequencyMap.find(mpVal+idx);
241 
242  if (neighborItr != frequencyMap.end() && 5 * neighborItr->second > mpCount)
243  {
244  meanSum += neighborItr->first * neighborItr->second;
245  meanCnt += neighborItr->second;
246  }
247  }
248 
249  mean = 0.25 * T(meanSum) / T(meanCnt); // Note that bins were expanded by a factor of 4 above
250 
251  // do rms calculation - the old fashioned way and over all adc values
252  typename std::vector<T> locWaveform = waveform;
253 
254  std::transform(locWaveform.begin(), locWaveform.end(), locWaveform.begin(),std::bind(std::minus<T>(),std::placeholders::_1,mean));
255 
256  // sort in ascending order so we can truncate the sume
257  std::sort(locWaveform.begin(), locWaveform.end(),[](const auto& left, const auto& right){return std::fabs(left) < std::fabs(right);});
258 
259  // recalculate the rms for truncation
260  rmsFull = std::inner_product(locWaveform.begin(), locWaveform.end(), locWaveform.begin(), 0.);
261  rmsFull = std::sqrt(std::max(T(0.),rmsFull / T(locWaveform.size())));
262 
263  // recalculate the rms for truncation
264  rmsTrunc = std::inner_product(locWaveform.begin(), locWaveform.begin() + meanCnt, locWaveform.begin(), 0.);
265  rmsTrunc = std::sqrt(std::max(T(0.),rmsTrunc / T(meanCnt)));
266  nTrunc = meanCnt;
267 
268  return;
269 }
270 
271 void WaveformTools::firstDerivative(const std::vector<double>& inputVec, std::vector<double>& derivVec) const
272 {
273  firstDerivative<double>(inputVec, derivVec);
274 
275  return;
276 }
277 
278 void WaveformTools::firstDerivative(const std::vector<float>& inputVec, std::vector<float>& derivVec) const
279 {
280  firstDerivative<float>(inputVec, derivVec);
281 
282  return;
283 }
284 
285 template <typename T> void WaveformTools::firstDerivative(const std::vector<T>& inputVec, std::vector<T>& derivVec) const
286 {
287  derivVec.resize(inputVec.size(), 0.);
288 
289  for(size_t idx = 1; idx < derivVec.size() - 1; idx++)
290  derivVec.at(idx) = 0.5 * (inputVec.at(idx + 1) - inputVec.at(idx - 1));
291 
292  return;
293 }
294 
295 void WaveformTools::findPeaks(std::vector<double>::iterator startItr, std::vector<double>::iterator stopItr, PeakTupleVec& peakTupleVec, double threshold, size_t firstTick) const
296 {
297  findPeaks<double>(startItr, stopItr, peakTupleVec, threshold, firstTick);
298 
299  return;
300 }
301 
302 void WaveformTools::findPeaks(std::vector<float>::iterator startItr, std::vector<float>::iterator stopItr, PeakTupleVec& peakTupleVec, float threshold, size_t firstTick) const
303 {
304  findPeaks<float>(startItr, stopItr, peakTupleVec, threshold, firstTick);
305 
306  return;
307 }
308 
309 template <typename T> void WaveformTools::findPeaks(typename std::vector<T>::iterator startItr,
310  typename std::vector<T>::iterator stopItr,
311  PeakTupleVec& peakTupleVec,
312  T threshold,
313  size_t firstTick) const
314 {
315  // Need a minimum distance or else nothing to do
316  if (std::distance(startItr,stopItr) > 4)
317  {
318  // This is a divide and conquer algorithm, start by finding the maximum element.
319  typename std::vector<T>::iterator firstItr = std::max_element(startItr,stopItr,[](float left, float right){return std::fabs(left) < std::fabs(right);});
320 
321  // Are we over threshold?
322  if (std::fabs(*firstItr) > threshold)
323  {
324  // What am I thinking?
325  // First task is to find the "other" lobe max point
326  // Set one to the "first", the other to the "second"
327  // Search backward from first to find start point, forward from second to find end point
328  // Set mid point between first and second as "peak"?
329  typename std::vector<T>::iterator secondItr = firstItr;
330 
331  // Assume if max bin is positive then second lobe is later
332  if (*firstItr > 0)
333  {
334  typename std::vector<T>::iterator tempItr = secondItr;
335 
336  while(tempItr != stopItr)
337  {
338  if (*++tempItr < -threshold)
339  {
340  if (*tempItr < *secondItr) secondItr = tempItr;
341  }
342  else if (secondItr != firstItr) break;
343  }
344  }
345  // Otherwise it goes the other way
346  else
347  {
348  typename std::vector<T>::iterator tempItr = secondItr;
349 
350  while(tempItr != startItr)
351  {
352  if (*--tempItr > threshold)
353  {
354  if (*tempItr > *secondItr) secondItr = tempItr;
355  }
356  else if (secondItr != firstItr) break;
357  }
358 
359  std::swap(firstItr,secondItr);
360  }
361 
362  // It might that no real pulse was found
363  if (firstItr != secondItr)
364  {
365  // Get the "peak" position
366  size_t peakBin = std::distance(startItr,firstItr) + std::distance(firstItr,secondItr) / 2;
367 
368  // Advance (forward or backward) the first and second iterators to get back to zero crossing
369  while(firstItr != startItr) if (*--firstItr < 0.) break;
370  while(secondItr != stopItr) if (*++secondItr > 0.) break;
371 
372  size_t firstBin = std::distance(startItr,firstItr);
373  size_t lastBin = std::distance(startItr,secondItr);
374 
375  // Find leading peaks
376  findPeaks(startItr, firstItr, peakTupleVec, threshold, firstTick);
377 
378  // Save this peak
379  peakTupleVec.push_back(PeakTuple(firstBin+firstTick,peakBin+firstTick,lastBin+firstTick));
380 
381  // Find downstream peaks
382  findPeaks(secondItr, stopItr, peakTupleVec, threshold, firstTick + std::distance(startItr,secondItr));
383  }
384  }
385  }
386 
387  return;
388 }
389 
390 void WaveformTools::getFFTPower(const std::vector<float>& inputVec, std::vector<float>& outputPowerVec) const
391 {
392  std::vector<double> inputDoubleVec(inputVec.size());
393  std::vector<double> outputDoubleVec(inputVec.size()/2);
394 
395  std::copy(inputVec.begin(),inputVec.end(),inputDoubleVec.begin());
396 
397  getFFTPower(inputDoubleVec, outputDoubleVec);
398 
399  if (outputDoubleVec.size() != outputPowerVec.size()) outputPowerVec.resize(outputDoubleVec.size());
400 
401  std::copy(outputDoubleVec.begin(),outputDoubleVec.end(),outputPowerVec.begin());
402 
403  return;
404 }
405 
406 void WaveformTools::getFFTPower(const std::vector<double>& inputVec, std::vector<double>& outputPowerVec) const
407 {
408  // Get the FFT of the response
409  int fftDataSize = inputVec.size();
410 
411  TVirtualFFT* fftr2c = TVirtualFFT::FFT(1, &fftDataSize, "R2C");
412 
413  fftr2c->SetPoints(inputVec.data());
414  fftr2c->Transform();
415 
416  // Recover the results so we can compute the power spectrum
417  size_t halfFFTDataSize(fftDataSize/2 + 1);
418 
419  std::vector<double> realVals(halfFFTDataSize);
420  std::vector<double> imaginaryVals(halfFFTDataSize);
421 
422  fftr2c->GetPointsComplex(realVals.data(), imaginaryVals.data());
423 
424  if (outputPowerVec.size() != halfFFTDataSize) outputPowerVec.resize(halfFFTDataSize,0.);
425 
426  std::transform(realVals.begin(), realVals.begin() + halfFFTDataSize, imaginaryVals.begin(), outputPowerVec.begin(), [](const double& real, const double& imaginary){return std::sqrt(real*real + imaginary*imaginary);});
427 
428  return;
429 }
430 
432  int structuringElement,
433  HistogramMap& histogramMap,
434  Waveform<short>& erosionVec,
435  Waveform<short>& dilationVec,
436  Waveform<short>& averageVec,
437  Waveform<short>& differenceVec) const
438 {
439  getErosionDilationAverageDifference<short>(waveform, structuringElement, histogramMap, erosionVec, dilationVec, averageVec, differenceVec);
440 
441  return;
442 }
443 
445  int structuringElement,
446  HistogramMap& histogramMap,
447  Waveform<float>& erosionVec,
448  Waveform<float>& dilationVec,
449  Waveform<float>& averageVec,
450  Waveform<float>& differenceVec) const
451 {
452  getErosionDilationAverageDifference<float>(waveform, structuringElement, histogramMap, erosionVec, dilationVec, averageVec, differenceVec);
453 
454  return;
455 }
456 
458  int structuringElement,
459  HistogramMap& histogramMap,
460  Waveform<double>& erosionVec,
461  Waveform<double>& dilationVec,
462  Waveform<double>& averageVec,
463  Waveform<double>& differenceVec) const
464 {
465  getErosionDilationAverageDifference<double>(waveform, structuringElement, histogramMap, erosionVec, dilationVec, averageVec, differenceVec);
466 
467  return;
468 }
469 
470 template <typename T> void WaveformTools::getErosionDilationAverageDifference(const Waveform<T>& inputWaveform,
471  int structuringElement,
472  HistogramMap& histogramMap,
473  Waveform<T>& erosionVec,
474  Waveform<T>& dilationVec,
475  Waveform<T>& averageVec,
476  Waveform<T>& differenceVec) const
477 {
478  // Set the window size
479  int halfWindowSize(structuringElement/2);
480 
481  // Initialize min and max elements
483  std::minmax_element(inputWaveform.begin(),inputWaveform.begin()+halfWindowSize);
484 
485  typename Waveform<T>::const_iterator minElementItr = minMaxItr.first;
486  typename Waveform<T>::const_iterator maxElementItr = minMaxItr.second;
487 
488  // Initialize the erosion and dilation vectors
489  erosionVec.resize(inputWaveform.size());
490  dilationVec.resize(inputWaveform.size());
491  averageVec.resize(inputWaveform.size());
492  differenceVec.resize(inputWaveform.size());
493 
494  // Now loop through remaining elements and complete the vectors
495  typename Waveform<T>::iterator minItr = erosionVec.begin();
496  typename Waveform<T>::iterator maxItr = dilationVec.begin();
497  typename Waveform<T>::iterator aveItr = averageVec.begin();
498  typename Waveform<T>::iterator difItr = differenceVec.begin();
499 
500  for (typename Waveform<T>::const_iterator inputItr = inputWaveform.begin(); inputItr != inputWaveform.end(); inputItr++)
501  {
502  // There are two conditions to check:
503  // 1) is the current min/max element outside the current window?
504  // 2) is the new element smaller/larger than the current min/max?
505 
506  // Make sure we are not running off the end of the vector
507  if (std::distance(inputItr,inputWaveform.end()) > halfWindowSize)
508  {
509  if (std::distance(minElementItr,inputItr) >= halfWindowSize)
510  minElementItr = std::min_element(inputItr - halfWindowSize + 1, inputItr + halfWindowSize + 1);
511  else if (*(inputItr + halfWindowSize) < *minElementItr)
512  minElementItr = inputItr + halfWindowSize;
513 
514  if (std::distance(maxElementItr,inputItr) >= halfWindowSize)
515  maxElementItr = std::max_element(inputItr - halfWindowSize + 1, inputItr + halfWindowSize + 1);
516  else if (*(inputItr + halfWindowSize) > *maxElementItr)
517  maxElementItr = inputItr + halfWindowSize;
518  }
519 
520  // Update the vectors
521  *minItr++ = *minElementItr;
522  *maxItr++ = *maxElementItr;
523  *aveItr++ = 0.5 * (*maxElementItr + *minElementItr);
524  *difItr++ = *maxElementItr - *minElementItr;
525 
526  if (!histogramMap.empty())
527  {
528  int curBin = std::distance(inputWaveform.begin(),inputItr);
529 
530  histogramMap.at(WAVEFORM)->Fill( curBin, *inputItr);
531  histogramMap.at(EROSION)->Fill( curBin, *minElementItr);
532  histogramMap.at(DILATION)->Fill( curBin, *maxElementItr);
533  histogramMap.at(AVERAGE)->Fill( curBin, 0.5*(*maxElementItr + *minElementItr));
534  histogramMap.at(DIFFERENCE)->Fill( curBin, *maxElementItr - *minElementItr);
535  }
536 
537  }
538 
539  return;
540 }
541 
543  const Waveform<short>& dilationVec,
544  int structuringElement,
545  HistogramMap& histogramMap,
546  Waveform<short>& openingVec,
547  Waveform<short>& closingVec) const
548 {
549  getOpeningAndClosing<short>(erosionVec, dilationVec, structuringElement, histogramMap, openingVec, closingVec);
550 
551  return;
552 }
553 
555  const Waveform<float>& dilationVec,
556  int structuringElement,
557  HistogramMap& histogramMap,
558  Waveform<float>& openingVec,
559  Waveform<float>& closingVec) const
560 {
561  getOpeningAndClosing<float>(erosionVec, dilationVec, structuringElement, histogramMap, openingVec, closingVec);
562 
563  return;
564 }
565 
567  const Waveform<double>& dilationVec,
568  int structuringElement,
569  HistogramMap& histogramMap,
570  Waveform<double>& openingVec,
571  Waveform<double>& closingVec) const
572 {
573  getOpeningAndClosing<double>(erosionVec, dilationVec, structuringElement, histogramMap, openingVec, closingVec);
574 
575  return;
576 }
577 
578 template <typename T> void WaveformTools::getOpeningAndClosing(const Waveform<T>& erosionVec,
579  const Waveform<T>& dilationVec,
580  int structuringElement,
581  HistogramMap& histogramMap,
582  Waveform<T>& openingVec,
583  Waveform<T>& closingVec) const
584 {
585  // Set the window size
586  int halfWindowSize(structuringElement/2);
587 
588  // Start with the opening, here we get the max element in the input erosion vector
589  typename Waveform<T>::const_iterator maxElementItr = std::max_element(erosionVec.begin(),erosionVec.begin()+halfWindowSize);
590 
591  // Initialize the opening vector
592  openingVec.resize(erosionVec.size());
593 
594  // Now loop through remaining elements and complete the vectors
595  typename Waveform<T>::iterator maxItr = openingVec.begin();
596 
597  for (typename Waveform<T>::const_iterator inputItr = erosionVec.begin(); inputItr != erosionVec.end(); inputItr++)
598  {
599  // There are two conditions to check:
600  // 1) is the current min/max element outside the current window?
601  // 2) is the new element smaller/larger than the current min/max?
602 
603  // Make sure we are not running off the end of the vector
604  if (std::distance(inputItr,erosionVec.end()) > halfWindowSize)
605  {
606  if (std::distance(maxElementItr,inputItr) >= halfWindowSize)
607  maxElementItr = std::max_element(inputItr - halfWindowSize + 1, inputItr + halfWindowSize + 1);
608  else if (*(inputItr + halfWindowSize) > *maxElementItr)
609  maxElementItr = inputItr + halfWindowSize;
610  }
611 
612  // Update the vectors
613  *maxItr++ = *maxElementItr;
614 
615  if (!histogramMap.empty())
616  {
617  int curBin = std::distance(erosionVec.begin(),inputItr);
618 
619  histogramMap.at(OPENING)->Fill(curBin, *maxElementItr);
620  }
621  }
622 
623  // Now go with the closling, here we get the min element in the input dilation vector
624  typename Waveform<T>::const_iterator minElementItr = std::min_element(dilationVec.begin(),dilationVec.begin()+halfWindowSize);
625 
626  // Initialize the opening and closing vectors
627  closingVec.resize(dilationVec.size());
628 
629  // Now loop through remaining elements and complete the vectors
630  typename Waveform<T>::iterator minItr = closingVec.begin();
631 
632  for (typename Waveform<T>::const_iterator inputItr = dilationVec.begin(); inputItr != dilationVec.end(); inputItr++)
633  {
634  // There are two conditions to check:
635  // 1) is the current min/max element outside the current window?
636  // 2) is the new element smaller/larger than the current min/max?
637 
638  // Make sure we are not running off the end of the vector
639  if (std::distance(inputItr,dilationVec.end()) > halfWindowSize)
640  {
641  if (std::distance(minElementItr,inputItr) >= halfWindowSize)
642  minElementItr = std::min_element(inputItr - halfWindowSize + 1, inputItr + halfWindowSize + 1);
643  else if (*(inputItr + halfWindowSize) < *minElementItr)
644  minElementItr = inputItr + halfWindowSize;
645  }
646 
647  // Update the vectors
648  *minItr++ = *minElementItr;
649 
650  if (!histogramMap.empty())
651  {
652  int curBin = std::distance(dilationVec.begin(),inputItr);
653 
654  histogramMap.at(CLOSING)->Fill(curBin, *minElementItr);
655  histogramMap.at(DOPENCLOSING)->Fill(curBin, *minElementItr - openingVec.at(curBin));
656  }
657  }
658 
659  return;
660 }
661 
663 }
void medianSmooth(const std::vector< float > &, std::vector< float > &, size_t=3) const override
WaveformTools(const fhicl::ParameterSet &pset)
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:112
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:45
Utilities related to art service access.
std::tuple< size_t, size_t, size_t > PeakTuple
Definition: IWaveformTool.h:46
std::tuple< size_t, size_t, size_t > PeakTuple
void configure(const fhicl::ParameterSet &pset) override
void getErosionDilationAverageDifference(const Waveform< short > &, int, HistogramMap &, Waveform< short > &, Waveform< short > &, Waveform< short > &, Waveform< short > &) const override
std::vector< T > Waveform
Definition: IWaveformTool.h:21
intermediate_table::iterator iterator
void getOpeningAndClosing(const Waveform< short > &, const Waveform< short > &, int, HistogramMap &, Waveform< short > &, Waveform< short > &) const override
This is the interface class for tools/algorithms that perform various operations on waveforms...
void findPeaks(std::vector< float >::iterator, std::vector< float >::iterator, PeakTupleVec &, float, size_t) const override
std::vector< PeakTuple > PeakTupleVec
Definition: IWaveformTool.h:47
void triangleSmooth(const std::vector< float > &, std::vector< float > &, size_t=0) const override
Generic class for shaping signals on wires.
Int_t max
Definition: plot.C:27
intermediate_table::const_iterator const_iterator
void firstDerivative(const std::vector< float > &, std::vector< float > &) const override
void getFFTPower(const std::vector< float > &inputVec, std::vector< float > &outputPowerVec) const override
Definition of data types for geometry description.
std::map< int, TProfile * > HistogramMap
Definition: IWaveformTool.h:37
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:15
Int_t min
Definition: plot.C:26
void getTruncatedMeanRMS(const std::vector< double > &, double &, double &, double &, int &) const override
art framework interface to geometry description