Example #1
0
    def check_wrong_end(self, track, mom=None, HT=None, maxdist=3):
        """
        See if the algorithm's end segment was correct or not.
        """

        if mom is None and HT is None:
            raise ValueError(
                'Requires either a moments object or a HybridTrack object')

        g4xfull, g4yfull = tp.get_image_xy(track)
        g4x, g4y = g4xfull[0], g4yfull[0]

        # could throw an AttributeError if there were errors in the algorithm
        if mom:
            algx, algy = mom.start_coordinates
        elif HT:
            algx, algy = HT.start_coordinates
        else:
            raise ValueError('bad value in moments or HybridTrack object')

        dist = np.sqrt((algx - g4x)**2 + (algy - g4y)**2)
        self.end_distance = dist
        if dist > maxdist:
            self.wrong_end = True
        else:
            self.wrong_end = False

        self.g4xy = g4x, g4y
        self.algxy = algx, algy
Example #2
0
    def check_wrong_end(self, track, mom=None, HT=None, maxdist=3):
        """
        See if the algorithm's end segment was correct or not.
        """

        if mom is None and HT is None:
            raise ValueError(
                'Requires either a moments object or a HybridTrack object')

        g4xfull, g4yfull = tp.get_image_xy(track)
        g4x, g4y = g4xfull[0], g4yfull[0]

        # could throw an AttributeError if there were errors in the algorithm
        if mom:
            algx, algy = mom.start_coordinates
        elif HT:
            algx, algy = HT.start_coordinates
        else:
            raise ValueError('bad value in moments or HybridTrack object')

        dist = np.sqrt((algx - g4x)**2 + (algy - g4y)**2)
        self.end_distance = dist
        if dist > maxdist:
            self.wrong_end = True
        else:
            self.wrong_end = False

        self.g4xy = g4x, g4y
        self.algxy = algx, algy
Example #3
0
def show_event(ind, track, mom, classifier):
    """
    Plot stuff for one event.

    geant4 is cyan
    ridge-following is light green
    moments is magenta
    """

    if track.g4track.energy_tot_kev < 100:
        print('Low energy event: {} keV'.format(track.g4track.energy_tot_kev))
        return None

    mom.reconstruct()
    try:
        _, HTinfo = ht.reconstruct(track)
    except ht.HybridTrackError:
        HTinfo = None

    # geant4 position
    g4x, g4y = tp.get_image_xy(track)
    g4x0 = np.array([g4x[0], g4y[0]])
    # geant4 direction (radians)
    g4_alpha_deg = track.g4track.alpha_deg
    g4_alpha_rad = g4_alpha_deg * np.pi / 180.0

    # moments
    mom_arc, mom_ep = tp.get_arc2(mom)
    mom_alpha_rad = mom.alpha
    reject_flag, reject_reason = mom_reject(mom)
    mom_da = ev.AlphaUncertainty.delta_alpha(
        g4_alpha_deg, mom_alpha_rad * 180.0 / np.pi)

    # ridge-following
    # HTinfo = track.algorithms['python HT v1.52'].info
    ridge_ep = (HTinfo.ridge[HTinfo.measurement_start_pt].coordinates_pix
                - np.array([1, 1]))
    ridge_alpha_rad = (track.algorithms['python HT v1.52'].alpha_deg
                       * np.pi / 180.0)
    ridge_da = ev.AlphaUncertainty.delta_alpha(
        g4_alpha_deg, ridge_alpha_rad * 180.0 / np.pi)

    titlebase = (
        r'{}' + '\n' +
        r'E={:.0f}keV, $\beta$={:.0f}{deg}, ' +
        r'scattering {:.1f}{deg}, E_end={:.1f}keV' + '\n' +
        r'Rejection: {}' + '\n')
    titlestr = titlebase.format(
        ind,
        track.g4track.energy_tot_kev,
        track.g4track.beta_deg,
        classifier.total_scatter_angle * 180 / np.pi,
        mom.end_energy,
        reject_reason,
        deg=DEG,)
    if np.abs(classifier.g4track.beta_deg) > 60:
        titlestr += '[Beta > 60{}]'.format(DEG)
    if classifier.early_scatter:
        titlestr += ' [Early scatter in 25um]'
    if classifier.overlap:
        titlestr += ' [Overlapping]'
    if classifier.wrong_end:
        titlestr += ' [Wrong end]'

    # PLOTS
    fig = plt.figure()

    # top left: ridge-following, zoomed
    plt.subplot(2, 2, 1)
    # g4
    plot_track(track.image)
    plt.plot(g4y, g4x, '.c')
    tp.plot_arrow(g4x0, g4_alpha_rad, color='c')
    # ridge
    ridge = HTinfo.ridge[HTinfo.measurement_start_pt:HTinfo.measurement_end_pt]
    tp.plot_ridgepoints(
        plt.gca(), ridge, fmtstring='.', offset=[1, 1], color=[0, 1, 0])
    tp.plot_arrow(ridge_ep, ridge_alpha_rad, color=[0, 1, 0])
    # general
    xoff = mom.end_segment_offsets[1]
    yoff = mom.end_segment_offsets[0]
    plt.xlim((xoff - 1, xoff + mom.end_segment_image.shape[1] + 1))
    plt.ylim((yoff - 1, yoff + mom.end_segment_image.shape[0] + 1))
    plt.xlabel('y [pixels]')
    plt.ylabel('x [pixels]')
    plt.colorbar()

    # bottom left: ridge-following, full
    plt.subplot(2, 2, 3)
    # g4
    plot_track(track.image)
    plt.plot(g4y, g4x, '.c')
    tp.plot_arrow(g4x0, g4_alpha_rad, color='c')
    # ridge
    ridge = HTinfo.ridge[HTinfo.measurement_start_pt:HTinfo.measurement_end_pt]
    tp.plot_ridgepoints(
        plt.gca(), ridge, fmtstring='.', offset=[1, 1], color=[0, 1, 0])
    tp.plot_arrow(ridge_ep, ridge_alpha_rad, color=[0, 1, 0])
    # general
    plt.xlim((0, track.image.shape[1] - 1))
    plt.ylim((0, track.image.shape[0] - 1))
    plt.xlabel('y [pixels]')
    plt.ylabel('x [pixels]')
    plt.colorbar()
    plt.title(r'Ridge-following, $\Delta_\alpha$ = {:2.1f}{}'.format(
        ridge_da, DEG))

    # top right: moments, zoomed
    plt.subplot(2, 2, 2)
    # g4
    plot_track(track.image)
    plt.plot(g4y, g4x, '.c')
    tp.plot_arrow(g4x0, g4_alpha_rad, color='c')
    # moments
    plt.plot(mom.box_y, mom.box_x, 'm')
    if reject_flag:
        plt.plot(mom_arc[1, :], mom_arc[0, :], 'm', lw=2.5, ls='dashed')
        tp.plot_arrow(mom_ep, mom_alpha_rad, color='m', ls='dashed')
    else:
        plt.plot(mom_arc[1, :], mom_arc[0, :], 'm', lw=2.5)
        tp.plot_arrow(mom_ep, mom_alpha_rad, color='m')
    # general
    xoff = mom.end_segment_offsets[1]
    yoff = mom.end_segment_offsets[0]
    plt.xlim((xoff - 1, xoff + mom.end_segment_image.shape[1] + 1))
    plt.ylim((yoff - 1, yoff + mom.end_segment_image.shape[0] + 1))
    plt.xlabel('y [pixels]')
    plt.ylabel('x [pixels]')
    plt.colorbar()

    # bottom right: moments, full
    plt.subplot(2, 2, 4)
    # g4
    plot_track(track.image)
    plt.plot(g4y, g4x, '.c')
    tp.plot_arrow(g4x0, g4_alpha_rad, color='c')
    # moments
    plt.plot(mom.box_y, mom.box_x, 'm')
    if reject_flag:
        plt.plot(mom_arc[1, :], mom_arc[0, :], 'm', lw=2.5, ls='dashed')
        tp.plot_arrow(mom_ep, mom_alpha_rad, color='m', ls='dashed')
    else:
        plt.plot(mom_arc[1, :], mom_arc[0, :], 'm', lw=2.5)
        tp.plot_arrow(mom_ep, mom_alpha_rad, color='m')
    # general
    plt.xlim((0, track.image.shape[1] - 1))
    plt.ylim((0, track.image.shape[0] - 1))
    plt.xlabel('y [pixels]')
    plt.ylabel('x [pixels]')
    plt.colorbar()
    plt.title(r'Moments, $\Delta_\alpha$ = {:2.1f}{}'.format(mom_da, DEG))

    fig.suptitle(titlestr)

    figManager = plt.get_current_fig_manager()
    figManager.window.showMaximized()
    plt.show()
    return fig
Example #4
0
def show_event(ind, track, mom, classifier):
    """
    Plot stuff for one event.

    geant4 is cyan
    ridge-following is light green
    moments is magenta
    """

    if track.g4track.energy_tot_kev < 100:
        print('Low energy event: {} keV'.format(track.g4track.energy_tot_kev))
        return None

    mom.reconstruct()
    try:
        _, HTinfo = ht.reconstruct(track)
    except ht.HybridTrackError:
        HTinfo = None

    # geant4 position
    g4x, g4y = tp.get_image_xy(track)
    g4x0 = np.array([g4x[0], g4y[0]])
    # geant4 direction (radians)
    g4_alpha_deg = track.g4track.alpha_deg
    g4_alpha_rad = g4_alpha_deg * np.pi / 180.0

    # moments
    mom_arc, mom_ep = tp.get_arc2(mom)
    mom_alpha_rad = mom.alpha
    reject_flag, reject_reason = mom_reject(mom)
    mom_da = ev.AlphaUncertainty.delta_alpha(g4_alpha_deg,
                                             mom_alpha_rad * 180.0 / np.pi)

    # ridge-following
    # HTinfo = track.algorithms['python HT v1.52'].info
    ridge_ep = (HTinfo.ridge[HTinfo.measurement_start_pt].coordinates_pix -
                np.array([1, 1]))
    ridge_alpha_rad = (track.algorithms['python HT v1.52'].alpha_deg * np.pi /
                       180.0)
    ridge_da = ev.AlphaUncertainty.delta_alpha(g4_alpha_deg,
                                               ridge_alpha_rad * 180.0 / np.pi)

    titlebase = (r'{}' + '\n' + r'E={:.0f}keV, $\beta$={:.0f}{deg}, ' +
                 r'scattering {:.1f}{deg}, E_end={:.1f}keV' + '\n' +
                 r'Rejection: {}' + '\n')
    titlestr = titlebase.format(
        ind,
        track.g4track.energy_tot_kev,
        track.g4track.beta_deg,
        classifier.total_scatter_angle * 180 / np.pi,
        mom.end_energy,
        reject_reason,
        deg=DEG,
    )
    if np.abs(classifier.g4track.beta_deg) > 60:
        titlestr += '[Beta > 60{}]'.format(DEG)
    if classifier.early_scatter:
        titlestr += ' [Early scatter in 25um]'
    if classifier.overlap:
        titlestr += ' [Overlapping]'
    if classifier.wrong_end:
        titlestr += ' [Wrong end]'

    # PLOTS
    fig = plt.figure()

    # top left: ridge-following, zoomed
    plt.subplot(2, 2, 1)
    # g4
    plot_track(track.image)
    plt.plot(g4y, g4x, '.c')
    tp.plot_arrow(g4x0, g4_alpha_rad, color='c')
    # ridge
    ridge = HTinfo.ridge[HTinfo.measurement_start_pt:HTinfo.measurement_end_pt]
    tp.plot_ridgepoints(plt.gca(),
                        ridge,
                        fmtstring='.',
                        offset=[1, 1],
                        color=[0, 1, 0])
    tp.plot_arrow(ridge_ep, ridge_alpha_rad, color=[0, 1, 0])
    # general
    xoff = mom.end_segment_offsets[1]
    yoff = mom.end_segment_offsets[0]
    plt.xlim((xoff - 1, xoff + mom.end_segment_image.shape[1] + 1))
    plt.ylim((yoff - 1, yoff + mom.end_segment_image.shape[0] + 1))
    plt.xlabel('y [pixels]')
    plt.ylabel('x [pixels]')
    plt.colorbar()

    # bottom left: ridge-following, full
    plt.subplot(2, 2, 3)
    # g4
    plot_track(track.image)
    plt.plot(g4y, g4x, '.c')
    tp.plot_arrow(g4x0, g4_alpha_rad, color='c')
    # ridge
    ridge = HTinfo.ridge[HTinfo.measurement_start_pt:HTinfo.measurement_end_pt]
    tp.plot_ridgepoints(plt.gca(),
                        ridge,
                        fmtstring='.',
                        offset=[1, 1],
                        color=[0, 1, 0])
    tp.plot_arrow(ridge_ep, ridge_alpha_rad, color=[0, 1, 0])
    # general
    plt.xlim((0, track.image.shape[1] - 1))
    plt.ylim((0, track.image.shape[0] - 1))
    plt.xlabel('y [pixels]')
    plt.ylabel('x [pixels]')
    plt.colorbar()
    plt.title(r'Ridge-following, $\Delta_\alpha$ = {:2.1f}{}'.format(
        ridge_da, DEG))

    # top right: moments, zoomed
    plt.subplot(2, 2, 2)
    # g4
    plot_track(track.image)
    plt.plot(g4y, g4x, '.c')
    tp.plot_arrow(g4x0, g4_alpha_rad, color='c')
    # moments
    plt.plot(mom.box_y, mom.box_x, 'm')
    if reject_flag:
        plt.plot(mom_arc[1, :], mom_arc[0, :], 'm', lw=2.5, ls='dashed')
        tp.plot_arrow(mom_ep, mom_alpha_rad, color='m', ls='dashed')
    else:
        plt.plot(mom_arc[1, :], mom_arc[0, :], 'm', lw=2.5)
        tp.plot_arrow(mom_ep, mom_alpha_rad, color='m')
    # general
    xoff = mom.end_segment_offsets[1]
    yoff = mom.end_segment_offsets[0]
    plt.xlim((xoff - 1, xoff + mom.end_segment_image.shape[1] + 1))
    plt.ylim((yoff - 1, yoff + mom.end_segment_image.shape[0] + 1))
    plt.xlabel('y [pixels]')
    plt.ylabel('x [pixels]')
    plt.colorbar()

    # bottom right: moments, full
    plt.subplot(2, 2, 4)
    # g4
    plot_track(track.image)
    plt.plot(g4y, g4x, '.c')
    tp.plot_arrow(g4x0, g4_alpha_rad, color='c')
    # moments
    plt.plot(mom.box_y, mom.box_x, 'm')
    if reject_flag:
        plt.plot(mom_arc[1, :], mom_arc[0, :], 'm', lw=2.5, ls='dashed')
        tp.plot_arrow(mom_ep, mom_alpha_rad, color='m', ls='dashed')
    else:
        plt.plot(mom_arc[1, :], mom_arc[0, :], 'm', lw=2.5)
        tp.plot_arrow(mom_ep, mom_alpha_rad, color='m')
    # general
    plt.xlim((0, track.image.shape[1] - 1))
    plt.ylim((0, track.image.shape[0] - 1))
    plt.xlabel('y [pixels]')
    plt.ylabel('x [pixels]')
    plt.colorbar()
    plt.title(r'Moments, $\Delta_\alpha$ = {:2.1f}{}'.format(mom_da, DEG))

    fig.suptitle(titlestr)

    figManager = plt.get_current_fig_manager()
    figManager.window.showMaximized()
    plt.show()
    return fig