5 # @purpose Do theory stuff
6 # Because sadly, Mathematica does not work on my new laptop
14 import re # Regular expressions - for removing comments
15 #import odict #ordered dictionary
17 import Gnuplot, Gnuplot.funcutils
19 gnuplot = Gnuplot.Gnuplot()
24 # @purpose Model the secondary electron distribution using M. Furman's formula
26 def se_dist(s, Ep, sigma_p, dE, n_max=0.75):
30 results.append([E, n_max *s * E / (s - 1.0 + E**s) , math.exp(-(E - Ep)**2.0 / (2.0*sigma_p**2.0))])
36 # @purpose integrate function numerically over a range of arguments
38 def integrate(f, xmin, xmax, dx):
46 # @function derivative
47 # @purpose get derivative of a function at a value
49 return (f(x + dx) - f(x)) / dx
54 def tcs(f, sigma, Emin, Emax, dE):
58 results.append([E, (1.0 - sigma(0)) * f(-E) - integrate(lambda e : f(e - E) * der(sigma, E, dE), Emin, Emax, dE)])
68 def table(f, xmin, xmax, dx):
72 result.append([x, f(x)])
76 def gaussian(x, sigma):
77 return math.exp(- (x**2.0)/(2.0 * sigma**2.0)) / (sigma * (2.0 * math.pi)**0.50)
79 def step(x, sigma, T):
80 return 1.0 / (math.exp((x - sigma)/T) + 1.0)
83 # @function write_data
84 # @purpose Write a list of data to a file suitable for gnuplotting
86 def write_data(data, fileName):
87 out = open(fileName, "w")
90 out.write(str(column) + "\t")
95 gnuplot.replot(Gnuplot.Data(data, with_="lp"))
100 #test = se_dist(4.0, 7.0, 0.2, 0.01)
101 #write_data(test, "se_dist.dat")
104 #print("Press enter to exit")
105 #sys.stdin.readline()
110 if __name__ == "__main__":