BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
VertexFit.h
Go to the documentation of this file.
1#ifndef VertexFit_VertexFit_H
2#define VertexFit_VertexFit_H
3
4#include <vector>
9
10// NOTE: if you want to update the parameters of daughter tracks after vertex fitting,
11// you should add the following code after invoking the interface "Fit()".
12// VertexFit->Swim(n);
13// here, n is vertex number.
14
15////////////////////////////////////////////////////////////////////////////////////////
16//
17// Attention: In this new Version, in order to find out why chisquare can be negative,
18// so when successfully returned from Fit(int n), you will find chisq may be negative.
19// You can Add this code:
20//
21// if (chisq < 0) return StatusCode::SUCCESS
22//
23// to avoid this situation
24//
25////////////////////////////////////////////////////////////////////////////////////////
26class VertexFit : public TrackPool
27{
28public:
29 // constructor & deconstructor
30 static VertexFit *instance();
31 ~VertexFit();
32
33 // initialization, must be called before VertexFit each time
34 void init();
35
36 // add methods
37 void AddVertex(int number, VertexParameter vpar, std::vector<int> lis);
38 void AddVertex(int number, VertexParameter vpar, int n1, int n2);
39 void AddVertex(int number, VertexParameter vpar, int n1, int n2, int n3);
40 void AddVertex(int number, VertexParameter vpar, int n1, int n2, int n3, int n4);
41 void AddVertex(int number, VertexParameter vpar, int n1, int n2, int n3, int n4, int n5);
42 void AddVertex(int number, VertexParameter vpar, int n1, int n2, int n3, int n4, int n5, int n6);
43 void AddVertex(int number, VertexParameter vpar, int n1, int n2, int n3, int n4, int n5, int n6, int n7);
44 void AddVertex(int number, VertexParameter vpar, int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8);
45 void AddVertex(int number, VertexParameter vpar, int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int n9);
46 void AddVertex(int number, VertexParameter vpar, int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int n9, int n10);
47 void AddVertex(int number, VertexParameter vpar, int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int n9, int n10, int n11);
48 void AddVertex(int number, VertexParameter vpar, int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int n9, int n10, int n11, int n12);
49 void AddBeamFit(int number, VertexParameter vpar, int n);
50
51 // build virtual particle, parameter number must be match with vertex number
52 void BuildVirtualParticle(int number);
53
54 // set iteration number and chisq cut
55 void setIterNumber(const int niter = 10) { m_niter = niter; }
56 void setChisqCut(const double chicut = 1000, const double chiter = 1.0e-3) { m_chicut = chicut;m_chiter=chiter; }
57
58 // fit function
59 bool Fit();
60 bool Fit(int n);
61 bool BeamFit(int n);
62
63 // renew track parameters and convariance
64 void Swim(int n){ vertexCovMatrix(n); swimVertex(n);}
65
66 //
67 // Fit Results
68 //
69
70 // chisq of fit
71 double chisq() const {return m_chi;}
72 double chisq(int n) const {return m_chisq[n];}
73
74 // Pull distribution for 5-helix parameters.
75 // Return true on success, the resulting pull will be stored in p;
76 // Return false on failure.
77 bool pull(int n, int itk, HepVector& p);
78
79 // updated WTrack parameter in vertex fit
80 HepLorentzVector pfit(int n) const {return wTrackInfit(n).p();}
81 HepPoint3D xfit(int n) const {return wTrackInfit(n).x();}
82 HepVector w(int n) const {return wTrackInfit(n).w();}
83 HepSymMatrix Ew(int n) const {return wTrackInfit(n).Ew();}
84 WTrackParameter wtrk(int n) const {return wTrackInfit(n);}
85
86 // time counter
87 HepVector cpu() const {return m_cpu;}
88
89 // updated Vertex Parameter in vertex fit
90 HepPoint3D vx(int n) const { return m_vpar_infit[n].vx();}
91 HepVector Vx(int n) const { return m_vpar_infit[n].Vx();}
92 HepSymMatrix Evx(int n) const { return m_vpar_infit[n].Evx();}
93 double errorVx(int n, int i) const { return sqrt((m_vpar_infit[n].Evx())[i][i]);}
94 VertexParameter vpar(int n) const {return m_vpar_infit[n];}
95
96 // virtual particle from Vertex Fit
97 WTrackParameter wVirtualTrack(int n) const {return m_virtual_wtrk[n];}
98
99 // Users need not care below
100private:
101 // renew vertex constraints
102 void UpdateConstraints(const VertexConstraints &vc);
103 // vertex fit
104 void fitVertex(int n);
105 // renew covariance of input track parameters
106 void vertexCovMatrix(int n);
107 // extrapolate input track parameters to the vertex
108 void swimVertex(int n);
109
110 void fitBeam(int n);
111 void swimBeam(int n);
112
113 // vertex parameters before fit
114 std::vector<VertexParameter> m_vpar_origin;
115 // vertex parameters in fit
116 std::vector<VertexParameter> m_vpar_infit;
117 // vertex constraints
118 std::vector<VertexConstraints> m_vc;
119 // chisquare counter
120 std::vector<double> m_chisq;
121 double m_chi; // total chisquare
122 int m_nvtrk; // number of WTracks in VertexFit
123 // virtual particle in WTrackParameter format
124 std::vector<WTrackParameter> m_virtual_wtrk;
125
126 // track parameters storage and access
127 // origin vertex and its covariance matrix
128 HepVector m_xOrigin;
129 HepSymMatrix m_xcovOrigin;
130 HepSymMatrix m_xcovOriginInversed;
131 inline HepVector xOrigin() const {return m_xOrigin;}
132 inline void setXOrigin(const HepVector &x) { m_xOrigin = x;}
133 inline HepSymMatrix xcovOrigin() const {return m_xcovOrigin;}
134 inline void setXCovOrigin(const HepSymMatrix &v) {m_xcovOrigin = v;}
135 inline HepSymMatrix xcovOriginInversed() const {return m_xcovOriginInversed;}
136 inline void setXCovOriginInversed(const HepSymMatrix &v){m_xcovOriginInversed = v;}
137
138 // vertex and covariance matrix in fit
139 HepVector m_xInfit;
140 HepSymMatrix m_xcovInfit;
141 HepSymMatrix m_xcovInfitInversed;
142 inline HepVector xInfit() const {return m_xInfit;}
143 inline void setXInfit(const HepVector &x) {m_xInfit = x;}
144 inline HepSymMatrix xcovInfit() const {return m_xcovInfit;}
145 void setXCovInfit(const HepSymMatrix &v) {m_xcovInfit = v;}
146 inline HepSymMatrix xcovInfitInversed() const {return m_xcovInfitInversed;}
147 void setXCovInfitInversed(const HepSymMatrix &v) {m_xcovInfitInversed = v;}
148
149 // track parameters and covariance matrice at initial
150 HepVector m_pOrigin;
151 HepSymMatrix m_pcovOrigin;
152 inline HepVector pOrigin(int i) const { return m_pOrigin.sub(i*NTRKPAR+1, (i+1)*NTRKPAR); }
153 inline void setPOrigin(int i, const HepVector &p) { m_pOrigin.sub(i*NTRKPAR+1, p); }
154 inline HepSymMatrix pcovOrigin(int i) const { return m_pcovOrigin.sub(i*NTRKPAR+1, (i+1)*NTRKPAR); }
155 inline void setPCovOrigin(int i, const HepSymMatrix &v) { m_pcovOrigin.sub(i*NTRKPAR+1,v); }
156
157 // track parameters and covariance matrice in fit
158 HepVector m_pInfit;
159 HepSymMatrix m_pcovInfit;
160 inline HepVector pInfit(int i) const { return m_pInfit.sub(i*NTRKPAR+1, (i+1)*NTRKPAR); }
161 inline void setPInfit(int i, const HepVector &p) { m_pInfit.sub(i*NTRKPAR+1, p); }
162 inline HepSymMatrix pcovInfit(int i) const { return m_pcovInfit.sub(i*NTRKPAR+1, (i+1)*NTRKPAR); }
163 inline void setPCovInfit(int i, const HepSymMatrix &v) { m_pcovInfit.sub(i*NTRKPAR+1, v); }
164
165 // some matrices convenient for calculation
166 HepMatrix m_B; // NCONSTR x NVTXPAR -- E
167 inline HepMatrix vfB(int i) const {return m_B.sub(i*NCONSTR+1, (i+1)*NCONSTR, 1, NVTXPAR);}
168 inline void setB(int i, const HepMatrix &e) {m_B.sub(i*NCONSTR+1, 1, e);}
169
170 HepMatrix m_BT; // NVTXPAR x NCONSTR -- E.T()
171 inline HepMatrix vfBT(int i) const {return m_BT.sub(1, NVTXPAR, i*NCONSTR+1, (i+1)*NCONSTR);}
172 inline void setBT(int i, const HepMatrix &e) {m_BT.sub(1, i*NCONSTR+1, e);}
173
174 HepMatrix m_A; // NCONSTR x NTRKPAR -- D
175 inline HepMatrix vfA(int i) const {return m_A.sub(i*NCONSTR+1, (i+1)*NCONSTR, i*NTRKPAR+1, (i+1)*NTRKPAR);}
176 inline void setA(int i, const HepMatrix &d) {m_A.sub(i*NCONSTR+1, i*NTRKPAR+1, d);}
177
178 HepMatrix m_AT; // NTRKPAR x NCONSTR -- D.T()
179 inline HepMatrix vfAT(int i) const {return m_AT.sub(i*NTRKPAR+1, (i+1)*NTRKPAR, i*NCONSTR+1, (i+1)*NCONSTR);}
180 inline void setAT(int i, const HepMatrix &d) {m_AT.sub(i*NTRKPAR+1, i*NCONSTR+1, d);}
181
182 HepMatrix m_KQ; // NVTXPAR x NCONSTR -- Vx E.T() VD
183 inline HepMatrix vfKQ(int i) const {return m_KQ.sub(1, NVTXPAR, i*NCONSTR+1, (i+1)*NCONSTR);}
184 inline void setKQ(int i, const HepMatrix &d) {m_KQ.sub(1, i*NCONSTR+1, d);}
185
186 HepVector m_G; // NCONSTR x 1 -- Dda + Edx + d
187 inline HepVector vfG(int i) const {return m_G.sub(i*NCONSTR+1, (i+1)*NCONSTR);}
188 inline void setG(int i, const HepVector &p) {m_G.sub(i*NCONSTR+1, p);}
189
190 HepSymMatrix m_W; // NCONSTR x NCONSTR -- VD
191 inline HepSymMatrix vfW(int i) const {return m_W.sub(i*NCONSTR+1, (i+1)*NCONSTR);}
192 inline void setW(int i, HepSymMatrix &m) {m_W.sub(i*NCONSTR+1, m);}
193
194 HepMatrix m_E; // NTRKPAR x NVTXPAR -- -Va0 D.T() VD E Vx
195 inline HepMatrix vfE(int i) const {return m_E.sub(i*NTRKPAR+1, (i+1)*NTRKPAR, 1, NVTXPAR);}
196 inline void setE(int i, const HepMatrix &p){m_E.sub(i*NTRKPAR+1, 1, p);}
197
198 //NEW ADDED
199 HepMatrix m_TRA; // transform matrix from 7x1 to 6x1
200 HepMatrix m_TRB; // transform matrix from 6x1 to 7x1
201 // convert HepVector 6x1 to 7x1
202 // (px, py, pz, x, y, z) -> (px, py, pz, e, x, y, z)
203 HepVector Convert67(const double &mass, const HepVector &p);
204 // convert HepVector 7x1 to 6x1
205 // (px, py, pz, e, x, y, z) -> (px, py, pz, x, y, z)
206 HepVector Convert76(const HepVector &p);
207 //NEW ADDED
208
209 // Singleton Design
210 VertexFit();
211 static VertexFit *m_pointer;
212
213 int m_niter; //number of iteration for vertex fitting
214 double m_chicut; //chisquare upper limit
215 double m_chiter;
216 HepVector m_cpu;
217
218 static const int NTRKPAR; //number of track parameters
219 static const int NVTXPAR; //number of vertex parameters
220 static const int NCONSTR; //number of vertex constraints
221};
222#endif //VertexFit_VertexFit_H
223
double mass
const Int_t n
Double_t x[10]
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
Definition: KarLud.h:35
int n2
Definition: SD0Tag.cxx:55
int n1
Definition: SD0Tag.cxx:54
std::vector< WTrackParameter > wTrackInfit() const
Definition: TrackPool.h:73
WTrackParameter wtrk(int n) const
Definition: VertexFit.h:84
double chisq() const
Definition: VertexFit.h:71
HepVector Vx(int n) const
Definition: VertexFit.h:91
HepVector w(int n) const
Definition: VertexFit.h:82
HepSymMatrix Ew(int n) const
Definition: VertexFit.h:83
void setIterNumber(const int niter=10)
Definition: VertexFit.h:55
double chisq(int n) const
Definition: VertexFit.h:72
WTrackParameter wVirtualTrack(int n) const
Definition: VertexFit.h:97
bool BeamFit(int n)
Definition: VertexFit.cxx:257
void AddBeamFit(int number, VertexParameter vpar, int n)
Definition: VertexFit.cxx:72
void init()
Definition: VertexFit.cxx:29
void AddVertex(int number, VertexParameter vpar, std::vector< int > lis)
Definition: VertexFit.cxx:87
HepSymMatrix Evx(int n) const
Definition: VertexFit.h:92
bool pull(int n, int itk, HepVector &p)
Definition: VertexFit.cxx:454
HepPoint3D vx(int n) const
Definition: VertexFit.h:90
HepLorentzVector pfit(int n) const
Definition: VertexFit.h:80
HepPoint3D xfit(int n) const
Definition: VertexFit.h:81
HepVector cpu() const
Definition: VertexFit.h:87
static VertexFit * instance()
Definition: VertexFit.cxx:15
VertexParameter vpar(int n) const
Definition: VertexFit.h:94
void BuildVirtualParticle(int number)
Definition: VertexFit.cxx:616
void Swim(int n)
Definition: VertexFit.h:64
bool Fit()
Definition: VertexFit.cxx:299
void setChisqCut(const double chicut=1000, const double chiter=1.0e-3)
Definition: VertexFit.h:56
double errorVx(int n, int i) const
Definition: VertexFit.h:93