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/RandGeneral.h
Go to the documentation of this file.
1
// $Id: RandGeneral.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2
// -*- C++ -*-
3
//
4
// -----------------------------------------------------------------------
5
// HEP Random
6
// --- RandGeneral ---
7
// class header file
8
// -----------------------------------------------------------------------
9
10
// Class defining methods for shooting generally distributed random values,
11
// given a user-defined probability distribution function.
12
13
// =======================================================================
14
// S.Magni & G.Pieri - Created: 29 April 1998
15
// G.Cosmo - Added constructor using default engine from the
16
// static generator: 20 Aug 1998
17
// S.Magni & G.Pieri - Added linear interpolation: 24 March 1999
18
// M. Fischler - Added private methods that simplify the implementaion
19
// prepareTables(), useFlatDistribution(), mapRandom()
20
// - Added private variable oneOverNbins.
21
// - Made the warning about shoot() not being static a tad
22
// more prominent. 14 May 1999
23
// M Fischler - put and get to/from streams 12/15/04
24
// =======================================================================
25
26
#ifndef RandGeneral_h
27
#define RandGeneral_h 1
28
29
#include "CLHEP/Random/defs.h"
30
#include "CLHEP/Random/Random.h"
31
#include "CLHEP/Utility/memory.h"
32
#include <vector>
33
34
namespace
CLHEP {
35
40
class
RandGeneral
:
public
HepRandom
{
41
42
public
:
43
44
RandGeneral
(
const
double
* aProbFunc,
45
int
theProbSize,
46
int
IntType=0 );
47
RandGeneral
(
HepRandomEngine
& anEngine,
48
const
double
* aProbFunc,
49
int
theProbSize,
50
int
IntType=0 );
51
RandGeneral
(
HepRandomEngine
* anEngine,
52
const
double
* aProbFunc,
53
int
theProbSize,
54
int
IntType=0 );
55
// These constructors should be used to instantiate a RandGeneral
56
// distribution object defining a local engine for it.
57
// The static generator will be skipped by using the non-static methods
58
// defined below. In case no engine is specified in the constructor, the
59
// default engine used by the static generator is applied.
60
// If the engine is passed by pointer the corresponding engine object
61
// will be deleted by the RandGeneral destructor.
62
// If the engine is passed by reference the corresponding engine object
63
// will not be deleted by the RandGeneral destructor.
64
// The probability distribution function (Pdf) must be provided by the user
65
// as an array of positive real number. The array size must also be
66
// provided. The Pdf doesn't need to be normalized to 1.
67
// if IntType = 0 ( default value ) a uniform random number is
68
// generated using the engine. The uniform number is then transformed
69
// to the user's distribution using the cumulative probability
70
// distribution constructed from his histogram. The cumulative
71
// distribution is inverted using a binary search for the nearest
72
// bin boundary and a linear interpolation within the
73
// bin. RandGeneral therefore generates a constant density within
74
// each bin.
75
// if IntType = 1 no interpolation is performed and the result is a
76
// discrete distribution.
77
78
virtual
~RandGeneral
();
79
// Destructor
80
81
// Methods to shoot random values using the static generator
82
// N.B.: The methods are NOT static since they use nonstatic members
83
// theIntegralPdf & nBins
84
86
// //
87
// BIG RED WARNING //
88
// //
90
//
91
// The above N.B. is telling users that the shoot() methods in this
92
// class are NOT STATIC. You cannot do
93
// double x = RandGeneral::shoot();
94
// It would not make sense to provide a static shoot -- what would
95
// the default probability function look like?
96
97
inline
double
shoot
();
98
99
inline
void
shootArray
(
const
int
size,
double
* vect);
100
101
// Methods to shoot random values using a given engine
102
// by-passing the static generator.
103
104
double
shoot
(
HepRandomEngine
* anEngine );
105
106
void
shootArray
(
HepRandomEngine
* anEngine,
const
int
size,
107
double
* vect );
108
109
// Methods using the localEngine to shoot random values, by-passing
110
// the static generator.
111
112
double
fire
();
113
114
void
fireArray
(
const
int
size,
double
* vect);
115
116
double
operator()
();
117
118
// Save and restore to/from streams
119
120
std::ostream &
put
( std::ostream & os )
const
;
121
std::istream &
get
( std::istream & is );
122
123
std::string
name
()
const
;
124
HepRandomEngine
&
engine
();
125
126
static
std::string
distributionName
() {
return
"RandGeneral"
;}
127
// Provides the name of this distribution class
128
129
130
private
:
131
132
shared_ptr<HepRandomEngine>
localEngine;
133
std::vector<double> theIntegralPdf;
134
int
nBins;
135
double
oneOverNbins;
136
int
InterpolationType;
137
138
// Private methods to factor out replicated implementation sections
139
void
prepareTable(
const
double
* aProbFunc);
140
void
useFlatDistribution();
141
double
mapRandom(
double
rand)
const
;
142
143
};
144
145
}
// namespace CLHEP
146
147
#ifdef ENABLE_BACKWARDS_COMPATIBILITY
148
// backwards compatibility will be enabled ONLY in CLHEP 1.9
149
using namespace
CLHEP;
150
#endif
151
152
#include "CLHEP/Random/RandGeneral.icc"
153
154
#endif
Generated on Mon May 6 2013 04:04:11 for CLHEP by
1.8.1.2