-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmuon.php
More file actions
executable file
·40 lines (32 loc) · 924 Bytes
/
muon.php
File metadata and controls
executable file
·40 lines (32 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
function get_accepted_ratio($l1, $w1, $l2, $w2, $loff, $woff, $distance, $n_event)
{
$n_accepted = 0;
for($i = 0; $i < $n_event; $i++)
{
$x = (rand()/getrandmax()-0.5)*$l1;
$y = (rand()/getrandmax()-0.5)*$w1;
$theta = generate_theta();
$phi = rand()/getrandmax()*2*pi();
$phi = rand(0, 2*pi());
$x_low = $x + $distance*tan($theta)*cos($phi) + $loff;
$y_low = $y + $distance*tan($theta)*sin($phi) + $woff;
if($x_low>-0.5*$l2 and $x_low<0.5*$l2 and $y_low>-0.5*$w2 and $y_low<0.5*$w2)
{
$n_accepted = $n_accepted + 1;
}
}
return $n_accepted/$n_event;
}
/////////////////////////////////////////////////////////////////////
function generate_theta()
{
while(1)
{
$theta = rand()/getrandmax()*0.5*pi();
$pdf = cos($theta)*cos($theta)*sin($theta);
$pdf_r = rand()/getrandmax()*2.0/3.0/sqrt(3.0);
if($pdf_r < $pdf) return $theta;
}
}
?>