1 /**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-------------------------------------------------------------------------
19 // AOD track base class
20 // Base class for Analysis Object Data
22 // Author: Markus Oldenburg, CERN
23 //-------------------------------------------------------------------------
25 #include "AliAODVertex.h"
27 #include "AliAODTrack.h"
29 ClassImp(AliAODVertex)
31 //______________________________________________________________________________
32 AliAODVertex::AliAODVertex() :
41 // default constructor
43 fPosition[0] = fPosition[1] = fPosition[2] = -999.;
46 //______________________________________________________________________________
47 AliAODVertex::AliAODVertex(const Double_t position[3],
48 const Double_t covMatrix[6],
54 fChi2perNDF(chi2perNDF),
63 SetPosition(position);
64 if (covMatrix) SetCovMatrix(covMatrix);
67 //______________________________________________________________________________
68 AliAODVertex::AliAODVertex(const Float_t position[3],
69 const Float_t covMatrix[6],
76 fChi2perNDF(chi2perNDF),
85 SetPosition(position);
86 if (covMatrix) SetCovMatrix(covMatrix);
89 //______________________________________________________________________________
90 AliAODVertex::AliAODVertex(const Double_t position[3],
94 fChi2perNDF(chi2perNDF),
101 // constructor without covariance matrix
103 SetPosition(position);
106 //______________________________________________________________________________
107 AliAODVertex::AliAODVertex(const Float_t position[3],
111 fChi2perNDF(chi2perNDF),
118 // constructor without covariance matrix
120 SetPosition(position);
123 //______________________________________________________________________________
124 AliAODVertex::~AliAODVertex()
131 //______________________________________________________________________________
132 AliAODVertex::AliAODVertex(const AliAODVertex& vtx) :
134 fChi2perNDF(vtx.fChi2perNDF),
138 fParent(vtx.fParent),
139 fDaughters(vtx.fDaughters)
143 for (int i = 0; i < 3; i++)
144 fPosition[i] = vtx.fPosition[i];
146 if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
149 //______________________________________________________________________________
150 AliAODVertex& AliAODVertex::operator=(const AliAODVertex& vtx)
152 // Assignment operator
156 TObject::operator=(vtx);
159 for (int i = 0; i < 3; i++)
160 fPosition[i] = vtx.fPosition[i];
162 fChi2perNDF = vtx.fChi2perNDF;
169 if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
172 fParent = vtx.fParent;
173 fDaughters = vtx.fDaughters;
179 //______________________________________________________________________________
180 template <class T> void AliAODVertex::GetSigmaXYZ(T sigma[3]) const
182 // Return errors on vertex position in thrust frame
185 sigma[0]=fCovMatrix[3]; //GetCovXZ
186 sigma[1]=fCovMatrix[4]; //GetCovYZ
187 sigma[2]=fCovMatrix[5]; //GetCovZZ
189 sigma[0]=sigma[1]=sigma[2]=-999.;
192 for (int i = 0, j = 6; i < 3; i++) {
194 sigma[2-i] = fCovMatrix ? TMath::Sqrt(fCovMatrix[j]) : -999.;
199 //______________________________________________________________________________
200 Int_t AliAODVertex::GetNContributors() const
202 // Returns the number of tracks used to fit this vertex.
206 for (Int_t iDaug = 0; iDaug < GetNDaughters(); iDaug++) {
207 if (((AliAODTrack*)fDaughters.At(iDaug))->GetUsedForVtxFit()) cont++;
213 //______________________________________________________________________________
214 Bool_t AliAODVertex::HasDaughter(TObject *daughter) const
216 // Checks if the given daughter (particle) is part of this vertex.
218 TRefArrayIter iter(&fDaughters);
219 while (TObject *daugh = iter.Next()) {
220 if (daugh == daughter) return kTRUE;
225 //______________________________________________________________________________
226 Double_t AliAODVertex::RotatedCovMatrixXX(Double_t phi, Double_t theta) const
228 // XX term of covariance matrix after rotation by phi around z-axis
229 // and, then, by theta around new y-axis
232 //AliFatal("Covariance matrix not set");
236 Double_t covMatrix[6];
238 GetCovMatrix(covMatrix);
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);
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
253 //______________________________________________________________________________
254 Double_t AliAODVertex::RotatedCovMatrixXY(Double_t phi, Double_t theta) const
256 // XY term of covariance matrix after rotation by phi around z-axis
257 // and, then, by theta around new y-axis
260 //AliFatal("Covariance matrix not set");
264 Double_t covMatrix[6];
266 GetCovMatrix(covMatrix);
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);
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
280 //______________________________________________________________________________
281 Double_t AliAODVertex::RotatedCovMatrixXZ(Double_t phi, Double_t theta) const
283 // XZ term of covariance matrix after rotation by phi around z-axis
284 // and, then, by theta around new y-axis
287 //AliFatal("Covariance matrix not set");
291 Double_t covMatrix[6];
293 GetCovMatrix(covMatrix);
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);
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
308 //______________________________________________________________________________
309 Double_t AliAODVertex::RotatedCovMatrixYY(Double_t phi) const
311 // YY term of covariance matrix after rotation by phi around z-axis
312 // and, then, by theta around new y-axis
315 //AliFatal("Covariance matrix not set");
319 Double_t covMatrix[6];
321 GetCovMatrix(covMatrix);
323 Double_t cp = TMath::Cos(phi);
324 Double_t sp = TMath::Sin(phi);
326 covMatrix[0]*sp*sp // GetCovXX
327 -covMatrix[1]*2.*cp*sp // GetCovXY
328 +covMatrix[2]*cp*cp; // GetCovYY
331 //______________________________________________________________________________
332 Double_t AliAODVertex::RotatedCovMatrixYZ(Double_t phi, Double_t theta) const
334 // YZ term of covariance matrix after rotation by phi around z-axis
335 // and, then, by theta around new y-axis
338 //AliFatal("Covariance matrix not set");
342 Double_t covMatrix[6];
344 GetCovMatrix(covMatrix);
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);
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
358 //______________________________________________________________________________
359 Double_t AliAODVertex::RotatedCovMatrixZZ(Double_t phi, Double_t theta) const
361 // ZZ term of covariance matrix after rotation by phi around z-axis
362 // and, then, by theta around new y-axis
365 //AliFatal("Covariance matrix not set");
369 Double_t covMatrix[6];
371 GetCovMatrix(covMatrix);
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);
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
386 //______________________________________________________________________________
387 Double_t AliAODVertex::DistanceToVertex(AliAODVertex *vtx) const
389 // distance in 3D to another AliAODVertex
391 Double_t dx = GetX()-vtx->GetX();
392 Double_t dy = GetY()-vtx->GetY();
393 Double_t dz = GetZ()-vtx->GetZ();
395 return TMath::Sqrt(dx*dx+dy*dy+dz*dz);
398 //______________________________________________________________________________
399 Double_t AliAODVertex::DistanceXYToVertex(AliAODVertex *vtx) const
401 // distance in XY to another AliAODVertex
403 Double_t dx = GetX()-vtx->GetX();
404 Double_t dy = GetY()-vtx->GetY();
406 return TMath::Sqrt(dx*dx+dy*dy);
409 //______________________________________________________________________________
410 Double_t AliAODVertex::ErrorDistanceToVertex(AliAODVertex *vtx) const
412 // error on the distance in 3D to another AliAODVertex
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);
421 return TMath::Sqrt(error2+error2vtx);
424 //______________________________________________________________________________
425 Double_t AliAODVertex::ErrorDistanceXYToVertex(AliAODVertex *vtx) const
427 // error on the distance in XY to another AliAODVertex
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);
436 return TMath::Sqrt(error2+error2vtx);
439 //______________________________________________________________________________
440 template <class T, class P>
441 void AliAODVertex::PhiAndThetaToVertex(AliAODVertex *vtx, P &phi, T &theta) const
443 // rotation angles around z-axis (phi) and around new y-axis (theta)
444 // with which vtx is seen (used by RotatedCovMatrix... methods)
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);
452 //______________________________________________________________________________
453 void AliAODVertex::PrintIndices() const
455 // Print indices of particles originating form this vertex
457 TRefArrayIter iter(&fDaughters);
458 while (TObject *daugh = iter.Next()) {
459 printf("Particle %p originates from this vertex.\n", daugh);
463 //______________________________________________________________________________
464 void AliAODVertex::Print(Option_t* /*option*/) const
466 // Print information of all data members
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);
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",
490 printf(" Chi^2/NDF = %f\n", fChi2perNDF);