Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Minuit2] Code improvements #17869

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions math/minuit2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 1 addition & 22 deletions math/minuit2/inc/Minuit2/InitialGradientCalculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions math/minuit2/inc/Minuit2/MnLineSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define ROOT_Minuit2_MnLineSearch

#include "Minuit2/MnMatrix.h"
#include "Minuit2/MnPoint.h"

namespace ROOT {

Expand All @@ -19,7 +20,6 @@ namespace Minuit2 {
class MnFcn;
class MinimumParameters;
class MnMachinePrecision;
class MnParabolaPoint;

/**

Expand All @@ -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
};

Expand Down
4 changes: 4 additions & 0 deletions math/minuit2/inc/Minuit2/MnMachinePrecision.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
111 changes: 11 additions & 100 deletions math/minuit2/inc/Minuit2/MnParabola.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<p>

???????!!!!!!!!! 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.

<p>

???????!!!!!!!!! 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:
Expand Down
10 changes: 5 additions & 5 deletions math/minuit2/inc/Minuit2/MnParabolaFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
79 changes: 0 additions & 79 deletions math/minuit2/inc/Minuit2/MnParabolaPoint.h

This file was deleted.

52 changes: 52 additions & 0 deletions math/minuit2/inc/Minuit2/MnPoint.h
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading