Fixes for bug #52499: Field polarities inconsistiency
[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
216//______________________________________________________________________________
cfa5b70c 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
cfa5b70c 237//______________________________________________________________________________
df9db588 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
257//______________________________________________________________________________
0657f082 258Int_t AliAODVertex::GetNContributors() const
259{
260 // Returns the number of tracks used to fit this vertex.
261
262 Int_t cont = 0;
263
264 for (Int_t iDaug = 0; iDaug < GetNDaughters(); iDaug++) {
265 if (((AliAODTrack*)fDaughters.At(iDaug))->GetUsedForVtxFit()) cont++;
266 }
267
268 return cont;
269}
270
271//______________________________________________________________________________
df9db588 272Bool_t AliAODVertex::HasDaughter(TObject *daughter) const
273{
274 // Checks if the given daughter (particle) is part of this vertex.
bca58dd7 275 if (!fProngs) {
276 TRefArrayIter iter(&fDaughters);
277 while (TObject *daugh = iter.Next()) {
278 if (daugh == daughter) return kTRUE;
279 }
280 return kFALSE;
281 } else {
282 Bool_t has = kFALSE;
5c2137c1 283 for (int i = 0; i < fNprong; i++) {
bca58dd7 284 if (fProngs[i].GetObject() == daughter) has = kTRUE;
285 }
286 return has;
287 }
df9db588 288}
289
290//______________________________________________________________________________
291Double_t AliAODVertex::RotatedCovMatrixXX(Double_t phi, Double_t theta) const
292{
293 // XX term of covariance matrix after rotation by phi around z-axis
294 // and, then, by theta around new y-axis
295
296 if (!fCovMatrix) {
297 //AliFatal("Covariance matrix not set");
298 return -999.;
299 }
300
301 Double_t covMatrix[6];
302
303 GetCovMatrix(covMatrix);
304
305 Double_t cp = TMath::Cos(phi);
306 Double_t sp = TMath::Sin(phi);
307 Double_t ct = TMath::Cos(theta);
308 Double_t st = TMath::Sin(theta);
309 return
310 covMatrix[0]*cp*cp*ct*ct // GetCovXX
311 +covMatrix[1]*2.*cp*sp*ct*ct // GetCovXY
312 +covMatrix[3]*2.*cp*ct*st // GetCovXZ
313 +covMatrix[2]*sp*sp*ct*ct // GetCovYY
314 +covMatrix[4]*2.*sp*ct*st // GetCovYZ
315 +covMatrix[5]*st*st; // GetCovZZ
316}
317
318//______________________________________________________________________________
319Double_t AliAODVertex::RotatedCovMatrixXY(Double_t phi, Double_t theta) const
320{
321 // XY term of covariance matrix after rotation by phi around z-axis
322 // and, then, by theta around new y-axis
323
324 if (!fCovMatrix) {
325 //AliFatal("Covariance matrix not set");
326 return -999.;
327 }
328
329 Double_t covMatrix[6];
330
331 GetCovMatrix(covMatrix);
332
333 Double_t cp = TMath::Cos(phi);
334 Double_t sp = TMath::Sin(phi);
335 Double_t ct = TMath::Cos(theta);
336 Double_t st = TMath::Sin(theta);
337 return
338 -covMatrix[0]*cp*sp*ct // GetCovXX
339 +covMatrix[1]*ct*(cp*cp-sp*sp) // GetCovXY
340 -covMatrix[3]*sp*st // GetCovXZ
341 +covMatrix[2]*cp*sp*ct // GetCovYY
342 +covMatrix[4]*cp*st; // GetCovYZ
343}
344
345//______________________________________________________________________________
346Double_t AliAODVertex::RotatedCovMatrixXZ(Double_t phi, Double_t theta) const
347{
348 // XZ term of covariance matrix after rotation by phi around z-axis
349 // and, then, by theta around new y-axis
350
351 if (!fCovMatrix) {
352 //AliFatal("Covariance matrix not set");
353 return -999.;
354 }
355
356 Double_t covMatrix[6];
357
358 GetCovMatrix(covMatrix);
359
360 Double_t cp = TMath::Cos(phi);
361 Double_t sp = TMath::Sin(phi);
362 Double_t ct = TMath::Cos(theta);
363 Double_t st = TMath::Sin(theta);
364 return
365 -covMatrix[0]*cp*cp*ct*st // GetCovXX
366 -covMatrix[1]*2.*cp*sp*ct*st // GetCovXY
367 +covMatrix[3]*cp*(ct*ct-st*st) // GetCovXZ
368 -covMatrix[2]*sp*sp*ct*st // GetCovYY
369 +covMatrix[4]*sp*(ct*ct-st*st) // GetCovYZ
370 +covMatrix[5]*ct*st; // GetCovZZ
371}
372
373//______________________________________________________________________________
374Double_t AliAODVertex::RotatedCovMatrixYY(Double_t phi) const
375{
376 // YY term of covariance matrix after rotation by phi around z-axis
377 // and, then, by theta around new y-axis
378
379 if (!fCovMatrix) {
380 //AliFatal("Covariance matrix not set");
381 return -999.;
382 }
383
384 Double_t covMatrix[6];
385
386 GetCovMatrix(covMatrix);
387
388 Double_t cp = TMath::Cos(phi);
389 Double_t sp = TMath::Sin(phi);
390 return
391 covMatrix[0]*sp*sp // GetCovXX
392 -covMatrix[1]*2.*cp*sp // GetCovXY
393 +covMatrix[2]*cp*cp; // GetCovYY
394}
395
396//______________________________________________________________________________
397Double_t AliAODVertex::RotatedCovMatrixYZ(Double_t phi, Double_t theta) const
398{
399 // YZ term of covariance matrix after rotation by phi around z-axis
400 // and, then, by theta around new y-axis
401
402 if (!fCovMatrix) {
403 //AliFatal("Covariance matrix not set");
404 return -999.;
405 }
406
407 Double_t covMatrix[6];
408
409 GetCovMatrix(covMatrix);
410
411 Double_t cp = TMath::Cos(phi);
412 Double_t sp = TMath::Sin(phi);
413 Double_t ct = TMath::Cos(theta);
414 Double_t st = TMath::Sin(theta);
415 return
416 covMatrix[0]*cp*sp*st // GetCovXX
417 +covMatrix[1]*st*(sp*sp-cp*cp) // GetCovXY
418 -covMatrix[3]*sp*ct // GetCovXZ
419 -covMatrix[2]*cp*sp*st // GetCovYY
420 +covMatrix[4]*cp*ct; // GetCovYZ
421}
422
423//______________________________________________________________________________
424Double_t AliAODVertex::RotatedCovMatrixZZ(Double_t phi, Double_t theta) const
425{
426 // ZZ term of covariance matrix after rotation by phi around z-axis
427 // and, then, by theta around new y-axis
428
429 if (!fCovMatrix) {
430 //AliFatal("Covariance matrix not set");
431 return -999.;
432 }
433
434 Double_t covMatrix[6];
435
436 GetCovMatrix(covMatrix);
437
438 Double_t cp = TMath::Cos(phi);
439 Double_t sp = TMath::Sin(phi);
440 Double_t ct = TMath::Cos(theta);
441 Double_t st = TMath::Sin(theta);
442 return
443 covMatrix[0]*cp*cp*st*st // GetCovXX
444 +covMatrix[1]*2.*cp*sp*st*st // GetCovXY
445 -covMatrix[3]*2.*cp*ct*st // GetCovXZ
446 +covMatrix[2]*sp*sp*st*st // GetCovYY
447 -covMatrix[4]*2.*sp*sp*ct*st // GetCovYZ
448 +covMatrix[5]*ct*ct; // GetCovZZ
449}
450
451//______________________________________________________________________________
452Double_t AliAODVertex::DistanceToVertex(AliAODVertex *vtx) const
453{
454 // distance in 3D to another AliAODVertex
455
456 Double_t dx = GetX()-vtx->GetX();
457 Double_t dy = GetY()-vtx->GetY();
458 Double_t dz = GetZ()-vtx->GetZ();
459
460 return TMath::Sqrt(dx*dx+dy*dy+dz*dz);
461}
462
463//______________________________________________________________________________
464Double_t AliAODVertex::DistanceXYToVertex(AliAODVertex *vtx) const
465{
466 // distance in XY to another AliAODVertex
467
468 Double_t dx = GetX()-vtx->GetX();
469 Double_t dy = GetY()-vtx->GetY();
470
471 return TMath::Sqrt(dx*dx+dy*dy);
472}
473
474//______________________________________________________________________________
475Double_t AliAODVertex::ErrorDistanceToVertex(AliAODVertex *vtx) const
476{
477 // error on the distance in 3D to another AliAODVertex
478
479 Double_t phi,theta;
480 PhiAndThetaToVertex(vtx,phi,theta);
481 // error2 due to this vertex
482 Double_t error2 = RotatedCovMatrixXX(phi,theta);
483 // error2 due to vtx vertex
484 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi,theta);
485
486 return TMath::Sqrt(error2+error2vtx);
487}
488
489//______________________________________________________________________________
490Double_t AliAODVertex::ErrorDistanceXYToVertex(AliAODVertex *vtx) const
491{
492 // error on the distance in XY to another AliAODVertex
493
494 Double_t phi,theta;
495 PhiAndThetaToVertex(vtx,phi,theta);
496 // error2 due to this vertex
497 Double_t error2 = RotatedCovMatrixXX(phi);
498 // error2 due to vtx vertex
499 Double_t error2vtx = vtx->RotatedCovMatrixXX(phi);
500
501 return TMath::Sqrt(error2+error2vtx);
502}
503
504//______________________________________________________________________________
505template <class T, class P>
506void AliAODVertex::PhiAndThetaToVertex(AliAODVertex *vtx, P &phi, T &theta) const
507{
508 // rotation angles around z-axis (phi) and around new y-axis (theta)
509 // with which vtx is seen (used by RotatedCovMatrix... methods)
510
b1a9edc8 511 phi = TMath::Pi()+TMath::ATan2(-vtx->GetY()+GetY(),-vtx->GetX()+GetX());
df9db588 512 Double_t vtxxphi = vtx->GetX()*TMath::Cos(phi)+vtx->GetY()*TMath::Sin(phi);
513 Double_t xphi = GetX()*TMath::Cos(phi)+GetY()*TMath::Sin(phi);
514 theta = TMath::ATan2(vtx->GetZ()-GetZ(),vtxxphi-xphi);
515}
516
517//______________________________________________________________________________
518void AliAODVertex::PrintIndices() const
519{
520 // Print indices of particles originating form this vertex
521
522 TRefArrayIter iter(&fDaughters);
523 while (TObject *daugh = iter.Next()) {
f12d42ce 524 printf("Particle %p originates from this vertex.\n", static_cast<void*>(daugh));
df9db588 525 }
526}
527
528//______________________________________________________________________________
529void AliAODVertex::Print(Option_t* /*option*/) const
530{
531 // Print information of all data members
532
533 printf("Vertex position:\n");
534 printf(" x = %f\n", fPosition[0]);
535 printf(" y = %f\n", fPosition[1]);
536 printf(" z = %f\n", fPosition[2]);
f12d42ce 537 printf(" parent particle: %p\n", static_cast<void*>(fParent.GetObject()));
df9db588 538 printf(" origin of %d particles\n", fDaughters.GetEntriesFast());
539 printf(" vertex type %d\n", fType);
540
541 /*
542 if (fCovMatrix) {
543 printf("Covariance matrix:\n");
544 printf(" %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n %12.10f %12.10f %12.10f\n",
545 fCovMatrix[0],
546 fCovMatrix[1],
547 fCovMatrix[3],
548 fCovMatrix[1],
549 fCovMatrix[2],
550 fCovMatrix[4],
551 fCovMatrix[3],
552 fCovMatrix[4],
553 fCovMatrix[5]);
554 } */
0657f082 555 printf(" Chi^2/NDF = %f\n", fChi2perNDF);
df9db588 556}
557