Belle II Software light-2406-ragdoll
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#include <analysis/VertexFitting/TreeFitter/Origin.h>
11#include <analysis/VertexFitting/TreeFitter/FitParams.h>
12#include <analysis/dataobjects/Particle.h>
13#include <framework/logging/Logger.h>
14#include <framework/geometry/B2Vector3.h>
15
16namespace TreeFitter {
17
19 const ConstraintConfiguration& config,
20 bool forceFitAll
21 ) :
22 ParticleBase("Origin"),
23 m_constraintDimension(config.m_originDimension), //this also affects the geometric constraint
24 m_customOriginVertex(config.m_customOriginVertex),
25 m_customOriginCovariance(config.m_customOriginCovariance),
26 m_posVec(config.m_originDimension),
27 m_covariance(config.m_originDimension, config.m_originDimension),
28 m_isBeamSpot(config.m_ipConstraint),
29 m_inflationFactorCovZ(config.m_inflationFactorCovZ)
30 {
31 addDaughter(daughter, config, forceFitAll);
32 initOrigin();
33 }
34
36 {
37 return ErrCode(ErrCode::Status::success);
38 }
39
41 {
42 ErrCode status;
43 const int posindex = posIndex();
44 fitparams.getStateVector().segment(posindex, m_constraintDimension) = m_posVec.segment(0, m_constraintDimension);
45
46 for (auto daughter : m_daughters) {
47 status |= daughter->initMotherlessParticle(fitparams);
48 status |= daughter->initParticleWithMother(fitparams);
49 }
50
51 return status;
52 }
53
55 {
57 m_covariance = Eigen::Matrix<double, 3, 3>::Zero(3, 3);
58 const Belle2::B2Vector3D& vertexVector = m_beamSpot->getIPPosition();
59 const TMatrixDSym& covVertex = m_beamSpot->getCovVertex();
60 m_posVec(0) = vertexVector.X();
61 m_posVec(1) = vertexVector.Y();
62 m_posVec(2) = vertexVector.Z();
63 m_covariance(0, 0) = covVertex(0, 0);
64 m_covariance(1, 1) = covVertex(1, 1);
65 m_covariance(2, 2) = covVertex(2, 2);
66 m_covariance(1, 0) = covVertex(1, 0);
67 m_covariance(2, 0) = covVertex(2, 0);
68 m_covariance(2, 1) = covVertex(2, 1);
69
70 } else if (m_beamSpot && m_isBeamSpot && m_constraintDimension == 2) {
71 m_covariance = Eigen::Matrix<double, 2, 2>::Zero(2, 2);
72 const Belle2::B2Vector3D& vertexVector = m_beamSpot->getIPPosition();
73 const TMatrixDSym& covVertex = m_beamSpot->getCovVertex();
74 m_posVec(0) = vertexVector.X();
75 m_posVec(1) = vertexVector.Y();
76 m_covariance(0, 0) = covVertex(0, 0);
77 m_covariance(1, 1) = covVertex(1, 1);
78 m_covariance(1, 0) = covVertex(1, 0);
79
80 } else if (!m_isBeamSpot && m_constraintDimension == 3) {
81
82 if (!(m_customOriginVertex.size() == 3) || !(m_customOriginCovariance.size() == 9)) {
83 B2FATAL("Incorrect dimension of customOriginVertex or customOriginCovariance. customOriginVertex dim = "
84 << m_customOriginVertex.size() << " customOriginCovariance dim = " << m_customOriginCovariance.size());
85 } else if ((m_customOriginCovariance.at(0) < 0) || (m_customOriginCovariance.at(4) < 0) || (m_customOriginCovariance.at(8) < 0)) {
86 B2WARNING("An element of customOriginCovariance diagonal is smaller than 0.");
87 return ErrCode(ErrCode::Status::badsetup);
88 }
96
97 // all with z
103 } else {
104 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.");
105 }
106
107 return ErrCode(ErrCode::Status::success);
108 }
109
111 {
112 ErrCode status;
113 const int posindex = posIndex();
114 for (int row = 0; row < m_constraintDimension; ++row) {
115 fitpar.getCovariance()(posindex + row, posindex + row) = 1000 * m_covariance(row, row);
116 }
117 for (auto daughter : m_daughters) {
118 status |= daughter->initCovariance(fitpar);
119 }
120 return status;
121 }
122
124 {
125 const int posindex = posIndex();
126
127 p.getResiduals().segment(0, m_constraintDimension) =
128 m_posVec.segment(0, m_constraintDimension) -
129 fitparams.getStateVector().segment(posindex, m_constraintDimension);
130
131 for (int row = 0; row < m_constraintDimension; ++row) {
132 p.getH()(row, posindex + row) = -1;
133
134 for (int col = 0; col <= row; ++col) {
135 p.getV()(row, col) = m_covariance(row, col);
136 }
137 }
138
139 return ErrCode(ErrCode::Status::success);
140 }
141
143 {
144 ErrCode status;
145 switch (type) {
146 case Constraint::origin:
147 status |= projectOriginConstraint(fitparams, p);
148 break;
149 default:
150 status |= ParticleBase::projectConstraint(type, fitparams, p);
151 }
152 return status;
153 }
154
155 void Origin::addToConstraintList(constraintlist& list, int depth) const
156 {
157 for (auto daughter : m_daughters) {
158 daughter->addToConstraintList(list, depth - 1);
159 }
160 list.push_back(Constraint(this, Constraint::origin, depth, m_constraintDimension)) ;
161 }
162}
DataType Z() const
access variable Z (= .at(2) without boundary check)
Definition: B2Vector3.h:435
DataType X() const
access variable X (= .at(0) without boundary check)
Definition: B2Vector3.h:431
DataType Y() const
access variable Y (= .at(1) without boundary check)
Definition: B2Vector3.h:433
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:75
constraint configuration class
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, 1 > & getStateVector()
getter for the fit parameters/statevector
Definition: FitParams.h:65
Eigen::Matrix< double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > & getCovariance()
getter for the states covariance
Definition: FitParams.h:53
ErrCode projectOriginConstraint(const FitParams &fitpar, Projection &) const
the actual constraint projection
Definition: Origin.cc:123
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:110
virtual ErrCode projectConstraint(Constraint::Type, const FitParams &, Projection &) const override
the abstract projection
Definition: Origin.cc:142
ErrCode initOrigin()
init the origin "particle"
Definition: Origin.cc:54
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:18
virtual ErrCode initParticleWithMother(FitParams &fitparams) override
init particle, used if it has a mother
Definition: Origin.cc:35
virtual void addToConstraintList(constraintlist &list, int depth) const override
adds the origin as a particle to the constraint list
Definition: Origin.cc:155
virtual ErrCode initMotherlessParticle(FitParams &fitparams) override
init particle, used if it has no mother
Definition: Origin.cc:40
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
Definition: ParticleBase.cc:65
virtual ErrCode projectConstraint(Constraint::Type, const FitParams &, Projection &) const
project constraint.
std::vector< ParticleBase * > m_daughters
daughter container
Definition: ParticleBase.h:198
std::vector< Constraint > constraintlist
alias
Definition: ParticleBase.h:52
class to store the projected residuals and the corresponding jacobian as well as the covariance matri...
Definition: Projection.h:18