AliRoot Core  edcc906 (edcc906)
AliESDCaloCells.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 
16 #include "AliESDCaloCells.h"
17 
19 ClassImp(AliESDCaloCells) ;
21 
25 //_____________________________________________________
27  AliVCaloCells(), fNCells(0), fHGLG(0),fCellNumber(0),
28  fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
29  fIsSorted(kTRUE), fType(kUndef)
30 {
31 }
32 
36 //______________________________________________________________________________________
37  AliESDCaloCells::AliESDCaloCells(const char* name, const char* title, VCells_t ttype) :
38  AliVCaloCells(name, title), fNCells(0), fHGLG(0),fCellNumber(0),
39  fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
40  fIsSorted(kTRUE), fType(ttype)
41 {
42 }
43 
47 //__________________________________________________________
50  fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
52 {
53  fHGLG = new Bool_t[fNCells] ;
54  fCellNumber = new Short_t[fNCells];
55  fAmplitude = new Double32_t[fNCells];
56  fTime = new Double32_t[fNCells];
57  fMCLabel = new Int_t[fNCells];
58  fEFraction = new Double32_t[fNCells];
59 
60  for(Int_t i = 0; i < fNCells; i++)
61  {
62  fCellNumber[i] = c.fCellNumber[i];
63  fAmplitude[i] = c.fAmplitude[i];
64  fTime[i] = c.fTime[i];
65  if(c.fMCLabel) fMCLabel[i] = c.fMCLabel[i];
66  if(c.fEFraction)fEFraction[i] = c.fEFraction[i];
67  }
68 
69  if(c.fHGLG)
70  {
71  for(Int_t i = 0; i < fNCells; i++)
72  {
73  fHGLG[i] = c.fHGLG[i];
74  }
75  }
76 }
77 
81 //__________________________________________________________________________
83 {
84  if(this != &source)
85  {
87 
88  if(fNCells != source.fNCells)
89  {
90  if(fHGLG)
91  delete [] fHGLG ;
92  delete [] fCellNumber;
93  delete [] fAmplitude;
94  delete [] fTime;
95  delete [] fMCLabel;
96  delete [] fEFraction;
97 
98  fNCells = source.fNCells;
99 
100  if(source.fHGLG)
101  fHGLG = new Bool_t[fNCells] ;
102  fCellNumber = new Short_t[fNCells];
103  fAmplitude = new Double32_t[fNCells];
104  fTime = new Double32_t[fNCells];
105  fMCLabel = new Int_t[fNCells];
106  fEFraction = new Double32_t[fNCells];
107  }
108 
109  if(source.fHGLG)
110  memcpy(fCellNumber,source.fHGLG,fNCells*sizeof(Bool_t));
111  memcpy(fCellNumber,source.fCellNumber,fNCells*sizeof(Short_t));
112  memcpy(fAmplitude, source.fAmplitude, fNCells*sizeof(Double32_t));
113  memcpy(fTime, source.fTime, fNCells*sizeof(Double32_t));
114  if(source.fMCLabel && fMCLabel) memcpy(fMCLabel, source.fMCLabel, fNCells*sizeof(Int_t));
115  if(source.fEFraction && fEFraction) memcpy(fEFraction, source.fEFraction, fNCells*sizeof(Double32_t));
116 
117  fIsSorted = source.fIsSorted;
118  fType = source.fType;
119 
120  }
121 
122  return *this;
123 }
124 
130 //____________________________________________
131 void AliESDCaloCells::Copy(TObject &obj) const
132 {
133  if(this==&obj)return;
134  AliESDCaloCells *robj = dynamic_cast<AliESDCaloCells*>(&obj);
135  if(!robj)return; // not an AliESDCaloCells
136  *robj = *this;
137 }
138 
143 //______________________________________________________________________
145 {
146  AliVCaloCells *obj = new AliESDCaloCells();
147 
148  if(all){
149  obj->SetName (GetName()) ;
150  obj->SetTitle(GetTitle()) ;
151  obj->SetType (GetType()) ;
152 
154  for (Short_t i = 0; i < fNCells; i++)
155  {
156  Int_t mclabel = -1;
157  if(fMCLabel) mclabel = fMCLabel[i];
158 
159  Float_t efrac = 0.;
160  if(fEFraction) efrac = fEFraction[i];
161 
162  obj->SetCell(i,fCellNumber[i],fAmplitude[i],fTime[i],mclabel,efrac);
163  }
164  }
165 
166  return obj;
167 }
168 
172 //_________________________________
174 {
175  DeleteContainer();
176 }
177 
181 //__________________________________________
182 void AliESDCaloCells::Clear(const Option_t*)
183 {
184  DeleteContainer();
185 }
186 
190 //___________________________________________________
192 {
193  DeleteContainer();
194 
195  if (nCells <= 0)
196  {
197  fNCells = 0;
198  return;
199  }
200 
201  fNCells = nCells;
202 
203  fHGLG = new Bool_t[fNCells];
204  fCellNumber = new Short_t[fNCells];
205  fAmplitude = new Double32_t[fNCells];
206  fTime = new Double32_t[fNCells];
207  fMCLabel = new Int_t[fNCells];
208  fEFraction = new Double32_t[fNCells];
209 
210  // set to zero
211  for(int i = 0;i<fNCells;++i)
212  {
213  fHGLG[i]=kFALSE ;
214  fAmplitude [i] = 0.;
215  fCellNumber[i] = -1 ;
216  fEFraction [i] = 0.;
217  fTime [i] = -1.;
218  fMCLabel [i] = -1 ;
219  }
220 }
221 
225 //_____________________________________
227 {
228  if(fHGLG)
229  {
230  delete[] fHGLG;
231  fHGLG = 0 ;
232  }
233 
234  if (fCellNumber)
235  {
236  delete[] fCellNumber;
237  fCellNumber = 0;
238  }
239 
240  if (fAmplitude)
241  {
242  delete[] fAmplitude;
243  fAmplitude = NULL;
244  }
245 
246  if (fTime)
247  {
248  delete[] fTime;
249  fTime = NULL;
250  }
251 
252  if (fMCLabel)
253  {
254  delete[] fMCLabel;
255  fMCLabel = NULL;
256  }
257 
258  if (fEFraction)
259  {
260  delete[] fEFraction;
261  fEFraction = NULL;
262  }
263 
264  fNCells = 0;
265  fIsSorted = kFALSE;
266 
267 }
268 
272 //__________________________
274 {
275  Int_t *idxArray = new Int_t[fNCells];
276  TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
277 
278  Short_t *newIndex = new Short_t[fNCells];
279  Double32_t *newAmplitude = new Double32_t[fNCells];
280  Double32_t *newTime = new Double32_t[fNCells];
281 
282  Int_t *newMCLabel = 0 ;
283  Double32_t *newEFraction = 0 ;
284  if(fMCLabel) newMCLabel = new Int_t[fNCells];
285  if(fEFraction) newEFraction = new Double32_t[fNCells];
286 
287  for (Int_t i=0; i < fNCells; i++)
288  {
289  newIndex[i] = fCellNumber[idxArray[i]];
290  newAmplitude[i] = fAmplitude [idxArray[i]];
291  newTime[i] = fTime [idxArray[i]];
292  if(fMCLabel) newMCLabel[i] = fMCLabel [idxArray[i]];
293  if(fEFraction) newEFraction[i] = fEFraction[idxArray[i]];
294  }
295  if(fHGLG){
296  Bool_t *newHGLG = new Bool_t[fNCells];
297  for (Int_t i=0; i < fNCells; i++) {
298  newHGLG[i] = fHGLG[idxArray[i]];
299  }
300  delete [] fHGLG;
301  fHGLG = newHGLG;
302  }
303 
304  delete [] fCellNumber;
305  delete [] fAmplitude;
306  delete [] fTime;
307  delete [] fMCLabel;
308  delete [] fEFraction;
309 
310  fCellNumber = newIndex;
311  fAmplitude = newAmplitude;
312  fTime = newTime;
313  fMCLabel = newMCLabel;
314  fEFraction = newEFraction;
315 
316  delete [] idxArray;
317 
318  fIsSorted = kTRUE;
319 }
320 
331 //________________________________________________________________________________________
332 Bool_t AliESDCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude,
333  Double32_t time, Int_t mclabel, Double32_t efrac, Bool_t isHG)
334 {
335  if (pos>=0 && pos < fNCells)
336  {
337  if(fHGLG)
338  fHGLG[pos]=isHG ;
339  fCellNumber[pos] = cellNumber;
340  fAmplitude[pos] = amplitude;
341  fTime[pos] = time;
342 
343  // note: initialize (can't use memset for non-0 values)
344  // plus sizeof(Double32_t) is 0
345  if(!fMCLabel){
346  fMCLabel = new Int_t[fNCells];
347 
348  for( Int_t i = 0; i < fNCells; i++ )
349  fMCLabel[i] = -1;
350  }
351  if(!fEFraction){
352  fEFraction = new Double32_t[fNCells];
353 
354  for( Int_t i = 0; i < fNCells; i++ )
355  fEFraction[i] = 0;
356  }
357 
358  fMCLabel[pos] = mclabel;
359  fEFraction[pos] = efrac;
360 
361  fIsSorted = kFALSE;
362 
363  return kTRUE;
364 
365  } else {
366  return kFALSE;
367  }
368 }
void Clear(const Option_t *)
Double32_t * fAmplitude
Array with cell amplitudes (= energy!).
virtual AliVCaloCells * CopyCaloCells(Bool_t all) const
Char_t fType
Cell type.
Bool_t fIsSorted
! True if cell arrays are sorted by index.
virtual 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=kTRUE)=0
Char_t GetType() const
Virtual class for calorimeter cell data handling.
Definition: AliVCaloCells.h:19
Double32_t * fTime
Array with cell times.
AliESDCaloCells & operator=(const AliESDCaloCells &source)
Int_t fNCells
Number of cells.
void CreateContainer(Short_t nCells)
AliVCaloCells & operator=(const AliVCaloCells &cells)
Short_t * fCellNumber
Array of cell absolute Id. numbers.
virtual void Copy(TObject &obj) const
virtual void SetNumberOfCells(Int_t n)=0
virtual void SetType(Char_t ttype)=0
Double32_t * fEFraction
Array with fraction of MC energy and data - for embedding.
Bool_t * fHGLG
If Cell is High Gain or Low Gain.
Int_t * fMCLabel
Array of MC labels, each label is the highest contributor to the cell signal.
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)
Class for calorimeter cell ESD data handling.
virtual ~AliESDCaloCells()