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
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
24namespace ROOT {
25
26
27namespace 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
43void 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 if (Minim::gDefaultMinimAlgo == "" && ( Minim::gDefaultMinimizer == "Minuit" ||
48 Minim::gDefaultMinimizer == "Minuit2") )
49 Minim::gDefaultMinimAlgo = "Migrad";
50}
52 // set the default error definition
54}
56 // set the default tolerance
58}
60 // set the default precision
62}
64 // set the default maximum number of function calls
66}
68 // set the default maximum number of iterations
69 Minim::gDefaultMaxIter = maxiter;
70}
72 // set the default minimization strategy
74}
76 // set the default printing level
78}
80 // set the pointer to default extra options
82 Minim::gDefaultExtraOptions = (extraoptions) ? extraoptions->Clone() : 0;
83}
84
86 if (Minim::gDefaultMinimAlgo == "Migrad" && Minim::gDefaultMinimizer != "Minuit" &&
87 Minim::gDefaultMinimizer != "Minuit2" )
90}
99
101{
102 // return default minimizer
103 // if is "" (no default is set) read from etc/system.rootrc
104
105#ifdef MATH_NO_PLUGIN_MANAGER
108
109 Minim::gDefaultMinimizer = "Minuit2"; // in case no PM exists
110
111#else
113
116
118
119 // Another thread also waiting for the write lock might have
120 // done the assignment
123
124 // use value defined in etc/system.rootrc (if not found Minuit is used)
125 if (gEnv)
126 Minim::gDefaultMinimizer = gEnv->GetValue("Root.Fitter","Minuit");
127#endif
128
130}
131
132
134 fExtraOptions(0)
135{
136 // constructor using the default options
137
139}
140
141
143 // copy constructor
144 (*this) = opt;
145}
146
148 // assignment operator
149 if (this == &opt) return *this; // self assignment
150 fLevel = opt.fLevel;
151 fMaxCalls = opt.fMaxCalls;
152 fMaxIter = opt.fMaxIter;
153 fStrategy = opt.fStrategy;
154 fErrorDef = opt.fErrorDef;
158 fAlgoType = opt.fAlgoType;
159
160 delete fExtraOptions;
161 fExtraOptions = (opt.fExtraOptions) ? (opt.fExtraOptions)->Clone() : 0;
162
163 return *this;
164}
165
167 delete fExtraOptions;
168}
169
178
180
182
183 // case of Fumili2 and TMinuit
184 if (fMinimType == "TMinuit")
185 fMinimType = "Minuit";
186 else if (fMinimType == "Fumili2") {
187 fMinimType = "Minuit2";
188 fAlgoType = "Fumili";
189 }
190 else if (fMinimType == "GSLMultiMin" && fAlgoType == "Migrad")
191 fAlgoType = "BFGS2";
192 else if (fMinimType != "Minuit" && fMinimType != "Minuit2" && fAlgoType == "Migrad")
193 fAlgoType = "";
194
195 delete fExtraOptions;
196 fExtraOptions = 0;
197 // check if extra options exists (copy them if needed)
200 else {
201 IOptions * gopts = FindDefault( fMinimType.c_str() );
202 if (gopts) fExtraOptions = gopts->Clone();
203 }
204}
205
207 // set extra options (clone the passed one)
208 delete fExtraOptions;
209 fExtraOptions = opt.Clone();
210}
211
212void MinimizerOptions::Print(std::ostream & os) const {
213 //print all the options
214 os << std::setw(25) << "Minimizer Type" << " : " << std::setw(15) << fMinimType << std::endl;
215 os << std::setw(25) << "Minimizer Algorithm" << " : " << std::setw(15) << fAlgoType << std::endl;
216 os << std::setw(25) << "Strategy" << " : " << std::setw(15) << fStrategy << std::endl;
217 os << std::setw(25) << "Tolerance" << " : " << std::setw(15) << fTolerance << std::endl;
218 os << std::setw(25) << "Max func calls" << " : " << std::setw(15) << fMaxCalls << std::endl;
219 os << std::setw(25) << "Max iterations" << " : " << std::setw(15) << fMaxIter << std::endl;
220 os << std::setw(25) << "Func Precision" << " : " << std::setw(15) << fPrecision << std::endl;
221 os << std::setw(25) << "Error definition" << " : " << std::setw(15) << fErrorDef << std::endl;
222 os << std::setw(25) << "Print Level" << " : " << std::setw(15) << fLevel << std::endl;
223
224 if (ExtraOptions()) {
225 os << fMinimType << " specific options :" << std::endl;
226 ExtraOptions()->Print(os);
227 }
228}
229
231 // create default extra options for the given algorithm type
233}
234
236 // find extra options for the given algorithm type
238}
239
240void MinimizerOptions::PrintDefault(const char * name, std::ostream & os) {
241 //print default options
243 tmp.Print(os);
244 if (!tmp.ExtraOptions() ) {
245 IOptions * opt = FindDefault(name);
246 os << "Specific options for " << name << std::endl;
247 if (opt) opt->Print(os);
248 }
249}
250
251
252
253
254} // end namespace Math
255
256} // end namespace ROOT
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
R__EXTERN TEnv * gEnv
Definition: TEnv.h:170
char name[80]
Definition: TGX11.cxx:110
int type
Definition: TGX11.cxx:121
#define R__WRITE_LOCKGUARD(mutex)
#define R__READ_LOCKGUARD(mutex)
static IOptions & Default(const char *algoname)
static IOptions * FindDefault(const char *algoname)
Generic interface for defining configuration options of a numerical algorithm.
Definition: IOptions.h:31
virtual void Print(std::ostream &=std::cout) const
print options
Definition: IOptions.h:99
virtual IOptions * Clone() const =0
MinimizerOptions & operator=(const MinimizerOptions &opt)
assignment operators
static void SetDefaultMinimizer(const char *type, const char *algo=0)
Set the the default Minimizer type and corresponding algorithms.
static ROOT::Math::IOptions & Default(const char *name)
Retrieve extra options for a given minimizer name.
static void SetDefaultMaxFunctionCalls(int maxcall)
Set the maximum number of function calls.
const IOptions * ExtraOptions() const
return extra options (NULL pointer if they are not present)
static ROOT::Math::IOptions * FindDefault(const char *name)
Find an extra options and return a nullptr if it is not existing.
static void SetDefaultExtraOptions(const IOptions *extraoptions)
Set additional minimizer options as pair of (string,value).
static IOptions * DefaultExtraOptions()
static void SetDefaultMaxIterations(int maxiter)
Set the maximum number of iterations.
static void SetDefaultErrorDef(double up)
Set the default level for computing the parameter errors.
static void SetDefaultStrategy(int strat)
Set the default strategy.
static void SetDefaultPrecision(double prec)
Set the default Minimizer precision.
static const std::string & DefaultMinimizerType()
void SetExtraOptions(const IOptions &opt)
set extra options (in this case pointer is cloned)
static void PrintDefault(const char *name, std::ostream &os=std::cout)
Print all the default options including the extra one specific for a given minimizer name.
static const std::string & DefaultMinimizerAlgo()
static void SetDefaultPrintLevel(int level)
Set the default Print Level.
ROOT::Math::IOptions * fExtraOptions
void ResetToDefaultOptions()
non-static methods for setting options
static void SetDefaultTolerance(double tol)
Set the Minimization tolerance.
void Print(std::ostream &os=std::cout) const
print all the options
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
Namespace for new Math classes and functions.
static double gDefaultPrecision
static int gDefaultPrintLevel
static int gDefaultStrategy
static std::string gDefaultMinimAlgo
static double gDefaultTolerance
static int gDefaultMaxCalls
static int gDefaultMaxIter
static double gDefaultErrorDef
static std::string gDefaultMinimizer
static IOptions * gDefaultExtraOptions
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
R__EXTERN TVirtualRWMutex * gCoreMutex