Newer
Older
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
'''
renamed variables not to have a variable with the same name as the fuction the variable is used within
-- ME. 2018-07-23
'''
def beta(energy: float, mass=938.2720813):
'''
Parameters
----------
energy: float
kinetic energy of the particle in MeV/c2
mass: float
mass of the moving particle, optional, if not given mass of proton is used
Returns
-------
relaivistic beta of the particle
'''
b=(1-gamma(energy, mass)**-2)**0.5
return b
def beta_c(energy, mass=938.2720813):
'''
Parameters
----------
energy: float
kinetic energy of the particle in MeV/c2
mass: float
mass of the moving particle, optional, if not given mass of proton is used
Returns
-------
relaivistic c*beta of the particle
'''
bc=c()*(1-gamma(energy, mass)**-2)**0.5
return bc
def beta_from_gamma(gamma):
'''
Parameters
----------
gamma: float
relaivistic gamma of the particle
Returns
-------
relaivistic beta of the particle
raises
------
if given gamma is smaller than one raises a warning
'''
if gamma < 1:
print('gamma cannot be less than one')
beta = 0
else:
beta=(1-gamma**-2)**0.5
return beta
def gamma(energy, mass=938.2720813):
'''
Parameters
----------
energy: float
kinetic energy of the particle in MeV/c2
mass: float
mass of the moving particle, optional, if not given mass of proton is used
Returns
-------
relaivistic gamma of the particle
'''
#if mass>0:
g=1+(energy/mass)
return g
def gamma_from_beta(beta):
'''
Parameters
----------
beta: float
relaivistic beta of the particle
Returns
-------
relaivistic gamma of the particle
'''
if beta == 1:
from math import inf as math_inf
gamma = math_inf
else:
gamma = (1-beta**2)**-0.5
return gamma
def energy(gamma_beta, mass=938.2720813):
'''
Parameters
----------
gamma_beta: float
gamma or beta of the particle; if gamma_beta >= 1 the value is gamma, if gamma_beta < 1 the value is beta
mass: float
mass of the moving particle, optional, if not given mass of proton is used
Returns
-------
returns kinetic energy of the particle in MeV.
example:
sprel.energy(2.55, 938)
> 1453.8999999999999
if gamma_beta < 1 the value is beta
example:
sprel.energy(.55, 938)
> 185.13182200743233
'''
if gamma_beta >= 1: #assuming the value given is gamma
e = (gamma_beta - 1) * mass
elif gamma_beta < 1: #adduming the value given is beta
e = mass * (-1 + 1 / (1 - gamma_beta ** 2) ** 0.5)
return e
def c():
'''
speed of light, 299792458 m/s
'''
return 299792458