CLHEP VERSION Reference Documentation
CLHEP Home Page
CLHEP Documentation
CLHEP Bug Reports
Main Page
Namespaces
Classes
Files
File List
File Members
Matrix
CLHEP
Random
Matrix/CLHEP/Random/RandFlat.h
Go to the documentation of this file.
1
// $Id: RandFlat.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2
// -*- C++ -*-
3
//
4
// -----------------------------------------------------------------------
5
// HEP Random
6
// --- RandFlat ---
7
// class header file
8
// -----------------------------------------------------------------------
9
// This file is part of Geant4 (simulation toolkit for HEP).
10
11
// Class defining methods for shooting flat random numbers, double or
12
// integers.
13
// It provides methods to fill with double flat values arrays of
14
// specified size, as well as methods for shooting sequences of 0,1 (bits).
15
// Default boundaries ]0.1[ for operator()().
16
17
// =======================================================================
18
// Gabriele Cosmo - Created: 5th September 1995
19
// Peter Urban - ShootBit() and related stuff added: 5th Sep 1996
20
// Gabriele Cosmo - Added operator() and additional methods to fill
21
// arrays specifying boundaries: 24th Jul 1997
22
// J.Marraffino - Added default arguments as attributes and
23
// operator() with arguments: 16th Feb 1998
24
// M. Fischler - Moved copy constructor to protected so that
25
// derived RandBit can get at it.
26
// M Fischler - put and get to/from streams 12/10/04
27
// =======================================================================
28
29
#ifndef RandFlat_h
30
#define RandFlat_h 1
31
32
#include "CLHEP/Random/defs.h"
33
#include "CLHEP/Random/Random.h"
34
#include "CLHEP/Utility/memory.h"
35
36
namespace
CLHEP {
37
42
class
RandFlat
:
public
HepRandom
{
43
44
public
:
45
46
inline
RandFlat
(
HepRandomEngine
& anEngine );
47
inline
RandFlat
(
HepRandomEngine
& anEngine,
double
width );
48
inline
RandFlat
(
HepRandomEngine
& anEngine,
double
a
,
double
b
);
49
inline
RandFlat
(
HepRandomEngine
* anEngine );
50
inline
RandFlat
(
HepRandomEngine
* anEngine,
double
width );
51
inline
RandFlat
(
HepRandomEngine
* anEngine,
double
a,
double
b );
52
// These constructors should be used to instantiate a RandFlat
53
// distribution object defining a local engine for it.
54
// The static generator will be skipped using the non-static methods
55
// defined below.
56
// If the engine is passed by pointer the corresponding engine object
57
// will be deleted by the RandFlat destructor.
58
// If the engine is passed by reference the corresponding engine object
59
// will not be deleted by the RandFlat destructor.
60
61
virtual
~RandFlat
();
62
// Destructor
63
64
// Static methods to shoot random values using the static generator
65
66
static
double
shoot
();
67
68
static
inline
double
shoot
(
double
width );
69
70
static
inline
double
shoot
(
double
a,
double
b );
71
72
static
inline
long
shootInt
(
long
n
);
73
74
static
inline
long
shootInt
(
long
a1,
long
n );
75
76
static
inline
int
shootBit
();
77
78
static
void
shootArray
(
const
int
size,
double
* vect );
79
80
static
void
shootArray
(
const
int
size,
double
* vect,
81
double
lx,
double
dx );
82
83
// Static methods to shoot random values using a given engine
84
// by-passing the static generator.
85
86
static
inline
double
shoot
(
HepRandomEngine
* anEngine );
87
88
static
inline
double
shoot
(
HepRandomEngine
* anEngine,
double
width );
89
90
static
inline
double
shoot
(
HepRandomEngine
* anEngine,
91
double
a,
double
b );
92
static
inline
long
shootInt
(
HepRandomEngine
* anEngine,
long
n );
93
94
static
inline
long
shootInt
(
HepRandomEngine
* anEngine,
long
a1,
long
n );
95
96
static
inline
int
shootBit
(
HepRandomEngine
* );
97
98
static
inline
void
shootArray
(
HepRandomEngine
* anEngine,
99
const
int
size,
double
* vect );
100
101
static
void
shootArray
(
HepRandomEngine
* anEngine,
102
const
int
size,
double
* vect,
103
double
lx,
double
dx );
104
105
// Methods using the localEngine to shoot random values, by-passing
106
// the static generator.
107
108
inline
double
fire
();
109
110
inline
double
fire
(
double
width );
111
112
inline
double
fire
(
double
a,
double
b );
113
114
inline
long
fireInt
(
long
n );
115
116
inline
long
fireInt
(
long
a1,
long
n );
117
118
inline
int
fireBit
();
119
120
void
fireArray
(
const
int
size,
double
* vect);
121
122
void
fireArray
(
const
int
size,
double
* vect,
123
double
lx,
double
dx);
124
125
double
operator()
();
126
double
operator()
(
double
width );
127
double
operator()
(
double
a,
double
b );
128
129
// Save and restore to/from streams
130
131
std::ostream &
put
( std::ostream & os )
const
;
132
std::istream &
get
( std::istream & is );
133
134
std::string
name
()
const
;
135
HepRandomEngine
&
engine
();
136
137
static
std::string
distributionName
() {
return
"RandFlat"
;}
138
// Provides the name of this distribution class
139
140
// Methods overriding the base class static saveEngineStatus ones,
141
// by adding extra data so that save in one program, then further shootBit()s
142
// will produce the identical sequence to restore in another program, then
143
// generating shootBit() randoms there
144
145
static
void
saveEngineStatus
(
const
char
filename[] =
"Config.conf"
);
146
// Saves to file the current status of the current engine.
147
148
static
void
restoreEngineStatus
(
const
char
filename[] =
"Config.conf"
);
149
// Restores a saved status (if any) for the current engine.
150
151
static
std::ostream&
saveFullState
( std::ostream & os );
152
// Saves to stream the state of the engine and cached data.
153
154
static
std::istream&
restoreFullState
( std::istream & is );
155
// Restores from stream the state of the engine and cached data.
156
157
static
std::ostream&
saveDistState
( std::ostream & os );
158
// Saves to stream the state of the cached data.
159
160
static
std::istream&
restoreDistState
( std::istream & is );
161
// Restores from stream the state of the cached data.
162
163
164
protected
:
165
166
#if 0
167
// Protected copy constructor. Defining it here disallows use by users.
168
RandFlat
(
const
RandFlat
& d);
169
#endif // 0
170
171
private
:
172
173
// ShootBits generates an integer random number,
174
// which is used by fireBit().
175
// The number is stored in randomInt and firstUnusedBit
176
177
inline
void
fireBits();
178
static
inline
void
shootBits();
179
static
inline
void
shootBits(
HepRandomEngine
*);
180
181
// In MSB, the most significant bit of the integer random number
182
// generated by ShootBits() is set.
183
// Note:
184
// the number of significant bits must be chosen so that
185
// - an unsigned long can hold it
186
// - and it should be less than the number of bits returned
187
// by Shoot() which are not affected by precision problems
188
// on _each_ architecture.
189
// (Aim: the random generators should be machine-independent).
190
191
static
const
unsigned
long
MSB;
192
static
const
int
MSBBits;
193
// These two are set up in RandFlat.cc and need not be saved/restored
194
195
unsigned
long
randomInt;
196
unsigned
long
firstUnusedBit;
197
static
unsigned
long
staticRandomInt;
198
static
unsigned
long
staticFirstUnusedBit;
199
200
shared_ptr<HepRandomEngine>
localEngine;
201
double
defaultWidth;
202
double
defaultA;
203
double
defaultB;
204
205
};
206
207
}
// namespace CLHEP
208
209
#ifdef ENABLE_BACKWARDS_COMPATIBILITY
210
// backwards compatibility will be enabled ONLY in CLHEP 1.9
211
using namespace
CLHEP;
212
#endif
213
214
#include "CLHEP/Random/RandFlat.icc"
215
216
#endif
Generated on Mon May 6 2013 04:04:11 for CLHEP by
1.8.1.2