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