1 /**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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 //-------------------------------------------------------------------------
24 #include "AliESDCaloCells.h"
26 ClassImp(AliESDCaloCells)
28 //_____________________________________________________
29 AliESDCaloCells::AliESDCaloCells() :
30 AliVCaloCells(), fNCells(0), fCellNumber(0),
31 fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
32 fIsSorted(kTRUE), fType(kUndef)
34 // default constructor
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)
42 // AliVCaloCells constructor
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)
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];
59 for(Int_t i = 0; i < fNCells; i++)
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];
69 //__________________________________________________________________________
70 AliESDCaloCells & AliESDCaloCells::operator =(const AliESDCaloCells& source)
72 // assignment operator
76 AliVCaloCells::operator=(source);
78 if(fNCells != source.fNCells)
80 delete [] fCellNumber;
86 fNCells = source.fNCells;
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];
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));
101 fIsSorted = source.fIsSorted;
102 fType = source.fType;
109 //____________________________________________
110 void AliESDCaloCells::Copy(TObject &obj) const
112 // this overwrites the virtual TOBject::Copy()
113 // to allow run time copying without casting
116 if(this==&obj)return;
117 AliESDCaloCells *robj = dynamic_cast<AliESDCaloCells*>(&obj);
118 if(!robj)return; // not an AliESDCaloCells
123 //______________________________________________________________________
124 AliVCaloCells* AliESDCaloCells::CopyCaloCells(Bool_t all = kTRUE) const
126 // copy the calo cells into a new object. If option all=FALSE, just the object type,
129 AliVCaloCells *obj = new AliESDCaloCells();
132 obj->SetName (GetName()) ;
133 obj->SetTitle(GetTitle()) ;
134 obj->SetType (GetType()) ;
136 obj->SetNumberOfCells(fNCells);
137 for (Short_t i = 0; i < fNCells; i++)
140 if(fMCLabel) mclabel = fMCLabel[i];
143 if(fEFraction) efrac = fEFraction[i];
145 obj->SetCell(i,fCellNumber[i],fAmplitude[i],fTime[i],mclabel,efrac);
153 //_________________________________
154 AliESDCaloCells::~AliESDCaloCells()
161 //__________________________________________
162 void AliESDCaloCells::Clear(const Option_t*)
170 //___________________________________________________
171 void AliESDCaloCells::CreateContainer(Short_t nCells)
173 // function that creates container to store calorimeter cell data
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];
192 for(int i = 0;i<fNCells;++i)
195 fCellNumber[i] = -1 ;
202 //_____________________________________
203 void AliESDCaloCells::DeleteContainer()
205 // deletes allocated memory
209 delete[] fCellNumber;
242 //__________________________
243 void AliESDCaloCells::Sort()
245 // sort the cell array by cell number
247 Int_t *idxArray = new Int_t[fNCells];
248 TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
250 Short_t *newIndex = new Short_t[fNCells];
251 Double32_t *newAmplitude = new Double32_t[fNCells];
252 Double32_t *newTime = new Double32_t[fNCells];
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];
259 for (Int_t i=0; i < fNCells; i++)
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]];
268 delete [] fCellNumber;
269 delete [] fAmplitude;
272 delete [] fEFraction;
274 fCellNumber = newIndex;
275 fAmplitude = newAmplitude;
277 if(fMCLabel) fMCLabel = newMCLabel;
278 if(fEFraction) fEFraction = newEFraction;
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)
289 // Sets a cell at the given position
291 if (pos>=0 && pos < fNCells)
293 fCellNumber[pos] = cellNumber;
294 fAmplitude[pos] = amplitude;
297 // note: initialize (can't use memset for non-0 values)
298 // plus sizeof(Double32_t) is 0
300 fMCLabel = new Int_t[fNCells];
302 for( Int_t i = 0; i < fNCells; i++ )
306 fEFraction = new Double32_t[fNCells];
308 for( Int_t i = 0; i < fNCells; i++ )
312 fMCLabel[pos] = mclabel;
313 fEFraction[pos] = efrac;