62 if (prevErrorIgnoreLevel < 1001) {
64 return prevErrorIgnoreLevel;
87 : Minimizer(), fDim(0), fMinimizer(nullptr), fMinuitFCN(nullptr), fMinimum(nullptr)
97 std::string algoname(
type);
99 std::transform(algoname.begin(), algoname.end(), algoname.begin(), (
int (*)(
int))tolower);
102 if (algoname ==
"simplex")
104 if (algoname ==
"minimize")
106 if (algoname ==
"scan")
108 if (algoname ==
"fumili" || algoname ==
"fumili2")
110 if (algoname ==
"bfgs")
193 print.
Info(
"Parameter",
name,
"has zero or invalid step size - consider it as constant");
199 if (minuit2Index != ivar) {
200 print.
Warn(
"Wrong index", minuit2Index,
"used for the variable",
name);
230 double lower,
double upper)
244 double step = (val != 0) ? 0.1 * std::abs(val) : 0.1;
256 return std::string();
282 for (
unsigned int ivar = 0; ivar <
n; ++ivar)
349 print.
Error(
"Wrong variable index");
360 print.
Error(
"Wrong variable index");
395 print.
Error(
"Wrong Fit method function for Fumili");
404 print.
Error(
"Wrong Fit method function for Fumili");
434 auto customize = [&minuit2Opt](
const char *
name,
auto val) {
439 st.SetGradientNCycles(customize(
"GradientNCycles",
int(st.GradientNCycles())));
440 st.SetHessianNCycles(customize(
"HessianNCycles",
int(st.HessianNCycles())));
441 st.SetHessianGradientNCycles(customize(
"HessianGradientNCycles",
int(st.HessianGradientNCycles())));
443 st.SetGradientTolerance(customize(
"GradientTolerance", st.GradientTolerance()));
444 st.SetGradientStepTolerance(customize(
"GradientStepTolerance", st.GradientStepTolerance()));
445 st.SetHessianStepTolerance(customize(
"HessianStepTolerance", st.HessianStepTolerance()));
446 st.SetHessianG2Tolerance(customize(
"HessianG2Tolerance", st.HessianG2Tolerance()));
461 print.
Error(
"FCN function has not been set");
474 const int strategyLevel =
Strategy();
480 int maxfcn_used = maxfcn;
481 if (maxfcn_used == 0) {
483 maxfcn_used = 200 + 100 * nvar + 5 * nvar * nvar;
485 std::cout <<
"Minuit2Minimizer: Minimize with max-calls " << maxfcn_used <<
" convergence for edm < " << tol
486 <<
" strategy " << strategyLevel << std::endl;
507 int storageLevel = 1;
508 bool ret = minuit2Opt->
GetValue(
"StorageLevel", storageLevel);
512 if (printLevel > 0) {
513 std::cout <<
"Minuit2Minimizer::Minuit - Changing default options" << std::endl;
522 if (printLevel == 10 &&
gROOT) {
530 if (printLevel == 20 || printLevel == 30 || printLevel == 40 || (printLevel >= 20000 && printLevel < 30000)) {
531 int parNumber = printLevel - 20000;
532 if (printLevel == 20)
534 if (printLevel == 30)
536 if (printLevel == 40)
541 if (printLevel == 100 || (printLevel >= 10000 && printLevel < 20000)) {
542 int parNumber = printLevel - 10000;
553 if (gradFCN !=
nullptr) {
596 if (debugLevel >= 3) {
598 const std::vector<ROOT::Minuit2::MinimumState> &iterationStates = min.
States();
599 std::cout <<
"Number of iterations " << iterationStates.size() << std::endl;
600 for (
unsigned int i = 0; i < iterationStates.size(); ++i) {
603 std::cout <<
"----------> Iteration " << i << std::endl;
604 int pr = std::cout.precision(12);
605 std::cout <<
" FVAL = " << st.
Fval() <<
" Edm = " << st.
Edm() <<
" Nfcn = " << st.
NFcn()
607 std::cout.precision(pr);
609 std::cout <<
" Error matrix change = " << st.
Error().
Dcovar() << std::endl;
611 std::cout <<
" Parameters : ";
613 for (
int j = 0; j < st.
size(); ++j)
615 std::cout << std::endl;
625 txt =
"Covar is not pos def";
629 txt =
"Covar was made pos def";
633 txt =
"Hesse is not valid";
637 txt =
"Edm is above max";
641 txt =
"Reached call limit";
645 MnPrint print(
"Minuit2Minimizer::Minimize", debugLevel);
646 bool validMinimum = min.
IsValid();
650 if (
fStatus != 0 && debugLevel > 0)
656 txt =
"unknown failure";
659 print.
Warn(
"Minimization did NOT converge,", txt);
667 if (paramsObj.empty())
669 assert(
fDim == paramsObj.size());
673 for (
unsigned int i = 0; i <
fDim; ++i) {
674 fValues[i] = paramsObj[i].Value();
687 std::cout <<
"Minuit2Minimizer : Valid minimum - status = " <<
fStatus << std::endl;
688 int pr = std::cout.precision(18);
689 std::cout <<
"FVAL = " <<
fState.
Fval() << std::endl;
690 std::cout <<
"Edm = " <<
fState.
Edm() << std::endl;
691 std::cout.precision(pr);
692 std::cout <<
"Nfcn = " <<
fState.
NFcn() << std::endl;
695 std::cout << par.
Name() <<
"\t = " << par.
Value() <<
"\t ";
697 std::cout <<
"(fixed)" << std::endl;
699 std::cout <<
"(const)" << std::endl;
701 std::cout <<
"+/- " << par.
Error() <<
"\t(limited)" << std::endl;
703 std::cout <<
"+/- " << par.
Error() << std::endl;
706 std::cout <<
"Minuit2Minimizer : Invalid minimum - status = " <<
fStatus << std::endl;
707 std::cout <<
"FVAL = " <<
fState.
Fval() << std::endl;
708 std::cout <<
"Edm = " <<
fState.
Edm() << std::endl;
709 std::cout <<
"Nfcn = " <<
fState.
NFcn() << std::endl;
717 if (paramsObj.empty())
719 assert(
fDim == paramsObj.size());
724 for (
unsigned int i = 0; i <
fDim; ++i) {
756 for (
unsigned int i = 0; i <
fDim; ++i) {
758 for (
unsigned int j = 0; j <
fDim; ++j) {
759 cov[i *
fDim + j] = 0;
763 for (
unsigned int j = 0; j <
fDim; ++j) {
765 int k = i *
fDim + j;
786 for (
unsigned int i = 0; i <
fDim; ++i) {
788 for (
unsigned int j = 0; j <
fDim; ++j) {
789 hess[i *
fDim + j] = 0;
793 for (
unsigned int j = 0; j <
fDim; ++j) {
795 int k = i *
fDim + j;
873 print.
Error(
"Failed - no function minimum existing");
878 print.
Error(
"Failed - invalid function minimum");
891 if ((mstatus & 8) != 0) {
892 print.
Info([&](std::ostream &os) {
893 os <<
"Found a new minimum: run again the Minimization starting from the new point";
896 os <<
'\n' << par.Name() <<
"\t = " << par.Value();
905 print.
Info(
"Run now again Minos from the new found Minimum");
915 bool isValid = ((mstatus & 1) == 0) && ((mstatus & 2) == 0);
922 bool runLower = runopt != 2;
923 bool runUpper = runopt != 1;
947 tol = std::max(tol, 0.01);
950 int maxfcn_used = maxfcn;
951 if (maxfcn_used == 0) {
953 maxfcn_used = 2 * (nvar + 1) * (200 + 100 * nvar + 5 * nvar * nvar);
957 if (debugLevel >= 1) {
958 std::cout <<
"************************************************************************************************"
960 std::cout <<
"Minuit2Minimizer::GetMinosError - Run MINOS LOWER error for parameter #" << i <<
" : "
961 << par_name <<
" using max-calls " << maxfcn_used <<
", tolerance " << tol << std::endl;
963 low = minos.
Loval(i, maxfcn, tol);
966 if (debugLevel >= 1) {
967 std::cout <<
"************************************************************************************************"
969 std::cout <<
"Minuit2Minimizer::GetMinosError - Run MINOS UPPER error for parameter #" << i <<
" : "
970 << par_name <<
" using max-calls " << maxfcn_used <<
", tolerance " << tol << std::endl;
972 up = minos.
Upval(i, maxfcn, tol);
989 if (debugLevel > 0) {
992 std::cout <<
"Minos: Invalid lower error for parameter " << par_name << std::endl;
994 std::cout <<
"Minos: Parameter : " << par_name <<
" is at Lower limit; error is " << me.
Lower()
997 std::cout <<
"Minos: Maximum number of function calls exceeded when running for lower error for parameter "
998 << par_name << std::endl;
1000 std::cout <<
"Minos: New Minimum found while running Minos for lower error for parameter " << par_name
1004 std::cout <<
"Minos: Lower error for parameter " << par_name <<
" : " << me.
Lower() << std::endl;
1008 std::cout <<
"Minos: Invalid upper error for parameter " << par_name << std::endl;
1010 std::cout <<
"Minos: Parameter " << par_name <<
" is at Upper limit; error is " << me.
Upper() << std::endl;
1012 std::cout <<
"Minos: Maximum number of function calls exceeded when running for upper error for parameter "
1013 << par_name << std::endl;
1015 std::cout <<
"Minos: New Minimum found while running Minos for upper error for parameter " << par_name
1019 std::cout <<
"Minos: Upper error for parameter " << par_name <<
" : " << me.
Upper() << std::endl;
1024 bool lowerInvalid = (runLower && !me.
LowerValid());
1025 bool upperInvalid = (runUpper && !me.
UpperValid());
1042 if (lowerInvalid || upperInvalid) {
1068 errLow = me.
Lower();
1094 print.
Error(
"Function must be set before using Scan");
1099 print.
Error(
"Invalid number; minimizer variables must be set before using Scan");
1112 double amin = scan.
Fval();
1115 std::vector<std::pair<double, double>>
result = scan(ipar, nstep - 1,
xmin,
xmax);
1118 if (prev_level > -2)
1122 if (
result.size() != nstep) {
1123 print.
Error(
"Invalid result from MnParameterScan");
1129 for (
unsigned int i = 0; i < nstep; ++i) {
1136 if (scan.
Fval() < amin) {
1137 print.
Info(
"A new minimum has been found");
1152 print.
Error(
"No function minimum existing; must minimize function before");
1157 print.
Error(
"Invalid function minimum");
1182 if (prev_level > -2)
1187 std::vector<std::pair<double, double>>
result = contour(ipar, jpar, npoints);
1188 if (
result.size() != npoints) {
1189 print.
Error(
"Invalid result from MnContours");
1192 for (
unsigned int i = 0; i < npoints; ++i) {
1210 print.
Error(
"FCN function has not been set");
1215 print.
Info(
"Using max-calls", maxfcn);
1248 if (prev_level > -2)
1253 std::cout <<
"Minuit2Minimizer::Hesse - State returned from Hesse " << std::endl;
1254 std::cout <<
fState << std::endl;
1258 std::string covStatusType =
"not valid";
1260 covStatusType =
"approximate";
1262 covStatusType =
"full but made positive defined";
1264 covStatusType =
"accurate";
1266 covStatusType =
"full but not positive defined";
1282 print.
Warn(
"Hesse failed - matrix is", covStatusType);
1283 print.
Warn(hstatus);
1289 print.
Info(
"Hesse is valid - matrix is", covStatusType);
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Int_t gErrorIgnoreLevel
Error handling routines.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
void Set(const std::string &name, double value, double step)
set value and name (unlimited parameter)
void SetLimits(double low, double up)
set a double side limit, if low == up the parameter is fixed if low > up the limits are removed The c...
void SetUpperLimit(double up)
set a single upper limit
void Fix()
fix the parameter
void SetLowerLimit(double low)
set a single lower limit
FitMethodFunction class Interface for objective functions (like chi2 and likelihood used in the fit) ...
Documentation for the abstract class IBaseFunctionMultiDim.
virtual bool HasGradient() const
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Generic interface for defining configuration options of a numerical algorithm.
bool GetValue(const char *name, T &t) const
virtual void Print(std::ostream &=std::cout) const
print options
const IOptions * ExtraOptions() const
return extra options (NULL pointer if they are not present)
static ROOT::Math::IOptions * FindDefault(const char *name)
Find an extra options and return a nullptr if it is not existing.
double Tolerance() const
absolute tolerance
unsigned int MaxFunctionCalls() const
max number of function calls
double Precision() const
precision of minimizer in the evaluation of the objective function ( a value <=0 corresponds to the l...
int fStatus
status of minimizer
int Strategy() const
strategy
double ErrorDef() const
return the statistical scale used for calculate the error is typically 1 for Chi2 and 0....
MinimizerOptions fOptions
minimizer options
bool IsValidError() const
return true if Minimizer has performed a detailed error validation (e.g. run Hesse for Minuit)
int PrintLevel() const
minimizer configuration parameters
Combined minimizer: combination of Migrad and Simplex.
template wrapped class for adapting to FCNBase signature
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
virtual void SetErrorDef(double)
add interface to set dynamically a new error definition Re-implement this function if needed.
template wrapped class for adapting to FCNBase signature a IGradFunction
void SetHessianFunction(Func f)
template wrapped class for adapting to FumiliFCNBase signature
Instantiates the seed generator and Minimum builder for the Fumili minimization method.
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
const std::vector< MinimumState > & States() const
const MinimumError & Error() const
bool HasAccurateCovar() const
bool HasReachedCallLimit() const
const MnUserParameterState & UserState() const
const MinimumState & State() const
bool HasMadePosDefCovar() const
bool IsAboveMaxEdm() const
bool HasValidCovariance() const
bool HasPosDefCovar() const
bool HasCovariance() const
void SetErrorDef(double up)
virtual void SetStorageLevel(int level)
virtual void SetPrintLevel(int level)
virtual void SetTraceObject(MnTraceObject &obj)
bool InvertFailed() const
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
bool HasParameters() const
const MinimumError & Error() const
const MnAlgebraicVector & Vec() const
bool HasCovariance() const
Class holding the result of Minos (lower and upper values) for a specific parameter.
bool AtUpperLimit() const
bool AtLowerMaxFcn() const
bool AtUpperMaxFcn() const
bool AtLowerLimit() const
Minuit2Minimizer class implementing the ROOT::Math::Minimizer interface for Minuit2 minimization algo...
bool ExamineMinimum(const ROOT::Minuit2::FunctionMinimum &min)
examine the minimum result
Minuit2Minimizer(ROOT::Minuit2::EMinimizerType type=ROOT::Minuit2::kMigrad)
Default constructor.
void SetStorageLevel(int level)
set storage level = 1 : store all iteration states (default) = 0 : store only first and last state to...
Minuit2Minimizer & operator=(const Minuit2Minimizer &rhs)
Assignment operator.
std::vector< double > fValues
bool SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double, double) override
set upper/lower limited variable (override if minimizer supports them )
bool Contour(unsigned int i, unsigned int j, unsigned int &npoints, double *xi, double *xj) override
find the contour points (xi,xj) of the function for parameter i and j around the minimum The contour ...
bool IsFixedVariable(unsigned int ivar) const override
query if an existing variable is fixed (i.e.
bool SetVariableUpperLimit(unsigned int ivar, double upper) override
set the upper-limit of an already existing variable
double GlobalCC(unsigned int i) const override
get global correlation coefficient for the variable i.
bool SetVariableValues(const double *val) override
set the values of all existing variables (array must be dimensioned to the size of the existing param...
bool SetVariable(unsigned int ivar, const std::string &name, double val, double step) override
set free variable
virtual const ROOT::Minuit2::FCNBase * GetFCN() const
const double * Errors() const override
return errors at the minimum
void SetFunction(const ROOT::Math::IMultiGenFunction &func) override
set the function to minimize
bool SetVariableStepSize(unsigned int ivar, double step) override
set the step size of an already existing variable
bool GetCovMatrix(double *cov) const override
Fill the passed array with the covariance matrix elements if the variable is fixed or const the value...
bool ReleaseVariable(unsigned int ivar) override
release an existing variable
void SetHessianFunction(std::function< bool(const std::vector< double > &, double *)> hfunc) override
set the function implementing Hessian computation
bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings &varObj) const override
get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
bool Hesse() override
perform a full calculation of the Hessian matrix for error calculation If a valid minimum exists the ...
std::vector< double > fErrors
ROOT::Minuit2::ModularFunctionMinimizer * fMinimizer
bool GetMinosError(unsigned int i, double &errLow, double &errUp, int=0) override
get the minos error for parameter i, return false if Minos failed A minimizaiton must be performed be...
std::string VariableName(unsigned int ivar) const override
get name of variables (override if minimizer support storing of variable names)
int RunMinosError(unsigned int i, double &errLow, double &errUp, int runopt)
bool SetVariableLimits(unsigned int ivar, double lower, double upper) override
set the limits of an already existing variable
double Correlation(unsigned int i, unsigned int j) const override
return correlation coefficient between variable i and j.
bool SetLowerLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double lower) override
set lower limit variable (override if minimizer supports them )
void SetTraceObject(MnTraceObject &obj)
set an object to trace operation for each iteration The object must be a (or inherit from) ROOT::Minu...
virtual const ROOT::Minuit2::ModularFunctionMinimizer * GetMinimizer() const
double CovMatrix(unsigned int i, unsigned int j) const override
return covariance matrix elements if the variable is fixed or const the value is zero The ordering of...
void SetMinimizerType(ROOT::Minuit2::EMinimizerType type)
bool SetVariableValue(unsigned int ivar, double val) override
set variable
bool Scan(unsigned int i, unsigned int &nstep, double *x, double *y, double xmin=0, double xmax=0) override
scan a parameter i around the minimum.
int VariableIndex(const std::string &name) const override
get index of variable given a variable given a name return -1 if variable is not found
bool SetUpperLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double upper) override
set upper limit variable (override if minimizer supports them )
ROOT::Minuit2::MnUserParameterState fState
bool SetVariableLowerLimit(unsigned int ivar, double lower) override
set the lower-limit of an already existing variable
bool FixVariable(unsigned int ivar) override
fix an existing variable
virtual void SetMinimizer(ROOT::Minuit2::ModularFunctionMinimizer *m)
bool Minimize() override
method to perform the minimization.
ROOT::Minuit2::FunctionMinimum * fMinimum
bool SetFixedVariable(unsigned int, const std::string &, double) override
set fixed variable (override if minimizer supports them )
bool GetHessianMatrix(double *h) const override
Fill the passed array with the Hessian matrix elements The Hessian matrix is the matrix of the second...
ROOT::Minuit2::FCNBase * fMinuitFCN
void PrintResults() override
return reference to the objective function virtual const ROOT::Math::IGenFunction & Function() const;
void Clear() override
reset for consecutive minimization - implement if needed
~Minuit2Minimizer() override
Destructor (no operations)
int CovMatrixStatus() const override
return the status of the covariance matrix status = -1 : not available (inversion failed or Hesse fai...
class for the individual Minuit Parameter with Name and number; contains the input numbers for the mi...
double LowerLimit() const
double UpperLimit() const
const char * Name() const
bool HasLowerLimit() const
bool HasUpperLimit() const
API class for Contours Error analysis (2-dim errors); minimization has to be done before and Minimum ...
const MnUserParameterState & State() const
const std::vector< double > & GlobalCC() const
API class for calculating the numerical covariance matrix (== 2x Inverse Hessian == 2x Inverse 2nd de...
API class for Minos Error analysis (asymmetric errors); minimization has to be done before and Minimu...
MnCross Loval(unsigned int, unsigned int maxcalls=0, double toler=0.1) const
MnCross Upval(unsigned int, unsigned int maxcalls=0, double toler=0.1) const
Scans the values of FCN as a function of one Parameter and retains the best function and Parameter va...
const MnUserParameters & Parameters() const
void Error(const Ts &... args)
void Info(const Ts &... args)
static int SetGlobalLevel(int level)
void Warn(const Ts &... args)
API class for defining four levels of strategies: low (0), medium (1), high (2), very high (>=3); act...
virtual void Init(const MnUserParameterState &state)
class which holds the external user and/or internal Minuit representation of the parameters and error...
void SetLimits(unsigned int, double, double)
const MnUserParameters & Parameters() const
double Value(unsigned int) const
void RemoveLimits(unsigned int)
unsigned int NFcn() const
unsigned int Index(const std::string &) const
const std::string & GetName(unsigned int) const
double Int2ext(unsigned int, double) const
const MnGlobalCorrelationCoeff & GlobalCC() const
void Release(unsigned int)
unsigned int VariableParameters() const
const MinuitParameter & Parameter(unsigned int i) const
void SetValue(unsigned int, double)
void Add(const std::string &name, double val, double err)
const char * Name(unsigned int) const
MnUserCovariance Hessian() const
const std::vector< ROOT::Minuit2::MinuitParameter > & MinuitParameters() const
facade: forward interface of MnUserParameters and MnUserTransformation
void SetPrecision(double eps)
unsigned int IntOfExt(unsigned int) const
const MnUserTransformation & Trafo() const
void SetUpperLimit(unsigned int, double)
const MnUserCovariance & IntCovariance() const
const MnUserCovariance & Covariance() const
int CovarianceStatus() const
void SetError(unsigned int, double)
void SetLowerLimit(unsigned int, double)
bool HasCovariance() const
double Value(unsigned int) const
virtual const MinimumBuilder & Builder() const =0
FunctionMinimum Minimize(const FCNBase &, const std::vector< double > &, const std::vector< double > &, unsigned int stra=1, unsigned int maxfcn=0, double toler=0.1) const override
Class implementing the required methods for a minimization using SCAN API is provided in the upper RO...
Class implementing the required methods for a minimization using Simplex.
Instantiates the SeedGenerator and MinimumBuilder for Variable Metric Minimization method.
Mother of all ROOT objects.
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Namespace for new Math classes and functions.
void RestoreGlobalPrintLevel(int)
int TurnOffPrintInfoLevel()
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...