148 if (hitCandidateVec.empty())
return;
151 chi2PerNDF = std::numeric_limits<double>::infinity();
153 int startTime = hitCandidateVec.front().startTick;
154 int endTime = hitCandidateVec.back().stopTick;
155 int roiSize = endTime - startTime;
161 fHistogram = TH1F(histName.c_str(),
"",roiSize,0.,roiSize);
165 for(
int idx = 0; idx < roiSize; idx++)
fHistogram.SetBinContent(idx+1,roiSignalVec[startTime+idx]);
171 for(
size_t idx = 1; idx < hitCandidateVec.size(); idx++) equation +=
"+gaus(" +
std::to_string(3*idx) +
")";
178 baseline = roiSignalVec[startTime];
184 TF1 Gaus(
"Gaus",equation.c_str(),0,roiSize,TF1::EAddToList::kNo);
186 unsigned int const nGaus = hitCandidateVec.size();
195 baseline = roiSignalVec[startTime];
196 Gaus.SetParameter(nGaus * 3, baseline);
197 Gaus.SetParLimits( nGaus * 3, baseline - 12., baseline + 12.);
199 else Gaus.FixParameter(nGaus * 3, baseline);
212 for(
auto const& candidateHit : hitCandidateVec)
214 double const peakMean = candidateHit.hitCenter -
float(startTime);
215 double const peakWidth = candidateHit.hitSigma;
216 double const amplitude = candidateHit.hitHeight - baseline;
218 double const meanHiLim =
std::min(peakMean +
fPeakRange * peakWidth,
double(roiSize));
227 Gaus.SetParameter( parIdx, amplitude);
228 Gaus.SetParameter(1+parIdx, peakMean);
229 Gaus.SetParameter(2+parIdx, peakWidth);
230 Gaus.SetParLimits( parIdx, 0.1 * amplitude,
fAmpRange * amplitude);
231 Gaus.SetParLimits(1+parIdx, meanLowLim, meanHiLim);
240 { fitResult =
fHistogram.Fit(&Gaus,
"QNWB",
"", 0., roiSize);}
242 {
mf::LogWarning(
"GausHitFinder") <<
"Fitter failed finding a hit";}
250 chi2PerNDF = (Gaus.GetChisquare() / Gaus.GetNDF());
254 for(
size_t idx = 0; idx < hitCandidateVec.size(); idx++)
256 PeakFitParams_t peakParams;
258 peakParams.peakAmplitude = Gaus.GetParameter(parIdx);
259 peakParams.peakAmplitudeError = Gaus.GetParError( parIdx);
260 peakParams.peakCenter = Gaus.GetParameter(parIdx + 1) +
float(startTime);
261 peakParams.peakCenterError = Gaus.GetParError( parIdx + 1);
262 peakParams.peakSigma = Gaus.GetParameter(parIdx + 2);
263 peakParams.peakSigmaError = Gaus.GetParError( parIdx + 2);
272 peakParamsVec.emplace_back(peakParams);
virtual TF1 * Get(size_t nFunc)
Returns a function sum of nFunc base functions.
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::string to_string(ModuleType const mt)