50 TMinuit * TMinuitMinimizer::fgMinuit = 0;
70 if (fDim > 0) InitTMinuit(fDim);
84 std::string algoname(type);
85 std::transform(algoname.begin(), algoname.end(), algoname.begin(), (int(*)(int)) tolower );
119 if (
this == &rhs)
return *
this;
263 f = gFunc->operator()(
x);
266 if (iflag == 2) gFunc->
Gradient(x,g);
304 Warning(
"TMinuitMinimizer::SetLowerLimitedVariable",
"not implemented - use as upper limit 1.E7 instead of +inf");
311 Warning(
"TMinuitMinimizer::SetUpperLimitedVariable",
"not implemented - use as lower limit -1.E7 instead of -inf");
319 Error(
"TMinuitMinimizer::CheckMinuitInstance",
"Invalid TMinuit pointer. Need to call first SetFunction");
328 Error(
"TMinuitMinimizer::CheckVarIndex",
"Invalid parameter index");
348 double step = ( val != 0) ? 0.1 *
std::abs(val) : 0.1;
374 double curval,err, lowlim, uplim;
377 fMinuit->
mnpout(ivar, name, curval, err, lowlim, uplim,iuint);
378 if (iuint == -1)
return false;
387 Warning(
"TMinuitMinimizer::SetVariableLowerLimit",
"not implemented - use as upper limit 1.E30 instead of +inf");
393 Warning(
"TMinuitMinimizer::SetVariableUpperLimit",
"not implemented - - use as lower limit -1.E30 instead of +inf");
404 double curval,err, lowlim, uplim;
407 fMinuit->
mnpout(ivar, name, curval, err, lowlim, uplim,iuint);
408 if (iuint == -1)
return false;
441 double curval,err, lowlim, uplim;
444 fMinuit->
mnpout(ivar, name, curval, err, lowlim, uplim,iuint);
445 if (iuint == -1)
return false;
446 var.
Set(name.
Data(), curval, err, lowlim, uplim);
462 Error(
"TMinuitMinimizer::VariableIndex",
" find index of a variable from its name is not implemented in TMinuit");
476 Error(
"TMinuitMinimizer::Minimize",
"invalid TMinuit pointer. Need to call first SetFunction and SetVariable");
483 Error(
"TMinuitMinimizer::Minimize",
"The total number of defined parameters is different than the function dimension, npar = %d, dim = %d",
fMinuit->
fNu,
fDim);
494 if (printlevel > 0)
Info(
"TMinuitMinimizer::Minimize",
"There are no free parameter - just compute the function value");
507 arglist[0] = printlevel - 1;
511 if (printlevel == 0)
fMinuit->
mnexcm(
"SET NOW",arglist,0,ierr);
521 if (strategy >=0 && strategy <=2 ) {
553 if (arglist[1] >= 1.) nargs = 2;
566 int minErrStatus = ierr;
568 if (printlevel>2)
Info(
"TMinuitMinimizer::Minimize",
"Finished to run MIGRAD - status %d",ierr);
574 if (printlevel>2)
Info(
"TMinuitMinimizer::Minimize",
"Finished to run IMPROVE - status %d",ierr);
584 if (printlevel>2)
Info(
"TMinuitMinimizer::Minimize",
"Finished to run HESSE - status %d",ierr);
590 if (minErrStatus == 0) {
615 for (
unsigned int i = 0; i <
fDim; ++i) {
626 unsigned int nfree =
NFree();
635 std::vector<double> tmpMat(nfree*nfree);
639 for (
unsigned int i = 0; i <
fDim; ++i) {
643 for (
unsigned int j = 0; j <= i; ++j) {
645 fCovar[i*fDim + j] = tmpMat[l*nfree +
m];
693 Error(
"TMinuitMinimizer::GetHessianMatrix",
"Hessian matrix has not been computed - status %d",covStatus);
707 Error(
"TMinuitMinimizer::GetHessianMatrix",
"Hessian matrix has not been computed - status %d",covStatus);
711 unsigned int nfree =
NFree();
719 for (
unsigned int i = 0; i <
fDim; ++i) {
722 for (
unsigned int j = 0; j <= i; ++j) {
724 hes[i*fDim + j] = mat(l,m);
725 hes[j*fDim + i] = hes[i*fDim + j];
761 if (iin < 1)
return 0;
769 Error(
"TMinuitMinimizer::GetMinosError",
"invalid TMinuit pointer. Need to call first SetFunction and SetVariable");
775 if (
PrintLevel() > 0)
Info(
"TMinuitMinimizer::GetMinosError",
"Parameter %s is fixed. There are no Minos error to calculate. Ignored.",
VariableName(i).c_str());
776 errLow = 0; errUp = 0;
814 bool isValid = (ierr == 0);
902 Error(
"TMinuitMinimizer::Contour",
" invalid TMinuit instance");
926 Error(
"TMinuitMinimizer::Contour",
"Cannot make contour with so few points");
934 Error(
"TMinuitMinimizer::Contour",
"Cannot find more than 4 points");
937 if (npfound!=(
int)npoints) {
939 Warning(
"TMinuitMinimizer::Contour",
"Returning only %d points ",npfound);
956 Error(
"TMinuitMinimizer::Scan",
" invalid TMinuit instance");
961 if (xmin >= xmax && (
int) ipar < fMinuit->GetNumPars() ) {
962 double val = 0;
double err = 0;
964 double xlow = 0;
double xup = 0 ;
969 if (iuint > 0 && err > 0) {
971 xmax = val + 2 * err;
989 if (nstep == 0)
return false;
991 arglist[1] = nstep+2;
1000 Error(
"TMinuitMinimizer::Scan",
" Error executing command SCAN");
1006 Error(
"TMinuitMinimizer::Scan",
" Error in returned graph object");
1012 std::copy(gr->
GetX(), gr->
GetX()+nstep,
x);
1013 std::copy(gr->
GetY(), gr->
GetY()+nstep,
y);
1022 Error(
"TMinuitMinimizer::Hesse",
"invalid TMinuit pointer. Need to call first SetFunction and SetVariable");
1035 arglist[0] = printlevel - 1;
1039 if (printlevel == 0)
fMinuit->
mnexcm(
"SET NOW",arglist,0,ierr);
1052 if (ierr != 0)
return false;
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 )
virtual TObject * GetPlot() const
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
virtual bool SetVariableStepSize(unsigned int, double)
set the step size of an existing variable
virtual bool Minimize()
method to perform the minimization
virtual void mnprin(Int_t inkode, Double_t fval)
*-*-*-*Prints the values of the parameters at the time of the call*-*-*-*-* *-* =====================...
virtual std::string VariableName(unsigned int ivar) const
return reference to the objective function virtual const ROOT::Math::IGenFunction & Function() const;...
bool CheckMinuitInstance() const
check TMinuit instance
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
unsigned int MaxFunctionCalls() const
max number of function calls
static TMinuit * fgMinuit
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 )
Implementation in C++ of the Minuit package written by F.
ClassImp(TMinuitMinimizer) TMinuitMinimizer
bool IsValidError() const
return true if Minimizer has performed a detailed error validation (e.g. run Hesse for Minuit) ...
Namespace for new ROOT classes and functions.
virtual void mnemat(Double_t *emat, Int_t ndim)
Calculates the external error matrix from the internal matrix.
virtual double Edm() const
return expected distance reached from the minimum
std::vector< double > fParams
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
void RetrieveParams()
retrieve minimum parameters and errors from TMinuit
TMinuitMinimizer & operator=(const TMinuitMinimizer &rhs)
Assignment operator.
static void FcnGrad(int &, double *g, double &f, double *, int)
implementation of FCN for Minuit when user provided gradient is used
bool CheckVarIndex(unsigned int ivar) const
check parameter
virtual bool SetVariableUpperLimit(unsigned int, double)
set the upper-limit of an existing variable
int Strategy() const
strategy
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 )
double Tolerance() const
absolute tolerance
virtual bool SetFixedVariable(unsigned int, const std::string &, double)
set fixed variable (override if minimizer supports them )
ClassImp(TIterator) Bool_t TIterator return false
Compare two iterator objects.
virtual double MinValue() const
return minimum function value
virtual Int_t GetNumPars() const
returns the total number of parameters that have been defined as fixed or free.
virtual Int_t FixParameter(Int_t parNo)
fix a parameter
const char * Data() const
void SuppressMinuitWarnings(bool nowarn=true)
suppress the minuit warnings (if called with false will enable them) By default they are suppressed o...
virtual void SetFCN(void *fcn)
*-*-*-*-*-*-*To set the address of the minimization function*-*-*-*-*-*-*-* *-* =====================...
void InitTMinuit(int ndim)
initialize the TMinuit instance
R__EXTERN TMinuit * gMinuit
virtual double GlobalCC(unsigned int) const
global correlation coefficient for variable i
virtual void mnrn15(Double_t &val, Int_t &inseed)
*-*-*-*-*-*-*This is a super-portable random number generator*-*-*-*-*-*-* *-* ======================...
virtual bool Hesse()
perform a full calculation of the Hessian matrix for error calculation
static Vc_ALWAYS_INLINE Vector< T > abs(const Vector< T > &x)
void Info(const char *location, const char *msgfmt,...)
void Fix()
fix the parameter
virtual bool ReleaseVariable(unsigned int)
release an existing variable
void Error(const char *location, const char *msgfmt,...)
virtual const Element * GetMatrixArray() const
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 bool FixVariable(unsigned int)
fix an existing variable
virtual Int_t DefineParameter(Int_t parNo, const char *name, Double_t initVal, Double_t initErr, Double_t lowerLimit, Double_t upperLimit)
Define a parameter.
static bool fgUseStaticMinuit
void DoReleaseFixParameter(int ivar)
release a parameter that is fixed when it is redefined
virtual void mncont(Int_t ke1, Int_t ke2, Int_t nptu, Double_t *xptu, Double_t *yptu, Int_t &ierrf)
*-*-*-*-*-*-*Find points along a contour where FCN is minimum*-*-*-*-*-*-* *-* ======================...
double ErrorDef() const
return the statistical scale used for calculate the error is typically 1 for Chi2 and 0...
static ROOT::Math::IMultiGenFunction *& GetGlobalFuncPtr()
TString * fCpnam
Character to be plotted at the X,Y contour positions.
virtual void mncler()
*-*-*-*-*-*-*-*-*-*-*Resets the parameter list to UNDEFINED*-*-*-*-*-*-*-* *-* ======================...
virtual bool SetVariableValue(unsigned int, double)
set the value of an existing variable
virtual Int_t GetParameter(Int_t parNo, Double_t ¤tValue, Double_t ¤tError) const
return parameter value and error
RooCmdArg Minimizer(const char *type, const char *alg=0)
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
static void Fcn(int &, double *, double &f, double *, int)
implementation of FCN for Minuit
virtual bool SetVariableLowerLimit(unsigned int, double)
set the lower-limit of an existing variable
void RetrieveErrorMatrix()
retrieve error matrix from TMinuit
int PrintLevel() const
minimizer configuration parameters
virtual unsigned int NFree() const
number of free variables (real dimension of the problem) this is <= Function().NDim() which is the to...
virtual bool GetHessianMatrix(double *h) const
Fill the passed array with the Hessian matrix elements The Hessian matrix is the matrix of the second...
void Warning(const char *location, const char *msgfmt,...)
virtual void mnerrs(Int_t number, Double_t &eplus, Double_t &eminus, Double_t &eparab, Double_t &gcc)
*-*-*-*-*-*-*-*-*-*Utility routine to get MINOS errors*-*-*-*-*-*-*-*-*-*-* *-* =====================...
void Set(const std::string &name, double value, double step)
set value and name (unlimited parameter)
virtual Int_t GetNumFixedPars() const
returns the number of currently fixed parameters
double Precision() const
precision of minimizer in the evaluation of the objective function ( a value <=0 corresponds to the l...
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)
set the function to minimize
virtual bool GetCovMatrix(double *cov) const
Fill the passed array with the covariance matrix elements if the variable is fixed or const the value...
ROOT::Minuit::EMinimizerType fType
virtual bool SetVariableLimits(unsigned int ivar, double lower, double upper)
set the limits of an existing variable
~TMinuitMinimizer()
Destructor (no operations)
virtual Int_t Release(Int_t parNo)
release a parameter
TMinuitMinimizer(ROOT::Minuit::EMinimizerType type=ROOT::Minuit::kMigrad, unsigned int ndim=0)
Default constructor.
virtual bool IsFixedVariable(unsigned int) const
query if an existing variable is fixed (i.e.
double func(double *x, double *p)
virtual void mnexcm(const char *comand, Double_t *plist, Int_t llist, Int_t &ierflg)
*-*-*-*-*-*Interprets a command and takes appropriate action*-*-*-*-*-*-*-* *-* =====================...
virtual int CovMatrixStatus() const
return status of covariance matrix
TMatrixTSym< Element > & Invert(Double_t *det=0)
Invert the matrix and calculate its determinant Notice that the LU decomposition is used instead of B...
virtual int VariableIndex(const std::string &name) const
get index of variable given a variable given a name return always -1 .
TMinuitMinimizer class: ROOT::Math::Minimizer implementation based on TMinuit.
virtual void PrintResults()
return reference to the objective function virtual const ROOT::Math::IGenFunction & Function() const ...
virtual unsigned int NCalls() const
number of function calls to reach the minimum
A Graph is a graphics object made of two arrays X and Y with npoints each.
std::vector< double > fCovar
virtual bool GetVariableSettings(unsigned int, ROOT::Fit::ParameterSettings &) const
get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
static bool UseStaticMinuit(bool on=true)
static function to switch on/off usage of static global TMinuit instance (gMinuit) By default it is u...
Documentation for the abstract class IBaseFunctionMultiDim.
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 ...
virtual void mnpout(Int_t iuext, TString &chnam, Double_t &val, Double_t &err, Double_t &xlolim, Double_t &xuplim, Int_t &iuint) const
*-*-*-*Provides the user with information concerning the current status*-*-* *-* ====================...
std::vector< double > fErrors
virtual void Gradient(const double *x, double *grad) const
Evaluate all the vector of function derivatives (gradient) at a point x.
virtual bool SetVariable(unsigned int ivar, const std::string &name, double val, double step)
set free variable
virtual bool GetMinosError(unsigned int i, double &errLow, double &errUp, int=0)
minos error for variable i, return false if Minos failed