35#ifdef USE_FUMILI_FUNCTION
46template<
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
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) {
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) {
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);
447bool 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;
void Error(const char *location, const char *msgfmt,...)
Chi2FCN class for binnned fits using the least square methods.
class evaluating the log likelihood for binned Poisson likelihood fits it is template to distinguish ...
FitMethodFunction class Interface for objective functions (like chi2 and likelihood used in the fit) ...
virtual Type_t Type() const
return the type of method, override if needed
Type_t
enumeration specyfing the possible fit method types
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 NPoints() const
return the number of data points used in evaluating the function
FunctionType::BaseFunc BaseFunction
virtual unsigned int NDim() const
Number of dimension (parameters) .
virtual void UpdateNCalls() const
update number of calls
Documentation for the abstract class IBaseFunctionMultiDim.
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
virtual unsigned int NDim() const=0
Retrieve the dimension of the function.
double Tolerance() const
absolute tolerance
unsigned int MaxFunctionCalls() const
max number of function calls
int PrintLevel() const
minimizer configuration parameters
Param Functor class for Multidimensional functions.
TFumiliMinimizer class: minimizer implementation based on TFumili.
~TFumiliMinimizer()
Destructor (no operations)
virtual bool Minimize()
method to perform the minimization
static ROOT::Math::FitMethodFunction * fgFunc
TFumiliMinimizer(int dummy=0)
Default constructor (an argument is needed by plug-in manager)
virtual bool SetVariableValue(unsigned int ivar, double val)
set the value of an existing variable
std::vector< double > fParams
virtual bool SetFixedVariable(unsigned int, const std::string &, double)
set fixed variable (override if minimizer supports them )
static double EvaluateFCN(const double *x, double *g)
implementation of FCN for Fumili when user provided gradient is used
virtual bool SetVariable(unsigned int ivar, const std::string &name, double val, double step)
set free variable
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 )
static ROOT::Math::FitMethodGradFunction * fgGradFunc
TFumiliMinimizer & operator=(const TFumiliMinimizer &rhs)
Assignment operator.
static TFumili * fgFumili
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)
set the function to minimize
std::vector< double > fErrors
std::vector< double > fCovar
static void Fcn(int &, double *, double &f, double *, int)
implementation of FCN for Fumili
virtual Int_t GetNumberFreeParameters() const
Return the number of free parameters.
virtual Double_t GetParError(Int_t ipar) const
Return error of parameter ipar.
virtual void PrintResults(Int_t k, Double_t p) const
Prints fit results.
virtual Int_t ExecuteCommand(const char *command, Double_t *args, Int_t nargs)
Execute MINUIT commands.
virtual void FixParameter(Int_t ipar)
Fixes parameter number ipar.
Double_t * GetPL0() const
void SetParNumber(Int_t ParNum)
virtual Int_t GetStats(Double_t &amin, Double_t &edm, Double_t &errdef, Int_t &nvpar, Int_t &nparx) const
Return global fit parameters.
virtual Bool_t IsFixed(Int_t ipar) const
Return kTRUE if parameter ipar is fixed, kFALSE otherwise)
virtual Double_t * GetCovarianceMatrix() const
Return a pointer to the covariance matrix.
virtual Int_t SetParameter(Int_t ipar, const char *parname, Double_t value, Double_t verr, Double_t vlow, Double_t vhigh)
Sets for parameter number ipar initial parameter value, name parname, initial error verr and limits v...
virtual Double_t GetParameter(Int_t ipar) const
Return current value of parameter ipar.
virtual const char * GetParName(Int_t ipar) const
Return name of parameter ipar.
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.
T EvalLog(T x)
safe evaluation of log(x) with a protections against negative or zero argument to the log smooth line...
BasicFitMethodFunction< ROOT::Math::IMultiGenFunction > FitMethodFunction
RooCmdArg Minimizer(const char *type, const char *alg=0)
static constexpr double s
static long int sum(long int i)