Project
Loading...
Searching...
No Matches
CaloRawFitter.h
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#ifndef EMCALRAWFITTER_H_
12#define EMCALRAWFITTER_H_
13
14#include <iosfwd>
15#include <array>
16#include <optional>
17#include <string_view>
18#include <Rtypes.h>
19#include <gsl/span>
23
24namespace o2
25{
26
27namespace emcal
28{
29
41{
42
43 public:
55
59 static std::string createErrorMessage(RawFitterError_t fiterror) { return getErrorTypeDescription(fiterror); }
60
64 static int getErrorNumber(RawFitterError_t fiterror);
65
72 static RawFitterError_t intToErrorType(unsigned int fiterror);
73
76 static constexpr int getNumberOfErrorTypes() noexcept { return 5; }
77
85 static const char* getErrorTypeName(RawFitterError_t fiterror);
86
94 static const char* getErrorTypeName(unsigned int fiterror)
95 {
96 return getErrorTypeName(intToErrorType(fiterror));
97 }
98
106 static const char* getErrorTypeTitle(RawFitterError_t fiterror);
107
115 static const char* getErrorTypeTitle(unsigned int fiterror)
116 {
117 return getErrorTypeTitle(intToErrorType(fiterror));
118 }
119
127 static const char* getErrorTypeDescription(RawFitterError_t fiterror);
128
136 static const char* getErrorTypeDescription(unsigned int fiterror)
137 {
138 return getErrorTypeDescription(intToErrorType(fiterror));
139 }
140
142 CaloRawFitter(const char* name, const char* nameshort);
143
145 virtual ~CaloRawFitter() = default;
146
147 virtual CaloFitResults evaluate(const gsl::span<const Bunch> bunchvector) = 0;
148
160 std::tuple<int, int, float, short, short, float, int, int> preFitEvaluateSamples(const gsl::span<const Bunch> bunchvector, int adcThreshold);
161
163 void setTimeConstraint(int min, int max);
164
165 void setIsZeroSuppressed(bool iszs = true) { mIsZerosupressed = iszs; }
166 void setAmpCut(float cut) { mAmpCut = cut; }
167 void setNsamplePed(int i) { mNsamplePed = i; }
168 void setL1Phase(double phase) { mL1Phase = phase; }
169
170 bool getIsZeroSuppressed() const { return mIsZerosupressed; }
171 float getAmpCut() const { return mAmpCut; }
172 int getNsamplePed() const { return mNsamplePed; }
173
174 // access to array info
175 double getReversed(const int i) const { return mReversed[i]; }
176 const std::string_view getAlgoName() const { return mName.c_str(); }
177 const std::string_view getAlgoAbbr() const { return mNameShort.c_str(); }
178
181 FitAlgorithm getAlgo() const { return mAlgo; }
182
186 std::tuple<short, int> getMaxAmplitudeBunch(const Bunch& bunchx) const;
187
190 unsigned short getMaxAmplitudeBunch(const gsl::span<unsigned short> data) const;
191
195 bool isMaxADCBunchEdge(const Bunch& bunch) const;
196
202 bool isInTimeRange(int indexMaxADC, int maxtime, int mintime) const;
203
207 std::tuple<float, std::array<double, constants::EMCAL_MAXTIMEBINS>> reverseAndSubtractPed(const Bunch& bunch) const;
208
215 std::tuple<short, short, short> selectMaximumBunch(const gsl::span<const Bunch>& bunchvector);
216
223 std::tuple<int, int> findPeakRegion(const gsl::span<double> adcValues, short indexMaxADC, int threshold) const;
224
229 double evaluatePedestal(const gsl::span<const uint16_t> data, std::optional<int> length) const;
230
241 double calculateChi2(double amp, double time,
242 int first, int last,
243 double adcErr = 1,
244 double tau = 2.35) const;
245
246 int getMinTimeIndex() const { return mMinTimeIndex; }
247 int getMaxTimeIndex() const { return mMaxTimeIndex; }
248
249 protected:
250 std::array<double, constants::EMCAL_MAXTIMEBINS> mReversed;
251
254
255 float mAmpCut;
256
258
260
261 std::string mName;
262 std::string mNameShort;
263
265
266 double mL1Phase;
267
268 double mAmp;
269
271}; // CaloRawFitter
272
277std::ostream& operator<<(std::ostream& stream, const CaloRawFitter::RawFitterError_t error);
278
279} // namespace emcal
280
281} // namespace o2
282#endif
uint64_t phase
Definition RawEventData.h:7
int16_t time
Definition RawEventData.h:4
int32_t i
ALTRO bunch information.
Definition Bunch.h:40
Container class to hold results from fitting.
float mAmpCut
Max ADC - pedestal must be higher than this befor attemting to extract the amplitude.
static constexpr int getNumberOfErrorTypes() noexcept
Get the number of raw fit error types supported.
ClassDefNV(CaloRawFitter, 1)
static const char * getErrorTypeDescription(unsigned int fiterror)
Get the description connected to the fit error type.
void setAmpCut(float cut)
bool isMaxADCBunchEdge(const Bunch &bunch) const
Check if the max. ADC value is at the edge of a bunch.
void setIsZeroSuppressed(bool iszs=true)
std::string mNameShort
Abbrevation for the name.
double getReversed(const int i) const
std::tuple< short, short, short > selectMaximumBunch(const gsl::span< const Bunch > &bunchvector)
We select the bunch with the highest amplitude unless any time constraints is set.
FitAlgorithm getAlgo() const
Get Type of the fit algorithm.
static const char * getErrorTypeTitle(RawFitterError_t fiterror)
Get the title connected to the fit error type.
static const char * getErrorTypeTitle(unsigned int fiterror)
Get the title connected to the fit error type.
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.
virtual CaloFitResults evaluate(const gsl::span< const Bunch > bunchvector)=0
int mMaxTimeIndex
The timebin of the max signal value must be between fMinTimeIndex and fMaxTimeIndex.
std::array< double, constants::EMCAL_MAXTIMEBINS > mReversed
Reversed sequence of samples (pedestalsubtracted)
std::string mName
Name of the algorithm.
double mL1Phase
Phase of the ADC sampling clock relative to the LHC clock.
std::tuple< short, int > getMaxAmplitudeBunch(const Bunch &bunchx) const
Get the maximum amplitude and its index of a bunch array.
bool isInTimeRange(int indexMaxADC, int maxtime, int mintime) const
Check if the index of the max ADC vaue is within accepted time range.
const std::string_view getAlgoName() const
bool getIsZeroSuppressed() const
double evaluatePedestal(const gsl::span< const uint16_t > data, std::optional< int > length) const
Calculate the pedestal from the ADC values in a bunch.
static const char * getErrorTypeName(unsigned int fiterror)
Get the name connected to the fit error type.
const std::string_view getAlgoAbbr() const
double mAmp
The amplitude in entities of ADC counts.
static int getErrorNumber(RawFitterError_t fiterror)
Convert error type to numeric representation.
static const char * getErrorTypeDescription(RawFitterError_t fiterror)
Get the description connected to the fit error type.
std::tuple< int, int > findPeakRegion(const gsl::span< double > adcValues, short indexMaxADC, int threshold) const
Find region constrainded by its closest minima around the main peak.
std::tuple< float, std::array< double, constants::EMCAL_MAXTIMEBINS > > reverseAndSubtractPed(const Bunch &bunch) const
Time sample comes in reversed order, revers them back Subtract the baseline based on content of altro...
double calculateChi2(double amp, double time, int first, int last, double adcErr=1, double tau=2.35) const
Calculates the chi2 of the fit.
virtual ~CaloRawFitter()=default
Destructor.
RawFitterError_t
Error codes for failures in raw fitter procedure.
@ LOW_SIGNAL
No ADC value above threshold found.
@ SAMPLE_UNINITIALIZED
Samples not initialized or length is 0.
@ CHI2_ERROR
Chi2 cannot be determined (usually due to insufficient amount of samples)
static const char * getErrorTypeName(RawFitterError_t fiterror)
Get the name connected to the fit error type.
FitAlgorithm mAlgo
Which algorithm to use.
static RawFitterError_t intToErrorType(unsigned int fiterror)
Convert numeric representation of error type to RawFitterError_t.
void setTimeConstraint(int min, int max)
The require time range if the maximum ADC value is between min and max (timebin)
bool mIsZerosupressed
Wether or not the data is zeros supressed, by default its assumed that the baseline is also subtracte...
int mMinTimeIndex
The timebin of the max signal value must be between fMinTimeIndex and fMaxTimeIndex.
static std::string createErrorMessage(RawFitterError_t fiterror)
Create error message for a given error type.
void setL1Phase(double phase)
int mNsamplePed
Number of samples used for pedestal calculation (first in bunch)
GLuint const GLchar * name
Definition glcorearb.h:781
GLboolean * data
Definition glcorearb.h:298
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
GLuint GLuint stream
Definition glcorearb.h:1806
std::ostream & operator<<(std::ostream &stream, const Cell &cell)
Stream operator for EMCAL cell.
Definition Cell.cxx:355
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
constexpr size_t min
constexpr size_t max