#ifndef ALIESDCALOCELLS_H
#define ALIESDCALOCELLS_H
#include <AliVCaloCells.h>
#include <TMath.h>
class AliESDCaloCells : public AliVCaloCells
{
public:
AliESDCaloCells();
AliESDCaloCells(const char* name, const char* title, VCells_t ttype=kUndef);
AliESDCaloCells(const AliESDCaloCells & cells);
AliESDCaloCells & operator=(const AliESDCaloCells& source);
virtual ~AliESDCaloCells();
virtual AliVCaloCells * CopyCaloCells(Bool_t all) const;
virtual void Copy(TObject &obj) const;
void Clear(const Option_t*);
void CreateContainer(Short_t nCells);
void DeleteContainer();
void Sort();
Bool_t IsEMCAL() const { return (fType == kEMCALCell); }
Bool_t IsPHOS() const { return (fType == kPHOSCell) ; }
Char_t GetType() const { return fType ; }
void SetType(Char_t t){ fType = t ; }
inline Bool_t GetCell(Short_t pos, Short_t &cellNumber, Double_t &litude, Double_t &time, Int_t &mclabel, Double_t &efrac) const;
Bool_t SetCell(Short_t pos, Short_t cellNumber, Double_t amplitude, Double_t time, Int_t mclabel = -1, Double_t efrac = 0., Bool_t isHG=kFALSE);
Short_t GetNumberOfCells() const { return fNCells ; }
void SetNumberOfCells(Int_t n) { fNCells = n ; }
inline Double_t GetCellAmplitude(Short_t cellNumber);
inline Bool_t GetCellHighGain(Short_t cellNumber);
inline Short_t GetCellPosition(Short_t cellNumber);
inline Double_t GetCellTime(Short_t cellNumber);
inline Double_t GetAmplitude(Short_t pos) const;
inline Bool_t GetHighGain(Short_t pos) const;
inline Double_t GetTime(Short_t pos) const;
inline Short_t GetCellNumber(Short_t pos) const;
inline Int_t GetCellMCLabel(Short_t cellNumber) ;
inline Int_t GetMCLabel(Short_t pos) const ;
inline Double_t GetCellEFraction(Short_t cellNumber) ;
inline Double_t GetEFraction(Short_t pos) const ;
inline void SetEFraction (Short_t pos, Double32_t efrac) ;
inline void SetCellEFraction(Short_t cellNumber, Double32_t efrac) ;
protected:
Int_t fNCells;
Bool_t *fHGLG;
Short_t *fCellNumber;
Double32_t *fAmplitude;
Double32_t *fTime;
Double32_t *fEFraction;
Int_t *fMCLabel;
Bool_t fIsSorted;
Char_t fType;
ClassDef(AliESDCaloCells, 5);
};
Bool_t AliESDCaloCells::GetCell(Short_t pos, Short_t &cellNumber, Double_t &litude,
Double_t & time, Int_t & mclabel, Double_t & efrac) const
{
if (pos>=0 && pos<fNCells)
{
cellNumber = fCellNumber[pos];
amplitude = fAmplitude[pos];
time = fTime[pos];
if(fMCLabel) mclabel = fMCLabel[pos];
else mclabel =-1 ;
if(fEFraction) efrac = fEFraction[pos];
else efrac = 0 ;
return kTRUE;
} else
{
return kFALSE;
}
}
Double_t AliESDCaloCells::GetCellAmplitude(Short_t cellNumber)
{
if (!fIsSorted) {
Sort();
fIsSorted=kTRUE;
}
Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber ) {
return fAmplitude[pos];
} else {
return 0.;
}
}
Bool_t AliESDCaloCells::GetCellHighGain(Short_t cellNumber)
{
if (!fIsSorted) {
Sort();
fIsSorted=kTRUE;
}
Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber ) {
if(fHGLG)
return fHGLG[pos];
else{
if(fMCLabel)
return !(fMCLabel[pos]==-2) ;
else
return kTRUE ;
}
} else {
return kFALSE;
}
}
Double_t AliESDCaloCells::GetCellTime(Short_t cellNumber)
{
if (!fIsSorted) {
Sort();
fIsSorted=kTRUE;
}
Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber) {
return fTime[pos];
} else {
return -1.;
}
}
Double_t AliESDCaloCells::GetAmplitude(Short_t pos) const
{
if (pos>=0 && pos<fNCells) {
return fAmplitude[pos];
} else {
return 0.;
}
}
Bool_t AliESDCaloCells::GetHighGain(Short_t pos) const
{
if (pos>=0 && pos<fNCells) {
if(fHGLG)
return fHGLG[pos];
else{
if(fMCLabel)
return !(fMCLabel[pos]==-2) ;
else
return kTRUE ;
}
} else {
return kFALSE;
}
}
Double_t AliESDCaloCells::GetTime(Short_t pos) const
{
if (pos>=0 && pos<fNCells) {
return fTime[pos];
} else {
return -1.;
}
}
Short_t AliESDCaloCells::GetCellNumber(Short_t pos) const
{
if (pos>=0 && pos<fNCells) {
return fCellNumber[pos];
} else {
return fNCells;
}
}
Short_t AliESDCaloCells::GetCellPosition(Short_t cellNumber)
{
if (!fIsSorted) {
Sort();
fIsSorted=kTRUE;
}
Int_t nabove, nbelow, middle;
Short_t pos = -1;
nabove = fNCells + 1;
nbelow = 0;
while (nabove - nbelow > 1) {
middle = (nabove + nbelow) / 2;
if (cellNumber == fCellNumber[middle-1]) {
pos = middle - 1;
break;
}
if (cellNumber < fCellNumber[middle-1]) nabove = middle;
else nbelow = middle;
}
return pos;
}
Int_t AliESDCaloCells::GetMCLabel(Short_t pos) const
{
if (pos>=0 && pos<fNCells && fMCLabel) {
return fMCLabel[pos];
} else {
return -1 ;
}
}
Double_t AliESDCaloCells::GetEFraction(Short_t pos) const
{
if (pos>=0 && pos<fNCells && fEFraction) {
return fEFraction[pos];
} else {
return 0.;
}
}
Int_t AliESDCaloCells::GetCellMCLabel(Short_t cellNumber)
{
if (!fIsSorted) {
Sort();
fIsSorted=kTRUE;
}
Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
if (pos>=0 && fCellNumber[pos] == cellNumber && fMCLabel) {
return fMCLabel[pos];
} else {
return -1;
}
}
Double_t AliESDCaloCells::GetCellEFraction(Short_t cellNumber)
{
if (!fIsSorted) {
Sort();
fIsSorted=kTRUE;
}
Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber && fEFraction) {
return fEFraction[pos];
} else {
return 0.;
}
}
void AliESDCaloCells::SetEFraction(Short_t pos, Double32_t efrac)
{
if (pos>=0 && pos < fNCells)
{
if(!fEFraction) fEFraction = new Double32_t[fNCells];
fEFraction[pos] = efrac;
}
}
void AliESDCaloCells::SetCellEFraction(Short_t cellNumber, Double32_t efrac)
{
if (!fIsSorted) {
Sort();
fIsSorted=kTRUE;
}
Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber)
{
if(!fEFraction) fEFraction = new Double32_t[fNCells];
fEFraction[pos] = efrac;
}
}
#endif