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() :
44 // default constructor
46 fPosition[0] = fPosition[1] = fPosition[2] = -999.;
49 //______________________________________________________________________________
50 AliAODVertex::AliAODVertex(const Double_t position[3],
51 const Double_t covMatrix[6],
58 fChi2perNDF(chi2perNDF),
70 SetPosition(position);
71 if (covMatrix) SetCovMatrix(covMatrix);
75 //______________________________________________________________________________
76 AliAODVertex::AliAODVertex(const Float_t position[3],
77 const Float_t covMatrix[6],
85 fChi2perNDF(chi2perNDF),
97 SetPosition(position);
98 if (covMatrix) SetCovMatrix(covMatrix);
102 //______________________________________________________________________________
103 AliAODVertex::AliAODVertex(const Double_t position[3],
108 fChi2perNDF(chi2perNDF),
118 // constructor without covariance matrix
120 SetPosition(position);
124 //______________________________________________________________________________
125 AliAODVertex::AliAODVertex(const Float_t position[3],
127 Char_t vtype, Int_t nprong) :
129 fChi2perNDF(chi2perNDF),
139 // constructor without covariance matrix
141 SetPosition(position);
145 //______________________________________________________________________________
146 AliAODVertex::~AliAODVertex()
151 if (fNprong > 0) delete[] fProngs;
154 //______________________________________________________________________________
155 AliAODVertex::AliAODVertex(const AliAODVertex& vtx) :
157 fChi2perNDF(vtx.fChi2perNDF),
160 fNprong(vtx.fNprong),
161 fIprong(vtx.fIprong),
163 fParent(vtx.fParent),
164 fDaughters(vtx.fDaughters),
169 for (int i = 0; i < 3; i++)
170 fPosition[i] = vtx.fPosition[i];
172 if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
174 for (int i = 0; i < fNprong; i++) {
175 fProngs[i] = vtx.fProngs[i];
179 //______________________________________________________________________________
180 AliAODVertex& AliAODVertex::operator=(const AliAODVertex& vtx)
182 // Assignment operator
186 AliVVertex::operator=(vtx);
189 for (int i = 0; i < 3; i++)
190 fPosition[i] = vtx.fPosition[i];
192 fChi2perNDF = vtx.fChi2perNDF;
199 if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
202 fParent = vtx.fParent;
203 fDaughters = vtx.fDaughters;
204 fNprong = vtx.fNprong;
205 fIprong = vtx.fIprong;
208 for (int i = 0; i < fNprong; i++) {
209 fProngs[i] = vtx.fProngs[i];
216 //______________________________________________________________________________
217 void AliAODVertex::AddDaughter(TObject *daughter)
219 // Add reference to daughter track
221 if (fDaughters.GetEntries()==0) {
222 TRefArray* arr = &fDaughters;
223 new(arr)TRefArray(TProcessID::GetProcessWithUID(daughter));
225 fDaughters.Add(daughter);
227 if (fIprong < fNprong) {
228 fProngs[fIprong++] = daughter;
230 AliWarning("Number of daughters out of range !\n");
237 //______________________________________________________________________________
238 template <class T> void AliAODVertex::GetSigmaXYZ(T sigma[3]) const
240 // Return errors on vertex position in thrust frame
243 sigma[0]=fCovMatrix[3]; //GetCovXZ
244 sigma[1]=fCovMatrix[4]; //GetCovYZ
245 sigma[2]=fCovMatrix[5]; //GetCovZZ
247 sigma[0]=sigma[1]=sigma[2]=-999.;
250 for (int i = 0, j = 6; i < 3; i++) {
252 sigma[2-i] = fCovMatrix ? TMath::Sqrt(fCovMatrix[j]) : -999.;
257 //______________________________________________________________________________
258 Int_t AliAODVertex::GetNContributors() const
260 // Returns the number of tracks used to fit this vertex.
263 if (!strcmp(GetTitle(), "vertexer: 3D")) {
264 cont = fNContributors;
266 for (Int_t iDaug = 0; iDaug < GetNDaughters(); iDaug++) {
267 if (((AliAODTrack*)fDaughters.At(iDaug))->GetUsedForVtxFit()) cont++;
273 //______________________________________________________________________________
274 Bool_t AliAODVertex::HasDaughter(TObject *daughter) const
276 // Checks if the given daughter (particle) is part of this vertex.
278 TRefArrayIter iter(&fDaughters);
279 while (TObject *daugh = iter.Next()) {
280 if (daugh == daughter) return kTRUE;
285 for (int i = 0; i < fNprong; i++) {
286 if (fProngs[i].GetObject() == daughter) has = kTRUE;
292 //______________________________________________________________________________
293 Double_t AliAODVertex::RotatedCovMatrixXX(Double_t phi, Double_t theta) const
295 // XX term of covariance matrix after rotation by phi around z-axis
296 // and, then, by theta around new y-axis
299 //AliFatal("Covariance matrix not set");
303 Double_t covMatrix[6];
305 GetCovMatrix(covMatrix);
307 Double_t cp = TMath::Cos(phi);
308 Double_t sp = TMath::Sin(phi);
309 Double_t ct = TMath::Cos(theta);
310 Double_t st = TMath::Sin(theta);
312 covMatrix[0]*cp*cp*ct*ct // GetCovXX
313 +covMatrix[1]*2.*cp*sp*ct*ct // GetCovXY
314 +covMatrix[3]*2.*cp*ct*st // GetCovXZ
315 +covMatrix[2]*sp*sp*ct*ct // GetCovYY
316 +covMatrix[4]*2.*sp*ct*st // GetCovYZ
317 +covMatrix[5]*st*st; // GetCovZZ
320 //______________________________________________________________________________
321 Double_t AliAODVertex::RotatedCovMatrixXY(Double_t phi, Double_t theta) const
323 // XY term of covariance matrix after rotation by phi around z-axis
324 // and, then, by theta around new y-axis
327 //AliFatal("Covariance matrix not set");
331 Double_t covMatrix[6];
333 GetCovMatrix(covMatrix);
335 Double_t cp = TMath::Cos(phi);
336 Double_t sp = TMath::Sin(phi);
337 Double_t ct = TMath::Cos(theta);
338 Double_t st = TMath::Sin(theta);
340 -covMatrix[0]*cp*sp*ct // GetCovXX
341 +covMatrix[1]*ct*(cp*cp-sp*sp) // GetCovXY
342 -covMatrix[3]*sp*st // GetCovXZ
343 +covMatrix[2]*cp*sp*ct // GetCovYY
344 +covMatrix[4]*cp*st; // GetCovYZ
347 //______________________________________________________________________________
348 Double_t AliAODVertex::RotatedCovMatrixXZ(Double_t phi, Double_t theta) const
350 // XZ term of covariance matrix after rotation by phi around z-axis
351 // and, then, by theta around new y-axis
354 //AliFatal("Covariance matrix not set");
358 Double_t covMatrix[6];
360 GetCovMatrix(covMatrix);
362 Double_t cp = TMath::Cos(phi);
363 Double_t sp = TMath::Sin(phi);
364 Double_t ct = TMath::Cos(theta);
365 Double_t st = TMath::Sin(theta);
367 -covMatrix[0]*cp*cp*ct*st // GetCovXX
368 -covMatrix[1]*2.*cp*sp*ct*st // GetCovXY
369 +covMatrix[3]*cp*(ct*ct-st*st) // GetCovXZ
370 -covMatrix[2]*sp*sp*ct*st // GetCovYY
371 +covMatrix[4]*sp*(ct*ct-st*st) // GetCovYZ
372 +covMatrix[5]*ct*st; // GetCovZZ
375 //______________________________________________________________________________
376 Double_t AliAODVertex::RotatedCovMatrixYY(Double_t phi) const
378 // YY term of covariance matrix after rotation by phi around z-axis
379 // and, then, by theta around new y-axis
382 //AliFatal("Covariance matrix not set");
386 Double_t covMatrix[6];
388 GetCovMatrix(covMatrix);
390 Double_t cp = TMath::Cos(phi);
391 Double_t sp = TMath::Sin(phi);
393 covMatrix[0]*sp*sp // GetCovXX
394 -covMatrix[1]*2.*cp*sp // GetCovXY
395 +covMatrix[2]*cp*cp; // GetCovYY
398 //______________________________________________________________________________
399 Double_t AliAODVertex::RotatedCovMatrixYZ(Double_t phi, Double_t theta) const
401 // YZ term of covariance matrix after rotation by phi around z-axis
402 // and, then, by theta around new y-axis
405 //AliFatal("Covariance matrix not set");
409 Double_t covMatrix[6];
411 GetCovMatrix(covMatrix);
413 Double_t cp = TMath::Cos(phi);
414 Double_t sp = TMath::Sin(phi);
415 Double_t ct = TMath::Cos(theta);
416 Double_t st = TMath::Sin(theta);
418 covMatrix[0]*cp*sp*st // GetCovXX
419 +covMatrix[1]*st*(sp*sp-cp*cp) // GetCovXY
420 -covMatrix[3]*sp*ct // GetCovXZ
421 -covMatrix[2]*cp*sp*st // GetCovYY
422 +covMatrix[4]*cp*ct; // GetCovYZ
425 //______________________________________________________________________________
426 Double_t AliAODVertex::RotatedCovMatrixZZ(Double_t phi, Double_t theta) const
428 // ZZ 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);
442 Double_t ct = TMath::Cos(theta);
443 Double_t st = TMath::Sin(theta);
445 covMatrix[0]*cp*cp*st*st // GetCovXX
446 +covMatrix[1]*2.*cp*sp*st*st // GetCovXY
447 -covMatrix[3]*2.*cp*ct*st // GetCovXZ
448 +covMatrix[2]*sp*sp*st*st // GetCovYY
449 -covMatrix[4]*2.*sp*sp*ct*st // GetCovYZ
450 +covMatrix[5]*ct*ct; // GetCovZZ
453 //______________________________________________________________________________
454 Double_t AliAODVertex::DistanceToVertex(AliAODVertex *vtx) const
456 // distance in 3D to another AliAODVertex
458 Double_t dx = GetX()-vtx->GetX();
459 Double_t dy = GetY()-vtx->GetY();
460 Double_t dz = GetZ()-vtx->GetZ();
462 return TMath::Sqrt(dx*dx+dy*dy+dz*dz);
465 //______________________________________________________________________________
466 Double_t AliAODVertex::DistanceXYToVertex(AliAODVertex *vtx) const
468 // distance in XY to another AliAODVertex
470 Double_t dx = GetX()-vtx->GetX();
471 Double_t dy = GetY()-vtx->GetY();
473 return TMath::Sqrt(dx*dx+dy*dy);
476 //______________________________________________________________________________
477 Double_t AliAODVertex::ErrorDistanceToVertex(AliAODVertex *vtx) const
479 // error on the distance in 3D to another AliAODVertex
482 PhiAndThetaToVertex(vtx,phi,theta);
483 // error2 due to this vertex
484 Double_t error2 = RotatedCovMatrixXX(phi,theta);
485 // error2 due to vtx vertex
486 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi,theta);
488 return TMath::Sqrt(error2+error2vtx);
491 //______________________________________________________________________________
492 Double_t AliAODVertex::ErrorDistanceXYToVertex(AliAODVertex *vtx) const
494 // error on the distance in XY to another AliAODVertex
497 PhiAndThetaToVertex(vtx,phi,theta);
498 // error2 due to this vertex
499 Double_t error2 = RotatedCovMatrixXX(phi);
500 // error2 due to vtx vertex
501 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi);
503 return TMath::Sqrt(error2+error2vtx);
506 //______________________________________________________________________________
507 template <class T, class P>
508 void AliAODVertex::PhiAndThetaToVertex(AliAODVertex *vtx, P &phi, T &theta) const
510 // rotation angles around z-axis (phi) and around new y-axis (theta)
511 // with which vtx is seen (used by RotatedCovMatrix... methods)
513 phi = TMath::Pi()+TMath::ATan2(-vtx->GetY()+GetY(),-vtx->GetX()+GetX());
514 Double_t vtxxphi = vtx->GetX()*TMath::Cos(phi)+vtx->GetY()*TMath::Sin(phi);
515 Double_t xphi = GetX()*TMath::Cos(phi)+GetY()*TMath::Sin(phi);
516 theta = TMath::ATan2(vtx->GetZ()-GetZ(),vtxxphi-xphi);
519 //______________________________________________________________________________
520 void AliAODVertex::PrintIndices() const
522 // Print indices of particles originating form this vertex
524 TRefArrayIter iter(&fDaughters);
525 while (TObject *daugh = iter.Next()) {
526 printf("Particle %p originates from this vertex.\n", static_cast<void*>(daugh));
530 //______________________________________________________________________________
531 void AliAODVertex::Print(Option_t* /*option*/) const
533 // Print information of all data members
535 printf("Vertex position:\n");
536 printf(" x = %f\n", fPosition[0]);
537 printf(" y = %f\n", fPosition[1]);
538 printf(" z = %f\n", fPosition[2]);
539 printf(" parent particle: %p\n", static_cast<void*>(fParent.GetObject()));
540 printf(" origin of %d particles\n", fDaughters.GetEntriesFast());
541 printf(" vertex type %d\n", fType);
545 printf("Covariance matrix:\n");
546 printf(" %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n",
557 printf(" Chi^2/NDF = %f\n", fChi2perNDF);