1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-10 08:55:37 +00:00

improvement of Minuit minimizer

This commit is contained in:
Antonin Portelli 2014-09-18 17:18:51 +01:00
parent d70d84862d
commit 36ef20c929
2 changed files with 17 additions and 12 deletions

View File

@ -25,6 +25,7 @@
#include <Minuit2/MnPrint.h>
#include <Minuit2/MnPlot.h>
#include <Minuit2/MnScan.h>
#include <Minuit2/MnSimplex.h>
#include <Minuit2/ScanMinimizer.h>
#include <Minuit2/SimplexMinimizer.h>
#include <Minuit2/VariableMetricMinimizer.h>
@ -34,6 +35,9 @@ using namespace ROOT;
using namespace Minuit2;
using namespace Latan;
static constexpr double initErr = 0.5;
static constexpr unsigned int maxTry = 10u;
/******************************************************************************
* MinuitMinimizer implementation *
******************************************************************************/
@ -71,12 +75,12 @@ const DVec & MinuitMinimizer::operator()(const DoubleFunction &f)
for (Index i = 0; i < x.size(); ++i)
{
parameters.Add("x_" + strFrom(i), x(i), 0.1*fabs(x(i)));
parameters.Add("x_" + strFrom(i), x(i), initErr*fabs(x(i)));
}
// pre-minimization
MnMigrad migrad1(minuitF, parameters, 1);
FunctionMinimum min = migrad1();
MnSimplex preMinimizer(minuitF, parameters, 0);
FunctionMinimum min = preMinimizer();
if (verbosity >= Verbosity::Debug)
{
@ -85,16 +89,17 @@ const DVec & MinuitMinimizer::operator()(const DoubleFunction &f)
cout << "--------------------------------------------------------";
cout << endl;
}
for (unsigned int i = 0; i < x.size(); ++i)
{
parameters.SetValue(i, min.UserParameters().Value(i));
parameters.SetError(i, min.UserParameters().Error(i));
}
parameters = preMinimizer.Parameters();
// minimization and output
MnMigrad migrad2(minuitF, parameters, 2);
MnMigrad minimizer(minuitF, parameters, 2);
unsigned int iTry = 0;
min = migrad2();
while ((!min.IsValid())&&(iTry < maxTry))
{
min = minimizer();
iTry++;
}
if (!min.IsValid())
{
LATAN_WARNING("MINUIT library reported that minimization result is not valid");

View File

@ -48,8 +48,8 @@ private:
const DoubleFunction *f_;
};
public:
// constructors
using Minimizer::Minimizer;
// constructor
MinuitMinimizer(void) = default;
// destructor
virtual ~MinuitMinimizer(void) = default;
// minimization