]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AOD/AliAODCaloCells.cxx
Added possibility to load automatically the field in analysis via AliInputEventHandle...
[u/mrichter/AliRoot.git] / STEER / AOD / AliAODCaloCells.cxx
CommitLineData
8d122774 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
25ClassImp(AliAODCaloCells)
26
77e93dc2 27//_______________________________________________________
28AliAODCaloCells::AliAODCaloCells() :
29 AliVCaloCells(), fNCells(0), fCellNumber(0),
30 fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
31 fIsSorted(kTRUE), fType(kUndef)
8d122774 32{
33 // default constructor
34}
35
77e93dc2 36//_____________________________________________________________________________________
c8fe2783 37AliAODCaloCells::AliAODCaloCells(const char* name, const char* title, VCells_t ttype) :
77e93dc2 38 AliVCaloCells(name, title), fNCells(0), fCellNumber(0),
39 fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
40 fIsSorted(kTRUE), fType(ttype)
8d122774 41{
c8fe2783 42 //constructor
8d122774 43}
44
77e93dc2 45//________________________________________________________________
5c1dc41f 46AliAODCaloCells::AliAODCaloCells(const AliAODCaloCells& cells) :
77e93dc2 47 AliVCaloCells(cells), fNCells(cells.fNCells), fCellNumber(0),
48 fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
49 fIsSorted(cells.fIsSorted), fType(cells.fType)
5c1dc41f 50{
51// Copy constructor
c8fe2783 52 fCellNumber = new Short_t[fNCells];
53 fAmplitude = new Double32_t[fNCells];
77e93dc2 54 fTime = new Double32_t[fNCells];
60d77596 55 fMCLabel = new Int_t[fNCells];
77e93dc2 56 fEFraction = new Double32_t[fNCells];
57
c8fe2783 58 for (Int_t i = 0; i < fNCells; i++) {
59 fCellNumber[i] = cells.fCellNumber[i];
60 fAmplitude[i] = cells.fAmplitude[i];
00c970e8 61 if(cells.fTime) fTime[i] = cells.fTime[i];
77e93dc2 62 if(cells.fMCLabel) fMCLabel[i] = cells.fMCLabel[i];
63 if(cells.fEFraction)fEFraction[i] = cells.fEFraction[i];
c8fe2783 64 }
5c1dc41f 65}
66
77e93dc2 67//________________________________________________________________________
0d7404df 68AliAODCaloCells& AliAODCaloCells::operator=(const AliAODCaloCells& source)
5c1dc41f 69{
77e93dc2 70 // Assignment operator
71 if(this != &source)
72 {
0d7404df 73 AliVCaloCells::operator=(source);
74
77e93dc2 75 if(fNCells != source.fNCells)
76 {
0d7404df 77 delete [] fCellNumber;
78 delete [] fAmplitude;
77e93dc2 79 delete [] fTime;
80 delete [] fMCLabel;
81 delete [] fEFraction;
82
0d7404df 83 fNCells = source.fNCells;
77e93dc2 84
0d7404df 85 fCellNumber = new Short_t[fNCells];
86 fAmplitude = new Double32_t[fNCells];
77e93dc2 87 fTime = new Double32_t[fNCells];
60d77596 88 fMCLabel = new Int_t[fNCells];
77e93dc2 89 fEFraction = new Double32_t[fNCells];
0d7404df 90 }
77e93dc2 91
0d7404df 92 memcpy(fCellNumber,source.fCellNumber, fNCells*sizeof(Short_t));
93 memcpy(fAmplitude, source.fAmplitude, fNCells*sizeof(Double32_t));
77e93dc2 94 if(source.fTime && fTime) memcpy(fTime, source.fTime, fNCells*sizeof(Double32_t));
60d77596 95 if(source.fMCLabel && fMCLabel) memcpy(fMCLabel, source.fMCLabel, fNCells*sizeof(Int_t));
77e93dc2 96 if(source.fEFraction && fEFraction) memcpy(fEFraction, source.fEFraction, fNCells*sizeof(Double32_t));
97
0d7404df 98 fIsSorted = source.fIsSorted;
99 fType = source.fType;
c8fe2783 100 }
0d7404df 101
c8fe2783 102 return *this;
0d7404df 103
5c1dc41f 104}
105
77e93dc2 106//_________________________________
8d122774 107AliAODCaloCells::~AliAODCaloCells()
108{
109 // destructor
110
111 DeleteContainer();
112}
113
8dd6eba0 114void AliAODCaloCells::Clear(const Option_t*)
115{
116 // clear
117
118 DeleteContainer();
119}
ecff8f07 120
77e93dc2 121void AliAODCaloCells::Copy(TObject &obj) const
122{
ecff8f07 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
77e93dc2 135//______________________________________________________________________
136AliVCaloCells *AliAODCaloCells::CopyCaloCells(Bool_t all = kTRUE) const
137{
ecff8f07 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++)
77e93dc2 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 }
ecff8f07 163 }
164
165 return obj;
166
167}
168
77e93dc2 169//___________________________________________________
8d122774 170void AliAODCaloCells::CreateContainer(Short_t nCells)
171{
172 // function that creates container to store calorimeter cell data
173
174 DeleteContainer();
175
f8785caa 176 if (nCells <= 0)
177 {
8d122774 178 fNCells = 0;
179 return;
180 }
181
182 fNCells = nCells;
183
184 fCellNumber = new Short_t[fNCells];
c8fe2783 185 fAmplitude = new Double32_t[fNCells];
77e93dc2 186 fTime = new Double32_t[fNCells];
60d77596 187 fMCLabel = new Int_t[fNCells];
77e93dc2 188 fEFraction = new Double32_t[fNCells];
c8fe2783 189
341952b8 190 // set to zero
f8785caa 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 ;
341952b8 198 }
8d122774 199}
200
77e93dc2 201//_____________________________________
8d122774 202void AliAODCaloCells::DeleteContainer()
203{
204 // deletes allocated memory
205
206 if (fCellNumber)
207 {
208 delete[] fCellNumber;
c8fe2783 209 fCellNumber = NULL;
8d122774 210 }
211
212 if (fAmplitude)
213 {
214 delete[] fAmplitude;
c8fe2783 215 fAmplitude = NULL;
8d122774 216 }
c8fe2783 217
77e93dc2 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
8d122774 237 fNCells = 0;
238 fIsSorted = kFALSE;
239}
240
77e93dc2 241//__________________________
8d122774 242void 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
c8fe2783 249 Short_t *newIndex = new Short_t[fNCells];
8d122774 250 Double32_t *newAmplitude = new Double32_t[fNCells];
f8785caa 251
252 Double32_t *newTime = 0;
60d77596 253 Int_t *newMCLabel = 0 ;
f8785caa 254 Double32_t *newEFraction = 0 ;
255 if(fTime) newTime = new Double32_t[fNCells];
60d77596 256 if(fMCLabel) newMCLabel = new Int_t[fNCells];
f8785caa 257 if(fEFraction) newEFraction = new Double32_t[fNCells];
258
77e93dc2 259 for (Int_t i=0; i < fNCells; i++)
260 {
c8fe2783 261 newIndex[i] = fCellNumber[idxArray[i]];
77e93dc2 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]];
8d122774 266 }
77e93dc2 267
8d122774 268 delete [] fCellNumber;
269 delete [] fAmplitude;
77e93dc2 270 delete [] fTime;
271 delete [] fMCLabel;
272 delete [] fEFraction;
273
8d122774 274 fCellNumber = newIndex;
c8fe2783 275 fAmplitude = newAmplitude;
77e93dc2 276 if(fTime) fTime = newTime;
277 if(fMCLabel) fMCLabel = newMCLabel;
278 if(fEFraction) fEFraction = newEFraction;
279
8d122774 280 delete [] idxArray;
281
282 fIsSorted = kTRUE;
283}
284
77e93dc2 285//________________________________________________________________________________________
286Bool_t AliAODCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude,
60d77596 287 Double32_t time, Int_t mclabel, Double32_t efrac)
8d122774 288{
289 // Sets a cell at the given position
290
77e93dc2 291 if (pos>=0 && pos < fNCells)
292 {
8d122774 293 fCellNumber[pos] = cellNumber;
c8fe2783 294 fAmplitude[pos] = amplitude;
77e93dc2 295
00c970e8 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){
60d77596 305 fMCLabel = new Int_t[fNCells];
00c970e8 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 }
77e93dc2 316
317 fTime[pos] = time;
318 fMCLabel[pos] = mclabel;
319 fEFraction[pos] = efrac;
320
321 fIsSorted = kFALSE;
322
8d122774 323 return kTRUE;
77e93dc2 324
8d122774 325 } else {
326 return kFALSE;
327 }
328}
77e93dc2 329
330
331
332