150 if (hitCandidateVec.empty())
return;
153 chi2PerNDF = std::numeric_limits<double>::infinity();
155 int startTime = hitCandidateVec.front().startTick;
156 int endTime = hitCandidateVec.back().stopTick;
157 int roiSize = endTime - startTime;
162 std::string histName =
"PeakFitterHitSignal_" +
std::to_string(roiSize);
163 fHistogram = TH1F(histName.c_str(),
"",roiSize,0.,roiSize);
167 for(
int idx = 0; idx < roiSize; idx++)
fHistogram.SetBinContent(idx+1,roiSignalVec[startTime+idx]);
171 std::string equation =
"gaus(0)";
173 for(
size_t idx = 1; idx < hitCandidateVec.size(); idx++) equation +=
"+gaus(" +
std::to_string(3*idx) +
")";
186 TF1 Gaus(
"Gaus",equation.c_str(),0,roiSize,TF1::EAddToList::kNo);
188 unsigned int const nGaus = hitCandidateVec.size();
198 Gaus.SetParameter(nGaus * 3,
baseline);
201 else Gaus.FixParameter(nGaus * 3,
baseline);
214 for(
auto const& candidateHit : hitCandidateVec)
216 double const peakMean = candidateHit.hitCenter - float(startTime);
217 double const peakWidth = candidateHit.hitSigma;
218 double const amplitude = candidateHit.hitHeight -
baseline;
219 double const meanLowLim = std::max(peakMean -
fPeakRange * peakWidth, 0.);
220 double const meanHiLim = std::min(peakMean +
fPeakRange * peakWidth,
double(roiSize));
229 Gaus.SetParameter( parIdx, amplitude);
230 Gaus.SetParameter(1+parIdx, peakMean);
231 Gaus.SetParameter(2+parIdx, peakWidth);
232 Gaus.SetParLimits( parIdx, 0.1 * amplitude,
fAmpRange * amplitude);
233 Gaus.SetParLimits(1+parIdx, meanLowLim, meanHiLim);
242 { fitResult =
fHistogram.Fit(&Gaus,
"QNWB",
"", 0., roiSize);}
244 {mf::LogWarning(
"GausHitFinder") <<
"Fitter failed finding a hit";}
252 chi2PerNDF = (Gaus.GetChisquare() / Gaus.GetNDF());
256 for(
size_t idx = 0; idx < hitCandidateVec.size(); idx++)
260 peakParams.peakAmplitude = Gaus.GetParameter(parIdx);
261 peakParams.peakAmplitudeError = Gaus.GetParError( parIdx);
262 peakParams.peakCenter = Gaus.GetParameter(parIdx + 1) + float(startTime);
263 peakParams.peakCenterError = Gaus.GetParError( parIdx + 1);
264 peakParams.peakSigma = Gaus.GetParameter(parIdx + 2);
265 peakParams.peakSigmaError = Gaus.GetParError( parIdx + 2);
274 peakParamsVec.emplace_back(peakParams);
virtual TF1 * Get(size_t nFunc)
Returns a function sum of nFunc base functions.
std::string to_string(WindowPattern const &pattern)