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() :
45 // default constructor
47 fPosition[0] = fPosition[1] = fPosition[2] = -999.;
50 //______________________________________________________________________________
51 AliAODVertex::AliAODVertex(const Double_t position[3],
52 const Double_t covMatrix[6],
59 fChi2perNDF(chi2perNDF),
72 SetPosition(position);
73 if (covMatrix) SetCovMatrix(covMatrix);
77 //______________________________________________________________________________
78 AliAODVertex::AliAODVertex(const Float_t position[3],
79 const Float_t covMatrix[6],
87 fChi2perNDF(chi2perNDF),
100 SetPosition(position);
101 if (covMatrix) SetCovMatrix(covMatrix);
105 //______________________________________________________________________________
106 AliAODVertex::AliAODVertex(const Double_t position[3],
111 fChi2perNDF(chi2perNDF),
122 // constructor without covariance matrix
124 SetPosition(position);
128 //______________________________________________________________________________
129 AliAODVertex::AliAODVertex(const Float_t position[3],
131 Char_t vtype, Int_t nprong) :
133 fChi2perNDF(chi2perNDF),
144 // constructor without covariance matrix
146 SetPosition(position);
150 //______________________________________________________________________________
151 AliAODVertex::~AliAODVertex()
156 if (fNprong > 0) delete[] fProngs;
159 //______________________________________________________________________________
160 AliAODVertex::AliAODVertex(const AliAODVertex& vtx) :
162 fChi2perNDF(vtx.fChi2perNDF),
165 fNprong(vtx.fNprong),
166 fIprong(vtx.fIprong),
167 fNContributors(vtx.fNContributors),
169 fParent(vtx.fParent),
170 fDaughters(vtx.fDaughters),
175 for (int i = 0; i < 3; i++)
176 fPosition[i] = vtx.fPosition[i];
178 if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
180 for (int i = 0; i < fNprong; i++) {
181 fProngs[i] = vtx.fProngs[i];
185 //______________________________________________________________________________
186 AliAODVertex& AliAODVertex::operator=(const AliAODVertex& vtx)
188 // Assignment operator
192 AliVVertex::operator=(vtx);
195 for (int i = 0; i < 3; i++)
196 fPosition[i] = vtx.fPosition[i];
198 fChi2perNDF = vtx.fChi2perNDF;
205 if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
208 fParent = vtx.fParent;
209 fDaughters = vtx.fDaughters;
210 fNprong = vtx.fNprong;
211 fIprong = vtx.fIprong;
214 for (int i = 0; i < fNprong; i++) {
215 fProngs[i] = vtx.fProngs[i];
222 //______________________________________________________________________________
223 void AliAODVertex::AddDaughter(TObject *daughter)
225 // Add reference to daughter track
227 if (fDaughters.GetEntries()==0) {
228 TRefArray* arr = &fDaughters;
229 new(arr)TRefArray(TProcessID::GetProcessWithUID(daughter));
231 fDaughters.Add(daughter);
233 if (fIprong < fNprong) {
234 fProngs[fIprong++] = daughter;
236 AliWarning("Number of daughters out of range !\n");
243 //______________________________________________________________________________
244 template <class T> void AliAODVertex::GetSigmaXYZ(T sigma[3]) const
246 // Return errors on vertex position in thrust frame
249 sigma[0]=fCovMatrix[3]; //GetCovXZ
250 sigma[1]=fCovMatrix[4]; //GetCovYZ
251 sigma[2]=fCovMatrix[5]; //GetCovZZ
253 sigma[0]=sigma[1]=sigma[2]=-999.;
256 for (int i = 0, j = 6; i < 3; i++) {
258 sigma[2-i] = fCovMatrix ? TMath::Sqrt(fCovMatrix[j]) : -999.;
263 //______________________________________________________________________________
264 Int_t AliAODVertex::GetNContributors() const
266 // Returns the number of tracks used to fit this vertex.
269 TString vtitle = GetTitle();
270 if (!vtitle.Contains("VertexerTracks")) {
271 cont = fNContributors;
273 for (Int_t iDaug = 0; iDaug < GetNDaughters(); iDaug++) {
274 AliAODTrack* aodT = dynamic_cast<AliAODTrack*>(fDaughters.At(iDaug));
276 if (aodT->GetUsedForPrimVtxFit()) cont++;
278 // the constraint adds another DOF
279 if(vtitle.Contains("VertexerTracksWithConstraint"))cont++;
284 //______________________________________________________________________________
285 Bool_t AliAODVertex::HasDaughter(TObject *daughter) const
287 // Checks if the given daughter (particle) is part of this vertex.
289 TRefArrayIter iter(&fDaughters);
290 while (TObject *daugh = iter.Next()) {
291 if (daugh == daughter) return kTRUE;
296 for (int i = 0; i < fNprong; i++) {
297 if (fProngs[i].GetObject() == daughter) has = kTRUE;
303 //______________________________________________________________________________
304 Double_t AliAODVertex::RotatedCovMatrixXX(Double_t phi, Double_t theta) const
306 // XX term of covariance matrix after rotation by phi around z-axis
307 // and, then, by theta around new y-axis
310 //AliFatal("Covariance matrix not set");
314 Double_t covMatrix[6];
316 GetCovMatrix(covMatrix);
318 Double_t cp = TMath::Cos(phi);
319 Double_t sp = TMath::Sin(phi);
320 Double_t ct = TMath::Cos(theta);
321 Double_t st = TMath::Sin(theta);
323 covMatrix[0]*cp*cp*ct*ct // GetCovXX
324 +covMatrix[1]*2.*cp*sp*ct*ct // GetCovXY
325 +covMatrix[3]*2.*cp*ct*st // GetCovXZ
326 +covMatrix[2]*sp*sp*ct*ct // GetCovYY
327 +covMatrix[4]*2.*sp*ct*st // GetCovYZ
328 +covMatrix[5]*st*st; // GetCovZZ
331 //______________________________________________________________________________
332 Double_t AliAODVertex::RotatedCovMatrixXY(Double_t phi, Double_t theta) const
334 // XY 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*ct // GetCovXX
352 +covMatrix[1]*ct*(cp*cp-sp*sp) // GetCovXY
353 -covMatrix[3]*sp*st // GetCovXZ
354 +covMatrix[2]*cp*sp*ct // GetCovYY
355 +covMatrix[4]*cp*st; // GetCovYZ
358 //______________________________________________________________________________
359 Double_t AliAODVertex::RotatedCovMatrixXZ(Double_t phi, Double_t theta) const
361 // XZ 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*ct*st // GetCovXX
379 -covMatrix[1]*2.*cp*sp*ct*st // GetCovXY
380 +covMatrix[3]*cp*(ct*ct-st*st) // GetCovXZ
381 -covMatrix[2]*sp*sp*ct*st // GetCovYY
382 +covMatrix[4]*sp*(ct*ct-st*st) // GetCovYZ
383 +covMatrix[5]*ct*st; // GetCovZZ
386 //______________________________________________________________________________
387 Double_t AliAODVertex::RotatedCovMatrixYY(Double_t phi) const
389 // YY term of covariance matrix after rotation by phi around z-axis
390 // and, then, by theta around new y-axis
393 //AliFatal("Covariance matrix not set");
397 Double_t covMatrix[6];
399 GetCovMatrix(covMatrix);
401 Double_t cp = TMath::Cos(phi);
402 Double_t sp = TMath::Sin(phi);
404 covMatrix[0]*sp*sp // GetCovXX
405 -covMatrix[1]*2.*cp*sp // GetCovXY
406 +covMatrix[2]*cp*cp; // GetCovYY
409 //______________________________________________________________________________
410 Double_t AliAODVertex::RotatedCovMatrixYZ(Double_t phi, Double_t theta) const
412 // YZ term of covariance matrix after rotation by phi around z-axis
413 // and, then, by theta around new y-axis
416 //AliFatal("Covariance matrix not set");
420 Double_t covMatrix[6];
422 GetCovMatrix(covMatrix);
424 Double_t cp = TMath::Cos(phi);
425 Double_t sp = TMath::Sin(phi);
426 Double_t ct = TMath::Cos(theta);
427 Double_t st = TMath::Sin(theta);
429 covMatrix[0]*cp*sp*st // GetCovXX
430 +covMatrix[1]*st*(sp*sp-cp*cp) // GetCovXY
431 -covMatrix[3]*sp*ct // GetCovXZ
432 -covMatrix[2]*cp*sp*st // GetCovYY
433 +covMatrix[4]*cp*ct; // GetCovYZ
436 //______________________________________________________________________________
437 Double_t AliAODVertex::RotatedCovMatrixZZ(Double_t phi, Double_t theta) const
439 // ZZ term of covariance matrix after rotation by phi around z-axis
440 // and, then, by theta around new y-axis
443 //AliFatal("Covariance matrix not set");
447 Double_t covMatrix[6];
449 GetCovMatrix(covMatrix);
451 Double_t cp = TMath::Cos(phi);
452 Double_t sp = TMath::Sin(phi);
453 Double_t ct = TMath::Cos(theta);
454 Double_t st = TMath::Sin(theta);
456 covMatrix[0]*cp*cp*st*st // GetCovXX
457 +covMatrix[1]*2.*cp*sp*st*st // GetCovXY
458 -covMatrix[3]*2.*cp*ct*st // GetCovXZ
459 +covMatrix[2]*sp*sp*st*st // GetCovYY
460 -covMatrix[4]*2.*sp*sp*ct*st // GetCovYZ
461 +covMatrix[5]*ct*ct; // GetCovZZ
464 //______________________________________________________________________________
465 Double_t AliAODVertex::DistanceToVertex(AliAODVertex *vtx) const
467 // distance in 3D to another AliAODVertex
469 Double_t dx = GetX()-vtx->GetX();
470 Double_t dy = GetY()-vtx->GetY();
471 Double_t dz = GetZ()-vtx->GetZ();
473 return TMath::Sqrt(dx*dx+dy*dy+dz*dz);
476 //______________________________________________________________________________
477 Double_t AliAODVertex::DistanceXYToVertex(AliAODVertex *vtx) const
479 // distance in XY to another AliAODVertex
481 Double_t dx = GetX()-vtx->GetX();
482 Double_t dy = GetY()-vtx->GetY();
484 return TMath::Sqrt(dx*dx+dy*dy);
487 //______________________________________________________________________________
488 Double_t AliAODVertex::ErrorDistanceToVertex(AliAODVertex *vtx) const
490 // error on the distance in 3D to another AliAODVertex
493 PhiAndThetaToVertex(vtx,phi,theta);
494 // error2 due to this vertex
495 Double_t error2 = RotatedCovMatrixXX(phi,theta);
496 // error2 due to vtx vertex
497 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi,theta);
499 return TMath::Sqrt(error2+error2vtx);
502 //______________________________________________________________________________
503 Double_t AliAODVertex::ErrorDistanceXYToVertex(AliAODVertex *vtx) const
505 // error on the distance in XY to another AliAODVertex
508 PhiAndThetaToVertex(vtx,phi,theta);
509 // error2 due to this vertex
510 Double_t error2 = RotatedCovMatrixXX(phi);
511 // error2 due to vtx vertex
512 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi);
514 return TMath::Sqrt(error2+error2vtx);
517 //______________________________________________________________________________
518 template <class T, class P>
519 void AliAODVertex::PhiAndThetaToVertex(AliAODVertex *vtx, P &phi, T &theta) const
521 // rotation angles around z-axis (phi) and around new y-axis (theta)
522 // with which vtx is seen (used by RotatedCovMatrix... methods)
524 phi = TMath::Pi()+TMath::ATan2(-vtx->GetY()+GetY(),-vtx->GetX()+GetX());
525 Double_t vtxxphi = vtx->GetX()*TMath::Cos(phi)+vtx->GetY()*TMath::Sin(phi);
526 Double_t xphi = GetX()*TMath::Cos(phi)+GetY()*TMath::Sin(phi);
527 theta = TMath::ATan2(vtx->GetZ()-GetZ(),vtxxphi-xphi);
530 //______________________________________________________________________________
531 void AliAODVertex::PrintIndices() const
533 // Print indices of particles originating form this vertex
535 TRefArrayIter iter(&fDaughters);
536 while (TObject *daugh = iter.Next()) {
537 printf("Particle %p originates from this vertex.\n", static_cast<void*>(daugh));
541 //______________________________________________________________________________
542 void AliAODVertex::Print(Option_t* /*option*/) const
544 // Print information of all data members
546 printf("Vertex position:\n");
547 printf(" x = %f\n", fPosition[0]);
548 printf(" y = %f\n", fPosition[1]);
549 printf(" z = %f\n", fPosition[2]);
550 printf(" parent particle: %p\n", static_cast<void*>(fParent.GetObject()));
551 printf(" origin of %d particles\n", fDaughters.GetEntriesFast());
552 printf(" vertex type %d\n", fType);
556 printf("Covariance matrix:\n");
557 printf(" %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n",
568 printf(" Chi^2/NDF = %f\n", fChi2perNDF);