]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODVertex.cxx
Fix for copy/paste error
[u/mrichter/AliRoot.git] / STEER / AliAODVertex.cxx
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 track base class
20 //     Base class for Analysis Object Data
21 //     Generic version
22 //     Author: Markus Oldenburg, CERN
23 //-------------------------------------------------------------------------
24
25 #include "AliAODVertex.h"
26
27 #include "AliAODTrack.h"
28
29 ClassImp(AliAODVertex)
30
31 //______________________________________________________________________________
32 AliAODVertex::AliAODVertex() : 
33   TObject(),
34   fChi2perNDF(-999.),
35   fID(-1),
36   fType(kUndef),
37   fCovMatrix(NULL),
38   fParent(),
39   fDaughters()
40   {
41   // default constructor
42
43   fPosition[0] = fPosition[1] = fPosition[2] = -999.;
44 }
45
46 //______________________________________________________________________________
47 AliAODVertex::AliAODVertex(const Double_t position[3], 
48                            const Double_t covMatrix[6],
49                            Double_t  chi2perNDF,
50                            TObject  *parent,
51                            Short_t id,
52                            Char_t vtype) :
53   TObject(),
54   fChi2perNDF(chi2perNDF),
55   fID(id),
56   fType(vtype),
57   fCovMatrix(NULL),
58   fParent(parent),
59   fDaughters()
60 {
61   // constructor
62
63   SetPosition(position);
64   if (covMatrix) SetCovMatrix(covMatrix);
65 }
66
67 //______________________________________________________________________________
68 AliAODVertex::AliAODVertex(const Float_t position[3], 
69                            const Float_t  covMatrix[6],
70                            Double_t  chi2perNDF,
71                            TObject  *parent,
72                            Short_t id,
73                            Char_t vtype) :
74
75   TObject(),
76   fChi2perNDF(chi2perNDF),
77   fID(id),
78   fType(vtype),
79   fCovMatrix(NULL),
80   fParent(parent),
81   fDaughters()
82 {
83   // constructor
84
85   SetPosition(position);
86   if (covMatrix) SetCovMatrix(covMatrix);
87 }
88
89 //______________________________________________________________________________
90 AliAODVertex::AliAODVertex(const Double_t position[3], 
91                            Double_t  chi2perNDF,
92                            Char_t vtype) :
93   TObject(),
94   fChi2perNDF(chi2perNDF),
95   fID(-1),
96   fType(vtype),
97   fCovMatrix(NULL),
98   fParent(),
99   fDaughters()
100 {
101   // constructor without covariance matrix
102
103   SetPosition(position);  
104 }
105
106 //______________________________________________________________________________
107 AliAODVertex::AliAODVertex(const Float_t position[3], 
108                            Double_t  chi2perNDF,
109                            Char_t vtype) :
110   TObject(),
111   fChi2perNDF(chi2perNDF),
112   fID(-1),
113   fType(vtype),
114   fCovMatrix(NULL),
115   fParent(),
116   fDaughters()
117 {
118   // constructor without covariance matrix
119
120   SetPosition(position);  
121 }
122
123 //______________________________________________________________________________
124 AliAODVertex::~AliAODVertex() 
125 {
126   // Destructor
127
128   delete fCovMatrix;
129 }
130
131 //______________________________________________________________________________
132 AliAODVertex::AliAODVertex(const AliAODVertex& vtx) :
133   TObject(vtx),
134   fChi2perNDF(vtx.fChi2perNDF),
135   fID(vtx.fID),
136   fType(vtx.fType),
137   fCovMatrix(NULL),
138   fParent(vtx.fParent),
139   fDaughters(vtx.fDaughters)
140 {
141   // Copy constructor.
142   
143   for (int i = 0; i < 3; i++) 
144     fPosition[i] = vtx.fPosition[i];
145
146   if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
147 }
148
149 //______________________________________________________________________________
150 AliAODVertex& AliAODVertex::operator=(const AliAODVertex& vtx) 
151 {
152   // Assignment operator
153   if (this != &vtx) {
154
155     // name and type
156     TObject::operator=(vtx);
157
158     //momentum
159     for (int i = 0; i < 3; i++) 
160       fPosition[i] = vtx.fPosition[i];
161     
162     fChi2perNDF = vtx.fChi2perNDF;
163     fID = vtx.fID;
164     fType = vtx.fType;
165
166     //covariance matrix
167     delete fCovMatrix;
168     fCovMatrix = NULL;   
169     if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
170     
171     //other stuff
172     fParent = vtx.fParent;
173     fDaughters = vtx.fDaughters;
174   }
175   
176   return *this;
177 }
178
179 //______________________________________________________________________________
180 template <class T> void AliAODVertex::GetSigmaXYZ(T sigma[3]) const
181 {
182   // Return errors on vertex position in thrust frame
183   
184   if(fCovMatrix) {
185     sigma[0]=fCovMatrix[3]; //GetCovXZ
186     sigma[1]=fCovMatrix[4]; //GetCovYZ
187     sigma[2]=fCovMatrix[5]; //GetCovZZ
188   } else 
189     sigma[0]=sigma[1]=sigma[2]=-999.;
190
191   /*
192   for (int i = 0, j = 6; i < 3; i++) {
193     j -= i+1;
194     sigma[2-i] = fCovMatrix ? TMath::Sqrt(fCovMatrix[j]) : -999.;
195   }
196   */
197 }
198
199 //______________________________________________________________________________
200 Int_t AliAODVertex::GetNContributors() const 
201 {
202   // Returns the number of tracks used to fit this vertex.
203   
204   Int_t cont = 0;
205
206   for (Int_t iDaug = 0; iDaug < GetNDaughters(); iDaug++) {
207     if (((AliAODTrack*)fDaughters.At(iDaug))->GetUsedForVtxFit()) cont++;
208   }
209
210   return cont;
211 }
212
213 //______________________________________________________________________________
214 Bool_t AliAODVertex::HasDaughter(TObject *daughter) const 
215 {
216   // Checks if the given daughter (particle) is part of this vertex.
217
218   TRefArrayIter iter(&fDaughters);
219   while (TObject *daugh = iter.Next()) {
220     if (daugh == daughter) return kTRUE;
221   }
222   return kFALSE;
223 }
224
225 //______________________________________________________________________________
226 Double_t AliAODVertex::RotatedCovMatrixXX(Double_t phi, Double_t theta) const
227 {
228   // XX term of covariance matrix after rotation by phi around z-axis
229   // and, then, by theta around new y-axis
230
231   if (!fCovMatrix) {
232     //AliFatal("Covariance matrix not set");
233     return -999.;
234   }
235
236   Double_t covMatrix[6];
237
238   GetCovMatrix(covMatrix);
239
240   Double_t cp = TMath::Cos(phi);
241   Double_t sp = TMath::Sin(phi);
242   Double_t ct = TMath::Cos(theta);
243   Double_t st = TMath::Sin(theta);
244   return
245      covMatrix[0]*cp*cp*ct*ct  // GetCovXX
246     +covMatrix[1]*2.*cp*sp*ct*ct  // GetCovXY
247     +covMatrix[3]*2.*cp*ct*st  // GetCovXZ
248     +covMatrix[2]*sp*sp*ct*ct  // GetCovYY
249     +covMatrix[4]*2.*sp*ct*st  // GetCovYZ
250     +covMatrix[5]*st*st;  // GetCovZZ
251 }
252
253 //______________________________________________________________________________
254 Double_t AliAODVertex::RotatedCovMatrixXY(Double_t phi, Double_t theta) const
255 {
256   // XY term of covariance matrix after rotation by phi around z-axis
257   // and, then, by theta around new y-axis
258
259   if (!fCovMatrix) {
260     //AliFatal("Covariance matrix not set");
261     return -999.;
262   }
263
264   Double_t covMatrix[6];
265
266   GetCovMatrix(covMatrix);
267
268   Double_t cp = TMath::Cos(phi);
269   Double_t sp = TMath::Sin(phi);
270   Double_t ct = TMath::Cos(theta);
271   Double_t st = TMath::Sin(theta);
272   return 
273     -covMatrix[0]*cp*sp*ct  // GetCovXX
274     +covMatrix[1]*ct*(cp*cp-sp*sp)  // GetCovXY
275     -covMatrix[3]*sp*st  // GetCovXZ
276     +covMatrix[2]*cp*sp*ct  // GetCovYY
277     +covMatrix[4]*cp*st;  // GetCovYZ
278 }
279
280 //______________________________________________________________________________
281 Double_t AliAODVertex::RotatedCovMatrixXZ(Double_t phi, Double_t theta) const
282 {
283   // XZ term of covariance matrix after rotation by phi around z-axis
284   // and, then, by theta around new y-axis
285
286   if (!fCovMatrix) {
287     //AliFatal("Covariance matrix not set");
288     return -999.;
289   }
290
291   Double_t covMatrix[6];
292
293   GetCovMatrix(covMatrix);
294
295   Double_t cp = TMath::Cos(phi);
296   Double_t sp = TMath::Sin(phi);
297   Double_t ct = TMath::Cos(theta);
298   Double_t st = TMath::Sin(theta);
299   return 
300     -covMatrix[0]*cp*cp*ct*st  // GetCovXX
301     -covMatrix[1]*2.*cp*sp*ct*st  // GetCovXY
302     +covMatrix[3]*cp*(ct*ct-st*st)  // GetCovXZ
303     -covMatrix[2]*sp*sp*ct*st  // GetCovYY
304     +covMatrix[4]*sp*(ct*ct-st*st)  // GetCovYZ
305     +covMatrix[5]*ct*st;  // GetCovZZ
306 }
307
308 //______________________________________________________________________________
309 Double_t AliAODVertex::RotatedCovMatrixYY(Double_t phi) const
310 {
311   // YY term of covariance matrix after rotation by phi around z-axis
312   // and, then, by theta around new y-axis
313
314   if (!fCovMatrix) {
315     //AliFatal("Covariance matrix not set");
316     return -999.;
317   }
318
319   Double_t covMatrix[6];
320
321   GetCovMatrix(covMatrix);
322
323   Double_t cp = TMath::Cos(phi);
324   Double_t sp = TMath::Sin(phi);
325   return
326      covMatrix[0]*sp*sp  // GetCovXX
327     -covMatrix[1]*2.*cp*sp  // GetCovXY
328     +covMatrix[2]*cp*cp;  // GetCovYY
329 }
330
331 //______________________________________________________________________________
332 Double_t AliAODVertex::RotatedCovMatrixYZ(Double_t phi, Double_t theta) const
333 {
334   // YZ term of covariance matrix after rotation by phi around z-axis
335   // and, then, by theta around new y-axis
336
337   if (!fCovMatrix) {
338     //AliFatal("Covariance matrix not set");
339     return -999.;
340   }
341
342   Double_t covMatrix[6];
343
344   GetCovMatrix(covMatrix);
345
346   Double_t cp = TMath::Cos(phi);
347   Double_t sp = TMath::Sin(phi);
348   Double_t ct = TMath::Cos(theta);
349   Double_t st = TMath::Sin(theta);
350   return 
351      covMatrix[0]*cp*sp*st  // GetCovXX
352     +covMatrix[1]*st*(sp*sp-cp*cp)  // GetCovXY
353     -covMatrix[3]*sp*ct  // GetCovXZ
354     -covMatrix[2]*cp*sp*st  // GetCovYY
355     +covMatrix[4]*cp*ct;  // GetCovYZ
356 }
357
358 //______________________________________________________________________________
359 Double_t AliAODVertex::RotatedCovMatrixZZ(Double_t phi, Double_t theta) const
360 {
361   // ZZ term of covariance matrix after rotation by phi around z-axis
362   // and, then, by theta around new y-axis
363
364   if (!fCovMatrix) {
365     //AliFatal("Covariance matrix not set");
366     return -999.;
367   }
368
369   Double_t covMatrix[6];
370
371   GetCovMatrix(covMatrix);
372
373   Double_t cp = TMath::Cos(phi);
374   Double_t sp = TMath::Sin(phi);
375   Double_t ct = TMath::Cos(theta);
376   Double_t st = TMath::Sin(theta);
377   return
378      covMatrix[0]*cp*cp*st*st  // GetCovXX
379     +covMatrix[1]*2.*cp*sp*st*st  // GetCovXY
380     -covMatrix[3]*2.*cp*ct*st  // GetCovXZ
381     +covMatrix[2]*sp*sp*st*st  // GetCovYY
382     -covMatrix[4]*2.*sp*sp*ct*st  // GetCovYZ
383     +covMatrix[5]*ct*ct;  // GetCovZZ
384 }
385
386 //______________________________________________________________________________
387 Double_t AliAODVertex::DistanceToVertex(AliAODVertex *vtx) const
388 {
389   // distance in 3D to another AliAODVertex
390
391   Double_t dx = GetX()-vtx->GetX();
392   Double_t dy = GetY()-vtx->GetY();
393   Double_t dz = GetZ()-vtx->GetZ();
394
395   return TMath::Sqrt(dx*dx+dy*dy+dz*dz);
396 }
397
398 //______________________________________________________________________________
399 Double_t AliAODVertex::DistanceXYToVertex(AliAODVertex *vtx) const
400 {
401   // distance in XY to another AliAODVertex
402
403   Double_t dx = GetX()-vtx->GetX();
404   Double_t dy = GetY()-vtx->GetY();
405
406   return TMath::Sqrt(dx*dx+dy*dy);
407 }
408
409 //______________________________________________________________________________
410 Double_t AliAODVertex::ErrorDistanceToVertex(AliAODVertex *vtx) const
411 {
412   // error on the distance in 3D to another AliAODVertex
413
414   Double_t phi,theta;
415   PhiAndThetaToVertex(vtx,phi,theta);
416   // error2 due to this vertex
417   Double_t error2 = RotatedCovMatrixXX(phi,theta);
418   // error2 due to vtx vertex
419   Double_t error2vtx = vtx->RotatedCovMatrixXX(phi,theta);
420
421   return TMath::Sqrt(error2+error2vtx);
422 }
423
424 //______________________________________________________________________________
425 Double_t AliAODVertex::ErrorDistanceXYToVertex(AliAODVertex *vtx) const
426 {
427   // error on the distance in XY to another AliAODVertex
428
429   Double_t phi,theta;
430   PhiAndThetaToVertex(vtx,phi,theta);
431   // error2 due to this vertex
432   Double_t error2 = RotatedCovMatrixXX(phi);
433   // error2 due to vtx vertex
434   Double_t error2vtx = vtx->RotatedCovMatrixXX(phi);
435
436   return TMath::Sqrt(error2+error2vtx);
437 }
438
439 //______________________________________________________________________________
440 template <class T, class P> 
441 void AliAODVertex::PhiAndThetaToVertex(AliAODVertex *vtx, P &phi, T &theta) const
442 {
443   // rotation angles around z-axis (phi) and around new y-axis (theta)
444   // with which vtx is seen (used by RotatedCovMatrix... methods)
445
446   phi = TMath::Pi()+TMath::ATan2(-vtx->GetY()+GetY(),-vtx->GetX()+GetX());
447   Double_t vtxxphi = vtx->GetX()*TMath::Cos(phi)+vtx->GetY()*TMath::Sin(phi);
448   Double_t xphi = GetX()*TMath::Cos(phi)+GetY()*TMath::Sin(phi);
449   theta = TMath::ATan2(vtx->GetZ()-GetZ(),vtxxphi-xphi);
450 }
451
452 //______________________________________________________________________________
453 void AliAODVertex::PrintIndices() const 
454 {
455   // Print indices of particles originating form this vertex
456
457   TRefArrayIter iter(&fDaughters);
458   while (TObject *daugh = iter.Next()) {
459     printf("Particle %p originates from this vertex.\n", daugh);
460   }
461 }
462
463 //______________________________________________________________________________
464 void AliAODVertex::Print(Option_t* /*option*/) const 
465 {
466   // Print information of all data members
467
468   printf("Vertex position:\n");
469   printf("     x = %f\n", fPosition[0]);
470   printf("     y = %f\n", fPosition[1]);
471   printf("     z = %f\n", fPosition[2]);
472   printf(" parent particle: %p\n", fParent.GetObject());
473   printf(" origin of %d particles\n", fDaughters.GetEntriesFast());
474   printf(" vertex type %d\n", fType);
475   
476   /*
477   if (fCovMatrix) {
478     printf("Covariance matrix:\n");
479     printf(" %12.10f  %12.10f  %12.10f\n %12.10f  %12.10f  %12.10f\n %12.10f  %12.10f  %12.10f\n", 
480            fCovMatrix[0],
481            fCovMatrix[1],
482            fCovMatrix[3],
483            fCovMatrix[1],
484            fCovMatrix[2],
485            fCovMatrix[4],
486            fCovMatrix[3],
487            fCovMatrix[4],
488            fCovMatrix[5]); 
489            } */
490   printf(" Chi^2/NDF = %f\n", fChi2perNDF);
491 }
492