All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PeakFitterGaussElimination_tool.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file PeakFitterGaussElimination.cc
3 /// \author T. Usher
4 ////////////////////////////////////////////////////////////////////////
5 
7 
8 #include "art/Utilities/ToolMacros.h"
10 
11 #include <algorithm>
12 
13 namespace reco_tool
14 {
15 
17 {
18 public:
19  explicit PeakFitterGaussElimination(const fhicl::ParameterSet& pset);
20 
21  void findPeakParameters(const std::vector<float>&,
24  double&,
25  int&) const override;
26 
27 private:
28  // Member variables from the fhicl file
29  float fStepSize; ///< Step size used by gaussian elim alg
30  float fMax; ///< Max
31 
32  std::unique_ptr<util::GaussianEliminationAlg> fGEAlg;
33 };
34 
35 //----------------------------------------------------------------------
36 // Constructor.
38 {
39  // Start by recovering the parameters
40  fStepSize = pset.get<float>("StepSize", 0.1);
41  fMax = pset.get<float>("Max", 0.5);
42 
43 // fGEAlg = std::make_unique<util::GaussianEliminationAlg>(fStepSize, fMax);
44 
45  return;
46 }
47 
48 // --------------------------------------------------------------------------------------------
49 void PeakFitterGaussElimination::findPeakParameters(const std::vector<float>& roiSignalVec,
50  const ICandidateHitFinder::HitCandidateVec& hitCandidateVec,
51  PeakParamsVec& peakParamsVec,
52  double& chi2PerNDF,
53  int& NDF) const
54 {
55  // This module tries to use the method for fitting hits found in the RRFHitFinder
56  // from Wes Ketchum. It uses the gaussian elimation algorithm he set up.
57  //
58  // *** NOTE: this algorithm assumes the reference time for input hit candidates is to
59  // the first tick of the input waveform (ie 0)
60  //
61  if (hitCandidateVec.empty()) return;
62 
63  std::vector<float> meanVec;
64  std::vector<float> sigmaVec;
65  std::vector<float> heightVec;
66 
67  for(const auto& hitCandidate : hitCandidateVec)
68  {
69  float candMean = hitCandidate.hitCenter;
70  float candSigma = hitCandidate.hitSigma;
71  size_t bin = std::floor(candMean);
72 
73  bin = std::min(bin, roiSignalVec.size() - 1);
74 
75  float candHeight = roiSignalVec[bin] - (candMean-(float)bin)*(roiSignalVec[bin]-roiSignalVec[bin+1]);
76 
77  meanVec.push_back(candMean);
78  sigmaVec.push_back(candSigma);
79  heightVec.push_back(candHeight);
80  }
81 
82  return;
83 }
84 
85 DEFINE_ART_CLASS_TOOL(PeakFitterGaussElimination)
86 }
float fStepSize
Step size used by gaussian elim alg.
void findPeakParameters(const std::vector< float > &, const ICandidateHitFinder::HitCandidateVec &, PeakParamsVec &, double &, int &) const override
PeakFitterGaussElimination(const fhicl::ParameterSet &pset)
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
std::unique_ptr< util::GaussianEliminationAlg > fGEAlg
std::vector< HitCandidate > HitCandidateVec