adding control histograms to particle selection class
[u/mrichter/AliRoot.git] / STEER / ESD / AliESDCaloCells.cxx
CommitLineData
e649177a 1/**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
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//-------------------------------------------------------------------------
23
24#include "AliESDCaloCells.h"
25
26ClassImp(AliESDCaloCells)
27
77e93dc2 28//_____________________________________________________
e649177a 29AliESDCaloCells::AliESDCaloCells() :
77e93dc2 30 AliVCaloCells(), fNCells(0), fCellNumber(0),
31 fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
32 fIsSorted(kTRUE), fType(kUndef)
e649177a 33{
34 // default constructor
35}
77e93dc2 36//______________________________________________________________________________________
c8fe2783 37 AliESDCaloCells::AliESDCaloCells(const char* name, const char* title, VCells_t ttype) :
77e93dc2 38 AliVCaloCells(name, title), fNCells(0), fCellNumber(0),
39 fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
40 fIsSorted(kTRUE), fType(ttype)
c8fe2783 41{
42 // AliVCaloCells constructor
e649177a 43 }
44
77e93dc2 45//__________________________________________________________
e649177a 46AliESDCaloCells::AliESDCaloCells(const AliESDCaloCells& c) :
77e93dc2 47 AliVCaloCells(c), fNCells(c.fNCells), fCellNumber(0),
48 fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
49 fIsSorted(c.fIsSorted), fType(c.fType)
e649177a 50{
51 // copy constructor
52
c8fe2783 53 fCellNumber = new Short_t[fNCells];
54 fAmplitude = new Double32_t[fNCells];
41086670 55 fTime = new Double32_t[fNCells];
77e93dc2 56 fMCLabel = new Short_t[fNCells];
57 fEFraction = new Double32_t[fNCells];
58
59 for(Int_t i = 0; i < fNCells; i++)
60 {
c8fe2783 61 fCellNumber[i] = c.fCellNumber[i];
62 fAmplitude[i] = c.fAmplitude[i];
63 fTime[i] = c.fTime[i];
77e93dc2 64 if(c.fMCLabel) fMCLabel[i] = c.fMCLabel[i];
65 if(c.fEFraction)fEFraction[i] = c.fEFraction[i];
e649177a 66 }
67}
68
77e93dc2 69//__________________________________________________________________________
e649177a 70AliESDCaloCells & AliESDCaloCells::operator =(const AliESDCaloCells& source)
71{
72 // assignment operator
73
77e93dc2 74 if(this != &source)
75 {
80e4768f 76 AliVCaloCells::operator=(source);
77
77e93dc2 78 if(fNCells != source.fNCells)
79 {
80e4768f 80 delete [] fCellNumber;
81 delete [] fAmplitude;
82 delete [] fTime;
77e93dc2 83 delete [] fMCLabel;
84 delete [] fEFraction;
85
80e4768f 86 fNCells = source.fNCells;
77e93dc2 87
80e4768f 88 fCellNumber = new Short_t[fNCells];
77e93dc2 89 fAmplitude = new Double32_t[fNCells];
90 fTime = new Double32_t[fNCells];
91 fMCLabel = new Short_t[fNCells];
92 fTime = new Double32_t[fNCells];
80e4768f 93 }
80e4768f 94
77e93dc2 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(Short_t));
99 if(source.fEFraction && fEFraction) memcpy(fEFraction, source.fEFraction, fNCells*sizeof(Double32_t));
100
80e4768f 101 fIsSorted = source.fIsSorted;
102 fType = source.fType;
103
e649177a 104 }
105
106 return *this;
e649177a 107}
108
77e93dc2 109//____________________________________________
110void AliESDCaloCells::Copy(TObject &obj) const
111{
732a24fe 112 // this overwrites the virtual TOBject::Copy()
113 // to allow run time copying without casting
114 // in AliESDEvent
115
116 if(this==&obj)return;
117 AliESDCaloCells *robj = dynamic_cast<AliESDCaloCells*>(&obj);
118 if(!robj)return; // not an AliESDCaloCells
119 *robj = *this;
120
121}
122
77e93dc2 123//______________________________________________________________________
124AliVCaloCells* AliESDCaloCells::CopyCaloCells(Bool_t all = kTRUE) const
125{
ecff8f07 126 // copy the calo cells into a new object. If option all=FALSE, just the object type,
127 // for mixing
128
129 AliVCaloCells *obj = new AliESDCaloCells();
130
131 if(all){
132 obj->SetName (GetName()) ;
133 obj->SetTitle(GetTitle()) ;
134 obj->SetType (GetType()) ;
135
136 obj->SetNumberOfCells(fNCells);
137 for (Short_t i = 0; i < fNCells; i++)
77e93dc2 138 {
139 Int_t mclabel = -1;
140 if(fMCLabel) mclabel = fMCLabel[i];
141
142 Float_t efrac = 0.;
143 if(fEFraction) efrac = fEFraction[i];
144
145 obj->SetCell(i,fCellNumber[i],fAmplitude[i],fTime[i],mclabel,efrac);
146 }
ecff8f07 147 }
148
149 return obj;
150}
151
152
77e93dc2 153//_________________________________
e649177a 154AliESDCaloCells::~AliESDCaloCells()
155{
156 // destructor
157
158 DeleteContainer();
159}
160
77e93dc2 161//__________________________________________
8dd6eba0 162void AliESDCaloCells::Clear(const Option_t*)
163{
164 // clear
165
166 DeleteContainer();
167}
168
169
77e93dc2 170//___________________________________________________
e649177a 171void AliESDCaloCells::CreateContainer(Short_t nCells)
172{
173 // function that creates container to store calorimeter cell data
174
175 DeleteContainer();
176
177 if (nCells <= 0) {
178 fNCells = 0;
179 return;
180 }
181
182 fNCells = nCells;
183
184 fCellNumber = new Short_t[fNCells];
c8fe2783 185 fAmplitude = new Double32_t[fNCells];
186 fTime = new Double32_t[fNCells];
77e93dc2 187 fMCLabel = new Short_t[fNCells];
188 fEFraction = new Double32_t[fNCells];
189
190 // set to zero
191 for(int i = 0;i<fNCells;++i)
192 {
193 fAmplitude[i] = fCellNumber[i] = fEFraction[i] = 0 ;
194 fTime[i] = fMCLabel[i] = -1 ;
c8fe2783 195 }
e649177a 196}
197
77e93dc2 198//_____________________________________
e649177a 199void AliESDCaloCells::DeleteContainer()
200{
201 // deletes allocated memory
202
203 if (fCellNumber)
204 {
205 delete[] fCellNumber;
206 fCellNumber = 0;
207 }
208
209 if (fAmplitude)
210 {
211 delete[] fAmplitude;
c8fe2783 212 fAmplitude = NULL;
e649177a 213 }
214
215 if (fTime)
216 {
217 delete[] fTime;
c8fe2783 218 fTime = NULL;
e649177a 219 }
c8fe2783 220
77e93dc2 221 if (fMCLabel)
222 {
223 delete[] fMCLabel;
224 fMCLabel = NULL;
225 }
226
227 if (fEFraction)
228 {
229 delete[] fEFraction;
230 fEFraction = NULL;
231 }
232
e649177a 233 fNCells = 0;
234 fIsSorted = kFALSE;
77e93dc2 235
e649177a 236}
237
77e93dc2 238//__________________________
e649177a 239void AliESDCaloCells::Sort()
240{
241 // sort the cell array by cell number
242
243 Int_t *idxArray = new Int_t[fNCells];
244 TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
245
77e93dc2 246 Short_t *newIndex = new Short_t[fNCells];
e649177a 247 Double32_t *newAmplitude = new Double32_t[fNCells];
c8fe2783 248 Double32_t *newTime = new Double32_t[fNCells];
77e93dc2 249 Short_t *newMCLabel = new Short_t[fNCells];
250 Double32_t *newEFraction = new Double32_t[fNCells];
251
252 for (Int_t i=0; i < fNCells; i++)
253 {
c8fe2783 254 newIndex[i] = fCellNumber[idxArray[i]];
77e93dc2 255 newAmplitude[i] = fAmplitude [idxArray[i]];
256 newTime[i] = fTime [idxArray[i]];
257 if(fMCLabel) newMCLabel[i] = fMCLabel [idxArray[i]];
258 if(fEFraction) newEFraction[i] = fEFraction[idxArray[i]];
e649177a 259 }
77e93dc2 260
e649177a 261 delete [] fCellNumber;
262 delete [] fAmplitude;
263 delete [] fTime;
77e93dc2 264 delete [] fMCLabel;
265 delete [] fEFraction;
c8fe2783 266
e649177a 267 fCellNumber = newIndex;
c8fe2783 268 fAmplitude = newAmplitude;
269 fTime = newTime;
77e93dc2 270 if(fMCLabel) fMCLabel = newMCLabel;
271 if(fEFraction) fEFraction = newEFraction;
e649177a 272
273 delete [] idxArray;
274
275 fIsSorted = kTRUE;
276}
277
77e93dc2 278//________________________________________________________________________________________
279Bool_t AliESDCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude,
280 Double32_t time, Short_t mclabel, Double32_t efrac)
e649177a 281{
282 // Sets a cell at the given position
283
77e93dc2 284 if (pos>=0 && pos < fNCells)
285 {
e649177a 286 fCellNumber[pos] = cellNumber;
c8fe2783 287 fAmplitude[pos] = amplitude;
288 fTime[pos] = time;
77e93dc2 289
290 if(!fMCLabel) fMCLabel = new Short_t[fNCells];
291 if(!fEFraction) fEFraction = new Double32_t[fNCells];
c8fe2783 292
77e93dc2 293 fMCLabel[pos] = mclabel;
294 fEFraction[pos] = efrac;
295
e649177a 296 fIsSorted = kFALSE;
77e93dc2 297
e649177a 298 return kTRUE;
77e93dc2 299
e649177a 300 } else {
301 return kFALSE;
302 }
303}