Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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#include <RConfig.h>
16
17// case of using ROOT plug-in manager
18#ifndef MATH_NO_PLUGIN_MANAGER
19#include "TEnv.h"
20#include "TVirtualRWMutex.h"
21#endif
22
23
24#include <iomanip>
25
26namespace ROOT {
27
28
29namespace Math {
30
31 namespace Minim {
32 static std::string gDefaultMinimizer = ""; // take from /etc/system.rootrc in ROOT Fitter
33 static std::string gDefaultMinimAlgo = "Migrad";
34 static double gDefaultErrorDef = 1.;
35 static double gDefaultTolerance = 1.E-2;
36 static double gDefaultPrecision = -1; // value <= 0 means left to minimizer
37 static int gDefaultMaxCalls = 0; // 0 means leave default values Deaf
38 static int gDefaultMaxIter = 0;
39 static int gDefaultStrategy = 1;
40 static int gDefaultPrintLevel = 0;
41 static IOptions * gDefaultExtraOptions = nullptr; // pointer to default extra options
42 }
43
44
45void MinimizerOptions::SetDefaultMinimizer(const char * type, const char * algo) {
46 // set the default minimizer type and algorithm
47 if (type) Minim::gDefaultMinimizer = std::string(type);
48 if (algo) Minim::gDefaultMinimAlgo = std::string(algo);
49 if (Minim::gDefaultMinimAlgo == "" && ( Minim::gDefaultMinimizer == "Minuit" ||
50 Minim::gDefaultMinimizer == "Minuit2") )
51 Minim::gDefaultMinimAlgo = "Migrad";
52}
54 // set the default error definition
56}
58 // set the default tolerance
60}
62 // set the default precision
64}
66 // set the default maximum number of function calls
68}
70 // set the default maximum number of iterations
71 Minim::gDefaultMaxIter = maxiter;
72}
74 // set the default minimization strategy
76}
78 // set the default printing level
80}
82 // set the pointer to default extra options
84 Minim::gDefaultExtraOptions = (extraoptions) ? extraoptions->Clone() : nullptr;
85}
86
88 if (Minim::gDefaultMinimAlgo == "Migrad" && Minim::gDefaultMinimizer != "Minuit" &&
89 Minim::gDefaultMinimizer != "Minuit2" )
92}
101
103{
104 // return default minimizer
105 // if is "" (no default is set) read from etc/system.rootrc
106
107
108 // The "default default" minimizer in case there is nothing set in .rootrc
109#ifdef R__HAS_MINUIT2
110 static constexpr auto defaultDefaultMinimizer = "Minuit2";
111#else
112 static constexpr auto defaultDefaultMinimizer = "Minuit";
113#endif // R__HAS_MINUIT2
114
115
116#ifdef MATH_NO_PLUGIN_MANAGER
119
120 Minim::gDefaultMinimizer = defaultDefaultMinimizer; // in case no PM exists
121
122#else
124
127
129
130 // Another thread also waiting for the write lock might have
131 // done the assignment
134
135 // use value defined in etc/system.rootrc (if not found Minuit is used)
136 if (gEnv)
137 Minim::gDefaultMinimizer = gEnv->GetValue("Root.Fitter",defaultDefaultMinimizer);
138#endif
139
141}
142
143
145 fExtraOptions(nullptr)
146{
147 // constructor using the default options
148
150}
151
152
153MinimizerOptions::MinimizerOptions(const MinimizerOptions & opt) : fExtraOptions(nullptr) {
154 // copy constructor
155 (*this) = opt;
156}
157
159 // assignment operator
160 if (this == &opt) return *this; // self assignment
161 fLevel = opt.fLevel;
162 fMaxCalls = opt.fMaxCalls;
163 fMaxIter = opt.fMaxIter;
164 fStrategy = opt.fStrategy;
165 fErrorDef = opt.fErrorDef;
169 fAlgoType = opt.fAlgoType;
170
171 delete fExtraOptions;
172 fExtraOptions = (opt.fExtraOptions) ? (opt.fExtraOptions)->Clone() : nullptr;
173
174 return *this;
175}
176
178 delete fExtraOptions;
179}
180
189
191
193
194 // case of Fumili2 and TMinuit
195 if (fMinimType == "TMinuit")
196 fMinimType = "Minuit";
197 else if (fMinimType == "Fumili2") {
198 fMinimType = "Minuit2";
199 fAlgoType = "Fumili";
200 }
201 else if (fMinimType == "GSLMultiMin" && fAlgoType == "Migrad")
202 fAlgoType = "BFGS2";
203 else if (fMinimType != "Minuit" && fMinimType != "Minuit2" && fAlgoType == "Migrad")
204 fAlgoType = "";
205
206 delete fExtraOptions;
207 fExtraOptions = nullptr;
208 // check if extra options exists (copy them if needed)
211 else {
212 IOptions * gopts = FindDefault( fMinimType.c_str() );
213 if (gopts) fExtraOptions = gopts->Clone();
214 }
215}
216
218 // set extra options (clone the passed one)
219 delete fExtraOptions;
220 fExtraOptions = opt.Clone();
221}
222
223void MinimizerOptions::Print(std::ostream & os) const {
224 //print all the options
225 os << std::setw(25) << "Minimizer Type" << " : " << std::setw(15) << fMinimType << std::endl;
226 os << std::setw(25) << "Minimizer Algorithm" << " : " << std::setw(15) << fAlgoType << std::endl;
227 os << std::setw(25) << "Strategy" << " : " << std::setw(15) << fStrategy << std::endl;
228 os << std::setw(25) << "Tolerance" << " : " << std::setw(15) << fTolerance << std::endl;
229 os << std::setw(25) << "Max func calls" << " : " << std::setw(15) << fMaxCalls << std::endl;
230 os << std::setw(25) << "Max iterations" << " : " << std::setw(15) << fMaxIter << std::endl;
231 os << std::setw(25) << "Func Precision" << " : " << std::setw(15) << fPrecision << std::endl;
232 os << std::setw(25) << "Error definition" << " : " << std::setw(15) << fErrorDef << std::endl;
233 os << std::setw(25) << "Print Level" << " : " << std::setw(15) << fLevel << std::endl;
234
235 if (ExtraOptions()) {
236 os << fMinimType << " specific options :" << std::endl;
237 ExtraOptions()->Print(os);
238 }
239}
240
242 // create default extra options for the given algorithm type
244}
245
247 // find extra options for the given algorithm type
249}
250
251void MinimizerOptions::PrintDefault(const char * name, std::ostream & os) {
252 //print default options
254 tmp.Print(os);
255 if (!tmp.ExtraOptions() ) {
256 if (name) {
257 IOptions * opt = FindDefault(name);
258 os << "Specific options for " << name << std::endl;
259 if (opt) opt->Print(os);
260 } else {
262 }
263 }
264}
265
266
267
268
269} // end namespace Math
270
271} // end namespace ROOT
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
#define R__WRITE_LOCKGUARD(mutex)
#define R__READ_LOCKGUARD(mutex)
static void PrintAllDefault(std::ostream &os=std::cout)
print all the default options
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:28
virtual IOptions * Clone() const =0
virtual void Print(std::ostream &=std::cout) const
print options
Definition IOptions.cxx:56
MinimizerOptions & operator=(const MinimizerOptions &opt)
assignment operators
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.
double fPrecision
precision of the objective function evaluation (value <=0 means left to default)
std::string fMinimType
Minimizer type (Minuit, Minuit2, etc..
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.
int fMaxIter
maximum number of iterations
static void SetDefaultExtraOptions(const IOptions *extraoptions)
Set additional minimizer options as pair of (string,value).
static IOptions * DefaultExtraOptions()
std::string fAlgoType
Minimizer algorithmic specification (Migrad, Minimize, ...)
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 SetDefaultMinimizer(const char *type, const char *algo=nullptr)
Set the default Minimizer type and corresponding algorithms.
static void SetDefaultStrategy(int strat)
Set the default strategy.
static void SetDefaultPrecision(double prec)
Set the default Minimizer precision.
static const std::string & DefaultMinimizerType()
double fTolerance
minimize tolerance to reach solution
void SetExtraOptions(const IOptions &opt)
set extra options (in this case pointer is cloned)
int fStrategy
minimizer strategy (used by Minuit)
static void PrintDefault(const char *name=nullptr, std::ostream &os=std::cout)
Print all the default options including the extra one specific for a given minimizer name.
int fMaxCalls
maximum number of function calls
static const std::string & DefaultMinimizerAlgo()
double fErrorDef
error definition (=1. for getting 1 sigma error for chi2 fits)
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 std::string gDefaultMinimAlgo
static double gDefaultTolerance
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