示例#1
0
def plot_PLU_filter(folder):
    fp = files.get_msmt_fp(folder)

    # get the PLU marked photons first
    is_ph_ch0, is_ph_ch1 = events.get_photons(fp)
    is_ph = is_ph_ch0 | is_ph_ch1
    is_ph_with_PLU_mrkr = is_ph & events.filter_marker(fp, 2)

    # first window
    fig, (ax0, ax1) = plot_photon_hist_filter_comparison(
        fp, save=False, fltr=is_ph_with_PLU_mrkr, log=True,
        binedges=settings.PHOTONHIST_BINEDGES)

    ax0.axvline(settings.CH0_START, color='k', linestyle='--')
    ax0.text(settings.CH0_START+1, 1, '{} ns'.format(settings.CH0_START), color='k')
    ax0.legend()
    ax0.set_title('PLU (hardware) filter first pi-pulse ch0')

    ax1.axvline(settings.CH1_START, color='k', linestyle='--')
    ax1.text(settings.CH1_START+1, 1, '{} ns'.format(settings.CH1_START), color='k')
    ax1.legend()
    ax1.set_title('PLU (hardware) filter first pi-pulse ch1')

    fig.savefig(os.path.join(folder, 'PLU_photons_window1.png'))

    # second window
    fig, (ax0, ax1) = plot_photon_hist_filter_comparison(
        fp, save=False, fltr=is_ph_with_PLU_mrkr, log=True,
        binedges=settings.PHOTONHIST_BINEDGES + settings.PIPULSESEP)

    ax0.axvline(settings.CH0_START+settings.PIPULSESEP, color='k', linestyle='--')
    ax0.text(settings.CH0_START+settings.PIPULSESEP+1, 
        1, '{} ns'.format(settings.CH0_START+settings.PIPULSESEP), color='k')
    ax0.legend()
    ax0.set_title('PLU (hardware) filter second pi-pulse ch0')

    ax1.axvline(settings.CH1_START+settings.PIPULSESEP, color='k', linestyle='--')
    ax1.text(settings.CH1_START+settings.PIPULSESEP+1, 
        1, '{} ns'.format(settings.CH1_START+settings.PIPULSESEP), color='k')
    ax1.legend()
    ax1.set_title('PLU (hardware) filter second pi-pulse ch1')
     
    fig.savefig(os.path.join(folder, 'PLU_photons_window2.png'))
示例#2
0
def get_teleportation_events(folder, force_eval=False, verbose=True):
    fp = files.get_msmt_fp(folder)
    fname = files.get_msmt_name(fp)

    if files.has_analysis_data(fp, 'teleportation_events') and not force_eval:
        tev, _a = files.get_analysis_data(fp, 'teleportation_events')
        return tev

    f = h5py.File(fp, 'r')
    sync_times = f['/HH_sync_time-1'].value * 1e-3  # we prefer ns over ps
    sync_numbers = f['/HH_sync_number-1'].value
    channels = f['/HH_channel-1'].value
    abs_times = f['/HH_time-1'].value
    ad1_reps = f['{}/adwin_lt1_data/completed_reps'.format(fname)].value
    ad1_ssro1 = f['{}/adwin_lt1_data/SSRO1_results'.format(fname)].value
    ad1_ssro2 = f['{}/adwin_lt1_data/SSRO2_results'.format(fname)].value
    ad2_reps = f['{}/adwin_lt2_data/completed_reps'.format(fname)].value
    ad2_ssro = f['{}/adwin_lt2_data/SSRO_lt2_data'.format(fname)].value
    ad1_CR_before = f['{}/adwin_lt1_data/CR_before'.format(fname)].value
    ad2_CR_before = f['{}/adwin_lt2_data/CR_before'.format(fname)].value
    ad1_CR_after = f['{}/adwin_lt1_data/CR_after'.format(fname)].value
    ad2_CR_after = f['{}/adwin_lt2_data/CR_after'.format(fname)].value

    seq_reps = int(f['{}'.format(fname)].attrs['LDE_attempts_before_CR'])

    f.close()

    # binary encoding: 0 = 00, 1 = 01, 2 = 10, 3 = 11
    BSM_outcomes = (2**1 * ad1_ssro2) + (2**0 * ad1_ssro1)

    ### First the HH events
    PLU_mrkr = 2
    psiminus_mrkr = 3
    psiplus_mrkr = 4
    # this conversion might be neccesary due to a wrong conversion in T2_tools.pyx
    # of the channel bits from a uint_32 to a uint_8.
    is_PLU_mrkr = get_markers(fp, 2**(PLU_mrkr - 1))
    has_same_sync_number_as_PLU_mrkr = filter_marker(fp, 2**(PLU_mrkr - 1))
    is_psiplus_mrkr = get_markers(fp, 2**(psiplus_mrkr - 1))
    is_psiminus_mrkr = get_markers(fp, 2**(psiminus_mrkr - 1))
    has_same_sync_number_as_psiminus_mrkr = filter_marker(
        fp, 2**(psiminus_mrkr - 1))

    is_ph_ch0, is_ph_ch1 = get_photons(fp)
    is_ph = is_ph_ch0 | is_ph_ch1

    is_ph_with_PLU_mrkr = is_ph & filter_marker(fp, 2**(PLU_mrkr - 1))
    is_ph0_with_PLU_mrkr = is_ph_ch0 & filter_marker(fp, 2**(PLU_mrkr - 1))
    is_ph1_with_PLU_mrkr = is_ph_ch1 & filter_marker(fp, 2**(PLU_mrkr - 1))
    is_ph0_with_psiminus_mrkr = is_ph_ch0 & filter_marker(
        fp, 2**(psiminus_mrkr - 1))
    is_ph1_with_psiminus_mrkr = is_ph_ch1 & filter_marker(
        fp, 2**(psiminus_mrkr - 1))

    if settings.VERBOSE:

        print
        print fp
        print
        print 'HH data'
        print '-------'
        print 'Number of PLU markers received:', len(np.where(is_PLU_mrkr)[0])
        print 'Number of Psi+ markers received:', len(
            np.where(is_psiplus_mrkr)[0])
        print 'Number of Psi- markers received:', len(
            np.where(is_psiminus_mrkr)[0])
        print 'Number of photons with the same sync as a PLU marker:', len(
            np.where(is_ph_with_PLU_mrkr)[0])
        print '    ch0:', len(np.where(is_ph0_with_PLU_mrkr)[0])
        print '    ch1:', len(np.where(is_ph1_with_PLU_mrkr)[0])

    is_ph0_with_PLU_mrkr_in_first_window = is_ph0_with_PLU_mrkr & \
        filter_synctime(sync_times, settings.CH0_START,settings.CH0_STOP)
    is_ph1_with_PLU_mrkr_in_first_window = is_ph1_with_PLU_mrkr & \
        filter_synctime(sync_times, settings.CH1_START, settings.CH1_STOP)
    is_ph_with_PLU_mrkr_in_first_window = is_ph0_with_PLU_mrkr_in_first_window | \
        is_ph1_with_PLU_mrkr_in_first_window

    if settings.VERBOSE:

        print
        print 'Number of PLU-marked photons in first window:', \
            len(np.where(is_ph_with_PLU_mrkr_in_first_window)[0])

    is_ph0_with_PLU_mrkr_in_second_window = is_ph0_with_PLU_mrkr & filter_synctime(
        sync_times, settings.CH0_START + settings.PIPULSESEP,
        settings.CH0_STOP + settings.PIPULSESEP)
    is_ph1_with_PLU_mrkr_in_second_window = is_ph1_with_PLU_mrkr & filter_synctime(
        sync_times, settings.CH1_START + settings.PIPULSESEP,
        settings.CH1_STOP + settings.PIPULSESEP)
    is_ph_with_PLU_mrkr_in_second_window = is_ph0_with_PLU_mrkr_in_second_window | \
        is_ph1_with_PLU_mrkr_in_second_window

    if settings.VERBOSE:

        print 'Number of PLU-marked photons in second window:', \
            len(np.where(is_ph_with_PLU_mrkr_in_second_window)[0])

    LDE_ph0_sync_times = sync_times[is_ph0_with_PLU_mrkr]
    LDE_ph0_sync_numbers = sync_numbers[is_ph0_with_PLU_mrkr]
    LDE_ph1_sync_times = sync_times[is_ph1_with_PLU_mrkr]
    LDE_ph1_sync_numbers = sync_numbers[is_ph1_with_PLU_mrkr]
    PLU_mrkr_sync_numbers = sync_numbers[is_PLU_mrkr]
    PLU_mrkr_abs_times = abs_times[is_PLU_mrkr]
    psi_minus_mrkr_sync_numbers = sync_numbers[is_psiminus_mrkr]
    psi_plus_mrkr_sync_numbers = sync_numbers[is_psiplus_mrkr]

    attempts = np.zeros(PLU_mrkr_sync_numbers.size)
    of = 0
    for i, sn in enumerate(PLU_mrkr_sync_numbers):
        a = (sn - of) % seq_reps
        of = sn
        attempts[i] = a

    ### Adwin SSROs
    if settings.VERBOSE:

        print
        print 'Adwin LT1'
        print '---------'
        print 'Number of events:', ad1_reps,
        if ad1_reps != len(np.where(is_PLU_mrkr)[0]):
            raise Exception(
                fp +
                '\nAdwin LT1 events do not match HH events - data set seems faulty :('
            )
        else:
            print 'OK :)'

        print
        print 'Adwin LT2'
        print '---------'
        print 'Number of events:', ad2_reps,
        if ad2_reps != len(np.where(is_PLU_mrkr)[0]):
            raise Exception(
                fp +
                '\nAdwin LT2 events do not match HH events - data set seems faulty :('
            )
        else:
            print 'OK :)'

    # columns: sync no | attempt | ph1 arrival time | ph1 ch | ph2 arrival time | ph2 ch | dt | BSM outcome | Bob outcome |
    #          LDE_type (1 = psi-, 0 = psi+) | CR before 1 | CR after 1 | CR before 2 | CR after 2 | PLU mrkr abs. time
    teleportation_events = np.empty((0, 15))

    for i, s in enumerate(PLU_mrkr_sync_numbers):
        attempt = attempts[i]

        _ph0 = LDE_ph0_sync_numbers == s
        _ph1 = LDE_ph1_sync_numbers == s

        if len(LDE_ph0_sync_numbers[_ph0]) == 1 and len(
                LDE_ph1_sync_numbers[_ph1]) == 1:
            psiminus = 1
            stimes = np.array(
                [LDE_ph0_sync_times[_ph0],
                 LDE_ph1_sync_times[_ph1]]).reshape(-1)
            chans = np.array([0, 1])

        elif len(LDE_ph0_sync_numbers[_ph0]) == 2 and len(
                LDE_ph1_sync_numbers[_ph1]) == 0:
            psiminus = 0
            stimes = LDE_ph0_sync_times[_ph0].reshape(-1)
            chans = np.array([0, 0])

        elif len(LDE_ph0_sync_numbers[_ph0]) == 0 and len(
                LDE_ph1_sync_numbers[_ph1]) == 2:
            psiminus = 0
            stimes = LDE_ph1_sync_times[_ph1].reshape(-1)
            chans = np.array([1, 1])

        else:
            continue

        idx = np.argsort(stimes)
        atimes = stimes[idx]
        atimes[1] -= settings.PIPULSESEP
        chans = chans[idx]
        dt = atimes[1] - atimes[0]

        _evnt = np.array([
            s,
            attempt,
            atimes[0],
            chans[0],
            atimes[1],
            chans[1],
            dt,
            BSM_outcomes[i],
            ad2_ssro[i],
            psiminus,
            ad1_CR_before[i],
            ad1_CR_after[i],
            ad2_CR_before[i],
            ad2_CR_after[i],
            PLU_mrkr_abs_times[i],
        ])

        teleportation_events = np.vstack((teleportation_events, _evnt))

    if settings.VERBOSE:
        print
        print 'Found {} valid teleportation events.'.format(
            int(len(teleportation_events)))
        print '===================================='
        print

    files.set_analysis_data(fp, 'teleportation_events', teleportation_events)

    return teleportation_events
示例#3
0
def get_teleportation_events(folder, force_eval=False, verbose=True):
    fp = files.get_msmt_fp(folder)
    fname = files.get_msmt_name(fp)

    if files.has_analysis_data(fp, 'teleportation_events') and not force_eval:
        tev, _a = files.get_analysis_data(fp, 'teleportation_events')
        return tev

    f = h5py.File(fp, 'r')
    sync_times = f['/HH_sync_time-1'].value * 1e-3 # we prefer ns over ps
    sync_numbers = f['/HH_sync_number-1'].value
    channels = f['/HH_channel-1'].value
    abs_times = f['/HH_time-1'].value
    ad1_reps = f['{}/adwin_lt1_data/completed_reps'.format(fname)].value
    ad1_ssro1 = f['{}/adwin_lt1_data/SSRO1_results'.format(fname)].value
    ad1_ssro2 = f['{}/adwin_lt1_data/SSRO2_results'.format(fname)].value
    ad2_reps = f['{}/adwin_lt2_data/completed_reps'.format(fname)].value
    ad2_ssro = f['{}/adwin_lt2_data/SSRO_lt2_data'.format(fname)].value
    ad1_CR_before = f['{}/adwin_lt1_data/CR_before'.format(fname)].value
    ad2_CR_before = f['{}/adwin_lt2_data/CR_before'.format(fname)].value
    ad1_CR_after = f['{}/adwin_lt1_data/CR_after'.format(fname)].value
    ad2_CR_after = f['{}/adwin_lt2_data/CR_after'.format(fname)].value
    
    seq_reps = int(f['{}'.format(fname)].attrs['LDE_attempts_before_CR'])

    f.close()

    # binary encoding: 0 = 00, 1 = 01, 2 = 10, 3 = 11
    BSM_outcomes = (2**1 * ad1_ssro2) + (2**0 * ad1_ssro1)

    ### First the HH events
    PLU_mrkr = 2
    psiminus_mrkr = 3
    psiplus_mrkr = 4
    # this conversion might be neccesary due to a wrong conversion in T2_tools.pyx
    # of the channel bits from a uint_32 to a uint_8. 
    is_PLU_mrkr = get_markers(fp, 2**(PLU_mrkr-1))
    has_same_sync_number_as_PLU_mrkr = filter_marker(fp, 2**(PLU_mrkr-1))
    is_psiplus_mrkr = get_markers(fp, 2**(psiplus_mrkr-1))
    is_psiminus_mrkr = get_markers(fp, 2**(psiminus_mrkr-1))
    has_same_sync_number_as_psiminus_mrkr = filter_marker(fp, 2**(psiminus_mrkr-1))

    is_ph_ch0, is_ph_ch1 = get_photons(fp)
    is_ph = is_ph_ch0 | is_ph_ch1

    is_ph_with_PLU_mrkr = is_ph & filter_marker(fp, 2**(PLU_mrkr-1))
    is_ph0_with_PLU_mrkr = is_ph_ch0 & filter_marker(fp, 2**(PLU_mrkr-1))
    is_ph1_with_PLU_mrkr = is_ph_ch1 & filter_marker(fp, 2**(PLU_mrkr-1))
    is_ph0_with_psiminus_mrkr = is_ph_ch0 & filter_marker(fp, 2**(psiminus_mrkr-1))
    is_ph1_with_psiminus_mrkr = is_ph_ch1 & filter_marker(fp, 2**(psiminus_mrkr-1))

    if settings.VERBOSE:

        print
        print fp
        print
        print 'HH data'
        print '-------'
        print 'Number of PLU markers received:', len(np.where(is_PLU_mrkr)[0])
        print 'Number of Psi+ markers received:', len(np.where(is_psiplus_mrkr)[0])
        print 'Number of Psi- markers received:', len(np.where(is_psiminus_mrkr)[0])
        print 'Number of photons with the same sync as a PLU marker:', len(np.where(is_ph_with_PLU_mrkr)[0])
        print '    ch0:', len(np.where(is_ph0_with_PLU_mrkr)[0])
        print '    ch1:', len(np.where(is_ph1_with_PLU_mrkr)[0])

    is_ph0_with_PLU_mrkr_in_first_window = is_ph0_with_PLU_mrkr & \
        filter_synctime(sync_times, settings.CH0_START,settings.CH0_STOP)
    is_ph1_with_PLU_mrkr_in_first_window = is_ph1_with_PLU_mrkr & \
        filter_synctime(sync_times, settings.CH1_START, settings.CH1_STOP)
    is_ph_with_PLU_mrkr_in_first_window = is_ph0_with_PLU_mrkr_in_first_window | \
        is_ph1_with_PLU_mrkr_in_first_window

    if settings.VERBOSE:

        print
        print 'Number of PLU-marked photons in first window:', \
            len(np.where(is_ph_with_PLU_mrkr_in_first_window)[0])

    is_ph0_with_PLU_mrkr_in_second_window = is_ph0_with_PLU_mrkr & filter_synctime(sync_times, 
        settings.CH0_START+settings.PIPULSESEP, 
        settings.CH0_STOP+settings.PIPULSESEP)
    is_ph1_with_PLU_mrkr_in_second_window = is_ph1_with_PLU_mrkr & filter_synctime(sync_times, 
        settings.CH1_START+settings.PIPULSESEP, 
        settings.CH1_STOP+settings.PIPULSESEP)
    is_ph_with_PLU_mrkr_in_second_window = is_ph0_with_PLU_mrkr_in_second_window | \
        is_ph1_with_PLU_mrkr_in_second_window

    if settings.VERBOSE:

        print 'Number of PLU-marked photons in second window:', \
            len(np.where(is_ph_with_PLU_mrkr_in_second_window)[0])

    LDE_ph0_sync_times = sync_times[is_ph0_with_PLU_mrkr]
    LDE_ph0_sync_numbers = sync_numbers[is_ph0_with_PLU_mrkr]
    LDE_ph1_sync_times = sync_times[is_ph1_with_PLU_mrkr]
    LDE_ph1_sync_numbers = sync_numbers[is_ph1_with_PLU_mrkr]
    PLU_mrkr_sync_numbers = sync_numbers[is_PLU_mrkr]
    PLU_mrkr_abs_times = abs_times[is_PLU_mrkr]
    psi_minus_mrkr_sync_numbers = sync_numbers[is_psiminus_mrkr]
    psi_plus_mrkr_sync_numbers = sync_numbers[is_psiplus_mrkr]

    attempts = np.zeros(PLU_mrkr_sync_numbers.size)
    of = 0
    for i, sn in enumerate(PLU_mrkr_sync_numbers):
        a = (sn-of) % seq_reps
        of = sn
        attempts[i] = a

    ### Adwin SSROs
    if settings.VERBOSE:

        print 
        print 'Adwin LT1'
        print '---------'
        print 'Number of events:', ad1_reps,
        if ad1_reps != len(np.where(is_PLU_mrkr)[0]):
            raise Exception(fp + '\nAdwin LT1 events do not match HH events - data set seems faulty :(')
        else:
            print 'OK :)'
            
        print 
        print 'Adwin LT2'
        print '---------'
        print 'Number of events:', ad2_reps,
        if ad2_reps != len(np.where(is_PLU_mrkr)[0]):
            raise Exception(fp+'\nAdwin LT2 events do not match HH events - data set seems faulty :(')
        else:
            print 'OK :)'
        
    # columns: sync no | attempt | ph1 arrival time | ph1 ch | ph2 arrival time | ph2 ch | dt | BSM outcome | Bob outcome |
    #          LDE_type (1 = psi-, 0 = psi+) | CR before 1 | CR after 1 | CR before 2 | CR after 2 | PLU mrkr abs. time
    teleportation_events = np.empty((0,15))

    for i,s in enumerate(PLU_mrkr_sync_numbers):
        attempt = attempts[i]

        _ph0 = LDE_ph0_sync_numbers==s
        _ph1 = LDE_ph1_sync_numbers==s
        
        if len(LDE_ph0_sync_numbers[_ph0]) == 1 and len(LDE_ph1_sync_numbers[_ph1]) == 1:
            psiminus = 1
            stimes = np.array([ LDE_ph0_sync_times[_ph0], LDE_ph1_sync_times[_ph1] ]).reshape(-1)
            chans = np.array([0,1])            

        elif len(LDE_ph0_sync_numbers[_ph0]) == 2 and len(LDE_ph1_sync_numbers[_ph1]) == 0:
            psiminus = 0
            stimes = LDE_ph0_sync_times[_ph0].reshape(-1)
            chans = np.array([0,0])

        elif len(LDE_ph0_sync_numbers[_ph0]) == 0 and len(LDE_ph1_sync_numbers[_ph1]) == 2:
            psiminus = 0
            stimes = LDE_ph1_sync_times[_ph1].reshape(-1)
            chans = np.array([1,1])

        else:
            continue

        
        idx = np.argsort(stimes)
        atimes = stimes[idx]
        atimes[1] -= settings.PIPULSESEP
        chans = chans[idx]
        dt = atimes[1] - atimes[0]
       
        _evnt = np.array([s, 
            attempt,
            atimes[0],
            chans[0],
            atimes[1],
            chans[1],
            dt,
            BSM_outcomes[i],
            ad2_ssro[i],
            psiminus,
            ad1_CR_before[i],
            ad1_CR_after[i],
            ad2_CR_before[i],
            ad2_CR_after[i],
            PLU_mrkr_abs_times[i],
            ])

        teleportation_events = np.vstack((teleportation_events, _evnt))

    if settings.VERBOSE:
        print
        print 'Found {} valid teleportation events.'.format(int(len(teleportation_events)))
        print '===================================='
        print 

    files.set_analysis_data(fp, 'teleportation_events', teleportation_events)

    return teleportation_events
示例#4
0
文件: plots.py 项目: zaguros/analysis
def plot_PLU_filter(folder):
    fp = files.get_msmt_fp(folder)

    # get the PLU marked photons first
    is_ph_ch0, is_ph_ch1 = events.get_photons(fp)
    is_ph = is_ph_ch0 | is_ph_ch1
    is_ph_with_PLU_mrkr = is_ph & events.filter_marker(fp, 2)

    # first window
    fig, (ax0, ax1) = plot_photon_hist_filter_comparison(
        fp,
        save=False,
        fltr=is_ph_with_PLU_mrkr,
        log=True,
        binedges=settings.PHOTONHIST_BINEDGES)

    ax0.axvline(settings.CH0_START, color='k', linestyle='--')
    ax0.text(settings.CH0_START + 1,
             1,
             '{} ns'.format(settings.CH0_START),
             color='k')
    ax0.legend()
    ax0.set_title('PLU (hardware) filter first pi-pulse ch0')

    ax1.axvline(settings.CH1_START, color='k', linestyle='--')
    ax1.text(settings.CH1_START + 1,
             1,
             '{} ns'.format(settings.CH1_START),
             color='k')
    ax1.legend()
    ax1.set_title('PLU (hardware) filter first pi-pulse ch1')

    fig.savefig(os.path.join(folder, 'PLU_photons_window1.png'))

    # second window
    fig, (ax0, ax1) = plot_photon_hist_filter_comparison(
        fp,
        save=False,
        fltr=is_ph_with_PLU_mrkr,
        log=True,
        binedges=settings.PHOTONHIST_BINEDGES + settings.PIPULSESEP)

    ax0.axvline(settings.CH0_START + settings.PIPULSESEP,
                color='k',
                linestyle='--')
    ax0.text(settings.CH0_START + settings.PIPULSESEP + 1,
             1,
             '{} ns'.format(settings.CH0_START + settings.PIPULSESEP),
             color='k')
    ax0.legend()
    ax0.set_title('PLU (hardware) filter second pi-pulse ch0')

    ax1.axvline(settings.CH1_START + settings.PIPULSESEP,
                color='k',
                linestyle='--')
    ax1.text(settings.CH1_START + settings.PIPULSESEP + 1,
             1,
             '{} ns'.format(settings.CH1_START + settings.PIPULSESEP),
             color='k')
    ax1.legend()
    ax1.set_title('PLU (hardware) filter second pi-pulse ch1')

    fig.savefig(os.path.join(folder, 'PLU_photons_window2.png'))