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>
20#include <analysis/VertexFitting/TreeFitter/RecoPhoton.h>
21#include <analysis/VertexFitting/TreeFitter/RecoKlong.h>
22#include <analysis/VertexFitting/TreeFitter/Resonance.h>
23#include <analysis/VertexFitting/TreeFitter/Origin.h>
24#include <analysis/VertexFitting/TreeFitter/FitParams.h>
31 m_isStronglyDecayingResonance(false),
48 m_isStronglyDecayingResonance(false),
78 B2ERROR(
"Cannot remove particle, because not found ...");
85 daughter->updateIndex(offset);
97 return new Origin(daughter, config, forceFitAll);
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();
258 Eigen::Matrix < double, 1, -1, 1, 1, 3 > x_vec = fitparams.
getStateVector().segment(posindex,
dim);
259 Eigen::Matrix < double, 1, -1, 1, 1, 3 > x_m = fitparams.
getStateVector().segment(posindexmother,
dim);
260 Eigen::Matrix < double, 1, -1, 1, 1, 3 > p_vec = fitparams.
getStateVector().segment(momindex,
dim);
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.");
294 for (
int row = 0; row <
dim; ++row) {
296 double posxmother = x_m(row);
297 double posx = x_vec(row);
298 double momx = p_vec(row);
303 p.getResiduals()(row) = posxmother + tau * momx / mom - posx ;
304 p.getH()(row, posindexmother + row) = 1;
305 p.getH()(row, posindex + row) = -1;
306 p.getH()(row, tauindex) = momx / mom;
309 return ErrCode(ErrCode::Status::success);
316 if (
particle()->hasExtraInfo(
"treeFitterMassConstraintValue")) {
319 const double mass2 = mass * mass;
327 const int momindex = daughter->momIndex();
330 const double py_daughter = fitparams.
getStateVector()(momindex + 1);
331 const double pz_daughter = fitparams.
getStateVector()(momindex + 2);
336 if (daughter->hasEnergy()) {
341 if (daughter->particle()->hasExtraInfo(
"treeFitterMassConstraintValue")) {
342 m = daughter->particle()->getExtraInfo(
"treeFitterMassConstraintValue");
343 }
else m = daughter->particle()->getPDGMass();
344 E += std::sqrt(m * m + px_daughter * px_daughter + py_daughter * py_daughter + pz_daughter * pz_daughter);
351 p.getResiduals()(0) = mass2 -
E *
E + px * px + py * py + pz * pz;
355 const int momindex = daughter->momIndex();
356 p.getH()(0, momindex) = 2.0 * px;
357 p.getH()(0, momindex + 1) = 2.0 * py;
358 p.getH()(0, momindex + 2) = 2.0 * pz;
360 if (daughter->hasEnergy()) {
361 p.getH()(0, momindex + 3) = -2.0 *
E;
364 const double py_daughter = fitparams.
getStateVector()(momindex + 1);
365 const double pz_daughter = fitparams.
getStateVector()(momindex + 2);
367 if (daughter->particle()->hasExtraInfo(
"treeFitterMassConstraintValue")) {
368 m = daughter->particle()->getExtraInfo(
"treeFitterMassConstraintValue");
369 }
else m = daughter->particle()->getPDGMass();
371 const double E_daughter = std::sqrt(m * m + px_daughter * px_daughter + py_daughter * py_daughter + pz_daughter * pz_daughter);
372 const double E_by_E_daughter =
E / E_daughter;
373 p.getH()(0, momindex) -= 2.0 * E_by_E_daughter * px_daughter;
374 p.getH()(0, momindex + 1) -= 2.0 * E_by_E_daughter * py_daughter;
375 p.getH()(0, momindex + 2) -= 2.0 * E_by_E_daughter * pz_daughter;
379 return ErrCode(ErrCode::Status::success);
388 const double mass2 = mass * mass;
398 p.getResiduals()(0) = mass2 -
E *
E + px * px + py * py + pz * pz;
400 p.getH()(0, momindex) = 2.0 * px;
401 p.getH()(0, momindex + 1) = 2.0 * py;
402 p.getH()(0, momindex + 2) = 2.0 * pz;
403 p.getH()(0, momindex + 3) = -2.0 *
E;
411 return ErrCode(ErrCode::Status::success);
427 if (
type == Constraint::mass) {
430 B2FATAL(
"Trying to project constraint of ParticleBase type. This is undefined.");
432 return ErrCode(ErrCode::Status::badsetup);
446 const Eigen::Matrix < double, 1, -1, 1, 1, 3 > vertex_dist =
448 const Eigen::Matrix < double, 1, -1, 1, 1, 3 >
454 const double mom_norm = mom.norm();
455 const double dot = std::abs(vertex_dist.dot(mom));
456 const double tau = dot / mom_norm;
457 if (0 == mom_norm || 0 == dot) {
468 return ErrCode(ErrCode::Status::success);
static const double speedOfLight
[cm/ns]
Class to store reconstructed particles.
const KLMCluster * getKLMCluster() const
Returns the pointer to the KLMCluster object that was used to create this Particle (ParticleType == c...
const Track * getTrack() const
Returns the pointer to the Track object that was used to create this Particle (ParticleType == c_Trac...
const ECLCluster * getECLCluster() const
Returns the pointer to the ECLCluster object that was used to create this Particle (if ParticleType =...
std::string getName() const override
Return name of this particle.
bool hasExtraInfo(const std::string &name) const
Return whether the extra info with the given name is set.
unsigned getMdstArrayIndex(void) const
Returns 0-based index of MDST store array object (0 for composite particles)
int getPDGCode(void) const
Returns PDG code.
double getPDGMass(void) const
Returns uncertainty on the invariant mass (requires valid momentum error matrix)
double getPDGLifetime() const
Returns particle nominal lifetime.
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
const int m_originDimension
dimension of the origin constraint and ALL geometric gcosntraints
int m_headOfTreePDG
PDG code of the head particle.
const bool m_massConstraintType
const flag for the type of the mass constraint
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
base class for all particles
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
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 Klong constraint
representation of the photon constraint
representation of all charged final states FIXME rename since this name is taken in tracking
class for resonances as internal particles