Belle II Software  release-06-01-15
RecoComposite.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 
11 #include <analysis/VertexFitting/TreeFitter/RecoComposite.h>
12 #include <analysis/VertexFitting/TreeFitter/FitParams.h>
13 
14 #include <TMatrixFSym.h>
15 
16 namespace TreeFitter {
17 
19  : ParticleBase(particle, mother), m_params(), m_hasEnergy(true)
20  {
21  updateParams();
22  }
23 
25  bool massConstraint)
26  : ParticleBase(particle, mother, &config), m_params(), m_hasEnergy(true), m_massconstraint(massConstraint)
27  {
28  updateParams();
29  }
30 
32  {
33  return initTau(fitparams);
34  }
35 
37  {
38  const int posindex = posIndex();
39  const int momindex = momIndex();
40 
41  fitparams.getStateVector().segment(posindex, 3) = m_params.segment(0, 3);
42 
43  fitparams.getStateVector().segment(momindex, 4) = m_params.segment(3, 4);
44 
45  return ErrCode(ErrCode::Status::success) ;
46  }
47 
49  {
50  const TVector3 pos = particle()->getVertex();
51  const TVector3 mom = particle()->getMomentum();
52  const double energy = particle()->getEnergy();
53 
54  m_params = Eigen::Matrix<double, 7, 1>::Zero(7, 1);
55  m_params(0) = pos.X();
56  m_params(1) = pos.Y();
57  m_params(2) = pos.Z();
58  m_params(3) = mom.X();
59  m_params(4) = mom.Y();
60  m_params(5) = mom.Z();
61 
62  m_params(6) = energy;
63 
64  m_covariance = Eigen::Matrix < double, -1, -1, 0, 7, 7 >::Zero(7, 7);
65  const TMatrixFSym cov7in = particle()->getMomentumVertexErrorMatrix(); //this is (p,E,x)
66 
67  for (int row = 0; row < 4; ++row) { //first the p,E block
68  for (int col = 0; col <= row; ++col) {
69  m_covariance(3 + row, 3 + col) = cov7in[row][col];
70  }
71  }
72 
73  for (int row = 0; row < 3; ++row) { //then the x block
74  for (int col = 0; col <= row; ++col) {
75  m_covariance(row, col) = cov7in[3 + row][3 + col];
76  }
77  }
78  }
79 
81  {
82  const int posindex = posIndex() ;
83  const int momindex = momIndex() ;
84 
85  p.getResiduals().segment(0, 3) = m_params.segment(0, 3) - fitparams.getStateVector().segment(posindex, 3);
86 
87  p.getResiduals().segment(3, 4) = m_params.segment(3, 4) - fitparams.getStateVector().segment(momindex, 4);
88 
89  for (int row = 0; row < 3; ++row) {
90  p.getH()(row, posindex + row) = -1;
91  }
92 
93  for (int row = 0; row < 4; ++row) {
94  p.getH()(3 + row, momindex + row) = -1;
95  }
96 
97  p.getV().triangularView<Eigen::Lower>() = m_covariance.triangularView<Eigen::Lower>();
98 
99  return ErrCode(ErrCode::Status::success) ;
100  }
101 
103  {
104  ErrCode status;
105  switch (type) {
106  case Constraint::mass:
107  status |= projectMassConstraint(fitparams, p);
108  break;
109  case Constraint::composite:
110  status |= projectRecoComposite(fitparams, p);
111  break ;
112  case Constraint::geometric:
113  status |= projectGeoConstraint(fitparams, p);
114  break ;
115  default:
116  status |= ParticleBase::projectConstraint(type, fitparams, p);
117  }
118  return status ;
119  }
120 
121 }
Class to store reconstructed particles.
Definition: Particle.h:74
float getEnergy() const
Returns total energy.
Definition: Particle.h:467
TVector3 getVertex() const
Returns vertex position (POCA for charged, IP for neutral FS particles)
Definition: Particle.h:551
TVector3 getMomentum() const
Returns momentum vector.
Definition: Particle.h:488
TMatrixFSym getMomentumVertexErrorMatrix() const
Returns 7x7 error matrix.
Definition: Particle.cc:430
Type
type of constraints the order of these constraints is important: it is the order in which they are ap...
Definition: Constraint.h:27
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, 1 > & getStateVector()
getter for the fit parameters/statevector
Definition: FitParams.h:65
base class for all particles
Definition: ParticleBase.h:25
Belle2::Particle * particle() const
get basf2 particle
Definition: ParticleBase.h:96
ErrCode initTau(FitParams &par) const
initialises tau as a length
virtual ErrCode projectMassConstraint(const FitParams &, Projection &) const
project mass constraint abstract
virtual ErrCode projectConstraint(Constraint::Type, const FitParams &, Projection &) const
project constraint.
virtual ErrCode projectGeoConstraint(const FitParams &, Projection &) const
project geometrical constraint
class to store the projected residuals and the corresponding jacobian as well as the covariance matri...
Definition: Projection.h:18
ErrCode projectRecoComposite(const FitParams &fitparams, Projection &p) const
project this particle constraint
void updateParams()
update changed params
virtual ErrCode projectConstraint(Constraint::Type, const FitParams &, Projection &) const override
project this constraint
Eigen::Matrix< double, 7, 1 > m_params
column vector to store the measurement
Definition: RecoComposite.h:84
virtual int momIndex() const override
get momentum index in statevector
Definition: RecoComposite.h:63
Eigen::Matrix< double, -1, -1, 0, 7, 7 > m_covariance
only lower triangle filled!
Definition: RecoComposite.h:87
virtual int type() const override
get ype
Definition: RecoComposite.h:54
virtual ErrCode initParticleWithMother(FitParams &fitparams) override
init particle in case it has a mother
virtual ErrCode initMotherlessParticle(FitParams &fitparams) override
init particle in case it has no mother
virtual int posIndex() const override
get position index in statevectof x,y,z,tau,px,py,pz
Definition: RecoComposite.h:57
RecoComposite(Belle2::Particle *bc, const ParticleBase *mother)
constructor