Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
QuasiRandom.h
Go to the documentation of this file.
1 // @(#)root/mathmore:$Id$
2 // Author: L. Moneta, A. Zsenei 08/2005
3 
4  /**********************************************************************
5  * *
6  * Copyright (c) 2004 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 GSLRandom
26 //
27 // Created by: moneta at Sun Nov 21 16:26:03 2004
28 //
29 // Last update: Sun Nov 21 16:26:03 2004
30 //
31 #ifndef ROOT_Math_QuasiRandom
32 #define ROOT_Math_QuasiRandom
33 
34 #include <string>
35 
36 /**
37  @defgroup QuasiRandom QuasiRandom number generators and distributions
38  Classes for generating QuasiRandom numbers and based on GSL
39  @ingroup Random
40  @ingroup MathMore
41 */
42 
43 
44 
45 namespace ROOT {
46 namespace Math {
47 
48 
49 //_____________________________________________________________________________________
50 /**
51  User class for MathMore random numbers template on the Engine type.
52  The API of this class followed that of the class ROOT::Math::Random
53  It must be implemented using as Engine one of the derived classes of
54  ROOT::Math::GSLQuasiRandomEngine, like ROOT::Math::GSLQrngSobol
55 
56  @ingroup QuasiRandom
57 
58 */
59 template < class Engine>
60 class QuasiRandom {
61 
62 public:
63 
64 
65  /**
66  Create a QuasiRandom generator. Use default engine constructor.
67  Engine will be initialized via Initialize() function in order to
68  allocate resources
69  */
70  QuasiRandom(unsigned int dimension = 1) {
71  fEngine.Initialize(dimension);
72  }
73 
74 
75  /**
76  Create a QuasiRandom generator based on a provided generic engine.
77  Engine will be initialized via Initialize() function in order to
78  allocate resources
79  */
80  explicit QuasiRandom(const Engine & e, unsigned int dimension = 1) : fEngine(e) {
81  fEngine.Initialize(dimension);
82  }
83 
84  /**
85  Destructor: call Terminate() function of engine to free any
86  allocated resource
87  */
88  ~QuasiRandom() {
89  fEngine.Terminate();
90  }
91 
92  /**
93  Generate next quasi random numbers points
94  */
95  bool Next(double * x) {
96  return fEngine(x);
97  }
98 
99  /**
100  Generate next quasi random numbers point (1 - dimension)
101  */
102  double Next() {
103  return fEngine();
104  }
105 
106  /**
107  Generate quasi random numbers between ]0,1[
108  0 and 1 are excluded
109  Function to be compatible with ROOT TRandom compatibility
110  */
111  double Rndm() {
112  return fEngine();
113  }
114 
115  /**
116  skip the next n number and jumb directly to the current state + n
117  */
118  bool Skip(unsigned int n) {
119  return fEngine.Skip(n);
120  }
121  /**
122  Generate an array of random numbers between ]0,1[
123  Function to preserve ROOT Trandom compatibility
124  The array will be filled as x1,y1,z1,....x2,y2,z2,...
125  */
126  bool RndmArray(int n, double * array) {
127  return fEngine.GenerateArray(array, array+n*NDim());
128  }
129 
130  /**
131  Return the type (name) of the used generator
132  */
133  std::string Type() const {
134  return fEngine.Name();
135  }
136 
137  /**
138  Return the size of the generator state
139  */
140  unsigned int EngineSize() const {
141  return fEngine.Size();
142  }
143 
144  /**
145  Return the dimension of the generator
146  */
147  unsigned int NDim() const {
148  return fEngine.NDim();
149  }
150 
151  /**
152  Return the name of the generator
153  */
154  std::string Name() const {
155  return fEngine.Name();
156  }
157 
158 private:
159 
160  Engine fEngine;
161 
162 };
163 
164 
165 
166 } // namespace Math
167 } // namespace ROOT
168 
169 #include "Math/GSLQuasiRandom.h"
170 
171 
172 
173 
174 namespace ROOT {
175 namespace Math {
176 
177 
178 typedef QuasiRandom<ROOT::Math::GSLQRngSobol> QuasiRandomSobol;
179 typedef QuasiRandom<ROOT::Math::GSLQRngNiederreiter2> QuasiRandomNiederreiter;
180 
181 } // namespace Math
182 } // namespace ROOT
183 
184 
185 #endif /* ROOT_Math_QuasiRandom */
186 
187 
188