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