26
26
#include " Minuit2/NumericalDerivator.h"
27
27
#include < cmath>
28
28
#include < algorithm>
29
- #include < Math/IFunction.h>
30
29
#include < iostream>
31
30
#include < TMath.h>
32
31
#include < cassert>
@@ -44,51 +43,52 @@ NumericalDerivator::NumericalDerivator(bool always_exactly_mimic_minuit2)
44
43
45
44
NumericalDerivator::NumericalDerivator (double step_tolerance, double grad_tolerance, unsigned int ncycles,
46
45
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),
48
50
fAlwaysExactlyMimicMinuit2(always_exactly_mimic_minuit2)
49
51
{
50
52
}
51
53
52
- NumericalDerivator::NumericalDerivator (const NumericalDerivator &/* other*/ ) = default;
53
-
54
+ NumericalDerivator::NumericalDerivator (const NumericalDerivator & /* other*/ ) = default;
54
55
55
56
// / This function sets internal state based on input parameters. This state
56
57
// / 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,
58
59
std::span<const ROOT::Fit::ParameterSettings> parameters)
59
60
{
60
61
assert (function != nullptr && " function is a nullptr" );
61
62
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 ());
66
67
67
68
// convert to Minuit external parameters
68
- for (unsigned i = 0 ; i < function-> NDim () ; i++) {
69
+ for (unsigned i = 0 ; i < nDim ; i++) {
69
70
fVxExternal [i] = Int2ext (parameters[i], fVx [i]);
70
71
}
71
72
72
73
if (fVx != fVxFValCache ) {
73
74
fVxFValCache = fVx ;
74
- fVal = (*function)(fVxExternal . data () ); // value of function at given points
75
+ fVal = (*function)(fVxExternal ); // value of function at given points
75
76
}
76
77
77
78
fDfmin = 8 . * fPrecision .Eps2 () * (std::abs (fVal ) + fUp );
78
79
fVrysml = 8 . * fPrecision .Eps () * fPrecision .Eps ();
79
80
}
80
81
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,
83
83
std::span<const ROOT::Fit::ParameterSettings> parameters,
84
84
unsigned int i_component, DerivatorElement previous)
85
85
{
86
- SetupDifferentiate (function, x, parameters);
86
+ SetupDifferentiate (nDim, function, x, parameters);
87
87
return FastPartialDerivative (function, parameters, i_component, previous);
88
88
}
89
89
90
90
// leaves the parameter setup to the caller
91
- DerivatorElement NumericalDerivator::FastPartialDerivative (const ROOT::Math::IBaseFunctionMultiDim *function,
91
+ DerivatorElement NumericalDerivator::FastPartialDerivative (const FCNBase *function,
92
92
std::span<const ROOT::Fit::ParameterSettings> parameters,
93
93
unsigned int i_component, const DerivatorElement &previous)
94
94
{
@@ -121,11 +121,11 @@ DerivatorElement NumericalDerivator::FastPartialDerivative(const ROOT::Math::IBa
121
121
step_old = step;
122
122
fVx [i_component] = xtf + step;
123
123
fVxExternal [i_component] = Int2ext (parameters[i_component], fVx [i_component]);
124
- double fs1 = (*function)(fVxExternal . data () );
124
+ double fs1 = (*function)(fVxExternal );
125
125
126
126
fVx [i_component] = xtf - step;
127
127
fVxExternal [i_component] = Int2ext (parameters[i_component], fVx [i_component]);
128
- double fs2 = (*function)(fVxExternal . data () );
128
+ double fs2 = (*function)(fVxExternal );
129
129
130
130
fVx [i_component] = xtf;
131
131
fVxExternal [i_component] = Int2ext (parameters[i_component], fVx [i_component]);
@@ -142,24 +142,24 @@ DerivatorElement NumericalDerivator::FastPartialDerivative(const ROOT::Math::IBa
142
142
return deriv;
143
143
}
144
144
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,
146
146
std::span<const ROOT::Fit::ParameterSettings> parameters,
147
147
unsigned int i_component, const DerivatorElement &previous)
148
148
{
149
- return PartialDerivative (function, x, parameters, i_component, previous);
149
+ return PartialDerivative (nDim, function, x, parameters, i_component, previous);
150
150
}
151
151
152
152
std::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,
154
154
std::span<const ROOT::Fit::ParameterSettings> parameters,
155
155
std::span<const DerivatorElement> previous_gradient)
156
156
{
157
- SetupDifferentiate (function, cx, parameters);
157
+ SetupDifferentiate (nDim, function, cx, parameters);
158
158
159
159
std::vector<DerivatorElement> gradient;
160
- gradient.reserve (function-> NDim () );
160
+ gradient.reserve (nDim );
161
161
162
- for (unsigned int ix = 0 ; ix < function-> NDim () ; ++ix) {
162
+ for (unsigned int ix = 0 ; ix < nDim ; ++ix) {
163
163
gradient.emplace_back (FastPartialDerivative (function, parameters, ix, previous_gradient[ix]));
164
164
}
165
165
0 commit comments