BOSS 6.6.4.p01
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}
85
87{
88// const double alpha = -0.00299792458;
89// const double field = 1.0;
90// double field_p = VertexFitBField::instance()->getBFieldZ(m_vpar_primary.vx());
91// double field_s = VertexFitBField::instance()->getBFieldZ(m_vpar_secondary.vx());
92// double field = (field_p + field_s) * 0.5 ;
93// std::cout << "field in SeconVertexFit= " << field << std::endl;
94
95 bool okfit = false;
96
97 HepVector aOrigin(10, 0);
98 HepVector aInfit(10, 0);
99 HepSymMatrix VaOrigin(10, 0);
100 HepSymMatrix VaInfit(10, 0);
101 aOrigin.sub(1, wTrackOrigin(0).w());
102 aOrigin.sub(8, m_vpar_primary.Vx());
103 VaOrigin.sub(1, wTrackOrigin(0).Ew());
104 VaOrigin.sub(8, m_vpar_primary.Evx());
105 HepVector ctOrigin(1, 0);
106 HepVector ctInfit(1, 0);
107 HepSymMatrix Vct(1, 0);
108 aInfit = aOrigin;
109 ctInfit = ctOrigin;
110
111 std::vector<double> chisq;
112 chisq.clear();
113 double chi2 = 999;
114 for(int it = 0; it < m_niter; it++)
115 {
116 HepMatrix D(3, 10, 0);
117 HepLorentzVector p4par = HepLorentzVector(aInfit[0], aInfit[1], aInfit[2], aInfit[3]);
118 HepMatrix E(3,1,0);
119 HepVector d(3, 0);
120 if (wTrackOrigin(0).charge() == 0)
121 {
122 D[0][4] = -1.0;
123 D[0][7] = 1.0;
124 D[1][5] = -1.0;
125 D[1][8] = 1.0;
126 D[2][6] = -1.0;
127 D[2][9] = 1.0;
128
129 E[0][0] = p4par.px()/p4par.m();
130 E[1][0] = p4par.py()/p4par.m();
131 E[2][0] = p4par.pz()/p4par.m();
132
133 d[0] = aInfit[7]-aInfit[4]+ctInfit[0]*p4par.px()/p4par.m();
134 d[1] = aInfit[8]-aInfit[5]+ctInfit[0]*p4par.py()/p4par.m();
135 d[2] = aInfit[9]-aInfit[6]+ctInfit[0]*p4par.pz()/p4par.m();
136 }
137 else
138 {
139 double afield = VertexFitBField::instance()->getCBz(m_vpar_primary.Vx(), m_vpar_secondary.Vx());
140 double a = afield * wTrackOrigin(0).charge();
141 D[0][4] = -1.0;
142 D[0][7] = 1.0;
143 D[1][5] = -1.0;
144 D[1][8] = 1.0;
145 D[2][6] = -1.0;
146 D[2][9] = 1.0;
147
148 E[0][0] = p4par.px() / p4par.m() * cos(a * ctInfit[0] / p4par.m()) + p4par.py() / p4par.m() * sin(a * ctInfit[0] / p4par.m());
149 E[1][0] = p4par.py() / p4par.m() * cos(a * ctInfit[0] / p4par.m()) - p4par.px() / p4par.m() * sin(a * ctInfit[0] / p4par.m());
150 E[2][0] = p4par.pz() / p4par.m();
151
152 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()));
153 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()));
154 d[2] = aInfit[9] - aInfit[6]+ctInfit[0]*p4par.pz()/p4par.m();
155 }
156
157 HepSymMatrix VD(3, 0);
158 HepVector dela0(10, 0);
159 HepVector lambda0(3, 0);
160 HepVector delct(1, 0);
161 HepVector lambda(3, 0);
162 int ifail;
163
164 VD = (VaOrigin.similarity(D)).inverse(ifail);
165 dela0 = aOrigin - aInfit;
166 lambda0 = VD*(D*dela0 + d);
167 Vct = (VD.similarity(E.T())).inverse(ifail);
168 delct = -(Vct * E.T()) * lambda0;
169 ctInfit = ctInfit + delct;
170 lambda = lambda0 + (VD * E) * delct;
171 aInfit = aOrigin - (VaOrigin * D.T()) * lambda;
172 chi2 = dot(lambda, D*dela0 + d);
173 VaInfit = VaOrigin - (VD.similarity(D.T())).similarity(VaOrigin);
174 VaInfit = VaInfit + (((Vct.similarity(E)).similarity(VD)).similarity(D.T())).similarity(VaOrigin);
175
176 chisq.push_back(chi2);
177
178 if(it > 0)
179 {
180 double delchi = chisq[it] - chisq[it-1];
181 if (fabs(delchi) < m_chiter)
182 {
183// std::cout <<"Fit(): pass all " << it <<" , " << delchi << std::endl;
184 break;
185 }
186 }
187 }
188 if (chi2 < 0 || chi2 > m_chicut)
189 return okfit;
190
191 HepLorentzVector p4par = HepLorentzVector(aInfit[0], aInfit[1], aInfit[2], aInfit[3]);
192 m_ctau = ctInfit[0];
193 m_ctau_error = sqrt(Vct[0][0]);
194 m_lxyz = ctInfit[0] * p4par.rho() / p4par.m();
195 m_lxyz_error = sqrt(Vct[0][0]) * p4par.rho() / p4par.m();
196 m_chisq = chi2;
197 m_p4par = p4par;
198 for(int i = 0; i < 3; i++)
199 m_crxyz[i] = aInfit[4+i];
200 HepVector w(7, 0);
201 HepSymMatrix Ew(7, 0);
202 for(int i = 0; i < 7; i++)
203 {
204 w[i] = aInfit[i];
205 for(int j = 0; j < 7; j++)
206 {
207 Ew[i][j] = VaInfit[i][j];
208 }
209 }
210 m_wtrk.setW(w);
211 m_wtrk.setEw(Ew);
212 m_wtrk.setCharge(wTrackOrigin(0).charge());
213 okfit = true;
214 return okfit;
215}
216
217
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)