Line data Source code
1 : /* Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
2 : * See cxx source for full Copyright notice */
3 :
4 :
5 : //-------------------------------------------------------------------------
6 : /// \class AliAODCaloCells
7 : /// \brief Class for calorimeter cell AOD data handling
8 : ///
9 : /// AOD class to store calorimeter cell data
10 : ///
11 : /// Data is stored in different arrays, each entry of the array corresponding to a cell.
12 : /// The data stored is the cell energy, time, high gain bool, absolute id number,
13 : /// MC label that deposited most energy, and a container for the MC embedded energy.
14 : ///
15 : /// \author Markus Oldenburg, CERN.
16 : /// \author Gustavo Conesa Balbastre, <Gustavo.Conesa.Balbastre@cern.ch>, LPSC-Grenoble
17 : ///
18 : //-------------------------------------------------------------------------
19 :
20 : #ifndef ALIAODCELLS_H
21 : #define ALIAODCELLS_H
22 :
23 : #include <AliVCaloCells.h>
24 : #include <TMath.h>
25 :
26 : class AliAODCaloCells : public AliVCaloCells
27 : {
28 : public:
29 : AliAODCaloCells();
30 : AliAODCaloCells(const char* name, const char* title, VCells_t ttype=kUndef);
31 : AliAODCaloCells(const AliAODCaloCells& cells);
32 : AliAODCaloCells& operator=(const AliAODCaloCells& cells);
33 : virtual ~AliAODCaloCells();
34 :
35 : virtual AliVCaloCells* CopyCaloCells(Bool_t all) const;
36 : virtual void Copy(TObject &obj) const;
37 : void Clear(const Option_t*);
38 : void CreateContainer(Short_t nCells);
39 : void DeleteContainer();
40 : void Sort();
41 :
42 : inline Bool_t GetCell(Short_t pos, Short_t &cellNumber, Double_t &litude, Double_t &time, Int_t &mclabel, Double_t &efrac) const ;
43 : 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);
44 :
45 16 : Short_t GetNumberOfCells() const { return fNCells ; }
46 0 : void SetNumberOfCells(Int_t n) { fNCells = n ; }
47 :
48 : inline Double_t GetCellAmplitude(Short_t cellNumber);
49 : inline Bool_t GetCellHighGain(Short_t cellNumber); //is this cell High Gain
50 : inline Short_t GetCellPosition(Short_t cellNumber);
51 : inline Double_t GetCellTime(Short_t cellNumber);
52 :
53 : inline Double_t GetAmplitude(Short_t pos) const;
54 : inline Bool_t GetHighGain(Short_t pos) const;
55 : inline Short_t GetCellNumber(Short_t pos) const;
56 : inline Double_t GetTime(Short_t pos) const;
57 :
58 0 : Bool_t IsEMCAL() const { return (fType == kEMCALCell); }
59 0 : Bool_t IsPHOS() const { return (fType == kPHOSCell) ; }
60 :
61 0 : Char_t GetType() const { return fType;}
62 32 : void SetType(Char_t ttype) { fType=ttype; }
63 :
64 : // MC & embedding
65 : inline Int_t GetCellMCLabel(Short_t cellNumber) ;
66 : inline Int_t GetMCLabel(Short_t pos) const ;
67 :
68 : inline Double_t GetCellEFraction(Short_t cellNumber) ;
69 : inline Double_t GetEFraction(Short_t pos) const ;
70 :
71 : inline void SetEFraction (Short_t pos, Double32_t efrac) ;
72 : inline void SetCellEFraction(Short_t cellNumber, Double32_t efrac) ;
73 :
74 : protected:
75 :
76 : Int_t fNCells; ///< Number of cells.
77 :
78 : /// If Cell is High Gain or Low Gain
79 : Bool_t *fHGLG; //[fNCells]
80 :
81 : /// Array of cell absolute Id. numbers.
82 : Short_t *fCellNumber; //[fNCells]
83 :
84 : /// Array with cell amplitudes (= energy!).
85 : Double32_t *fAmplitude; //[fNCells][0.,0.,16]
86 :
87 : /// Array with cell times.
88 : Double32_t *fTime; //[fNCells][0.,0.,16]
89 :
90 : /// Array with fraction of MC energy and data - for embedding.
91 : Double32_t *fEFraction; //[fNCells][0.,0.,16]
92 :
93 : /// Array of MC labels, each label is the highest contributor to the cell signal.
94 : Int_t *fMCLabel; //[fNCells]
95 :
96 : Bool_t fIsSorted; //!<! True if cell arrays are sorted by index.
97 :
98 : Char_t fType; ///< Cell type
99 :
100 : /// \cond CLASSIMP
101 258 : ClassDef(AliAODCaloCells, 5) ;
102 : /// \endcond
103 :
104 : };
105 :
106 : ///
107 : /// Given the position index in the array, return the cell parameters
108 : ///
109 : /// \param pos: Index of cell in array
110 : /// \param cellNumber: Absolute cell Id. number
111 : /// \param amplitude: Cell energy
112 : /// \param time: Cell time
113 : /// \param mclabel: MC particle index in kine tree
114 : /// \param efrac: Fraction of energy (embedding)
115 : ///
116 : /// \return True if pos is correct not negative or larger than expected.
117 : ///
118 : Bool_t AliAODCaloCells::GetCell(Short_t pos, Short_t &cellNumber, Double_t &litude,
119 : Double_t &time, Int_t & mclabel, Double_t & efrac) const
120 : {
121 546 : if (pos>=0 && pos<fNCells)
122 : {
123 182 : cellNumber = fCellNumber[pos];
124 182 : amplitude = fAmplitude[pos];
125 :
126 364 : if(fTime) time = fTime[pos];
127 0 : else time =-1.;
128 364 : if(fMCLabel) mclabel = fMCLabel[pos];
129 0 : else mclabel =-1 ;
130 364 : if(fEFraction) efrac = fEFraction[pos];
131 0 : else efrac = 0 ;
132 :
133 182 : return kTRUE;
134 :
135 : } else {
136 0 : return kFALSE;
137 : }
138 182 : }
139 :
140 : ///
141 : /// \return Cell amplitude (GeV)
142 : /// \param cellNumber: Cell absolute Id.
143 : ///
144 : Double_t AliAODCaloCells::GetCellAmplitude(Short_t cellNumber)
145 : {
146 0 : if (!fIsSorted) {
147 0 : Sort();
148 0 : fIsSorted=kTRUE;
149 0 : }
150 :
151 0 : Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
152 0 : if (pos>=0 && fCellNumber[pos] == cellNumber) {
153 0 : return fAmplitude[pos];
154 : } else {
155 0 : return 0.;
156 : }
157 0 : }
158 :
159 : ///
160 : /// \return True for high gain, False for low gain.
161 : /// \param cellNumber: Cell absolute Id.
162 : ///
163 : Bool_t AliAODCaloCells::GetCellHighGain(Short_t cellNumber)
164 : {
165 0 : if (!fIsSorted) {
166 0 : Sort();
167 0 : fIsSorted=kTRUE;
168 0 : }
169 :
170 0 : Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
171 0 : if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber ) {
172 0 : if(fHGLG)
173 0 : return fHGLG[pos];
174 : else{
175 0 : if(fMCLabel) //old version of AOD,
176 0 : return !(fMCLabel[pos]==-2) ;
177 : else
178 0 : return kTRUE ;
179 : }
180 : } else {
181 0 : return kFALSE;
182 : }
183 0 : }
184 :
185 : ///
186 : /// \return Cell time (s).
187 : /// \param cellNumber: Cell absolute Id.
188 : ///
189 : Double_t AliAODCaloCells::GetCellTime(Short_t cellNumber)
190 : {
191 0 : if(!fTime) return -1;
192 :
193 0 : if (!fIsSorted) {
194 0 : Sort();
195 0 : fIsSorted=kTRUE;
196 0 : }
197 :
198 0 : Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
199 0 : if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber) {
200 0 : return fTime[pos];
201 : } else {
202 0 : return -1.;
203 : }
204 0 : }
205 :
206 : ///
207 : /// \return Cell amplitude (GeV).
208 : /// \param pos: Cell position in array.
209 : ///
210 : Double_t AliAODCaloCells::GetAmplitude(Short_t pos) const
211 : {
212 0 : if (pos>=0 && pos<fNCells) {
213 0 : return fAmplitude[pos];
214 : } else {
215 0 : return 0.;
216 : }
217 0 : }
218 :
219 : ///
220 : /// \return True for high gain, False for low gain.
221 : /// \param pos: Cell position in array.
222 : ///
223 : Bool_t AliAODCaloCells::GetHighGain(Short_t pos) const
224 : {
225 0 : if (pos>=0 && pos<fNCells) {
226 0 : if(fHGLG)
227 0 : return fHGLG[pos];
228 : else{
229 0 : if(fMCLabel) //Old version of AOD store this flag in MCLabel
230 0 : return !(fMCLabel[pos]==-2) ;
231 : else
232 0 : return kTRUE ;
233 : }
234 : } else {
235 0 : return kFALSE;
236 : }
237 0 : }
238 :
239 : ///
240 : /// \return Cell time (s).
241 : /// \param pos: Cell position in array.
242 : ///
243 : Double_t AliAODCaloCells::GetTime(Short_t pos) const
244 : {
245 0 : if (pos>=0 && pos<fNCells && fTime) {
246 0 : return fTime[pos];
247 : } else {
248 0 : return -1.;
249 : }
250 0 : }
251 :
252 : ///
253 : /// \return Cell absolute Id. number.
254 : /// \param pos: Cell position in array.
255 : ///
256 : Short_t AliAODCaloCells::GetCellNumber(Short_t pos) const
257 : {
258 0 : if (pos>=0 && pos<fNCells) {
259 0 : return fCellNumber[pos];
260 : } else {
261 0 : return fNCells;
262 : }
263 0 : }
264 :
265 : ///
266 : /// \param cellNumber: Cell absolute Id. number.
267 : /// \return Cell position in array.
268 : ///
269 : Short_t AliAODCaloCells::GetCellPosition(Short_t cellNumber)
270 : {
271 0 : if (!fIsSorted) {
272 0 : Sort();
273 0 : fIsSorted=kTRUE;
274 0 : }
275 :
276 : Int_t nabove, nbelow, middle;
277 : Short_t pos = -1;
278 :
279 0 : nabove = fNCells + 1;
280 : nbelow = 0;
281 0 : while (nabove - nbelow > 1) {
282 0 : middle = (nabove + nbelow) / 2;
283 0 : if (cellNumber == fCellNumber[middle-1]) {
284 0 : pos = middle - 1;
285 0 : break;
286 : }
287 0 : if (cellNumber < fCellNumber[middle-1]) nabove = middle;
288 : else nbelow = middle;
289 : }
290 :
291 0 : return pos;
292 : }
293 :
294 : ///
295 : /// \return MC label of highest contributor particle depositing energy in cell.
296 : /// \param pos: Cell position in array.
297 : ///
298 : Int_t AliAODCaloCells::GetMCLabel(Short_t pos) const
299 : {
300 0 : if (pos>=0 && pos<fNCells && fMCLabel) {
301 0 : return fMCLabel[pos];
302 : } else {
303 0 : return 0;
304 : }
305 0 : }
306 :
307 : ///
308 : /// \return Fraction of energy in cell from embedding.
309 : /// \param pos: Cell position in array.
310 : ///
311 : Double_t AliAODCaloCells::GetEFraction(Short_t pos) const
312 : {
313 0 : if (pos>=0 && pos<fNCells && fEFraction) {
314 0 : return fEFraction[pos];
315 : } else {
316 0 : return 0.;
317 : }
318 0 : }
319 :
320 : ///
321 : /// \return MC label of highest contributor particle depositing energy in cell.
322 : /// \param cellNumber: Cell position in array.
323 : ///
324 : Int_t AliAODCaloCells::GetCellMCLabel(Short_t cellNumber)
325 : {
326 0 : if(!fMCLabel) return -1;
327 :
328 0 : if (!fIsSorted) {
329 0 : Sort();
330 0 : fIsSorted=kTRUE;
331 0 : }
332 :
333 0 : Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
334 0 : if (pos>=0 && fCellNumber[pos] == cellNumber) {
335 0 : return fMCLabel[pos];
336 : } else {
337 0 : return 0;
338 : }
339 0 : }
340 :
341 : ///
342 : /// \return Fraction of energy in cell from embedding.
343 : /// \param cellNumber: Absolute Id number of cell.
344 : ///
345 : Double_t AliAODCaloCells::GetCellEFraction(Short_t cellNumber)
346 : {
347 0 : if(!fEFraction) return 0;
348 :
349 0 : if (!fIsSorted) {
350 0 : Sort();
351 0 : fIsSorted=kTRUE;
352 0 : }
353 :
354 0 : Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
355 0 : if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber) {
356 0 : return fEFraction[pos];
357 : } else {
358 0 : return -1.;
359 : }
360 0 : }
361 :
362 : ///
363 : /// Set Fraction of energy in cell from embedding.
364 : /// \param pos: Cell position in array.
365 : /// \param efrac: fraction of energy.
366 : ///
367 : void AliAODCaloCells::SetEFraction(Short_t pos, Double32_t efrac)
368 : {
369 0 : if (pos>=0 && pos < fNCells)
370 : {
371 0 : if(!fEFraction) fEFraction = new Double32_t[fNCells];
372 0 : fEFraction[pos] = efrac;
373 0 : }
374 0 : }
375 :
376 : ///
377 : /// Set fraction of energy in cell from embedding.
378 : /// \param cellNumber: Absolute cell Id. number of cell.
379 : /// \param efrac: fraction of energy.
380 : ///
381 : void AliAODCaloCells::SetCellEFraction(Short_t cellNumber, Double32_t efrac)
382 : {
383 0 : if (!fIsSorted) {
384 0 : Sort();
385 0 : fIsSorted=kTRUE;
386 0 : }
387 :
388 0 : Short_t pos = TMath::BinarySearch(fNCells, fCellNumber, cellNumber);
389 0 : if (pos>=0 && pos < fNCells && fCellNumber[pos] == cellNumber)
390 : {
391 0 : if(!fEFraction) fEFraction = new Double32_t[fNCells];
392 0 : fEFraction[pos] = efrac;
393 0 : }
394 0 : }
395 :
396 :
397 : #endif
|