Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
rnorm.cpp
Go to the documentation of this file.
1#ifdef VISUAL_STUDIO
2#define _USE_MATH_DEFINES
3// see comment in math.h:
4/* Define _USE_MATH_DEFINES before including math.h to expose these macro
5 * definitions for common math constants. These are placed under an #ifdef
6 * since these commonly-defined names are not part of the C/C++ standards.
7 */
8#endif
9#include <cmath>
12
14
15double rnorm_improved(void) {
19 } else {
20 double x1, x2, w, y1, y2;
21 do {
22 x1 = 2.0 * SRANLUX() - 1.0;
23 x2 = 2.0 * SRANLUX() - 1.0;
24 w = x1 * x1 + x2 * x2;
25 } while (w > 1.0);
26
27 w = sqrt(-2.0 * log(w) / w);
28 y1 = x1 * w;
29 y2 = x2 * w;
32 return y1;
33 }
34}
35
36void rnorm_double(double r1, double r2, double &x1, double &x2) {
37 double r = sqrt(-2.0 * log(r1));
38 double fi = 2.0 * M_PI * r2;
39 x1 = r * cos(fi);
40 x2 = r * sin(fi);
41}
42
43void rnorm_float(float r1, float r2, float &x1, float &x2) {
44 float r = sqrt(-2.0 * log(r1));
45 float fi = 2.0 * M_PI * r2;
46 x1 = r * cos(fi);
47 x2 = r * sin(fi);
48}
DoubleAc cos(const DoubleAc &f)
Definition: DoubleAc.cpp:431
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:313
DoubleAc sin(const DoubleAc &f)
Definition: DoubleAc.cpp:383
Definition: rnorm.h:7
double second_ran
Definition: rnorm.h:9
int s_inited_second_ran
Definition: rnorm.h:10
ffloat SRANLUX(void)
Definition: ranluxint.h:262
void rnorm_double(double r1, double r2, double &x1, double &x2)
Definition: rnorm.cpp:36
void rnorm_float(float r1, float r2, float &x1, float &x2)
Definition: rnorm.cpp:43
GausState gaus_state
Definition: rnorm.cpp:13
double rnorm_improved(void)
Definition: rnorm.cpp:15