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::CloneWithoutRefs() const
188 // Special method to copy all but the refs
190 Double_t cov[6] = { 0.0 };
192 if (fCovMatrix) fCovMatrix->GetCovMatrix(cov);
194 AliAODVertex* v = new AliAODVertex(fPosition,
202 v->SetNContributors(fNContributors);
207 //______________________________________________________________________________
208 AliAODVertex& AliAODVertex::operator=(const AliAODVertex& vtx)
210 // Assignment operator
214 AliVVertex::operator=(vtx);
217 for (int i = 0; i < 3; i++)
218 fPosition[i] = vtx.fPosition[i];
220 fChi2perNDF = vtx.fChi2perNDF;
227 if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
230 fParent = vtx.fParent;
231 fDaughters = vtx.fDaughters;
232 fNprong = vtx.fNprong;
233 fIprong = vtx.fIprong;
236 for (int i = 0; i < fNprong; i++) {
237 fProngs[i] = vtx.fProngs[i];
244 //______________________________________________________________________________
245 void AliAODVertex::AddDaughter(TObject *daughter)
247 // Add reference to daughter track
249 if (fDaughters.GetEntries()==0) {
250 TRefArray* arr = &fDaughters;
251 new(arr)TRefArray(TProcessID::GetProcessWithUID(daughter));
253 fDaughters.Add(daughter);
255 if (fIprong < fNprong) {
256 fProngs[fIprong++] = daughter;
258 AliWarning("Number of daughters out of range !\n");
265 //______________________________________________________________________________
266 template <class T> void AliAODVertex::GetSigmaXYZ(T sigma[3]) const
268 // Return errors on vertex position in thrust frame
271 sigma[0]=fCovMatrix[3]; //GetCovXZ
272 sigma[1]=fCovMatrix[4]; //GetCovYZ
273 sigma[2]=fCovMatrix[5]; //GetCovZZ
275 sigma[0]=sigma[1]=sigma[2]=-999.;
278 for (int i = 0, j = 6; i < 3; i++) {
280 sigma[2-i] = fCovMatrix ? TMath::Sqrt(fCovMatrix[j]) : -999.;
285 //______________________________________________________________________________
286 Int_t AliAODVertex::GetNContributors() const
288 // Returns the number of tracks used to fit this vertex.
291 TString vtitle = GetTitle();
292 if (!vtitle.Contains("VertexerTracks")) {
293 cont = fNContributors;
295 for (Int_t iDaug = 0; iDaug < GetNDaughters(); iDaug++) {
296 AliAODTrack* aodT = dynamic_cast<AliAODTrack*>(fDaughters.At(iDaug));
298 if (aodT->GetUsedForPrimVtxFit()) cont++;
300 // the constraint adds another DOF
301 if(vtitle.Contains("VertexerTracksWithConstraint"))cont++;
306 //______________________________________________________________________________
307 Bool_t AliAODVertex::HasDaughter(TObject *daughter) const
309 // Checks if the given daughter (particle) is part of this vertex.
311 TRefArrayIter iter(&fDaughters);
312 while (TObject *daugh = iter.Next()) {
313 if (daugh == daughter) return kTRUE;
318 for (int i = 0; i < fNprong; i++) {
319 if (fProngs[i].GetObject() == daughter) has = kTRUE;
325 //______________________________________________________________________________
326 Double_t AliAODVertex::RotatedCovMatrixXX(Double_t phi, Double_t theta) const
328 // XX term of covariance matrix after rotation by phi around z-axis
329 // and, then, by theta around new y-axis
332 //AliFatal("Covariance matrix not set");
336 Double_t covMatrix[6];
338 GetCovMatrix(covMatrix);
340 Double_t cp = TMath::Cos(phi);
341 Double_t sp = TMath::Sin(phi);
342 Double_t ct = TMath::Cos(theta);
343 Double_t st = TMath::Sin(theta);
345 covMatrix[0]*cp*cp*ct*ct // GetCovXX
346 +covMatrix[1]*2.*cp*sp*ct*ct // GetCovXY
347 +covMatrix[3]*2.*cp*ct*st // GetCovXZ
348 +covMatrix[2]*sp*sp*ct*ct // GetCovYY
349 +covMatrix[4]*2.*sp*ct*st // GetCovYZ
350 +covMatrix[5]*st*st; // GetCovZZ
353 //______________________________________________________________________________
354 Double_t AliAODVertex::RotatedCovMatrixXY(Double_t phi, Double_t theta) const
356 // XY term of covariance matrix after rotation by phi around z-axis
357 // and, then, by theta around new y-axis
360 //AliFatal("Covariance matrix not set");
364 Double_t covMatrix[6];
366 GetCovMatrix(covMatrix);
368 Double_t cp = TMath::Cos(phi);
369 Double_t sp = TMath::Sin(phi);
370 Double_t ct = TMath::Cos(theta);
371 Double_t st = TMath::Sin(theta);
373 -covMatrix[0]*cp*sp*ct // GetCovXX
374 +covMatrix[1]*ct*(cp*cp-sp*sp) // GetCovXY
375 -covMatrix[3]*sp*st // GetCovXZ
376 +covMatrix[2]*cp*sp*ct // GetCovYY
377 +covMatrix[4]*cp*st; // GetCovYZ
380 //______________________________________________________________________________
381 Double_t AliAODVertex::RotatedCovMatrixXZ(Double_t phi, Double_t theta) const
383 // XZ term of covariance matrix after rotation by phi around z-axis
384 // and, then, by theta around new y-axis
387 //AliFatal("Covariance matrix not set");
391 Double_t covMatrix[6];
393 GetCovMatrix(covMatrix);
395 Double_t cp = TMath::Cos(phi);
396 Double_t sp = TMath::Sin(phi);
397 Double_t ct = TMath::Cos(theta);
398 Double_t st = TMath::Sin(theta);
400 -covMatrix[0]*cp*cp*ct*st // GetCovXX
401 -covMatrix[1]*2.*cp*sp*ct*st // GetCovXY
402 +covMatrix[3]*cp*(ct*ct-st*st) // GetCovXZ
403 -covMatrix[2]*sp*sp*ct*st // GetCovYY
404 +covMatrix[4]*sp*(ct*ct-st*st) // GetCovYZ
405 +covMatrix[5]*ct*st; // GetCovZZ
408 //______________________________________________________________________________
409 Double_t AliAODVertex::RotatedCovMatrixYY(Double_t phi) const
411 // YY term of covariance matrix after rotation by phi around z-axis
412 // and, then, by theta around new y-axis
415 //AliFatal("Covariance matrix not set");
419 Double_t covMatrix[6];
421 GetCovMatrix(covMatrix);
423 Double_t cp = TMath::Cos(phi);
424 Double_t sp = TMath::Sin(phi);
426 covMatrix[0]*sp*sp // GetCovXX
427 -covMatrix[1]*2.*cp*sp // GetCovXY
428 +covMatrix[2]*cp*cp; // GetCovYY
431 //______________________________________________________________________________
432 Double_t AliAODVertex::RotatedCovMatrixYZ(Double_t phi, Double_t theta) const
434 // YZ term of covariance matrix after rotation by phi around z-axis
435 // and, then, by theta around new y-axis
438 //AliFatal("Covariance matrix not set");
442 Double_t covMatrix[6];
444 GetCovMatrix(covMatrix);
446 Double_t cp = TMath::Cos(phi);
447 Double_t sp = TMath::Sin(phi);
448 Double_t ct = TMath::Cos(theta);
449 Double_t st = TMath::Sin(theta);
451 covMatrix[0]*cp*sp*st // GetCovXX
452 +covMatrix[1]*st*(sp*sp-cp*cp) // GetCovXY
453 -covMatrix[3]*sp*ct // GetCovXZ
454 -covMatrix[2]*cp*sp*st // GetCovYY
455 +covMatrix[4]*cp*ct; // GetCovYZ
458 //______________________________________________________________________________
459 Double_t AliAODVertex::RotatedCovMatrixZZ(Double_t phi, Double_t theta) const
461 // ZZ term of covariance matrix after rotation by phi around z-axis
462 // and, then, by theta around new y-axis
465 //AliFatal("Covariance matrix not set");
469 Double_t covMatrix[6];
471 GetCovMatrix(covMatrix);
473 Double_t cp = TMath::Cos(phi);
474 Double_t sp = TMath::Sin(phi);
475 Double_t ct = TMath::Cos(theta);
476 Double_t st = TMath::Sin(theta);
478 covMatrix[0]*cp*cp*st*st // GetCovXX
479 +covMatrix[1]*2.*cp*sp*st*st // GetCovXY
480 -covMatrix[3]*2.*cp*ct*st // GetCovXZ
481 +covMatrix[2]*sp*sp*st*st // GetCovYY
482 -covMatrix[4]*2.*sp*sp*ct*st // GetCovYZ
483 +covMatrix[5]*ct*ct; // GetCovZZ
486 //______________________________________________________________________________
487 Double_t AliAODVertex::Distance2ToVertex(AliAODVertex *vtx) const
489 // distance in 3D to another AliAODVertex
491 Double_t dx = GetX()-vtx->GetX();
492 Double_t dy = GetY()-vtx->GetY();
493 Double_t dz = GetZ()-vtx->GetZ();
495 return dx*dx+dy*dy+dz*dz;
498 //______________________________________________________________________________
499 Double_t AliAODVertex::DistanceXY2ToVertex(AliAODVertex *vtx) const
501 // distance in XY to another AliAODVertex
503 Double_t dx = GetX()-vtx->GetX();
504 Double_t dy = GetY()-vtx->GetY();
509 //______________________________________________________________________________
510 Double_t AliAODVertex::Error2DistanceToVertex(AliAODVertex *vtx) const
512 // error on the distance in 3D to another AliAODVertex
515 PhiAndThetaToVertex(vtx,phi,theta);
516 // error2 due to this vertex
517 Double_t error2 = RotatedCovMatrixXX(phi,theta);
518 // error2 due to vtx vertex
519 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi,theta);
521 return error2+error2vtx;
524 //______________________________________________________________________________
525 Double_t AliAODVertex::Error2DistanceXYToVertex(AliAODVertex *vtx) const
527 // error on the distance in XY to another AliAODVertex
530 PhiAndThetaToVertex(vtx,phi,theta);
531 // error2 due to this vertex
532 Double_t error2 = RotatedCovMatrixXX(phi);
533 // error2 due to vtx vertex
534 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi);
536 return error2+error2vtx;
539 //______________________________________________________________________________
540 template <class T, class P>
541 void AliAODVertex::PhiAndThetaToVertex(AliAODVertex *vtx, P &phi, T &theta) const
543 // rotation angles around z-axis (phi) and around new y-axis (theta)
544 // with which vtx is seen (used by RotatedCovMatrix... methods)
546 phi = TMath::Pi()+TMath::ATan2(-vtx->GetY()+GetY(),-vtx->GetX()+GetX());
547 Double_t vtxxphi = vtx->GetX()*TMath::Cos(phi)+vtx->GetY()*TMath::Sin(phi);
548 Double_t xphi = GetX()*TMath::Cos(phi)+GetY()*TMath::Sin(phi);
549 theta = TMath::ATan2(vtx->GetZ()-GetZ(),vtxxphi-xphi);
552 //______________________________________________________________________________
553 void AliAODVertex::PrintIndices() const
555 // Print indices of particles originating form this vertex
557 TRefArrayIter iter(&fDaughters);
558 while (TObject *daugh = iter.Next()) {
559 printf("Particle %p originates from this vertex.\n", static_cast<void*>(daugh));
563 //______________________________________________________________________________
564 const char* AliAODVertex::AsString() const
566 // Make a string describing this object
568 TString tmp(Form("%10s pos(%7.2f,%7.2f,%7.2f)",GetTypeName((AODVtx_t)GetType()),GetX(),GetY(),GetZ()));
570 if (GetType()==kPrimary || GetType()==kMainSPD || GetType()==kPileupSPD )
572 tmp += Form(" ncontrib %d chi2/ndf %4.1f",GetNContributors(),GetChi2perNDF());
576 if ( !fParent.GetObject() )
580 if ( fDaughters.GetEntriesFast() > 0 )
582 if ( fDaughters.GetEntriesFast() == 1 )
584 tmp += " origin of 1 particle";
588 tmp += Form(" origin of %2d particles",fDaughters.GetEntriesFast());
595 //______________________________________________________________________________
596 const char* AliAODVertex::GetTypeName(AODVtx_t type)
598 // Return an ASCII version of type
632 //______________________________________________________________________________
633 void AliAODVertex::Print(Option_t* /*option*/) const
635 // Print information of all data members
637 printf("Vertex position:\n");
638 printf(" x = %f\n", fPosition[0]);
639 printf(" y = %f\n", fPosition[1]);
640 printf(" z = %f\n", fPosition[2]);
641 printf(" parent particle: %p\n", static_cast<void*>(fParent.GetObject()));
642 printf(" origin of %d particles\n", fDaughters.GetEntriesFast());
643 printf(" vertex type %d\n", fType);
647 printf("Covariance matrix:\n");
648 printf(" %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n",
659 printf(" Chi^2/NDF = %f\n", fChi2perNDF);