Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
IntegratorOptions.h
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 #ifndef ROOT_Math_IntegratorOptions
12 #define ROOT_Math_IntegratorOptions
13 
15 
16 #include <string>
17 #include <iostream>
18 
19 namespace ROOT {
20 
21 
22 namespace Math {
23 
24  class IOptions;
25 
26 
27 //_______________________________________________________________________________
28 /**
29  Base class for Numerical integration options
30  common in 1D and multi-dimension
31  This is an internal class and is not supposed to be instantiated by the user
32 
33  @ingroup Integration
34 */
35 class BaseIntegratorOptions {
36 
37 protected:
38 
39  /// protected constructor to avoid user creating this class
40  BaseIntegratorOptions();
41 
42 public:
43 
44  // copy constructor
45  BaseIntegratorOptions(const BaseIntegratorOptions & opt);
46 
47  /// assignment operators
48  BaseIntegratorOptions & operator=(const BaseIntegratorOptions & opt);
49 
50 
51  /// protected constructor to avoid user creating this class
52  virtual ~BaseIntegratorOptions() { ClearExtra(); }
53 
54 
55  /// name of 1D integrator
56  virtual std::string Integrator() const = 0;
57 
58  /** non-static methods for retrivieng options */
59 
60  /// absolute tolerance
61  double AbsTolerance() const { return fAbsTolerance; }
62 
63  /// absolute tolerance
64  double RelTolerance() const { return fRelTolerance; }
65 
66  /// size of the workspace
67  unsigned int WKSize() const { return fWKSize; }
68 
69 
70  /// return extra options
71  IOptions * ExtraOptions() const { return fExtraOptions; }
72 
73  /** non-static methods for setting options */
74 
75 
76  /// set the abs tolerance
77  void SetAbsTolerance(double tol) { fAbsTolerance = tol; }
78 
79  /// set the relative tolerance
80  void SetRelTolerance(double tol) { fRelTolerance = tol; }
81 
82  /// set workspace size
83  void SetWKSize(unsigned int size) { fWKSize = size; }
84 
85  /// set extra options (in this case pointer is cloned)
86  void SetExtraOptions(const IOptions & opt);
87 
88 
89 protected:
90 
91  void ClearExtra();
92 
93  int fIntegType; // Integrator type (value converted from enum)
94 
95  unsigned int fWKSize; // workspace size
96  unsigned int fNCalls; // (max) funxtion calls
97  double fAbsTolerance; // absolute tolerance
98  double fRelTolerance; // relative tolerance
99 
100 
101  // extra options
102  ROOT::Math::IOptions * fExtraOptions; // extra options
103 
104 };
105 
106 //_______________________________________________________________________________
107 /**
108  Numerical one dimensional integration options
109 
110  @ingroup Integration
111 */
112 
113 class IntegratorOneDimOptions : public BaseIntegratorOptions {
114 
115 public:
116 
117 
118  // constructor using the default options
119  // can pass a pointer to extra options (N.B. pointer will be managed by the class)
120  IntegratorOneDimOptions(IOptions * extraOpts = 0);
121 
122  virtual ~IntegratorOneDimOptions() {}
123 
124  // copy constructor
125  IntegratorOneDimOptions(const IntegratorOneDimOptions & rhs) :
126  BaseIntegratorOptions(rhs)
127  {}
128 
129  // assignment operator
130  IntegratorOneDimOptions & operator=(const IntegratorOneDimOptions & rhs) {
131  if (this == &rhs) return *this;
132  static_cast<BaseIntegratorOptions &>(*this) = rhs;
133  return *this;
134  }
135 
136  // specific method for one-dim
137  /// set number of points rule
138  /// values of 1,2,3,4,5,6 corresponds to 15,21,31,41,51,61 and they are used in GSL adaptive
139  /// values > 6 corresponds to the actual points and they are used by teh GaussLegendre integrator
140  void SetNPoints(unsigned int n) { fNCalls = n; }
141 
142  /// maximum number of function calls
143  unsigned int NPoints() const { return fNCalls; }
144 
145  /// name of 1D integrator
146  std::string Integrator() const;
147 
148  /// type of the integrator (return the enumeration type)
149  IntegrationOneDim::Type IntegratorType() const { return (IntegrationOneDim::Type) fIntegType; }
150 
151  /// set 1D integrator name
152  void SetIntegrator(const char * name);
153 
154  /// print all the options
155  void Print(std::ostream & os = std::cout) const;
156 
157  // static methods for setting and retrieving the default options
158 
159  static void SetDefaultIntegrator(const char * name);
160  static void SetDefaultAbsTolerance(double tol);
161  static void SetDefaultRelTolerance(double tol);
162  static void SetDefaultWKSize(unsigned int size);
163  static void SetDefaultNPoints(unsigned int n);
164 
165  static std::string DefaultIntegrator();
166  static IntegrationOneDim::Type DefaultIntegratorType();
167  static double DefaultAbsTolerance();
168  static double DefaultRelTolerance();
169  static unsigned int DefaultWKSize();
170  static unsigned int DefaultNPoints();
171 
172  /// retrieve specific options - if not existing create a IOptions
173  static ROOT::Math::IOptions & Default(const char * name);
174 
175  // find specific options - return 0 if not existing
176  static ROOT::Math::IOptions * FindDefault(const char * name);
177 
178  /// print only the specified default options
179  static void PrintDefault(const char * name = 0, std::ostream & os = std::cout);
180 
181 
182 private:
183 
184 
185 };
186 
187 //_______________________________________________________________________________
188 /**
189  Numerical multi dimensional integration options
190 
191  @ingroup Integration
192 */
193 
194 class IntegratorMultiDimOptions : public BaseIntegratorOptions {
195 
196 public:
197 
198 
199  // constructor using the default options
200  // can pass a pointer to extra options (N.B. pointer will be managed by the class)
201  IntegratorMultiDimOptions(IOptions * extraOpts = 0);
202 
203  virtual ~IntegratorMultiDimOptions() {}
204 
205  // copy constructor
206  IntegratorMultiDimOptions(const IntegratorMultiDimOptions & rhs) :
207  BaseIntegratorOptions(rhs)
208  {}
209 
210  // assignment operator
211  IntegratorMultiDimOptions & operator=(const IntegratorMultiDimOptions & rhs) {
212  if (this == &rhs) return *this;
213  static_cast<BaseIntegratorOptions &>(*this) = rhs;
214  return *this;
215  }
216 
217  // specific method for multi-dim
218  /// set maximum number of function calls
219  void SetNCalls(unsigned int calls) { fNCalls = calls; }
220 
221  /// maximum number of function calls
222  unsigned int NCalls() const { return fNCalls; }
223 
224  /// name of multi-dim integrator
225  std::string Integrator() const;
226 
227  /// type of the integrator (return the enumeration type)
228  IntegrationMultiDim::Type IntegratorType() const { return (IntegrationMultiDim::Type) fIntegType; }
229 
230  /// set multi-dim integrator name
231  void SetIntegrator(const char * name);
232 
233  /// print all the options
234  void Print(std::ostream & os = std::cout) const;
235 
236  // static methods for setting and retrieving the default options
237 
238  static void SetDefaultIntegrator(const char * name);
239  static void SetDefaultAbsTolerance(double tol);
240  static void SetDefaultRelTolerance(double tol);
241  static void SetDefaultWKSize(unsigned int size);
242  static void SetDefaultNCalls(unsigned int ncall);
243 
244  static std::string DefaultIntegrator();
245  static IntegrationMultiDim::Type DefaultIntegratorType();
246  static double DefaultAbsTolerance();
247  static double DefaultRelTolerance();
248  static unsigned int DefaultWKSize();
249  static unsigned int DefaultNCalls();
250 
251  // retrieve specific options
252  static ROOT::Math::IOptions & Default(const char * name);
253 
254  // find specific options - return 0 if not existing
255  static ROOT::Math::IOptions * FindDefault(const char * name);
256 
257  /// print only the specified default options
258  static void PrintDefault(const char * name = 0, std::ostream & os = std::cout);
259 
260 
261 private:
262 
263 
264 };
265 
266 
267  } // end namespace Math
268 
269 } // end namespace ROOT
270 
271 #endif