]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AOD/AliAODCaloCells.cxx
add new data members, move members to the correlation class to the base one, and...
[u/mrichter/AliRoot.git] / STEER / AOD / AliAODCaloCells.cxx
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 /* $Id$ */
17
18 //-------------------------------------------------------------------------
19 //     AOD class to store calorimeter cell data
20 //     Author: Markus Oldenburg, CERN
21 //-------------------------------------------------------------------------
22
23 #include "AliAODCaloCells.h"
24
25 ClassImp(AliAODCaloCells)
26
27 //_______________________________________________________
28 AliAODCaloCells::AliAODCaloCells() : 
29     AliVCaloCells(), fNCells(0), fHGLG(0), fCellNumber(0), 
30     fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
31     fIsSorted(kTRUE), fType(kUndef)
32 {
33   // default constructor
34 }
35
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   //constructor
43 }
44
45 //________________________________________________________________
46 AliAODCaloCells::AliAODCaloCells(const AliAODCaloCells& cells) :
47     AliVCaloCells(cells), fNCells(cells.fNCells), fHGLG(0), fCellNumber(0),
48     fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
49     fIsSorted(cells.fIsSorted), fType(cells.fType)
50 {
51 // Copy constructor
52   fCellNumber = new Short_t[fNCells];
53   fAmplitude  = new Double32_t[fNCells]; 
54   fTime       = new Double32_t[fNCells]; 
55   fMCLabel    = new Int_t[fNCells]; 
56   fEFraction  = new Double32_t[fNCells]; 
57
58   for (Int_t i = 0; i < fNCells; i++) {
59     fCellNumber[i]    = cells.fCellNumber[i];
60     fAmplitude[i]     = cells.fAmplitude[i];
61     if(cells.fTime)  fTime[i]      = cells.fTime[i];
62     if(cells.fMCLabel)  fMCLabel[i]   = cells.fMCLabel[i];
63     if(cells.fEFraction)fEFraction[i] = cells.fEFraction[i];    
64   }
65   if(cells.fHGLG){
66     fHGLG       = new Bool_t[fNCells] ;
67     for (Int_t i = 0; i < fNCells; i++) {
68       fHGLG[i]          = cells.fHGLG[i];     
69     }
70   }
71 }
72
73 //________________________________________________________________________
74 AliAODCaloCells& AliAODCaloCells::operator=(const AliAODCaloCells& source)
75 {
76   // Assignment operator
77   if(this != &source) 
78   {
79     AliVCaloCells::operator=(source);
80     
81     if(fNCells != source.fNCells) 
82     {
83       if(fHGLG)
84         delete [] fHGLG ;
85       delete [] fCellNumber;
86       delete [] fAmplitude;
87       delete [] fTime;
88       delete [] fMCLabel;
89       delete [] fEFraction;
90
91       fNCells     = source.fNCells;
92       
93       if(source.fHGLG)
94         fHGLG       = new Bool_t[fNCells] ;
95       fCellNumber = new Short_t[fNCells];
96       fAmplitude  = new Double32_t[fNCells];
97       fTime       = new Double32_t[fNCells];
98       fMCLabel    = new Int_t[fNCells];
99       fEFraction  = new Double32_t[fNCells];
100     }
101     
102     if(source.fHGLG)
103       memcpy(fCellNumber,source.fHGLG,fNCells*sizeof(Bool_t));
104     memcpy(fCellNumber,source.fCellNumber, fNCells*sizeof(Short_t));
105     memcpy(fAmplitude, source.fAmplitude,  fNCells*sizeof(Double32_t));
106     if(source.fTime      && fTime)      memcpy(fTime,      source.fTime,      fNCells*sizeof(Double32_t));
107     if(source.fMCLabel   && fMCLabel)   memcpy(fMCLabel,   source.fMCLabel,   fNCells*sizeof(Int_t));
108     if(source.fEFraction && fEFraction) memcpy(fEFraction, source.fEFraction, fNCells*sizeof(Double32_t));
109
110     fIsSorted = source.fIsSorted;
111     fType     = source.fType;
112   }
113
114   return *this;
115   
116 }
117
118 //_________________________________
119 AliAODCaloCells::~AliAODCaloCells()
120 {
121   // destructor
122
123   DeleteContainer();
124 }
125
126 void AliAODCaloCells::Clear(const Option_t*)
127 {
128   // clear
129   
130   DeleteContainer();
131 }
132
133 void AliAODCaloCells::Copy(TObject &obj) const 
134 {
135   
136   // this overwrites the virtual TOBject::Copy()
137   // to allow run time copying without casting
138   // in AliESDEvent
139   
140   if(this==&obj)return;
141   AliAODCaloCells *robj = dynamic_cast<AliAODCaloCells*>(&obj);
142   if(!robj)return; // not an AliAODCaloCells
143   *robj = *this;
144   
145 }
146
147 //______________________________________________________________________
148 AliVCaloCells *AliAODCaloCells::CopyCaloCells(Bool_t all = kTRUE) const 
149 {
150   
151   // copy the calo cells into a new object. If option all=FALSE, just the object type, 
152   // for mixing
153   
154   AliVCaloCells *obj =  new AliAODCaloCells();
155   
156   if(all){
157     obj->SetName (GetName()) ; 
158     obj->SetTitle(GetTitle()) ; 
159     obj->SetType (GetType()) ; 
160   
161     obj->SetNumberOfCells(fNCells);
162     for (Short_t i = 0; i < fNCells; i++) 
163     {
164       Int_t mclabel = -1;
165       if(fMCLabel) mclabel = fMCLabel[i];
166       
167       Float_t efrac = 0.;
168       if(fEFraction) efrac = fEFraction[i];
169       
170       Float_t time = -1;
171       if(fTime) time = fTime[i];
172       
173       obj->SetCell(i,fCellNumber[i],fAmplitude[i],time,mclabel,efrac);
174     }
175   }
176   
177   return obj;
178   
179 }
180
181 //___________________________________________________
182 void AliAODCaloCells::CreateContainer(Short_t nCells)
183 {
184   // function that creates container to store calorimeter cell data
185
186   DeleteContainer();
187   
188   if (nCells <= 0) 
189   {
190     fNCells = 0;
191     return;
192   }
193
194   fNCells = nCells;
195
196   fHGLG       = new Bool_t[fNCells];
197   fCellNumber = new Short_t[fNCells];
198   fAmplitude  = new Double32_t[fNCells];
199   fTime       = new Double32_t[fNCells];
200   fMCLabel    = new Int_t[fNCells];
201   fEFraction  = new Double32_t[fNCells];
202
203   // set to zero
204   for(int i = 0;i<fNCells;++i)
205   {
206     fHGLG[i]=kFALSE ;
207     fAmplitude [i] =  0.; 
208     fCellNumber[i] = -1 ; 
209     fEFraction [i] =  0.;
210     fTime      [i] = -1.;
211     fMCLabel   [i] = -1 ;
212   }
213 }
214
215 //_____________________________________
216 void AliAODCaloCells::DeleteContainer()
217 {
218   // deletes allocated memory
219   if(fHGLG){
220     delete[] fHGLG;
221     fHGLG = 0 ;
222   }
223
224   if (fCellNumber)
225   {
226     delete[] fCellNumber;
227     fCellNumber = NULL;
228   }
229
230   if (fAmplitude)
231   {
232     delete[] fAmplitude;
233     fAmplitude = NULL;
234   }
235   
236   if (fTime)
237   {
238     delete[] fTime;
239     fTime = NULL;
240   }
241   
242   if (fMCLabel)
243   {
244     delete[] fMCLabel;
245     fMCLabel = NULL;
246   }
247   
248   if (fEFraction)
249   {
250     delete[] fEFraction;
251     fEFraction = NULL;
252   }
253   
254   
255   fNCells = 0;
256   fIsSorted = kFALSE;
257 }
258
259 //__________________________
260 void AliAODCaloCells::Sort() 
261 {
262   // sort the cell array by cell number
263   
264   Int_t *idxArray = new Int_t[fNCells];
265   TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
266   
267   Bool_t     *newHGLG =0x0 ;
268   if(fHGLG) newHGLG = new Bool_t[fNCells];
269   Short_t    *newIndex     = new Short_t[fNCells];
270   Double32_t *newAmplitude = new Double32_t[fNCells];
271   
272   Double32_t *newTime      = 0; 
273   Int_t     *newMCLabel   = 0 ;
274   Double32_t *newEFraction = 0 ; 
275   if(fTime)      newTime      = new Double32_t[fNCells];
276   if(fMCLabel)   newMCLabel   = new Int_t[fNCells];
277   if(fEFraction) newEFraction = new Double32_t[fNCells];
278   
279   for (Int_t i=0; i < fNCells; i++) 
280   {
281     newIndex[i]     = fCellNumber[idxArray[i]];
282     newAmplitude[i] = fAmplitude [idxArray[i]];
283     if(fTime)      newTime[i]      = fTime     [idxArray[i]];
284     if(fMCLabel)   newMCLabel[i]   = fMCLabel  [idxArray[i]];
285     if(fEFraction) newEFraction[i] = fEFraction[idxArray[i]];  
286   }
287   if(fHGLG){
288     for (Int_t i=0; i < fNCells; i++) 
289     {
290       newHGLG[i]      = fHGLG[idxArray[i]];
291     }
292     delete [] fHGLG;
293   }
294   
295   delete [] fCellNumber;
296   delete [] fAmplitude;
297   delete [] fTime;
298   delete [] fMCLabel;
299   delete [] fEFraction;
300
301   fHGLG = newHGLG;
302   fCellNumber = newIndex;
303   fAmplitude  = newAmplitude;
304   if(fTime)      fTime       = newTime;
305   if(fMCLabel)   fMCLabel    = newMCLabel;
306   if(fEFraction) fEFraction  = newEFraction;
307
308   delete [] idxArray;
309   
310   fIsSorted = kTRUE;
311
312
313 //________________________________________________________________________________________
314 Bool_t AliAODCaloCells::SetCell(Short_t pos,     Short_t cellNumber, Double32_t amplitude, 
315                                 Double32_t time, Int_t mclabel,    Double32_t efrac, Bool_t isHG)
316 {
317   // Sets a cell at the given position
318
319   if (pos>=0 && pos < fNCells) 
320   {
321     if(fHGLG)
322       fHGLG[pos]=isHG ;
323     fCellNumber[pos] = cellNumber;
324     fAmplitude[pos]  = amplitude;
325     
326     // note: initialize (can't use memset for non-0 values)
327     //       plus sizeof(Double32_t) is 0
328     if(!fTime){
329       fTime  = new Double32_t[fNCells];
330       
331       for( Int_t i = 0; i < fNCells; i++ )
332         fTime[i] = -1;
333     }
334     if(!fMCLabel){
335       fMCLabel = new Int_t[fNCells];
336       
337       for( Int_t i = 0; i < fNCells; i++ )
338         fMCLabel[i] = -1;
339     }
340     if(!fEFraction){
341       fEFraction = new Double32_t[fNCells];
342       
343       for( Int_t i = 0; i < fNCells; i++ )
344         fEFraction[i] = 0;
345     }
346     
347     fTime[pos]       = time;
348     fMCLabel[pos]    = mclabel;
349     fEFraction[pos]  = efrac;
350     
351     fIsSorted        = kFALSE;
352     
353     return kTRUE;
354     
355   } else {
356     return kFALSE;
357   }
358 }
359
360
361
362