All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
reco_tool::PeakFitterMrqdt Class Reference
Inheritance diagram for reco_tool::PeakFitterMrqdt:
reco_tool::IPeakFitter

Public Member Functions

 PeakFitterMrqdt (const fhicl::ParameterSet &pset)
 
void findPeakParameters (const std::vector< float > &, const ICandidateHitFinder::HitCandidateVec &, PeakParamsVec &, double &, int &) const override
 

Private Attributes

const double fMinWidth
 
const double fMaxWidthMult
 
const double fPeakRange
 
const double fAmpRange
 
std::unique_ptr< gshf::MarqFitAlg > fMarqFitAlg
 
const geo::GeometryCorefGeometry = lar::providerFrom<geo::Geometry>()
 
- Private Attributes inherited from reco_tool::IPeakFitter
float peakCenterError
 
float peakSigma
 
float peakSigmaError
 
float peakAmplitude
 
float peakAmplitudeError
 
float peakTauLeft
 
float peakTauLeftError
 
float peakTauRight
 
float peakTauRightError
 
float peakBaseline
 
float peakBaselineError
 

Additional Inherited Members

- Private Types inherited from reco_tool::IPeakFitter
using PeakFitParams_t = struct PeakFitParams{float peakCenter
 
using PeakParamsVec = std::vector< PeakFitParams_t >
 
using PeakParamsVec = std::vector< PeakFitParams_t >
 
- Private Member Functions inherited from reco_tool::IPeakFitter
virtual ~IPeakFitter () noexcept=default
 
virtual void configure (const fhicl::ParameterSet &pset)=0
 
virtual ~IPeakFitter ()=default
 

Detailed Description

Definition at line 19 of file PeakFitterMrqdt_tool.cc.

Constructor & Destructor Documentation

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

Definition at line 44 of file PeakFitterMrqdt_tool.cc.

45  : fMinWidth(pset.get<double>("MinWidth", 0.5))
46  , fMaxWidthMult(pset.get<double>("MaxWidthMult", 3.))
47  , fPeakRange(pset.get<double>("PeakRangeFact", 2.))
48  , fAmpRange(pset.get<double>("PeakAmpRange", 2.))
49  {}

Member Function Documentation

void reco_tool::PeakFitterMrqdt::findPeakParameters ( const std::vector< float > &  signal,
const ICandidateHitFinder::HitCandidateVec fhc_vec,
PeakParamsVec mhpp_vec,
double &  chi2PerNDF,
int &  NDF 
) const
overridevirtual

Implements reco_tool::IPeakFitter.

Definition at line 54 of file PeakFitterMrqdt_tool.cc.

59  {
60  if (fhc_vec.empty()) return;
61 
62  const float chiCut = 1e-3;
63  float lambda = 0.001; /* Marquardt damping parameter */
64  float chiSqr = std::numeric_limits<float>::max(), dchiSqr = std::numeric_limits<float>::max();
65  int nParams = 0;
66 
67  int startTime = fhc_vec.front().startTick;
68  int endTime = fhc_vec.back().stopTick;
69 
70  int roiSize = endTime - startTime;
71 
72  // init to a large number in case the fit fails
73  chi2PerNDF = chiSqr;
74 
75  std::vector<float> y(roiSize);
76  std::vector<float> p(3 * fhc_vec.size());
77  std::vector<float> plimmin(3 * fhc_vec.size());
78  std::vector<float> plimmax(3 * fhc_vec.size());
79  std::vector<float> perr(3 * fhc_vec.size());
80 
81  /* choose the fit function and set the parameters */
82  nParams = 0;
83 
84  for (size_t ih = 0; ih < fhc_vec.size(); ih++) {
85  float const peakMean =
86  fhc_vec[ih].hitCenter - 0.5 - (float)startTime; //shift by 0.5 to account for bin width
87  float const peakWidth = fhc_vec[ih].hitSigma;
88  float const amplitude = fhc_vec[ih].hitHeight;
89  float const meanLowLim = fmax(peakMean - fPeakRange * peakWidth, 0.);
90  float const meanHiLim = fmin(peakMean + fPeakRange * peakWidth, (float)roiSize);
91  p[0 + nParams] = amplitude;
92  p[1 + nParams] = peakMean;
93  p[2 + nParams] = peakWidth;
94 
95  plimmin[0 + nParams] = amplitude * 0.1;
96  plimmin[1 + nParams] = meanLowLim;
97  plimmin[2 + nParams] = std::max(fMinWidth, 0.1 * peakWidth);
98 
99  plimmax[0 + nParams] = amplitude * fAmpRange;
100  plimmax[1 + nParams] = meanHiLim;
101  plimmax[2 + nParams] = fMaxWidthMult * peakWidth;
102 
103  nParams += 3;
104  }
105  int fitResult = -1;
106 
107  for (size_t idx = 0; idx < size_t(roiSize); idx++) {
108  y[idx] = signal[startTime + idx];
109  }
110 
111  int trial = 0;
112  lambda = -1.; /* initialize lambda on first call */
113  do {
114  fitResult = fMarqFitAlg->gshf::MarqFitAlg::mrqdtfit(
115  lambda, &p[0], &plimmin[0], &plimmax[0], &y[0], nParams, roiSize, chiSqr, dchiSqr);
116  trial++;
117  if (fitResult || (trial > 100)) break;
118  } while (fabs(dchiSqr) >= chiCut);
119 
120  if (!fitResult) {
121  int fitResult2 =
122  fMarqFitAlg->gshf::MarqFitAlg::cal_perr(&p[0], &y[0], nParams, roiSize, &perr[0]);
123  if (!fitResult2) {
124  NDF = roiSize - nParams;
125  chi2PerNDF = chiSqr / NDF;
126  int parIdx = 0;
127  for (size_t i = 0; i < fhc_vec.size(); i++) {
128 
129  /* stand alone method
130  mhpp_vec[i].peakAmplitude = p[parIdx + 0];
131  mhpp_vec[i].peakAmplitudeError = perr[parIdx + 0];
132  mhpp_vec[i].peakCenter = p[parIdx + 1] + 0.5 + float(startTime);
133  mhpp_vec[i].peakCenterError = perr[parIdx + 1];
134  mhpp_vec[i].peakSigma = p[parIdx + 2];
135  mhpp_vec[i].peakSigmaError = perr[parIdx + 2];
136  */
137 
138  PeakFitParams_t mhpp;
139  mhpp.peakAmplitude = p[parIdx + 0];
140  mhpp.peakAmplitudeError = perr[parIdx + 0];
141  mhpp.peakCenter =
142  p[parIdx + 1] + 0.5 + float(startTime); //shift by 0.5 to account for bin width
143  mhpp.peakCenterError = perr[parIdx + 1];
144  mhpp.peakSigma = std::abs(p[parIdx + 2]);
145  mhpp.peakSigmaError = perr[parIdx + 2];
146 
147  mhpp_vec.emplace_back(mhpp);
148 
149  parIdx += 3;
150  }
151 
152  // fitStat=0;
153  }
154  }
155  return;
156  }
double lambda(double a, double b, double c)
std::unique_ptr< gshf::MarqFitAlg > fMarqFitAlg
pdgs p
Definition: selectors.fcl:22
T abs(T value)
process_name opflash particleana ie ie y
do i e

Member Data Documentation

const double reco_tool::PeakFitterMrqdt::fAmpRange
private

Definition at line 34 of file PeakFitterMrqdt_tool.cc.

const geo::GeometryCore* reco_tool::PeakFitterMrqdt::fGeometry = lar::providerFrom<geo::Geometry>()
private

Definition at line 38 of file PeakFitterMrqdt_tool.cc.

std::unique_ptr<gshf::MarqFitAlg> reco_tool::PeakFitterMrqdt::fMarqFitAlg
private

Definition at line 36 of file PeakFitterMrqdt_tool.cc.

const double reco_tool::PeakFitterMrqdt::fMaxWidthMult
private

Definition at line 32 of file PeakFitterMrqdt_tool.cc.

const double reco_tool::PeakFitterMrqdt::fMinWidth
private

Definition at line 31 of file PeakFitterMrqdt_tool.cc.

const double reco_tool::PeakFitterMrqdt::fPeakRange
private

Definition at line 33 of file PeakFitterMrqdt_tool.cc.


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