]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/ESD/AliESDCaloCells.cxx
f9978610f25b0d8aff83b5787028bf2ff4798b0c
[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), 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), 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),  fCellNumber(0), 
48   fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
49   fIsSorted(c.fIsSorted), fType(c.fType)
50 {
51   // copy constructor
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   {
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 }
68
69 //__________________________________________________________________________
70 AliESDCaloCells & AliESDCaloCells::operator =(const AliESDCaloCells& source)  
71 {
72   // assignment operator
73
74   if(this != &source)
75   {
76     AliVCaloCells::operator=(source);
77     
78     if(fNCells != source.fNCells) 
79     {
80       delete [] fCellNumber;
81       delete [] fAmplitude;
82       delete [] fTime;
83       delete [] fMCLabel;
84       delete [] fEFraction;
85       
86       fNCells = source.fNCells;
87       
88       fCellNumber = new Short_t[fNCells];
89       fAmplitude  = new Double32_t[fNCells];
90       fTime       = new Double32_t[fNCells];
91       fMCLabel    = new Int_t[fNCells];
92       fEFraction  = new Double32_t[fNCells];
93     }
94     
95     memcpy(fCellNumber,source.fCellNumber,fNCells*sizeof(Short_t));
96     memcpy(fAmplitude, source.fAmplitude, fNCells*sizeof(Double32_t));
97     memcpy(fTime,      source.fTime,      fNCells*sizeof(Double32_t));
98     if(source.fMCLabel   && fMCLabel)   memcpy(fMCLabel,   source.fMCLabel,   fNCells*sizeof(Int_t));
99     if(source.fEFraction && fEFraction) memcpy(fEFraction, source.fEFraction, fNCells*sizeof(Double32_t));
100
101     fIsSorted = source.fIsSorted;
102     fType = source.fType;
103     
104   }
105
106   return *this;
107 }
108
109 //____________________________________________
110 void AliESDCaloCells::Copy(TObject &obj) const 
111 {
112   // this overwrites the virtual TOBject::Copy()
113   // to allow run time copying without casting
114   // in AliESDEvent
115
116   if(this==&obj)return;
117   AliESDCaloCells *robj = dynamic_cast<AliESDCaloCells*>(&obj);
118   if(!robj)return; // not an AliESDCaloCells
119   *robj = *this;
120
121 }
122
123 //______________________________________________________________________
124 AliVCaloCells* AliESDCaloCells::CopyCaloCells(Bool_t all = kTRUE) const
125 {  
126   // copy the calo cells into a new object. If option all=FALSE, just the object type, 
127   // for mixing
128   
129   AliVCaloCells *obj = new AliESDCaloCells();
130   
131   if(all){
132     obj->SetName (GetName()) ; 
133     obj->SetTitle(GetTitle()) ; 
134     obj->SetType (GetType()) ; 
135     
136     obj->SetNumberOfCells(fNCells);
137     for (Short_t i = 0; i < fNCells; i++) 
138     {
139       Int_t mclabel = -1;
140       if(fMCLabel) mclabel = fMCLabel[i];
141       
142       Float_t efrac = 0.;
143       if(fEFraction) efrac = fEFraction[i];
144       
145       obj->SetCell(i,fCellNumber[i],fAmplitude[i],fTime[i],mclabel,efrac);
146     }
147   }
148
149   return obj;
150 }
151
152
153 //_________________________________
154 AliESDCaloCells::~AliESDCaloCells()
155 {
156   // destructor
157
158   DeleteContainer();
159 }
160
161 //__________________________________________
162 void AliESDCaloCells::Clear(const Option_t*)
163 {
164   // clear
165   
166   DeleteContainer();
167 }
168
169
170 //___________________________________________________
171 void AliESDCaloCells::CreateContainer(Short_t nCells)
172 {
173   // function that creates container to store calorimeter cell data
174
175   DeleteContainer();
176   
177   if (nCells <= 0) 
178   {
179     fNCells = 0;
180     return;
181   }
182
183   fNCells = nCells;
184
185   fCellNumber = new Short_t[fNCells];
186   fAmplitude  = new Double32_t[fNCells];
187   fTime       = new Double32_t[fNCells];
188   fMCLabel    = new Int_t[fNCells];
189   fEFraction  = new Double32_t[fNCells];
190
191   // set to zero
192   for(int i = 0;i<fNCells;++i)
193   {
194     fAmplitude [i] =  0.; 
195     fCellNumber[i] = -1 ; 
196     fEFraction [i] =  0.;
197     fTime      [i] = -1.;
198     fMCLabel   [i] = -1 ;
199   }
200 }
201
202 //_____________________________________
203 void AliESDCaloCells::DeleteContainer()
204 {
205   // deletes allocated memory
206
207   if (fCellNumber)
208   {
209     delete[] fCellNumber;
210     fCellNumber = 0;
211   }
212
213   if (fAmplitude)
214   {
215     delete[] fAmplitude;
216     fAmplitude = NULL;
217   }
218
219   if (fTime)
220   {
221     delete[] fTime;
222     fTime = NULL;
223   }
224   
225   if (fMCLabel)
226   {
227     delete[] fMCLabel;
228     fMCLabel = NULL;
229   }
230   
231   if (fEFraction)
232   {
233     delete[] fEFraction;
234     fEFraction = NULL;
235   }
236   
237   fNCells = 0;
238   fIsSorted = kFALSE;
239   
240 }
241
242 //__________________________
243 void AliESDCaloCells::Sort() 
244 {
245   // sort the cell array by cell number
246   
247   Int_t *idxArray = new Int_t[fNCells];
248   TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
249   
250   Short_t    *newIndex     = new Short_t[fNCells];
251   Double32_t *newAmplitude = new Double32_t[fNCells];
252   Double32_t *newTime      = new Double32_t[fNCells];
253   
254   Int_t    *newMCLabel   = 0 ;
255   Double32_t *newEFraction = 0 ; 
256   if(fMCLabel)   newMCLabel   = new Int_t[fNCells];
257   if(fEFraction) newEFraction = new Double32_t[fNCells];
258     
259   for (Int_t i=0; i < fNCells; i++) 
260   {
261     newIndex[i]     = fCellNumber[idxArray[i]];
262     newAmplitude[i] = fAmplitude [idxArray[i]];
263     newTime[i]      = fTime      [idxArray[i]];
264     if(fMCLabel)   newMCLabel[i]   = fMCLabel  [idxArray[i]];
265     if(fEFraction) newEFraction[i] = fEFraction[idxArray[i]];
266   }
267   
268   delete [] fCellNumber;
269   delete [] fAmplitude;
270   delete [] fTime;
271   delete [] fMCLabel;
272   delete [] fEFraction;
273
274   fCellNumber = newIndex;
275   fAmplitude  = newAmplitude;
276   fTime       = newTime;
277   if(fMCLabel)   fMCLabel    = newMCLabel;
278   if(fEFraction) fEFraction  = newEFraction;
279
280   delete [] idxArray;
281   
282   fIsSorted = kTRUE;
283
284
285 //________________________________________________________________________________________
286 Bool_t AliESDCaloCells::SetCell(Short_t pos,     Short_t cellNumber, Double32_t amplitude,  
287                                 Double32_t time, Int_t mclabel,    Double32_t efrac)
288 {
289   // Sets a cell at the given position
290
291   if (pos>=0 && pos < fNCells) 
292   {
293     fCellNumber[pos] = cellNumber;
294     fAmplitude[pos]  = amplitude;
295     fTime[pos]       = time;
296     
297     // note: initialize (can't use memset for non-0 values)
298     //       plus sizeof(Double32_t) is 0
299     if(!fMCLabel){
300       fMCLabel   = new Int_t[fNCells];
301
302       for( Int_t i = 0; i < fNCells; i++ )
303         fMCLabel[i] = -1;
304     }
305     if(!fEFraction){
306       fEFraction = new Double32_t[fNCells];
307
308       for( Int_t i = 0; i < fNCells; i++ )
309         fEFraction[i] = 0;
310     }
311
312     fMCLabel[pos]    = mclabel;
313     fEFraction[pos]  = efrac;
314     
315     fIsSorted = kFALSE;
316     
317     return kTRUE;
318     
319   } else {
320     return kFALSE;
321   }
322 }