Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
GSLMCIntegrationWorkspace.h
Go to the documentation of this file.
1// @(#)root/mathmore:$Id$
2// Author: Magdalena Slawinska 08/2007
3
4 /**********************************************************************
5 * *
6 * Copyright (c) 2007 ROOT Foundation, CERN/PH-SFT *
7 * *
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU General Public License *
10 * as published by the Free Software Foundation; either version 2 *
11 * of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this library (see file COPYING); if not, write *
20 * to the Free Software Foundation, Inc., 59 Temple Place, Suite *
21 * 330, Boston, MA 02111-1307 USA, or contact the author. *
22 * *
23 **********************************************************************/
24
25// Header file for class GSLIntegratorWorkspace
26//
27// Author: Magdalena Slawinska
28//
29
30
31
32#ifndef ROOT_Math_GSLMCIntegrationWorkspace
33#define ROOT_Math_GSLMCIntegrationWorkspace
34
35#include "gsl/gsl_math.h"
36#include "gsl/gsl_monte.h"
37#include "gsl/gsl_monte_vegas.h"
38#include "gsl/gsl_monte_miser.h"
39#include "gsl/gsl_monte_plain.h"
40
41#include "Math/MCParameters.h"
43
44namespace ROOT {
45namespace Math {
46
47
48
50
51 public :
52
54
56
57 virtual MCIntegration::Type Type() const = 0;
58
59 virtual size_t NDim() const { return 0; }
60
61 /// initialize the workspace creating the GSL pointer if it is not there
62 virtual bool Init(size_t dim) = 0;
63
64 /// re-initialize an existing the workspace
65 virtual bool ReInit() = 0;
66
67 /// free the workspace deleting the GSL pointer
68 virtual void Clear() {}
69
70 /// retrieve option pointer corresponding to parameters
71 /// create a new object to be managed by the user
72 virtual std::unique_ptr<ROOT::Math::IOptions> Options() const = 0;
73
74 /// set options
75 virtual void SetOptions(const ROOT::Math::IOptions &) = 0;
76
77 private:
78
79
80 };
81
82 /**
83 workspace for VEGAS
84 */
86
87 public :
88
90 fWs(nullptr)
91 {
92 if (dim > 0) Init(dim);
93 }
94
95 bool Init(size_t dim) override {
96 fWs = gsl_monte_vegas_alloc( dim);
98 return (fWs != nullptr);
99 }
100
101 bool ReInit() override {
102 // according to the code - reinit just reset default GSL values
103 if (!fWs) return false;
104 int iret = gsl_monte_vegas_init( fWs );
106 return (iret == 0);
107 }
108
109 void Clear() override {
110 if (fWs) gsl_monte_vegas_free( fWs);
111 fWs = nullptr;
112 }
113
114 gsl_monte_vegas_state * GetWS() { return fWs; }
115
116 void SetParameters(const struct VegasParameters &p) {
117 fParams = p;
118 if (fWs) SetVegasParameters();
119 }
120
121 size_t NDim() const override { return (fWs) ? fWs->dim : 0; }
122
123 double Result() const { return (fWs) ? fWs->result : -1;}
124
125 double Sigma() const { return (fWs) ? fWs->sigma : 0;}
126
127 double Chisq() const { return (fWs) ? fWs->chisq: -1;}
128
129 MCIntegration::Type Type() const override { return MCIntegration::kVEGAS; }
130
131 const VegasParameters & Parameters() const { return fParams; }
133
134 std::unique_ptr<IOptions> Options() const override {
135 return fParams.MakeIOptions();
136 }
137 /// set options
138 virtual void SetOptions(const ROOT::Math::IOptions & opt) override {
140 }
141
142 private:
143
145 fWs->alpha = fParams.alpha;
146 fWs->iterations = fParams.iterations;
147 fWs->stage = fParams.stage;
148 fWs->mode = fParams.mode;
149 fWs->verbose = fParams.verbose;
150 }
151
152
153 gsl_monte_vegas_state * fWs;
155
156 };
157
158
159 /**
160 Workspace for MISER
161 */
163
164 public :
165
167 fHaveNewParams(false),
168 fWs(nullptr)
169 {
170 if (dim > 0) Init(dim);
171 }
172
173
174 bool Init(size_t dim) override {
175 fWs = gsl_monte_miser_alloc( dim);
176 // need this to set parameters according to dimension
178 if (fWs) SetMiserParameters();
179 return (fWs != nullptr);
180 }
181
182 bool ReInit() override {
183 // according to the code - reinit just reset default GSL values
184 if (!fWs) return false;
185 int iret = gsl_monte_miser_init( fWs );
187 return (iret == 0);
188 }
189
190 void Clear() override {
191 if (fWs) gsl_monte_miser_free( fWs);
192 fWs = nullptr;
193 }
194
195 gsl_monte_miser_state * GetWS() { return fWs; }
196
198 fParams = p;
199 fHaveNewParams = true;
200 if (fWs) SetMiserParameters();
201 }
202
203 size_t NDim() const override { return (fWs) ? fWs->dim : 0; }
204
205 MCIntegration::Type Type() const override { return MCIntegration::kMISER; }
206
207
208 const MiserParameters & Parameters() const { return fParams; }
210
211 std::unique_ptr<ROOT::Math::IOptions> Options() const override {
212 return fParams.MakeIOptions();
213 }
214 virtual void SetOptions(const ROOT::Math::IOptions & opt) override {
216 }
217
218 private:
219
221 {
222 fWs->estimate_frac = fParams.estimate_frac;
223 fWs->min_calls = fParams.min_calls;
224 fWs->min_calls_per_bisection = fParams.min_calls_per_bisection;
225 fWs->alpha = fParams.alpha;
226 fWs->dither = fParams.dither;
227 }
228
229
231 gsl_monte_miser_state * fWs;
233
234 };
235
236
237
238
240
241 public :
242
244 fWs(nullptr)
245 { }
246
247 bool Init(size_t dim) override {
248 fWs = gsl_monte_plain_alloc( dim);
249 // no parameter exists for plain
250 return (fWs != nullptr);
251 }
252
253 bool ReInit() override {
254 if (!fWs) return false;
255 int iret = gsl_monte_plain_init( fWs );
256 return (iret == GSL_SUCCESS);
257 }
258
259 void Clear() override {
260 if (fWs) gsl_monte_plain_free( fWs);
261 fWs = nullptr;
262 }
263
264 gsl_monte_plain_state * GetWS() { return fWs; }
265
266 //void SetParameters(const struct PlainParameters &p);
267
268 MCIntegration::Type Type() const override { return MCIntegration::kPLAIN; }
269
270 size_t NDim() const override { return (fWs) ? fWs->dim : 0; }
271
272 std::unique_ptr<ROOT::Math::IOptions> Options() const override {
273 return std::unique_ptr<ROOT::Math::IOptions>();
274 }
275
276 virtual void SetOptions(const ROOT::Math::IOptions &) override {}
277
278
279 private:
280
281 gsl_monte_plain_state * fWs;
282
283
284 };
285
286
287} // namespace Math
288} // namespace ROOT
289
290
291
292
293#endif /* ROOT_Math_GSLMCIntegrationWorkspace */
winID h TVirtualViewer3D TVirtualGLPainter p
virtual void Clear()
free the workspace deleting the GSL pointer
virtual void SetOptions(const ROOT::Math::IOptions &)=0
set options
virtual MCIntegration::Type Type() const =0
virtual bool ReInit()=0
re-initialize an existing the workspace
virtual std::unique_ptr< ROOT::Math::IOptions > Options() const =0
retrieve option pointer corresponding to parameters create a new object to be managed by the user
virtual bool Init(size_t dim)=0
initialize the workspace creating the GSL pointer if it is not there
bool ReInit() override
re-initialize an existing the workspace
void Clear() override
free the workspace deleting the GSL pointer
std::unique_ptr< ROOT::Math::IOptions > Options() const override
retrieve option pointer corresponding to parameters create a new object to be managed by the user
bool Init(size_t dim) override
initialize the workspace creating the GSL pointer if it is not there
virtual void SetOptions(const ROOT::Math::IOptions &opt) override
set options
MCIntegration::Type Type() const override
void Clear() override
free the workspace deleting the GSL pointer
MCIntegration::Type Type() const override
bool ReInit() override
re-initialize an existing the workspace
bool Init(size_t dim) override
initialize the workspace creating the GSL pointer if it is not there
virtual void SetOptions(const ROOT::Math::IOptions &) override
set options
std::unique_ptr< ROOT::Math::IOptions > Options() const override
retrieve option pointer corresponding to parameters create a new object to be managed by the user
std::unique_ptr< IOptions > Options() const override
retrieve option pointer corresponding to parameters create a new object to be managed by the user
void Clear() override
free the workspace deleting the GSL pointer
bool ReInit() override
re-initialize an existing the workspace
bool Init(size_t dim) override
initialize the workspace creating the GSL pointer if it is not there
MCIntegration::Type Type() const override
virtual void SetOptions(const ROOT::Math::IOptions &opt) override
set options
void SetParameters(const struct VegasParameters &p)
Generic interface for defining configuration options of a numerical algorithm.
Definition IOptions.h:28
Type
enumeration specifying the integration types.
Namespace for new Math classes and functions.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
Structure collecting parameters for MISER multidimensional integration.
std::unique_ptr< ROOT::Math::IOptions > MakeIOptions() const
convert to options (return object is managed by the user)
Structures collecting parameters for VEGAS multidimensional integration For implementation of default...
std::unique_ptr< ROOT::Math::IOptions > MakeIOptions() const
Convert to options.