diff options
author | tlatorre <tlatorre@uchicago.edu> | 2018-08-27 10:12:17 -0500 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2018-08-27 10:12:17 -0500 |
commit | 779266ec72a5c76ee52043ab3ae17479ba6a9788 (patch) | |
tree | 9a03c335731aeff2cadb728bc3fe4309aafef874 /src/random.c | |
parent | 4e3eb54e364f578b3ea6608b0b3fc34125985ab8 (diff) | |
download | sddm-779266ec72a5c76ee52043ab3ae17479ba6a9788.tar.gz sddm-779266ec72a5c76ee52043ab3ae17479ba6a9788.tar.bz2 sddm-779266ec72a5c76ee52043ab3ae17479ba6a9788.zip |
add code to expand the track of a particle using a KL expansion
To fit the path of muons and electrons I use the Karhunen-Loeve expansion of a
random 2D walk in the polar angle in x and y. This allows you to decompose the
path into a sum over sine functions whose coefficients become random variables.
The nice thing about fitting the path in this way is that you can capture
*most* of the variation in the path using a small number of variables by only
summing over the first N terms in the expansion and it is easy to calculate the
probability of the coefficients since they are all uncorrelated.
Diffstat (limited to 'src/random.c')
-rw-r--r-- | src/random.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/random.c b/src/random.c index f6cf85e..e2e5641 100644 --- a/src/random.c +++ b/src/random.c @@ -12,3 +12,19 @@ double randn(void) return sqrt(-2*log(u1))*cos(2*M_PI*u2); } + +void rand_sphere(double *dir) +{ + /* Generates a random point on the unit sphere. */ + double u, v, theta, phi; + + u = genrand_real1(); + v = genrand_real1(); + + phi = 2*M_PI*u; + theta = acos(2*v-1); + + dir[0] = sin(theta)*cos(phi); + dir[1] = sin(theta)*sin(phi); + dir[2] = cos(theta); +} |