Skip to content
Snippets Groups Projects
Commit ca792216 authored by Yngve Levinsen's avatar Yngve Levinsen
Browse files

for relativity, using scipy.constants when applicable

moving examples out of sources
parent a595615b
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,14 @@
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):
from scipy import constants
# Proton mass in MeV/c
proton_mass_in_MeV=constants.physical_constants['proton mass energy equivalent in MeV'][0]
# Speed of light in m/s
c=constants.c
def beta(energy: float, mass=proton_mass_in_MeV):
'''
Parameters
----------
......@@ -18,7 +25,7 @@ def beta(energy: float, mass=938.2720813):
b=(1-gamma(energy, mass)**-2)**0.5
return b
def beta_c(energy, mass=938.2720813):
def beta_c(energy, mass=proton_mass_in_MeV):
'''
Parameters
----------
......@@ -31,7 +38,7 @@ def beta_c(energy, mass=938.2720813):
-------
relaivistic c*beta of the particle
'''
bc=c()*(1-gamma(energy, mass)**-2)**0.5
bc=c*(1-gamma(energy, mass)**-2)**0.5
return bc
def beta_from_gamma(gamma):
......@@ -56,7 +63,7 @@ def beta_from_gamma(gamma):
beta=(1-gamma**-2)**0.5
return beta
def gamma(energy, mass=938.2720813):
def gamma(energy, mass=proton_mass_in_MeV):
'''
Parameters
----------
......@@ -91,7 +98,7 @@ def gamma_from_beta(beta):
gamma = (1-beta**2)**-0.5
return gamma
def energy(gamma_beta, mass=938.2720813):
def energy(gamma_beta, mass=proton_mass_in_MeV):
'''
Parameters
----------
......@@ -120,9 +127,3 @@ def energy(gamma_beta, mass=938.2720813):
e = mass * (-1 + 1 / (1 - gamma_beta ** 2) ** 0.5)
return e
def c():
'''
speed of light, 299792458 m/s
'''
return 299792458
......@@ -59,7 +59,7 @@ def Field_TTF(field_1d, step_dz, freq, E_in, mass, RetMaxPhase):
#print(dE)
if dE<0:
print('Please adjust the field level, particle decelrated to zero energy!')
t += dz/(myrel.c()*myrel.beta(dE, mass))
t += dz/(myrel.c*myrel.beta(dE, mass))
if dE > Emax:
Emax = dE
#print('Emax', Emax)
......@@ -112,20 +112,3 @@ def TTF_beta(field_1d, step_dz, freq, mass):
return TTFb
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# #
# E X A M P L E S #
# #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
Header, Field = bccb.read_binary_fieldmap('Data/FM/HB_W_coupler.edz', 3)
fz = field_on_axis(Field, 3, Header[0], Header[2], Header[5])
z = np.arange(0,int(Header[0]+1))
dz = Header[1]/Header[0]
z_points = dz*z
print('Int_E:', Field_integral(fz, dz), '[TTF, Phase_Max_Energy]: ', Field_TTF(fz, dz, 704.42, 700, 938, True))
TTFb = TTF_beta(fz, dz, 704.42, 938)
#plot(z_points, fz);
#plot(TTFb[0,:], 50*TTFb[1,:]);
\ No newline at end of file
from ess import fieldmap
'''
Example
The parameters in the following six rows define the path to your fieldmap, no name is needed, this script
scans the folder and converts all files, assumes all are binary fieldmaps, to ASCII fieldmaps.
The dimension of the field is also needed.
If you need to cut the field, the n_enter and n_exit should be adjusted.
'''
mypath = 'Data/FM/' # where the fieldmaps are stored
fieldmap_dim = 3
#fieldmap_dim = 2
#fieldmap_dim = 1
n_enter = 0 #Number of lines to be removed from entrance of fieldmap
n_exit = 0 #Number of lines to be removed from exit of fieldmap
onlyfiles = [f for f in os.listdir(mypath) if os.path.isfile(os.path.join(mypath, f))]
for f in onlyfiles:
if f[0]!=".":
if (n_enter+n_exit>0):
Header, Field = fieldmap.cut_fieldmap_length(f, fieldmap_dim, n_enter, n_exit, 'b')
else:
Header, Field = fieldmap.read_binary_fieldmap(mypath+f, fieldmap_dim)
save_to_ascii(Header, Field, fieldmap.fieldmap_dim, 'Data/FM/ASCII/', f)
test = False
#%pylab inline
if test == True:
#field = field_on_axis_from_file('Data/FM/MB_W_coupler.edz', 3, 'b')
field = field_on_axis_from_file('Data/FM/ASCII/Spoke_W_coupler.edz', 3, 'a')
plot(field[0,:], field[1,:])
from ess import TTF
Header, Field = TTF.bccb.read_binary_fieldmap('Data/FM/HB_W_coupler.edz', 3)
fz = TTF.field_on_axis(Field, 3, Header[0], Header[2], Header[5])
z = np.arange(0,int(Header[0]+1))
dz = Header[1]/Header[0]
z_points = dz*z
print('Int_E:', TTF.Field_integral(fz, dz), '[TTF, Phase_Max_Energy]: ', TTF.Field_TTF(fz, dz, 704.42, 700, 938, True))
TTFb = TTF_beta(fz, dz, 704.42, 938)
#plot(z_points, fz);
#plot(TTFb[0,:], 50*TTFb[1,:]);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment