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// 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 = nullptr; // 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.empty() && ( 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() : nullptr;
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
106 // The "default default" minimizer in case there is nothing set in .rootrc
107 static constexpr auto defaultDefaultMinimizer = "Minuit2";
108
109#ifdef MATH_NO_PLUGIN_MANAGER
112
113 Minim::gDefaultMinimizer = defaultDefaultMinimizer; // in case no PM exists
114
115#else
117
118 if (!Minim::gDefaultMinimizer.empty())
120
122
123 // Another thread also waiting for the write lock might have
124 // done the assignment
125 if (!Minim::gDefaultMinimizer.empty())
127
128 // use value defined in etc/system.rootrc (if not found Minuit is used)
129 if (gEnv)
130 Minim::gDefaultMinimizer = gEnv->GetValue("Root.Fitter",defaultDefaultMinimizer);
131#endif
132
134}
135
136
138 fExtraOptions(nullptr)
139{
140 // constructor using the default options
141
143}
144
145
146MinimizerOptions::MinimizerOptions(const MinimizerOptions & opt) : fExtraOptions(nullptr) {
147 // copy constructor
148 (*this) = opt;
149}
150
152 // assignment operator
153 if (this == &opt) return *this; // self assignment
154 fLevel = opt.fLevel;
155 fMaxCalls = opt.fMaxCalls;
156 fMaxIter = opt.fMaxIter;
157 fStrategy = opt.fStrategy;
158 fErrorDef = opt.fErrorDef;
162 fAlgoType = opt.fAlgoType;
163
164 delete fExtraOptions;
165 fExtraOptions = (opt.fExtraOptions) ? (opt.fExtraOptions)->Clone() : nullptr;
166
167 return *this;
168}
169
171 delete fExtraOptions;
172}
173
182
184
186
187 // case of Fumili2 and TMinuit
188 if (fMinimType == "TMinuit")
189 fMinimType = "Minuit";
190 else if (fMinimType == "Fumili2") {
191 fMinimType = "Minuit2";
192 fAlgoType = "Fumili";
193 }
194 else if (fMinimType == "GSLMultiMin" && fAlgoType == "Migrad")
195 fAlgoType = "BFGS2";
196 else if (fMinimType != "Minuit" && fMinimType != "Minuit2" && fAlgoType == "Migrad")
197 fAlgoType = "";
198
199 delete fExtraOptions;
200 fExtraOptions = nullptr;
201 // check if extra options exists (copy them if needed)
204 else {
205 IOptions * gopts = FindDefault( fMinimType.c_str() );
206 if (gopts) fExtraOptions = gopts->Clone();
207 }
208}
209
211 // set extra options (clone the passed one)
212 delete fExtraOptions;
213 fExtraOptions = opt.Clone();
214}
215
216void MinimizerOptions::Print(std::ostream & os) const {
217 //print all the options
218 os << std::setw(25) << "Minimizer Type" << " : " << std::setw(15) << fMinimType << std::endl;
219 os << std::setw(25) << "Minimizer Algorithm" << " : " << std::setw(15) << fAlgoType << std::endl;
220 os << std::setw(25) << "Strategy" << " : " << std::setw(15) << fStrategy << std::endl;
221 os << std::setw(25) << "Tolerance" << " : " << std::setw(15) << fTolerance << std::endl;
222 os << std::setw(25) << "Max func calls" << " : " << std::setw(15) << fMaxCalls << std::endl;
223 os << std::setw(25) << "Max iterations" << " : " << std::setw(15) << fMaxIter << std::endl;
224 os << std::setw(25) << "Func Precision" << " : " << std::setw(15) << fPrecision << std::endl;
225 os << std::setw(25) << "Error definition" << " : " << std::setw(15) << fErrorDef << std::endl;
226 os << std::setw(25) << "Print Level" << " : " << std::setw(15) << fLevel << std::endl;
227
228 if (ExtraOptions()) {
229 os << fMinimType << " specific options :" << std::endl;
230 ExtraOptions()->Print(os);
231 }
232}
233
235 // create default extra options for the given algorithm type
237}
238
240 // find extra options for the given algorithm type
242}
243
244void MinimizerOptions::PrintDefault(const char * name, std::ostream & os) {
245 //print default options
247 tmp.Print(os);
248 if (!tmp.ExtraOptions() ) {
249 if (name) {
250 IOptions * opt = FindDefault(name);
251 os << "Specific options for " << name << std::endl;
252 if (opt) opt->Print(os);
253 } else {
255 }
256 }
257}
258
259
260
261
262} // end namespace Math
263
264} // 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
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
R__EXTERN TVirtualRWMutex * gCoreMutex