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