Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/Math/ModABRootFinder.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/mathcore:$Id$
0002 // Authors: Nedelcho Ganchovski    03/03/2026
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2026  CERN                                           *
0007  * All rights reserved.                                               *
0008  *                                                                    *
0009  * For the licensing terms see $ROOTSYS/LICENSE.                      *
0010  * For the list of contributors see $ROOTSYS/README/CREDITS.          *
0011  *                                                                    *
0012  **********************************************************************/
0013 
0014 // Header for the RootFinder
0015 //
0016 // Created by: Nedelcho Ganchovski  : Wed March 03 2026
0017 //
0018 
0019 #ifndef ROOT_Math_ModABRootFinder
0020 #define ROOT_Math_ModABRootFinder
0021 
0022 #include "Math/IFunction.h"
0023 #include "Math/IRootFinderMethod.h"
0024 
0025 namespace ROOT::Math {
0026 
0027 //___________________________________________________________________________________________
0028 /**
0029    Class for finding the root of a one dimensional function using the ModAB algorithm.
0030    It is based on the Modified Anderson-Björck method (2022 Ganchovski & Traykov) that
0031    adaptively switches between bisection and regula-falsi with
0032    side-correction, yielding superlinear convergence on well-behaved
0033    functions while retaining the robustness of bisection.
0034    @ingroup RootFinders
0035  */
0036 
0037 class ModABRootFinder : public IRootFinderMethod {
0038 public:
0039    /** Set function to solve and the interval in where to look for the root.
0040 
0041        \@param f Function to be minimized.
0042        \@param xlow Lower bound of the search interval.
0043        \@param xup Upper bound of the search interval.
0044    */
0045    using IRootFinderMethod::SetFunction;
0046    bool SetFunction(const ROOT::Math::IGenFunction &f, double xlow, double xup) override;
0047 
0048    /** Returns the X value corresponding to the function value fy for (xmin<x<xmax).
0049        Method:
0050        Modified Anderson-Björck method is applied on the bracketed interval.
0051 
0052        \@param maxIter maximum number of iterations.
0053        \@param absTol desired absolute error in the minimum position.
0054        \@param relTol desired relative error in the minimum position.
0055    */
0056    bool Solve(int maxIter = 100, double absTol = 1E-8, double relTol = 1E-10) override;
0057 
0058    /** Returns root value. Need to call first Solve(). */
0059    double Root() const override { return fRoot; }
0060 
0061    /** Returns status of last estimate. If = 0 is OK */
0062    int Status() const override { return fStatus; }
0063 
0064    /** Return number of iteration used to find minimum */
0065    int Iterations() const override { return fNIter; }
0066 
0067    /** Return name of root finder algorithm ("ModABRootFinder"). */
0068    const char *Name() const override;
0069 
0070 private:
0071    const IGenFunction *fFunction = nullptr; // Pointer to the function.
0072    int fNIter = 0;                          // Number of iterations needed for the last estimation.
0073    int fStatus = -1;                        // Status of code of the last estimate
0074    double fXMin = 0.;                       // Lower bound of the search interval.
0075    double fXMax = 0.;                       // Upper bound of the search interval
0076    double fRoot = 0.;                       // Current estimation of the function root.
0077 };
0078 } // namespace ROOT::Math
0079 
0080 #endif /* ROOT_Math_ModABRootFinder */