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