12 #include "cetlib_except/exception.h" 45 std::size_t iGaus = 0;
51 auto* pF =
new TF1(func_name.c_str(), formula.c_str());
52 pF->SetParName(iGaus * 3,
"baseline");
68 void findPeakParameters(
const std::vector<float>&,
103 fMinWidth = pset.
get<
double>(
"MinWidth", 0.5);
104 fMaxWidthMult = pset.
get<
double>(
"MaxWidthMult", 3.);
105 fPeakRange = pset.
get<
double>(
"PeakRangeFact", 2.);
106 fAmpRange = pset.
get<
double>(
"PeakAmpRange", 2.);
107 fFloatBaseline = pset.
get<
bool >(
"FloatBaseline",
false);
109 fHistogram = TH1F(
"PeakFitterHitSignal",
"",500,0.,500.);
113 std::string
function =
"Gaus(0)";
131 if (hitCandidateVec.empty())
return;
134 chi2PerNDF = std::numeric_limits<double>::infinity();
136 int startTime = hitCandidateVec.front().startTick;
137 int endTime = hitCandidateVec.back().stopTick;
138 int roiSize = endTime - startTime;
141 if (roiSize > fHistogram.GetNbinsX())
143 std::string histName =
"PeakFitterHitSignal_" +
std::to_string(roiSize);
144 fHistogram = TH1F(histName.c_str(),
"",roiSize,0.,roiSize);
148 for(
int idx = 0; idx < roiSize; idx++) fHistogram.SetBinContent(idx+1,roiSignalVec.at(startTime+idx));
152 std::string equation =
"gaus(0)";
154 for(
size_t idx = 1; idx < hitCandidateVec.size(); idx++) equation +=
"+gaus(" +
std::to_string(3*idx) +
")";
161 baseline = roiSignalVec.at(startTime);
167 TF1 Gaus(
"Gaus",equation.c_str(),0,roiSize,TF1::EAddToList::kNo);
169 unsigned int const nGaus = hitCandidateVec.size();
170 assert(fFitCache.Get(nGaus));
171 TF1& Gaus = *(fFitCache.Get(nGaus));
174 float const baseline = fFloatBaseline? roiSignalVec.at(startTime): 0.0;
176 Gaus.FixParameter(nGaus * 3, baseline);
182 for(
auto const& candidateHit : hitCandidateVec)
184 double const peakMean = candidateHit.hitCenter - float(startTime);
185 double const peakWidth = candidateHit.hitSigma;
186 double const amplitude = candidateHit.hitHeight - baseline;
187 double const meanLowLim =
std::max(peakMean - fPeakRange * peakWidth, 0.);
188 double const meanHiLim =
std::min(peakMean + fPeakRange * peakWidth,
double(roiSize));
190 Gaus.SetParameter( parIdx, amplitude);
191 Gaus.SetParameter(1+parIdx, peakMean);
192 Gaus.SetParameter(2+parIdx, peakWidth);
193 Gaus.SetParLimits( parIdx, 0.1 * amplitude, fAmpRange * amplitude);
194 Gaus.SetParLimits(1+parIdx, meanLowLim, meanHiLim);
195 Gaus.SetParLimits(2+parIdx,
std::max(fMinWidth, 0.1 * peakWidth), fMaxWidthMult * peakWidth);
203 { fitResult = fHistogram.Fit(&Gaus,
"QNWB",
"", 0., roiSize);}
205 {
mf::LogWarning(
"GausHitFinder") <<
"Fitter failed finding a hit";}
213 chi2PerNDF = (Gaus.GetChisquare() / Gaus.GetNDF());
217 for(
size_t idx = 0; idx < hitCandidateVec.size(); idx++)
221 peakParams.peakAmplitude = Gaus.GetParameter(parIdx);
222 peakParams.peakAmplitudeError = Gaus.GetParError( parIdx);
223 peakParams.peakCenter = Gaus.GetParameter(parIdx + 1) + float(startTime);
224 peakParams.peakCenterError = Gaus.GetParError( parIdx + 1);
225 peakParams.peakSigma = Gaus.GetParameter(parIdx + 2);
226 peakParams.peakSigmaError = Gaus.GetParError( parIdx + 2);
228 peakParamsVec.emplace_back(peakParams);
A set of TF1 linear sum of base functions (Gaussians)
T get(std::string const &key) const
Description of geometry of one entire detector.
GausFitCache(std::string new_name="GausFitCache")
Constructor; optionally set the name of the repository.
Detector simulation of raw signals on wires.
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
This provides an interface for tools which are tasked with fitting peaks on input waveforms...
virtual std::string FunctionName(size_t nFunc) const
Returns a name for the function with nFunc base functions.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Provide caches for TF1 functions to be used with ROOT fitters.
art framework interface to geometry description