forked from greyson-newton/Muon_Sim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiterateMuon.py
43 lines (31 loc) · 1.48 KB
/
iterateMuon.py
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
41
42
43
import math
import random
from numba import jit
from constants import pi, typicalScatteringDistance, angleConstant, speedDecreaseConstant, massOverCharge, magneticField
from geometry import *
@jit
def iterateMuon(angleInitial, speed, charge, xInitial, yInitial):
#radiusOfCurvature = massOverCharge*speed/magneticField #negative means curve the other way
radiusOfCurvature = returnRadiusOfCurvature(massOverCharge, speed, magneticField)
#flip y by charge, then flip back
yInitial = yInitial*charge
x0, y0 = circleFromPointAndRadius(xInitial, yInitial, radiusOfCurvature, angleInitial)
#calculate scattering distance:
distance = scatteringDistance()
circumference = 2*pi*abs(radiusOfCurvature)
if distance > circumference:
distance = -999
xFinal, yFinal, angleFinal = xInitial, yInitial, angleInitial
angleAfterScatter = angleInitial
else:
angleCovered = distance/circumference*2*pi #angles are radians
angleFinal = angleInitial + angleCovered
xFinal, yFinal = circleFromPointAndRadius(x0,y0, -radiusOfCurvature, angleFinal)
scatAngle = scatteringAngle(speed)
angleAfterScatter = angleFinal + scatAngle
speed = scatteringSpeed(speed,scatAngle)
if xFinal < xInitial:
distance = -999
#flip y by charge, then flip back
yFinal = yFinal*charge
return xFinal, yFinal, angleAfterScatter, speed, distance, x0, y0, radiusOfCurvature