Project
Loading...
Searching...
No Matches
CaloRawFitterStandard.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#include <fairlogger/Logger.h>
16#include <random>
17
18// ROOT sytem
19#include "TMath.h"
20#include "TF1.h"
21#include "TGraph.h"
22
26
28
29using namespace o2::emcal;
30
31CaloRawFitterStandard::CaloRawFitterStandard() : CaloRawFitter("Chi Square ( Standard )", "Standard")
32{
34}
35
37{
38 double signal = 0.;
39 double tau = par[2];
40 double n = par[3];
41 double ped = par[4];
42 double xx = (x[0] - par[1] + tau) / tau;
43
44 if (xx <= 0) {
45 signal = ped;
46 } else {
47 signal = ped + par[0] * TMath::Power(xx, n) * TMath::Exp(n * (1 - xx));
48 }
49
50 return signal;
51}
52
53CaloFitResults CaloRawFitterStandard::evaluate(const gsl::span<const Bunch> bunchlist)
54{
55 float time = 0;
56 float amp = 0;
57 float chi2 = 0;
58 int ndf = 0;
59 bool fitDone = kFALSE;
60
61 auto [nsamples, bunchIndex, ampEstimate,
62 maxADC, timeEstimate, pedEstimate, first, last] = preFitEvaluateSamples(bunchlist, mAmpCut);
63
64 if (bunchIndex >= 0 && ampEstimate >= mAmpCut) {
65 time = timeEstimate;
66 int timebinOffset = bunchlist[bunchIndex].getStartTime() - (bunchlist[bunchIndex].getBunchLength() - 1);
67 amp = ampEstimate;
68
69 if (nsamples > 1 && maxADC < constants::OVERFLOWCUT) {
70 try {
71 std::tie(amp, time, chi2) = fitRaw(first, last);
72 time += timebinOffset;
73 timeEstimate += timebinOffset;
74 ndf = nsamples - 2;
75 fitDone = true;
76 } catch (RawFitterError_t& error) {
77 }
78 }
79 }
80 if (fitDone) {
81 float ampAsymm = (amp - ampEstimate) / (amp + ampEstimate);
82 float timeDiff = time - timeEstimate;
83
84 if ((TMath::Abs(ampAsymm) > 0.1) || (TMath::Abs(timeDiff) > 2)) {
85 amp = ampEstimate;
86 time = timeEstimate;
87 fitDone = kFALSE;
88 }
89 }
90 if (amp >= mAmpCut) {
91 if (!fitDone) {
92 std::default_random_engine generator;
93 std::uniform_real_distribution<float> distribution(0.0, 1.0);
94 amp += (0.5 - distribution(generator));
95 }
96 time = time * constants::EMCAL_TIMESAMPLE;
97 time -= mL1Phase;
98
99 return CaloFitResults(maxADC, pedEstimate, 0, amp, time, (int)time, chi2, ndf);
100 }
102}
103
104std::tuple<float, float, float> CaloRawFitterStandard::fitRaw(int firstTimeBin, int lastTimeBin) const
105{
106
107 float amp(0), time(0), chi2(0);
108
109 int nsamples = lastTimeBin - firstTimeBin + 1;
110 if (nsamples < 3) {
112 }
113
114 TGraph gSig(nsamples);
115
116 for (int i = 0; i < nsamples; i++) {
117 int timebin = firstTimeBin + i;
118 gSig.SetPoint(i, timebin, getReversed(timebin));
119 }
120
121 TF1 signalF("signal", CaloRawFitterStandard::rawResponseFunction, 0, constants::EMCAL_MAXTIMEBINS, 5);
122
123 signalF.SetParameters(10., 5., constants::TAU, constants::ORDER, 0.); // set all defaults once, just to be safe
124 signalF.SetParNames("amp", "t0", "tau", "N", "ped");
125 signalF.FixParameter(2, constants::TAU);
126 signalF.FixParameter(3, constants::ORDER);
127 signalF.FixParameter(4, 0);
128 signalF.SetParameter(1, time);
129 signalF.SetParameter(0, amp);
130 signalF.SetParLimits(0, 0.5 * amp, 2 * amp);
131 signalF.SetParLimits(1, time - 4, time + 4);
132
133 int status = gSig.Fit(&signalF, "QROW"); // Note option 'W': equal errors on all points
134 if (status == 0) {
135 amp = signalF.GetParameter(0);
136 time = signalF.GetParameter(1);
137 chi2 = signalF.GetChisquare();
138 } else {
140 }
141
142 return std::make_tuple(amp, time, chi2);
143}
int16_t time
Definition RawEventData.h:4
int32_t i
std::vector< uint16_t > nsamples
Definition testDigit.cxx:38
Container class to hold results from fitting.
CaloFitResults evaluate(const gsl::span< const Bunch > bunchvector) final
Evaluation Amplitude and TOF.
static double rawResponseFunction(double *x, double *par)
Approximate response function of the EMCal electronics.
std::tuple< float, float, float > fitRaw(int firstTimeBin, int lastTimeBin) const
Fits the raw signal time distribution using TMinuit.
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.
FitAlgorithm mAlgo
Which algorithm to use.
GLdouble n
Definition glcorearb.h:1982
GLint GLenum GLint x
Definition glcorearb.h:403
GLint first
Definition glcorearb.h:399
@ Standard
Standard raw fitter.
Definition Constants.h:112