]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AOD/AliAODCaloCells.h
Fixed warnings (Constantin)
[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, Short_t &mclabel,      Double_t &efrac) const ;
34   Bool_t          SetCell(Short_t pos, Short_t  cellNumber, Double_t  amplitude,  Double_t  time, Short_t  mclabel = -1, Double_t  efrac = 0.)  ;
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 Short_t  GetCellPosition(Short_t cellNumber);
41   inline Double_t GetCellTime(Short_t cellNumber);
42   
43   inline Double_t GetAmplitude(Short_t pos) const;
44   inline Short_t  GetCellNumber(Short_t pos) const;
45   inline Double_t GetTime(Short_t pos) const;
46   
47   Bool_t          IsEMCAL() const { return (fType == kEMCALCell); }
48   Bool_t          IsPHOS()  const { return (fType == kPHOSCell) ; }
49   
50   Char_t          GetType() const { return fType;}
51   void            SetType(Char_t ttype) { fType=ttype; }
52   
53   // MC & embedding
54   inline Short_t  GetCellMCLabel(Short_t cellNumber) ;
55   inline Short_t  GetMCLabel(Short_t pos) const ;
56   
57   inline Double_t GetCellEFraction(Short_t cellNumber) ;
58   inline Double_t GetEFraction(Short_t pos) const ;  
59   
60   inline void     SetEFraction    (Short_t pos,         Double32_t efrac) ;
61   inline void     SetCellEFraction(Short_t cellNumber,  Double32_t efrac) ;
62   
63  protected:
64   
65   Int_t       fNCells;       // Number of cells
66   Short_t    *fCellNumber;   //[fNCells] array of cell numbers
67   Double32_t *fAmplitude;    //[fNCells][0.,0.,16] array with cell amplitudes (= energy!)
68   Double32_t *fTime;         //[fNCells][0.,0.,16] array with cell times
69   Double32_t *fEFraction;    //[fNCells][0.,0.,16] array with fraction of MC energy and data - for embedding
70   Short_t    *fMCLabel;      //[fNCells] array of MC labels
71   Bool_t      fIsSorted;     //! true if cell arrays are sorted by index
72   Char_t      fType;         // Cell type
73   
74   ClassDef(AliAODCaloCells, 3);
75   
76 };
77
78 Bool_t AliAODCaloCells::GetCell(Short_t pos, Short_t &cellNumber, Double_t &amplitude, 
79                                 Double_t &time, Short_t & mclabel, Double_t & efrac) const 
80
81   if (pos>=0 && pos<fNCells) 
82   {
83     cellNumber = fCellNumber[pos];
84     amplitude  = fAmplitude[pos];
85     
86     if(fTime)      time    = fTime[pos];
87     else           time    =-1.;
88     if(fMCLabel)   mclabel = fMCLabel[pos];
89     else           mclabel =-1 ; 
90     if(fEFraction) efrac   = fEFraction[pos];
91     else           efrac   = 0 ;
92     
93     return kTRUE;
94     
95   } else {
96     return kFALSE;
97   }
98 }
99
100 Double_t AliAODCaloCells::GetCellAmplitude(Short_t cellNumber)
101
102   if (!fIsSorted) {
103     Sort();
104     fIsSorted=kTRUE;
105   }
106
107   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
108   if (pos>=0 && fCellNumber[pos] == cellNumber) {
109     return fAmplitude[pos];
110   } else {
111     return 0.;
112   }
113 }
114
115 Double_t AliAODCaloCells::GetCellTime(Short_t cellNumber)
116
117   if(!fTime) return -1;
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 fTime[pos];
127   } else {
128     return -1.;
129   }
130 }
131
132 Double_t AliAODCaloCells::GetAmplitude(Short_t pos) const 
133
134   if (pos>=0 && pos<fNCells) {
135     return fAmplitude[pos];
136   } else {
137     return 0.;
138   }
139 }
140
141 Double_t AliAODCaloCells::GetTime(Short_t pos) const 
142
143   if (pos>=0 && pos<fNCells && fTime) {
144     return fTime[pos];
145   } else {
146     return -1.;
147   }
148 }
149
150 Short_t AliAODCaloCells::GetCellNumber(Short_t pos) const 
151
152   if (pos>=0 && pos<fNCells) {
153     return fCellNumber[pos];
154   } else {
155     return fNCells;
156   }
157 }
158
159 Short_t AliAODCaloCells::GetCellPosition(Short_t cellNumber)
160
161   if (!fIsSorted) {
162     Sort();
163     fIsSorted=kTRUE;
164   }
165
166    Int_t nabove, nbelow, middle;
167    Short_t pos = -1;
168
169    nabove = fNCells + 1;
170    nbelow = 0;
171    while (nabove - nbelow > 1) {
172       middle = (nabove + nbelow) / 2;
173       if (cellNumber == fCellNumber[middle-1]) {
174           pos =   middle - 1;
175           break;
176       }
177       if (cellNumber  < fCellNumber[middle-1]) nabove = middle;
178       else                                     nbelow = middle;
179    }
180
181   return pos;
182 }
183
184 Short_t AliAODCaloCells::GetMCLabel(Short_t pos) const 
185
186   if (pos>=0 && pos<fNCells && fMCLabel) {
187     return fMCLabel[pos];
188   } else {
189     return 0;
190   }
191 }
192
193 Double_t AliAODCaloCells::GetEFraction(Short_t pos) const 
194
195   if (pos>=0 && pos<fNCells && fEFraction) {
196     return fEFraction[pos];
197   } else {
198     return 0.;
199   }
200 }
201
202 Short_t AliAODCaloCells::GetCellMCLabel(Short_t cellNumber)
203
204   if(!fMCLabel) return -1;
205   
206   if (!fIsSorted) {
207     Sort();
208     fIsSorted=kTRUE;
209   }
210   
211   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
212   if (pos>=0 && fCellNumber[pos] == cellNumber) {
213     return fMCLabel[pos];
214   } else {
215     return 0;
216   }
217 }
218
219 Double_t AliAODCaloCells::GetCellEFraction(Short_t cellNumber)
220
221   if(!fEFraction) return 0;
222
223   if (!fIsSorted) {
224     Sort();
225     fIsSorted=kTRUE;
226   }
227   
228   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
229   if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber) {
230     return fEFraction[pos];
231   } else {
232     return -1.;
233   }
234 }
235
236 void AliAODCaloCells::SetEFraction(Short_t pos,  Double32_t efrac)
237 {
238   // Sets the fraction of energy from MC with respect to data at the given position
239   
240   
241   if (pos>=0 && pos < fNCells) 
242   {
243     if(!fEFraction) fEFraction = new Double32_t[fNCells];
244     fEFraction[pos]  = efrac;
245   } 
246 }
247
248 void AliAODCaloCells::SetCellEFraction(Short_t cellNumber, Double32_t efrac)
249
250   if (!fIsSorted) {
251     Sort();
252     fIsSorted=kTRUE;
253   }
254   
255   Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
256   if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber) 
257   {
258     if(!fEFraction) fEFraction = new Double32_t[fNCells];
259     fEFraction[pos] = efrac;
260   } 
261 }
262
263
264 #endif