forked from mrvanolog/PHAS0051_HPGe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResolutionAnalysis.py
197 lines (172 loc) · 7.48 KB
/
ResolutionAnalysis.py
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
from Spectrum import Spectrum
import numpy as np
import matplotlib.pyplot as plt
# Initialising calibration factors
Spectrum.calibration_a = -5.677763487790322e-08
Spectrum.calibration_b = 0.7626393415958842
Spectrum.calibration_c = -0.7553693869647748
# Creating Cobalt-60 object
co60 = Spectrum()
co60.read_from_csv("18-10-18_Co60.csv")
co60.apply_polynomial_calibration()
co60.plot()
# Creating Bismuth-207 object
bi207 = Spectrum()
bi207.read_from_csv("25-10-18_Bi207.csv")
bi207.apply_polynomial_calibration()
# Creating an unknown source object
us = Spectrum()
us.read_from_csv("IAEA_sample_present_20.11.18.csv")
us.apply_polynomial_calibration()
# And its background
bkgd_us = Spectrum()
bkgd_us.read_from_csv("IAEA_sample_not_present_22.11.18.csv")
# Reducing the background.
#us.plot(calibrated=False, log=False) # plots unknown source spectra
us_reduced = Spectrum.reduce_background(us, bkgd_us)
### Finding FWHM OF PEAKS ###
# Initialising arrays
our_energies = np.array([])
d_our_energies = np.array([])
FWHM_array = np.array([])
d_FWHM_array = np.array([])
# COBALT #
peaks = co60.find_peaks(show=False)
for i in peaks:
FWHM, d_FWHM = co60.fit_3sigma_gaussian(i, mode="FWHM", show=False)
mean, d_mean = co60.fit_3sigma_gaussian(i, mode="Mean", show=False)
FWHM_array = np.append(FWHM_array, FWHM)
d_FWHM_array = np.append(d_FWHM_array, d_FWHM)
our_energies = np.append(our_energies, mean)
d_our_energies = np.append(d_our_energies, d_mean)
# BISMUTH #
bi207_peaks = bi207.find_peaks(threshold=0.3, show=False)
#bi207.plot(calibrated=False, xMin=bi207_peaks[0]-10, xMax=bi207_peaks[0]+10)
# Second X-Ray peak
FWHM, d_FWHM = bi207.fit_gaussian(bi207.channels[bi207_peaks[1]-2:bi207_peaks[1]+3],
bi207.counts[bi207_peaks[1]-2:bi207_peaks[1]+3],
mode="FWHM", show=False)
mean, d_mean = bi207.fit_gaussian(bi207.channels[bi207_peaks[1]-2:bi207_peaks[1]+3],
bi207.counts[bi207_peaks[1]-2:bi207_peaks[1]+3],
mode="Mean", show=False)
print("X-Ray 2:", FWHM, "+-", d_FWHM)
FWHM_array = np.append(FWHM_array, FWHM)
d_FWHM_array = np.append(d_FWHM_array, d_FWHM)
our_energies = np.append(our_energies, mean)
d_our_energies = np.append(d_our_energies, d_mean)
# this is for uncertainties of first X-Ray
d1 = d_mean/mean
d2 = d_FWHM/FWHM
# First X-Ray peak
FWHM, d_FWHM = bi207.fit_gaussian(bi207.channels[bi207_peaks[0]-3:bi207_peaks[0]+2],
bi207.counts[bi207_peaks[0]-3:bi207_peaks[0]+2],
mode="FWHM", show=False)
mean, d_mean = bi207.fit_gaussian(bi207.channels[bi207_peaks[0]-3:bi207_peaks[0]+2],
bi207.counts[bi207_peaks[0]-3:bi207_peaks[0]+2],
mode="Mean", show=False)
# Due to only one datapoint to the right of the peak,
# I assume same % uncertainty as the neighbouring peak
FWHM_array = np.append(FWHM_array, FWHM)
d_FWHM_array = np.append(d_FWHM_array, d2*FWHM)
our_energies = np.append(our_energies, mean)
d_our_energies = np.append(d_our_energies, d1*mean)
print("X-Ray 1:", FWHM, "+-", d2*FWHM)
# Other peaks
bi207_peaks = bi207_peaks[2:]
for i in bi207_peaks:
FWHM, d_FWHM = bi207.fit_3sigma_gaussian(i, mode="FWHM", show=False)
mean, d_mean = bi207.fit_3sigma_gaussian(i, mode="Mean", show=False)
FWHM_array = np.append(FWHM_array, FWHM)
d_FWHM_array = np.append(d_FWHM_array, d_FWHM)
our_energies = np.append(our_energies, mean)
d_our_energies = np.append(d_our_energies, d_mean)
# Last peak
FWHM, d_FWHM = bi207.fit_3sigma_gaussian(2322, mode="FWHM", show=False)
mean, d_mean = bi207.fit_3sigma_gaussian(2322, mode="Mean", show=False)
FWHM_array = np.append(FWHM_array, FWHM)
d_FWHM_array = np.append(d_FWHM_array, d_FWHM)
our_energies = np.append(our_energies, mean)
d_our_energies = np.append(d_our_energies, d_mean)
# UNKNOWN SOURCE #
us_peaks = us_reduced.find_peaks(abs_threshold=True, threshold=500)
us_peaks = us_peaks[-5:]
# gaussians plotted for 5 peaks highest in energy
for i in us_peaks:
FWHM, d_FWHM = us.fit_3sigma_gaussian(i, mode="FWHM", show=False)
mean, d_mean = us.fit_3sigma_gaussian(i, mode="Mean", show=False)
FWHM_array = np.append(FWHM_array, FWHM)
d_FWHM_array = np.append(d_FWHM_array, d_FWHM)
our_energies = np.append(our_energies, mean)
d_our_energies = np.append(d_our_energies, d_mean)
#
# Tl-208, Bi-214, Cs-137 / Ba-137m, something, K-40
#
# Peak around 461 channel, 351 energy
# Bi-211
FWHM, d_FWHM = us.fit_3sigma_gaussian(461, mode="FWHM", show=False)
mean, d_mean = us.fit_3sigma_gaussian(461, mode="Mean", show=False)
FWHM_array = np.append(FWHM_array, FWHM)
d_FWHM_array = np.append(d_FWHM_array, d_FWHM)
our_energies = np.append(our_energies, mean)
d_our_energies = np.append(d_our_energies, d_mean)
# Peak around channel 313
# Pb-212
FWHM, d_FWHM = us.fit_3sigma_gaussian(313, mode="FWHM", show=False)
mean, d_mean = us.fit_3sigma_gaussian(313, mode="Mean", show=False)
FWHM_array = np.append(FWHM_array, FWHM)
d_FWHM_array = np.append(d_FWHM_array, d_FWHM)
our_energies = np.append(our_energies, mean)
d_our_energies = np.append(d_our_energies, d_mean)
# Peaks around channel 388
# Pb-214
FWHM, d_FWHM = us.fit_3sigma_gaussian(388, mode="FWHM", show=False)
mean, d_mean = us.fit_3sigma_gaussian(388, mode="Mean", show=False)
FWHM_array = np.append(FWHM_array, FWHM)
d_FWHM_array = np.append(d_FWHM_array, d_FWHM)
our_energies = np.append(our_energies, mean)
d_our_energies = np.append(d_our_energies, d_mean)
# peaks around channel 3428
# Tl-208 (Thalium)
FWHM, d_FWHM = us.fit_3sigma_gaussian(3428, mode="FWHM", show=False)
mean, d_mean = us.fit_3sigma_gaussian(3428, mode="Mean", show=False)
FWHM_array = np.append(FWHM_array, FWHM)
d_FWHM_array = np.append(d_FWHM_array, d_FWHM)
our_energies = np.append(our_energies, mean)
d_our_energies = np.append(d_our_energies, d_mean)
# peaks around channel 2315
# Bi-214
FWHM, d_FWHM = us.fit_3sigma_gaussian(2315, mode="FWHM", show=False)
mean, d_mean = us.fit_3sigma_gaussian(2315, mode="Mean", show=False)
FWHM_array = np.append(FWHM_array, FWHM)
d_FWHM_array = np.append(d_FWHM_array, d_FWHM)
our_energies = np.append(our_energies, mean)
d_our_energies = np.append(d_our_energies, d_mean)
# Converting channels to energies
Spectrum.channel_to_energy(our_energies)
d_our_energies = np.add(d_our_energies, 0.62)
print("FWHM:", FWHM_array)
print("d_FWHM:", d_FWHM_array)
print("Our Energies:", our_energies)
# Plotting FWHM againts energy
plt.figure(figsize=(8, 8))
plt.title("FWHM dependence on energies of the peaks.")
plt.errorbar(our_energies, FWHM_array, xerr=d_our_energies, yerr=d_FWHM_array, fmt="k.", label="Data Points")
plt.grid(True, linestyle='--', linewidth=0.2)
plt.legend(loc="upper left")
plt.xlim(0, np.amax(our_energies)*1.1)
plt.xlabel("Energy, KeV")
plt.ylabel("FWHM, KeV")
plt.show()
# Calculating resolution
resolution = FWHM/our_energies * 100
d_resolution = resolution*np.sqrt((d_FWHM_array/FWHM)**2 + (d_our_energies/our_energies)**2)
# Plotting it
plt.figure(figsize=(5, 5))
plt.errorbar(our_energies, resolution, xerr=d_our_energies, yerr=d_resolution,
fmt="k.", linewidth=0.4, markersize=2)
plt.grid(True, linestyle='--', linewidth=0.2)
plt.xlim(0, np.amax(our_energies)*1.1)
plt.ylim(0)
plt.xlabel("Energy, KeV")
plt.ylabel("Resolution")
plt.show()