60 if (fhc_vec.empty())
return;
62 const float chiCut = 1
e-3;
64 float chiSqr = std::numeric_limits<float>::max(), dchiSqr = std::numeric_limits<float>::max();
67 int startTime = fhc_vec.front().startTick;
68 int endTime = fhc_vec.back().stopTick;
70 int roiSize = endTime - startTime;
75 std::vector<float>
y(roiSize);
76 std::vector<float>
p(3 * fhc_vec.size());
77 std::vector<float> plimmin(3 * fhc_vec.size());
78 std::vector<float> plimmax(3 * fhc_vec.size());
79 std::vector<float> perr(3 * fhc_vec.size());
84 for (
size_t ih = 0; ih < fhc_vec.size(); ih++) {
85 float const peakMean =
86 fhc_vec[ih].hitCenter - 0.5 - (float)startTime;
87 float const peakWidth = fhc_vec[ih].hitSigma;
88 float const amplitude = fhc_vec[ih].hitHeight;
89 float const meanLowLim = fmax(peakMean -
fPeakRange * peakWidth, 0.);
90 float const meanHiLim = fmin(peakMean +
fPeakRange * peakWidth, (
float)roiSize);
91 p[0 + nParams] = amplitude;
92 p[1 + nParams] = peakMean;
93 p[2 + nParams] = peakWidth;
95 plimmin[0 + nParams] = amplitude * 0.1;
96 plimmin[1 + nParams] = meanLowLim;
97 plimmin[2 + nParams] = std::max(
fMinWidth, 0.1 * peakWidth);
99 plimmax[0 + nParams] = amplitude *
fAmpRange;
100 plimmax[1 + nParams] = meanHiLim;
107 for (
size_t idx = 0; idx < size_t(roiSize); idx++) {
108 y[idx] = signal[startTime + idx];
114 fitResult =
fMarqFitAlg->gshf::MarqFitAlg::mrqdtfit(
115 lambda, &
p[0], &plimmin[0], &plimmax[0], &
y[0], nParams, roiSize, chiSqr, dchiSqr);
117 if (fitResult || (trial > 100))
break;
118 }
while (fabs(dchiSqr) >= chiCut);
122 fMarqFitAlg->gshf::MarqFitAlg::cal_perr(&
p[0], &
y[0], nParams, roiSize, &perr[0]);
124 NDF = roiSize - nParams;
125 chi2PerNDF = chiSqr / NDF;
127 for (
size_t i = 0; i < fhc_vec.size(); i++) {
139 mhpp.peakAmplitude =
p[parIdx + 0];
140 mhpp.peakAmplitudeError = perr[parIdx + 0];
142 p[parIdx + 1] + 0.5 + float(startTime);
143 mhpp.peakCenterError = perr[parIdx + 1];
144 mhpp.peakSigma =
std::abs(
p[parIdx + 2]);
145 mhpp.peakSigmaError = perr[parIdx + 2];
147 mhpp_vec.emplace_back(mhpp);
double lambda(double a, double b, double c)
process_name opflash particleana ie ie y