Skip to content
Snippets Groups Projects
Commit da7e5f17 authored by Mamad Eshraqi's avatar Mamad Eshraqi
Browse files

Update SP_Relativity.py with functions emit_geo and emit_norm which return the...

Update SP_Relativity.py with functions emit_geo and emit_norm which return the geometrical and normalized emittances
parent f55a255f
No related branches found
No related tags found
No related merge requests found
Pipeline #11429 passed
'''
renamed variables not to have a variable with the same name as the fuction the variable is used within
-- ME. 2018-07-23
added geometrical and normalized emittance calculations
-- ME. 2019-02-19
'''
from scipy import constants
......@@ -127,3 +130,50 @@ def energy(gamma_beta, mass=proton_mass_in_MeV):
e = mass * (-1 + 1 / (1 - gamma_beta ** 2) ** 0.5)
return e
def emit_geo(u_up_array):
'''
parameters
----------
u_up_array: array like
a 2D array containing that has u_up_array[:,:2] as coordinates in u and u'
returns
-------
geometrical emittance of the distribution/array in units of pi.mm.mrad
'''
u_shift = u_up_array[:,0] # x
up_shift = u_up_array[:,1] # x'
u = u_shift - np.average(u_shift)
up = up_shift - np.average(up_shift)
u2 = np.square(u) # x2
u2ave = np.average(u2) # <x2>
print(u2ave)
up2 = np.square(up) # x'2
up2ave = np.average(up2) # <x'2>
print(up2ave)
uup = np.multiply(u, up) # x.x'
uupave = np.average(uup) # <x.x'>
uupave2 = uupave**2 # <x.x'>2
print(uupave2)
emit2 = (u2ave * up2ave) - uupave2
emit = np.sqrt(emit2)
return emit
def emit_norm(u_up_array, gamma):
'''
parameters
----------
u_up_array: array like
a 2D array containing that has u_up_array[:,:2] as coordinates in u and u'
gamma: float
relativistic gamma of the particles in the beam
returns
-------
normalized emittance of the distribution/array in units of pi.mm.mrad
'''
#from ess import SP_Relativity as spr
bt = spr.beta_from_gamma(gamma)
geo_emit = emit_geo(u_up_array)
emit = bt * gamma * geo_emit
return emit
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