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)
355 MN_ERROR_MSG(
"Minuit2Minimizer: Wrong Fit method function for Fumili");
373 MN_ERROR_MSG(
"Minuit2Minimizer: Wrong Fit method function for Fumili");
384 MN_ERROR_MSG2(
"Minuit2Minimizer::Minimize",
"FCN function has not been set");
401 if (printLevel >=1) {
403 int maxfcn_used = maxfcn;
404 if (maxfcn_used == 0) {
406 maxfcn_used = 200 + 100*nvar + 5*nvar*nvar;
408 std::cout <<
"Minuit2Minimizer: Minimize with max-calls " << maxfcn_used
409 <<
" convergence for edm < " << tol <<
" strategy " 410 << strategyLevel << std::endl;
437 minuit2Opt->
GetValue(
"GradientNCycles",nGradCycles);
438 minuit2Opt->
GetValue(
"HessianNCycles",nHessCycles);
439 minuit2Opt->
GetValue(
"HessianGradientNCycles",nHessGradCycles);
441 minuit2Opt->
GetValue(
"GradientTolerance",gradTol);
442 minuit2Opt->
GetValue(
"GradientStepTolerance",gradStepTol);
443 minuit2Opt->
GetValue(
"HessianStepTolerance",hessStepTol);
444 minuit2Opt->
GetValue(
"HessianG2Tolerance",hessG2Tol);
455 int storageLevel = 1;
456 bool ret = minuit2Opt->
GetValue(
"StorageLevel",storageLevel);
459 if (printLevel > 0) {
460 std::cout <<
"Minuit2Minimizer::Minuit - Changing default options" << std::endl;
470 #ifdef USE_ROOT_ERROR 471 if (printLevel == 10 &&
gROOT) {
472 TObject * obj =
gROOT->FindObject(
"Minuit2TraceObject");
479 if (printLevel == 20 || printLevel == 30 || printLevel == 40 || (printLevel >= 20000 && printLevel < 30000) ) {
480 int parNumber = printLevel-20000;
481 if (printLevel == 20) parNumber = -1;
482 if (printLevel == 30) parNumber = -2;
483 if (printLevel == 40) parNumber = 0;
487 if (printLevel == 100 || (printLevel >= 10000 && printLevel < 20000)) {
488 int parNumber = printLevel-10000;
523 if (traceObj) {
delete traceObj; }
532 if (debugLevel >= 3) {
534 const std::vector<ROOT::Minuit2::MinimumState>& iterationStates = min.
States();
535 std::cout <<
"Number of iterations " << iterationStates.size() << std::endl;
536 for (
unsigned int i = 0; i < iterationStates.size(); ++i) {
539 std::cout <<
"----------> Iteration " << i << std::endl;
540 int pr = std::cout.precision(12);
541 std::cout <<
" FVAL = " << st.
Fval() <<
" Edm = " << st.
Edm() <<
" Nfcn = " << st.
NFcn() << std::endl;
542 std::cout.precision(pr);
544 std::cout <<
" Error matrix change = " << st.
Error().
Dcovar() << std::endl;
546 std::cout <<
" Parameters : ";
548 for (
int j = 0; j < st.
size() ; ++j) std::cout <<
" p" << j <<
" = " <<
fState.
Int2ext( j, st.
Vec()(j) );
549 std::cout << std::endl;
557 txt =
"Covar was made pos def";
561 txt =
"Hesse is not valid";
565 txt =
"Edm is above max";
569 txt =
"Reached call limit";
574 bool validMinimum = min.
IsValid();
583 txt =
"unknown failure";
586 std::string msg =
"Minimization did NOT converge, " + txt;
600 std::cout <<
"Minuit2Minimizer : Valid minimum - status = " <<
fStatus << std::endl;
601 int pr = std::cout.precision(18);
602 std::cout <<
"FVAL = " <<
fState.
Fval() << std::endl;
603 std::cout <<
"Edm = " <<
fState.
Edm() << std::endl;
604 std::cout.precision(pr);
605 std::cout <<
"Nfcn = " <<
fState.
NFcn() << std::endl;
608 std::cout << par.
Name() <<
"\t = " << par.
Value() <<
"\t ";
609 if (par.
IsFixed() ) std::cout <<
"(fixed)" << std::endl;
610 else if (par.
IsConst() ) std::cout <<
"(const)" << std::endl;
612 std::cout <<
"+/- " << par.
Error() <<
"\t(limited)"<< std::endl;
614 std::cout <<
"+/- " << par.
Error() << std::endl;
618 std::cout <<
"Minuit2Minimizer : Invalid Minimum - status = " <<
fStatus << std::endl;
619 std::cout <<
"FVAL = " <<
fState.
Fval() << std::endl;
620 std::cout <<
"Edm = " <<
fState.
Edm() << std::endl;
621 std::cout <<
"Nfcn = " <<
fState.
NFcn() << std::endl;
628 if (paramsObj.size() == 0)
return 0;
629 assert(
fDim == paramsObj.size());
633 for (
unsigned int i = 0; i <
fDim; ++i) {
634 fValues[i] = paramsObj[i].Value();
644 if (paramsObj.size() == 0)
return 0;
645 assert(
fDim == paramsObj.size());
649 for (
unsigned int i = 0; i <
fDim; ++i) {
663 if ( i >=
fDim || i >=
fDim)
return 0;
675 for (
unsigned int i = 0; i <
fDim; ++i) {
677 for (
unsigned int j = 0; j <
fDim; ++j) { cov[i*fDim + j] = 0; }
682 for (
unsigned int j = 0; j <
fDim; ++j) {
703 for (
unsigned int i = 0; i <
fDim; ++i) {
705 for (
unsigned int j = 0; j <
fDim; ++j) { hess[i*fDim + j] = 0; }
709 for (
unsigned int j = 0; j <
fDim; ++j) {
730 if ( i >=
fDim || i >=
fDim)
return 0;
738 if (tmp > 0 )
return cij/tmp;
747 if ( i >=
fDim || i >=
fDim)
return 0;
761 errLow = 0; errUp = 0;
762 bool runLower = runopt != 2;
763 bool runUpper = runopt != 1;
782 MN_ERROR_MSG(
"Minuit2Minimizer::GetMinosErrors: failed - no function minimum existing");
787 MN_ERROR_MSG(
"Minuit2Minimizer::MINOS failed due to invalid function minimum");
816 tol = std::max(tol, 0.01);
820 int maxfcn_used = maxfcn;
821 if (maxfcn_used == 0) {
823 maxfcn_used = 2*(nvar+1)*(200 + 100*nvar + 5*nvar*nvar);
825 std::cout <<
"Minuit2Minimizer::GetMinosError for parameter " << i <<
" " << par_name
826 <<
" using max-calls " << maxfcn_used <<
", tolerance " << tol << std::endl;
830 if (runLower) low = minos.
Loval(i,maxfcn,tol);
831 if (runUpper) up = minos.
Upval(i,maxfcn,tol);
844 if (debugLevel >= 1) {
846 if (!me.LowerValid() )
847 std::cout <<
"Minos: Invalid lower error for parameter " << par_name << std::endl;
848 if(me.AtLowerLimit())
849 std::cout <<
"Minos: Parameter : " << par_name <<
" is at Lower limit."<<std::endl;
850 if(me.AtLowerMaxFcn())
851 std::cout <<
"Minos: Maximum number of function calls exceeded when running for lower error" <<std::endl;
852 if(me.LowerNewMin() )
853 std::cout <<
"Minos: New Minimum found while running Minos for lower error" <<std::endl;
855 if (debugLevel > 1) std::cout <<
"Minos: Lower error for parameter " << par_name <<
" : " << me.Lower() << std::endl;
859 if (!me.UpperValid() )
860 std::cout <<
"Minos: Invalid upper error for parameter " << par_name << std::endl;
861 if(me.AtUpperLimit())
862 std::cout <<
"Minos: Parameter " << par_name <<
" is at Upper limit."<<std::endl;
863 if(me.AtUpperMaxFcn())
864 std::cout <<
"Minos: Maximum number of function calls exceeded when running for upper error" <<std::endl;
865 if(me.UpperNewMin() )
866 std::cout <<
"Minos: New Minimum found while running Minos for upper error" <<std::endl;
868 if (debugLevel > 1) std::cout <<
"Minos: Upper error for parameter " << par_name <<
" : " << me.Upper() << std::endl;
873 bool lowerInvalid = (runLower && !me.LowerValid() );
874 bool upperInvalid = (runUpper && !me.UpperValid() );
876 if (lowerInvalid || upperInvalid ) {
884 if (me.AtLowerMaxFcn() ) mstatus |= 4;
885 if (me.LowerNewMin() ) mstatus |= 8;
889 if (me.AtUpperMaxFcn() ) mstatus |= 4;
890 if (me.UpperNewMin() ) mstatus |= 8;
899 bool isValid = (runLower && me.LowerValid() ) || (runUpper && me.UpperValid() );
910 MN_ERROR_MSG2(
"Minuit2Minimizer::Scan",
" Function must be set before using Scan");
915 MN_ERROR_MSG2(
"Minuit2Minimizer::Scan",
" Invalid number. Minimizer variables must be set before using Scan");
929 double amin = scan.
Fval();
932 std::vector<std::pair<double, double> >
result = scan(ipar, nstep-1, xmin, xmax);
936 if (result.size() != nstep) {
937 MN_ERROR_MSG2(
"Minuit2Minimizer::Scan",
" Invalid result from MnParameterScan");
941 std::sort(result.begin(), result.end() );
944 for (
unsigned int i = 0; i < nstep; ++i ) {
945 x[i] = result[i].first;
946 y[i] = result[i].second;
951 if (scan.Fval() < amin ) {
952 MN_INFO_MSG2(
"Minuit2Minimizer::Scan",
"A new minimum has been found");
965 MN_ERROR_MSG2(
"Minuit2Minimizer::Contour",
" no function minimum existing. Must minimize function before");
970 MN_ERROR_MSG2(
"Minuit2Minimizer::Contour",
"Invalid function minimum");
999 std::vector<std::pair<double,double> >
result = contour(ipar,jpar, npoints);
1000 if (result.size() != npoints) {
1001 MN_ERROR_MSG2(
"Minuit2Minimizer::Contour",
" Invalid result from MnContours");
1004 for (
unsigned int i = 0; i < npoints; ++i ) {
1005 x[i] = result[i].first;
1006 y[i] = result[i].second;
1025 MN_ERROR_MSG2(
"Minuit2Minimizer::Hesse",
"FCN function has not been set");
1066 std::cout <<
"Minuit2Minimizer::Hesse - State returned from Hesse " << std::endl;
1067 std::cout <<
fState << std::endl;
1071 std::string covStatusType =
"not valid";
1072 if (covStatus == 1) covStatusType =
"approximate";
1073 if (covStatus == 2) covStatusType =
"full but made positive defined";
1074 if (covStatus == 3) covStatusType =
"accurate";
1087 std::string msg =
"Hesse failed - matrix is " + covStatusType;
1095 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.
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
#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)
R__EXTERN Int_t gErrorIgnoreLevel
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
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)
#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 unsigned int NDim() const =0
Retrieve the dimension of the function.
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
double func(double *x, double *p)
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 ...
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.
Documentation for the abstract class IBaseFunctionMultiDim.
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
double Value(unsigned int) const
virtual const MinimumBuilder & Builder() const =0
const MnAlgebraicVector & Vec() const