BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Analysis/VertexFit/include/VertexFit/KinematicFit.h
Go to the documentation of this file.
1#ifndef VertexFit_KinematicFit_H
2#define VertexFit_KinematicFit_H
3
4#include "VertexFit/GammaShape.h"
5#include "VertexFit/KinematicConstraints.h"
6#include "VertexFit/TrackPool.h"
7#include "VertexFit/WTrackParameter.h"
8#include <vector>
9
10class KinematicFit : public TrackPool {
11
12public:
13 // constructor & destructor
14
15 static KinematicFit* instance();
17 //
18 // Resonance Constraints
19 //
20 void AddResonance( int number, double mres, std::vector<int> tlis );
21 void AddResonance( int number, double mres, int n1 );
22 void AddResonance( int number, double mres, int n1, int n2 );
23 void AddResonance( int number, double mres, int n1, int n2, int n3 );
24 void AddResonance( int number, double mres, int n1, int n2, int n3, int n4 );
25 void AddResonance( int number, double mres, int n1, int n2, int n3, int n4, int n5 );
26 void AddResonance( int number, double mres, int n1, int n2, int n3, int n4, int n5, int n6 );
27 void AddResonance( int number, double mres, int n1, int n2, int n3, int n4, int n5, int n6,
28 int n7 );
29 void AddResonance( int number, double mres, int n1, int n2, int n3, int n4, int n5, int n6,
30 int n7, int n8 );
31 void AddResonance( int number, double mres, int n1, int n2, int n3, int n4, int n5, int n6,
32 int n7, int n8, int n9 );
33 void AddResonance( int number, double mres, int n1, int n2, int n3, int n4, int n5, int n6,
34 int n7, int n8, int n9, int n10 );
35 void AddResonance( int number, double mres, int n1, int n2, int n3, int n4, int n5, int n6,
36 int n7, int n8, int n9, int n10, int n11 );
37 void AddResonance( int number, double mres, int n1, int n2, int n3, int n4, int n5, int n6,
38 int n7, int n8, int n9, int n10, int n11, int n12 );
39 //
40 // Total Energy Constraints
41 //
42 void AddTotalEnergy( int number, double etot, std::vector<int> lis );
43 void AddTotalEnergy( int number, double etot, int n1 );
44 void AddTotalEnergy( int number, double etot, int n1, int n2 );
45 void AddTotalEnergy( int number, double etot, int n1, int n2, int n3 );
46 void AddTotalEnergy( int number, double etot, int n1, int n2, int n3, int n4 );
47 void AddTotalEnergy( int number, double etot, int n1, int n2, int n3, int n4, int n5 );
48 void AddTotalEnergy( int number, double etot, int n1, int n2, int n3, int n4, int n5,
49 int n6 );
50 void AddTotalEnergy( int number, double etot, int n1, int n2, int n3, int n4, int n5, int n6,
51 int n7 );
52 void AddTotalEnergy( int number, double etot, int n1, int n2, int n3, int n4, int n5, int n6,
53 int n7, int n8 );
54 void AddTotalEnergy( int number, double etot, int n1, int n2, int n3, int n4, int n5, int n6,
55 int n7, int n8, int n9 );
56 void AddTotalEnergy( int number, double etot, int n1, int n2, int n3, int n4, int n5, int n6,
57 int n7, int n8, int n9, int n10 );
58 void AddTotalEnergy( int number, double etot, int n1, int n2, int n3, int n4, int n5, int n6,
59 int n7, int n8, int n9, int n10, int n11 );
60 void AddTotalEnergy( int number, double etot, int n1, int n2, int n3, int n4, int n5, int n6,
61 int n7, int n8, int n9, int n10, int n11, int n12 );
62
63 //
64 // Total Momentum Constraints
65 //
66 void AddTotalMomentum( int number, double ptot, std::vector<int> lis );
67 void AddTotalMomentum( int number, double ptot, int n1 );
68 void AddTotalMomentum( int number, double ptot, int n1, int n2 );
69 void AddTotalMomentum( int number, double ptot, int n1, int n2, int n3 );
70 void AddTotalMomentum( int number, double ptot, int n1, int n2, int n3, int n4 );
71 void AddTotalMomentum( int number, double ptot, int n1, int n2, int n3, int n4, int n5 );
72 void AddTotalMomentum( int number, double ptot, int n1, int n2, int n3, int n4, int n5,
73 int n6 );
74 void AddTotalMomentum( int number, double ptot, int n1, int n2, int n3, int n4, int n5,
75 int n6, int n7 );
76 void AddTotalMomentum( int number, double ptot, int n1, int n2, int n3, int n4, int n5,
77 int n6, int n7, int n8 );
78 void AddTotalMomentum( int number, double ptot, int n1, int n2, int n3, int n4, int n5,
79 int n6, int n7, int n8, int n9 );
80 void AddTotalMomentum( int number, double ptot, int n1, int n2, int n3, int n4, int n5,
81 int n6, int n7, int n8, int n9, int n10 );
82 void AddTotalMomentum( int number, double ptot, int n1, int n2, int n3, int n4, int n5,
83 int n6, int n7, int n8, int n9, int n10, int n11 );
84 void AddTotalMomentum( int number, double ptot, int n1, int n2, int n3, int n4, int n5,
85 int n6, int n7, int n8, int n9, int n10, int n11, int n12 );
86 //
87 // Three Momentum Constraints
88 //
89 void AddThreeMomentum( int number, Hep3Vector p3 );
90 //
91 // Four Momentum Constraints
92 //
93 void AddFourMomentum( int number, HepLorentzVector p4 );
94 void AddFourMomentum( int number, double etot );
95
96 //
97 // Equal Mass Constraints
98 //
99
100 void AddEqualMass( int number, std::vector<int> tlis1, std::vector<int> tlis2 );
101
102 //
103 // Position Constraints
104 //
105 // void AddPosition(int number, HepPoint3D xorigin, std::vector<int> tlis_V);
106
107 //
108 // Build Virtual Particle
109 //
110 void BuildVirtualParticle( int number );
111
112 // initialization called before fit
113
114 void init();
115 //
116 // set iteration number and chisq cut
117 //
118 void setFlag( const bool flag = 1 ) { m_flag = flag; }
119 void setIterNumber( const int niter = 5 ) { m_niter = niter; }
120 void setChisqCut( const double chicut = 200, const double chiter = 0.05 ) {
121 m_chicut = chicut;
122 m_chiter = chiter;
123 }
124 //
125 // set error matrix parameters
126 //
127 void setKalman( const int kalman ) { m_kalman = kalman; }
128 void setEspread( const double espread = 0.0009 ) { m_espread = espread; }
129 void setCollideangle( const double collideangle = 11e-3 ) { m_collideangle = collideangle; }
130 void setDynamicerror( const bool dynamicerror = 1 ) { m_dynamicerror = dynamicerror; }
131 //
132 // fit function
133 //
134 bool Fit();
135 bool Fit( int n );
136 //
137 // Fit Results
138 //
139 // chisq of fit
140 //
141 double chisq() const { return m_chi; }
142 double chisq( int n ) const { return m_chisq[n]; }
143 // updated WTrack parameter after kinematic fit
144 // HepLorentzVector pfit(int n) const {return wTrackInfit(n).p();}
145 HepLorentzVector pfit( int n ) const { return p4Infit( n ); }
146 // added by yanl 05.10.07
147 // HepLorentzVector pfit1(int n) const {return wTrackOrigin(n).p();}
148 HepLorentzVector pfit1( int n ) const { return p4Origin( n ); }
149
150 WTrackParameter origin( int n ) const { return wTrackOrigin( n ); }
151 WTrackParameter infit( int n ) const { return wTrackInfit( n ); }
152
153 HepVector pull( int n );
154 // error Matrix parameters
155 double espread() const { return m_espread; }
156 double collideangle() const { return m_collideangle; }
157 bool dynamicerror() const { return m_dynamicerror; }
158 // cpu time
159 HepVector cpu() const { return m_cpu; }
160
161 WTrackParameter wVirtualTrack( int n ) const { return m_virtual_wtrk[n]; }
162
163private:
164 // bulid virtual particle
165 std::vector<WTrackParameter> m_virtual_wtrk;
166
167 void updateConstraints( KinematicConstraints kc );
168 void fits();
169 void fit();
170 // void covMatrix();
171 void upCovmtx();
172 void fit( int n );
173 void covMatrix( int n );
174 void gda();
175
176private:
177 std::vector<KinematicConstraints> m_kc;
178 std::vector<double> m_chisq;
179 double m_chi;
180 // std::vector<HepMatrix> m_D;
181 // std::vector<HepMatrix> m_DT;
182 HepMatrix m_D;
183 HepMatrix D( int ic, int itk ) const {
184 return m_D.sub( ic + 1, ic + 1, itk * NTRKPAR + 1, ( itk + 1 ) * NTRKPAR );
185 }
186 void setD( int ic, int itk, const HepMatrix& p ) { m_D.sub( ic + 1, itk * NTRKPAR + 1, p ); }
187 HepMatrix m_DT;
188 HepMatrix DT( int itk, int ic ) const {
189 return m_DT.sub( itk * NTRKPAR + 1, ( itk + 1 ) * NTRKPAR, ic + 1, ic + 1 );
190 }
191 void setDT( int itk, int ic, const HepMatrix& p ) {
192 m_DT.sub( itk * NTRKPAR + 1, ic + 1, p );
193 }
194 HepVector m_d;
195 HepSymMatrix m_VD;
196 HepMatrix m_KP;
197 // HepVector m_lambda;
198 int m_nc;
199 int m_nktrk;
200 HepVector m_pOrigin;
201 HepVector m_pInfit;
202 HepSymMatrix m_covOrigin;
203 HepSymMatrix m_covInfit;
204 HepVector m_massvector; // add to save the mass of each particle
205 HepVector pOrigin( int i ) const {
206 return m_pOrigin.sub( i * NTRKPAR + 1, ( i + 1 ) * NTRKPAR );
207 }
208 HepLorentzVector p4Origin( int i ) const {
209 HepVector p( 3, 0 );
210 p = pOrigin( i );
211 double E = sqrt( p[0] * p[0] + p[1] * p[1] + p[2] * p[2] +
212 origin( i ).mass() * origin( i ).mass() );
213 return HepLorentzVector( p[0], p[1], p[2], E );
214 } // modified by yanl 2010.7.26 for changing the wtrackparameters
215 HepVector pInfit( int i ) const {
216 return m_pInfit.sub( i * NTRKPAR + 1, ( i + 1 ) * NTRKPAR );
217 }
218 HepLorentzVector p4Infit( int i ) const {
219 HepVector p( 3, 0 );
220 p = pInfit( i );
221 double E = sqrt( p[0] * p[0] + p[1] * p[1] + p[2] * p[2] +
222 origin( i ).mass() * origin( i ).mass() );
223 return HepLorentzVector( p[0], p[1], p[2], E );
224 } // modified by yanl 2010.7.26 for changing the wtrackparameters
225 void setPOrigin( int i, const HepVector& p ) { m_pOrigin.sub( i * NTRKPAR + 1, p ); }
226 void setPInfit( int i, const HepVector& p ) { m_pInfit.sub( i * NTRKPAR + 1, p ); }
227 HepSymMatrix covOrigin( int i ) const {
228 return m_covOrigin.sub( i * NTRKPAR + 1, ( i + 1 ) * NTRKPAR );
229 }
230 HepSymMatrix covInfit( int i ) const {
231 return m_covInfit.sub( i * NTRKPAR + 1, ( i + 1 ) * NTRKPAR );
232 }
233 void setCovOrigin( int i, const HepSymMatrix& c ) { m_covOrigin.sub( i * NTRKPAR + 1, c ); }
234 void setCovInfit( int i, const HepSymMatrix& c ) { m_covInfit.sub( i * NTRKPAR + 1, c ); }
235 void setMassvector( int i, const double mass ) { m_massvector[i] = mass; }
236
237private:
238 KinematicFit();
239 static KinematicFit* m_pointer;
240
241private:
242 int m_niter;
243 bool m_flag;
244 double m_chicut;
245 double m_chiter;
246
247private:
248 int m_kalman;
249 double m_espread;
250 double m_collideangle;
251
252private:
253 HepVector m_cpu;
254
255private:
256 bool m_dynamicerror;
257
258private:
259 static const int NTRKPAR;
260
261 static const int Resonance;
262 static const int TotalEnergy;
263 static const int TotalMomentum;
264 static const int ThreeMomentum;
265 static const int FourMomentum;
266 static const int EqualMass;
267 static const int Position;
268};
269#endif
double mass
const Int_t n
Double_t etot
const DifPoint origin
int n2
Definition SD0Tag.cxx:59
int n1
Definition SD0Tag.cxx:58
static KinematicFit * instance()
void BuildVirtualParticle(int number)
void AddResonance(int number, double mres, std::vector< int > tlis)
void setEspread(const double espread=0.0009)
void AddEqualMass(int number, std::vector< int > tlis1, std::vector< int > tlis2)
void setChisqCut(const double chicut=200, const double chiter=0.05)
void setDynamicerror(const bool dynamicerror=1)
void AddThreeMomentum(int number, Hep3Vector p3)
void AddFourMomentum(int number, HepLorentzVector p4)
HepVector pull(int n)
void setCollideangle(const double collideangle=11e-3)
void AddTotalEnergy(int number, double etot, std::vector< int > lis)
void AddTotalMomentum(int number, double ptot, std::vector< int > lis)
std::vector< WTrackParameter > wTrackInfit() const
std::vector< WTrackParameter > wTrackOrigin() const