Update master to aliroot
[u/mrichter/AliRoot.git] / STEER / AOD / AliAODCaloCluster.cxx
CommitLineData
fa86343a 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// AOD calorimeter cluster class (for PHOS and EMCAL)
20// Author: Markus Oldenburg, CERN
21//-------------------------------------------------------------------------
22
78902954 23#include <TLorentzVector.h>
fa86343a 24#include "AliAODCaloCluster.h"
25
26ClassImp(AliAODCaloCluster)
27
28//______________________________________________________________________________
29AliAODCaloCluster::AliAODCaloCluster() :
30 AliAODCluster(),
31 fDistToBadChannel(-999.),
32 fDispersion(-1),
33 fM20(0.),
fa86343a 34 fM02(0.),
fa86343a 35 fEmcCpvDistance(-999.),
d1388fe9 36 fTrackDx(-999),
37 fTrackDz(-999),
78902954 38 fNExMax(0),
39 fTOF(0.),
619b4b09 40 fCoreEnergy(0.),
fa86343a 41 fTracksMatched(),
e649177a 42 fNCells(0),
341952b8 43 fCellsAbsId(0x0),
44 fCellsAmpFraction(0x0)
fa86343a 45{
46 // default constructor
47
48}
49
50//______________________________________________________________________________
51AliAODCaloCluster::AliAODCaloCluster(Int_t id,
52 UInt_t nLabel,
53 Int_t *label,
54 Double_t energy,
55 Double_t x[3],
83dd7da3 56 Double_t pid[13],
fa86343a 57 Char_t ttype,
58 UInt_t selectInfo) :
59 AliAODCluster(id, nLabel, label, energy, x, pid, ttype, selectInfo),
60 fDistToBadChannel(-999.),
61 fDispersion(-1),
62 fM20(0.),
fa86343a 63 fM02(0.),
fa86343a 64 fEmcCpvDistance(-999.),
d1388fe9 65 fTrackDx(-999),
66 fTrackDz(-999),
fa86343a 67 fNExMax(0),
78902954 68 fTOF(0.),
619b4b09 69 fCoreEnergy(0.),
fa86343a 70 fTracksMatched(),
e649177a 71 fNCells(0),
341952b8 72 fCellsAbsId(0x0),
73 fCellsAmpFraction(0x0)
fa86343a 74{
75 // constructor
76
77}
78
79//______________________________________________________________________________
80AliAODCaloCluster::AliAODCaloCluster(Int_t id,
81 UInt_t nLabel,
82 Int_t *label,
83 Float_t energy,
84 Float_t x[3],
83dd7da3 85 Float_t pid[13],
fa86343a 86 Char_t ttype,
87 UInt_t selectInfo) :
88 AliAODCluster(id, nLabel, label, energy, x, pid, ttype, selectInfo),
89 fDistToBadChannel(-999.),
90 fDispersion(-1),
91 fM20(0.),
fa86343a 92 fM02(0.),
fa86343a 93 fEmcCpvDistance(-999.),
d1388fe9 94 fTrackDx(-999),
95 fTrackDz(-999),
fa86343a 96 fNExMax(0),
78902954 97 fTOF(0.),
619b4b09 98 fCoreEnergy(0.),
fa86343a 99 fTracksMatched(),
e649177a 100 fNCells(0),
341952b8 101 fCellsAbsId(0x0),
102 fCellsAmpFraction(0x0)
fa86343a 103{
104 // constructor
105}
106
107
108//______________________________________________________________________________
109AliAODCaloCluster::~AliAODCaloCluster()
110{
111 // destructor
e649177a 112 if(fCellsAmpFraction) delete[] fCellsAmpFraction; fCellsAmpFraction=0;
8dd6eba0 113 if(fCellsAbsId) delete[] fCellsAbsId; fCellsAbsId = 0;
fa86343a 114}
115
8dd6eba0 116//______________________________________________________________________________
117void AliAODCaloCluster::Clear(const Option_t*)
118{
119 // clear
120 RemoveLabel();
121 if(fCellsAmpFraction) delete[] fCellsAmpFraction; fCellsAmpFraction=0;
122 if(fCellsAbsId) delete[] fCellsAbsId; fCellsAbsId = 0;
123}
fa86343a 124
125//______________________________________________________________________________
126AliAODCaloCluster::AliAODCaloCluster(const AliAODCaloCluster& clus) :
127 AliAODCluster(clus),
128 fDistToBadChannel(clus.fDistToBadChannel),
129 fDispersion(clus.fDispersion),
130 fM20(clus.fM20),
fa86343a 131 fM02(clus.fM02),
fa86343a 132 fEmcCpvDistance(clus.fEmcCpvDistance),
d1388fe9 133 fTrackDx(clus.fTrackDx),
134 fTrackDz(clus.fTrackDz),
fa86343a 135 fNExMax(clus.fNExMax),
78902954 136 fTOF(clus.fTOF),
619b4b09 137 fCoreEnergy(clus.fCoreEnergy),
fa86343a 138 fTracksMatched(clus.fTracksMatched),
e649177a 139 fNCells(clus.fNCells),
341952b8 140 fCellsAbsId(0x0),
141 fCellsAmpFraction(0x0)
fa86343a 142{
143 // Copy constructor
e649177a 144
145 if (clus.fNCells > 0) {
146
147 if(clus.fCellsAbsId){
148 fCellsAbsId = new UShort_t[clus.fNCells];
149 for (Int_t i=0; i<clus.fNCells; i++)
d1388fe9 150 fCellsAbsId[i]=clus.fCellsAbsId[i];
e649177a 151 }
152
153 if(clus.fCellsAmpFraction){
154 fCellsAmpFraction = new Double32_t[clus.fNCells];
155 for (Int_t i=0; i<clus.fNCells; i++)
d1388fe9 156 fCellsAmpFraction[i]=clus.fCellsAmpFraction[i];
e649177a 157 }
158
159 }
160
fa86343a 161}
162
163//______________________________________________________________________________
164AliAODCaloCluster& AliAODCaloCluster::operator=(const AliAODCaloCluster& clus)
165{
166 // Assignment operator
167 if(this!=&clus) {
168
169 AliAODCluster::operator=(clus);
170
171 fDistToBadChannel = clus.fDistToBadChannel;
172 fDispersion = clus.fDispersion;
173 fM20 = clus.fM20;
fa86343a 174 fM02 = clus.fM02;
fa86343a 175 fEmcCpvDistance = clus.fEmcCpvDistance;
d1388fe9 176 fTrackDx=clus.fTrackDx;
177 fTrackDz=clus.fTrackDz;
fa86343a 178 fNExMax = clus.fNExMax;
78902954 179 fTOF = clus.fTOF;
619b4b09 180 fCoreEnergy = clus.fCoreEnergy;
fa86343a 181 fTracksMatched = clus.fTracksMatched;
e649177a 182
183 fNCells= clus. fNCells;
341952b8 184 // delete anyway
185 if(fCellsAbsId)delete [] fCellsAbsId;
186 if(fCellsAmpFraction)delete [] fCellsAmpFraction;
187
e649177a 188 if (clus.fNCells > 0) {
189
190 if(clus.fCellsAbsId){
191 fCellsAbsId = new UShort_t[clus.fNCells];
192 for (Int_t i=0; i<clus.fNCells; i++)
193 fCellsAbsId[i]=clus.fCellsAbsId[i];
194 }
195
196 if(clus.fCellsAmpFraction){
197 fCellsAmpFraction = new Double32_t[clus.fNCells];
198 for (Int_t i=0; i<clus.fNCells; i++)
199 fCellsAmpFraction[i]=clus.fCellsAmpFraction[i];
200 }
201
202 }
203
fa86343a 204 }
205
206 return *this;
207}
208
209//_______________________________________________________________________
210Bool_t AliAODCaloCluster::HasTrackMatched(TObject *trk) const
211{
212 // Checks if the given track contributed to this cluster.
213
214 TRefArrayIter iter(&fTracksMatched);
215 while (TObject *track = iter.Next()) {
216 if (trk == track) return kTRUE;
217 }
218 return kFALSE;
219}
78902954 220
221//_______________________________________________________________________
38dbf8ce 222void AliAODCaloCluster::GetMomentum(TLorentzVector& p, Double_t *vertex ) const {
78902954 223 // Returns TLorentzVector with momentum of the cluster. Only valid for clusters
224 // identified as photons or pi0 (overlapped gamma) produced on the vertex
225 //Vertex can be recovered with esd pointer doing:
226 //" Double_t vertex[3] ; esd->GetVertex()->GetXYZ(vertex) ; "
227
228 Double32_t energy = E();
c8fe2783 229 Float_t pos[3];
78902954 230 GetPosition(pos);
231
232 if(vertex){//calculate direction from vertex
233 pos[0]-=vertex[0];
234 pos[1]-=vertex[1];
235 pos[2]-=vertex[2];
236 }
237
238 Double_t r = TMath::Sqrt(pos[0]*pos[0]+
239 pos[1]*pos[1]+
240 pos[2]*pos[2] ) ;
241
242 p.SetPxPyPzE( energy*pos[0]/r, energy*pos[1]/r, energy*pos[2]/r, energy) ;
243
244}
1b54b5a3 245
246
247void AliAODCaloCluster::SetCellsAbsId(UShort_t *array)
248{
249 // Set the array of cell absId numbers
250 if (fNCells) {
341952b8 251 if(!fCellsAbsId)fCellsAbsId = new UShort_t[fNCells];
252 for (Int_t i = 0; i < fNCells; i++) fCellsAbsId[i] = array[i];
1b54b5a3 253 }
254}
255
256void AliAODCaloCluster::SetCellsAmplitudeFraction(Double32_t *array)
257{
258 // Set the array of cell amplitude fraction
259 if (fNCells) {
341952b8 260 if(!fCellsAmpFraction)fCellsAmpFraction = new Double32_t[fNCells];
261 for (Int_t i = 0; i < fNCells; i++) fCellsAmpFraction[i] = array[i];
1b54b5a3 262 }
263}