Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
IntegratorOptions.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#include "Math/Integrator.h"
14#include "Math/GenAlgoOptions.h"
15
16#include "RConfigure.h"
17
18#include <algorithm>
19#include <functional>
20#include <cctype> // need to use c version of tolower defined here
21
22#include <map>
23
24namespace ROOT {
25
26namespace Math {
27
28 // eventually could take values from /etc/system.rootrc
29
30namespace IntegOneDim {
31
32#ifdef R__HAS_MATHMORE
34#else
36#endif
37 static double gDefaultAbsTolerance = 1.E-09;
38 static double gDefaultRelTolerance = 1.E-09;
39 static unsigned int gDefaultWKSize = 1000;
40 static unsigned int gDefaultNPointsLegendre = 10;
41 static unsigned int gDefaultNPointsGSLAdaptive = 3; // corresponds to 31 points
43
44
45}
46
47namespace IntegMultiDim {
48
50 // by default do not use absolute tolerance in AdaptiveIntegration multidim.
51 // If an absolute tolerance is given integration of shar peaks often failed
52 static double gDefaultAbsTolerance = 0.0;
53 static double gDefaultRelTolerance = 1.E-09;
54 static unsigned int gDefaultWKSize = 100000;
55 static unsigned int gDefaultNCalls = 100000;
56
57
58}
59
60
61// some utility functions
62
64
65
66 // traits for the specific methods 1D - ND
67 template<class OptionType>
68 struct OptionTrait {
69 static int N() { return 0; }
70 static int N(const OptionType & ) { return 0; }
71 static const char * DescriptionOfN() {return nullptr; }
72 };
73 template<>
76 static int N() { return OptType::DefaultNPoints(); }
77 static int N(const OptType & opt) { return opt.NPoints(); }
78 static const char * DescriptionOfN() {return "Rule (Npoints)";}
79 };
80 template<>
83 static int N() { return OptType::DefaultNCalls(); }
84 static int N(const OptType & opt) { return opt.NCalls(); }
85 static const char * DescriptionOfN() {return "(max) function calls";}
86 };
87
88
89 //print option values (not the default ones)
90 template <class OptionType>
91 void Print(std::ostream & os,const OptionType & opt) {
92 //print all the options
93 os << std::setw(25) << "Integrator Type" << " : " << std::setw(15) << opt.Integrator() << std::endl;
94 os << std::setw(25) << "Absolute tolerance" << " : " << std::setw(15) << opt.AbsTolerance() << std::endl;
95 os << std::setw(25) << "Relative tolerance" << " : " << std::setw(15) << opt.RelTolerance() << std::endl;
96 os << std::setw(25) << "Workspace size" << " : " << std::setw(15) << opt.WKSize() << std::endl;
98 os << std::setw(25) << OPT::DescriptionOfN() << " : " << std::setw(15) << OPT::N(opt) << std::endl;
99 if (opt.ExtraOptions()) {
100 os << opt.Integrator() << " specific options :" << std::endl;
101 opt.ExtraOptions()->Print(os);
102 }
103 }
104
105
106 /// print default options
107 template <class OptionType>
108 void PrintDefault(const char * name, std::ostream & os) {
109 //print default options
110 std::string integName = (name != nullptr) ? name : OptionType::DefaultIntegrator();
111 os << "Default options for numerical integrator " << integName << " : " << std::endl;
112 os << std::setw(25) << "Absolute tolerance" << " : " << std::setw(15) << OptionType::DefaultAbsTolerance() << std::endl;
113 os << std::setw(25) << "Relative tolerance" << " : " <<std::setw(15) << OptionType::DefaultRelTolerance() << std::endl;
114 os << std::setw(25) << "Workspace size" << " : " << std::setw(15) << OptionType::DefaultWKSize() << std::endl;
116 os << std::setw(25) << OPT::DescriptionOfN() << " : " << std::setw(15) << OPT::N() << std::endl;
117 IOptions * opts = GenAlgoOptions::FindDefault(integName.c_str());
118 if (opts) opts->Print(os);
119 }
120
121}
122
123
124/// constructor (protected) to avoid user creating this class
131
133 // copy constructor
134 (*this) = opt;
135}
136
138 // assignment operator
139 if (this == &opt) return *this; // self assignment
140 fWKSize = opt.fWKSize;
141 fNCalls = opt.fNCalls;
145
146// std::cout << " copy options for " << fIntegName << std::endl;
147// std::cout << fExtraOptions << std::endl;
148// if (fExtraOptions) fExtraOptions->Print(std::cout);
149
150// std::cout << opt.fExtraOptions << std::endl;
151// if (opt.fExtraOptions) (opt.fExtraOptions)->Print(std::cout);
152
153
154
155 ClearExtra();
156 if (opt.fExtraOptions) fExtraOptions = (opt.fExtraOptions)->Clone();
157 return *this;
158}
159
160
162 // delete extra options
163 if (fExtraOptions) delete fExtraOptions;
164 fExtraOptions = nullptr;
165}
166
168 // delete extra options
169 ClearExtra();
170 fExtraOptions = opt.Clone();
171}
172
173
174
175// one dim specific methods
176
177// implementation of non-static methods
178
180{
186
187 fExtraOptions = opts; // N.B. ownership of pointer is given to the class !
188
189 // check the default options if opts = 0
190 if (!fExtraOptions) {
191 std::string igname = DefaultIntegrator();
192 IOptions * gopts = FindDefault( igname.c_str() );
193 if (gopts) fExtraOptions = gopts->Clone();
194 }
195}
196
198 // set the default 1D integrator
199 if (!algo) return;
201}
202
206
207void IntegratorOneDimOptions::Print(std::ostream & os) const {
208 //print all the options
209 IntegOptionsUtil::Print(os, *this);
210}
211
212// one dim integrator options: implementation for static methods
213
214/// print default options
215void IntegratorOneDimOptions::PrintDefault(const char * name, std::ostream & os) {
216 //print default options
218}
219
220
221
233
234
239
244
245
247 // set the default tolerance
249}
251 // set the default tolerance
253}
254
256 // set the default workspace size
258}
260 // set the default number of points for the integration rule
262}
263
264
269
270
272 // create default extra options for the given algorithm type
273 return GenAlgoOptions::Default(algo);
274}
275
277 // find extra options for the given algorithm type
278 return GenAlgoOptions::FindDefault(algo);
279}
280
281//////////////////////////////////////////////////////
282//Multi-dim integration options implementation
283/////////////////////////////////////////////////////////
284
286{
292
293 fExtraOptions = opts; // N.B. ownership of pointer is given to the class !
294
295 // check the default options if opts = 0
296 if (!fExtraOptions) {
297 IOptions * gopts = FindDefault( DefaultIntegrator().c_str() );
298 if (gopts) fExtraOptions = gopts->Clone();
299 }
300}
301
303 // set the default integrator
304 if (!algo) return;
306}
307
311
312void IntegratorMultiDimOptions::Print(std::ostream & os) const {
313 //print all the options
314 IntegOptionsUtil::Print(os, *this);
315}
316
317// multi dim integrator options: implementation for static methods
318
319/// print default options
320void IntegratorMultiDimOptions::PrintDefault(const char * name, std::ostream & os) {
321 //print default options
323}
324
325
327 // set the default integrator
328 if (!algo) return;
329 // check if type is correct
331 if (type == IntegrationMultiDim::kDEFAULT) return; // this is possible only when invalid name was specified
333}
334
335
340
345
346
348 // set the default tolerance
350}
351
353 // set the default tolerance
355}
356
358 // set the default workspace size
360}
362 // set the default (max) function calls
364}
365
366
371
372
374 // create default extra options for the given algorithm type
375 return GenAlgoOptions::Default(algo);
376}
377
379 // create default extra options for the given algorithm type
380 return GenAlgoOptions::FindDefault(algo);
381}
382
383
384} // end namespace Math
385
386} // end namespace ROOT
387
#define OPT
Definition Match.cxx:38
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
char name[80]
Definition TGX11.cxx:148
int fIntegType
Integrator type (value converted from enum).
BaseIntegratorOptions()
protected constructor to avoid user creating this class
void SetExtraOptions(const IOptions &opt)
set extra options (in this case pointer is cloned)
double fAbsTolerance
absolute tolerance
double fRelTolerance
relative tolerance
BaseIntegratorOptions & operator=(const BaseIntegratorOptions &opt)
assignment operators
unsigned int fNCalls
(max) function calls
unsigned int fWKSize
workspace size
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
Numerical multi dimensional integration options.
static void SetDefaultWKSize(unsigned int size)
static void SetDefaultIntegrator(const char *name)
void Print(std::ostream &os=std::cout) const
print all the options
static void SetDefaultNCalls(unsigned int ncall)
IntegratorMultiDimOptions(IOptions *extraOpts=nullptr)
constructor using the default options can pass a pointer to extra options (N.B.
static ROOT::Math::IOptions * FindDefault(const char *name)
find specific options - return 0 if not existing
void SetIntegrator(const char *name)
set multi-dim integrator name
static IntegrationMultiDim::Type DefaultIntegratorType()
static ROOT::Math::IOptions & Default(const char *name)
retrieve specific options
std::string Integrator() const override
name of multi-dim integrator
unsigned int NCalls() const
maximum number of function calls
static void PrintDefault(const char *name=nullptr, std::ostream &os=std::cout)
print only the specified default options
static std::string GetName(IntegrationMultiDim::Type)
static function to get a string from the enumeration
IntegrationMultiDim::Type Type
static IntegrationMultiDim::Type GetType(const char *name)
static function to get the enumeration from a string
Numerical one dimensional integration options.
static void SetDefaultNPoints(unsigned int n)
static void SetDefaultAbsTolerance(double tol)
IntegratorOneDimOptions(IOptions *extraOpts=nullptr)
constructor using the default options can pass a pointer to extra options (N.B.
void Print(std::ostream &os=std::cout) const
print all the options
void SetIntegrator(const char *name)
set 1D integrator name
static void SetDefaultRelTolerance(double tol)
static void SetDefaultIntegrator(const char *name)
static ROOT::Math::IOptions & Default(const char *name)
retrieve specific options - if not existing create a IOptions
static void SetDefaultWKSize(unsigned int size)
std::string Integrator() const override
name of 1D integrator
static void PrintDefault(const char *name=nullptr, std::ostream &os=std::cout)
print only the specified default options
static IntegrationOneDim::Type DefaultIntegratorType()
static ROOT::Math::IOptions * FindDefault(const char *name)
find specific options - return 0 if not existing
unsigned int NPoints() const
Number of points used by current integration rule.
static std::string GetName(IntegrationOneDim::Type)
static function to get a string from the enumeration
IntegrationOneDim::Type Type
Definition Integrator.h:98
static IntegrationOneDim::Type GetType(const char *name)
static function to get the enumeration from a string
Type
enumeration specifying the integration types.
@ kADAPTIVESINGULAR
default adaptive integration type which can be used in the case of the presence of singularities.
@ kLEGENDRE
Gauss-Legendre integration.
@ kADAPTIVE
to be used for general functions without singularities
@ kGAUSS
simple Gauss integration method with fixed rule
@ kDEFAULT
default type specified in the static options
Type
enumeration specifying the integration types.
@ kADAPTIVE
adaptive multi-dimensional integration
@ kDEFAULT
default type specified in the static option
const Int_t n
Definition legend1.C:16
static unsigned int gDefaultNCalls
static unsigned int gDefaultWKSize
static unsigned int gDefaultWKSize
static unsigned int gDefaultNPoints
static unsigned int gDefaultNPointsGSLAdaptive
static unsigned int gDefaultNPointsLegendre
void PrintDefault(const char *name, std::ostream &os)
print default options
void Print(std::ostream &os, const OptionType &opt)