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,
double *)
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.) ;
92 double resVal = (
y-fval)*invError;
93 for (
unsigned int k = 0; k < npar; ++k) {
105 double DoEval(
const double *
x )
const {
106 return (*fObjFunc)(
x);
110 const MethodFunc * fObjFunc;
147#ifdef USE_STATIC_TMINUIT
188 Error(
"SetFunction",
"Wrong Fit method function type used for Fumili");
202 Error(
"SetFunction",
"Wrong Fit method function type used for Fumili");
210#ifdef USE_FUMILI_FUNCTION
255 unsigned int ndata = 0;
256 unsigned int npar = 0;
269 std::vector<double> gf(npar);
270 std::vector<double> hess(npar*(npar+1)/2);
271 std::vector<double>
h(npar*(npar+1)/2);
274 for (
unsigned int ipar = 0; ipar < npar; ++ipar)
281 std::cout <<
"=============================================";
282 std::cout <<
"par = ";
283 for (
unsigned int ipar = 0; ipar < npar; ++ipar)
284 std::cout <<
x[ipar] <<
"\t";
285 std::cout << std::endl;
296 for (
unsigned int i = 0; i < ndata; ++i) {
310 sum += 0.5 * fval * fval;
312 for (
unsigned int j = 0; j < npar; ++j) {
313 grad[j] += fval * gf[j];
314 for (
unsigned int k = j; k < npar; ++ k) {
315 int idx = j + k*(k+1)/2;
317 hess[idx] += 0.5 *
h[idx];
330 for (
unsigned int i = 0; i < ndata; ++i) {
345 for (
unsigned int j = 0; j < npar; ++j) {
347 for (
unsigned int k = j; k < npar; ++ k) {
348 int idx = j + k*(k+1)/2;
358 for (
unsigned int i = 0; i < ndata; ++i) {
371 for (
unsigned int j = 0; j < npar; ++j) {
374 for (
unsigned int k = j; k < npar; ++k) {
375 int idx = j + k * (k + 1) / 2;
376 hess[idx] += gfj * gf[k];
381 Error(
"EvaluateFCN",
" type of fit method is not supported, it must be chi2 or log-likelihood");
388 assert(zmatrix !=
nullptr);
389 assert(pl0 !=
nullptr);
392 for (
unsigned int i = 0; i < npar; ++i) {
393 for (
unsigned int j = 0; j <= i; ++j) {
394 if (pl0[i] > 0 && pl0[j] > 0) {
395 zmatrix[
l++] = hess[k];
402 std::cout <<
"FCN value " <<
sum <<
" grad ";
403 for (
unsigned int ipar = 0; ipar < npar; ++ipar)
404 std::cout << grad[ipar] <<
"\t";
405 std::cout << std::endl << std::endl;
418 Error(
"SetVariableValue",
"invalid TFumili pointer. Set function first ");
422 std::cout <<
"set variable " << ivar <<
" " <<
name <<
" value " << val <<
" step " << step << std::endl;
427 Error(
"SetVariable",
"Error for parameter %d ",ivar);
436 Error(
"SetVariableValue",
"invalid TFumili pointer. Set function first ");
440 std::cout <<
"set limited variable " << ivar <<
" " <<
name <<
" value " << val <<
" step " << step << std::endl;
444 Error(
"SetLimitedVariable",
"Error for parameter %d ",ivar);
450bool Fumili2Minimizer::SetLowerLimitedVariable(
unsigned int ivar ,
const std::string &
name ,
double val ,
double step ,
double lower ) {
452 double s = val-lower;
453 double upper = s*1.0E15;
454 if (s != 0) upper = 1.0E15;
455 return SetLimitedVariable(ivar,
name, val, step, lower,upper);
463 Error(
"SetVariableValue",
"invalid TFumili pointer. Set function first ");
472 std::cout <<
"Fix variable " << ivar <<
" " <<
name <<
" value " << std::endl;
476 Error(
"SetFixedVariable",
"Error for parameter %d ",ivar);
485 Error(
"SetVariableValue",
"invalid TFumili pointer. Set function first ");
489 double oldval, verr, vlow, vhigh = 0;
492 Error(
"SetVariableValue",
"Error for parameter %d ",ivar);
496 std::cout <<
"set variable " << ivar <<
" " <<
name <<
" value "
497 << val <<
" step " << verr << std::endl;
502 Error(
"SetVariableValue",
"Error for parameter %d ",ivar);
515 Error(
"SetVariableValue",
"invalid TFumili pointer. Set function first ");
545 std::cout <<
"Minimize using TFumili with tolerance = " <<
Tolerance()
572 assert (
static_cast<unsigned int>(ntot) ==
fDim);
584 for (
unsigned int i = 0; i <
fDim; ++i) {
589 for (
unsigned int j = 0; j <=i ; ++j) {
599 return (iret==0) ? true :
false;
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Chi2FCN class for binned 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 specifying the possible fit method types
virtual double DataElement(const double *x, unsigned int i, double *g=nullptr, double *h=nullptr, bool fullHessian=false) 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
unsigned int NDim() const override
Number of dimension (parameters) .
FunctionType::BaseFunc BaseFunction
virtual void UpdateNCalls() const
update number of calls
Documentation for the abstract class IBaseFunctionMultiDim.
virtual bool HasGradient() const
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 fStatus
status of minimizer
int PrintLevel() const
minimizer configuration parameters
Param Functor class for Multidimensional functions.
TFumiliMinimizer class: minimizer implementation based on TFumili.
static ROOT::Math::FitMethodFunction * fgFunc
bool SetFixedVariable(unsigned int, const std::string &, double) override
set fixed variable (override if minimizer supports them )
TFumiliMinimizer(int dummy=0)
Default constructor (an argument is needed by plug-in manager)
std::vector< double > fParams
bool SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double, double) override
set upper/lower limited 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
~TFumiliMinimizer() override
Destructor (no operations)
bool Minimize() override
method to perform the minimization
static ROOT::Math::FitMethodGradFunction * fgGradFunc
static TFumili * fgFumili
bool SetVariableValue(unsigned int ivar, double val) override
set the value of an existing variable
std::vector< double > fErrors
std::vector< double > fCovar
void SetFunction(const ROOT::Math::IMultiGenFunction &func) override
set the function to minimize
bool SetVariable(unsigned int ivar, const std::string &name, double val, double step) override
set free variable
static void Fcn(int &, double *, double &f, double *, int)
implementation of FCN for Fumili
Double_t GetParameter(Int_t ipar) const override
Return current value of parameter ipar.
Double_t GetParError(Int_t ipar) const override
Return error of parameter ipar.
Bool_t IsFixed(Int_t ipar) const override
Return kTRUE if parameter ipar is fixed, kFALSE otherwise)
Int_t ExecuteCommand(const char *command, Double_t *args, Int_t nargs) override
Execute MINUIT commands.
void PrintResults(Int_t k, Double_t p) const override
Prints fit results.
Int_t GetNumberFreeParameters() const override
Return the number of free parameters.
Double_t * GetCovarianceMatrix() const override
Return a pointer to the covariance matrix.
Int_t GetStats(Double_t &amin, Double_t &edm, Double_t &errdef, Int_t &nvpar, Int_t &nparx) const override
Return global fit parameters.
const char * GetParName(Int_t ipar) const override
Return name of parameter ipar.
void FixParameter(Int_t ipar) override
Fixes parameter number ipar.
Double_t * GetPL0() const
void SetParNumber(Int_t ParNum)
Int_t SetParameter(Int_t ipar, const char *parname, Double_t value, Double_t verr, Double_t vlow, Double_t vhigh) override
Sets for parameter number ipar initial parameter value, name parname, initial error verr and limits v...
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
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
static uint64_t sum(uint64_t i)