diff --git a/math/minuit2/CMakeLists.txt b/math/minuit2/CMakeLists.txt index c204e61b78ae7..3807757135abb 100644 --- a/math/minuit2/CMakeLists.txt +++ b/math/minuit2/CMakeLists.txt @@ -74,16 +74,15 @@ if(CMAKE_PROJECT_NAME STREQUAL ROOT) Minuit2/MnMinos.h Minuit2/MnParabola.h Minuit2/MnParabolaFactory.h - Minuit2/MnParabolaPoint.h Minuit2/MnParameterScan.h Minuit2/MnPlot.h + Minuit2/MnPoint.h Minuit2/MnPosDef.h Minuit2/MnPrint.h Minuit2/MnScan.h Minuit2/MnSeedGenerator.h Minuit2/MnSimplex.h Minuit2/MnStrategy.h - Minuit2/MnTiny.h Minuit2/MnTraceObject.h Minuit2/MnUserCovariance.h Minuit2/MnUserFcn.h @@ -148,7 +147,6 @@ if(CMAKE_PROJECT_NAME STREQUAL ROOT) src/MnScan.cxx src/MnSeedGenerator.cxx src/MnStrategy.cxx - src/MnTiny.cxx src/MnTraceObject.cxx src/MnUserFcn.cxx src/MnUserParameterState.cxx diff --git a/math/minuit2/inc/Minuit2/InitialGradientCalculator.h b/math/minuit2/inc/Minuit2/InitialGradientCalculator.h index 93dfcbefdac4d..bf6a080f425df 100644 --- a/math/minuit2/inc/Minuit2/InitialGradientCalculator.h +++ b/math/minuit2/inc/Minuit2/InitialGradientCalculator.h @@ -16,30 +16,9 @@ namespace ROOT { namespace Minuit2 { -class MnFcn; class MnUserTransformation; -class MnMachinePrecision; -/** - Class to calculate an initial estimate of the gradient - */ -class InitialGradientCalculator : public GradientCalculator { - -public: - InitialGradientCalculator(const MnFcn &fcn, const MnUserTransformation &par) : fFcn(fcn), fTransformation(par) {} - - FunctionGradient operator()(const MinimumParameters &) const override; - - FunctionGradient operator()(const MinimumParameters &, const FunctionGradient &) const override; - - const MnFcn &Fcn() const { return fFcn; } - const MnUserTransformation &Trafo() const { return fTransformation; } - const MnMachinePrecision &Precision() const; - -private: - const MnFcn &fFcn; - const MnUserTransformation &fTransformation; -}; +FunctionGradient calculateInitialGradient(const MinimumParameters &, const MnUserTransformation &, double errorDef); } // namespace Minuit2 diff --git a/math/minuit2/inc/Minuit2/MnLineSearch.h b/math/minuit2/inc/Minuit2/MnLineSearch.h index c2a36d5ecffc4..630874b4804b7 100644 --- a/math/minuit2/inc/Minuit2/MnLineSearch.h +++ b/math/minuit2/inc/Minuit2/MnLineSearch.h @@ -11,6 +11,7 @@ #define ROOT_Minuit2_MnLineSearch #include "Minuit2/MnMatrix.h" +#include "Minuit2/MnPoint.h" namespace ROOT { @@ -19,7 +20,6 @@ namespace Minuit2 { class MnFcn; class MinimumParameters; class MnMachinePrecision; -class MnParabolaPoint; /** @@ -40,15 +40,15 @@ and Lorenzo Moneta class MnLineSearch { public: - MnParabolaPoint operator()(const MnFcn &, const MinimumParameters &, const MnAlgebraicVector &, double, - const MnMachinePrecision &) const; + MnPoint operator()(const MnFcn &, const MinimumParameters &, const MnAlgebraicVector &, double, + const MnMachinePrecision &) const; #ifdef USE_OTHER_LS - MnParabolaPoint CubicSearch(const MnFcn &, const MinimumParameters &, const MnAlgebraicVector &, double, double, - const MnMachinePrecision &) const; + MnPoint CubicSearch(const MnFcn &, const MinimumParameters &, const MnAlgebraicVector &, double, double, + const MnMachinePrecision &) const; - MnParabolaPoint BrentSearch(const MnFcn &, const MinimumParameters &, const MnAlgebraicVector &, double, double, - const MnMachinePrecision &) const; + MnPoint BrentSearch(const MnFcn &, const MinimumParameters &, const MnAlgebraicVector &, double, double, + const MnMachinePrecision &) const; #endif }; diff --git a/math/minuit2/inc/Minuit2/MnMachinePrecision.h b/math/minuit2/inc/Minuit2/MnMachinePrecision.h index 59d9972f7e254..2ed1c0dece08f 100644 --- a/math/minuit2/inc/Minuit2/MnMachinePrecision.h +++ b/math/minuit2/inc/Minuit2/MnMachinePrecision.h @@ -52,8 +52,12 @@ class MnMachinePrecision { void ComputePrecision(); private: + double One() const; + double Tiny(double epsp1) const; + double fEpsMac; double fEpsMa2; + double fOne = 1.; }; } // namespace Minuit2 diff --git a/math/minuit2/inc/Minuit2/MnParabola.h b/math/minuit2/inc/Minuit2/MnParabola.h index 9c1c11665455f..5ae0ba9791bd2 100644 --- a/math/minuit2/inc/Minuit2/MnParabola.h +++ b/math/minuit2/inc/Minuit2/MnParabola.h @@ -30,118 +30,29 @@ and Lorenzo Moneta class MnParabola { public: - /** - - Constructor that initializes the parabola with its three parameters. - - @param a the coefficient of the quadratic term - @param b the coefficient of the linear term - @param c the constant - - */ - + /// Constructor that initializes the parabola with its three parameters. + /// + /// @param a the coefficient of the quadratic term. + /// @param b the coefficient of the linear term. + /// @param c the constant. MnParabola(double a, double b, double c) : fA(a), fB(b), fC(c) {} - /** - - Evaluates the parabola a the point x. - - @param x the coordinate where the parabola needs to be evaluated. - - @return the y coordinate of the parabola corresponding to x. - - */ - + /// Evaluates the parabola a the point x. double Y(double x) const { return (fA * x * x + fB * x + fC); } - /** - - Calculates the bigger of the two x values corresponding to the - given y Value. - -
- - ???????!!!!!!!!! And when there is none?? it looks like it will - crash?? what is sqrt (-1.0) ? - - @param y the y Value for which the x Value is to be calculated. - - @return the bigger one of the two corresponding values. - - */ - - // ok, at first glance it does not look like the formula for the quadratic - // equation, but it is! ;-) - double X_pos(double y) const { return (std::sqrt(y / fA + Min() * Min() - fC / fA) + Min()); } - // maybe it is worth to check the performance improvement with the below formula?? - // double X_pos(double y) const {return (std::sqrt(y/fA + fB*fB/(4.*fA*fA) - fC/fA) - fB/(2.*fA));} - - /** - - Calculates the smaller of the two x values corresponding to the - given y Value. - -
- - ???????!!!!!!!!! And when there is none?? it looks like it will - crash?? what is sqrt (-1.0) ? - - @param y the y Value for which the x Value is to be calculated. - - @return the smaller one of the two corresponding values. - - */ - - double X_neg(double y) const { return (-std::sqrt(y / fA + Min() * Min() - fC / fA) + Min()); } - - /** - - Calculates the x coordinate of the Minimum of the parabola. - - @return x coordinate of the Minimum. - - */ - + /// Calculate the x coordinate of the Minimum of the parabola. double Min() const { return -fB / (2. * fA); } - /** - - Calculates the y coordinate of the Minimum of the parabola. - - @return y coordinate of the Minimum. - - */ - + /// Calculate the y coordinate of the Minimum of the parabola. double YMin() const { return (-fB * fB / (4. * fA) + fC); } - /** - - Accessor to the coefficient of the quadratic term. - - @return the coefficient of the quadratic term. - - */ - + /// Get the coefficient of the quadratic term. double A() const { return fA; } - /** - - Accessor to the coefficient of the linear term. - - @return the coefficient of the linear term. - - */ - + /// Get the coefficient of the linear term. double B() const { return fB; } - /** - - Accessor to the coefficient of the constant term. - - @return the coefficient of the constant term. - - */ - + /// Get the coefficient of the constant term. double C() const { return fC; } private: diff --git a/math/minuit2/inc/Minuit2/MnParabolaFactory.h b/math/minuit2/inc/Minuit2/MnParabolaFactory.h index 57f7da674f112..89547e42c7160 100644 --- a/math/minuit2/inc/Minuit2/MnParabolaFactory.h +++ b/math/minuit2/inc/Minuit2/MnParabolaFactory.h @@ -10,18 +10,18 @@ #ifndef ROOT_Minuit2_MnParabolaFactory #define ROOT_Minuit2_MnParabolaFactory +#include "Minuit2/MnParabola.h" +#include "Minuit2/MnPoint.h" + namespace ROOT { namespace Minuit2 { -class MnParabola; -class MnParabolaPoint; - class MnParabolaFactory { public: - MnParabola operator()(const MnParabolaPoint &, const MnParabolaPoint &, const MnParabolaPoint &) const; + MnParabola operator()(const MnPoint &, const MnPoint &, const MnPoint &) const; - MnParabola operator()(const MnParabolaPoint &, double, const MnParabolaPoint &) const; + MnParabola operator()(const MnPoint &, double, const MnPoint &) const; }; } // namespace Minuit2 diff --git a/math/minuit2/inc/Minuit2/MnParabolaPoint.h b/math/minuit2/inc/Minuit2/MnParabolaPoint.h deleted file mode 100644 index 21b4ab7e58997..0000000000000 --- a/math/minuit2/inc/Minuit2/MnParabolaPoint.h +++ /dev/null @@ -1,79 +0,0 @@ -// @(#)root/minuit2:$Id$ -// Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005 - -/********************************************************************** - * * - * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT * - * * - **********************************************************************/ - -#ifndef ROOT_Minuit2_MnParabolaPoint -#define ROOT_Minuit2_MnParabolaPoint - -namespace ROOT { - -namespace Minuit2 { - -/** - -A point of a parabola. - -
-
-????!!!! in reality it is just a general point in two dimensional space,
-there is nothing that would indicate, that it belongs to a parabola.
-This class defines simply an (x,y) pair!!!!
-
-@author Fred James and Matthias Winkler; comments added by Andras Zsenei
-and Lorenzo Moneta
-
-@ingroup Minuit
-
-\todo Should it be called MnParabolaPoint or just Point?
-
- */
-
-class MnParabolaPoint {
-
-public:
- /**
-
- Initializes the point with its coordinates.
-
- @param x the x (first) coordinate of the point.
- @param y the y (second) coordinate of the point.
-
- */
-
- MnParabolaPoint(double x, double y) : fX(x), fY(y) {}
-
- /**
-
- Accessor to the x (first) coordinate.
-
- @return the x (first) coordinate of the point.
-
- */
-
- double X() const { return fX; }
-
- /**
-
- Accessor to the y (second) coordinate.
-
- @return the y (second) coordinate of the point.
-
- */
-
- double Y() const { return fY; }
-
-private:
- double fX;
- double fY;
-};
-
-} // namespace Minuit2
-
-} // namespace ROOT
-
-#endif // ROOT_Minuit2_MnParabolaPoint
diff --git a/math/minuit2/inc/Minuit2/MnPoint.h b/math/minuit2/inc/Minuit2/MnPoint.h
new file mode 100644
index 0000000000000..b6272f325266c
--- /dev/null
+++ b/math/minuit2/inc/Minuit2/MnPoint.h
@@ -0,0 +1,52 @@
+// @(#)root/minuit2:$Id$
+// Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005
+
+/**********************************************************************
+ * *
+ * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
+ * *
+ **********************************************************************/
+
+#ifndef ROOT_Minuit2_MnPoint
+#define ROOT_Minuit2_MnPoint
+
+namespace ROOT {
+
+namespace Minuit2 {
+
+/**
+
+A point in x-y.
+
+@author Fred James and Matthias Winkler; comments added by Andras Zsenei
+and Lorenzo Moneta
+
+@ingroup Minuit
+
+ */
+
+class MnPoint {
+
+public:
+ /// Initializes the point with its coordinates.
+ ///
+ /// @param x the x (first) coordinate of the point.
+ /// @param y the y (second) coordinate of the point.
+ MnPoint(double x, double y) : fX(x), fY(y) {}
+
+ /// Get the x (first) coordinate.
+ double X() const { return fX; }
+
+ /// Get the y (second) coordinate.
+ double Y() const { return fY; }
+
+private:
+ double fX;
+ double fY;
+};
+
+} // namespace Minuit2
+
+} // namespace ROOT
+
+#endif // ROOT_Minuit2_MnPoint
diff --git a/math/minuit2/inc/Minuit2/MnTiny.h b/math/minuit2/inc/Minuit2/MnTiny.h
deleted file mode 100644
index 0410b837903e3..0000000000000
--- a/math/minuit2/inc/Minuit2/MnTiny.h
+++ /dev/null
@@ -1,32 +0,0 @@
-// @(#)root/minuit2:$Id$
-// Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005
-
-/**********************************************************************
- * *
- * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
- * *
- **********************************************************************/
-
-#ifndef ROOT_Minuit2_MnTiny
-#define ROOT_Minuit2_MnTiny
-
-namespace ROOT {
-
-namespace Minuit2 {
-
-class MnTiny {
-
-public:
- double One() const;
-
- double operator()(double epsp1) const;
-
-private:
- double fOne = 1.;
-};
-
-} // namespace Minuit2
-
-} // namespace ROOT
-
-#endif // ROOT_Minuit2_MnTiny
diff --git a/math/minuit2/inc/Minuit2/Numerical2PGradientCalculator.h b/math/minuit2/inc/Minuit2/Numerical2PGradientCalculator.h
index 2a9daf062f8aa..64ecc9a763825 100644
--- a/math/minuit2/inc/Minuit2/Numerical2PGradientCalculator.h
+++ b/math/minuit2/inc/Minuit2/Numerical2PGradientCalculator.h
@@ -43,7 +43,6 @@ class Numerical2PGradientCalculator : public GradientCalculator {
FunctionGradient operator()(const MinimumParameters &, const FunctionGradient &) const override;
- const MnFcn &Fcn() const { return fFcn; }
const MnUserTransformation &Trafo() const { return fTransformation; }
const MnMachinePrecision &Precision() const;
const MnStrategy &Strategy() const { return fStrategy; }
diff --git a/math/minuit2/src/CMakeLists.txt b/math/minuit2/src/CMakeLists.txt
index 630750baf233b..2344c6e07b808 100644
--- a/math/minuit2/src/CMakeLists.txt
+++ b/math/minuit2/src/CMakeLists.txt
@@ -64,16 +64,15 @@ set(MINUIT2_HEADERS
MnMinos.h
MnParabola.h
MnParabolaFactory.h
- MnParabolaPoint.h
MnParameterScan.h
MnPlot.h
+ MnPoint.h
MnPosDef.h
MnPrint.h
MnScan.h
MnSeedGenerator.h
MnSimplex.h
MnStrategy.h
- MnTiny.h
MnTraceObject.h
MnUserCovariance.h
MnUserFcn.h
@@ -137,7 +136,6 @@ set(MINUIT2_SOURCES
MnScan.cxx
MnSeedGenerator.cxx
MnStrategy.cxx
- MnTiny.cxx
MnTraceObject.cxx
MnUserFcn.cxx
MnUserParameterState.cxx
diff --git a/math/minuit2/src/FumiliBuilder.cxx b/math/minuit2/src/FumiliBuilder.cxx
index f9bf7f3b93caf..9f2d867a29904 100644
--- a/math/minuit2/src/FumiliBuilder.cxx
+++ b/math/minuit2/src/FumiliBuilder.cxx
@@ -10,7 +10,6 @@
#include "Minuit2/FumiliBuilder.h"
#include "Minuit2/FumiliStandardMaximumLikelihoodFCN.h"
#include "Minuit2/GradientCalculator.h"
-//#include "Minuit2/Numerical2PGradientCalculator.h"
#include "Minuit2/MinimumState.h"
#include "Minuit2/MinimumError.h"
#include "Minuit2/FunctionGradient.h"
@@ -20,7 +19,6 @@
#include "Minuit2/MnFcn.h"
#include "Minuit2/MnMachinePrecision.h"
#include "Minuit2/MnPosDef.h"
-#include "Minuit2/MnParabolaPoint.h"
#include "Minuit2/MnStrategy.h"
#include "Minuit2/MnHesse.h"
#include "Minuit2/MnPrint.h"
@@ -265,7 +263,6 @@ FunctionMinimum FumiliBuilder::Minimum(const MnFcn &fcn, const GradientCalculato
}
}
-
// take a full step
//evaluate function only if doing a line search
@@ -277,7 +274,7 @@ FunctionMinimum FumiliBuilder::Minimum(const MnFcn &fcn, const GradientCalculato
if (doLineSearch && p.Fval() >= s0.Fval()) {
print.Debug("Do a line search", fcn.NumOfCalls());
MnLineSearch lsearch;
- MnParabolaPoint pp = lsearch(fcn, s0.Parameters(), step, gdel, prec);
+ auto pp = lsearch(fcn, s0.Parameters(), step, gdel, prec);
if (std::fabs(pp.Y() - s0.Fval()) < prec.Eps()) {
// std::cout<<"FumiliBuilder: no improvement"<