diff --git a/lib/Minimizer.cpp b/lib/Minimizer.cpp index 163dc96..7354e8f 100644 --- a/lib/Minimizer.cpp +++ b/lib/Minimizer.cpp @@ -49,9 +49,13 @@ void Minimizer::resize(const Index dim) } } -// limits ////////////////////////////////////////////////////////////////////// double Minimizer::getHighLimit(const Index i) const { + if (i >= getDim()) + { + LATAN_ERROR(Size, "invalid variable index"); + } + return highLimit_(i); } @@ -62,6 +66,11 @@ const DVec & Minimizer::getHighLimit(const PlaceHolder ph __dumb) const double Minimizer::getLowLimit(const Index i) const { + if (i >= getDim()) + { + LATAN_ERROR(Size, "invalid variable index"); + } + return lowLimit_(i); } @@ -72,11 +81,21 @@ const DVec & Minimizer::getLowLimit(const PlaceHolder ph __dumb) const bool Minimizer::hasHighLimit(const Index i) const { + if (i >= getDim()) + { + LATAN_ERROR(Size, "invalid variable index"); + } + return hasHighLimit_(i); } bool Minimizer::hasLowLimit(const Index i) const { + if (i >= getDim()) + { + LATAN_ERROR(Size, "invalid variable index"); + } + return hasLowLimit_(i); } @@ -84,7 +103,7 @@ void Minimizer::setHighLimit(const Index i, const double l) { if (i >= getDim()) { - LATAN_ERROR(Size, "invalid limit index"); + resize(i + 1); } else { @@ -97,7 +116,7 @@ void Minimizer::setHighLimit(const PlaceHolder ph __dumb, const DVec &l) { if (l.size() != getDim()) { - LATAN_ERROR(Size, "invalid limit vector size"); + resize(l.size()); } else { @@ -110,7 +129,7 @@ void Minimizer::setLowLimit(const Index i, const double l) { if (i >= getDim()) { - LATAN_ERROR(Size, "invalid limit index"); + resize(i + 1); } else { @@ -123,7 +142,7 @@ void Minimizer::setLowLimit(const PlaceHolder ph __dumb, const DVec &l) { if (l.size() != getDim()) { - LATAN_ERROR(Size, "invalid limit vector size"); + resize(l.size()); } else { @@ -136,7 +155,7 @@ void Minimizer::useHighLimit(const Index i, const bool use) { if (i >= getDim()) { - LATAN_ERROR(Size, "invalid limit index"); + resize(i + 1); } else { @@ -153,7 +172,7 @@ void Minimizer::useLowLimit(const Index i, const bool use) { if (i >= getDim()) { - LATAN_ERROR(Size, "invalid limit index"); + resize(i + 1); } else { @@ -165,3 +184,13 @@ void Minimizer::useLowLimit(const PlaceHolder ph __dumb, const bool use) { hasLowLimit_.fill(use); } + +unsigned int Minimizer::getMaxPass(void) const +{ + return maxPass_; +} + +void Minimizer::setMaxPass(const unsigned int maxPass) +{ + maxPass_ = maxPass; +} diff --git a/lib/Minimizer.hpp b/lib/Minimizer.hpp index c0fa8a0..97c589b 100644 --- a/lib/Minimizer.hpp +++ b/lib/Minimizer.hpp @@ -40,8 +40,7 @@ public: // destructor virtual ~Minimizer(void) = default; // access - virtual void resize(const Index dim); - // limits + virtual void resize(const Index dim); virtual double getHighLimit(const Index i) const ; virtual const DVec & getHighLimit(const PlaceHolder ph = _) const; virtual double getLowLimit(const Index i) const; @@ -58,11 +57,14 @@ public: virtual void useLowLimit(const Index i, const bool use = true); virtual void useLowLimit(const PlaceHolder ph = _, const bool use = true); + virtual unsigned int getMaxPass(void) const; + virtual void setMaxPass(const unsigned int maxPass); // minimization virtual const DVec & operator()(const DoubleFunction &f) = 0; private: - DVec highLimit_, lowLimit_; - Vec hasHighLimit_, hasLowLimit_; + DVec highLimit_, lowLimit_; + Vec hasHighLimit_, hasLowLimit_; + unsigned int maxPass_{5u}; }; END_LATAN_NAMESPACE diff --git a/lib/MinuitMinimizer.cpp b/lib/MinuitMinimizer.cpp index a9684ae..2715068 100644 --- a/lib/MinuitMinimizer.cpp +++ b/lib/MinuitMinimizer.cpp @@ -25,8 +25,7 @@ using namespace std; using namespace Latan; -static constexpr double initErr = 0.1; -static constexpr unsigned int maxTry = 10u; +static constexpr double initErr = 0.1; /****************************************************************************** * MinuitMinimizer implementation * @@ -137,28 +136,21 @@ const DVec & MinuitMinimizer::operator()(const DoubleFunction &f) int status; unsigned int n = 0; - if (getVerbosity() >= Verbosity::Normal) - { - cout << "========== Minuit minimization, pass #1"; - cout << " ==========" << endl; - } - min->SetStrategy(0); - min->Minimize(); + min->SetStrategy(2); do { - n++; if (getVerbosity() >= Verbosity::Normal) { cout << "========== Minuit minimization, pass #" << n + 1; - cout << " ==========" << endl; + cout << " =========" << endl; } - min->SetStrategy(2); min->Minimize(); status = min->Status(); - } while (status and (n < maxTry)); + n++; + } while (status and (n < getMaxPass())); if (getVerbosity() >= Verbosity::Normal) { - cout << "======================================" << endl; + cout << "=================================================" << endl; } switch (status) { diff --git a/lib/MinuitMinimizer.hpp b/lib/MinuitMinimizer.hpp index c5ea135..dfe42ed 100644 --- a/lib/MinuitMinimizer.hpp +++ b/lib/MinuitMinimizer.hpp @@ -27,7 +27,8 @@ BEGIN_LATAN_NAMESPACE /****************************************************************************** - * interface to CERN Minuit minimizer (http://www.cern.ch/minuit) * + * interface to CERN Minuit minimizer * + * ( http://www.cern.ch/minuit ) * ******************************************************************************/ class MinuitMinimizer: public Minimizer {