def ToF_sweep_action(self): filter_parameters = get_filter_parameters(self) ce_filtered = filter_clusters(self.ce, filter_parameters) number_bins = int(self.tofBins.text()) bus_start = self.module_min.value() bus_stop = self.module_max.value() ToF_Sweep_Animation(ce_filtered, number_bins, bus_start, bus_stop)
def ToF_Overlay_action(self): paths = QFileDialog.getOpenFileNames(self, "", "../data")[0] if len(paths) > 0: # Declare parameters filter_parameters = get_filter_parameters(self) number_bins = int(self.tofBins.text()) labels = ['Beam', 'Background'] # Plot fig = plt.figure() hists = [] bin_centers_vec = [] range = [0, 71e3] for path, label in zip(paths, labels): # Get data data_set = path.rsplit('/', 1)[-1][:-3] + '.zip' ce = pd.read_hdf(path, 'ce') ce_filtered = filter_clusters(ce, filter_parameters) # Get normalization norm = 1 / self.BM_counts_dict[data_set] # Plot hist, bins = ToF_histogram(ce_filtered, number_bins, label, norm, range) hists.append(hist) bin_centers_vec.append(bins) plt.plot(bin_centers_vec[0], hists[0] - hists[1], label='Difference', zorder=5) plt.title('ToF') plt.xlabel('ToF [$\mu$s]') plt.ylabel('Counts (Normalized by beam monitor)') plt.legend() plt.grid(True, which='major', linestyle='--', zorder=0) plt.grid(True, which='minor', linestyle='--', zorder=0) fig.show()
def PHS_wires_vs_grids_action(self): if (self.data_sets != ''): filter_parameters = get_filter_parameters(self) ce_filtered = filter_clusters(self.ce, filter_parameters) bus_start = self.module_min.value() bus_stop = self.module_max.value() fig = PHS_wires_vs_grids_plot(ce_filtered, bus_start, bus_stop) fig.show()
def Multiplicity_action(self): if (self.data_sets != ''): filter_parameters = get_filter_parameters(self) ce_filtered = filter_clusters(self.ce, filter_parameters) bus_start = self.module_min.value() bus_stop = self.module_max.value() fig = multiplicity_plot(ce_filtered, bus_start, bus_stop) fig.show()
def CE_2D_comparison_action(self): paths = QFileDialog.getOpenFileNames(self, "", "../data")[0] if len(paths) > 0: # Declare parameters filter_parameters = get_filter_parameters(self) front_hists = [] top_hists = [] side_hists = [] # Extract histogram data for i, path in enumerate(paths): # Import data data_set = path.rsplit('/', 1)[-1][:-3] + '.zip' ce = pd.read_hdf(path, 'ce') ce_filtered = filter_clusters(ce, filter_parameters) # Extract histograms bus_start = self.module_min.value() bus_stop = self.module_max.value() norm = 1 / self.BM_counts_dict[data_set] __, histograms = coincidences_projections_plot( ce_filtered, bus_start, bus_stop, norm) front_hists.append(np.transpose(histograms[0])) top_hists.append(np.transpose(histograms[1])) side_hists.append(np.transpose(histograms[2])) # Take difference between histograms projections_hists = [front_hists, top_hists, side_hists] diffs = [] for hists in projections_hists: diffs.append(hists[0] - hists[1]) # Define figure properties labels_vec = [['Front view', 'Row', 'Grid'], ['Top view', 'Row', 'Layer'], ['Side view', 'Layer', 'Grid']] limits_vec = [[3e-6, 2e-3], [3e-4, 4e-3], [3e-5, 2e-3]] # Plot difference fig = plt.figure() fig.set_figheight(5) fig.set_figwidth(17) for i, (diff, labels, limits) in enumerate(zip(diffs, labels_vec, limits_vec)): vmin, vmax = limits plt.subplot(1, 3, 1 + i) plt.imshow(diff, cmap='jet', norm=LogNorm(), origin='lower', interpolation='nearest', aspect='auto', vmin=vmin, vmax=vmax) # Stylize plot title, xlabel, ylabel = labels plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel) cbar = plt.colorbar() cbar.set_label('Counts (Normalized to beam monitor)') plt.tight_layout() fig.show()
def Animation_3D_action(self): filter_parameters = get_filter_parameters(self) ce_filtered = filter_clusters(self.ce, filter_parameters) origin_voxel = [ int(self.bus_origin.text()), int(self.gCh_origin.text()), int(self.wCh_origin.text()) ] Animation_3D_plot(ce_filtered, origin_voxel)
def Energy_Resolution_action(self): if (self.data_sets != ''): filter_parameters = get_filter_parameters(self) ce_filtered = filter_clusters(self.ce, filter_parameters) dE_values = calculate_energy_transfer(ce_filtered, Ei) # NEED A WAY TO GET HE3 VALUES FWHM = calculate_energy_resolution(dE_values, self.Ei, filter_parameters) print('FWHM: %.2f' % FWHM)
def Lineshape_action(self): origin_voxel = [ int(self.bus_origin.text()), int(self.gCh_origin.text()), int(self.wCh_origin.text()) ] MG_filter_parameters = get_filter_parameters(self) He3_filter_parameters = get_He3_filter_parameters(self) analyze_all_lineshapes(origin_voxel, MG_filter_parameters, He3_filter_parameters)
def Coincidences_3D_action(self): if self.data_sets != '': filter_parameters = get_filter_parameters(self) ce_filtered = filter_clusters(self.ce, filter_parameters) origin_voxel = [ int(self.bus_origin.text()), int(self.gCh_origin.text()), int(self.wCh_origin.text()) ] coincidences_3D_plot(ce_filtered, origin_voxel)
def PHS_1D_action(self): if self.data_sets != '': filter_parameters = get_filter_parameters(self) ce_filtered = filter_clusters(self.ce, filter_parameters) number_bins = int(self.phsBins.text()) fig = plt.figure() fig.set_figheight(5) fig.set_figwidth(10) PHS_1D_plot(ce_filtered, number_bins) fig.show()
def full_analysis_action(self): # Prepare filter parameters origin_voxel = [ int(self.bus_origin.text()), int(self.gCh_origin.text()), int(self.wCh_origin.text()) ] MG_filter_parameters = get_filter_parameters(self) He3_filter_parameters = get_He3_filter_parameters(self) # Define colors and normalization colors = {'MG_Coated': 'blue', 'MG_Non_Coated': 'green', 'He3': 'red'} monitor_norm_coated = 1 / 11411036 monitor_norm_non_coated = 1 / 9020907 monitor_norm_He3 = 1 / 10723199 # Prepare data full_data = prepare_data(origin_voxel, MG_filter_parameters, He3_filter_parameters) MG_coated_data, MG_non_coated_data, He3_data = full_data[0], full_data[ 1], full_data[4] MG_coated_background, MG_non_coated_background, He3_background = full_data[ 2], full_data[3], full_data[5] # Plot all peaks Coated_values = plot_all_peaks(MG_coated_data, 'MG_Coated', colors['MG_Coated'], 28.413) NonCoated_values = plot_all_peaks(MG_non_coated_data, 'MG_Non_Coated', colors['MG_Non_Coated'], 28.413 + 1.5e-3) He3_values = plot_all_peaks(He3_data, 'He3', colors['He3'], 28.239 + 3e-3) # Extract key values energies_Coated, FoM_Coated, FoM_err_Coated, peak_areas_Coated, peak_err_Coated = Coated_values energies_NonCoated, FoM_NonCoated, FoM_err_NonCoated, peak_areas_NonCoated, peak_err_NonCoated = NonCoated_values energies_He3, FoM_He3, FoM_err_He3, peak_areas_He3, peak_err_He3 = He3_values # Store all values in vectors energies = [energies_Coated, energies_NonCoated, energies_He3] labels = ['MG_Coated', 'MG_Non_Coated', 'He3'] FoMs = [FoM_Coated, FoM_NonCoated, FoM_He3] FoM_errors = [FoM_err_Coated, FoM_err_NonCoated, FoM_err_He3] # Plot efficiency fig = plt.figure() fig.set_figheight(5) fig.set_figwidth(15) plot_efficiency(np.array(energies_He3), np.array(energies_NonCoated), np.array(peak_areas_He3), np.array(peak_areas_NonCoated), np.array(peak_err_He3), np.array(peak_err_NonCoated), monitor_norm_He3, monitor_norm_non_coated) fig.show() # Plot FoM fig = plt.figure() for energy, FoM, error, label in zip(energies, FoMs, FoM_errors, labels): plot_FoM(energy, FoM, error, label, colors[label]) plt.legend() fig.show()
def time_sweep_action(self): filter_parameters = get_filter_parameters(self) ce_filtered = filter_clusters(self.ce, filter_parameters) origin_voxel = [ int(self.bus_origin.text()), int(self.gCh_origin.text()), int(self.wCh_origin.text()) ] number_bins = int(self.tofBins.text()) bus_start = self.module_min.value() bus_stop = self.module_max.value() Time_Sweep_Animation(ce_filtered, number_bins, origin_voxel, bus_start, bus_stop)
def Count_Rate_action(self): if (self.data_sets != ''): # Declare parameters number_bins = int(self.tofBins.text()) time_offset = (0.6e-3) period_time = (1 / 14) filter_parameters = get_filter_parameters(self) ce_filtered = filter_clusters(self.ce, filter_parameters) ToF_values = (ce_filtered.ToF * 62.5e-9 + time_offset) % period_time fig = plt.figure() count_rate = calculate_count_rate(ToF_values, self.measurement_time, number_bins) fig.show() print('Count rate: %.1f [Hz]' % count_rate)
def Wavelength_action(self): if (self.data_sets != ''): filter_parameters = get_filter_parameters(self) ce_filtered = filter_clusters(self.ce, filter_parameters) number_bins = int(self.dE_bins.text()) origin_voxel = [ int(self.bus_origin.text()), int(self.gCh_origin.text()), int(self.wCh_origin.text()) ] fig = plt.figure() start = 0 stop = 10 plot_energy = False energy_plot(ce_filtered, origin_voxel, number_bins, start, stop, plot_energy) fig.show()
def Coincidences_2D_action(self): if self.data_sets != '': filter_parameters = get_filter_parameters(self) ce_filtered = filter_clusters(self.ce, filter_parameters) bus_start = self.module_min.value() bus_stop = self.module_max.value() fig, histograms = coincidences_2D_plot(ce_filtered, self.measurement_time, bus_start, bus_stop) # Export histograms to text dir_name = os.path.dirname(__file__) output_path = os.path.join(dir_name, '../output/') for bus, histogram in enumerate(histograms): path = output_path + '2D_Coincidences_Bus_%d.txt' % bus np.savetxt(path, histogram, fmt="%d", delimiter=",") # Plot figure fig.show()
def ToF_MG_vs_ToF_He3_action(self): # Get filter parameters for MG and He-3 parameters_MG = get_filter_parameters(self) parameters_He3 = get_He3_filter_parameters(self) # Filter data MG_red = filter_clusters(self.ce, parameters_MG) He3_red = filter_He3(self.He3_df, parameters_He3) # Declare paremeters number_bins = int(self.tofBins.text()) MG_label, He3_label = self.data_sets, self.He3_data_sets useMaxNorm = True # Plot data fig = plt.figure() He3_ToF_plot(He3_red, number_bins, He3_label) ToF_histogram(MG_red, number_bins, MG_label) plt.legend() fig.show()
def Timestamp_action(self): if (self.data_sets != ''): filter_parameters = get_filter_parameters(self) ce_filtered = filter_clusters(self.ce, filter_parameters) number_bins = int(self.tofBins.text()) unit = 'hours' fig = plt.figure() bus_start = self.module_min.value() bus_stop = self.module_max.value() for Bus in np.arange(bus_start, bus_stop + 1, 1): df_temp = ce_filtered[ce_filtered.Bus == Bus] if df_temp.shape[0] > 0: Time = (df_temp.Time * 62.5e-9) / (60**2) label = 'Bus %d' % Bus timestamp_plot(Time, number_bins, unit, label) plt.legend(loc=2) fig.show()
def Wavelength_overlay_action(self): paths = QFileDialog.getOpenFileNames(self, "", "../data")[0] number_bins = int(self.dE_bins.text()) origin_voxel = [ int(self.bus_origin.text()), int(self.gCh_origin.text()), int(self.wCh_origin.text()) ] MG_filter_parameters = get_filter_parameters(self) He3_filter_parameters = get_He3_filter_parameters(self) fig = plt.figure() # Multi-Grid for i, path in enumerate(paths): label = path.rsplit('/', 1)[-1] ce = pd.read_hdf(path, 'ce') ce_filtered = filter_clusters(ce, MG_filter_parameters) duration = get_duration(ce) norm = 1 / duration energy = calculate_energy(ce_filtered, origin_voxel) plt.hist(meV_to_A(energy), bins=number_bins, range=[0, 10], zorder=5, histtype='step', label=label, weights=norm * np.ones(len(energy))) print('Progress: %d/%d' % (i + 1, len(paths))) # He-3 He3_df_red = filter_He3(self.He3_df, He3_filter_parameters) energy_He3 = calculate_He3_energy(He3_df_red) norm_He3 = 1 / 54304 plt.hist(meV_to_A(energy_He3), bins=number_bins, range=[0, 10], zorder=5, histtype='step', label='2019_09_HZB_He3InBeam54304s_overnight.lst', weights=norm * np.ones(len(energy_He3))) plt.grid(True, which='major', linestyle='--', zorder=0) plt.grid(True, which='minor', linestyle='--', zorder=0) plt.ylabel('Counts (Normalized to duration)') plt.xlabel('Wavelength [Å]') plt.title('Wavelength Distribution') plt.legend(loc=1) fig.show()
def Layers_action(self): # Extract origin voxel origin_voxel = [ int(self.bus_origin.text()), int(self.gCh_origin.text()), int(self.wCh_origin.text()) ] # Get MG data MG_parameters = get_filter_parameters(self) df_MG = filter_clusters(self.ce, MG_parameters) # Get He3 data #He3_parameters = get_He3_filter_parameters(self) #df_He3 = filter_He3(self.He3_df, He3_parameters) # Investigate ToF spread #investigate_layers_FWHM(df_MG, df_He3, origin_voxel) #investigate_layers_delta_ToF(df_MG, df_He3, origin_voxel) duration = get_duration(df_MG) investigate_layers_counts(df_MG, duration)
def PHS_comparison_action(self): paths = QFileDialog.getOpenFileNames(self, "", "../data")[0] if len(paths) > 0: # Declare parameters filter_parameters = get_filter_parameters(self) number_bins = int(self.phsBins.text()) ylabel = '(Normalized to beam monitor)' intervals = [[0, 4095], [0, 10000]] # Extract histogram data fig = plt.figure() fig.set_figheight(5) fig.set_figwidth(10) labels = ['(Beam)', '(Background)'] hists = [] bins_vec = [] errors = [] norms = [] # Plot data for path, label in zip(paths, labels): # Import data data_set = path.rsplit('/', 1)[-1][:-3] + '.zip' ce = pd.read_hdf(path, 'ce') ce_filtered = filter_clusters(ce, filter_parameters) # Extract normalization norm = 1 / self.BM_counts_dict[data_set] bins, hist = PHS_1D_plot(ce_filtered, number_bins, label, norm, ylabel, intervals) hists.append(np.array(hist)) errors.append(np.array(hist) / norm) norms.append(norm) bins_vec.append(bins) # Plot difference for i in range(0, 2): plt.subplot(1, 2, i + 1) plt.plot( bins_vec[0][i], hists[0][i] - hists[1][i], #np.sqrt((errors[0][i]*norms[0]) ** 2 + (errors[1][i]*norms[1]) ** 2), #fmt='.-', capsize=5, zorder=3, label='Difference') plt.legend(loc=1) fig.show()
def PHS_comparison_region_action(self): if (self.data_sets != ''): # Declare parameters number_bins = int(self.phsBins.text()) filter_parameters = get_filter_parameters(self) df = filter_clusters(self.ce, filter_parameters) # Extract data from different regions df_cross = df[(((df.Bus * 4) + df.wCh // 20) >= 4) & (((df.Bus * 4) + df.wCh // 20) <= 7) & (df.gCh >= 98) & (df.gCh <= 101)] df_neutron = df[(((df.Bus * 4) + df.wCh // 20) == 6) & (df.gCh >= 87) & (df.gCh <= 89)] norm = 1 / self.measurement_time fig = plt.figure() fig.set_figheight(5) fig.set_figwidth(10) PHS_1D_plot(df_cross, number_bins, '(Cross talk)', norm) PHS_1D_plot(df_neutron, number_bins, '(Neutrons)', norm) plt.legend() fig.show()
def ToF_action(self): if self.data_sets != '': # Filter data filter_parameters = get_filter_parameters(self) ce_filtered = filter_clusters(self.ce, filter_parameters) number_bins = int(self.tofBins.text()) # Plot data fig = plt.figure() hist, bins = ToF_histogram(ce_filtered, number_bins, range=[0, 71429]) # Save histogram in ASCII-format dir_name = os.path.dirname(__file__) output_path = os.path.join( dir_name, '../output/ToF_%s.txt' % self.data_sets[5:-5]) np.savetxt(output_path, np.transpose(np.array([bins, hist])), delimiter=",", header='ToF (µs), Counts') fig.show()
def Coincidences_Projections_action(self): if self.data_sets != '': filter_parameters = get_filter_parameters(self) ce_filtered = filter_clusters(self.ce, filter_parameters) bus_start = self.module_min.value() bus_stop = self.module_max.value() # Get beam monitor data file_name = self.data_sets[5:-5] norm = 1 / get_duration( ce_filtered) #self.BM_counts_dict[file_name] fig, histograms = coincidences_projections_plot( ce_filtered, bus_start, bus_stop, norm) # Export histograms to text dir_name = os.path.dirname(__file__) output_path = os.path.join(dir_name, '../output/') file_names = ['Front', 'Top', 'Side'] for file_name, histogram in zip(file_names, histograms): path = output_path + '2D_Coincidences_Projections_%s.txt' % file_name np.savetxt(path, histogram, fmt="%d", delimiter=",") # Plot figure fig.show()