Belle II Software  light-2212-foldex
ParticleBase.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * External Contributor: Wouter Hulsbergen *
5  * *
6  * See git log for contributors and copyright holders. *
7  * This file is licensed under LGPL-3.0, see LICENSE.md. *
8  **************************************************************************/
9 #pragma once
10 
11 #include <analysis/VertexFitting/TreeFitter/Constraint.h>
12 #include <analysis/VertexFitting/TreeFitter/Projection.h>
13 #include <analysis/VertexFitting/TreeFitter/ErrCode.h>
14 #include <analysis/VertexFitting/TreeFitter/ConstraintConfiguration.h>
15 #include <Eigen/Core>
16 
17 #include <analysis/dataobjects/Particle.h>
18 
19 namespace TreeFitter {
20 
21  class FitParams;
22  class ConstraintConfiguration;
23 
25  class ParticleBase {
26 
27  public:
28 
30  enum TFParticleType {kInteractionPoint,
31  kOrigin,
32  kRecoComposite,
33  kRecoResonance,
34  kInternalParticle,
35  kRecoTrack,
36  kResonance,
37  kRecoPhoton,
38  kRecoKlong,
39  kMissingParticle
40  };
41 
44 
47 
48 
50  ParticleBase(const std::string& name);
51 
53  virtual ~ParticleBase();
54 
56  typedef std::vector<Constraint> constraintlist;
57 
59  typedef std::vector< std::pair<const ParticleBase*, int> > indexmap;
60 
63  const ParticleBase* mother,
64  const ConstraintConfiguration& config,
65  bool forceFitAll = false
66  );
67 
69  static ParticleBase* createOrigin(Belle2::Particle* daughter,
70  const ConstraintConfiguration& config,
71  bool forceFitAll
72  );
73 
76 
79 
81  virtual ErrCode initCovariance(FitParams&) const;
82 
84  virtual int dim() const = 0 ;
85 
87  virtual void updateIndex(int& offset);
88 
90  virtual std::string parname(int index) const ;
91 
94 
96  Belle2::Particle* particle() const { return m_particle ; }
97 
99  int index() const { return m_index ; }
100 
102  const ParticleBase* mother() const { return m_mother; };
103 
105  virtual ErrCode projectGeoConstraint(const FitParams&, Projection&) const ;
106 
109 
112 
114  virtual ErrCode projectMassConstraint(const FitParams&, Projection&) const ;
115 
118 
120  virtual void forceP4Sum(FitParams&) const {} ;
121 
123  virtual int type() const = 0 ;
124 
126  virtual int posIndex() const { return -1 ; }
127 
129  virtual int tauIndex() const { return -1 ; }
130 
132  virtual int momIndex() const { return -1 ; }
133 
134  // does the particle have a 3-momentum or a 4-momentum ?
136  virtual bool hasEnergy() const { return false ; }
137 
139  virtual bool hasPosition() const { return false ; }
140 
142  int eneIndex() const { return hasEnergy() ? momIndex() + 3 : -1 ; }
143 
145  virtual double chiSquare(const FitParams&) const;
146 
148  int charge() const
149  {
150  if (m_particle->getPDGCode()) {
151  double fltcharge = m_particle->getCharge();
152  return fltcharge < 0 ? int(fltcharge - 0.5) : int(fltcharge + 0.5);
153  } else {
154  return m_particle->getCharge() > 0 ? 1 : (m_particle->getCharge() < 0 ? -1 : 0);
155  }
156  }
157 
159  virtual ParticleBase* addDaughter(Belle2::Particle*, const ConstraintConfiguration& config, bool forceFitAll = false);
160 
162  virtual void removeDaughter(const ParticleBase* pb);
163 
165  virtual void retrieveIndexMap(indexmap& anindexmap) const ;
166 
168  void setMother(const ParticleBase* m) { m_mother = m ; }
169 
171  virtual void addToConstraintList(constraintlist& alist, int depth) const = 0 ;
172 
174  void collectVertexDaughters(std::vector<ParticleBase*>& particles, int posindex) ;
175 
177  virtual int nFinalChargedCandidates() const;
178 
179  protected:
180 
182  typedef std::vector<ParticleBase*> ParticleContainer;
183 
187  static bool isAResonance(Belle2::Particle* particle) ;
188 
190  ErrCode initTau(FitParams& par) const ;
191 
193  void setIndex(int i) { m_index = i ; }
194 
197 
200 
202  std::vector<ParticleBase*> m_daughters;
203 
206 
209 
210  private:
212  int m_index;
213 
215  std::string m_name;
216 
217  }; // end class ParticleBase
218 } // end namespace TreeFitter
Class to store reconstructed particles.
Definition: Particle.h:74
int getPDGCode(void) const
Returns PDG code.
Definition: Particle.h:441
double getCharge(void) const
Returns particle charge.
Definition: Particle.cc:654
Type
type of constraints the order of these constraints is important: it is the order in which they are ap...
Definition: Constraint.h:27
abstract errorocode be aware that the default is success
Definition: ErrCode.h:14
Class to store and manage fitparams (statevector)
Definition: FitParams.h:20
base class for all particles
Definition: ParticleBase.h:25
ParticleBase(Belle2::Particle *particle, const ParticleBase *mother, const ConstraintConfiguration *config)
default constructor
Definition: ParticleBase.cc:30
Belle2::Particle * particle() const
get basf2 particle
Definition: ParticleBase.h:96
virtual void addToConstraintList(constraintlist &alist, int depth) const =0
add to constraint list
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
Definition: ParticleBase.cc:82
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
void setMother(const ParticleBase *m)
set mother
Definition: ParticleBase.h:168
virtual int nFinalChargedCandidates() const
number of charged candidates
virtual void retrieveIndexMap(indexmap &anindexmap) const
get index map
virtual void forceP4Sum(FitParams &) const
force p4 sum conservation all along the tree
Definition: ParticleBase.h:120
virtual ErrCode projectMassConstraint(const FitParams &, Projection &) const
project mass constraint abstract
const ConstraintConfiguration * m_config
has all the constraint config
Definition: ParticleBase.h:208
virtual ErrCode initParticleWithMother(FitParams &)=0
init particle that does need a mother vertex
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
int eneIndex() const
get energy index
Definition: ParticleBase.h:142
const ParticleBase * locate(Belle2::Particle *particle) const
get particle base from basf2 particle
void setIndex(int i)
set Index (in statevector)
Definition: ParticleBase.h:193
std::vector< ParticleBase * > ParticleContainer
just an alias
Definition: ParticleBase.h:182
virtual void removeDaughter(const ParticleBase *pb)
remove daughter
Definition: ParticleBase.cc:90
const ParticleBase * m_mother
motherparticle
Definition: ParticleBase.h:199
bool m_isStronglyDecayingResonance
decay length less than 1 micron
Definition: ParticleBase.h:205
virtual ErrCode initCovariance(FitParams &) const
init covariance matrix
virtual int type() const =0
get particle type
Belle2::Particle * m_particle
pointer to framework type
Definition: ParticleBase.h:196
virtual ErrCode initMotherlessParticle(FitParams &)=0
init particle that does not need a mother vertex
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!)
Definition: ParticleBase.h:126
std::vector< std::pair< const ParticleBase *, int > > indexmap
alias
Definition: ParticleBase.h:59
virtual int momIndex() const
get momentum index
Definition: ParticleBase.h:132
int index() const
get index
Definition: ParticleBase.h:99
virtual bool hasEnergy() const
get momentum dimension
Definition: ParticleBase.h:136
std::vector< ParticleBase * > m_daughters
daughter container
Definition: ParticleBase.h:202
TFParticleType
particle types
Definition: ParticleBase.h:30
std::string m_name
name
Definition: ParticleBase.h:215
virtual ~ParticleBase()
destructor, actually does something
Definition: ParticleBase.cc:74
void collectVertexDaughters(std::vector< ParticleBase * > &particles, int posindex)
get vertex daughters
virtual int tauIndex() const
get tau index
Definition: ParticleBase.h:129
int charge() const
get charge
Definition: ParticleBase.h:148
virtual bool hasPosition() const
get false
Definition: ParticleBase.h:139
std::vector< Constraint > constraintlist
alias
Definition: ParticleBase.h:56
const ParticleBase * mother() const
getMother() / hasMother()
Definition: ParticleBase.h:102
class to store the projected residuals and the corresponding jacobian as well as the covariance matri...
Definition: Projection.h:18