]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDCaloCells.h
Bug fix - chack the abs values
[u/mrichter/AliRoot.git] / STEER / AliESDCaloCells.h
1 #ifndef ALIESDCALOCELLS_H
2 #define ALIESDCALOCELLS_H
3 /* Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5 /* $Id$ */
6 /* $Log $ */
7
8 //-------------------------------------------------------------------------
9 //     ESD class to store calorimeter cell data
10 //     Clone of AliAODCaloCells made by Markus Oldenburg, CERN
11 //     Author: Gustavo Conesa Balbastre INFN-LNF
12 //
13 //-------------------------------------------------------------------------
14
15
16 #include <AliVCaloCells.h>
17 #include <TMath.h>
18
19 class AliESDCaloCells : public AliVCaloCells
20 {
21  public:
22
23   AliESDCaloCells();
24   AliESDCaloCells(const char* name, const char* title, VCells_t ttype=kUndef);
25   AliESDCaloCells(const AliESDCaloCells & cells);
26   AliESDCaloCells & operator=(const AliESDCaloCells& source);
27   virtual ~AliESDCaloCells();
28   virtual void Copy(TObject &obj) const;
29   virtual AliVCaloCells * CopyCaloCells(Bool_t all) const;
30   void Clear(const Option_t*);
31   
32   Bool_t IsEMCAL()  const { return (fType == kEMCALCell);}
33   Bool_t IsPHOS()   const { return (fType == kPHOSCell) ;}
34   Char_t  GetType() const { return  fType;}
35   void    SetType(Char_t ttype) { fType = ttype; }
36
37   void CreateContainer(Short_t nCells);
38   void DeleteContainer();
39   void Sort();
40   
41   Bool_t SetCell(Short_t pos, Short_t cellNumber, Double_t amplitude, Double_t time);
42   
43   Short_t GetNumberOfCells() const { return fNCells; }
44   void SetNumberOfCells(Int_t n) { fNCells = n ; }
45   inline Bool_t   GetCell(Short_t pos, Short_t &cellNumber, Double_t &amplitude, Double_t &time) const;
46   inline Double_t GetCellAmplitude(Short_t cellNumber);
47   inline Double_t GetCellTime(Short_t cellNumber);
48   inline Double_t GetAmplitude(Short_t pos) const;
49   inline Double_t GetTime(Short_t pos) const;
50   inline Short_t  GetCellNumber(Short_t pos) const;
51
52  protected:
53   Int_t       fNCells;       // Number of cells
54   Short_t    *fCellNumber;   //[fNCells] array of cell numbers
55   Double32_t *fAmplitude;    //[fNCells][0.,0.,16] array with cell amplitudes (= energy!)
56   Double32_t *fTime;         //[fNCells][0.,0.,16] array with cell times
57   Bool_t      fIsSorted;     //! true if cell arrays are sorted by index
58   Char_t      fType;         // Cell type
59
60   ClassDef(AliESDCaloCells, 2);
61 };
62
63
64 Bool_t AliESDCaloCells::GetCell(Short_t pos, Short_t &cellNumber, Double_t &amplitude, Double_t & time) const 
65
66   if (pos>=0 && pos<fNCells) {
67     cellNumber = fCellNumber[pos];
68     amplitude = fAmplitude[pos];
69     time = fTime[pos];
70     return kTRUE;
71   } else {
72     Error("GetCell","Invalid cell array index %d", pos);
73     return kFALSE;
74   }
75 }
76
77
78 Double_t AliESDCaloCells::GetCellAmplitude(Short_t cellNumber)
79
80   if (!fIsSorted) {
81     Sort();
82     fIsSorted=kTRUE;
83   }
84
85   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
86   if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber ) {
87     return fAmplitude[pos];
88   } else {
89     Warning("GetCellAmplitude","Wrong cell array index %d", pos);
90     return 0.;
91   }
92 }
93
94 Double_t AliESDCaloCells::GetCellTime(Short_t cellNumber)
95
96   if (!fIsSorted) {
97     Sort();
98     fIsSorted=kTRUE;
99   }
100
101   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
102   if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber) {
103     return fTime[pos];
104   } else {
105     Warning("GetCellTime","Wrong cell array index %d", pos);
106     return 0.;
107   }
108 }
109
110 Double_t AliESDCaloCells::GetAmplitude(Short_t pos) const 
111
112   if (pos>=0 && pos<fNCells) {
113     return fAmplitude[pos];
114   } else {
115     Error("GetAmplitude","Invalid cell array index %d", pos);
116     return 0.;
117   }
118 }
119
120 Double_t AliESDCaloCells::GetTime(Short_t pos) const 
121
122   if (pos>=0 && pos<fNCells) {
123     return fTime[pos];
124   } else {
125     Error("GetTime","Invalid cell array index %d", pos);
126     return 0.;
127   }
128 }
129
130 Short_t AliESDCaloCells::GetCellNumber(Short_t pos) const 
131
132   if (pos>=0 && pos<fNCells) {
133     return fCellNumber[pos];
134   } else {
135     Error("GetCellNumber","Invalid cell array index %d", pos);
136     return fNCells;
137   }
138 }
139
140 #endif