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