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.");
60 m_massconstraint = std::find(config.m_massConstraintListPDG.begin(), config.m_massConstraintListPDG.end(),
67 config.m_fixedToMotherVertexListPDG.end(),
72 config.m_geoConstraintListPDG.end(),
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);