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