10 #include <analysis/dataobjects/Particle.h>
12 #include <analysis/VertexFitting/TreeFitter/InternalParticle.h>
13 #include <analysis/VertexFitting/TreeFitter/FitParams.h>
14 #include <analysis/VertexFitting/TreeFitter/HelixUtils.h>
15 #include <framework/logging/Logger.h>
16 #include <mdst/dataobjects/Track.h>
20 namespace TreeFitter {
22 inline bool sortByType(
const ParticleBase* lhs,
const ParticleBase* rhs)
24 int lhstype = lhs->type() ;
25 int rhstype = rhs->type() ;
27 if (lhstype == rhstype &&
28 lhstype == ParticleBase::TFParticleType::kRecoTrack) {
30 rc = lhs->particle()->getMomentum().Rho() > rhs->particle()->getMomentum().Rho();
31 }
else if (lhs->particle() && rhs->particle() && lhs->particle()->getNDaughters() > 0 &&
32 rhs->particle()->getNDaughters() > 0) {
33 rc = lhs->nFinalChargedCandidates() > rhs->nFinalChargedCandidates();
35 rc = lhstype < rhstype;
46 m_massconstraint(false),
47 m_beamconstraint(false),
48 m_lifetimeconstraint(false),
49 m_isconversion(false),
50 m_automatic_vertex_constraining(config.m_automatic_vertex_constraining)
57 B2ERROR(
"Trying to create an InternalParticle from NULL. This should never happen.");
92 status |= daughter->initMotherlessParticle(fitparams);
99 fitparams.
getStateVector().segment(posindex, 3) = Eigen::Matrix<double, 3, 1>::Zero(3);
101 std::vector<ParticleBase*> alldaughters;
104 std::vector<ParticleBase*> vtxdaughters;
106 vector<RecoTrack*> trkdaughters;
107 for (
auto daughter : alldaughters) {
108 if (daughter->type() == ParticleBase::TFParticleType::kRecoTrack) {
109 trkdaughters.push_back(
static_cast<RecoTrack*
>(daughter));
110 }
else if (daughter->hasPosition()
112 vtxdaughters.push_back(daughter);
118 if (trkdaughters.size() >= 2) {
129 double flt1(0), flt2(0);
139 }
else if (
false && trkdaughters.size() + vtxdaughters.size() >= 2) {
147 fitparams.
getStateVector().segment(posindex, 3) = Eigen::Matrix<double, 1, 3>::Zero(3);
152 daughter->initParticleWithMother(fitparams);
177 fitparams.
getStateVector().segment(momindex, 4) = Eigen::Matrix<double, 4, 1>::Zero(4);
180 int daumomindex = daughter->momIndex();
181 int maxrow = daughter->hasEnergy() ? 4 : 3;
183 double e2 = fitparams.
getStateVector().segment(daumomindex, maxrow).squaredNorm();
187 double mass = daughter->particle()->getPDGMass();
188 fitparams.
getStateVector()(momindex + 3) += std::sqrt(e2 + mass * mass);
191 return ErrCode(ErrCode::Status::success);
199 status |= daughter->initCovariance(fitparams);
211 p.getResiduals().segment(0, 4) = fitparams.
getStateVector().segment(momindex, 4);
213 for (
int imom = 0; imom < 4; ++imom) {
214 p.getH()(imom, momindex + imom) = 1;
218 const int daumomindex = daughter->momIndex();
219 const Eigen::Matrix<double, 1, 3> p3_vec = fitparams.
getStateVector().segment(daumomindex, 3);
222 p.getResiduals().segment(0, 3) -= p3_vec;
225 if (daughter->hasEnergy()) {
226 p.getResiduals()(3) -= fitparams.
getStateVector()(daumomindex + 3);
227 p.getH()(3, daumomindex + 3) = -1;
232 const double mass = daughter->particle()->getPDGMass();
233 const double p2 = p3_vec.squaredNorm();
234 const double energy = std::sqrt(mass * mass + p2);
235 p.getResiduals()(3) -= energy;
237 for (
unsigned i = 0; i < 3; ++i) {
239 p.getH()(3, daumomindex + i) = -1 * p3_vec(i) / energy;
245 for (
unsigned i = 0; i < 3; ++i) {
246 p.getH()(i, daumomindex + i) = -1;
249 return ErrCode(ErrCode::Status::success);
259 const Eigen::Matrix<double, 4, 1> fitMomE = fitparams.
getStateVector().segment(momindex, 4);
263 for (
int row = 0; row < 4; ++row) {
264 p.getH()(row, momindex + row) = -1;
269 return ErrCode(ErrCode::Status::success) ;
279 case Constraint::mass:
282 case Constraint::geometric:
285 case Constraint::kinematic:
288 case Constraint::beam:
349 daughter->addToConstraintList(list, depth - 1);
352 list.push_back(
Constraint(
this, Constraint::lifetime, depth, 1));
355 list.push_back(
Constraint(
this, Constraint::kinematic, depth, 4, 3));
360 list.push_back(
Constraint(
this, Constraint::geometric, depth,
dim, 3));
363 list.push_back(
Constraint(
this, Constraint::mass, depth, 1, 3));
367 list.push_back(
Constraint(
this, Constraint::beam, depth, 4, 3));
375 if (!
mother() &&
id >= 3) {++id;}
382 daughter->forceP4Sum(fitparams);
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)
Provides a type-safe way to pass members of the chargedStableSet set.
This class represents an ideal helix in perigee parameterization.
Class to store reconstructed particles.
const Track * getTrack() const
Returns the pointer to the Track object that was used to create this Particle (ParticleType == c_Trac...
int getPDGCode(void) const
Returns PDG code.
std::vector< Belle2::Particle * > getDaughters() const
Returns a vector of pointers to daughter particles.
ROOT::Math::XYZVector getMomentum() const
Returns momentum vector.
Helix getHelix() const
Conversion to framework Helix (without covariance).
const TrackFitResult * getTrackFitResultWithClosestMass(const Const::ChargedStable &requestedType) const
Return the track fit for a fit hypothesis with the closest mass.
const int m_originDimension
dimension of the origin constraint and ALL geometric gcosntraints
Eigen::Matrix< double, 4, 1 > m_beamMomE
Beam four-momentum.
const std::vector< int > m_geoConstraintListPDG
list of pdg codes to mass constrain
const std::vector< int > m_fixedToMotherVertexListPDG
list of pdg codes to mass constrain
int m_headOfTreePDG
PDG code of the head particle.
const std::vector< int > m_massConstraintListPDG
list of pdg codes to mass constrain
const int m_beamConstraintPDG
PDG code to beam constraint.
Eigen::Matrix< double, 4, 4 > m_beamCovariance
Beam Covariance.
class to manage the order of constraints and their filtering
Type
type of constraints the order of these constraints is important: it is the order in which they are ap...
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
int getDimensionOfState() const
get the states dimension
static double helixPoca(const Belle2::Helix &helix1, const Belle2::Helix &helix2, double &flt1, double &flt2, Belle2::B2Vector3D &vertex, bool parallel=false)
POCA between two tracks.
virtual void forceP4Sum(FitParams &) const override
enforce conservation of momentum sum
virtual int tauIndex() const override
tau index in fit params only if it has a mother
bool m_isconversion
is conversion
virtual std::string parname(int index) const override
name
ErrCode projectKineConstraint(const FitParams &, Projection &) const
project kinematical constraint
virtual int dim() const override
space reserved in fit params, if has mother then it has tau
bool m_beamconstraint
has beam constraint
bool m_massconstraint
has mass constraint
ErrCode projectBeamConstraint(const FitParams &, Projection &) const
project beam four momentum constraint
virtual ErrCode initCovariance(FitParams &) const override
init covariance
virtual int type() const override
type
bool m_automatic_vertex_constraining
automatically figure out if mother and particle vertex should be the same and also add geometric cons...
virtual bool hasEnergy() const override
has energy in fitparams
virtual bool hasPosition() const override
has position index
ErrCode projectConstraint(const Constraint::Type type, const FitParams &fitparams, Projection &p) const override
find out which constraint it is and project
virtual ErrCode initParticleWithMother(FitParams &fitparams) override
init particle in case it has a mother
virtual int momIndex() const override
momentum index in fit params depending on whether it has a mother
ErrCode initMomentum(FitParams &fitparams) const
init momentum of *this and daughters
virtual void addToConstraintList(constraintlist &list, int depth) const override
add to constraint list
virtual ErrCode initMotherlessParticle(FitParams &fitparams) override
init particle in case it has no mother
static bool compTrkTransverseMomentum(const RecoTrack *lhs, const RecoTrack *rhs)
compare transverse track momentum
virtual int posIndex() const override
position index in fit params
InternalParticle(Belle2::Particle *particle, const ParticleBase *mother, const ConstraintConfiguration &config, bool forceFitAll)
constructor
bool m_lifetimeconstraint
has lifetime constraint
bool m_geo_constraint
use a geo metric constraint
bool m_shares_vertex_with_mother
shares vertex with mother, that means decay vertex = productionvertex
base class for all particles
Belle2::Particle * particle() const
get basf2 particle
ErrCode initTau(FitParams &par) const
initialises tau as a length
virtual ParticleBase * addDaughter(Belle2::Particle *, const ConstraintConfiguration &config, bool forceFitAll=false)
add daughter
virtual ErrCode projectMassConstraint(const FitParams &, Projection &) const
project mass constraint abstract
const ConstraintConfiguration * m_config
has all the constraint config
virtual std::string parname(int index) const
get name of parameter i
virtual ErrCode projectConstraint(Constraint::Type, const FitParams &, Projection &) const
project constraint.
bool m_isStronglyDecayingResonance
decay length less than 1 micron
virtual ErrCode initCovariance(FitParams &) const
init covariance matrix
Belle2::Particle * m_particle
pointer to framework type
virtual ErrCode projectGeoConstraint(const FitParams &, Projection &) const
project geometrical constraint
virtual int posIndex() const
get vertex index (in statevector!)
int index() const
get index
std::vector< ParticleBase * > m_daughters
daughter container
void collectVertexDaughters(std::vector< ParticleBase * > &particles, int posindex)
get vertex daughters
std::vector< Constraint > constraintlist
alias
const ParticleBase * mother() const
getMother() / hasMother()
class to store the projected residuals and the corresponding jacobian as well as the covariance matri...
representation of all charged final states FIXME rename since this name is taken in tracking
void setFlightLength(double flt)
setter for the flight length