Belle II Software development
MergedConstraint Class Reference

Merge multiple constraints that we want to project simultaneously. More...

#include <MergedConstraint.h>

Inheritance diagram for MergedConstraint:
Constraint

Public Types

typedef std::vector< Constraint * > constraintlist
 typedef of a list of constraints
 
enum  Type {
  unknown = 0 ,
  beamenergy ,
  beamspot ,
  beam ,
  origin ,
  lifetime ,
  resonance ,
  composite ,
  track ,
  photon ,
  klong ,
  conversion ,
  kinematic ,
  geometric ,
  mass ,
  massEnergy ,
  merged ,
  ntypes ,
  helix
}
 type of constraints the order of these constraints is important: it is the order in which they are applied. More...
 

Public Member Functions

 MergedConstraint ()
 empty constructor
 
virtual ~MergedConstraint ()
 destructor
 
 MergedConstraint (const constraintlist &list)
 constructor with constraint list
 
virtual ErrCode project (const FitParams &fitpar, Projection &p) const override
 project the constraints
 
void push_back (Constraint *c)
 push back a new constraint
 
bool operator< (const Constraint &rhs) const
 operator used to sort the constraints
 
bool operator== (const Constraint &rhs) const
 operator
 
Type type () const
 get type of constraint
 
unsigned int dim () const
 get dimension of constraint
 
bool isLinear () const
 is this a linear constraint
 
unsigned int nIter () const
 get maximum number of iterations for non in constraint
 
virtual ErrCode filter (FitParams &fitpar)
 filter this constraint
 
virtual ErrCode filterWithReference (FitParams &fitpar, const FitParams &oldState)
 filter this constraint
 
std::string name () const
 get name of constraint

 
void setWeight (int w)
 used to be able to weight the constraints
 

Protected Member Functions

void setDim (unsigned int d)
 set dimension of constraint
 
void setNIter (unsigned int d)
 set max number of iterations for non lin constraint

 

Private Attributes

constraintlist m_list
 list of the constraints to merge
 
const ParticleBasem_node
 particle behind the constraint

 
int m_depth
 chi2 coming from the constraint
 
Type m_type
 type of constraint
 
unsigned int m_dim
 dimension of constraint
 
int m_weight
 weight of this constraint currently we set them all to unity

 
int m_maxNIter
 maximum number of iterations for non-linear constraints

 

Detailed Description

Merge multiple constraints that we want to project simultaneously.

As of release-00-08-00 this causes issues when referencing, see DecayChain.cc

Definition at line 18 of file MergedConstraint.h.

Member Typedef Documentation

◆ constraintlist

typedef std::vector<Constraint*> constraintlist

typedef of a list of constraints

Definition at line 21 of file MergedConstraint.h.

Member Enumeration Documentation

◆ Type

enum Type
inherited

type of constraints the order of these constraints is important: it is the order in which they are applied.

Definition at line 27 of file Constraint.h.

27 { unknown = 0,
28 beamenergy,
29 beamspot,
30 beam,
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 };

Constructor & Destructor Documentation

◆ MergedConstraint() [1/2]

MergedConstraint ( )
inline

empty constructor

Definition at line 24 of file MergedConstraint.h.

24: Constraint(Constraint::merged) {}
Constraint()
constructor
Definition: Constraint.h:70

◆ ~MergedConstraint()

virtual ~MergedConstraint ( )
inlinevirtual

destructor

Definition at line 26 of file MergedConstraint.h.

26{}

◆ MergedConstraint() [2/2]

MergedConstraint ( const constraintlist list)
inlineexplicit

constructor with constraint list

Definition at line 28 of file MergedConstraint.h.

28 :
29 Constraint(Constraint::merged), m_list(list)
30 {
31 int d = 0;
32 for (constraintlist::iterator it = m_list.begin() ;
33 it != m_list.end(); ++it) d += (*it)->dim() ;
34 setDim(d) ;
35 }
void setDim(unsigned int d)
set dimension of constraint
Definition: Constraint.h:123
constraintlist m_list
list of the constraints to merge

Member Function Documentation

◆ dim()

unsigned int dim ( ) const
inlineinherited

get dimension of constraint

Definition at line 61 of file Constraint.h.

61{ return m_dim; }
unsigned int m_dim
dimension of constraint
Definition: Constraint.h:143

◆ filter()

ErrCode filter ( FitParams fitpar)
virtualinherited

filter this constraint

We don't have reference state yet so we use the k-1 last state to linearize non-linear constraints

Definition at line 28 of file Constraint.cc.

29 {
34 ErrCode status;
35 Projection p(fitpar.getDimensionOfState(), m_dim);
36 KalmanCalculator kalman(m_dim, fitpar.getDimensionOfState());
37
38 double chisq(0);
39 int iter(0);
40 bool finished(false) ;
41
42 double accumulated_chi2 = 0;
43 while (!finished && !status.failure()) {
44
45 p.resetProjection();
46 status |= project(fitpar, p);
47
48 if (!status.failure()) {
49
50 status |= kalman.calculateGainMatrix(
51 p.getResiduals(),
52 p.getH(),
53 fitpar,
54 &p.getV(),
55 1
56 );
57
58 if (!status.failure()) {
59 kalman.updateState(fitpar);
60
61 // r R^-1 r
62 double newchisq = kalman.getChiSquare();
63
64 double dchisqconverged = 0.001 ;
65
66 double dchisq = newchisq - chisq;
67 bool diverging = iter > 0 && dchisq > 0;
68 bool converged = std::abs(dchisq) < dchisqconverged;
69 finished = ++iter >= m_maxNIter || diverging || converged;
70 chisq = newchisq;
71 accumulated_chi2 += newchisq;
72 }
73 }
74 }
75
76 const unsigned int number_of_constraints = kalman.getConstraintDim();
77 fitpar.addChiSquare(accumulated_chi2, number_of_constraints);
78
79 kalman.updateCovariance(fitpar);
80 return status;
81 }
int m_maxNIter
maximum number of iterations for non-linear constraints
Definition: Constraint.h:149
virtual ErrCode project(const FitParams &fitpar, Projection &p) const
call the constraints projection function
Definition: Constraint.cc:23

◆ filterWithReference()

ErrCode filterWithReference ( FitParams fitpar,
const FitParams oldState 
)
virtualinherited

filter this constraint

We now linearise around the last iteration $\alpha$ (const FitParams& oldState) In this implementation we can no longer linearize non-linear constraints but we ensured by the linearisation around the last state that the step size is small enough so we just use them as if they were linear

here we project the old state and use only the change with respect to the new state instead of the new state in the update . the advantage is more stable fit Downside: non-linear constraints can't be filtered multiple times anymore.

Definition at line 83 of file Constraint.cc.

84 {
91 ErrCode status;
92 Projection p(fitpar.getDimensionOfState(), m_dim);
93 KalmanCalculator kalman(m_dim, fitpar.getDimensionOfState());
94
95 p.resetProjection();
96 status |= project(oldState, p);
97
102 p.getResiduals() += p.getH() * (fitpar.getStateVector() - oldState.getStateVector());
103 if (!status.failure()) {
104 status |= kalman.calculateGainMatrix(
105 p.getResiduals(),
106 p.getH(),
107 fitpar,
108 &p.getV(),
109 1
110 );
111
112 if (!status.failure()) {
113 kalman.updateState(fitpar);
114 }
115 }
116
117 const unsigned int number_of_constraints = kalman.getConstraintDim();
118 fitpar.addChiSquare(kalman.getChiSquare(), number_of_constraints);
119
120 kalman.updateCovariance(fitpar);
121 return status;
122 }

◆ isLinear()

bool isLinear ( ) const
inlineinherited

is this a linear constraint

Definition at line 64 of file Constraint.h.

64{ return m_maxNIter <= 1; }

◆ name()

std::string name ( ) const
inherited

get name of constraint

Definition at line 124 of file Constraint.cc.

125 {
126 std::string rc = "unknown constraint!";
127 switch (m_type) {
128 case beamspot: rc = "beamspot"; break;
129 case beamenergy: rc = "beamenergy"; break;
130 case beam: rc = "beam"; break;
131 case origin: rc = "origin"; break;
132 case composite: rc = "composite"; break;
133 case resonance: rc = "resonance"; break;
134 case track: rc = "track"; break;
135 case photon: rc = "photon"; break;
136 case klong: rc = "klong"; break;
137 case kinematic: rc = "kinematic"; break;
138 case geometric: rc = "geometric"; break;
139 case mass: rc = "mass"; break;
140 case massEnergy: rc = "massEnergy"; break;
141 case lifetime: rc = "lifetime"; break;
142 case merged: rc = "merged"; break;
143 case conversion: rc = "conversion"; break;
144 case helix: rc = "helix"; break;
145 case ntypes:
146 case unknown:
147 break;
148 }
149 return rc;
150 }
Type m_type
type of constraint
Definition: Constraint.h:140

◆ nIter()

unsigned int nIter ( ) const
inlineinherited

get maximum number of iterations for non in constraint

Definition at line 67 of file Constraint.h.

67{ return m_maxNIter; }

◆ operator<()

bool operator< ( const Constraint rhs) const
inherited

operator used to sort the constraints

Definition at line 17 of file Constraint.cc.

18 {
19 return m_depth < rhs.m_depth ||
20 (m_depth == rhs.m_depth && m_type < rhs.m_type);
21 }
int m_depth
chi2 coming from the constraint
Definition: Constraint.h:137

◆ operator==()

bool operator== ( const Constraint rhs) const
inlineinherited

operator

Definition at line 52 of file Constraint.h.

53 {
54 return m_type == rhs.m_type;
55 }

◆ project()

ErrCode project ( const FitParams fitpar,
Projection p 
) const
overridevirtual

project the constraints

Reimplemented from Constraint.

Definition at line 19 of file MergedConstraint.cc.

20 {
21 ErrCode status ;
22 for (auto element : m_list) {
23 status |= element->project(fitpar, p) ;
24 p.incrementOffset(element->dim()) ;
25 }
26 return status ;
27 }

◆ push_back()

void push_back ( Constraint c)
inline

push back a new constraint

Definition at line 43 of file MergedConstraint.h.

44 {
45 m_list.push_back(c) ;
46 setDim(dim() + c->dim()) ;
47 setNIter(std::max(nIter(), c->nIter())) ;
48 }
unsigned int dim() const
get dimension of constraint
Definition: Constraint.h:61
void setNIter(unsigned int d)
set max number of iterations for non lin constraint
Definition: Constraint.h:126
unsigned int nIter() const
get maximum number of iterations for non in constraint
Definition: Constraint.h:67

◆ setDim()

void setDim ( unsigned int  d)
inlineprotectedinherited

set dimension of constraint

Definition at line 123 of file Constraint.h.

123{ m_dim = d; }

◆ setNIter()

void setNIter ( unsigned int  d)
inlineprotectedinherited

set max number of iterations for non lin constraint

Definition at line 126 of file Constraint.h.

126{ m_maxNIter = d; }

◆ setWeight()

void setWeight ( int  w)
inlineinherited

used to be able to weight the constraints

Definition at line 109 of file Constraint.h.

109{ m_weight = w < 0 ? -1 : 1; }
int m_weight
weight of this constraint currently we set them all to unity
Definition: Constraint.h:146

◆ type()

Type type ( ) const
inlineinherited

get type of constraint

Definition at line 58 of file Constraint.h.

58{ return m_type; }

Member Data Documentation

◆ m_depth

int m_depth
privateinherited

chi2 coming from the constraint

depth of the constraint in the tree (determines for example the order of the track constraints)

Definition at line 137 of file Constraint.h.

◆ m_dim

unsigned int m_dim
privateinherited

dimension of constraint

Definition at line 143 of file Constraint.h.

◆ m_list

constraintlist m_list
private

list of the constraints to merge

Definition at line 53 of file MergedConstraint.h.

◆ m_maxNIter

int m_maxNIter
privateinherited

maximum number of iterations for non-linear constraints

Definition at line 149 of file Constraint.h.

◆ m_node

const ParticleBase* m_node
privateinherited

particle behind the constraint

Definition at line 131 of file Constraint.h.

◆ m_type

Type m_type
privateinherited

type of constraint

Definition at line 140 of file Constraint.h.

◆ m_weight

int m_weight
privateinherited

weight of this constraint currently we set them all to unity

Definition at line 146 of file Constraint.h.


The documentation for this class was generated from the following files: