]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/ESD/AliESDCaloCells.cxx
drawCorrelation macro adapted for Toy Model (MW)
[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];
60d77596 56 fMCLabel = new Int_t[fNCells];
77e93dc2 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];
60d77596 91 fMCLabel = new Int_t[fNCells];
f8785caa 92 fEFraction = 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));
60d77596 98 if(source.fMCLabel && fMCLabel) memcpy(fMCLabel, source.fMCLabel, fNCells*sizeof(Int_t));
77e93dc2 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
f8785caa 177 if (nCells <= 0)
178 {
e649177a 179 fNCells = 0;
180 return;
181 }
182
183 fNCells = nCells;
184
185 fCellNumber = new Short_t[fNCells];
c8fe2783 186 fAmplitude = new Double32_t[fNCells];
187 fTime = new Double32_t[fNCells];
60d77596 188 fMCLabel = new Int_t[fNCells];
77e93dc2 189 fEFraction = new Double32_t[fNCells];
190
191 // set to zero
192 for(int i = 0;i<fNCells;++i)
193 {
f8785caa 194 fAmplitude [i] = 0.;
195 fCellNumber[i] = -1 ;
196 fEFraction [i] = 0.;
197 fTime [i] = -1.;
198 fMCLabel [i] = -1 ;
c8fe2783 199 }
e649177a 200}
201
77e93dc2 202//_____________________________________
e649177a 203void AliESDCaloCells::DeleteContainer()
204{
205 // deletes allocated memory
206
207 if (fCellNumber)
208 {
209 delete[] fCellNumber;
210 fCellNumber = 0;
211 }
212
213 if (fAmplitude)
214 {
215 delete[] fAmplitude;
c8fe2783 216 fAmplitude = NULL;
e649177a 217 }
218
219 if (fTime)
220 {
221 delete[] fTime;
c8fe2783 222 fTime = NULL;
e649177a 223 }
c8fe2783 224
77e93dc2 225 if (fMCLabel)
226 {
227 delete[] fMCLabel;
228 fMCLabel = NULL;
229 }
230
231 if (fEFraction)
232 {
233 delete[] fEFraction;
234 fEFraction = NULL;
235 }
236
e649177a 237 fNCells = 0;
238 fIsSorted = kFALSE;
77e93dc2 239
e649177a 240}
241
77e93dc2 242//__________________________
e649177a 243void AliESDCaloCells::Sort()
244{
245 // sort the cell array by cell number
246
247 Int_t *idxArray = new Int_t[fNCells];
248 TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
249
77e93dc2 250 Short_t *newIndex = new Short_t[fNCells];
e649177a 251 Double32_t *newAmplitude = new Double32_t[fNCells];
c8fe2783 252 Double32_t *newTime = new Double32_t[fNCells];
f8785caa 253
60d77596 254 Int_t *newMCLabel = 0 ;
f8785caa 255 Double32_t *newEFraction = 0 ;
60d77596 256 if(fMCLabel) newMCLabel = new Int_t[fNCells];
f8785caa 257 if(fEFraction) newEFraction = new Double32_t[fNCells];
77e93dc2 258
259 for (Int_t i=0; i < fNCells; i++)
260 {
c8fe2783 261 newIndex[i] = fCellNumber[idxArray[i]];
77e93dc2 262 newAmplitude[i] = fAmplitude [idxArray[i]];
263 newTime[i] = fTime [idxArray[i]];
264 if(fMCLabel) newMCLabel[i] = fMCLabel [idxArray[i]];
265 if(fEFraction) newEFraction[i] = fEFraction[idxArray[i]];
e649177a 266 }
77e93dc2 267
e649177a 268 delete [] fCellNumber;
269 delete [] fAmplitude;
270 delete [] fTime;
77e93dc2 271 delete [] fMCLabel;
272 delete [] fEFraction;
c8fe2783 273
e649177a 274 fCellNumber = newIndex;
c8fe2783 275 fAmplitude = newAmplitude;
276 fTime = newTime;
77e93dc2 277 if(fMCLabel) fMCLabel = newMCLabel;
278 if(fEFraction) fEFraction = newEFraction;
e649177a 279
280 delete [] idxArray;
281
282 fIsSorted = kTRUE;
283}
284
77e93dc2 285//________________________________________________________________________________________
286Bool_t AliESDCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude,
60d77596 287 Double32_t time, Int_t mclabel, Double32_t efrac)
e649177a 288{
289 // Sets a cell at the given position
290
77e93dc2 291 if (pos>=0 && pos < fNCells)
292 {
e649177a 293 fCellNumber[pos] = cellNumber;
c8fe2783 294 fAmplitude[pos] = amplitude;
295 fTime[pos] = time;
77e93dc2 296
00c970e8 297 // note: initialize (can't use memset for non-0 values)
298 // plus sizeof(Double32_t) is 0
299 if(!fMCLabel){
60d77596 300 fMCLabel = new Int_t[fNCells];
00c970e8 301
302 for( Int_t i = 0; i < fNCells; i++ )
303 fMCLabel[i] = -1;
304 }
305 if(!fEFraction){
306 fEFraction = new Double32_t[fNCells];
307
308 for( Int_t i = 0; i < fNCells; i++ )
309 fEFraction[i] = 0;
310 }
c8fe2783 311
77e93dc2 312 fMCLabel[pos] = mclabel;
313 fEFraction[pos] = efrac;
314
e649177a 315 fIsSorted = kFALSE;
77e93dc2 316
e649177a 317 return kTRUE;
77e93dc2 318
e649177a 319 } else {
320 return kFALSE;
321 }
322}