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