10#include <framework/logging/Logger.h>
12#include <analysis/dataobjects/Particle.h>
13#include <mdst/dataobjects/ECLCluster.h>
15#include <analysis/ClusterUtility/ClusterUtils.h>
17#include <analysis/VertexFitting/TreeFitter/RecoPhoton.h>
18#include <analysis/VertexFitting/TreeFitter/FitParams.h>
19#include <analysis/VertexFitting/TreeFitter/ErrCode.h>
21#include <framework/gearbox/Const.h>
40 Eigen::Matrix<double, 1, 3> vertexToCluster = Eigen::Matrix<double, 1, 3>::Zero(1, 3);
41 for (
unsigned int i = 0; i < 3; ++i) {
45 const double distanceToMother = vertexToCluster.norm();
49 for (
unsigned int i = 0; i < 3; ++i) {
51 fitparams.
getStateVector()(momindex + i) = energy * vertexToCluster(i) / distanceToMother;
54 return ErrCode(ErrCode::Status::success);
59 return ErrCode(ErrCode::Status::success);
65 const int pdg =
particle.getPDGCode();
80 const double factorX = 1000;
83 Eigen::Matrix<double, 4, 4>::Identity(4, 4) * factorE;
86 Eigen::Matrix<double, 3, 3>::Identity(3, 3) * factorX;
88 return ErrCode(ErrCode::Status::success);
95 const ROOT::Math::XYZVector centroid = cluster->getClusterPosition();
96 const double energy = cluster->getEnergy(clusterhypo);
104 Eigen::Matrix<double, 2, 2> covPhiTheta = Eigen::Matrix<double, 2, 2>::Zero(2, 2);
106 for (
int row = 0; row < 2; ++row) {
108 for (
int col = 0; col < 2; ++col) {
109 covPhiTheta(row, col) = cov_EPhiTheta[row + 1][col + 1];
114 const double R = cluster->getR();
115 const double theta = cluster->getPhi();
116 const double phi = cluster->getTheta();
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);
123 Eigen::Matrix<double, 2, 3> polarToCartesian = Eigen::Matrix<double, 2, 3>::Zero(2, 3);
126 polarToCartesian(0, 0) = -1. *
R * st * sp;
127 polarToCartesian(0, 1) =
R * st * cp;
128 polarToCartesian(0, 2) = 0;
130 polarToCartesian(1, 0) =
R * ct * cp;
131 polarToCartesian(1, 1) =
R * ct * sp;
132 polarToCartesian(1, 2) = -1. *
R * st;
134 m_covariance.block<3, 3>(0, 0) = polarToCartesian.transpose() * covPhiTheta * polarToCartesian;
144 if ((std::abs(p_vec.X()) >= std::abs(p_vec.Y())) && (std::abs(p_vec.X()) >= std::abs(p_vec.Z()))) {
148 }
else if ((std::abs(p_vec.Y()) >= std::abs(p_vec.X())) && (std::abs(p_vec.Y()) >= std::abs(p_vec.Z()))) {
152 }
else if ((std::abs(p_vec.Z()) >= std::abs(p_vec.Y())) && (std::abs(p_vec.Z()) >= std::abs(p_vec.X()))) {
157 B2ERROR(
"Could not estimate highest momentum for photon constraint. Aborting this fit.\n px: "
158 << p_vec.X() <<
" py: " << p_vec.Y() <<
" pz: " << p_vec.Z() <<
" calculated from Ec: " <<
m_clusterPars(3));
159 return ErrCode(ErrCode::Status::photondimerror);
162 return ErrCode(ErrCode::Status::success);
185 const Eigen::Matrix<double, 1, 3> x_vertex = fitparams.
getStateVector().segment(posindex, 3);
186 const Eigen::Matrix<double, 1, 3> p_vec = fitparams.
getStateVector().segment(momindex, 3);
188 if (0 == p_vec[
m_i1]) {
189 return ErrCode(ErrCode::photondimerror);
194 const double mom = p_vec.norm();
197 Eigen::Matrix<double, 3, 1> residual3 = Eigen::Matrix<double, 3, 1>::Zero(3, 1);
203 Eigen::Matrix<double, 3, 4> P = Eigen::Matrix<double, 3, 4>::Zero(3, 4);
212 p.getResiduals().segment(0, 3) = residual3;
214 p.getV() = P *
m_covariance.selfadjointView<Eigen::Lower>() * P.transpose();
218 p.getH()(0, posindex +
m_i1) = p_vec[
m_i2] / p_vec[
m_i1];
219 p.getH()(0, posindex +
m_i2) = -1.0;
220 p.getH()(0, posindex +
m_i3) = 0;
222 p.getH()(1, posindex +
m_i1) = p_vec[
m_i3] / p_vec[
m_i1];
223 p.getH()(1, posindex +
m_i2) = 0;
224 p.getH()(1, posindex +
m_i3) = -1.0;
227 p.getH()(0, momindex +
m_i1) = p_vec[
m_i2] * elim / p_vec[
m_i1];
228 p.getH()(0, momindex +
m_i2) = -1. * elim;
229 p.getH()(0, momindex +
m_i3) = 0;
231 p.getH()(1, momindex +
m_i1) = p_vec[
m_i3] * elim / p_vec[
m_i1];
232 p.getH()(1, momindex +
m_i2) = 0;
233 p.getH()(1, momindex +
m_i3) = -1. * elim;
235 p.getH()(2, momindex +
m_i1) = -1. * p_vec[
m_i1] / mom;
236 p.getH()(2, momindex +
m_i2) = -1. * p_vec[
m_i2] / mom;
237 p.getH()(2, momindex +
m_i3) = -1. * p_vec[
m_i3] / mom;
241 return ErrCode(ErrCode::Status::success);
Class to provide momentum-related information from ECLClusters.
const TMatrixDSym GetCovarianceMatrix3x3FromCluster(const ECLCluster *cluster, int particleHypo=Const::photon.getPDGCode())
Returns 3x3 covariance matrix (E, theta, phi)
The ParticleType class for identifying different particle types.
static const ParticleType pi0
neutral pion particle
static const ParticleType photon
photon particle
EHypothesisBit
The hypothesis bits for this ECLCluster (Connected region (CR) is split using this hypothesis.
Class to store reconstructed particles.
const ECLCluster * getECLCluster() const
Returns the pointer to the ECLCluster object that was used to create this Particle (if ParticleType =...
ROOT::Math::XYZVector getMomentum() const
Returns momentum vector.
ECLCluster::EHypothesisBit getECLClusterEHypothesisBit() const
Returns the ECLCluster EHypothesisBit for this Particle.
abstract errorocode be aware that the default is success
Class to store and manage fitparams (statevector)
Eigen::Matrix< double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > & getStateVector()
getter for the fit parameters/statevector
Eigen::Matrix< double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > & getCovariance()
getter for the states covariance
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...
virtual int momIndex() const override
get momentum index
RecoParticle(Belle2::Particle *bc, const ParticleBase *mother)
constructor
bool m_useEnergy
has energy ins statevector
Eigen::Matrix< double, 4, 4 > m_covariance
covariance (x_c,y_c,z_c,E_c) of measured pars
ErrCode initCovariance(FitParams &fitparams) const override
init covariance
RecoPhoton(Belle2::Particle *bc, const ParticleBase *mother)
constructor
ErrCode initParams()
update or init params
const float m_momentumScalingFactor
scale the momentum / energy by this correction factor
const int m_dim
dimension of residuals and 'width' of H
int m_i3
another random index
int m_i1
index with the highest momentum.
virtual ErrCode initParticleWithMother(FitParams &fitparams) override
init particle with mother
static bool useEnergy(const Belle2::Particle &cand)
has energy in fit params?
int m_i2
random other index
virtual ErrCode initMotherlessParticle(FitParams &fitparams) override
init particle without mother
bool m_init
was initialized*
ErrCode projectRecoConstraint(const FitParams &fitparams, Projection &p) const override
project photon constraint
Eigen::Matrix< double, 1, 4 > m_clusterPars
constrains measured params (x_c, y_c, z_c, E_c)