14#include <TMatrixFSym.h>
16#include <analysis/VertexFitting/KFit/MakeMotherKFit.h>
17#include <analysis/VertexFitting/KFit/VertexFitKFit.h>
18#include <analysis/utility/CLHEPToROOT.h>
19#include <framework/gearbox/Const.h>
23using namespace Belle2::analysis;
28 m_AfterVertexError(HepSymMatrix(3, 0)),
29 m_BeamError(HepSymMatrix(3, 0))
39 m_V_E = HepMatrix(3, 3, 0);
40 m_v = HepMatrix(3, 1, 0);
41 m_v_a = HepMatrix(3, 1, 0);
68 sprintf(buf,
"%s:%s(): already constrained to IPtube", __FILE__, __func__);
85 sprintf(buf,
"%s:%s(): already constrained to IP", __FILE__, __func__);
255 HepMatrix tmp_al_a(
m_al_a);
257 HepMatrix tmp_D(
m_D), tmp_E(
m_E);
261 HepMatrix tmp2_D(
m_D), tmp2_E(
m_E);
278 HepMatrix tV_Ein(3, 3, 0);
292 m_V_D.sub(2 * k + 1, 2 * k + 1, tV_D);
293 HepMatrix tE =
m_E.sub(2 * k + 1, 2 * (k + 1), 1, 3);
294 tV_Ein += (tE.T()) * tV_D * tE;
296 HepMatrix td =
m_d.sub(2 * k + 1, 2 * (k + 1), 1, 1);
297 HepMatrix tlam0 = tV_D * (tD * tDeltaAl + td);
298 m_lam0.sub(2 * k + 1, 1, tlam0);
303 m_V_E = tV_Ein.inverse(err_inverse);
312 if (tmp_chisq <= chisq) {
359 if (tmp2_chisq <= chisq) {
422 HepMatrix tmp_al_a(
m_al_a);
424 HepMatrix tmp_D(
m_D), tmp_E(
m_E);
425 HepMatrix tmp_lam(
m_lam);
433 double tmp_vertex_chisq = 1.e+30;
436 bool it_flag =
false;
446 HepMatrix tV_Dt = tV_Dtin.inverse(err_inverse);
456 HepMatrix td =
m_d.sub(2 * k + 1, 2 * (k + 1), 1, 1);
457 HepMatrix tE =
m_E.sub(2 * k + 1, 2 * (k + 1), 1, 3);
458 chisq += ((
m_lam.sub(2 * k + 1, 2 * (k + 1), 1, 1).T()) * (tD * tDeltaAl + tE * (
m_v -
m_v_a) + td))(1,
469 if (tmp_chisq <= chisq && it_flag) {
483 if (tmp_chisq <= chisq) it_flag =
true;
503 m_V_Dt = tV_Dtin.inverse(err_inverse);
546 HepMatrix tmp_al_a(
m_al_a);
548 HepMatrix tmp_al_0(
m_al_1);
569 m_V_D.sub(2 * k + 1, 2 * k + 1, tV_D);
572 HepMatrix td =
m_d.sub(2 * k + 1, 2 * (k + 1), 1, 1);
573 HepMatrix tlam = tV_D * (tD * tDeltaAl + td);
574 m_lam.sub(2 * k + 1, 1, tlam);
575 m_EachCHIsq[k] = ((tlam.T()) * (tD * tDeltaAl + td))(1, 1);
583 if (tmp_chisq <= chisq) {
650 tmp_property[index][0] = track.getCharge();
651 tmp_property[index][1] = track.getMass();
698 for (
int i = 0; i < 3; i++)
725 pdata.setError(
makeError1(pdata.getMomentum(),
742 for (
int i = 0; i < 3; i++)
for (
int j = i; j < 3; j++)
777 double pt =
sqrt(px * px + py * py);
784 double invPt = 1. / pt;
785 double invPt2 = invPt * invPt;
786 double dlx =
m_v_a[0][0] - x;
787 double dly =
m_v_a[1][0] - y;
788 double dlz =
m_v_a[2][0] - z;
789 double a1 = -dlx * py + dly * px;
790 double a2 = dlx * px + dly * py;
791 double r2d2 = dlx * dlx + dly * dly;
792 double Rx = dlx - 2.*px * a2 * invPt2;
793 double Ry = dly - 2.*py * a2 * invPt2;
797 double B = a * a2 * invPt2;
800 B2DEBUG(10,
"KFitError: Cannot calculate arcsin");
806 double tmp0 = 1.0 - B * B;
813 double sqrtag = 1.0 /
sqrt(tmp0);
815 U = dlz - pz * sininv / a;
821 U = dlz - pz * a2 * invPt2;
825 m_d[i * 2 + 0][0] = a1 - 0.5 * a * r2d2;
826 m_d[i * 2 + 1][0] = U * pt;
843 m_E[i * 2 + 0][0] = -py - a * dlx;
844 m_E[i * 2 + 0][1] = px - a * dly;
845 m_E[i * 2 + 0][2] = 0.0;
846 m_E[i * 2 + 1][0] = -px * pz * pt * S;
847 m_E[i * 2 + 1][1] = -py * pz * pt * S;
848 m_E[i * 2 + 1][2] = pt;
873 sprintf(buf,
"%s:%s(): internal error; duplicated appendTube() call?", __FILE__, __func__);
892 sprintf(buf,
"%s:%s(): internal error; duplicated deleteTube() call?", __FILE__, __func__);
908 for (
unsigned i = 0; i < n; ++i) {
912 for (
unsigned j = i + 1; j < n; ++j) {
923 double prob = TMath::Prob(chi2, ndf);
DataType Z() const
access variable Z (= .at(2) without boundary check)
DataType X() const
access variable X (= .at(0) without boundary check)
DataType Y() const
access variable Y (= .at(1) without boundary check)
static const double speedOfLight
[cm/ns]
Class to store reconstructed particles.
void setExtraInfo(const std::string &name, double value)
Sets the user-defined data of given name to the given value.
bool hasExtraInfo(const std::string &name) const
Return whether the extra info with the given name is set.
void addExtraInfo(const std::string &name, double value)
Sets the user-defined data of given name to the given value.
void updateMomentum(const ROOT::Math::PxPyPzEVector &p4, const ROOT::Math::XYZVector &vertex, const TMatrixFSym &errMatrix, double pValue)
Sets Lorentz vector, position, 7x7 error matrix and p-value.
int m_NecessaryTrackCount
Number needed tracks to perform fit.
double m_MagneticField
Magnetic field.
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.
CLHEP::HepMatrix m_al_1
See J.Tanaka Ph.D (2001) p136 for definition.
CLHEP::HepMatrix m_V_Dt
See J.Tanaka Ph.D (2001) p138 for definition.
const CLHEP::HepSymMatrix getTrackError(const int id) const
Get an error matrix of the track.
virtual double getCHIsq(void) const
Get a chi-square of the fit.
const CLHEP::HepLorentzVector getTrackMomentum(const int id) const
Get a Lorentz vector of the track.
CLHEP::HepMatrix m_lam
See J.Tanaka Ph.D (2001) p137 for definition.
enum KFitError::ECode doFit2(void)
Perform a fit (used in VertexFitKFit::doFit() and MassVertexFitKFit::doFit()).
CLHEP::HepMatrix m_E
See J.Tanaka Ph.D (2001) p137 for definition.
const HepPoint3D getTrackPosition(const int id) const
Get a position of the track.
bool m_FlagOverIteration
Flag whether the iteration count exceeds the limit.
CLHEP::HepMatrix m_property
Container of charges and masses.
virtual double getTrackCHIsq(const int id) const
Get a chi-square of the track.
enum KFitError::ECode m_ErrorCode
Error code.
CLHEP::HepMatrix m_V_al_1
See J.Tanaka Ph.D (2001) p138 for definition.
virtual int getNDF(void) const
Get an NDF of the fit.
CLHEP::HepMatrix m_d
See J.Tanaka Ph.D (2001) p137 for definition.
CLHEP::HepMatrix m_lam0
See J.Tanaka Ph.D (2001) p138 for definition.
bool isFitted(void) const
Return false if fit is not performed yet or performed fit is failed; otherwise true.
CLHEP::HepMatrix m_al_a
See J.Tanaka Ph.D (2001) p137 for definition.
CLHEP::HepMatrix m_D
See J.Tanaka Ph.D (2001) p137 for definition.
CLHEP::HepMatrix m_V_D
See J.Tanaka Ph.D (2001) p138 for definition.
bool isTrackIDInRange(const int id) const
Check if the id is in the range.
CLHEP::HepMatrix m_v_a
See J.Tanaka Ph.D (2001) p137 for definition.
virtual const CLHEP::HepMatrix getCorrelation(const int id1, const int id2, const int flag=KFitConst::kAfterFit) const
Get a correlation matrix between two tracks.
bool m_FlagCorrelation
Flag whether a correlation among tracks exists.
CLHEP::HepSymMatrix m_V_al_0
See J.Tanaka Ph.D (2001) p137 for definition.
CLHEP::HepMatrix m_V_E
See J.Tanaka Ph.D (2001) p138 for definition.
CLHEP::HepMatrix m_Cov_v_al_1
See J.Tanaka Ph.D (2001) p137 for definition.
const KFitTrack getTrack(const int id) const
Get a specified track object.
virtual enum KFitError::ECode prepareCorrelation(void)
Build a grand correlation matrix from input-track properties.
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.
bool m_FlagFitted
Flag to indicate if the fit is performed and succeeded.
double m_CHIsq
chi-square of the fit.
int getTrackCount(void) const
Get the number of added tracks.
std::vector< KFitTrack > m_Tracks
Container of input tracks.
CLHEP::HepMatrix m_v
See J.Tanaka Ph.D (2001) p137 for definition.
int m_TrackCount
Number of tracks.
CLHEP::HepMatrix m_al_0
See J.Tanaka Ph.D (2001) p136 for definition.
static void displayError(const char *file, const int line, const char *func, const enum ECode code)
Display a description of error and its location.
ECode
ECode is a error code enumerate.
@ kCannotGetARCSIN
Cannot get arcsin (bad track property or internal error)
@ kCannotGetMatrixInverse
Cannot calculate matrix inverse (bad track property or internal error)
@ kOutOfRange
Specified track-id out of range.
@ kDivisionByZero
Division by zero (bad track property or internal error)
@ kBadInitialCHIsq
Bad initial chi-square (internal error)
@ kBadTrackSize
Track count too small to perform fit.
KFitTrack is a container of the track information (Lorentz vector, position, and error matrix),...
MakeMotherKFit is a class to build mother particle from kinematically fitted daughters.
enum KFitError::ECode setVertex(const HepPoint3D &v)
Set a vertex position of the mother particle.
enum KFitError::ECode addTrack(const KFitTrack &kp)
Add a track to the make-mother object.
enum KFitError::ECode doMake(void)
Perform a reconstruction of mother particle.
const CLHEP::HepSymMatrix getMotherError(void) const
Get an error matrix of the mother particle.
enum KFitError::ECode setCorrelation(const CLHEP::HepMatrix &e)
Set a correlation matrix.
const HepPoint3D getMotherPosition(void) const
Get a position of the mother particle.
enum KFitError::ECode setVertexError(const CLHEP::HepSymMatrix &e)
Set a vertex error matrix of the mother particle.
enum KFitError::ECode setTrackVertexError(const CLHEP::HepMatrix &e)
Set a vertex error matrix of the child particle in the addTrack'ed order.
const CLHEP::HepLorentzVector getMotherMomentum(void) const
Get a Lorentz vector of the mother particle.
enum KFitError::ECode setMagneticField(const double mf)
Change a magnetic field from the default value KFitConst::kDefaultMagneticField.
enum KFitError::ECode setIpTubeProfile(const CLHEP::HepLorentzVector &p, const HepPoint3D &x, const CLHEP::HepSymMatrix &e, const double q)
Set a virtual IP-tube track for the vertex constraint fit.
enum KFitError::ECode doFit5(void)
Perform a fixed-vertex-position fit mainly for slow pion.
enum KFitError::ECode setKnownVertex(const bool flag=true)
Tell the object to perform a fit with vertex position fixed.
enum KFitError::ECode prepareInputMatrix(void) override
Build grand matrices for minimum search from input-track properties.
enum KFitError::ECode doFit4(void)
Perform a IP-ellipsoid and vertex-constraint fit.
enum KFitError::ECode calculateNDF(void) override
Calculate an NDF of the fit.
enum KFitError::ECode setInitialVertex(const HepPoint3D &v)
Set an initial vertex point for the vertex-vertex constraint fit.
double getCHIsq(void) const override
Get a chi-square of the fit.
KFitTrack m_TubeTrack
Entity of the virtual IP-tube track.
VertexFitKFit(void)
Construct an object with no argument.
enum KFitError::ECode deleteTube(void)
Delete the virtual tube track to m_Tracks just after the internal minimization call.
bool m_FlagTube
Flag if to perform IP-tube constraint fit.
bool m_FlagKnownVertex
Flag controlled by setKnownVertex().
enum KFitError::ECode updateMother(Particle *mother)
Update mother particle.
const CLHEP::HepSymMatrix getVertexError(void) const
Get a fitted vertex error matrix.
enum KFitError::ECode prepareInputSubMatrix(void) override
Build sub-matrices for minimum search from input-track properties.
CLHEP::HepSymMatrix m_BeamError
Error matrix modeling the IP ellipsoid.
enum KFitError::ECode doFit(void)
Perform a vertex-constraint fit.
double getTrackPartCHIsq(void) const
Get a sum of the chi-square associated to the input tracks.
enum KFitError::ECode doFit3(void)
Perform a standard vertex-constraint fit including IP-tube constraint.
~VertexFitKFit(void)
Destruct the object.
enum KFitError::ECode makeCoreMatrix(void) override
Build matrices using the kinematical constraint.
HepPoint3D m_AfterVertex
Vertex position after the fit.
std::vector< CLHEP::HepMatrix > m_AfterTrackVertexError
Array of vertex error matrices after the fit.
double m_EachCHIsq[KFitConst::kMaxTrackCount2]
Container of chi-square's of the input tracks.
double getTrackCHIsq(const int id) const override
Get a chi-square of the track.
enum KFitError::ECode setCorrelationMode(const bool m)
Tell the object to perform a fit with track correlations.
int getTrackPartNDF(void) const
Get an NDF relevant to the getTrackPartCHIsq().
bool m_FlagBeam
Flag if to perform IP-ellipsoid constraint fit.
int m_iTrackTube
ID of the virtual tube track in the m_Tracks.
enum KFitError::ECode setIpProfile(const HepPoint3D &ip, const CLHEP::HepSymMatrix &ipe)
Set an IP-ellipsoid shape for the vertex constraint fit.
const HepPoint3D getVertex(const int flag=KFitConst::kAfterFit) const
Get a vertex position.
double m_CHIsqVertex
chi-square of the fit excluding IP-constraint part.
double getCHIsqVertex(void) const
Get a chi-square of the fit excluding IP-constraint part.
enum KFitError::ECode appendTube(void)
Add the virtual tube track to m_Tracks just before the internal minimization call.
CLHEP::HepSymMatrix m_AfterVertexError
Vertex error matrix after the fit.
bool m_CorrelationMode
Flag controlled by setCorrelationMode().
enum KFitError::ECode prepareOutputMatrix(void) override
Build an output error matrix.
const CLHEP::HepMatrix getTrackVertexError(const int id) const
Get a vertex error matrix of the track.
HepPoint3D m_BeforeVertex
Vertex position before the fit.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.
static constexpr double kInitialCHIsq
Initial chi-square value (internal use)
static const int kMaxTrackCount
Maximum track size.
static const int kMaxTrackCount2
Maximum track size (internal use)
static const int kNumber6
Constant 6 to check matrix size (internal use)
static const int kMaxIterationCount
Maximum iteration step (internal use)
static const int kAfterFit
Input parameter to specify after-fit when setting/getting a track attribute.
static const int kBeforeFit
Input parameter to specify before-fit when setting/getting a track attribute.
static const int kNumber7
Constant 7 to check matrix size (internal use)