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/V0.h> 
   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;
 
   53      for (
auto daughter : 
particle->getDaughters()) {
 
   57      B2ERROR(
"Trying to create an InternalParticle from NULL. This should never happen.");
 
   60    m_massconstraint = std::find(config.m_massConstraintListPDG.begin(), config.m_massConstraintListPDG.end(),
 
   61                                 std::abs(
m_particle->getPDGCode())) != config.m_massConstraintListPDG.end()
 
   62                       or 
m_particle->hasExtraInfo(
"treeFitterMassConstraint");
 
   70                                               config.m_fixedToMotherVertexListPDG.end(),
 
   71                                               std::abs(
m_particle->getPDGCode())) != config.m_fixedToMotherVertexListPDG.end() && this->
mother();
 
   75                                   config.m_geoConstraintListPDG.end(),
 
 
   93      status |= daughter->initMotherlessParticle(fitparams);
 
  100      fitparams.
getStateVector().segment(posindex, 3) = Eigen::Matrix<double, 3, 1>::Zero(3);
 
  102      std::vector<ParticleBase*> alldaughters;
 
  105      std::vector<ParticleBase*> vtxdaughters;
 
  107      vector<RecoTrack*> trkdaughters;
 
  108      for (
auto daughter : alldaughters) {
 
  109        if (daughter->type() == ParticleBase::TFParticleType::kRecoTrack) {
 
  110          trkdaughters.push_back(
static_cast<RecoTrack*
>(daughter));
 
  111        } 
else if (daughter->hasPosition()
 
  113          vtxdaughters.push_back(daughter);
 
  117      if (trkdaughters.size() >= 2) {
 
  120        auto dummy_vertex = ROOT::Math::XYZVector(0, 0, 0);
 
  122        bool initWithV0 = 
false;
 
  123        if (v0 && v0->getFittedVertexPosition() != dummy_vertex) {
 
  127          auto recotrack_dau1 = std::find_if(trkdaughters.begin(), trkdaughters.end(),
 
  128          [&part_dau1](
RecoTrack * rt) { return rt->particle()->getMdstSource() == part_dau1->getMdstSource(); });
 
  129          auto recotrack_dau2 = std::find_if(trkdaughters.begin(), trkdaughters.end(),
 
  130          [&part_dau2](
RecoTrack * rt) { return rt->particle()->getMdstSource() == part_dau2->getMdstSource(); });
 
  132          if (recotrack_dau1 == trkdaughters.end() || recotrack_dau2 == trkdaughters.end()) {
 
  133            B2WARNING(
"V0 daughter particles do not match with RecoTracks.");
 
  135            double X_V0(v0->getFittedVertexX()), Y_V0(v0->getFittedVertexY()), Z_V0(v0->getFittedVertexZ());
 
  140            Belle2::Helix helix1 = v0->getTrackFitResults().first->getHelix();
 
  141            Belle2::Helix helix2 = v0->getTrackFitResults().second->getHelix();
 
  159          double flt1(0), flt2(0);
 
  160          ROOT::Math::XYZVector v;
 
  171      } 
else if (
false && trkdaughters.size() + vtxdaughters.size() >= 2)  {
 
  179        fitparams.
getStateVector().segment(posindex, 3) = Eigen::Matrix<double, 1, 3>::Zero(3);
 
  184      daughter->initParticleWithMother(fitparams);
 
 
  209    fitparams.
getStateVector().segment(momindex, 4) = Eigen::Matrix<double, 4, 1>::Zero(4);
 
  212      int daumomindex = daughter->momIndex();
 
  213      int maxrow = daughter->hasEnergy() ? 4 : 3;
 
  215      double e2 = fitparams.
getStateVector().segment(daumomindex, maxrow).squaredNorm();
 
  220        if (daughter->particle()->hasExtraInfo(
"treeFitterMassConstraintValue")) {
 
  221          mass = daughter->particle()->getExtraInfo(
"treeFitterMassConstraintValue");
 
  222        } 
else mass = daughter->particle()->getPDGMass();
 
  223        fitparams.
getStateVector()(momindex + 3) += std::sqrt(e2 + mass * mass);
 
  226    return ErrCode(ErrCode::Status::success);
 
 
  234      status |= daughter->initCovariance(fitparams);
 
 
  246    p.getResiduals().segment(0, 4) = fitparams.
getStateVector().segment(momindex, 4);
 
  248    for (
int imom = 0; imom < 4; ++imom) {
 
  249      p.getH()(imom, momindex + imom) = 1;
 
  253      const int daumomindex = daughter->momIndex();
 
  254      const Eigen::Matrix<double, 1, 3> p3_vec = fitparams.
getStateVector().segment(daumomindex, 3);
 
  257      p.getResiduals().segment(0, 3) -= p3_vec;
 
  260      if (daughter->hasEnergy()) {
 
  261        p.getResiduals()(3) -= fitparams.
getStateVector()(daumomindex + 3);
 
  262        p.getH()(3, daumomindex + 3) = -1; 
 
  268        if (daughter->particle()->hasExtraInfo(
"treeFitterMassConstraintValue")) {
 
  269          mass = daughter->particle()->getExtraInfo(
"treeFitterMassConstraintValue");
 
  270        } 
else mass = daughter->particle()->getPDGMass();
 
  271        const double p2 = p3_vec.squaredNorm();
 
  272        const double energy = std::sqrt(mass * mass + p2);
 
  273        p.getResiduals()(3) -= energy;
 
  275        for (
unsigned i = 0; i < 3; ++i) {
 
  277          p.getH()(3, daumomindex + i) = -1 * p3_vec(i) / energy;
 
  283      for (
unsigned i = 0; i < 3; ++i) {
 
  284        p.getH()(i, daumomindex + i) = -1;
 
  287    return ErrCode(ErrCode::Status::success);
 
 
  297    const Eigen::Matrix<double, 4, 1> fitMomE = fitparams.
getStateVector().segment(momindex, 4);
 
  299    p.getResiduals() = 
m_config->m_beamMomE - fitMomE;
 
  301    for (
int row = 0; row < 4; ++row) {
 
  302      p.getH()(row, momindex + row) = -1;
 
  305    p.getV() =  
m_config->m_beamCovariance;
 
  307    return ErrCode(ErrCode::Status::success) ;
 
 
  317      case Constraint::mass:
 
  320      case Constraint::geometric:
 
  323      case Constraint::kinematic:
 
  326      case Constraint::beam:
 
 
  387      daughter->addToConstraintList(list, depth - 1);
 
  390      list.push_back(
Constraint(
this, Constraint::lifetime, depth, 1));
 
  393      list.push_back(
Constraint(
this, Constraint::kinematic, depth, 4, 3));
 
  398      list.push_back(
Constraint(
this, Constraint::geometric, depth, 
dim, 3));
 
  401      list.push_back(
Constraint(
this, Constraint::mass, depth, 1, 3));
 
  405      list.push_back(
Constraint(
this, Constraint::beam, depth, 4, 3));
 
 
  413    if (!
mother() && 
id >= 3) {++id;}
 
 
  420      daughter->forceP4Sum(fitparams);
 
 
This class represents an ideal helix in perigee parameterization.
double getArcLength2DAtXY(const double &x, const double &y) const
Calculates the two dimensional arc length at which the circle in the xy projection is closest to the ...
Class to store reconstructed particles.
const V0 * getV0() const
Returns the pointer to the V0 object that was used to create this Particle (if ParticleType == c_V0).
ROOT::Math::XYZVector getMomentum() const
Returns momentum vector.
const TrackFitResult * getTrackFitResult() const
Returns the pointer to the TrackFitResult that was used to create this Particle (ParticleType == c_Tr...
const Particle * getDaughter(unsigned i) const
Returns a pointer to the i-th daughter particle.
Helix getHelix() const
Conversion to framework Helix (without covariance).
constraint configuration class
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, ROOT::Math::XYZVector &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
ParticleBase(Belle2::Particle *particle, const ParticleBase *mother, const ConstraintConfiguration *config=nullptr)
default constructor
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
const ParticleBase * mother() const
getMother() / hasMother()
std::vector< Constraint > constraintlist
alias
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