11 #include "art_root_io/TFileService.h"
12 #include "art/Framework/Services/Registry/ServiceHandle.h"
13 #include "art/Utilities/ToolMacros.h"
14 #include "messagefacility/MessageLogger/MessageLogger.h"
45 std::size_t iGaus = 0;
46 while (iGaus < nFunc) formula +=
"gaus(" +
std::to_string(3 * (iGaus++)) +
") + ";
50 auto* pF =
new TF1(func_name.c_str(), formula.c_str());
51 pF->SetParName(iGaus * 3,
"baseline");
99 fMinWidth(pset.
get<double>(
"MinWidth", 0.5)),
100 fMaxWidthMult (pset.
get<double>(
"MaxWidthMult", 3.)),
101 fPeakRange(pset.
get<double>(
"PeakRangeFact", 2.)),
102 fAmpRange(pset.
get<double>(
"PeakAmpRange", 2.)),
103 fFloatBaseline(pset.
get<
bool >(
"FloatBaseline",
false)),
104 fOutputHistograms(pset.
get<
bool >(
"OutputHistograms",
false))
106 fHistogram = TH1F(
"PeakFitterHitSignal",
"",500,0.,500.);
110 std::string
function =
"Gaus(0)";
117 art::ServiceHandle<art::TFileService>
tfs;
120 art::TFileDirectory
dir = tfs->mkdir(
"PeakFit");
122 fNumCandHitsHist = dir.make<TH1F>(
"NumCandHits",
"# Candidate Hits", 100, 0., 100.);
123 fROISizeHist = dir.make<TH1F>(
"ROISize",
"ROI Size", 400, 0., 400.);
125 fCandPeakWidHist = dir.make<TH1F>(
"CPeadWidth",
"Peak Width", 100, 0., 25.);
129 fFitPeakWidHist = dir.make<TH1F>(
"FPeadWidth",
"Peak Width", 100, 0., 25.);
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) +
")";
180 baseline = roiSignalVec[startTime];
186 TF1 Gaus(
"Gaus",equation.c_str(),0,roiSize,TF1::EAddToList::kNo);
188 unsigned int const nGaus = hitCandidateVec.size();
197 baseline = roiSignalVec[startTime];
198 Gaus.SetParameter(nGaus * 3, baseline);
199 Gaus.SetParLimits( nGaus * 3, baseline - 12., baseline + 12.);
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);
Utilities related to art service access.
A set of TF1 linear sum of base functions (Gaussians)
virtual TF1 * Get(size_t nFunc)
Returns a function sum of nFunc base functions.
Description of geometry of one entire detector.
GausFitCache(std::string new_name="GausFitCache")
Constructor; optionally set the name of the repository.
std::string to_string(WindowPattern const &pattern)
virtual std::string FunctionName(size_t nFunc) const
Returns a name for the function with nFunc base functions.
Provide caches for TF1 functions to be used with ROOT fitters.
art::ServiceHandle< art::TFileService > tfs
art framework interface to geometry description