Skip to content

Commit

Permalink
Merge branch 'dev' into 'master'
Browse files Browse the repository at this point in the history
Dev

See merge request lesnat/p2sat!7
  • Loading branch information
lesnat committed Sep 13, 2018
2 parents 669e835 + f66ca56 commit dadb972
Show file tree
Hide file tree
Showing 5 changed files with 403 additions and 71 deletions.
42 changes: 42 additions & 0 deletions examples/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#coding:utf8

"""
This is an example of how to use the `PhaseSpace.stat` object of p2sat.
It allows to make statistics on phase space data in a very simple way
"""

# Import p2sat
p2sat_path="../"
import sys
if p2sat_path not in sys.path:sys.path.append(p2sat_path)
import p2sat

# Boolean to export or not the generated phase space
export = False

# Instanciate a PhaseSpace object for electron specie
eps = p2sat.PhaseSpace(specie="electron")

# Define energy and angle parameters
ekin_dict = {"law":"exp","T":1.0}
# theta_dict = {"law":"gauss","mu":0.,"sigma":5.}
theta_dict = {"law":"iso","max":20.}
phi_dict = {"law":"iso"}

# Generate particle phase space
eps.data.generate(Nconf = 1e5, Npart = 1e12, ekin=ekin_dict, theta=theta_dict, phi=phi_dict)

# Look at the consistency of phase space generation
print(eps)
eps.plot.figure(0)
eps.plot.h1('ekin',bwidth=.1,log=True)
eps.plot.f1('ekin',func_name="exp",log=True,bwidth=.1)

eps.plot.figure(1)
eps.plot.h2('theta','phi',log=True,
bwidth1=.5,bwidth2=1.)

# Export phase space if needed
if export:
eps.export.txt("test_eps.csv",sep=",")
45 changes: 42 additions & 3 deletions p2sat/PhaseSpace.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,20 @@ class PhaseSpace(object):
See sub-objects documentation for more informations
"""
def __init__(self,specie):
self.specie = specie
if specie in ("gamma","g"):
self.specie = "gamma"
self.mass = 0
elif specie in ("positron","electron","e-","e+","e"):
elif specie in ("positron","e+"):
self.specie = "e+"
self.mass = 0.511
elif specie in ("muon","muon+","muon-","mu+","mu-","mu"):
elif specie in ("electron","e-"):
self.specie = "e-"
self.mass = 0.511
elif specie in ("muon+","mu+"):
self.specie = "mu+"
self.mass = 105.6
elif specie in ("muon-","mu-"):
self.specie = "mu-"
self.mass = 105.6
else:
raise NameError("Unknown particle specie.")
Expand Down Expand Up @@ -73,6 +81,37 @@ def __add__(self,other):

return ps

def __str__(self):
txt = "\n"
txt += "p2sat PhaseSpace instance located at %s\n\n"%hex(id(self))
txt += "Specie : %s\n"%self.specie
txt += "Number of configurations : %i\n"%len(self)
txt += "Total number of particles : %.4E\n\n"%sum(self.data.w)
txt += "Statistics : ( min , max , mean , std ) unit\n"
txt += " w : (% .3E, % .3E, % .3E, % .3E) \n"%(min(self.data.w),max(self.data.w),self.data.w.mean(),self.data.w.std())
txt += " t : (% .3E, % .3E, % .3E, % .3E) fs\n\n"%(min(self.data.t),max(self.data.t),self.data.t.mean(),self.data.t.std())

txt += " x : (% .3E, % .3E, % .3E, % .3E) um\n"%(min(self.data.x),max(self.data.x),self.data.x.mean(),self.data.x.std())
txt += " y : (% .3E, % .3E, % .3E, % .3E) um\n"%(min(self.data.y),max(self.data.y),self.data.y.mean(),self.data.y.std())
txt += " z : (% .3E, % .3E, % .3E, % .3E) um\n"%(min(self.data.z),max(self.data.z),self.data.z.mean(),self.data.z.std())
txt += " r : (% .3E, % .3E, % .3E, % .3E) um\n\n"%(min(self.data.r),max(self.data.r),self.data.r.mean(),self.data.r.std())

txt += " px : (% .3E, % .3E, % .3E, % .3E) MeV/c\n"%(min(self.data.px),max(self.data.px),self.data.px.mean(),self.data.px.std())
txt += " py : (% .3E, % .3E, % .3E, % .3E) MeV/c\n"%(min(self.data.py),max(self.data.py),self.data.py.mean(),self.data.py.std())
txt += " pz : (% .3E, % .3E, % .3E, % .3E) MeV/c\n"%(min(self.data.pz),max(self.data.pz),self.data.pz.mean(),self.data.pz.std())
txt += " p : (% .3E, % .3E, % .3E, % .3E) MeV/c\n\n"%(min(self.data.p),max(self.data.p),self.data.p.mean(),self.data.p.std())

txt += " ekin : (% .3E, % .3E, % .3E, % .3E) MeV\n"%(min(self.data.ekin),max(self.data.ekin),self.data.ekin.mean(),self.data.ekin.std())
txt += " gamma : (% .3E, % .3E, % .3E, % .3E) \n"%(min(self.data.gamma),max(self.data.gamma),self.data.gamma.mean(),self.data.gamma.std())
txt += " beta : (% .3E, % .3E, % .3E, % .3E) \n"%(min(self.data.beta),max(self.data.beta),self.data.beta.mean(),self.data.beta.std())
txt += " v : (% .3E, % .3E, % .3E, % .3E) um/fs\n\n"%(min(self.data.v),max(self.data.v),self.data.v.mean(),self.data.v.std())

txt += " theta : (% .3E, % .3E, % .3E, % .3E) deg\n"%(min(self.data.theta),max(self.data.theta),self.data.theta.mean(),self.data.theta.std())
txt += " phi : (% .3E, % .3E, % .3E, % .3E) deg\n"%(min(self.data.phi),max(self.data.phi),self.data.phi.mean(),self.data.phi.std())
txt += ""

return txt

def __len__(self):
"""
Return the total number of configurations.
Expand Down
Loading

0 comments on commit dadb972

Please sign in to comment.