12 #include <TDatabasePDG.h>
14 #include <analysis/VertexFitting/TreeFitter/ParticleBase.h>
15 #include <analysis/VertexFitting/TreeFitter/InternalParticle.h>
16 #include <analysis/VertexFitting/TreeFitter/RecoComposite.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>
26 #include <framework/geometry/BFieldManager.h>
28 namespace TreeFitter {
33 m_isStronglyDecayingResonance(false),
36 m_pdgMass(particle->getPDGMass()),
38 m_pdgLifeTime(TDatabasePDG::Instance()->GetParticle(particle->getPDGCode())->Lifetime() * 1e9),
50 m_charge = fltcharge < 0 ? int(fltcharge - 0.5) : int(fltcharge + 0.5);
61 m_isStronglyDecayingResonance(false),
64 m_pdgMass(particle->getPDGMass()),
66 m_pdgLifeTime(TDatabasePDG::Instance()->GetParticle(particle->getPDGCode())->Lifetime() * 1e9),
78 m_charge = fltcharge < 0 ? int(fltcharge - 0.5) : int(fltcharge + 0.5);
89 m_isStronglyDecayingResonance(false),
123 B2ERROR(
"Cannot remove particle, because not found ...");
130 daughter->updateIndex(offset);
142 return new Origin(daughter, config, forceFitAll);
217 lifetime = TDatabasePDG::Instance()->GetParticle(pdgcode)->Lifetime() * 1e9;
249 particles.push_back(
this);
253 daughter->collectVertexDaughters(particles, posindex);
264 for (
int i = 0; i < 3; ++i) {
272 for (
int i = 0; i < maxrow; ++i) {
291 std::string rc =
name();
293 case 0: rc +=
"_x ";
break;
294 case 1: rc +=
"_y ";
break;
295 case 2: rc +=
"_z ";
break;
296 case 3: rc +=
"_tau";
break;
297 case 4: rc +=
"_px ";
break;
298 case 5: rc +=
"_py ";
break;
299 case 6: rc +=
"_pz ";
break;
300 case 7: rc +=
"_E ";
break;
320 map.push_back(std::pair<const ParticleBase*, int>(
this,
index()));
322 daughter->retrieveIndexMap(map);
330 rc += daughter->chiSquare(fitparams);
339 rc += daughter->nFinalChargedCandidates();
355 Eigen::Matrix < double, 1, -1, 1, 1, 3 > x_vec = fitparams.
getStateVector().segment(posindex,
dim);
356 Eigen::Matrix < double, 1, -1, 1, 1, 3 > x_m = fitparams.
getStateVector().segment(posindexmother,
dim);
357 Eigen::Matrix < double, 1, -1, 1, 1, 3 > p_vec = fitparams.
getStateVector().segment(momindex,
dim);
358 const double mom = p_vec.norm();
359 const double mom3 = mom * mom * mom;
364 p.getH()(0, momindex) = tau * (p_vec(1) * p_vec(1) + p_vec(2) * p_vec(2)) / mom3 ;
365 p.getH()(1, momindex + 1) = tau * (p_vec(0) * p_vec(0) + p_vec(2) * p_vec(2)) / mom3 ;
366 p.getH()(2, momindex + 2) = tau * (p_vec(0) * p_vec(0) + p_vec(1) * p_vec(1)) / mom3 ;
369 p.getH()(0, momindex + 1) = - tau * p_vec(0) * p_vec(1) / mom3 ;
370 p.getH()(0, momindex + 2) = - tau * p_vec(0) * p_vec(2) / mom3 ;
372 p.getH()(1, momindex + 0) = - tau * p_vec(1) * p_vec(0) / mom3 ;
373 p.getH()(1, momindex + 2) = - tau * p_vec(1) * p_vec(2) / mom3 ;
375 p.getH()(2, momindex + 0) = - tau * p_vec(2) * p_vec(0) / mom3 ;
376 p.getH()(2, momindex + 1) = - tau * p_vec(2) * p_vec(1) / mom3 ;
378 }
else if (2 ==
dim) {
381 p.getH()(0, momindex) = tau * (p_vec(1) * p_vec(1)) / mom3 ;
382 p.getH()(1, momindex + 1) = tau * (p_vec(0) * p_vec(0)) / mom3 ;
385 p.getH()(0, momindex + 1) = - tau * p_vec(0) * p_vec(1) / mom3 ;
386 p.getH()(1, momindex + 0) = - tau * p_vec(1) * p_vec(0) / mom3 ;
388 B2FATAL(
"Dimension of Geometric constraint is not 2 or 3. This will crash many things. You should feel bad.");
391 for (
int row = 0; row <
dim; ++row) {
393 double posxmother = x_m(row);
394 double posx = x_vec(row);
395 double momx = p_vec(row);
400 p.getResiduals()(row) = posxmother + tau * momx / mom - posx ;
401 p.getH()(row, posindexmother + row) = 1;
402 p.getH()(row, posindex + row) = -1;
403 p.getH()(row, tauindex) = momx / mom;
406 return ErrCode(ErrCode::Status::success);
409 void inline setExtraInfo(
Belle2::Particle* part,
const std::string& name,
const double value)
412 if (part->hasExtraInfo(name)) {
413 part->setExtraInfo(name, value);
415 part->addExtraInfo(name, value);
424 const double mass2 = mass * mass;
432 const int momindex = daughter->momIndex();
435 const double py_daughter = fitparams.
getStateVector()(momindex + 1);
436 const double pz_daughter = fitparams.
getStateVector()(momindex + 2);
441 if (daughter->hasEnergy()) {
445 const double m = daughter->pdgMass();
446 E += std::sqrt(m * m + px_daughter * px_daughter + py_daughter * py_daughter + pz_daughter * pz_daughter);
453 p.getResiduals()(0) = mass2 - E * E + px * px + py * py + pz * pz;
457 const int momindex = daughter->momIndex();
458 p.getH()(0, momindex) = 2.0 * px;
459 p.getH()(0, momindex + 1) = 2.0 * py;
460 p.getH()(0, momindex + 2) = 2.0 * pz;
462 if (daughter->hasEnergy()) {
463 p.getH()(0, momindex + 3) = -2.0 * E;
466 const double py_daughter = fitparams.
getStateVector()(momindex + 1);
467 const double pz_daughter = fitparams.
getStateVector()(momindex + 2);
468 const double m = daughter->pdgMass();
470 const double E_daughter = std::sqrt(m * m + px_daughter * px_daughter + py_daughter * py_daughter + pz_daughter * pz_daughter);
471 const double E_by_E_daughter = E / E_daughter;
472 p.getH()(0, momindex) -= 2.0 * E_by_E_daughter * px_daughter;
473 p.getH()(0, momindex + 1) -= 2.0 * E_by_E_daughter * py_daughter;
474 p.getH()(0, momindex + 2) -= 2.0 * E_by_E_daughter * pz_daughter;
478 return ErrCode(ErrCode::Status::success);
485 const double mass2 = mass * mass;
495 p.getResiduals()(0) = mass2 - E * E + px * px + py * py + pz * pz;
497 p.getH()(0, momindex) = 2.0 * px;
498 p.getH()(0, momindex + 1) = 2.0 * py;
499 p.getH()(0, momindex + 2) = 2.0 * pz;
500 p.getH()(0, momindex + 3) = -2.0 * E;
508 return ErrCode(ErrCode::Status::success);
524 if (
type == Constraint::mass) {
527 B2FATAL(
"Trying to project constraint of ParticleBase type. This is undefined.");
529 return ErrCode(ErrCode::Status::badsetup);
548 const Eigen::Matrix < double, 1, -1, 1, 1, 3 > vertex_dist =
550 const Eigen::Matrix < double, 1, -1, 1, 1, 3 >
556 const double mom_norm = mom.norm();
557 const double dot = std::abs(vertex_dist.dot(mom));
558 const double tau = dot / mom_norm;
559 if (0 == mom_norm || 0 == dot) {
566 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.
float getExtraInfo(const std::string &name) const
Return given value if set.
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.
float getCharge(void) const
Returns particle charge.
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, MAX_MATRIX_SIZE > & getCovariance()
getter for the states covariance
Eigen::Matrix< double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > & getStateVector()
getter for the fit parameters/statevector
another unnecessary layer of abstraction
representation of the beamspot as a particle
base class for all particles
ParticleBase(Belle2::Particle *particle, const ParticleBase *mother, const ConstraintConfiguration *config)
default constructor
Belle2::Particle * particle() const
get basf2 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
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
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
const std::string & name() const
get name of the particle
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()
double pdgMass() const
get pdg mass
virtual bool hasPosition() const
get false
double pdgLifeTime() const
get pdg lifetime
double pdgTime() const
get Tau
static double bFieldOverC()
Bz/c
class to store the projected residuals and the corresponding jacobian as well as the covariance matri...
A class for composite particles.
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
static void getField(const double *pos, double *field)
return the magnetic field at a given position.