Belle II Software development
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
19namespace 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) {
36 m_headOfChain = ParticleBase::createOrigin(particle, config, forceFitAll);
37 } else {
38 m_headOfChain = ParticleBase::createParticle(particle, nullptr, config, forceFitAll);
39 }
40
42
43 m_cand = locate(particle);
44 }
45
47 {
48 if (m_headOfChain && m_isOwner) {
49 delete m_headOfChain;
50 }
51 }
52
54 {
55 m_constraintlist.clear();
58 std::sort(m_constraintlist.begin(), m_constraintlist.end());
59 }
60
62 {
63 for (auto removeConstraint : m_config.m_removeConstraintList) {
64 m_constraintlist.erase(std::remove_if(m_constraintlist.begin(), m_constraintlist.end(),
65 [&](const Constraint & constraint) { return constraint.name() == removeConstraint ;}),
66 m_constraintlist.end());
67 }
68 }
69
71 {
72 ErrCode status;
73 par.resetStateVector();
75 par.resetCovariance();
76 status |= m_headOfChain->initCovariance(par);
78 return status;
79 }
80
82 {
83 ErrCode status;
84 par.resetCovariance();
85 status |= m_headOfChain->initCovariance(par);
86 par.resetChiSquare();
87 for (auto constraint : m_constraintlist) {
88 status |= constraint.filter(par);
89 }
90 return status;
91 }
92
94 {
95 ErrCode status;
96 par.resetCovariance();
97 status |= m_headOfChain->initCovariance(par);
98 par.resetChiSquare();
99 for (auto constraint : m_constraintlist) {
100 status |= constraint.filterWithReference(par, ref);
101 }
102 return status;
103 }
104
105
106 double DecayChain::chiSquare(const FitParams& par) const
107 {
108 return m_headOfChain->chiSquare(par);
109 }
110
112 {
113 const ParticleBase* rc(nullptr);
114 const auto mapRow = m_particleMap.find(particle) ;
115
116 if (mapRow == m_particleMap.end()) {
117 //take head of chain and recursively find particle in it
118 rc = m_headOfChain->locate(particle);
119
120 if (rc && rc->particle()) {
121 const_cast<DecayChain*>(this)->m_particleMap[rc->particle()] = rc;
122 }
123 } else {
124 //only used for "head of tree"
125 rc = mapRow->second;// (B2::Particle, Particlebase)
126 }
127 return rc;
128 }
129
131 {
132 const ParticleBase* base = locate(particle);
133 if (base) {
134 return base->index();
135 }
136 return -1;
137 }
138
140 {
141 const ParticleBase* base = locate(particle);
142 if (base) {
143 return base->posIndex();
144 }
145 return -1;
146 }
147
149 {
150 const ParticleBase* base = locate(particle);
151 if (base) {
152 return base->momIndex();
153 }
154 return -1;
155 }
156
158 {
159 const ParticleBase* base = locate(particle);
160 if (base) {
161 return base->tauIndex();
162 }
163 return -1;
164 }
165}
Class to store reconstructed particles.
Definition: Particle.h:75
constraint configuration class
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:106
const ConstraintConfiguration m_config
config container
Definition: DecayChain.h:108
ErrCode initialize(FitParams &par)
initialize the chain
Definition: DecayChain.cc:70
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:61
void initConstraintList()
init contraintlist
Definition: DecayChain.cc:53
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:111
ErrCode filterWithReference(FitParams &par, const FitParams &ref)
filter with respect to a previous iteration for better stability
Definition: DecayChain.cc:93
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:130
DecayChain()
empty constructor
Definition: DecayChain.h:28
int tauIndex(Belle2::Particle *bc) const
get tau (i.e.
Definition: DecayChain.cc:157
int momIndex() const
!NOT IMPLEMENTED
~DecayChain()
destructor
Definition: DecayChain.cc:46
ErrCode filter(FitParams &par)
filter down the chain
Definition: DecayChain.cc:81
int posIndex(Belle2::Particle *bc) const
get the vertex index of the particle in state vector
Definition: DecayChain.cc:139
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 statevector
Definition: FitParams.cc:31
void resetChiSquare()
reset chi2
Definition: FitParams.h:99
void resetCovariance()
reset the statevector
Definition: FitParams.cc:36
base class for all particles
Definition: ParticleBase.h:25
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.
Definition: ParticleBase.cc:84
Belle2::Particle * particle() const
get basf2 particle
Definition: ParticleBase.h:92
static ParticleBase * createOrigin(Belle2::Particle *daughter, const ConstraintConfiguration &config, bool forceFitAll)
create a custom origin particle or a beamspot
Definition: ParticleBase.cc:93
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