10#ifndef ROOT_Minuit2_FumiliFCNAdapter
11#define ROOT_Minuit2_FumiliFCNAdapter
42template <
class Function>
47 typedef typename Function::Type_t
Type_t;
55 double Up()
const {
return fUp; }
76template <
class Function>
79 MnPrint print(
"FumiliFCNAdaptor");
84 unsigned int npar = Dimension();
86 print.
Error(
"npar", npar,
"v.size()",
v.size());
87 assert(npar ==
v.size());
90 std::vector<double> &grad = Gradient();
91 std::vector<double> &hess = Hessian();
93 assert(grad.size() == npar);
94 grad.assign(npar, 0.0);
95 hess.assign(hess.size(), 0.0);
98 unsigned int ndata = fFunc.NPoints();
100 std::vector<double> gf(npar);
105 if (fFunc.Type() == Function::kLeastSquare) {
107 for (
unsigned int i = 0; i < ndata; ++i) {
109 double fval = fFunc.DataElement(&
v.front(), i, &gf[0]);
114 for (
unsigned int j = 0; j < npar; ++j) {
115 grad[j] += 2. * fval * gf[j];
116 for (
unsigned int k = j; k < npar; ++k) {
117 int idx = j + k * (k + 1) / 2;
118 hess[idx] += 2.0 * gf[j] * gf[k];
122 }
else if (fFunc.Type() == Function::kLogLikelihood) {
124 for (
unsigned int i = 0; i < ndata; ++i) {
128 double fval = fFunc.DataElement(&
v.front(), i, &gf[0]);
132 for (
unsigned int j = 0; j < npar; ++j) {
135 for (
unsigned int k = j; k < npar; ++k) {
136 int idx = j + k * (k + 1) / 2;
137 hess[idx] += gfj * gf[k];
142 print.
Error(
"Type of fit method is not supported, it must be chi2 or log-likelihood");
Double_t(* Function)(Double_t)
template wrapped class for adapting to FumiliFCNBase signature
double operator()(const double *v) const
void SetErrorDef(double up)
add interface to set dynamically a new error definition Re-implement this function if needed.
double operator()(const std::vector< double > &v) const
The meaning of the vector of parameters is of course defined by the user, who uses the values of thos...
void EvaluateAll(const std::vector< double > &v)
evaluate gradient hessian and function value needed by fumili
FumiliFCNAdapter(const Function &f, unsigned int ndim, double up=1.)
double Up() const
Error definition of the function.
Extension of the FCNBase for the Fumili method.
void Error(const Ts &... args)
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)