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/Temperatures/'
- sources = ['22C', '30C', '35C']
- colors = ['purple', 'dodgerblue', 'yellowgreen']
- def histos_and_peaks(minargs, maxargs, maximum, maxrows):
- numbins = maximum
- # 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('Am241 spectrum with TPX3', fontweight='bold')
- for i in range(len(sources)):
- minarg = minargs[i]
- maxarg = maxargs[i]
- source = sources[i]
- print('Processing '+sources[i]+' data...')
- data = np.genfromtxt(input_data_path+'am241_'+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])
- energies = 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', color=colors[i],
- label=sources[i] + ' data')
- bins2 = np.zeros(len(bins)-1)
- for w in range(len(bins)-1):
- bins2[w] = (bins[w+1] + bins[w])/2
- 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=r'Fit ($\mu$ = ' + str(np.round(mu, 3)) + ')', linestyle='--', color=colors[i])
- plt.xlim(80, maximum)
- plt.xlabel('ToT value')
- plt.ylabel('Total counts')
- plt.legend(fontsize='small')
- plt.savefig(output_data_path+'Am_drifting.png')
- return mus
- 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_peaks2(matrices, minargs, maxargs, calibration_type, maximum, maxrows):
- # 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
- numbins = maximum
- mus = list()
- x1 = np.linspace(0, maximum, 500)
- plt.figure()
- plt.title('Am241 spectrum with TPX3 ('+calibration_type+')', fontweight='bold')
- for i in range(len(sources)):
- minarg = minargs[i]
- maxarg = maxargs[i]
- source = sources[i]
- print('Processing '+sources[i]+' data...')
- data = np.genfromtxt(input_data_path+'am241_'+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])
- 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', color=colors[i],
- label=sources[i] + ' data')
- bins2 = np.zeros(len(bins)-1)
- for w in range(len(bins)-1):
- bins2[w] = (bins[w+1] + bins[w])/2
- 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=r'Fit ($\mu$ = ' + str(np.round(mu, 3)) + ')', linestyle='--', color=colors[i])
- plt.xlim(35, maximum)
- plt.xlabel('Energy [keV]')
- plt.ylabel('Total counts')
- plt.legend(fontsize='small')
- plt.savefig(output_data_path+calibration_type+'_Am_drifting.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)
- print('No calibration:')
- histos_and_peaks([115, 90, 75], [200, 200, 200], 200, 100000)
- print('Default:')
- histos_and_peaks2(param_mats_default, [53, 50, 45], [70, 70, 70], 'Default', 70, 100000)
- print('STP:')
- histos_and_peaks2(param_mats_stp, [53, 50, 45], [70, 70, 70], 'STP', 70, 100000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement