Belle II Software  release-06-02-00
Origin.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/Origin.h>
12 #include <analysis/VertexFitting/TreeFitter/FitParams.h>
13 #include <analysis/dataobjects/Particle.h>
14 #include <framework/logging/Logger.h>
15 namespace TreeFitter {
16 
18  const ConstraintConfiguration& config,
19  bool forceFitAll
20  ) :
21  ParticleBase("Origin"),
22  m_constraintDimension(config.m_originDimension), //this also affects the geometric constraint
23  m_customOriginVertex(config.m_customOriginVertex),
24  m_customOriginCovariance(config.m_customOriginCovariance),
25  m_posVec(config.m_originDimension),
26  m_covariance(config.m_originDimension, config.m_originDimension),
27  m_isBeamSpot(config.m_ipConstraint),
28  m_inflationFactorCovZ(config.m_inflationFactorCovZ)
29  {
30  addDaughter(daughter, config, forceFitAll);
31  initOrigin();
32  }
33 
34  ErrCode Origin::initParticleWithMother([[gnu::unused]] FitParams& fitparams)
35  {
36  return ErrCode(ErrCode::Status::success);
37  }
38 
40  {
41  ErrCode status;
42  const int posindex = posIndex();
43  fitparams.getStateVector().segment(posindex, m_constraintDimension) = m_posVec.segment(0, m_constraintDimension);
44 
45  for (auto daughter : m_daughters) {
46  status |= daughter->initMotherlessParticle(fitparams);
47  status |= daughter->initParticleWithMother(fitparams);
48  }
49 
50  return status;
51  }
52 
54  {
56  m_covariance = Eigen::Matrix<double, 3, 3>::Zero(3, 3);
57  const TVector3& vertexVector = m_beamSpot->getIPPosition();
58  const TMatrixDSym& covVertex = m_beamSpot->getCovVertex();
59  m_posVec(0) = vertexVector.x();
60  m_posVec(1) = vertexVector.y();
61  m_posVec(2) = vertexVector.z();
62  m_covariance(0, 0) = covVertex(0 , 0);
63  m_covariance(1, 1) = covVertex(1 , 1);
64  m_covariance(2, 2) = covVertex(2 , 2);
65  m_covariance(1, 0) = covVertex(1 , 0);
66  m_covariance(2, 0) = covVertex(2 , 0);
67  m_covariance(2, 1) = covVertex(2 , 1);
68 
69  } else if (m_beamSpot && m_isBeamSpot && m_constraintDimension == 2) {
70  m_covariance = Eigen::Matrix<double, 2, 2>::Zero(2, 2);
71  const TVector3& vertexVector = m_beamSpot->getIPPosition();
72  const TMatrixDSym& covVertex = m_beamSpot->getCovVertex();
73  m_posVec(0) = vertexVector.x();
74  m_posVec(1) = vertexVector.y();
75  m_covariance(0, 0) = covVertex(0 , 0);
76  m_covariance(1, 1) = covVertex(1 , 1);
77  m_covariance(1, 0) = covVertex(1 , 0);
78 
79  } else if (!m_isBeamSpot && m_constraintDimension == 3) {
80 
81  if (!(m_customOriginVertex.size() == 3) || !(m_customOriginCovariance.size() == 9)) {
82  B2FATAL("Incorrect dimension of customOriginVertex or customOriginCovariance. customOriginVertex dim = "
83  << m_customOriginVertex.size() << " customOriginCovariance dim = " << m_customOriginCovariance.size());
84  } else if ((m_customOriginCovariance.at(0) < 0) || (m_customOriginCovariance.at(4) < 0) || (m_customOriginCovariance.at(8) < 0)) {
85  B2WARNING("An element of customOriginCovariance diagonal is smaller than 0.");
86  return ErrCode(ErrCode::Status::badsetup);
87  }
95 
96  // all with z
102  } else {
103  B2FATAL("The Origin is nether beamspot nor custom. This is ether a configuration error or no beam parameters were found to build the beam spot.");
104  }
105 
106  return ErrCode(ErrCode::Status::success);
107  }
108 
110  {
111  ErrCode status;
112  const int posindex = posIndex();
113  for (int row = 0; row < m_constraintDimension; ++row) {
114  fitpar.getCovariance()(posindex + row, posindex + row) = 1000 * m_covariance(row, row);
115  }
116  for (auto daughter : m_daughters) {
117  status |= daughter->initCovariance(fitpar);
118  }
119  return status;
120  }
121 
123  {
124  const int posindex = posIndex();
125 
126  p.getResiduals().segment(0, m_constraintDimension) =
127  m_posVec.segment(0, m_constraintDimension) -
128  fitparams.getStateVector().segment(posindex, m_constraintDimension);
129 
130  for (int row = 0; row < m_constraintDimension; ++row) {
131  p.getH()(row, posindex + row) = -1;
132 
133  for (int col = 0; col <= row; ++col) {
134  p.getV()(row, col) = m_covariance(row, col);
135  }
136  }
137 
138  return ErrCode(ErrCode::Status::success);
139  }
140 
142  {
143  ErrCode status;
144  switch (type) {
145  case Constraint::origin:
146  status |= projectOriginConstraint(fitparams, p);
147  break;
148  default:
149  status |= ParticleBase::projectConstraint(type, fitparams, p);
150  }
151  return status;
152  }
153 
154  void Origin::addToConstraintList(constraintlist& list, int depth) const
155  {
156  for (auto daughter : m_daughters) {
157  daughter->addToConstraintList(list, depth - 1);
158  }
159  list.push_back(Constraint(this, Constraint::origin, depth, m_constraintDimension)) ;
160  }
161 }
TMatrixDSym getCovVertex() const
Get the total covariance matrix of theIP position (for compatibility with BeamParameters)
Definition: BeamSpot.h:85
const TVector3 & getIPPosition() const
Get the IP position.
Definition: BeamSpot.h:66
Class to store reconstructed particles.
Definition: Particle.h:74
class to manage the order of constraints and their filtering
Definition: Constraint.h:20
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, 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
ErrCode projectOriginConstraint(const FitParams &fitpar, Projection &) const
the actual constraint projection
Definition: Origin.cc:122
const int m_constraintDimension
dimension of the constraint
Definition: Origin.h:80
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor, 3, 3 > m_covariance
covariance of the origin dont know size but I know the max size
Definition: Origin.h:94
const std::vector< double > m_customOriginVertex
vertex coordinates
Definition: Origin.h:83
virtual ErrCode initCovariance(FitParams &fitpar) const override
init covariance matrix of the constraint
Definition: Origin.cc:109
virtual ErrCode projectConstraint(Constraint::Type, const FitParams &, Projection &) const override
the abstract projection
Definition: Origin.cc:141
ErrCode initOrigin()
init the origin "particle"
Definition: Origin.cc:53
virtual int type() const override
get particle type
Definition: Origin.h:51
const std::vector< double > m_customOriginCovariance
vertex covariance
Definition: Origin.h:86
Eigen::Matrix< double, Eigen::Dynamic, 1, Eigen::ColMajor, 3, 1 > m_posVec
vertex position of the origin
Definition: Origin.h:89
Origin(Belle2::Particle *particle, const ConstraintConfiguration &config, const bool forceFitAll)
Constructor.
Definition: Origin.cc:17
virtual ErrCode initParticleWithMother(FitParams &fitparams) override
init particle, used if it has a mother
Definition: Origin.cc:34
virtual void addToConstraintList(constraintlist &list, int depth) const override
adds the origin as a particle to the constraint list
Definition: Origin.cc:154
virtual ErrCode initMotherlessParticle(FitParams &fitparams) override
init particle, used if it has no mother
Definition: Origin.cc:39
virtual int posIndex() const override
vertex position index in the statevector
Definition: Origin.h:63
const bool m_isBeamSpot
is this the beam constraint?
Definition: Origin.h:97
Belle2::DBObjPtr< Belle2::BeamSpot > m_beamSpot
the parameters are initialize elsewhere this is just a pointer to that
Definition: Origin.h:100
const int m_inflationFactorCovZ
inflated the covariance matrix in z by this number
Definition: Origin.h:103
base class for all particles
Definition: ParticleBase.h:25
virtual ParticleBase * addDaughter(Belle2::Particle *, const ConstraintConfiguration &config, bool forceFitAll=false)
add daughter
virtual ErrCode projectConstraint(Constraint::Type, const FitParams &, Projection &) const
project constraint.
std::vector< ParticleBase * > m_daughters
daughter container
Definition: ParticleBase.h:218
std::vector< Constraint > constraintlist
alias
Definition: ParticleBase.h:56
class to store the projected residuals and the corresponding jacobian as well as the covariance matri...
Definition: Projection.h:18