00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "Math/MinimizerOptions.h"
00012
00013 #include "Math/GenAlgoOptions.h"
00014
00015
00016 #ifndef MATH_NO_PLUGIN_MANAGER
00017 #include "TEnv.h"
00018 #endif
00019
00020 #include <iomanip>
00021
00022 namespace ROOT {
00023
00024
00025 namespace Math {
00026
00027 namespace Minim {
00028 static std::string gDefaultMinimizer = "";
00029 static std::string gDefaultMinimAlgo = "Migrad";
00030 static double gDefaultErrorDef = 1.;
00031 static double gDefaultTolerance = 1.E-4;
00032 static double gDefaultPrecision = -1;
00033 static int gDefaultMaxCalls = 0;
00034 static int gDefaultMaxIter = 0;
00035 static int gDefaultStrategy = 1;
00036 static int gDefaultPrintLevel = 0;
00037 }
00038
00039
00040 void MinimizerOptions::SetDefaultMinimizer(const char * type, const char * algo ) {
00041
00042 if (type) Minim::gDefaultMinimizer = std::string(type);
00043 if (algo) Minim::gDefaultMinimAlgo = std::string(algo);
00044 }
00045 void MinimizerOptions::SetDefaultErrorDef(double up) {
00046
00047 Minim::gDefaultErrorDef = up;
00048 }
00049 void MinimizerOptions::SetDefaultTolerance(double tol) {
00050
00051 Minim::gDefaultTolerance = tol;
00052 }
00053 void MinimizerOptions::SetDefaultPrecision(double prec) {
00054
00055 Minim::gDefaultPrecision = prec;
00056 }
00057 void MinimizerOptions::SetDefaultMaxFunctionCalls(int maxcall) {
00058
00059 Minim::gDefaultMaxCalls = maxcall;
00060 }
00061 void MinimizerOptions::SetDefaultMaxIterations(int maxiter) {
00062
00063 Minim::gDefaultMaxIter = maxiter;
00064 }
00065 void MinimizerOptions::SetDefaultStrategy(int stra) {
00066
00067 Minim::gDefaultStrategy = stra;
00068 }
00069 void MinimizerOptions::SetDefaultPrintLevel(int level) {
00070
00071 Minim::gDefaultPrintLevel = level;
00072 }
00073
00074 const std::string & MinimizerOptions::DefaultMinimizerAlgo() { return Minim::gDefaultMinimAlgo; }
00075 double MinimizerOptions::DefaultErrorDef() { return Minim::gDefaultErrorDef; }
00076 double MinimizerOptions::DefaultTolerance() { return Minim::gDefaultTolerance; }
00077 double MinimizerOptions::DefaultPrecision() { return Minim::gDefaultPrecision; }
00078 int MinimizerOptions::DefaultMaxFunctionCalls() { return Minim::gDefaultMaxCalls; }
00079 int MinimizerOptions::DefaultMaxIterations() { return Minim::gDefaultMaxIter; }
00080 int MinimizerOptions::DefaultStrategy() { return Minim::gDefaultStrategy; }
00081 int MinimizerOptions::DefaultPrintLevel() { return Minim::gDefaultPrintLevel; }
00082
00083 const std::string & MinimizerOptions::DefaultMinimizerType()
00084 {
00085
00086
00087
00088 if (Minim::gDefaultMinimizer.size() == 0) {
00089 #ifndef MATH_NO_PLUGIN_MANAGER
00090
00091 if (gEnv)
00092 Minim::gDefaultMinimizer = gEnv->GetValue("Root.Fitter","Minuit");
00093 #else
00094 Minim::gDefaultMinimizer = "Minuit2";
00095 #endif
00096 }
00097
00098 return Minim::gDefaultMinimizer;
00099 }
00100
00101
00102 MinimizerOptions::MinimizerOptions(IOptions * extraOpts):
00103 fLevel( Minim::gDefaultPrintLevel),
00104 fMaxCalls( Minim::gDefaultMaxCalls ),
00105 fMaxIter( Minim::gDefaultMaxIter ),
00106 fStrategy( Minim::gDefaultStrategy ),
00107 fErrorDef( Minim::gDefaultErrorDef ),
00108 fTolerance( Minim::gDefaultTolerance ),
00109 fPrecision( Minim::gDefaultPrecision ),
00110 fExtraOptions(extraOpts)
00111 {
00112
00113
00114 fMinimType = MinimizerOptions::DefaultMinimizerType();
00115
00116 fAlgoType = Minim::gDefaultMinimAlgo;
00117
00118
00119 if (fMinimType == "TMinuit") fMinimType = "Minuit";
00120 else if (fMinimType == "Fumili2") {
00121 fMinimType = "Minuit2";
00122 fAlgoType = "Fumili";
00123 }
00124 else if (fMinimType == "GSLMultiMin" && fAlgoType == "Migrad")
00125 fAlgoType = "BFGS2";
00126
00127
00128 if (!fExtraOptions) {
00129 IOptions * gopts = FindDefault( fMinimType.c_str() );
00130 if (gopts) fExtraOptions = gopts->Clone();
00131 }
00132 }
00133
00134
00135 MinimizerOptions::MinimizerOptions(const MinimizerOptions & opt) : fExtraOptions(0) {
00136
00137 (*this) = opt;
00138 }
00139
00140 MinimizerOptions & MinimizerOptions::operator=(const MinimizerOptions & opt) {
00141
00142 if (this == &opt) return *this;
00143 fLevel = opt.fLevel;
00144 fMaxCalls = opt.fMaxCalls;
00145 fMaxIter = opt.fMaxIter;
00146 fStrategy = opt.fStrategy;
00147 fErrorDef = opt.fErrorDef;
00148 fTolerance = opt.fTolerance;
00149 fPrecision = opt.fPrecision;
00150 fMinimType = opt.fMinimType;
00151 fAlgoType = opt.fAlgoType;
00152
00153 if (fExtraOptions) delete fExtraOptions;
00154 fExtraOptions = 0;
00155 if (opt.fExtraOptions) fExtraOptions = (opt.fExtraOptions)->Clone();
00156 return *this;
00157 }
00158
00159 MinimizerOptions::~MinimizerOptions() {
00160 if (fExtraOptions) delete fExtraOptions;
00161 }
00162
00163 void MinimizerOptions::SetExtraOptions(const IOptions & opt) {
00164
00165 if (fExtraOptions) delete fExtraOptions;
00166 fExtraOptions = opt.Clone();
00167 }
00168
00169 void MinimizerOptions::Print(std::ostream & os) const {
00170
00171 os << std::setw(25) << "Minimizer Type" << " : " << std::setw(15) << fMinimType << std::endl;
00172 os << std::setw(25) << "Minimizer Algorithm" << " : " << std::setw(15) << fAlgoType << std::endl;
00173 os << std::setw(25) << "Strategy" << " : " << std::setw(15) << fStrategy << std::endl;
00174 os << std::setw(25) << "Tolerance" << " : " << std::setw(15) << fTolerance << std::endl;
00175 os << std::setw(25) << "Max func calls" << " : " << std::setw(15) << fMaxCalls << std::endl;
00176 os << std::setw(25) << "Max iterations" << " : " << std::setw(15) << fMaxIter << std::endl;
00177 os << std::setw(25) << "Func Precision" << " : " << std::setw(15) << fPrecision << std::endl;
00178 os << std::setw(25) << "Error definition" << " : " << std::setw(15) << fErrorDef << std::endl;
00179 os << std::setw(25) << "Print Level" << " : " << std::setw(15) << fLevel << std::endl;
00180
00181 if (ExtraOptions()) {
00182 os << fMinimType << " specific options :" << std::endl;
00183 ExtraOptions()->Print(os);
00184 }
00185 }
00186
00187 IOptions & MinimizerOptions::Default(const char * name) {
00188
00189 return GenAlgoOptions::Default(name);
00190 }
00191
00192 IOptions * MinimizerOptions::FindDefault(const char * name) {
00193
00194 return GenAlgoOptions::FindDefault(name);
00195 }
00196
00197 void MinimizerOptions::PrintDefault(const char * name, std::ostream & os) {
00198
00199 MinimizerOptions tmp;
00200 tmp.Print(os);
00201 if (!tmp.ExtraOptions() ) {
00202 IOptions * opt = FindDefault(name);
00203 os << "Specific options for " << name << std::endl;
00204 if (opt) opt->Print(os);
00205 }
00206 }
00207
00208
00209
00210
00211 }
00212
00213 }
00214