]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODVertex.cxx
New classes added.
[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 //-------------------------------------------------------------------------
24
25 #include "AliAODVertex.h"
26
27 #include "AliAODTrack.h"
28
29 ClassImp(AliAODVertex)
30
31 //______________________________________________________________________________
32 AliAODVertex::AliAODVertex() : 
33   TObject(),
34   fChi2perNDF(-999.),
35   fCovMatrix(NULL),
36   fParent(0x0),
37   fDaughters(),
38   fType(kUndef)
39  {
40   // default constructor
41
42   fPosition[0] = fPosition[1] = fPosition[2] = -999.;
43 }
44
45 //______________________________________________________________________________
46 AliAODVertex::AliAODVertex(const Double_t position[3], 
47                            const Double_t covMatrix[6],
48                            Double_t  chi2perNDF,
49                            TObject  *parent,
50                            Char_t vtype) :
51   TObject(),
52   fChi2perNDF(chi2perNDF),
53   fCovMatrix(NULL),
54   fParent(parent),
55   fDaughters(),
56   fType(vtype)
57 {
58   // constructor
59
60   SetPosition(position);
61   if (covMatrix) SetCovMatrix(covMatrix);
62 }
63
64 //______________________________________________________________________________
65 AliAODVertex::AliAODVertex(const Float_t position[3], 
66                            const Float_t  covMatrix[6],
67                            Double_t  chi2perNDF,
68                            TObject  *parent,
69                            Char_t vtype) :
70
71   TObject(),
72   fChi2perNDF(chi2perNDF),
73   fCovMatrix(NULL),
74   fParent(parent),
75   fDaughters(),
76   fType(vtype)
77 {
78   // constructor
79
80   SetPosition(position);
81   if (covMatrix) SetCovMatrix(covMatrix);
82 }
83
84 //______________________________________________________________________________
85 AliAODVertex::AliAODVertex(const Double_t position[3], 
86                            Double_t  chi2perNDF,
87                            Char_t vtype) :
88   TObject(),
89   fChi2perNDF(chi2perNDF),
90   fCovMatrix(NULL),
91   fParent(0x0),
92   fDaughters(),
93   fType(vtype)
94 {
95   // constructor without covariance matrix
96
97   SetPosition(position);  
98 }
99
100 //______________________________________________________________________________
101 AliAODVertex::AliAODVertex(const Float_t position[3], 
102                            Double_t  chi2perNDF,
103                            Char_t vtype) :
104   TObject(),
105   fChi2perNDF(chi2perNDF),
106   fCovMatrix(NULL),
107   fParent(0x0),
108   fDaughters(),
109   fType(vtype)
110 {
111   // constructor without covariance matrix
112
113   SetPosition(position);  
114 }
115
116 //______________________________________________________________________________
117 AliAODVertex::~AliAODVertex() 
118 {
119   // Destructor
120
121   delete fCovMatrix;
122 }
123
124 //______________________________________________________________________________
125 AliAODVertex::AliAODVertex(const AliAODVertex& vtx) :
126   TObject(vtx),
127   fChi2perNDF(vtx.fChi2perNDF),
128   fCovMatrix(NULL),
129   fParent(vtx.fParent),
130   fDaughters(vtx.fDaughters),
131   fType(vtx.fType)
132 {
133   // Copy constructor.
134   
135   for (int i = 0; i < 3; i++) 
136     fPosition[i] = vtx.fPosition[i];
137
138   if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
139 }
140
141 //______________________________________________________________________________
142 AliAODVertex& 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     
154     fChi2perNDF = vtx.fChi2perNDF;
155
156     //covariance matrix
157     delete fCovMatrix;
158     fCovMatrix = NULL;   
159     if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
160     
161     //other stuff
162     fParent = vtx.fParent;
163     fDaughters = vtx.fDaughters;
164     fType = vtx.fType;
165   }
166   
167   return *this;
168 }
169
170 //______________________________________________________________________________
171 template <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
190 //______________________________________________________________________________
191 Int_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
204 //______________________________________________________________________________
205 Bool_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 //______________________________________________________________________________
217 Double_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 //______________________________________________________________________________
245 Double_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 //______________________________________________________________________________
272 Double_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 //______________________________________________________________________________
300 Double_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 //______________________________________________________________________________
323 Double_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 //______________________________________________________________________________
350 Double_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 //______________________________________________________________________________
378 Double_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 //______________________________________________________________________________
390 Double_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 //______________________________________________________________________________
401 Double_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 //______________________________________________________________________________
416 Double_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 //______________________________________________________________________________
431 template <class T, class P> 
432 void 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 //______________________________________________________________________________
444 void 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 //______________________________________________________________________________
455 void 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            } */
481   printf(" Chi^2/NDF = %f\n", fChi2perNDF);
482 }
483