Skip to content

Commit

Permalink
[Minuit2] Remove redundant constructors
Browse files Browse the repository at this point in the history
A `MnUserParameters` instance implicitly converts to a
`MnUserParameterState`.
  • Loading branch information
guitargeek committed Sep 16, 2024
1 parent 65d8efb commit 8dd7784
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 87 deletions.
10 changes: 1 addition & 9 deletions math/minuit2/inc/Minuit2/MnFumiliMinimize.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ class MnFumiliMinimize : public MnApplication {
{
}

/// construct from FumiliFCNBase + MnUserParameters
MnFumiliMinimize(const FumiliFCNBase &fcn, const MnUserParameters &par, unsigned int stra = 1)
: MnApplication(fcn, MnUserParameterState(par), MnStrategy(stra)), fMinimizer(FumiliMinimizer()), fFCN(fcn)
{
}

/// construct from FumiliFCNBase + MnUserParameters + MnUserCovariance
MnFumiliMinimize(const FumiliFCNBase &fcn, const MnUserParameters &par, const MnUserCovariance &cov,
unsigned int stra = 1)
Expand All @@ -74,7 +68,7 @@ class MnFumiliMinimize : public MnApplication {
}

/// construct from FumiliFCNBase + MnUserParameterState + MnStrategy
MnFumiliMinimize(const FumiliFCNBase &fcn, const MnUserParameterState &par, const MnStrategy &str)
MnFumiliMinimize(const FumiliFCNBase &fcn, const MnUserParameterState &par, const MnStrategy &str = MnStrategy{1})
: MnApplication(fcn, MnUserParameterState(par), str), fMinimizer(FumiliMinimizer()), fFCN(fcn)
{
}
Expand All @@ -85,8 +79,6 @@ class MnFumiliMinimize : public MnApplication {
{
}

~MnFumiliMinimize() override {}

FumiliMinimizer &Minimizer() override { return fMinimizer; }
const FumiliMinimizer &Minimizer() const override { return fMinimizer; }

Expand Down
4 changes: 0 additions & 4 deletions math/minuit2/inc/Minuit2/MnHesse.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class MnHesse {
/// conctructor with specific strategy
MnHesse(const MnStrategy &stra) : fStrategy(stra) {}

~MnHesse() {}

///
/// low-level API
///
Expand All @@ -67,8 +65,6 @@ class MnHesse {
///
/// high-level API
///
/// FCN + MnUserParameters
MnUserParameterState operator()(const FCNBase &, const MnUserParameters &, unsigned int maxcalls = 0) const;
/// FCN + MnUserParameters + MnUserCovariance
MnUserParameterState
operator()(const FCNBase &, const MnUserParameters &, const MnUserCovariance &, unsigned int maxcalls = 0) const;
Expand Down
20 changes: 6 additions & 14 deletions math/minuit2/inc/Minuit2/MnMigrad.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,36 @@ class MnMigrad : public MnApplication {
public:
/// construct from FCNBase + std::vector for parameters and errors
MnMigrad(const FCNBase &fcn, std::span<const double> par, std::span<const double> err, unsigned int stra = 1)
: MnApplication(fcn, MnUserParameterState(par, err), MnStrategy(stra)), fMinimizer(VariableMetricMinimizer())
: MnApplication(fcn, {par, err}, MnStrategy(stra)), fMinimizer(VariableMetricMinimizer())
{
}

/// construct from FCNBase + std::vector for parameters and covariance
MnMigrad(const FCNBase &fcn, std::span<const double> par, unsigned int nrow, std::span<const double> cov,
unsigned int stra = 1)
: MnApplication(fcn, MnUserParameterState(par, cov, nrow), MnStrategy(stra)),
: MnApplication(fcn, {par, cov, nrow}, MnStrategy(stra)),
fMinimizer(VariableMetricMinimizer())
{
}

/// construct from FCNBase + std::vector for parameters and MnUserCovariance
MnMigrad(const FCNBase &fcn, std::span<const double> par, const MnUserCovariance &cov, unsigned int stra = 1)
: MnApplication(fcn, MnUserParameterState(par, cov), MnStrategy(stra)), fMinimizer(VariableMetricMinimizer())
{
}

/// construct from FCNBase + MnUserParameters
MnMigrad(const FCNBase &fcn, const MnUserParameters &par, unsigned int stra = 1)
: MnApplication(fcn, MnUserParameterState(par), MnStrategy(stra)), fMinimizer(VariableMetricMinimizer())
: MnApplication(fcn, {par, cov}, MnStrategy(stra)), fMinimizer(VariableMetricMinimizer())
{
}

/// construct from FCNBase + MnUserParameters + MnUserCovariance
MnMigrad(const FCNBase &fcn, const MnUserParameters &par, const MnUserCovariance &cov, unsigned int stra = 1)
: MnApplication(fcn, MnUserParameterState(par, cov), MnStrategy(stra)), fMinimizer(VariableMetricMinimizer())
: MnApplication(fcn, {par, cov}, MnStrategy(stra)), fMinimizer(VariableMetricMinimizer())
{
}

/// construct from FCNBase + MnUserParameterState + MnStrategy
MnMigrad(const FCNBase &fcn, const MnUserParameterState &par, const MnStrategy &str)
: MnApplication(fcn, MnUserParameterState(par), str), fMinimizer(VariableMetricMinimizer())
MnMigrad(const FCNBase &fcn, const MnUserParameterState &par, const MnStrategy &str = MnStrategy{1})
: MnApplication(fcn, {par}, str), fMinimizer(VariableMetricMinimizer())
{
}

~MnMigrad() override {}

/// Copy constructor, copy shares the reference to the same FCNBase in MnApplication
MnMigrad(const MnMigrad &) = default;

Expand Down
20 changes: 6 additions & 14 deletions math/minuit2/inc/Minuit2/MnMinimize.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,32 @@ class MnMinimize : public MnApplication {
public:
/// construct from FCNBase + std::vector for parameters and errors
MnMinimize(const FCNBase &fcn, std::span<const double> par, std::span<const double> err, unsigned int stra = 1)
: MnApplication(fcn, MnUserParameterState(par, err), MnStrategy(stra)), fMinimizer(CombinedMinimizer())
: MnApplication(fcn, {par, err}, MnStrategy(stra)), fMinimizer(CombinedMinimizer())
{
}

/// construct from FCNBase + std::vector for parameters and covariance
MnMinimize(const FCNBase &fcn, std::span<const double> par, unsigned int nrow, std::span<const double> cov,
unsigned int stra = 1)
: MnApplication(fcn, MnUserParameterState(par, cov, nrow), MnStrategy(stra)), fMinimizer(CombinedMinimizer())
: MnApplication(fcn, {par, cov, nrow}, MnStrategy(stra)), fMinimizer(CombinedMinimizer())
{
}

/// construct from FCNBase + std::vector for parameters and MnUserCovariance
MnMinimize(const FCNBase &fcn, std::span<const double> par, const MnUserCovariance &cov, unsigned int stra = 1)
: MnApplication(fcn, MnUserParameterState(par, cov), MnStrategy(stra)), fMinimizer(CombinedMinimizer())
{
}

/// construct from FCNBase + MnUserParameters
MnMinimize(const FCNBase &fcn, const MnUserParameters &par, unsigned int stra = 1)
: MnApplication(fcn, MnUserParameterState(par), MnStrategy(stra)), fMinimizer(CombinedMinimizer())
: MnApplication(fcn, {par, cov}, MnStrategy(stra)), fMinimizer(CombinedMinimizer())
{
}

/// construct from FCNBase + MnUserParameters + MnUserCovariance
MnMinimize(const FCNBase &fcn, const MnUserParameters &par, const MnUserCovariance &cov, unsigned int stra = 1)
: MnApplication(fcn, MnUserParameterState(par, cov), MnStrategy(stra)), fMinimizer(CombinedMinimizer())
: MnApplication(fcn, {par, cov}, MnStrategy(stra)), fMinimizer(CombinedMinimizer())
{
}

/// construct from FCNBase + MnUserParameterState + MnStrategy
MnMinimize(const FCNBase &fcn, const MnUserParameterState &par, const MnStrategy &str)
: MnApplication(fcn, MnUserParameterState(par), str), fMinimizer(CombinedMinimizer())
MnMinimize(const FCNBase &fcn, const MnUserParameterState &par, const MnStrategy &str = MnStrategy{1})
: MnApplication(fcn, {par}, str), fMinimizer(CombinedMinimizer())
{
}

Expand All @@ -72,8 +66,6 @@ class MnMinimize : public MnApplication {
{
}

~MnMinimize() override {}

ModularFunctionMinimizer &Minimizer() override { return fMinimizer; }
const ModularFunctionMinimizer &Minimizer() const override { return fMinimizer; }

Expand Down
2 changes: 0 additions & 2 deletions math/minuit2/inc/Minuit2/MnParameterScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class MnParameterScan {

MnParameterScan(const FCNBase &, const MnUserParameters &, double);

~MnParameterScan() {}

// returns pairs of (x,y) points, x=parameter Value, y=function Value of FCN
std::vector<std::pair<double, double>>
operator()(unsigned int par, unsigned int maxsteps = 41, double low = 0., double high = 0.);
Expand Down
10 changes: 1 addition & 9 deletions math/minuit2/inc/Minuit2/MnScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,14 @@ class MnScan : public MnApplication {
{
}

/// construct from FCNBase + MnUserParameters
MnScan(const FCNBase &fcn, const MnUserParameters &par, unsigned int stra = 1)
: MnApplication(fcn, MnUserParameterState(par), MnStrategy(stra)), fMinimizer(ScanMinimizer())
{
}

/// construct from FCNBase + MnUserParameters + MnUserCovariance
MnScan(const FCNBase &fcn, const MnUserParameters &par, const MnUserCovariance &cov, unsigned int stra = 1)
: MnApplication(fcn, MnUserParameterState(par, cov), MnStrategy(stra)), fMinimizer(ScanMinimizer())
{
}

/// construct from FCNBase + MnUserParameterState + MnStrategy
MnScan(const FCNBase &fcn, const MnUserParameterState &par, const MnStrategy &str)
MnScan(const FCNBase &fcn, const MnUserParameterState &par, const MnStrategy &str = MnStrategy{})
: MnApplication(fcn, MnUserParameterState(par), str), fMinimizer(ScanMinimizer())
{
}
Expand All @@ -75,8 +69,6 @@ class MnScan : public MnApplication {
{
}

~MnScan() override {}

ModularFunctionMinimizer &Minimizer() override { return fMinimizer; }
const ModularFunctionMinimizer &Minimizer() const override { return fMinimizer; }

Expand Down
10 changes: 1 addition & 9 deletions math/minuit2/inc/Minuit2/MnSimplex.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,14 @@ class MnSimplex : public MnApplication {
{
}

/// construct from FCNBase + MnUserParameters
MnSimplex(const FCNBase &fcn, const MnUserParameters &par, unsigned int stra = 1)
: MnApplication(fcn, MnUserParameterState(par), MnStrategy(stra)), fMinimizer(SimplexMinimizer())
{
}

/// construct from FCNBase + MnUserParameters + MnUserCovariance
MnSimplex(const FCNBase &fcn, const MnUserParameters &par, const MnUserCovariance &cov, unsigned int stra = 1)
: MnApplication(fcn, MnUserParameterState(par, cov), MnStrategy(stra)), fMinimizer(SimplexMinimizer())
{
}

/// construct from FCNBase + MnUserParameterState + MnStrategy
MnSimplex(const FCNBase &fcn, const MnUserParameterState &par, const MnStrategy &str)
MnSimplex(const FCNBase &fcn, const MnUserParameterState &par, const MnStrategy &str = MnStrategy{1})
: MnApplication(fcn, MnUserParameterState(par), str), fMinimizer(SimplexMinimizer())
{
}
Expand All @@ -77,8 +71,6 @@ class MnSimplex : public MnApplication {
{
}

~MnSimplex() override {}

ModularFunctionMinimizer &Minimizer() override { return fMinimizer; }
const ModularFunctionMinimizer &Minimizer() const override { return fMinimizer; }

Expand Down
5 changes: 0 additions & 5 deletions math/minuit2/inc/Minuit2/ModularFunctionMinimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class FumiliFCNBase;
class ModularFunctionMinimizer : public FunctionMinimizer {

public:
~ModularFunctionMinimizer() override {}

// inherited interface
FunctionMinimum Minimize(const FCNBase &, std::span<const double>, std::span<const double>,
unsigned int stra = 1, unsigned int maxfcn = 0, double toler = 0.1) const override;
Expand All @@ -51,9 +49,6 @@ class ModularFunctionMinimizer : public FunctionMinimizer {
double toler = 0.1) const override;

// extension
virtual FunctionMinimum Minimize(const FCNBase &, const MnUserParameters &, const MnStrategy &,
unsigned int maxfcn = 0, double toler = 0.1) const;

virtual FunctionMinimum Minimize(const FCNBase &, const MnUserParameters &, const MnUserCovariance &,
const MnStrategy &, unsigned int maxfcn = 0, double toler = 0.1) const;

Expand Down
6 changes: 0 additions & 6 deletions math/minuit2/src/MnHesse.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ MnUserParameterState MnHesse::operator()(const FCNBase &fcn, std::span<const dou
return (*this)(fcn, MnUserParameterState(par, cov), maxcalls);
}

MnUserParameterState MnHesse::operator()(const FCNBase &fcn, const MnUserParameters &par, unsigned int maxcalls) const
{
// interface from MnUserParameters
return (*this)(fcn, MnUserParameterState(par), maxcalls);
}

MnUserParameterState MnHesse::operator()(const FCNBase &fcn, const MnUserParameters &par, const MnUserCovariance &cov,
unsigned int maxcalls) const
{
Expand Down
11 changes: 0 additions & 11 deletions math/minuit2/src/ModularFunctionMinimizer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ namespace ROOT {

namespace Minuit2 {

// #include "Minuit2/MnUserParametersPrint.h"

FunctionMinimum ModularFunctionMinimizer::Minimize(const FCNBase &fcn, std::span<const double> par,
std::span<const double> err, unsigned int stra,
unsigned int maxfcn, double toler) const
Expand All @@ -56,15 +54,6 @@ FunctionMinimum ModularFunctionMinimizer::Minimize(const FCNBase &fcn, std::span
return Minimize(fcn, st, strategy, maxfcn, toler);
}

FunctionMinimum ModularFunctionMinimizer::Minimize(const FCNBase &fcn, const MnUserParameters &upar,
const MnStrategy &strategy, unsigned int maxfcn, double toler) const
{
// minimize from FCNBase and MnUserParameters object

MnUserParameterState st(upar);
return Minimize(fcn, st, strategy, maxfcn, toler);
}

FunctionMinimum ModularFunctionMinimizer::Minimize(const FCNBase &fcn, const MnUserParameters &upar,
const MnUserCovariance &cov, const MnStrategy &strategy,
unsigned int maxfcn, double toler) const
Expand Down
2 changes: 0 additions & 2 deletions math/minuit2/test/testADMinim.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ void RosenBrock(Int_t &, Double_t *, Double_t &f, Double_t *par, Int_t /*iflag*/
class RosenBrockFunction : public ROOT::Math::IMultiGenFunction {

public:
~RosenBrockFunction() override {}

unsigned int NDim() const override { return 2; }

ROOT::Math::IMultiGenFunction *Clone() const override { return new RosenBrockFunction(); }
Expand Down
2 changes: 0 additions & 2 deletions math/minuit2/test/testMinimizer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ void RosenBrock(Int_t &, Double_t *, Double_t &f, Double_t *par, Int_t /*iflag*/
class RosenBrockFunction : public ROOT::Math::IMultiGenFunction {

public:
~RosenBrockFunction() override {}

unsigned int NDim() const override { return 2; }

ROOT::Math::IMultiGenFunction *Clone() const override { return new RosenBrockFunction(); }
Expand Down

0 comments on commit 8dd7784

Please sign in to comment.