10#ifndef ROOT_Minuit2_FumiliFCNAdapter
11#define ROOT_Minuit2_FumiliFCNAdapter
42template <
class Function>
47 typedef typename Function::Type_t
Type_t;
53 double operator()(
const std::vector<double> &
v)
const override {
return fFunc.operator()(&
v[0]); }
55 double Up()
const override {
return fUp; }
76template <
class Function>
79 MnPrint print(
"FumiliFCNAdapter");
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);
97 unsigned int ndata = fFunc.NPoints();
99 std::vector<double> gf(npar);
100 std::vector<double>
h(hess.size());
105 if (fFunc.Type() == Function::kLeastSquare) {
106 print.
Debug(
"Chi2 FCN: Evaluate gradient and Hessian");
108 for (
unsigned int i = 0; i < ndata; ++i) {
110 double fval = fFunc.DataElement(&
v.front(), i, &gf[0]);
112 for (
unsigned int j = 0; j < npar; ++j) {
113 grad[j] += 2. * fval * gf[j];
114 for (
unsigned int k = j; k < npar; ++k) {
115 int idx = j + k * (k + 1) / 2;
116 hess[idx] += 2.0 * gf[j] * gf[k];
120 }
else if (fFunc.Type() == Function::kLogLikelihood) {
121 print.
Debug(
"LogLikelihood FCN: Evaluate gradient and Hessian");
122 for (
unsigned int i = 0; i < ndata; ++i) {
125 fFunc.DataElement(&
v.front(), i, &gf[0]);
127 for (
unsigned int j = 0; j < npar; ++j) {
130 for (
unsigned int k = j; k < npar; ++k) {
131 int idx = j + k * (k + 1) / 2;
132 hess[idx] += gfj * gf[k];
136 }
else if (fFunc.Type() == Function::kPoissonLikelihood) {
137 print.
Debug(
"Poisson Likelihood FCN: Evaluate gradient and Hessian");
139 for (
unsigned int i = 0; i < ndata; ++i) {
141 fFunc.DataElement(&
v.front(), i, gf.data(),
h.data());
142 for (
size_t j = 0; j < npar; ++j) {
144 for (
unsigned int k = j; k < npar; ++k) {
145 int idx = j + k * (k + 1) / 2;
151 print.
Error(
"Type of fit method is not supported, it must be chi2 or log-likelihood or Poisson Likelihood");
Double_t(* Function)(Double_t)
template wrapped class for adapting to FumiliFCNBase signature
double Up() const override
Error definition of the function.
double operator()(const double *v) const
void SetErrorDef(double up) override
add interface to set dynamically a new error definition Re-implement this function if needed.
void EvaluateAll(const std::vector< double > &v) override
evaluate gradient hessian and function value needed by fumili
double operator()(const std::vector< double > &v) const override
The meaning of the vector of parameters is of course defined by the user, who uses the values of thos...
FumiliFCNAdapter(const Function &f, unsigned int ndim, double up=1.)
~FumiliFCNAdapter() override
Extension of the FCNBase for the Fumili method.
void Debug(const Ts &... args)
void Error(const Ts &... args)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...