00001 // @(#)root/mathcore:$Id: MinimizerOptions.h 36905 2010-11-24 15:44:34Z moneta $ 00002 // Author: L. Moneta Fri Aug 15 2008 00003 00004 /********************************************************************** 00005 * * 00006 * Copyright (c) 2008 LCG ROOT Math Team, CERN/PH-SFT * 00007 * * 00008 * * 00009 **********************************************************************/ 00010 00011 #ifndef ROOT_Math_MinimizerOptions 00012 #define ROOT_Math_MinimizerOptions 00013 00014 #include <string> 00015 00016 #include <iostream> 00017 00018 namespace ROOT { 00019 00020 00021 namespace Math { 00022 00023 00024 class IOptions; 00025 00026 //_______________________________________________________________________________ 00027 /** 00028 Minimizer options 00029 00030 @ingroup MultiMin 00031 */ 00032 class MinimizerOptions { 00033 00034 public: 00035 00036 // static methods for setting and retrieving the default options 00037 00038 static void SetDefaultMinimizer(const char * type, const char * algo = 0); 00039 static void SetDefaultErrorDef( double up); 00040 static void SetDefaultTolerance(double tol); 00041 static void SetDefaultPrecision(double prec); 00042 static void SetDefaultMaxFunctionCalls(int maxcall); 00043 static void SetDefaultMaxIterations(int maxiter); 00044 static void SetDefaultStrategy(int strat); 00045 static void SetDefaultPrintLevel(int level); 00046 00047 static const std::string & DefaultMinimizerType(); 00048 static const std::string & DefaultMinimizerAlgo(); 00049 static double DefaultErrorDef(); 00050 static double DefaultTolerance(); 00051 static double DefaultPrecision(); 00052 static int DefaultMaxFunctionCalls(); 00053 static int DefaultMaxIterations(); 00054 static int DefaultStrategy(); 00055 static int DefaultPrintLevel(); 00056 00057 /// retrieve extra options - if not existing create a IOptions 00058 static ROOT::Math::IOptions & Default(const char * name); 00059 00060 // find extra options - return 0 if not existing 00061 static ROOT::Math::IOptions * FindDefault(const char * name); 00062 00063 /// print all the default options for the name given 00064 static void PrintDefault(const char * name = 0, std::ostream & os = std::cout); 00065 00066 public: 00067 00068 // constructor using the default options 00069 // pass optionally a pointer to the additional options 00070 // otehrwise look if they exist for this default minimizer 00071 // and in that case they are copied in the constructed instance 00072 MinimizerOptions(IOptions * extraOpts = 0); 00073 00074 // destructor 00075 ~MinimizerOptions(); 00076 00077 // copy constructor 00078 MinimizerOptions(const MinimizerOptions & opt); 00079 00080 /// assignment operators 00081 MinimizerOptions & operator=(const MinimizerOptions & opt); 00082 00083 /** non-static methods for retrivieng options */ 00084 00085 /// set print level 00086 int PrintLevel() const { return fLevel; } 00087 00088 /// max number of function calls 00089 unsigned int MaxFunctionCalls() const { return fMaxCalls; } 00090 00091 /// max iterations 00092 unsigned int MaxIterations() const { return fMaxIter; } 00093 00094 /// strategy 00095 int Strategy() const { return fStrategy; } 00096 00097 /// absolute tolerance 00098 double Tolerance() const { return fTolerance; } 00099 00100 /// precision in the objective funciton calculation (value <=0 means left to default) 00101 double Precision() const { return fPrecision; } 00102 00103 /// error definition 00104 double ErrorDef() const { return fErrorDef; } 00105 00106 /// return extra options (NULL pointer if they are not present) 00107 IOptions * ExtraOptions() const { return fExtraOptions; } 00108 00109 /// type of minimizer 00110 const std::string & MinimizerType() const { return fMinimType; } 00111 00112 /// type of algorithm 00113 const std::string & MinimizerAlgorithm() const { return fAlgoType; } 00114 00115 /// print all the options 00116 void Print(std::ostream & os = std::cout) const; 00117 00118 /** non-static methods for setting options */ 00119 00120 /// set print level 00121 void SetPrintLevel(int level) { fLevel = level; } 00122 00123 ///set maximum of function calls 00124 void SetMaxFunctionCalls(unsigned int maxfcn) { fMaxCalls = maxfcn; } 00125 00126 /// set maximum iterations (one iteration can have many function calls) 00127 void SetMaxIterations(unsigned int maxiter) { fMaxIter = maxiter; } 00128 00129 /// set the tolerance 00130 void SetTolerance(double tol) { fTolerance = tol; } 00131 00132 /// set the precision 00133 void SetPrecision(double prec) { fPrecision = prec; } 00134 00135 /// set the strategy 00136 void SetStrategy(int stra) { fStrategy = stra; } 00137 00138 /// set error def 00139 void SetErrorDef(double err) { fErrorDef = err; } 00140 00141 /// set minimizer type 00142 void SetMinimizerType(const char * type) { fMinimType = type; } 00143 00144 /// set minimizer algorithm 00145 void SetMinimizerAlgorithm(const char *type) { fAlgoType = type; } 00146 00147 /// set extra options (in this case pointer is cloned) 00148 void SetExtraOptions(const IOptions & opt); 00149 00150 00151 private: 00152 00153 int fLevel; // debug print level 00154 int fMaxCalls; // maximum number of function calls 00155 int fMaxIter; // maximum number of iterations 00156 int fStrategy; // minimizer strategy (used by Minuit) 00157 double fErrorDef; // error definition (=1. for getting 1 sigma error for chi2 fits) 00158 double fTolerance; // minimize tolerance to reach solution 00159 double fPrecision; // precision of the objective function evaluation (value <=0 means left to default) 00160 std::string fMinimType; // Minimizer type (Minuit, Minuit2, etc.. 00161 std::string fAlgoType; // Minimizer algorithmic specification (Migrad, Minimize, ...) 00162 00163 // extra options 00164 ROOT::Math::IOptions * fExtraOptions; // extra options 00165 00166 }; 00167 00168 } // end namespace Math 00169 00170 } // end namespace ROOT 00171 00172 #endif