19#include "analysis/OrcaKinFit/IterationScanner.h"
21#include "analysis/OrcaKinFit/BaseFitter.h"
22#include "analysis/OrcaKinFit/NewFitterGSL.h"
23#include "analysis/OrcaKinFit/BaseFitObject.h"
24#include "analysis/OrcaKinFit/BaseHardConstraint.h"
25#include <framework/logging/Logger.h>
30#include <gsl/gsl_vector.h>
43 namespace OrcaKinFit {
45 IterationScanner::IterationScanner(BaseFitter& fitter_)
49 void IterationScanner::doScan(
int xglobal,
58 const char* titleprefix)
61 NewFitterGSL* newfitter =
dynamic_cast<NewFitterGSL*
>(&fitter);
63 FitObjectContainer* fitobjects = fitter.getFitObjects();
64 if (fitobjects == 0)
return;
65 ConstraintContainer* constraints = fitter.getConstraints();
66 if (constraints == 0)
return;
68 FitObjectContainer fitobjects_backup(fitobjects->size());
69 for (
unsigned int i = 0; i < fitobjects->size(); ++i) {
70 BaseFitObject* fo = (*fitobjects)[i];
72 fitobjects_backup[i] = fo->copy();
80 for (FitObjectIterator i = fitobjects->begin(); i != fitobjects->end(); ++i) {
81 BaseFitObject* fo = *i;
83 for (
int ilocal = 0; ilocal < fo->getNPar(); ++ilocal) {
84 int iglobal = fo->getGlobalParNum(ilocal);
85 if (iglobal >= idim) idim = iglobal + 1;
86 if (iglobal == xglobal) xname = fo->getParamName(ilocal);
87 if (iglobal == yglobal) yname = fo->getParamName(ilocal);
90 for (ConstraintIterator i = constraints->begin(); i != constraints->end(); ++i) {
91 BaseHardConstraint* c = *i;
93 int iglobal = c->getGlobalNum();
94 if (iglobal >= idim) idim = iglobal + 1;
97 if (xglobal >= idim)
return;
98 if (yglobal >= idim)
return;
100 double* parsave =
new double [idim];
101 double* par =
new double [idim];
104 for (FitObjectIterator i = fitobjects->begin(); i != fitobjects->end(); ++i) {
105 BaseFitObject* fo = *i;
107 for (
int ilocal = 0; ilocal < fo->getNPar(); ++ilocal) {
108 int iglobal = fo->getGlobalParNum(ilocal);
109 assert(iglobal >= 0 && iglobal < idim);
110 parsave[iglobal] = fo->getParam(ilocal);
116 TString idpostfix(
"");
117 idpostfix += xglobal;
119 idpostfix += yglobal;
121 TString titlepostfix(
" vs ");
122 titlepostfix += xname;
123 titlepostfix +=
" and ";
124 titlepostfix += yname;
126 titlepostfix += xname;
128 titlepostfix += yname;
132 TString id(idprefix);
136 TString title(titleprefix);
137 title +=
"Iterations ";
138 title += titlepostfix;
140 TH2F* hnit =
new TH2F(
id, title, nx, xstart, xstop, ny, ystart, ystop);
141 B2INFO(
"Booking Histo '" <<
id <<
"': '" << title <<
"'");
146 for (
int ix = 1; ix <= nx; ++ix) {
147 double x = (ix - 0.5) * (xstop - xstart) / nx + xstart;
148 for (
int iy = 1; iy <= ny; ++iy) {
149 double y = (iy - 0.5) * (ystop - ystart) / ny + ystart;
152 for (
int i = 0; i < idim; ++i) par[i] = parsave[i];
155 for (FitObjectIterator i = fitobjects->begin(); i != fitobjects->end(); ++i) {
156 BaseFitObject* fo = *i;
158 fo->updateParams(par, idim);
161 for (
unsigned int i = 0; i < fitobjects->size(); ++i) {
162 BaseFitObject* fo = (*fitobjects)[i];
163 BaseFitObject* fobu = fitobjects_backup[i];
166 for (
int j = 0; j < fobu->getNPar(); ++j) {
167 for (
int k = 0; k < fobu->getNPar(); ++k) {
168 fo->setCov(j, k, fobu->getCov(j, k));
175 double fprob = fitter.fit();
176 double nit = fitter.getIterations();
178 B2INFO(
"IterationScanner::doScan: x=" << x);
179 if (newfitter) B2INFO(
" -> " << gsl_vector_get(newfitter->x, xglobal));
181 if (newfitter) B2INFO(
" -> " << gsl_vector_get(newfitter->x, yglobal));
182 B2INFO(
", fitprob=" << fprob <<
", nit=" << nit);
185 hnit->SetBinContent(ix, iy, nit);
192 for (
unsigned int i = 0; i < fitobjects_backup.size(); ++i) {
193 delete fitobjects_backup[i];
Abstract base class for different kinds of events.