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