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), 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), 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), 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];
67 //________________________________________________________________________
68 AliAODCaloCells& AliAODCaloCells::operator=(const AliAODCaloCells& source)
70 // Assignment operator
73 AliVCaloCells::operator=(source);
75 if(fNCells != source.fNCells)
77 delete [] fCellNumber;
83 fNCells = source.fNCells;
85 fCellNumber = new Short_t[fNCells];
86 fAmplitude = new Double32_t[fNCells];
87 fTime = new Double32_t[fNCells];
88 fMCLabel = new Int_t[fNCells];
89 fEFraction = new Double32_t[fNCells];
92 memcpy(fCellNumber,source.fCellNumber, fNCells*sizeof(Short_t));
93 memcpy(fAmplitude, source.fAmplitude, fNCells*sizeof(Double32_t));
94 if(source.fTime && fTime) memcpy(fTime, source.fTime, fNCells*sizeof(Double32_t));
95 if(source.fMCLabel && fMCLabel) memcpy(fMCLabel, source.fMCLabel, fNCells*sizeof(Int_t));
96 if(source.fEFraction && fEFraction) memcpy(fEFraction, source.fEFraction, fNCells*sizeof(Double32_t));
98 fIsSorted = source.fIsSorted;
106 //_________________________________
107 AliAODCaloCells::~AliAODCaloCells()
114 void AliAODCaloCells::Clear(const Option_t*)
121 void AliAODCaloCells::Copy(TObject &obj) const
124 // this overwrites the virtual TOBject::Copy()
125 // to allow run time copying without casting
128 if(this==&obj)return;
129 AliAODCaloCells *robj = dynamic_cast<AliAODCaloCells*>(&obj);
130 if(!robj)return; // not an AliAODCaloCells
135 //______________________________________________________________________
136 AliVCaloCells *AliAODCaloCells::CopyCaloCells(Bool_t all = kTRUE) const
139 // copy the calo cells into a new object. If option all=FALSE, just the object type,
142 AliVCaloCells *obj = new AliAODCaloCells();
145 obj->SetName (GetName()) ;
146 obj->SetTitle(GetTitle()) ;
147 obj->SetType (GetType()) ;
149 obj->SetNumberOfCells(fNCells);
150 for (Short_t i = 0; i < fNCells; i++)
153 if(fMCLabel) mclabel = fMCLabel[i];
156 if(fEFraction) efrac = fEFraction[i];
159 if(fTime) time = fTime[i];
161 obj->SetCell(i,fCellNumber[i],fAmplitude[i],time,mclabel,efrac);
169 //___________________________________________________
170 void AliAODCaloCells::CreateContainer(Short_t nCells)
172 // function that creates container to store calorimeter cell data
184 fCellNumber = new Short_t[fNCells];
185 fAmplitude = new Double32_t[fNCells];
186 fTime = new Double32_t[fNCells];
187 fMCLabel = new Int_t[fNCells];
188 fEFraction = new Double32_t[fNCells];
191 for(int i = 0;i<fNCells;++i)
194 fCellNumber[i] = -1 ;
201 //_____________________________________
202 void AliAODCaloCells::DeleteContainer()
204 // deletes allocated memory
208 delete[] fCellNumber;
241 //__________________________
242 void AliAODCaloCells::Sort()
244 // sort the cell array by cell number
246 Int_t *idxArray = new Int_t[fNCells];
247 TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
249 Short_t *newIndex = new Short_t[fNCells];
250 Double32_t *newAmplitude = new Double32_t[fNCells];
252 Double32_t *newTime = 0;
253 Int_t *newMCLabel = 0 ;
254 Double32_t *newEFraction = 0 ;
255 if(fTime) newTime = new Double32_t[fNCells];
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 if(fTime) 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;
276 if(fTime) fTime = newTime;
277 if(fMCLabel) fMCLabel = newMCLabel;
278 if(fEFraction) fEFraction = newEFraction;
285 //________________________________________________________________________________________
286 Bool_t AliAODCaloCells::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;
296 // note: initialize (can't use memset for non-0 values)
297 // plus sizeof(Double32_t) is 0
299 fTime = new Double32_t[fNCells];
301 for( Int_t i = 0; i < fNCells; i++ )
305 fMCLabel = new Int_t[fNCells];
307 for( Int_t i = 0; i < fNCells; i++ )
311 fEFraction = new Double32_t[fNCells];
313 for( Int_t i = 0; i < fNCells; i++ )
318 fMCLabel[pos] = mclabel;
319 fEFraction[pos] = efrac;