11 #include "art_root_io/TFileService.h" 43 std::size_t iGaus = 0;
44 while (iGaus < nFunc) formula +=
"gaus(" +
std::to_string(3 * (iGaus++)) +
") + ";
48 auto* pF =
new TF1(func_name.c_str(), formula.c_str());
49 pF->SetParName(iGaus * 3,
"baseline");
61 void findPeakParameters(
const std::vector<float>&,
97 fMinWidth(pset.
get<double>(
"MinWidth", 0.5)),
98 fMaxWidthMult (pset.
get<double>(
"MaxWidthMult", 3.)),
99 fPeakRange(pset.
get<double>(
"PeakRangeFact", 2.)),
100 fAmpRange(pset.
get<double>(
"PeakAmpRange", 2.)),
101 fFloatBaseline(pset.
get<
bool >(
"FloatBaseline", false)),
102 fOutputHistograms(pset.
get<
bool >(
"OutputHistograms", false))
104 fHistogram = TH1F(
"PeakFitterHitSignal",
"",500,0.,500.);
118 art::TFileDirectory
dir = tfs->mkdir(
"PeakFit");
120 fNumCandHitsHist = dir.make<TH1F>(
"NumCandHits",
"# Candidate Hits", 100, 0., 100.);
121 fROISizeHist = dir.make<TH1F>(
"ROISize",
"ROI Size", 400, 0., 400.);
123 fCandPeakWidHist = dir.make<TH1F>(
"CPeadWidth",
"Peak Width", 100, 0., 25.);
127 fFitPeakWidHist = dir.make<TH1F>(
"FPeadWidth",
"Peak Width", 100, 0., 25.);
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++)
260 peakParams.
peakCenter = Gaus.GetParameter(parIdx + 1) +
float(startTime);
262 peakParams.
peakSigma = Gaus.GetParameter(parIdx + 2);
272 peakParamsVec.emplace_back(peakParams);
art framework interface to geometry description
A set of TF1 linear sum of base functions (Gaussians)
virtual TF1 * Get(size_t nFunc)
Returns a function sum of nFunc base functions.
static int max(int a, int b)
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.
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
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.
auto const & get(AssnsNode< L, R, D > const &r)
std::string to_string(ModuleType const mt)