def sweep(dir_out,box,channel,width,delay,scope,min_volt=None): """Perform a measurement using a default number of pulses, with user defined width, channel and rate settings. """ print '____________________________' print width #fixed options height = 16383 fibre_delay = 0 trigger_delay = 0 pulse_number = 100 #first select the correct channel and provide settings logical_channel = (box-1)*8 + channel sc.select_channel(logical_channel) sc.set_pulse_width(width) sc.set_pulse_height(16383) sc.set_pulse_number(pulse_number) sc.set_pulse_delay(delay) sc.set_fibre_delay(fibre_delay) sc.set_trigger_delay(trigger_delay) # first, run a single acquisition with a forced trigger, effectively to clear the waveform scope._connection.send("trigger:state ready") time.sleep(0.1) scope._connection.send("trigger force") time.sleep(0.1) # Get pin read time.sleep(0.1) sc.fire_sequence() # previously fire_sequence! #wait for the sequence to end tsleep = pulse_number * (delay*1e-3 + 210e-6) time.sleep(tsleep) #add the offset in pin = None # while not comms_flags.valid_pin(pin,channel): while pin==None: pin,rms, _ = sc.tmp_read_rms() print "PIN (sweep):",pin[logical_channel], rms[logical_channel] sc.stop() # File system stuff check_dir("%s/raw_data/" % (dir_out)) directory = check_dir("%s/raw_data/Channel_%02d/" % (dir_out,logical_channel)) fname = "%sWidth%05d" % (directory,width) # Check scope ck = find_and_set_scope_y_scale(1,height,width,delay,scope,scaleGuess=min_volt) if ck == True: print "Saving raw files to: %s..." % fname sc.fire_continuous() time.sleep(0.2) save_ck = save_scopeTraces(fname, scope, 1, 100) sc.stop() if save_ck == True: # Calc and return params x,y = calc.readPickleChannel(fname, 1) results = calc.dictionary_of_params(x,y) results["pin"] = pin[logical_channel] results["pin error"] = rms[logical_channel] calc.printParamsDict(results, width) calc.plot_eg_pulses(x,y,10, fname='%s/LastMeasuredPulses.png' % dir_out.split("/")[0]) #os.system("open %s/LastMeasuredPulses.png" % dir_out.split("/")[0]) elif save_ck == False: results = return_zero_result() results['pin'] = pin[logical_channel] else: results = return_zero_result() results['pin'] = pin[logical_channel] results["pin error"] = rms[logical_channel] sc.stop() return results
dataPath = os.path.join(p[0],p[1],"Box_%02d/raw_data/channel_%02d/" % (box,overallChan)) files = [ f for f in os.listdir(dataPath) if os.path.isfile(os.path.join(dataPath,f)) ] output_filename = "%s_check.dat" % options.file[0:-4] output_file = file(output_filename,'w') output_file.write("#PWIDTH\tPWIDTH Error\tPIN\tPIN Error\tWIDTH\tWIDTH Error\tRISE\tRISE Error\tFALL\tFALL Error\tAREA\tAREA Error\t\ Minimum\tMinimum Error\n") for i, file in enumerate(files): fname = os.path.join(dataPath,file) x,y = calc.readPickleChannel(fname, 1) width = fname[-8:-4] #if int(width) == 8500: #calc.plot_eg_pulses(x,y,66,show=True) tmpResults = calc.dictionary_of_params(x,y) calc.printParamsDict(tmpResults, width) if i < 7: iter = i else: iter = i-1 output_file.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n"%(width, 0, res_list[iter]["pin"], res_list[iter]["pin_err"], tmpResults["width"], tmpResults["width error"], tmpResults["rise"], tmpResults["rise error"], tmpResults["fall"], tmpResults["fall error"], tmpResults["area"], tmpResults["area error"], tmpResults["peak"], tmpResults["peak error"] )) calc.plot_eg_pulses(x,y,100,show=True) output_file.close()
def sweep(dir_out, box, channel, width, delay, scope, min_volt=None): """Perform a measurement using a default number of pulses, with user defined width, channel and rate settings. """ print '____________________________' print width #fixed options height = 16383 fibre_delay = 0 trigger_delay = 0 pulse_number = 100 #first select the correct channel and provide settings logical_channel = (box - 1) * 8 + channel sc.select_channel(logical_channel) sc.set_pulse_width(width) sc.set_pulse_height(16383) sc.set_pulse_number(pulse_number) sc.set_pulse_delay(delay) sc.set_fibre_delay(fibre_delay) sc.set_trigger_delay(trigger_delay) # first, run a single acquisition with a forced trigger, effectively to clear the waveform scope._connection.send("trigger:state ready") time.sleep(0.1) scope._connection.send("trigger force") time.sleep(0.1) # Get pin read time.sleep(0.1) sc.fire_sequence() # previously fire_sequence! #wait for the sequence to end tsleep = pulse_number * (delay * 1e-3 + 210e-6) time.sleep(tsleep) #add the offset in pin = None # while not comms_flags.valid_pin(pin,channel): while pin == None: pin, rms, _ = sc.tmp_read_rms() print "PIN (sweep):", pin[logical_channel], rms[logical_channel] sc.stop() # File system stuff check_dir("%s/raw_data/" % (dir_out)) directory = check_dir("%s/raw_data/Channel_%02d/" % (dir_out, logical_channel)) fname = "%sWidth%05d" % (directory, width) # Check scope ck = find_and_set_scope_y_scale(1, height, width, delay, scope, scaleGuess=min_volt) if ck == True: print "Saving raw files to: %s..." % fname sc.fire_continuous() time.sleep(0.2) save_ck = save_scopeTraces(fname, scope, 1, 100) sc.stop() if save_ck == True: # Calc and return params x, y = calc.readPickleChannel(fname, 1) results = calc.dictionary_of_params(x, y) results["pin"] = pin[logical_channel] results["pin error"] = rms[logical_channel] calc.printParamsDict(results, width) calc.plot_eg_pulses(x, y, 10, fname='%s/LastMeasuredPulses.png' % dir_out.split("/")[0]) #os.system("open %s/LastMeasuredPulses.png" % dir_out.split("/")[0]) elif save_ck == False: results = return_zero_result() results['pin'] = pin[logical_channel] else: results = return_zero_result() results['pin'] = pin[logical_channel] results["pin error"] = rms[logical_channel] sc.stop() return results