Belle II Software  release-06-00-14
RecoTrack.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * External Contributor: Wouter Hulsbergen *
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 #include <analysis/VertexFitting/TreeFitter/RecoTrack.h>
11 #include <analysis/VertexFitting/TreeFitter/FitParams.h>
12 #include <analysis/VertexFitting/TreeFitter/HelixUtils.h>
13 
14 #include <framework/gearbox/Const.h>
15 #include <mdst/dataobjects/Track.h>
16 
17 #include <TMath.h>
18 
19 namespace TreeFitter {
20  constexpr double pi = TMath::Pi();
21  constexpr double twoPi = TMath::TwoPi();
22 
24  RecoParticle(particle, mother),
25  m_bfield(0),
26  m_trackfit(particle->getTrackFitResult()),
27  m_cached(false),
28  m_flt(0),
29  m_params(5),
30  m_covariance(5, 5),
31  m_momentumScalingFactor(particle->getMomentumScalingFactor())
32  {
33  m_bfield = Belle2::BFieldManager::getField(TVector3(0, 0, 0)).Z() / Belle2::Unit::T; //Bz in Tesla
34  m_covariance = Eigen::Matrix<double, 5, 5>::Zero(5, 5);
35  }
36 
38  {
39  //initPar2
40  if (m_flt == 0) {
41  const_cast<RecoTrack*>(this)->updFltToMother(fitparams);
42  }
43  TVector3 recoP = m_trackfit->getHelix(m_momentumScalingFactor).getMomentumAtArcLength2D(m_flt, m_bfield);
44  const int momindex = momIndex();
45  fitparams.getStateVector()(momindex) = recoP.X();
46  fitparams.getStateVector()(momindex + 1) = recoP.Y();
47  fitparams.getStateVector()(momindex + 2) = recoP.Z();
48  return ErrCode(ErrCode::Status::success);
49  }
50 
52  {
53  return ErrCode(ErrCode::Status::success);
54  }
55 
57  {
58  // we only need a rough estimate of the covariance
59  TMatrixFSym p4Err = particle()->getMomentumErrorMatrix();
60  const int momindex = momIndex();
61 
62  for (int row = 0; row < 3; ++row) {
63  fitparams.getCovariance()(momindex + row, momindex + row) = 1000 * p4Err[row][row];
64  }
65 
66  return ErrCode(ErrCode::Status::success);
67  }
68 
69 
71  {
72  const int posindexmother = mother()->posIndex();
73  m_flt = m_trackfit->getHelix(m_momentumScalingFactor).getArcLength2DAtXY(
74  fitparams.getStateVector()(posindexmother),
75  fitparams.getStateVector()(posindexmother + 1));
76  return ErrCode(ErrCode::Status::success);
77  } ;
78 
80  {
81  m_flt = flt;
82  std::vector<float> trackParameter = m_trackfit->getTau();
83  for (unsigned int i = 0; i < trackParameter.size(); ++i) {
84  m_params(i) = trackParameter[i];
85  if (i == 2) m_params(2) /= m_momentumScalingFactor; // index 2 is the curvature of the track
86  }
87  TMatrixDSym cov = m_trackfit->getCovariance5();
88  for (int row = 0; row < 5; ++row) {
89  for (int col = 0; col <= row; ++col) {
90  m_covariance(row, col) = cov[row][col];
91  }
92  }
93 
94  m_cached = true;
95  return ErrCode(ErrCode::Status::success);
96  }
97 
99  {
100  ErrCode status;
101  const int posindexmother = mother()->posIndex();
102  const int momindex = momIndex();
103 
104  Eigen::Matrix<double, 1, 6> positionAndMom = Eigen::Matrix<double, 1, 6>::Zero(1, 6);
105  positionAndMom.segment(0, 3) = fitparams.getStateVector().segment(posindexmother, 3);
106  positionAndMom.segment(3, 3) = fitparams.getStateVector().segment(momindex, 3);
107  Eigen::Matrix<double, 5, 6> jacobian = Eigen::Matrix<double, 5, 6>::Zero(5, 6);
108 
110  TVector3(
111  positionAndMom(0),
112  positionAndMom(1),
113  positionAndMom(2)),
114  TVector3(
115  positionAndMom(3),
116  positionAndMom(4),
117  positionAndMom(5)),
118  charge(),
119  m_bfield
120  );
121 
123  positionAndMom(0),
124  positionAndMom(1),
125  positionAndMom(2),
126  positionAndMom(3),
127  positionAndMom(4),
128  positionAndMom(5),
129  m_bfield,
130  charge()
131  );
132  if (!m_cached) {
133  auto* nonconst = const_cast<RecoTrack*>(this);
134  if (m_flt == 0) { nonconst->updFltToMother(fitparams); }
135  nonconst->updateParams(m_flt);
136  }
137 
138  Eigen::Matrix<double, 1, 5> helixpars(5);
139  helixpars(0) = helix.getD0();
140  helixpars(1) = helix.getPhi0();
141  helixpars(2) = helix.getOmega();
142  helixpars(3) = helix.getZ0();
143  helixpars(4) = helix.getTanLambda();
144 
145  p.getResiduals().segment(0, 5) = m_params - helixpars;
146 
147  //account for periodic boundary in phi residual
148  double phiResidual = p.getResiduals().segment(0, 5)(1);
149  phiResidual = std::fmod(phiResidual + pi, twoPi);
150  if (phiResidual < 0) phiResidual += twoPi;
151  phiResidual -= pi;
152  p.getResiduals().segment(0, 5)(1) = phiResidual;
153 
154  p.getV().triangularView<Eigen::Lower>() = m_covariance.triangularView<Eigen::Lower>();
155 
156  p.getH().block<5, 3>(0, posindexmother) = -1.0 * jacobian.block<5, 3>(0, 0);
157  p.getH().block<5, 3>(0, momindex) = -1.0 * jacobian.block<5, 3>(0, 3);
158 
159  return status;
160  }
161 
162 }//end recotrack
Helix parameter class.
Definition: Helix.h:48
Class to store reconstructed particles.
Definition: Particle.h:74
TMatrixFSym getMomentumErrorMatrix() const
Returns the 4x4 momentum error matrix.
Definition: Particle.cc:445
std::vector< float > getTau() const
Getter for all perigee parameters.
Helix getHelix() const
Conversion to framework Helix (without covariance).
TMatrixDSym getCovariance5() const
Getter for covariance matrix of perigee parameters in matrix form.
static const double T
[tesla]
Definition: Unit.h:120
abstract errorocode be aware that the default is success
Definition: ErrCode.h:14
Class to store and manage fitparams (statevector)
Definition: FitParams.h:20
Eigen::Matrix< double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > & getCovariance()
getter for the states covariance
Definition: FitParams.h:53
Eigen::Matrix< double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > & getStateVector()
getter for the fit parameters/statevector
Definition: FitParams.h:65
static void getJacobianToCartesianFrameworkHelix(Eigen::Matrix< double, 5, 6 > &jacobian, const double x, const double y, const double z, const double px, const double py, const double pz, const double bfield, const double charge)
get the jacobian dh={helix pars}/dx={x,y,z,px,py,pz} for the implementation of the framework helix.
Definition: HelixUtils.cc:379
base class for all particles
Definition: ParticleBase.h:25
Belle2::Particle * particle() const
get basf2 particle
Definition: ParticleBase.h:96
virtual int posIndex() const
get vertex index (in statevector!)
Definition: ParticleBase.h:129
int charge() const
get charge
Definition: ParticleBase.h:163
const ParticleBase * mother() const
getMother() / hasMother()
class to store the projected residuals and the corresponding jacobian as well as the covariance matri...
Definition: Projection.h:18
base for RecoPhoton RecoTrack
Definition: RecoParticle.h:16
virtual int momIndex() const override
get momentum index
Definition: RecoParticle.h:42
representation of all charged final states FIXME rename since this name is taken in tracking
Definition: RecoTrack.h:18
ErrCode initCovariance(FitParams &fitparams) const override
init covariance matrix of this particle constraint
Definition: RecoTrack.cc:56
const Belle2::TrackFitResult * m_trackfit
trackfit result from reconstruction
Definition: RecoTrack.h:72
Eigen::Matrix< double, 1, 5 > m_params
column vector to store the measurement
Definition: RecoTrack.h:81
const float m_momentumScalingFactor
scale the momenta by this correction factor
Definition: RecoTrack.h:87
virtual ErrCode projectRecoConstraint(const FitParams &, Projection &) const override
project the constraint (calculate residuals)
Definition: RecoTrack.cc:98
ErrCode updateParams(double flt)
updated the cached parameters
Definition: RecoTrack.cc:79
virtual ErrCode initParticleWithMother(FitParams &fitparams) override
init with mother particle (replacing initPar2)
Definition: RecoTrack.cc:37
double m_bfield
B field along z
Definition: RecoTrack.h:69
virtual ErrCode initMotherlessParticle(FitParams &fitparams) override
init without mother particle
Definition: RecoTrack.cc:51
ErrCode updFltToMother(const FitParams &fitparams)
update flight length to mother
Definition: RecoTrack.cc:70
double m_flt
helix arc length at vertex
Definition: RecoTrack.h:78
Eigen::Matrix< double, 5, 5 > m_covariance
only lower triangle filled!
Definition: RecoTrack.h:84
bool m_cached
flag to mark the particle as initialised
Definition: RecoTrack.h:75
RecoTrack(Belle2::Particle *bc, const ParticleBase *mother)
constructor
Definition: RecoTrack.cc:23
static void getField(const double *pos, double *field)
return the magnetic field at a given position.