 |
Belle II Software
release-05-01-25
|
11 #include <analysis/dataobjects/Particle.h>
13 #include <analysis/VertexFitting/TreeFitter/InternalParticle.h>
14 #include <analysis/VertexFitting/TreeFitter/FitParams.h>
15 #include <analysis/VertexFitting/TreeFitter/HelixUtils.h>
16 #include <framework/logging/Logger.h>
17 #include <mdst/dataobjects/Track.h>
21 namespace TreeFitter {
23 inline bool sortByType(
const ParticleBase* lhs,
const ParticleBase* rhs)
25 int lhstype = lhs->type() ;
26 int rhstype = rhs->type() ;
28 if (lhstype == rhstype &&
29 lhstype == ParticleBase::TFParticleType::kRecoTrack) {
31 rc = lhs->particle()->getMomentum().Perp() > rhs->particle()->getMomentum().Perp();
32 }
else if (lhs->particle() && rhs->particle() && lhs->particle()->getNDaughters() > 0 &&
33 rhs->particle()->getNDaughters() > 0) {
34 rc = lhs->nFinalChargedCandidates() > rhs->nFinalChargedCandidates();
36 rc = lhstype < rhstype;
47 m_massconstraint(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.");
90 status |= daughter->initMotherlessParticle(fitparams);
97 fitparams.
getStateVector().segment(posindex, 3) = Eigen::Matrix<double, 3, 1>::Zero(3);
110 std::vector<ParticleBase*> alldaughters;
113 std::vector<ParticleBase*> vtxdaughters;
115 vector<RecoTrack*> trkdaughters;
116 for (
auto daughter : alldaughters) {
117 if (daughter->type() == ParticleBase::TFParticleType::kRecoTrack) {
118 trkdaughters.push_back(
static_cast<RecoTrack*
>(daughter));
119 }
else if (daughter->hasPosition()
121 vtxdaughters.push_back(daughter);
127 if (trkdaughters.size() >= 2) {
138 double flt1(0), flt2(0);
148 }
else if (
false && trkdaughters.size() + vtxdaughters.size() >= 2) {
156 fitparams.
getStateVector().segment(posindex, 3) = Eigen::Matrix<double, 1, 3>::Zero(3);
163 daughter->initParticleWithMother(fitparams);
188 fitparams.
getStateVector().segment(momindex, 4) = Eigen::Matrix<double, 4, 1>::Zero(4);
191 int daumomindex = daughter->momIndex();
192 int maxrow = daughter->hasEnergy() ? 4 : 3;
194 double e2 = fitparams.
getStateVector().segment(daumomindex, maxrow).squaredNorm();
198 double mass = daughter->pdgMass();
199 fitparams.
getStateVector()(momindex + 3) += std::sqrt(e2 + mass * mass);
202 return ErrCode(ErrCode::Status::success);
210 status |= daughter->initCovariance(fitparams);
222 p.getResiduals().segment(0, 4) = fitparams.
getStateVector().segment(momindex, 4);
224 for (
int imom = 0; imom < 4; ++imom) {
225 p.getH()(imom, momindex + imom) = 1;
229 const int daumomindex = daughter->momIndex();
230 const Eigen::Matrix<double, 1, 3> p3_vec = fitparams.
getStateVector().segment(daumomindex, 3);
233 p.getResiduals().segment(0, 3) -= p3_vec;
236 if (daughter->hasEnergy()) {
237 p.getResiduals()(3) -= fitparams.
getStateVector()(daumomindex + 3);
238 p.getH()(3, daumomindex + 3) = -1;
243 const double mass = daughter->pdgMass();
244 const double p2 = p3_vec.squaredNorm();
245 const double energy = std::sqrt(mass * mass + p2);
246 p.getResiduals()(3) -= energy;
248 for (
unsigned i = 0; i < 3; ++i) {
250 p.getH()(3, daumomindex + i) = -1 * p3_vec(i) / energy;
256 for (
unsigned i = 0; i < 3; ++i) {
257 p.getH()(i, daumomindex + i) = -1;
260 return ErrCode(ErrCode::Status::success);
270 case Constraint::mass:
273 case Constraint::geometric:
276 case Constraint::kinematic:
341 daughter->addToConstraintList(list, depth - 1);
344 list.push_back(
Constraint(
this, Constraint::lifetime, depth, 1));
347 list.push_back(
Constraint(
this, Constraint::kinematic, depth, 4, 3));
352 list.push_back(
Constraint(
this, Constraint::geometric, depth,
dim, 3));
355 list.push_back(
Constraint(
this, Constraint::mass, depth, 1, 3));
363 if (!
mother() &&
id >= 3) {++id;}
370 daughter->forceP4Sum(fitparams);
int getPDGCode(void) const
Returns PDG code.
bool m_massconstraint
has mass cosntraint
virtual ErrCode projectConstraint(Constraint::Type, const FitParams &, Projection &) const
project constraint.
virtual ErrCode projectMassConstraint(const FitParams &, Projection &) const
project mass constraint abstract
bool m_isconversion
is conversion
int getDimensionOfState() const
get the states dimension
ErrCode projectKineConstraint(const FitParams &, Projection &) const
project kinematical constraint
TVector3 getVertex() const
Returns vertex position (POCA for charged, IP for neutral FS particles)
virtual bool hasEnergy() const override
has energy in fitparams
virtual void forceP4Sum(FitParams &) const override
enforce conservation of momentum sum
virtual int type() const override
type
bool m_lifetimeconstraint
has lifetime constraint
bool m_automatic_vertex_constraining
automatically figure out if mother and particle vertex should be the same and also add geometric cons...
const std::vector< int > m_massConstraintListPDG
list of pdg codes to mass constrain
abstract errorocode be aware that the default is succes
const std::vector< int > m_geoConstraintListPDG
list of pdg codes to mass constrain
base class for all particles
virtual int tauIndex() const override
tau index in fit params only if it has a mother
Class to store and manage fitparams (statevector)
bool m_shares_vertex_with_mother
shares vertex with mother, that means decay vertex = productionvertex
int m_headOfTreePDG
PDG code of the head particle.
virtual void addToConstraintList(constraintlist &list, int depth) const override
add to constraint list
Eigen::Matrix< double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > & getStateVector()
getter for the fit parameters/statevector
ErrCode initTau(FitParams &par) const
initialises tau as a length
reprasentation of all charged final states FIXME rename since this name is taken in tracking
Type
type of constraints the order of these constraints is important: it is the order in which they are ap...
int index() const
get index
virtual ErrCode initMotherlessParticle(FitParams &fitparams) override
init particle in case it has no mother
virtual int dim() const override
space reserved in fit params, if has mother then it has tau
virtual ErrCode initParticleWithMother(FitParams &fitparams) override
init particle in case it has a mother
ErrCode projectConstraint(const Constraint::Type type, const FitParams &fitparams, Projection &p) const override
find out which constraint it is and project
std::vector< Belle2::Particle * > getDaughters() const
Returns a vector of pointers to daughter particles.
static double helixPoca(const Belle2::Helix &helix1, const Belle2::Helix &helix2, double &flt1, double &flt2, TVector3 &vertex, bool parallel=false)
POCA between two tracks.
const TrackFitResult * getTrackFitResultWithClosestMass(const Const::ChargedStable &requestedType) const
Return the track fit for a fit hypothesis with the closest mass.
class to manage the order of contraints and their filtering
const int m_originDimension
dimension of the origin constraint and ALL geometric gcosntraints
virtual ErrCode projectGeoConstraint(const FitParams &, Projection &) const
project geometrical constraint
const std::vector< int > m_fixedToMotherVertexListPDG
list of pdg codes to mass constrain
virtual std::string parname(int index) const override
name
virtual int posIndex() const
get vertex index (in statevector!)
static bool compTrkTransverseMomentum(const RecoTrack *lhs, const RecoTrack *rhs)
compare transverse track momentum
std::vector< Constraint > constraintlist
alias
TVector3 getMomentum() const
Returns momentum vector.
void setFlightLength(double flt)
setter for the flight length
const Track * getTrack() const
Returns the pointer to the Track object that was used to create this Particle (ParticleType == c_Trac...
bool m_isStronglyDecayingResonance
decay length less than 1 micron
virtual ErrCode initCovariance(FitParams &) const
init covariance matrix
virtual std::string parname(int index) const
get name of parameter i
Class to store reconstructed particles.
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
Belle2::Particle * m_particle
pointer to framework type
const ParticleBase * mother() const
getMother() / hasMother()
Provides a type-safe way to pass members of the chargedStableSet set.
bool m_geo_constraint
use a geo metric constraint
virtual bool hasPosition() const override
has position index
InternalParticle(Belle2::Particle *particle, const ParticleBase *mother, const ConstraintConfiguration &config, bool forceFitAll)
constructor
void collectVertexDaughters(std::vector< ParticleBase * > &particles, int posindex)
get vertex daughters
Helix getHelix() const
Conversion to framework Helix (without covariance).
const ConstraintConfiguration * m_config
has all the constraint config
virtual ErrCode initCovariance(FitParams &) const override
init covariance
Belle2::Particle * particle() const
get basf2 particle
class to store the projected residuals and the corresponding jacobian as well as the covariance matri...
std::vector< ParticleBase * > m_daughters
daughter container
virtual int posIndex() const override
position index in fit params
virtual ParticleBase * addDaughter(Belle2::Particle *, const ConstraintConfiguration &config, bool forceFitAll=false)
add daughter