All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Private Member Functions | List of all members
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
 
- Private Member Functions inherited from reco_tool::IWaveformTool
virtual ~IWaveformTool () noexcept=default
 

Additional Inherited Members

- Private Types inherited from reco_tool::IWaveformTool
using PeakTuple = std::tuple< size_t, size_t, size_t >
 
using PeakTupleVec = std::vector< PeakTuple >
 

Detailed Description

Definition at line 17 of file WaveformTools_tool.cc.

Member Typedef Documentation

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

Definition at line 26 of file WaveformTools_tool.cc.

Definition at line 27 of file WaveformTools_tool.cc.

Constructor & Destructor Documentation

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

Definition at line 88 of file WaveformTools_tool.cc.

89 {
90  configure(pset);
91 }
void configure(const fhicl::ParameterSet &pset) override
reco_tool::WaveformTools::~WaveformTools ( )
inline

Definition at line 22 of file WaveformTools_tool.cc.

22 {}

Member Function Documentation

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

Implements reco_tool::IWaveformTool.

Definition at line 93 of file WaveformTools_tool.cc.

94 {
95  // Start by recovering the parameters
96 // fThisPlane = pset.get<size_t>("Plane");
97 
98  return;
99 }
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 297 of file WaveformTools_tool.cc.

298 {
299  findPeaks<float>(startItr, stopItr, peakTupleVec, threshold, firstTick);
300 
301  return;
302 }
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 290 of file WaveformTools_tool.cc.

291 {
292  findPeaks<double>(startItr, stopItr, peakTupleVec, threshold, firstTick);
293 
294  return;
295 }
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 304 of file WaveformTools_tool.cc.

309 {
310  // Need a minimum distance or else nothing to do
311  if (std::distance(startItr,stopItr) > 4)
312  {
313  // This is a divide and conquer algorithm, start by finding the maximum element.
314  typename std::vector<T>::iterator firstItr = std::max_element(startItr,stopItr,[](float left, float right){return std::fabs(left) < std::fabs(right);});
315 
316  // Are we over threshold?
317  if (std::fabs(*firstItr) > threshold)
318  {
319  // What am I thinking?
320  // First task is to find the "other" lobe max point
321  // Set one to the "first", the other to the "second"
322  // Search backward from first to find start point, forward from second to find end point
323  // Set mid point between first and second as "peak"?
324  typename std::vector<T>::iterator secondItr = firstItr;
325 
326  // Assume if max bin is positive then second lobe is later
327  if (*firstItr > 0)
328  {
329  typename std::vector<T>::iterator tempItr = secondItr;
330 
331  while(tempItr != stopItr)
332  {
333  if (*++tempItr < -threshold)
334  {
335  if (*tempItr < *secondItr) secondItr = tempItr;
336  }
337  else if (secondItr != firstItr) break;
338  }
339  }
340  // Otherwise it goes the other way
341  else
342  {
343  typename std::vector<T>::iterator tempItr = secondItr;
344 
345  while(tempItr != startItr)
346  {
347  if (*--tempItr > threshold)
348  {
349  if (*tempItr > *secondItr) secondItr = tempItr;
350  }
351  else if (secondItr != firstItr) break;
352  }
353 
354  std::swap(firstItr,secondItr);
355  }
356 
357  // It might that no real pulse was found
358  if (firstItr != secondItr)
359  {
360  // Get the "peak" position
361  size_t peakBin = std::distance(startItr,firstItr) + std::distance(firstItr,secondItr) / 2;
362 
363  // Advance (forward or backward) the first and second iterators to get back to zero crossing
364  while(firstItr != startItr) if (*--firstItr < 0.) break;
365  while(secondItr != stopItr) if (*++secondItr > 0.) break;
366 
367  size_t firstBin = std::distance(startItr,firstItr);
368  size_t lastBin = std::distance(startItr,secondItr);
369 
370  // Find leading peaks
371  findPeaks(startItr, firstItr, peakTupleVec, threshold, firstTick);
372 
373  // Save this peak
374  peakTupleVec.push_back(PeakTuple(firstBin+firstTick,peakBin+firstTick,lastBin+firstTick));
375 
376  // Find downstream peaks
377  findPeaks(secondItr, stopItr, peakTupleVec, threshold, firstTick + std::distance(startItr,secondItr));
378  }
379  }
380  }
381 
382  return;
383 }
std::tuple< size_t, size_t, size_t > PeakTuple
walls no right
Definition: selectors.fcl:105
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
walls no left
Definition: selectors.fcl:105
void findPeaks(std::vector< float >::iterator, std::vector< float >::iterator, PeakTupleVec &, float, size_t) const override
void reco_tool::WaveformTools::firstDerivative ( const std::vector< float > &  inputVec,
std::vector< float > &  derivVec 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 273 of file WaveformTools_tool.cc.

274 {
275  firstDerivative<float>(inputVec, derivVec);
276 
277  return;
278 }
void reco_tool::WaveformTools::firstDerivative ( const std::vector< double > &  inputVec,
std::vector< double > &  derivVec 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 266 of file WaveformTools_tool.cc.

267 {
268  firstDerivative<double>(inputVec, derivVec);
269 
270  return;
271 }
template<typename T >
void reco_tool::WaveformTools::firstDerivative ( const std::vector< T > &  inputVec,
std::vector< T > &  derivVec 
) const
private

Definition at line 280 of file WaveformTools_tool.cc.

281 {
282  derivVec.resize(inputVec.size(), 0.);
283 
284  for(size_t idx = 1; idx < derivVec.size() - 1; idx++)
285  derivVec.at(idx) = 0.5 * (inputVec.at(idx + 1) - inputVec.at(idx - 1));
286 
287  return;
288 }
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 426 of file WaveformTools_tool.cc.

433 {
434  getErosionDilationAverageDifference<short>(waveform, structuringElement, histogramMap, erosionVec, dilationVec, averageVec, differenceVec);
435 
436  return;
437 }
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 439 of file WaveformTools_tool.cc.

446 {
447  getErosionDilationAverageDifference<float>(waveform, structuringElement, histogramMap, erosionVec, dilationVec, averageVec, differenceVec);
448 
449  return;
450 }
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 452 of file WaveformTools_tool.cc.

459 {
460  getErosionDilationAverageDifference<double>(waveform, structuringElement, histogramMap, erosionVec, dilationVec, averageVec, differenceVec);
461 
462  return;
463 }
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 465 of file WaveformTools_tool.cc.

472 {
473  // Set the window size
474  int halfWindowSize(structuringElement/2);
475 
476  // Initialize min and max elements
477  std::pair<typename Waveform<T>::const_iterator,typename Waveform<T>::const_iterator> minMaxItr =
478  std::minmax_element(inputWaveform.begin(),inputWaveform.begin()+halfWindowSize);
479 
480  typename Waveform<T>::const_iterator minElementItr = minMaxItr.first;
481  typename Waveform<T>::const_iterator maxElementItr = minMaxItr.second;
482 
483  // Initialize the erosion and dilation vectors
484  erosionVec.resize(inputWaveform.size());
485  dilationVec.resize(inputWaveform.size());
486  averageVec.resize(inputWaveform.size());
487  differenceVec.resize(inputWaveform.size());
488 
489  // Now loop through remaining elements and complete the vectors
490  typename Waveform<T>::iterator minItr = erosionVec.begin();
491  typename Waveform<T>::iterator maxItr = dilationVec.begin();
492  typename Waveform<T>::iterator aveItr = averageVec.begin();
493  typename Waveform<T>::iterator difItr = differenceVec.begin();
494 
495  for (typename Waveform<T>::const_iterator inputItr = inputWaveform.begin(); inputItr != inputWaveform.end(); inputItr++)
496  {
497  // There are two conditions to check:
498  // 1) is the current min/max element outside the current window?
499  // 2) is the new element smaller/larger than the current min/max?
500 
501  // Make sure we are not running off the end of the vector
502  if (std::distance(inputItr,inputWaveform.end()) > halfWindowSize)
503  {
504  if (std::distance(minElementItr,inputItr) >= halfWindowSize)
505  minElementItr = std::min_element(inputItr - halfWindowSize + 1, inputItr + halfWindowSize + 1);
506  else if (*(inputItr + halfWindowSize) < *minElementItr)
507  minElementItr = inputItr + halfWindowSize;
508 
509  if (std::distance(maxElementItr,inputItr) >= halfWindowSize)
510  maxElementItr = std::max_element(inputItr - halfWindowSize + 1, inputItr + halfWindowSize + 1);
511  else if (*(inputItr + halfWindowSize) > *maxElementItr)
512  maxElementItr = inputItr + halfWindowSize;
513  }
514 
515  // Update the vectors
516  *minItr++ = *minElementItr;
517  *maxItr++ = *maxElementItr;
518  *aveItr++ = 0.5 * (*maxElementItr + *minElementItr);
519  *difItr++ = *maxElementItr - *minElementItr;
520 
521  if (!histogramMap.empty())
522  {
523  int curBin = std::distance(inputWaveform.begin(),inputItr);
524 
525  histogramMap.at(WAVEFORM)->Fill( curBin, *inputItr);
526  histogramMap.at(EROSION)->Fill( curBin, *minElementItr);
527  histogramMap.at(DILATION)->Fill( curBin, *maxElementItr);
528  histogramMap.at(AVERAGE)->Fill( curBin, 0.5*(*maxElementItr + *minElementItr));
529  histogramMap.at(DIFFERENCE)->Fill( curBin, *maxElementItr - *minElementItr);
530  }
531 
532  }
533 
534  return;
535 }
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
void reco_tool::WaveformTools::getFFTPower ( const std::vector< float > &  inputVec,
std::vector< float > &  outputPowerVec 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 385 of file WaveformTools_tool.cc.

386 {
387  std::vector<double> inputDoubleVec(inputVec.size());
388  std::vector<double> outputDoubleVec(inputVec.size()/2);
389 
390  std::copy(inputVec.begin(),inputVec.end(),inputDoubleVec.begin());
391 
392  getFFTPower(inputDoubleVec, outputDoubleVec);
393 
394  if (outputDoubleVec.size() != outputPowerVec.size()) outputPowerVec.resize(outputDoubleVec.size());
395 
396  std::copy(outputDoubleVec.begin(),outputDoubleVec.end(),outputPowerVec.begin());
397 
398  return;
399 }
void getFFTPower(const std::vector< float > &inputVec, std::vector< float > &outputPowerVec) const override
T copy(T const &v)
void reco_tool::WaveformTools::getFFTPower ( const std::vector< double > &  inputVec,
std::vector< double > &  outputPowerVec 
) const
overridevirtual

Implements reco_tool::IWaveformTool.

Definition at line 401 of file WaveformTools_tool.cc.

402 {
403  // Get the FFT of the response
404  int fftDataSize = inputVec.size();
405 
406  TVirtualFFT* fftr2c = TVirtualFFT::FFT(1, &fftDataSize, "R2C");
407 
408  fftr2c->SetPoints(inputVec.data());
409  fftr2c->Transform();
410 
411  // Recover the results so we can compute the power spectrum
412  size_t halfFFTDataSize(fftDataSize/2 + 1);
413 
414  std::vector<double> realVals(halfFFTDataSize);
415  std::vector<double> imaginaryVals(halfFFTDataSize);
416 
417  fftr2c->GetPointsComplex(realVals.data(), imaginaryVals.data());
418 
419  if (outputPowerVec.size() != halfFFTDataSize) outputPowerVec.resize(halfFFTDataSize,0.);
420 
421  std::transform(realVals.begin(), realVals.begin() + halfFFTDataSize, imaginaryVals.begin(), outputPowerVec.begin(), [](const double& real, const double& imaginary){return std::sqrt(real*real + imaginary*imaginary);});
422 
423  return;
424 }
static constexpr Sample_t transform(Sample_t sample)
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 537 of file WaveformTools_tool.cc.

543 {
544  getOpeningAndClosing<short>(erosionVec, dilationVec, structuringElement, histogramMap, openingVec, closingVec);
545 
546  return;
547 }
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 549 of file WaveformTools_tool.cc.

555 {
556  getOpeningAndClosing<float>(erosionVec, dilationVec, structuringElement, histogramMap, openingVec, closingVec);
557 
558  return;
559 }
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 561 of file WaveformTools_tool.cc.

567 {
568  getOpeningAndClosing<double>(erosionVec, dilationVec, structuringElement, histogramMap, openingVec, closingVec);
569 
570  return;
571 }
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 573 of file WaveformTools_tool.cc.

579 {
580  // Set the window size
581  int halfWindowSize(structuringElement/2);
582 
583  // Start with the opening, here we get the max element in the input erosion vector
584  typename Waveform<T>::const_iterator maxElementItr = std::max_element(erosionVec.begin(),erosionVec.begin()+halfWindowSize);
585 
586  // Initialize the opening vector
587  openingVec.resize(erosionVec.size());
588 
589  // Now loop through remaining elements and complete the vectors
590  typename Waveform<T>::iterator maxItr = openingVec.begin();
591 
592  for (typename Waveform<T>::const_iterator inputItr = erosionVec.begin(); inputItr != erosionVec.end(); inputItr++)
593  {
594  // There are two conditions to check:
595  // 1) is the current min/max element outside the current window?
596  // 2) is the new element smaller/larger than the current min/max?
597 
598  // Make sure we are not running off the end of the vector
599  if (std::distance(inputItr,erosionVec.end()) > halfWindowSize)
600  {
601  if (std::distance(maxElementItr,inputItr) >= halfWindowSize)
602  maxElementItr = std::max_element(inputItr - halfWindowSize + 1, inputItr + halfWindowSize + 1);
603  else if (*(inputItr + halfWindowSize) > *maxElementItr)
604  maxElementItr = inputItr + halfWindowSize;
605  }
606 
607  // Update the vectors
608  *maxItr++ = *maxElementItr;
609 
610  if (!histogramMap.empty())
611  {
612  int curBin = std::distance(erosionVec.begin(),inputItr);
613 
614  histogramMap.at(OPENING)->Fill(curBin, *maxElementItr);
615  }
616  }
617 
618  // Now go with the closling, here we get the min element in the input dilation vector
619  typename Waveform<T>::const_iterator minElementItr = std::min_element(dilationVec.begin(),dilationVec.begin()+halfWindowSize);
620 
621  // Initialize the opening and closing vectors
622  closingVec.resize(dilationVec.size());
623 
624  // Now loop through remaining elements and complete the vectors
625  typename Waveform<T>::iterator minItr = closingVec.begin();
626 
627  for (typename Waveform<T>::const_iterator inputItr = dilationVec.begin(); inputItr != dilationVec.end(); inputItr++)
628  {
629  // There are two conditions to check:
630  // 1) is the current min/max element outside the current window?
631  // 2) is the new element smaller/larger than the current min/max?
632 
633  // Make sure we are not running off the end of the vector
634  if (std::distance(inputItr,dilationVec.end()) > halfWindowSize)
635  {
636  if (std::distance(minElementItr,inputItr) >= halfWindowSize)
637  minElementItr = std::min_element(inputItr - halfWindowSize + 1, inputItr + halfWindowSize + 1);
638  else if (*(inputItr + halfWindowSize) < *minElementItr)
639  minElementItr = inputItr + halfWindowSize;
640  }
641 
642  // Update the vectors
643  *minItr++ = *minElementItr;
644 
645  if (!histogramMap.empty())
646  {
647  int curBin = std::distance(dilationVec.begin(),inputItr);
648 
649  histogramMap.at(CLOSING)->Fill(curBin, *minElementItr);
650  histogramMap.at(DOPENCLOSING)->Fill(curBin, *minElementItr - openingVec.at(curBin));
651  }
652  }
653 
654  return;
655 }
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
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 195 of file WaveformTools_tool.cc.

196 {
197  getTruncatedMeanRMS<double>(waveform, mean, rmsFull, rmsTrunc, nTrunc);
198 }
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:13
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 200 of file WaveformTools_tool.cc.

201 {
202  getTruncatedMeanRMS<float>(waveform, mean, rmsFull, rmsTrunc, nTrunc);
203 }
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:13
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 205 of file WaveformTools_tool.cc.

206 {
207  // We need to get a reliable estimate of the mean and can't assume the input waveform will be ~zero mean...
208  // Basic idea is to find the most probable value in the ROI presented to us
209  // From that we can develop an average of the true baseline of the ROI.
210  // To do that we employ a map based scheme
211  std::map<int,int> frequencyMap;
212  int mpCount(0);
213  int mpVal(0);
214 
215  for(const auto& val : waveform)
216  {
217  int intVal = std::round(4.*val);
218 
219  frequencyMap[intVal]++;
220 
221  if (frequencyMap.at(intVal) > mpCount)
222  {
223  mpCount = frequencyMap.at(intVal);
224  mpVal = intVal;
225  }
226  }
227 
228  // take a weighted average of two neighbor bins
229  int meanCnt = 0;
230  int meanSum = 0;
231  int binRange = std::min(16, int(frequencyMap.size()/2 + 1));
232 
233  for(int idx = -binRange; idx <= binRange; idx++)
234  {
235  std::map<int,int>::iterator neighborItr = frequencyMap.find(mpVal+idx);
236 
237  if (neighborItr != frequencyMap.end() && 5 * neighborItr->second > mpCount)
238  {
239  meanSum += neighborItr->first * neighborItr->second;
240  meanCnt += neighborItr->second;
241  }
242  }
243 
244  mean = 0.25 * T(meanSum) / T(meanCnt); // Note that bins were expanded by a factor of 4 above
245 
246  // do rms calculation - the old fashioned way and over all adc values
247  typename std::vector<T> locWaveform = waveform;
248 
249  std::transform(locWaveform.begin(), locWaveform.end(), locWaveform.begin(),std::bind(std::minus<T>(),std::placeholders::_1,mean));
250 
251  // sort in ascending order so we can truncate the sume
252  std::sort(locWaveform.begin(), locWaveform.end(),[](const auto& left, const auto& right){return std::fabs(left) < std::fabs(right);});
253 
254  // recalculate the rms for truncation
255  rmsFull = std::inner_product(locWaveform.begin(), locWaveform.end(), locWaveform.begin(), 0.);
256  rmsFull = std::sqrt(std::max(T(0.),rmsFull / T(locWaveform.size())));
257 
258  // recalculate the rms for truncation
259  rmsTrunc = std::inner_product(locWaveform.begin(), locWaveform.begin() + meanCnt, locWaveform.begin(), 0.);
260  rmsTrunc = std::sqrt(std::max(T(0.),rmsTrunc / T(meanCnt)));
261  nTrunc = meanCnt;
262 
263  return;
264 }
static constexpr Sample_t transform(Sample_t sample)
walls no right
Definition: selectors.fcl:105
walls no left
Definition: selectors.fcl:105
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:13
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 142 of file WaveformTools_tool.cc.

143 {
144  medianSmooth<float>(inputVec, smoothVec, nBins);
145 
146  return;
147 }
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 149 of file WaveformTools_tool.cc.

150 {
151  medianSmooth<double>(inputVec, smoothVec, nBins);
152 
153  return;
154 }
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 156 of file WaveformTools_tool.cc.

157 {
158  // For our purposes, nBins must be odd
159  if (nBins % 2 == 0) nBins++;
160 
161  // Make sure the input vector is right sized
162  if (inputVec.size() != smoothVec.size()) smoothVec.resize(inputVec.size());
163 
164  // Basic set up
165  typename std::vector<T> medianVec(nBins);
166  typename std::vector<T>::const_iterator startItr = inputVec.begin();
167  typename std::vector<T>::const_iterator stopItr = startItr;
168 
169  std::advance(stopItr, inputVec.size() - nBins);
170 
171  size_t medianBin = nBins/2;
172  size_t smoothBin = medianBin;
173 
174  // First bins are not smoothed
175  std::copy(startItr, startItr + medianBin, smoothVec.begin());
176 
177  while(std::distance(startItr,stopItr) > 0)
178  {
179  std::copy(startItr,startItr+nBins,medianVec.begin());
180  std::sort(medianVec.begin(),medianVec.end());
181 
182  T medianVal = medianVec[medianBin];
183 
184  smoothVec[smoothBin++] = medianVal;
185 
186  startItr++;
187  }
188 
189  // Last bins are not smoothed
190  std::copy(startItr + medianBin, inputVec.end(), smoothVec.begin() + smoothBin);
191 
192  return;
193 }
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
T copy(T const &v)
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 108 of file WaveformTools_tool.cc.

109 {
110  triangleSmooth<float>(inputVec, smoothVec, lowestBin);
111 
112  return;
113 }
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 101 of file WaveformTools_tool.cc.

102 {
103  triangleSmooth<double>(inputVec, smoothVec, lowestBin);
104 
105  return;
106 }
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 115 of file WaveformTools_tool.cc.

116 {
117  if (inputVec.size() != smoothVec.size()) smoothVec.resize(inputVec.size());
118 
119  // Watch for edge condition
120  if (inputVec.size() > 4)
121  {
122  std::copy(inputVec.begin(), inputVec.begin() + 2 + lowestBin, smoothVec.begin());
123  std::copy(inputVec.end() - 2, inputVec.end(), smoothVec.end() - 2);
124 
125  typename std::vector<T>::iterator curItr = smoothVec.begin() + 2 + lowestBin;
126  typename std::vector<T>::const_iterator curInItr = inputVec.begin() + 1 + lowestBin;
127  typename std::vector<T>::const_iterator stopInItr = inputVec.end() - 3;
128 
129  while(curInItr++ != stopInItr)
130  {
131  // Take the weighted average of five consecutive points centered on current point
132  T newVal = (*(curInItr - 2) + 2. * *(curInItr - 1) + 3. * *curInItr + 2. * *(curInItr + 1) + *(curInItr + 2)) / 9.;
133 
134  *curItr++ = newVal;
135  }
136  }
137  else std::copy(inputVec.begin(), inputVec.end(), smoothVec.begin());
138 
139  return;
140 }
T copy(T const &v)

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