10 #ifndef ROOT_Minuit2_FumiliFCNAdapter
11 #define ROOT_Minuit2_FumiliFCNAdapter
13 #ifndef ROOT_Minuit2_FumiliFCNBase
17 #ifndef ROOT_Math_FitMethodFunction
21 #ifndef ROOT_Minuit2_MnPrint
46 template<
class Function>
52 typedef typename Function::Type_t
Type_t;
64 return fFunc.operator()(&v[0]);
67 return fFunc.operator()(
v);
94 template<
class Function>
100 unsigned int npar = Dimension();
101 if (npar != v.size() ) std::cout <<
"npar = " << npar <<
" " << v.size() << std::endl;
105 std::vector<double> & grad = Gradient();
106 std::vector<double> & hess = Hessian();
108 assert(grad.size() == npar);
109 grad.assign( npar, 0.0);
110 hess.assign( hess.size(), 0.0);
113 unsigned int ndata = fFunc.NPoints();
115 std::vector<double> gf(npar);
121 if (fFunc.Type() == Function::kLeastSquare) {
123 for (
unsigned int i = 0; i <
ndata; ++i) {
125 double fval = fFunc.DataElement(&v.front(), i, &gf[0]);
130 for (
unsigned int j = 0; j < npar; ++j) {
131 grad[j] += 2. * fval * gf[j];
132 for (
unsigned int k = j; k < npar; ++ k) {
133 int idx = j + k*(k+1)/2;
134 hess[idx] += 2.0 * gf[j] * gf[k];
139 else if (fFunc.Type() == Function::kLogLikelihood) {
142 for (
unsigned int i = 0; i <
ndata; ++i) {
146 double fval = fFunc.DataElement(&v.front(), i, &gf[0]);
150 for (
unsigned int j = 0; j < npar; ++j) {
153 for (
unsigned int k = j; k < npar; ++ k) {
154 int idx = j + k*(k+1)/2;
155 hess[idx] += gfj * gf[k] ;
161 MN_ERROR_MSG(
"FumiliFCNAdapter: type of fit method is not supported, it must be chi2 or log-likelihood");
173 #endif //ROOT_Minuit2_FCNAdapter
#define MN_ERROR_MSG(str)
Namespace for new ROOT classes and functions.
double operator()(const double *v) const
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 SetErrorDef(double up)
add interface to set dynamically a new error definition Re-implement this function if needed...
double Up() const
Error definition of the function.
template wrapped class for adapting to FumiliFCNBase signature
Extension of the FCNBase for the Fumili method.
FumiliFCNAdapter(const Function &f, unsigned int ndim, double up=1.)
void EvaluateAll(const std::vector< double > &v)
evaluate gradient hessian and function value needed by fumili