CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
SecondVertexFit.cxx
Go to the documentation of this file.
2#include "VertexFit/BField.h"
3
4//----------------------------------------------------
5// In Second Vertex Fit:
6//
7// Fitting Parameters
8// (px, py, pz, E, xd, yd, zd, xp, yp, zp)
9//
10// Constraints (charge = 0)
11//
12// xp - xd + px/m * ct = 0
13// yp - yd + py/m * ct = 0
14// zp - zd + pz/m * ct = 0
15//
16// ( 0 0 0 0 -1 0 0 1 0 0 )
17// D = ( 0 0 0 0 0 -1 0 0 1 0 )
18// ( 0 0 0 0 0 0 -1 0 0 1 )
19//
20// ( px/m )
21// E = ( py/m )
22// ( pz/m )
23//
24// ( xp - xd + px/m * ct )
25// d = ( yp - yd + py/m * ct )
26// ( zp - zd + pz/m * ct )
27//
28// Constraints (charge != 0)
29//
30// xp - xd + px/a * sin(a ctau/m) + py/a(1-cos(a ctau/m)) = 0
31// yp - yd + py/a * sin(a ctau/m) - px/a(1-cos(a ctau/m)) = 0
32// zp - zd + pz/m ctau = 0
33// ( 0 0 0 0 -1 0 0 1 0 0 )
34// D = ( 0 0 0 0 0 -1 0 0 1 0 )
35// ( 0 0 0 0 0 0 -1 0 0 1 )
36//
37// ( px/m cos(a * ct/m) + py/m * sin (a * ct/m))
38// E = ( py/m cos(a * ct/m) - px/m * sin (a * ct/m))
39// ( pz/m )
40//
41//----------------------------------------------------
42
43SecondVertexFit *SecondVertexFit::m_pointer = 0;
44
46{
47 if (m_pointer)
48 return m_pointer;
49 m_pointer = new SecondVertexFit();
50 return m_pointer;
51}
52
53SecondVertexFit::SecondVertexFit()
54{
55 HepVector vx(3,0);
56 m_vpar_primary.setVx(vx);
57 HepSymMatrix evx(3,0);
58 evx[0][0] = 0.1 * 0.1;
59 evx[1][1] = 0.1 * 0.1;
60 evx[2][2] = 1.5 * 1.5;
61 m_vpar_primary.setEvx(evx);
62}
63
65{
66 //if(m_pointer) delete m_pointer;
67}
68
70{
74 m_vpar_secondary = VertexParameter();
75 m_lxyz = 0;
76 m_lxyz_error = 0;
77 m_p4par = HepLorentzVector(0, 0, 0, 0);
78 m_crxyz = HepVector(3, 0);
79 m_chisq = 9999;
80 m_wtrk = WTrackParameter();
81 m_niter = 10;
82 m_chicut = 500;
83 m_chiter = 1.0e-2;
84 m_factor = 1.000;
85}
86
88{
89 bool okfit = false;
90
91 HepVector aOrigin(10, 0);
92 HepVector aInfit(10, 0);
93 HepSymMatrix VaOrigin(10, 0);
94 HepSymMatrix VaInfit(10, 0);
95 aOrigin.sub(1, wTrackOrigin(0).w());
96 aOrigin.sub(8, m_vpar_primary.Vx());
97 VaOrigin.sub(1, wTrackOrigin(0).Ew());
98 VaOrigin.sub(8, m_vpar_primary.Evx());
99 HepVector ctOrigin(1, 0);
100 HepVector ctInfit(1, 0);
101 HepSymMatrix Vct(1, 0);
102 aInfit = aOrigin;
103 ctInfit = ctOrigin;
104
105 std::vector<double> chisq;
106 chisq.clear();
107 double chi2 = 999;
108 for(int it = 0; it < m_niter; it++)
109 {
110 HepMatrix D(3, 10, 0);
111 HepLorentzVector p4par = HepLorentzVector(aInfit[0], aInfit[1], aInfit[2], aInfit[3]);
112 HepMatrix E(3,1,0);
113 HepVector d(3, 0);
114 if (wTrackOrigin(0).charge() == 0)
115 {
116 D[0][4] = -1.0;
117 D[0][7] = 1.0;
118 D[1][5] = -1.0;
119 D[1][8] = 1.0;
120 D[2][6] = -1.0;
121 D[2][9] = 1.0;
122
123 E[0][0] = p4par.px()/p4par.m();
124 E[1][0] = p4par.py()/p4par.m();
125 E[2][0] = p4par.pz()/p4par.m();
126
127 d[0] = aInfit[7]-aInfit[4]+ctInfit[0]*p4par.px()/p4par.m();
128 d[1] = aInfit[8]-aInfit[5]+ctInfit[0]*p4par.py()/p4par.m();
129 d[2] = aInfit[9]-aInfit[6]+ctInfit[0]*p4par.pz()/p4par.m();
130 }
131 else
132 {
133// double afield = VertexFitBField::instance()->getCBz(m_vpar_primary.Vx(), m_vpar_secondary.Vx());
134 double afield = m_factor * VertexFitBField::instance()->getCBz(m_vpar_primary.Vx(), m_vpar_secondary.Vx());
135 double a = afield * wTrackOrigin(0).charge();
136 D[0][4] = -1.0;
137 D[0][7] = 1.0;
138 D[1][5] = -1.0;
139 D[1][8] = 1.0;
140 D[2][6] = -1.0;
141 D[2][9] = 1.0;
142
143 E[0][0] = p4par.px() / p4par.m() * cos(a * ctInfit[0] / p4par.m()) + p4par.py() / p4par.m() * sin(a * ctInfit[0] / p4par.m());
144 E[1][0] = p4par.py() / p4par.m() * cos(a * ctInfit[0] / p4par.m()) - p4par.px() / p4par.m() * sin(a * ctInfit[0] / p4par.m());
145 E[2][0] = p4par.pz() / p4par.m();
146
147 d[0] = aInfit[7] - aInfit[4]+p4par.px()/a * sin(a * ctInfit[0]/p4par.m()) + p4par.py()/a*(1-cos(a*ctInfit[0]/p4par.m()));
148 d[1] = aInfit[8] - aInfit[5]+p4par.py()/a * sin(a * ctInfit[0]/p4par.m()) - p4par.px()/a*(1-cos(a*ctInfit[0]/p4par.m()));
149 d[2] = aInfit[9] - aInfit[6]+ctInfit[0]*p4par.pz()/p4par.m();
150 }
151
152 HepSymMatrix VD(3, 0);
153 HepVector dela0(10, 0);
154 HepVector lambda0(3, 0);
155 HepVector delct(1, 0);
156 HepVector lambda(3, 0);
157 int ifail;
158
159 VD = (VaOrigin.similarity(D)).inverse(ifail);
160 dela0 = aOrigin - aInfit;
161 lambda0 = VD*(D*dela0 + d);
162 Vct = (VD.similarity(E.T())).inverse(ifail);
163 delct = -(Vct * E.T()) * lambda0;
164 ctInfit = ctInfit + delct;
165 lambda = lambda0 + (VD * E) * delct;
166 aInfit = aOrigin - (VaOrigin * D.T()) * lambda;
167 chi2 = dot(lambda, D*dela0 + d);
168 VaInfit = VaOrigin - (VD.similarity(D.T())).similarity(VaOrigin);
169 VaInfit = VaInfit + (((Vct.similarity(E)).similarity(VD)).similarity(D.T())).similarity(VaOrigin);
170
171 chisq.push_back(chi2);
172
173 if(it > 0)
174 {
175 double delchi = chisq[it] - chisq[it-1];
176 if (fabs(delchi) < m_chiter) break;
177 }
178 }
179 if (chi2 < 0 || chi2 > m_chicut)
180 return okfit;
181
182 HepLorentzVector p4par = HepLorentzVector(aInfit[0], aInfit[1], aInfit[2], aInfit[3]);
183 m_ctau = ctInfit[0];
184 m_ctau_error = sqrt(Vct[0][0]);
185 m_lxyz = ctInfit[0] * p4par.rho() / p4par.m();
186 m_lxyz_error = sqrt(Vct[0][0]) * p4par.rho() / p4par.m();
187 m_chisq = chi2;
188 m_p4par = p4par;
189 for(int i = 0; i < 3; i++)
190 m_crxyz[i] = aInfit[4+i];
191 HepVector w(7, 0);
192 HepSymMatrix Ew(7, 0);
193 for(int i = 0; i < 7; i++)
194 {
195 w[i] = aInfit[i];
196 for(int j = 0; j < 7; j++)
197 {
198 Ew[i][j] = VaInfit[i][j];
199 }
200 }
201 m_wtrk.setW(w);
202 m_wtrk.setEw(Ew);
203 m_wtrk.setCharge(wTrackOrigin(0).charge());
204 okfit = true;
205 return okfit;
206}
207
208
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
HepLorentzVector p4par() const
static SecondVertexFit * instance()
double chisq() const
void clearWTrackOrigin()
Definition: TrackPool.h:111
void clearWTrackList()
Definition: TrackPool.h:113
std::vector< WTrackParameter > wTrackOrigin() const
Definition: TrackPool.h:72
void clearWTrackInfit()
Definition: TrackPool.h:112
double getCBz(const HepVector &vtx, const HepVector &trackPosition)
HepSymMatrix Evx() const
void setEvx(const HepSymMatrix &eVx)
HepVector Vx() const
void setVx(const HepPoint3D &vx)
void setEw(const HepSymMatrix &Ew)
void setCharge(const int charge)
void setW(const HepVector &w)