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 // Inheritance from AliVVertex: A. Dainese
24 //-------------------------------------------------------------------------
26 #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 AliVVertex::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 void AliAODVertex::AddDaughter(TObject *daughter)
182 // Add reference to daughter track
184 if (fDaughters.GetEntries()==0) {
185 TRefArray* arr = &fDaughters;
186 new(arr)TRefArray(TProcessID::GetProcessWithUID(daughter));
188 fDaughters.Add(daughter);
193 //______________________________________________________________________________
194 template <class T> void AliAODVertex::GetSigmaXYZ(T sigma[3]) const
196 // Return errors on vertex position in thrust frame
199 sigma[0]=fCovMatrix[3]; //GetCovXZ
200 sigma[1]=fCovMatrix[4]; //GetCovYZ
201 sigma[2]=fCovMatrix[5]; //GetCovZZ
203 sigma[0]=sigma[1]=sigma[2]=-999.;
206 for (int i = 0, j = 6; i < 3; i++) {
208 sigma[2-i] = fCovMatrix ? TMath::Sqrt(fCovMatrix[j]) : -999.;
213 //______________________________________________________________________________
214 Int_t AliAODVertex::GetNContributors() const
216 // Returns the number of tracks used to fit this vertex.
220 for (Int_t iDaug = 0; iDaug < GetNDaughters(); iDaug++) {
221 if (((AliAODTrack*)fDaughters.At(iDaug))->GetUsedForVtxFit()) cont++;
227 //______________________________________________________________________________
228 Bool_t AliAODVertex::HasDaughter(TObject *daughter) const
230 // Checks if the given daughter (particle) is part of this vertex.
232 TRefArrayIter iter(&fDaughters);
233 while (TObject *daugh = iter.Next()) {
234 if (daugh == daughter) return kTRUE;
239 //______________________________________________________________________________
240 Double_t AliAODVertex::RotatedCovMatrixXX(Double_t phi, Double_t theta) const
242 // XX term of covariance matrix after rotation by phi around z-axis
243 // and, then, by theta around new y-axis
246 //AliFatal("Covariance matrix not set");
250 Double_t covMatrix[6];
252 GetCovMatrix(covMatrix);
254 Double_t cp = TMath::Cos(phi);
255 Double_t sp = TMath::Sin(phi);
256 Double_t ct = TMath::Cos(theta);
257 Double_t st = TMath::Sin(theta);
259 covMatrix[0]*cp*cp*ct*ct // GetCovXX
260 +covMatrix[1]*2.*cp*sp*ct*ct // GetCovXY
261 +covMatrix[3]*2.*cp*ct*st // GetCovXZ
262 +covMatrix[2]*sp*sp*ct*ct // GetCovYY
263 +covMatrix[4]*2.*sp*ct*st // GetCovYZ
264 +covMatrix[5]*st*st; // GetCovZZ
267 //______________________________________________________________________________
268 Double_t AliAODVertex::RotatedCovMatrixXY(Double_t phi, Double_t theta) const
270 // XY term of covariance matrix after rotation by phi around z-axis
271 // and, then, by theta around new y-axis
274 //AliFatal("Covariance matrix not set");
278 Double_t covMatrix[6];
280 GetCovMatrix(covMatrix);
282 Double_t cp = TMath::Cos(phi);
283 Double_t sp = TMath::Sin(phi);
284 Double_t ct = TMath::Cos(theta);
285 Double_t st = TMath::Sin(theta);
287 -covMatrix[0]*cp*sp*ct // GetCovXX
288 +covMatrix[1]*ct*(cp*cp-sp*sp) // GetCovXY
289 -covMatrix[3]*sp*st // GetCovXZ
290 +covMatrix[2]*cp*sp*ct // GetCovYY
291 +covMatrix[4]*cp*st; // GetCovYZ
294 //______________________________________________________________________________
295 Double_t AliAODVertex::RotatedCovMatrixXZ(Double_t phi, Double_t theta) const
297 // XZ term of covariance matrix after rotation by phi around z-axis
298 // and, then, by theta around new y-axis
301 //AliFatal("Covariance matrix not set");
305 Double_t covMatrix[6];
307 GetCovMatrix(covMatrix);
309 Double_t cp = TMath::Cos(phi);
310 Double_t sp = TMath::Sin(phi);
311 Double_t ct = TMath::Cos(theta);
312 Double_t st = TMath::Sin(theta);
314 -covMatrix[0]*cp*cp*ct*st // GetCovXX
315 -covMatrix[1]*2.*cp*sp*ct*st // GetCovXY
316 +covMatrix[3]*cp*(ct*ct-st*st) // GetCovXZ
317 -covMatrix[2]*sp*sp*ct*st // GetCovYY
318 +covMatrix[4]*sp*(ct*ct-st*st) // GetCovYZ
319 +covMatrix[5]*ct*st; // GetCovZZ
322 //______________________________________________________________________________
323 Double_t AliAODVertex::RotatedCovMatrixYY(Double_t phi) const
325 // YY term of covariance matrix after rotation by phi around z-axis
326 // and, then, by theta around new y-axis
329 //AliFatal("Covariance matrix not set");
333 Double_t covMatrix[6];
335 GetCovMatrix(covMatrix);
337 Double_t cp = TMath::Cos(phi);
338 Double_t sp = TMath::Sin(phi);
340 covMatrix[0]*sp*sp // GetCovXX
341 -covMatrix[1]*2.*cp*sp // GetCovXY
342 +covMatrix[2]*cp*cp; // GetCovYY
345 //______________________________________________________________________________
346 Double_t AliAODVertex::RotatedCovMatrixYZ(Double_t phi, Double_t theta) const
348 // YZ term of covariance matrix after rotation by phi around z-axis
349 // and, then, by theta around new y-axis
352 //AliFatal("Covariance matrix not set");
356 Double_t covMatrix[6];
358 GetCovMatrix(covMatrix);
360 Double_t cp = TMath::Cos(phi);
361 Double_t sp = TMath::Sin(phi);
362 Double_t ct = TMath::Cos(theta);
363 Double_t st = TMath::Sin(theta);
365 covMatrix[0]*cp*sp*st // GetCovXX
366 +covMatrix[1]*st*(sp*sp-cp*cp) // GetCovXY
367 -covMatrix[3]*sp*ct // GetCovXZ
368 -covMatrix[2]*cp*sp*st // GetCovYY
369 +covMatrix[4]*cp*ct; // GetCovYZ
372 //______________________________________________________________________________
373 Double_t AliAODVertex::RotatedCovMatrixZZ(Double_t phi, Double_t theta) const
375 // ZZ term of covariance matrix after rotation by phi around z-axis
376 // and, then, by theta around new y-axis
379 //AliFatal("Covariance matrix not set");
383 Double_t covMatrix[6];
385 GetCovMatrix(covMatrix);
387 Double_t cp = TMath::Cos(phi);
388 Double_t sp = TMath::Sin(phi);
389 Double_t ct = TMath::Cos(theta);
390 Double_t st = TMath::Sin(theta);
392 covMatrix[0]*cp*cp*st*st // GetCovXX
393 +covMatrix[1]*2.*cp*sp*st*st // GetCovXY
394 -covMatrix[3]*2.*cp*ct*st // GetCovXZ
395 +covMatrix[2]*sp*sp*st*st // GetCovYY
396 -covMatrix[4]*2.*sp*sp*ct*st // GetCovYZ
397 +covMatrix[5]*ct*ct; // GetCovZZ
400 //______________________________________________________________________________
401 Double_t AliAODVertex::DistanceToVertex(AliAODVertex *vtx) const
403 // distance in 3D to another AliAODVertex
405 Double_t dx = GetX()-vtx->GetX();
406 Double_t dy = GetY()-vtx->GetY();
407 Double_t dz = GetZ()-vtx->GetZ();
409 return TMath::Sqrt(dx*dx+dy*dy+dz*dz);
412 //______________________________________________________________________________
413 Double_t AliAODVertex::DistanceXYToVertex(AliAODVertex *vtx) const
415 // distance in XY to another AliAODVertex
417 Double_t dx = GetX()-vtx->GetX();
418 Double_t dy = GetY()-vtx->GetY();
420 return TMath::Sqrt(dx*dx+dy*dy);
423 //______________________________________________________________________________
424 Double_t AliAODVertex::ErrorDistanceToVertex(AliAODVertex *vtx) const
426 // error on the distance in 3D to another AliAODVertex
429 PhiAndThetaToVertex(vtx,phi,theta);
430 // error2 due to this vertex
431 Double_t error2 = RotatedCovMatrixXX(phi,theta);
432 // error2 due to vtx vertex
433 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi,theta);
435 return TMath::Sqrt(error2+error2vtx);
438 //______________________________________________________________________________
439 Double_t AliAODVertex::ErrorDistanceXYToVertex(AliAODVertex *vtx) const
441 // error on the distance in XY to another AliAODVertex
444 PhiAndThetaToVertex(vtx,phi,theta);
445 // error2 due to this vertex
446 Double_t error2 = RotatedCovMatrixXX(phi);
447 // error2 due to vtx vertex
448 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi);
450 return TMath::Sqrt(error2+error2vtx);
453 //______________________________________________________________________________
454 template <class T, class P>
455 void AliAODVertex::PhiAndThetaToVertex(AliAODVertex *vtx, P &phi, T &theta) const
457 // rotation angles around z-axis (phi) and around new y-axis (theta)
458 // with which vtx is seen (used by RotatedCovMatrix... methods)
460 phi = TMath::Pi()+TMath::ATan2(-vtx->GetY()+GetY(),-vtx->GetX()+GetX());
461 Double_t vtxxphi = vtx->GetX()*TMath::Cos(phi)+vtx->GetY()*TMath::Sin(phi);
462 Double_t xphi = GetX()*TMath::Cos(phi)+GetY()*TMath::Sin(phi);
463 theta = TMath::ATan2(vtx->GetZ()-GetZ(),vtxxphi-xphi);
466 //______________________________________________________________________________
467 void AliAODVertex::PrintIndices() const
469 // Print indices of particles originating form this vertex
471 TRefArrayIter iter(&fDaughters);
472 while (TObject *daugh = iter.Next()) {
473 printf("Particle %p originates from this vertex.\n", static_cast<void*>(daugh));
477 //______________________________________________________________________________
478 void AliAODVertex::Print(Option_t* /*option*/) const
480 // Print information of all data members
482 printf("Vertex position:\n");
483 printf(" x = %f\n", fPosition[0]);
484 printf(" y = %f\n", fPosition[1]);
485 printf(" z = %f\n", fPosition[2]);
486 printf(" parent particle: %p\n", static_cast<void*>(fParent.GetObject()));
487 printf(" origin of %d particles\n", fDaughters.GetEntriesFast());
488 printf(" vertex type %d\n", fType);
492 printf("Covariance matrix:\n");
493 printf(" %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n",
504 printf(" Chi^2/NDF = %f\n", fChi2perNDF);