21 #include <Math/Minimizer.h>
25 RootMinimizerAdapter::RootMinimizerAdapter(
const MinimizerInfo& minimizerInfo)
30 RootMinimizerAdapter::~RootMinimizerAdapter() =
default;
35 rootMinimizer()->SetFunction(*m_adapter->rootObjectiveFunction(fcn, parameters));
36 return minimize(parameters);
42 rootMinimizer()->SetFunction(*m_adapter->rootResidualFunction(fcn, parameters));
43 return minimize(parameters);
48 setParameters(parameters);
51 m_status = rootMinimizer()->Minimize();
55 result.setParameters(parameters);
58 result.setNumberOfCalls(m_adapter->numberOfCalls());
59 result.setNumberOfGradientCalls(m_adapter->numberOfGradientCalls());
66 return m_minimizerInfo.name();
71 return m_minimizerInfo.algorithmName();
74 void RootMinimizerAdapter::setParameters(
const Fit::Parameters& parameters)
76 unsigned int index(0);
77 for (
const auto& par : parameters)
78 setParameter(index++, par);
83 return rootMinimizer()->MinValue();
88 return m_status ?
"Minimum found" :
"Error in solving";
93 return rootMinimizer()->ProvidesError();
98 std::map<std::string, std::string> result;
102 result[
"ProvidesError"] =
"Provides parameters error and error matrix";
104 result[
"ProvidesError"] =
"Doesn't provide error calculation";
124 Fit::Parameters::corr_matrix_t matrix;
130 matrix[i][j] = rootMinimizer()->Correlation(
static_cast<unsigned int>(i),
131 static_cast<unsigned int>(j));
133 parameters.setCorrelationMatrix(matrix);
137 void RootMinimizerAdapter::setParameter(
unsigned int index,
const Fit::Parameter& par)
140 if (par.limits().isFixed()) {
141 success = rootMinimizer()->SetFixedVariable(index, par.name().c_str(), par.value());
145 else if (par.limits().isLimited()) {
146 success = rootMinimizer()->SetLimitedVariable(index, par.name().c_str(), par.value(),
147 par.step(), par.limits().lowerLimit(),
148 par.limits().upperLimit());
151 else if (par.limits().isLowerLimited()) {
152 success = rootMinimizer()->SetLowerLimitedVariable(index, par.name().c_str(), par.value(),
153 par.step(), par.limits().lowerLimit());
156 else if (par.limits().isUpperLimited()) {
157 success = rootMinimizer()->SetUpperLimitedVariable(index, par.name().c_str(), par.value(),
158 par.step(), par.limits().upperLimit());
161 else if (par.limits().isLimitless()) {
162 success = rootMinimizer()->SetVariable(index, par.name().c_str(), par.value(), par.step());
166 throw std::runtime_error(
"BasicMinimizer::setParameter() -> Error! Unexpected parameter.");
170 std::ostringstream ostr;
171 ostr <<
"BasicMinimizer::setParameter() -> Error! Can't set minimizer's fit parameter";
172 ostr <<
"Index:" << index <<
" name '" << par.name() <<
"'";
173 throw std::runtime_error(ostr.str());
181 return rootMinimizer()->NDim();
188 std::vector<double> result;
190 std::copy(rootMinimizer()->X(), rootMinimizer()->X() +
fitDimension(), result.begin());
198 std::vector<double> result;
200 if (rootMinimizer()->Errors() != 0) {
201 std::copy(rootMinimizer()->Errors(), rootMinimizer()->Errors() +
fitDimension(),
207 RootMinimizerAdapter::root_minimizer_t* RootMinimizerAdapter::rootMinimizer()
209 return const_cast<root_minimizer_t*
>(
Declares MinimizerResultUtils namespace.
Declares class ObjectiveFunctionAdapter.
Declares class RootMinimizerAdapter.
Declares class RootResidualFunction.
Defines classes RootScalarFunction.
Defines a few helper functions.
Result of minimization round.
Converts user objective function to function ROOT expects.
A fittable parameter with value, error, step, and limits.
A collection of fit parameters.
Info about a minimizer, including list of defined minimization algorithms.
void setOptionString(const std::string &options)
Set options from their string representation.
Pure virtual interface that adapts the CERN ROOT minimizer to our IMinimizer.
Fit::MinimizerResult minimize_scalar(fcn_scalar_t fcn, Fit::Parameters parameters) override
run minimization
size_t fitDimension() const
Returns number of fit parameters defined (i.e. dimension of the function to be minimized).
std::string minimizerName() const override final
Returns name of the minimizer.
virtual std::string statusToString() const
Returns string representation of current minimizer status.
std::string algorithmName() const override final
Returns name of the minimization algorithm.
double minValue() const override final
Returns minimum function value.
void propagateResults(Fit::Parameters ¶meters)
Propagates results of minimization to fit parameter set.
virtual std::map< std::string, std::string > statusMap() const
Returns map of string representing different minimizer statuses.
std::vector< double > parErrorsAtMinimum() const
Returns errors of the variables at minimum.
void setOptions(const std::string &optionString) override final
Sets option string to the minimizer.
std::vector< double > parValuesAtMinimum() const
Returns value of the variables at minimum.
bool providesError() const
Returns true if minimizer provides error and error matrix.
Objective function types.
std::string reportToString(const RootMinimizerAdapter &minimizer)
Reports results of minimization in the form of multi-line string.
std::string scientific(const T value, int n=10)
Returns scientific string representing given value of any numeric type.