def Coincidences_2D_plot(window): # Declare parameters (added with condition if empty array) data_sets = window.data_sets.splitlines()[0] # Import data df_20 = window.Clusters_20_layers df_16 = window.Clusters_16_layers # Initial filter, keep only coincident events clusters_20 = filter_coincident_events(df_20, window) clusters_16 = filter_coincident_events(df_16, window) # Plot data fig = plt.figure() fig.set_figheight(4.5) fig.set_figwidth(9) plt.suptitle('Coincident events (2D)\nData set(s): %s' % data_sets) # for 20 layers plt.subplot(1, 2, 1) plt.title('20 layers') plt.hist2d(clusters_20.wCh, clusters_20.gCh, bins=[80, 12], range=[[-0.5, 79.5], [-0.5, 11.5]], norm=LogNorm(), cmap='jet') plt.xlabel('Wire [Channel number]') plt.ylabel('Grid [Channel number]') plt.colorbar() # for 16 layers plt.subplot(1, 2, 2) plt.title('16 layers') plt.hist2d(clusters_16.wCh, clusters_16.gCh, bins=[64, 12], range=[[-0.5, 63.5], [-0.5, 11.5]], norm=LogNorm(), cmap='jet') plt.xlabel('Wire [Channel number]') plt.ylabel('Grid [Channel number]') plt.colorbar() plt.subplots_adjust(left=0.08, right=0.96, top=0.82, bottom=0.12, wspace=0.32) return fig
def rate_action(self): if self.data_sets != '': ce_16 = self.Clusters_16_layers ce_20 = self.Clusters_20_layers layers_vec = [16, 20] events_vec = [ce_16, ce_20] for layer, events in zip(layers_vec, events_vec): ce_red = filter_coincident_events(events, self) start_time = ce_red.head(1)['Time'].values[0] end_time = ce_red.tail(1)['Time'].values[0] rate = ce_red.shape[0] / ((end_time - start_time) * 1e-9) print('Total neutron rate (%s layers): %f Hz' % (layer, rate))
def channel_rates(window): """plots neutron event rate for each channel raw: for all events clustered: only neutron (coincidence) events """ def channel_rates_plot_bus(events, subtitle, typeCh, wires): plt.xlabel('grid channel') plt.ylabel('Rate of total counts') plt.grid(True, which='major', zorder=0) plt.grid(True, which='minor', linestyle='--', zorder=0) plt.title("Grid rates") #print("Grid channel \t rate") gChs = [] g_rates = [] if typeCh == 'gCh': for gCh in np.arange(0, 12, 1): counts = len(events[events.gCh == gCh]) rate = counts / ((end_time - start_time) * 1e-9) gChs.append(gCh) g_rates.append(rate) #print(gCh, "\t", rate, "Hz") plt.scatter(gChs, g_rates, color="darkorange", zorder=2) plt.title(sub_title) #print("Wire channel \t rate") wChs = [] w_rates = [] if typeCh == 'wCh': for wCh in np.arange(0, wires, 1): counts = len(events[events.wCh == wCh]) rate = counts / ((end_time - start_time) * 1e-9) wChs.append(wCh) w_rates.append(rate) #print(wCh, "\t", rate, "Hz") plt.scatter(wChs, w_rates, color="crimson", zorder=2) plt.title(sub_title) if window.raw_rates.isChecked(): events_16 = window.Events_16_layers events_16 = filter_events(events_16, window) events_20 = window.Events_20_layers events_20 = filter_events(events_20, window) start_time = events_16.head(1)['srs_timestamp'].values[0] end_time = events_16.tail(1)['srs_timestamp'].values[0] tag = "raw data" else: events_16 = window.Clusters_16_layers events_16 = filter_coincident_events(events_16, window) events_20 = window.Clusters_20_layers events_20 = filter_coincident_events(events_20, window) start_time = events_16.head(1)['Time'].values[0] end_time = events_16.tail(1)['Time'].values[0] tag = "neutrons" typeChs = ['gCh', 'wCh'] grids_or_wires = {'wCh': 'Wires', 'gCh': 'Grids'} # plot fig = plt.figure() fig.set_figheight(5) fig.set_figwidth(10) plt.suptitle('Total rate per channel -- %s\n%s)' % (tag, window.data_sets.splitlines()[0])) # for 20 layers for i, typeCh in enumerate(typeChs): sub_title = "%s -- 20 layers" % grids_or_wires[typeCh] wires = 80 plt.subplot(2, 2, i + 1) channel_rates_plot_bus(events_20, sub_title, typeCh, wires) # for 16 layers for i, typeCh in enumerate(typeChs): sub_title = "%s -- 16 layers" % grids_or_wires[typeCh] plt.subplot(2, 2, i + 3) wires = 64 channel_rates_plot_bus(events_16, sub_title, typeCh, wires) plt.subplots_adjust(left=0.1, right=0.98, top=0.86, bottom=0.09, wspace=0.25, hspace=0.45) return fig
def Coincidences_3D_plot(window): # Import data df_20 = window.Clusters_20_layers df_16 = window.Clusters_16_layers data_sets = window.data_sets.splitlines()[0] # Perform initial filters clusters_20 = filter_coincident_events(df_20, window) clusters_16 = filter_coincident_events(df_16, window) # Declare max and min count min_count = 0 max_count = np.inf # Initiate 'voxel_id -> (x, y, z)'-mapping MG24_ch_to_coord_20, MG24_ch_to_coord_16 = get_MG24_to_XYZ_mapping() # Calculate 3D histogram # 20 layers H_20, edges_20 = np.histogramdd(clusters_20[['wCh', 'gCh']].values, bins=(80, 13), range=((0, 80), (0, 13))) # Insert results into an array hist_20 = [[], [], [], []] loc_20 = 0 labels_20 = [] for wCh in range(0, 80): for gCh in range(0, 13): over_min = H_20[wCh, gCh] > min_count under_max = H_20[wCh, gCh] <= max_count if over_min and under_max: coord = MG24_ch_to_coord_20[gCh, wCh] hist_20[0].append(coord['x']) hist_20[1].append(coord['y']) hist_20[2].append(coord['z']) hist_20[3].append(H_20[wCh, gCh]) loc_20 += 1 labels_20.append('Wire Channel: ' + str(wCh) + '<br>' + 'Grid Channel: ' + str(gCh) + '<br>' + 'Counts: ' + str(H_20[wCh, gCh])) # 16 layers H_16, edges_16 = np.histogramdd(clusters_16[['wCh', 'gCh']].values, bins=(80, 12), range=((0, 80), (0, 12))) # Insert results into an array hist_16 = [[], [], [], []] loc_16 = 0 labels_16 = [] for wCh in range(0, 80): for gCh in range(0, 12): over_min = H_16[wCh, gCh] > min_count under_max = H_16[wCh, gCh] <= max_count if over_min and under_max: coord = MG24_ch_to_coord_16[gCh, wCh] hist_16[0].append(coord['x']) hist_16[1].append(coord['y']) hist_16[2].append(coord['z']) hist_16[3].append(H_16[wCh, gCh]) loc_16 += 1 labels_16.append('Wire Channel: ' + str(wCh) + '<br>' + 'Grid Channel: ' + str(gCh) + '<br>' + 'Counts: ' + str(H_16[wCh, gCh])) # Produce 3D histogram plot labels = [] labels.extend(labels_20) labels.extend(labels_16) # Produce 3D histogram plot hist = [[], [], [], []] hist_x_offset = [i + 100 for i in hist_20[0]] hist_z_offset = [i + 40 for i in hist_16[2]] hist[0].extend(hist_x_offset) hist[0].extend(hist_16[0]) hist[1].extend(hist_20[1]) hist[1].extend(hist_16[1]) hist[2].extend(hist_20[2]) hist[2].extend(hist_z_offset) hist[2].extend(hist_16[2]) hist[3].extend(hist_20[3]) hist[3].extend(hist_16[3]) MG_3D_trace = go.Scatter3d(x=hist[0], y=hist[1], z=hist[2], mode='markers', marker=dict( size=20, color=np.log10(hist[3]), colorscale='Jet', opacity=1, colorbar=dict(thickness=20, title='log10(counts)'), ), text=labels, name='Multi-Grid', scene='scene1') # Introduce figure and put everything together fig = py.tools.make_subplots(rows=1, cols=1, specs=[[{'is_3d': True}]]) # Insert histogram fig.append_trace(MG_3D_trace, 1, 1) # making the axis lengths according to data (important when only three grid rows) fig.update_layout(scene_aspectmode='data') # Assign layout with axis labels, title and camera angle fig['layout']['scene1']['xaxis'].update(title='x [mm]') fig['layout']['scene1']['yaxis'].update(title='y [mm]') fig['layout']['scene1']['zaxis'].update(title='z [mm]') fig['layout'].update(title='Coincidences (3D) \n%s' % data_sets) fig.layout.showlegend = False # If in plot He3-tubes histogram, return traces, else save HTML and plot py.offline.plot(fig, filename='../Results/Coincidences_3D/Ce3Dhistogram.html', auto_open=True)