@@ -22,13 +22,13 @@ namespace ROOT {
2222
2323namespace Minuit2 {
2424
25- FunctionGradient InitialGradientCalculator::operator ()(const MinimumParameters &par) const
25+ // / Initial rough estimate of the gradient using the parameter step size.
26+ FunctionGradient
27+ calculateInitialGradient (const MinimumParameters &par, const MnUserTransformation &trafo, double errorDef)
2628{
27- // initial rough estimate of the gradient using the parameter step size
28-
2929 assert (par.IsValid ());
3030
31- unsigned int n = Trafo () .VariableParameters ();
31+ unsigned int n = trafo .VariableParameters ();
3232 assert (n == par.Vec ().size ());
3333
3434 MnPrint print (" InitialGradientCalculator" );
@@ -38,58 +38,46 @@ FunctionGradient InitialGradientCalculator::operator()(const MinimumParameters &
3838 MnAlgebraicVector gr (n), gr2 (n), gst (n);
3939
4040 for (unsigned int i = 0 ; i < n; i++) {
41- unsigned int exOfIn = Trafo () .ExtOfInt (i);
41+ unsigned int exOfIn = trafo .ExtOfInt (i);
4242
4343 double var = par.Vec ()(i);
44- double werr = Trafo () .Parameter (exOfIn).Error ();
45- double save1 = Trafo () .Int2ext (i, var);
44+ double werr = trafo .Parameter (exOfIn).Error ();
45+ double save1 = trafo .Int2ext (i, var);
4646 double save2 = save1 + werr;
47- if (Trafo () .Parameter (exOfIn).HasLimits ()) {
48- if (Trafo () .Parameter (exOfIn).HasUpperLimit () && save2 > Trafo () .Parameter (exOfIn).UpperLimit ())
49- save2 = Trafo () .Parameter (exOfIn).UpperLimit ();
47+ if (trafo .Parameter (exOfIn).HasLimits ()) {
48+ if (trafo .Parameter (exOfIn).HasUpperLimit () && save2 > trafo .Parameter (exOfIn).UpperLimit ())
49+ save2 = trafo .Parameter (exOfIn).UpperLimit ();
5050 }
51- double var2 = Trafo () .Ext2int (exOfIn, save2);
51+ double var2 = trafo .Ext2int (exOfIn, save2);
5252 double vplu = var2 - var;
5353 save2 = save1 - werr;
54- if (Trafo () .Parameter (exOfIn).HasLimits ()) {
55- if (Trafo () .Parameter (exOfIn).HasLowerLimit () && save2 < Trafo () .Parameter (exOfIn).LowerLimit ())
56- save2 = Trafo () .Parameter (exOfIn).LowerLimit ();
54+ if (trafo .Parameter (exOfIn).HasLimits ()) {
55+ if (trafo .Parameter (exOfIn).HasLowerLimit () && save2 < trafo .Parameter (exOfIn).LowerLimit ())
56+ save2 = trafo .Parameter (exOfIn).LowerLimit ();
5757 }
58- var2 = Trafo () .Ext2int (exOfIn, save2);
58+ var2 = trafo .Ext2int (exOfIn, save2);
5959 double vmin = var2 - var;
60- double gsmin = 8 . * Precision ().Eps2 () * (std::fabs (var) + Precision ().Eps2 ());
60+ double gsmin = 8 . * trafo. Precision ().Eps2 () * (std::fabs (var) + trafo. Precision ().Eps2 ());
6161 // protect against very small step sizes which can cause dirin to zero and then nan values in grd
6262 double dirin = std::max (0.5 * (std::fabs (vplu) + std::fabs (vmin)), gsmin);
63- double g2 = 2.0 * fFcn . ErrorDef () / (dirin * dirin);
63+ double g2 = 2.0 * errorDef / (dirin * dirin);
6464 double gstep = std::max (gsmin, 0.1 * dirin);
6565 double grd = g2 * dirin;
66- if (Trafo () .Parameter (exOfIn).HasLimits ()) {
66+ if (trafo .Parameter (exOfIn).HasLimits ()) {
6767 if (gstep > 0.5 )
6868 gstep = 0.5 ;
6969 }
7070 gr (i) = grd;
7171 gr2 (i) = g2;
7272 gst (i) = gstep;
7373
74- print.Trace (" Computed initial gradient for parameter" , Trafo () .Name (exOfIn), " value" , var, " [" , vmin, " ," , vplu,
74+ print.Trace (" Computed initial gradient for parameter" , trafo .Name (exOfIn), " value" , var, " [" , vmin, " ," , vplu,
7575 " ]" , " dirin" , dirin, " grd" , grd, " g2" , g2);
7676 }
7777
7878 return FunctionGradient (gr, gr2, gst);
7979}
8080
81- FunctionGradient InitialGradientCalculator::operator ()(const MinimumParameters &par, const FunctionGradient &) const
82- {
83- // Base class interface
84- return (*this )(par);
85- }
86-
87- const MnMachinePrecision &InitialGradientCalculator::Precision () const
88- {
89- // return precision (is set in transformation class)
90- return fTransformation .Precision ();
91- }
92-
9381} // namespace Minuit2
9482
9583} // namespace ROOT
0 commit comments