Belle II Software  release-06-00-14
RecoPhoton.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/ECLCluster.h>
14 
15 #include <analysis/ClusterUtility/ClusterUtils.h>
16 
17 #include <analysis/VertexFitting/TreeFitter/RecoPhoton.h>
18 #include <analysis/VertexFitting/TreeFitter/FitParams.h>
19 #include <analysis/VertexFitting/TreeFitter/ErrCode.h>
20 
21 #include <framework/gearbox/Const.h>
22 
23 namespace TreeFitter {
24 
26  RecoParticle(particle, mother),
27  m_dim(3),
28  m_init(false),
29  m_useEnergy(useEnergy(*particle)),
30  m_clusterPars(),
31  m_covariance(),
32  m_momentumScalingFactor(particle->getMomentumScalingFactor())
33  {
34  initParams() ;
35  }
36 
38  {
39  const int posindexmother = mother()->posIndex();
40 
41  Eigen::Matrix<double, 1, 3> vertexToCluster = Eigen::Matrix<double, 1, 3>::Zero(1, 3);
42  for (unsigned int i = 0; i < 3; ++i) {
43  vertexToCluster(i) = m_clusterPars(i) - fitparams.getStateVector()(posindexmother + i);
44  }
45 
46  const double distanceToMother = vertexToCluster.norm();
47  const double energy = m_momentumScalingFactor * m_clusterPars(3); // apply scaling factor to correct energy bias
48  const int momindex = momIndex();
49 
50  for (unsigned int i = 0; i < 3; ++i) {
51  //px = E dx/|dx|
52  fitparams.getStateVector()(momindex + i) = energy * vertexToCluster(i) / distanceToMother;
53  }
54 
55  return ErrCode(ErrCode::Status::success);
56  }
57 
59  {
60  return ErrCode(ErrCode::Status::success);
61  }
62 
64  {
65  bool rc = true ;
66  const int pdg = particle.getPDGCode();
67  if (pdg &&
70  rc = false ;
71  }
72  return rc ;
73  }
74 
76  {
77  const int momindex = momIndex();
78  const int posindex = mother()->posIndex();
79 
80  const double factorE = 1000 * m_covariance(3, 3);
81  const double factorX = 1000; // ~ 10cm error on initial vertex
82 
83  fitparams.getCovariance().block<4, 4>(momindex, momindex) =
84  Eigen::Matrix<double, 4, 4>::Identity(4, 4) * factorE;
85 
86  fitparams.getCovariance().block<3, 3>(posindex, posindex) =
87  Eigen::Matrix<double, 3, 3>::Identity(3, 3) * factorX;
88 
89  return ErrCode(ErrCode::Status::success);
90  }
91 
93  {
94  const Belle2::ECLCluster* cluster = particle()->getECLCluster();
96  const TVector3 centroid = cluster->getClusterPosition();
97  const double energy = cluster->getEnergy(clusterhypo);
98 
99  m_init = true;
100  m_covariance = Eigen::Matrix<double, 4, 4>::Zero(4, 4);
102 
103  TMatrixDSym cov_EPhiTheta = cluster->getCovarianceMatrix3x3();
104 
105  Eigen::Matrix<double, 2, 2> covPhiTheta = Eigen::Matrix<double, 2, 2>::Zero(2, 2);
106 
107  for (int row = 0; row < 2; ++row) { // we go through all elements here instead of selfadjoint view later
108  for (int col = 0; col < 2; ++col) {
109  covPhiTheta(row, col) = cov_EPhiTheta[row + 1][col + 1];
110  }
111  }
112 
113  // the in going x-E correlations are 0 so we don't fill them
114  const double R = cluster->getR();
115  const double theta = cluster->getPhi();
116  const double phi = cluster->getTheta();
117 
118  const double st = std::sin(theta);
119  const double ct = std::cos(theta);
120  const double sp = std::sin(phi);
121  const double cp = std::cos(phi);
122 
123  Eigen::Matrix<double, 2, 3> polarToCartesian = Eigen::Matrix<double, 2, 3>::Zero(2, 3);
124 
125  // polarToCartesian({phi,theta} -> {x,y,z} )
126  polarToCartesian(0, 0) = -1. * R * st * sp;// dx/dphi
127  polarToCartesian(0, 1) = R * st * cp; // dy/dphi
128  polarToCartesian(0, 2) = 0 ; // dz/dphi
129 
130  polarToCartesian(1, 0) = R * ct * cp; // dx/dtheta
131  polarToCartesian(1, 1) = R * ct * sp; // dy/dtheta
132  polarToCartesian(1, 2) = -1. * R * st ; // dz/dtheta
133 
134  m_covariance.block<3, 3>(0, 0) = polarToCartesian.transpose() * covPhiTheta * polarToCartesian;
135 
136  m_covariance(3, 3) = cov_EPhiTheta[0][0];
137  m_clusterPars(0) = centroid.X();
138  m_clusterPars(1) = centroid.Y();
139  m_clusterPars(2) = centroid.Z();
140  m_clusterPars(3) = energy;
141 
142 
143  auto p_vec = particle()->getMomentum();
144  // find highest momentum, eliminate dim with highest mom
145  if ((std::abs(p_vec(0)) >= std::abs(p_vec(1))) && (std::abs(p_vec(0)) >= std::abs(p_vec(2)))) {
146  m_i1 = 0; m_i2 = 1; m_i3 = 2;
147  } else if ((std::abs(p_vec(1)) >= std::abs(p_vec(0))) && (std::abs(p_vec(1)) >= std::abs(p_vec(2)))) {
148  m_i1 = 1; m_i2 = 0; m_i3 = 2;
149  } else if ((std::abs(p_vec(2)) >= std::abs(p_vec(1))) && (std::abs(p_vec(2)) >= std::abs(p_vec(0)))) {
150  m_i1 = 2; m_i2 = 1; m_i3 = 0;
151  } else {
152  B2ERROR("Could not estimate highest momentum for photon constraint. Aborting this fit.\n px: "
153  << p_vec(0) << " py: " << p_vec(1) << " pz: " << p_vec(2) << " calculated from Ec: " << m_clusterPars(3));
154  return ErrCode(ErrCode::Status::photondimerror);
155  }
156 
157 
158  return ErrCode(ErrCode::Status::success);
159  }
160 
162  {
163  const int momindex = momIndex() ;
164  const int posindex = mother()->posIndex();
181  const Eigen::Matrix<double, 1, 3> x_vertex = fitparams.getStateVector().segment(posindex, 3);
182  const Eigen::Matrix<double, 1, 3> p_vec = fitparams.getStateVector().segment(momindex, 3);
183 
184  if (0 == p_vec[m_i1]) { return ErrCode(ErrCode::photondimerror); }
185 
186  // p_vec[m_i1] must not be 0
187  const double elim = (m_clusterPars[m_i1] - x_vertex[m_i1]) / p_vec[m_i1];
188  const double mom = p_vec.norm();
189 
190  // r'
191  Eigen::Matrix<double, 3, 1> residual3 = Eigen::Matrix<double, 3, 1>::Zero(3, 1);
192  residual3(0) = m_clusterPars[m_i2] - x_vertex[m_i2] - p_vec[m_i2] * elim;
193  residual3(1) = m_clusterPars[m_i3] - x_vertex[m_i3] - p_vec[m_i3] * elim;
194  residual3(2) = m_momentumScalingFactor * m_clusterPars[3] - mom; // scale measured energy by scaling factor
195 
196  // dr'/dm | m:={xc,yc,zc,Ec} the measured quantities
197  Eigen::Matrix<double, 3, 4> P = Eigen::Matrix<double, 3, 4>::Zero(3, 4);
198  // deriving by the cluster pars
199  P(0, m_i2) = 1;
200  P(0, m_i1) = - p_vec[m_i2] / p_vec[m_i1];
201 
202  P(1, m_i3) = 1;
203  P(1, m_i1) = - p_vec[m_i3] / p_vec[m_i1];
204  P(2, 3) = 1; // dE/dEc
205 
206  p.getResiduals().segment(0, 3) = residual3;
207 
208  p.getV() = P * m_covariance.selfadjointView<Eigen::Lower>() * P.transpose();
209 
210  // dr'/dm | m:={x,y,z,px,py,pz,E}
211  // x := x_vertex (decay vertex of mother)
212  p.getH()(0, posindex + m_i1) = p_vec[m_i2] / p_vec[m_i1];
213  p.getH()(0, posindex + m_i2) = -1.0;
214  p.getH()(0, posindex + m_i3) = 0;
215 
216  p.getH()(1, posindex + m_i1) = p_vec[m_i3] / p_vec[m_i1];
217  p.getH()(1, posindex + m_i2) = 0;
218  p.getH()(1, posindex + m_i3) = -1.0;
219 
220  // elim already divided by p_vec[m_i1]
221  p.getH()(0, momindex + m_i1) = p_vec[m_i2] * elim / p_vec[m_i1];
222  p.getH()(0, momindex + m_i2) = -1. * elim;
223  p.getH()(0, momindex + m_i3) = 0;
224 
225  p.getH()(1, momindex + m_i1) = p_vec[m_i3] * elim / p_vec[m_i1];
226  p.getH()(1, momindex + m_i2) = 0;
227  p.getH()(1, momindex + m_i3) = -1. * elim;
228 
229  p.getH()(2, momindex + m_i1) = -1. * p_vec[m_i1] / mom;
230  p.getH()(2, momindex + m_i2) = -1. * p_vec[m_i2] / mom;
231  p.getH()(2, momindex + m_i3) = -1. * p_vec[m_i3] / mom;
232  // the photon does not store an energy in the state vector
233  // so no p.getH()(2, momindex + 3) here
234 
235  return ErrCode(ErrCode::Status::success);
236  }
237 
238 }
239 
240 
Class to provide momentum-related information from ECLClusters.
Definition: ClusterUtils.h:34
The ParticleType class for identifying different particle types.
Definition: Const.h:289
static const ParticleType pi0
neutral pion particle
Definition: Const.h:555
static const ParticleType photon
photon particle
Definition: Const.h:554
ECL cluster data.
Definition: ECLCluster.h:27
EHypothesisBit
The hypothesis bits for this ECLCluster (Connected region (CR) is split using this hypothesis.
Definition: ECLCluster.h:31
Class to store reconstructed particles.
Definition: Particle.h:74
const ECLCluster * getECLCluster() const
Returns the pointer to the ECLCluster object that was used to create this Particle (if ParticleType =...
Definition: Particle.cc:860
TVector3 getMomentum() const
Returns momentum vector.
Definition: Particle.h:488
int getPDGCode(void) const
Returns PDG code.
Definition: Particle.h:392
ECLCluster::EHypothesisBit getECLClusterEHypothesisBit() const
Returns the ECLCluster EHypothesisBit for this Particle.
Definition: Particle.h:901
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()
class to store the projected residuals and the corresponding jacobian as well as the covariance matri...
Definition: Projection.h:18
base for RecoPhoton RecoTrack
Definition: RecoParticle.h:16
virtual int momIndex() const override
get momentum index
Definition: RecoParticle.h:42
Eigen::Matrix< double, 4, 4 > m_covariance
covariance (x_c,y_c,z_c,E_c) of measured pars
Definition: RecoPhoton.h:76
ErrCode initCovariance(FitParams &fitparams) const override
init covariance
Definition: RecoPhoton.cc:75
RecoPhoton(Belle2::Particle *bc, const ParticleBase *mother)
constructor
Definition: RecoPhoton.cc:25
ErrCode initParams()
update or init params
Definition: RecoPhoton.cc:92
const float m_momentumScalingFactor
scale the momentum / energy by this correction factor
Definition: RecoPhoton.h:86
int m_i3
another random index
Definition: RecoPhoton.h:83
int m_i1
index with the highest momentum.
Definition: RecoPhoton.h:79
virtual ErrCode initParticleWithMother(FitParams &fitparams) override
init particle with mother
Definition: RecoPhoton.cc:37
static bool useEnergy(const Belle2::Particle &cand)
has energy in fit params?
Definition: RecoPhoton.cc:63
int m_i2
random other index
Definition: RecoPhoton.h:81
virtual ErrCode initMotherlessParticle(FitParams &fitparams) override
init particle without mother
Definition: RecoPhoton.cc:58
bool m_init
was initialized*
Definition: RecoPhoton.h:67
ErrCode projectRecoConstraint(const FitParams &fitparams, Projection &p) const override
project photon constraint
Definition: RecoPhoton.cc:161
Eigen::Matrix< double, 1, 4 > m_clusterPars
constrains measured params (x_c, y_c, z_c, E_c)
Definition: RecoPhoton.h:73