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 // AOD class to store calorimeter cell data
20 // Author: Markus Oldenburg, CERN
21 //-------------------------------------------------------------------------
23 #include "AliAODCaloCells.h"
25 ClassImp(AliAODCaloCells)
27 //_______________________________________________________
28 AliAODCaloCells::AliAODCaloCells() :
29 AliVCaloCells(), fNCells(0), fHGLG(0), fCellNumber(0),
30 fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
31 fIsSorted(kTRUE), fType(kUndef)
33 // default constructor
36 //_____________________________________________________________________________________
37 AliAODCaloCells::AliAODCaloCells(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)
45 //________________________________________________________________
46 AliAODCaloCells::AliAODCaloCells(const AliAODCaloCells& cells) :
47 AliVCaloCells(cells), fNCells(cells.fNCells), fHGLG(0), fCellNumber(0),
48 fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
49 fIsSorted(cells.fIsSorted), fType(cells.fType)
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];
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];
66 fHGLG = new Bool_t[fNCells] ;
67 for (Int_t i = 0; i < fNCells; i++) {
68 fHGLG[i] = cells.fHGLG[i];
73 //________________________________________________________________________
74 AliAODCaloCells& AliAODCaloCells::operator=(const AliAODCaloCells& source)
76 // Assignment operator
79 AliVCaloCells::operator=(source);
81 if(fNCells != source.fNCells)
85 delete [] fCellNumber;
91 fNCells = source.fNCells;
94 fHGLG = new Bool_t[fNCells] ;
95 fCellNumber = new Short_t[fNCells];
96 fAmplitude = new Double32_t[fNCells];
97 fTime = new Double32_t[fNCells];
98 fMCLabel = new Int_t[fNCells];
99 fEFraction = new Double32_t[fNCells];
103 memcpy(fCellNumber,source.fHGLG,fNCells*sizeof(Bool_t));
104 memcpy(fCellNumber,source.fCellNumber, fNCells*sizeof(Short_t));
105 memcpy(fAmplitude, source.fAmplitude, fNCells*sizeof(Double32_t));
106 if(source.fTime && fTime) memcpy(fTime, source.fTime, fNCells*sizeof(Double32_t));
107 if(source.fMCLabel && fMCLabel) memcpy(fMCLabel, source.fMCLabel, fNCells*sizeof(Int_t));
108 if(source.fEFraction && fEFraction) memcpy(fEFraction, source.fEFraction, fNCells*sizeof(Double32_t));
110 fIsSorted = source.fIsSorted;
111 fType = source.fType;
118 //_________________________________
119 AliAODCaloCells::~AliAODCaloCells()
126 void AliAODCaloCells::Clear(const Option_t*)
133 void AliAODCaloCells::Copy(TObject &obj) const
136 // this overwrites the virtual TOBject::Copy()
137 // to allow run time copying without casting
140 if(this==&obj)return;
141 AliAODCaloCells *robj = dynamic_cast<AliAODCaloCells*>(&obj);
142 if(!robj)return; // not an AliAODCaloCells
147 //______________________________________________________________________
148 AliVCaloCells *AliAODCaloCells::CopyCaloCells(Bool_t all = kTRUE) const
151 // copy the calo cells into a new object. If option all=FALSE, just the object type,
154 AliVCaloCells *obj = new AliAODCaloCells();
157 obj->SetName (GetName()) ;
158 obj->SetTitle(GetTitle()) ;
159 obj->SetType (GetType()) ;
161 obj->SetNumberOfCells(fNCells);
162 for (Short_t i = 0; i < fNCells; i++)
165 if(fMCLabel) mclabel = fMCLabel[i];
168 if(fEFraction) efrac = fEFraction[i];
171 if(fTime) time = fTime[i];
173 obj->SetCell(i,fCellNumber[i],fAmplitude[i],time,mclabel,efrac);
181 //___________________________________________________
182 void AliAODCaloCells::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 AliAODCaloCells::DeleteContainer()
218 // deletes allocated memory
226 delete[] fCellNumber;
259 //__________________________
260 void AliAODCaloCells::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 Bool_t *newHGLG =0x0 ;
268 if(fHGLG) newHGLG = new Bool_t[fNCells];
269 Short_t *newIndex = new Short_t[fNCells];
270 Double32_t *newAmplitude = new Double32_t[fNCells];
272 Double32_t *newTime = 0;
273 Int_t *newMCLabel = 0 ;
274 Double32_t *newEFraction = 0 ;
275 if(fTime) newTime = new Double32_t[fNCells];
276 if(fMCLabel) newMCLabel = new Int_t[fNCells];
277 if(fEFraction) newEFraction = new Double32_t[fNCells];
279 for (Int_t i=0; i < fNCells; i++)
281 newIndex[i] = fCellNumber[idxArray[i]];
282 newAmplitude[i] = fAmplitude [idxArray[i]];
283 if(fTime) newTime[i] = fTime [idxArray[i]];
284 if(fMCLabel) newMCLabel[i] = fMCLabel [idxArray[i]];
285 if(fEFraction) newEFraction[i] = fEFraction[idxArray[i]];
288 for (Int_t i=0; i < fNCells; i++)
290 newHGLG[i] = fHGLG[idxArray[i]];
295 delete [] fCellNumber;
296 delete [] fAmplitude;
299 delete [] fEFraction;
302 fCellNumber = newIndex;
303 fAmplitude = newAmplitude;
304 if(fTime) fTime = newTime;
305 if(fMCLabel) fMCLabel = newMCLabel;
306 if(fEFraction) fEFraction = newEFraction;
313 //________________________________________________________________________________________
314 Bool_t AliAODCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude,
315 Double32_t time, Int_t mclabel, Double32_t efrac, Bool_t isHG)
317 // Sets a cell at the given position
319 if (pos>=0 && pos < fNCells)
323 fCellNumber[pos] = cellNumber;
324 fAmplitude[pos] = amplitude;
326 // note: initialize (can't use memset for non-0 values)
327 // plus sizeof(Double32_t) is 0
329 fTime = new Double32_t[fNCells];
331 for( Int_t i = 0; i < fNCells; i++ )
335 fMCLabel = new Int_t[fNCells];
337 for( Int_t i = 0; i < fNCells; i++ )
341 fEFraction = new Double32_t[fNCells];
343 for( Int_t i = 0; i < fNCells; i++ )
348 fMCLabel[pos] = mclabel;
349 fEFraction[pos] = efrac;