62 if (prevErrorIgnoreLevel < 1001) {
64 return prevErrorIgnoreLevel;
102 std::string algoname(type);
104 std::transform(algoname.begin(), algoname.end(), algoname.begin(), (int(*)(int)) tolower );
107 if (algoname ==
"simplex") algoType =
kSimplex;
108 if (algoname ==
"minimize" ) algoType =
kCombined;
109 if (algoname ==
"scan" ) algoType =
kScan;
110 if (algoname ==
"fumili" ) algoType =
kFumili;
167 if (
this == &rhs)
return *
this;
193 std::string txtmsg =
"Parameter " + name +
" has zero or invalid step size - consider it as constant ";
200 unsigned int minuit2Index =
fState.
Index(name.c_str() );
201 if ( minuit2Index != ivar) {
202 std::string txtmsg(
"Wrong index used for the variable " + name);
204 MN_INFO_VAL2(
"Minuit2Minimizer::SetVariable",minuit2Index);
215 if (!
SetVariable(ivar, name, val, step) )
return false;
222 if (!
SetVariable(ivar, name, val, step) )
return false;
231 if (!
SetVariable(ivar, name, val, step) )
return false;
240 double step = ( val != 0) ? 0.1 * std::abs(val) : 0.1;
272 if (n== 0)
return false;
273 for (
unsigned int ivar = 0; ivar <
n; ++ivar)
366 MN_ERROR_MSG(
"Minuit2Minimizer: Wrong Fit method function for Fumili");
384 MN_ERROR_MSG(
"Minuit2Minimizer: Wrong Fit method function for Fumili");
395 MN_ERROR_MSG2(
"Minuit2Minimizer::Minimize",
"FCN function has not been set");
412 if (printLevel >=1) {
414 int maxfcn_used = maxfcn;
415 if (maxfcn_used == 0) {
417 maxfcn_used = 200 + 100*nvar + 5*nvar*nvar;
419 std::cout <<
"Minuit2Minimizer: Minimize with max-calls " << maxfcn_used
420 <<
" convergence for edm < " << tol <<
" strategy " 421 << strategyLevel << std::endl;
448 minuit2Opt->
GetValue(
"GradientNCycles",nGradCycles);
449 minuit2Opt->
GetValue(
"HessianNCycles",nHessCycles);
450 minuit2Opt->
GetValue(
"HessianGradientNCycles",nHessGradCycles);
452 minuit2Opt->
GetValue(
"GradientTolerance",gradTol);
453 minuit2Opt->
GetValue(
"GradientStepTolerance",gradStepTol);
454 minuit2Opt->
GetValue(
"HessianStepTolerance",hessStepTol);
455 minuit2Opt->
GetValue(
"HessianG2Tolerance",hessG2Tol);
466 int storageLevel = 1;
467 bool ret = minuit2Opt->
GetValue(
"StorageLevel",storageLevel);
470 if (printLevel > 0) {
471 std::cout <<
"Minuit2Minimizer::Minuit - Changing default options" << std::endl;
481 #ifdef USE_ROOT_ERROR 482 if (printLevel == 10 &&
gROOT) {
483 TObject * obj =
gROOT->FindObject(
"Minuit2TraceObject");
490 if (printLevel == 20 || printLevel == 30 || printLevel == 40 || (printLevel >= 20000 && printLevel < 30000) ) {
491 int parNumber = printLevel-20000;
492 if (printLevel == 20) parNumber = -1;
493 if (printLevel == 30) parNumber = -2;
494 if (printLevel == 40) parNumber = 0;
498 if (printLevel == 100 || (printLevel >= 10000 && printLevel < 20000)) {
499 int parNumber = printLevel-10000;
534 if (traceObj) {
delete traceObj; }
543 if (debugLevel >= 3) {
545 const std::vector<ROOT::Minuit2::MinimumState>& iterationStates = min.
States();
546 std::cout <<
"Number of iterations " << iterationStates.size() << std::endl;
547 for (
unsigned int i = 0; i < iterationStates.size(); ++i) {
550 std::cout <<
"----------> Iteration " << i << std::endl;
551 int pr = std::cout.precision(12);
552 std::cout <<
" FVAL = " << st.
Fval() <<
" Edm = " << st.
Edm() <<
" Nfcn = " << st.
NFcn() << std::endl;
553 std::cout.precision(pr);
555 std::cout <<
" Error matrix change = " << st.
Error().
Dcovar() << std::endl;
557 std::cout <<
" Parameters : ";
559 for (
int j = 0; j < st.
size() ; ++j) std::cout <<
" p" << j <<
" = " <<
fState.
Int2ext( j, st.
Vec()(j) );
560 std::cout << std::endl;
568 txt =
"Covar was made pos def";
572 txt =
"Hesse is not valid";
576 txt =
"Edm is above max";
580 txt =
"Reached call limit";
585 bool validMinimum = min.
IsValid();
594 txt =
"unknown failure";
597 std::string msg =
"Minimization did NOT converge, " + txt;
611 std::cout <<
"Minuit2Minimizer : Valid minimum - status = " <<
fStatus << std::endl;
612 int pr = std::cout.precision(18);
613 std::cout <<
"FVAL = " <<
fState.
Fval() << std::endl;
614 std::cout <<
"Edm = " <<
fState.
Edm() << std::endl;
615 std::cout.precision(pr);
616 std::cout <<
"Nfcn = " <<
fState.
NFcn() << std::endl;
619 std::cout << par.
Name() <<
"\t = " << par.
Value() <<
"\t ";
620 if (par.
IsFixed() ) std::cout <<
"(fixed)" << std::endl;
621 else if (par.
IsConst() ) std::cout <<
"(const)" << std::endl;
623 std::cout <<
"+/- " << par.
Error() <<
"\t(limited)"<< std::endl;
625 std::cout <<
"+/- " << par.
Error() << std::endl;
629 std::cout <<
"Minuit2Minimizer : Invalid Minimum - status = " <<
fStatus << std::endl;
630 std::cout <<
"FVAL = " <<
fState.
Fval() << std::endl;
631 std::cout <<
"Edm = " <<
fState.
Edm() << std::endl;
632 std::cout <<
"Nfcn = " <<
fState.
NFcn() << std::endl;
639 if (paramsObj.size() == 0)
return 0;
640 assert(
fDim == paramsObj.size());
644 for (
unsigned int i = 0; i <
fDim; ++i) {
645 fValues[i] = paramsObj[i].Value();
655 if (paramsObj.size() == 0)
return 0;
656 assert(
fDim == paramsObj.size());
660 for (
unsigned int i = 0; i <
fDim; ++i) {
674 if ( i >=
fDim || j >=
fDim)
return 0;
686 for (
unsigned int i = 0; i <
fDim; ++i) {
688 for (
unsigned int j = 0; j <
fDim; ++j) { cov[i*fDim + j] = 0; }
693 for (
unsigned int j = 0; j <
fDim; ++j) {
714 for (
unsigned int i = 0; i <
fDim; ++i) {
716 for (
unsigned int j = 0; j <
fDim; ++j) { hess[i*fDim + j] = 0; }
720 for (
unsigned int j = 0; j <
fDim; ++j) {
741 if ( i >=
fDim || j >=
fDim)
return 0;
749 if (tmp > 0 )
return cij/tmp;
758 if ( i >=
fDim )
return 0;
772 errLow = 0; errUp = 0;
773 bool runLower = runopt != 2;
774 bool runUpper = runopt != 1;
793 MN_ERROR_MSG(
"Minuit2Minimizer::GetMinosErrors: failed - no function minimum existing");
798 MN_ERROR_MSG(
"Minuit2Minimizer::MINOS failed due to invalid function minimum");
827 tol = std::max(tol, 0.01);
831 int maxfcn_used = maxfcn;
832 if (maxfcn_used == 0) {
834 maxfcn_used = 2*(nvar+1)*(200 + 100*nvar + 5*nvar*nvar);
836 std::cout <<
"Minuit2Minimizer::GetMinosError for parameter " << i <<
" " << par_name
837 <<
" using max-calls " << maxfcn_used <<
", tolerance " << tol << std::endl;
841 if (runLower) low = minos.
Loval(i,maxfcn,tol);
842 if (runUpper) up = minos.
Upval(i,maxfcn,tol);
855 if (debugLevel >= 1) {
857 if (!me.LowerValid() )
858 std::cout <<
"Minos: Invalid lower error for parameter " << par_name << std::endl;
859 if(me.AtLowerLimit())
860 std::cout <<
"Minos: Parameter : " << par_name <<
" is at Lower limit."<<std::endl;
861 if(me.AtLowerMaxFcn())
862 std::cout <<
"Minos: Maximum number of function calls exceeded when running for lower error" <<std::endl;
863 if(me.LowerNewMin() )
864 std::cout <<
"Minos: New Minimum found while running Minos for lower error" <<std::endl;
866 if (debugLevel > 1) std::cout <<
"Minos: Lower error for parameter " << par_name <<
" : " << me.Lower() << std::endl;
870 if (!me.UpperValid() )
871 std::cout <<
"Minos: Invalid upper error for parameter " << par_name << std::endl;
872 if(me.AtUpperLimit())
873 std::cout <<
"Minos: Parameter " << par_name <<
" is at Upper limit."<<std::endl;
874 if(me.AtUpperMaxFcn())
875 std::cout <<
"Minos: Maximum number of function calls exceeded when running for upper error" <<std::endl;
876 if(me.UpperNewMin() )
877 std::cout <<
"Minos: New Minimum found while running Minos for upper error" <<std::endl;
879 if (debugLevel > 1) std::cout <<
"Minos: Upper error for parameter " << par_name <<
" : " << me.Upper() << std::endl;
884 bool lowerInvalid = (runLower && !me.LowerValid() );
885 bool upperInvalid = (runUpper && !me.UpperValid() );
887 if (lowerInvalid || upperInvalid ) {
895 if (me.AtLowerMaxFcn() ) mstatus |= 4;
896 if (me.LowerNewMin() ) mstatus |= 8;
900 if (me.AtUpperMaxFcn() ) mstatus |= 4;
901 if (me.UpperNewMin() ) mstatus |= 8;
910 bool isValid = (runLower && me.LowerValid() ) || (runUpper && me.UpperValid() );
921 MN_ERROR_MSG2(
"Minuit2Minimizer::Scan",
" Function must be set before using Scan");
926 MN_ERROR_MSG2(
"Minuit2Minimizer::Scan",
" Invalid number. Minimizer variables must be set before using Scan");
940 double amin = scan.
Fval();
943 std::vector<std::pair<double, double> > result = scan(ipar, nstep-1, xmin, xmax);
947 if (result.size() != nstep) {
948 MN_ERROR_MSG2(
"Minuit2Minimizer::Scan",
" Invalid result from MnParameterScan");
952 std::sort(result.begin(), result.end() );
955 for (
unsigned int i = 0; i < nstep; ++i ) {
956 x[i] = result[i].first;
957 y[i] = result[i].second;
962 if (scan.Fval() < amin ) {
963 MN_INFO_MSG2(
"Minuit2Minimizer::Scan",
"A new minimum has been found");
976 MN_ERROR_MSG2(
"Minuit2Minimizer::Contour",
" no function minimum existing. Must minimize function before");
981 MN_ERROR_MSG2(
"Minuit2Minimizer::Contour",
"Invalid function minimum");
1010 std::vector<std::pair<double,double> > result = contour(ipar,jpar, npoints);
1011 if (result.size() != npoints) {
1012 MN_ERROR_MSG2(
"Minuit2Minimizer::Contour",
" Invalid result from MnContours");
1015 for (
unsigned int i = 0; i < npoints; ++i ) {
1016 x[i] = result[i].first;
1017 y[i] = result[i].second;
1036 MN_ERROR_MSG2(
"Minuit2Minimizer::Hesse",
"FCN function has not been set");
1077 std::cout <<
"Minuit2Minimizer::Hesse - State returned from Hesse " << std::endl;
1078 std::cout <<
fState << std::endl;
1082 std::string covStatusType =
"not valid";
1083 if (covStatus == 1) covStatusType =
"approximate";
1084 if (covStatus == 2) covStatusType =
"full but made positive defined";
1085 if (covStatus == 3) covStatusType =
"accurate";
1098 std::string msg =
"Hesse failed - matrix is " + covStatusType;
1106 std::string msg =
"Hesse is valid - matrix is " + covStatusType;
virtual bool Scan(unsigned int i, unsigned int &nstep, double *x, double *y, double xmin=0, double xmax=0)
scan a parameter i around the minimum.
virtual const ROOT::Minuit2::ModularFunctionMinimizer * GetMinimizer() const
Minuit2Minimizer & operator=(const Minuit2Minimizer &rhs)
Assignment operator.
#define MN_INFO_VAL2(loc, x)
void SetHessianG2Tolerance(double toler)
#define MN_ERROR_MSG(str)
void Release(unsigned int)
void SetError(unsigned int, double)
virtual bool SetUpperLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double upper)
set upper limit variable (override if minimizer supports them )
double ErrorDef() const
return the statistical scale used for calculate the error is typically 1 for Chi2 and 0...
MnCross Upval(unsigned int, unsigned int maxcalls=0, double toler=0.1) const
const std::string & GetName(unsigned int) const
virtual void Init(const MnUserParameterState &state)
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
R__EXTERN Int_t gErrorIgnoreLevel
Namespace for new ROOT classes and functions.
virtual void SetPrintLevel(int level)
void SetHessianNCycles(unsigned int n)
double GradientTolerance() const
virtual bool GetCovMatrix(double *cov) const
Fill the passed array with the covariance matrix elements if the variable is fixed or const the value...
virtual void SetTraceObject(MnTraceObject &obj)
virtual void Print(std::ostream &=std::cout) const
print options
virtual bool SetVariableLimits(unsigned int ivar, double lower, double upper)
set the limits of an already existing variable
double LowerLimit() const
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
ROOT::Minuit2::FunctionMinimum * fMinimum
virtual bool SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double, double)
set upper/lower limited variable (override if minimizer supports them )
API class for Contours Error analysis (2-dim errors); minimization has to be done before and Minimum ...
template wrapped class for adapting to FCNBase signature
double HessianStepTolerance() const
unsigned int GradientNCycles() const
Class implementing the required methods for a minimization using SCAN API is provided in the upper RO...
void SetHessianGradientNCycles(unsigned int n)
bool InvertFailed() const
virtual std::string VariableName(unsigned int ivar) const
get name of variables (override if minimizer support storing of variable names)
bool HasValidCovariance() const
virtual double GlobalCC(unsigned int i) const
get global correlation coefficient for the variable i.
Minimizer()
Default constructor.
virtual bool Contour(unsigned int i, unsigned int j, unsigned int &npoints, double *xi, double *xj)
find the contour points (xi,xj) of the function for parameter i and j around the minimum The contour ...
void Add(const std::string &name, double val, double err)
virtual void SetMinimizer(ROOT::Minuit2::ModularFunctionMinimizer *m)
class for the individual Minuit Parameter with Name and number; contains the input numbers for the mi...
bool GetValue(const char *name, T &t) const
unsigned int NFcn() const
int PrintLevel() const
minimizer configuration parameters
void SetGradientStepTolerance(double stp)
const MinuitParameter & Parameter(unsigned int i) const
MnCross Loval(unsigned int, unsigned int maxcalls=0, double toler=0.1) const
void SetPrecision(double eps)
bool IsAboveMaxEdm() const
void RestoreGlobalPrintLevel(int)
unsigned int VariableParameters() const
void SetHessianStepTolerance(double stp)
bool HasLowerLimit() const
virtual const double * Errors() const
return errors at the minimum
const std::vector< ROOT::Minuit2::MinuitParameter > & MinuitParameters() const
facade: forward interface of MnUserParameters and MnUserTransformation
template wrapped class for adapting to FCNBase signature a IGradFunction
void SetGradientTolerance(double toler)
virtual bool SetVariableValue(unsigned int ivar, double val)
set variable
double GradientStepTolerance() const
void SetLimits(unsigned int, double, double)
Extension of the FCNBase for providing the analytical Gradient of the function.
ROOT::Minuit2::MnUserParameterState fState
bool IsValidError() const
return true if Minimizer has performed a detailed error validation (e.g. run Hesse for Minuit) ...
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
API class for calculating the numerical covariance matrix (== 2x Inverse Hessian == 2x Inverse 2nd de...
unsigned int HessianNCycles() const
API class for Minos Error analysis (asymmetric errors); minimization has to be done before and Minimu...
void Fix()
fix the parameter
double HessianG2Tolerance() const
bool HasCovariance() const
const MinimumState & State() const
MnUserCovariance Hessian() const
virtual bool ReleaseVariable(unsigned int ivar)
release an existing variable
int TurnOffPrintInfoLevel()
const std::vector< ROOT::Minuit2::MinimumState > & States() const
virtual void SetStorageLevel(int level)
double Tolerance() const
absolute tolerance
#define MN_INFO_MSG2(loc, str)
const MnUserTransformation & Trafo() const
bool HasMadePosDefCovar() const
void SetLowerLimit(double low)
set a single lower limit
double UpperLimit() const
virtual ~Minuit2Minimizer()
Destructor (no operations)
Documentation for the abstract class IBaseFunctionMultiDim.
#define MN_ERROR_MSG2(loc, str)
virtual bool FixVariable(unsigned int ivar)
fix an existing variable
static ROOT::Math::IOptions * FindDefault(const char *name)
int Strategy() const
strategy
unsigned int IntOfExt(unsigned int) const
RooCmdArg Minimizer(const char *type, const char *alg=0)
int CovarianceStatus() const
Class holding the result of Minos (lower and upper values) for a specific parameter.
virtual bool SetLowerLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double lower)
set lower limit variable (override if minimizer supports them )
void SetValue(unsigned int, double)
virtual double Correlation(unsigned int i, unsigned int j) const
return correlation coefficient between variable i and j.
const char * Name() const
Instantiates the seed generator and Minimum builder for the Fumili minimization method.
void SetUpperLimit(unsigned int, double)
class which holds the external user and/or internal Minuit representation of the parameters and error...
const MnGlobalCorrelationCoeff & GlobalCC() const
double Precision() const
precision of minimizer in the evaluation of the objective function ( a value <=0 corresponds to the l...
virtual bool SetFixedVariable(unsigned int, const std::string &, double)
set fixed variable (override if minimizer supports them )
virtual bool SetVariableValues(const double *val)
set the values of all existing variables (array must be dimensioned to the size of the existing param...
virtual void PrintResults()
return reference to the objective function virtual const ROOT::Math::IGenFunction & Function() const;...
Instantiates the SeedGenerator and MinimumBuilder for Variable Metric Minimization method...
virtual bool GetHessianMatrix(double *h) const
Fill the passed array with the Hessian matrix elements The Hessian matrix is the matrix of the second...
virtual void SetErrorDef(double)
add interface to set dynamically a new error definition Re-implement this function if needed...
void SetLowerLimit(unsigned int, double)
void Set(const std::string &name, double value, double step)
set value and name (unlimited parameter)
const std::vector< double > & GlobalCC() const
const MnUserCovariance & Covariance() const
virtual 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
bool HasReachedCallLimit() const
bool HasCovariance() const
static int SetLevel(int level)
bool HasAccurateCovar() const
const MnUserParameters & Parameters() const
Minuit2Minimizer class implementing the ROOT::Math::Minimizer interface for Minuit2 minimization algo...
FitMethodFunction class Interface for objective functions (like chi2 and likelihood used in the fit) ...
const MinimumError & Error() const
const char * Name(unsigned int) const
std::vector< double > fValues
std::vector< double > fErrors
void SetErrorDef(double up)
virtual bool SetVariableLowerLimit(unsigned int ivar, double lower)
set the lower-limit of an already existing variable
virtual void Clear()
reset for consecutive minimizations - implement if needed
const MnUserCovariance & IntCovariance() const
virtual int CovMatrixStatus() const
return the status of the covariance matrix status = -1 : not available (inversion failed or Hesse fai...
Class implementing the required methods for a minimization using Simplex.
void SetMinimizerType(ROOT::Minuit2::EMinimizerType type)
unsigned int HessianGradientNCycles() const
Namespace for new Math classes and functions.
unsigned int Index(const std::string &) const
Mother of all ROOT objects.
virtual const ROOT::Minuit2::FCNBase * GetFCN() const
unsigned int MaxFunctionCalls() const
max number of function calls
Minuit2Minimizer(ROOT::Minuit2::EMinimizerType type=ROOT::Minuit2::kMigrad)
Default constructor.
Generic interface for defining configuration options of a numerical algorithm.
virtual bool SetVariable(unsigned int ivar, const std::string &name, double val, double step)
set free variable
template wrapped class for adapting to FumiliFCNBase signature
ROOT::Minuit2::ModularFunctionMinimizer * fMinimizer
bool HasParameters() const
void SetTraceObject(MnTraceObject &obj)
set an object to trace operation for each iteration The object muust implement operator() (unsigned i...
virtual bool Minimize()
method to perform the minimization.
virtual const double * X() const
return pointer to X values at the minimum
bool HasCovariance() const
virtual double CovMatrix(unsigned int i, unsigned int j) const
return covariance matrix elements if the variable is fixed or const the value is zero The ordering of...
void SetUpperLimit(double up)
set a single upper limit
bool ExamineMinimum(const ROOT::Minuit2::FunctionMinimum &min)
examine the minimum result
void SetStorageLevel(int level)
set storage level = 1 : store all iteration states (default) = 0 : store only first and last state to...
ROOT::Minuit2::FCNBase * fMinuitFCN
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...
Scans the values of FCN as a function of one Parameter and retains the best function and Parameter va...
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
double Int2ext(unsigned int, double) const
virtual bool Hesse()
perform a full calculation of the Hessian matrix for error calculation If a valid minimum exists the ...
const MnUserParameterState & UserState() const
virtual bool GetMinosError(unsigned int i, double &errLow, double &errUp, int=0)
get the minos error for parameter i, return false if Minos failed A minimizaiton must be performed be...
Combined minimizer: combination of Migrad and Simplex.
bool HasUpperLimit() const
API class for defining three levels of strategies: low (0), medium (1), high (>=2); acts on: Migrad (...
virtual bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings &varObj) const
get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
const MinimumError & Error() const
virtual int VariableIndex(const std::string &name) const
get index of variable given a variable given a name return -1 if variable is not found ...
void SetGradientNCycles(unsigned int n)
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)
set the function to minimize
virtual bool IsFixedVariable(unsigned int ivar) const
query if an existing variable is fixed (i.e.
virtual bool SetVariableUpperLimit(unsigned int ivar, double upper)
set the upper-limit of an already existing variable
void RemoveLimits(unsigned int)
virtual bool SetVariableStepSize(unsigned int ivar, double step)
set the step size of an already existing variable
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
double Value(unsigned int) const
virtual const MinimumBuilder & Builder() const =0
const MnAlgebraicVector & Vec() const