BOSS 7.0.1
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
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, const HepSymMatrix err) {
30 int ifail;
31 int ierr;
32 //HepSymMatrix err0(5, 0); //inverse of err;
33 //err0 = err.inverse(ifail);
34 HepSymMatrix Wc(2, 0);
35 Wc[0][0] = err[0][0];
36 Wc[0][1] = Wc[1][0] = err[0][3];
37 Wc[1][1] = err[3][3];
38 Wc = Wc.inverse(ifail);
39
40 HepVector p0(3, 0), v0(3, 0);
41 double pxy = 1./fabs(helix[2]);
42 p0[0] = 0 - pxy*sin(helix[1]); //px
43 p0[1] = pxy*cos(helix[1]); //py
44 p0[2] = pxy * helix[4]; //pz
45 v0[0] = helix[0]*cos(helix[1]);//x
46 v0[1] = helix[0]*sin(helix[1]);//y
47 v0[2] = helix[3]; //z
48
49 HepPoint3D vv0(v0[0], v0[1], v0[2]);
50 double bField = VertexFitBField::instance()->getBFieldZRef();
51
52 int charge = (helix[2]>0 ? +1 :-1);
53 double a = alpha * bField * charge;
54 double T0 = sqrt((p0[0]+a*p0[1])*(p0[0]+a*p0[1])+(p0[1]-a*p0[0])*(p0[1]-a*p0[0]));
55
56 HepMatrix Dc(2, 3, 0);
57 Dc[0][0] = (p0[1] - a*v0[0])/T0;
58 Dc[0][1] = 0 - (p0[0] + a*v0[1])/T0;
59 Dc[1][0] = 0 - (p0[2]/T0) * (p0[0] + a*v0[1])/T0;
60 Dc[1][1] = 0 - (p0[2]/T0) * (p0[1] - a*v0[0])/T0;
61 Dc[1][2] = 1;
62
63 m_D.push_back(Dc);
64 m_W.push_back(Wc);
65
66 HepSymMatrix DTWD(3, 0);
67 DTWD = Wc.similarity(Dc.T());
68 HepVector qTrk(2, 0);
69 qTrk[0] = helix[0];
70 qTrk[1] = helix[3];
71 //HepVector xp(3, 0);
72 //xp = Dc.inverse(ierr) * qTrk;
73 m_DTWD.push_back(DTWD);
74 m_xp.push_back(v0);
75}
76
78 bool fitResult = false;
79
80 int ifail;
81 HepSymMatrix total_DTWD(3, 0);
82 HepVector total_xp(3, 0);
83
84 for(int i = 0; i < m_DTWD.size(); i++) {
85 total_DTWD += m_DTWD[i];
86 total_xp += m_DTWD[i]*m_xp[i];
87 }
88 m_Vx = total_DTWD.inverse(ifail) * total_xp;
89 m_Evx = total_DTWD.inverse(ifail);
90
91 double chisq = 0;
92 for(int i = 0; i < m_xp.size(); i++) {
93 double chi2 = (m_DTWD[i].similarity((m_xp[i] - m_Vx).T()))[0][0];
94 chisq += chi2;
95 }
96 m_chisq = chisq;
97
98 fitResult = true;
99 return fitResult;
100}
101
102HepVector FastVertexFit::Pull() const {
103 HepVector pull(3, 0);
104 pull[0] = m_Vx[0]/sqrt(m_Evx[0][0]);
105 pull[1] = m_Vx[1]/sqrt(m_Evx[1][1]);
106 pull[2] = m_Vx[2]/sqrt(m_Evx[2][2]);
107 return pull;
108}
109
110//FastVertexFit::updateMatrices(const HepVector helix, const HepSymMatrix err) {
111
112//}
const double alpha
double sin(const BesAngle a)
double cos(const BesAngle a)
static FastVertexFit * instance()
HepVector Pull() const
void addTrack(const int number, const HepVector helix, const HepSymMatrix err)