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;
162 if (
this == &rhs)
return *
this;
188 std::string txtmsg =
"Parameter " + name +
" has zero or invalid step size - consider it as constant ";
195 unsigned int minuit2Index =
fState.
Index(name.c_str() );
196 if ( minuit2Index != ivar) {
197 std::string txtmsg(
"Wrong index used for the variable " + name);
199 MN_INFO_VAL2(
"Minuit2Minimizer::SetVariable",minuit2Index);
210 if (!
SetVariable(ivar, name, val, step) )
return false;
217 if (!
SetVariable(ivar, name, val, step) )
return false;
226 if (!
SetVariable(ivar, name, val, step) )
return false;
235 double step = ( val != 0) ? 0.1 * std::abs(val) : 0.1;
267 if (n== 0)
return false;
268 for (
unsigned int ivar = 0; ivar <
n; ++ivar)
361 MN_ERROR_MSG(
"Minuit2Minimizer: Wrong Fit method function for Fumili");
379 MN_ERROR_MSG(
"Minuit2Minimizer: Wrong Fit method function for Fumili");
390 MN_ERROR_MSG2(
"Minuit2Minimizer::Minimize",
"FCN function has not been set");
407 if (printLevel >=1) {
409 int maxfcn_used = maxfcn;
410 if (maxfcn_used == 0) {
412 maxfcn_used = 200 + 100*nvar + 5*nvar*nvar;
414 std::cout <<
"Minuit2Minimizer: Minimize with max-calls " << maxfcn_used
415 <<
" convergence for edm < " << tol <<
" strategy " 416 << strategyLevel << std::endl;
443 minuit2Opt->
GetValue(
"GradientNCycles",nGradCycles);
444 minuit2Opt->
GetValue(
"HessianNCycles",nHessCycles);
445 minuit2Opt->
GetValue(
"HessianGradientNCycles",nHessGradCycles);
447 minuit2Opt->
GetValue(
"GradientTolerance",gradTol);
448 minuit2Opt->
GetValue(
"GradientStepTolerance",gradStepTol);
449 minuit2Opt->
GetValue(
"HessianStepTolerance",hessStepTol);
450 minuit2Opt->
GetValue(
"HessianG2Tolerance",hessG2Tol);
461 int storageLevel = 1;
462 bool ret = minuit2Opt->
GetValue(
"StorageLevel",storageLevel);
465 if (printLevel > 0) {
466 std::cout <<
"Minuit2Minimizer::Minuit - Changing default options" << std::endl;
476 #ifdef USE_ROOT_ERROR 477 if (printLevel == 10 &&
gROOT) {
478 TObject * obj =
gROOT->FindObject(
"Minuit2TraceObject");
485 if (printLevel == 20 || printLevel == 30 || printLevel == 40 || (printLevel >= 20000 && printLevel < 30000) ) {
486 int parNumber = printLevel-20000;
487 if (printLevel == 20) parNumber = -1;
488 if (printLevel == 30) parNumber = -2;
489 if (printLevel == 40) parNumber = 0;
493 if (printLevel == 100 || (printLevel >= 10000 && printLevel < 20000)) {
494 int parNumber = printLevel-10000;
529 if (traceObj) {
delete traceObj; }
538 if (debugLevel >= 3) {
540 const std::vector<ROOT::Minuit2::MinimumState>& iterationStates = min.
States();
541 std::cout <<
"Number of iterations " << iterationStates.size() << std::endl;
542 for (
unsigned int i = 0; i < iterationStates.size(); ++i) {
545 std::cout <<
"----------> Iteration " << i << std::endl;
546 int pr = std::cout.precision(12);
547 std::cout <<
" FVAL = " << st.
Fval() <<
" Edm = " << st.
Edm() <<
" Nfcn = " << st.
NFcn() << std::endl;
548 std::cout.precision(pr);
550 std::cout <<
" Error matrix change = " << st.
Error().
Dcovar() << std::endl;
552 std::cout <<
" Parameters : ";
554 for (
int j = 0; j < st.
size() ; ++j) std::cout <<
" p" << j <<
" = " <<
fState.
Int2ext( j, st.
Vec()(j) );
555 std::cout << std::endl;
563 txt =
"Covar was made pos def";
567 txt =
"Hesse is not valid";
571 txt =
"Edm is above max";
575 txt =
"Reached call limit";
580 bool validMinimum = min.
IsValid();
589 txt =
"unknown failure";
592 std::string msg =
"Minimization did NOT converge, " + txt;
606 std::cout <<
"Minuit2Minimizer : Valid minimum - status = " <<
fStatus << std::endl;
607 int pr = std::cout.precision(18);
608 std::cout <<
"FVAL = " <<
fState.
Fval() << std::endl;
609 std::cout <<
"Edm = " <<
fState.
Edm() << std::endl;
610 std::cout.precision(pr);
611 std::cout <<
"Nfcn = " <<
fState.
NFcn() << std::endl;
614 std::cout << par.
Name() <<
"\t = " << par.
Value() <<
"\t ";
615 if (par.
IsFixed() ) std::cout <<
"(fixed)" << std::endl;
616 else if (par.
IsConst() ) std::cout <<
"(const)" << std::endl;
618 std::cout <<
"+/- " << par.
Error() <<
"\t(limited)"<< std::endl;
620 std::cout <<
"+/- " << par.
Error() << std::endl;
624 std::cout <<
"Minuit2Minimizer : Invalid Minimum - status = " <<
fStatus << std::endl;
625 std::cout <<
"FVAL = " <<
fState.
Fval() << std::endl;
626 std::cout <<
"Edm = " <<
fState.
Edm() << std::endl;
627 std::cout <<
"Nfcn = " <<
fState.
NFcn() << std::endl;
634 if (paramsObj.size() == 0)
return 0;
635 assert(
fDim == paramsObj.size());
639 for (
unsigned int i = 0; i <
fDim; ++i) {
640 fValues[i] = paramsObj[i].Value();
650 if (paramsObj.size() == 0)
return 0;
651 assert(
fDim == paramsObj.size());
655 for (
unsigned int i = 0; i <
fDim; ++i) {
669 if ( i >=
fDim || i >=
fDim)
return 0;
681 for (
unsigned int i = 0; i <
fDim; ++i) {
683 for (
unsigned int j = 0; j <
fDim; ++j) { cov[i*fDim + j] = 0; }
688 for (
unsigned int j = 0; j <
fDim; ++j) {
709 for (
unsigned int i = 0; i <
fDim; ++i) {
711 for (
unsigned int j = 0; j <
fDim; ++j) { hess[i*fDim + j] = 0; }
715 for (
unsigned int j = 0; j <
fDim; ++j) {
736 if ( i >=
fDim || i >=
fDim)
return 0;
744 if (tmp > 0 )
return cij/tmp;
753 if ( i >=
fDim || i >=
fDim)
return 0;
767 errLow = 0; errUp = 0;
768 bool runLower = runopt != 2;
769 bool runUpper = runopt != 1;
788 MN_ERROR_MSG(
"Minuit2Minimizer::GetMinosErrors: failed - no function minimum existing");
793 MN_ERROR_MSG(
"Minuit2Minimizer::MINOS failed due to invalid function minimum");
822 tol = std::max(tol, 0.01);
826 int maxfcn_used = maxfcn;
827 if (maxfcn_used == 0) {
829 maxfcn_used = 2*(nvar+1)*(200 + 100*nvar + 5*nvar*nvar);
831 std::cout <<
"Minuit2Minimizer::GetMinosError for parameter " << i <<
" " << par_name
832 <<
" using max-calls " << maxfcn_used <<
", tolerance " << tol << std::endl;
836 if (runLower) low = minos.
Loval(i,maxfcn,tol);
837 if (runUpper) up = minos.
Upval(i,maxfcn,tol);
850 if (debugLevel >= 1) {
852 if (!me.LowerValid() )
853 std::cout <<
"Minos: Invalid lower error for parameter " << par_name << std::endl;
854 if(me.AtLowerLimit())
855 std::cout <<
"Minos: Parameter : " << par_name <<
" is at Lower limit."<<std::endl;
856 if(me.AtLowerMaxFcn())
857 std::cout <<
"Minos: Maximum number of function calls exceeded when running for lower error" <<std::endl;
858 if(me.LowerNewMin() )
859 std::cout <<
"Minos: New Minimum found while running Minos for lower error" <<std::endl;
861 if (debugLevel > 1) std::cout <<
"Minos: Lower error for parameter " << par_name <<
" : " << me.Lower() << std::endl;
865 if (!me.UpperValid() )
866 std::cout <<
"Minos: Invalid upper error for parameter " << par_name << std::endl;
867 if(me.AtUpperLimit())
868 std::cout <<
"Minos: Parameter " << par_name <<
" is at Upper limit."<<std::endl;
869 if(me.AtUpperMaxFcn())
870 std::cout <<
"Minos: Maximum number of function calls exceeded when running for upper error" <<std::endl;
871 if(me.UpperNewMin() )
872 std::cout <<
"Minos: New Minimum found while running Minos for upper error" <<std::endl;
874 if (debugLevel > 1) std::cout <<
"Minos: Upper error for parameter " << par_name <<
" : " << me.Upper() << std::endl;
879 bool lowerInvalid = (runLower && !me.LowerValid() );
880 bool upperInvalid = (runUpper && !me.UpperValid() );
882 if (lowerInvalid || upperInvalid ) {
890 if (me.AtLowerMaxFcn() ) mstatus |= 4;
891 if (me.LowerNewMin() ) mstatus |= 8;
895 if (me.AtUpperMaxFcn() ) mstatus |= 4;
896 if (me.UpperNewMin() ) mstatus |= 8;
905 bool isValid = (runLower && me.LowerValid() ) || (runUpper && me.UpperValid() );
916 MN_ERROR_MSG2(
"Minuit2Minimizer::Scan",
" Function must be set before using Scan");
921 MN_ERROR_MSG2(
"Minuit2Minimizer::Scan",
" Invalid number. Minimizer variables must be set before using Scan");
935 double amin = scan.
Fval();
938 std::vector<std::pair<double, double> > result = scan(ipar, nstep-1, xmin, xmax);
942 if (result.size() != nstep) {
943 MN_ERROR_MSG2(
"Minuit2Minimizer::Scan",
" Invalid result from MnParameterScan");
947 std::sort(result.begin(), result.end() );
950 for (
unsigned int i = 0; i < nstep; ++i ) {
951 x[i] = result[i].first;
952 y[i] = result[i].second;
957 if (scan.Fval() < amin ) {
958 MN_INFO_MSG2(
"Minuit2Minimizer::Scan",
"A new minimum has been found");
971 MN_ERROR_MSG2(
"Minuit2Minimizer::Contour",
" no function minimum existing. Must minimize function before");
976 MN_ERROR_MSG2(
"Minuit2Minimizer::Contour",
"Invalid function minimum");
1005 std::vector<std::pair<double,double> > result = contour(ipar,jpar, npoints);
1006 if (result.size() != npoints) {
1007 MN_ERROR_MSG2(
"Minuit2Minimizer::Contour",
" Invalid result from MnContours");
1010 for (
unsigned int i = 0; i < npoints; ++i ) {
1011 x[i] = result[i].first;
1012 y[i] = result[i].second;
1031 MN_ERROR_MSG2(
"Minuit2Minimizer::Hesse",
"FCN function has not been set");
1072 std::cout <<
"Minuit2Minimizer::Hesse - State returned from Hesse " << std::endl;
1073 std::cout <<
fState << std::endl;
1077 std::string covStatusType =
"not valid";
1078 if (covStatus == 1) covStatusType =
"approximate";
1079 if (covStatus == 2) covStatusType =
"full but made positive defined";
1080 if (covStatus == 3) covStatusType =
"accurate";
1093 std::string msg =
"Hesse failed - matrix is " + covStatusType;
1101 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