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