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 #include "AliAODTrack.h"
29 ClassImp(AliAODVertex)
31 //______________________________________________________________________________
32 AliAODVertex::AliAODVertex() :
40 // default constructor
42 fPosition[0] = fPosition[1] = fPosition[2] = -999.;
45 //______________________________________________________________________________
46 AliAODVertex::AliAODVertex(const Double_t position[3],
47 const Double_t covMatrix[6],
52 fChi2perNDF(chi2perNDF),
60 SetPosition(position);
61 if (covMatrix) SetCovMatrix(covMatrix);
64 //______________________________________________________________________________
65 AliAODVertex::AliAODVertex(const Float_t position[3],
66 const Float_t covMatrix[6],
72 fChi2perNDF(chi2perNDF),
80 SetPosition(position);
81 if (covMatrix) SetCovMatrix(covMatrix);
84 //______________________________________________________________________________
85 AliAODVertex::AliAODVertex(const Double_t position[3],
89 fChi2perNDF(chi2perNDF),
95 // constructor without covariance matrix
97 SetPosition(position);
100 //______________________________________________________________________________
101 AliAODVertex::AliAODVertex(const Float_t position[3],
105 fChi2perNDF(chi2perNDF),
111 // constructor without covariance matrix
113 SetPosition(position);
116 //______________________________________________________________________________
117 AliAODVertex::~AliAODVertex()
124 //______________________________________________________________________________
125 AliAODVertex::AliAODVertex(const AliAODVertex& vtx) :
127 fChi2perNDF(vtx.fChi2perNDF),
129 fParent(vtx.fParent),
130 fDaughters(vtx.fDaughters),
135 for (int i = 0; i < 3; i++)
136 fPosition[i] = vtx.fPosition[i];
138 if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
141 //______________________________________________________________________________
142 AliAODVertex& AliAODVertex::operator=(const AliAODVertex& vtx)
144 // Assignment operator
148 TObject::operator=(vtx);
151 for (int i = 0; i < 3; i++)
152 fPosition[i] = vtx.fPosition[i];
154 fChi2perNDF = vtx.fChi2perNDF;
159 if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
162 fParent = vtx.fParent;
163 fDaughters = vtx.fDaughters;
170 //______________________________________________________________________________
171 template <class T> void AliAODVertex::GetSigmaXYZ(T sigma[3]) const
173 // Return errors on vertex position in thrust frame
176 sigma[0]=fCovMatrix[3]; //GetCovXZ
177 sigma[1]=fCovMatrix[4]; //GetCovYZ
178 sigma[2]=fCovMatrix[5]; //GetCovZZ
180 sigma[0]=sigma[1]=sigma[2]=-999.;
183 for (int i = 0, j = 6; i < 3; i++) {
185 sigma[2-i] = fCovMatrix ? TMath::Sqrt(fCovMatrix[j]) : -999.;
190 //______________________________________________________________________________
191 Int_t AliAODVertex::GetNContributors() const
193 // Returns the number of tracks used to fit this vertex.
197 for (Int_t iDaug = 0; iDaug < GetNDaughters(); iDaug++) {
198 if (((AliAODTrack*)fDaughters.At(iDaug))->GetUsedForVtxFit()) cont++;
204 //______________________________________________________________________________
205 Bool_t AliAODVertex::HasDaughter(TObject *daughter) const
207 // Checks if the given daughter (particle) is part of this vertex.
209 TRefArrayIter iter(&fDaughters);
210 while (TObject *daugh = iter.Next()) {
211 if (daugh == daughter) return kTRUE;
216 //______________________________________________________________________________
217 Double_t AliAODVertex::RotatedCovMatrixXX(Double_t phi, Double_t theta) const
219 // XX term of covariance matrix after rotation by phi around z-axis
220 // and, then, by theta around new y-axis
223 //AliFatal("Covariance matrix not set");
227 Double_t covMatrix[6];
229 GetCovMatrix(covMatrix);
231 Double_t cp = TMath::Cos(phi);
232 Double_t sp = TMath::Sin(phi);
233 Double_t ct = TMath::Cos(theta);
234 Double_t st = TMath::Sin(theta);
236 covMatrix[0]*cp*cp*ct*ct // GetCovXX
237 +covMatrix[1]*2.*cp*sp*ct*ct // GetCovXY
238 +covMatrix[3]*2.*cp*ct*st // GetCovXZ
239 +covMatrix[2]*sp*sp*ct*ct // GetCovYY
240 +covMatrix[4]*2.*sp*ct*st // GetCovYZ
241 +covMatrix[5]*st*st; // GetCovZZ
244 //______________________________________________________________________________
245 Double_t AliAODVertex::RotatedCovMatrixXY(Double_t phi, Double_t theta) const
247 // XY term of covariance matrix after rotation by phi around z-axis
248 // and, then, by theta around new y-axis
251 //AliFatal("Covariance matrix not set");
255 Double_t covMatrix[6];
257 GetCovMatrix(covMatrix);
259 Double_t cp = TMath::Cos(phi);
260 Double_t sp = TMath::Sin(phi);
261 Double_t ct = TMath::Cos(theta);
262 Double_t st = TMath::Sin(theta);
264 -covMatrix[0]*cp*sp*ct // GetCovXX
265 +covMatrix[1]*ct*(cp*cp-sp*sp) // GetCovXY
266 -covMatrix[3]*sp*st // GetCovXZ
267 +covMatrix[2]*cp*sp*ct // GetCovYY
268 +covMatrix[4]*cp*st; // GetCovYZ
271 //______________________________________________________________________________
272 Double_t AliAODVertex::RotatedCovMatrixXZ(Double_t phi, Double_t theta) const
274 // XZ term of covariance matrix after rotation by phi around z-axis
275 // and, then, by theta around new y-axis
278 //AliFatal("Covariance matrix not set");
282 Double_t covMatrix[6];
284 GetCovMatrix(covMatrix);
286 Double_t cp = TMath::Cos(phi);
287 Double_t sp = TMath::Sin(phi);
288 Double_t ct = TMath::Cos(theta);
289 Double_t st = TMath::Sin(theta);
291 -covMatrix[0]*cp*cp*ct*st // GetCovXX
292 -covMatrix[1]*2.*cp*sp*ct*st // GetCovXY
293 +covMatrix[3]*cp*(ct*ct-st*st) // GetCovXZ
294 -covMatrix[2]*sp*sp*ct*st // GetCovYY
295 +covMatrix[4]*sp*(ct*ct-st*st) // GetCovYZ
296 +covMatrix[5]*ct*st; // GetCovZZ
299 //______________________________________________________________________________
300 Double_t AliAODVertex::RotatedCovMatrixYY(Double_t phi) const
302 // YY term of covariance matrix after rotation by phi around z-axis
303 // and, then, by theta around new y-axis
306 //AliFatal("Covariance matrix not set");
310 Double_t covMatrix[6];
312 GetCovMatrix(covMatrix);
314 Double_t cp = TMath::Cos(phi);
315 Double_t sp = TMath::Sin(phi);
317 covMatrix[0]*sp*sp // GetCovXX
318 -covMatrix[1]*2.*cp*sp // GetCovXY
319 +covMatrix[2]*cp*cp; // GetCovYY
322 //______________________________________________________________________________
323 Double_t AliAODVertex::RotatedCovMatrixYZ(Double_t phi, Double_t theta) const
325 // YZ term of covariance matrix after rotation by phi around z-axis
326 // and, then, by theta around new y-axis
329 //AliFatal("Covariance matrix not set");
333 Double_t covMatrix[6];
335 GetCovMatrix(covMatrix);
337 Double_t cp = TMath::Cos(phi);
338 Double_t sp = TMath::Sin(phi);
339 Double_t ct = TMath::Cos(theta);
340 Double_t st = TMath::Sin(theta);
342 covMatrix[0]*cp*sp*st // GetCovXX
343 +covMatrix[1]*st*(sp*sp-cp*cp) // GetCovXY
344 -covMatrix[3]*sp*ct // GetCovXZ
345 -covMatrix[2]*cp*sp*st // GetCovYY
346 +covMatrix[4]*cp*ct; // GetCovYZ
349 //______________________________________________________________________________
350 Double_t AliAODVertex::RotatedCovMatrixZZ(Double_t phi, Double_t theta) const
352 // ZZ term of covariance matrix after rotation by phi around z-axis
353 // and, then, by theta around new y-axis
356 //AliFatal("Covariance matrix not set");
360 Double_t covMatrix[6];
362 GetCovMatrix(covMatrix);
364 Double_t cp = TMath::Cos(phi);
365 Double_t sp = TMath::Sin(phi);
366 Double_t ct = TMath::Cos(theta);
367 Double_t st = TMath::Sin(theta);
369 covMatrix[0]*cp*cp*st*st // GetCovXX
370 +covMatrix[1]*2.*cp*sp*st*st // GetCovXY
371 -covMatrix[3]*2.*cp*ct*st // GetCovXZ
372 +covMatrix[2]*sp*sp*st*st // GetCovYY
373 -covMatrix[4]*2.*sp*sp*ct*st // GetCovYZ
374 +covMatrix[5]*ct*ct; // GetCovZZ
377 //______________________________________________________________________________
378 Double_t AliAODVertex::DistanceToVertex(AliAODVertex *vtx) const
380 // distance in 3D to another AliAODVertex
382 Double_t dx = GetX()-vtx->GetX();
383 Double_t dy = GetY()-vtx->GetY();
384 Double_t dz = GetZ()-vtx->GetZ();
386 return TMath::Sqrt(dx*dx+dy*dy+dz*dz);
389 //______________________________________________________________________________
390 Double_t AliAODVertex::DistanceXYToVertex(AliAODVertex *vtx) const
392 // distance in XY to another AliAODVertex
394 Double_t dx = GetX()-vtx->GetX();
395 Double_t dy = GetY()-vtx->GetY();
397 return TMath::Sqrt(dx*dx+dy*dy);
400 //______________________________________________________________________________
401 Double_t AliAODVertex::ErrorDistanceToVertex(AliAODVertex *vtx) const
403 // error on the distance in 3D to another AliAODVertex
406 PhiAndThetaToVertex(vtx,phi,theta);
407 // error2 due to this vertex
408 Double_t error2 = RotatedCovMatrixXX(phi,theta);
409 // error2 due to vtx vertex
410 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi,theta);
412 return TMath::Sqrt(error2+error2vtx);
415 //______________________________________________________________________________
416 Double_t AliAODVertex::ErrorDistanceXYToVertex(AliAODVertex *vtx) const
418 // error on the distance in XY to another AliAODVertex
421 PhiAndThetaToVertex(vtx,phi,theta);
422 // error2 due to this vertex
423 Double_t error2 = RotatedCovMatrixXX(phi);
424 // error2 due to vtx vertex
425 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi);
427 return TMath::Sqrt(error2+error2vtx);
430 //______________________________________________________________________________
431 template <class T, class P>
432 void AliAODVertex::PhiAndThetaToVertex(AliAODVertex *vtx, P &phi, T &theta) const
434 // rotation angles around z-axis (phi) and around new y-axis (theta)
435 // with which vtx is seen (used by RotatedCovMatrix... methods)
437 phi = TMath::ATan2(vtx->GetY()-GetY(),vtx->GetX()-GetX());
438 Double_t vtxxphi = vtx->GetX()*TMath::Cos(phi)+vtx->GetY()*TMath::Sin(phi);
439 Double_t xphi = GetX()*TMath::Cos(phi)+GetY()*TMath::Sin(phi);
440 theta = TMath::ATan2(vtx->GetZ()-GetZ(),vtxxphi-xphi);
443 //______________________________________________________________________________
444 void AliAODVertex::PrintIndices() const
446 // Print indices of particles originating form this vertex
448 TRefArrayIter iter(&fDaughters);
449 while (TObject *daugh = iter.Next()) {
450 printf("Particle %p originates from this vertex.\n", daugh);
454 //______________________________________________________________________________
455 void AliAODVertex::Print(Option_t* /*option*/) const
457 // Print information of all data members
459 printf("Vertex position:\n");
460 printf(" x = %f\n", fPosition[0]);
461 printf(" y = %f\n", fPosition[1]);
462 printf(" z = %f\n", fPosition[2]);
463 printf(" parent particle: %p\n", fParent.GetObject());
464 printf(" origin of %d particles\n", fDaughters.GetEntriesFast());
465 printf(" vertex type %d\n", fType);
469 printf("Covariance matrix:\n");
470 printf(" %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n",
481 printf(" Chi^2/NDF = %f\n", fChi2perNDF);