17#include "analysis/OrcaKinFit/TextTracer.h"
18#include "analysis/OrcaKinFit/BaseFitter.h"
19#include "analysis/OrcaKinFit/BaseFitObject.h"
20#include "analysis/OrcaKinFit/BaseConstraint.h"
21#include "analysis/OrcaKinFit/BaseHardConstraint.h"
22#include "analysis/OrcaKinFit/BaseSoftConstraint.h"
33 namespace OrcaKinFit {
35 TextTracer::TextTracer(std::ostream& os_)
37 istep(0), isubstep(0), chi2fo(0), chi2sc(0), sumhc(0), sumhcscal(0)
40 TextTracer::~TextTracer() =
default;
45 os <<
"=============== Starting fit ======================\n";
47 printFitObjects(fitter);
48 printConstraints(fitter);
49 printTraceValues(fitter);
55 BaseTracer::initialize(fitter);
61 os <<
"--------------- Step " << istep <<
" --------------------\n";
63 printFitObjects(fitter);
64 printConstraints(fitter);
65 printTraceValues(fitter);
69 BaseTracer::step(fitter);
74 os <<
"---- Substep " << istep <<
"." << isubstep <<
" ----\n";
76 printFitObjects(fitter);
77 printConstraints(fitter);
78 printTraceValues(fitter);
82 BaseTracer::substep(fitter, flag);
88 os <<
"=============== Final result ======================\n";
89 printFitObjects(fitter);
90 printConstraints(fitter);
91 printTraceValues(fitter);
94 os <<
"=============== Finished fit ======================\n";
97 BaseTracer::finish(fitter);
100 void TextTracer::printFitObjects(
BaseFitter& fitter)
103 FitObjectContainer* fitobjects = fitter.getFitObjects();
104 if (!fitobjects)
return;
105 os <<
"Fit objects:\n";
106 for (
auto fo : *fitobjects) {
108 os << fo->getName() <<
": " << *fo <<
", chi2=" << fo->getChi2() << std::endl;
109 chi2fo += fo->getChi2();
112 void TextTracer::printConstraints(BaseFitter& fitter)
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;
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());
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);
136 os << i - softConstraints->begin() <<
" " << c->getName() <<
": " << c->getValue() <<
"+-" << c->getError()
137 <<
", chi2=" << sc->getChi2() << std::endl;
138 chi2sc += sc->getChi2();
143 void TextTracer::printTraceValues(
const BaseFitter& fitter)
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;;
151 void TextTracer::printSums(BaseFitter& fitter)
153 os <<
"Total chi2: " << fitter.getChi2()
154 <<
" = " << chi2fo + chi2sc <<
" = " << chi2fo <<
"(fo) + " << chi2sc <<
"(sc)"
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;
Abstract base class for fitting engines of kinematic fits.
Abstract base class for different kinds of events.