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