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 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++) {
60 fHGLG[i] = cells.fHGLG[i];
61 fCellNumber[i] = cells.fCellNumber[i];
62 fAmplitude[i] = cells.fAmplitude[i];
63 if(cells.fTime) fTime[i] = cells.fTime[i];
64 if(cells.fMCLabel) fMCLabel[i] = cells.fMCLabel[i];
65 if(cells.fEFraction)fEFraction[i] = cells.fEFraction[i];
69 //________________________________________________________________________
70 AliAODCaloCells& AliAODCaloCells::operator=(const AliAODCaloCells& source)
72 // Assignment operator
75 AliVCaloCells::operator=(source);
77 if(fNCells != source.fNCells)
80 delete [] fCellNumber;
86 fNCells = source.fNCells;
88 fHGLG = new Bool_t[fNCells] ;
89 fCellNumber = new Short_t[fNCells];
90 fAmplitude = new Double32_t[fNCells];
91 fTime = new Double32_t[fNCells];
92 fMCLabel = new Int_t[fNCells];
93 fEFraction = new Double32_t[fNCells];
96 memcpy(fCellNumber,source.fHGLG,fNCells*sizeof(Bool_t));
97 memcpy(fCellNumber,source.fCellNumber, fNCells*sizeof(Short_t));
98 memcpy(fAmplitude, source.fAmplitude, fNCells*sizeof(Double32_t));
99 if(source.fTime && fTime) memcpy(fTime, source.fTime, fNCells*sizeof(Double32_t));
100 if(source.fMCLabel && fMCLabel) memcpy(fMCLabel, source.fMCLabel, fNCells*sizeof(Int_t));
101 if(source.fEFraction && fEFraction) memcpy(fEFraction, source.fEFraction, fNCells*sizeof(Double32_t));
103 fIsSorted = source.fIsSorted;
104 fType = source.fType;
111 //_________________________________
112 AliAODCaloCells::~AliAODCaloCells()
119 void AliAODCaloCells::Clear(const Option_t*)
126 void AliAODCaloCells::Copy(TObject &obj) const
129 // this overwrites the virtual TOBject::Copy()
130 // to allow run time copying without casting
133 if(this==&obj)return;
134 AliAODCaloCells *robj = dynamic_cast<AliAODCaloCells*>(&obj);
135 if(!robj)return; // not an AliAODCaloCells
140 //______________________________________________________________________
141 AliVCaloCells *AliAODCaloCells::CopyCaloCells(Bool_t all = kTRUE) const
144 // copy the calo cells into a new object. If option all=FALSE, just the object type,
147 AliVCaloCells *obj = new AliAODCaloCells();
150 obj->SetName (GetName()) ;
151 obj->SetTitle(GetTitle()) ;
152 obj->SetType (GetType()) ;
154 obj->SetNumberOfCells(fNCells);
155 for (Short_t i = 0; i < fNCells; i++)
158 if(fMCLabel) mclabel = fMCLabel[i];
161 if(fEFraction) efrac = fEFraction[i];
164 if(fTime) time = fTime[i];
166 obj->SetCell(i,fCellNumber[i],fAmplitude[i],time,mclabel,efrac);
174 //___________________________________________________
175 void AliAODCaloCells::CreateContainer(Short_t nCells)
177 // function that creates container to store calorimeter cell data
189 fHGLG = new Bool_t[fNCells];
190 fCellNumber = new Short_t[fNCells];
191 fAmplitude = new Double32_t[fNCells];
192 fTime = new Double32_t[fNCells];
193 fMCLabel = new Int_t[fNCells];
194 fEFraction = new Double32_t[fNCells];
197 for(int i = 0;i<fNCells;++i)
201 fCellNumber[i] = -1 ;
208 //_____________________________________
209 void AliAODCaloCells::DeleteContainer()
211 // deletes allocated memory
219 delete[] fCellNumber;
252 //__________________________
253 void AliAODCaloCells::Sort()
255 // sort the cell array by cell number
257 Int_t *idxArray = new Int_t[fNCells];
258 TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
260 Bool_t *newHGLG = new Bool_t[fNCells];
261 Short_t *newIndex = new Short_t[fNCells];
262 Double32_t *newAmplitude = new Double32_t[fNCells];
264 Double32_t *newTime = 0;
265 Int_t *newMCLabel = 0 ;
266 Double32_t *newEFraction = 0 ;
267 if(fTime) newTime = new Double32_t[fNCells];
268 if(fMCLabel) newMCLabel = new Int_t[fNCells];
269 if(fEFraction) newEFraction = new Double32_t[fNCells];
271 for (Int_t i=0; i < fNCells; i++)
273 newHGLG[i] = fHGLG[idxArray[i]];
274 newIndex[i] = fCellNumber[idxArray[i]];
275 newAmplitude[i] = fAmplitude [idxArray[i]];
276 if(fTime) newTime[i] = fTime [idxArray[i]];
277 if(fMCLabel) newMCLabel[i] = fMCLabel [idxArray[i]];
278 if(fEFraction) newEFraction[i] = fEFraction[idxArray[i]];
282 delete [] fCellNumber;
283 delete [] fAmplitude;
286 delete [] fEFraction;
289 fCellNumber = newIndex;
290 fAmplitude = newAmplitude;
291 if(fTime) fTime = newTime;
292 if(fMCLabel) fMCLabel = newMCLabel;
293 if(fEFraction) fEFraction = newEFraction;
300 //________________________________________________________________________________________
301 Bool_t AliAODCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude,
302 Double32_t time, Int_t mclabel, Double32_t efrac, Bool_t isHG)
304 // Sets a cell at the given position
306 if (pos>=0 && pos < fNCells)
309 fCellNumber[pos] = cellNumber;
310 fAmplitude[pos] = amplitude;
312 // note: initialize (can't use memset for non-0 values)
313 // plus sizeof(Double32_t) is 0
315 fTime = new Double32_t[fNCells];
317 for( Int_t i = 0; i < fNCells; i++ )
321 fMCLabel = new Int_t[fNCells];
323 for( Int_t i = 0; i < fNCells; i++ )
327 fEFraction = new Double32_t[fNCells];
329 for( Int_t i = 0; i < fNCells; i++ )
334 fMCLabel[pos] = mclabel;
335 fEFraction[pos] = efrac;