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