Belle II Software light-2406-ragdoll
TextTracer Class Reference
Inheritance diagram for TextTracer:
Collaboration diagram for TextTracer:

Public Member Functions

 TextTracer (std::ostream &os_)
 
virtual void initialize (BaseFitter &fitter) override
 Called at the start of a new fit (during initialization)
 
virtual void step (BaseFitter &fitter) override
 Called at the end of each step.
 
virtual void substep (BaseFitter &fitter, int flag) override
 Called at intermediate points during a step.
 
virtual void finish (BaseFitter &fitter) override
 Called at the end of a fit.
 
void printFitObjects (BaseFitter &fitter)
 
void printConstraints (BaseFitter &fitter)
 
void printTraceValues (const BaseFitter &fitter)
 
void printSums (BaseFitter &fitter)
 
virtual void setNextTracer (BaseTracer *next_)
 
virtual void setNextTracer (BaseTracer &next_)
 
virtual BaseTracergetNextTracer ()
 

Protected Types

typedef std::vector< BaseFitObject * > FitObjectContainer
 
typedef std::vector< BaseHardConstraint * > ConstraintContainer
 
typedef std::vector< BaseSoftConstraint * > SoftConstraintContainer
 
typedef FitObjectContainer::iterator FitObjectIterator
 
typedef ConstraintContainer::iterator ConstraintIterator
 
typedef SoftConstraintContainer::iterator SoftConstraintIterator
 

Protected Attributes

std::ostream & os
 
int istep
 
int isubstep
 
double chi2fo
 
double chi2sc
 
double sumhc
 
double sumhcscal
 
BaseTracernext
 

Detailed Description

Definition at line 45 of file TextTracer.h.

Member Typedef Documentation

◆ ConstraintContainer

typedef std::vector<BaseHardConstraint*> ConstraintContainer
protectedinherited

Definition at line 97 of file BaseTracer.h.

◆ ConstraintIterator

typedef ConstraintContainer::iterator ConstraintIterator
protectedinherited

Definition at line 101 of file BaseTracer.h.

◆ FitObjectContainer

typedef std::vector<BaseFitObject*> FitObjectContainer
protectedinherited

Definition at line 96 of file BaseTracer.h.

◆ FitObjectIterator

typedef FitObjectContainer::iterator FitObjectIterator
protectedinherited

Definition at line 100 of file BaseTracer.h.

◆ SoftConstraintContainer

typedef std::vector<BaseSoftConstraint*> SoftConstraintContainer
protectedinherited

Definition at line 98 of file BaseTracer.h.

◆ SoftConstraintIterator

typedef SoftConstraintContainer::iterator SoftConstraintIterator
protectedinherited

Definition at line 102 of file BaseTracer.h.

Constructor & Destructor Documentation

◆ TextTracer()

TextTracer ( std::ostream &  os_)
explicit

Definition at line 35 of file TextTracer.cc.

36 : os(os_),
37 istep(0), isubstep(0), chi2fo(0), chi2sc(0), sumhc(0), sumhcscal(0)
38 {}

Member Function Documentation

◆ finish()

void finish ( BaseFitter fitter)
overridevirtual

Called at the end of a fit.

Reimplemented from BaseTracer.

Definition at line 85 of file TextTracer.cc.

86 {
87
88 os << "=============== Final result ======================\n";
89 printFitObjects(fitter);
90 printConstraints(fitter);
91 printTraceValues(fitter);
92 printSums(fitter);
93
94 os << "=============== Finished fit ======================\n";
95
96
97 BaseTracer::finish(fitter);
98 }
virtual void finish(BaseFitter &fitter)
Called at the end of a fit.
Definition: BaseTracer.cc:45

◆ getNextTracer()

BaseTracer * getNextTracer ( )
virtualinherited

Definition at line 60 of file BaseTracer.cc.

61 {
62 return next;
63 }

◆ initialize()

void initialize ( BaseFitter fitter)
overridevirtual

Called at the start of a new fit (during initialization)

Reimplemented from BaseTracer.

Definition at line 43 of file TextTracer.cc.

44 {
45 os << "=============== Starting fit ======================\n";
46
47 printFitObjects(fitter);
48 printConstraints(fitter);
49 printTraceValues(fitter);
50 printSums(fitter);
51
52 istep = 1;
53 isubstep = 0;
54
56 }
virtual void initialize(BaseFitter &fitter)
Called at the start of a new fit (during initialization)
Definition: BaseTracer.cc:30

◆ printConstraints()

void printConstraints ( BaseFitter fitter)

Definition at line 112 of file TextTracer.cc.

113 {
114 chi2sc = 0;
115 sumhc = 0;
116 sumhcscal = 0;
117 ConstraintContainer* constraints = fitter.getConstraints();
118 if (constraints && constraints->size() > 0) {
119 os << "Hard Constraints:\n";
120 for (auto i = constraints->begin(); i != constraints->end(); ++i) {
121 BaseConstraint* c = *i;
122 assert(c);
123 os << i - constraints->begin() << " " << c->getName() << ": " << c->getValue() << "+-" << c->getError() << std::endl;
124 sumhc += std::fabs(c->getValue());
125 sumhcscal += std::fabs(c->getValue() / c->getError());
126 }
127 }
128 SoftConstraintContainer* softConstraints = fitter.getSoftConstraints();
129 if (softConstraints && softConstraints->size() > 0) {
130 os << "Soft Constraints:\n";
131 for (auto i = softConstraints->begin(); i != softConstraints->end(); ++i) {
132 BaseConstraint* c = *i;
133 auto* sc = dynamic_cast<BaseSoftConstraint*>(c);
134 assert(c);
135 assert(sc);
136 os << i - softConstraints->begin() << " " << c->getName() << ": " << c->getValue() << "+-" << c->getError()
137 << ", chi2=" << sc->getChi2() << std::endl;
138 chi2sc += sc->getChi2();
139 }
140 }
141 }

◆ printFitObjects()

void printFitObjects ( BaseFitter fitter)

Definition at line 100 of file TextTracer.cc.

101 {
102 chi2fo = 0;
103 FitObjectContainer* fitobjects = fitter.getFitObjects();
104 if (!fitobjects) return;
105 os << "Fit objects:\n";
106 for (auto fo : *fitobjects) {
107 assert(fo);
108 os << fo->getName() << ": " << *fo << ", chi2=" << fo->getChi2() << std::endl;
109 chi2fo += fo->getChi2();
110 }
111 }

◆ printSums()

void printSums ( BaseFitter fitter)

Definition at line 151 of file TextTracer.cc.

152 {
153 os << "Total chi2: " << fitter.getChi2()
154 << " = " << chi2fo + chi2sc << " = " << chi2fo << "(fo) + " << chi2sc << "(sc)"
155 << std::endl;
156 os << "Hard constraints: " << sumhc << ", scaled: " << sumhcscal << std::endl;
157 auto i = fitter.traceValues.find("mu");
158 if (i != fitter.traceValues.end()) {
159 double mu = i->second;
160 os << "Contribution to merit function: " << sumhc* mu << ", scaled: " << sumhcscal* mu << std::endl;
161 os << "Merit function: " << chi2fo + chi2sc + sumhc* mu << ", scaled: " << chi2fo + chi2sc + sumhcscal* mu << std::endl;
162 }
163
164 }

◆ printTraceValues()

void printTraceValues ( const BaseFitter fitter)

Definition at line 143 of file TextTracer.cc.

144 {
145 for (auto& traceValue : fitter.traceValues) {
146 std::string name = traceValue.first;
147 double value = traceValue.second;
148 os << "Value of " << name << ": " << value << std::endl;;
149 }
150 }

◆ setNextTracer() [1/2]

void setNextTracer ( BaseTracer next_)
virtualinherited

Definition at line 55 of file BaseTracer.cc.

56 {
57 next = &next_;
58 }

◆ setNextTracer() [2/2]

void setNextTracer ( BaseTracer next_)
virtualinherited

Definition at line 50 of file BaseTracer.cc.

51 {
52 next = next_;
53 }

◆ step()

void step ( BaseFitter fitter)
overridevirtual

Called at the end of each step.

Reimplemented from BaseTracer.

Definition at line 58 of file TextTracer.cc.

59 {
60 isubstep = 1;
61 os << "--------------- Step " << istep << " --------------------\n";
62
63 printFitObjects(fitter);
64 printConstraints(fitter);
65 printTraceValues(fitter);
66 printSums(fitter);
67
68 ++istep;
69 BaseTracer::step(fitter);
70 }
virtual void step(BaseFitter &fitter)
Called at the end of each step.
Definition: BaseTracer.cc:35

◆ substep()

void substep ( BaseFitter fitter,
int  flag 
)
overridevirtual

Called at intermediate points during a step.

Reimplemented from BaseTracer.

Definition at line 72 of file TextTracer.cc.

73 {
74 os << "---- Substep " << istep << "." << isubstep << " ----\n";
75
76 printFitObjects(fitter);
77 printConstraints(fitter);
78 printTraceValues(fitter);
79 printSums(fitter);
80
81 ++isubstep;
82 BaseTracer::substep(fitter, flag);
83 }
virtual void substep(BaseFitter &fitter, int flag)
Called at intermediate points during a step.
Definition: BaseTracer.cc:40

Member Data Documentation

◆ chi2fo

double chi2fo
protected

Definition at line 71 of file TextTracer.h.

◆ chi2sc

double chi2sc
protected

Definition at line 72 of file TextTracer.h.

◆ istep

int istep
protected

Definition at line 69 of file TextTracer.h.

◆ isubstep

int isubstep
protected

Definition at line 70 of file TextTracer.h.

◆ next

BaseTracer* next
protectedinherited

Definition at line 104 of file BaseTracer.h.

◆ os

std::ostream& os
protected

Definition at line 67 of file TextTracer.h.

◆ sumhc

double sumhc
protected

Definition at line 73 of file TextTracer.h.

◆ sumhcscal

double sumhcscal
protected

Definition at line 74 of file TextTracer.h.


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