CbmRoot
CbmKFPrimaryVertexFinder.cxx
Go to the documentation of this file.
1 
9 
10 #include "CbmKF.h"
11 #include "CbmKFTrack.h"
12 
13 #include <vector>
14 
15 using std::vector;
16 
18 
19  void CbmKFPrimaryVertexFinder::Clear(Option_t* /*opt*/) {
20  Tracks.clear();
21 }
22 
24  Tracks.push_back(Track);
25 }
26 
27 void CbmKFPrimaryVertexFinder::SetTracks(vector<CbmKFTrackInterface*>& vTr) {
28  Tracks = vTr;
29 }
30 
32  //* Constants
33 
34  const Double_t CutChi2 = 3.5 * 3.5;
35  const Int_t MaxIter = 3;
36 
37  //* Vertex state vector and the covariance matrix
38 
39  Double_t r[3], *C = vtx.GetCovMatrix();
40 
41  //* Initialize the vertex
42 
43  for (Int_t i = 0; i < 6; i++)
44  C[i] = 0;
45  if (CbmKF::Instance()->vTargets.empty()) {
46  r[0] = r[1] = r[2] = 0.;
47  C[0] = C[2] = 5.;
48  C[5] = 0.25;
49  } else {
51  r[0] = r[1] = 0.;
52  r[2] = t.z;
53  C[0] = C[2] = t.RR / 3.5 / 3.5;
54  C[5] = (t.dz / 2 / 3.5) * (t.dz / 2 / 3.5);
55  }
56 
57  //* Iteratively fit vertex - number of iterations fixed at MaxIter
58 
59  for (Int_t iteration = 0; iteration < MaxIter; ++iteration) {
60 
61  //* Store vertex from previous iteration
62 
63  Double_t r0[3], C0[6];
64 
65  for (Int_t i = 0; i < 3; i++)
66  r0[i] = r[i];
67  for (Int_t i = 0; i < 6; i++)
68  C0[i] = C[i];
69 
70  //* Initialize the vertex covariance, Chi^2 & NDF
71 
72  C[0] = 100.;
73  C[1] = 0.;
74  C[2] = 100.;
75  C[3] = 0.;
76  C[4] = 0.;
77  C[5] = 100.;
78 
79  vtx.GetRefNDF() = -3;
80  vtx.GetRefChi2() = 0.;
81  vtx.GetRefNTracks() = 0;
82 
83  for (vector<CbmKFTrackInterface*>::iterator itr = Tracks.begin();
84  itr != Tracks.end();
85  ++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  Double_t a = 0, b = 0;
94  {
95  Double_t zeta[2] = {r0[0] - m[0], r0[1] - m[1]};
96 
97  //* Check track Chi^2 deviation from the r0 vertex estimate
98 
99  Double_t S[3] = {(C0[2] + V[2]), -(C0[1] + V[1]), (C0[0] + V[0])};
100  Double_t s = S[2] * S[0] - S[1] * S[1];
101  Double_t chi2 = zeta[0] * zeta[0] * S[0] + 2 * zeta[0] * zeta[1] * S[1]
102  + zeta[1] * zeta[1] * S[2];
103  if (chi2 > s * CutChi2) continue;
104 
105  //* Fit of vertex track slopes (a,b) to r0 vertex
106 
107  s = V[0] * V[2] - V[1] * V[1];
108  if (s < 1.E-20) continue;
109  s = 1. / s;
110  a = m[2]
111  + s
112  * ((V[3] * V[2] - V[4] * V[1]) * zeta[0]
113  + (-V[3] * V[1] + V[4] * V[0]) * zeta[1]);
114  b = m[3]
115  + s
116  * ((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]
155  + 2 * zeta[0] * zeta[1] * S[1]
156  + zeta[1] * zeta[1] * S[2] + T.GetRefChi2();
157  vtx.GetRefNDF() += 2 + T.GetRefNDF();
158  vtx.GetRefNTracks()++;
159 
160  //* Kalman gain K = CH'*S
161 
162  Double_t K[3][2];
163 
164  for (Int_t i = 0; i < 3; ++i) {
165  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 
169  //* New estimation of the vertex position r += K*zeta
170 
171  for (Int_t i = 0; i < 3; ++i)
172  r[i] += K[i][0] * zeta[0] + K[i][1] * zeta[1];
173 
174  //* New covariance matrix C -= K*(CH')'
175 
176  C[0] -= K[0][0] * CHt[0][0] + K[0][1] * CHt[0][1];
177  C[1] -= K[1][0] * CHt[0][0] + K[1][1] * CHt[0][1];
178  C[2] -= K[1][0] * CHt[1][0] + K[1][1] * CHt[1][1];
179  C[3] -= K[2][0] * CHt[0][0] + K[2][1] * CHt[0][1];
180  C[4] -= K[2][0] * CHt[1][0] + K[2][1] * CHt[1][1];
181  C[5] -= K[2][0] * CHt[2][0] + K[2][1] * CHt[2][1];
182 
183  } //* itr
184 
185  } //* finished iterations
186 
187  //* Copy state vector to output (covariance matrix was used directly )
188 
189  vtx.GetRefX() = r[0];
190  vtx.GetRefY() = r[1];
191  vtx.GetRefZ() = r[2];
192 }
CbmKFTube::z
Double_t z
Definition: CbmKFMaterial.h:92
CbmKFTube::RR
Double_t RR
Definition: CbmKFMaterial.h:93
CbmKFPrimaryVertexFinder.h
CbmKF.h
CbmKFPrimaryVertexFinder::Tracks
std::vector< CbmKFTrackInterface * > Tracks
Definition: CbmKFPrimaryVertexFinder.h:20
CbmKFTrack::GetTrack
Double_t * GetTrack()
Is it electron.
Definition: CbmKFTrack.h:58
CbmKFVertexInterface::GetRefNTracks
virtual Int_t & GetRefNTracks()
Number of Degrees of Freedom after fit.
Definition: CbmKFVertexInterface.cxx:34
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmKFPrimaryVertexFinder::AddTrack
void AddTrack(CbmKFTrackInterface *Track)
Definition: CbmKFPrimaryVertexFinder.cxx:23
CbmKFPrimaryVertexFinder::Fit
void Fit(CbmKFVertexInterface &vtx)
Definition: CbmKFPrimaryVertexFinder.cxx:31
CbmKF::vTargets
std::vector< CbmKFTube > vTargets
Definition: CbmKF.h:79
CbmKFVertexInterface::GetRefChi2
virtual Double_t & GetRefChi2()
Array[6] of covariance matrix.
Definition: CbmKFVertexInterface.cxx:32
CbmKFPrimaryVertexFinder
Definition: CbmKFPrimaryVertexFinder.h:18
CbmKFTrack::GetRefChi2
Double_t & GetRefChi2()
array[15] of covariance matrix
Definition: CbmKFTrack.h:60
CbmKF::Instance
static CbmKF * Instance()
Definition: CbmKF.h:39
CbmKFTrack::GetRefNDF
Int_t & GetRefNDF()
Chi^2 after fit.
Definition: CbmKFTrack.h:61
CbmKFVertexInterface::GetRefZ
virtual Double_t & GetRefZ()
Definition: CbmKFVertexInterface.cxx:30
CbmKFTrack::GetCovMatrix
Double_t * GetCovMatrix()
array[6] of track parameters(x,y,tx,ty,qp,z)
Definition: CbmKFTrack.h:59
CbmKFVertexInterface
Definition: CbmKFVertexInterface.h:24
CbmKFTube::dz
Double_t dz
Definition: CbmKFMaterial.h:92
CbmKFTrack.h
CbmKFVertexInterface::GetRefX
virtual Double_t & GetRefX()
Definition: CbmKFVertexInterface.cxx:28
CbmKFTrackInterface
Definition: CbmKFTrackInterface.h:26
CbmKFVertexInterface::GetRefY
virtual Double_t & GetRefY()
Definition: CbmKFVertexInterface.cxx:29
ClassImp
ClassImp(CbmKFPrimaryVertexFinder) void CbmKFPrimaryVertexFinder
Definition: CbmKFPrimaryVertexFinder.cxx:17
CbmKFTube
Definition: CbmKFMaterial.h:77
m
__m128 m
Definition: L1/vectors/P4_F32vec4.h:26
CbmKFTrack
Definition: CbmKFTrack.h:21
CbmKFVertexInterface::GetRefNDF
virtual Int_t & GetRefNDF()
Chi^2 after fit.
Definition: CbmKFVertexInterface.cxx:33
CbmKFPrimaryVertexFinder::SetTracks
void SetTracks(std::vector< CbmKFTrackInterface * > &vTracks)
Definition: CbmKFPrimaryVertexFinder.cxx:27
CbmKFVertexInterface::GetCovMatrix
virtual Double_t * GetCovMatrix()
Definition: CbmKFVertexInterface.cxx:31
CbmKFPrimaryVertexFinder::Clear
virtual void Clear(Option_t *opt="")
CbmKFTrackInterface::Extrapolate
Int_t Extrapolate(Double_t z, Double_t *QP0=0)
Access to i-th hit.
Definition: CbmKFTrackInterface.cxx:39