]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/ESD/AliESDCaloCells.h
added headers needed for compilation
[u/mrichter/AliRoot.git] / STEER / ESD / 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   
29   virtual AliVCaloCells * CopyCaloCells(Bool_t all) const;
30   virtual void    Copy(TObject &obj) const;
31   void            Clear(const Option_t*);
32   void            CreateContainer(Short_t nCells);
33   void            DeleteContainer();
34   void            Sort();
35   
36   Bool_t          IsEMCAL()  const { return (fType == kEMCALCell); }
37   Bool_t          IsPHOS()   const { return (fType == kPHOSCell) ; }
38   Char_t          GetType()  const { return  fType               ; }
39   void            SetType(Char_t t){ fType = t                   ; }
40   
41   inline Bool_t   GetCell(Short_t pos, Short_t &cellNumber, Double_t &amplitude, Double_t &time, Int_t &mclabel,      Double_t &efrac) const;
42   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);
43   
44   Short_t         GetNumberOfCells() const  { return fNCells ; }
45   void            SetNumberOfCells(Int_t n) { fNCells = n    ; }
46   
47   
48   inline Double_t GetCellAmplitude(Short_t cellNumber);
49   inline Bool_t   GetCellHighGain(Short_t cellNumber);  //is this cell High Gain
50   inline Short_t  GetCellPosition(Short_t cellNumber);
51   inline Double_t GetCellTime(Short_t cellNumber);
52   
53   inline Double_t GetAmplitude(Short_t pos) const;
54   inline Bool_t   GetHighGain(Short_t pos) const;
55   inline Double_t GetTime(Short_t pos) const;
56   inline Short_t  GetCellNumber(Short_t pos) const;
57
58   // MC & embedding
59   inline Int_t    GetCellMCLabel(Short_t cellNumber) ;
60   inline Int_t    GetMCLabel(Short_t pos) const ;
61   
62   inline Double_t GetCellEFraction(Short_t cellNumber) ;
63   inline Double_t GetEFraction(Short_t pos) const ;
64   
65   inline void     SetEFraction    (Short_t pos,         Double32_t efrac) ;
66   inline void     SetCellEFraction(Short_t cellNumber,  Double32_t efrac) ;
67   
68  protected:
69   
70   Int_t       fNCells;       // Number of cells
71   Bool_t     *fHGLG;         //[fNCells] if sell HG or LG
72   Short_t    *fCellNumber;   //[fNCells] array of cell numbers
73   Double32_t *fAmplitude;    //[fNCells][0.,0.,16] array with cell amplitudes (= energy!)
74   Double32_t *fTime;         //[fNCells][0.,0.,16] array with cell times
75   Double32_t *fEFraction;    //[fNCells][0.,0.,16] array with fraction of MC energy and data - for embedding
76   Int_t      *fMCLabel;      //[fNCells] array of MC labels
77   Bool_t      fIsSorted;     //! true if cell arrays are sorted by index
78   Char_t      fType;         // Cell type
79
80   ClassDef(AliESDCaloCells, 5);
81 };
82
83
84 Bool_t AliESDCaloCells::GetCell(Short_t pos, Short_t &cellNumber, Double_t &amplitude, 
85                                 Double_t & time, Int_t & mclabel, Double_t & efrac) const 
86
87   if (pos>=0 && pos<fNCells) 
88   {
89     cellNumber = fCellNumber[pos];
90     amplitude  = fAmplitude[pos];
91     time       = fTime[pos];
92     
93     if(fMCLabel)   mclabel = fMCLabel[pos];
94     else           mclabel =-1 ; 
95     if(fEFraction) efrac   = fEFraction[pos];
96     else           efrac   = 0 ;
97     
98     return kTRUE;
99     
100   } else 
101   {
102     return kFALSE;
103   }
104 }
105
106 Double_t AliESDCaloCells::GetCellAmplitude(Short_t cellNumber)
107
108   if (!fIsSorted) {
109     Sort();
110     fIsSorted=kTRUE;
111   }
112
113   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
114   if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber ) {
115     return fAmplitude[pos];
116   } else {
117     return 0.;
118   }
119 }
120
121 Bool_t AliESDCaloCells::GetCellHighGain(Short_t cellNumber)
122
123   if (!fIsSorted) {
124     Sort();
125     fIsSorted=kTRUE;
126   }
127
128   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
129   if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber ) {
130     if(fHGLG)
131       return fHGLG[pos];
132     else //old version of ESD, for data HG flag stored in MCLabel 
133       return !(fMCLabel[pos]==-2) ;
134   } else {
135     return 0.;
136   }
137 }
138
139 Double_t AliESDCaloCells::GetCellTime(Short_t cellNumber)
140
141   if (!fIsSorted) {
142     Sort();
143     fIsSorted=kTRUE;
144   }
145
146   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
147   if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber) {
148     return fTime[pos];
149   } else {
150     return -1.;
151   }
152 }
153
154 Double_t AliESDCaloCells::GetAmplitude(Short_t pos) const 
155
156   if (pos>=0 && pos<fNCells) {
157     return fAmplitude[pos];
158   } else {
159     return 0.;
160   }
161 }
162 Bool_t AliESDCaloCells::GetHighGain(Short_t pos) const 
163
164   if (pos>=0 && pos<fNCells) {
165     if(fHGLG)
166       return fHGLG[pos];
167     else //old version of ESD, for data HG flag stored in MCLabel 
168       return !(fMCLabel[pos]==-2) ;
169   } else {
170     return 0.;
171   }
172 }
173
174 Double_t AliESDCaloCells::GetTime(Short_t pos) const 
175
176   if (pos>=0 && pos<fNCells) {
177     return fTime[pos];
178   } else {
179     return -1.;
180   }
181 }
182
183 Short_t AliESDCaloCells::GetCellNumber(Short_t pos) const 
184
185   if (pos>=0 && pos<fNCells) {
186     return fCellNumber[pos];
187   } else {
188     return fNCells;
189   }
190 }
191
192 Short_t AliESDCaloCells::GetCellPosition(Short_t cellNumber)
193
194   if (!fIsSorted) {
195     Sort();
196     fIsSorted=kTRUE;
197   }
198   
199   Int_t nabove, nbelow, middle;
200   Short_t pos = -1;
201   
202   nabove = fNCells + 1;
203   nbelow = 0;
204   while (nabove - nbelow > 1) {
205     middle = (nabove + nbelow) / 2;
206     if (cellNumber == fCellNumber[middle-1]) {
207       pos =   middle - 1;
208       break;
209     }
210     if (cellNumber  < fCellNumber[middle-1]) nabove = middle;
211     else                                     nbelow = middle;
212   }
213   
214   return pos;
215 }
216
217 Int_t AliESDCaloCells::GetMCLabel(Short_t pos) const 
218
219   if (pos>=0 && pos<fNCells && fMCLabel) {
220     return fMCLabel[pos];
221   } else {
222     return -1 ;
223   }
224 }
225
226 Double_t AliESDCaloCells::GetEFraction(Short_t pos) const 
227
228   if (pos>=0 && pos<fNCells && fEFraction) {
229     return fEFraction[pos];
230   } else {
231     return 0.;
232   }
233 }
234
235 Int_t AliESDCaloCells::GetCellMCLabel(Short_t cellNumber)
236
237   if (!fIsSorted) {
238     Sort();
239     fIsSorted=kTRUE;
240   }
241   
242   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
243   if (pos>=0 && fCellNumber[pos] == cellNumber && fMCLabel) {
244     return fMCLabel[pos];
245   } else {
246     return -1;
247   }
248 }
249
250 Double_t AliESDCaloCells::GetCellEFraction(Short_t cellNumber)
251
252   if (!fIsSorted) {
253     Sort();
254     fIsSorted=kTRUE;
255   }
256   
257   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
258   if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber && fEFraction) {
259     return fEFraction[pos];
260   } else {
261     return 0.;
262   }
263 }
264
265 void AliESDCaloCells::SetEFraction(Short_t pos,  Double32_t efrac)
266 {
267   // Sets the fraction of energy from MC with respect to data at the given position
268   
269   if (pos>=0 && pos < fNCells) 
270   {
271     if(!fEFraction) fEFraction = new Double32_t[fNCells];
272     fEFraction[pos]  = efrac;
273   } 
274 }
275
276 void AliESDCaloCells::SetCellEFraction(Short_t cellNumber, Double32_t efrac)
277
278   if (!fIsSorted) {
279     Sort();
280     fIsSorted=kTRUE;
281   }
282   
283   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
284   if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber) 
285   {
286     if(!fEFraction) fEFraction = new Double32_t[fNCells];
287     fEFraction[pos] = efrac;
288   } 
289 }
290
291
292 #endif