]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/ESD/AliESDCaloCluster.cxx
small fix for the copy constructor
[u/mrichter/AliRoot.git] / STEER / ESD / AliESDCaloCluster.cxx
CommitLineData
85c60a8e 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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/* $Log $ */
18
19//-----------------------------------------------------------------
20// Implementation of the ESD Calorimeter cluster class
21// ESD = Event Summary Data
22// This is the class to deal with during the phisics analysis of data
23//
24// J.L. Klay (LLNL)
25//-----------------------------------------------------------------
26
bab0b5f0 27#include <TLorentzVector.h>
85c60a8e 28#include "AliESDCaloCluster.h"
29
30ClassImp(AliESDCaloCluster)
31
32//_______________________________________________________________________
33AliESDCaloCluster::AliESDCaloCluster() :
c8fe2783 34 AliVCluster(),
5efdec54 35 fTracksMatched(0x0),
36 fLabels(0x0),
e649177a 37 fNCells(0),
38 fCellsAbsId(0x0),
39 fCellsAmpFraction(0x0),
8ada0ffe 40 fEnergy(0),
41 fDispersion(0),
42 fChi2(0),
43 fM20(0),
44 fM02(0),
8ada0ffe 45 fEmcCpvDistance(1024),
f1cedef3 46 fTrackDx(1024),fTrackDz(1024),
8ada0ffe 47 fDistToBadChannel(1024),
48 fID(0),
49 fNExMax(0),
7eff06f2 50 fClusterType(kUndef),
51 fTOF(0.),
52 fMCEnergyFraction(0.)
85c60a8e 53{
54 //
55 // The default ESD constructor
56 //
57 fGlobalPos[0] = fGlobalPos[1] = fGlobalPos[2] = 0.;
00a38d07 58 for(Int_t i=0; i<AliPID::kSPECIESCN; i++) fPID[i] = 0.;
85c60a8e 59}
60
61//_______________________________________________________________________
62AliESDCaloCluster::AliESDCaloCluster(const AliESDCaloCluster& clus) :
c8fe2783 63 AliVCluster(clus),
4dd59c4a 64 fTracksMatched(clus.fTracksMatched?new TArrayI(*clus.fTracksMatched):0x0),
65 fLabels(clus.fLabels?new TArrayI(*clus.fLabels):0x0),
e649177a 66 fNCells(clus.fNCells),
67 fCellsAbsId(),
68 fCellsAmpFraction(),
85c60a8e 69 fEnergy(clus.fEnergy),
70 fDispersion(clus.fDispersion),
71 fChi2(clus.fChi2),
e3e93796 72 fM20(clus.fM20),
73 fM02(clus.fM02),
e3e93796 74 fEmcCpvDistance(clus.fEmcCpvDistance),
f1cedef3 75 fTrackDx(clus.fTrackDx),
76 fTrackDz(clus.fTrackDz),
45636e1b 77 fDistToBadChannel(clus.fDistToBadChannel),
8ada0ffe 78 fID(clus.fID),
79 fNExMax(clus.fNExMax),
78902954 80 fClusterType(clus.fClusterType),
7eff06f2 81 fTOF(clus.fTOF),
d56f6973 82 fMCEnergyFraction(clus.fMCEnergyFraction)
85c60a8e 83{
84 //
85 // The copy constructor
86 //
87 fGlobalPos[0] = clus.fGlobalPos[0];
88 fGlobalPos[1] = clus.fGlobalPos[1];
89 fGlobalPos[2] = clus.fGlobalPos[2];
90
00a38d07 91 for(Int_t i=0; i<AliPID::kSPECIESCN; i++) fPID[i] = clus.fPID[i];
85c60a8e 92
e649177a 93 if (clus.fNCells > 0) {
94
95 if(clus.fCellsAbsId){
96 fCellsAbsId = new UShort_t[clus.fNCells];
97 for (Int_t i=0; i<clus.fNCells; i++)
98 fCellsAbsId[i]=clus.fCellsAbsId[i];
99 }
100
101 if(clus.fCellsAmpFraction){
102 fCellsAmpFraction = new Double32_t[clus.fNCells];
103 for (Int_t i=0; i<clus.fNCells; i++)
104 fCellsAmpFraction[i]=clus.fCellsAmpFraction[i];
105 }
106
107 }
108
85c60a8e 109}
110
fe12e09c 111//_______________________________________________________________________
112AliESDCaloCluster &AliESDCaloCluster::operator=(const AliESDCaloCluster& source)
113{
114 // assignment operator
115
116 if(&source == this) return *this;
c8fe2783 117 AliVCluster::operator=(source);
8ada0ffe 118 fGlobalPos[0] = source.fGlobalPos[0];
119 fGlobalPos[1] = source.fGlobalPos[1];
120 fGlobalPos[2] = source.fGlobalPos[2];
121
fe12e09c 122 fEnergy = source.fEnergy;
123 fDispersion = source.fDispersion;
124 fChi2 = source.fChi2;
fe12e09c 125 fM20 = source.fM20;
126 fM02 = source.fM02;
fe12e09c 127 fEmcCpvDistance = source.fEmcCpvDistance;
f1cedef3 128 fTrackDx= source.fTrackDx ;
129 fTrackDz= source.fTrackDz ;
45636e1b 130 fDistToBadChannel = source.fDistToBadChannel ;
00a38d07 131 for(Int_t i=0; i<AliPID::kSPECIESCN; i++) fPID[i] = source.fPID[i];
8ada0ffe 132 fID = source.fID;
fe12e09c 133
732a24fe 134 fNCells= source.fNCells;
135
e649177a 136 if (source.fNCells > 0) {
e649177a 137 if(source.fCellsAbsId){
85005d58 138 if(fNCells != source.fNCells||!fCellsAbsId){
139 if(fCellsAbsId)delete [] fCellsAbsId;
732a24fe 140 fCellsAbsId = new UShort_t[source.fNCells];
141 }
85005d58 142 for (Int_t i=0; i<source.fNCells; i++){
e649177a 143 fCellsAbsId[i]=source.fCellsAbsId[i];
85005d58 144 }
e649177a 145 }
146
147 if(source.fCellsAmpFraction){
85005d58 148 if(fNCells != source.fNCells||!fCellsAmpFraction){
149 if(fCellsAmpFraction) delete [] fCellsAmpFraction;
732a24fe 150 fCellsAmpFraction = new Double32_t[source.fNCells];
151 }
e649177a 152 for (Int_t i=0; i<source.fNCells; i++)
153 fCellsAmpFraction[i]=source.fCellsAmpFraction[i];
732a24fe 154 }
e649177a 155 }
156
157 fNExMax = source.fNExMax;
158 fClusterType = source.fClusterType;
78902954 159 fTOF = source.fTOF;
e649177a 160
161 //not in use
732a24fe 162 if(source.fTracksMatched){
163 // assign or copy construct
85005d58 164 if(fTracksMatched){
165 *fTracksMatched = *source.fTracksMatched;
166 }
732a24fe 167 else fTracksMatched = new TArrayI(*source.fTracksMatched);
168 }
169 else{
85005d58 170 if(fTracksMatched)delete fTracksMatched;
732a24fe 171 fTracksMatched = 0;
172 }
173
174 if(source.fLabels){
175 // assign or copy construct
85005d58 176 if(fLabels){
177 *fLabels = *source.fLabels;
178 }
732a24fe 179 else fLabels = new TArrayI(*source.fLabels);
180 }
181 else{
85005d58 182 if(fLabels)delete fLabels;
732a24fe 183 fLabels = 0;
184 }
185
7eff06f2 186 fMCEnergyFraction = source.fMCEnergyFraction;
e649177a 187
fe12e09c 188 return *this;
189
190}
191
7a54a755 192//_______________________________________________________________________
732a24fe 193void AliESDCaloCluster::Copy(TObject &obj) const {
194
195 // this overwrites the virtual TOBject::Copy()
196 // to allow run time copying without casting
197 // in AliESDEvent
198
199 if(this==&obj)return;
200 AliESDCaloCluster *robj = dynamic_cast<AliESDCaloCluster*>(&obj);
201 if(!robj)return; // not an AliESDCluster
202 *robj = *this;
203
204}
85c60a8e 205
206//_______________________________________________________________________
207AliESDCaloCluster::~AliESDCaloCluster(){
208 //
5efdec54 209 // This is destructor according Coding Conventions
85c60a8e 210 //
85005d58 211 if(fTracksMatched)delete fTracksMatched;fTracksMatched = 0;
212 if(fLabels) delete fLabels; fLabels = 0;
85005d58 213 if(fCellsAmpFraction){ delete[] fCellsAmpFraction; fCellsAmpFraction=0;}
214 if(fCellsAbsId){ delete[] fCellsAbsId; fCellsAbsId = 0;}
85c60a8e 215}
216
8dd6eba0 217//_______________________________________________________________________
218void AliESDCaloCluster::Clear(const Option_t*){
219 //
220 // This is destructor according Coding Conventions
221 //
222 if(fTracksMatched)delete fTracksMatched;fTracksMatched = 0;
223 if(fLabels) delete fLabels; fLabels = 0;
224 if(fCellsAmpFraction){ delete[] fCellsAmpFraction; fCellsAmpFraction=0;}
225 if(fCellsAbsId){ delete[] fCellsAbsId; fCellsAbsId = 0;}
226}
227
228
85c60a8e 229//_______________________________________________________________________
c8fe2783 230void AliESDCaloCluster::SetPID(const Float_t *p) {
85c60a8e 231 // Sets the probability of each particle type
232 // Copied from AliESDtrack SetPIDValues
233 // This function copies "n" PID weights from "scr" to "dest"
234 // and normalizes their sum to 1 thus producing conditional
235 // probabilities.
236 // The negative weights are set to 0.
237 // In case all the weights are non-positive they are replaced by
238 // uniform probabilities
239
00a38d07 240 Int_t n = AliPID::kSPECIESCN;
85c60a8e 241
242 Float_t uniform = 1./(Float_t)n;
243
244 Float_t sum = 0;
245 for (Int_t i=0; i<n; i++)
246 if (p[i]>=0) {
247 sum+=p[i];
248 fPID[i] = p[i];
249 }
250 else {
251 fPID[i] = 0;
252 }
253
254 if(sum>0)
255 for (Int_t i=0; i<n; i++) fPID[i] /= sum;
256 else
257 for (Int_t i=0; i<n; i++) fPID[i] = uniform;
258
259}
bab0b5f0 260
261//_______________________________________________________________________
5efdec54 262void AliESDCaloCluster::GetMomentum(TLorentzVector& p, Double_t *vertex ) {
bab0b5f0 263 // Returns TLorentzVector with momentum of the cluster. Only valid for clusters
264 // identified as photons or pi0 (overlapped gamma) produced on the vertex
5efdec54 265 //Vertex can be recovered with esd pointer doing:
266 //" Double_t vertex[3] ; esd->GetVertex()->GetXYZ(vertex) ; "
267
c8fe2783 268 Double32_t pos[3]={ fGlobalPos[0], fGlobalPos[1], fGlobalPos[2]};
269 if(vertex){//calculate direction from vertex
270 pos[0]-=vertex[0];
271 pos[1]-=vertex[1];
272 pos[2]-=vertex[2];
273 }
274
275 Double_t r = TMath::Sqrt(pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2] ) ;
276
277 p.SetPxPyPzE( fEnergy*pos[0]/r, fEnergy*pos[1]/r, fEnergy*pos[2]/r, fEnergy) ;
bab0b5f0 278}
ed712271 279
280//_______________________________________________________________________
281void AliESDCaloCluster::SetCellsAbsId(UShort_t *array)
282{
283 // Set the array of cell absId numbers
c8fe2783 284 if (fNCells) {
285 fCellsAbsId = new UShort_t[fNCells];
286 for (Int_t i = 0; i < fNCells; i++) fCellsAbsId[i] = array[i];
287 }
ed712271 288}
289
290//_______________________________________________________________________
291void AliESDCaloCluster::SetCellsAmplitudeFraction(Double32_t *array)
292{
c8fe2783 293 // Set the array of cell amplitude fraction
294 if (fNCells) {
295 fCellsAmpFraction = new Double32_t[fNCells];
296 for (Int_t i = 0; i < fNCells; i++) fCellsAmpFraction[i] = array[i];
297 }
ed712271 298}
c8fe2783 299
300//______________________________________________________________________________
301void AliESDCaloCluster::SetPosition(Float_t *x)
302{
303 // set the position
304
305 if (x) {
306 fGlobalPos[0] = x[0];
307 fGlobalPos[1] = x[1];
308 fGlobalPos[2] = x[2];
309 } else {
310
311 fGlobalPos[0] = -999.;
312 fGlobalPos[1] = -999.;
313 fGlobalPos[2] = -999.;
314 }
315}
316
317