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/RandGauss.h
Go to the documentation of this file.
1
// $Id: RandGauss.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2
// -*- C++ -*-
3
//
4
// -----------------------------------------------------------------------
5
// HEP Random
6
// --- RandGauss ---
7
// class header file
8
// -----------------------------------------------------------------------
9
// This file is part of Geant4 (simulation toolkit for HEP).
10
11
// Class defining methods for shooting gaussian distributed random values,
12
// given a mean (default=0) or specifying also a deviation (default=1).
13
// Gaussian random numbers are generated two at the time, so every
14
// other time shoot is called the number returned is the one generated the
15
// time before.
16
// Default values are used for operator()().
17
18
// =======================================================================
19
// Gabriele Cosmo - Created: 5th September 1995
20
// - Minor corrections: 31st October 1996
21
// - Added methods to shoot arrays: 28th July 1997
22
// J.Marraffino - Added default arguments as attributes and
23
// operator() with arguments. Introduced method normal()
24
// for computation in fire(): 16th Feb 1998
25
// Gabriele Cosmo - Relocated static data from HepRandom: 5th Jan 1999
26
// M Fischler - put and get to/from streams 12/8/04
27
// =======================================================================
28
29
#ifndef RandGauss_h
30
#define RandGauss_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
RandGauss
:
public
HepRandom
{
43
44
public
:
45
46
inline
RandGauss
(
HepRandomEngine
& anEngine,
double
mean=0.0,
47
double
stdDev=1.0 );
48
inline
RandGauss
(
HepRandomEngine
* anEngine,
double
mean=0.0,
49
double
stdDev=1.0 );
50
// These constructors should be used to instantiate a RandGauss
51
// distribution object defining a local engine for it.
52
// The static generator will be skipped using the non-static methods
53
// defined below.
54
// If the engine is passed by pointer the corresponding engine object
55
// will be deleted by the RandGauss destructor.
56
// If the engine is passed by reference the corresponding engine object
57
// will not be deleted by the RandGauss destructor.
58
59
virtual
~RandGauss
();
60
// Destructor
61
62
// Static methods to shoot random values using the static generator
63
64
static
double
shoot
();
65
66
static
inline
double
shoot
(
double
mean,
double
stdDev );
67
68
static
void
shootArray
(
const
int
size,
double
* vect,
69
double
mean=0.0,
double
stdDev=1.0 );
70
71
// Static methods to shoot random values using a given engine
72
// by-passing the static generator.
73
74
static
double
shoot
(
HepRandomEngine
* anEngine );
75
76
static
inline
double
shoot
(
HepRandomEngine
* anEngine,
77
double
mean,
double
stdDev );
78
79
static
void
shootArray
(
HepRandomEngine
* anEngine,
const
int
size,
80
double
* vect,
double
mean=0.0,
81
double
stdDev=1.0 );
82
83
// Methods using the localEngine to shoot random values, by-passing
84
// the static generator.
85
86
double
fire
();
87
88
inline
double
fire
(
double
mean,
double
stdDev );
89
90
void
fireArray
(
const
int
size,
double
* vect);
91
void
fireArray
(
const
int
size,
double
* vect,
92
double
mean,
double
stdDev );
93
94
virtual
double
operator()
();
95
virtual
double
operator()
(
double
mean,
double
stdDev );
96
97
std::string
name
()
const
;
98
HepRandomEngine
&
engine
();
99
100
static
std::string
distributionName
() {
return
"RandGauss"
;}
101
// Provides the name of this distribution class
102
103
// Save and restore to/from streams
104
105
std::ostream &
put
( std::ostream & os )
const
;
106
std::istream &
get
( std::istream & is );
107
108
// Methods setFlag(false) and setF(false) if invoked in the client
109
// code before shoot/fire will force generation of a new couple of
110
// values.
111
112
static
bool
getFlag
() {
return
set_st;}
113
114
static
void
setFlag
(
bool
val ) {set_st = val;}
115
116
bool
getF
()
const
{
return
set
;}
117
118
void
setF
(
bool
val ) {
set
= val;}
119
120
// Methods overriding the base class static saveEngineStatus ones,
121
// by adding extra data so that save in one program, then further gaussians,
122
// will produce the identical sequence to restore in another program, then
123
// generating gaussian randoms there
124
125
static
void
saveEngineStatus
(
const
char
filename[] =
"Config.conf"
);
126
// Saves to file the current status of the current engine.
127
128
static
void
restoreEngineStatus
(
const
char
filename[] =
"Config.conf"
);
129
// Restores a saved status (if any) for the current engine.
130
131
static
std::ostream&
saveFullState
( std::ostream & os );
132
// Saves to stream the state of the engine and cached data.
133
134
static
std::istream&
restoreFullState
( std::istream & is );
135
// Restores from stream the state of the engine and cached data.
136
137
static
std::ostream&
saveDistState
( std::ostream & os );
138
// Saves to stream the state of the cached data.
139
140
static
std::istream&
restoreDistState
( std::istream & is );
141
// Restores from stream the state of the cached data.
142
143
144
protected
:
145
146
static
double
getVal
() {
return
nextGauss_st;}
147
148
static
void
setVal
(
double
nextVal ) {nextGauss_st = nextVal;}
149
150
double
normal
();
151
152
double
defaultMean
;
153
double
defaultStdDev
;
154
155
shared_ptr<HepRandomEngine>
localEngine
;
156
157
private
:
158
159
bool
set
;
160
double
nextGauss;
161
162
// static data
163
static
bool
set_st;
164
static
double
nextGauss_st;
165
166
};
167
168
}
// namespace CLHEP
169
170
#ifdef ENABLE_BACKWARDS_COMPATIBILITY
171
// backwards compatibility will be enabled ONLY in CLHEP 1.9
172
using namespace
CLHEP;
173
#endif
174
175
#include "CLHEP/Random/RandGauss.icc"
176
177
#endif
Generated on Sun Jun 17 2012 08:08:27 for CLHEP by
1.8.1.1