BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
SecondVertexFit.cxx
Go to the documentation of this file.
1#include "VertexFit/SecondVertexFit.h"
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
45SecondVertexFit* SecondVertexFit::instance() {
46 if ( m_pointer ) return m_pointer;
47 m_pointer = new SecondVertexFit();
48 return m_pointer;
49}
50
51SecondVertexFit::SecondVertexFit() {
52 HepVector vx( 3, 0 );
53 m_vpar_primary.setVx( vx );
54 HepSymMatrix evx( 3, 0 );
55 evx[0][0] = 0.1 * 0.1;
56 evx[1][1] = 0.1 * 0.1;
57 evx[2][2] = 1.5 * 1.5;
58 m_vpar_primary.setEvx( evx );
59}
60
62 // if(m_pointer) delete m_pointer;
63}
64
69 m_vpar_secondary = VertexParameter();
70 m_lxyz = 0;
71 m_lxyz_error = 0;
72 m_p4par = HepLorentzVector( 0, 0, 0, 0 );
73 m_crxyz = HepVector( 3, 0 );
74 m_chisq = 9999;
75 m_wtrk = WTrackParameter();
76 m_niter = 10;
77 m_chicut = 500;
78 m_chiter = 1.0e-2;
79 m_factor = 1.000;
80}
81
83 bool okfit = false;
84
85 HepVector aOrigin( 10, 0 );
86 HepVector aInfit( 10, 0 );
87 HepSymMatrix VaOrigin( 10, 0 );
88 HepSymMatrix VaInfit( 10, 0 );
89 aOrigin.sub( 1, wTrackOrigin( 0 ).w() );
90 aOrigin.sub( 8, m_vpar_primary.Vx() );
91 VaOrigin.sub( 1, wTrackOrigin( 0 ).Ew() );
92 VaOrigin.sub( 8, m_vpar_primary.Evx() );
93 HepVector ctOrigin( 1, 0 );
94 HepVector ctInfit( 1, 0 );
95 HepSymMatrix Vct( 1, 0 );
96 aInfit = aOrigin;
97 ctInfit = ctOrigin;
98
99 std::vector<double> chisq;
100 chisq.clear();
101 double chi2 = 999;
102 for ( int it = 0; it < m_niter; it++ )
103 {
104 HepMatrix D( 3, 10, 0 );
105 HepLorentzVector p4par = HepLorentzVector( aInfit[0], aInfit[1], aInfit[2], aInfit[3] );
106 HepMatrix E( 3, 1, 0 );
107 HepVector d( 3, 0 );
108 if ( wTrackOrigin( 0 ).charge() == 0 )
109 {
110 D[0][4] = -1.0;
111 D[0][7] = 1.0;
112 D[1][5] = -1.0;
113 D[1][8] = 1.0;
114 D[2][6] = -1.0;
115 D[2][9] = 1.0;
116
117 E[0][0] = p4par.px() / p4par.m();
118 E[1][0] = p4par.py() / p4par.m();
119 E[2][0] = p4par.pz() / p4par.m();
120
121 d[0] = aInfit[7] - aInfit[4] + ctInfit[0] * p4par.px() / p4par.m();
122 d[1] = aInfit[8] - aInfit[5] + ctInfit[0] * p4par.py() / p4par.m();
123 d[2] = aInfit[9] - aInfit[6] + ctInfit[0] * p4par.pz() / p4par.m();
124 }
125 else
126 {
127 // double afield =
128 //VertexFitBField::instance()->getCBz(m_vpar_primary.Vx(), m_vpar_secondary.Vx());
129 double afield = m_factor * VertexFitBField::instance()->getCBz( m_vpar_primary.Vx(),
130 m_vpar_secondary.Vx() );
131 double a = afield * wTrackOrigin( 0 ).charge();
132 D[0][4] = -1.0;
133 D[0][7] = 1.0;
134 D[1][5] = -1.0;
135 D[1][8] = 1.0;
136 D[2][6] = -1.0;
137 D[2][9] = 1.0;
138
139 E[0][0] = p4par.px() / p4par.m() * cos( a * ctInfit[0] / p4par.m() ) +
140 p4par.py() / p4par.m() * sin( a * ctInfit[0] / p4par.m() );
141 E[1][0] = p4par.py() / p4par.m() * cos( a * ctInfit[0] / p4par.m() ) -
142 p4par.px() / p4par.m() * sin( a * ctInfit[0] / p4par.m() );
143 E[2][0] = p4par.pz() / p4par.m();
144
145 d[0] = aInfit[7] - aInfit[4] + p4par.px() / a * sin( a * ctInfit[0] / p4par.m() ) +
146 p4par.py() / a * ( 1 - cos( a * ctInfit[0] / p4par.m() ) );
147 d[1] = aInfit[8] - aInfit[5] + p4par.py() / a * sin( a * ctInfit[0] / p4par.m() ) -
148 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() ) )
170 .similarity( VaOrigin );
171
172 chisq.push_back( chi2 );
173
174 if ( it > 0 )
175 {
176 double delchi = chisq[it] - chisq[it - 1];
177 if ( fabs( delchi ) < m_chiter ) break;
178 }
179 }
180 if ( chi2 < 0 || chi2 > m_chicut ) 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++ ) m_crxyz[i] = aInfit[4 + i];
190 HepVector w( 7, 0 );
191 HepSymMatrix Ew( 7, 0 );
192 for ( int i = 0; i < 7; i++ )
193 {
194 w[i] = aInfit[i];
195 for ( int j = 0; j < 7; j++ ) { Ew[i][j] = VaInfit[i][j]; }
196 }
197 m_wtrk.setW( w );
198 m_wtrk.setEw( Ew );
199 m_wtrk.setCharge( wTrackOrigin( 0 ).charge() );
200 okfit = true;
201 return okfit;
202}
double w
static SecondVertexFit * instance()
std::vector< WTrackParameter > wTrackOrigin() const
double getCBz(const HepVector &vtx, const HepVector &trackPosition)