LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
hit::RFFHitFitter Class Reference

#include "RFFHitFitter.h"

Public Member Functions

 RFFHitFitter (float, unsigned int, float, float step=0.1, float max=5.0)
 
 RFFHitFitter (float step=0.1, float max=5.0)
 
void SetFitterParams (float, unsigned int, float)
 
void RunFitter (const std::vector< float > &signal)
 
const std::vector< float > & MeanVector ()
 
const std::vector< float > & SigmaVector ()
 
const std::vector< float > & MeanErrorVector ()
 
const std::vector< float > & SigmaErrorVector ()
 
const std::vector< float > & AmplitudeVector ()
 
const std::vector< float > & AmplitudeErrorVector ()
 
unsigned int NHits ()
 
void ClearResults ()
 
void PrintResults ()
 

Private Types

typedef std::pair< float, float > MeanSigmaPair
 

Private Member Functions

void CalculateAllMeansAndSigmas (const std::vector< float > &signal)
 
void CalculateMergedMeansAndSigmas (std::size_t signal_size)
 
void CalculateAmplitudes (const std::vector< float > &signal)
 
void CreateMergeVector ()
 
bool HitsBelowThreshold ()
 

Private Attributes

float fMeanMatchThreshold
 
unsigned int fMinMergeMultiplicity
 
float fFinalAmpThreshold
 
util::GaussianEliminationAlg fGEAlg
 
std::vector< float > fMeanVector
 
std::vector< float > fSigmaVector
 
std::vector< float > fMeanErrorVector
 
std::vector< float > fSigmaErrorVector
 
std::vector< float > fAmpVector
 
std::vector< float > fAmpErrorVector
 
std::multiset< MeanSigmaPair, SignalSetCompfSignalSet
 
std::vector< std::vector< std::multiset< MeanSigmaPair >::iterator > > fMergeVector
 

Detailed Description

Definition at line 32 of file RFFHitFitter.h.

Member Typedef Documentation

typedef std::pair<float, float> hit::RFFHitFitter::MeanSigmaPair
private

Definition at line 34 of file RFFHitFitter.h.

Constructor & Destructor Documentation

hit::RFFHitFitter::RFFHitFitter ( float  max_mean,
unsigned int  min_multi,
float  threshold,
float  step = 0.1,
float  max = 5.0 
)

Definition at line 22 of file RFFHitFitter.cxx.

References SetFitterParams().

27  : fGEAlg(step, max)
28 {
29  SetFitterParams(max_mean, min_multi, threshold);
30 }
void SetFitterParams(float, unsigned int, float)
util::GaussianEliminationAlg fGEAlg
Definition: RFFHitFitter.h:64
hit::RFFHitFitter::RFFHitFitter ( float  step = 0.1,
float  max = 5.0 
)

Title: RFFHitFitter Class Author: Wes Ketchum (wketc.nosp@m.hum@.nosp@m.lanl..nosp@m.gov)

Description: Class that does the base RFF algorithm. RFF works by simplifiying a Gaussian fit by dividing a pulse by its derivative. for a Gaussian, the result is a line, with the slope and intercept related to the sigma and mean of the Gaussian.

Input: Signal (vector of floats) Output: Guassian means and sigmas

Definition at line 20 of file RFFHitFitter.cxx.

20 : fGEAlg(step, max) {}
util::GaussianEliminationAlg fGEAlg
Definition: RFFHitFitter.h:64

Member Function Documentation

const std::vector<float>& hit::RFFHitFitter::AmplitudeErrorVector ( )
inline

Definition at line 49 of file RFFHitFitter.h.

Referenced by hit::RFFHitFinderAlg::EmplaceHit().

49 { return fAmpErrorVector; }
std::vector< float > fAmpErrorVector
Definition: RFFHitFitter.h:71
const std::vector<float>& hit::RFFHitFitter::AmplitudeVector ( )
inline

Definition at line 48 of file RFFHitFitter.h.

Referenced by hit::RFFHitFinderAlg::EmplaceHit().

48 { return fAmpVector; }
std::vector< float > fAmpVector
Definition: RFFHitFitter.h:70
void hit::RFFHitFitter::CalculateAllMeansAndSigmas ( const std::vector< float > &  signal)
private

Definition at line 53 of file RFFHitFitter.cxx.

References fSignalSet, and pmtana::mean().

Referenced by RunFitter().

54 {
55  if (signal.size() <= 2) return;
56 
57  float prev_dev = 0, this_dev = 0;
58  ;
59  float slope = 0;
60  float sigma = 0;
61  float intercept = 0;
62  float mean = 0;
63 
64  for (size_t i_tick = 1; i_tick < signal.size() - 1; i_tick++) {
65  this_dev = 0.5 * (signal[i_tick + 1] - signal[i_tick - 1]) / signal[i_tick];
66  slope = this_dev - prev_dev;
67 
68  prev_dev = this_dev;
69 
70  if (slope >= 0) continue;
71 
72  sigma = std::sqrt(-1 / slope);
73  intercept = 0.5 * (signal[i_tick + 1] - signal[i_tick - 1]) / signal[i_tick] - slope * i_tick;
74  mean = -1 * intercept / slope;
75 
76  fSignalSet.insert(std::make_pair(mean, sigma));
77  }
78 }
std::multiset< MeanSigmaPair, SignalSetComp > fSignalSet
Definition: RFFHitFitter.h:73
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:13
void hit::RFFHitFitter::CalculateAmplitudes ( const std::vector< float > &  signal)
private

Definition at line 138 of file RFFHitFitter.cxx.

References bin, fAmpErrorVector, fAmpVector, fFinalAmpThreshold, fGEAlg, fMeanErrorVector, fMeanVector, fSigmaErrorVector, fSigmaVector, HitsBelowThreshold(), and util::GaussianEliminationAlg::SolveEquations().

Referenced by RunFitter().

139 {
140  std::vector<float> heightVector(fMeanVector.size());
141  size_t bin = 0;
142 
143  for (size_t i = 0; i < fMeanVector.size(); i++) {
144  if (fMeanVector[i] < 0)
145  bin = 0;
146  else if (fMeanVector[i] + 1 > signal.size())
147  bin = signal.size() - 2;
148  else
149  bin = std::floor(fMeanVector[i]);
150 
151  if (bin >= signal.size() - 1)
152  throw cet::exception("RFFHitFitter")
153  << "Error in CalculatAmplitudes! bin is out of range!\n"
154  << "\tFor element " << i << " bin is " << bin << "(" << fMeanVector[i] << ")"
155  << " but size is " << signal.size() << ".\n";
156 
157  heightVector[i] = signal[bin] - (fMeanVector[i] - (float)bin) * (signal[bin] - signal[bin + 1]);
158  }
159 
161 
162  while (HitsBelowThreshold()) {
163  for (size_t i = 0; i < fAmpVector.size(); i++) {
164  if (fAmpVector[i] < fFinalAmpThreshold) {
165  fMeanVector.erase(fMeanVector.begin() + i);
166  fMeanErrorVector.erase(fMeanErrorVector.begin() + i);
167  fSigmaVector.erase(fSigmaVector.begin() + i);
168  fSigmaErrorVector.erase(fSigmaErrorVector.begin() + i);
169  fAmpVector.erase(fAmpVector.begin() + i);
170  heightVector.erase(heightVector.begin() + i);
171  }
172  }
174  }
175 
176  fAmpErrorVector.resize(fAmpVector.size(), 0.0);
177 }
std::vector< float > fAmpErrorVector
Definition: RFFHitFitter.h:71
std::vector< float > fSigmaVector
Definition: RFFHitFitter.h:67
util::GaussianEliminationAlg fGEAlg
Definition: RFFHitFitter.h:64
float fFinalAmpThreshold
Definition: RFFHitFitter.h:59
const std::vector< float > & SolveEquations(const std::vector< float > &meanVector, const std::vector< float > &sigmaVector, const std::vector< float > &heightVector)
float bin[41]
Definition: plottest35.C:14
std::vector< float > fAmpVector
Definition: RFFHitFitter.h:70
std::vector< float > fSigmaErrorVector
Definition: RFFHitFitter.h:69
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::vector< float > fMeanVector
Definition: RFFHitFitter.h:66
std::vector< float > fMeanErrorVector
Definition: RFFHitFitter.h:68
void hit::RFFHitFitter::CalculateMergedMeansAndSigmas ( std::size_t  signal_size)
private

Definition at line 96 of file RFFHitFitter.cxx.

References fMeanErrorVector, fMeanVector, fMergeVector, fMinMergeMultiplicity, fSigmaErrorVector, fSigmaVector, and util::size().

Referenced by RunFitter().

97 {
98  fMeanVector.reserve(fMergeVector.size());
99  fSigmaVector.reserve(fMergeVector.size());
100  fMeanErrorVector.reserve(fMergeVector.size());
101  fSigmaErrorVector.reserve(fMergeVector.size());
102 
103  for (size_t i_col = 0; i_col < fMergeVector.size(); i_col++) {
104  if (fMergeVector[i_col].size() < fMinMergeMultiplicity) continue;
105 
106  fMeanVector.push_back(0.0);
107  fSigmaVector.push_back(0.0);
108 
109  for (auto const& sigpair : fMergeVector[i_col]) {
110  fMeanVector.back() += sigpair->first;
111  fSigmaVector.back() += sigpair->second;
112  }
113 
114  fMeanVector.back() /= fMergeVector[i_col].size();
115  fSigmaVector.back() /= fMergeVector[i_col].size();
116 
117  if (fMeanVector.back() < 0 || fMeanVector.back() > signal_size - 1) {
118  fMeanVector.pop_back();
119  fSigmaVector.pop_back();
120  continue;
121  }
122 
123  fMeanErrorVector.push_back(0.0);
124  fSigmaErrorVector.push_back(0.0);
125 
126  for (auto const& sigpair : fMergeVector[i_col]) {
127  fMeanErrorVector.back() +=
128  (sigpair->first - fMeanVector.back()) * (sigpair->first - fMeanVector.back());
129  fSigmaErrorVector.back() +=
130  (sigpair->second - fSigmaVector.back()) * (sigpair->second - fSigmaVector.back());
131  }
132 
133  fMeanErrorVector.back() = std::sqrt(fMeanErrorVector.back()) / fMergeVector[i_col].size();
134  fSigmaErrorVector.back() = std::sqrt(fSigmaErrorVector.back()) / fMergeVector[i_col].size();
135  }
136 }
unsigned int fMinMergeMultiplicity
Definition: RFFHitFitter.h:58
std::vector< std::vector< std::multiset< MeanSigmaPair >::iterator > > fMergeVector
Definition: RFFHitFitter.h:74
std::vector< float > fSigmaVector
Definition: RFFHitFitter.h:67
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
std::vector< float > fSigmaErrorVector
Definition: RFFHitFitter.h:69
std::vector< float > fMeanVector
Definition: RFFHitFitter.h:66
std::vector< float > fMeanErrorVector
Definition: RFFHitFitter.h:68
void hit::RFFHitFitter::ClearResults ( )

Definition at line 186 of file RFFHitFitter.cxx.

References fAmpErrorVector, fAmpVector, fMeanErrorVector, fMeanVector, fMergeVector, fSigmaErrorVector, fSigmaVector, and fSignalSet.

Referenced by RunFitter(), and SetFitterParams().

187 {
188  fMeanVector.clear();
189  fSigmaVector.clear();
190  fMeanErrorVector.clear();
191  fSigmaErrorVector.clear();
192  fAmpVector.clear();
193  fAmpErrorVector.clear();
194  fSignalSet.clear();
195  fMergeVector.clear();
196 }
std::vector< float > fAmpErrorVector
Definition: RFFHitFitter.h:71
std::vector< std::vector< std::multiset< MeanSigmaPair >::iterator > > fMergeVector
Definition: RFFHitFitter.h:74
std::vector< float > fSigmaVector
Definition: RFFHitFitter.h:67
std::multiset< MeanSigmaPair, SignalSetComp > fSignalSet
Definition: RFFHitFitter.h:73
std::vector< float > fAmpVector
Definition: RFFHitFitter.h:70
std::vector< float > fSigmaErrorVector
Definition: RFFHitFitter.h:69
std::vector< float > fMeanVector
Definition: RFFHitFitter.h:66
std::vector< float > fMeanErrorVector
Definition: RFFHitFitter.h:68
void hit::RFFHitFitter::CreateMergeVector ( )
private

Definition at line 80 of file RFFHitFitter.cxx.

References util::abs(), fMeanMatchThreshold, fMergeVector, fSignalSet, and lar::dump::vector().

Referenced by RunFitter().

81 {
82  fMergeVector.clear();
83  fMergeVector.reserve(fSignalSet.size());
84 
85  float prev_mean = -9e6;
86  for (std::multiset<MeanSigmaPair>::iterator it = fSignalSet.begin(); it != fSignalSet.end();
87  it++) {
88  if (std::abs(it->first - prev_mean) > fMeanMatchThreshold || fMergeVector.size() == 0)
90  else
91  fMergeVector.back().push_back(it);
92  prev_mean = it->first;
93  }
94 }
intermediate_table::iterator iterator
std::vector< std::vector< std::multiset< MeanSigmaPair >::iterator > > fMergeVector
Definition: RFFHitFitter.h:74
constexpr auto abs(T v)
Returns the absolute value of the argument.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
std::multiset< MeanSigmaPair, SignalSetComp > fSignalSet
Definition: RFFHitFitter.h:73
float fMeanMatchThreshold
Definition: RFFHitFitter.h:57
bool hit::RFFHitFitter::HitsBelowThreshold ( )
private

Definition at line 179 of file RFFHitFitter.cxx.

References fAmpVector, and fFinalAmpThreshold.

Referenced by CalculateAmplitudes().

180 {
181  for (auto const& amp : fAmpVector)
182  if (amp < fFinalAmpThreshold) return true;
183  return false;
184 }
float fFinalAmpThreshold
Definition: RFFHitFitter.h:59
std::vector< float > fAmpVector
Definition: RFFHitFitter.h:70
const std::vector<float>& hit::RFFHitFitter::MeanErrorVector ( )
inline

Definition at line 46 of file RFFHitFitter.h.

Referenced by hit::RFFHitFinderAlg::EmplaceHit().

46 { return fMeanErrorVector; }
std::vector< float > fMeanErrorVector
Definition: RFFHitFitter.h:68
const std::vector<float>& hit::RFFHitFitter::MeanVector ( )
inline

Definition at line 44 of file RFFHitFitter.h.

Referenced by hit::RFFHitFinderAlg::EmplaceHit().

44 { return fMeanVector; }
std::vector< float > fMeanVector
Definition: RFFHitFitter.h:66
unsigned int hit::RFFHitFitter::NHits ( )
inline

Definition at line 50 of file RFFHitFitter.h.

Referenced by hit::RFFHitFinderAlg::EmplaceHit(), and PrintResults().

50 { return fMeanVector.size(); }
std::vector< float > fMeanVector
Definition: RFFHitFitter.h:66
void hit::RFFHitFitter::PrintResults ( )

Definition at line 198 of file RFFHitFitter.cxx.

References fAmpErrorVector, fAmpVector, fMeanErrorVector, fMeanVector, fSigmaErrorVector, fSigmaVector, fSignalSet, and NHits().

199 {
200  std::cout << "InitialSignalSet" << std::endl;
201 
202  for (auto const& sigpair : fSignalSet)
203  std::cout << "\t" << sigpair.first << " / " << sigpair.second << std::endl;
204 
205  std::cout << "\nNHits = " << NHits() << std::endl;
206  std::cout << "\tMean / Sigma / Amp" << std::endl;
207  for (size_t i = 0; i < NHits(); i++)
208  std::cout << "\t" << fMeanVector[i] << " +- " << fMeanErrorVector[i] << " / " << fSigmaVector[i]
209  << " +- " << fSigmaErrorVector[i] << " / " << fAmpVector[i] << " +- "
210  << fAmpErrorVector[i] << std::endl;
211 }
std::vector< float > fAmpErrorVector
Definition: RFFHitFitter.h:71
std::vector< float > fSigmaVector
Definition: RFFHitFitter.h:67
std::multiset< MeanSigmaPair, SignalSetComp > fSignalSet
Definition: RFFHitFitter.h:73
std::vector< float > fAmpVector
Definition: RFFHitFitter.h:70
std::vector< float > fSigmaErrorVector
Definition: RFFHitFitter.h:69
unsigned int NHits()
Definition: RFFHitFitter.h:50
std::vector< float > fMeanVector
Definition: RFFHitFitter.h:66
std::vector< float > fMeanErrorVector
Definition: RFFHitFitter.h:68
void hit::RFFHitFitter::RunFitter ( const std::vector< float > &  signal)

Definition at line 44 of file RFFHitFitter.cxx.

References CalculateAllMeansAndSigmas(), CalculateAmplitudes(), CalculateMergedMeansAndSigmas(), ClearResults(), and CreateMergeVector().

Referenced by hit::RFFHitFinderAlg::Run().

45 {
46  ClearResults();
49  CalculateMergedMeansAndSigmas(signal.size());
50  CalculateAmplitudes(signal);
51 }
void CalculateMergedMeansAndSigmas(std::size_t signal_size)
void CalculateAllMeansAndSigmas(const std::vector< float > &signal)
void CalculateAmplitudes(const std::vector< float > &signal)
void hit::RFFHitFitter::SetFitterParams ( float  max_mean,
unsigned int  min_multi,
float  threshold 
)

Definition at line 32 of file RFFHitFitter.cxx.

References ClearResults(), fFinalAmpThreshold, fMeanMatchThreshold, and fMinMergeMultiplicity.

Referenced by RFFHitFitter(), and hit::RFFHitFinderAlg::SetFitterParams().

33 {
34  fMeanMatchThreshold = max_mean;
35  fMinMergeMultiplicity = min_multi;
36 
38 
39  fFinalAmpThreshold = threshold;
40 
41  ClearResults();
42 }
unsigned int fMinMergeMultiplicity
Definition: RFFHitFitter.h:58
float fFinalAmpThreshold
Definition: RFFHitFitter.h:59
float fMeanMatchThreshold
Definition: RFFHitFitter.h:57
const std::vector<float>& hit::RFFHitFitter::SigmaErrorVector ( )
inline

Definition at line 47 of file RFFHitFitter.h.

Referenced by hit::RFFHitFinderAlg::EmplaceHit().

47 { return fSigmaErrorVector; }
std::vector< float > fSigmaErrorVector
Definition: RFFHitFitter.h:69
const std::vector<float>& hit::RFFHitFitter::SigmaVector ( )
inline

Definition at line 45 of file RFFHitFitter.h.

Referenced by hit::RFFHitFinderAlg::EmplaceHit().

45 { return fSigmaVector; }
std::vector< float > fSigmaVector
Definition: RFFHitFitter.h:67

Member Data Documentation

std::vector<float> hit::RFFHitFitter::fAmpErrorVector
private

Definition at line 71 of file RFFHitFitter.h.

Referenced by CalculateAmplitudes(), ClearResults(), and PrintResults().

std::vector<float> hit::RFFHitFitter::fAmpVector
private

Definition at line 70 of file RFFHitFitter.h.

Referenced by CalculateAmplitudes(), ClearResults(), HitsBelowThreshold(), and PrintResults().

float hit::RFFHitFitter::fFinalAmpThreshold
private

Definition at line 59 of file RFFHitFitter.h.

Referenced by CalculateAmplitudes(), HitsBelowThreshold(), and SetFitterParams().

util::GaussianEliminationAlg hit::RFFHitFitter::fGEAlg
private

Definition at line 64 of file RFFHitFitter.h.

Referenced by CalculateAmplitudes().

std::vector<float> hit::RFFHitFitter::fMeanErrorVector
private
float hit::RFFHitFitter::fMeanMatchThreshold
private

Definition at line 57 of file RFFHitFitter.h.

Referenced by CreateMergeVector(), and SetFitterParams().

std::vector<float> hit::RFFHitFitter::fMeanVector
private
std::vector<std::vector<std::multiset<MeanSigmaPair>::iterator> > hit::RFFHitFitter::fMergeVector
private

Definition at line 74 of file RFFHitFitter.h.

Referenced by CalculateMergedMeansAndSigmas(), ClearResults(), and CreateMergeVector().

unsigned int hit::RFFHitFitter::fMinMergeMultiplicity
private

Definition at line 58 of file RFFHitFitter.h.

Referenced by CalculateMergedMeansAndSigmas(), and SetFitterParams().

std::vector<float> hit::RFFHitFitter::fSigmaErrorVector
private
std::vector<float> hit::RFFHitFitter::fSigmaVector
private
std::multiset<MeanSigmaPair, SignalSetComp> hit::RFFHitFitter::fSignalSet
private

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