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 ROOT::Math::IOptions * Options() const = 0;
73
74 private:
75
76
77 };
78
79 /**
80 workspace for VEGAS
81 */
83
84 public :
85
87 fWs(0)
88 {
89 if (dim > 0) Init(dim);
90 }
91
92 bool Init(size_t dim) override {
93 fWs = gsl_monte_vegas_alloc( dim);
95 return (fWs != 0);
96 }
97
98 bool ReInit() override {
99 // according to the code - reinit just reset default GSL values
100 if (!fWs) return false;
101 int iret = gsl_monte_vegas_init( fWs );
103 return (iret == 0);
104 }
105
106 void Clear() override {
107 if (fWs) gsl_monte_vegas_free( fWs);
108 fWs = 0;
109 }
110
111 gsl_monte_vegas_state * GetWS() { return fWs; }
112
113 void SetParameters(const struct VegasParameters &p) {
114 fParams = p;
115 if (fWs) SetVegasParameters();
116 }
117
118 size_t NDim() const override { return (fWs) ? fWs->dim : 0; }
119
120 double Result() const { return (fWs) ? fWs->result : -1;}
121
122 double Sigma() const { return (fWs) ? fWs->sigma : 0;}
123
124 double Chisq() const { return (fWs) ? fWs->chisq: -1;}
125
126 MCIntegration::Type Type() const override { return MCIntegration::kVEGAS; }
127
128 const VegasParameters & Parameters() const { return fParams; }
130
131 ROOT::Math::IOptions * Options() const override {
132 return fParams();
133 }
134
135
136 private:
137
139 fWs->alpha = fParams.alpha;
140 fWs->iterations = fParams.iterations;
141 fWs->stage = fParams.stage;
142 fWs->mode = fParams.mode;
143 fWs->verbose = fParams.verbose;
144 }
145
146
147 gsl_monte_vegas_state * fWs;
149
150 };
151
152
153 /**
154 Workspace for MISER
155 */
157
158 public :
159
161 fHaveNewParams(false),
162 fWs(0)
163 {
164 if (dim > 0) Init(dim);
165 }
166
167
168 bool Init(size_t dim) override {
169 fWs = gsl_monte_miser_alloc( dim);
170 // need this to set parameters according to dimension
172 if (fWs) SetMiserParameters();
173 return (fWs != 0);
174 }
175
176 bool ReInit() override {
177 // according to the code - reinit just reset default GSL values
178 if (!fWs) return false;
179 int iret = gsl_monte_miser_init( fWs );
181 return (iret == 0);
182 }
183
184 void Clear() override {
185 if (fWs) gsl_monte_miser_free( fWs);
186 fWs = 0;
187 }
188
189 gsl_monte_miser_state * GetWS() { return fWs; }
190
192 fParams = p;
193 fHaveNewParams = true;
194 if (fWs) SetMiserParameters();
195 }
196
197 size_t NDim() const override { return (fWs) ? fWs->dim : 0; }
198
199 MCIntegration::Type Type() const override { return MCIntegration::kMISER; }
200
201
202 const MiserParameters & Parameters() const { return fParams; }
204
205 ROOT::Math::IOptions * Options() const override {
206 return fParams();
207 }
208
209 private:
210
212 {
213 fWs->estimate_frac = fParams.estimate_frac;
214 fWs->min_calls = fParams.min_calls;
215 fWs->min_calls_per_bisection = fParams.min_calls_per_bisection;
216 fWs->alpha = fParams.alpha;
217 fWs->dither = fParams.dither;
218 }
219
220
222 gsl_monte_miser_state * fWs;
224
225 };
226
227
228
229
231
232 public :
233
235 fWs(0)
236 { }
237
238 bool Init(size_t dim) override {
239 fWs = gsl_monte_plain_alloc( dim);
240 // no parameter exists for plain
241 return (fWs != 0);
242 }
243
244 bool ReInit() override {
245 if (!fWs) return false;
246 int iret = gsl_monte_plain_init( fWs );
247 return (iret == GSL_SUCCESS);
248 }
249
250 void Clear() override {
251 if (fWs) gsl_monte_plain_free( fWs);
252 fWs = 0;
253 }
254
255 gsl_monte_plain_state * GetWS() { return fWs; }
256
257 //void SetParameters(const struct PlainParameters &p);
258
259 MCIntegration::Type Type() const override { return MCIntegration::kPLAIN; }
260
261 size_t NDim() const override { return (fWs) ? fWs->dim : 0; }
262
263 ROOT::Math::IOptions * Options() const override {
264 return 0;
265 }
266
267
268 private:
269
270 gsl_monte_plain_state * fWs;
271
272
273 };
274
275
276} // namespace Math
277} // namespace ROOT
278
279
280
281
282#endif /* ROOT_Math_GSLMCIntegrationWorkspace */
winID h TVirtualViewer3D TVirtualGLPainter p
virtual void Clear()
free the workspace deleting the GSL pointer
virtual ROOT::Math::IOptions * Options() const =0
retrieve option pointer corresponding to parameters create a new object to be managed by the user
virtual MCIntegration::Type Type() const =0
virtual bool ReInit()=0
re-initialize an existing the workspace
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
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
MCIntegration::Type Type() const override
ROOT::Math::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
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
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
ROOT::Math::IOptions * Options() const override
retrieve option pointer corresponding to parameters create a new object to be managed by the user
void SetParameters(const struct VegasParameters &p)
Generic interface for defining configuration options of a numerical algorithm.
Definition IOptions.h:31
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.
structures collecting parameters for MISER multidimensional integration
structures collecting parameters for VEGAS multidimensional integration FOr implementation of default...