]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAODVertex.cxx
Some more classes moved from libSTEER to libSTEERBase.
[u/mrichter/AliRoot.git] / STEER / AliAODVertex.cxx
CommitLineData
df9db588 1/**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18//-------------------------------------------------------------------------
19// AOD track base class
20// Base class for Analysis Object Data
21// Generic version
22// Author: Markus Oldenburg, CERN
23//-------------------------------------------------------------------------
24
25#include "AliAODVertex.h"
26
0657f082 27#include "AliAODTrack.h"
28
df9db588 29ClassImp(AliAODVertex)
30
31//______________________________________________________________________________
32AliAODVertex::AliAODVertex() :
33 TObject(),
0657f082 34 fChi2perNDF(-999.),
9f7c531f 35 fCovMatrix(NULL),
df9db588 36 fParent(0x0),
9f7c531f 37 fDaughters(),
38 fType(kUndef)
39 {
df9db588 40 // default constructor
41
42 fPosition[0] = fPosition[1] = fPosition[2] = -999.;
43}
44
45//______________________________________________________________________________
46AliAODVertex::AliAODVertex(const Double_t position[3],
31fd97b2 47 const Double_t covMatrix[6],
0657f082 48 Double_t chi2perNDF,
df9db588 49 TObject *parent,
50 Char_t vtype) :
51 TObject(),
0657f082 52 fChi2perNDF(chi2perNDF),
9f7c531f 53 fCovMatrix(NULL),
df9db588 54 fParent(parent),
9f7c531f 55 fDaughters(),
56 fType(vtype)
df9db588 57{
58 // constructor
59
60 SetPosition(position);
61 if (covMatrix) SetCovMatrix(covMatrix);
62}
63
64//______________________________________________________________________________
65AliAODVertex::AliAODVertex(const Float_t position[3],
66 const Float_t covMatrix[6],
0657f082 67 Double_t chi2perNDF,
df9db588 68 TObject *parent,
69 Char_t vtype) :
4d209fca 70
df9db588 71 TObject(),
0657f082 72 fChi2perNDF(chi2perNDF),
9f7c531f 73 fCovMatrix(NULL),
df9db588 74 fParent(parent),
9f7c531f 75 fDaughters(),
76 fType(vtype)
df9db588 77{
78 // constructor
79
80 SetPosition(position);
81 if (covMatrix) SetCovMatrix(covMatrix);
82}
83
84//______________________________________________________________________________
85AliAODVertex::AliAODVertex(const Double_t position[3],
0657f082 86 Double_t chi2perNDF,
df9db588 87 Char_t vtype) :
88 TObject(),
0657f082 89 fChi2perNDF(chi2perNDF),
9f7c531f 90 fCovMatrix(NULL),
df9db588 91 fParent(0x0),
9f7c531f 92 fDaughters(),
93 fType(vtype)
df9db588 94{
95 // constructor without covariance matrix
96
97 SetPosition(position);
98}
99
100//______________________________________________________________________________
101AliAODVertex::AliAODVertex(const Float_t position[3],
0657f082 102 Double_t chi2perNDF,
df9db588 103 Char_t vtype) :
104 TObject(),
0657f082 105 fChi2perNDF(chi2perNDF),
9f7c531f 106 fCovMatrix(NULL),
df9db588 107 fParent(0x0),
9f7c531f 108 fDaughters(),
109 fType(vtype)
df9db588 110{
111 // constructor without covariance matrix
112
113 SetPosition(position);
114}
115
116//______________________________________________________________________________
117AliAODVertex::~AliAODVertex()
118{
119 // Destructor
120
121 delete fCovMatrix;
122}
123
124//______________________________________________________________________________
125AliAODVertex::AliAODVertex(const AliAODVertex& vtx) :
126 TObject(vtx),
0657f082 127 fChi2perNDF(vtx.fChi2perNDF),
9f7c531f 128 fCovMatrix(NULL),
df9db588 129 fParent(vtx.fParent),
9f7c531f 130 fDaughters(vtx.fDaughters),
131 fType(vtx.fType)
df9db588 132{
133 // Copy constructor.
134
135 for (int i = 0; i < 3; i++)
136 fPosition[i] = vtx.fPosition[i];
137
5d62ce04 138 if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
df9db588 139}
140
141//______________________________________________________________________________
142AliAODVertex& AliAODVertex::operator=(const AliAODVertex& vtx)
143{
144 // Assignment operator
145 if (this != &vtx) {
146
147 // name and type
148 TObject::operator=(vtx);
149
150 //momentum
151 for (int i = 0; i < 3; i++)
152 fPosition[i] = vtx.fPosition[i];
153
0657f082 154 fChi2perNDF = vtx.fChi2perNDF;
9f7c531f 155
df9db588 156 //covariance matrix
157 delete fCovMatrix;
9f7c531f 158 fCovMatrix = NULL;
5d62ce04 159 if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
df9db588 160
161 //other stuff
df9db588 162 fParent = vtx.fParent;
163 fDaughters = vtx.fDaughters;
164 fType = vtx.fType;
165 }
166
167 return *this;
168}
169
170//______________________________________________________________________________
171template <class T> void AliAODVertex::GetSigmaXYZ(T sigma[3]) const
172{
173 // Return errors on vertex position in thrust frame
174
175 if(fCovMatrix) {
176 sigma[0]=fCovMatrix[3]; //GetCovXZ
177 sigma[1]=fCovMatrix[4]; //GetCovYZ
178 sigma[2]=fCovMatrix[5]; //GetCovZZ
179 } else
180 sigma[0]=sigma[1]=sigma[2]=-999.;
181
182 /*
183 for (int i = 0, j = 6; i < 3; i++) {
184 j -= i+1;
185 sigma[2-i] = fCovMatrix ? TMath::Sqrt(fCovMatrix[j]) : -999.;
186 }
187 */
188}
189
0657f082 190//______________________________________________________________________________
191Int_t AliAODVertex::GetNContributors() const
192{
193 // Returns the number of tracks used to fit this vertex.
194
195 Int_t cont = 0;
196
197 for (Int_t iDaug = 0; iDaug < GetNDaughters(); iDaug++) {
198 if (((AliAODTrack*)fDaughters.At(iDaug))->GetUsedForVtxFit()) cont++;
199 }
200
201 return cont;
202}
203
df9db588 204//______________________________________________________________________________
205Bool_t AliAODVertex::HasDaughter(TObject *daughter) const
206{
207 // Checks if the given daughter (particle) is part of this vertex.
208
209 TRefArrayIter iter(&fDaughters);
210 while (TObject *daugh = iter.Next()) {
211 if (daugh == daughter) return kTRUE;
212 }
213 return kFALSE;
214}
215
216//______________________________________________________________________________
217Double_t AliAODVertex::RotatedCovMatrixXX(Double_t phi, Double_t theta) const
218{
219 // XX term of covariance matrix after rotation by phi around z-axis
220 // and, then, by theta around new y-axis
221
222 if (!fCovMatrix) {
223 //AliFatal("Covariance matrix not set");
224 return -999.;
225 }
226
227 Double_t covMatrix[6];
228
229 GetCovMatrix(covMatrix);
230
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);
235 return
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
242}
243
244//______________________________________________________________________________
245Double_t AliAODVertex::RotatedCovMatrixXY(Double_t phi, Double_t theta) const
246{
247 // XY term of covariance matrix after rotation by phi around z-axis
248 // and, then, by theta around new y-axis
249
250 if (!fCovMatrix) {
251 //AliFatal("Covariance matrix not set");
252 return -999.;
253 }
254
255 Double_t covMatrix[6];
256
257 GetCovMatrix(covMatrix);
258
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);
263 return
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
269}
270
271//______________________________________________________________________________
272Double_t AliAODVertex::RotatedCovMatrixXZ(Double_t phi, Double_t theta) const
273{
274 // XZ term of covariance matrix after rotation by phi around z-axis
275 // and, then, by theta around new y-axis
276
277 if (!fCovMatrix) {
278 //AliFatal("Covariance matrix not set");
279 return -999.;
280 }
281
282 Double_t covMatrix[6];
283
284 GetCovMatrix(covMatrix);
285
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);
290 return
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
297}
298
299//______________________________________________________________________________
300Double_t AliAODVertex::RotatedCovMatrixYY(Double_t phi) const
301{
302 // YY term of covariance matrix after rotation by phi around z-axis
303 // and, then, by theta around new y-axis
304
305 if (!fCovMatrix) {
306 //AliFatal("Covariance matrix not set");
307 return -999.;
308 }
309
310 Double_t covMatrix[6];
311
312 GetCovMatrix(covMatrix);
313
314 Double_t cp = TMath::Cos(phi);
315 Double_t sp = TMath::Sin(phi);
316 return
317 covMatrix[0]*sp*sp // GetCovXX
318 -covMatrix[1]*2.*cp*sp // GetCovXY
319 +covMatrix[2]*cp*cp; // GetCovYY
320}
321
322//______________________________________________________________________________
323Double_t AliAODVertex::RotatedCovMatrixYZ(Double_t phi, Double_t theta) const
324{
325 // YZ term of covariance matrix after rotation by phi around z-axis
326 // and, then, by theta around new y-axis
327
328 if (!fCovMatrix) {
329 //AliFatal("Covariance matrix not set");
330 return -999.;
331 }
332
333 Double_t covMatrix[6];
334
335 GetCovMatrix(covMatrix);
336
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);
341 return
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
347}
348
349//______________________________________________________________________________
350Double_t AliAODVertex::RotatedCovMatrixZZ(Double_t phi, Double_t theta) const
351{
352 // ZZ term of covariance matrix after rotation by phi around z-axis
353 // and, then, by theta around new y-axis
354
355 if (!fCovMatrix) {
356 //AliFatal("Covariance matrix not set");
357 return -999.;
358 }
359
360 Double_t covMatrix[6];
361
362 GetCovMatrix(covMatrix);
363
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);
368 return
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
375}
376
377//______________________________________________________________________________
378Double_t AliAODVertex::DistanceToVertex(AliAODVertex *vtx) const
379{
380 // distance in 3D to another AliAODVertex
381
382 Double_t dx = GetX()-vtx->GetX();
383 Double_t dy = GetY()-vtx->GetY();
384 Double_t dz = GetZ()-vtx->GetZ();
385
386 return TMath::Sqrt(dx*dx+dy*dy+dz*dz);
387}
388
389//______________________________________________________________________________
390Double_t AliAODVertex::DistanceXYToVertex(AliAODVertex *vtx) const
391{
392 // distance in XY to another AliAODVertex
393
394 Double_t dx = GetX()-vtx->GetX();
395 Double_t dy = GetY()-vtx->GetY();
396
397 return TMath::Sqrt(dx*dx+dy*dy);
398}
399
400//______________________________________________________________________________
401Double_t AliAODVertex::ErrorDistanceToVertex(AliAODVertex *vtx) const
402{
403 // error on the distance in 3D to another AliAODVertex
404
405 Double_t phi,theta;
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);
411
412 return TMath::Sqrt(error2+error2vtx);
413}
414
415//______________________________________________________________________________
416Double_t AliAODVertex::ErrorDistanceXYToVertex(AliAODVertex *vtx) const
417{
418 // error on the distance in XY to another AliAODVertex
419
420 Double_t phi,theta;
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);
426
427 return TMath::Sqrt(error2+error2vtx);
428}
429
430//______________________________________________________________________________
431template <class T, class P>
432void AliAODVertex::PhiAndThetaToVertex(AliAODVertex *vtx, P &phi, T &theta) const
433{
434 // rotation angles around z-axis (phi) and around new y-axis (theta)
435 // with which vtx is seen (used by RotatedCovMatrix... methods)
436
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);
441}
442
443//______________________________________________________________________________
444void AliAODVertex::PrintIndices() const
445{
446 // Print indices of particles originating form this vertex
447
448 TRefArrayIter iter(&fDaughters);
449 while (TObject *daugh = iter.Next()) {
450 printf("Particle %p originates from this vertex.\n", daugh);
451 }
452}
453
454//______________________________________________________________________________
455void AliAODVertex::Print(Option_t* /*option*/) const
456{
457 // Print information of all data members
458
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);
466
467 /*
468 if (fCovMatrix) {
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",
471 fCovMatrix[0],
472 fCovMatrix[1],
473 fCovMatrix[3],
474 fCovMatrix[1],
475 fCovMatrix[2],
476 fCovMatrix[4],
477 fCovMatrix[3],
478 fCovMatrix[4],
479 fCovMatrix[5]);
480 } */
0657f082 481 printf(" Chi^2/NDF = %f\n", fChi2perNDF);
df9db588 482}
483