def threshold_crossings(filename, can, thresh=0.4): #for i in range(len(y[:,1])): dt, count = np.zeros(1e4), 0 #for file in os.listdir(filename): #print options.file+str(file) #x,y = cu.readPickleChannel(options.file+str(file), 1) x,y = cu.readPickleChannel(filename, 1) peak = min(y[0,:]) threshold = thresh*peak index = np.where( y[0,:] < threshold )[0] for j, idx in enumerate(index): if j < len(index)-1: tmp = x[index[j+1]] - x[index[j]] if tmp > 1e-7: # make sure we didn't miss a pulse dt[count] = tmp count = count + 1 dt = np.trim_zeros(dt, 'fb') #Get rid of unused 'zero' points scale = 1e6 mean, std = np.mean(dt), np.std(dt) nBins, mi, ma = 20, -2e-9, +2e9 dt_hist = r.TH1F('dt','Transient time spead on PMT response transients', nBins, mi, ma) for d in dt: dt_hist.Fill(d-mean) dt_hist.GetYaxis().SetTitle("Counts / %1.1f ns" % ((ma-mi)/nBins) ) dt_hist.GetXaxis().SetTitle('Pulse separation - mean(Pulse separation) [s]') dt_hist.Draw() can.Update() #dt_hist.SaveAs("./PulseSeparation.pdf") can.SaveAs("./PulseSeparation.png")
def threshold_crossings(filename, can, thresh=0.4): #for i in range(len(y[:,1])): dt, count = np.zeros(1e4), 0 #for file in os.listdir(filename): #print options.file+str(file) #x,y = cu.readPickleChannel(options.file+str(file), 1) x, y = cu.readPickleChannel(filename, 1) peak = min(y[0, :]) threshold = thresh * peak index = np.where(y[0, :] < threshold)[0] for j, idx in enumerate(index): if j < len(index) - 1: tmp = x[index[j + 1]] - x[index[j]] if tmp > 1e-7: # make sure we didn't miss a pulse dt[count] = tmp count = count + 1 dt = np.trim_zeros(dt, 'fb') #Get rid of unused 'zero' points scale = 1e6 mean, std = np.mean(dt), np.std(dt) nBins, mi, ma = 20, -2e-9, +2e9 dt_hist = r.TH1F('dt', 'Transient time spead on PMT response transients', nBins, mi, ma) for d in dt: dt_hist.Fill(d - mean) dt_hist.GetYaxis().SetTitle("Counts / %1.1f ns" % ((ma - mi) / nBins)) dt_hist.GetXaxis().SetTitle( 'Pulse separation - mean(Pulse separation) [s]') dt_hist.Draw() can.Update() #dt_hist.SaveAs("./PulseSeparation.pdf") can.SaveAs("./PulseSeparation.png")
def get_clean_data_points(widths, gain, path): '''Check all data points for saturation or 0 result.''' index = [] for i, g in enumerate(gain): file = '%s/Width%05d.pkl' % (path, widths[i]) if os.path.isfile(file): x, y = calc.readPickleChannel(file, 1) print i, len(widths) if check_saturation(y) is False and gain[i] > 0: index.append(i) return index
########################################### # Script to read in pickled wave # file for basic checks. Inherits # strongly from AcquireTek/calc_utils.py # # Author: Ed Leming # Date: 08/04/2015 ############################################ import time import sys import calc_utils as calc if __name__ == "__main__": ## File path fileName = sys.argv[1] ## Read data fileRead = time.time() x, y = calc.readPickleChannel(fileName, 1) print "Reading %d pulses from file took %1.2f s" % (len( y[:, 0]), (time.time() - fileRead)) calc.printParams(x, y, "pmt pulses") print "Reading + calcs on %d pulses from file took %1.2f s" % (len( y[:, 0]), (time.time() - fileRead)) ### PLOT ### calc.plot_eg_pulses(x, y, 10, show=True)
import sys import calc_utils as calc import numpy as np import matplotlib.pyplot as plt if __name__ == "__main__": ## File path fileName1 = sys.argv[1] fileName2 = sys.argv[2] ## Read data x1,y1 = calc.readPickleChannel(fileName1, 1,False) x2,y2 = calc.readPickleChannel(fileName2, 1, False) y1mean = np.mean(y1,0) y2mean = np.mean(y2,0) plt.figure(0) plt.plot(x1,y1mean,label=fileName1) plt.plot(x1,y2mean,label=fileName2) plt.legend(loc = "upper right") plt.show()
########################################### # Script to read in pickled wave # file for basic checks. Inherits # strongly from AcquireTek/calc_utils.py # # Author: Ed Leming # Date: 08/04/2015 ############################################ import time import sys import calc_utils as calc if __name__ == "__main__": ## File path fileName = sys.argv[1] ## Read data fileRead = time.time() x,y = calc.readPickleChannel(fileName, 1) print "Reading %d pulses from file took %1.2f s" % ( len(y[:,0]), (time.time()-fileRead) ) calc.printParams(x,y,"pmt pulses") print "Reading + calcs on %d pulses from file took %1.2f s" % ( len(y[:,0]), (time.time()-fileRead) ) ### PLOT ### calc.plot_eg_pulses(x,y,10,show=True)
try: while True: print "Event no: %i" % counter if counter != 0: pulseTimes.append(time.time()-startTime) sc.fire_sequence() save_ck0 = sweep_noise.save_scopeTraces("./tempTraces", scope, 1, num_traces) #sleeping for 5 seconds to ensure TELLIE has stopped pulsing sleep_time = ((pulse_delay*1e-3)*pulse_number)+0.05 time.sleep(sleep_time+3) pin = None # while not comms_flags.valid_pin(pin,channel): while pin==None: pin,rms,chans = sc.tmp_read_rms() x1,y1 = calc.readPickleChannel("./tempTraces.pkl", 1,True) num_photons_average_rms = get_photons(calc.calcArea(x1,y1),0.7) singleTraceAreas = calcAreaArray(x1,y1) singlePMTTime, singlePMTTimeErr = get_pmt_time_and_spread(x1,y1) print "LEN Y1: "+str(len(y1)) if counter != 0: photonCount.append(num_photons_average_rms[0]) photonCountError.append(num_photons_average_rms[1]/np.sqrt(len(y1))) pmtTime.append(singlePMTTime) pmtTimeErr.append(singlePMTTimeErr) for singleArea in singleTraceAreas: singleTracePhotonCounts.append(get_photons(singleArea,0.7)) os.system("rm ./tempTraces.pkl") print "\n=====================================" print "%1.1f +/- %1.3f" % (float(pin[channel]), float(rms[channel])/np.sqrt(pulse_number)) if counter != 0:
time_trace = [] got_time_trace = False #Arrays pmt_traces = [] pin_vals = [] pin_rms = [] npulses = [] for pmt_file in os.listdir(pmt_dir): x1 = None y1 = None if width != -1000: if int(pmt_file[-9:-4]) != width: continue try: x1,y1 = calc.readPickleChannel(os.path.join(pmt_dir,pmt_file), 1,False) except: continue if not got_time_trace: time_trace = x1 for i in range(len(y1)): pmt_traces.append(y1[i]) for pin_file in os.listdir(pin_dir): if width != -1000: if int(pin_file[-9:-4]) != width: continue print pin_file numPulses,pin,rms = readPinFile(os.path.join(pin_dir,pin_file)) pin_vals.append(pin)
print p box = int(p[2][4:6]) chan = int(p[3][4:6]) print chan overallChan = ((box-1)*8)+chan 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"],
plt.show() plt.clf() if __name__ == "__main__": ## File path dataPath = "./results/" runs = [1, 2, 3, 4, 5] for i in runs: run = "run_%i" % i fileName = "%s%s.pkl" % (dataPath, run) # Read data fileRead = time.time() x1, y1 = calc.readPickleChannel(fileName, 1) x2, y2 = calc.readPickleChannel(fileName, 2) print "Reading %d pulses from %s took %1.2f s" % (len( y1[:, 0]), fileName, (time.time() - fileRead)) # Calculate and print parameters calc.printParams(x1, y1, "Trigger") calc.printParams(x2, y2, "Signal") separation, Jitter, JittErr = calc.calcJitter(x1, y1, x2, y2) print "\nJitter = %1.2f +/- %1.2f ps\n" % (Jitter * 1e12, JittErr * 1e12) print "Reading + calcs on %d pulses from file took %1.2f s" % (len( y1[:, 0]), (time.time() - fileRead)) plot_eg_pulses(x1,
def sweep_timing(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 = 11100 #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 sc.stop() # File system stuff check_dir("%s/raw_data/" % (dir_out)) directory = check_dir("%s/raw_data/Channel_%02d/" % (dir_out,logical_channel)) channels = [1,4] fnames = [] fnames.append("%sPMTPulseWidth%05d" % (directory,width)) fnames.append("%sTriggerPulseWidth%05d" % (directory,width)) # Check scope ck = find_and_set_scope_y_scale(1,height,width,delay,scope,scaleGuess=min_volt) scope.set_edge_trigger(1.4, 4 , falling=False) # Rising edge trigger if ck == True: print "Saving raw files to: %s and %s" % (fnames[0],fnames[1]) sc.fire_continuous() time.sleep(0.2) save_ck = save_scopeTraces_Multiple(fnames, scope, channels, 100) sc.stop() time.sleep(5) if save_ck == True: # Calc and return params xPMT,yPMT = calc.readPickleChannel(fnames[0], 1) xTrigger,yTrigger = calc.readPickleChannel(fnames[1], 1) meanJitter, JitterDev, JitterErrorOnMean = calc.calcJitter(xTrigger,yTrigger,xPMT,yPMT) return meanJitter, JitterErrorOnMean
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
def sweep_timing(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 = 11100 #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 sc.stop() # File system stuff check_dir("%s/raw_data/" % (dir_out)) directory = check_dir("%s/raw_data/Channel_%02d/" % (dir_out, logical_channel)) channels = [1, 4] fnames = [] fnames.append("%sPMTPulseWidth%05d" % (directory, width)) fnames.append("%sTriggerPulseWidth%05d" % (directory, width)) # Check scope ck = find_and_set_scope_y_scale(1, height, width, delay, scope, scaleGuess=min_volt) scope.set_edge_trigger(1.4, 4, falling=False) # Rising edge trigger if ck == True: print "Saving raw files to: %s and %s" % (fnames[0], fnames[1]) sc.fire_continuous() time.sleep(0.2) save_ck = save_scopeTraces_Multiple(fnames, scope, channels, 100) sc.stop() time.sleep(5) if save_ck == True: # Calc and return params xPMT, yPMT = calc.readPickleChannel(fnames[0], 1) xTrigger, yTrigger = calc.readPickleChannel(fnames[1], 1) meanJitter, JitterDev, JitterErrorOnMean = calc.calcJitter( xTrigger, yTrigger, xPMT, yPMT) return meanJitter, JitterErrorOnMean
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