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