BOSS 7.1.0
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// You can find the corresponding tutorial on the following web page:
16// http://docbes3.ihep.ac.cn/~offlinesoftware/index.php/Vertex_Fit
17
18class VertexFit : public TrackPool
19{
20 friend class VertexFitRefine; // add by Hao-Kai SUN <[email protected]>
21public:
22 // constructor & deconstructor
23 static VertexFit *instance();
24 ~VertexFit();
25
26 // initialization, must be called before VertexFit each time
27 void init();
28
29 // add methods
30 void AddVertex(int number, VertexParameter vpar, std::vector<int> lis);
31 void AddVertex(int number, VertexParameter vpar, int n1, int n2);
32 void AddVertex(int number, VertexParameter vpar, int n1, int n2, int n3);
33 void AddVertex(int number, VertexParameter vpar, int n1, int n2, int n3, int n4);
34 void AddVertex(int number, VertexParameter vpar, int n1, int n2, int n3, int n4, int n5);
35 void AddVertex(int number, VertexParameter vpar, int n1, int n2, int n3, int n4, int n5, int n6);
36 void AddVertex(int number, VertexParameter vpar, int n1, int n2, int n3, int n4, int n5, int n6, int n7);
37 void AddVertex(int number, VertexParameter vpar, int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8);
38 void AddVertex(int number, VertexParameter vpar, int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int n9);
39 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);
40 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);
41 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);
42 void AddBeamFit(int number, VertexParameter vpar, int n);
43
44 // build virtual particle, parameter number must be match with vertex number
45 void BuildVirtualParticle(int number);
46
47 // set iteration number and chisq cut
48 void setIterNumber(const int niter = 10) { m_niter = niter; }
49 void setChisqCut(const double chicut = 1000, const double chiter = 1.0e-3) { m_chicut = chicut;m_chiter = chiter; }
50 void setMagCorrFactor(const double factor = 1.000) { m_factor = factor; }
51 double factor() const { return m_factor; }
52
53 // fit function
54 bool Fit();
55 bool Fit(int n);
56 bool BeamFit(int n);
57
58 // renew track parameters and convariance
59 void Swim(int n){ vertexCovMatrix(n); swimVertex(n);}
60
61 //
62 // Fit Results
63 //
64
65 // chisq of fit
66 double chisq() const {return m_chi;}
67 double chisq(int n) const {return m_chisq[n];}
68
69 // Pull distribution for 5-helix parameters.
70 // Return true on success, the resulting pull will be stored in p;
71 // Return false on failure.
72 bool pull(int n, int itk, HepVector& p);
73
74 // updated WTrack parameter in vertex fit
75 HepLorentzVector pfit(int n) const {return wTrackInfit(n).p();}
76 HepPoint3D xfit(int n) const {return wTrackInfit(n).x();}
77 HepVector w(int n) const {return wTrackInfit(n).w();}
78 HepSymMatrix Ew(int n) const {return wTrackInfit(n).Ew();}
79 WTrackParameter wtrk(int n) const {return wTrackInfit(n);}
80
81 // time counter
82 HepVector cpu() const {return m_cpu;}
83
84 // updated Vertex Parameter in vertex fit
85 HepPoint3D vx(int n) const { return m_vpar_infit[n].vx();}
86 HepVector Vx(int n) const { return m_vpar_infit[n].Vx();}
87 HepSymMatrix Evx(int n) const { return m_vpar_infit[n].Evx();}
88 double errorVx(int n, int i) const { return sqrt((m_vpar_infit[n].Evx())[i][i]);}
89 VertexParameter vpar(int n) const {return m_vpar_infit[n];}
90
91 // virtual particle from Vertex Fit
92 WTrackParameter wVirtualTrack(int n) const {return m_virtual_wtrk[n];}
93
94 // Users need not care below
95private:
96 // renew vertex constraints
97 void UpdateConstraints(const VertexConstraints &vc);
98 // vertex fit
99 void fitVertex(int n);
100 // renew covariance of input track parameters
101 void vertexCovMatrix(int n);
102 // extrapolate input track parameters to the vertex
103 void swimVertex(int n);
104
105 void fitBeam(int n);
106 void swimBeam(int n);
107
108 // vertex parameters before fit
109 std::vector<VertexParameter> m_vpar_origin;
110 // vertex parameters in fit
111 std::vector<VertexParameter> m_vpar_infit;
112 // vertex constraints
113 std::vector<VertexConstraints> m_vc;
114 // chisquare counter
115 std::vector<double> m_chisq;
116 double m_chi; // total chisquare
117 int m_nvtrk; // number of WTracks in VertexFit
118 // virtual particle in WTrackParameter format
119 std::vector<WTrackParameter> m_virtual_wtrk;
120
121 // track parameters storage and access
122 // origin vertex and its covariance matrix
123 HepVector m_xOrigin;
124 HepSymMatrix m_xcovOrigin;
125 HepSymMatrix m_xcovOriginInversed;
126 inline HepVector xOrigin() const {return m_xOrigin;}
127 inline void setXOrigin(const HepVector &x) { m_xOrigin = x;}
128 inline HepSymMatrix xcovOrigin() const {return m_xcovOrigin;}
129 inline void setXCovOrigin(const HepSymMatrix &v) {m_xcovOrigin = v;}
130 inline HepSymMatrix xcovOriginInversed() const {return m_xcovOriginInversed;}
131 inline void setXCovOriginInversed(const HepSymMatrix &v){m_xcovOriginInversed = v;}
132
133 // vertex and covariance matrix in fit
134 HepVector m_xInfit;
135 HepSymMatrix m_xcovInfit;
136 HepSymMatrix m_xcovInfitInversed;
137 inline HepVector xInfit() const {return m_xInfit;}
138 inline void setXInfit(const HepVector &x) {m_xInfit = x;}
139 inline HepSymMatrix xcovInfit() const {return m_xcovInfit;}
140 void setXCovInfit(const HepSymMatrix &v) {m_xcovInfit = v;}
141 inline HepSymMatrix xcovInfitInversed() const {return m_xcovInfitInversed;}
142 void setXCovInfitInversed(const HepSymMatrix &v) {m_xcovInfitInversed = v;}
143
144 // track parameters and covariance matrice at initial
145 HepVector m_pOrigin;
146 HepSymMatrix m_pcovOrigin;
147 inline HepVector pOrigin(int i) const { return m_pOrigin.sub(i*NTRKPAR+1, (i+1)*NTRKPAR); }
148 inline void setPOrigin(int i, const HepVector &p) { m_pOrigin.sub(i*NTRKPAR+1, p); }
149 inline HepSymMatrix pcovOrigin(int i) const { return m_pcovOrigin.sub(i*NTRKPAR+1, (i+1)*NTRKPAR); }
150 inline void setPCovOrigin(int i, const HepSymMatrix &v) { m_pcovOrigin.sub(i*NTRKPAR+1,v); }
151
152 // track parameters and covariance matrice in fit
153 HepVector m_pInfit;
154 HepSymMatrix m_pcovInfit;
155 inline HepVector pInfit(int i) const { return m_pInfit.sub(i*NTRKPAR+1, (i+1)*NTRKPAR); }
156 inline void setPInfit(int i, const HepVector &p) { m_pInfit.sub(i*NTRKPAR+1, p); }
157 inline HepSymMatrix pcovInfit(int i) const { return m_pcovInfit.sub(i*NTRKPAR+1, (i+1)*NTRKPAR); }
158 inline void setPCovInfit(int i, const HepSymMatrix &v) { m_pcovInfit.sub(i*NTRKPAR+1, v); }
159
160 // some matrices convenient for calculation
161 HepMatrix m_B; // NCONSTR x NVTXPAR -- E
162 inline HepMatrix vfB(int i) const {return m_B.sub(i*NCONSTR+1, (i+1)*NCONSTR, 1, NVTXPAR);}
163 inline void setB(int i, const HepMatrix &e) {m_B.sub(i*NCONSTR+1, 1, e);}
164
165 HepMatrix m_BT; // NVTXPAR x NCONSTR -- E.T()
166 inline HepMatrix vfBT(int i) const {return m_BT.sub(1, NVTXPAR, i*NCONSTR+1, (i+1)*NCONSTR);}
167 inline void setBT(int i, const HepMatrix &e) {m_BT.sub(1, i*NCONSTR+1, e);}
168
169 HepMatrix m_A; // NCONSTR x NTRKPAR -- D
170 inline HepMatrix vfA(int i) const {return m_A.sub(i*NCONSTR+1, (i+1)*NCONSTR, i*NTRKPAR+1, (i+1)*NTRKPAR);}
171 inline void setA(int i, const HepMatrix &d) {m_A.sub(i*NCONSTR+1, i*NTRKPAR+1, d);}
172
173 HepMatrix m_AT; // NTRKPAR x NCONSTR -- D.T()
174 inline HepMatrix vfAT(int i) const {return m_AT.sub(i*NTRKPAR+1, (i+1)*NTRKPAR, i*NCONSTR+1, (i+1)*NCONSTR);}
175 inline void setAT(int i, const HepMatrix &d) {m_AT.sub(i*NTRKPAR+1, i*NCONSTR+1, d);}
176
177 HepMatrix m_KQ; // NVTXPAR x NCONSTR -- Vx E.T() VD
178 inline HepMatrix vfKQ(int i) const {return m_KQ.sub(1, NVTXPAR, i*NCONSTR+1, (i+1)*NCONSTR);}
179 inline void setKQ(int i, const HepMatrix &d) {m_KQ.sub(1, i*NCONSTR+1, d);}
180
181 HepVector m_G; // NCONSTR x 1 -- Dda + Edx + d
182 inline HepVector vfG(int i) const {return m_G.sub(i*NCONSTR+1, (i+1)*NCONSTR);}
183 inline void setG(int i, const HepVector &p) {m_G.sub(i*NCONSTR+1, p);}
184
185 HepSymMatrix m_W; // NCONSTR x NCONSTR -- VD
186 inline HepSymMatrix vfW(int i) const {return m_W.sub(i*NCONSTR+1, (i+1)*NCONSTR);}
187 inline void setW(int i, HepSymMatrix &m) {m_W.sub(i*NCONSTR+1, m);}
188
189 HepMatrix m_E; // NTRKPAR x NVTXPAR -- -Va0 D.T() VD E Vx
190 inline HepMatrix vfE(int i) const {return m_E.sub(i*NTRKPAR+1, (i+1)*NTRKPAR, 1, NVTXPAR);}
191 inline void setE(int i, const HepMatrix &p){m_E.sub(i*NTRKPAR+1, 1, p);}
192
193 HepMatrix m_TRA; // transform matrix from 7x1 to 6x1
194 HepMatrix m_TRB; // transform matrix from 6x1 to 7x1
195 // convert HepVector 6x1 to 7x1
196 // (px, py, pz, x, y, z) -> (px, py, pz, e, x, y, z)
197 HepVector Convert67(const double &mass, const HepVector &p);
198 // convert HepVector 7x1 to 6x1
199 // (px, py, pz, e, x, y, z) -> (px, py, pz, x, y, z)
200 HepVector Convert76(const HepVector &p);
201
202 // Singleton Design
203 VertexFit();
204 static VertexFit *m_pointer;
205
206 int m_niter; //number of iteration for vertex fitting
207 double m_chicut; //chisquare upper limit
208 double m_chiter;
209 double m_factor; //B Field correction factor
210 HepVector m_cpu;
211
212 static const int NTRKPAR; //number of track parameters
213 static const int NVTXPAR; //number of vertex parameters
214 static const int NCONSTR; //number of vertex constraints
215};
216#endif //VertexFit_VertexFit_H
217
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:79
double chisq() const
Definition: VertexFit.h:66
HepVector Vx(int n) const
Definition: VertexFit.h:86
HepVector w(int n) const
Definition: VertexFit.h:77
HepSymMatrix Ew(int n) const
Definition: VertexFit.h:78
void setIterNumber(const int niter=10)
Definition: VertexFit.h:48
double chisq(int n) const
Definition: VertexFit.h:67
double factor() const
Definition: VertexFit.h:51
WTrackParameter wVirtualTrack(int n) const
Definition: VertexFit.h:92
bool BeamFit(int n)
Definition: VertexFit.cxx:259
void AddBeamFit(int number, VertexParameter vpar, int n)
Definition: VertexFit.cxx:74
void init()
Definition: VertexFit.cxx:29
void AddVertex(int number, VertexParameter vpar, std::vector< int > lis)
Definition: VertexFit.cxx:89
HepSymMatrix Evx(int n) const
Definition: VertexFit.h:87
bool pull(int n, int itk, HepVector &p)
Definition: VertexFit.cxx:457
HepPoint3D vx(int n) const
Definition: VertexFit.h:85
HepLorentzVector pfit(int n) const
Definition: VertexFit.h:75
HepPoint3D xfit(int n) const
Definition: VertexFit.h:76
HepVector cpu() const
Definition: VertexFit.h:82
void setMagCorrFactor(const double factor=1.000)
Definition: VertexFit.h:50
static VertexFit * instance()
Definition: VertexFit.cxx:15
VertexParameter vpar(int n) const
Definition: VertexFit.h:89
void BuildVirtualParticle(int number)
Definition: VertexFit.cxx:619
void Swim(int n)
Definition: VertexFit.h:59
bool Fit()
Definition: VertexFit.cxx:301
void setChisqCut(const double chicut=1000, const double chiter=1.0e-3)
Definition: VertexFit.h:49
double errorVx(int n, int i) const
Definition: VertexFit.h:88