diff --git a/lib/MinuitMinimizer.cpp b/lib/MinuitMinimizer.cpp index 2b3f052..b2f2447 100644 --- a/lib/MinuitMinimizer.cpp +++ b/lib/MinuitMinimizer.cpp @@ -62,11 +62,17 @@ double MinuitMinimizer::MinuitFunction::Up(void) const } // constructor ///////////////////////////////////////////////////////////////// -MinuitMinimizer::MinuitMinimizer(const Index dim) +MinuitMinimizer::MinuitMinimizer(const Index dim, const Algorithm algorithm) : Minimizer(dim) +, algorithm_(algorithm) {} // access ////////////////////////////////////////////////////////////////////// +MinuitMinimizer::Algorithm MinuitMinimizer::getAlgorithm(void) const +{ + return algorithm_; +} + double MinuitMinimizer::getPrecision(void) const { LATAN_ERROR(Implementation, @@ -75,6 +81,11 @@ double MinuitMinimizer::getPrecision(void) const return 0.; } +void MinuitMinimizer::setAlgorithm(const Algorithm algorithm) +{ + algorithm_ = algorithm; +} + void MinuitMinimizer::setPrecision(const double precision __dumb) { LATAN_ERROR(Implementation, @@ -134,13 +145,21 @@ const DVec & MinuitMinimizer::operator()(const DoubleFunction &f) } // minimization and output - MnMigrad minimizer(minuitF, parameters, 2); + unique_ptr minimizer(nullptr); + if (algorithm_ == Algorithm::Migrad) + { + minimizer.reset(new MnMigrad(minuitF, parameters, 2)); + } + else if (algorithm_ == Algorithm::Simplex) + { + minimizer.reset(new MnSimplex(minuitF, parameters, 2)); + } unsigned int iTry = 0; - FunctionMinimum min = minimizer(); + FunctionMinimum min = (*minimizer)(); while ((!min.IsValid())&&(iTry < maxTry)) { - min = minimizer(); + min = (*minimizer)(); iTry++; } if (!min.IsValid()) diff --git a/lib/MinuitMinimizer.hpp b/lib/MinuitMinimizer.hpp index 7399865..99153b8 100644 --- a/lib/MinuitMinimizer.hpp +++ b/lib/MinuitMinimizer.hpp @@ -33,6 +33,12 @@ BEGIN_LATAN_NAMESPACE class MinuitMinimizer: public Minimizer { +public: + enum class Algorithm + { + Migrad = 1, + Simplex = 2 + }; private: class MinuitFunction: public ROOT::Minuit2::FCNBase { @@ -49,14 +55,19 @@ private: }; public: // constructor - explicit MinuitMinimizer(const Index dim); + explicit MinuitMinimizer(const Index dim, + const Algorithm algorithm = Algorithm::Migrad); // destructor virtual ~MinuitMinimizer(void) = default; // access virtual double getPrecision(void) const; + Algorithm getAlgorithm(void) const; virtual void setPrecision(const double precision); + void setAlgorithm(const Algorithm algorithm); // minimization virtual const DVec & operator()(const DoubleFunction &f); +private: + Algorithm algorithm_; }; END_LATAN_NAMESPACE