Belle II Software  release-06-02-00
DecayChain.cc
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 
10 
11 #include <algorithm>
12 #include <framework/logging/Logger.h>
13 
14 #include <analysis/VertexFitting/TreeFitter/FitParams.h>
15 #include <analysis/VertexFitting/TreeFitter/ParticleBase.h>
16 #include <analysis/VertexFitting/TreeFitter/DecayChain.h>
17 
18 
19 namespace TreeFitter {
20 
22  const ConstraintConfiguration& config,
23  bool forceFitAll
24  ) :
25  m_dim(0),
26  m_headOfChain(nullptr),
27  m_isOwner(true),
28  m_config(config)
29  {
30 
31  if (config.m_ipConstraint && config.m_customOrigin) {
32  B2FATAL("Setup error. Can't have both custom origin and ip constraint.");
33  }
34  config.m_headOfTreePDG = std::abs(particle->getPDGCode());
35  if (config.m_ipConstraint || config.m_customOrigin) {
37  config,
38  forceFitAll
39  );
40  } else if ((!config.m_customOrigin) && (!config.m_ipConstraint)) {
41 
42  m_headOfChain = ParticleBase::createParticle(particle, nullptr, config, forceFitAll);
43  }
44 
46 
47  m_cand = locate(particle);
48  }
49 
51  {
52  if (m_headOfChain && m_isOwner) {
53  delete m_headOfChain;
54  }
55  }
56 
58  {
59  m_constraintlist.clear();
62  std::sort(m_constraintlist.begin(), m_constraintlist.end());
63  }
64 
66  {
67  for (auto removeConstraint : m_config.m_removeConstraintList) {
68  m_constraintlist.erase(std::remove_if(m_constraintlist.begin(), m_constraintlist.end(),
69  [&](const Constraint & constraint) { return constraint.name() == removeConstraint ;}),
70  m_constraintlist.end());
71  }
72  }
73 
75  {
76  ErrCode status;
77  par.resetStateVector();
78  status |= m_headOfChain->initMotherlessParticle(par);
79  par.resetCovariance();
80  status |= m_headOfChain->initCovariance(par);
82  return status;
83  }
84 
86  {
87  ErrCode status;
88  par.resetCovariance();
89  status |= m_headOfChain->initCovariance(par);
90  par.resetChiSquare();
91  for (auto constraint : m_constraintlist) {
92  status |= constraint.filter(par);
93  }
94  return status;
95  }
96 
98  {
99  ErrCode status;
100  par.resetCovariance();
101  status |= m_headOfChain->initCovariance(par);
102  par.resetChiSquare();
103  for (auto constraint : m_constraintlist) {
104  status |= constraint.filterWithReference(par, ref);
105  }
106  return status;
107  }
108 
109 
110  double DecayChain::chiSquare(const FitParams& par) const
111  {
112  return m_headOfChain->chiSquare(par);
113  }
114 
116  {
117  const ParticleBase* rc(nullptr);
118  const auto mapRow = m_particleMap.find(particle) ;
119 
120  if (mapRow == m_particleMap.end()) {
121  //take head of chain and recursively find particle in it
122  rc = m_headOfChain->locate(particle);
123 
124  if (rc && rc->particle()) {
125  const_cast<DecayChain*>(this)->m_particleMap[rc->particle()] = rc;
126  }
127  } else {
128  //only used for "head of tree"
129  rc = mapRow->second;// (B2::Particle, Particlebase)
130  }
131  return rc;
132  }
133 
134  int DecayChain::index(Belle2::Particle* particle) const
135  {
136  const ParticleBase* base = locate(particle);
137  if (base) {
138  return base->index();
139  }
140  return -1;
141  }
142 
144  {
145  const ParticleBase* base = locate(particle);
146  if (base) {
147  return base->posIndex();
148  }
149  return -1;
150  }
151 
153  {
154  const ParticleBase* base = locate(particle);
155  if (base) {
156  return base->momIndex();
157  }
158  return -1;
159  }
160 
162  {
163  const ParticleBase* base = locate(particle);
164  if (base) {
165  return base->tauIndex();
166  }
167  return -1;
168  }
169 }
Class to store reconstructed particles.
Definition: Particle.h:74
const std::vector< std::string > m_removeConstraintList
list of constraints not to apply in tree fit
class to manage the order of constraints and their filtering
Definition: Constraint.h:20
this class does a lot of stuff: Build decaytree structure allowing to index particles and handle the ...
Definition: DecayChain.h:23
double chiSquare(const FitParams &par) const
get the chi2 for the head of the chain
Definition: DecayChain.cc:110
const ConstraintConfiguration m_config
config container
Definition: DecayChain.h:108
ErrCode initialize(FitParams &par)
initialize the chain
Definition: DecayChain.cc:74
int m_dim
the dimension of constraint
Definition: DecayChain.h:89
ParticleBase::constraintlist m_constraintlist
list of constraints
Definition: DecayChain.h:96
void removeConstraintFromList()
remove constraints from list
Definition: DecayChain.cc:65
void initConstraintList()
init contraintlist
Definition: DecayChain.cc:57
ParticleBase * m_headOfChain
head of decay tree
Definition: DecayChain.h:91
const ParticleBase * locate(Belle2::Particle *bc) const
convert Belle2::particle into particle base(fitter base particle)
Definition: DecayChain.cc:115
ErrCode filterWithReference(FitParams &par, const FitParams &ref)
filter with respect to a previous iteration for better stability
Definition: DecayChain.cc:97
const bool m_isOwner
internal class member to check if we own the chain
Definition: DecayChain.h:105
const ParticleBase * m_cand
fit candidate (not same to mother in case of bs/be constraint)
Definition: DecayChain.h:93
int index(Belle2::Particle *bc) const
get the particle index
Definition: DecayChain.cc:134
DecayChain()
empty constructor
Definition: DecayChain.h:28
int tauIndex(Belle2::Particle *bc) const
get tau (i.e.
Definition: DecayChain.cc:161
int momIndex() const
!NOT IMPLEMENTED
~DecayChain()
destructor
Definition: DecayChain.cc:50
ErrCode filter(FitParams &par)
filter down the chain
Definition: DecayChain.cc:85
int posIndex(Belle2::Particle *bc) const
get the vertex index of the particle in state vector
Definition: DecayChain.cc:143
ParticleMap m_particleMap
the map from Belle2::Particles to TreeFitter::ParticleBase
Definition: DecayChain.h:102
abstract errorocode be aware that the default is success
Definition: ErrCode.h:14
Class to store and manage fitparams (statevector)
Definition: FitParams.h:20
void resetStateVector()
reset the staevector
Definition: FitParams.cc:31
void resetChiSquare()
reset chi2
Definition: FitParams.h:138
void resetCovariance()
reset the staevector
Definition: FitParams.cc:36
base class for all particles
Definition: ParticleBase.h:25
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.
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
const ParticleBase * locate(Belle2::Particle *particle) const
get particle base from basf2 particle
virtual ErrCode initCovariance(FitParams &) const
init covariance matrix
virtual ErrCode initMotherlessParticle(FitParams &)=0
init particle that does not need a mother vertex
virtual double chiSquare(const FitParams &) const
get chi2