35 #ifdef USE_FUMILI_FUNCTION
36 bool gUseFumiliFunction =
true;
46 template<
class MethodFunc>
57 fObjFunc =
dynamic_cast<const MethodFunc *
>(
func);
62 fFumili->SetUserFunc(fModFunc);
67 FumiliFunction * Clone()
const {
return new FumiliFunction(fFumili, fObjFunc); }
71 double DataElement(
const double * ,
unsigned int i,
double * g)
const {
76 unsigned int npar = fObjFunc->NDim();
79 const double *x = fObjFunc->Data().GetPoint(i,y,invError);
80 double fval = fFumili->EvalTFN(g,const_cast<double *>( x));
81 fFumili->Derivatives(g, const_cast<double *>( x));
85 for (
unsigned int k = 0; k < npar; ++k) {
86 g[k] *= ( y/fval - 1.) ;
97 double resVal = (y-fval)*invError;
98 for (
unsigned int k = 0; k < npar; ++k) {
110 double DoEval(
const double *x )
const {
111 return (*fObjFunc)(
x);
115 const MethodFunc * fObjFunc;
120 bool gUseFumiliFunction =
false;
136 TFumili * TFumiliMinimizer::fgFumili = 0;
152 #ifdef USE_STATIC_TMINUIT
154 if (fgFumili == 0) fgFumili =
new TFumili(0);
157 if (fFumili)
delete fFumili;
180 if (
this == &rhs)
return *
this;
199 Error(
"SetFunction",
"Wrong Fit method function type used for Fumili");
207 #ifdef USE_FUMILI_FUNCTION
208 if (gUseFumiliFunction) {
229 Error(
"SetFunction",
"Wrong Fit method function type used for Fumili");
273 unsigned int ndata = 0;
274 unsigned int npar = 0;
287 std::vector<double> gf(npar);
288 std::vector<double> hess(npar*(npar+1)/2);
291 for (
unsigned int ipar = 0; ipar < npar; ++ipar)
298 std::cout <<
"=============================================";
299 std::cout <<
"par = ";
300 for (
unsigned int ipar = 0; ipar < npar; ++ipar)
301 std::cout << x[ipar] <<
"\t";
302 std::cout << std::endl;
313 for (
unsigned int i = 0; i <
ndata; ++i) {
316 if (gUseFumiliFunction) {
331 for (
unsigned int j = 0; j < npar; ++j) {
332 grad[j] += fval * gf[j];
333 for (
unsigned int k = j; k < npar; ++ k) {
334 int idx = j + k*(k+1)/2;
335 hess[idx] += gf[j] * gf[k];
349 for (
unsigned int i = 0; i <
ndata; ++i) {
351 if (gUseFumiliFunction) {
367 for (
unsigned int j = 0; j < npar; ++j) {
370 for (
unsigned int k = j; k < npar; ++ k) {
371 int idx = j + k*(k+1)/2;
372 hess[idx] += gfj * gf[k];
378 Error(
"EvaluateFCN",
" type of fit method is not supported, it must be chi2 or log-likelihood");
389 for (
unsigned int i = 0; i < npar; ++i) {
390 for (
unsigned int j = 0; j <= i; ++j) {
391 if (pl0[i] > 0 && pl0[j] > 0) {
392 zmatrix[l++] = hess[k];
399 std::cout <<
"FCN value " << sum <<
" grad ";
400 for (
unsigned int ipar = 0; ipar < npar; ++ipar)
401 std::cout << grad[ipar] <<
"\t";
402 std::cout << std::endl << std::endl;
415 Error(
"SetVariableValue",
"invalid TFumili pointer. Set function first ");
419 std::cout <<
"set variable " << ivar <<
" " << name <<
" value " << val <<
" step " << step << std::endl;
424 Error(
"SetVariable",
"Error for parameter %d ",ivar);
433 Error(
"SetVariableValue",
"invalid TFumili pointer. Set function first ");
437 std::cout <<
"set limited variable " << ivar <<
" " << name <<
" value " << val <<
" step " << step << std::endl;
441 Error(
"SetLimitedVariable",
"Error for parameter %d ",ivar);
447 bool Fumili2Minimizer::SetLowerLimitedVariable(
unsigned int ivar ,
const std::string & name ,
double val ,
double step ,
double lower ) {
449 double s = val-
lower;
450 double upper = s*1.0E15;
451 if (s != 0) upper = 1.0E15;
452 return SetLimitedVariable(ivar, name, val, step, lower,upper);
460 Error(
"SetVariableValue",
"invalid TFumili pointer. Set function first ");
469 std::cout <<
"Fix variable " << ivar <<
" " << name <<
" value " << std::endl;
473 Error(
"SetFixedVariable",
"Error for parameter %d ",ivar);
482 Error(
"SetVariableValue",
"invalid TFumili pointer. Set function first ");
486 double oldval, verr, vlow, vhigh = 0;
489 Error(
"SetVariableValue",
"Error for parameter %d ",ivar);
493 std::cout <<
"set variable " << ivar <<
" " << name <<
" value "
494 << val <<
" step " << verr << std::endl;
499 Error(
"SetVariableValue",
"Error for parameter %d ",ivar);
512 Error(
"SetVariableValue",
"invalid TFumili pointer. Set function first ");
542 std::cout <<
"Minimize using TFumili with tolerance = " <<
Tolerance()
569 assert (static_cast<unsigned int>(ntot) ==
fDim);
581 for (
unsigned int i = 0; i <
fDim; ++i) {
586 for (
unsigned int j = 0; j <=i ; ++j) {
596 return (iret==0) ?
true :
false;
virtual bool SetVariable(unsigned int ivar, const std::string &name, double val, double step)
set free variable
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
unsigned int MaxFunctionCalls() const
max number of function calls
Namespace for new ROOT classes and functions.
virtual Type_t Type() const
return the type of method, override if needed
virtual void FixParameter(Int_t ipar)
Fixes parameter number ipar.
virtual Int_t GetStats(Double_t &amin, Double_t &edm, Double_t &errdef, Int_t &nvpar, Int_t &nparx) const
return global fit parameters amin : chisquare edm : estimated distance to minimum errdef nvpar : numb...
virtual unsigned int NPoints() const
return the number of data points used in evaluating the function
static double EvaluateFCN(const double *x, double *g)
implementation of FCN for Fumili when user provided gradient is used
double Tolerance() const
absolute tolerance
TFumiliMinimizer class: minimizer implementation based on TFumili.
virtual void SetFCN(void *fcn)
To set the address of the minimization objective function.
static ROOT::Math::FitMethodFunction * fgFunc
TFumiliMinimizer(int dummy=0)
Default constructor (an argument is needed by plug-in manager)
virtual Double_t GetParameter(Int_t ipar) const
return current value of parameter ipar
virtual Int_t SetParameter(Int_t ipar, const char *parname, Double_t value, Double_t verr, Double_t vlow, Double_t vhigh)
Sets for prameter number ipar initial parameter value, name parname, initial error verr and limits vl...
virtual void PrintResults(Int_t k, Double_t p) const
Prints fit results.
virtual Double_t GetParError(Int_t ipar) const
return error of parameter ipar
class evaluating the log likelihood for binned Poisson likelihood fits it is template to distinguish ...
std::vector< double > fParams
virtual bool SetFixedVariable(unsigned int, const std::string &, double)
set fixed variable (override if minimizer supports them )
virtual bool Minimize()
method to perform the minimization
virtual Int_t GetNumberFreeParameters() const
return the number of free parameters
void Error(const char *location, const char *msgfmt,...)
Chi2FCN class for binnned fits using the least square methods.
ClassImp(TFumiliMinimizer) TFumiliMinimizer
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_t * GetPL0() const
virtual unsigned int NDim() const
Number of dimension (parameters) .
RooCmdArg Minimizer(const char *type, const char *alg=0)
std::vector< double > fCovar
virtual Bool_t IsFixed(Int_t ipar) const
return kTRUE if parameter ipar is fixed, kFALSE othersise)
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
int PrintLevel() const
minimizer configuration parameters
FunctionType::BaseFunc BaseFunction
virtual Int_t ExecuteCommand(const char *command, Double_t *args, Int_t nargs)
Execute MINUIT commands.
~TFumiliMinimizer()
Destructor (no operations)
FitMethodFunction class Interface for objective functions (like chi2 and likelihood used in the fit) ...
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)
set the function to minimize
virtual Double_t * GetCovarianceMatrix() const
return a pointer to the covariance matrix
double func(double *x, double *p)
Namespace for new Math classes and functions.
double EvalLog(double x)
safe evaluation of log(x) with a protections against negative or zero argument to the log smooth line...
static ROOT::Math::FitMethodGradFunction * fgGradFunc
static TFumili * fgFumili
virtual void UpdateNCalls() const
update number of calls
std::vector< double > fErrors
TFumiliMinimizer & operator=(const TFumiliMinimizer &rhs)
Assignment operator.
Param Functor class for Multidimensional functions.
void SetParNumber(Int_t ParNum)
Documentation for the abstract class IBaseFunctionMultiDim.
virtual bool SetVariableValue(unsigned int ivar, double val)
set the value of an existing variable
Type_t
enumeration specyfing the possible fit method types
static void Fcn(int &, double *, double &f, double *, int)
implementation of FCN for Fumili
virtual const char * GetParName(Int_t ipar) const
return name of parameter ipar
virtual double DataElement(const double *x, unsigned int i, double *g=0) const =0
method returning the data i-th contribution to the fit objective function For example the residual fo...
BasicFitMethodFunction< ROOT::Math::IMultiGenFunction > FitMethodFunction