]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODVertex.cxx
changed the names of the histograms, requested by AMORE
[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   fCovMatrix(NULL),
40   fParent(),
41   fDaughters(),
42   fProngs(NULL)
43   {
44   // default constructor
45
46   fPosition[0] = fPosition[1] = fPosition[2] = -999.;
47 }
48
49 //______________________________________________________________________________
50 AliAODVertex::AliAODVertex(const Double_t position[3], 
51                            const Double_t covMatrix[6],
52                            Double_t  chi2perNDF,
53                            TObject  *parent,
54                            Short_t id,
55                            Char_t vtype, 
56                            Int_t  nprong) :
57   AliVVertex(),
58   fChi2perNDF(chi2perNDF),
59   fID(id),
60   fType(vtype),
61   fNprong(nprong),
62   fIprong(0),
63   fCovMatrix(NULL),
64   fParent(parent),
65   fDaughters(),
66   fProngs(0)
67 {
68   // constructor
69
70   SetPosition(position);
71   if (covMatrix) SetCovMatrix(covMatrix);
72   MakeProngs();
73 }
74
75 //______________________________________________________________________________
76 AliAODVertex::AliAODVertex(const Float_t position[3], 
77                            const Float_t  covMatrix[6],
78                            Double_t  chi2perNDF,
79                            TObject  *parent,
80                            Short_t id,
81                            Char_t vtype,
82                            Int_t nprong) :
83
84   AliVVertex(),
85   fChi2perNDF(chi2perNDF),
86   fID(id),
87   fType(vtype),
88   fNprong(nprong),
89   fIprong(0),
90   fCovMatrix(NULL),
91   fParent(parent),
92   fDaughters(),
93   fProngs(0)
94 {
95   // constructor
96
97   SetPosition(position);
98   if (covMatrix) SetCovMatrix(covMatrix);
99   MakeProngs();
100 }
101
102 //______________________________________________________________________________
103 AliAODVertex::AliAODVertex(const Double_t position[3], 
104                            Double_t  chi2perNDF,
105                            Char_t vtype, 
106                            Int_t nprong) :
107   AliVVertex(),
108   fChi2perNDF(chi2perNDF),
109   fID(-1),
110   fType(vtype),
111   fNprong(nprong),
112   fIprong(0),
113   fCovMatrix(NULL),
114   fParent(),
115   fDaughters(),
116   fProngs(0)
117 {
118   // constructor without covariance matrix
119
120   SetPosition(position);  
121   MakeProngs();
122 }
123
124 //______________________________________________________________________________
125 AliAODVertex::AliAODVertex(const Float_t position[3], 
126                            Double_t  chi2perNDF,
127                            Char_t vtype, Int_t nprong) :
128   AliVVertex(),
129   fChi2perNDF(chi2perNDF),
130   fID(-1),
131   fType(vtype),
132   fNprong(nprong),
133   fIprong(0),
134   fCovMatrix(NULL),
135   fParent(),
136   fDaughters(),
137   fProngs(0)
138 {
139   // constructor without covariance matrix
140
141   SetPosition(position);  
142   MakeProngs();
143 }
144
145 //______________________________________________________________________________
146 AliAODVertex::~AliAODVertex() 
147 {
148   // Destructor
149
150   delete fCovMatrix;
151   if (fNprong > 0) delete[] fProngs;
152 }
153
154 //______________________________________________________________________________
155 AliAODVertex::AliAODVertex(const AliAODVertex& vtx) :
156   AliVVertex(vtx),
157   fChi2perNDF(vtx.fChi2perNDF),
158   fID(vtx.fID),
159   fType(vtx.fType),
160   fNprong(vtx.fNprong),
161   fIprong(vtx.fIprong),
162   fCovMatrix(NULL),
163   fParent(vtx.fParent),
164   fDaughters(vtx.fDaughters),
165   fProngs(0)
166 {
167   // Copy constructor.
168   
169   for (int i = 0; i < 3; i++) 
170     fPosition[i] = vtx.fPosition[i];
171
172   if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
173   MakeProngs();
174   for (int i = 0; i < fNprong; i++) {
175       fProngs[i] = vtx.fProngs[i];
176   }
177 }
178
179 //______________________________________________________________________________
180 AliAODVertex& AliAODVertex::operator=(const AliAODVertex& vtx) 
181 {
182   // Assignment operator
183   if (this != &vtx) {
184
185     // name and type
186     AliVVertex::operator=(vtx);
187
188     //momentum
189     for (int i = 0; i < 3; i++) 
190       fPosition[i] = vtx.fPosition[i];
191     
192     fChi2perNDF = vtx.fChi2perNDF;
193     fID = vtx.fID;
194     fType = vtx.fType;
195
196     //covariance matrix
197     delete fCovMatrix;
198     fCovMatrix = NULL;   
199     if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
200     
201     //other stuff
202     fParent = vtx.fParent;
203     fDaughters = vtx.fDaughters;
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     }
211   }
212   
213   return *this;
214 }
215
216 //______________________________________________________________________________
217 void AliAODVertex::AddDaughter(TObject *daughter)
218 {
219   // Add reference to daughter track
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     }
233   return;
234 }
235
236
237 //______________________________________________________________________________
238 template <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 //______________________________________________________________________________
258 Int_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 //______________________________________________________________________________
272 Bool_t AliAODVertex::HasDaughter(TObject *daughter) const 
273 {
274   // Checks if the given daughter (particle) is part of this vertex.
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;
283         for (int i = 0; i < fNprong; i++) {
284             if (fProngs[i].GetObject() == daughter) has = kTRUE;
285         }
286         return has;
287     }
288 }
289
290 //______________________________________________________________________________
291 Double_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 //______________________________________________________________________________
319 Double_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 //______________________________________________________________________________
346 Double_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 //______________________________________________________________________________
374 Double_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 //______________________________________________________________________________
397 Double_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 //______________________________________________________________________________
424 Double_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 //______________________________________________________________________________
452 Double_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 //______________________________________________________________________________
464 Double_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 //______________________________________________________________________________
475 Double_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 //______________________________________________________________________________
490 Double_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 //______________________________________________________________________________
505 template <class T, class P> 
506 void 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
511   phi = TMath::Pi()+TMath::ATan2(-vtx->GetY()+GetY(),-vtx->GetX()+GetX());
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 //______________________________________________________________________________
518 void AliAODVertex::PrintIndices() const 
519 {
520   // Print indices of particles originating form this vertex
521
522   TRefArrayIter iter(&fDaughters);
523   while (TObject *daugh = iter.Next()) {
524     printf("Particle %p originates from this vertex.\n", static_cast<void*>(daugh));
525   }
526 }
527
528 //______________________________________________________________________________
529 void 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]);
537   printf(" parent particle: %p\n", static_cast<void*>(fParent.GetObject()));
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            } */
555   printf(" Chi^2/NDF = %f\n", fChi2perNDF);
556 }
557