Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:14

0001 // @(#)root/mathcore:$Id$
0002 // Author: David Gonzalez Maline 2/2008
0003  /**********************************************************************
0004   *                                                                    *
0005   * Copyright (c) 2004  CERN                                           *
0006   * All rights reserved.                                               *
0007   *                                                                    *
0008   * For the licensing terms see $ROOTSYS/LICENSE.                      *
0009   * For the list of contributors see $ROOTSYS/README/CREDITS.          *
0010   *                                                                    *
0011   **********************************************************************/
0012 
0013 // Header file for class BrentMinimizer1D
0014 //
0015 // Created by: Maline  at Mon Feb  4 09:32:36 2008
0016 //
0017 //
0018 
0019 
0020 #ifndef ROOT_Math_BrentMinimizer1D
0021 #define ROOT_Math_BrentMinimizer1D
0022 
0023 #include "Math/IMinimizer1D.h"
0024 
0025 #include "Math/IFunctionfwd.h"
0026 
0027 
0028 namespace ROOT {
0029 namespace Math {
0030 
0031 //___________________________________________________________________________________________
0032 /**
0033    User class for performing function minimization
0034 
0035    It will use the Brent Method for function minimization in a given interval.
0036    First, a grid search is used to bracket the minimum value
0037    with the a step size = (xmax-xmin)/npx. The step size
0038    can be controlled via the SetNpx() function. A default value of npx = 100 is used.
0039    The default value con be changed using the static method SetDefaultNpx.
0040    If the function is unimodal or if its extrema are far apart, setting the fNpx to
0041    a small value speeds the algorithm up many times.
0042    Then, Brent's method is applied on the bracketed interval.
0043    If the Brent method fails to converge the bracketing is repeated on the latest best estimate of the
0044    interval. The procedure is repeated with a maximum value (default =10) which can be set for all
0045    BrentRootFinder classes with the method SetDefaultNSearch
0046 
0047 
0048 
0049    This class is implemented from TF1::GetMinimum.
0050 
0051    To use the class, three steps have to be taken:
0052        1. Create the class.
0053        2. Set a function within an interval to look for the minimum.
0054        3. Call the Minimize function with the error parameters.
0055 
0056    If another minimization is to be performed, repeat the last two steps.
0057 
0058    @ingroup Min1D
0059 
0060  */
0061 
0062    class BrentMinimizer1D: private ROOT::Math::IMinimizer1D {
0063 
0064    public:
0065 
0066       /** Default Constructor. */
0067       BrentMinimizer1D();
0068 
0069       /** Default Destructor. */
0070       ~BrentMinimizer1D() override {}
0071 
0072    public:
0073 
0074       /** Return current estimate of the position of the minimum. */
0075       double XMinimum() const override {   return fXMinimum;  }
0076 
0077       /** Return current lower bound of the minimization interval. */
0078       double XLower() const override {   return fXMin;  }
0079 
0080       /** Return current upper bound of the minimization interval. */
0081       double XUpper() const override {   return fXMax;  }
0082 
0083       /** Return function value at current estimate of the minimum. */
0084       double FValMinimum() const override;
0085 
0086       /** Return function value at current lower bound of the minimization interval. */
0087       double FValLower() const override;
0088 
0089       /** Return function value at current upper bound of the minimization interval. */
0090       double FValUpper() const override;
0091 
0092       /** Find minimum position iterating until convergence specified by the absolute and relative tolerance or
0093           the maximum number of iteration is reached.
0094           Return true if iterations converged successfully
0095           \@param maxIter maximum number of iterations.
0096           \@param absTol desired absolute error in the minimum position (default 1.E-8)
0097           \@param absTol desired relative error in the minimum position (default = 1.E-10)
0098       */
0099       bool Minimize( int maxIter, double absTol = 1.E-8, double relTol = 1.E-10) override;
0100 
0101       /** Return number of iteration used to find minimum */
0102       int Iterations() const override { return fNIter; }
0103 
0104       /** Return name of minimization algorithm ("BrentMinimizer1D") */
0105       const char * Name() const override;
0106 
0107       /** Sets function to be minimized.
0108 
0109           \@param f Function to be minimized.
0110           \@param xlow Lower bound of the search interval.
0111           \@param xup Upper bound of the search interval.
0112       */
0113       void SetFunction(const ROOT::Math::IGenFunction& f, double xlow, double xup);
0114 
0115       /** Set the number of point used to bracket root using a grid */
0116       void SetNpx(int npx) { fNpx = npx; }
0117 
0118       /**
0119           Set a log grid scan (default is equidistant bins)
0120           will work only if xlow > 0
0121       */
0122       void SetLogScan(bool on) { fLogScan = on; }
0123 
0124 
0125       /** Returns status of last estimate. If = 0 is OK */
0126       int Status() const override { return fStatus; }
0127 
0128       // static function used to modify the default parameters
0129 
0130       /** set number of default Npx used at construction time (when SetNpx is not called)
0131           Default value is 100
0132        */
0133       static void SetDefaultNpx(int npx);
0134 
0135       /** set number of  times the bracketing search in combination with is done to find a good interval
0136           Default value is 10
0137        */
0138       static void SetDefaultNSearch(int n);
0139 
0140    private:
0141 
0142       const IGenFunction* fFunction; ///< Pointer to the function.
0143       bool fLogScan;                 ///< flag to control usage of a log scan
0144       int fNIter;                    ///< Number of iterations needed for the last estimation.
0145       int fNpx;                      ///< Number of points to bracket minimum with grid (def is 100)
0146       int fStatus;                   ///< Status of code of the last estimate
0147       double fXMin;                  ///< Lower bound of the search interval.
0148       double fXMax;                  ///< Upper bound of the search interval
0149       double fXMinimum;              ///< Position of the estimated minimum.
0150 
0151    };  // end class BrentMinimizer1D
0152 
0153 } // end namespace Math
0154 
0155 } // end namespace ROOT
0156 
0157 #endif /* ROOT_Math_BrentMinimizer1D */