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->SetName(GetName());
209 // NOTE title is not allowed to be set, as GetNContributors
210 // relies on the title to use the references which are not copied here
212 // to insure the main vertex retains the ncontributors information
213 // (which is otherwise computed dynamically from
214 // references to tracks, which is not kept in the returned object)
216 v->SetNContributors(fNContributors);
221 //______________________________________________________________________________
222 AliAODVertex& AliAODVertex::operator=(const AliAODVertex& vtx)
224 // Assignment operator
228 AliVVertex::operator=(vtx);
231 for (int i = 0; i < 3; i++)
232 fPosition[i] = vtx.fPosition[i];
234 fChi2perNDF = vtx.fChi2perNDF;
242 if (vtx.fCovMatrix) fCovMatrix = new AliAODRedCov<3>(*vtx.fCovMatrix);
245 fNContributors = vtx.fNContributors;
246 fParent = vtx.fParent;
247 fDaughters = vtx.fDaughters;
248 fNprong = vtx.fNprong;
249 fIprong = vtx.fIprong;
252 for (int i = 0; i < fNprong; i++) {
253 fProngs[i] = vtx.fProngs[i];
260 //______________________________________________________________________________
261 void AliAODVertex::AddDaughter(TObject *daughter)
263 // Add reference to daughter track
265 if (fDaughters.GetEntries()==0) {
266 TRefArray* arr = &fDaughters;
267 new(arr)TRefArray(TProcessID::GetProcessWithUID(daughter));
269 fDaughters.Add(daughter);
271 if (fIprong < fNprong) {
272 fProngs[fIprong++] = daughter;
274 AliWarning("Number of daughters out of range !\n");
281 //______________________________________________________________________________
282 template <class T> void AliAODVertex::GetSigmaXYZ(T sigma[3]) const
284 // Return errors on vertex position in thrust frame
287 sigma[0]=fCovMatrix[3]; //GetCovXZ
288 sigma[1]=fCovMatrix[4]; //GetCovYZ
289 sigma[2]=fCovMatrix[5]; //GetCovZZ
291 sigma[0]=sigma[1]=sigma[2]=-999.;
294 for (int i = 0, j = 6; i < 3; i++) {
296 sigma[2-i] = fCovMatrix ? TMath::Sqrt(fCovMatrix[j]) : -999.;
301 //______________________________________________________________________________
302 Int_t AliAODVertex::GetNContributors() const
304 // Returns the number of tracks used to fit this vertex.
307 TString vtitle = GetTitle();
308 if (!vtitle.Contains("VertexerTracks") || vtitle.Contains("TracksNoConstraint") || fType==kPileupTracks
310 cont = fNContributors;
312 for (Int_t iDaug = 0; iDaug < GetNDaughters(); iDaug++) {
313 AliAODTrack* aodT = dynamic_cast<AliAODTrack*>(fDaughters.At(iDaug));
315 if (aodT->GetUsedForPrimVtxFit()) cont++;
317 // the constraint adds another DOF
318 if(vtitle.Contains("VertexerTracksWithConstraint"))cont++;
323 //______________________________________________________________________________
324 Bool_t AliAODVertex::HasDaughter(TObject *daughter) const
326 // Checks if the given daughter (particle) is part of this vertex.
328 TRefArrayIter iter(&fDaughters);
329 while (TObject *daugh = iter.Next()) {
330 if (daugh == daughter) return kTRUE;
335 for (int i = 0; i < fNprong; i++) {
336 if (fProngs[i].GetObject() == daughter) has = kTRUE;
342 //______________________________________________________________________________
343 Double_t AliAODVertex::RotatedCovMatrixXX(Double_t phi, Double_t theta) const
345 // XX term of covariance matrix after rotation by phi around z-axis
346 // and, then, by theta around new y-axis
349 //AliFatal("Covariance matrix not set");
353 Double_t covMatrix[6];
355 GetCovMatrix(covMatrix);
357 Double_t cp = TMath::Cos(phi);
358 Double_t sp = TMath::Sin(phi);
359 Double_t ct = TMath::Cos(theta);
360 Double_t st = TMath::Sin(theta);
362 covMatrix[0]*cp*cp*ct*ct // GetCovXX
363 +covMatrix[1]*2.*cp*sp*ct*ct // GetCovXY
364 +covMatrix[3]*2.*cp*ct*st // GetCovXZ
365 +covMatrix[2]*sp*sp*ct*ct // GetCovYY
366 +covMatrix[4]*2.*sp*ct*st // GetCovYZ
367 +covMatrix[5]*st*st; // GetCovZZ
370 //______________________________________________________________________________
371 Double_t AliAODVertex::RotatedCovMatrixXY(Double_t phi, Double_t theta) const
373 // XY term of covariance matrix after rotation by phi around z-axis
374 // and, then, by theta around new y-axis
377 //AliFatal("Covariance matrix not set");
381 Double_t covMatrix[6];
383 GetCovMatrix(covMatrix);
385 Double_t cp = TMath::Cos(phi);
386 Double_t sp = TMath::Sin(phi);
387 Double_t ct = TMath::Cos(theta);
388 Double_t st = TMath::Sin(theta);
390 -covMatrix[0]*cp*sp*ct // GetCovXX
391 +covMatrix[1]*ct*(cp*cp-sp*sp) // GetCovXY
392 -covMatrix[3]*sp*st // GetCovXZ
393 +covMatrix[2]*cp*sp*ct // GetCovYY
394 +covMatrix[4]*cp*st; // GetCovYZ
397 //______________________________________________________________________________
398 Double_t AliAODVertex::RotatedCovMatrixXZ(Double_t phi, Double_t theta) const
400 // XZ term of covariance matrix after rotation by phi around z-axis
401 // and, then, by theta around new y-axis
404 //AliFatal("Covariance matrix not set");
408 Double_t covMatrix[6];
410 GetCovMatrix(covMatrix);
412 Double_t cp = TMath::Cos(phi);
413 Double_t sp = TMath::Sin(phi);
414 Double_t ct = TMath::Cos(theta);
415 Double_t st = TMath::Sin(theta);
417 -covMatrix[0]*cp*cp*ct*st // GetCovXX
418 -covMatrix[1]*2.*cp*sp*ct*st // GetCovXY
419 +covMatrix[3]*cp*(ct*ct-st*st) // GetCovXZ
420 -covMatrix[2]*sp*sp*ct*st // GetCovYY
421 +covMatrix[4]*sp*(ct*ct-st*st) // GetCovYZ
422 +covMatrix[5]*ct*st; // GetCovZZ
425 //______________________________________________________________________________
426 Double_t AliAODVertex::RotatedCovMatrixYY(Double_t phi) const
428 // YY term of covariance matrix after rotation by phi around z-axis
429 // and, then, by theta around new y-axis
432 //AliFatal("Covariance matrix not set");
436 Double_t covMatrix[6];
438 GetCovMatrix(covMatrix);
440 Double_t cp = TMath::Cos(phi);
441 Double_t sp = TMath::Sin(phi);
443 covMatrix[0]*sp*sp // GetCovXX
444 -covMatrix[1]*2.*cp*sp // GetCovXY
445 +covMatrix[2]*cp*cp; // GetCovYY
448 //______________________________________________________________________________
449 Double_t AliAODVertex::RotatedCovMatrixYZ(Double_t phi, Double_t theta) const
451 // YZ term of covariance matrix after rotation by phi around z-axis
452 // and, then, by theta around new y-axis
455 //AliFatal("Covariance matrix not set");
459 Double_t covMatrix[6];
461 GetCovMatrix(covMatrix);
463 Double_t cp = TMath::Cos(phi);
464 Double_t sp = TMath::Sin(phi);
465 Double_t ct = TMath::Cos(theta);
466 Double_t st = TMath::Sin(theta);
468 covMatrix[0]*cp*sp*st // GetCovXX
469 +covMatrix[1]*st*(sp*sp-cp*cp) // GetCovXY
470 -covMatrix[3]*sp*ct // GetCovXZ
471 -covMatrix[2]*cp*sp*st // GetCovYY
472 +covMatrix[4]*cp*ct; // GetCovYZ
475 //______________________________________________________________________________
476 Double_t AliAODVertex::RotatedCovMatrixZZ(Double_t phi, Double_t theta) const
478 // ZZ term of covariance matrix after rotation by phi around z-axis
479 // and, then, by theta around new y-axis
482 //AliFatal("Covariance matrix not set");
486 Double_t covMatrix[6];
488 GetCovMatrix(covMatrix);
490 Double_t cp = TMath::Cos(phi);
491 Double_t sp = TMath::Sin(phi);
492 Double_t ct = TMath::Cos(theta);
493 Double_t st = TMath::Sin(theta);
495 covMatrix[0]*cp*cp*st*st // GetCovXX
496 +covMatrix[1]*2.*cp*sp*st*st // GetCovXY
497 -covMatrix[3]*2.*cp*ct*st // GetCovXZ
498 +covMatrix[2]*sp*sp*st*st // GetCovYY
499 -covMatrix[4]*2.*sp*sp*ct*st // GetCovYZ
500 +covMatrix[5]*ct*ct; // GetCovZZ
503 //______________________________________________________________________________
504 Double_t AliAODVertex::Distance2ToVertex(const AliAODVertex *vtx) const
506 // distance in 3D to another AliAODVertex
508 Double_t dx = GetX()-vtx->GetX();
509 Double_t dy = GetY()-vtx->GetY();
510 Double_t dz = GetZ()-vtx->GetZ();
512 return dx*dx+dy*dy+dz*dz;
515 //______________________________________________________________________________
516 Double_t AliAODVertex::DistanceXY2ToVertex(const AliAODVertex *vtx) const
518 // distance in XY to another AliAODVertex
520 Double_t dx = GetX()-vtx->GetX();
521 Double_t dy = GetY()-vtx->GetY();
526 //______________________________________________________________________________
527 Double_t AliAODVertex::Error2DistanceToVertex(AliAODVertex *vtx) const
529 // error on the distance in 3D to another AliAODVertex
532 PhiAndThetaToVertex(vtx,phi,theta);
533 // error2 due to this vertex
534 Double_t error2 = RotatedCovMatrixXX(phi,theta);
535 // error2 due to vtx vertex
536 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi,theta);
538 return error2+error2vtx;
541 //______________________________________________________________________________
542 Double_t AliAODVertex::Error2DistanceXYToVertex(AliAODVertex *vtx) const
544 // error on the distance in XY to another AliAODVertex
547 PhiAndThetaToVertex(vtx,phi,theta);
548 // error2 due to this vertex
549 Double_t error2 = RotatedCovMatrixXX(phi);
550 // error2 due to vtx vertex
551 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi);
553 return error2+error2vtx;
556 //______________________________________________________________________________
557 template <class T, class P>
558 void AliAODVertex::PhiAndThetaToVertex(AliAODVertex *vtx, P &phi, T &theta) const
560 // rotation angles around z-axis (phi) and around new y-axis (theta)
561 // with which vtx is seen (used by RotatedCovMatrix... methods)
563 phi = TMath::Pi()+TMath::ATan2(-vtx->GetY()+GetY(),-vtx->GetX()+GetX());
564 Double_t vtxxphi = vtx->GetX()*TMath::Cos(phi)+vtx->GetY()*TMath::Sin(phi);
565 Double_t xphi = GetX()*TMath::Cos(phi)+GetY()*TMath::Sin(phi);
566 theta = TMath::ATan2(vtx->GetZ()-GetZ(),vtxxphi-xphi);
569 //______________________________________________________________________________
570 void AliAODVertex::PrintIndices() const
572 // Print indices of particles originating form this vertex
574 TRefArrayIter iter(&fDaughters);
575 while (TObject *daugh = iter.Next()) {
576 printf("Particle %p originates from this vertex.\n", static_cast<void*>(daugh));
580 //______________________________________________________________________________
581 const char* AliAODVertex::AsString() const
583 // Make a string describing this object
585 TString tmp(Form("%10s pos(%7.2f,%7.2f,%7.2f)",GetTypeName((AODVtx_t)GetType()),GetX(),GetY(),GetZ()));
587 if (GetType()==kPrimary || GetType()==kMainSPD || GetType()==kPileupSPD )
589 tmp += Form(" ncontrib %d chi2/ndf %4.1f",GetNContributors(),GetChi2perNDF());
593 if ( !fParent.GetObject() )
597 if ( fDaughters.GetEntriesFast() > 0 )
599 if ( fDaughters.GetEntriesFast() == 1 )
601 tmp += " origin of 1 particle";
605 tmp += Form(" origin of %2d particles",fDaughters.GetEntriesFast());
612 //______________________________________________________________________________
613 const char* AliAODVertex::GetTypeName(AODVtx_t type)
615 // Return an ASCII version of type
649 //______________________________________________________________________________
650 void AliAODVertex::Print(Option_t* /*option*/) const
652 // Print information of all data members
654 printf("Vertex position:\n");
655 printf(" x = %f\n", fPosition[0]);
656 printf(" y = %f\n", fPosition[1]);
657 printf(" z = %f\n", fPosition[2]);
658 printf(" parent particle: %p\n", static_cast<void*>(fParent.GetObject()));
659 printf(" origin of %d particles\n", fDaughters.GetEntriesFast());
660 printf(" vertex type %d\n", fType);
664 printf("Covariance matrix:\n");
665 printf(" %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n",
676 printf(" Chi^2/NDF = %f\n", fChi2perNDF);