2626#include " Minuit2/NumericalDerivator.h"
2727#include < cmath>
2828#include < algorithm>
29- #include < Math/IFunction.h>
3029#include < iostream>
3130#include < TMath.h>
3231#include < cassert>
@@ -44,51 +43,52 @@ NumericalDerivator::NumericalDerivator(bool always_exactly_mimic_minuit2)
4443
4544NumericalDerivator::NumericalDerivator (double step_tolerance, double grad_tolerance, unsigned int ncycles,
4645 double error_level, bool always_exactly_mimic_minuit2)
47- : fStepTolerance (step_tolerance), fGradTolerance (grad_tolerance), fUp (error_level), fNCycles (ncycles),
46+ : fStepTolerance (step_tolerance),
47+ fGradTolerance (grad_tolerance),
48+ fUp(error_level),
49+ fNCycles(ncycles),
4850 fAlwaysExactlyMimicMinuit2(always_exactly_mimic_minuit2)
4951{
5052}
5153
52- NumericalDerivator::NumericalDerivator (const NumericalDerivator &/* other*/ ) = default;
53-
54+ NumericalDerivator::NumericalDerivator (const NumericalDerivator & /* other*/ ) = default;
5455
5556// / This function sets internal state based on input parameters. This state
5657// / setup is used in the actual (partial) derivative calculations.
57- void NumericalDerivator::SetupDifferentiate (const ROOT::Math::IBaseFunctionMultiDim *function, const double *cx,
58+ void NumericalDerivator::SetupDifferentiate (unsigned int nDim, const FCNBase *function, const double *cx,
5859 std::span<const ROOT::Fit::ParameterSettings> parameters)
5960{
6061 assert (function != nullptr && " function is a nullptr" );
6162
62- fVx .resize (function-> NDim () );
63- fVxExternal .resize (function-> NDim () );
64- fVxFValCache .resize (function-> NDim () );
65- std::copy (cx, cx + function-> NDim () , fVx .data ());
63+ fVx .resize (nDim );
64+ fVxExternal .resize (nDim );
65+ fVxFValCache .resize (nDim );
66+ std::copy (cx, cx + nDim , fVx .data ());
6667
6768 // convert to Minuit external parameters
68- for (unsigned i = 0 ; i < function-> NDim () ; i++) {
69+ for (unsigned i = 0 ; i < nDim ; i++) {
6970 fVxExternal [i] = Int2ext (parameters[i], fVx [i]);
7071 }
7172
7273 if (fVx != fVxFValCache ) {
7374 fVxFValCache = fVx ;
74- fVal = (*function)(fVxExternal . data () ); // value of function at given points
75+ fVal = (*function)(fVxExternal ); // value of function at given points
7576 }
7677
7778 fDfmin = 8 . * fPrecision .Eps2 () * (std::abs (fVal ) + fUp );
7879 fVrysml = 8 . * fPrecision .Eps () * fPrecision .Eps ();
7980}
8081
81- DerivatorElement NumericalDerivator::PartialDerivative (const ROOT::Math::IBaseFunctionMultiDim *function,
82- const double *x,
82+ DerivatorElement NumericalDerivator::PartialDerivative (unsigned int nDim, const FCNBase *function, const double *x,
8383 std::span<const ROOT::Fit::ParameterSettings> parameters,
8484 unsigned int i_component, DerivatorElement previous)
8585{
86- SetupDifferentiate (function, x, parameters);
86+ SetupDifferentiate (nDim, function, x, parameters);
8787 return FastPartialDerivative (function, parameters, i_component, previous);
8888}
8989
9090// leaves the parameter setup to the caller
91- DerivatorElement NumericalDerivator::FastPartialDerivative (const ROOT::Math::IBaseFunctionMultiDim *function,
91+ DerivatorElement NumericalDerivator::FastPartialDerivative (const FCNBase *function,
9292 std::span<const ROOT::Fit::ParameterSettings> parameters,
9393 unsigned int i_component, const DerivatorElement &previous)
9494{
@@ -121,11 +121,11 @@ DerivatorElement NumericalDerivator::FastPartialDerivative(const ROOT::Math::IBa
121121 step_old = step;
122122 fVx [i_component] = xtf + step;
123123 fVxExternal [i_component] = Int2ext (parameters[i_component], fVx [i_component]);
124- double fs1 = (*function)(fVxExternal . data () );
124+ double fs1 = (*function)(fVxExternal );
125125
126126 fVx [i_component] = xtf - step;
127127 fVxExternal [i_component] = Int2ext (parameters[i_component], fVx [i_component]);
128- double fs2 = (*function)(fVxExternal . data () );
128+ double fs2 = (*function)(fVxExternal );
129129
130130 fVx [i_component] = xtf;
131131 fVxExternal [i_component] = Int2ext (parameters[i_component], fVx [i_component]);
@@ -142,24 +142,24 @@ DerivatorElement NumericalDerivator::FastPartialDerivative(const ROOT::Math::IBa
142142 return deriv;
143143}
144144
145- DerivatorElement NumericalDerivator::operator ()(const ROOT::Math::IBaseFunctionMultiDim *function, const double *x,
145+ DerivatorElement NumericalDerivator::operator ()(unsigned int nDim, const FCNBase *function, const double *x,
146146 std::span<const ROOT::Fit::ParameterSettings> parameters,
147147 unsigned int i_component, const DerivatorElement &previous)
148148{
149- return PartialDerivative (function, x, parameters, i_component, previous);
149+ return PartialDerivative (nDim, function, x, parameters, i_component, previous);
150150}
151151
152152std::vector<DerivatorElement>
153- NumericalDerivator::Differentiate (const ROOT::Math::IBaseFunctionMultiDim *function, const double *cx,
153+ NumericalDerivator::Differentiate (unsigned int nDim, const FCNBase *function, const double *cx,
154154 std::span<const ROOT::Fit::ParameterSettings> parameters,
155155 std::span<const DerivatorElement> previous_gradient)
156156{
157- SetupDifferentiate (function, cx, parameters);
157+ SetupDifferentiate (nDim, function, cx, parameters);
158158
159159 std::vector<DerivatorElement> gradient;
160- gradient.reserve (function-> NDim () );
160+ gradient.reserve (nDim );
161161
162- for (unsigned int ix = 0 ; ix < function-> NDim () ; ++ix) {
162+ for (unsigned int ix = 0 ; ix < nDim ; ++ix) {
163163 gradient.emplace_back (FastPartialDerivative (function, parameters, ix, previous_gradient[ix]));
164164 }
165165
0 commit comments