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() :
36 fBCID(AliVTrack::kTOFBCNA),
46 // default constructor
48 fPosition[0] = fPosition[1] = fPosition[2] = -999.;
51 //______________________________________________________________________________
52 AliAODVertex::AliAODVertex(const Double_t position[3],
53 const Double_t covMatrix[6],
60 fChi2perNDF(chi2perNDF),
62 fBCID(AliVTrack::kTOFBCNA),
74 SetPosition(position);
75 if (covMatrix) SetCovMatrix(covMatrix);
79 //______________________________________________________________________________
80 AliAODVertex::AliAODVertex(const Float_t position[3],
81 const Float_t covMatrix[6],
89 fChi2perNDF(chi2perNDF),
91 fBCID(AliVTrack::kTOFBCNA),
103 SetPosition(position);
104 if (covMatrix) SetCovMatrix(covMatrix);
108 //______________________________________________________________________________
109 AliAODVertex::AliAODVertex(const Double_t position[3],
114 fChi2perNDF(chi2perNDF),
116 fBCID(AliVTrack::kTOFBCNA),
126 // constructor without covariance matrix
128 SetPosition(position);
132 //______________________________________________________________________________
133 AliAODVertex::AliAODVertex(const Float_t position[3],
135 Char_t vtype, Int_t nprong) :
137 fChi2perNDF(chi2perNDF),
139 fBCID(AliVTrack::kTOFBCNA),
149 // constructor without covariance matrix
151 SetPosition(position);
155 //______________________________________________________________________________
156 AliAODVertex::~AliAODVertex()
161 if (fNprong > 0) delete[] fProngs;
164 //______________________________________________________________________________
165 AliAODVertex::AliAODVertex(const AliAODVertex& vtx) :
167 fChi2perNDF(vtx.fChi2perNDF),
171 fNprong(vtx.fNprong),
172 fIprong(vtx.fIprong),
173 fNContributors(vtx.fNContributors),
175 fParent(vtx.fParent),
176 fDaughters(vtx.fDaughters),
181 for (int i = 0; i < 3; i++)
182 fPosition[i] = vtx.fPosition[i];
184 if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
186 for (int i = 0; i < fNprong; i++) {
187 fProngs[i] = vtx.fProngs[i];
191 //______________________________________________________________________________
192 AliAODVertex* AliAODVertex::CloneWithoutRefs() const
194 // Special method to copy all but the refs
196 Double_t cov[6] = { 0.0 };
198 if (fCovMatrix) fCovMatrix->GetCovMatrix(cov);
200 AliAODVertex* v = new AliAODVertex(fPosition,
208 v->SetNContributors(fNContributors);
213 //______________________________________________________________________________
214 AliAODVertex& AliAODVertex::operator=(const AliAODVertex& vtx)
216 // Assignment operator
220 AliVVertex::operator=(vtx);
223 for (int i = 0; i < 3; i++)
224 fPosition[i] = vtx.fPosition[i];
226 fChi2perNDF = vtx.fChi2perNDF;
234 if (vtx.fCovMatrix) fCovMatrix = new AliAODRedCov<3>(*vtx.fCovMatrix);
237 fNContributors = vtx.fNContributors;
238 fParent = vtx.fParent;
239 fDaughters = vtx.fDaughters;
240 fNprong = vtx.fNprong;
241 fIprong = vtx.fIprong;
244 for (int i = 0; i < fNprong; i++) {
245 fProngs[i] = vtx.fProngs[i];
252 //______________________________________________________________________________
253 void AliAODVertex::AddDaughter(TObject *daughter)
255 // Add reference to daughter track
257 if (fDaughters.GetEntries()==0) {
258 TRefArray* arr = &fDaughters;
259 new(arr)TRefArray(TProcessID::GetProcessWithUID(daughter));
261 fDaughters.Add(daughter);
263 if (fIprong < fNprong) {
264 fProngs[fIprong++] = daughter;
266 AliWarning("Number of daughters out of range !\n");
273 //______________________________________________________________________________
274 template <class T> void AliAODVertex::GetSigmaXYZ(T sigma[3]) const
276 // Return errors on vertex position in thrust frame
279 sigma[0]=fCovMatrix[3]; //GetCovXZ
280 sigma[1]=fCovMatrix[4]; //GetCovYZ
281 sigma[2]=fCovMatrix[5]; //GetCovZZ
283 sigma[0]=sigma[1]=sigma[2]=-999.;
286 for (int i = 0, j = 6; i < 3; i++) {
288 sigma[2-i] = fCovMatrix ? TMath::Sqrt(fCovMatrix[j]) : -999.;
293 //______________________________________________________________________________
294 Int_t AliAODVertex::GetNContributors() const
296 // Returns the number of tracks used to fit this vertex.
299 TString vtitle = GetTitle();
300 if (!vtitle.Contains("VertexerTracks")) {
301 cont = fNContributors;
303 for (Int_t iDaug = 0; iDaug < GetNDaughters(); iDaug++) {
304 AliAODTrack* aodT = dynamic_cast<AliAODTrack*>(fDaughters.At(iDaug));
306 if (aodT->GetUsedForPrimVtxFit()) cont++;
308 // the constraint adds another DOF
309 if(vtitle.Contains("VertexerTracksWithConstraint"))cont++;
314 //______________________________________________________________________________
315 Bool_t AliAODVertex::HasDaughter(TObject *daughter) const
317 // Checks if the given daughter (particle) is part of this vertex.
319 TRefArrayIter iter(&fDaughters);
320 while (TObject *daugh = iter.Next()) {
321 if (daugh == daughter) return kTRUE;
326 for (int i = 0; i < fNprong; i++) {
327 if (fProngs[i].GetObject() == daughter) has = kTRUE;
333 //______________________________________________________________________________
334 Double_t AliAODVertex::RotatedCovMatrixXX(Double_t phi, Double_t theta) const
336 // XX term of covariance matrix after rotation by phi around z-axis
337 // and, then, by theta around new y-axis
340 //AliFatal("Covariance matrix not set");
344 Double_t covMatrix[6];
346 GetCovMatrix(covMatrix);
348 Double_t cp = TMath::Cos(phi);
349 Double_t sp = TMath::Sin(phi);
350 Double_t ct = TMath::Cos(theta);
351 Double_t st = TMath::Sin(theta);
353 covMatrix[0]*cp*cp*ct*ct // GetCovXX
354 +covMatrix[1]*2.*cp*sp*ct*ct // GetCovXY
355 +covMatrix[3]*2.*cp*ct*st // GetCovXZ
356 +covMatrix[2]*sp*sp*ct*ct // GetCovYY
357 +covMatrix[4]*2.*sp*ct*st // GetCovYZ
358 +covMatrix[5]*st*st; // GetCovZZ
361 //______________________________________________________________________________
362 Double_t AliAODVertex::RotatedCovMatrixXY(Double_t phi, Double_t theta) const
364 // XY term of covariance matrix after rotation by phi around z-axis
365 // and, then, by theta around new y-axis
368 //AliFatal("Covariance matrix not set");
372 Double_t covMatrix[6];
374 GetCovMatrix(covMatrix);
376 Double_t cp = TMath::Cos(phi);
377 Double_t sp = TMath::Sin(phi);
378 Double_t ct = TMath::Cos(theta);
379 Double_t st = TMath::Sin(theta);
381 -covMatrix[0]*cp*sp*ct // GetCovXX
382 +covMatrix[1]*ct*(cp*cp-sp*sp) // GetCovXY
383 -covMatrix[3]*sp*st // GetCovXZ
384 +covMatrix[2]*cp*sp*ct // GetCovYY
385 +covMatrix[4]*cp*st; // GetCovYZ
388 //______________________________________________________________________________
389 Double_t AliAODVertex::RotatedCovMatrixXZ(Double_t phi, Double_t theta) const
391 // XZ term of covariance matrix after rotation by phi around z-axis
392 // and, then, by theta around new y-axis
395 //AliFatal("Covariance matrix not set");
399 Double_t covMatrix[6];
401 GetCovMatrix(covMatrix);
403 Double_t cp = TMath::Cos(phi);
404 Double_t sp = TMath::Sin(phi);
405 Double_t ct = TMath::Cos(theta);
406 Double_t st = TMath::Sin(theta);
408 -covMatrix[0]*cp*cp*ct*st // GetCovXX
409 -covMatrix[1]*2.*cp*sp*ct*st // GetCovXY
410 +covMatrix[3]*cp*(ct*ct-st*st) // GetCovXZ
411 -covMatrix[2]*sp*sp*ct*st // GetCovYY
412 +covMatrix[4]*sp*(ct*ct-st*st) // GetCovYZ
413 +covMatrix[5]*ct*st; // GetCovZZ
416 //______________________________________________________________________________
417 Double_t AliAODVertex::RotatedCovMatrixYY(Double_t phi) const
419 // YY term of covariance matrix after rotation by phi around z-axis
420 // and, then, by theta around new y-axis
423 //AliFatal("Covariance matrix not set");
427 Double_t covMatrix[6];
429 GetCovMatrix(covMatrix);
431 Double_t cp = TMath::Cos(phi);
432 Double_t sp = TMath::Sin(phi);
434 covMatrix[0]*sp*sp // GetCovXX
435 -covMatrix[1]*2.*cp*sp // GetCovXY
436 +covMatrix[2]*cp*cp; // GetCovYY
439 //______________________________________________________________________________
440 Double_t AliAODVertex::RotatedCovMatrixYZ(Double_t phi, Double_t theta) const
442 // YZ term of covariance matrix after rotation by phi around z-axis
443 // and, then, by theta around new y-axis
446 //AliFatal("Covariance matrix not set");
450 Double_t covMatrix[6];
452 GetCovMatrix(covMatrix);
454 Double_t cp = TMath::Cos(phi);
455 Double_t sp = TMath::Sin(phi);
456 Double_t ct = TMath::Cos(theta);
457 Double_t st = TMath::Sin(theta);
459 covMatrix[0]*cp*sp*st // GetCovXX
460 +covMatrix[1]*st*(sp*sp-cp*cp) // GetCovXY
461 -covMatrix[3]*sp*ct // GetCovXZ
462 -covMatrix[2]*cp*sp*st // GetCovYY
463 +covMatrix[4]*cp*ct; // GetCovYZ
466 //______________________________________________________________________________
467 Double_t AliAODVertex::RotatedCovMatrixZZ(Double_t phi, Double_t theta) const
469 // ZZ term of covariance matrix after rotation by phi around z-axis
470 // and, then, by theta around new y-axis
473 //AliFatal("Covariance matrix not set");
477 Double_t covMatrix[6];
479 GetCovMatrix(covMatrix);
481 Double_t cp = TMath::Cos(phi);
482 Double_t sp = TMath::Sin(phi);
483 Double_t ct = TMath::Cos(theta);
484 Double_t st = TMath::Sin(theta);
486 covMatrix[0]*cp*cp*st*st // GetCovXX
487 +covMatrix[1]*2.*cp*sp*st*st // GetCovXY
488 -covMatrix[3]*2.*cp*ct*st // GetCovXZ
489 +covMatrix[2]*sp*sp*st*st // GetCovYY
490 -covMatrix[4]*2.*sp*sp*ct*st // GetCovYZ
491 +covMatrix[5]*ct*ct; // GetCovZZ
494 //______________________________________________________________________________
495 Double_t AliAODVertex::Distance2ToVertex(const AliAODVertex *vtx) const
497 // distance in 3D to another AliAODVertex
499 Double_t dx = GetX()-vtx->GetX();
500 Double_t dy = GetY()-vtx->GetY();
501 Double_t dz = GetZ()-vtx->GetZ();
503 return dx*dx+dy*dy+dz*dz;
506 //______________________________________________________________________________
507 Double_t AliAODVertex::DistanceXY2ToVertex(const AliAODVertex *vtx) const
509 // distance in XY to another AliAODVertex
511 Double_t dx = GetX()-vtx->GetX();
512 Double_t dy = GetY()-vtx->GetY();
517 //______________________________________________________________________________
518 Double_t AliAODVertex::Error2DistanceToVertex(AliAODVertex *vtx) const
520 // error on the distance in 3D to another AliAODVertex
523 PhiAndThetaToVertex(vtx,phi,theta);
524 // error2 due to this vertex
525 Double_t error2 = RotatedCovMatrixXX(phi,theta);
526 // error2 due to vtx vertex
527 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi,theta);
529 return error2+error2vtx;
532 //______________________________________________________________________________
533 Double_t AliAODVertex::Error2DistanceXYToVertex(AliAODVertex *vtx) const
535 // error on the distance in XY to another AliAODVertex
538 PhiAndThetaToVertex(vtx,phi,theta);
539 // error2 due to this vertex
540 Double_t error2 = RotatedCovMatrixXX(phi);
541 // error2 due to vtx vertex
542 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi);
544 return error2+error2vtx;
547 //______________________________________________________________________________
548 template <class T, class P>
549 void AliAODVertex::PhiAndThetaToVertex(AliAODVertex *vtx, P &phi, T &theta) const
551 // rotation angles around z-axis (phi) and around new y-axis (theta)
552 // with which vtx is seen (used by RotatedCovMatrix... methods)
554 phi = TMath::Pi()+TMath::ATan2(-vtx->GetY()+GetY(),-vtx->GetX()+GetX());
555 Double_t vtxxphi = vtx->GetX()*TMath::Cos(phi)+vtx->GetY()*TMath::Sin(phi);
556 Double_t xphi = GetX()*TMath::Cos(phi)+GetY()*TMath::Sin(phi);
557 theta = TMath::ATan2(vtx->GetZ()-GetZ(),vtxxphi-xphi);
560 //______________________________________________________________________________
561 void AliAODVertex::PrintIndices() const
563 // Print indices of particles originating form this vertex
565 TRefArrayIter iter(&fDaughters);
566 while (TObject *daugh = iter.Next()) {
567 printf("Particle %p originates from this vertex.\n", static_cast<void*>(daugh));
571 //______________________________________________________________________________
572 const char* AliAODVertex::AsString() const
574 // Make a string describing this object
576 TString tmp(Form("%10s pos(%7.2f,%7.2f,%7.2f)",GetTypeName((AODVtx_t)GetType()),GetX(),GetY(),GetZ()));
578 if (GetType()==kPrimary || GetType()==kMainSPD || GetType()==kPileupSPD )
580 tmp += Form(" ncontrib %d chi2/ndf %4.1f",GetNContributors(),GetChi2perNDF());
584 if ( !fParent.GetObject() )
588 if ( fDaughters.GetEntriesFast() > 0 )
590 if ( fDaughters.GetEntriesFast() == 1 )
592 tmp += " origin of 1 particle";
596 tmp += Form(" origin of %2d particles",fDaughters.GetEntriesFast());
603 //______________________________________________________________________________
604 const char* AliAODVertex::GetTypeName(AODVtx_t type)
606 // Return an ASCII version of type
640 //______________________________________________________________________________
641 void AliAODVertex::Print(Option_t* /*option*/) const
643 // Print information of all data members
645 printf("Vertex position:\n");
646 printf(" x = %f\n", fPosition[0]);
647 printf(" y = %f\n", fPosition[1]);
648 printf(" z = %f\n", fPosition[2]);
649 printf(" parent particle: %p\n", static_cast<void*>(fParent.GetObject()));
650 printf(" origin of %d particles\n", fDaughters.GetEntriesFast());
651 printf(" vertex type %d\n", fType);
655 printf("Covariance matrix:\n");
656 printf(" %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n",
667 printf(" Chi^2/NDF = %f\n", fChi2perNDF);