15#include <fairlogger/Logger.h>
43 auto [
nsamples, bunchIndex, ampEstimate,
46 if (bunchIndex >= 0 && ampEstimate >=
mAmpCut) {
48 int timebinOffset = bunchlist[bunchIndex].getStartTime() - (bunchlist[bunchIndex].getBunchLength() - 1);
51 if (
nsamples > 2 && maxADC < constants::OVERFLOWCUT) {
52 std::tie(amp,
time) = doParabolaFit(timeEstimate - 1);
65 time += timebinOffset;
66 timeEstimate += timebinOffset;
72 float ampAsymm = (amp - ampEstimate) / (amp + ampEstimate);
73 float timeDiff =
time - timeEstimate;
75 if ((TMath::Abs(ampAsymm) > 0.1) || (TMath::Abs(timeDiff) > 2)) {
83 std::default_random_engine generator;
84 std::uniform_real_distribution<float> distribution(0.0, 1.0);
85 amp += (0.5 - distribution(generator));
87 time =
time * constants::EMCAL_TIMESAMPLE;
96float CaloRawFitterGamma2::doFit_1peak(
int firstTimeBin,
int nSamples,
float& ampl,
float&
time)
105 if (mNiter > mNiterationsMax) {
119 for (
int itbin = 0; itbin < nSamples; itbin++) {
121 double ti = (itbin -
time) / constants::TAU;
126 double g_1i = (ti + 1) * TMath::Exp(-2 * ti);
127 double g_i = (ti + 1) * g_1i;
128 double gp_i = 2 * (g_i - g_1i);
129 double q1_i = (2 * ti + 1) * TMath::Exp(-2 * ti);
130 double q2_i = g_1i * g_1i * (4 * ti + 1);
131 c11 += (
getReversed(itbin) - ampl * 2 * g_i) * gp_i;
138 chi2 += (delta * delta);
141 D = c11 * c22 - c12 * c21;
143 if (TMath::Abs(D) < DBL_EPSILON) {
147 dt = (d1 * c22 -
d2 * c12) / D * constants::TAU;
148 dA = (d1 * c21 -
d2 * c11) / D;
153 if (TMath::Abs(dA) > 1 || TMath::Abs(dt) > 0.01) {
154 chi2 = doFit_1peak(firstTimeBin, nSamples, ampl,
time);
160std::tuple<float, float> CaloRawFitterGamma2::doParabolaFit(
int maxTimeBin)
const
162 float amp(0.),
time(0.);
169 if (TMath::Abs(
a) < DBL_EPSILON) {
171 time = maxTimeBin + 1;
172 return std::make_tuple(amp,
time);
176 double c =
getReversed(maxTimeBin) -
b * maxTimeBin -
a * maxTimeBin * maxTimeBin;
181 return std::make_tuple(amp,
time);
std::vector< uint16_t > nsamples
Container class to hold results from fitting.
CaloRawFitterGamma2()
Constructor.
CaloFitResults evaluate(const gsl::span< const Bunch > bunchvector) final
Evaluation Amplitude and TOF.
float mAmpCut
Max ADC - pedestal must be higher than this befor attemting to extract the amplitude.
double getReversed(const int i) const
std::tuple< int, int, float, short, short, float, int, int > preFitEvaluateSamples(const gsl::span< const Bunch > bunchvector, int adcThreshold)
Method to do the selection of what should possibly be fitted.
double mL1Phase
Phase of the ADC sampling clock relative to the LHC clock.
RawFitterError_t
Error codes for failures in raw fitter procedure.
@ FIT_ERROR
Fit procedure failed.
FitAlgorithm mAlgo
Which algorithm to use.
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
@ Gamma2
Gamma2 raw fitter.