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