AliRoot Core  edcc906 (edcc906)
AliAODCaloCells.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 "AliAODCaloCells.h"
17 
19 ClassImp(AliAODCaloCells) ;
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 AliAODCaloCells::AliAODCaloCells(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 //________________________________________________________________
49  AliVCaloCells(cells), fNCells(cells.fNCells), fHGLG(0), fCellNumber(0),
50  fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
51  fIsSorted(cells.fIsSorted), fType(cells.fType)
52 {
53  fCellNumber = new Short_t[fNCells];
54  fAmplitude = new Double32_t[fNCells];
55  fTime = new Double32_t[fNCells];
56  fMCLabel = new Int_t[fNCells];
57  fEFraction = new Double32_t[fNCells];
58 
59  for (Int_t i = 0; i < fNCells; i++) {
60  fCellNumber[i] = cells.fCellNumber[i];
61  fAmplitude[i] = cells.fAmplitude[i];
62  if(cells.fTime) fTime[i] = cells.fTime[i];
63  if(cells.fMCLabel) fMCLabel[i] = cells.fMCLabel[i];
64  if(cells.fEFraction)fEFraction[i] = cells.fEFraction[i];
65  }
66  if(cells.fHGLG){
67  fHGLG = new Bool_t[fNCells] ;
68  for (Int_t i = 0; i < fNCells; i++) {
69  fHGLG[i] = cells.fHGLG[i];
70  }
71  }
72 }
73 
77 //________________________________________________________________________
79 {
80  if(this != &source)
81  {
83 
84  if(fNCells != source.fNCells)
85  {
86  if(fHGLG)
87  delete [] fHGLG ;
88  delete [] fCellNumber;
89  delete [] fAmplitude;
90  delete [] fTime;
91  delete [] fMCLabel;
92  delete [] fEFraction;
93 
94  fNCells = source.fNCells;
95 
96  if(source.fHGLG)
97  fHGLG = new Bool_t[fNCells] ;
98  fCellNumber = new Short_t[fNCells];
99  fAmplitude = new Double32_t[fNCells];
100  fTime = new Double32_t[fNCells];
101  fMCLabel = new Int_t[fNCells];
102  fEFraction = new Double32_t[fNCells];
103  }
104 
105  if(source.fHGLG)
106  memcpy(fCellNumber,source.fHGLG,fNCells*sizeof(Bool_t));
107  memcpy(fCellNumber,source.fCellNumber, fNCells*sizeof(Short_t));
108  memcpy(fAmplitude, source.fAmplitude, fNCells*sizeof(Double32_t));
109  if(source.fTime && fTime) memcpy(fTime, source.fTime, fNCells*sizeof(Double32_t));
110  if(source.fMCLabel && fMCLabel) memcpy(fMCLabel, source.fMCLabel, fNCells*sizeof(Int_t));
111  if(source.fEFraction && fEFraction) memcpy(fEFraction, source.fEFraction, fNCells*sizeof(Double32_t));
112 
113  fIsSorted = source.fIsSorted;
114  fType = source.fType;
115  }
116 
117  return *this;
118 
119 }
120 
121 //_________________________________
123 {
124  // destructor
125 
126  DeleteContainer();
127 }
128 
132 //__________________________________________
133 void AliAODCaloCells::Clear(const Option_t*)
134 {
135  DeleteContainer();
136 }
137 
143 //____________________________________________
144 void AliAODCaloCells::Copy(TObject &obj) const
145 {
146  if(this==&obj)return;
147  AliAODCaloCells *robj = dynamic_cast<AliAODCaloCells*>(&obj);
148  if(!robj)return; // not an AliAODCaloCells
149  *robj = *this;
150 }
151 
156 //_____________________________________________________________________
158 {
159  AliVCaloCells *obj = new AliAODCaloCells();
160 
161  if(all){
162  obj->SetName (GetName()) ;
163  obj->SetTitle(GetTitle()) ;
164  obj->SetType (GetType()) ;
165 
167  for (Short_t i = 0; i < fNCells; i++)
168  {
169  Int_t mclabel = -1;
170  if(fMCLabel) mclabel = fMCLabel[i];
171 
172  Float_t efrac = 0.;
173  if(fEFraction) efrac = fEFraction[i];
174 
175  Float_t time = -1;
176  if(fTime) time = fTime[i];
177 
178  obj->SetCell(i,fCellNumber[i],fAmplitude[i],time,mclabel,efrac);
179  }
180  }
181 
182  return obj;
183 
184 }
185 
189 //___________________________________________________
191 {
192  DeleteContainer();
193 
194  if (nCells <= 0)
195  {
196  fNCells = 0;
197  return;
198  }
199 
200  fNCells = nCells;
201 
202  fHGLG = new Bool_t[fNCells];
203  fCellNumber = new Short_t[fNCells];
204  fAmplitude = new Double32_t[fNCells];
205  fTime = new Double32_t[fNCells];
206  fMCLabel = new Int_t[fNCells];
207  fEFraction = new Double32_t[fNCells];
208 
209  // set to zero
210  for(int i = 0;i<fNCells;++i)
211  {
212  fHGLG[i]=kFALSE ;
213  fAmplitude [i] = 0.;
214  fCellNumber[i] = -1 ;
215  fEFraction [i] = 0.;
216  fTime [i] = -1.;
217  fMCLabel [i] = -1 ;
218  }
219 }
220 
224 //_____________________________________
226 {
227  if(fHGLG){
228  delete[] fHGLG;
229  fHGLG = 0 ;
230  }
231 
232  if (fCellNumber)
233  {
234  delete[] fCellNumber;
235  fCellNumber = NULL;
236  }
237 
238  if (fAmplitude)
239  {
240  delete[] fAmplitude;
241  fAmplitude = NULL;
242  }
243 
244  if (fTime)
245  {
246  delete[] fTime;
247  fTime = NULL;
248  }
249 
250  if (fMCLabel)
251  {
252  delete[] fMCLabel;
253  fMCLabel = NULL;
254  }
255 
256  if (fEFraction)
257  {
258  delete[] fEFraction;
259  fEFraction = NULL;
260  }
261 
262 
263  fNCells = 0;
264  fIsSorted = kFALSE;
265 }
266 
270 //__________________________
272 {
273  Int_t *idxArray = new Int_t[fNCells];
274  TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
275 
276  Bool_t *newHGLG =0x0 ;
277  if(fHGLG) newHGLG = new Bool_t[fNCells];
278  Short_t *newIndex = new Short_t[fNCells];
279  Double32_t *newAmplitude = new Double32_t[fNCells];
280 
281  Double32_t *newTime = 0 ;
282  Int_t *newMCLabel = 0 ;
283  Double32_t *newEFraction = 0 ;
284  if(fTime) newTime = new Double32_t[fNCells];
285  if(fMCLabel) newMCLabel = new Int_t[fNCells];
286  if(fEFraction) newEFraction = new Double32_t[fNCells];
287 
288  for (Int_t i=0; i < fNCells; i++)
289  {
290  newIndex[i] = fCellNumber[idxArray[i]];
291  newAmplitude[i] = fAmplitude [idxArray[i]];
292  if(fTime) newTime[i] = fTime [idxArray[i]];
293  if(fMCLabel) newMCLabel[i] = fMCLabel [idxArray[i]];
294  if(fEFraction) newEFraction[i] = fEFraction[idxArray[i]];
295  }
296 
297  if(fHGLG)
298  {
299  for (Int_t i=0; i < fNCells; i++)
300  {
301  newHGLG[i] = fHGLG[idxArray[i]];
302  }
303  delete [] fHGLG;
304  }
305 
306  delete [] fCellNumber;
307  delete [] fAmplitude;
308  delete [] fTime;
309  delete [] fMCLabel;
310  delete [] fEFraction;
311 
312  fHGLG = newHGLG;
313  fCellNumber = newIndex;
314  fAmplitude = newAmplitude;
315  fTime = newTime;
316  fMCLabel = newMCLabel;
317  fEFraction = newEFraction;
318 
319  delete [] idxArray;
320 
321  fIsSorted = kTRUE;
322 }
323 
334 //________________________________________________________________________________________
335 Bool_t AliAODCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude,
336  Double32_t time, Int_t mclabel, Double32_t efrac, Bool_t isHG)
337 {
338  if (pos>=0 && pos < fNCells)
339  {
340  if(fHGLG)
341  fHGLG[pos]=isHG ;
342  fCellNumber[pos] = cellNumber;
343  fAmplitude[pos] = amplitude;
344 
345  // note: initialize (can't use memset for non-0 values)
346  // plus sizeof(Double32_t) is 0
347  if(!fTime){
348  fTime = new Double32_t[fNCells];
349 
350  for( Int_t i = 0; i < fNCells; i++ )
351  fTime[i] = -1;
352  }
353  if(!fMCLabel){
354  fMCLabel = new Int_t[fNCells];
355 
356  for( Int_t i = 0; i < fNCells; i++ )
357  fMCLabel[i] = -1;
358  }
359  if(!fEFraction){
360  fEFraction = new Double32_t[fNCells];
361 
362  for( Int_t i = 0; i < fNCells; i++ )
363  fEFraction[i] = 0;
364  }
365 
366  fTime[pos] = time;
367  fMCLabel[pos] = mclabel;
368  fEFraction[pos] = efrac;
369 
370  fIsSorted = kFALSE;
371 
372  return kTRUE;
373 
374  } else {
375  return kFALSE;
376  }
377 }
378 
379 
380 
381 
Double32_t * fTime
Array with cell times.
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
Class for calorimeter cell AOD data handling.
Double32_t * fEFraction
Array with fraction of MC energy and data - for embedding.
Virtual class for calorimeter cell data handling.
Definition: AliVCaloCells.h:19
AliAODCaloCells & operator=(const AliAODCaloCells &cells)
Int_t fNCells
Number of cells.
AliVCaloCells & operator=(const AliVCaloCells &cells)
Int_t * fMCLabel
Array of MC labels, each label is the highest contributor to the cell signal.
virtual void Copy(TObject &obj) const
void CreateContainer(Short_t nCells)
virtual void SetNumberOfCells(Int_t n)=0
void Clear(const Option_t *)
Short_t * fCellNumber
Array of cell absolute Id. numbers.
virtual AliVCaloCells * CopyCaloCells(Bool_t all) const
Bool_t * fHGLG
If Cell is High Gain or Low Gain.
Char_t fType
Cell type.
Double32_t * fAmplitude
Array with cell amplitudes (= energy!).
virtual void SetType(Char_t ttype)=0
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)
Char_t GetType() const
virtual ~AliAODCaloCells()
Bool_t fIsSorted
! True if cell arrays are sorted by index.