SHARE
TWEET

Untitled

a guest Aug 19th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import Cluster
  4. import Fit
  5.  
  6. output_data_path = '/Users/marialauraperez/Desktop/'
  7. input_data_path = '/Volumes/TOSHIBA EXT/Temperatures/'
  8. sources = ['22C', '30C', '35C']
  9. colors = ['purple', 'dodgerblue', 'yellowgreen']
  10.  
  11.  
  12. def histos_and_peaks(minargs, maxargs, maximum, maxrows):
  13.     numbins = maximum
  14.     # clusters, may calibrate, gives histograms and returns info of histogram
  15.     # maximum: in histogram
  16.     # maxrows: number of events to import
  17.     # calibration_type: string, non calibrated, test pulse or default
  18.     # if calibrate is false, everything is done with ToT values
  19.     mus = list()
  20.     x1 = np.linspace(0, maximum, 500)
  21.     plt.figure()
  22.     plt.title('Am241 spectrum with TPX3', fontweight='bold')
  23.     for i in range(len(sources)):
  24.         minarg = minargs[i]
  25.         maxarg = maxargs[i]
  26.         source = sources[i]
  27.         print('Processing '+sources[i]+' data...')
  28.         data = np.genfromtxt(input_data_path+'am241_'+source+'.t3pa', skip_header=1, delimiter='\t', unpack=True,
  29.                              max_rows=maxrows)
  30.         indexes = np.ndarray.astype(data[1, :], int)
  31.         ToA_vals = data[2, :]
  32.         ToT_vals = data[3, :]
  33.         x_vals, y_vals = np.unravel_index(indexes, [256, 256])
  34.         energies = ToT_vals
  35.         clusters = Cluster.db_cluster(x_vals, y_vals, ToA_vals, energies, eps=1.99, scale=[1.0, 1.0, 100.])
  36.         x_cvals, y_cvals, t_cvals, e_cvals = Cluster.get_clustered_energies(clusters)
  37.         del data
  38.         del energies
  39.         del clusters
  40.         n, bins, patches = plt.hist(e_cvals, bins=numbins, range=[0, maximum], histtype='step', color=colors[i],
  41.                                     label=sources[i] + ' data')
  42.         bins2 = np.zeros(len(bins)-1)
  43.         for w in range(len(bins)-1):
  44.             bins2[w] = (bins[w+1] + bins[w])/2
  45.         gauss = Fit.FitGauss().fit(x=bins2[minarg:maxarg], y=n[minarg:maxarg])
  46.         y1 = Fit.gauss(x1, gauss[0])
  47.         mu = gauss[0][1]
  48.         mus.append(mu)
  49.         plt.plot(x1, y1, label=r'Fit ($\mu$ = ' + str(np.round(mu, 3)) + ')', linestyle='--', color=colors[i])
  50.     plt.xlim(80, maximum)
  51.     plt.xlabel('ToT value')
  52.     plt.ylabel('Total counts')
  53.     plt.legend(fontsize='small')
  54.     plt.savefig(output_data_path+'Am_drifting.png')
  55.     return mus
  56.  
  57.  
  58. def load_parameter_matrices(suffix, path_to_data):
  59.     # suffix: of the data
  60.     # path_to_data: where txt matrices are
  61.     parameter_matrices = []
  62.     names = ['A', 'B', 'C', 'T']
  63.     for i in range(len(names)):
  64.         if i is 0:
  65.             parameter_matrices.append(Cluster.remove_dead_pixels(np.genfromtxt(
  66.                 path_to_data + names[i] + suffix)))
  67.         else:
  68.             parameter_matrices.append(np.genfromtxt(path_to_data + names[i] + suffix))
  69.     return parameter_matrices
  70.  
  71.  
  72. def histos_and_peaks2(matrices, minargs, maxargs, calibration_type, maximum, maxrows):
  73.     # clusters, may calibrate, gives histograms and returns info of histogram
  74.     # maximum: in histogram
  75.     # maxrows: number of events to import
  76.     # calibration_type: string, non calibrated, test pulse or default
  77.     # if calibrate is false, everything is done with ToT values
  78.     numbins = maximum
  79.     mus = list()
  80.     x1 = np.linspace(0, maximum, 500)
  81.     plt.figure()
  82.     plt.title('Am241 spectrum with TPX3 ('+calibration_type+')', fontweight='bold')
  83.     for i in range(len(sources)):
  84.         minarg = minargs[i]
  85.         maxarg = maxargs[i]
  86.         source = sources[i]
  87.         print('Processing '+sources[i]+' data...')
  88.         data = np.genfromtxt(input_data_path+'am241_'+source+'.t3pa', skip_header=1, delimiter='\t', unpack=True,
  89.                              max_rows=maxrows)
  90.         indexes = np.ndarray.astype(data[1, :], int)
  91.         ToA_vals = data[2, :]
  92.         ToT_vals = data[3, :]
  93.         x_vals, y_vals = np.unravel_index(indexes, [256, 256])
  94.         energies = Cluster.calibrate(matrices, x_vals, y_vals, ToT_vals)
  95.         clusters = Cluster.db_cluster(x_vals, y_vals, ToA_vals, energies, eps=1.99, scale=[1.0, 1.0, 100.])
  96.         x_cvals, y_cvals, t_cvals, e_cvals = Cluster.get_clustered_energies(clusters)
  97.         del data
  98.         del energies
  99.         del clusters
  100.         n, bins, patches = plt.hist(e_cvals, bins=numbins, range=[0, maximum], histtype='step', color=colors[i],
  101.                                     label=sources[i] + ' data')
  102.         bins2 = np.zeros(len(bins)-1)
  103.         for w in range(len(bins)-1):
  104.             bins2[w] = (bins[w+1] + bins[w])/2
  105.         gauss = Fit.FitGauss().fit(x=bins2[minarg:maxarg], y=n[minarg:maxarg])
  106.         y1 = Fit.gauss(x1, gauss[0])
  107.         mu = gauss[0][1]
  108.         mus.append(mu)
  109.         plt.plot(x1, y1, label=r'Fit ($\mu$ = ' + str(np.round(mu, 3)) + ')', linestyle='--', color=colors[i])
  110.     plt.xlim(35, maximum)
  111.     plt.xlabel('Energy [keV]')
  112.     plt.ylabel('Total counts')
  113.     plt.legend(fontsize='small')
  114.     plt.savefig(output_data_path+calibration_type+'_Am_drifting.png')
  115.     return mus
  116.  
  117.  
  118. matpath = '/Users/marialauraperez/Desktop/param_mats/'
  119. param_mats_default = load_parameter_matrices('_SiTPX3.txt', matpath)
  120. param_mats_stp = load_parameter_matrices('_SourceTestPulse.txt', matpath)
  121.  
  122. print('No calibration:')
  123. histos_and_peaks([115, 90, 75], [200, 200, 200], 200, 100000)
  124. print('Default:')
  125. histos_and_peaks2(param_mats_default, [53, 50, 45], [70, 70, 70], 'Default', 70, 100000)
  126. print('STP:')
  127. histos_and_peaks2(param_mats_stp, [53, 50, 45], [70, 70, 70], 'STP', 70, 100000)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top