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