Belle II Software development
InternalParticle Class Reference

another unnecessary layer of abstraction More...

#include <InternalParticle.h>

Inheritance diagram for InternalParticle:
ParticleBase Resonance

Public Types

enum  TFParticleType {
  kInteractionPoint ,
  kOrigin ,
  kComposite ,
  kRecoResonance ,
  kInternalParticle ,
  kRecoTrack ,
  kResonance ,
  kRecoNeutral ,
  kMissingParticle
}
 particle types More...
 
typedef std::vector< Constraintconstraintlist
 alias
 
typedef std::vector< std::pair< const ParticleBase *, int > > indexmap
 alias
 

Public Member Functions

 InternalParticle (Belle2::Particle *particle, const ParticleBase *mother, const ConstraintConfiguration &config, bool forceFitAll)
 constructor
 
virtual ~InternalParticle ()
 destructor
 
virtual ErrCode initCovariance (FitParams &) const override
 init covariance
 
ErrCode projectKineConstraint (const FitParams &, Projection &) const
 project kinematical constraint
 
ErrCode projectBeamConstraint (const FitParams &, Projection &) const
 project beam four momentum constraint
 
virtual void forceP4Sum (FitParams &) const override
 enforce conservation of momentum sum
 
virtual ErrCode initParticleWithMother (FitParams &fitparams) override
 init particle in case it has a mother
 
virtual ErrCode initMotherlessParticle (FitParams &fitparams) override
 init particle in case it has no mother
 
ErrCode projectConstraint (const Constraint::Type type, const FitParams &fitparams, Projection &p) const override
 find out which constraint it is and project
 
virtual int dim () const override
 space reserved in fit params, if has mother then it has tau
 
virtual int type () const override
 type
 
virtual int posIndex () const override
 position index in fit params
 
virtual int tauIndex () const override
 tau index in fit params only if it has a mother
 
virtual int momIndex () const override
 momentum index in fit params depending on whether it has a mother
 
virtual bool hasEnergy () const override
 has energy in fitparams
 
virtual bool hasPosition () const override
 has position index
 
virtual std::string parname (int index) const override
 name
 
virtual void addToConstraintList (constraintlist &list, int depth) const override
 add to constraint list
 
void setMassConstraint (bool b)
 set mass constraint flag
 
virtual void updateIndex (int &offset)
 this sets the index for momentum, position, etc.
 
const ParticleBaselocate (Belle2::Particle *particle) const
 get particle base from basf2 particle
 
Belle2::Particleparticle () const
 get basf2 particle
 
int index () const
 get index
 
const ParticleBasemother () const
 getMother() / hasMother()
 
virtual ErrCode projectGeoConstraint (const FitParams &, Projection &) const
 project geometrical constraint
 
virtual ErrCode projectMassConstraintParticle (const FitParams &, Projection &) const
 project mass constraint using the particles parameters
 
virtual ErrCode projectMassConstraintDaughters (const FitParams &, Projection &) const
 project mass constraint using the parameters of the daughters
 
virtual ErrCode projectMassConstraint (const FitParams &, Projection &) const
 project mass constraint abstract
 
int eneIndex () const
 get energy index
 
virtual double chiSquare (const FitParams &) const
 get chi2
 
int charge () const
 get charge
 
virtual ParticleBaseaddDaughter (Belle2::Particle *, const ConstraintConfiguration &config, bool forceFitAll=false)
 add daughter
 
virtual void removeDaughter (const ParticleBase *pb)
 remove daughter
 
virtual void retrieveIndexMap (indexmap &anindexmap) const
 get index map
 
void setMother (const ParticleBase *m)
 set mother
 
void collectVertexDaughters (std::vector< ParticleBase * > &particles, int posindex)
 get vertex daughters
 
virtual int nFinalChargedCandidates () const
 number of charged candidates
 

Static Public Member Functions

static ParticleBasecreateParticle (Belle2::Particle *particle, const ParticleBase *mother, const ConstraintConfiguration &config, bool forceFitAll=false)
 create the according treeFitter particle obj for a basf2 particle type
 
static ParticleBasecreateOrigin (Belle2::Particle *daughter, const ConstraintConfiguration &config, bool forceFitAll)
 create a custom origin particle or a beamspot
 

Protected Types

typedef std::vector< ParticleBase * > ParticleContainer
 just an alias
 

Protected Member Functions

ErrCode initMomentum (FitParams &fitparams) const
 init momentum of *this and daughters
 
ErrCode initTau (FitParams &par) const
 initialises tau as a length
 
void setIndex (int i)
 set Index (in statevector)
 

Static Protected Member Functions

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.
 

Protected Attributes

Belle2::Particlem_particle
 pointer to framework type
 
const ParticleBasem_mother
 motherparticle
 
std::vector< ParticleBase * > m_daughters
 daughter container
 
bool m_isStronglyDecayingResonance
 decay length less than 1 micron
 
const ConstraintConfigurationm_config
 has all the constraint config
 

Static Private Member Functions

static bool compTrkTransverseMomentum (const RecoTrack *lhs, const RecoTrack *rhs)
 compare transverse track momentum
 

Private Attributes

bool m_massconstraint
 has mass constraint
 
bool m_beamconstraint
 has beam constraint
 
bool m_shares_vertex_with_mother
 shares vertex with mother, that means decay vertex = productionvertex
 
bool m_geo_constraint
 use a geo metric constraint
 
bool m_lifetimeconstraint
 has lifetime constraint
 
bool m_isconversion
 is conversion
 
bool m_automatic_vertex_constraining
 automatically figure out if mother and particle vertex should be the same and also add geometric constraints
 
int m_index
 index
 
std::string m_name
 name
 

Detailed Description

another unnecessary layer of abstraction

Definition at line 19 of file InternalParticle.h.

Member Typedef Documentation

◆ constraintlist

typedef std::vector<Constraint> constraintlist
inherited

alias

Definition at line 48 of file ParticleBase.h.

◆ indexmap

typedef std::vector< std::pair<const ParticleBase*, int> > indexmap
inherited

alias

Definition at line 51 of file ParticleBase.h.

◆ ParticleContainer

typedef std::vector<ParticleBase*> ParticleContainer
protectedinherited

just an alias

Definition at line 174 of file ParticleBase.h.

Member Enumeration Documentation

◆ TFParticleType

enum TFParticleType
inherited

particle types

Definition at line 27 of file ParticleBase.h.

27 {kInteractionPoint,
28 kOrigin,
29 kComposite,
30 kRecoResonance,
31 kInternalParticle,
32 kRecoTrack,
33 kResonance,
34 kRecoNeutral,
35 kMissingParticle
36 };

Constructor & Destructor Documentation

◆ InternalParticle()

InternalParticle ( Belle2::Particle * particle,
const ParticleBase * mother,
const ConstraintConfiguration & config,
bool forceFitAll )

constructor

Definition at line 43 of file InternalParticle.cc.

47 :
48 ParticleBase(particle, mother, &config),// config pointer here to allow final states not to have it
49 m_massconstraint(false),
50 m_beamconstraint(false),
51 m_lifetimeconstraint(false),
52 m_isconversion(false),
53 m_automatic_vertex_constraining(config.m_automatic_vertex_constraining)
54 {
55 if (particle) {
56 for (auto daughter : particle->getDaughters()) {
57 addDaughter(daughter, config, forceFitAll);
58 }
59 } else {
60 B2ERROR("Trying to create an InternalParticle from NULL. This should never happen.");
61 }
62
63 m_massconstraint = std::find_if(config.m_massConstraintListPDG.begin(), config.m_massConstraintListPDG.end(),
64 [pdg = std::abs(m_particle->getPDGCode())](int val) { return std::abs(val) == pdg; }) != config.m_massConstraintListPDG.end()
65 or m_particle->hasExtraInfo("treeFitterMassConstraint");
66
67 m_beamconstraint = (std::abs(m_particle->getPDGCode()) == std::abs(config.m_beamConstraintPDG));
68
69 if (!m_automatic_vertex_constraining) {
70 // if this is a hadronically decaying resonance it is useful to constrain the decay vertex to its mother's decay vertex.
71 //
72 m_shares_vertex_with_mother = std::find_if(config.m_fixedToMotherVertexListPDG.begin(), config.m_fixedToMotherVertexListPDG.end(),
73 [pdg = std::abs(m_particle->getPDGCode())](int val) { return std::abs(val) == pdg; }) != config.m_fixedToMotherVertexListPDG.end()
74 and this->mother();
75
76 // use geo constraint if this particle is in the list to constrain
77 m_geo_constraint = std::find_if(config.m_geoConstraintListPDG.begin(), config.m_geoConstraintListPDG.end(),
78 [pdg = std::abs(m_particle->getPDGCode())](int val) { return std::abs(val) == pdg; }) != config.m_geoConstraintListPDG.end()
79 and this->mother() and !m_shares_vertex_with_mother;
80 } else {
81 m_shares_vertex_with_mother = this->mother() && m_isStronglyDecayingResonance;
82 m_geo_constraint = this->mother() && !m_shares_vertex_with_mother;
83 }
84 }

◆ ~InternalParticle()

virtual ~InternalParticle ( )
inlinevirtual

destructor

Definition at line 31 of file InternalParticle.h.

31{};

Member Function Documentation

◆ addDaughter()

ParticleBase * addDaughter ( Belle2::Particle * cand,
const ConstraintConfiguration & config,
bool forceFitAll = false )
virtualinherited

add daughter

Definition at line 63 of file ParticleBase.cc.

64 {
65 auto newDaughter = ParticleBase::createParticle(cand, this, config, forceFitAll);
66 m_daughters.push_back(newDaughter);
67 return m_daughters.back();
68 }

◆ addToConstraintList()

void addToConstraintList ( constraintlist & list,
int depth ) const
overridevirtual

add to constraint list

Implements ParticleBase.

Definition at line 381 of file InternalParticle.cc.

383 {
384
385 for (auto daughter : m_daughters) {
386 daughter->addToConstraintList(list, depth - 1);
387 }
388 if (tauIndex() >= 0 && m_lifetimeconstraint) {
389 list.push_back(Constraint(this, Constraint::lifetime, depth, 1));
390 }
391 if (momIndex() >= 0) {
392 list.push_back(Constraint(this, Constraint::kinematic, depth, 4, 3));
393 }
394 if (m_geo_constraint) {
395 assert(m_config);
396 const int dim = m_config->m_originDimension == 2 && std::abs(m_particle->getPDGCode()) == m_config->m_headOfTreePDG ? 2 : 3;
397 list.push_back(Constraint(this, Constraint::geometric, depth, dim, 3));
398 }
399 if (m_massconstraint) {
400 list.push_back(Constraint(this, Constraint::mass, depth, 1, 3));
401 }
402 if (m_beamconstraint) {
403 assert(m_config);
404 list.push_back(Constraint(this, Constraint::beam, depth, 4, 3));
405 }
406
407 }

◆ charge()

int charge ( ) const
inlineinherited

get charge

Definition at line 140 of file ParticleBase.h.

141 {
142 if (m_particle->getPDGCode()) {
143 double fltcharge = m_particle->getCharge();
144 return fltcharge < 0 ? int(fltcharge - 0.5) : int(fltcharge + 0.5);
145 } else {
146 return m_particle->getCharge() > 0 ? 1 : (m_particle->getCharge() < 0 ? -1 : 0);
147 }
148 }

◆ chiSquare()

double chiSquare ( const FitParams & fitparams) const
virtualinherited

get chi2

Definition at line 229 of file ParticleBase.cc.

230 {
231 double rc = 0;
232 for (auto* daughter : m_daughters) {
233 rc += daughter->chiSquare(fitparams);
234 }
235 return rc;
236 }

◆ collectVertexDaughters()

void collectVertexDaughters ( std::vector< ParticleBase * > & particles,
int posindex )
inherited

get vertex daughters

Definition at line 154 of file ParticleBase.cc.

155 {
156 if (mother() && mother()->posIndex() == posindex) {
157 particles.push_back(this);
158 }
159
160 for (auto* daughter : m_daughters) {
161 daughter->collectVertexDaughters(particles, posindex);
162 }
163 }

◆ compTrkTransverseMomentum()

bool compTrkTransverseMomentum ( const RecoTrack * lhs,
const RecoTrack * rhs )
staticprivate

compare transverse track momentum

Definition at line 86 of file InternalParticle.cc.

87 {
88
89 return lhs->particle()->getMomentum().Rho() > rhs->particle()->getMomentum().Rho();
90 }

◆ createOrigin()

ParticleBase * createOrigin ( Belle2::Particle * daughter,
const ConstraintConfiguration & config,
bool forceFitAll )
staticinherited

create a custom origin particle or a beamspot

Definition at line 91 of file ParticleBase.cc.

96 {
97 return new Origin(daughter, config, forceFitAll);
98 }

◆ createParticle()

ParticleBase * createParticle ( Belle2::Particle * particle,
const ParticleBase * mother,
const ConstraintConfiguration & config,
bool forceFitAll = false )
staticinherited

create the according treeFitter particle obj for a basf2 particle type

Definition at line 100 of file ParticleBase.cc.

102 {
103 ParticleBase* rc = nullptr;
104
105 if (!mother) { // If there is no mother, this is the 'head of tree' particle (is never a resonance)
106 rc = new InternalParticle(particle, nullptr, config, forceFitAll);
107 } else if (particle->hasExtraInfo("bremsCorrected") // Has Bremsstrahlungs-recovery
108 && particle->getExtraInfo("bremsCorrected") != 0) { // and gammas are attached
109 rc = new Composite(particle, mother, config, true);
110 // if no gamma is attached, it is treated as a RecoTrack
111 } else if (particle->hasExtraInfo("treeFitterTreatMeAsInvisible")
112 && particle->getExtraInfo("treeFitterTreatMeAsInvisible") == 1) { // dummy particles with invisible flag
113 rc = new RecoResonance(particle, mother, config);
114 } else if (particle->getTrack()) { // external reconstructed track
115 rc = new RecoTrack(particle, mother);
116 } else if (particle->getParticleSource() == Belle2::Particle::EParticleSourceObject::c_ECLCluster
117 or particle->getParticleSource() == Belle2::Particle::EParticleSourceObject::c_KLMCluster) {
118 // external reconstructed neutral final-state particle
119 rc = new RecoNeutral(particle, mother);
120 } else if (particle->getMdstArrayIndex()) { // external composite e.g. V0
121 rc = new InternalParticle(particle, mother, config, forceFitAll);
122 } else { // 'internal' particles
123 if (isAResonance(particle)) {
124 rc = new Resonance(particle, mother, config, forceFitAll);
125 } else {
126 rc = new InternalParticle(particle, mother, config, forceFitAll);
127 }
128 }
129 return rc;
130 }

◆ dim()

int dim ( ) const
overridevirtual

space reserved in fit params, if has mother then it has tau

Implements ParticleBase.

Reimplemented in Resonance.

Definition at line 341 of file InternalParticle.cc.

342 {
343 // { x, y, z, tau, px, py, pz, E }
344 // the last 4 always exists for composite particles
345 // tau index only exist with a vertex and geo constraint
346 //
347 if (m_shares_vertex_with_mother) { return 4; }
348 else if (!m_geo_constraint) { return 7; }
349 else { return 8; }
350 }

◆ eneIndex()

int eneIndex ( ) const
inlineinherited

get energy index

Definition at line 134 of file ParticleBase.h.

134{ return hasEnergy() ? momIndex() + 3 : -1 ; }

◆ forceP4Sum()

void forceP4Sum ( FitParams & fitparams) const
overridevirtual

enforce conservation of momentum sum

Reimplemented from ParticleBase.

Definition at line 416 of file InternalParticle.cc.

417 {
418 for (const auto daughter : m_daughters) {
419 daughter->forceP4Sum(fitparams);
420 }
421 const int momindex = momIndex();
422 if (momindex > 0) {
423 const int dim = hasEnergy() ? 4 : 3;
424 Projection p(fitparams.getDimensionOfState(), dim);
425 projectKineConstraint(fitparams, p);
426 fitparams.getStateVector().segment(momindex, dim) -= p.getResiduals().segment(0, dim);
427 }
428 }

◆ hasEnergy()

virtual bool hasEnergy ( ) const
inlineoverridevirtual

has energy in fitparams

Reimplemented from ParticleBase.

Definition at line 70 of file InternalParticle.h.

70{ return true ; }

◆ hasPosition()

bool hasPosition ( ) const
overridevirtual

has position index

Reimplemented from ParticleBase.

Reimplemented in Resonance.

Definition at line 374 of file InternalParticle.cc.

375 {
376 // does this particle have a position index (decayvertex)
377 // true in any case
378 return true;
379 }

◆ index()

int index ( ) const
inlineinherited

get index

Definition at line 91 of file ParticleBase.h.

91{ return m_index ; }

◆ initCovariance()

ErrCode initCovariance ( FitParams & fitparams) const
overridevirtual

init covariance

Reimplemented from ParticleBase.

Definition at line 228 of file InternalParticle.cc.

229 {
230 ErrCode status;
231 ParticleBase::initCovariance(fitparams);
232 for (auto daughter : m_daughters) {
233 status |= daughter->initCovariance(fitparams);
234 }
235 return status;
236 }

◆ initMomentum()

ErrCode initMomentum ( FitParams & fitparams) const
protected

init momentum of *this and daughters

Definition at line 205 of file InternalParticle.cc.

206 {
207 int momindex = momIndex();
208 fitparams.getStateVector().segment(momindex, 4) = Eigen::Matrix<double, 4, 1>::Zero(4);
209
210 for (auto daughter : m_daughters) {
211 int daumomindex = daughter->momIndex();
212 int maxrow = daughter->hasEnergy() ? 4 : 3;
213
214 double e2 = fitparams.getStateVector().segment(daumomindex, maxrow).squaredNorm();
215 fitparams.getStateVector().segment(momindex, maxrow) += fitparams.getStateVector().segment(daumomindex, maxrow);
216
217 if (maxrow == 3) {
218 double mass = 0;
219 if (daughter->particle()->hasExtraInfo("treeFitterMassConstraintValue")) {
220 mass = daughter->particle()->getExtraInfo("treeFitterMassConstraintValue");
221 } else mass = daughter->particle()->getPDGMass();
222 fitparams.getStateVector()(momindex + 3) += std::sqrt(e2 + mass * mass);
223 }
224 }
225 return ErrCode(ErrCode::Status::success);
226 }

◆ initMotherlessParticle()

ErrCode initMotherlessParticle ( FitParams & fitparams)
overridevirtual

init particle in case it has no mother

(0,0,0) is the best guess in any other case

Implements ParticleBase.

Reimplemented in Resonance.

Definition at line 92 of file InternalParticle.cc.

93 {
94 ErrCode status ;
95 for (auto daughter : m_daughters) {
96 status |= daughter->initMotherlessParticle(fitparams);
97 }
98
99 int posindex = posIndex();
100 // FIXME update this and check if this position is already initialised
101 // lower stream vertices might be better
102 if (hasPosition()) {
103 fitparams.getStateVector().segment(posindex, 3) = Eigen::Matrix<double, 3, 1>::Zero(3);
104
105 std::vector<ParticleBase*> alldaughters;
106 ParticleBase::collectVertexDaughters(alldaughters, posindex);
107
108 std::vector<ParticleBase*> vtxdaughters;
109
110 vector<RecoTrack*> trkdaughters;
111 for (auto daughter : alldaughters) {
112 if (daughter->type() == ParticleBase::TFParticleType::kRecoTrack) {
113 trkdaughters.push_back(static_cast<RecoTrack*>(daughter));
114 } else if (daughter->hasPosition()
115 && fitparams.getStateVector()(daughter->posIndex()) != 0) {
116 vtxdaughters.push_back(daughter);
117 }
118 }
119
120 if (trkdaughters.size() >= 2) {
121
122 auto v0 = particle()->getV0();
123 auto dummy_vertex = ROOT::Math::XYZVector(0, 0, 0);
124
125 bool initWithV0 = false;
126 if (v0 && v0->getFittedVertexPosition() != dummy_vertex) {
127 auto part_dau1 = particle()->getDaughter(0);
128 auto part_dau2 = particle()->getDaughter(1);
129
130 auto recotrack_dau1 = std::find_if(trkdaughters.begin(), trkdaughters.end(),
131 [&part_dau1](RecoTrack * rt) { return rt->particle()->getMdstSource() == part_dau1->getMdstSource(); });
132 auto recotrack_dau2 = std::find_if(trkdaughters.begin(), trkdaughters.end(),
133 [&part_dau2](RecoTrack * rt) { return rt->particle()->getMdstSource() == part_dau2->getMdstSource(); });
134
135 if (recotrack_dau1 == trkdaughters.end() || recotrack_dau2 == trkdaughters.end()) {
136 B2WARNING("V0 daughter particles do not match with RecoTracks.");
137 } else {
138 double X_V0(v0->getFittedVertexX()), Y_V0(v0->getFittedVertexY()), Z_V0(v0->getFittedVertexZ());
139 fitparams.getStateVector()(posindex) = X_V0;
140 fitparams.getStateVector()(posindex + 1) = Y_V0;
141 fitparams.getStateVector()(posindex + 2) = Z_V0;
142
143 Belle2::Helix helix1 = v0->getTrackFitResults().first->getHelix();
144 Belle2::Helix helix2 = v0->getTrackFitResults().second->getHelix();
145
146 (*recotrack_dau1)->setFlightLength(helix1.getArcLength2DAtXY(X_V0, Y_V0));
147 (*recotrack_dau2)->setFlightLength(helix2.getArcLength2DAtXY(X_V0, Y_V0));
148
149 initWithV0 = true;
150 }
151 }
152
153 if (!initWithV0) {
154 std::sort(trkdaughters.begin(), trkdaughters.end(), compTrkTransverseMomentum);
155
156 RecoTrack* dau1 = trkdaughters[0];
157 RecoTrack* dau2 = trkdaughters[1];
158
159 Belle2::Helix helix1 = dau1->particle()->getTrackFitResult()->getHelix();
160 Belle2::Helix helix2 = dau2->particle()->getTrackFitResult()->getHelix();
161
162 double flt1(0), flt2(0);
163 Eigen::Vector3d v;
164 HelixUtils::helixPoca(helix1, helix2, flt1, flt2, v, m_isconversion);
165
166 fitparams.getStateVector().segment<3>(posindex) = v;
167
168 dau1->setFlightLength(flt1);
169 dau2->setFlightLength(flt2);
170 }
171
172 } else if (false && trkdaughters.size() + vtxdaughters.size() >= 2) {
173 // TODO switched off waiting for refactoring of init1 and init2 functions (does not affect performance)
174 } else if (mother() && mother()->posIndex() >= 0) {
175 const int posindexmother = mother()->posIndex();
176 const int dim = m_config->m_originDimension; //TODO access mother
177 fitparams.getStateVector().segment(posindex, dim) = fitparams.getStateVector().segment(posindexmother, dim);
178 } else {
180 fitparams.getStateVector().segment(posindex, 3) = Eigen::Matrix<double, 1, 3>::Zero(3);
181 }
182 }
183
184 for (auto daughter : m_daughters) {
185 daughter->initParticleWithMother(fitparams);
186 }
187
188 initMomentum(fitparams);
189 return status;
190 }

◆ initParticleWithMother()

ErrCode initParticleWithMother ( FitParams & fitparams)
overridevirtual

init particle in case it has a mother

Implements ParticleBase.

Reimplemented in Resonance.

Definition at line 192 of file InternalParticle.cc.

193 {
194 int posindex = posIndex();
195 if (hasPosition() &&
196 mother() &&
197 fitparams.getStateVector().segment<3>(posindex).isZero()) {
198 const int posindexmom = mother()->posIndex();
199 const int dim = m_config->m_originDimension; //TODO access mother?
200 fitparams.getStateVector().segment(posindex, dim) = fitparams.getStateVector().segment(posindexmom, dim);
201 }
202 return initTau(fitparams);
203 }

◆ initTau()

ErrCode initTau ( FitParams & par) const
protectedinherited

initialises tau as a length

Definition at line 428 of file ParticleBase.cc.

429 {
430 const int tauindex = tauIndex();
431 if (tauindex >= 0 && hasPosition()) {
432
433 const int posindex = posIndex();
434 const int mother_ps_index = mother()->posIndex();
435 const int dim = m_config->m_originDimension; // TODO can we configure this to be particle specific?
436
437 // tau has different meaning depending on the dimension of the constraint
438 // 2-> use x-y projection
439 const Eigen::Matrix < double, 1, -1, 1, 1, 3 > vertex_dist =
440 fitparams.getStateVector().segment(posindex, dim) - fitparams.getStateVector().segment(mother_ps_index, dim);
441 const Eigen::Matrix < double, 1, -1, 1, 1, 3 >
442 mom = fitparams.getStateVector().segment(posindex, dim);
443
444 // if an intermediate vertex is not well defined by a track or so it will be initialised with 0
445 // same for the momentum of for example B0, it might be initialised with 0
446 // in those cases use pdg value
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) {
451 const double mass = m_particle->getPDGMass();
452 if (mass > 0)
453 fitparams.getStateVector()(tauindex) = m_particle->getPDGLifetime() * 1e9 * Belle2::Const::speedOfLight / mass;
454 else
455 fitparams.getStateVector()(tauindex) = 0;
456 } else {
457 fitparams.getStateVector()(tauindex) = tau;
458 }
459 }
460
461 return ErrCode(ErrCode::Status::success);
462 }
static const double speedOfLight
[cm/ns]
Definition Const.h:695
T dot(GeneralVector< T > a, GeneralVector< T > b)
dot product of two general vectors

◆ isAResonance()

bool isAResonance ( Belle2::Particle * particle)
staticprotectedinherited

controls if a particle is treated as a resonance(lifetime=0) or a particle that has a finite lifetime.

A finite life time means it will register a geo constraint for this particle

Definition at line 132 of file ParticleBase.cc.

133 {
134 bool rc = false ;
135 const int pdgcode = std::abs(particle->getPDGCode());
136
137 if (pdgcode && !(particle->getMdstArrayIndex())) {
138 switch (pdgcode) {
139 case 22: //photon conversion
140 rc = false;
141 break ;
142
143 case -11: //bremsstrahlung
144 case 11:
145 rc = true ;
146 break ;
147 default: //everything with boosted flight length less than 1 micrometer
148 rc = (pdgcode && particle->getPDGLifetime() < 1e-14);
149 }
150 }
151 return rc ;
152 }

◆ locate()

const ParticleBase * locate ( Belle2::Particle * particle) const
inherited

get particle base from basf2 particle

Definition at line 209 of file ParticleBase.cc.

210 {
211 const ParticleBase* rc = (m_particle == particle) ? this : nullptr;
212 if (!rc) {
213 for (auto* daughter : m_daughters) {
214 rc = daughter->locate(particle);
215 if (rc) {break;}
216 }
217 }
218 return rc;
219 }

◆ momIndex()

int momIndex ( ) const
overridevirtual

momentum index in fit params depending on whether it has a mother

indexing in { x, y, z, tau, px, py, pz, E } but tau is not existing for all InternalParticles

Reimplemented from ParticleBase.

Reimplemented in Resonance.

Definition at line 358 of file InternalParticle.cc.

359 {
363
364 if (m_geo_constraint && !m_shares_vertex_with_mother) { return this->index() + 4; }
365
366 if (m_shares_vertex_with_mother) { return this->index(); }
367
368 if (!m_geo_constraint) {return index() + 3 ;}
369
370 // this will crash the initialisation
371 return -1;
372 }

◆ mother()

const ParticleBase * mother ( ) const
inlineinherited

getMother() / hasMother()

Definition at line 94 of file ParticleBase.h.

94{ return m_mother; };

◆ nFinalChargedCandidates()

int nFinalChargedCandidates ( ) const
virtualinherited

number of charged candidates

Reimplemented in RecoTrack.

Definition at line 238 of file ParticleBase.cc.

239 {
240 int rc = 0;
241 for (auto* daughter : m_daughters) {
242 rc += daughter->nFinalChargedCandidates();
243 }
244 return rc;
245 }

◆ parname()

std::string parname ( int index) const
overridevirtual

name

Reimplemented from ParticleBase.

Reimplemented in Resonance.

Definition at line 409 of file InternalParticle.cc.

410 {
411 int id = thisindex;
412 if (!mother() && id >= 3) {++id;}
413 return ParticleBase::parname(id);
414 }

◆ particle()

Belle2::Particle * particle ( ) const
inlineinherited

get basf2 particle

Definition at line 88 of file ParticleBase.h.

88{ return m_particle ; }

◆ posIndex()

int posIndex ( ) const
overridevirtual

position index in fit params

Reimplemented from ParticleBase.

Reimplemented in Resonance.

Definition at line 335 of file InternalParticle.cc.

336 {
337 // for example B0 and D* can share the same vertex
338 return m_shares_vertex_with_mother ? this->mother()->posIndex() : index();
339 }

◆ projectBeamConstraint()

ErrCode projectBeamConstraint ( const FitParams & fitparams,
Projection & p ) const

project beam four momentum constraint

Definition at line 290 of file InternalParticle.cc.

292 {
293
294 const int momindex = momIndex() ;
295
296 const Eigen::Matrix<double, 4, 1> fitMomE = fitparams.getStateVector().segment(momindex, 4);
297
298 p.getResiduals() = m_config->m_beamMomE - fitMomE;
299
300 for (int row = 0; row < 4; ++row) {
301 p.getH()(row, momindex + row) = -1;
302 }
303
304 p.getV() = m_config->m_beamCovariance;
305
306 return ErrCode(ErrCode::Status::success) ;
307 }

◆ projectConstraint()

ErrCode projectConstraint ( const Constraint::Type type,
const FitParams & fitparams,
Projection & p ) const
overridevirtual

find out which constraint it is and project

Reimplemented from ParticleBase.

Definition at line 310 of file InternalParticle.cc.

313 {
314 ErrCode status;
315 switch (type) {
316 case Constraint::mass:
317 status |= projectMassConstraint(fitparams, p);
318 break;
319 case Constraint::geometric:
320 status |= projectGeoConstraint(fitparams, p);
321 break;
322 case Constraint::kinematic:
323 status |= projectKineConstraint(fitparams, p);
324 break;
325 case Constraint::beam:
326 status |= projectBeamConstraint(fitparams, p);
327 break;
328 default:
329 status |= ParticleBase::projectConstraint(type, fitparams, p);
330 }
331
332 return status;
333 }

◆ projectGeoConstraint()

ErrCode projectGeoConstraint ( const FitParams & fitparams,
Projection & p ) const
virtualinherited

project geometrical constraint

the direction of the momentum is very well known from the kinematic constraints that is why we do not extract the distance as a vector here

Definition at line 247 of file ParticleBase.cc.

248 {
249 assert(m_config);
250 // only allow 2d for head of tree particles that are beam constrained
251 const int dim = m_config->m_originDimension == 2 && std::abs(m_particle->getPDGCode()) == m_config->m_headOfTreePDG ? 2 : 3;
252 const int posindexmother = mother()->posIndex();
253 const int posindex = posIndex();
254 const int tauindex = tauIndex();
255 const int momindex = momIndex();
256
257 const double tau = fitparams.getStateVector()(tauindex);
258 Eigen::VectorXd x_vec = fitparams.getStateVector().segment(posindex, dim);
259 Eigen::VectorXd x_m = fitparams.getStateVector().segment(posindexmother, dim);
260 Eigen::VectorXd p_vec = fitparams.getStateVector().segment(momindex, dim);
261 const double mom = p_vec.norm();
262 const double mom3 = mom * mom * mom;
263
264 if (3 == dim) {
265 // we can already set these
266 //diagonal momentum
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 ;
270
271 //offdiagonal momentum
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 ;
274
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 ;
277
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 ;
280
281 } else if (2 == dim) {
282
283 // NOTE THAT THESE ARE DIFFERENT IN 2d
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 ;
286
287 //offdiagonal momentum
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 ;
290 } else {
291 B2FATAL("Dimension of Geometric constraint is not 2 or 3. This will crash many things. You should feel bad.");
292 }
293
294 // --- Fill residuals and remaining Jacobian entries ---
298 Eigen::VectorXd residuals = x_m + tau * p_vec / mom - x_vec;
299 p.getResiduals().segment(0, dim) = residuals;
300
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;
305 }
306
307 return ErrCode(ErrCode::Status::success);
308 }

◆ projectKineConstraint()

ErrCode projectKineConstraint ( const FitParams & fitparams,
Projection & p ) const

project kinematical constraint

Definition at line 239 of file InternalParticle.cc.

241 {
242 const int momindex = momIndex();
243
244 // `this` always has an energy row
245 p.getResiduals().segment(0, 4) = fitparams.getStateVector().segment(momindex, 4);
246
247 for (int imom = 0; imom < 4; ++imom) {
248 p.getH()(imom, momindex + imom) = 1;
249 }
250
251 for (const auto daughter : m_daughters) {
252 const int daumomindex = daughter->momIndex();
253 const Eigen::Matrix<double, 1, 3> p3_vec = fitparams.getStateVector().segment(daumomindex, 3);
254
255 // three momentum is easy just subtract the vectors
256 p.getResiduals().segment(0, 3) -= p3_vec;
257
258 // energy depends on the parametrisation!
259 if (daughter->hasEnergy()) {
260 p.getResiduals()(3) -= fitparams.getStateVector()(daumomindex + 3);
261 p.getH()(3, daumomindex + 3) = -1; // d/dE -E
262 } else {
263 // m^2 + p^2 = E^2
264 // so
265 // E = sqrt(m^2 + p^2)
266 double mass = 0;
267 if (daughter->particle()->hasExtraInfo("treeFitterMassConstraintValue")) {
268 mass = daughter->particle()->getExtraInfo("treeFitterMassConstraintValue");
269 } else mass = daughter->particle()->getPDGMass();
270 const double p2 = p3_vec.squaredNorm();
271 const double energy = std::sqrt(mass * mass + p2);
272 p.getResiduals()(3) -= energy;
273
274 for (unsigned i = 0; i < 3; ++i) {
275 // d/dpx_i sqrt(m^2 + p^2)
276 p.getH()(3, daumomindex + i) = -1 * p3_vec(i) / energy;
277 }
278 }
279
280 // this has to be in any case
281 // d/dp_i p_i
282 for (unsigned i = 0; i < 3; ++i) {
283 p.getH()(i, daumomindex + i) = -1;
284 }
285 }
286 return ErrCode(ErrCode::Status::success);
287 }

◆ projectMassConstraint()

ErrCode projectMassConstraint ( const FitParams & fitparams,
Projection & p ) const
virtualinherited

project mass constraint abstract

Definition at line 407 of file ParticleBase.cc.

409 {
410 assert(m_config);
411 if (m_config->m_massConstraintType == 0) {
412 return projectMassConstraintParticle(fitparams, p);
413 } else {
414 return projectMassConstraintDaughters(fitparams, p);
415 }
416 }

◆ projectMassConstraintDaughters()

ErrCode projectMassConstraintDaughters ( const FitParams & fitparams,
Projection & p ) const
virtualinherited

project mass constraint using the parameters of the daughters

be aware that the signs here are important E-|p|-m extracts a negative mass and messes with the momentum !

Definition at line 310 of file ParticleBase.cc.

312 {
313 double mass = 0;
314 if (particle()->hasExtraInfo("treeFitterMassConstraintValue")) {
315 mass = particle()->getExtraInfo("treeFitterMassConstraintValue");
316 } else mass = particle()->getPDGMass();
317 const double mass2 = mass * mass;
318 double px = 0;
319 double py = 0;
320 double pz = 0;
321 double E = 0;
322
323 // the parameters of the daughters must be used otherwise the mass constraint does not have an effect on the extracted daughter momenta
324 for (const auto* daughter : m_daughters) {
325 const int momindex = daughter->momIndex();
326 // in most cases the daughters will be final states so we cache the value to use it in the energy column
327 const double px_daughter = fitparams.getStateVector()(momindex);
328 const double py_daughter = fitparams.getStateVector()(momindex + 1);
329 const double pz_daughter = fitparams.getStateVector()(momindex + 2);
330
331 px += px_daughter;
332 py += py_daughter;
333 pz += pz_daughter;
334 if (daughter->hasEnergy()) {
335 E += fitparams.getStateVector()(momindex + 3);
336 } else {
337 // final states dont have an energy index
338 double m = 0;
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);
343 }
344 }
345
349 p.getResiduals()(0) = mass2 - E * E + px * px + py * py + pz * pz;
350
351 for (const auto* daughter : m_daughters) {
352 //dr/dx = d/dx m2-{E1+E2+...}^2+{p1+p2+...}^2 = 2*x (x= E or p)
353 const int momindex = daughter->momIndex();
354 Eigen::Vector3d mom(px, py, pz);
355 p.getH().block<1, 3>(0, momindex) = 2.0 * mom;
356
357 if (daughter->hasEnergy()) {
358 p.getH()(0, momindex + 3) = -2.0 * E;
359 } else {
360 Eigen::Vector3d mom_daughter = fitparams.getStateVector().segment<3>(momindex);
361 double m = 0;
362 if (daughter->particle()->hasExtraInfo("treeFitterMassConstraintValue")) {
363 m = daughter->particle()->getExtraInfo("treeFitterMassConstraintValue");
364 } else m = daughter->particle()->getPDGMass();
365
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;
369 }
370
371 }
372 return ErrCode(ErrCode::Status::success);
373 }
R E
internal precision of FFTW codelets

◆ projectMassConstraintParticle()

ErrCode projectMassConstraintParticle ( const FitParams & fitparams,
Projection & p ) const
virtualinherited

project mass constraint using the particles parameters

be aware that the signs here are important E-|p|-m extracts a negative mass and messes with the momentum !

Definition at line 375 of file ParticleBase.cc.

377 {
378 double mass = 0;
379 if (particle()->hasExtraInfo("treeFitterMassConstraintValue")) mass = particle()->getExtraInfo("treeFitterMassConstraintValue");
380 else mass = particle()->getPDGMass();
381 const double mass2 = mass * mass;
382 const int momindex = momIndex();
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);
389
393 p.getResiduals()(0) = mass2 - E * E + px * px + py * py + pz * pz;
394
395 p.getH().block<1, 3>(0, momindex) = 2.0 * p3;
396 p.getH()(0, momindex + 3) = -2.0 * E;
397
398 // TODO 0 in most cases -> needs special treatment if width=0 to not crash chi2 calculation
399 // const double width = TDatabasePDG::Instance()->GetParticle(particle()->getPDGCode())->Width();
400 // transport measurement uncertainty into residual system
401 // f' = sigma_x^2 * (df/dx)^2
402 // p.getV()(0) = width * width * 4 * mass2;
403
404 return ErrCode(ErrCode::Status::success);
405 }

◆ removeDaughter()

void removeDaughter ( const ParticleBase * pb)
virtualinherited

remove daughter

Definition at line 71 of file ParticleBase.cc.

72 {
73 auto iter = std::find(m_daughters.begin(), m_daughters.end(), pb);
74 if (iter != m_daughters.end()) {
75 delete *iter;
76 m_daughters.erase(iter);
77 } else {
78 B2ERROR("Cannot remove particle, because not found ...");
79 }
80 }

◆ retrieveIndexMap()

void retrieveIndexMap ( indexmap & anindexmap) const
virtualinherited

get index map

Definition at line 221 of file ParticleBase.cc.

222 {
223 map.push_back(std::pair<const ParticleBase*, int>(this, index()));
224 for (auto* daughter : m_daughters) {
225 daughter->retrieveIndexMap(map);
226 }
227 }

◆ setIndex()

void setIndex ( int i)
inlineprotectedinherited

set Index (in statevector)

Definition at line 185 of file ParticleBase.h.

185{ m_index = i ; }

◆ setMassConstraint()

void setMassConstraint ( bool b)
inline

set mass constraint flag

Definition at line 82 of file InternalParticle.h.

82{ m_massconstraint = b ; }

◆ setMother()

void setMother ( const ParticleBase * m)
inlineinherited

set mother

Definition at line 160 of file ParticleBase.h.

160{ m_mother = m ; }

◆ tauIndex()

int tauIndex ( ) const
overridevirtual

tau index in fit params only if it has a mother

only exists if particle is geo constraint and has a mother

Reimplemented from ParticleBase.

Reimplemented in Resonance.

Definition at line 352 of file InternalParticle.cc.

353 {
355 return m_geo_constraint ? index() + 3 : -1;
356 }

◆ type()

virtual int type ( ) const
inlineoverridevirtual

type

Implements ParticleBase.

Reimplemented in Resonance.

Definition at line 58 of file InternalParticle.h.

58{ return kInternalParticle ; }

◆ updateIndex()

void updateIndex ( int & offset)
virtualinherited

this sets the index for momentum, position, etc.

in the statevector

Definition at line 82 of file ParticleBase.cc.

83 {
84 for (auto* daughter : m_daughters) {
85 daughter->updateIndex(offset);
86 }
87 m_index = offset;
88 offset += dim();
89 }

Member Data Documentation

◆ m_automatic_vertex_constraining

bool m_automatic_vertex_constraining
private

automatically figure out if mother and particle vertex should be the same and also add geometric constraints

Definition at line 114 of file InternalParticle.h.

◆ m_beamconstraint

bool m_beamconstraint
private

has beam constraint

Definition at line 98 of file InternalParticle.h.

◆ m_config

const ConstraintConfiguration* m_config
protectedinherited

has all the constraint config

Definition at line 200 of file ParticleBase.h.

◆ m_daughters

std::vector<ParticleBase*> m_daughters
protectedinherited

daughter container

Definition at line 194 of file ParticleBase.h.

◆ m_geo_constraint

bool m_geo_constraint
private

use a geo metric constraint

Definition at line 104 of file InternalParticle.h.

◆ m_index

int m_index
privateinherited

index

Definition at line 204 of file ParticleBase.h.

◆ m_isconversion

bool m_isconversion
private

is conversion

Definition at line 110 of file InternalParticle.h.

◆ m_isStronglyDecayingResonance

bool m_isStronglyDecayingResonance
protectedinherited

decay length less than 1 micron

Definition at line 197 of file ParticleBase.h.

◆ m_lifetimeconstraint

bool m_lifetimeconstraint
private

has lifetime constraint

Definition at line 107 of file InternalParticle.h.

◆ m_massconstraint

bool m_massconstraint
private

has mass constraint

Definition at line 95 of file InternalParticle.h.

◆ m_mother

const ParticleBase* m_mother
protectedinherited

motherparticle

Definition at line 191 of file ParticleBase.h.

◆ m_name

std::string m_name
privateinherited

name

Definition at line 207 of file ParticleBase.h.

◆ m_particle

Belle2::Particle* m_particle
protectedinherited

pointer to framework type

Definition at line 188 of file ParticleBase.h.

◆ m_shares_vertex_with_mother

bool m_shares_vertex_with_mother
private

shares vertex with mother, that means decay vertex = productionvertex

Definition at line 101 of file InternalParticle.h.


The documentation for this class was generated from the following files: