]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/ESD/AliESDVertex.cxx
Compatibility with ROOT trunk
[u/mrichter/AliRoot.git] / STEER / ESD / AliESDVertex.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2003, 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 //-----------------------------------------------------------------
17 //           Implementation of the Primary Vertex class
18 //           for the Event Data Summary class
19 //           This class contains the Primary Vertex
20 //           of the event coming from reconstruction
21 // Origin: A.Dainese, andrea.dainese@lnl.infn.it
22 //-----------------------------------------------------------------
23
24 //---- standard headers ----
25 #include "Riostream.h"
26 //---- Root headers --------
27 #include <TMath.h>
28 #include <TROOT.h>
29 #include <TMatrixDSym.h>
30 //---- AliRoot headers -----
31 #include "AliESDVertex.h"
32 #include "AliVTrack.h"
33 #include "AliLog.h"
34
35 ClassImp(AliESDVertex)
36
37 //--------------------------------------------------------------------------
38 AliESDVertex::AliESDVertex() :
39   AliVertex(),
40   fCovXX(0.005*0.005),
41   fCovXY(0),
42   fCovYY(0.005*0.005),
43   fCovXZ(0),
44   fCovYZ(0),
45   fCovZZ(5.3*5.3),
46   fChi2(0),
47   fID(-1),   // ID=-1 means the vertex with the biggest number of contributors 
48   fBCID(AliVTrack::kTOFBCNA)
49 {
50   //
51   // Default Constructor, set everything to 0
52   //
53   SetToZero();
54 }
55
56 //--------------------------------------------------------------------------
57 AliESDVertex::AliESDVertex(Double_t positionZ,Double_t sigmaZ,
58                            Int_t nContributors,const Char_t *vtxName) :
59   AliVertex(),
60   fCovXX(0.005*0.005),
61   fCovXY(0),
62   fCovYY(0.005*0.005),
63   fCovXZ(0),
64   fCovYZ(0),
65   fCovZZ(sigmaZ*sigmaZ),
66   fChi2(0),
67   fID(-1),   // ID=-1 means the vertex with the biggest number of contributors 
68   fBCID(AliVTrack::kTOFBCNA)
69 {
70   //
71   // Constructor for vertex Z from pixels
72   //
73
74   SetToZero();
75
76   fPosition[2]   = positionZ;
77   SetName(vtxName);
78   SetNContributors(nContributors);
79
80 }
81
82 //------------------------------------------------------------------------- 
83 AliESDVertex::AliESDVertex(Double_t position[3],Double_t covmatrix[6],
84                            Double_t chi2,Int_t nContributors,
85                            const Char_t *vtxName) :
86   AliVertex(position,0.,nContributors),
87   fCovXX(covmatrix[0]),
88   fCovXY(covmatrix[1]),
89   fCovYY(covmatrix[2]),
90   fCovXZ(covmatrix[3]),
91   fCovYZ(covmatrix[4]),
92   fCovZZ(covmatrix[5]),
93   fChi2(chi2),
94   fID(-1),   // ID=-1 means the vertex with the biggest number of contributors 
95   fBCID(AliVTrack::kTOFBCNA)
96 {
97   //
98   // Constructor for vertex in 3D from tracks
99   //
100
101   SetToZero();
102   SetName(vtxName);
103
104 }
105 //--------------------------------------------------------------------------
106 AliESDVertex::AliESDVertex(Double_t position[3],Double_t sigma[3],
107                            const Char_t *vtxName) :
108   AliVertex(position,0.,0),
109   fCovXX(sigma[0]*sigma[0]),
110   fCovXY(0),
111   fCovYY(sigma[1]*sigma[1]),
112   fCovXZ(0),
113   fCovYZ(0),
114   fCovZZ(sigma[2]*sigma[2]),
115   fChi2(0),
116   fID(-1),   // ID=-1 means the vertex with the biggest number of contributors 
117   fBCID(AliVTrack::kTOFBCNA)
118 {
119   //
120   // Constructor for smearing of true position
121   //
122
123   SetToZero();
124   SetName(vtxName);
125
126 }
127 //--------------------------------------------------------------------------
128 AliESDVertex::AliESDVertex(Double_t position[3],Double_t sigma[3],
129                            Double_t snr[3], const Char_t *vtxName) :
130   AliVertex(position,0.,0),
131   fCovXX(sigma[0]*sigma[0]),
132   fCovXY(0),
133   fCovYY(sigma[1]*sigma[1]),
134   fCovXZ(0),
135   fCovYZ(0),
136   fCovZZ(sigma[2]*sigma[2]),
137   fChi2(0),
138   fID(-1),   // ID=-1 means the vertex with the biggest number of contributors 
139   fBCID(AliVTrack::kTOFBCNA)
140 {
141   //
142   // Constructor for Pb-Pb
143   //
144
145   SetToZero();
146   SetName(vtxName);
147
148   fSNR[0]        = snr[0];
149   fSNR[1]        = snr[1];
150   fSNR[2]        = snr[2];
151
152 }
153 //--------------------------------------------------------------------------
154 AliESDVertex::AliESDVertex(const AliESDVertex &source):
155   AliVertex(source),
156   fCovXX(source.fCovXX),
157   fCovXY(source.fCovXY),
158   fCovYY(source.fCovYY),
159   fCovXZ(source.fCovXZ),
160   fCovYZ(source.fCovYZ),
161   fCovZZ(source.fCovZZ),
162   fChi2(source.fChi2),
163   fID(source.fID),
164   fBCID(source.fBCID)
165 {
166   //
167   // Copy constructor
168   //
169   for(Int_t i=0;i<3;i++) {
170     fSNR[i] = source.fSNR[i];
171   }
172 }
173 //--------------------------------------------------------------------------
174 AliESDVertex &AliESDVertex::operator=(const AliESDVertex &source){
175   //
176   // assignment operator
177   //
178   if(&source != this){
179     AliVertex::operator=(source);
180     for(Int_t i=0;i<3;++i)fSNR[i] = source.fSNR[i];
181     fCovXX = source.fCovXX;
182     fCovXY = source.fCovXY;
183     fCovYY = source.fCovYY;
184     fCovXZ = source.fCovXZ;
185     fCovYZ = source.fCovYZ;
186     fCovZZ = source.fCovZZ;
187     fChi2 = source.fChi2;
188     fID = source.fID;
189     fBCID = source.fBCID;
190   }
191   return *this;
192 }
193 //--------------------------------------------------------------------------
194 void AliESDVertex::Copy(TObject &obj) const {
195   
196   // this overwrites the virtual TOBject::Copy()
197   // to allow run time copying without casting
198   // in AliESDEvent
199
200   if(this==&obj)return;
201   AliESDVertex *robj = dynamic_cast<AliESDVertex*>(&obj);
202   if(!robj)return; // not an AliESDVertex
203   *robj = *this;
204
205 }
206 //--------------------------------------------------------------------------
207 void AliESDVertex::SetToZero() {
208   //
209   // Set the content of arrays to 0. Used by constructors
210   //
211   for(Int_t i=0; i<3; i++){
212     fSNR[i] = 0.;
213   }
214 }
215 //--------------------------------------------------------------------------
216 void AliESDVertex::GetSigmaXYZ(Double_t sigma[3]) const {
217   //
218   // Return errors on vertex position in thrust frame
219   //
220   sigma[0] = TMath::Sqrt(fCovXX);
221   sigma[1] = TMath::Sqrt(fCovYY);
222   sigma[2] = TMath::Sqrt(fCovZZ);
223
224   return;
225 }
226 //--------------------------------------------------------------------------
227 void AliESDVertex::GetCovMatrix(Double_t covmatrix[6]) const {
228   //
229   // Return covariance matrix of the vertex
230   //
231   covmatrix[0] = fCovXX;
232   covmatrix[1] = fCovXY;
233   covmatrix[2] = fCovYY;
234   covmatrix[3] = fCovXZ;
235   covmatrix[4] = fCovYZ;
236   covmatrix[5] = fCovZZ;
237
238   return;
239 }
240
241 //--------------------------------------------------------------------------
242 void AliESDVertex::SetCovarianceMatrix(const Double_t *covmatrix) {
243   //
244   // Return covariance matrix of the vertex
245   //
246   fCovXX = covmatrix[0];
247   fCovXY = covmatrix[1];
248   fCovYY = covmatrix[2];
249   fCovXZ = covmatrix[3];
250   fCovYZ = covmatrix[4];
251   fCovZZ = covmatrix[5];
252
253   return;
254 }
255
256 //--------------------------------------------------------------------------
257 void AliESDVertex::GetSNR(Double_t snr[3]) const {
258   //
259   // Return S/N ratios
260   //
261   for(Int_t i=0;i<3;i++) snr[i] = fSNR[i];
262
263   return;
264 }
265 //--------------------------------------------------------------------------
266 void AliESDVertex::Print(Option_t* /*option*/) const {
267   //
268   // Print out information on all data members
269   //
270   printf("ESD vertex position:\n");
271   printf("   x = %f +- %f\n",fPosition[0], fCovXX>0 ? TMath::Sqrt(fCovXX) : 0.);
272   printf("   y = %f +- %f\n",fPosition[1], fCovYY>0 ? TMath::Sqrt(fCovYY) : 0.);
273   printf("   z = %f +- %f\n",fPosition[2], fCovZZ>0 ? TMath::Sqrt(fCovZZ) : 0.);
274   printf(" Covariance matrix:\n");
275   printf(" %12.10f  %12.10f  %12.10f\n %12.10f  %12.10f  %12.10f\n %12.10f  %12.10f  %12.10f\n",fCovXX,fCovXY,fCovXZ,fCovXY,fCovYY,fCovYZ,fCovXZ,fCovYZ,fCovZZ);
276   printf(" S/N = (%f, %f, %f)\n",fSNR[0],fSNR[1],fSNR[2]);
277   printf(" chi2 = %f\n",fChi2);
278   printf(" # tracks (or tracklets) = %d BCID=%d\n",fNContributors,int(fBCID));
279   //
280   if (fCovXX<0 || fCovYY<0 || fCovZZ<0) {AliError("Attention: negative diagonal element");}
281   //
282   return;
283 }
284
285
286 //____________________________________________________________
287 Double_t AliESDVertex::GetWDist(const AliESDVertex* v) const
288 {
289   // calculate sqrt of weighted distance to other vertex
290   static TMatrixDSym vVb(3);
291   double dist = -1;
292   double dx = fPosition[0]-v->fPosition[0], dy = fPosition[1]-v->fPosition[1], dz = fPosition[2]-v->fPosition[2];
293   vVb(0,0) = fCovXX + v->fCovXX;
294   vVb(1,1) = fCovYY + v->fCovYY;
295   vVb(2,2) = fCovZZ + v->fCovZZ;;
296   vVb(1,0) = vVb(0,1) = fCovXY + v->fCovXY;
297   vVb(0,2) = vVb(1,2) = vVb(2,0) = vVb(2,1) = 0.;
298   vVb.InvertFast();
299   if (!vVb.IsValid()) {AliError("Singular Matrix"); return dist;}
300   dist = vVb(0,0)*dx*dx + vVb(1,1)*dy*dy + vVb(2,2)*dz*dz
301     +    2*vVb(0,1)*dx*dy + 2*vVb(0,2)*dx*dz + 2*vVb(1,2)*dy*dz;
302   return dist>0 ? TMath::Sqrt(dist) : -1; 
303 }