Belle II Software  release-05-02-19
Constraint.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributor: Wouter Hulsbergen, Francesco Tenchini, Jo-Frederik Krohn *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <string>
13 #include <analysis/VertexFitting/TreeFitter/ErrCode.h>
14 
15 namespace TreeFitter {
16  class ParticleBase ;
17  class Projection ;
18  class FitParams ;
19 
21  class Constraint {
22  public:
28  enum Type { unknown = 0,
29  beamenergy,
30  beamspot,
31  origin,
32  lifetime,
33  resonance,
34  composite,
35  track,
36  photon,
37  klong,
38  conversion,
39  kinematic,
40  geometric,
41  mass,
42  massEnergy,
43  merged,
44  ntypes,
45  helix
46  };
47 
49  bool operator<(const Constraint& rhs) const;
50 
52  bool operator==(const Constraint& rhs) const
53  {
54  return m_type == rhs.m_type;
55  }
56 
58  Type type() const { return m_type; }
59 
61  unsigned int dim() const { return m_dim; }
62 
64  bool isLinear() const { return m_maxNIter <= 1; }
65 
67  unsigned int nIter() const { return m_maxNIter; }
68 
70  Constraint() :
71  m_node(0),
72  m_depth(0),
73  m_type(unknown),
74  m_dim(0),
76  m_maxNIter(0) {}
77 
79  Constraint(const ParticleBase* node,
80  Type type,
81  int depth,
82  unsigned int dim,
83  int maxniter = 1) :
84  m_node(node),
85  m_depth(depth),
86  m_type(type),
88  m_weight(1),
89  m_maxNIter(maxniter) {}
90 
92  virtual ~Constraint() {}
93 
95  virtual ErrCode project(const FitParams& fitpar, Projection& p) const;
96 
98  virtual ErrCode filter(FitParams& fitpar);
99 
101  virtual ErrCode filterWithReference(FitParams& fitpar, const FitParams& oldState);
102 
104  std::string name() const;
105 
109  [[gnu::unused]] void setWeight(int w) { m_weight = w < 0 ? -1 : 1; }
110 
111  protected:
112 
114  explicit Constraint(Constraint::Type type) :
115  m_node(0),
116  m_depth(0),
118  m_dim(0),
119  m_weight(0),
120  m_maxNIter(0) {}
121 
123  void setDim(unsigned int d) { m_dim = d; }
124 
126  void setNIter(unsigned int d) { m_maxNIter = d; }
127 
128  private:
129 
132 
137  int m_depth;
138 
140  Type m_type;
141 
143  unsigned int m_dim;
144 
146  int m_weight;
147 
149  int m_maxNIter;
150  };
151 
152 }
TreeFitter::Constraint::m_maxNIter
int m_maxNIter
maximum number of iterations for non-linear constraints
Definition: Constraint.h:157
TreeFitter::Constraint::m_dim
unsigned int m_dim
dimension of constraint
Definition: Constraint.h:151
TreeFitter::Constraint::type
Type type() const
get type of constraint
Definition: Constraint.h:66
TreeFitter::Constraint::m_depth
int m_depth
chi2 coming from the constraint
Definition: Constraint.h:145
TreeFitter::Constraint::m_node
const ParticleBase * m_node
particle behind the constraint
Definition: Constraint.h:139
TreeFitter::Constraint::isLinear
bool isLinear() const
is this a linear constraint
Definition: Constraint.h:72
TreeFitter::Constraint::m_weight
int m_weight
weight of this constraint currently we set them all to unity
Definition: Constraint.h:154
TreeFitter::ParticleBase
base class for all particles
Definition: ParticleBase.h:36
TreeFitter::Constraint::Constraint
Constraint()
constructor
Definition: Constraint.h:78
TreeFitter::Constraint::filterWithReference
virtual ErrCode filterWithReference(FitParams &fitpar, const FitParams &oldState)
filter this constraint
Definition: Constraint.cc:92
TreeFitter::Constraint::Type
Type
type of constraints the order of these constraints is important: it is the order in which they are ap...
Definition: Constraint.h:36
TreeFitter::Constraint::setDim
void setDim(unsigned int d)
set dimension of cosntraint
Definition: Constraint.h:131
TreeFitter::Constraint::m_type
Type m_type
type of constraint
Definition: Constraint.h:148
TreeFitter::Constraint::dim
unsigned int dim() const
get dimension of constraint
Definition: Constraint.h:69
TreeFitter::Constraint
class to manage the order of contraints and their filtering
Definition: Constraint.h:29
TreeFitter::Constraint::setNIter
void setNIter(unsigned int d)
set max number of iterations for non lin constraint
Definition: Constraint.h:134
TreeFitter::Constraint::filter
virtual ErrCode filter(FitParams &fitpar)
filter this constraint
Definition: Constraint.cc:37
TreeFitter::Constraint::setWeight
void setWeight(int w)
used to be able to weigth the cosntraints
Definition: Constraint.h:117
TreeFitter::Constraint::project
virtual ErrCode project(const FitParams &fitpar, Projection &p) const
call the constraints projection function
Definition: Constraint.cc:32
TreeFitter::Constraint::name
std::string name() const
get name of constraint
Definition: Constraint.cc:133
TreeFitter::Constraint::operator<
bool operator<(const Constraint &rhs) const
operator used to sort the constraints
Definition: Constraint.cc:26
TreeFitter::Constraint::~Constraint
virtual ~Constraint()
destructor
Definition: Constraint.h:100
TreeFitter::Constraint::operator==
bool operator==(const Constraint &rhs) const
operator
Definition: Constraint.h:60
TreeFitter::Constraint::nIter
unsigned int nIter() const
get maximum number of iterations for non in contraint
Definition: Constraint.h:75