Bug fix. Removed delete statement
[u/mrichter/AliRoot.git] / STEER / AliKFVertex.cxx
1 //----------------------------------------------------------------------------
2 // Implementation of the AliKFVertex class
3 // .
4 // @author  S.Gorbunov, I.Kisel
5 // @version 1.0
6 // @since   13.05.07
7 // 
8 // Class to reconstruct and store primary and secondary vertices
9 // The method is described in CBM-SOFT note 2007-003, 
10 // ``Reconstruction of decayed particles based on the Kalman filter'', 
11 // http://www.gsi.de/documents/DOC-2007-May-14-1.pdf
12 //
13 // This class is ALICE interface to general mathematics in AliKFParticleCore
14 // 
15 //  -= Copyright &copy ALICE HLT Group =-
16 //____________________________________________________________________________
17
18
19 #include "AliKFVertex.h"
20 #include "Riostream.h"
21
22 ClassImp(AliKFVertex)
23
24
25 AliKFVertex::AliKFVertex( const AliVVertex &vertex ): fIsConstrained(0)
26 {
27   // Constructor from ALICE VVertex
28
29   vertex.GetXYZ( fP );
30   vertex.GetCovarianceMatrix( fC );  
31   fChi2 = vertex.GetChi2();  
32   fNDF = 2*vertex.GetNContributors() - 3;
33   fQ = 0;
34   fAtProductionVertex = 0;
35   fIsLinearized = 0;
36   fSFromDecay = 0;
37 }
38
39 /*
40 void     AliKFVertex::Print(Option_t* ) const
41 {  
42   cout<<"AliKFVertex position:    "<<GetX()<<" "<<GetY()<<" "<<GetZ()<<endl;
43   cout<<"AliKFVertex cov. matrix: "<<GetCovariance(0)<<endl;
44   cout<<"                         "<<GetCovariance(1)<<" "<<GetCovariance(2)<<endl;
45   cout<<"                         "<<GetCovariance(3)<<" "<<GetCovariance(4)<<" "<<GetCovariance(5)<<endl;
46 }
47   */
48
49 void AliKFVertex::SetBeamConstraint( Double_t x, Double_t y, Double_t z, 
50                                       Double_t errX, Double_t errY, Double_t errZ )
51 {
52   // Set beam constraint to the vertex
53   fP[0] = x;
54   fP[1] = y;
55   fP[2] = z;
56   fC[0] = errX*errX;
57   fC[1] = 0;
58   fC[2] = errY*errY;
59   fC[3] = 0;
60   fC[4] = 0;
61   fC[5] = errZ*errZ;
62   fIsConstrained = 1;
63 }
64
65 void AliKFVertex::SetBeamConstraintOff()
66 {
67   fIsConstrained = 0;
68 }
69
70 void AliKFVertex::ConstructPrimaryVertex( const AliKFParticle *vDaughters[], 
71                                           int NDaughters, Bool_t vtxFlag[],
72                                           Double_t ChiCut  )
73 {
74   //* Primary vertex finder with simple rejection of outliers
75   if( NDaughters<2 ) return;
76   Construct( vDaughters, NDaughters, 0, -1, fIsConstrained );
77   for( int i=0; i<NDaughters; i++ ) vtxFlag[i] = 1;
78
79   Int_t nRest = NDaughters;
80   while( nRest>2 )
81     {    
82       Double_t worstChi = 0.;
83       Int_t worstDaughter = 0;
84       for( Int_t it=0; it<NDaughters; it++ ){
85         if( !vtxFlag[it] ) continue;
86         const AliKFParticle &p = *(vDaughters[it]);
87         AliKFVertex tmp = *this - p;
88         Double_t chi = p.GetDeviationFromVertex( tmp );      
89         if( worstChi < chi ){
90           worstChi = chi;
91           worstDaughter = it;
92         }
93       }
94       if( worstChi < ChiCut ) break;
95       
96       vtxFlag[worstDaughter] = 0;    
97       *this -= *(vDaughters[worstDaughter]);
98       nRest--;
99     } 
100
101   if( nRest<=2 && GetChi2()>ChiCut*ChiCut*GetNDF() ){
102     for( int i=0; i<NDaughters; i++ ) vtxFlag[i] = 0;
103     fNDF = -3;
104     fChi2 = 0;
105   }
106 }