12#include <TDatabasePDG.h>
14#include <analysis/VertexFitting/TreeFitter/ParticleBase.h>
15#include <analysis/VertexFitting/TreeFitter/InternalParticle.h>
16#include <analysis/VertexFitting/TreeFitter/Composite.h>
17#include <analysis/VertexFitting/TreeFitter/RecoResonance.h>
18#include <analysis/VertexFitting/TreeFitter/RecoTrack.h>
19#include <analysis/VertexFitting/TreeFitter/RecoNeutral.h>
20#include <analysis/VertexFitting/TreeFitter/Resonance.h>
21#include <analysis/VertexFitting/TreeFitter/Origin.h>
22#include <analysis/VertexFitting/TreeFitter/FitParams.h>
23#include <analysis/VertexFitting/TreeFitter/ConstraintConfiguration.h>
24#include <analysis/VertexFitting/TreeFitter/Projection.h>
38 const int pdgcode =
particle->getPDGCode();
78 B2ERROR(
"Cannot remove particle, because not found ...");
85 daughter->updateIndex(offset);
97 return new Origin(daughter, config, forceFitAll);
107 }
else if (
particle->hasExtraInfo(
"bremsCorrected")
108 &&
particle->getExtraInfo(
"bremsCorrected") != 0) {
111 }
else if (
particle->hasExtraInfo(
"treeFitterTreatMeAsInvisible")
112 &&
particle->getExtraInfo(
"treeFitterTreatMeAsInvisible") == 1) {
116 }
else if (
particle->getParticleSource() == Belle2::Particle::EParticleSourceObject::c_ECLCluster
117 or
particle->getParticleSource() == Belle2::Particle::EParticleSourceObject::c_KLMCluster) {
120 }
else if (
particle->getMdstArrayIndex()) {
135 const int pdgcode = std::abs(
particle->getPDGCode());
137 if (pdgcode && !(
particle->getMdstArrayIndex())) {
148 rc = (pdgcode &&
particle->getPDGLifetime() < 1e-14);
157 particles.push_back(
this);
161 daughter->collectVertexDaughters(particles, posindex);
172 for (
int i = 0; i < 3; ++i) {
180 for (
int i = 0; i < maxrow; ++i) {
196 case 0: rc +=
"_x ";
break;
197 case 1: rc +=
"_y ";
break;
198 case 2: rc +=
"_z ";
break;
199 case 3: rc +=
"_tau";
break;
200 case 4: rc +=
"_px ";
break;
201 case 5: rc +=
"_py ";
break;
202 case 6: rc +=
"_pz ";
break;
203 case 7: rc +=
"_E ";
break;
223 map.push_back(std::pair<const ParticleBase*, int>(
this,
index()));
225 daughter->retrieveIndexMap(
map);
233 rc += daughter->chiSquare(fitparams);
242 rc += daughter->nFinalChargedCandidates();
261 const double mom = p_vec.norm();
262 const double mom3 = mom * mom * mom;
267 p.getH()(0, momindex) = tau * (p_vec(1) * p_vec(1) + p_vec(2) * p_vec(2)) / mom3 ;
268 p.getH()(1, momindex + 1) = tau * (p_vec(0) * p_vec(0) + p_vec(2) * p_vec(2)) / mom3 ;
269 p.getH()(2, momindex + 2) = tau * (p_vec(0) * p_vec(0) + p_vec(1) * p_vec(1)) / mom3 ;
272 p.getH()(0, momindex + 1) = - tau * p_vec(0) * p_vec(1) / mom3 ;
273 p.getH()(0, momindex + 2) = - tau * p_vec(0) * p_vec(2) / mom3 ;
275 p.getH()(1, momindex + 0) = - tau * p_vec(1) * p_vec(0) / mom3 ;
276 p.getH()(1, momindex + 2) = - tau * p_vec(1) * p_vec(2) / mom3 ;
278 p.getH()(2, momindex + 0) = - tau * p_vec(2) * p_vec(0) / mom3 ;
279 p.getH()(2, momindex + 1) = - tau * p_vec(2) * p_vec(1) / mom3 ;
281 }
else if (2 ==
dim) {
284 p.getH()(0, momindex) = tau * (p_vec(1) * p_vec(1)) / mom3 ;
285 p.getH()(1, momindex + 1) = tau * (p_vec(0) * p_vec(0)) / mom3 ;
288 p.getH()(0, momindex + 1) = - tau * p_vec(0) * p_vec(1) / mom3 ;
289 p.getH()(1, momindex + 0) = - tau * p_vec(1) * p_vec(0) / mom3 ;
291 B2FATAL(
"Dimension of Geometric constraint is not 2 or 3. This will crash many things. You should feel bad.");
298 Eigen::VectorXd residuals = x_m + tau * p_vec / mom - x_vec;
299 p.getResiduals().segment(0,
dim) = residuals;
301 for (
int row = 0; row <
dim; ++row) {
302 p.getH()(row, posindexmother + row) = 1;
303 p.getH()(row, posindex + row) = -1;
304 p.getH()(row, tauindex) = p_vec(row) / mom;
307 return ErrCode(ErrCode::Status::success);
314 if (
particle()->hasExtraInfo(
"treeFitterMassConstraintValue")) {
317 const double mass2 = mass * mass;
325 const int momindex = daughter->momIndex();
328 const double py_daughter = fitparams.
getStateVector()(momindex + 1);
329 const double pz_daughter = fitparams.
getStateVector()(momindex + 2);
334 if (daughter->hasEnergy()) {
339 if (daughter->particle()->hasExtraInfo(
"treeFitterMassConstraintValue")) {
340 m = daughter->particle()->getExtraInfo(
"treeFitterMassConstraintValue");
341 }
else m = daughter->particle()->getPDGMass();
342 E += std::sqrt(m * m + px_daughter * px_daughter + py_daughter * py_daughter + pz_daughter * pz_daughter);
349 p.getResiduals()(0) = mass2 -
E *
E + px * px + py * py + pz * pz;
353 const int momindex = daughter->momIndex();
354 Eigen::Vector3d mom(px, py, pz);
355 p.getH().block<1, 3>(0, momindex) = 2.0 * mom;
357 if (daughter->hasEnergy()) {
358 p.getH()(0, momindex + 3) = -2.0 *
E;
360 Eigen::Vector3d mom_daughter = fitparams.
getStateVector().segment<3>(momindex);
362 if (daughter->particle()->hasExtraInfo(
"treeFitterMassConstraintValue")) {
363 m = daughter->particle()->getExtraInfo(
"treeFitterMassConstraintValue");
364 }
else m = daughter->particle()->getPDGMass();
366 const double E_daughter = std::sqrt(m * m + mom_daughter.squaredNorm());
367 const double E_by_E_daughter =
E / E_daughter;
368 p.getH().block<1, 3>(0, momindex) -= 2.0 * E_by_E_daughter * mom_daughter;
372 return ErrCode(ErrCode::Status::success);
381 const double mass2 = mass * mass;
383 Eigen::Vector4d state = fitparams.
getStateVector().segment<4>(momindex);
384 Eigen::Vector3d p3 = state.head<3>();
385 const double px = state(0);
386 const double py = state(1);
387 const double pz = state(2);
388 const double E = state(3);
393 p.getResiduals()(0) = mass2 -
E *
E + px * px + py * py + pz * pz;
395 p.getH().block<1, 3>(0, momindex) = 2.0 * p3;
396 p.getH()(0, momindex + 3) = -2.0 *
E;
404 return ErrCode(ErrCode::Status::success);
411 if (
m_config->m_massConstraintType == 0) {
420 if (
type == Constraint::mass) {
423 B2FATAL(
"Trying to project constraint of ParticleBase type. This is undefined.");
425 return ErrCode(ErrCode::Status::badsetup);
439 const Eigen::Matrix < double, 1, -1, 1, 1, 3 > vertex_dist =
441 const Eigen::Matrix < double, 1, -1, 1, 1, 3 >
447 const double mom_norm = mom.norm();
448 const double dot = std::abs(vertex_dist.dot(mom));
449 const double tau = dot / mom_norm;
450 if (0 == mom_norm || 0 == dot) {
461 return ErrCode(ErrCode::Status::success);
static const double speedOfLight
[cm/ns]
Class to store reconstructed particles.
double getPDGMass(void) const
Returns uncertainty on the invariant mass (requires valid momentum error matrix)
double getExtraInfo(const std::string &name) const
Return given value if set.
A class for composite particles, where the daughters must be ignored by the fitter.
constraint configuration class
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
Eigen::Matrix< double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > & getCovariance()
getter for the states covariance
another unnecessary layer of abstraction
representation of the beamspot as a particle
virtual void updateIndex(int &offset)
this sets the index for momentum, position, etc.
virtual ErrCode projectMassConstraintParticle(const FitParams &, Projection &) const
project mass constraint using the particles parameters
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
static ParticleBase * createOrigin(Belle2::Particle *daughter, const ConstraintConfiguration &config, bool forceFitAll)
create a custom origin particle or a beamspot
static ParticleBase * createParticle(Belle2::Particle *particle, const ParticleBase *mother, const ConstraintConfiguration &config, bool forceFitAll=false)
create the according treeFitter particle obj for a basf2 particle type
virtual int dim() const =0
get dimension of constraint
virtual int nFinalChargedCandidates() const
number of charged candidates
virtual void retrieveIndexMap(indexmap &anindexmap) const
get index map
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
static bool isAResonance(Belle2::Particle *particle)
controls if a particle is treated as a resonance(lifetime=0) or a particle that has a finite lifetime...
virtual ErrCode projectConstraint(Constraint::Type, const FitParams &, Projection &) const
project constraint.
virtual ErrCode projectMassConstraintDaughters(const FitParams &, Projection &) const
project mass constraint using the parameters of the daughters
const ParticleBase * locate(Belle2::Particle *particle) const
get particle base from basf2 particle
virtual void removeDaughter(const ParticleBase *pb)
remove daughter
const ParticleBase * m_mother
motherparticle
bool m_isStronglyDecayingResonance
decay length less than 1 micron
virtual ErrCode initCovariance(FitParams &) const
init covariance matrix
virtual int type() const =0
get particle type
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 double chiSquare(const FitParams &) const
get chi2
virtual int posIndex() const
get vertex index (in statevector!)
std::vector< std::pair< const ParticleBase *, int > > indexmap
alias
virtual int momIndex() const
get momentum index
int index() const
get index
virtual bool hasEnergy() const
get momentum dimension
std::vector< ParticleBase * > m_daughters
daughter container
virtual ~ParticleBase()
destructor, actually does something
void collectVertexDaughters(std::vector< ParticleBase * > &particles, int posindex)
get vertex daughters
virtual int tauIndex() const
get tau index
const ParticleBase * mother() const
getMother() / hasMother()
virtual bool hasPosition() const
get false
class to store the projected residuals and the corresponding jacobian as well as the covariance matri...
representation of the neutral particle constraint
representation of all charged final states FIXME rename since this name is taken in tracking
class for resonances as internal particles