#ifndef ALICALORAWANALYZER_H
#define ALICALORAWANALYZER_H
#include "Rtypes.h"
#include "TObject.h"
#include <vector>
#include "TObjArray.h"
#include "AliCaloFitResults.h"
#include "AliCaloConstants.h"
using namespace ALTRO;
using namespace CALO;
class AliCaloBunchInfo;
class AliCaloRawAnalyzer : public TObject
{
public:
AliCaloRawAnalyzer(const char *name="AliCaloRawAnalyzer", const char *nameshort="RawAna");
virtual ~AliCaloRawAnalyzer() { ; }
virtual AliCaloFitResults Evaluate( const std::vector<AliCaloBunchInfo> &,
UInt_t , UInt_t ) = 0;
static void PrintBunches( const std::vector<AliCaloBunchInfo> &bunchvector );
static void PrintBunch ( const AliCaloBunchInfo &bunch );
int PreFitEvaluateSamples( const std::vector<AliCaloBunchInfo> &bunchvector,
UInt_t altrocfg1, UInt_t altrocfg2, Int_t & index,
Float_t & maxf, short & maxamp, short & maxampindex,
Float_t & ped, int & first, int & last, int acut);
void SetTimeConstraint (int min, int max );
void SetVerbose (bool verbose = true){ fVerbose = verbose; }
void SetIsZeroSuppressed(bool iszs = true) { fIsZerosupressed = iszs ; }
void SetAmpCut (Float_t cut) { fAmpCut = cut ; }
void SetFitArrayCut(Int_t cut) { fFitArrayCut = cut ; }
void SetNsampleCut (Int_t cut) { fNsampleCut = cut ; }
void SetOverflowCut(Int_t cut) { fOverflowCut = cut ; }
void SetNsamplePed (Int_t i) { fNsamplePed = i ; }
void SetL1Phase (Double_t phase) { fL1Phase = phase ; }
bool GetIsZeroSuppressed() const { return fIsZerosupressed;}
Float_t GetAmpCut() const { return fAmpCut ; }
Int_t GetFitArrayCut() const { return fFitArrayCut ; }
Int_t GetNsampleCut() const { return fNsampleCut ; }
Int_t GetOverflowCut() const { return fOverflowCut ; }
Int_t GetNsamplePed() const { return fNsamplePed ; }
Double_t GetReversed(const int i) const { return fReversed[i]; }
const char * GetAlgoName() const { return fName ; }
const char * GetAlgoAbbr() const { return fNameShort ; }
Algo::fitAlgorithm GetAlgo() const { return fAlgo ; }
Double_t CalculateChi2(const Double_t amp, const Double_t time,
const Int_t first, const Int_t last,
const Double_t adcErr=1,
const Double_t tau=2.35) const;
void CalculateMeanAndRMS(const Int_t first, const Int_t last,
Double_t & mean, Double_t & rms);
short Max( const AliCaloBunchInfo *const bunch, int * maxindex) const;
UShort_t Max(const UShort_t *data, const int length ) const;
bool CheckBunchEdgesForMax( const AliCaloBunchInfo *const bunch) const;
bool IsInTimeRange( const int maxindex, const int maxtime, const int mintime ) const;
Float_t ReverseAndSubtractPed( const AliCaloBunchInfo *bunch,
UInt_t altrocfg1, UInt_t altrocfg2,
double * outarray ) const;
int SelectBunch( const std::vector<AliCaloBunchInfo> &bunchvector,
short * maxampbin, short * maxamplitude );
void SelectSubarray( const Double_t *date, int length, short maxindex,
int * first, int * last, int cut) const;
Float_t EvaluatePedestal(const UShort_t * const data, const int length ) const;
Float_t GetTau() const { return fTau ; }
void SetTau (Float_t tau) { fTau = tau ; }
Bool_t GetFixTau() const { return fFixTau ; }
void SetFixTau(Bool_t b) { fFixTau = b ; }
protected:
Double_t fReversed[ALTROMAXSAMPLES];
int fMinTimeIndex;
int fMaxTimeIndex;
int fFitArrayCut;
Float_t fAmpCut;
int fNsampleCut;
int fOverflowCut;
int fNsamplePed;
bool fIsZerosupressed;
bool fVerbose;
char fName[256];
char fNameShort[256];
Algo::fitAlgorithm fAlgo;
Double_t fL1Phase;
Double_t fAmp;
Double_t fTof;
Float_t fTau;
Bool_t fFixTau;
ClassDef(AliCaloRawAnalyzer, 3)
};
#endif