-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrem_plot_dist.py
More file actions
126 lines (108 loc) · 5.04 KB
/
brem_plot_dist.py
File metadata and controls
126 lines (108 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#! /usr/bin/env python
import PyFrensie.Data.Native as Native
import PyFrensie.Utility as Utility
import PyFrensie.Utility.Prng as Prng
import PyFrensie.Utility.Interpolation as Interpolation
import PyFrensie.MonteCarlo.Collision as Collision
import PyTrilinos.Teuchos as Teuchos
import numpy
import matplotlib.pyplot as plt
Utility.initFrensiePrng()
#datadir = '/home/software/mcnpdata/'
datadir = '/home/lkersting/frensie/src/packages/test_files/'
source = Teuchos.FileInputSource( datadir + '/cross_sections.xml' )
xml_obj = source.getObject()
cs_list = Teuchos.XMLParameterListReader().toParameterList( xml_obj )
# -------------------------------------------------------------------------- ##
# Electroionization Data
# -------------------------------------------------------------------------- ##
# Possible Elements ['H-Native', 'Al-Native', 'Pb-Native']
elements = ['Pb-Native']
# Possible Interpolation Policies ["LogLogLog", "LinLinLin", "LinLinLog"]
interps = ["LogLogLog", "LinLinLin"]
# Possible Interpolation Schemes ["Correlated", "Exact"]
schemes = ["Correlated", "Exact"]
# Show Relative difference in schemes (True/False)
show_difference = True
# Possible energies [1e-2, 1e-1, 1.0, 15.7, 20.0]
energies = [15.7]
# Step length between plot points
step = 0.001
cdf_values = numpy.append(numpy.arange(0.0,1.0-step, step), 1.0-1e-15 )
random_numbers = ([])
for i in cdf_values:
random_numbers = numpy.append(random_numbers,i)
random_numbers = numpy.append(random_numbers,i)
plot_number = 1
for z in elements:
print "\n----------------------------"
print "-----", z, "Tests -----"
print "----------------------------"
data_list = cs_list.get( z )
file_name = datadir + data_list.get( 'electroatomic_file_path' )
native_data = Native.ElectronPhotonRelaxationDataContainer( file_name )
# Select distribution parameters
for interp in interps:
print "Interp = ", interp
print "----------------------------"
# Plot the given energy
for energy in energies:
title = 'Bremsstrahlung Energy Loss CDF at ' + str(energy)
fig = plt.figure(num=plot_number, figsize=(10,5))
if show_difference and len( schemes ) == 2:
ax1 = plt.subplot2grid((2,1),(0, 0), colspan=5)
else:
plt.subplot2grid((1,1),(0, 0), colspan=5)
plt.xlabel('Energy Loss')
plt.ylabel('CDF')
plt.title( title )
# plt.xlim(0.85,1.0)
# plt.ylim(0.02,0.05)
# Plot all schemes on one graph
samples = numpy.zeros(shape=(len( schemes ),len( cdf_values )))
differences = numpy.zeros(shape=(2,len( cdf_values )))
scheme_number = 0
for scheme in schemes:
# Create the distribution
brem_dist = Collision.createLogLogLogCorrelatedBremsstrahlungDistribution(native_data, 1e-12)
if interp == "LogLogLog":
if scheme == "Exact":
brem_dist = Collision.createLogLogLogExactBremsstrahlungDistribution(native_data, 1e-12)
elif scheme == "Stochastic":
brem_dist = Collision.createLogLogLogStochasticBremsstrahlungDistribution(native_data, 1e-12)
elif interp == "LinLinLog":
if scheme == "Correlated":
brem_dist = Collision.createLinLinLogCorrelatedBremsstrahlungDistribution(native_data, 1e-12)
elif scheme == "Exact":
brem_dist = Collision.createLinLinLogExactBremsstrahlungDistribution(native_data, 1e-12)
elif scheme == "Stochastic":
brem_dist = Collision.createLinLinLogStochasticBremsstrahlungDistribution(native_data, 1e-12)
elif interp == "LinLinLin":
if scheme == "Correlated":
brem_dist = Collision.createLinLinLinCorrelatedBremsstrahlungDistribution(native_data, 1e-12)
elif scheme == "Exact":
brem_dist = Collision.createLinLinLinExactBremsstrahlungDistribution(native_data, 1e-12)
elif scheme == "Stochastic":
brem_dist = Collision.createLinLinLinStochasticBremsstrahlungDistribution(native_data, 1e-12)
Prng.RandomNumberGenerator.setFakeStream(random_numbers)
angle = 0.0
for i in range(0,len(cdf_values)):
samples[scheme_number,i], angle = brem_dist.sample( energy )
label = interp + " " + scheme
plt.plot( samples[ scheme_number ], cdf_values, label=label)
plt.xscale('log')
plt.yscale('log')
scheme_number = scheme_number + 1
plt.legend( loc=4)
if show_difference and len( schemes ) == 2:
plt.subplot2grid((2,1),(1, 0), colspan=5, sharex=ax1)
for i in range(0,len(cdf_values)):
differences[0,i]= abs(samples[0,i] - samples[1,i])
differences[1,i]= differences[0,i]/samples[0,i]
plt.ylabel('Difference')
plt.plot( samples[0], differences[0], label="Absolute Differences" )
plt.plot( samples[0], differences[1], label="Rel. Absolute Differences" )
plt.xscale('log')
plt.legend( loc=2)
plot_number = plot_number + 1
plt.show()