Skip to content
Snippets Groups Projects
Commit bd446fc8 authored by Roger Wolf's avatar Roger Wolf
Browse files

a few fixes

parent b669ed4e
No related branches found
No related tags found
No related merge requests found
......@@ -34,8 +34,6 @@ def gaussian (x, mu, sigma = 50, baseline = 5, s = 0.9, N = 1000, xmin = 0, xmax
def compton_edge (x, mu, sigma = 10, A = 1, B = 0.5, baseline = 5, s = 0.9, N = 1000, xmin = 0, xmax = 100):
return s * special.erfc((x-mu)/(np.sqrt(2) * sigma)) /(2*(mu-xmin)) * (1 + (A * (x/(mu * B) - 1)**2)) + (1-s)*baseline/(xmax-xmin)
# return s * special.erfc((x-mu)/(np.sqrt(2) * sigma)) /(2*(mu-xmin)) + (1-s)*baseline/(xmax-xmin)
# return (s * special.erfc((x-mu)/(np.sqrt(2) * sigma)) * (1 + B * (x/mu - 0.5)**2))/(xmax-xmin) + (1-s)*baseline/(xmax-xmin)
......@@ -43,7 +41,7 @@ def compton_edge (x, mu, sigma = 10, A = 1, B = 0.5, baseline = 5, s = 0.9, N =
# Fit a photopeak using a Gaussian model function #
# ##################################################
def fit_peak (datax, datay, x1 = None, x2 = None, showResult = True, label = None, **initparams):
def fit_peak (datax, datay, x1 = None, x2 = None, label = None, xlabel = 'Channel', ylabel = 'Count', showResult = True, **initparams):
# Check if a lower x-limit for the fit is given, otherwise use the minimum of the provided dataset
if x1 == None:
x1 = min(datax)
......@@ -54,7 +52,7 @@ def fit_peak (datax, datay, x1 = None, x2 = None, showResult = True, label = Non
datax_clipped = np.delete(datax, np.where((x1 > datax) | (datax > x2)))
datay_clipped = np.delete(datay, np.where((x1 > datax) | (datax > x2)))
# Set axis labels
axislabels = ['Channel', 'Count']
axislabels = [xlabel, ylabel]
# Perform a Gaussian fit on the remaining data, choosing the position of the maximum value in the data as an initial value for the position of the peak
fit = hist_fit_data(datax_clipped, datay_clipped, model = gaussian, limitedparams = [['mu', {'lower':0}], ['sigma', {'lower':0}], ['s', {'lower':0, 'upper':1}]], fixedparams = [["N", np.sum(datay_clipped)], ["xmin", x1], ["xmax", x2]], mu = datax_clipped[np.argmax(datay_clipped)], label = label, showResult = showResult, axislabels = axislabels, **initparams)
# Return fit object
......@@ -66,7 +64,7 @@ def fit_peak (datax, datay, x1 = None, x2 = None, showResult = True, label = Non
# Fit a compton edge using a complementary error function #
# ##########################################################
def fit_compton (datax, datay, x1 = None, x2 = None, showResult = True, label = None, **initparams):
def fit_compton (datax, datay, x1 = None, x2 = None, label = None, xlabel = 'Channel', ylabel = 'Count', showResult = True, **initparams):
# Check if a lower x-limit for the fit is given, otherwise use the minimum of the provided dataset
if x1 == None:
x1 = min(datax)
......@@ -83,7 +81,7 @@ def fit_compton (datax, datay, x1 = None, x2 = None, showResult = True, label =
diffs.append(np.abs(np.sum(dif[i:i+25])))
mu0 = datax_clipped[np.argmax(diffs)]
# Set axis labels
axislabels = ['Channel', 'Count']
axislabels = [xlabel, ylabel]
# Perform the fit on the remaining data using the estimated position as an initial value
fit = hist_fit_data(datax_clipped, datay_clipped, model = compton_edge, limitedparams = [['mu', {'lower':0}], ['sigma', {'lower':0}], ['A', {'lower':0}], ['B', {'lower':0.3, 'upper':0.9}], ['s', {'lower':0, 'upper':1}]], fixedparams = [["N", np.sum(datay_clipped)], ["xmin", x1], ["xmax", x2]], mu = mu0, B = mu0, label = label, axislabels = axislabels, showResult = showResult, **initparams)
# Return fit object
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
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