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), fHGLG(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), fHGLG(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), fHGLG(0), fCellNumber(0),
48 fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
49 fIsSorted(c.fIsSorted), fType(c.fType)
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];
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];
68 for(Int_t i = 0; i < fNCells; i++){
69 fHGLG[i] = c.fHGLG[i];
74 //__________________________________________________________________________
75 AliESDCaloCells & AliESDCaloCells::operator =(const AliESDCaloCells& source)
77 // assignment operator
81 AliVCaloCells::operator=(source);
83 if(fNCells != source.fNCells)
87 delete [] fCellNumber;
93 fNCells = source.fNCells;
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];
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));
112 fIsSorted = source.fIsSorted;
113 fType = source.fType;
120 //____________________________________________
121 void AliESDCaloCells::Copy(TObject &obj) const
123 // this overwrites the virtual TOBject::Copy()
124 // to allow run time copying without casting
127 if(this==&obj)return;
128 AliESDCaloCells *robj = dynamic_cast<AliESDCaloCells*>(&obj);
129 if(!robj)return; // not an AliESDCaloCells
134 //______________________________________________________________________
135 AliVCaloCells* AliESDCaloCells::CopyCaloCells(Bool_t all = kTRUE) const
137 // copy the calo cells into a new object. If option all=FALSE, just the object type,
140 AliVCaloCells *obj = new AliESDCaloCells();
143 obj->SetName (GetName()) ;
144 obj->SetTitle(GetTitle()) ;
145 obj->SetType (GetType()) ;
147 obj->SetNumberOfCells(fNCells);
148 for (Short_t i = 0; i < fNCells; i++)
151 if(fMCLabel) mclabel = fMCLabel[i];
154 if(fEFraction) efrac = fEFraction[i];
156 obj->SetCell(i,fCellNumber[i],fAmplitude[i],fTime[i],mclabel,efrac);
164 //_________________________________
165 AliESDCaloCells::~AliESDCaloCells()
172 //__________________________________________
173 void AliESDCaloCells::Clear(const Option_t*)
181 //___________________________________________________
182 void AliESDCaloCells::CreateContainer(Short_t nCells)
184 // function that creates container to store calorimeter cell data
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];
204 for(int i = 0;i<fNCells;++i)
208 fCellNumber[i] = -1 ;
215 //_____________________________________
216 void AliESDCaloCells::DeleteContainer()
218 // deletes allocated memory
226 delete[] fCellNumber;
259 //__________________________
260 void AliESDCaloCells::Sort()
262 // sort the cell array by cell number
264 Int_t *idxArray = new Int_t[fNCells];
265 TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
267 Short_t *newIndex = new Short_t[fNCells];
268 Double32_t *newAmplitude = new Double32_t[fNCells];
269 Double32_t *newTime = new Double32_t[fNCells];
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];
276 for (Int_t i=0; i < fNCells; i++)
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]];
285 Bool_t *newHGLG = new Bool_t[fNCells];
286 for (Int_t i=0; i < fNCells; i++) {
287 newHGLG[i] = fHGLG[idxArray[i]];
293 delete [] fCellNumber;
294 delete [] fAmplitude;
297 delete [] fEFraction;
299 fCellNumber = newIndex;
300 fAmplitude = newAmplitude;
302 if(fMCLabel) fMCLabel = newMCLabel;
303 if(fEFraction) fEFraction = newEFraction;
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)
314 // Sets a cell at the given position
316 if (pos>=0 && pos < fNCells)
320 fCellNumber[pos] = cellNumber;
321 fAmplitude[pos] = amplitude;
324 // note: initialize (can't use memset for non-0 values)
325 // plus sizeof(Double32_t) is 0
327 fMCLabel = new Int_t[fNCells];
329 for( Int_t i = 0; i < fNCells; i++ )
333 fEFraction = new Double32_t[fNCells];
335 for( Int_t i = 0; i < fNCells; i++ )
339 fMCLabel[pos] = mclabel;
340 fEFraction[pos] = efrac;