BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
FastVertexFit.cxx
Go to the documentation of this file.
1#include "VertexFit/FastVertexFit.h"
2#include "VertexFit/BField.h" //FIXME
3
4const double alpha = -0.00299792458;
5using namespace std;
6
7FastVertexFit* FastVertexFit::m_pointer = 0;
8
9FastVertexFit* FastVertexFit::instance() {
10 if ( m_pointer ) return m_pointer;
11 m_pointer = new FastVertexFit();
12 return m_pointer;
13}
14
16
17FastVertexFit::FastVertexFit() { ; }
18
20 m_D.clear();
21 m_W.clear();
22 m_DTWD.clear();
23 m_xp.clear();
24 m_chisq = 999;
25 m_Vx = HepVector( 3, 0 );
26 m_Evx = HepSymMatrix( 3, 0 );
27}
28
29void FastVertexFit::addTrack( const int number, const HepVector helix,
30 const HepSymMatrix err ) {
31 int ifail;
32 int ierr;
33 // HepSymMatrix err0(5, 0); //inverse of err;
34 // err0 = err.inverse(ifail);
35 HepSymMatrix Wc( 2, 0 );
36 Wc[0][0] = err[0][0];
37 Wc[0][1] = Wc[1][0] = err[0][3];
38 Wc[1][1] = err[3][3];
39 Wc = Wc.inverse( ifail );
40
41 HepVector p0( 3, 0 ), v0( 3, 0 );
42 double pxy = 1. / fabs( helix[2] );
43 p0[0] = 0 - pxy * sin( helix[1] ); // px
44 p0[1] = pxy * cos( helix[1] ); // py
45 p0[2] = pxy * helix[4]; // pz
46 v0[0] = helix[0] * cos( helix[1] ); // x
47 v0[1] = helix[0] * sin( helix[1] ); // y
48 v0[2] = helix[3]; // z
49
50 HepPoint3D vv0( v0[0], v0[1], v0[2] );
51 double bField = VertexFitBField::instance()->getBFieldZRef();
52
53 int charge = ( helix[2] > 0 ? +1 : -1 );
54 double a = alpha * bField * charge;
55 double T0 = sqrt( ( p0[0] + a * p0[1] ) * ( p0[0] + a * p0[1] ) +
56 ( p0[1] - a * p0[0] ) * ( p0[1] - a * p0[0] ) );
57
58 HepMatrix Dc( 2, 3, 0 );
59 Dc[0][0] = ( p0[1] - a * v0[0] ) / T0;
60 Dc[0][1] = 0 - ( p0[0] + a * v0[1] ) / T0;
61 Dc[1][0] = 0 - ( p0[2] / T0 ) * ( p0[0] + a * v0[1] ) / T0;
62 Dc[1][1] = 0 - ( p0[2] / T0 ) * ( p0[1] - a * v0[0] ) / T0;
63 Dc[1][2] = 1;
64
65 m_D.push_back( Dc );
66 m_W.push_back( Wc );
67
68 HepSymMatrix DTWD( 3, 0 );
69 DTWD = Wc.similarity( Dc.T() );
70 HepVector qTrk( 2, 0 );
71 qTrk[0] = helix[0];
72 qTrk[1] = helix[3];
73 // HepVector xp(3, 0);
74 // xp = Dc.inverse(ierr) * qTrk;
75 m_DTWD.push_back( DTWD );
76 m_xp.push_back( v0 );
77}
78
80 bool fitResult = false;
81
82 int ifail;
83 HepSymMatrix total_DTWD( 3, 0 );
84 HepVector total_xp( 3, 0 );
85
86 for ( int i = 0; i < m_DTWD.size(); i++ )
87 {
88 total_DTWD += m_DTWD[i];
89 total_xp += m_DTWD[i] * m_xp[i];
90 }
91 m_Vx = total_DTWD.inverse( ifail ) * total_xp;
92 m_Evx = total_DTWD.inverse( ifail );
93
94 double chisq = 0;
95 for ( int i = 0; i < m_xp.size(); i++ )
96 {
97 double chi2 = ( m_DTWD[i].similarity( ( m_xp[i] - m_Vx ).T() ) )[0][0];
98 chisq += chi2;
99 }
100 m_chisq = chisq;
101
102 fitResult = true;
103 return fitResult;
104}
105
106HepVector FastVertexFit::Pull() const {
107 HepVector pull( 3, 0 );
108 pull[0] = m_Vx[0] / sqrt( m_Evx[0][0] );
109 pull[1] = m_Vx[1] / sqrt( m_Evx[1][1] );
110 pull[2] = m_Vx[2] / sqrt( m_Evx[2][2] );
111 return pull;
112}
113
114// FastVertexFit::updateMatrices(const HepVector helix, const HepSymMatrix err) {
115
116//}
double alpha
static FastVertexFit * instance()
HepVector Pull() const
void addTrack(const int number, const HepVector helix, const HepSymMatrix err)