35 #ifdef USE_FUMILI_FUNCTION 46 template<
class MethodFunc>
57 fObjFunc =
dynamic_cast<const MethodFunc *
>(func);
58 assert(fObjFunc != 0);
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;
152 #ifdef USE_STATIC_TMINUIT 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");
385 assert(zmatrix != 0);
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;
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
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...
static long int sum(long int i)
virtual void UpdateNCalls() const
update number of calls
Param Functor class for Multidimensional functions.
Type_t
enumeration specyfing the possible fit method types
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
virtual Double_t * GetCovarianceMatrix() const
return a pointer to the covariance matrix
Namespace for new ROOT classes and functions.
virtual void FixParameter(Int_t ipar)
Fixes parameter number ipar.
virtual Double_t GetParameter(Int_t ipar) const
return current value of parameter ipar
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
virtual void PrintResults(Int_t k, Double_t p) const
Prints fit results.
Double_t * GetPL0() const
TFumiliMinimizer class: minimizer implementation based on TFumili.
Minimizer()
Default constructor.
static ROOT::Math::FitMethodFunction * fgFunc
int PrintLevel() const
minimizer configuration parameters
TFumiliMinimizer(int dummy=0)
Default constructor (an argument is needed by plug-in manager)
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...
class evaluating the log likelihood for binned Poisson likelihood fits it is template to distinguish ...
virtual const char * GetParName(Int_t ipar) const
return name of parameter ipar
std::vector< double > fParams
virtual Type_t Type() const
return the type of method, override if needed
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
void Error(const char *location, const char *msgfmt,...)
T EvalLog(T x)
safe evaluation of log(x) with a protections against negative or zero argument to the log smooth line...
double Tolerance() const
absolute tolerance
virtual Double_t GetParError(Int_t ipar) const
return error of parameter ipar
Documentation for the abstract class IBaseFunctionMultiDim.
Chi2FCN class for binnned fits using the least square methods.
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 )
std::vector< double > fCovar
virtual Bool_t IsFixed(Int_t ipar) const
Return kTRUE if parameter ipar is fixed, kFALSE othersise)
virtual Int_t GetNumberFreeParameters() const
return the number of free parameters
FunctionType::BaseFunc BaseFunction
virtual unsigned int NDim() const
Number of dimension (parameters) .
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
static constexpr double s
virtual void SetFCN(void(*fcn)(Int_t &, Double_t *, Double_t &f, Double_t *, Int_t))
To set the address of the minimization objective function called by the native compiler (see function...
Namespace for new Math classes and functions.
unsigned int MaxFunctionCalls() const
max number of function calls
static ROOT::Math::FitMethodGradFunction * fgGradFunc
static TFumili * fgFumili
std::vector< double > fErrors
TFumiliMinimizer & operator=(const TFumiliMinimizer &rhs)
Assignment operator.
void SetParNumber(Int_t ParNum)
virtual bool SetVariableValue(unsigned int ivar, double val)
set the value of an existing variable
static void Fcn(int &, double *, double &f, double *, int)
implementation of FCN for Fumili
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...
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
BasicFitMethodFunction< ROOT::Math::IMultiGenFunction > FitMethodFunction