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>
22#include <framework/geometry/B2Vector3.h>
29 m_useEnergy(useEnergy(*particle)),
32 m_momentumScalingFactor(particle->getEffectiveMomentumScale())
41 Eigen::Matrix<double, 1, 3> vertexToCluster = Eigen::Matrix<double, 1, 3>::Zero(1, 3);
42 for (
unsigned int i = 0; i < 3; ++i) {
46 const double distanceToMother = vertexToCluster.norm();
50 for (
unsigned int i = 0; i < 3; ++i) {
52 fitparams.
getStateVector()(momindex + i) = energy * vertexToCluster(i) / distanceToMother;
55 return ErrCode(ErrCode::Status::success);
60 return ErrCode(ErrCode::Status::success);
81 const double factorX = 1000;
84 Eigen::Matrix<double, 4, 4>::Identity(4, 4) * factorE;
87 Eigen::Matrix<double, 3, 3>::Identity(3, 3) * factorX;
89 return ErrCode(ErrCode::Status::success);
97 const double energy = cluster->getEnergy(clusterhypo);
105 Eigen::Matrix<double, 2, 2> covPhiTheta = Eigen::Matrix<double, 2, 2>::Zero(2, 2);
107 for (
int row = 0; row < 2; ++row) {
109 for (
int col = 0; col < 2; ++col) {
110 covPhiTheta(row, col) = cov_EPhiTheta[row + 1][col + 1];
115 const double R = cluster->getR();
116 const double theta = cluster->getPhi();
117 const double phi = cluster->getTheta();
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);
124 Eigen::Matrix<double, 2, 3> polarToCartesian = Eigen::Matrix<double, 2, 3>::Zero(2, 3);
127 polarToCartesian(0, 0) = -1. * R * st * sp;
128 polarToCartesian(0, 1) = R * st * cp;
129 polarToCartesian(0, 2) = 0;
131 polarToCartesian(1, 0) = R * ct * cp;
132 polarToCartesian(1, 1) = R * ct * sp;
133 polarToCartesian(1, 2) = -1. * R * st;
135 m_covariance.block<3, 3>(0, 0) = polarToCartesian.transpose() * covPhiTheta * polarToCartesian;
145 if ((std::abs(p_vec.X()) >= std::abs(p_vec.Y())) && (std::abs(p_vec.X()) >= std::abs(p_vec.Z()))) {
149 }
else if ((std::abs(p_vec.Y()) >= std::abs(p_vec.X())) && (std::abs(p_vec.Y()) >= std::abs(p_vec.Z()))) {
153 }
else if ((std::abs(p_vec.Z()) >= std::abs(p_vec.Y())) && (std::abs(p_vec.Z()) >= std::abs(p_vec.X()))) {
158 B2ERROR(
"Could not estimate highest momentum for photon constraint. Aborting this fit.\n px: "
159 << p_vec.X() <<
" py: " << p_vec.Y() <<
" pz: " << p_vec.Z() <<
" calculated from Ec: " <<
m_clusterPars(3));
160 return ErrCode(ErrCode::Status::photondimerror);
163 return ErrCode(ErrCode::Status::success);
186 const Eigen::Matrix<double, 1, 3> x_vertex = fitparams.
getStateVector().segment(posindex, 3);
187 const Eigen::Matrix<double, 1, 3> p_vec = fitparams.
getStateVector().segment(momindex, 3);
189 if (0 == p_vec[
m_i1]) {
190 return ErrCode(ErrCode::photondimerror);
195 const double mom = p_vec.norm();
198 Eigen::Matrix<double, 3, 1> residual3 = Eigen::Matrix<double, 3, 1>::Zero(3, 1);
204 Eigen::Matrix<double, 3, 4> P = Eigen::Matrix<double, 3, 4>::Zero(3, 4);
213 p.getResiduals().segment(0, 3) = residual3;
215 p.getV() = P *
m_covariance.selfadjointView<Eigen::Lower>() * P.transpose();
219 p.getH()(0, posindex +
m_i1) = p_vec[
m_i2] / p_vec[
m_i1];
220 p.getH()(0, posindex +
m_i2) = -1.0;
221 p.getH()(0, posindex +
m_i3) = 0;
223 p.getH()(1, posindex +
m_i1) = p_vec[
m_i3] / p_vec[
m_i1];
224 p.getH()(1, posindex +
m_i2) = 0;
225 p.getH()(1, posindex +
m_i3) = -1.0;
228 p.getH()(0, momindex +
m_i1) = p_vec[
m_i2] * elim / p_vec[
m_i1];
229 p.getH()(0, momindex +
m_i2) = -1. * elim;
230 p.getH()(0, momindex +
m_i3) = 0;
232 p.getH()(1, momindex +
m_i1) = p_vec[
m_i3] * elim / p_vec[
m_i1];
233 p.getH()(1, momindex +
m_i2) = 0;
234 p.getH()(1, momindex +
m_i3) = -1. * elim;
236 p.getH()(2, momindex +
m_i1) = -1. * p_vec[
m_i1] / mom;
237 p.getH()(2, momindex +
m_i2) = -1. * p_vec[
m_i2] / mom;
238 p.getH()(2, momindex +
m_i3) = -1. * p_vec[
m_i3] / mom;
242 return ErrCode(ErrCode::Status::success);
DataType Z() const
access variable Z (= .at(2) without boundary check)
DataType X() const
access variable X (= .at(0) without boundary check)
DataType Y() const
access variable Y (= .at(1) without boundary check)
Class to provide momentum-related information from ECLClusters.
const TMatrixDSym GetCovarianceMatrix3x3FromCluster(const ECLCluster *cluster)
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 =...
int getPDGCode(void) const
Returns PDG code.
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...
base for RecoPhoton RecoTrack
virtual int momIndex() const override
get momentum index
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
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)