Logo ROOT   6.08/07
Reference Guide
MinimizerOptions.cxx
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: L. Moneta Fri Aug 15 2008
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2008 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 #include "Math/MinimizerOptions.h"
12 
13 #include "Math/GenAlgoOptions.h"
14 
15 // case of using ROOT plug-in manager
16 #ifndef MATH_NO_PLUGIN_MANAGER
17 #include "TEnv.h"
18 #endif
19 
20 #include <iomanip>
21 
22 namespace ROOT {
23 
24 
25 namespace Math {
26 
27  namespace Minim {
28  static std::string gDefaultMinimizer = ""; // take from /etc/system.rootrc in ROOT Fitter
29  static std::string gDefaultMinimAlgo = "Migrad";
30  static double gDefaultErrorDef = 1.;
31  static double gDefaultTolerance = 1.E-2;
32  static double gDefaultPrecision = -1; // value <= 0 means left to minimizer
33  static int gDefaultMaxCalls = 0; // 0 means leave default values Deaf
34  static int gDefaultMaxIter = 0;
35  static int gDefaultStrategy = 1;
36  static int gDefaultPrintLevel = 0;
37  static IOptions * gDefaultExtraOptions = 0; // pointer to default extra options
38  }
39 
40 
41 void MinimizerOptions::SetDefaultMinimizer(const char * type, const char * algo) {
42  // set the default minimizer type and algorithm
43  if (type) Minim::gDefaultMinimizer = std::string(type);
44  if (algo) Minim::gDefaultMinimAlgo = std::string(algo);
45 }
47  // set the default error definition
49 }
51  // set the default tolerance
53 }
55  // set the default precision
57 }
59  // set the default maximum number of function calls
60  Minim::gDefaultMaxCalls = maxcall;
61 }
63  // set the default maximum number of iterations
64  Minim::gDefaultMaxIter = maxiter;
65 }
67  // set the default minimization strategy
69 }
71  // set the default printing level
73 }
75  // set the pointer to default extra options
77  Minim::gDefaultExtraOptions = (extraoptions) ? extraoptions->Clone() : 0;
78 }
79 
89 
91 {
92  // return default minimizer
93  // if is "" (no default is set) read from etc/system.rootrc
94 
95  if (Minim::gDefaultMinimizer.size() == 0) {
96 #ifndef MATH_NO_PLUGIN_MANAGER
97  // use value defined in etc/system.rootrc (if not found Minuit is used)
98  if (gEnv)
99  Minim::gDefaultMinimizer = gEnv->GetValue("Root.Fitter","Minuit");
100 #else
101  Minim::gDefaultMinimizer = "Minuit2"; // in case no PM exists
102 #endif
103  }
104 
106 }
107 
108 
110  fExtraOptions(0)
111 {
112  // constructor using the default options
113 
115 }
116 
117 
119  // copy constructor
120  (*this) = opt;
121 }
122 
124  // assignment operator
125  if (this == &opt) return *this; // self assignment
126  fLevel = opt.fLevel;
127  fMaxCalls = opt.fMaxCalls;
128  fMaxIter = opt.fMaxIter;
129  fStrategy = opt.fStrategy;
130  fErrorDef = opt.fErrorDef;
131  fTolerance = opt.fTolerance;
132  fPrecision = opt.fPrecision;
133  fMinimType = opt.fMinimType;
134  fAlgoType = opt.fAlgoType;
135 
136  delete fExtraOptions;
137  fExtraOptions = (opt.fExtraOptions) ? (opt.fExtraOptions)->Clone() : 0;
138 
139  return *this;
140 }
141 
143  delete fExtraOptions;
144 }
145 
154 
156 
158 
159  // case of Fumili2 and TMinuit
160  if (fMinimType == "TMinuit") fMinimType = "Minuit";
161  else if (fMinimType == "Fumili2") {
162  fMinimType = "Minuit2";
163  fAlgoType = "Fumili";
164  }
165  else if (fMinimType == "GSLMultiMin" && fAlgoType == "Migrad")
166  fAlgoType = "BFGS2";
167 
168  delete fExtraOptions;
169  fExtraOptions = 0;
170  // check if extra options exists (copy them if needed)
173  else {
174  IOptions * gopts = FindDefault( fMinimType.c_str() );
175  if (gopts) fExtraOptions = gopts->Clone();
176  }
177 }
178 
180  // set extra options (clone the passed one)
181  delete fExtraOptions;
182  fExtraOptions = opt.Clone();
183 }
184 
185 void MinimizerOptions::Print(std::ostream & os) const {
186  //print all the options
187  os << std::setw(25) << "Minimizer Type" << " : " << std::setw(15) << fMinimType << std::endl;
188  os << std::setw(25) << "Minimizer Algorithm" << " : " << std::setw(15) << fAlgoType << std::endl;
189  os << std::setw(25) << "Strategy" << " : " << std::setw(15) << fStrategy << std::endl;
190  os << std::setw(25) << "Tolerance" << " : " << std::setw(15) << fTolerance << std::endl;
191  os << std::setw(25) << "Max func calls" << " : " << std::setw(15) << fMaxCalls << std::endl;
192  os << std::setw(25) << "Max iterations" << " : " << std::setw(15) << fMaxIter << std::endl;
193  os << std::setw(25) << "Func Precision" << " : " << std::setw(15) << fPrecision << std::endl;
194  os << std::setw(25) << "Error definition" << " : " << std::setw(15) << fErrorDef << std::endl;
195  os << std::setw(25) << "Print Level" << " : " << std::setw(15) << fLevel << std::endl;
196 
197  if (ExtraOptions()) {
198  os << fMinimType << " specific options :" << std::endl;
199  ExtraOptions()->Print(os);
200  }
201 }
202 
204  // create default extra options for the given algorithm type
205  return GenAlgoOptions::Default(name);
206 }
207 
209  // find extra options for the given algorithm type
210  return GenAlgoOptions::FindDefault(name);
211 }
212 
213 void MinimizerOptions::PrintDefault(const char * name, std::ostream & os) {
214  //print default options
215  MinimizerOptions tmp;
216  tmp.Print(os);
217  if (!tmp.ExtraOptions() ) {
218  IOptions * opt = FindDefault(name);
219  os << "Specific options for " << name << std::endl;
220  if (opt) opt->Print(os);
221  }
222 }
223 
224 
225 
226 
227 } // end namespace Math
228 
229 } // end namespace ROOT
230 
static IOptions * gDefaultExtraOptions
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
void Print(std::ostream &os=std::cout) const
print all the options
static IOptions * DefaultExtraOptions()
virtual void Print(std::ostream &=std::cout) const
print options
Definition: IOptions.h:100
static int gDefaultMaxCalls
const IOptions * ExtraOptions() const
return extra options (NULL pointer if they are not present)
static void SetDefaultExtraOptions(const IOptions *extraoptions)
static double gDefaultPrecision
static void SetDefaultMaxIterations(int maxiter)
static ROOT::Math::IOptions & Default(const char *name)
retrieve extra options - if not existing create a IOptions
void ResetToDefaultOptions()
non-static methods for setting options
static std::string gDefaultMinimAlgo
static void SetDefaultPrintLevel(int level)
MinimizerOptions & operator=(const MinimizerOptions &opt)
assignment operators
static int gDefaultStrategy
void SetExtraOptions(const IOptions &opt)
set extra options (in this case pointer is cloned)
static void SetDefaultErrorDef(double up)
static void SetDefaultStrategy(int strat)
static void SetDefaultMaxFunctionCalls(int maxcall)
const double tol
static ROOT::Math::IOptions * FindDefault(const char *name)
static const std::string & DefaultMinimizerType()
static void PrintDefault(const char *name, std::ostream &os=std::cout)
print all the default options for the name given
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:496
ROOT::Math::IOptions * fExtraOptions
static double gDefaultTolerance
virtual IOptions * Clone() const =0
static int gDefaultPrintLevel
static std::string gDefaultMinimizer
static const std::string & DefaultMinimizerAlgo()
static double gDefaultErrorDef
static void SetDefaultTolerance(double tol)
int type
Definition: TGX11.cxx:120
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
static void SetDefaultPrecision(double prec)
Namespace for new Math classes and functions.
static IOptions & Default(const char *algoname)
Generic interface for defining configuration options of a numerical algorithm.
Definition: IOptions.h:32
static int gDefaultMaxIter
static IOptions * FindDefault(const char *algoname)
static void SetDefaultMinimizer(const char *type, const char *algo=0)
char name[80]
Definition: TGX11.cxx:109