Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:22:05

0001 // @(#)root/mathcore:$Id$
0002 // Author: L. Moneta Fri Aug 15 2008
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2008  LCG ROOT Math Team, CERN/PH-SFT                *
0007  *                                                                    *
0008  *                                                                    *
0009  **********************************************************************/
0010 
0011 #ifndef ROOT_Math_IntegratorOptions
0012 #define ROOT_Math_IntegratorOptions
0013 
0014 #include "Math/AllIntegrationTypes.h"
0015 
0016 #include <string>
0017 #include <iostream>
0018 
0019 namespace ROOT {
0020 
0021 
0022 namespace Math {
0023 
0024    class IOptions;
0025 
0026 
0027 //_______________________________________________________________________________
0028 /**
0029     Base class for Numerical integration  options
0030     common in 1D and multi-dimension
0031     This is an internal class and is not supposed to be instantiated by the user
0032 
0033     @ingroup Integration
0034 */
0035 class BaseIntegratorOptions {
0036 
0037 protected:
0038 
0039    /// protected constructor to avoid user creating this class
0040    BaseIntegratorOptions();
0041 
0042 public:
0043 
0044    // copy constructor
0045    BaseIntegratorOptions(const BaseIntegratorOptions & opt);
0046 
0047    /// assignment operators
0048    BaseIntegratorOptions & operator=(const BaseIntegratorOptions & opt);
0049 
0050 
0051    /// protected constructor to avoid user creating this class
0052    virtual ~BaseIntegratorOptions() { ClearExtra(); }
0053 
0054 
0055    /// name of 1D integrator
0056    virtual std::string  Integrator() const = 0;
0057 
0058    /** non-static methods for  retrieving options */
0059 
0060    /// absolute tolerance
0061    double AbsTolerance() const { return  fAbsTolerance; }
0062 
0063    /// absolute tolerance
0064    double RelTolerance() const { return  fRelTolerance; }
0065 
0066    /// size of the workspace
0067    unsigned int WKSize() const { return fWKSize; }
0068 
0069 
0070    /// return extra options
0071    IOptions * ExtraOptions() const { return fExtraOptions; }
0072 
0073    /** non-static methods for setting options */
0074 
0075 
0076    /// set the abs tolerance
0077    void SetAbsTolerance(double tol) { fAbsTolerance = tol; }
0078 
0079    /// set the relative tolerance
0080    void SetRelTolerance(double tol) { fRelTolerance = tol; }
0081 
0082    /// set workspace size
0083    void SetWKSize(unsigned int size) { fWKSize = size; }
0084 
0085    /// set extra options (in this case pointer is cloned)
0086    void  SetExtraOptions(const IOptions & opt);
0087 
0088 
0089 protected:
0090 
0091    void ClearExtra();
0092 
0093    int       fIntegType;        ///< Integrator type (value converted from enum)
0094 
0095    unsigned int fWKSize;        ///< workspace size
0096    unsigned int fNCalls;        ///< (max) function calls
0097    double fAbsTolerance;        ///< absolute tolerance
0098    double fRelTolerance;        ///< relative tolerance
0099 
0100 
0101    // extra options
0102    ROOT::Math::IOptions *   fExtraOptions;  // extra options
0103 
0104 };
0105 
0106 //_______________________________________________________________________________
0107 /**
0108     Numerical one dimensional integration  options
0109 
0110     @ingroup Integration
0111 */
0112 
0113 class IntegratorOneDimOptions : public BaseIntegratorOptions {
0114 
0115 public:
0116 
0117 
0118    /// constructor using the default options
0119    /// can pass a pointer to extra options (N.B. pointer will be managed by the class)
0120    IntegratorOneDimOptions(IOptions * extraOpts = nullptr);
0121 
0122    ~IntegratorOneDimOptions() override {}
0123 
0124    /// copy constructor
0125    IntegratorOneDimOptions(const IntegratorOneDimOptions & rhs) :
0126       BaseIntegratorOptions(rhs)
0127    {}
0128 
0129    /// assignment operator
0130    IntegratorOneDimOptions & operator=(const IntegratorOneDimOptions & rhs) {
0131       if (this == &rhs) return *this;
0132       static_cast<BaseIntegratorOptions &>(*this) = rhs;
0133       return *this;
0134    }
0135 
0136    // specific method for one-dim
0137    /// Set number of points for active integration rule.
0138    /// - For the GSL adaptive integrator, `n = 1,2,3,4,5,6` correspond to the 15,21,31,41,51,61-point integration rules.
0139    /// - For the GaussLegendre integrator, use values > 6, which correspond to the actual number of points being evaluated.
0140    void SetNPoints(unsigned int n) { fNCalls = n; }
0141 
0142    /// Number of points used by current integration rule. \see SetNPoints().
0143    unsigned int NPoints() const { return fNCalls; }
0144 
0145    /// name of 1D integrator
0146    std::string  Integrator() const override;
0147 
0148    /// type of the integrator (return the enumeration type)
0149    IntegrationOneDim::Type IntegratorType() const { return (IntegrationOneDim::Type) fIntegType; }
0150 
0151    /// set 1D integrator name
0152    void SetIntegrator(const char * name);
0153 
0154    /// print all the options
0155    void Print(std::ostream & os = std::cout) const;
0156 
0157    // static methods for setting and retrieving the default options
0158 
0159    static void SetDefaultIntegrator(const char * name);
0160    static void SetDefaultAbsTolerance(double tol);
0161    static void SetDefaultRelTolerance(double tol);
0162    static void SetDefaultWKSize(unsigned int size);
0163    static void SetDefaultNPoints(unsigned int n);
0164 
0165    static std::string  DefaultIntegrator();
0166    static IntegrationOneDim::Type DefaultIntegratorType();
0167    static double DefaultAbsTolerance();
0168    static double DefaultRelTolerance();
0169    static unsigned int DefaultWKSize();
0170    static unsigned int DefaultNPoints();
0171 
0172    /// retrieve specific options - if not existing create a IOptions
0173    static ROOT::Math::IOptions & Default(const char * name);
0174 
0175    /// find specific options - return 0 if not existing
0176    static ROOT::Math::IOptions * FindDefault(const char * name);
0177 
0178    /// print only the specified default options
0179    static void PrintDefault(const char * name = nullptr, std::ostream & os = std::cout);
0180 
0181 
0182 private:
0183 
0184 
0185 };
0186 
0187 //_______________________________________________________________________________
0188 /**
0189     Numerical multi dimensional integration  options
0190 
0191     @ingroup Integration
0192 */
0193 
0194 class IntegratorMultiDimOptions : public BaseIntegratorOptions {
0195 
0196 public:
0197 
0198 
0199    /// constructor using the default options
0200    /// can pass a pointer to extra options (N.B. pointer will be managed by the class)
0201    IntegratorMultiDimOptions(IOptions * extraOpts = nullptr);
0202 
0203    ~IntegratorMultiDimOptions() override {}
0204 
0205    /// copy constructor
0206    IntegratorMultiDimOptions(const IntegratorMultiDimOptions & rhs) :
0207       BaseIntegratorOptions(rhs)
0208    {}
0209 
0210    /// assignment operator
0211    IntegratorMultiDimOptions & operator=(const IntegratorMultiDimOptions & rhs) {
0212       if (this == &rhs) return *this;
0213       static_cast<BaseIntegratorOptions &>(*this) = rhs;
0214       return *this;
0215    }
0216 
0217    // specific method for multi-dim
0218    /// set maximum number of function calls
0219    void SetNCalls(unsigned int calls) { fNCalls = calls; }
0220 
0221    /// maximum number of function calls
0222    unsigned int NCalls() const { return fNCalls; }
0223 
0224    /// name of multi-dim integrator
0225    std::string  Integrator() const override;
0226 
0227    /// type of the integrator (return the enumeration type)
0228    IntegrationMultiDim::Type IntegratorType() const { return (IntegrationMultiDim::Type) fIntegType; }
0229 
0230    /// set multi-dim integrator name
0231    void SetIntegrator(const char * name);
0232 
0233    /// print all the options
0234    void Print(std::ostream & os = std::cout) const;
0235 
0236    // static methods for setting and retrieving the default options
0237 
0238    static void SetDefaultIntegrator(const char * name);
0239    static void SetDefaultAbsTolerance(double tol);
0240    static void SetDefaultRelTolerance(double tol);
0241    static void SetDefaultWKSize(unsigned int size);
0242    static void SetDefaultNCalls(unsigned int ncall);
0243 
0244    static std::string DefaultIntegrator();
0245    static IntegrationMultiDim::Type DefaultIntegratorType();
0246    static double DefaultAbsTolerance();
0247    static double DefaultRelTolerance();
0248    static unsigned int DefaultWKSize();
0249    static unsigned int DefaultNCalls();
0250 
0251    /// retrieve specific options
0252    static ROOT::Math::IOptions & Default(const char * name);
0253 
0254    /// find specific options - return 0 if not existing
0255    static ROOT::Math::IOptions * FindDefault(const char * name);
0256 
0257    /// print only the specified default options
0258    static void PrintDefault(const char *name = nullptr, std::ostream & os = std::cout);
0259 
0260 
0261 private:
0262 
0263 
0264 };
0265 
0266 
0267    } // end namespace Math
0268 
0269 } // end namespace ROOT
0270 
0271 #endif