Exemple #1
0
def PHS_1D_plot(window):
    def PHS_1D_plot_bus(clusters, typeCh, sub_title, number_bins):
        # Plot
        plt.title(sub_title)
        plt.xlabel('Collected charge [ADC channels]')
        plt.ylabel('Counts')
        plt.grid(True, which='major', zorder=0)
        plt.grid(True, which='minor', linestyle='--', zorder=0)
        plt.yscale('log')
        if wg == 'g':
            adcs = clusters['gADC_m1'].append(clusters['gADC_m2'])
        else:
            adcs = clusters['wADC_m1']
        plt.hist(adcs,
                 bins=number_bins,
                 range=[0, 4095],
                 histtype='step',
                 color='black',
                 zorder=5)

    # Import data
    df_20 = window.Clusters_20_layers
    df_16 = window.Clusters_16_layers
    # Intial filter
    clusters_20 = filter_clusters(df_20, window)
    clusters_16 = filter_clusters(df_16, window)

    # Declare parameters
    number_bins = int(window.phsBins.text())
    wg_list = ['w', 'g']
    grids_or_wires = {'w': 'Wires', 'g': 'Grids'}

    # Prepare figure
    fig = plt.figure()
    title = 'PHS (1D)\n(%s, ...)' % window.data_sets.splitlines()[0]
    fig.suptitle(title, x=0.5, y=1.03)
    fig.set_figheight(4)
    fig.set_figwidth(10)

    # Plot figure for 20 layers
    for i, wg in enumerate(wg_list):
        plt.subplot(2, 2, i + 1)
        sub_title = grids_or_wires[wg] + " -- 20 layers"
        PHS_1D_plot_bus(clusters_20, wg, sub_title, number_bins)
    plt.tight_layout()

    # Plot figure for 16 layers
    for i, wg in enumerate(wg_list):
        plt.subplot(2, 2, i + 3)
        sub_title = grids_or_wires[wg] + " -- 16 layers"
        PHS_1D_plot_bus(clusters_16, wg, sub_title, number_bins)
    plt.tight_layout()

    return fig
Exemple #2
0
 def rate_action(self):
     if self.data_sets != '':
         # Declare clusters
         ce_20 = self.Clusters_20_layers
         ce_16 = self.Clusters_16_layers
         # Filter
         ce_red_20 = filter_clusters(ce_20, self)
         ce_red_16 = filter_clusters(ce_16, self)
         # Get measurement time
         measurement_time = self.get_measurement_time()
         rate_20 = ce_red_20.shape[0]/measurement_time
         rate_16 = ce_red_16.shape[0]/measurement_time
         print('Rate 20 layers: %f Hz' % rate_20)
         print('Rate 16 layers: %f Hz' % rate_16)
Exemple #3
0
def Coincidences_2D_plot(window):
    # Declare parameters (added with condition if empty array)
    data_sets = window.data_sets.splitlines()[0]
    df_20 = window.Clusters_20_layers
    df_16 = window.Clusters_16_layers
    # Intial filter
    clusters_20 = filter_clusters(df_20, window)
    clusters_16 = filter_clusters(df_16, window)
    #print(clusters_20)
    clusters_vec = [clusters_20, clusters_16]
    clusters_dict = {
        'ce_20': {
            'w': None,
            'g': None
        },
        'ce_16': {
            'w': None,
            'g': None
        }
    }
    # Select grids with highest collected charge
    for clusters, name in zip(clusters_vec, ['ce_20', 'ce_16']):
        #print('gADC_m1')
        #print(clusters['gADC_m1'])
        #print('gADC_m2')
        #print(clusters['gADC_m2'])
        #print('gCh_m1')
        #print(clusters['gCh_m1'])
        #print('gCh_2')
        #print(clusters['gCh_m2'])
        #print('wADC_m1')
        #print(clusters['wADC_m1'])
        #print('wCh_m1')
        #print(clusters['gCh_m1'])
        channels_g1 = clusters[
            clusters['gADC_m1'] > clusters['gADC_m2']]['gCh_m1']
        channels_w1 = clusters[
            clusters['gADC_m1'] > clusters['gADC_m2']]['wCh_m1']
        channels_g2 = clusters[
            clusters['gADC_m1'] <= clusters['gADC_m2']]['gCh_m2']
        channels_w2 = clusters[
            clusters['gADC_m1'] <= clusters['gADC_m2']]['wCh_m1']
        clusters_dict[name]['g'] = channels_g1.append(channels_g2)
        clusters_dict[name]['w'] = channels_w1.append(channels_w2)

    fig = plt.figure()
    plt.subplot(1, 2, 1)
    plt.title('16 layers')

    hist_all = plt.hist2d(clusters_dict['ce_16']['w'],
                          clusters_dict['ce_16']['g'],
                          bins=[64, 12],
                          range=[[-0.5, 63.5], [-0.5, 11.5]],
                          norm=LogNorm(),
                          cmap='jet')
    hist = hist_all[0]
    els = []
    for row in hist:
        for i in row:
            els.append(i)
    max_16 = max(els)
    min_16 = min(els)
    if min_16 == 0:
        min_16 = 1
    plt.xlabel('Wires')
    plt.ylabel('Grids')
    plt.colorbar()
    plt.subplot(1, 2, 2)
    plt.title('20 layers')
    plt.hist2d(clusters_dict['ce_20']['w'],
               clusters_dict['ce_20']['g'],
               bins=[80, 12],
               range=[[-0.5, 79.5], [-0.5, 11.5]],
               norm=LogNorm(),
               cmap='jet',
               vmin=min_16,
               vmax=max_16)
    print("Using color axis from 16-layers plot also for 20-layers plot")
    plt.xlabel('Wires')
    plt.ylabel('Grids')
    fig.suptitle('Coincident events (2D) -- Data set(s): %s' % data_sets)
    plt.colorbar()
    plt.tight_layout()

    return fig
Exemple #4
0
def Coincidences_3D_plot(window):
    # Intial filter
    #df = filter_clusters(df, window)
    df_20 = window.Clusters_20_layers
    df_16 = window.Clusters_16_layers
    #print(df_20[['wCh_m1', 'gCh_m1']])
    # Intial filter
    clusters_20 = filter_clusters(df_20, window)
    clusters_16 = filter_clusters(df_16, window)
    clusters_vec = [clusters_20, clusters_16]
    clusters_dict = {
        'ce_20': {
            'w': None,
            'g': None
        },
        'ce_16': {
            'w': None,
            'g': None
        }
    }
    # Select grids with highest collected charge
    for clusters, name in zip(clusters_vec, ['ce_20', 'ce_16']):
        channels_g1 = clusters[
            clusters['gADC_m1'] > clusters['gADC_m2']]['gCh_m1']
        channels_w1 = clusters[
            clusters['gADC_m1'] > clusters['gADC_m2']]['wCh_m1']
        channels_g2 = clusters[
            clusters['gADC_m1'] <= clusters['gADC_m2']]['gCh_m2']
        channels_w2 = clusters[
            clusters['gADC_m1'] <= clusters['gADC_m2']]['wCh_m1']
        clusters_dict[name]['g'] = channels_g1.append(channels_g2)
        clusters_dict[name]['w'] = channels_w1.append(channels_w2)

    # 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(window)
    #print(MG24_ch_to_coord_16)

    #print("20 wires", clusters_dict['ce_20']['w'].values)
    #print("20 grids", clusters_dict['ce_20']['g'].values)
    ##wires = clusters_dict['ce_20']['w']
    #print(np.array([clusters_dict['ce_20']['w'].values,
    #                clusters_dict['ce_20']['g'].values]))

    # Calculate 3D histogram
    H_20, edges_20 = np.histogramdd((clusters_dict['ce_20']['w'].values,
                                     clusters_dict['ce_20']['g'].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]))
    # for 16 layers
    H_16, edges_16 = np.histogramdd((clusters_dict['ce_16']['w'].values,
                                     clusters_dict['ce_16']['g'].values),
                                    bins=(64, 13),
                                    range=((0, 64), (0, 13)))

    # Insert results into an array
    hist_16 = [[], [], [], []]
    loc_16 = 0
    labels_16 = []
    for wCh in range(0, 64):
        for gCh in range(0, 13):
            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]))

    #print("hist20", hist_20[3])
    #print("hist16", hist_16[3])

    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[3].extend(hist_20[3])
    hist[3].extend(hist_16[3])

    #print(hist_20[0])
    #print("hist0", hist[0])
    #print("hist1", hist[1])
    #print("hist2", hist[2])
    #print("hist3", hist[3])
    MG_3D_trace = go.Scatter3d(
        x=hist[0],
        y=hist[1],
        z=hist[2],
        mode='markers',
        marker=dict(
            size=20,
            color=hist[3],  #(np.log10(hist[3])),
            colorscale='Jet',
            opacity=1,
            colorbar=dict(thickness=20, title='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)
    # 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) - ' + window.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)
Exemple #5
0
def Channels_rates_plot(window, measurement_time):
    """plots neutron event rate for each channel"""
    def channel_rates_plot_bus(events, subtitle, typeCh, name, 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 = 0
                vals = clusters_dict[name]['g'].values
                for val in vals:
                    if val == gCh:
                        counts += 1
                rate = counts / ((measurement_time))
                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 = 0
                vals = clusters_dict[name]['w'].values
                for val in vals:
                    if val == wCh:
                        counts += 1
                rate = counts / ((measurement_time))
                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)

    # Import data
    ce_20 = window.Clusters_20_layers
    ce_16 = window.Clusters_16_layers
    # Filter
    ce_red_20 = filter_clusters(ce_20, window)
    ce_red_16 = filter_clusters(ce_16, window)
    clusters_20 = ce_red_20  #.shape[0]
    clusters_16 = ce_red_16  #.shape[0]
    clusters_vec = [clusters_20, clusters_16]
    clusters_dict = {
        'ce_20': {
            'w': None,
            'g': None
        },
        'ce_16': {
            'w': None,
            'g': None
        }
    }
    # Select grids with highest collected charge
    for clusters, name in zip(clusters_vec, ['ce_20', 'ce_16']):
        channels_g1 = clusters[
            clusters['gADC_m1'] > clusters['gADC_m2']]['gCh_m1']
        channels_w1 = clusters[
            clusters['gADC_m1'] > clusters['gADC_m2']]['wCh_m1']
        channels_g2 = clusters[
            clusters['gADC_m1'] <= clusters['gADC_m2']]['gCh_m2']
        channels_w2 = clusters[
            clusters['gADC_m1'] <= clusters['gADC_m2']]['wCh_m1']
        clusters_dict[name]['g'] = channels_g1.append(channels_g2)
        clusters_dict[name]['w'] = channels_w1.append(channels_w2)

    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 \n%s' %
                 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
        name = 'ce_20'
        plt.subplot(2, 2, i + 1)
        channel_rates_plot_bus(clusters_20, sub_title, typeCh, name, wires)

    # for 16 layers
    for i, typeCh in enumerate(typeChs):
        sub_title = "%s -- 16 layers" % grids_or_wires[typeCh]
        name = 'ce_16'
        plt.subplot(2, 2, i + 3)
        wires = 64
        channel_rates_plot_bus(clusters_16, sub_title, typeCh, name, wires)

    plt.subplots_adjust(left=0.1,
                        right=0.98,
                        top=0.86,
                        bottom=0.09,
                        wspace=0.25,
                        hspace=0.45)
    return fig
Exemple #6
0
def PHS_2D_plot(window):
    def PHS_2D_plot_bus(clusters, wg, limit, bins, sub_title, vmin, vmax):
        plt.xlabel('Channel')
        plt.ylabel('Charge [ADC channels]')
        plt.title(sub_title)
        if wg == 'g':
            channels = clusters['gCh_m1'].append(clusters['gCh_m2'])
            adcs = clusters['gADC_m1'].append(clusters['gADC_m2'])
        else:
            channels = clusters['wCh_m1']
            adcs = clusters['wADC_m1']
        plt.hist2d(
            channels,
            adcs,
            bins=[bins, 120],
            range=[limit, [0, 4095]],
            norm=LogNorm(),
            #vmin=vmin, vmax=vmax,
            cmap='jet')
        plt.colorbar()

    # Import data
    df_20 = window.Clusters_20_layers
    df_16 = window.Clusters_16_layers
    # Intial filter
    clusters_20 = filter_clusters(df_20, window)
    clusters_16 = filter_clusters(df_16, window)

    # Declare parameters
    wg_list = ['w', 'g']
    limits_16 = [[-0.5, 63.5], [-0.5, 11.5]]
    bins_16 = [64, 12]
    limits_20 = [[-0.5, 79.5], [-0.5, 11.5]]
    bins_20 = [80, 12]
    grids_or_wires = {'w': 'Wires', 'g': 'Grids'}

    # Prepare figure
    fig = plt.figure()
    title = 'PHS (2D) - MG\n(%s, ...)' % window.data_sets.splitlines()[0]
    fig.suptitle(title, x=0.5, y=1.03)
    vmin = 1
    vmax_16 = clusters_16.shape[0] // 1000 + 100
    vmax_20 = clusters_20.shape[0] // 1000 + 100
    fig.set_figheight(4)
    fig.set_figwidth(10)
    # Plot figure
    for i, (wg, limit_16,
            bins_16) in enumerate(zip(wg_list, limits_16, bins_16)):
        # Filter events based on wires or grids
        plt.subplot(2, 2, i + 1)
        sub_title = grids_or_wires[wg] + " -- 16 layers"
        PHS_2D_plot_bus(clusters_16, wg, limit_16, bins_16, sub_title, vmin,
                        vmax_16)
    plt.tight_layout()

    for i, (wg, limit_20,
            bins_20) in enumerate(zip(wg_list, limits_20, bins_20)):
        # Filter events based on wires or grids
        plt.subplot(2, 2, i + 3)
        sub_title = grids_or_wires[wg] + " -- 20 layers"
        PHS_2D_plot_bus(clusters_20, wg, limit_20, bins_20, sub_title, vmin,
                        vmax_20)
    plt.tight_layout()

    return fig
Exemple #7
0
def PHS_Individual_plot(window):
    # Import data
    df_20 = window.Clusters_20_layers
    df_16 = window.Clusters_16_layers
    # Intial filter
    clusters_16 = filter_clusters(df_16, window)
    clusters_20 = filter_clusters(df_20, window)
    # Declare parameters
    clusters_vec = [clusters_16, clusters_20]
    detectors = ['16_layers', '20_layers']
    layers_vec = [16, 20]
    dir_name = os.path.dirname(__file__)
    folder_path = os.path.join(dir_name, '../../Results/PHS/')
    number_bins = int(window.phsBins.text())
    # Save all PHS
    for clusters, detector, layers in zip(clusters_vec, detectors, layers_vec):
        # Save wires PHS
        for wCh in np.arange(0, layers * 4, 1):
            print('%s, Wires: %d/%d' % (detector, wCh, layers * 4 - 1))
            # Get ADC values
            adcs = clusters[clusters.wCh_m1 == wCh]['wADC_m1']
            # Plot
            fig = plt.figure()
            plt.hist(adcs,
                     bins=number_bins,
                     range=[0, 4095],
                     histtype='step',
                     color='black',
                     zorder=5)
            plt.grid(True, which='major', zorder=0)
            plt.grid(True, which='minor', linestyle='--', zorder=0)
            plt.xlabel('Collected charge [ADC channels]')
            plt.ylabel('Counts')
            plt.title('PHS wires - Channel %d\nData set: %s' %
                      (wCh, window.data_sets))
            # Save
            output_path = '%s/%s/Wires/Channel_%d.pdf' % (folder_path,
                                                          detector, wCh)
            fig.savefig(output_path, bbox_inches='tight')
            plt.close()
        # Save grids PHS
        for gCh in np.arange(0, 12, 1):
            print('%s, Grids: %d/11' % (detector, gCh))
            # Get ADC values
            adcs_1 = clusters[clusters.gCh_m1 == gCh]['gADC_m1']
            adcs_2 = clusters[clusters.gCh_m2 == gCh]['gADC_m2']
            adcs = adcs_1.append(adcs_2)
            # Plot
            fig = plt.figure()
            plt.hist(adcs,
                     bins=number_bins,
                     range=[0, 4095],
                     histtype='step',
                     color='black',
                     zorder=5)
            plt.grid(True, which='major', zorder=0)
            plt.grid(True, which='minor', linestyle='--', zorder=0)
            plt.xlabel('Collected charge [ADC channels]')
            plt.ylabel('Counts')
            plt.title('PHS grids - Channel %d\nData set: %s' %
                      (gCh, window.data_sets))
            # Save
            output_path = '%s/%s/Grids/Channel_%d.pdf' % (folder_path,
                                                          detector, gCh)
            fig.savefig(output_path, bbox_inches='tight')
            plt.close()