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

added normalized emittance

dictionary return now excludes lost particles
this was essential for the twiss calculation apparently
parent f814eda7
No related branches found
No related tags found
No related merge requests found
......@@ -188,8 +188,19 @@ class plt:
def __getitem__(self, key):
if key in self.Nelp:
import numpy
i=self.Nelp.index(key)
return self._data[i]
ret={}
# some particles are lost, exclude those:
lost_mask=self._data[i]['l']==0
for key in self._data[i]:
if isinstance(self._data[i][key], numpy.ndarray):
ret[key]=self._data[i][key][lost_mask]
else:
ret[key]=self._data[i][key]
return ret
else:
print "No data to plot at element",key
......@@ -315,7 +326,9 @@ class plt:
for j in xrange(len(self.Nelp)):
i=self.Nelp[j]
data=self[i]
self.sigma.append([[numpy.mean( (data[n]-self.avg[m][j]) * (data[m] - self.avg[m][j]) ) for n in vals] for m in vals])
self.sigma.append([[numpy.mean( (data[n]-self.avg[n][j]) * (data[m] - self.avg[m][j]) ) for n in vals] for m in vals])
self.sigma=numpy.array(self.sigma)
......@@ -329,15 +342,23 @@ class plt:
if not hasattr(self,'sigma'):
self.calc_sigma()
if not hasattr(self,'gamma'):
self.calc_rel()
self.twiss_eps=[]
for j in xrange(len(self.Nelp)):
self.twiss_eps.append([numpy.sqrt(numpy.linalg.det(self.sigma[j][i:i+2][:,i:i+2])) for i in (0,2,4)])
self.twiss_beta = [[self.sigma[j][i][i] for i in (0,2,4)] for j in xrange(len(self.Nelp))]
self.twiss_eps=numpy.array(self.twiss_eps)
self.twiss_beta = [[self.sigma[j][i][i]/self.twiss_eps[j,i/2] for i in (0,2,4)] for j in xrange(len(self.Nelp))]
self.twiss_beta=numpy.array(self.twiss_beta)
# calculate normalized emittance:
self.twiss_eps_normed=self.twiss_eps.copy()
for i in xrange(3):
self.twiss_eps_normed[:,i]*=self.gamma*self.beta
......
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