Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from scipy.optimize import curve_fit
- import numpy as np
- import matplotlib.pyplot as plt
- def surrogate_function(x, a, b, c, t, g):
- y = a*g*x + b - c/(g*x-t)
- y[np.where(g*x < t)] = 0
- y *= y > 0
- return y
- datapath = '/Volumes/TOSHIBA EXT/23-07-19 - Test Pulses (22deg)/'
- data_path_output = '/Users/marialauraperez/Desktop/SummerCERN/Results/TestPulses-22deg/'
- first_charges = np.arange(500, 1600, 100)
- second_charges = np.arange(2000, 12000, 1000)
- charges = np.concatenate((first_charges, second_charges))
- ToT_data = list()
- mean_ToT = list()
- energies = charges*3.62/1000
- for i in range(len(charges)):
- matrix = np.genfromtxt(datapath+str(charges[i])+'e.txt_iToT.txt')
- ToT_data.append(matrix)
- mean_ToT.append(np.mean(matrix)/100)
- theoretical_XRF = [4.512, 6.405, 8.046, 15.775, 17.48, 25.271, 59.5]
- ToT_XRF = [12.05, 16.91, 20.98, 38.83, 42.64, 58.97, 118.54]
- poptmean, pcovn = curve_fit(surrogate_function, energies, mean_ToT)
- def surrogate_function_ABCT(A, B, C, T):
- def surrogate_function_g(x, g):
- y = g*A*x + B - C/(g*x-T)
- y[np.where(g * x < T)] = 0
- y *= y > 0
- return y
- return surrogate_function_g
- popt1, pcov1 = curve_fit(surrogate_function_ABCT(poptmean[0], poptmean[1], poptmean[2], poptmean[3]),
- theoretical_XRF, ToT_XRF)
- x = np.linspace(2, 60, 100)
- plt.figure()
- plt.title('Test pulse and source calibrations (whole detector)', fontweight='bold')
- plt.xlabel('Energy [keV]')
- plt.ylabel('ToT value')
- plt.plot(x, surrogate_function(x, *poptmean), label='TP Fit: a = '+str(np.round(poptmean[0], 3))
- + '; b = ' + str(np.round(poptmean[1], 3))
- + '; c = '+str(np.round(poptmean[2], 3))
- + '; t = '+str(np.round(poptmean[3], 3))
- + '; g = '+str(np.round(poptmean[4], 3)))
- plt.scatter(energies, mean_ToT, label='TP points', s=10)
- plt.plot(x, surrogate_function_ABCT(poptmean[0], poptmean[1], poptmean[2], poptmean[3])(x, popt1[0]),
- label='Source fit: g = '+str(np.round(popt1[0], 3)))
- plt.scatter(theoretical_XRF, ToT_XRF, label='Source points', s=10)
- plt.text(5.25, 6.94, 'Ti', fontsize=9)
- plt.text(7.4, 13.5, 'Fe', fontsize=9)
- plt.text(9.4, 19.9, 'Cu', fontsize=9)
- plt.text(16.7, 34.7, 'Zr', fontsize=9)
- plt.text(18.5, 41.4, 'Mo', fontsize=9)
- plt.text(26.16, 57, 'Sn', fontsize=9)
- plt.text(56.2, 110.4, 'Am 241', fontsize=9)
- plt.legend(fontsize='x-small', loc=2)
- plt.savefig('/Users/marialauraperez/Desktop/MeanCalib_Source+TP_22deg.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement