source: HiSusy/trunk/Pythia8/pythia8170/htmldoc/RandomNumbers.html @ 1

Last change on this file since 1 was 1, checked in by zerwas, 11 years ago

first import of structure, PYTHIA8 and DELPHES

File size: 5.5 KB
Line 
1<html>
2<head>
3<title>Random Numbers</title>
4<link rel="stylesheet" type="text/css" href="pythia.css"/>
5<link rel="shortcut icon" href="pythia32.gif"/>
6</head>
7<body>
8   
9<h2>Random Numbers</h2>
10
11This page describes the random-number generator in PYTHIA and
12how it can be replaced by an external one.
13 
14<h3>Internal random numbers</h3>
15
16The <code>Rndm</code> class generates random numbers, using the
17Marsaglia-Zaman-Tsang algorithm [<a href="Bibliography.html" target="page">Mar90</a>].
18
19<p/>
20Random numbers <code>R</code> uniformly distributed in
21<code>0 &lt; R &lt; 1</code> are obtained with
22<pre>
23   Rndm::flat();
24</pre>
25There are also methods to generate according to an exponential, to
26<i>x * exp(-x)</i>, to a Gaussian, or picked among a set of
27possibilites, which make use of <code>flat()</code>.
28
29<p/>
30If the random number generator is not initialized before, it will be
31so the first time it is asked to generate a random number, and then
32with the default seed, 19780503. This means that, by default, all runs
33will use identically the same random number sequence. This is
34convenient for debugging purposes, but dangerous if you intend to
35run several "identical" jobs to boost statistics. You can initialize,
36or reinitialize, with your own choice of seed with a
37<pre>
38   Rndm::init(seed);
39</pre>
40Here values <code>0 &lt; seed &lt; 900 000 000</code> gives so many
41different random number sequences, while <code>seed = 0</code> will call
42the <code>Stdlib time(0)</code> function to provide a "random"
43<code>seed</code>, and <code>seed &lt; 0</code> will revert back to
44the default <code>seed</code>.
45
46<p/>
47The <code>Pythia</code> class defines <a href="RandomNumberSeed.html" target="page">a
48flag and a mode</a>, that allows the <code>seed</code> to be set in
49the <code>Pythia::init</code> call. That would be the standard way for a
50user to pick the random number sequence in a run.
51
52<h3>External random numbers</h3>
53
54<code>RndmEngine</code> is a base class for the external handling of
55random-number generation. The user-written derived class is called
56if a pointer to it has been handed in with the
57<code>pythia.rndmEnginePtr()</code> method. Since the default
58Marsaglia-Zaman-Tsang algorithm is quite good, chances are that any
59replacement would be a step down, but this may still be required by
60consistency with other program elements in big experimental frameworks.
61
62<p/>
63There is only one pure virtual method in <code>RndmEngine</code>, to
64generate one random number flat in the range between 0 and 1:
65<pre>
66  virtual double flat() = 0;
67</pre>
68Note that methods for initialization are not provided in the base
69class, in part since input parameters may be specific to the generator
70used, in part since initialization can as well be taken care of
71externally to the <code>Pythia</code> code.
72
73<p/>
74An example illustrating how to run with an external random number
75generator is provided in <code>main23.cc</code>.
76
77<h3>The methods</h3>
78
79We here collect a more complete and formal overview of the methods.
80   
81<a name="method1"></a>
82<p/><strong>Rndm::Rndm() &nbsp;</strong> <br/>
83construct a random number generator, but does not initialize it.
84 
85   
86<a name="method2"></a>
87<p/><strong>Rndm::Rndm(int seed) &nbsp;</strong> <br/>
88construct a random number generator, and initialize it for the
89given seed number.
90 
91   
92<a name="method3"></a>
93<p/><strong>bool Rndm::rndmEnginePtr( RndmEngine* rndmPtr) &nbsp;</strong> <br/>
94pass in pointer for external random number generation.
95 
96   
97<a name="method4"></a>
98<p/><strong>void Rndm::init(int seed = 0) &nbsp;</strong> <br/>
99initialize, or reinitialize, the random number generator for the given
100seed number. Not necessary if the seed was already set in the constructor.
101 
102   
103<a name="method5"></a>
104<p/><strong>double Rndm::flat() &nbsp;</strong> <br/>
105generate next random number uniformly between 0 and 1.
106 
107   
108<a name="method6"></a>
109<p/><strong>double Rndm::exp() &nbsp;</strong> <br/>
110generate random numbers according to <i>exp(-x)</i>.
111 
112   
113<a name="method7"></a>
114<p/><strong>double Rndm::xexp() &nbsp;</strong> <br/>
115generate random numbers according to <i>x exp(-x)</i>.
116 
117   
118<a name="method8"></a>
119<p/><strong>double Rndm::gauss() &nbsp;</strong> <br/>
120generate random numbers according to <i>exp(-x^2/2)</i>.
121 
122   
123<a name="method9"></a>
124<p/><strong>pair&lt;double, double&gt; Rndm::gauss2() &nbsp;</strong> <br/>
125generate a pair of random numbers according to
126<i>exp( -(x^2 + y^2) / 2)</i>. Is faster than two calls
127to <code>gauss()</code>.
128 
129   
130<a name="method10"></a>
131<p/><strong>int Rndm::pick(const vector<double>& prob) &nbsp;</strong> <br/>
132pick one option among vector of (positive) probabilities.
133 
134   
135<a name="method11"></a>
136<p/><strong>bool Rndm::dumpState(string fileName) &nbsp;</strong> <br/>
137save the current state of the random number generator to a binary
138file. This involves two integers and 100 double-precision numbers.
139Intended for debug purposes. Note that binary files may be
140platform-dependent and thus not transportable.
141 
142   
143<a name="method12"></a>
144<p/><strong>bool Rndm::readState(string fileName) &nbsp;</strong> <br/>
145set the state of the random number generator by reading in a binary
146file saved by the above command. Comments as above.
147 
148   
149<a name="method13"></a>
150<p/><strong>virtual double RndmEngine::flat() &nbsp;</strong> <br/>
151if you want to construct an external random number generator
152(or generator interface) then you must implement this method
153in your class derived from the <code>RndmEningen</code> base class,
154to give a random number between 0 and 1.
155 
156
157</body>
158</html>
159
160<!-- Copyright (C) 2012 Torbjorn Sjostrand -->
Note: See TracBrowser for help on using the repository browser.