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