]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAODVertex.cxx
Merge branch 'devel'
[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
bdd011d6 23// Inheritance from AliVVertex: A. Dainese
df9db588 24//-------------------------------------------------------------------------
25
26#include "AliAODVertex.h"
0657f082 27#include "AliAODTrack.h"
28
df9db588 29ClassImp(AliAODVertex)
30
31//______________________________________________________________________________
32AliAODVertex::AliAODVertex() :
bdd011d6 33 AliVVertex(),
0657f082 34 fChi2perNDF(-999.),
02153d58 35 fID(-1),
9333290e 36 fType(kUndef),
bca58dd7 37 fNprong(0),
38 fIprong(0),
d999f2e6 39 fNContributors(0),
9f7c531f 40 fCovMatrix(NULL),
0f09edc3 41 fParent(),
bca58dd7 42 fDaughters(),
43 fProngs(NULL)
9333290e 44 {
df9db588 45 // default constructor
46
47 fPosition[0] = fPosition[1] = fPosition[2] = -999.;
48}
49
50//______________________________________________________________________________
51AliAODVertex::AliAODVertex(const Double_t position[3],
31fd97b2 52 const Double_t covMatrix[6],
0657f082 53 Double_t chi2perNDF,
df9db588 54 TObject *parent,
02153d58 55 Short_t id,
bca58dd7 56 Char_t vtype,
57 Int_t nprong) :
bdd011d6 58 AliVVertex(),
0657f082 59 fChi2perNDF(chi2perNDF),
02153d58 60 fID(id),
9333290e 61 fType(vtype),
bca58dd7 62 fNprong(nprong),
63 fIprong(0),
d999f2e6 64 fNContributors(0),
9f7c531f 65 fCovMatrix(NULL),
df9db588 66 fParent(parent),
bca58dd7 67 fDaughters(),
68 fProngs(0)
df9db588 69{
70 // constructor
71
72 SetPosition(position);
73 if (covMatrix) SetCovMatrix(covMatrix);
bca58dd7 74 MakeProngs();
df9db588 75}
76
77//______________________________________________________________________________
78AliAODVertex::AliAODVertex(const Float_t position[3],
79 const Float_t covMatrix[6],
0657f082 80 Double_t chi2perNDF,
df9db588 81 TObject *parent,
02153d58 82 Short_t id,
bca58dd7 83 Char_t vtype,
84 Int_t nprong) :
4d209fca 85
bdd011d6 86 AliVVertex(),
0657f082 87 fChi2perNDF(chi2perNDF),
02153d58 88 fID(id),
9333290e 89 fType(vtype),
bca58dd7 90 fNprong(nprong),
91 fIprong(0),
d999f2e6 92 fNContributors(0),
9f7c531f 93 fCovMatrix(NULL),
df9db588 94 fParent(parent),
bca58dd7 95 fDaughters(),
96 fProngs(0)
df9db588 97{
98 // constructor
99
100 SetPosition(position);
101 if (covMatrix) SetCovMatrix(covMatrix);
bca58dd7 102 MakeProngs();
df9db588 103}
104
105//______________________________________________________________________________
106AliAODVertex::AliAODVertex(const Double_t position[3],
0657f082 107 Double_t chi2perNDF,
bca58dd7 108 Char_t vtype,
109 Int_t nprong) :
bdd011d6 110 AliVVertex(),
0657f082 111 fChi2perNDF(chi2perNDF),
02153d58 112 fID(-1),
9333290e 113 fType(vtype),
bca58dd7 114 fNprong(nprong),
115 fIprong(0),
d999f2e6 116 fNContributors(0),
9f7c531f 117 fCovMatrix(NULL),
0f09edc3 118 fParent(),
bca58dd7 119 fDaughters(),
120 fProngs(0)
df9db588 121{
122 // constructor without covariance matrix
123
124 SetPosition(position);
bca58dd7 125 MakeProngs();
df9db588 126}
127
128//______________________________________________________________________________
129AliAODVertex::AliAODVertex(const Float_t position[3],
0657f082 130 Double_t chi2perNDF,
bca58dd7 131 Char_t vtype, Int_t nprong) :
bdd011d6 132 AliVVertex(),
0657f082 133 fChi2perNDF(chi2perNDF),
02153d58 134 fID(-1),
9333290e 135 fType(vtype),
bca58dd7 136 fNprong(nprong),
137 fIprong(0),
d999f2e6 138 fNContributors(0),
9f7c531f 139 fCovMatrix(NULL),
0f09edc3 140 fParent(),
bca58dd7 141 fDaughters(),
142 fProngs(0)
df9db588 143{
144 // constructor without covariance matrix
145
146 SetPosition(position);
bca58dd7 147 MakeProngs();
df9db588 148}
149
150//______________________________________________________________________________
151AliAODVertex::~AliAODVertex()
152{
153 // Destructor
154
155 delete fCovMatrix;
bca58dd7 156 if (fNprong > 0) delete[] fProngs;
df9db588 157}
158
159//______________________________________________________________________________
160AliAODVertex::AliAODVertex(const AliAODVertex& vtx) :
bdd011d6 161 AliVVertex(vtx),
0657f082 162 fChi2perNDF(vtx.fChi2perNDF),
02153d58 163 fID(vtx.fID),
9333290e 164 fType(vtx.fType),
bca58dd7 165 fNprong(vtx.fNprong),
166 fIprong(vtx.fIprong),
d999f2e6 167 fNContributors(vtx.fNContributors),
9f7c531f 168 fCovMatrix(NULL),
df9db588 169 fParent(vtx.fParent),
bca58dd7 170 fDaughters(vtx.fDaughters),
171 fProngs(0)
df9db588 172{
173 // Copy constructor.
174
175 for (int i = 0; i < 3; i++)
176 fPosition[i] = vtx.fPosition[i];
177
5d62ce04 178 if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
bca58dd7 179 MakeProngs();
180 for (int i = 0; i < fNprong; i++) {
181 fProngs[i] = vtx.fProngs[i];
182 }
df9db588 183}
184
185//______________________________________________________________________________
186AliAODVertex& AliAODVertex::operator=(const AliAODVertex& vtx)
187{
188 // Assignment operator
189 if (this != &vtx) {
190
191 // name and type
bdd011d6 192 AliVVertex::operator=(vtx);
df9db588 193
194 //momentum
195 for (int i = 0; i < 3; i++)
196 fPosition[i] = vtx.fPosition[i];
197
0657f082 198 fChi2perNDF = vtx.fChi2perNDF;
02153d58 199 fID = vtx.fID;
9333290e 200 fType = vtx.fType;
9f7c531f 201
df9db588 202 //covariance matrix
203 delete fCovMatrix;
9f7c531f 204 fCovMatrix = NULL;
5d62ce04 205 if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
df9db588 206
207 //other stuff
df9db588 208 fParent = vtx.fParent;
209 fDaughters = vtx.fDaughters;
bca58dd7 210 fNprong = vtx.fNprong;
211 fIprong = vtx.fIprong;
212
213 MakeProngs();
214 for (int i = 0; i < fNprong; i++) {
215 fProngs[i] = vtx.fProngs[i];
216 }
df9db588 217 }
218
219 return *this;
220}
221
cfa5b70c 222//______________________________________________________________________________
223void AliAODVertex::AddDaughter(TObject *daughter)
224{
225 // Add reference to daughter track
bca58dd7 226 if (!fProngs) {
227 if (fDaughters.GetEntries()==0) {
228 TRefArray* arr = &fDaughters;
229 new(arr)TRefArray(TProcessID::GetProcessWithUID(daughter));
230 }
231 fDaughters.Add(daughter);
232 } else {
233 if (fIprong < fNprong) {
234 fProngs[fIprong++] = daughter;
235 } else {
236 AliWarning("Number of daughters out of range !\n");
237 }
238 }
cfa5b70c 239 return;
240}
241
bca58dd7 242
df9db588 243//______________________________________________________________________________
244template <class T> void AliAODVertex::GetSigmaXYZ(T sigma[3]) const
245{
246 // Return errors on vertex position in thrust frame
247
248 if(fCovMatrix) {
249 sigma[0]=fCovMatrix[3]; //GetCovXZ
250 sigma[1]=fCovMatrix[4]; //GetCovYZ
251 sigma[2]=fCovMatrix[5]; //GetCovZZ
252 } else
253 sigma[0]=sigma[1]=sigma[2]=-999.;
254
255 /*
256 for (int i = 0, j = 6; i < 3; i++) {
257 j -= i+1;
258 sigma[2-i] = fCovMatrix ? TMath::Sqrt(fCovMatrix[j]) : -999.;
259 }
260 */
261}
262
0657f082 263//______________________________________________________________________________
264Int_t AliAODVertex::GetNContributors() const
265{
266 // Returns the number of tracks used to fit this vertex.
0657f082 267 Int_t cont = 0;
268
19d55689 269 if (!strcmp(GetTitle(), "vertexer: 3D")) {
91bad62d 270 cont = fNContributors;
19d55689 271 } else {
272 for (Int_t iDaug = 0; iDaug < GetNDaughters(); iDaug++) {
273 if (((AliAODTrack*)fDaughters.At(iDaug))->GetUsedForVtxFit()) cont++;
274 }
0657f082 275 }
0657f082 276 return cont;
277}
278
df9db588 279//______________________________________________________________________________
280Bool_t AliAODVertex::HasDaughter(TObject *daughter) const
281{
282 // Checks if the given daughter (particle) is part of this vertex.
bca58dd7 283 if (!fProngs) {
284 TRefArrayIter iter(&fDaughters);
285 while (TObject *daugh = iter.Next()) {
286 if (daugh == daughter) return kTRUE;
287 }
288 return kFALSE;
289 } else {
290 Bool_t has = kFALSE;
5c2137c1 291 for (int i = 0; i < fNprong; i++) {
bca58dd7 292 if (fProngs[i].GetObject() == daughter) has = kTRUE;
293 }
294 return has;
295 }
df9db588 296}
297
298//______________________________________________________________________________
299Double_t AliAODVertex::RotatedCovMatrixXX(Double_t phi, Double_t theta) const
300{
301 // XX term of covariance matrix after rotation by phi around z-axis
302 // and, then, by theta around new y-axis
303
304 if (!fCovMatrix) {
305 //AliFatal("Covariance matrix not set");
306 return -999.;
307 }
308
309 Double_t covMatrix[6];
310
311 GetCovMatrix(covMatrix);
312
313 Double_t cp = TMath::Cos(phi);
314 Double_t sp = TMath::Sin(phi);
315 Double_t ct = TMath::Cos(theta);
316 Double_t st = TMath::Sin(theta);
317 return
318 covMatrix[0]*cp*cp*ct*ct // GetCovXX
319 +covMatrix[1]*2.*cp*sp*ct*ct // GetCovXY
320 +covMatrix[3]*2.*cp*ct*st // GetCovXZ
321 +covMatrix[2]*sp*sp*ct*ct // GetCovYY
322 +covMatrix[4]*2.*sp*ct*st // GetCovYZ
323 +covMatrix[5]*st*st; // GetCovZZ
324}
325
326//______________________________________________________________________________
327Double_t AliAODVertex::RotatedCovMatrixXY(Double_t phi, Double_t theta) const
328{
329 // XY term of covariance matrix after rotation by phi around z-axis
330 // and, then, by theta around new y-axis
331
332 if (!fCovMatrix) {
333 //AliFatal("Covariance matrix not set");
334 return -999.;
335 }
336
337 Double_t covMatrix[6];
338
339 GetCovMatrix(covMatrix);
340
341 Double_t cp = TMath::Cos(phi);
342 Double_t sp = TMath::Sin(phi);
343 Double_t ct = TMath::Cos(theta);
344 Double_t st = TMath::Sin(theta);
345 return
346 -covMatrix[0]*cp*sp*ct // GetCovXX
347 +covMatrix[1]*ct*(cp*cp-sp*sp) // GetCovXY
348 -covMatrix[3]*sp*st // GetCovXZ
349 +covMatrix[2]*cp*sp*ct // GetCovYY
350 +covMatrix[4]*cp*st; // GetCovYZ
351}
352
353//______________________________________________________________________________
354Double_t AliAODVertex::RotatedCovMatrixXZ(Double_t phi, Double_t theta) const
355{
356 // XZ term of covariance matrix after rotation by phi around z-axis
357 // and, then, by theta around new y-axis
358
359 if (!fCovMatrix) {
360 //AliFatal("Covariance matrix not set");
361 return -999.;
362 }
363
364 Double_t covMatrix[6];
365
366 GetCovMatrix(covMatrix);
367
368 Double_t cp = TMath::Cos(phi);
369 Double_t sp = TMath::Sin(phi);
370 Double_t ct = TMath::Cos(theta);
371 Double_t st = TMath::Sin(theta);
372 return
373 -covMatrix[0]*cp*cp*ct*st // GetCovXX
374 -covMatrix[1]*2.*cp*sp*ct*st // GetCovXY
375 +covMatrix[3]*cp*(ct*ct-st*st) // GetCovXZ
376 -covMatrix[2]*sp*sp*ct*st // GetCovYY
377 +covMatrix[4]*sp*(ct*ct-st*st) // GetCovYZ
378 +covMatrix[5]*ct*st; // GetCovZZ
379}
380
381//______________________________________________________________________________
382Double_t AliAODVertex::RotatedCovMatrixYY(Double_t phi) const
383{
384 // YY term of covariance matrix after rotation by phi around z-axis
385 // and, then, by theta around new y-axis
386
387 if (!fCovMatrix) {
388 //AliFatal("Covariance matrix not set");
389 return -999.;
390 }
391
392 Double_t covMatrix[6];
393
394 GetCovMatrix(covMatrix);
395
396 Double_t cp = TMath::Cos(phi);
397 Double_t sp = TMath::Sin(phi);
398 return
399 covMatrix[0]*sp*sp // GetCovXX
400 -covMatrix[1]*2.*cp*sp // GetCovXY
401 +covMatrix[2]*cp*cp; // GetCovYY
402}
403
404//______________________________________________________________________________
405Double_t AliAODVertex::RotatedCovMatrixYZ(Double_t phi, Double_t theta) const
406{
407 // YZ term of covariance matrix after rotation by phi around z-axis
408 // and, then, by theta around new y-axis
409
410 if (!fCovMatrix) {
411 //AliFatal("Covariance matrix not set");
412 return -999.;
413 }
414
415 Double_t covMatrix[6];
416
417 GetCovMatrix(covMatrix);
418
419 Double_t cp = TMath::Cos(phi);
420 Double_t sp = TMath::Sin(phi);
421 Double_t ct = TMath::Cos(theta);
422 Double_t st = TMath::Sin(theta);
423 return
424 covMatrix[0]*cp*sp*st // GetCovXX
425 +covMatrix[1]*st*(sp*sp-cp*cp) // GetCovXY
426 -covMatrix[3]*sp*ct // GetCovXZ
427 -covMatrix[2]*cp*sp*st // GetCovYY
428 +covMatrix[4]*cp*ct; // GetCovYZ
429}
430
431//______________________________________________________________________________
432Double_t AliAODVertex::RotatedCovMatrixZZ(Double_t phi, Double_t theta) const
433{
434 // ZZ term of covariance matrix after rotation by phi around z-axis
435 // and, then, by theta around new y-axis
436
437 if (!fCovMatrix) {
438 //AliFatal("Covariance matrix not set");
439 return -999.;
440 }
441
442 Double_t covMatrix[6];
443
444 GetCovMatrix(covMatrix);
445
446 Double_t cp = TMath::Cos(phi);
447 Double_t sp = TMath::Sin(phi);
448 Double_t ct = TMath::Cos(theta);
449 Double_t st = TMath::Sin(theta);
450 return
451 covMatrix[0]*cp*cp*st*st // GetCovXX
452 +covMatrix[1]*2.*cp*sp*st*st // GetCovXY
453 -covMatrix[3]*2.*cp*ct*st // GetCovXZ
454 +covMatrix[2]*sp*sp*st*st // GetCovYY
455 -covMatrix[4]*2.*sp*sp*ct*st // GetCovYZ
456 +covMatrix[5]*ct*ct; // GetCovZZ
457}
458
459//______________________________________________________________________________
460Double_t AliAODVertex::DistanceToVertex(AliAODVertex *vtx) const
461{
462 // distance in 3D to another AliAODVertex
463
464 Double_t dx = GetX()-vtx->GetX();
465 Double_t dy = GetY()-vtx->GetY();
466 Double_t dz = GetZ()-vtx->GetZ();
467
468 return TMath::Sqrt(dx*dx+dy*dy+dz*dz);
469}
470
471//______________________________________________________________________________
472Double_t AliAODVertex::DistanceXYToVertex(AliAODVertex *vtx) const
473{
474 // distance in XY to another AliAODVertex
475
476 Double_t dx = GetX()-vtx->GetX();
477 Double_t dy = GetY()-vtx->GetY();
478
479 return TMath::Sqrt(dx*dx+dy*dy);
480}
481
482//______________________________________________________________________________
483Double_t AliAODVertex::ErrorDistanceToVertex(AliAODVertex *vtx) const
484{
485 // error on the distance in 3D to another AliAODVertex
486
487 Double_t phi,theta;
488 PhiAndThetaToVertex(vtx,phi,theta);
489 // error2 due to this vertex
490 Double_t error2 = RotatedCovMatrixXX(phi,theta);
491 // error2 due to vtx vertex
492 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi,theta);
493
494 return TMath::Sqrt(error2+error2vtx);
495}
496
497//______________________________________________________________________________
498Double_t AliAODVertex::ErrorDistanceXYToVertex(AliAODVertex *vtx) const
499{
500 // error on the distance in XY to another AliAODVertex
501
502 Double_t phi,theta;
503 PhiAndThetaToVertex(vtx,phi,theta);
504 // error2 due to this vertex
505 Double_t error2 = RotatedCovMatrixXX(phi);
506 // error2 due to vtx vertex
507 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi);
508
509 return TMath::Sqrt(error2+error2vtx);
510}
511
512//______________________________________________________________________________
513template <class T, class P>
514void AliAODVertex::PhiAndThetaToVertex(AliAODVertex *vtx, P &phi, T &theta) const
515{
516 // rotation angles around z-axis (phi) and around new y-axis (theta)
517 // with which vtx is seen (used by RotatedCovMatrix... methods)
518
b1a9edc8 519 phi = TMath::Pi()+TMath::ATan2(-vtx->GetY()+GetY(),-vtx->GetX()+GetX());
df9db588 520 Double_t vtxxphi = vtx->GetX()*TMath::Cos(phi)+vtx->GetY()*TMath::Sin(phi);
521 Double_t xphi = GetX()*TMath::Cos(phi)+GetY()*TMath::Sin(phi);
522 theta = TMath::ATan2(vtx->GetZ()-GetZ(),vtxxphi-xphi);
523}
524
525//______________________________________________________________________________
526void AliAODVertex::PrintIndices() const
527{
528 // Print indices of particles originating form this vertex
529
530 TRefArrayIter iter(&fDaughters);
531 while (TObject *daugh = iter.Next()) {
f12d42ce 532 printf("Particle %p originates from this vertex.\n", static_cast<void*>(daugh));
df9db588 533 }
534}
535
536//______________________________________________________________________________
537void AliAODVertex::Print(Option_t* /*option*/) const
538{
539 // Print information of all data members
540
541 printf("Vertex position:\n");
542 printf(" x = %f\n", fPosition[0]);
543 printf(" y = %f\n", fPosition[1]);
544 printf(" z = %f\n", fPosition[2]);
f12d42ce 545 printf(" parent particle: %p\n", static_cast<void*>(fParent.GetObject()));
df9db588 546 printf(" origin of %d particles\n", fDaughters.GetEntriesFast());
547 printf(" vertex type %d\n", fType);
548
549 /*
550 if (fCovMatrix) {
551 printf("Covariance matrix:\n");
552 printf(" %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n",
553 fCovMatrix[0],
554 fCovMatrix[1],
555 fCovMatrix[3],
556 fCovMatrix[1],
557 fCovMatrix[2],
558 fCovMatrix[4],
559 fCovMatrix[3],
560 fCovMatrix[4],
561 fCovMatrix[5]);
562 } */
0657f082 563 printf(" Chi^2/NDF = %f\n", fChi2perNDF);
df9db588 564}
565