Belle II Software  release-08-01-10
KFitBase.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * External Contributor: J. Tanaka *
5  * *
6  * See git log for contributors and copyright holders. *
7  * This file is licensed under LGPL-3.0, see LICENSE.md. *
8  **************************************************************************/
9 
10 #pragma once
11 
12 #include <vector>
13 
14 #include <CLHEP/Matrix/Matrix.h>
15 #include <CLHEP/Matrix/SymMatrix.h>
16 #include <CLHEP/Vector/LorentzVector.h>
17 #include <CLHEP/Geometry/Point3D.h>
18 
19 #include <analysis/dataobjects/Particle.h>
20 #include <analysis/VertexFitting/KFit/KFitConst.h>
21 #include <analysis/VertexFitting/KFit/KFitError.h>
22 #include <analysis/VertexFitting/KFit/KFitTrack.h>
23 
24 #ifndef ENABLE_BACKWARDS_COMPATIBILITY
26 #endif
27 
28 namespace Belle2 {
33  namespace analysis {
37  class KFitBase {
38  public:
40  KFitBase(void);
42  virtual ~KFitBase(void);
43 
44 
45  public:
50  enum KFitError::ECode addTrack(const KFitTrack& kp);
59  enum KFitError::ECode addTrack(const CLHEP::HepLorentzVector& p, const HepPoint3D& x, const CLHEP::HepSymMatrix& e,
60  const double q);
67  enum KFitError::ECode addParticle(const Particle* particle);
72  virtual enum KFitError::ECode setCorrelation(const CLHEP::HepMatrix& c);
76  virtual enum KFitError::ECode setZeroCorrelation(void);
81  enum KFitError::ECode setMagneticField(const double mf);
82 
83 
87  enum KFitError::ECode getErrorCode(void) const;
91  int getTrackCount(void) const;
95  virtual int getNDF(void) const;
99  virtual double getCHIsq(void) const;
103  double getMagneticField(void) const;
108  virtual double getTrackCHIsq(const int id) const;
113  const CLHEP::HepLorentzVector getTrackMomentum(const int id) const;
118  const HepPoint3D getTrackPosition(const int id) const;
123  const CLHEP::HepSymMatrix getTrackError(const int id) const;
128  const KFitTrack getTrack(const int id) const;
135  virtual const CLHEP::HepMatrix getCorrelation(const int id1, const int id2,
136  const int flag = KFitConst::kAfterFit) const;
137 
138 
139  public:
143  bool isFitted(void) const;
144 
145 
146  protected:
152  const CLHEP::HepSymMatrix makeError1(const CLHEP::HepLorentzVector& p, const CLHEP::HepMatrix& e) const;
159  const CLHEP::HepMatrix makeError1(const CLHEP::HepLorentzVector& p1, const CLHEP::HepLorentzVector& p2,
160  const CLHEP::HepMatrix& e) const;
166  const CLHEP::HepMatrix makeError2(const CLHEP::HepLorentzVector& p, const CLHEP::HepMatrix& e) const;
173  const CLHEP::HepSymMatrix makeError3(const CLHEP::HepLorentzVector& p, const CLHEP::HepMatrix& e, const bool is_fix_mass) const;
182  const CLHEP::HepMatrix makeError3(const CLHEP::HepLorentzVector& p1, const CLHEP::HepLorentzVector& p2,
183  const CLHEP::HepMatrix& e, const bool is_fix_mass1, const bool is_fix_mass2) const;
189  const CLHEP::HepMatrix makeError4(const CLHEP::HepLorentzVector& p, const CLHEP::HepMatrix& e) const;
190 
191 
195  virtual enum KFitError::ECode prepareInputMatrix(void) = 0;
199  virtual enum KFitError::ECode prepareInputSubMatrix(void) = 0;
203  virtual enum KFitError::ECode prepareCorrelation(void);
207  virtual enum KFitError::ECode prepareOutputMatrix(void) = 0;
211  virtual enum KFitError::ECode makeCoreMatrix(void) = 0;
215  virtual enum KFitError::ECode calculateNDF(void) = 0;
216 
217 
218  protected:
222  enum KFitError::ECode doFit1(void);
226  enum KFitError::ECode doFit2(void);
227 
228 
229  protected:
234  bool isTrackIDInRange(const int id) const;
239  bool isNonZeroEnergy(const CLHEP::HepLorentzVector& p) const;
240 
241 
246 
247 
249  std::vector<KFitTrack> m_Tracks;
251  std::vector<CLHEP::HepMatrix> m_BeforeCorrelation;
252 
253 
255  CLHEP::HepSymMatrix m_V_al_0;
257  CLHEP::HepMatrix m_al_0;
259  CLHEP::HepMatrix m_al_1;
261  CLHEP::HepMatrix m_al_a;
263  CLHEP::HepMatrix m_property;
264 
266  CLHEP::HepMatrix m_D;
268  CLHEP::HepMatrix m_d;
269 
271  CLHEP::HepMatrix m_V_D;
272 
274  CLHEP::HepMatrix m_V_al_1;
276  CLHEP::HepMatrix m_lam;
277 
279  CLHEP::HepMatrix m_E;
281  CLHEP::HepMatrix m_V_E;
283  CLHEP::HepMatrix m_lam0;
285  CLHEP::HepMatrix m_v;
287  CLHEP::HepMatrix m_v_a;
289  CLHEP::HepMatrix m_V_Dt;
291  CLHEP::HepMatrix m_Cov_v_al_1;
292 
293 
295  int m_NDF;
297  double m_CHIsq;
298 
299 
304 
309 
312  };
313 
314  } // namespace analysis
315 
317 } // namespace Belle2
318 
319 
Class to store reconstructed particles.
Definition: Particle.h:75
KFitBase is a base class for kinematical fitters.
Definition: KFitBase.h:37
KFitBase(void)
Construct an object with no argument.
Definition: KFitBase.cc:20
int m_NecessaryTrackCount
Number needed tracks to perform fit.
Definition: KFitBase.h:303
const CLHEP::HepMatrix makeError1(const CLHEP::HepLorentzVector &p1, const CLHEP::HepLorentzVector &p2, const CLHEP::HepMatrix &e) const
Rebuild an error matrix from a pair of Lorentz vectors and an error matrix.
virtual enum KFitError::ECode prepareInputMatrix(void)=0
Build grand matrices for minimum search from input-track properties.
enum KFitError::ECode addTrack(const KFitTrack &kp)
Add a track to the fitter object.
Definition: KFitBase.cc:38
virtual enum KFitError::ECode prepareOutputMatrix(void)=0
Build an output error matrix.
double m_MagneticField
Magnetic field.
Definition: KFitBase.h:311
bool isNonZeroEnergy(const CLHEP::HepLorentzVector &p) const
Check if the energy is non-zero.
Definition: KFitBase.cc:749
const CLHEP::HepMatrix makeError3(const CLHEP::HepLorentzVector &p1, const CLHEP::HepLorentzVector &p2, const CLHEP::HepMatrix &e, const bool is_fix_mass1, const bool is_fix_mass2) const
Rebuild an error matrix from a pair of Lorentz vectors and an error matrix.
CLHEP::HepMatrix m_al_1
See J.Tanaka Ph.D (2001) p136 for definition.
Definition: KFitBase.h:259
CLHEP::HepMatrix m_V_Dt
See J.Tanaka Ph.D (2001) p138 for definition.
Definition: KFitBase.h:289
virtual enum KFitError::ECode setCorrelation(const CLHEP::HepMatrix &c)
Set a correlation matrix.
Definition: KFitBase.cc:70
const CLHEP::HepSymMatrix getTrackError(const int id) const
Get an error matrix of the track.
Definition: KFitBase.cc:168
virtual double getCHIsq(void) const
Get a chi-square of the fit.
Definition: KFitBase.cc:121
const CLHEP::HepLorentzVector getTrackMomentum(const int id) const
Get a Lorentz vector of the track.
Definition: KFitBase.cc:154
CLHEP::HepMatrix m_lam
See J.Tanaka Ph.D (2001) p137 for definition.
Definition: KFitBase.h:276
double getMagneticField(void) const
Get a magnetic field.
Definition: KFitBase.cc:128
enum KFitError::ECode doFit2(void)
Perform a fit (used in VertexFitKFit::doFit() and MassVertexFitKFit::doFit()).
Definition: KFitBase.cc:577
CLHEP::HepMatrix m_E
See J.Tanaka Ph.D (2001) p137 for definition.
Definition: KFitBase.h:279
const CLHEP::HepSymMatrix makeError1(const CLHEP::HepLorentzVector &p, const CLHEP::HepMatrix &e) const
Rebuild an error matrix from a Lorentz vector and an error matrix.
const HepPoint3D getTrackPosition(const int id) const
Get a position of the track.
Definition: KFitBase.cc:161
bool m_FlagOverIteration
Flag whether the iteration count exceeds the limit.
Definition: KFitBase.h:308
CLHEP::HepMatrix m_property
Container of charges and masses.
Definition: KFitBase.h:263
virtual double getTrackCHIsq(const int id) const
Get a chi-square of the track.
Definition: KFitBase.cc:135
enum KFitError::ECode m_ErrorCode
Error code.
Definition: KFitBase.h:243
virtual enum KFitError::ECode prepareInputSubMatrix(void)=0
Build sub-matrices for minimum search from input-track properties.
virtual enum KFitError::ECode setZeroCorrelation(void)
Indicate no correlation between tracks.
Definition: KFitBase.cc:85
const CLHEP::HepSymMatrix makeError3(const CLHEP::HepLorentzVector &p, const CLHEP::HepMatrix &e, const bool is_fix_mass) const
Rebuild an error matrix from a Lorentz vector and an error matrix.
CLHEP::HepMatrix m_V_al_1
See J.Tanaka Ph.D (2001) p138 for definition.
Definition: KFitBase.h:274
virtual int getNDF(void) const
Get an NDF of the fit.
Definition: KFitBase.cc:114
CLHEP::HepMatrix m_d
See J.Tanaka Ph.D (2001) p137 for definition.
Definition: KFitBase.h:268
CLHEP::HepMatrix m_lam0
See J.Tanaka Ph.D (2001) p138 for definition.
Definition: KFitBase.h:283
virtual ~KFitBase(void)
Destruct the object.
bool isFitted(void) const
Return false if fit is not performed yet or performed fit is failed; otherwise true.
Definition: KFitBase.cc:727
CLHEP::HepMatrix m_al_a
See J.Tanaka Ph.D (2001) p137 for definition.
Definition: KFitBase.h:261
enum KFitError::ECode setMagneticField(const double mf)
Change a magnetic field from the default value KFitConst::kDefaultMagneticField.
Definition: KFitBase.cc:93
CLHEP::HepMatrix m_D
See J.Tanaka Ph.D (2001) p137 for definition.
Definition: KFitBase.h:266
CLHEP::HepMatrix m_V_D
See J.Tanaka Ph.D (2001) p138 for definition.
Definition: KFitBase.h:271
bool isTrackIDInRange(const int id) const
Check if the id is in the range.
Definition: KFitBase.cc:738
CLHEP::HepMatrix m_v_a
See J.Tanaka Ph.D (2001) p137 for definition.
Definition: KFitBase.h:287
virtual const CLHEP::HepMatrix getCorrelation(const int id1, const int id2, const int flag=KFitConst::kAfterFit) const
Get a correlation matrix between two tracks.
Definition: KFitBase.cc:183
bool m_FlagCorrelation
Flag whether a correlation among tracks exists.
Definition: KFitBase.h:306
CLHEP::HepSymMatrix m_V_al_0
See J.Tanaka Ph.D (2001) p137 for definition.
Definition: KFitBase.h:255
CLHEP::HepMatrix m_V_E
See J.Tanaka Ph.D (2001) p138 for definition.
Definition: KFitBase.h:281
CLHEP::HepMatrix m_Cov_v_al_1
See J.Tanaka Ph.D (2001) p137 for definition.
Definition: KFitBase.h:291
const KFitTrack getTrack(const int id) const
Get a specified track object.
Definition: KFitBase.cc:175
virtual enum KFitError::ECode prepareCorrelation(void)
Build a grand correlation matrix from input-track properties.
Definition: KFitBase.cc:458
virtual enum KFitError::ECode makeCoreMatrix(void)=0
Build matrices using the kinematical constraint.
const CLHEP::HepMatrix makeError2(const CLHEP::HepLorentzVector &p, const CLHEP::HepMatrix &e) const
Rebuild an error matrix from a Lorentz vector and an error matrix.
Definition: KFitBase.cc:296
enum KFitError::ECode addParticle(const Particle *particle)
Add a particle to the fitter.
Definition: KFitBase.cc:59
std::vector< CLHEP::HepMatrix > m_BeforeCorrelation
Container of input correlation matrices.
Definition: KFitBase.h:251
bool m_FlagFitted
Flag to indicate if the fit is performed and succeeded.
Definition: KFitBase.h:245
double m_CHIsq
chi-square of the fit.
Definition: KFitBase.h:297
int getTrackCount(void) const
Get the number of added tracks.
Definition: KFitBase.cc:107
int m_NDF
NDF of the fit.
Definition: KFitBase.h:295
std::vector< KFitTrack > m_Tracks
Container of input tracks.
Definition: KFitBase.h:249
CLHEP::HepMatrix m_v
See J.Tanaka Ph.D (2001) p137 for definition.
Definition: KFitBase.h:285
virtual enum KFitError::ECode calculateNDF(void)=0
Calculate an NDF of the fit.
const CLHEP::HepMatrix makeError4(const CLHEP::HepLorentzVector &p, const CLHEP::HepMatrix &e) const
Rebuild an error matrix from a Lorentz vector and an error matrix.
Definition: KFitBase.cc:438
int m_TrackCount
Number of tracks.
Definition: KFitBase.h:301
CLHEP::HepMatrix m_al_0
See J.Tanaka Ph.D (2001) p136 for definition.
Definition: KFitBase.h:257
enum KFitError::ECode doFit1(void)
Perform a fit (used in MassFitKFit::doFit()).
Definition: KFitBase.cc:501
enum KFitError::ECode getErrorCode(void) const
Get a code of the last error.
Definition: KFitBase.cc:101
ECode
ECode is a error code enumerate.
Definition: KFitError.h:34
KFitTrack is a container of the track information (Lorentz vector, position, and error matrix),...
Definition: KFitTrack.h:38
Abstract base class for different kinds of events.
static const int kAfterFit
Input parameter to specify after-fit when setting/getting a track attribute.
Definition: KFitConst.h:37