Пример #1
0
def readPickleChannel(file, channel_no, correct_offset=True):
    """Read data set as stored in pickle file"""
    # Make sure file path is correct format
    if file[-4:] == ".pkl":
        file = file[0:-4]
    ### READ Pickle File ###
    wave = utils.PickleFile(file, 4)
    wave.load()
    xRaw = wave.get_meta_data("timeform_1")
    yRaw = wave.get_data(channel_no)
    # Correct for trigger offset in timestamps
    length = len(xRaw) - 5 # Sometimes scope gets nPoints in y wrong
    x = xRaw[:length] - xRaw[0]
    # Count how many pulses saved the file
    count = 0
    for i in yRaw:
        count = count + 1
    ### Make 2D array of pulse y values ###
    y = np.zeros( (count,  length) )
    for i, ent in enumerate(yRaw):
        if correct_offset == True:
            y[i,:] = ent[:length]  - np.mean(ent[0:20])
        else:
            y[i,:] = ent[length]
    return x,y
Пример #2
0
def save_scopeTraces(fileName, scope, channel, noPulses):
    """Save a number of scope traces to file - uses compressed .pkl"""
    scope._get_preamble(channel)
    results = utils.PickleFile(fileName, 1)
    results.add_meta_data("timeform_1", scope.get_timeform(channel))

    #ct = scope.acquire_time_check()
    #if ct == False:
    #    print 'No triggers for this data point. Will skip and set data to 0.'
    #    results.save()
    #    results.close()
    #    return False

    t_start, loopStart = time.time(), time.time()
    for i in range(noPulses):
        try:
            ct = scope.acquire_time_check(timeout=.4)
            results.add_data(scope.get_waveform(channel), 1)
        except Exception, e:
            print "Scope died, acquisition lost."
            print e
        if i % 100 == 0 and i > 0:
            print "%d traces collected - This loop took : %1.1f s" % (
                i, time.time() - loopStart)
            loopStart = time.time()
Пример #3
0
        scope_rise_vs_ipw.SetPoint(i, ipw[i], rise_time)
        scope_fall_vs_photon.SetPoint(i, photon, fall_time)
        scope_fall_vs_ipw.SetPoint(i, ipw[i], fall_time)
        scope_width_vs_photon.SetPoint(i, photon, width_time)
        scope_width_vs_ipw.SetPoint(i, ipw[i], width_time)

        #now, the values from the graphs directly
        waveform_name = os.path.join(
            dirname, "Chan%02d_Width%05d" % (logical_channel, ipw[i]))

        # For Tektronix:
        if options.scope == "Tektronix":
            if not os.path.exists("%s.pkl" % waveform_name):
                print "SKIPPING", waveform_name
                continue
            waveform = utils.PickleFile(waveform_name, 1)
            waveform.load()
            wave_times = waveform.get_meta_data("timeform_1")
            wave_volts = waveform.get_data(1)[0]

        else:
            wave_times, wave_volts = get_waveform.get_waveform(waveform_name)

        wave_can.cd()
        gr = ROOT.TGraph()
        for j, t in enumerate(wave_times):
            gr.SetPoint(j, t, wave_volts[j])
        gr.Draw("alp")
        wave_can.Update()

        raw_input("wait:")
Пример #4
0
    box_name = int(box_name)
    chan_name = int(chan_name)
    chan = (box_name-1) * 8 + chan_name
    sc.select_channel(chan)
    sc.set_pulse_height(p._max_pulse_height)
    sc.set_pulse_width(0) #TODO: check that the pulse width is OK (higher width -> faster rise time)
    sc.set_pulse_delay(p._pulse_delay) #no zeros on the new chip!
    sc.set_pulse_number(1) #no zeros on the new chip!

    adjusted, adj_delay, setting = parameters.fibre_delay(delay_values[chan])
    print delay_values[chan],adj_delay,setting
    sc.set_fibre_delay(adj_delay)

    # create an output file and save
    fname = "results_with_offsets/Waveform_Box%02d_Chan%02d" % (box_name,chan_name)
    results = utils.PickleFile(fname,2)
    results.set_meta_data("timeform_1",scope.get_timeform(1))
    results.set_meta_data("timeform_2",scope.get_timeform(2))

    for i in range(1):
        sc.fire()
        results.add_data(scope.get_waveform(1),1)
        results.add_data(scope.get_waveform(2),2)
        time.sleep(p._short_pause)
        sc.read_pin()

    results.save()
    results.close()

    scope.unlock()
Пример #5
0
import ROOT
import utils
import os
import sys
import numpy
import math

if __name__ == "__main__":
    fname = sys.argv[1]
    results = utils.PickleFile(fname.split(".")[0], 2)
    results.load()

    trigger_t = results.get_meta_data("timeform_1")
    signal_t = results.get_meta_data("timeform_2")

    #for some reason the channels get switched over!
    trigger_v = []
    signal_v = []
    trigger_gr = []
    signal_gr = []
    for i in range(5):
        trigger_v.append(results.get_data(2)[i])
        signal_v.append(results.get_data(1)[i])
        trigger_gr.append(ROOT.TGraph())
        signal_gr.append(ROOT.TGraph())

    for i in range(5):
        trigger_gr[i].SetLineColor(ROOT.kBlack)
        signal_gr[i].SetLineColor(ROOT.kRed + 2)

        for j in range(len(trigger_t)):
Пример #6
0
    delay_values = {}
    for line in file("delays.txt", 'r').readlines():
        chan = int(line.split()[0])
        delay_values[chan] = float(line.split()[1])

    ctr = 0
    for f in os.listdir("results_with_offsets"):
        bits = f.split("_")
        if len(bits) != 3:
            continue
        box = int(bits[1][-2:])
        chan = int(bits[2].split('.')[0][-2:])
        logical_channel = (box - 1) * 8 + chan

        results = utils.PickleFile("results_with_offsets/%s" % f.split(".")[0],
                                   2)
        results.load()

        signal_t = results.get_meta_data("timeform_2")
        signal_v = results.get_data(1)[0]

        gr.append(ROOT.TGraph())
        gr[ctr].SetName("Box %02d Channel %02d" % (box, chan))
        gr[ctr].SetLineColor(colors[chan - 1])

        for i in range(len(signal_t)):
            adjusted_t = signal_t[i] - (delay_values[logical_channel] * 1e-9 /
                                        2.)
            #            gr[ctr].SetPoint(i,signal_t[i],signal_v[i])
            gr[ctr].SetPoint(i, adjusted_t, signal_v[i])
Пример #7
0
def sweep(dir_out,file_out,box,channel,width,delay,scope,min_volt=None,min_trigger=-0.005):
    """Perform a measurement using a default number of
    pulses, with user defined width, channel and rate settings.
    """
    print '____________________________'
    print width
    #fixed options
    height = p._max_pulse_height
    fibre_delay = 0
    trigger_delay = 0
    pulse_number = p._pulse_num
    #first select the correct channel and provide settings
    logical_channel = (box-1)*8 + channel
    
    if scope_name=="Tektronix3000":
        # first, run a single acquisition with a forced trigger, effectively to clear the waveform
        scope.set_single_acquisition()
        time.sleep(p._short_pause) #needed for now to get the force to work...
        scope._connection.send("trigger:state ready")
        time.sleep(p._short_pause)
        scope._connection.send("trigger force")
        time.sleep(p._short_pause)
    else:
        # Setup averaging and set to 0 averages
        scope.reset_averaging("A")
        scope.set_averaging("A", 1, 512)
        
    #if no trigger settings, run a test fire
    if min_volt==None:
        min_volt = get_min_volt(logical_channel,height,width,
                                delay,scope,min_trigger=min_trigger)

    sc.select_channel(logical_channel)
    sc.set_pulse_width(width)
    sc.set_pulse_height(p._max_pulse_height)
    sc.set_pulse_delay(delay)
    sc.set_fibre_delay(fibre_delay)
    sc.set_trigger_delay(trigger_delay)
  
    #set the trigger level to half the minimum value (and ensure a good scale)
    trigger = min_volt / 2
    if trigger > min_trigger:
        trigger = min_trigger
    volts_div = math.fabs(min_volt / 4) # 6 divs total, plus some leaway
    volts_div_setting = None
    #find the correct volts/div
    for i,t in enumerate(_v_div):
        if volts_div > t:
            if i<(len(_v_div)-2):
                volts_div_setting = _v_div[i+1]
            else:
                volts_div_setting = _v_div[-2]
    if volts_div_setting ==None:
        volts_div_setting = _v_div[0] # set to minimal
    print "VDIV",volts_div,volts_div_setting

    scope.set_y_scale(1,volts_div_setting)    
    if scope_name=="Tektronix3000":
        scope.set_edge_trigger(trigger,1,True)
        scope.set_average_acquisition(1000)
        scope.lock()
    else:
        # Also set the y offset
        print 'error'
        scope.set_y_position(1, volts_div_setting*2)
        scope.set_y_position("A", 0)
        scope.set_trigger_mode("normal")
        scope.enable_trigger()
        scope.set_trigger(1, trigger, True)
    sc.set_pulse_number(pulse_number)

    sc.fire_sequence()
    #wait for the sequence to end
    tsleep = pulse_number * (delay*1e-3 + 210e-6)
    time.sleep(tsleep) #add the offset in
    pin, rms = None, None
    #while not comms_flags.valid_pin(pin,channel):
    while pin==None:
        try:
            pin, rms, _ = sc.read_pin_sequence()
        except TypeError:
            pin = None
    print "PIN (sweep):",pin
    #should now have an averaged waveform
    directory = "%s/channel_%02d"%(dir_out,logical_channel)
    if not os.path.exists(directory):
        os.makedirs(directory)

    ## create an output file and save
    fname = "%s/Chan%02d_Width%05d" % (directory,logical_channel,width)

    if scope_name=="Tektronix3000":
        waveform = scope.get_waveform(1)
        if waveform!=None:
            results = utils.PickleFile(fname,1)
            results.set_meta_data("timeform_1",scope.get_timeform(1))
            results.add_data(waveform,1)    
            results.save()
            results.close()
        else:
            print "SKIPPING WAVEFORM FOR WIDTH",width
    else:
        waveform = scope.save_waveform("A", fname)
                
    #have saved a waveform, now save rise,fall,pin etc
    
    results = {}
    
    if scope_name=="Tektronix3000":
        results["area"] = (scope.measure(1,"area")) 
        results["rise"] = (scope.measure(1,"rise")) 
        results["fall"] = (scope.measure(1,"fall")) 
        results["width"] = (scope.measure(1,"nwidth")) 
        results["minimum"] = (scope.measure(1,"minimum"))
        scope.unlock()    
    else:
        results["area"] = (scope.measure("A","area")) 
        results["rise"] = (scope.measure("A","rise")) 
        results["fall"] = (scope.measure("A","fall")) 
        results["width"] = (scope.measure("A","width")) 
        results["minimum"] = (scope.measure("A","minimum"))
    results["pin"] = pin[logical_channel]

    return results
Пример #8
0
    can_all = ROOT.TCanvas("can_all")

    colors = [
        ROOT.kBlack, ROOT.kMagenta, ROOT.kRed + 1, ROOT.kOrange,
        ROOT.kYellow + 1, ROOT.kGreen + 1, ROOT.kCyan + 1, ROOT.kBlue + 1
    ]

    ctr = 0
    for f in os.listdir("results"):
        bits = f.split("_")
        if len(bits) != 3:
            continue
        box = int(bits[1][-2:])
        chan = int(bits[2].split('.')[0][-2:])

        results = utils.PickleFile("results/%s" % f.split(".")[0], 2)
        results.load()

        signal_t = results.get_meta_data("timeform_2")
        signal_v = results.get_data(1)[0]

        gr.append(ROOT.TGraph())
        gr[ctr].SetName("Box %02d Channel %02d" % (box, chan))
        gr[ctr].SetLineColor(colors[chan - 1])

        for i in range(len(signal_t)):
            gr[ctr].SetPoint(i, signal_t[i], signal_v[i])

        can_box[box - 1].cd()
        if p_box[box - 1] == 0:
            gr[ctr].Draw("al")