]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AOD/AliAODCaloCells.h
ClassDef increased
[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 //old version of AOD, 
129       return !(fMCLabel[pos]==-2) ;
130   } else {
131     return 0.;
132   }
133 }
134
135 Double_t AliAODCaloCells::GetCellTime(Short_t cellNumber)
136
137   if(!fTime) return -1;
138   
139   if (!fIsSorted) {
140     Sort();
141     fIsSorted=kTRUE;
142   }
143   
144   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
145   if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber) {
146     return fTime[pos];
147   } else {
148     return -1.;
149   }
150 }
151
152 Double_t AliAODCaloCells::GetAmplitude(Short_t pos) const 
153
154   if (pos>=0 && pos<fNCells) {
155     return fAmplitude[pos];
156   } else {
157     return 0.;
158   }
159 }
160 Bool_t AliAODCaloCells::GetHighGain(Short_t pos) const 
161
162   if (pos>=0 && pos<fNCells) {
163     if(fHGLG)
164       return fHGLG[pos];
165     else //Old version of AOD store this flag in MCLabel
166       return !(fMCLabel[pos]==-2) ;
167   } else {
168     return 0.;
169   }
170 }
171
172
173 Double_t AliAODCaloCells::GetTime(Short_t pos) const 
174
175   if (pos>=0 && pos<fNCells && fTime) {
176     return fTime[pos];
177   } else {
178     return -1.;
179   }
180 }
181
182 Short_t AliAODCaloCells::GetCellNumber(Short_t pos) const 
183
184   if (pos>=0 && pos<fNCells) {
185     return fCellNumber[pos];
186   } else {
187     return fNCells;
188   }
189 }
190
191 Short_t AliAODCaloCells::GetCellPosition(Short_t cellNumber)
192
193   if (!fIsSorted) {
194     Sort();
195     fIsSorted=kTRUE;
196   }
197
198    Int_t nabove, nbelow, middle;
199    Short_t pos = -1;
200
201    nabove = fNCells + 1;
202    nbelow = 0;
203    while (nabove - nbelow > 1) {
204       middle = (nabove + nbelow) / 2;
205       if (cellNumber == fCellNumber[middle-1]) {
206           pos =   middle - 1;
207           break;
208       }
209       if (cellNumber  < fCellNumber[middle-1]) nabove = middle;
210       else                                     nbelow = middle;
211    }
212
213   return pos;
214 }
215
216 Int_t AliAODCaloCells::GetMCLabel(Short_t pos) const 
217
218   if (pos>=0 && pos<fNCells && fMCLabel) {
219     return fMCLabel[pos];
220   } else {
221     return 0;
222   }
223 }
224
225 Double_t AliAODCaloCells::GetEFraction(Short_t pos) const 
226
227   if (pos>=0 && pos<fNCells && fEFraction) {
228     return fEFraction[pos];
229   } else {
230     return 0.;
231   }
232 }
233
234 Int_t AliAODCaloCells::GetCellMCLabel(Short_t cellNumber)
235
236   if(!fMCLabel) return -1;
237   
238   if (!fIsSorted) {
239     Sort();
240     fIsSorted=kTRUE;
241   }
242   
243   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
244   if (pos>=0 && fCellNumber[pos] == cellNumber) {
245     return fMCLabel[pos];
246   } else {
247     return 0;
248   }
249 }
250
251 Double_t AliAODCaloCells::GetCellEFraction(Short_t cellNumber)
252
253   if(!fEFraction) return 0;
254
255   if (!fIsSorted) {
256     Sort();
257     fIsSorted=kTRUE;
258   }
259   
260   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
261   if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber) {
262     return fEFraction[pos];
263   } else {
264     return -1.;
265   }
266 }
267
268 void AliAODCaloCells::SetEFraction(Short_t pos,  Double32_t efrac)
269 {
270   // Sets the fraction of energy from MC with respect to data at the given position
271   
272   
273   if (pos>=0 && pos < fNCells) 
274   {
275     if(!fEFraction) fEFraction = new Double32_t[fNCells];
276     fEFraction[pos]  = efrac;
277   } 
278 }
279
280 void AliAODCaloCells::SetCellEFraction(Short_t cellNumber, Double32_t efrac)
281
282   if (!fIsSorted) {
283     Sort();
284     fIsSorted=kTRUE;
285   }
286   
287   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
288   if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber) 
289   {
290     if(!fEFraction) fEFraction = new Double32_t[fNCells];
291     fEFraction[pos] = efrac;
292   } 
293 }
294
295
296 #endif