BmnRoot
Loading...
Searching...
No Matches
CbmKFPrimaryVertexFinder.cxx
Go to the documentation of this file.
1
9
10#include "CbmKF.h"
11#include "CbmKFTrack.h"
12
13#include <vector>
14
15using std::vector;
16
18{
19 Tracks.clear();
20}
21
23{
24 Tracks.push_back(Track);
25}
26
27void CbmKFPrimaryVertexFinder::SetTracks( vector<CbmKFTrackInterface*> &vTr )
28{
29 Tracks = vTr;
30}
31
33{
34 //* Constants
35
36 const Double_t CutChi2 = 3.5*3.5;
37 const Int_t MaxIter = 3;
38
39 //* Vertex state vector and the covariance matrix
40
41 Double_t r[3], *C = vtx.GetCovMatrix();
42
43 //* Initialize the vertex
44
45 for( Int_t i=0; i<6; i++ ) C[i]=0;
46 if( CbmKF::Instance()->vTargets.empty() ){
47 r[0] = r[1] = r[2] = 0.;
48 C[0] = C[2] = 5.;
49 C[5] = 0.25;
50 }else{
52 r[0] = r[1] = 0.;
53 r[2] = t.z;
54 C[0] = C[2] = t.RR/3.5/3.5;
55 C[5] = (t.dz/2/3.5)*(t.dz/2/3.5);
56 r[0] = 0.4; //AZ-210923 - run 8
57 //cout << t.x << " " << t.y << " " << t.z << endl; //AZ-180923
58 //cout << t.RR << " " << t.dz << endl; //AZ-180923
59 //exit(0); //AZ-180923
60 }
61
62 //* Iteratively fit vertex - number of iterations fixed at MaxIter
63
64 for( Int_t iteration = 0; iteration < MaxIter; ++iteration ){
65
66 //* Store vertex from previous iteration
67
68 Double_t r0[3], C0[6];
69
70 for( Int_t i=0; i<3; i++ ) r0[i] = r[i];
71 for( Int_t i=0; i<6; i++ ) C0[i] = C[i];
72
73 //* Initialize the vertex covariance, Chi^2 & NDF
74
75 C[0] = 100.;
76 C[1] = 0.; C[2] = 100.;
77 C[3] = 0.; C[4] = 0.; C[5] = 100.;
78
79 //AZ-210923 vtx.GetRefNDF() = -3;
80 vtx.GetRefNDF() = 0; //AZ-210923
81 vtx.GetRefChi2() = 0.;
82 vtx.GetRefNTracks() = 0;
83
84 for( vector<CbmKFTrackInterface*>::iterator itr = Tracks.begin();
85 itr != Tracks.end() ; ++itr ){
86
87 CbmKFTrack T(**itr);
88 Bool_t err = T.Extrapolate( r0[2] );
89 if( err ) continue;
90
91 Double_t *m = T.GetTrack();
92 Double_t *V = T.GetCovMatrix();
93 std::vector<Double_t> covMatr (V, V + 15); //AZ-190923
94 if (iteration == 0) { for (unsigned int j = 0; j < covMatr.size(); ++j) covMatr[j] *= 10; }; //AZ-190923
95 V = covMatr.data(); //AZ-190923
96 Double_t a = 0, b = 0;
97 {
98 Double_t zeta[2] = { r0[0]-m[0], r0[1]-m[1] };
99
100 //* Check track Chi^2 deviation from the r0 vertex estimate
101
102 //AZ-190923 Double_t S[3] = { (C0[2]+V[2]), -(C0[1]+V[1]), (C0[0]+V[0]) };
103 Double_t S[3] = { (C0[0]+V[0]), -(C0[1]+V[1]), (C0[2]+V[2]) }; //AZ-190923
104 Double_t s = S[2]*S[0] - S[1]*S[1];
105 Double_t chi2 = zeta[0]*zeta[0]*S[0] + 2*zeta[0]*zeta[1]*S[1]
106 + zeta[1]*zeta[1]*S[2];
107 if( chi2 > s*CutChi2 ) continue;
108
109 //* Fit of vertex track slopes (a,b) to r0 vertex
110
111 s = V[0]*V[2] - V[1]*V[1];
112 if ( s < 1.E-20 ) continue;
113 s = 1./s;
114 a = m[2] + s*( ( V[3]*V[2] - V[4]*V[1] )*zeta[0]
115 + (- V[3]*V[1] + V[4]*V[0] )*zeta[1] );
116 b = m[3] + s*( ( V[6]*V[2] - V[7]*V[1] )*zeta[0]
117 + (- V[6]*V[1] + V[7]*V[0] )*zeta[1] );
118 }
119
120 //** Update the vertex (r,C) with the track estimate (m,V) :
121
122 //* Linearized measurement matrix H = { { 1, 0, -a}, { 0, 1, -b} };
123
124 //* Residual (measured - estimated)
125
126 Double_t zeta[2] = { m[0] - ( r[0] - a*(r[2]-r0[2]) ),
127 m[1] - ( r[1] - b*(r[2]-r0[2]) ) };
128
129 //* CHt = CH'
130
131 Double_t CHt[3][2] = { { C[0] - a*C[3], C[1] - b*C[3]},
132 { C[1] - a*C[4], C[2] - b*C[4]},
133 { C[3] - a*C[5], C[4] - b*C[5]} };
134
135 //* S = (H*C*H' + V )^{-1}
136
137 Double_t S[3] = { V[0] + CHt[0][0] - a*CHt[2][0],
138 V[1] + CHt[1][0] - b*CHt[2][0],
139 V[2] + CHt[1][1] - b*CHt[2][1] };
140
141 //* Invert S
142 {
143 Double_t w = S[0]*S[2] - S[1]*S[1];
144 if ( w < 1.E-20 ) continue;
145 w = 1./w;
146 Double_t S0 = S[0];
147 S[0] = w*S[2];
148 S[1] = -w*S[1];
149 S[2] = w*S0;
150 }
151
152 //* Calculate Chi^2
153
154 vtx.GetRefChi2()+= zeta[0]*zeta[0]*S[0] + 2*zeta[0]*zeta[1]*S[1]
155 //AZ-190923 + zeta[1]*zeta[1]*S[2] + T.GetRefChi2();
156 + zeta[1]*zeta[1]*S[2]; //AZ-190923
157 //AZ-190923 vtx.GetRefNDF() += 2 + T.GetRefNDF();
158 vtx.GetRefNDF() += 2; //AZ-190923
159 vtx.GetRefNTracks()++;
160
161 //* Kalman gain K = CH'*S
162
163 Double_t K[3][2];
164
165 for( Int_t i=0; i<3; ++i ){ K[i][0] = CHt[i][0]*S[0] + CHt[i][1]*S[1] ;
166 K[i][1] = CHt[i][0]*S[1] + CHt[i][1]*S[2] ; }
167
168 //* New estimation of the vertex position r += K*zeta
169
170 for( Int_t i=0; i<3; ++i ) r[i]+= K[i][0]*zeta[0] + K[i][1]*zeta[1];
171
172 //* New covariance matrix C -= K*(CH')'
173
174 C[0] -= K[0][0]*CHt[0][0] + K[0][1]*CHt[0][1];
175 C[1] -= K[1][0]*CHt[0][0] + K[1][1]*CHt[0][1];
176 C[2] -= K[1][0]*CHt[1][0] + K[1][1]*CHt[1][1];
177 C[3] -= K[2][0]*CHt[0][0] + K[2][1]*CHt[0][1];
178 C[4] -= K[2][0]*CHt[1][0] + K[2][1]*CHt[1][1];
179 C[5] -= K[2][0]*CHt[2][0] + K[2][1]*CHt[2][1];
180
181 }//* itr
182
183 }//* finished iterations
184
185 //* Copy state vector to output (covariance matrix was used directly )
186
187 vtx.GetRefX() = r[0];
188 vtx.GetRefY() = r[1];
189 vtx.GetRefZ() = r[2];
190}
int i
Definition P4_F32vec4.h:22
__m128 m
Definition P4_F32vec4.h:27
void SetTracks(std::vector< CbmKFTrackInterface * > &vTracks)
void AddTrack(CbmKFTrackInterface *Track)
void Fit(CbmKFVertexInterface &vtx)
Int_t Extrapolate(Double_t z, Double_t *QP0=0, Bool_t line=false)
Access to i-th hit.
Double_t * GetTrack()
Is it electron.
Definition CbmKFTrack.h:51
Double_t * GetCovMatrix()
array[6] of track parameters(x,y,tx,ty,qp,z)
Definition CbmKFTrack.h:52
Double_t RR
Double_t dz
Double_t z
virtual Double_t & GetRefY()
virtual Double_t & GetRefX()
virtual Int_t & GetRefNTracks()
Number of Degrees of Freedom after fit.
virtual Double_t & GetRefZ()
virtual Double_t & GetRefChi2()
Array[6] of covariance matrix.
virtual Int_t & GetRefNDF()
Chi^2 after fit.
virtual Double_t * GetCovMatrix()
static CbmKF * Instance()
Definition CbmKF.h:35
std::vector< CbmKFTube > vTargets
Definition CbmKF.h:63