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>
26#include <framework/geometry/BFieldManager.h>
33 m_isStronglyDecayingResonance(false),
50 m_isStronglyDecayingResonance(false),
80 B2ERROR(
"Cannot remove particle, because not found ...");
87 daughter->updateIndex(offset);
99 return new Origin(daughter, config, forceFitAll);
159 particles.push_back(
this);
163 daughter->collectVertexDaughters(particles, posindex);
174 for (
int i = 0; i < 3; ++i) {
182 for (
int i = 0; i < maxrow; ++i) {
198 case 0: rc +=
"_x ";
break;
199 case 1: rc +=
"_y ";
break;
200 case 2: rc +=
"_z ";
break;
201 case 3: rc +=
"_tau";
break;
202 case 4: rc +=
"_px ";
break;
203 case 5: rc +=
"_py ";
break;
204 case 6: rc +=
"_pz ";
break;
205 case 7: rc +=
"_E ";
break;
225 map.push_back(std::pair<const ParticleBase*, int>(
this,
index()));
227 daughter->retrieveIndexMap(map);
235 rc += daughter->chiSquare(fitparams);
244 rc += daughter->nFinalChargedCandidates();
260 Eigen::Matrix < double, 1, -1, 1, 1, 3 > x_vec = fitparams.
getStateVector().segment(posindex,
dim);
261 Eigen::Matrix < double, 1, -1, 1, 1, 3 > x_m = fitparams.
getStateVector().segment(posindexmother,
dim);
262 Eigen::Matrix < double, 1, -1, 1, 1, 3 > p_vec = fitparams.
getStateVector().segment(momindex,
dim);
263 const double mom = p_vec.norm();
264 const double mom3 = mom * mom * mom;
269 p.getH()(0, momindex) = tau * (p_vec(1) * p_vec(1) + p_vec(2) * p_vec(2)) / mom3 ;
270 p.getH()(1, momindex + 1) = tau * (p_vec(0) * p_vec(0) + p_vec(2) * p_vec(2)) / mom3 ;
271 p.getH()(2, momindex + 2) = tau * (p_vec(0) * p_vec(0) + p_vec(1) * p_vec(1)) / mom3 ;
274 p.getH()(0, momindex + 1) = - tau * p_vec(0) * p_vec(1) / mom3 ;
275 p.getH()(0, momindex + 2) = - tau * p_vec(0) * p_vec(2) / mom3 ;
277 p.getH()(1, momindex + 0) = - tau * p_vec(1) * p_vec(0) / mom3 ;
278 p.getH()(1, momindex + 2) = - tau * p_vec(1) * p_vec(2) / mom3 ;
280 p.getH()(2, momindex + 0) = - tau * p_vec(2) * p_vec(0) / mom3 ;
281 p.getH()(2, momindex + 1) = - tau * p_vec(2) * p_vec(1) / mom3 ;
283 }
else if (2 ==
dim) {
286 p.getH()(0, momindex) = tau * (p_vec(1) * p_vec(1)) / mom3 ;
287 p.getH()(1, momindex + 1) = tau * (p_vec(0) * p_vec(0)) / mom3 ;
290 p.getH()(0, momindex + 1) = - tau * p_vec(0) * p_vec(1) / mom3 ;
291 p.getH()(1, momindex + 0) = - tau * p_vec(1) * p_vec(0) / mom3 ;
293 B2FATAL(
"Dimension of Geometric constraint is not 2 or 3. This will crash many things. You should feel bad.");
296 for (
int row = 0; row <
dim; ++row) {
298 double posxmother = x_m(row);
299 double posx = x_vec(row);
300 double momx = p_vec(row);
305 p.getResiduals()(row) = posxmother + tau * momx / mom - posx ;
306 p.getH()(row, posindexmother + row) = 1;
307 p.getH()(row, posindex + row) = -1;
308 p.getH()(row, tauindex) = momx / mom;
311 return ErrCode(ErrCode::Status::success);
318 const double mass2 = mass * mass;
326 const int momindex = daughter->momIndex();
329 const double py_daughter = fitparams.
getStateVector()(momindex + 1);
330 const double pz_daughter = fitparams.
getStateVector()(momindex + 2);
335 if (daughter->hasEnergy()) {
339 const double m = daughter->particle()->getPDGMass();
340 E += std::sqrt(m * m + px_daughter * px_daughter + py_daughter * py_daughter + pz_daughter * pz_daughter);
347 p.getResiduals()(0) = mass2 - E * E + px * px + py * py + pz * pz;
351 const int momindex = daughter->momIndex();
352 p.getH()(0, momindex) = 2.0 * px;
353 p.getH()(0, momindex + 1) = 2.0 * py;
354 p.getH()(0, momindex + 2) = 2.0 * pz;
356 if (daughter->hasEnergy()) {
357 p.getH()(0, momindex + 3) = -2.0 * E;
360 const double py_daughter = fitparams.
getStateVector()(momindex + 1);
361 const double pz_daughter = fitparams.
getStateVector()(momindex + 2);
362 const double m = daughter->particle()->getPDGMass();
364 const double E_daughter = std::sqrt(m * m + px_daughter * px_daughter + py_daughter * py_daughter + pz_daughter * pz_daughter);
365 const double E_by_E_daughter = E / E_daughter;
366 p.getH()(0, momindex) -= 2.0 * E_by_E_daughter * px_daughter;
367 p.getH()(0, momindex + 1) -= 2.0 * E_by_E_daughter * py_daughter;
368 p.getH()(0, momindex + 2) -= 2.0 * E_by_E_daughter * pz_daughter;
372 return ErrCode(ErrCode::Status::success);
379 const double mass2 = mass * mass;
389 p.getResiduals()(0) = mass2 - E * E + px * px + py * py + pz * pz;
391 p.getH()(0, momindex) = 2.0 * px;
392 p.getH()(0, momindex + 1) = 2.0 * py;
393 p.getH()(0, momindex + 2) = 2.0 * pz;
394 p.getH()(0, momindex + 3) = -2.0 * E;
402 return ErrCode(ErrCode::Status::success);
418 if (
type == Constraint::mass) {
421 B2FATAL(
"Trying to project constraint of ParticleBase type. This is undefined.");
423 return ErrCode(ErrCode::Status::badsetup);
437 const Eigen::Matrix < double, 1, -1, 1, 1, 3 > vertex_dist =
439 const Eigen::Matrix < double, 1, -1, 1, 1, 3 >
445 const double mom_norm = mom.norm();
446 const double dot = std::abs(vertex_dist.dot(mom));
447 const double tau = dot / mom_norm;
448 if (0 == mom_norm || 0 == dot) {
459 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