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;
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();
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;
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);
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);
virtual TF1 * Get(size_t nFunc)
Returns a function sum of nFunc base functions.
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning