21#include <fairlogger/Logger.h>
75 return "SampleUninitalized";
77 return "NoConvergence";
81 return "BunchRejected";
94 return "sample uninitalized";
96 return "No convergence";
100 return "Bunch rejected";
113 return "Sample for fit not initialzied or bunch length is 0";
115 return "Fit of the raw bunch was not successful";
117 return "Chi2 of the fit could not be determined";
119 return "Calo bunch could not be selected";
121 return "No ADC value above threshold found";
125 return "Unknown error code";
133 mIsZerosupressed(true),
135 mNameShort(nameshort),
145 if ((
min >
max) ||
min > constants::EMCAL_MAXTIMEBINS ||
max > constants::EMCAL_MAXTIMEBINS) {
146 LOG(warn) <<
"Attempt to set Invalid time bin range (Min , Max) = (" <<
min <<
", " <<
max <<
"), Ingored";
155 return *std::max_element(
data.begin(),
data.end());
161 int first(0), last(0);
162 int tmpfirst = indexMaxADC;
163 int tmplast = indexMaxADC;
164 double prevFirst = adcValues[indexMaxADC];
165 double prevLast = adcValues[indexMaxADC];
166 bool firstJump =
false;
167 bool lastJump =
false;
169 while ((tmpfirst >= 0) && (adcValues[tmpfirst] >= threshold) && (!firstJump)) {
171 if (tmpfirst != indexMaxADC) {
172 if (adcValues[tmpfirst] >= prevFirst) {
176 prevFirst = adcValues[tmpfirst];
180 while ((tmplast < adcValues.size()) && (adcValues[tmplast] >= threshold) && (!lastJump)) {
182 if (tmplast != indexMaxADC) {
183 if (adcValues[tmplast] >= prevLast) {
187 prevLast = adcValues[tmplast];
193 if (firstJump || tmpfirst < 0) {
196 if (lastJump || tmplast >= adcValues.size()) {
203 return std::make_tuple(
first, last);
208 std::array<double, constants::EMCAL_MAXTIMEBINS> outarray;
210 const gsl::span<const uint16_t> sig(bunch.
getADC());
215 outarray[
i] = sig[
length -
i - 1] - ped;
218 return std::make_tuple(ped, outarray);
236 const std::vector<uint16_t>& sig = bunch.
getADC();
239 if (sig[
i] > maxADC) {
252 const std::vector<uint16_t>& sig = bunch.
getADC();
255 if (sig[
i] > maxADC) {
261 bool isBunchEdge =
false;
271 short bunchindex = -1;
272 short indexMaxInBunch(0), maxADCallBunches(-1);
274 for (
unsigned int i = 0;
i < bunchvector.size();
i++) {
277 if (maxADC > maxADCallBunches) {
279 indexMaxInBunch = maxIndex;
280 maxADCallBunches = maxADC;
285 if (bunchindex >= 0) {
292 return std::make_tuple(bunchindex, indexMaxInBunch, maxADCallBunches);
297 if ((mintime < 0 && maxtime < 0) || maxtime < 0) {
301 return (indexMaxADC < maxtime) && (indexMaxADC > mintime) ?
true :
false;
306 double adcErr,
double tau)
const
319 double xx = (
x -
time + tau) / tau;
323 f = amp * xx * xx * TMath::Exp(2 * (1 - xx));
331 chi2 /= (adcErr * adcErr);
339 int nsamples(0),
first(0), last(0), indexMaxADCRReveresed(0);
340 double peakADC(0.), pedestal(0.);
346 for (
unsigned int i = 0;
i < bunchvector.size();
i++) {
347 if (bunchvector[
i].getBunchLength() > bunchvector[
i].getADC().
size()) {
354 if (bunchindex >= 0) {
355 if (adcMAX >= adcThreshold) {
358 int bunchlength = bunchvector[bunchindex].getBunchLength();
359 const std::vector<uint16_t>& sig = bunchvector[bunchindex].getADC();
365 int testindexReverse = -1;
366 for (
int i = 0;
i < bunchlength;
i++) {
367 mReversed[
i] = sig[bunchlength -
i - 1] - pedestal;
370 testindexReverse =
i;
374 if (peakADC >= adcThreshold)
377 indexMaxADCRReveresed = indexMaxADC - bunchvector[bunchindex].getStartTime();
378 std::tie(
first, last) =
findPeakRegion(gsl::span<double>(&
mReversed[0], bunchvector[bunchindex].getBunchLength()), indexMaxADCRReveresed, adcThreshold);
382 if (
first != indexMaxADCRReveresed && last != indexMaxADCRReveresed) {
394 return std::make_tuple(
nsamples, bunchindex, peakADC, adcMAX, indexMaxADCRReveresed, pedestal,
first, last);
std::vector< uint16_t > nsamples
uint8_t getStartTime() const
Get the start time bin.
const std::vector< uint16_t > & getADC() const
Get range of ADC values in the bunch.
uint8_t getBunchLength() const
Get the length of the bunch (number of time bins)
static constexpr int getNumberOfErrorTypes() noexcept
Get the number of raw fit error types supported.
CaloRawFitter(const char *name, const char *nameshort)
Constructor.
bool isMaxADCBunchEdge(const Bunch &bunch) const
Check if the max. ADC value is at the edge of a bunch.
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.
static const char * getErrorTypeTitle(RawFitterError_t 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.
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::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.
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 * 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.
RawFitterError_t
Error codes for failures in raw fitter procedure.
@ LOW_SIGNAL
No ADC value above threshold found.
@ FIT_ERROR
Fit procedure failed.
@ BUNCH_NOT_OK
Bunch selection failed.
@ 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.
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.
int mNsamplePed
Number of samples used for pedestal calculation (first in bunch)
GLuint const GLchar * name
GLuint GLsizei GLsizei * length
std::ostream & operator<<(std::ostream &stream, const Cell &cell)
Stream operator for EMCAL cell.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"