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 //-------------------------------------------------------------------------
25 #include "AliAODVertex.h"
27 ClassImp(AliAODVertex)
29 //______________________________________________________________________________
30 AliAODVertex::AliAODVertex() :
38 // default constructor
40 fPosition[0] = fPosition[1] = fPosition[2] = -999.;
43 //______________________________________________________________________________
44 AliAODVertex::AliAODVertex(const Double_t position[3],
45 const Double_t covMatrix[6],
58 SetPosition(position);
59 if (covMatrix) SetCovMatrix(covMatrix);
62 //______________________________________________________________________________
63 AliAODVertex::AliAODVertex(const Float_t position[3],
64 const Float_t covMatrix[6],
77 SetPosition(position);
78 if (covMatrix) SetCovMatrix(covMatrix);
81 //______________________________________________________________________________
82 AliAODVertex::AliAODVertex(const Double_t position[3],
92 // constructor without covariance matrix
94 SetPosition(position);
97 //______________________________________________________________________________
98 AliAODVertex::AliAODVertex(const Float_t position[3],
108 // constructor without covariance matrix
110 SetPosition(position);
113 //______________________________________________________________________________
114 AliAODVertex::~AliAODVertex()
121 //______________________________________________________________________________
122 AliAODVertex::AliAODVertex(const AliAODVertex& vtx) :
126 fParent(vtx.fParent),
127 fDaughters(vtx.fDaughters),
132 for (int i = 0; i < 3; i++)
133 fPosition[i] = vtx.fPosition[i];
135 if (vtx.fCovMatrix) fCovMatrix=new AliAODVtxCov(*vtx.fCovMatrix);
138 //______________________________________________________________________________
139 AliAODVertex& AliAODVertex::operator=(const AliAODVertex& vtx)
141 // Assignment operator
145 TObject::operator=(vtx);
148 for (int i = 0; i < 3; i++)
149 fPosition[i] = vtx.fPosition[i];
156 if (vtx.fCovMatrix) fCovMatrix=new AliAODVtxCov(*vtx.fCovMatrix);
159 fParent = vtx.fParent;
160 fDaughters = vtx.fDaughters;
167 //______________________________________________________________________________
168 template <class T> void AliAODVertex::GetSigmaXYZ(T sigma[3]) const
170 // Return errors on vertex position in thrust frame
173 sigma[0]=fCovMatrix[3]; //GetCovXZ
174 sigma[1]=fCovMatrix[4]; //GetCovYZ
175 sigma[2]=fCovMatrix[5]; //GetCovZZ
177 sigma[0]=sigma[1]=sigma[2]=-999.;
180 for (int i = 0, j = 6; i < 3; i++) {
182 sigma[2-i] = fCovMatrix ? TMath::Sqrt(fCovMatrix[j]) : -999.;
187 //______________________________________________________________________________
188 Bool_t AliAODVertex::HasDaughter(TObject *daughter) const
190 // Checks if the given daughter (particle) is part of this vertex.
192 TRefArrayIter iter(&fDaughters);
193 while (TObject *daugh = iter.Next()) {
194 if (daugh == daughter) return kTRUE;
199 //______________________________________________________________________________
200 Double_t AliAODVertex::RotatedCovMatrixXX(Double_t phi, Double_t theta) const
202 // XX term of covariance matrix after rotation by phi around z-axis
203 // and, then, by theta around new y-axis
206 //AliFatal("Covariance matrix not set");
210 Double_t covMatrix[6];
212 GetCovMatrix(covMatrix);
214 Double_t cp = TMath::Cos(phi);
215 Double_t sp = TMath::Sin(phi);
216 Double_t ct = TMath::Cos(theta);
217 Double_t st = TMath::Sin(theta);
219 covMatrix[0]*cp*cp*ct*ct // GetCovXX
220 +covMatrix[1]*2.*cp*sp*ct*ct // GetCovXY
221 +covMatrix[3]*2.*cp*ct*st // GetCovXZ
222 +covMatrix[2]*sp*sp*ct*ct // GetCovYY
223 +covMatrix[4]*2.*sp*ct*st // GetCovYZ
224 +covMatrix[5]*st*st; // GetCovZZ
227 //______________________________________________________________________________
228 Double_t AliAODVertex::RotatedCovMatrixXY(Double_t phi, Double_t theta) const
230 // XY term of covariance matrix after rotation by phi around z-axis
231 // and, then, by theta around new y-axis
234 //AliFatal("Covariance matrix not set");
238 Double_t covMatrix[6];
240 GetCovMatrix(covMatrix);
242 Double_t cp = TMath::Cos(phi);
243 Double_t sp = TMath::Sin(phi);
244 Double_t ct = TMath::Cos(theta);
245 Double_t st = TMath::Sin(theta);
247 -covMatrix[0]*cp*sp*ct // GetCovXX
248 +covMatrix[1]*ct*(cp*cp-sp*sp) // GetCovXY
249 -covMatrix[3]*sp*st // GetCovXZ
250 +covMatrix[2]*cp*sp*ct // GetCovYY
251 +covMatrix[4]*cp*st; // GetCovYZ
254 //______________________________________________________________________________
255 Double_t AliAODVertex::RotatedCovMatrixXZ(Double_t phi, Double_t theta) const
257 // XZ term of covariance matrix after rotation by phi around z-axis
258 // and, then, by theta around new y-axis
261 //AliFatal("Covariance matrix not set");
265 Double_t covMatrix[6];
267 GetCovMatrix(covMatrix);
269 Double_t cp = TMath::Cos(phi);
270 Double_t sp = TMath::Sin(phi);
271 Double_t ct = TMath::Cos(theta);
272 Double_t st = TMath::Sin(theta);
274 -covMatrix[0]*cp*cp*ct*st // GetCovXX
275 -covMatrix[1]*2.*cp*sp*ct*st // GetCovXY
276 +covMatrix[3]*cp*(ct*ct-st*st) // GetCovXZ
277 -covMatrix[2]*sp*sp*ct*st // GetCovYY
278 +covMatrix[4]*sp*(ct*ct-st*st) // GetCovYZ
279 +covMatrix[5]*ct*st; // GetCovZZ
282 //______________________________________________________________________________
283 Double_t AliAODVertex::RotatedCovMatrixYY(Double_t phi) const
285 // YY term of covariance matrix after rotation by phi around z-axis
286 // and, then, by theta around new y-axis
289 //AliFatal("Covariance matrix not set");
293 Double_t covMatrix[6];
295 GetCovMatrix(covMatrix);
297 Double_t cp = TMath::Cos(phi);
298 Double_t sp = TMath::Sin(phi);
300 covMatrix[0]*sp*sp // GetCovXX
301 -covMatrix[1]*2.*cp*sp // GetCovXY
302 +covMatrix[2]*cp*cp; // GetCovYY
305 //______________________________________________________________________________
306 Double_t AliAODVertex::RotatedCovMatrixYZ(Double_t phi, Double_t theta) const
308 // YZ term of covariance matrix after rotation by phi around z-axis
309 // and, then, by theta around new y-axis
312 //AliFatal("Covariance matrix not set");
316 Double_t covMatrix[6];
318 GetCovMatrix(covMatrix);
320 Double_t cp = TMath::Cos(phi);
321 Double_t sp = TMath::Sin(phi);
322 Double_t ct = TMath::Cos(theta);
323 Double_t st = TMath::Sin(theta);
325 covMatrix[0]*cp*sp*st // GetCovXX
326 +covMatrix[1]*st*(sp*sp-cp*cp) // GetCovXY
327 -covMatrix[3]*sp*ct // GetCovXZ
328 -covMatrix[2]*cp*sp*st // GetCovYY
329 +covMatrix[4]*cp*ct; // GetCovYZ
332 //______________________________________________________________________________
333 Double_t AliAODVertex::RotatedCovMatrixZZ(Double_t phi, Double_t theta) const
335 // ZZ term of covariance matrix after rotation by phi around z-axis
336 // and, then, by theta around new y-axis
339 //AliFatal("Covariance matrix not set");
343 Double_t covMatrix[6];
345 GetCovMatrix(covMatrix);
347 Double_t cp = TMath::Cos(phi);
348 Double_t sp = TMath::Sin(phi);
349 Double_t ct = TMath::Cos(theta);
350 Double_t st = TMath::Sin(theta);
352 covMatrix[0]*cp*cp*st*st // GetCovXX
353 +covMatrix[1]*2.*cp*sp*st*st // GetCovXY
354 -covMatrix[3]*2.*cp*ct*st // GetCovXZ
355 +covMatrix[2]*sp*sp*st*st // GetCovYY
356 -covMatrix[4]*2.*sp*sp*ct*st // GetCovYZ
357 +covMatrix[5]*ct*ct; // GetCovZZ
360 //______________________________________________________________________________
361 Double_t AliAODVertex::DistanceToVertex(AliAODVertex *vtx) const
363 // distance in 3D to another AliAODVertex
365 Double_t dx = GetX()-vtx->GetX();
366 Double_t dy = GetY()-vtx->GetY();
367 Double_t dz = GetZ()-vtx->GetZ();
369 return TMath::Sqrt(dx*dx+dy*dy+dz*dz);
372 //______________________________________________________________________________
373 Double_t AliAODVertex::DistanceXYToVertex(AliAODVertex *vtx) const
375 // distance in XY to another AliAODVertex
377 Double_t dx = GetX()-vtx->GetX();
378 Double_t dy = GetY()-vtx->GetY();
380 return TMath::Sqrt(dx*dx+dy*dy);
383 //______________________________________________________________________________
384 Double_t AliAODVertex::ErrorDistanceToVertex(AliAODVertex *vtx) const
386 // error on the distance in 3D to another AliAODVertex
389 PhiAndThetaToVertex(vtx,phi,theta);
390 // error2 due to this vertex
391 Double_t error2 = RotatedCovMatrixXX(phi,theta);
392 // error2 due to vtx vertex
393 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi,theta);
395 return TMath::Sqrt(error2+error2vtx);
398 //______________________________________________________________________________
399 Double_t AliAODVertex::ErrorDistanceXYToVertex(AliAODVertex *vtx) const
401 // error on the distance in XY to another AliAODVertex
404 PhiAndThetaToVertex(vtx,phi,theta);
405 // error2 due to this vertex
406 Double_t error2 = RotatedCovMatrixXX(phi);
407 // error2 due to vtx vertex
408 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi);
410 return TMath::Sqrt(error2+error2vtx);
413 //______________________________________________________________________________
414 template <class T, class P>
415 void AliAODVertex::PhiAndThetaToVertex(AliAODVertex *vtx, P &phi, T &theta) const
417 // rotation angles around z-axis (phi) and around new y-axis (theta)
418 // with which vtx is seen (used by RotatedCovMatrix... methods)
420 phi = TMath::ATan2(vtx->GetY()-GetY(),vtx->GetX()-GetX());
421 Double_t vtxxphi = vtx->GetX()*TMath::Cos(phi)+vtx->GetY()*TMath::Sin(phi);
422 Double_t xphi = GetX()*TMath::Cos(phi)+GetY()*TMath::Sin(phi);
423 theta = TMath::ATan2(vtx->GetZ()-GetZ(),vtxxphi-xphi);
426 //______________________________________________________________________________
427 void AliAODVertex::PrintIndices() const
429 // Print indices of particles originating form this vertex
431 TRefArrayIter iter(&fDaughters);
432 while (TObject *daugh = iter.Next()) {
433 printf("Particle %p originates from this vertex.\n", daugh);
437 //______________________________________________________________________________
438 void AliAODVertex::Print(Option_t* /*option*/) const
440 // Print information of all data members
442 printf("Vertex position:\n");
443 printf(" x = %f\n", fPosition[0]);
444 printf(" y = %f\n", fPosition[1]);
445 printf(" z = %f\n", fPosition[2]);
446 printf(" parent particle: %p\n", fParent.GetObject());
447 printf(" origin of %d particles\n", fDaughters.GetEntriesFast());
448 printf(" vertex type %d\n", fType);
452 printf("Covariance matrix:\n");
453 printf(" %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n",
464 printf(" Chi^2 = %f\n", fChi2);
467 //-------------------------------------------------------------------------
468 // AOD track cov matrix base class
469 //-------------------------------------------------------------------------
471 ClassImp(AliAODVertex::AliAODVtxCov)
473 //______________________________________________________________________________
474 template <class T> void AliAODVertex::AliAODVtxCov::GetCovMatrix(T *cmat) const
477 // Returns the external cov matrix
479 cmat[ 0] = fDiag[ 0]*fDiag[ 0];
480 cmat[ 2] = fDiag[ 1]*fDiag[ 1];
481 cmat[ 5] = fDiag[ 2]*fDiag[ 2];
484 cmat[ 1] = fODia[ 0]*fDiag[ 0]*fDiag[ 1];
485 cmat[ 3] = fODia[ 1]*fDiag[ 0]*fDiag[ 2];
486 cmat[ 4] = fODia[ 2]*fDiag[ 1]*fDiag[ 2];
490 //______________________________________________________________________________
491 template <class T> void AliAODVertex::AliAODVtxCov::SetCovMatrix(T *cmat)
494 // Sets the external cov matrix
497 fDiag[ 0] = TMath::Sqrt(cmat[ 0]);
498 fDiag[ 1] = TMath::Sqrt(cmat[ 2]);
499 fDiag[ 2] = TMath::Sqrt(cmat[ 5]);
501 fODia[ 0] = cmat[ 1]/(fDiag[ 0]*fDiag[ 1]);
502 fODia[ 1] = cmat[ 3]/(fDiag[ 0]*fDiag[ 2]);
503 fODia[ 2] = cmat[ 4]/(fDiag[ 1]*fDiag[ 2]);
505 for(Int_t i=0; i< 3; ++i) {
506 fDiag[i]=-999.; fODia[i]=0.;}