Belle II Software  release-06-02-00
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 
19 namespace TreeFitter {
20 
22  RecoParticle(particle, mother),
23  m_dim(3),
24  m_init(false),
25  m_useEnergy(true),
26  m_clusterPars(),
27  m_covariance()
28  {
29  initParams() ;
30  }
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 energy2 = energy * energy;
44  const double pdgMass2 = ParticleBase::pdgMass() * ParticleBase::pdgMass();
45  const double absMom = -1 * std::sqrt(energy2 - pdgMass2);
46 
47  const int momindex = momIndex();
48 
49  for (unsigned int i = 0; i < 3; ++i) {
50  //px = |p| dx/|dx|
51  fitparams.getStateVector()(momindex + i) = absMom * vertexToCluster(i) / distanceToMother;
52  }
53 
54  fitparams.getStateVector()(momindex + 3) = energy ;
55 
56  return ErrCode(ErrCode::Status::success);
57  }
58 
60  {
61  return ErrCode(ErrCode::Status::success);
62  }
63 
65  {
66  const int momindex = momIndex();
67  const int posindex = mother()->posIndex();
68 
69  const double factorE = 1000 * m_covariance(3, 3);
70  const double factorX = 1000; // ~ 10cm error on initial vertex
71 
72  fitparams.getCovariance().block<4, 4>(momindex, momindex) =
73  Eigen::Matrix<double, 4, 4>::Identity(4, 4) * factorE;
74 
75  fitparams.getCovariance().block<3, 3>(posindex, posindex) =
76  Eigen::Matrix<double, 3, 3>::Identity(3, 3) * factorX;
77 
78  return ErrCode(ErrCode::Status::success);
79  }
80 
82  {
83  const Belle2::KLMCluster* cluster = particle()->getKLMCluster();
84 
85  const TVector3 cluster_pos = cluster->getClusterPosition();
86 
87  m_init = true;
88  m_covariance = Eigen::Matrix<double, 4, 4>::Zero(4, 4);
89 
90  TMatrixDSym cov7 = cluster->getError7x7();
91 
92  for (int row = 0; row < 3; ++row) {
93  for (int col = 0; col < 3; ++col) {
94  m_covariance(row, col) = cov7[row + 4][col + 4] ;
95  }
96  }
97 
101  if (0 == m_covariance(3, 3)) {m_covariance(3, 3) = .214;}
102 
103  m_clusterPars(0) = cluster_pos.X();
104  m_clusterPars(1) = cluster_pos.Y();
105  m_clusterPars(2) = cluster_pos.Z();
106  m_clusterPars(3) = sqrt(particle()->getPDGMass() * particle()->getPDGMass() + cluster->getMomentumMag() *
107  cluster->getMomentumMag());
108 
109  auto p_vec = particle()->getMomentum();
110  // find highest momentum, eliminate dim with highest mom
111  if ((std::abs(p_vec(0)) >= std::abs(p_vec(1))) && (std::abs(p_vec(0)) >= std::abs(p_vec(2)))) {
112  m_i1 = 0; m_i2 = 1; m_i3 = 2;
113  } else if ((std::abs(p_vec(1)) >= std::abs(p_vec(0))) && (std::abs(p_vec(1)) >= std::abs(p_vec(2)))) {
114  m_i1 = 1; m_i2 = 0; m_i3 = 2;
115  } else if ((std::abs(p_vec(2)) >= std::abs(p_vec(1))) && (std::abs(p_vec(2)) >= std::abs(p_vec(0)))) {
116  m_i1 = 2; m_i2 = 1; m_i3 = 0;
117  } else {
118  B2ERROR("Could not estimate highest momentum for Klong constraint. Aborting this fit.\n px: "
119  << p_vec(0) << " py: " << p_vec(1) << " pz: " << p_vec(2) << " calculated from Ec: " << m_clusterPars(3));
120  return ErrCode(ErrCode::Status::photondimerror);
121  }
122 
123  return ErrCode(ErrCode::Status::success);
124  }
125 
127  {
128  const int momindex = momIndex() ;
129  const int posindex = mother()->posIndex();
130 
131  const Eigen::Matrix<double, 1, 3> x_vertex = fitparams.getStateVector().segment(posindex, 3);
132  const Eigen::Matrix<double, 1, 3> p_vec = fitparams.getStateVector().segment(momindex, 3);
133 
134  if (0 == p_vec[m_i1]) { return ErrCode(ErrCode::Status::klongdimerror); }
135 
136  // p_vec[m_i1] must not be 0
137  const double elim = (m_clusterPars[m_i1] - x_vertex[m_i1]) / p_vec[m_i1];
138  const double mom = p_vec.norm();
139  const double energy = fitparams.getStateVector()(momindex + 3);
140 
141  // r'
142  Eigen::Matrix<double, 3, 1> residual3 = Eigen::Matrix<double, 3, 1>::Zero(3, 1);
143  residual3(0) = m_clusterPars[m_i2] - x_vertex[m_i2] - p_vec[m_i2] * elim;
144  residual3(1) = m_clusterPars[m_i3] - x_vertex[m_i3] - p_vec[m_i3] * elim;
145  residual3(2) = m_clusterPars[3] - energy;
146 
147  Eigen::Matrix<double, 3, 4> P = Eigen::Matrix<double, 3, 4>::Zero(3, 4);
148 
149  // dr'/dm | m:={xc,yc,zc,Ec} the measured quantities
150  P(0, m_i2) = 1;
151  P(0, m_i1) = - p_vec[m_i2] / p_vec[m_i1];
152 
153  P(1, m_i3) = 1;
154  P(1, m_i1) = - p_vec[m_i3] / p_vec[m_i1];
155  P(2, 3) = 1; // dE/dEc
156 
157  p.getResiduals().segment(0, 3) = residual3;
158 
159  p.getV() = P * m_covariance.selfadjointView<Eigen::Lower>() * P.transpose();
160 
161  // dr'/dm | m:={x,y,z,px,py,pz,E}
162  // x := x_vertex (decay vertex of mother)
163  p.getH()(0, posindex + m_i1) = p_vec[m_i2] / p_vec[m_i1];
164  p.getH()(0, posindex + m_i2) = -1.0;
165  p.getH()(0, posindex + m_i3) = 0;
166 
167  p.getH()(1, posindex + m_i1) = p_vec[m_i3] / p_vec[m_i1];
168  p.getH()(1, posindex + m_i2) = 0;
169  p.getH()(1, posindex + m_i3) = -1.0;
170 
171  p.getH()(0, momindex + m_i1) = p_vec[m_i2] * elim / p_vec[m_i1];
172  p.getH()(0, momindex + m_i2) = -1. * elim;
173  p.getH()(0, momindex + m_i3) = 0;
174 
175  p.getH()(1, momindex + m_i1) = p_vec[m_i3] * elim / p_vec[m_i1];;
176  p.getH()(1, momindex + m_i2) = 0;
177  p.getH()(1, momindex + m_i3) = -1. * elim;
178 
179  p.getH()(2, momindex + m_i1) = -1. * p_vec[m_i1] / mom;
180  p.getH()(2, momindex + m_i2) = -1. * p_vec[m_i2] / mom;
181  p.getH()(2, momindex + m_i3) = -1. * p_vec[m_i3] / mom;
182  p.getH()(2, momindex + 3) = -1;
183 
184  return ErrCode(ErrCode::Status::success);
185  }
186 
187 }
188 
189 
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:895
TVector3 getMomentum() const
Returns momentum vector.
Definition: Particle.h:488
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:64
ErrCode initParams()
update or init params
Definition: RecoKlong.cc:81
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:59
bool m_init
was initialized*
Definition: RecoKlong.h:67
ErrCode projectRecoConstraint(const FitParams &fitparams, Projection &p) const override
project klong constraint
Definition: RecoKlong.cc:126
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