126 fMinimizer = std::make_unique<ROOT::Minuit2::FumiliMinimizer>();
131 fMinimizer = std::make_unique<ROOT::Minuit2::VariableMetricMinimizer>();
159 print.
Info(
"Parameter",
name,
"has zero or invalid step size - consider it as constant");
181 std::vector<double>
cov(
n * (
n + 1) / 2);
183 for (
unsigned int i = 0; i <
n; i++) {
184 for (
unsigned int j = i;
j <
n;
j++)
185 cov[i +
j * (
j + 1) / 2] = (i ==
j) ?
d2[i] : 0.;
235 double step = (val != 0) ? 0.1 * std::abs(val) : 0.1;
247 return std::string();
340 print.
Error(
"Wrong variable index");
351 print.
Error(
"Wrong variable index");
377 auto lambdaFunc = [&func](
double const *params) {
return func(params); };
392 print.
Error(
"Wrong Fit method function for Fumili");
395 fMinuitFCN = std::make_unique<ROOT::Minuit2::FumiliFCNAdapter<ROOT::Math::FitMethodGradFunction>>(*
fcnfunc,
fDim,
402 print.
Error(
"Wrong Fit method function for Fumili");
406 std::make_unique<ROOT::Minuit2::FumiliFCNAdapter<ROOT::Math::FitMethodFunction>>(*
fcnfunc,
fDim,
ErrorDef());
425 fcn->SetSecondDerivativeAlwaysVanishesFunc(std::move(func));
446 st.SetGradientNCycles(
customize(
"GradientNCycles",
int(
st.GradientNCycles())));
447 st.SetHessianNCycles(
customize(
"HessianNCycles",
int(
st.HessianNCycles())));
448 st.SetHessianGradientNCycles(
customize(
"HessianGradientNCycles",
int(
st.HessianGradientNCycles())));
450 st.SetGradientTolerance(
customize(
"GradientTolerance",
st.GradientTolerance()));
451 st.SetGradientStepTolerance(
customize(
"GradientStepTolerance",
st.GradientStepTolerance()));
452 st.SetHessianStepTolerance(
customize(
"HessianStepTolerance",
st.HessianStepTolerance()));
453 st.SetHessianG2Tolerance(
customize(
"HessianG2Tolerance",
st.HessianG2Tolerance()));
456 st.SetHessianCentralFDMixedDerivatives(
457 customize(
"HessianCentralFDMixedDerivatives",
int(
st.HessianCentralFDMixedDerivatives())));
458 st.SetHessianForcePosDef(
customize(
"HessianForcePosDef",
int(
st.HessianForcePosDef())));
479 print.
Error(
"FCN function has not been set");
502 std::cout <<
"Minuit2Minimizer: Minimize with max-calls " <<
maxfcn_used <<
" convergence for edm < " <<
tol
541 std::cout <<
"Minuit2Minimizer::Minuit - Changing default options" << std::endl;
581 fMinimum = std::make_unique<ROOT::Minuit2::FunctionMinimum>(min);
618 std::span<const ROOT::Minuit2::MinimumState>
iterationStates = min.States();
619 std::cout <<
"Number of iterations " <<
iterationStates.size() << std::endl;
623 std::cout <<
"----------> Iteration " << i << std::endl;
624 int pr = std::cout.precision(12);
625 std::cout <<
" FVAL = " <<
st.Fval() <<
" Edm = " <<
st.Edm() <<
" Nfcn = " <<
st.NFcn()
627 std::cout.precision(
pr);
628 if (
st.HasCovariance())
629 std::cout <<
" Error matrix change = " <<
st.Error().Dcovar() << std::endl;
630 if (
st.HasParameters()) {
631 std::cout <<
" Parameters : ";
633 for (
int j = 0;
j <
st.size(); ++
j)
635 std::cout << std::endl;
642 if (!min.HasPosDefCovar()) {
645 txt =
"Covar is not pos def";
648 if (min.HasMadePosDefCovar()) {
649 txt =
"Covar was made pos def";
652 if (min.HesseFailed()) {
653 txt =
"Hesse is not valid";
656 if (min.IsAboveMaxEdm()) {
657 txt =
"Edm is above max";
660 if (min.HasReachedCallLimit()) {
661 txt =
"Reached call limit";
676 txt =
"unknown failure";
679 print.
Warn(
"Minimization did NOT converge,",
txt);
693 for (
unsigned int i = 0; i <
fDim; ++i) {
707 std::cout <<
"Minuit2Minimizer : Valid minimum - status = " <<
fStatus << std::endl;
708 int pr = std::cout.precision(18);
709 std::cout <<
"FVAL = " <<
fState.
Fval() << std::endl;
710 std::cout <<
"Edm = " <<
fState.
Edm() << std::endl;
711 std::cout.precision(
pr);
712 std::cout <<
"Nfcn = " <<
fState.
NFcn() << std::endl;
715 std::cout << par.
Name() <<
"\t = " << par.
Value() <<
"\t ";
717 std::cout <<
"(fixed)" << std::endl;
719 std::cout <<
"(const)" << std::endl;
721 std::cout <<
"+/- " << par.
Error() <<
"\t(limited)" << std::endl;
723 std::cout <<
"+/- " << par.
Error() << std::endl;
726 std::cout <<
"Minuit2Minimizer : Invalid minimum - status = " <<
fStatus << std::endl;
727 std::cout <<
"FVAL = " <<
fState.
Fval() << std::endl;
728 std::cout <<
"Edm = " <<
fState.
Edm() << std::endl;
729 std::cout <<
"Nfcn = " <<
fState.
NFcn() << std::endl;
744 for (
unsigned int i = 0; i <
fDim; ++i) {
776 for (
unsigned int i = 0; i <
fDim; ++i) {
778 for (
unsigned int j = 0;
j <
fDim; ++
j) {
783 for (
unsigned int j = 0;
j <
fDim; ++
j) {
785 int k = i *
fDim +
j;
812 for (
unsigned int i = 0; i <
fDim; ++i) {
814 for (
unsigned int j = 0;
j <
fDim; ++
j) {
819 for (
unsigned int j = 0;
j <
fDim; ++
j) {
821 int k = i *
fDim +
j;
863 std::vector<double> out;
869 for (
unsigned int i = 0; i <
fDim; ++i) {
905 print.
Error(
"Failed - no function minimum existing");
910 print.
Error(
"Failed - invalid function minimum");
924 print.
Info([&](std::ostream &os) {
925 os <<
"Found a new minimum: run again the Minimization starting from the new point";
928 os <<
'\n' << par.Name() <<
"\t = " << par.Value();
937 print.
Info(
"Run now again Minos from the new found Minimum");
979 tol = std::max(
tol, 0.01);
985 maxfcn_used = 2 * (nvar + 1) * (200 + 100 * nvar + 5 * nvar * nvar);
990 std::cout <<
"************************************************************************************************"
992 std::cout <<
"Minuit2Minimizer::GetMinosError - Run MINOS LOWER error for parameter #" << i <<
" : "
999 std::cout <<
"************************************************************************************************"
1001 std::cout <<
"Minuit2Minimizer::GetMinosError - Run MINOS UPPER error for parameter #" << i <<
" : "
1024 std::cout <<
"Minos: Invalid lower error for parameter " <<
par_name << std::endl;
1026 std::cout <<
"Minos: Parameter : " <<
par_name <<
" is at Lower limit; error is " << me.
Lower()
1029 std::cout <<
"Minos: Maximum number of function calls exceeded when running for lower error for parameter "
1032 std::cout <<
"Minos: New Minimum found while running Minos for lower error for parameter " <<
par_name
1036 std::cout <<
"Minos: Lower error for parameter " <<
par_name <<
" : " << me.
Lower() << std::endl;
1040 std::cout <<
"Minos: Invalid upper error for parameter " <<
par_name << std::endl;
1042 std::cout <<
"Minos: Parameter " <<
par_name <<
" is at Upper limit; error is " << me.
Upper() << std::endl;
1044 std::cout <<
"Minos: Maximum number of function calls exceeded when running for upper error for parameter "
1047 std::cout <<
"Minos: New Minimum found while running Minos for upper error for parameter " <<
par_name
1051 std::cout <<
"Minos: Upper error for parameter " <<
par_name <<
" : " << me.
Upper() << std::endl;
1060 print.
Warn(
"Invalid lower error for parameter",
fMinimum->UserState().Name(i));
1063 print.
Warn(
"Invalid upper error for parameter",
fMinimum->UserState().Name(i));
1067 print.
Warn(
"Lower error for parameter",
fMinimum->UserState().Name(i),
"is at the Lower limit!");
1070 print.
Warn(
"Upper error for parameter",
fMinimum->UserState().Name(i),
"is at the Upper limit!");
1126 print.
Error(
"Function must be set before using Scan");
1131 print.
Error(
"Invalid number; minimizer variables must be set before using Scan");
1155 print.
Error(
"Invalid result from MnParameterScan");
1161 for (
unsigned int i = 0; i <
nstep; ++i) {
1169 print.
Info(
"A new minimum has been found");
1184 print.
Error(
"No function minimum existing; must minimize function before");
1189 print.
Error(
"Invalid function minimum");
1200 print.
Info(
"Computing contours at level -",
ErrorDef());
1221 print.
Error(
"Invalid result from MnContours");
1224 for (
unsigned int i = 0; i <
npoints; ++i) {
1228 print.
Info([&](std::ostream &os) {
1230 for (
unsigned int i = 0; i <
npoints; i++) {
1231 if (i %5 == 0) os << std::endl;
1232 os <<
"( " <<
x[i] <<
", " <<
y[i] <<
") ";
1234 os << std::endl << std::endl;
1250 print.
Error(
"FCN function has not been set");
1293 std::cout <<
"Minuit2Minimizer::Hesse - State returned from Hesse " << std::endl;
1294 std::cout <<
fState << std::endl;
1314 if (
fMinimum->Error().HesseFailed())
1316 if (
fMinimum->Error().InvertFailed())
1318 else if (!(
fMinimum->Error().IsPosDef()))
1347 else if (
fMinimum->HasMadePosDefCovar())
1349 else if (
fMinimum->HasValidCovariance())
1351 else if (
fMinimum->HasCovariance())
1372 fMinimizer->Builder().SetStorageLevel(level);
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Int_t gErrorIgnoreLevel
errors with level below this value will be ignored. Default is kUnset.
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...
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.
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.
int fStatus
status of minimizer
int Strategy() const
Strategy.
MinimizerOptions fOptions
minimizer options
bool IsValidError() const
int PrintLevel() const
Set print level.
Adapter class to wrap user-provided functions into the FCNBase interface.
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) ...
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
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
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...
std::vector< double > fValues
bool SetCovariance(std::span< const double > cov, unsigned int nrow) override
set initial covariance matrix
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 ...
virtual bool SetCovarianceDiag(std::span< const double > d2, unsigned int n) override
set initial second derivatives
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
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
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
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
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)
std::unique_ptr< ROOT::Minuit2::ModularFunctionMinimizer > fMinimizer
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
void SetSecondDerivativeAlwaysVanishesFunc(std::function< bool(unsigned int, unsigned int)> func)
Set a predicate advertising which mixed second derivatives of the minimized function are identically ...
void SetHessianFunction(std::function< bool(std::span< const double >, double *)> hfunc) override
set the function implementing Hessian computation
bool Minimize() override
method to perform the minimization.
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...
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)
std::vector< double > GlobalCC() const override
get global correlation coefficient for the variable i.
void SetFCN(unsigned int nDim, std::unique_ptr< ROOT::Minuit2::FCNBase > fcn)
To set the function directly to a Minuit 2 function.
int CovMatrixStatus() const override
return the status of the covariance matrix status = -1 : not available (inversion failed or Hesse fai...
std::unique_ptr< ROOT::Minuit2::FCNBase > fMinuitFCN
std::unique_ptr< ROOT::Minuit2::FunctionMinimum > fMinimum
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
class for global correlation coefficient
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 Debug(const Ts &... args)
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...
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
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
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
void AddCovariance(const MnUserCovariance &)
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
const_iterator begin() const
const_iterator end() const
Mother of all ROOT objects.
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
void RestoreGlobalPrintLevel(int)
int TurnOffPrintInfoLevel()