LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
reco_tool::WaveformTools Class Reference
Inheritance diagram for reco_tool::WaveformTools:
reco_tool::IWaveformTool

Public Types

using PeakTuple = std::tuple< size_t, size_t, size_t >
 
using PeakTupleVec = std::vector< PeakTuple >
 

Public Member Functions

 WaveformTools (const fhicl::ParameterSet &pset)
 
 ~WaveformTools ()
 
void configure (const fhicl::ParameterSet &pset) override
 
void triangleSmooth (const std::vector< float > &, std::vector< float > &, size_t=0) const override
 
void triangleSmooth (const std::vector< double > &, std::vector< double > &, size_t=0) const override
 
void medianSmooth (const std::vector< float > &, std::vector< float > &, size_t=3) const override
 
void medianSmooth (const std::vector< double > &, std::vector< double > &, size_t=3) const override
 
void getTruncatedMeanRMS (const std::vector< double > &, double &, double &, double &, int &) const override
 
void getTruncatedMeanRMS (const std::vector< float > &, float &, float &, float &, int &) const override
 
void firstDerivative (const std::vector< float > &, std::vector< float > &) const override
 
void firstDerivative (const std::vector< double > &, std::vector< double > &) const override
 
void findPeaks (std::vector< float >::iterator, std::vector< float >::iterator, PeakTupleVec &, float, size_t) const override
 
void findPeaks (std::vector< double >::iterator, std::vector< double >::iterator, PeakTupleVec &, double, size_t) const override
 
void getFFTPower (const std::vector< float > &inputVec, std::vector< float > &outputPowerVec) const override
 
void getFFTPower (const std::vector< double > &inputVec, std::vector< double > &outputPowerVec) const override
 
void getErosionDilationAverageDifference (const Waveform< short > &, int, HistogramMap &, Waveform< short > &, Waveform< short > &, Waveform< short > &, Waveform< short > &) const override
 
void getErosionDilationAverageDifference (const Waveform< float > &, int, HistogramMap &, Waveform< float > &, Waveform< float > &, Waveform< float > &, Waveform< float > &) const override
 
void getErosionDilationAverageDifference (const Waveform< double > &, int, HistogramMap &, Waveform< double > &, Waveform< double > &, Waveform< double > &, Waveform< double > &) const override
 
void getOpeningAndClosing (const Waveform< short > &, const Waveform< short > &, int, HistogramMap &, Waveform< short > &, Waveform< short > &) const override
 
void getOpeningAndClosing (const Waveform< float > &, const Waveform< float > &, int, HistogramMap &, Waveform< float > &, Waveform< float > &) const override
 
void getOpeningAndClosing (const Waveform< double > &, const Waveform< double > &, int, HistogramMap &, Waveform< double > &, Waveform< double > &) const override
 

Private Member Functions

template<typename T >
void triangleSmooth (const std::vector< T > &, std::vector< T > &, size_t=0) const
 
template<typename T >
void medianSmooth (const std::vector< T > &, std::vector< T > &, size_t=3) const
 
template<typename T >
void getTruncatedMeanRMS (const std::vector< T > &, T &, T &, T &, int &) const
 
template<typename T >
void firstDerivative (const std::vector< T > &, std::vector< T > &) const
 
template<typename T >
void findPeaks (typename std::vector< T >::iterator, typename std::vector< T >::iterator, PeakTupleVec &, T, size_t) const
 
template<typename T >
void getErosionDilationAverageDifference (const Waveform< T > &, int, HistogramMap &, Waveform< T > &, Waveform< T > &, Waveform< T > &, Waveform< T > &) const
 
template<typename T >
void getOpeningAndClosing (const Waveform< T > &, const Waveform< T > &, int, HistogramMap &, Waveform< T > &, Waveform< T > &) const
 

Detailed Description

Definition at line 28 of file WaveformTools_tool.cc.

Member Typedef Documentation

using reco_tool::WaveformTools::PeakTuple = std::tuple<size_t,size_t,size_t>

Definition at line 37 of file WaveformTools_tool.cc.

Definition at line 38 of file WaveformTools_tool.cc.

Constructor & Destructor Documentation

reco_tool::WaveformTools::WaveformTools ( const fhicl::ParameterSet pset)
explicit

Definition at line 99 of file WaveformTools_tool.cc.

References configure().

100 {
101  configure(pset);
102 }
void configure(const fhicl::ParameterSet &pset) override
reco_tool::WaveformTools::~WaveformTools ( )
inline

Definition at line 33 of file WaveformTools_tool.cc.

References configure().

33 {}

Member Function Documentation

void reco_tool::WaveformTools::configure ( const fhicl::ParameterSet pset)
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 104 of file WaveformTools_tool.cc.

Referenced by WaveformTools(), and ~WaveformTools().

105 {
106  // Start by recovering the parameters
107 // fThisPlane = pset.get<size_t>("Plane");
108 
109  return;
110 }
void reco_tool::WaveformTools::findPeaks ( std::vector< float >::iterator  startItr,
std::vector< float >::iterator  stopItr,
PeakTupleVec peakTupleVec,
float  threshold,
size_t  firstTick 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 302 of file WaveformTools_tool.cc.

Referenced by findPeaks().

303 {
304  findPeaks<float>(startItr, stopItr, peakTupleVec, threshold, firstTick);
305 
306  return;
307 }
void reco_tool::WaveformTools::findPeaks ( std::vector< double >::iterator  startItr,
std::vector< double >::iterator  stopItr,
PeakTupleVec peakTupleVec,
double  threshold,
size_t  firstTick 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 295 of file WaveformTools_tool.cc.

296 {
297  findPeaks<double>(startItr, stopItr, peakTupleVec, threshold, firstTick);
298 
299  return;
300 }
template<typename T >
void reco_tool::WaveformTools::findPeaks ( typename std::vector< T >::iterator  startItr,
typename std::vector< T >::iterator  stopItr,
PeakTupleVec peakTupleVec,
threshold,
size_t  firstTick 
) const
private

Definition at line 309 of file WaveformTools_tool.cc.

References findPeaks(), art::left(), and art::right().

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 }
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:112
std::tuple< size_t, size_t, size_t > PeakTuple
intermediate_table::iterator iterator
void findPeaks(std::vector< float >::iterator, std::vector< float >::iterator, PeakTupleVec &, float, size_t) const override
void swap(art::HLTGlobalStatus &lhs, art::HLTGlobalStatus &rhs)
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
void reco_tool::WaveformTools::firstDerivative ( const std::vector< float > &  inputVec,
std::vector< float > &  derivVec 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 278 of file WaveformTools_tool.cc.

279 {
280  firstDerivative<float>(inputVec, derivVec);
281 
282  return;
283 }
void reco_tool::WaveformTools::firstDerivative ( const std::vector< double > &  inputVec,
std::vector< double > &  derivVec 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 271 of file WaveformTools_tool.cc.

272 {
273  firstDerivative<double>(inputVec, derivVec);
274 
275  return;
276 }
template<typename T >
void reco_tool::WaveformTools::firstDerivative ( const std::vector< T > &  inputVec,
std::vector< T > &  derivVec 
) const
private

Definition at line 285 of file WaveformTools_tool.cc.

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 }
void reco_tool::WaveformTools::getErosionDilationAverageDifference ( const Waveform< short > &  waveform,
int  structuringElement,
HistogramMap histogramMap,
Waveform< short > &  erosionVec,
Waveform< short > &  dilationVec,
Waveform< short > &  averageVec,
Waveform< short > &  differenceVec 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 431 of file WaveformTools_tool.cc.

438 {
439  getErosionDilationAverageDifference<short>(waveform, structuringElement, histogramMap, erosionVec, dilationVec, averageVec, differenceVec);
440 
441  return;
442 }
void reco_tool::WaveformTools::getErosionDilationAverageDifference ( const Waveform< float > &  waveform,
int  structuringElement,
HistogramMap histogramMap,
Waveform< float > &  erosionVec,
Waveform< float > &  dilationVec,
Waveform< float > &  averageVec,
Waveform< float > &  differenceVec 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 444 of file WaveformTools_tool.cc.

451 {
452  getErosionDilationAverageDifference<float>(waveform, structuringElement, histogramMap, erosionVec, dilationVec, averageVec, differenceVec);
453 
454  return;
455 }
void reco_tool::WaveformTools::getErosionDilationAverageDifference ( const Waveform< double > &  waveform,
int  structuringElement,
HistogramMap histogramMap,
Waveform< double > &  erosionVec,
Waveform< double > &  dilationVec,
Waveform< double > &  averageVec,
Waveform< double > &  differenceVec 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 457 of file WaveformTools_tool.cc.

464 {
465  getErosionDilationAverageDifference<double>(waveform, structuringElement, histogramMap, erosionVec, dilationVec, averageVec, differenceVec);
466 
467  return;
468 }
template<typename T >
void reco_tool::WaveformTools::getErosionDilationAverageDifference ( const Waveform< T > &  inputWaveform,
int  structuringElement,
HistogramMap histogramMap,
Waveform< T > &  erosionVec,
Waveform< T > &  dilationVec,
Waveform< T > &  averageVec,
Waveform< T > &  differenceVec 
) const
private

Definition at line 470 of file WaveformTools_tool.cc.

References reco_tool::AVERAGE, reco_tool::DIFFERENCE, reco_tool::DILATION, reco_tool::EROSION, and reco_tool::WAVEFORM.

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 }
intermediate_table::iterator iterator
intermediate_table::const_iterator const_iterator
void reco_tool::WaveformTools::getFFTPower ( const std::vector< float > &  inputVec,
std::vector< float > &  outputPowerVec 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 390 of file WaveformTools_tool.cc.

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 }
void getFFTPower(const std::vector< float > &inputVec, std::vector< float > &outputPowerVec) const override
void reco_tool::WaveformTools::getFFTPower ( const std::vector< double > &  inputVec,
std::vector< double > &  outputPowerVec 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 406 of file WaveformTools_tool.cc.

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 }
void reco_tool::WaveformTools::getOpeningAndClosing ( const Waveform< short > &  erosionVec,
const Waveform< short > &  dilationVec,
int  structuringElement,
HistogramMap histogramMap,
Waveform< short > &  openingVec,
Waveform< short > &  closingVec 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 542 of file WaveformTools_tool.cc.

548 {
549  getOpeningAndClosing<short>(erosionVec, dilationVec, structuringElement, histogramMap, openingVec, closingVec);
550 
551  return;
552 }
void reco_tool::WaveformTools::getOpeningAndClosing ( const Waveform< float > &  erosionVec,
const Waveform< float > &  dilationVec,
int  structuringElement,
HistogramMap histogramMap,
Waveform< float > &  openingVec,
Waveform< float > &  closingVec 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 554 of file WaveformTools_tool.cc.

560 {
561  getOpeningAndClosing<float>(erosionVec, dilationVec, structuringElement, histogramMap, openingVec, closingVec);
562 
563  return;
564 }
void reco_tool::WaveformTools::getOpeningAndClosing ( const Waveform< double > &  erosionVec,
const Waveform< double > &  dilationVec,
int  structuringElement,
HistogramMap histogramMap,
Waveform< double > &  openingVec,
Waveform< double > &  closingVec 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 566 of file WaveformTools_tool.cc.

572 {
573  getOpeningAndClosing<double>(erosionVec, dilationVec, structuringElement, histogramMap, openingVec, closingVec);
574 
575  return;
576 }
template<typename T >
void reco_tool::WaveformTools::getOpeningAndClosing ( const Waveform< T > &  erosionVec,
const Waveform< T > &  dilationVec,
int  structuringElement,
HistogramMap histogramMap,
Waveform< T > &  openingVec,
Waveform< T > &  closingVec 
) const
private

Definition at line 578 of file WaveformTools_tool.cc.

References reco_tool::CLOSING, DEFINE_ART_CLASS_TOOL, reco_tool::DOPENCLOSING, and reco_tool::OPENING.

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 }
intermediate_table::iterator iterator
intermediate_table::const_iterator const_iterator
void reco_tool::WaveformTools::getTruncatedMeanRMS ( const std::vector< double > &  waveform,
double &  mean,
double &  rmsFull,
double &  rmsTrunc,
int &  nTrunc 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 200 of file WaveformTools_tool.cc.

References pmtana::mean().

201 {
202  getTruncatedMeanRMS<double>(waveform, mean, rmsFull, rmsTrunc, nTrunc);
203 }
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:15
void reco_tool::WaveformTools::getTruncatedMeanRMS ( const std::vector< float > &  waveform,
float &  mean,
float &  rmsFull,
float &  rmsTrunc,
int &  nTrunc 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 205 of file WaveformTools_tool.cc.

References pmtana::mean().

206 {
207  getTruncatedMeanRMS<float>(waveform, mean, rmsFull, rmsTrunc, nTrunc);
208 }
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:15
template<typename T >
void reco_tool::WaveformTools::getTruncatedMeanRMS ( const std::vector< T > &  waveform,
T &  mean,
T &  rmsFull,
T &  rmsTrunc,
int &  nTrunc 
) const
private

Definition at line 210 of file WaveformTools_tool.cc.

References art::left(), max, min, and art::right().

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 }
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:112
intermediate_table::iterator iterator
Int_t max
Definition: plot.C:27
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 reco_tool::WaveformTools::medianSmooth ( const std::vector< float > &  inputVec,
std::vector< float > &  smoothVec,
size_t  nBins = 3 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 147 of file WaveformTools_tool.cc.

148 {
149  medianSmooth<float>(inputVec, smoothVec, nBins);
150 
151  return;
152 }
void reco_tool::WaveformTools::medianSmooth ( const std::vector< double > &  inputVec,
std::vector< double > &  smoothVec,
size_t  nBins = 3 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 154 of file WaveformTools_tool.cc.

155 {
156  medianSmooth<double>(inputVec, smoothVec, nBins);
157 
158  return;
159 }
template<typename T >
void reco_tool::WaveformTools::medianSmooth ( const std::vector< T > &  inputVec,
std::vector< T > &  smoothVec,
size_t  nBins = 3 
) const
private

Definition at line 161 of file WaveformTools_tool.cc.

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 }
intermediate_table::const_iterator const_iterator
void reco_tool::WaveformTools::triangleSmooth ( const std::vector< float > &  inputVec,
std::vector< float > &  smoothVec,
size_t  lowestBin = 0 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 119 of file WaveformTools_tool.cc.

120 {
121  triangleSmooth<float>(inputVec, smoothVec, lowestBin);
122 
123  return;
124 }
void reco_tool::WaveformTools::triangleSmooth ( const std::vector< double > &  inputVec,
std::vector< double > &  smoothVec,
size_t  lowestBin = 0 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 112 of file WaveformTools_tool.cc.

113 {
114  triangleSmooth<double>(inputVec, smoothVec, lowestBin);
115 
116  return;
117 }
template<typename T >
void reco_tool::WaveformTools::triangleSmooth ( const std::vector< T > &  inputVec,
std::vector< T > &  smoothVec,
size_t  lowestBin = 0 
) const
private

Definition at line 126 of file WaveformTools_tool.cc.

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 }
intermediate_table::iterator iterator
intermediate_table::const_iterator const_iterator

The documentation for this class was generated from the following file: