Using TArrayI instead of TArrayS for the labels and track indexes (Gustavo)
[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),
fe12e09c 37 fDigitAmplitude(0x0),
38 fDigitTime(0x0),
8ada0ffe 39 fDigitIndex(0x0),
40 fEnergy(0),
41 fDispersion(0),
42 fChi2(0),
43 fM20(0),
44 fM02(0),
45 fM11(0),
46 fEmcCpvDistance(1024),
47 fDistToBadChannel(1024),
48 fID(0),
49 fNExMax(0),
50 fClusterType(kUndef)
85c60a8e 51{
52 //
53 // The default ESD constructor
54 //
55 fGlobalPos[0] = fGlobalPos[1] = fGlobalPos[2] = 0.;
56 for(Int_t i=0; i<AliPID::kSPECIESN; i++) fPID[i] = 0.;
57}
58
59//_______________________________________________________________________
60AliESDCaloCluster::AliESDCaloCluster(const AliESDCaloCluster& clus) :
61 TObject(clus),
4dd59c4a 62 fTracksMatched(clus.fTracksMatched?new TArrayI(*clus.fTracksMatched):0x0),
63 fLabels(clus.fLabels?new TArrayI(*clus.fLabels):0x0),
8ada0ffe 64 fDigitAmplitude(clus.fDigitAmplitude?new TArrayS(*clus.fDigitAmplitude):0x0),
65 fDigitTime(clus.fDigitTime?new TArrayS(*clus.fDigitTime):0x0),
66 fDigitIndex(clus.fDigitIndex?new TArrayS(*clus.fDigitIndex):0x0),
85c60a8e 67 fEnergy(clus.fEnergy),
68 fDispersion(clus.fDispersion),
69 fChi2(clus.fChi2),
e3e93796 70 fM20(clus.fM20),
71 fM02(clus.fM02),
e0af7ed2 72 fM11(clus.fM11),
e3e93796 73 fEmcCpvDistance(clus.fEmcCpvDistance),
45636e1b 74 fDistToBadChannel(clus.fDistToBadChannel),
8ada0ffe 75 fID(clus.fID),
76 fNExMax(clus.fNExMax),
77 fClusterType(clus.fClusterType)
85c60a8e 78{
79 //
80 // The copy constructor
81 //
82 fGlobalPos[0] = clus.fGlobalPos[0];
83 fGlobalPos[1] = clus.fGlobalPos[1];
84 fGlobalPos[2] = clus.fGlobalPos[2];
85
86 for(Int_t i=0; i<AliPID::kSPECIESN; i++) fPID[i] = clus.fPID[i];
87
85c60a8e 88}
89
fe12e09c 90//_______________________________________________________________________
91AliESDCaloCluster &AliESDCaloCluster::operator=(const AliESDCaloCluster& source)
92{
93 // assignment operator
94
95 if(&source == this) return *this;
8ada0ffe 96 TObject::operator=(source);
97
98 fGlobalPos[0] = source.fGlobalPos[0];
99 fGlobalPos[1] = source.fGlobalPos[1];
100 fGlobalPos[2] = source.fGlobalPos[2];
101
fe12e09c 102
fe12e09c 103 fEnergy = source.fEnergy;
104 fDispersion = source.fDispersion;
105 fChi2 = source.fChi2;
fe12e09c 106 fM20 = source.fM20;
107 fM02 = source.fM02;
108 fM11 = source.fM11;
fe12e09c 109 fEmcCpvDistance = source.fEmcCpvDistance;
45636e1b 110 fDistToBadChannel = source.fDistToBadChannel ;
fe12e09c 111 for(Int_t i=0; i<AliPID::kSPECIESN; i++) fPID[i] = source.fPID[i];
8ada0ffe 112 fID = source.fID;
fe12e09c 113
8ada0ffe 114 delete fTracksMatched;
4dd59c4a 115 fTracksMatched = source.fTracksMatched?new TArrayI(*source.fTracksMatched):0x0;
8ada0ffe 116 delete fLabels;
4dd59c4a 117 fLabels = source.fLabels?new TArrayI(*source.fLabels):0x0;
8ada0ffe 118
119 delete fDigitAmplitude;
a934c866 120 fDigitAmplitude = source.fDigitAmplitude?new TArrayS(*source.fDigitAmplitude):0x0;
8ada0ffe 121
122 delete fDigitTime;
a934c866 123 fDigitTime = source.fDigitTime?new TArrayS(*source.fDigitTime):0x0;
8ada0ffe 124
125 delete fDigitIndex;
a934c866 126 fDigitIndex = source.fDigitIndex?new TArrayS(*source.fDigitIndex):0x0;
fe12e09c 127
8ada0ffe 128 fNExMax = source.fNExMax;
129 fClusterType = source.fClusterType;
130
fe12e09c 131 return *this;
132
133}
134
85c60a8e 135
136//_______________________________________________________________________
137AliESDCaloCluster::~AliESDCaloCluster(){
138 //
5efdec54 139 // This is destructor according Coding Conventions
85c60a8e 140 //
5efdec54 141 delete fTracksMatched;
142 delete fLabels;
143 delete fDigitAmplitude;
144 delete fDigitTime;
145 delete fDigitIndex;
85c60a8e 146}
147
148//_______________________________________________________________________
149void AliESDCaloCluster::SetPid(const Float_t *p) {
150 // Sets the probability of each particle type
151 // Copied from AliESDtrack SetPIDValues
152 // This function copies "n" PID weights from "scr" to "dest"
153 // and normalizes their sum to 1 thus producing conditional
154 // probabilities.
155 // The negative weights are set to 0.
156 // In case all the weights are non-positive they are replaced by
157 // uniform probabilities
158
159 Int_t n = AliPID::kSPECIESN;
160
161 Float_t uniform = 1./(Float_t)n;
162
163 Float_t sum = 0;
164 for (Int_t i=0; i<n; i++)
165 if (p[i]>=0) {
166 sum+=p[i];
167 fPID[i] = p[i];
168 }
169 else {
170 fPID[i] = 0;
171 }
172
173 if(sum>0)
174 for (Int_t i=0; i<n; i++) fPID[i] /= sum;
175 else
176 for (Int_t i=0; i<n; i++) fPID[i] = uniform;
177
178}
bab0b5f0 179
180//_______________________________________________________________________
5efdec54 181void AliESDCaloCluster::GetMomentum(TLorentzVector& p, Double_t *vertex ) {
bab0b5f0 182 // Returns TLorentzVector with momentum of the cluster. Only valid for clusters
183 // identified as photons or pi0 (overlapped gamma) produced on the vertex
5efdec54 184 //Vertex can be recovered with esd pointer doing:
185 //" Double_t vertex[3] ; esd->GetVertex()->GetXYZ(vertex) ; "
186
187 if(vertex){//calculate direction from vertex
188 fGlobalPos[0]-=vertex[0];
189 fGlobalPos[1]-=vertex[1];
190 fGlobalPos[2]-=vertex[2];
191 }
bab0b5f0 192
193 Double_t r = TMath::Sqrt(fGlobalPos[0]*fGlobalPos[0]+
194 fGlobalPos[1]*fGlobalPos[1]+
195 fGlobalPos[2]*fGlobalPos[2] ) ;
196
197 p.SetPxPyPzE( fEnergy*fGlobalPos[0]/r, fEnergy*fGlobalPos[1]/r, fEnergy*fGlobalPos[2]/r, fEnergy) ;
198
199}
cb8cf003 200// Sep 7, 2007
201Int_t AliESDCaloCluster::GetTrueDigitAmplitude(Int_t i, Double_t cc)
202{
203 static Int_t amp=0; // amp is integer now
204 amp = 0;
205 if(i>=0 && i<fDigitAmplitude->GetSize() && cc>0.0) {
206 // true formula
207 amp = Int_t(Double_t(fDigitAmplitude->At(i))/500./cc+0.5);
208 }
209 return amp;
210}
211
212Double_t AliESDCaloCluster::GetTrueDigitEnergy(Int_t i, Double_t cc)
213{
214 return Double_t(GetTrueDigitAmplitude(i,cc)) * cc;
215}
216
217Double_t AliESDCaloCluster::GetRecalibratedDigitEnergy(Int_t i, Double_t ccOld, Double_t ccNew)
218{
219 return Double_t(GetTrueDigitAmplitude(i,ccOld)) * ccNew;
220}