]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/ESD/AliESDCaloCells.cxx
Merge branch 'TPCdev' into master
[u/mrichter/AliRoot.git] / STEER / ESD / AliESDCaloCells.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 //     ESD class to store calorimeter cell data
20 //     Clone of AliAODCaloCells made by Markus Oldenburg, CERN
21 //     Author: Gustavo Conesa Balbastre INFN-LNF
22 //-------------------------------------------------------------------------
23
24 #include "AliESDCaloCells.h"
25
26 ClassImp(AliESDCaloCells)
27
28 //_____________________________________________________
29 AliESDCaloCells::AliESDCaloCells() : 
30   AliVCaloCells(), fNCells(0), fHGLG(0),fCellNumber(0), 
31   fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0), 
32   fIsSorted(kTRUE), fType(kUndef)
33 {
34   // default constructor
35 }
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    // AliVCaloCells constructor
43  }
44
45 //__________________________________________________________
46 AliESDCaloCells::AliESDCaloCells(const AliESDCaloCells& c) : 
47   AliVCaloCells(c), fNCells(c.fNCells),  fHGLG(0), fCellNumber(0), 
48   fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
49   fIsSorted(c.fIsSorted), fType(c.fType)
50 {
51   // copy constructor
52   fHGLG       = new Bool_t[fNCells] ;
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   {
61     fCellNumber[i]    = c.fCellNumber[i];
62     fAmplitude[i]     = c.fAmplitude[i];
63     fTime[i]          = c.fTime[i];
64     if(c.fMCLabel)  fMCLabel[i]   = c.fMCLabel[i];
65     if(c.fEFraction)fEFraction[i] = c.fEFraction[i];
66   }
67   if(c.fHGLG){
68     for(Int_t i = 0; i < fNCells; i++){
69       fHGLG[i]          = c.fHGLG[i];   
70     }
71   }
72 }
73
74 //__________________________________________________________________________
75 AliESDCaloCells & AliESDCaloCells::operator =(const AliESDCaloCells& source)  
76 {
77   // assignment operator
78
79   if(this != &source)
80   {
81     AliVCaloCells::operator=(source);
82     
83     if(fNCells != source.fNCells) 
84     {
85       if(fHGLG)
86         delete [] fHGLG ;
87       delete [] fCellNumber;
88       delete [] fAmplitude;
89       delete [] fTime;
90       delete [] fMCLabel;
91       delete [] fEFraction;
92       
93       fNCells = source.fNCells;
94   
95       if(source.fHGLG)
96         fHGLG       = new Bool_t[fNCells] ;
97       fCellNumber = new Short_t[fNCells];
98       fAmplitude  = new Double32_t[fNCells];
99       fTime       = new Double32_t[fNCells];
100       fMCLabel    = new Int_t[fNCells];
101       fEFraction  = new Double32_t[fNCells];
102     }
103     
104     if(source.fHGLG)
105       memcpy(fCellNumber,source.fHGLG,fNCells*sizeof(Bool_t));
106     memcpy(fCellNumber,source.fCellNumber,fNCells*sizeof(Short_t));
107     memcpy(fAmplitude, source.fAmplitude, fNCells*sizeof(Double32_t));
108     memcpy(fTime,      source.fTime,      fNCells*sizeof(Double32_t));
109     if(source.fMCLabel   && fMCLabel)   memcpy(fMCLabel,   source.fMCLabel,   fNCells*sizeof(Int_t));
110     if(source.fEFraction && fEFraction) memcpy(fEFraction, source.fEFraction, fNCells*sizeof(Double32_t));
111
112     fIsSorted = source.fIsSorted;
113     fType = source.fType;
114     
115   }
116
117   return *this;
118 }
119
120 //____________________________________________
121 void AliESDCaloCells::Copy(TObject &obj) const 
122 {
123   // this overwrites the virtual TOBject::Copy()
124   // to allow run time copying without casting
125   // in AliESDEvent
126
127   if(this==&obj)return;
128   AliESDCaloCells *robj = dynamic_cast<AliESDCaloCells*>(&obj);
129   if(!robj)return; // not an AliESDCaloCells
130   *robj = *this;
131
132 }
133
134 //______________________________________________________________________
135 AliVCaloCells* AliESDCaloCells::CopyCaloCells(Bool_t all = kTRUE) const
136 {  
137   // copy the calo cells into a new object. If option all=FALSE, just the object type, 
138   // for mixing
139   
140   AliVCaloCells *obj = new AliESDCaloCells();
141   
142   if(all){
143     obj->SetName (GetName()) ; 
144     obj->SetTitle(GetTitle()) ; 
145     obj->SetType (GetType()) ; 
146     
147     obj->SetNumberOfCells(fNCells);
148     for (Short_t i = 0; i < fNCells; i++) 
149     {
150       Int_t mclabel = -1;
151       if(fMCLabel) mclabel = fMCLabel[i];
152       
153       Float_t efrac = 0.;
154       if(fEFraction) efrac = fEFraction[i];
155       
156       obj->SetCell(i,fCellNumber[i],fAmplitude[i],fTime[i],mclabel,efrac);
157     }
158   }
159
160   return obj;
161 }
162
163
164 //_________________________________
165 AliESDCaloCells::~AliESDCaloCells()
166 {
167   // destructor
168
169   DeleteContainer();
170 }
171
172 //__________________________________________
173 void AliESDCaloCells::Clear(const Option_t*)
174 {
175   // clear
176   
177   DeleteContainer();
178 }
179
180
181 //___________________________________________________
182 void AliESDCaloCells::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 AliESDCaloCells::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 = 0;
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   fNCells = 0;
255   fIsSorted = kFALSE;
256   
257 }
258
259 //__________________________
260 void AliESDCaloCells::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   Short_t    *newIndex     = new Short_t[fNCells];
268   Double32_t *newAmplitude = new Double32_t[fNCells];
269   Double32_t *newTime      = new Double32_t[fNCells];
270   
271   Int_t    *newMCLabel   = 0 ;
272   Double32_t *newEFraction = 0 ; 
273   if(fMCLabel)   newMCLabel   = new Int_t[fNCells];
274   if(fEFraction) newEFraction = new Double32_t[fNCells];
275     
276   for (Int_t i=0; i < fNCells; i++) 
277   {
278     newIndex[i]     = fCellNumber[idxArray[i]];
279     newAmplitude[i] = fAmplitude [idxArray[i]];
280     newTime[i]      = fTime      [idxArray[i]];
281     if(fMCLabel)   newMCLabel[i]   = fMCLabel  [idxArray[i]];
282     if(fEFraction) newEFraction[i] = fEFraction[idxArray[i]];
283   }
284   if(fHGLG){
285     Bool_t     *newHGLG      = new Bool_t[fNCells];
286     for (Int_t i=0; i < fNCells; i++) {
287       newHGLG[i]      = fHGLG[idxArray[i]];
288     }
289     delete [] fHGLG;  
290     fHGLG = newHGLG;
291   }
292   
293   delete [] fCellNumber;
294   delete [] fAmplitude;
295   delete [] fTime;
296   delete [] fMCLabel;
297   delete [] fEFraction;
298
299   fCellNumber = newIndex;
300   fAmplitude  = newAmplitude;
301   fTime       = newTime;
302   if(fMCLabel)   fMCLabel    = newMCLabel;
303   if(fEFraction) fEFraction  = newEFraction;
304
305   delete [] idxArray;
306   
307   fIsSorted = kTRUE;
308
309
310 //________________________________________________________________________________________
311 Bool_t AliESDCaloCells::SetCell(Short_t pos,     Short_t cellNumber, Double32_t amplitude,  
312                                 Double32_t time, Int_t mclabel,    Double32_t efrac, Bool_t isHG)
313 {
314   // Sets a cell at the given position
315
316   if (pos>=0 && pos < fNCells) 
317   {
318     if(fHGLG)
319       fHGLG[pos]=isHG ;
320     fCellNumber[pos] = cellNumber;
321     fAmplitude[pos]  = amplitude;
322     fTime[pos]       = time;
323     
324     // note: initialize (can't use memset for non-0 values)
325     //       plus sizeof(Double32_t) is 0
326     if(!fMCLabel){
327       fMCLabel   = new Int_t[fNCells];
328
329       for( Int_t i = 0; i < fNCells; i++ )
330         fMCLabel[i] = -1;
331     }
332     if(!fEFraction){
333       fEFraction = new Double32_t[fNCells];
334
335       for( Int_t i = 0; i < fNCells; i++ )
336         fEFraction[i] = 0;
337     }
338
339     fMCLabel[pos]    = mclabel;
340     fEFraction[pos]  = efrac;
341     
342     fIsSorted = kFALSE;
343     
344     return kTRUE;
345     
346   } else {
347     return kFALSE;
348   }
349 }