]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AOD/AliAODVertex.cxx
Added possibility of weighting according to run
[u/mrichter/AliRoot.git] / STEER / AOD / 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   fBCID(AliVTrack::kTOFBCNA),
37   fType(kUndef),
38   fNprong(0),
39   fIprong(0),
40   fNContributors(0),
41   fCovMatrix(NULL),
42   fParent(),
43   fDaughters(),
44   fProngs(NULL)
45   {
46   // default constructor
47
48   fPosition[0] = fPosition[1] = fPosition[2] = -999.;
49 }
50
51 //______________________________________________________________________________
52 AliAODVertex::AliAODVertex(const Double_t position[3], 
53                            const Double_t covMatrix[6],
54                            Double_t  chi2perNDF,
55                            TObject  *parent,
56                            Short_t id,
57                            Char_t vtype, 
58                            Int_t  nprong) :
59   AliVVertex(),
60   fChi2perNDF(chi2perNDF),
61   fID(id),
62   fBCID(AliVTrack::kTOFBCNA),
63   fType(vtype),
64   fNprong(nprong),
65   fIprong(0),
66   fNContributors(0),
67   fCovMatrix(NULL),
68   fParent(parent),
69   fDaughters(),
70   fProngs(0)
71 {
72   // constructor
73
74   SetPosition(position);
75   if (covMatrix) SetCovMatrix(covMatrix);
76   MakeProngs();
77 }
78
79 //______________________________________________________________________________
80 AliAODVertex::AliAODVertex(const Float_t position[3], 
81                            const Float_t  covMatrix[6],
82                            Double_t  chi2perNDF,
83                            TObject  *parent,
84                            Short_t id,
85                            Char_t vtype,
86                            Int_t nprong) :
87
88   AliVVertex(),
89   fChi2perNDF(chi2perNDF),
90   fID(id),
91   fBCID(AliVTrack::kTOFBCNA),
92   fType(vtype),
93   fNprong(nprong),
94   fIprong(0),
95   fNContributors(0),
96   fCovMatrix(NULL),
97   fParent(parent),
98   fDaughters(),
99   fProngs(0)
100 {
101   // constructor
102
103   SetPosition(position);
104   if (covMatrix) SetCovMatrix(covMatrix);
105   MakeProngs();
106 }
107
108 //______________________________________________________________________________
109 AliAODVertex::AliAODVertex(const Double_t position[3], 
110                            Double_t  chi2perNDF,
111                            Char_t vtype, 
112                            Int_t nprong) :
113   AliVVertex(),
114   fChi2perNDF(chi2perNDF),
115   fID(-1),
116   fBCID(AliVTrack::kTOFBCNA),
117   fType(vtype),
118   fNprong(nprong),
119   fIprong(0),
120   fNContributors(0),
121   fCovMatrix(NULL),
122   fParent(),
123   fDaughters(),
124   fProngs(0)
125 {
126   // constructor without covariance matrix
127
128   SetPosition(position);  
129   MakeProngs();
130 }
131
132 //______________________________________________________________________________
133 AliAODVertex::AliAODVertex(const Float_t position[3], 
134                            Double_t  chi2perNDF,
135                            Char_t vtype, Int_t nprong) :
136   AliVVertex(),
137   fChi2perNDF(chi2perNDF),
138   fID(-1),
139   fBCID(AliVTrack::kTOFBCNA),
140   fType(vtype),
141   fNprong(nprong),
142   fIprong(0),
143   fNContributors(0),
144   fCovMatrix(NULL),
145   fParent(),
146   fDaughters(),
147   fProngs(0)
148 {
149   // constructor without covariance matrix
150
151   SetPosition(position);  
152   MakeProngs();
153 }
154
155 //______________________________________________________________________________
156 AliAODVertex::~AliAODVertex() 
157 {
158   // Destructor
159
160   delete fCovMatrix;
161   if (fNprong > 0) delete[] fProngs;
162 }
163
164 //______________________________________________________________________________
165 AliAODVertex::AliAODVertex(const AliAODVertex& vtx) :
166   AliVVertex(vtx),
167   fChi2perNDF(vtx.fChi2perNDF),
168   fID(vtx.fID),
169   fBCID(vtx.fBCID),
170   fType(vtx.fType),
171   fNprong(vtx.fNprong),
172   fIprong(vtx.fIprong),
173   fNContributors(vtx.fNContributors),
174   fCovMatrix(NULL),
175   fParent(vtx.fParent),
176   fDaughters(vtx.fDaughters),
177   fProngs(0)
178 {
179   // Copy constructor.
180   
181   for (int i = 0; i < 3; i++) 
182     fPosition[i] = vtx.fPosition[i];
183
184   if (vtx.fCovMatrix) fCovMatrix=new AliAODRedCov<3>(*vtx.fCovMatrix);
185   MakeProngs();
186   for (int i = 0; i < fNprong; i++) {
187       fProngs[i] = vtx.fProngs[i];
188   }
189 }
190
191 //______________________________________________________________________________
192 AliAODVertex* AliAODVertex::CloneWithoutRefs() const
193 {
194   // Special method to copy all but the refs 
195   
196   Double_t cov[6] = { 0.0 };
197       
198   if (fCovMatrix) fCovMatrix->GetCovMatrix(cov);
199   
200   AliAODVertex* v = new AliAODVertex(fPosition,
201                                      cov,
202                                      fChi2perNDF,
203                                      0x0,
204                                      fID,
205                                      fType,
206                                      0);
207   
208   v->SetNContributors(fNContributors);  
209   
210   return v;
211 }
212
213 //______________________________________________________________________________
214 AliAODVertex& AliAODVertex::operator=(const AliAODVertex& vtx) 
215 {
216   // Assignment operator
217   if (this != &vtx) {
218
219     // name and type
220     AliVVertex::operator=(vtx);
221
222     //momentum
223     for (int i = 0; i < 3; i++) 
224         fPosition[i] = vtx.fPosition[i];
225     
226     fChi2perNDF = vtx.fChi2perNDF;
227     fID   = vtx.fID;
228     fType = vtx.fType;
229     fBCID = vtx.fBCID;
230     
231     //covariance matrix
232     delete fCovMatrix;
233     fCovMatrix = NULL;   
234     if (vtx.fCovMatrix) fCovMatrix = new AliAODRedCov<3>(*vtx.fCovMatrix);
235     
236     //other stuff
237     fNContributors = vtx.fNContributors;
238     fParent        = vtx.fParent;
239     fDaughters     = vtx.fDaughters;
240     fNprong        = vtx.fNprong;
241     fIprong        = vtx.fIprong;  
242     
243     MakeProngs();
244     for (int i = 0; i < fNprong; i++) {
245         fProngs[i] = vtx.fProngs[i];
246     }
247   }
248   
249   return *this;
250 }
251
252 //______________________________________________________________________________
253 void AliAODVertex::AddDaughter(TObject *daughter)
254 {
255   // Add reference to daughter track
256     if (!fProngs) {
257         if (fDaughters.GetEntries()==0) {
258             TRefArray* arr = &fDaughters;
259             new(arr)TRefArray(TProcessID::GetProcessWithUID(daughter));         
260         }
261         fDaughters.Add(daughter);       
262     } else {
263         if (fIprong < fNprong) {
264             fProngs[fIprong++] = daughter;
265         } else {
266             AliWarning("Number of daughters out of range !\n");
267         }
268     }
269   return;
270 }
271
272
273 //______________________________________________________________________________
274 template <class T> void AliAODVertex::GetSigmaXYZ(T sigma[3]) const
275 {
276   // Return errors on vertex position in thrust frame
277   
278   if(fCovMatrix) {
279     sigma[0]=fCovMatrix[3]; //GetCovXZ
280     sigma[1]=fCovMatrix[4]; //GetCovYZ
281     sigma[2]=fCovMatrix[5]; //GetCovZZ
282   } else 
283     sigma[0]=sigma[1]=sigma[2]=-999.;
284
285   /*
286   for (int i = 0, j = 6; i < 3; i++) {
287     j -= i+1;
288     sigma[2-i] = fCovMatrix ? TMath::Sqrt(fCovMatrix[j]) : -999.;
289   }
290   */
291 }
292
293 //______________________________________________________________________________
294 Int_t AliAODVertex::GetNContributors() const 
295 {
296   // Returns the number of tracks used to fit this vertex.
297   Int_t cont  = 0;
298
299   TString vtitle = GetTitle();
300   if (!vtitle.Contains("VertexerTracks")) {
301     cont = fNContributors;
302   } else {
303     for (Int_t iDaug = 0; iDaug < GetNDaughters(); iDaug++) {
304         AliAODTrack* aodT = dynamic_cast<AliAODTrack*>(fDaughters.At(iDaug));
305         if (!aodT) continue;
306         if (aodT->GetUsedForPrimVtxFit()) cont++;
307     } 
308     // the constraint adds another DOF
309     if(vtitle.Contains("VertexerTracksWithConstraint"))cont++;
310   }
311   return cont;
312 }
313
314 //______________________________________________________________________________
315 Bool_t AliAODVertex::HasDaughter(TObject *daughter) const 
316 {
317   // Checks if the given daughter (particle) is part of this vertex.
318     if (!fProngs) {
319         TRefArrayIter iter(&fDaughters);
320         while (TObject *daugh = iter.Next()) {
321             if (daugh == daughter) return kTRUE;
322         }
323         return kFALSE;
324     } else {
325         Bool_t has = kFALSE;
326         for (int i = 0; i < fNprong; i++) {
327             if (fProngs[i].GetObject() == daughter) has = kTRUE;
328         }
329         return has;
330     }
331 }
332
333 //______________________________________________________________________________
334 Double_t AliAODVertex::RotatedCovMatrixXX(Double_t phi, Double_t theta) const
335 {
336   // XX term of covariance matrix after rotation by phi around z-axis
337   // and, then, by theta around new y-axis
338
339   if (!fCovMatrix) {
340     //AliFatal("Covariance matrix not set");
341     return -999.;
342   }
343
344   Double_t covMatrix[6];
345
346   GetCovMatrix(covMatrix);
347
348   Double_t cp = TMath::Cos(phi);
349   Double_t sp = TMath::Sin(phi);
350   Double_t ct = TMath::Cos(theta);
351   Double_t st = TMath::Sin(theta);
352   return
353      covMatrix[0]*cp*cp*ct*ct  // GetCovXX
354     +covMatrix[1]*2.*cp*sp*ct*ct  // GetCovXY
355     +covMatrix[3]*2.*cp*ct*st  // GetCovXZ
356     +covMatrix[2]*sp*sp*ct*ct  // GetCovYY
357     +covMatrix[4]*2.*sp*ct*st  // GetCovYZ
358     +covMatrix[5]*st*st;  // GetCovZZ
359 }
360
361 //______________________________________________________________________________
362 Double_t AliAODVertex::RotatedCovMatrixXY(Double_t phi, Double_t theta) const
363 {
364   // XY term of covariance matrix after rotation by phi around z-axis
365   // and, then, by theta around new y-axis
366
367   if (!fCovMatrix) {
368     //AliFatal("Covariance matrix not set");
369     return -999.;
370   }
371
372   Double_t covMatrix[6];
373
374   GetCovMatrix(covMatrix);
375
376   Double_t cp = TMath::Cos(phi);
377   Double_t sp = TMath::Sin(phi);
378   Double_t ct = TMath::Cos(theta);
379   Double_t st = TMath::Sin(theta);
380   return 
381     -covMatrix[0]*cp*sp*ct  // GetCovXX
382     +covMatrix[1]*ct*(cp*cp-sp*sp)  // GetCovXY
383     -covMatrix[3]*sp*st  // GetCovXZ
384     +covMatrix[2]*cp*sp*ct  // GetCovYY
385     +covMatrix[4]*cp*st;  // GetCovYZ
386 }
387
388 //______________________________________________________________________________
389 Double_t AliAODVertex::RotatedCovMatrixXZ(Double_t phi, Double_t theta) const
390 {
391   // XZ term of covariance matrix after rotation by phi around z-axis
392   // and, then, by theta around new y-axis
393
394   if (!fCovMatrix) {
395     //AliFatal("Covariance matrix not set");
396     return -999.;
397   }
398
399   Double_t covMatrix[6];
400
401   GetCovMatrix(covMatrix);
402
403   Double_t cp = TMath::Cos(phi);
404   Double_t sp = TMath::Sin(phi);
405   Double_t ct = TMath::Cos(theta);
406   Double_t st = TMath::Sin(theta);
407   return 
408     -covMatrix[0]*cp*cp*ct*st  // GetCovXX
409     -covMatrix[1]*2.*cp*sp*ct*st  // GetCovXY
410     +covMatrix[3]*cp*(ct*ct-st*st)  // GetCovXZ
411     -covMatrix[2]*sp*sp*ct*st  // GetCovYY
412     +covMatrix[4]*sp*(ct*ct-st*st)  // GetCovYZ
413     +covMatrix[5]*ct*st;  // GetCovZZ
414 }
415
416 //______________________________________________________________________________
417 Double_t AliAODVertex::RotatedCovMatrixYY(Double_t phi) const
418 {
419   // YY term of covariance matrix after rotation by phi around z-axis
420   // and, then, by theta around new y-axis
421
422   if (!fCovMatrix) {
423     //AliFatal("Covariance matrix not set");
424     return -999.;
425   }
426
427   Double_t covMatrix[6];
428
429   GetCovMatrix(covMatrix);
430
431   Double_t cp = TMath::Cos(phi);
432   Double_t sp = TMath::Sin(phi);
433   return
434      covMatrix[0]*sp*sp  // GetCovXX
435     -covMatrix[1]*2.*cp*sp  // GetCovXY
436     +covMatrix[2]*cp*cp;  // GetCovYY
437 }
438
439 //______________________________________________________________________________
440 Double_t AliAODVertex::RotatedCovMatrixYZ(Double_t phi, Double_t theta) const
441 {
442   // YZ term of covariance matrix after rotation by phi around z-axis
443   // and, then, by theta around new y-axis
444
445   if (!fCovMatrix) {
446     //AliFatal("Covariance matrix not set");
447     return -999.;
448   }
449
450   Double_t covMatrix[6];
451
452   GetCovMatrix(covMatrix);
453
454   Double_t cp = TMath::Cos(phi);
455   Double_t sp = TMath::Sin(phi);
456   Double_t ct = TMath::Cos(theta);
457   Double_t st = TMath::Sin(theta);
458   return 
459      covMatrix[0]*cp*sp*st  // GetCovXX
460     +covMatrix[1]*st*(sp*sp-cp*cp)  // GetCovXY
461     -covMatrix[3]*sp*ct  // GetCovXZ
462     -covMatrix[2]*cp*sp*st  // GetCovYY
463     +covMatrix[4]*cp*ct;  // GetCovYZ
464 }
465
466 //______________________________________________________________________________
467 Double_t AliAODVertex::RotatedCovMatrixZZ(Double_t phi, Double_t theta) const
468 {
469   // ZZ term of covariance matrix after rotation by phi around z-axis
470   // and, then, by theta around new y-axis
471
472   if (!fCovMatrix) {
473     //AliFatal("Covariance matrix not set");
474     return -999.;
475   }
476
477   Double_t covMatrix[6];
478
479   GetCovMatrix(covMatrix);
480
481   Double_t cp = TMath::Cos(phi);
482   Double_t sp = TMath::Sin(phi);
483   Double_t ct = TMath::Cos(theta);
484   Double_t st = TMath::Sin(theta);
485   return
486      covMatrix[0]*cp*cp*st*st  // GetCovXX
487     +covMatrix[1]*2.*cp*sp*st*st  // GetCovXY
488     -covMatrix[3]*2.*cp*ct*st  // GetCovXZ
489     +covMatrix[2]*sp*sp*st*st  // GetCovYY
490     -covMatrix[4]*2.*sp*sp*ct*st  // GetCovYZ
491     +covMatrix[5]*ct*ct;  // GetCovZZ
492 }
493
494 //______________________________________________________________________________
495 Double_t AliAODVertex::Distance2ToVertex(const AliAODVertex *vtx) const
496 {
497   // distance in 3D to another AliAODVertex
498
499   Double_t dx = GetX()-vtx->GetX();
500   Double_t dy = GetY()-vtx->GetY();
501   Double_t dz = GetZ()-vtx->GetZ();
502
503   return dx*dx+dy*dy+dz*dz;
504 }
505
506 //______________________________________________________________________________
507 Double_t AliAODVertex::DistanceXY2ToVertex(const AliAODVertex *vtx) const
508 {
509   // distance in XY to another AliAODVertex
510
511   Double_t dx = GetX()-vtx->GetX();
512   Double_t dy = GetY()-vtx->GetY();
513
514   return dx*dx+dy*dy;
515 }
516
517 //______________________________________________________________________________
518 Double_t AliAODVertex::Error2DistanceToVertex(AliAODVertex *vtx) const
519 {
520   // error on the distance in 3D to another AliAODVertex
521
522   Double_t phi,theta;
523   PhiAndThetaToVertex(vtx,phi,theta);
524   // error2 due to this vertex
525   Double_t error2 = RotatedCovMatrixXX(phi,theta);
526   // error2 due to vtx vertex
527   Double_t error2vtx = vtx->RotatedCovMatrixXX(phi,theta);
528
529   return error2+error2vtx;
530 }
531
532 //______________________________________________________________________________
533 Double_t AliAODVertex::Error2DistanceXYToVertex(AliAODVertex *vtx) const
534 {
535   // error on the distance in XY to another AliAODVertex
536
537   Double_t phi,theta;
538   PhiAndThetaToVertex(vtx,phi,theta);
539   // error2 due to this vertex
540   Double_t error2 = RotatedCovMatrixXX(phi);
541   // error2 due to vtx vertex
542   Double_t error2vtx = vtx->RotatedCovMatrixXX(phi);
543
544   return error2+error2vtx;
545 }
546
547 //______________________________________________________________________________
548 template <class T, class P> 
549 void AliAODVertex::PhiAndThetaToVertex(AliAODVertex *vtx, P &phi, T &theta) const
550 {
551   // rotation angles around z-axis (phi) and around new y-axis (theta)
552   // with which vtx is seen (used by RotatedCovMatrix... methods)
553
554   phi = TMath::Pi()+TMath::ATan2(-vtx->GetY()+GetY(),-vtx->GetX()+GetX());
555   Double_t vtxxphi = vtx->GetX()*TMath::Cos(phi)+vtx->GetY()*TMath::Sin(phi);
556   Double_t xphi = GetX()*TMath::Cos(phi)+GetY()*TMath::Sin(phi);
557   theta = TMath::ATan2(vtx->GetZ()-GetZ(),vtxxphi-xphi);
558 }
559
560 //______________________________________________________________________________
561 void AliAODVertex::PrintIndices() const 
562 {
563   // Print indices of particles originating form this vertex
564
565   TRefArrayIter iter(&fDaughters);
566   while (TObject *daugh = iter.Next()) {
567     printf("Particle %p originates from this vertex.\n", static_cast<void*>(daugh));
568   }
569 }
570
571 //______________________________________________________________________________
572 const char* AliAODVertex::AsString() const
573 {
574   // Make a string describing this object
575   
576   TString tmp(Form("%10s pos(%7.2f,%7.2f,%7.2f)",GetTypeName((AODVtx_t)GetType()),GetX(),GetY(),GetZ()));
577   
578   if (GetType()==kPrimary || GetType()==kMainSPD || GetType()==kPileupSPD )
579   {
580     tmp += Form(" ncontrib %d chi2/ndf %4.1f",GetNContributors(),GetChi2perNDF());
581
582   }
583   
584   if ( !fParent.GetObject() ) 
585   {
586     tmp += " no parent";
587   }
588   if ( fDaughters.GetEntriesFast() > 0 )
589   {
590     if ( fDaughters.GetEntriesFast() == 1 ) 
591     {
592       tmp += " origin of 1 particle";
593     }
594     else
595     {
596       tmp += Form(" origin of %2d particles",fDaughters.GetEntriesFast());
597     }
598   }
599   
600   return tmp.Data();
601 }
602
603 //______________________________________________________________________________
604 const char* AliAODVertex::GetTypeName(AODVtx_t type)
605 {
606   // Return an ASCII version of type
607   
608   switch (type)
609   {
610     case kPrimary:
611       return "primary";
612       break;
613     case kKink:
614       return "kink";
615       break;
616     case kV0:
617       return "v0";
618       break;
619     case kCascade:
620       return "cascade";
621       break;
622     case kMainSPD:
623       return "mainSPD";
624       break;
625     case kPileupSPD:
626       return "pileupSPD";
627       break;
628     case kPileupTracks:
629       return "pileupTRK";
630       break;
631     case kMainTPC:
632       return "mainTPC";
633       break;
634     default:
635       return "unknown";
636       break;
637   };
638 }
639
640 //______________________________________________________________________________
641 void AliAODVertex::Print(Option_t* /*option*/) const 
642 {
643   // Print information of all data members
644
645   printf("Vertex position:\n");
646   printf("     x = %f\n", fPosition[0]);
647   printf("     y = %f\n", fPosition[1]);
648   printf("     z = %f\n", fPosition[2]);
649   printf(" parent particle: %p\n", static_cast<void*>(fParent.GetObject()));
650   printf(" origin of %d particles\n", fDaughters.GetEntriesFast());
651   printf(" vertex type %d\n", fType);
652   
653   /*
654   if (fCovMatrix) {
655     printf("Covariance matrix:\n");
656     printf(" %12.10f  %12.10f  %12.10f\n %12.10f  %12.10f  %12.10f\n %12.10f  %12.10f  %12.10f\n", 
657            fCovMatrix[0],
658            fCovMatrix[1],
659            fCovMatrix[3],
660            fCovMatrix[1],
661            fCovMatrix[2],
662            fCovMatrix[4],
663            fCovMatrix[3],
664            fCovMatrix[4],
665            fCovMatrix[5]); 
666            } */
667   printf(" Chi^2/NDF = %f\n", fChi2perNDF);
668 }
669