Belle II Software prerelease-10-00-00a
RecoKlong.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 <framework/logging/Logger.h>
11
12#include <analysis/dataobjects/Particle.h>
13#include <mdst/dataobjects/KLMCluster.h>
14
15#include <analysis/VertexFitting/TreeFitter/RecoKlong.h>
16#include <analysis/VertexFitting/TreeFitter/FitParams.h>
17#include <analysis/VertexFitting/TreeFitter/ErrCode.h>
18
19namespace TreeFitter {
20
31
33 {
34 const int posindexmother = mother()->posIndex();
35
36 Eigen::Matrix<double, 1, 3> vertexToCluster = Eigen::Matrix<double, 1, 3>::Zero(1, 3);
37 for (unsigned int i = 0; i < 3; ++i) {
38 vertexToCluster(i) = m_clusterPars(i) - fitparams.getStateVector()(posindexmother + i);
39 }
40
41 const double distanceToMother = vertexToCluster.norm();
42 const double energy = m_clusterPars(3);
43 const double pdgMass = particle()->getPDGMass();
44 const double absMom = std::sqrt(energy * energy - pdgMass * pdgMass);
45
46 const int momindex = momIndex();
47
48 for (unsigned int i = 0; i < 3; ++i) {
49 //px = |p| dx/|dx|
50 fitparams.getStateVector()(momindex + i) = absMom * vertexToCluster(i) / distanceToMother;
51 }
52
53 return ErrCode(ErrCode::Status::success);
54 }
55
57 {
58 return ErrCode(ErrCode::Status::success);
59 }
60
62 {
63 const int momindex = momIndex();
64 const int posindex = mother()->posIndex();
65
66 const double factorE = 1000 * m_covariance(3, 3);
67 const double factorX = 1000; // ~ 10cm error on initial vertex
68
69 fitparams.getCovariance().block<4, 4>(momindex, momindex) =
70 Eigen::Matrix<double, 4, 4>::Identity(4, 4) * factorE;
71
72 fitparams.getCovariance().block<3, 3>(posindex, posindex) =
73 Eigen::Matrix<double, 3, 3>::Identity(3, 3) * factorX;
74
75 return ErrCode(ErrCode::Status::success);
76 }
77
79 {
80 const Belle2::KLMCluster* cluster = particle()->getKLMCluster();
81
82 const ROOT::Math::XYZVector cluster_pos = cluster->getClusterPosition();
83
84 m_init = true;
85 m_covariance = Eigen::Matrix<double, 4, 4>::Zero(4, 4);
86
87 TMatrixDSym cov7 = cluster->getError7x7();
88
89 for (int row = 0; row < 3; ++row) {
90 for (int col = 0; col < 3; ++col) {
91 m_covariance(row, col) = cov7[row + 4][col + 4] ;
92 }
93 }
94
98 if (0 == m_covariance(3, 3)) {m_covariance(3, 3) = .214;}
99
100 m_clusterPars(0) = cluster_pos.X();
101 m_clusterPars(1) = cluster_pos.Y();
102 m_clusterPars(2) = cluster_pos.Z();
103 m_clusterPars(3) = sqrt(particle()->getPDGMass() * particle()->getPDGMass() +
104 cluster->getMomentumMag() * cluster->getMomentumMag());
105
106 auto p_vec = particle()->getMomentum();
107 // find highest momentum, eliminate dim with highest mom
108 if ((std::abs(p_vec.X()) >= std::abs(p_vec.Y())) && (std::abs(p_vec.X()) >= std::abs(p_vec.Z()))) {
109 m_i1 = 0; m_i2 = 1; m_i3 = 2;
110 } else if ((std::abs(p_vec.Y()) >= std::abs(p_vec.X())) && (std::abs(p_vec.Y()) >= std::abs(p_vec.Z()))) {
111 m_i1 = 1; m_i2 = 0; m_i3 = 2;
112 } else if ((std::abs(p_vec.Z()) >= std::abs(p_vec.Y())) && (std::abs(p_vec.Z()) >= std::abs(p_vec.X()))) {
113 m_i1 = 2; m_i2 = 1; m_i3 = 0;
114 } else {
115 B2ERROR("Could not estimate highest momentum for Klong constraint. Aborting this fit.\n px: "
116 << p_vec.X() << " py: " << p_vec.Y() << " pz: " << p_vec.Z() << " calculated from Ec: " << m_clusterPars(3));
117 return ErrCode(ErrCode::Status::photondimerror);
118 }
119
120 return ErrCode(ErrCode::Status::success);
121 }
122
124 {
125 const int momindex = momIndex() ;
126 const int posindex = mother()->posIndex();
127
128 const Eigen::Matrix<double, 1, 3> x_vertex = fitparams.getStateVector().segment(posindex, 3);
129 const Eigen::Matrix<double, 1, 3> p_vec = fitparams.getStateVector().segment(momindex, 3);
130
131 if (0 == p_vec[m_i1]) { return ErrCode(ErrCode::Status::klongdimerror); }
132
133 // p_vec[m_i1] must not be 0
134 const double elim = (m_clusterPars[m_i1] - x_vertex[m_i1]) / p_vec[m_i1];
135 const double mom = p_vec.norm();
136 const double pdgMass = particle()->getPDGMass();
137 const double energy = std::sqrt(mom * mom + pdgMass * pdgMass);
138
139 // r'
140 Eigen::Matrix<double, 3, 1> residual3 = Eigen::Matrix<double, 3, 1>::Zero(3, 1);
141 residual3(0) = m_clusterPars[m_i2] - x_vertex[m_i2] - p_vec[m_i2] * elim;
142 residual3(1) = m_clusterPars[m_i3] - x_vertex[m_i3] - p_vec[m_i3] * elim;
143 residual3(2) = m_clusterPars[3] - energy;
144
145 Eigen::Matrix<double, 3, 4> P = Eigen::Matrix<double, 3, 4>::Zero(3, 4);
146
147 // dr'/dm | m:={xc,yc,zc,Ec} the measured quantities
148 P(0, m_i2) = 1;
149 P(0, m_i1) = - p_vec[m_i2] / p_vec[m_i1];
150
151 P(1, m_i3) = 1;
152 P(1, m_i1) = - p_vec[m_i3] / p_vec[m_i1];
153 P(2, 3) = 1; // dE/dEc
154
155 p.getResiduals().segment(0, 3) = residual3;
156
157 p.getV() = P * m_covariance.selfadjointView<Eigen::Lower>() * P.transpose();
158
159 // dr'/dm | m:={x,y,z,px,py,pz,E}
160 // x := x_vertex (decay vertex of mother)
161 p.getH()(0, posindex + m_i1) = p_vec[m_i2] / p_vec[m_i1];
162 p.getH()(0, posindex + m_i2) = -1.0;
163 p.getH()(0, posindex + m_i3) = 0;
164
165 p.getH()(1, posindex + m_i1) = p_vec[m_i3] / p_vec[m_i1];
166 p.getH()(1, posindex + m_i2) = 0;
167 p.getH()(1, posindex + m_i3) = -1.0;
168
169 p.getH()(0, momindex + m_i1) = p_vec[m_i2] * elim / p_vec[m_i1];
170 p.getH()(0, momindex + m_i2) = -1. * elim;
171 p.getH()(0, momindex + m_i3) = 0;
172
173 p.getH()(1, momindex + m_i1) = p_vec[m_i3] * elim / p_vec[m_i1];;
174 p.getH()(1, momindex + m_i2) = 0;
175 p.getH()(1, momindex + m_i3) = -1. * elim;
176
177 p.getH()(2, momindex + m_i1) = -1. * p_vec[m_i1] / mom;
178 p.getH()(2, momindex + m_i2) = -1. * p_vec[m_i2] / mom;
179 p.getH()(2, momindex + m_i3) = -1. * p_vec[m_i3] / mom;
180
181 return ErrCode(ErrCode::Status::success);
182 }
183
184}
185
186
KLM cluster data.
Definition KLMCluster.h:29
Class to store reconstructed particles.
Definition Particle.h:76
const KLMCluster * getKLMCluster() const
Returns the pointer to the KLMCluster object that was used to create this Particle (ParticleType == c...
Definition Particle.cc:1011
double getPDGMass(void) const
Returns uncertainty on the invariant mass (requires valid momentum error matrix)
Definition Particle.cc:635
ROOT::Math::XYZVector getMomentum() const
Returns momentum vector.
Definition Particle.h:580
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
base class for all particles
Belle2::Particle * particle() const
get basf2 particle
virtual int posIndex() const
get vertex index (in statevector!)
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
bool m_useEnergy
has energy ins statevector
Definition RecoKlong.h:70
Eigen::Matrix< double, 4, 4 > m_covariance
covariance (x_c,y_c,z_c,E_c) of measured pars
Definition RecoKlong.h:76
ErrCode initCovariance(FitParams &fitparams) const override
init covariance
Definition RecoKlong.cc:61
ErrCode initParams()
update or init params
Definition RecoKlong.cc:78
const int m_dim
dimension of residuals and 'width' of H
Definition RecoKlong.h:64
int m_i3
another random index
Definition RecoKlong.h:83
int m_i1
index with the highest momentum.
Definition RecoKlong.h:79
virtual ErrCode initParticleWithMother(FitParams &fitparams) override
init particle with mother
Definition RecoKlong.cc:32
int m_i2
random index
Definition RecoKlong.h:81
RecoKlong(Belle2::Particle *bc, const ParticleBase *mother)
constructor
Definition RecoKlong.cc:21
virtual ErrCode initMotherlessParticle(FitParams &fitparams) override
init particle without mother
Definition RecoKlong.cc:56
bool m_init
was initialized*
Definition RecoKlong.h:67
ErrCode projectRecoConstraint(const FitParams &fitparams, Projection &p) const override
project klong constraint
Definition RecoKlong.cc:123
Eigen::Matrix< double, 1, 4 > m_clusterPars
constrains measured params (x_c, y_c, z_c, E_c)
Definition RecoKlong.h:73
virtual int momIndex() const override
get momentum index
RecoParticle(Belle2::Particle *bc, const ParticleBase *mother)
constructor