Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- import Cluster
- import Fit
- output_data_path = '/Users/marialauraperez/Desktop/'
- input_data_path = '/Volumes/TOSHIBA EXT/XRF_20190723_22C/raw/'
- sources = ['CaXRF', 'AgXRF', 'Am241XRF_1']
- names_hists = ['Ca XRF', 'Ag XRF', 'Am241']
- names = [['Ca', 'Cu'], ['Ag'], ['Sn', 'Gd']]
- colors_hists = ['lightcoral', 'yellowgreen', 'dodgerblue']
- colors_peaks = [['maroon', 'red'], ['olive'], ['navy', 'blueviolet']]
- maximum = 70
- numbins = 70
- maxrows = 100000
- def load_parameter_matrices(suffix, path_to_data):
- # suffix: of the data
- # path_to_data: where txt matrices are
- parameter_matrices = []
- names = ['A', 'B', 'C', 'T']
- for i in range(len(names)):
- if i is 0:
- parameter_matrices.append(Cluster.remove_dead_pixels(np.genfromtxt(
- path_to_data + names[i] + suffix)))
- else:
- parameter_matrices.append(np.genfromtxt(path_to_data + names[i] + suffix))
- return parameter_matrices
- def histos_and_peaks(matrices, calibration_type, minargs, maxargs):
- # clusters, may calibrate, gives histograms and returns info of histogram
- # maximum: in histogram
- # maxrows: number of events to import
- # calibration_type: string, non calibrated, test pulse or default
- # if calibrate is false, everything is done with ToT values
- mus = list()
- x1 = np.linspace(0, maximum, 500)
- plt.figure()
- plt.title('Test spectra with Si-TPX3 (' + calibration_type + ')', fontweight='bold')
- for i in range(len(sources)):
- source = sources[i]
- print('Processing '+names_hists[i]+' data...')
- data = np.genfromtxt(input_data_path+source+'.t3pa', skip_header=1, delimiter='\t', unpack=True,
- max_rows=maxrows)
- indexes = np.ndarray.astype(data[1, :], int)
- ToA_vals = data[2, :]
- ToT_vals = data[3, :]
- x_vals, y_vals = np.unravel_index(indexes, [256, 256])
- if calibration_type is 'NonCalibrated':
- energies = ToT_vals
- else:
- energies = Cluster.calibrate(matrices, x_vals, y_vals, ToT_vals)
- clusters = Cluster.db_cluster(x_vals, y_vals, ToA_vals, energies, eps=1.99, scale=[1.0, 1.0, 100.])
- x_cvals, y_cvals, t_cvals, e_cvals = Cluster.get_clustered_energies(clusters)
- del data
- del energies
- del clusters
- n, bins, patches = plt.hist(e_cvals, bins=numbins, range=[0, maximum], histtype='step',
- label=names_hists[i] + ' data', color=colors_hists[i])
- bins2 = np.zeros(len(bins)-1)
- for w in range(len(bins)-1):
- bins2[w] = (bins[w+1] + bins[w])/2
- # ('+str(len(x_cvals))+' clusters)
- for j in range(len(names[i])):
- name = names[i][j]
- print('Fitting '+name+' peak...')
- minarg = minargs[i][j]
- maxarg = maxargs[i][j]
- gauss = Fit.FitGauss().fit(x=bins2[minarg:maxarg], y=n[minarg:maxarg])
- y1 = Fit.gauss(x1, gauss[0])
- mu = gauss[0][1]
- mus.append(mu)
- plt.plot(x1, y1, label=name + r' fit ($\mu$ = ' + str(np.round(mu, 3)) + ')', color=colors_peaks[i][j],
- linestyle='--')
- plt.xlim(0, maximum)
- if calibration_type is 'NonCalibrated':
- plt.xlabel('ToT value')
- else:
- plt.xlabel('Energy [keV]')
- plt.ylabel('Total counts')
- plt.legend(fontsize='small')
- plt.savefig(output_data_path+calibration_type+'_Histos+Peaks.png')
- return mus
- matpath = '/Users/marialauraperez/Desktop/param_mats/'
- #param_mats_default = load_parameter_matrices('_SiTPX3.txt', matpath)
- #param_mats_stp = load_parameter_matrices('_SourceTestPulse.txt', matpath)
- #param_mats_tp = load_parameter_matrices('_TestPulse22deg.txt', matpath)
- param_mats_noam = load_parameter_matrices('_STP_NoAm.txt', matpath)
- #mus_def = histos_and_peaks(param_mats_default, 'Default', [[0, 6], [12], [15, 35]], [[6, 11], [35], [35, 47]])
- #mus_stp = histos_and_peaks(param_mats_stp, 'STP', [[0, 6], [12], [15, 35]], [[6, 11], [35], [35, 47]])
- #mus_tp = histos_and_peaks(param_mats_tp, 'Test Pulses', [[0, 5], [12], [15, 30]], [[5, 10], [35], [30, 38]])
- mus_noam = histos_and_peaks(param_mats_noam, 'STP (No Am)', [[0, 6], [12], [15, 35]], [[6, 11], [35], [35, 47]])
- #print(mus_def)
- #print(mus_stp)
- #print(mus_tp)
- print(mus_noam)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement