Logo ROOT  
Reference Guide
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 
11 #include "Math/IntegratorOptions.h"
12 #include "Math/Integrator.h"
14 #include "Math/GenAlgoOptions.h"
15 
16 #include "RConfigure.h"
17 
18 #include <algorithm>
19 #include <functional>
20 #include <ctype.h> // need to use c version of tolower defined here
21 
22 #include <map>
23 
24 namespace ROOT {
25 
26 namespace Math {
27 
28  // eventually could take values from /etc/system.rootrc
29 
30 namespace 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
42  static unsigned int gDefaultNPoints = gDefaultNPointsGSLAdaptive;
43 
44 
45 }
46 
47 namespace 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 
63 namespace IntegOptionsUtil {
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 0; }
72  };
73  template<>
74  struct OptionTrait<IntegratorOneDimOptions> {
75  typedef IntegratorOneDimOptions OptType;
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<>
81  struct OptionTrait<IntegratorMultiDimOptions> {
82  typedef IntegratorMultiDimOptions OptType;
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;
97  typedef OptionTrait<OptionType> OPT;
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 != 0) ? 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;
115  typedef OptionTrait<OptionType> OPT;
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
126  fIntegType(-1),
127  fWKSize(0), fNCalls(0),
128  fAbsTolerance(0), fRelTolerance(0),
129  fExtraOptions(0)
130 {}
131 
132 BaseIntegratorOptions::BaseIntegratorOptions(const BaseIntegratorOptions & opt) : fExtraOptions(0) {
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;
144  fIntegType = opt.fIntegType;
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 = 0;
165 }
166 
167 void BaseIntegratorOptions::SetExtraOptions(const IOptions & opt) {
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 
181 {
187 
188  fExtraOptions = opts; // N.B. ownership of pointer is given to the class !
189 
190  // check the default options if opts = 0
191  if (!fExtraOptions) {
192  std::string igname = DefaultIntegrator();
193  IOptions * gopts = FindDefault( igname.c_str() );
194  if (gopts) fExtraOptions = gopts->Clone();
195  }
196 }
197 
198 void IntegratorOneDimOptions::SetIntegrator(const char * algo ) {
199  // set the default 1D integrator
200  if (!algo) return;
202 }
203 
204 std::string IntegratorOneDimOptions::Integrator() const {
206 }
207 
208 void IntegratorOneDimOptions::Print(std::ostream & os) const {
209  //print all the options
210  IntegOptionsUtil::Print(os, *this);
211 }
212 
213 // one dim integrator options: implementation for static methods
214 
215 /// print default options
216 void IntegratorOneDimOptions::PrintDefault(const char * name, std::ostream & os) {
217  //print default options
218  IntegOptionsUtil::PrintDefault<IntegratorOneDimOptions>(name,os);
219 }
220 
221 
222 
223 void IntegratorOneDimOptions::SetDefaultIntegrator(const char * algo ) {
224  // set the default 1D integrator
225  if (!algo) return;
227  if (type == IntegrationOneDim::kDEFAULT) return; // this is possible only when invalid name was specified
233 }
234 
235 
237  // return default integrator name
239 }
240 
242  // return default integrator type (enum)
244 }
245 
246 
248  // set the default tolerance
250 }
252  // set the default tolerance
254 }
255 
256 void IntegratorOneDimOptions::SetDefaultWKSize(unsigned int size) {
257  // set the default workspace size
259 }
261  // set the default number of points for the integration rule
263 }
264 
265 
270 
271 
272 IOptions & IntegratorOneDimOptions::Default(const char * algo) {
273  // create default extra options for the given algorithm type
274  return GenAlgoOptions::Default(algo);
275 }
276 
278  // find extra options for the given algorithm type
280 }
281 
282 //////////////////////////////////////////////////////
283 //Multi-dim integration options implementation
284 /////////////////////////////////////////////////////////
285 
288 {
291  fAbsTolerance = IntegMultiDim::gDefaultAbsTolerance;
292  fRelTolerance = IntegMultiDim::gDefaultRelTolerance;
294 
295  fExtraOptions = opts; // N.B. ownership of pointer is given to the class !
296 
297  // check the default options if opts = 0
298  if (!fExtraOptions) {
299  IOptions * gopts = FindDefault( DefaultIntegrator().c_str() );
300  if (gopts) fExtraOptions = gopts->Clone();
301  }
302 }
303 
304 void IntegratorMultiDimOptions::SetIntegrator(const char * algo ) {
305  // set the default integrator
306  if (!algo) return;
308 }
309 
310 std::string IntegratorMultiDimOptions::Integrator() const {
312 }
313 
314 void IntegratorMultiDimOptions::Print(std::ostream & os) const {
315  //print all the options
316  IntegOptionsUtil::Print(os, *this);
317 }
318 
319 // multi dim integrator options: implementation for static methods
320 
321 /// print default options
322 void IntegratorMultiDimOptions::PrintDefault(const char * name, std::ostream & os) {
323  //print default options
324  IntegOptionsUtil::PrintDefault<IntegratorMultiDimOptions>(name,os);
325 }
326 
327 
328 void IntegratorMultiDimOptions::SetDefaultIntegrator(const char * algo ) {
329  // set the default integrator
330  if (!algo) return;
331  // check if type is correct
333  if (type == IntegrationMultiDim::kDEFAULT) return; // this is possible only when invalid name was specified
335 }
336 
337 
339  // return default integrator name
341 }
342 
344  // return default integrator type (enum)
346 }
347 
348 
350  // set the default tolerance
352 }
353 
355  // set the default tolerance
357 }
358 
360  // set the default workspace size
362 }
363 void IntegratorMultiDimOptions::SetDefaultNCalls(unsigned int ncall) {
364  // set the default (max) function calls
366 }
367 
368 
373 
374 
375 IOptions & IntegratorMultiDimOptions::Default(const char * algo) {
376  // create default extra options for the given algorithm type
377  return GenAlgoOptions::Default(algo);
378 }
379 
381  // create default extra options for the given algorithm type
383 }
384 
385 
386 } // end namespace Math
387 
388 } // end namespace ROOT
389 
ROOT::Math::IntegratorOneDimOptions::SetDefaultNPoints
static void SetDefaultNPoints(unsigned int n)
Definition: IntegratorOptions.cxx:270
n
const Int_t n
Definition: legend1.C:16
ROOT::Math::IntegOneDim::gDefaultRelTolerance
static double gDefaultRelTolerance
Definition: IntegratorOptions.cxx:53
ROOT::Math::IntegratorOneDimOptions::DefaultWKSize
static unsigned int DefaultWKSize()
Definition: IntegratorOptions.cxx:278
ROOT::Math::IntegOptionsUtil::Print
void Print(std::ostream &os, const OptionType &opt)
Definition: IntegratorOptions.cxx:101
ROOT::Math::IntegOptionsUtil::PrintDefault
void PrintDefault(const char *name, std::ostream &os)
print default options
Definition: IntegratorOptions.cxx:118
ROOT::Math::IntegratorMultiDimOptions::SetDefaultIntegrator
static void SetDefaultIntegrator(const char *name)
Definition: IntegratorOptions.cxx:338
Integrator.h
ROOT::Math::BaseIntegratorOptions::operator=
BaseIntegratorOptions & operator=(const BaseIntegratorOptions &opt)
assignment operators
Definition: IntegratorOptions.cxx:147
ROOT::Math::IntegratorMultiDimOptions::SetDefaultAbsTolerance
static void SetDefaultAbsTolerance(double tol)
Definition: IntegratorOptions.cxx:359
ROOT::Math::IntegMultiDim::gDefaultIntegrator
static int gDefaultIntegrator
Definition: IntegratorOptions.cxx:59
ROOT::Math::IntegratorOneDimOptions::SetDefaultAbsTolerance
static void SetDefaultAbsTolerance(double tol)
Definition: IntegratorOptions.cxx:257
ROOT::Math::BaseIntegratorOptions::BaseIntegratorOptions
BaseIntegratorOptions()
protected constructor to avoid user creating this class
Definition: IntegratorOptions.cxx:135
ROOT::Math::IntegratorMultiDimOptions::IntegratorMultiDimOptions
IntegratorMultiDimOptions(IOptions *extraOpts=0)
Definition: IntegratorOptions.cxx:296
ROOT::Math::IntegratorOneDimOptions::DefaultIntegrator
static std::string DefaultIntegrator()
Definition: IntegratorOptions.cxx:246
ROOT::Math::BaseIntegratorOptions::ClearExtra
void ClearExtra()
Definition: IntegratorOptions.cxx:171
ROOT::Math::BaseIntegratorOptions::fIntegType
int fIntegType
Definition: IntegratorOptions.h:103
ROOT::Math::IntegratorOneDimOptions::SetIntegrator
void SetIntegrator(const char *name)
set 1D integrator name
Definition: IntegratorOptions.cxx:208
N
#define N
ROOT::Math::IntegratorMultiDimOptions::PrintDefault
static void PrintDefault(const char *name=0, std::ostream &os=std::cout)
print only the specified default options
Definition: IntegratorOptions.cxx:332
ROOT::Math::IntegratorMultiDimOptions::Print
void Print(std::ostream &os=std::cout) const
print all the options
Definition: IntegratorOptions.cxx:324
ROOT::Math::IntegrationMultiDim::kDEFAULT
@ kDEFAULT
Definition: AllIntegrationTypes.h:75
ROOT::Math::IntegratorOneDimOptions::DefaultIntegratorType
static IntegrationOneDim::Type DefaultIntegratorType()
Definition: IntegratorOptions.cxx:251
ROOT::Math::IntegratorMultiDimOptions::DefaultWKSize
static unsigned int DefaultWKSize()
Definition: IntegratorOptions.cxx:381
ROOT::Math::IntegMultiDim::gDefaultRelTolerance
static double gDefaultRelTolerance
Definition: IntegratorOptions.cxx:63
ROOT::Math::IntegOneDim::gDefaultNPoints
static unsigned int gDefaultNPoints
Definition: IntegratorOptions.cxx:57
ROOT::Math::IntegrationOneDim::Type
Type
enumeration specifying the integration types.
Definition: AllIntegrationTypes.h:60
ROOT::Math::IntegratorOneDim::GetName
static std::string GetName(IntegrationOneDim::Type)
static function to get a string from the enumeration
Definition: Integrator.cxx:76
ROOT::Math::IntegrationOneDim::kADAPTIVESINGULAR
@ kADAPTIVESINGULAR
Definition: AllIntegrationTypes.h:65
ROOT::Math::IntegratorOneDim::Type
IntegrationOneDim::Type Type
Definition: Integrator.h:99
ROOT::Math::IntegrationMultiDim::kADAPTIVE
@ kADAPTIVE
Definition: AllIntegrationTypes.h:75
ROOT::Math::IntegratorOneDimOptions::SetDefaultRelTolerance
static void SetDefaultRelTolerance(double tol)
Definition: IntegratorOptions.cxx:261
ROOT::Math::IntegOneDim::gDefaultNPointsLegendre
static unsigned int gDefaultNPointsLegendre
Definition: IntegratorOptions.cxx:55
ROOT::Math::IntegrationOneDim::kDEFAULT
@ kDEFAULT
Definition: AllIntegrationTypes.h:65
ROOT::Math::IntegratorMultiDimOptions::SetDefaultNCalls
static void SetDefaultNCalls(unsigned int ncall)
Definition: IntegratorOptions.cxx:373
ROOT::Math::IntegratorMultiDim::GetName
static std::string GetName(IntegrationMultiDim::Type)
static function to get a string from the enumeration
Definition: Integrator.cxx:100
ROOT::Math::IntegratorOneDimOptions::PrintDefault
static void PrintDefault(const char *name=0, std::ostream &os=std::cout)
print only the specified default options
Definition: IntegratorOptions.cxx:226
ROOT::Math::IntegratorMultiDimOptions
Numerical multi dimensional integration options.
Definition: IntegratorOptions.h:204
ROOT::Math::IntegMultiDim::gDefaultWKSize
static unsigned int gDefaultWKSize
Definition: IntegratorOptions.cxx:64
ROOT::Math::IntegratorMultiDim::Type
IntegrationMultiDim::Type Type
Definition: IntegratorMultiDim.h:70
ROOT::Math::GenAlgoOptions::FindDefault
static IOptions * FindDefault(const char *algoname)
Definition: GenAlgoOptions.cxx:58
ROOT::Math::IntegratorOneDimOptions::SetDefaultIntegrator
static void SetDefaultIntegrator(const char *name)
Definition: IntegratorOptions.cxx:233
ROOT::Math::IntegratorMultiDimOptions::Default
static ROOT::Math::IOptions & Default(const char *name)
Definition: IntegratorOptions.cxx:385
ROOT::Math::IntegratorMultiDimOptions::SetDefaultRelTolerance
static void SetDefaultRelTolerance(double tol)
Definition: IntegratorOptions.cxx:364
ROOT::Math::IntegratorOneDimOptions::DefaultNPoints
static unsigned int DefaultNPoints()
Definition: IntegratorOptions.cxx:279
ROOT::Math::IntegOneDim::gDefaultNPointsGSLAdaptive
static unsigned int gDefaultNPointsGSLAdaptive
Definition: IntegratorOptions.cxx:56
ROOT::Math::IntegMultiDim::gDefaultAbsTolerance
static double gDefaultAbsTolerance
Definition: IntegratorOptions.cxx:62
ROOT::Math::IntegrationMultiDim::Type
Type
enumeration specifying the integration types.
Definition: AllIntegrationTypes.h:75
OPT
#define OPT
Definition: Match.cxx:38
ROOT::Math::BaseIntegratorOptions::fNCalls
unsigned int fNCalls
Definition: IntegratorOptions.h:106
ROOT::Math::IntegratorMultiDimOptions::FindDefault
static ROOT::Math::IOptions * FindDefault(const char *name)
Definition: IntegratorOptions.cxx:390
ROOT::Math::IntegratorMultiDimOptions::Integrator
std::string Integrator() const
name of multi-dim integrator
Definition: IntegratorOptions.cxx:320
ROOT::Math::IntegratorOneDimOptions::Default
static ROOT::Math::IOptions & Default(const char *name)
retrieve specific options - if not existing create a IOptions
Definition: IntegratorOptions.cxx:282
ROOT::Math::IOptions
Generic interface for defining configuration options of a numerical algorithm.
Definition: IOptions.h:41
ROOT::Math::IntegratorMultiDimOptions::SetIntegrator
void SetIntegrator(const char *name)
set multi-dim integrator name
Definition: IntegratorOptions.cxx:314
ROOT::Math::IntegratorOneDimOptions
Numerical one dimensional integration options.
Definition: IntegratorOptions.h:123
ROOT::Math::IntegOneDim::gDefaultIntegrator
static int gDefaultIntegrator
Definition: IntegratorOptions.cxx:50
ROOT::Math::BaseIntegratorOptions::fExtraOptions
ROOT::Math::IOptions * fExtraOptions
Definition: IntegratorOptions.h:112
ROOT::Math::BaseIntegratorOptions::SetExtraOptions
void SetExtraOptions(const IOptions &opt)
set extra options (in this case pointer is cloned)
Definition: IntegratorOptions.cxx:177
ROOT::Math::IOptions::Clone
virtual IOptions * Clone() const =0
ROOT::Math::IntegratorMultiDim::GetType
static IntegrationMultiDim::Type GetType(const char *name)
static function to get the enumeration from a string
Definition: Integrator.cxx:88
ROOT::Math::IntegratorMultiDimOptions::DefaultIntegratorType
static IntegrationMultiDim::Type DefaultIntegratorType()
Definition: IntegratorOptions.cxx:353
ROOT::Math::IntegratorOneDimOptions::Print
void Print(std::ostream &os=std::cout) const
print all the options
Definition: IntegratorOptions.cxx:218
ROOT::Math::IntegratorOneDimOptions::DefaultRelTolerance
static double DefaultRelTolerance()
Definition: IntegratorOptions.cxx:277
IntegratorOptions.h
ROOT::Math::IntegratorOneDimOptions::IntegratorOneDimOptions
IntegratorOneDimOptions(IOptions *extraOpts=0)
Definition: IntegratorOptions.cxx:189
ROOT::Math::IntegratorMultiDimOptions::DefaultIntegrator
static std::string DefaultIntegrator()
Definition: IntegratorOptions.cxx:348
ROOT::Math::IntegratorMultiDimOptions::DefaultRelTolerance
static double DefaultRelTolerance()
Definition: IntegratorOptions.cxx:380
ROOT::Math::IntegrationOneDim::kGAUSS
@ kGAUSS
Definition: AllIntegrationTypes.h:65
ROOT::Math::BaseIntegratorOptions::fWKSize
unsigned int fWKSize
Definition: IntegratorOptions.h:105
ROOT::Math::GenAlgoOptions::Default
static IOptions & Default(const char *algoname)
Definition: GenAlgoOptions.cxx:65
ROOT::Math::IntegrationOneDim::kLEGENDRE
@ kLEGENDRE
Definition: AllIntegrationTypes.h:65
ROOT::Math::IntegrationOneDim::kADAPTIVE
@ kADAPTIVE
Definition: AllIntegrationTypes.h:65
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Math::BaseIntegratorOptions::fRelTolerance
double fRelTolerance
Definition: IntegratorOptions.h:108
ROOT::Math::BaseIntegratorOptions
Base class for Numerical integration options common in 1D and multi-dimension This is an internal cla...
Definition: IntegratorOptions.h:45
ROOT::Math::IntegratorMultiDimOptions::DefaultNCalls
static unsigned int DefaultNCalls()
Definition: IntegratorOptions.cxx:382
ROOT::Math::IntegratorOneDimOptions::DefaultAbsTolerance
static double DefaultAbsTolerance()
Definition: IntegratorOptions.cxx:276
GenAlgoOptions.h
ROOT::Math::IntegratorMultiDimOptions::DefaultAbsTolerance
static double DefaultAbsTolerance()
Definition: IntegratorOptions.cxx:379
IntegratorMultiDim.h
ROOT::Math::IntegOneDim::gDefaultWKSize
static unsigned int gDefaultWKSize
Definition: IntegratorOptions.cxx:54
type
int type
Definition: TGX11.cxx:121
ROOT::Math::IntegratorOneDimOptions::FindDefault
static ROOT::Math::IOptions * FindDefault(const char *name)
Definition: IntegratorOptions.cxx:287
ROOT::Math::IntegratorOneDimOptions::SetDefaultWKSize
static void SetDefaultWKSize(unsigned int size)
Definition: IntegratorOptions.cxx:266
ROOT::Math::IntegratorOneDimOptions::Integrator
std::string Integrator() const
name of 1D integrator
Definition: IntegratorOptions.cxx:214
ROOT::Math::IntegMultiDim::gDefaultNCalls
static unsigned int gDefaultNCalls
Definition: IntegratorOptions.cxx:65
ROOT::Math::IntegratorOneDim::GetType
static IntegrationOneDim::Type GetType(const char *name)
static function to get the enumeration from a string
Definition: Integrator.cxx:63
ROOT::Math::IntegratorMultiDimOptions::SetDefaultWKSize
static void SetDefaultWKSize(unsigned int size)
Definition: IntegratorOptions.cxx:369
ROOT
VSD Structures.
Definition: StringConv.hxx:21
Math
ROOT::Math::BaseIntegratorOptions::fAbsTolerance
double fAbsTolerance
Definition: IntegratorOptions.h:107
ROOT::Math::IntegOneDim::gDefaultAbsTolerance
static double gDefaultAbsTolerance
Definition: IntegratorOptions.cxx:52
int