ALIROOT-5492 Add field to separate HG and LG digits
[u/mrichter/AliRoot.git] / STEER / AOD / AliAODCaloCells.h
CommitLineData
8d122774 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
c8fe2783 14#include <AliVCaloCells.h>
8d122774 15#include <TMath.h>
16
c8fe2783 17class AliAODCaloCells : public AliVCaloCells
8d122774 18{
19 public:
8d122774 20 AliAODCaloCells();
c8fe2783 21 AliAODCaloCells(const char* name, const char* title, VCells_t ttype=kUndef);
5c1dc41f 22 AliAODCaloCells(const AliAODCaloCells& cells);
23 AliAODCaloCells& operator=(const AliAODCaloCells& cells);
8d122774 24 virtual ~AliAODCaloCells();
8dd6eba0 25
77e93dc2 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();
8d122774 32
60d77596 33 inline Bool_t GetCell(Short_t pos, Short_t &cellNumber, Double_t &amplitude, Double_t &time, Int_t &mclabel, Double_t &efrac) const ;
dcd7321d 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);
77e93dc2 35
36 Short_t GetNumberOfCells() const { return fNCells ; }
37 void SetNumberOfCells(Int_t n) { fNCells = n ; }
8d122774 38
8d122774 39 inline Double_t GetCellAmplitude(Short_t cellNumber);
dcd7321d 40 inline Bool_t GetCellHighGain(Short_t cellNumber); //is this cell High Gain
b4620c80 41 inline Short_t GetCellPosition(Short_t cellNumber);
77e93dc2 42 inline Double_t GetCellTime(Short_t cellNumber);
43
8d122774 44 inline Double_t GetAmplitude(Short_t pos) const;
dcd7321d 45 inline Bool_t GetHighGain(Short_t pos) const;
8d122774 46 inline Short_t GetCellNumber(Short_t pos) const;
77e93dc2 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
60d77596 56 inline Int_t GetCellMCLabel(Short_t cellNumber) ;
57 inline Int_t GetMCLabel(Short_t pos) const ;
77e93dc2 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
8d122774 65 protected:
77e93dc2 66
8d122774 67 Int_t fNCells; // Number of cells
dcd7321d 68 Bool_t *fHGLG; //[fNCells] if sell HG or LG
8d122774 69 Short_t *fCellNumber; //[fNCells] array of cell numbers
e649177a 70 Double32_t *fAmplitude; //[fNCells][0.,0.,16] array with cell amplitudes (= energy!)
77e93dc2 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
60d77596 73 Int_t *fMCLabel; //[fNCells] array of MC labels
8d122774 74 Bool_t fIsSorted; //! true if cell arrays are sorted by index
75 Char_t fType; // Cell type
76
60d77596 77 ClassDef(AliAODCaloCells, 4);
8d122774 78
8d122774 79};
80
77e93dc2 81Bool_t AliAODCaloCells::GetCell(Short_t pos, Short_t &cellNumber, Double_t &amplitude,
60d77596 82 Double_t &time, Int_t & mclabel, Double_t & efrac) const
8d122774 83{
77e93dc2 84 if (pos>=0 && pos<fNCells)
85 {
8d122774 86 cellNumber = fCellNumber[pos];
77e93dc2 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
8d122774 96 return kTRUE;
77e93dc2 97
8d122774 98 } else {
8d122774 99 return kFALSE;
100 }
101}
102
8d122774 103Double_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);
37792174 111 if (pos>=0 && fCellNumber[pos] == cellNumber) {
8d122774 112 return fAmplitude[pos];
113 } else {
8d122774 114 return 0.;
115 }
116}
dcd7321d 117Bool_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}
8d122774 131
77e93dc2 132Double_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}
8d122774 148
149Double_t AliAODCaloCells::GetAmplitude(Short_t pos) const
150{
151 if (pos>=0 && pos<fNCells) {
152 return fAmplitude[pos];
153 } else {
8d122774 154 return 0.;
155 }
156}
dcd7321d 157Bool_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
8d122774 166
77e93dc2 167Double_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}
8d122774 175
176Short_t AliAODCaloCells::GetCellNumber(Short_t pos) const
177{
178 if (pos>=0 && pos<fNCells) {
179 return fCellNumber[pos];
180 } else {
8d122774 181 return fNCells;
182 }
183}
184
b4620c80 185Short_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
60d77596 210Int_t AliAODCaloCells::GetMCLabel(Short_t pos) const
77e93dc2 211{
212 if (pos>=0 && pos<fNCells && fMCLabel) {
213 return fMCLabel[pos];
214 } else {
121a537d 215 return 0;
77e93dc2 216 }
217}
218
219Double_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
60d77596 228Int_t AliAODCaloCells::GetCellMCLabel(Short_t cellNumber)
77e93dc2 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 {
121a537d 241 return 0;
77e93dc2 242 }
243}
244
245Double_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
262void 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
274void 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
8d122774 289
290#endif