Logo ROOT  
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 #include "TVirtualRWMutex.h"
19 #endif
20 
21 
22 #include <iomanip>
23 
24 namespace ROOT {
25 
26 
27 namespace Math {
28 
29  namespace Minim {
30  static std::string gDefaultMinimizer = ""; // take from /etc/system.rootrc in ROOT Fitter
31  static std::string gDefaultMinimAlgo = "Migrad";
32  static double gDefaultErrorDef = 1.;
33  static double gDefaultTolerance = 1.E-2;
34  static double gDefaultPrecision = -1; // value <= 0 means left to minimizer
35  static int gDefaultMaxCalls = 0; // 0 means leave default values Deaf
36  static int gDefaultMaxIter = 0;
37  static int gDefaultStrategy = 1;
38  static int gDefaultPrintLevel = 0;
39  static IOptions * gDefaultExtraOptions = 0; // pointer to default extra options
40  }
41 
42 
43 void MinimizerOptions::SetDefaultMinimizer(const char * type, const char * algo) {
44  // set the default minimizer type and algorithm
45  if (type) Minim::gDefaultMinimizer = std::string(type);
46  if (algo) Minim::gDefaultMinimAlgo = std::string(algo);
47 }
49  // set the default error definition
51 }
53  // set the default tolerance
55 }
56 void MinimizerOptions::SetDefaultPrecision(double prec) {
57  // set the default precision
59 }
61  // set the default maximum number of function calls
63 }
65  // set the default maximum number of iterations
67 }
69  // set the default minimization strategy
71 }
73  // set the default printing level
75 }
76 void MinimizerOptions::SetDefaultExtraOptions(const IOptions * extraoptions) {
77  // set the pointer to default extra options
79  Minim::gDefaultExtraOptions = (extraoptions) ? extraoptions->Clone() : 0;
80 }
81 
91 
93 {
94  // return default minimizer
95  // if is "" (no default is set) read from etc/system.rootrc
96 
97 #ifdef MATH_NO_PLUGIN_MANAGER
98  if (Minim::gDefaultMinimizer.size() != 0)
100 
101  Minim::gDefaultMinimizer = "Minuit2"; // in case no PM exists
102 
103 #else
105 
106  if (Minim::gDefaultMinimizer.size() != 0)
108 
110 
111  // Another thread also waiting for the write lock might have
112  // done the assignment
113  if (Minim::gDefaultMinimizer.size() != 0)
115 
116  // use value defined in etc/system.rootrc (if not found Minuit is used)
117  if (gEnv)
118  Minim::gDefaultMinimizer = gEnv->GetValue("Root.Fitter","Minuit");
119 #endif
120 
122 }
123 
124 
126  fExtraOptions(0)
127 {
128  // constructor using the default options
129 
131 }
132 
133 
134 MinimizerOptions::MinimizerOptions(const MinimizerOptions & opt) : fExtraOptions(0) {
135  // copy constructor
136  (*this) = opt;
137 }
138 
140  // assignment operator
141  if (this == &opt) return *this; // self assignment
142  fLevel = opt.fLevel;
143  fMaxCalls = opt.fMaxCalls;
145  fStrategy = opt.fStrategy;
146  fErrorDef = opt.fErrorDef;
147  fTolerance = opt.fTolerance;
148  fPrecision = opt.fPrecision;
150  fAlgoType = opt.fAlgoType;
151 
152  delete fExtraOptions;
153  fExtraOptions = (opt.fExtraOptions) ? (opt.fExtraOptions)->Clone() : 0;
154 
155  return *this;
156 }
157 
159  delete fExtraOptions;
160 }
161 
170 
172 
174 
175  // case of Fumili2 and TMinuit
176  if (fMinimType == "TMinuit") fMinimType = "Minuit";
177  else if (fMinimType == "Fumili2") {
178  fMinimType = "Minuit2";
179  fAlgoType = "Fumili";
180  }
181  else if (fMinimType == "GSLMultiMin" && fAlgoType == "Migrad")
182  fAlgoType = "BFGS2";
183 
184  delete fExtraOptions;
185  fExtraOptions = 0;
186  // check if extra options exists (copy them if needed)
189  else {
190  IOptions * gopts = FindDefault( fMinimType.c_str() );
191  if (gopts) fExtraOptions = gopts->Clone();
192  }
193 }
194 
195 void MinimizerOptions::SetExtraOptions(const IOptions & opt) {
196  // set extra options (clone the passed one)
197  delete fExtraOptions;
198  fExtraOptions = opt.Clone();
199 }
200 
201 void MinimizerOptions::Print(std::ostream & os) const {
202  //print all the options
203  os << std::setw(25) << "Minimizer Type" << " : " << std::setw(15) << fMinimType << std::endl;
204  os << std::setw(25) << "Minimizer Algorithm" << " : " << std::setw(15) << fAlgoType << std::endl;
205  os << std::setw(25) << "Strategy" << " : " << std::setw(15) << fStrategy << std::endl;
206  os << std::setw(25) << "Tolerance" << " : " << std::setw(15) << fTolerance << std::endl;
207  os << std::setw(25) << "Max func calls" << " : " << std::setw(15) << fMaxCalls << std::endl;
208  os << std::setw(25) << "Max iterations" << " : " << std::setw(15) << fMaxIter << std::endl;
209  os << std::setw(25) << "Func Precision" << " : " << std::setw(15) << fPrecision << std::endl;
210  os << std::setw(25) << "Error definition" << " : " << std::setw(15) << fErrorDef << std::endl;
211  os << std::setw(25) << "Print Level" << " : " << std::setw(15) << fLevel << std::endl;
212 
213  if (ExtraOptions()) {
214  os << fMinimType << " specific options :" << std::endl;
215  ExtraOptions()->Print(os);
216  }
217 }
218 
219 IOptions & MinimizerOptions::Default(const char * name) {
220  // create default extra options for the given algorithm type
222 }
223 
224 IOptions * MinimizerOptions::FindDefault(const char * name) {
225  // find extra options for the given algorithm type
227 }
228 
229 void MinimizerOptions::PrintDefault(const char * name, std::ostream & os) {
230  //print default options
231  MinimizerOptions tmp;
232  tmp.Print(os);
233  if (!tmp.ExtraOptions() ) {
235  os << "Specific options for " << name << std::endl;
236  if (opt) opt->Print(os);
237  }
238 }
239 
240 
241 
242 
243 } // end namespace Math
244 
245 } // end namespace ROOT
246 
ROOT::Math::MinimizerOptions::fErrorDef
double fErrorDef
Definition: MinimizerOptions.h:167
ROOT::Math::Minim::gDefaultStrategy
static int gDefaultStrategy
Definition: MinimizerOptions.cxx:52
ROOT::Math::MinimizerOptions::SetDefaultPrintLevel
static void SetDefaultPrintLevel(int level)
Definition: MinimizerOptions.cxx:82
ROOT::Math::Minim::gDefaultMinimAlgo
static std::string gDefaultMinimAlgo
Definition: MinimizerOptions.cxx:46
R__READ_LOCKGUARD
#define R__READ_LOCKGUARD(mutex)
Definition: TVirtualRWMutex.h:148
ROOT::Math::MinimizerOptions::SetDefaultMinimizer
static void SetDefaultMinimizer(const char *type, const char *algo=0)
Definition: MinimizerOptions.cxx:53
gEnv
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
ROOT::Math::MinimizerOptions::Print
void Print(std::ostream &os=std::cout) const
print all the options
Definition: MinimizerOptions.cxx:211
ROOT::Math::MinimizerOptions::SetDefaultStrategy
static void SetDefaultStrategy(int strat)
Definition: MinimizerOptions.cxx:78
ROOT::Math::Minim::gDefaultMaxCalls
static int gDefaultMaxCalls
Definition: MinimizerOptions.cxx:50
ROOT::Math::MinimizerOptions::SetDefaultExtraOptions
static void SetDefaultExtraOptions(const IOptions *extraoptions)
Definition: MinimizerOptions.cxx:86
ROOT::Math::Minim::gDefaultTolerance
static double gDefaultTolerance
Definition: MinimizerOptions.cxx:48
ROOT::Math::Minim::gDefaultPrintLevel
static int gDefaultPrintLevel
Definition: MinimizerOptions.cxx:53
ROOT::Math::MinimizerOptions::DefaultMaxFunctionCalls
static int DefaultMaxFunctionCalls()
Definition: MinimizerOptions.cxx:96
TVirtualRWMutex.h
ROOT::Math::MinimizerOptions::fExtraOptions
ROOT::Math::IOptions * fExtraOptions
Definition: MinimizerOptions.h:174
TEnv::GetValue
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
ROOT::gCoreMutex
R__EXTERN TVirtualRWMutex * gCoreMutex
Definition: TVirtualRWMutex.h:38
TEnv.h
ROOT::Math::MinimizerOptions::SetDefaultMaxIterations
static void SetDefaultMaxIterations(int maxiter)
Definition: MinimizerOptions.cxx:74
ROOT::Math::MinimizerOptions::fAlgoType
std::string fAlgoType
Definition: MinimizerOptions.h:171
ROOT::Math::MinimizerOptions::PrintDefault
static void PrintDefault(const char *name, std::ostream &os=std::cout)
print all the default options for the name given
Definition: MinimizerOptions.cxx:239
MinimizerOptions.h
ROOT::Math::MinimizerOptions::fTolerance
double fTolerance
Definition: MinimizerOptions.h:168
ROOT::Math::MinimizerOptions::FindDefault
static ROOT::Math::IOptions * FindDefault(const char *name)
Definition: MinimizerOptions.cxx:234
ROOT::Math::MinimizerOptions::ResetToDefaultOptions
void ResetToDefaultOptions()
non-static methods for setting options
Definition: MinimizerOptions.cxx:172
ROOT::Math::MinimizerOptions::DefaultMinimizerType
static const std::string & DefaultMinimizerType()
Definition: MinimizerOptions.cxx:102
ROOT::Math::GenAlgoOptions::FindDefault
static IOptions * FindDefault(const char *algoname)
Definition: GenAlgoOptions.cxx:58
ROOT::Math::MinimizerOptions::DefaultErrorDef
static double DefaultErrorDef()
Definition: MinimizerOptions.cxx:93
ROOT::Math::Minim::gDefaultErrorDef
static double gDefaultErrorDef
Definition: MinimizerOptions.cxx:47
ROOT::Math::MinimizerOptions
Minimizer options.
Definition: MinimizerOptions.h:42
ROOT::Math::MinimizerOptions::DefaultPrecision
static double DefaultPrecision()
Definition: MinimizerOptions.cxx:95
ROOT::Math::IOptions
Generic interface for defining configuration options of a numerical algorithm.
Definition: IOptions.h:41
ROOT::Math::MinimizerOptions::MinimizerOptions
MinimizerOptions()
Definition: MinimizerOptions.cxx:135
ROOT::Math::MinimizerOptions::SetDefaultErrorDef
static void SetDefaultErrorDef(double up)
Definition: MinimizerOptions.cxx:58
ROOT::Math::MinimizerOptions::DefaultStrategy
static int DefaultStrategy()
Definition: MinimizerOptions.cxx:98
ROOT::Math::IOptions::Clone
virtual IOptions * Clone() const =0
ROOT::Math::MinimizerOptions::fStrategy
int fStrategy
Definition: MinimizerOptions.h:166
ROOT::Math::MinimizerOptions::fMaxCalls
int fMaxCalls
Definition: MinimizerOptions.h:164
ROOT::Math::MinimizerOptions::DefaultMaxIterations
static int DefaultMaxIterations()
Definition: MinimizerOptions.cxx:97
ROOT::Math::MinimizerOptions::SetDefaultMaxFunctionCalls
static void SetDefaultMaxFunctionCalls(int maxcall)
Definition: MinimizerOptions.cxx:70
ROOT::Math::MinimizerOptions::ExtraOptions
const IOptions * ExtraOptions() const
return extra options (NULL pointer if they are not present)
Definition: MinimizerOptions.h:116
ROOT::Math::Minim::gDefaultExtraOptions
static IOptions * gDefaultExtraOptions
Definition: MinimizerOptions.cxx:54
ROOT::Math::MinimizerOptions::DefaultTolerance
static double DefaultTolerance()
Definition: MinimizerOptions.cxx:94
ROOT::Math::MinimizerOptions::DefaultExtraOptions
static IOptions * DefaultExtraOptions()
Definition: MinimizerOptions.cxx:100
ROOT::Math::MinimizerOptions::DefaultMinimizerAlgo
static const std::string & DefaultMinimizerAlgo()
Definition: MinimizerOptions.cxx:92
ROOT::Math::MinimizerOptions::fMinimType
std::string fMinimType
Definition: MinimizerOptions.h:170
ROOT::Math::GenAlgoOptions::Default
static IOptions & Default(const char *algoname)
Definition: GenAlgoOptions.cxx:65
ROOT::Math::MinimizerOptions::DefaultPrintLevel
static int DefaultPrintLevel()
Definition: MinimizerOptions.cxx:99
ROOT::Math::MinimizerOptions::SetDefaultPrecision
static void SetDefaultPrecision(double prec)
Definition: MinimizerOptions.cxx:66
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Math::IOptions::Print
virtual void Print(std::ostream &=std::cout) const
print options
Definition: IOptions.h:114
ROOT::Math::MinimizerOptions::fPrecision
double fPrecision
Definition: MinimizerOptions.h:169
GenAlgoOptions.h
R__WRITE_LOCKGUARD
#define R__WRITE_LOCKGUARD(mutex)
Definition: TVirtualRWMutex.h:151
type
int type
Definition: TGX11.cxx:121
ROOT::Math::Minim::gDefaultMaxIter
static int gDefaultMaxIter
Definition: MinimizerOptions.cxx:51
ROOT::Math::MinimizerOptions::~MinimizerOptions
~MinimizerOptions()
Definition: MinimizerOptions.cxx:168
ROOT::Math::MinimizerOptions::operator=
MinimizerOptions & operator=(const MinimizerOptions &opt)
assignment operators
Definition: MinimizerOptions.cxx:149
ROOT::Math::MinimizerOptions::SetDefaultTolerance
static void SetDefaultTolerance(double tol)
Definition: MinimizerOptions.cxx:62
ROOT::Math::Minim::gDefaultMinimizer
static std::string gDefaultMinimizer
Definition: MinimizerOptions.cxx:45
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Math::MinimizerOptions::fMaxIter
int fMaxIter
Definition: MinimizerOptions.h:165
Math
ROOT::Math::MinimizerOptions::Default
static ROOT::Math::IOptions & Default(const char *name)
retrieve extra options - if not existing create a IOptions
Definition: MinimizerOptions.cxx:229
ROOT::Math::MinimizerOptions::SetExtraOptions
void SetExtraOptions(const IOptions &opt)
set extra options (in this case pointer is cloned)
Definition: MinimizerOptions.cxx:205
ROOT::Math::Minim::gDefaultPrecision
static double gDefaultPrecision
Definition: MinimizerOptions.cxx:49
ROOT::Math::MinimizerOptions::fLevel
int fLevel
Definition: MinimizerOptions.h:163