def main(): run = '20170706_4' datapath = "/bluearc/storage/SBC-17-data/" runpath = datapath + run events = [evnt for evnt in listdir(runpath) if not isfile(join(runpath,evnt))] [m, smallpulses, smallpulsebins] = get_gain(datapath,run, sendPulses=True) print("gain calculated with all small pulses: %.2e"%m) V = [] VwithNIM = [] A = [] AwithNIM = [] Anogain = [] AnogainNIM = [] for event in events: e = sbc.DataHandling.GetSBCEvent.GetEvent(runpath,event) tr = e["PMTtraces"] trac = tr["traces"] dt = tr["dt"] for i in range(len(trac)): trace = np.fabs(trac[i][0]) nimpulse = trac[i][1] b = np.mean(trace[0:50]) trace -= b dt_tr = dt[i][0] V.append(max(trace)) A.append(pi.SBC_pulse_integrator_bressler(trace,dt_tr)[0]/m) Anogain.append(pi.SBC_pulse_integrator_bressler(trace,dt_tr)[0]) if min(nimpulse) < -30: VwithNIM.append(max(trace)) AwithNIM.append(pi.SBC_pulse_integrator_bressler(trace,dt_tr)[0]/m) AnogainNIM.append(pi.SBC_pulse_integrator_bressler(trace,dt_tr)[0]) NIM_efficiency_and_plot(V, VwithNIM, A, AwithNIM, Anogain, AnogainNIM, '20170706_4', smallpulses, smallpulsebins)
def randomized_t0_scintillation(runs, m): #m=4e7 #m=get_gain("/bluearc/storage/SBC-17-data/",runs[0]) Ncoinc = 0 Nblocked = 0 ntotcoinc = 0 totevents = 0 totbub = 0 diffs = [] goodz = [] pmtdiffs = [] coincspec = [] allxyzfname = "/pnfs/coupp/persistent/grid_output/SBC-17/output/SimpleXYZ_all.bin" xyzf = sbc.DataHandling.ReadBinary.ReadBlock(allxyzfname) for run in runs: print("randomized_t0_scintillation processing run " + run) indices = [ i for i, x in enumerate(xyzf["runid"]) if str(x[0]) + "_" + str(x[1]) == run ] runposreco = { "ev": [xyzf["ev"][indices]], "x": [xyzf["bubX"][indices]], "y": [xyzf["bubY"][indices]], "z": [xyzf["bubZ"][indices]] } runrawpath = "/bluearc/storage/SBC-17-data/%s/" % run runreconpath = "/pnfs/coupp/persistent/grid_output/SBC-17/output/%s/" % run acousticfilename = runreconpath + "AcousticAnalysis_%s.bin" % run a = sbc.DataHandling.ReadBinary.ReadBlock(acousticfilename) #c = sbc.DataHandling.ReadBinary.ReadBlock(getbubfile) bubt0 = a["bubble_t0"] events = [ evnt for evnt in listdir(runrawpath) if not isfile(join(runrawpath, evnt)) ] for x in events: totevents += 1 if not np.isnan(runposreco["z"][0][int(x)]): totbub += 1 e = sbc.DataHandling.GetSBCEvent.GetEvent(runrawpath, x) cgate = e["fastDAQ"]["CAMgate"] dcam = np.diff(cgate) fdt = e["fastDAQ"]["time"] camOffTimes = [ fdt[i] for i in range(len(dcam)) if dcam[i] > 0.5 ] pmttracetime = e["PMTtraces"]["t0_sec"][:, 0] + e["PMTtraces"][ "t0_frac"][:, 0] d = sbc.AnalysisModules.PMTfastDAQalignment.PMTandFastDAQalignment( e) pmtalign = d["PMT_trigt0_sec"] + d["PMT_trigt0_frac"] tracetimes = pmttracetime - pmtalign #at0 = bubt0[int(x),0] rand_at0 = fdt[randrange(np.shape(fdt)[0])] if rand_at0 - fdt[0] < 500e-6: print("too close to beginning") rand_at0 = fdt[randrange( np.shape(fdt)[0])] # just trying one more time #print("real t0: %f"%bubt0[int(x),0]) #print("randomized t0: %f"%rand_at0) i = 0 # to match the indexing of the pre-made code I had 1??? candidate = 0 candidate_time = 0 #candidate_PMTtime = 0 #candidate_index = 0 for t in (tracetimes - rand_at0): # loop through every PMT trace for the event if t < 0 and t > -500e-6: lastCamOff = 0 for k in range(len(camOffTimes)): if t + rand_at0 > camOffTimes[k]: lastCamOff = camOffTimes[k] elif t + rand_at0 < camOffTimes[k]: break if t + rand_at0 - lastCamOff > 25e-6: # if the trace time is within 500 microseconds before acoustic t0: ntotcoinc += 1 pmtdiffs.append(t) #take abs to get positive area: trace = np.fabs(e["PMTtraces"]["traces"][i][0]) #if ch0 saturated, stitch in low res channel: if max(trace) == 128: trace = pi.stitchTraces( trace, np.fabs(e["PMTtraces"]["traces"][i][1])) dt = e["PMTtraces"]["dt"][i][0] #subtract baseline: #Actually this gets done in pulse_integrator anyway #baseline = np.mean(trace[0:50]) #trace -= baseline #integrate and convert to phe: [phe, n, totInt, pktimes ] = pi.SBC_pulse_integrator_bressler(trace, dt) if phe != None: phe /= m #keep track of largest candidate: if phe > candidate: candidate = phe candidate_time = t #candidate_PMTtime = t+at0 #candidate_index = i i += 1 #i.e. if there is a candidate PMT trace with area greater than zero if candidate > 0: Ncoinc += 1 #ind = candidate_index #pmtt = candidate_PMTtime diffs.append(candidate_time) goodz.append(runposreco["z"][0][int(x)]) coincspec.append(candidate) elif candidate == 0 and not np.isnan(float(x)): bl = isBlocked(run, int(x), float(rand_at0), float(runposreco["z"][0][int(x)])) if bl: Nblocked += 1 else: coincspec.append(0) gc.collect() print("total number of events: " + str(totevents)) print("total number of bubbles: " + str(totbub)) print("total coincident triggers: " + str(ntotcoinc)) print("total blocked bubbles: " + str(Nblocked)) print("total coincident bubbles with scintillation greater than 0phe: " + str(Ncoinc)) print( "fraction of bubbles with a coincident scintillation signal greater than 0phe: " + str(Ncoinc * 100 / totbub) + "%") return [coincspec, Ncoinc, ntotcoinc, totevents, totbub]
def zdependence(runs, m): #m = 1e7 #m=get_gain("/bluearc/storage/SBC-17-data/",runs[0]) Ncoinc = [0, 0] ntotcoinc = [0, 0] totevents = [0, 0] totbub = [0, 0] diffs = [[], []] goodz = [[], []] pmtdiffs = [[], []] coincspec = [[], []] allxyzfname = "/pnfs/coupp/persistent/grid_output/SBC-17/output/SimpleXYZ_all.bin" xyzf = sbc.DataHandling.ReadBinary.ReadBlock(allxyzfname) for run in runs: print("zdependence processing run " + run) indices = [ i for i, x in enumerate(xyzf["runid"]) if str(x[0]) + "_" + str(x[1]) == run ] runposreco = { "ev": [xyzf["ev"][indices]], "x": [xyzf["bubX"][indices]], "y": [xyzf["bubY"][indices]], "z": [xyzf["bubZ"][indices]] } runrawpath = "/bluearc/storage/SBC-17-data/%s/" % run runreconpath = "/pnfs/coupp/persistent/grid_output/SBC-17/output/%s/" % run acousticfilename = runreconpath + "AcousticAnalysis_%s.bin" % run a = sbc.DataHandling.ReadBinary.ReadBlock(acousticfilename) #c = sbc.DataHandling.ReadBinary.ReadBlock(getbubfile) bubt0 = a["bubble_t0"] events = [ evnt for evnt in listdir(runrawpath) if not isfile(join(runrawpath, evnt)) ] for j in [0, 1]: with open( "/nashome/b/bressler/sbcoutput/%s_PMTmatching_ch%s.txt" % (run, str(j)), "w+") as f, open( "/nashome/b/bressler/sbcoutput/%s_muonCoincidences.txt" % run, 'w+') as fmu: f.write( "run event PMT_t0_index PMT_t0_-at0_us PMT_t0 at0 phe z\n") fmu.write("run event phe\n") for x in events: yes = False if int(x) < len(runposreco["z"][0]) - 1: yes = True totevents[j] += 1 if yes and not np.isnan(runposreco["z"][0][int(x)]): totbub[j] += 1 e = sbc.DataHandling.GetSBCEvent.GetEvent( runrawpath, x) veto = e["fastDAQ"]["VetoCoinc"] cgate = e["fastDAQ"]["CAMgate"] dcam = np.diff(cgate) fdt = e["fastDAQ"]["time"] camOffTimes = [ fdt[i] for i in range(len(dcam)) if dcam[i] > 0.5 ] muon = False pmttracetime = e["PMTtraces"]["t0_sec"][:, 0] + e[ "PMTtraces"]["t0_frac"][:, 0] d = sbc.AnalysisModules.PMTfastDAQalignment.PMTandFastDAQalignment( e) pmtalign = d["PMT_trigt0_sec"] + d["PMT_trigt0_frac"] tracetimes = pmttracetime - pmtalign at0 = bubt0[int(x), j] i = 0 # to match the indexing of the pre-made code I had 1??? candidate = 0 candidate_time = 0 candidate_PMTtime = 0 candidate_index = 0 for t in (tracetimes - at0): # loop through every PMT trace for the event if t < -150e-6 and t > -600e-6: # if the trace time is within 500 microsec before acoustic t0 if max(veto) > 0.1: if fdt[list(veto).index( max(veto) )] - at0 < 0 and fdt[list(veto).index( max(veto))] - at0 > -500e-6: print("Veto Coincidence: event " + run + "-" + str(x)) muon = True #lastCamOff = 0 #for k in range(len(camOffTimes)): # if t+at0 > camOffTimes[k]: # lastCamOff = camOffTimes[k] # elif t+at0 < camOffTimes[k]: # break #if t+at0-lastCamOff > 25e-6: # if the trace time is more than 25 microseconds away from a camera gate rise #but not doing it this way anymore because we'll check for the LED being on later during the merge ntotcoinc[j] += 1 pmtdiffs.append(t) #take abs to get positive area: trace = np.fabs(e["PMTtraces"]["traces"][i][0]) #if ch0 saturated, stitch in low res channel: if max(trace) == 128: trace = pi.stitchTraces( trace, np.fabs( e["PMTtraces"]["traces"][i][1])) dt = e["PMTtraces"]["dt"][i][0] #subtract baseline: #Actually this gets done in pulse_integrator anyway #baseline = np.mean(trace[0:50]) #trace -= baseline #integrate and convert to phe: [phe, n, totInt, pktimes] = pi.SBC_pulse_integrator_bressler( trace, dt) if phe != None: phe /= m #keep track of largest candidate: if phe > candidate: candidate = phe candidate_time = t candidate_PMTtime = t + at0 candidate_index = i #else: # candidate = -1.0 i += 1 #i.e. if there is a candidate PMT trace with area greater than zero if candidate > 0: Ncoinc[j] += 1 ind = candidate_index pmtt = candidate_PMTtime diffs[j].append(candidate_time) goodz[j].append(runposreco["z"][0][int(x)]) coincspec[j].append(candidate) f.write( "%s %s %d %f %f %f %f %f\n" % (run, x, ind, candidate_time * 1e6, pmtt, at0, candidate, runposreco["z"][0][int(x)])) if muon: fmu.write("%s %s %f\n" % (run, x, candidate)) gc.collect() print("run " + run + " file %s written" % str(j)) #pmtdiffs.append(candidate_times[candidates.index(max(candidates))]) print("total number of events: " + str(totevents)) print("total number of bubbles: " + str(totbub)) print("total coincident triggers: " + str(ntotcoinc)) print("total coincident bubbles with scintillation greater than 0phe: " + str(Ncoinc)) print( "fraction of bubbles with a coincident scintillation signal greater than 0phe: " + str(sum(Ncoinc) * 100 / sum(totbub)) + "%") return [goodz, diffs, coincspec, Ncoinc, ntotcoinc, totevents, totbub]
def coincidences(runs, m, PMTsearchwindow): Ncoinc = [0, 0] ntotcoinc = [0, 0] totevents = [0, 0] totbub = [0, 0] diffs = [[], []] goodz = [[], []] pmtdiffs = [[], []] coincspec = [[], []] allxyzfname = "/pnfs/coupp/persistent/grid_output/SBC-17/output/SimpleXYZ_all.bin" xyzf = sbc.DataHandling.ReadBinary.ReadBlock(allxyzfname) for run in runs: print("zdependence processing run " + run) indices = [ i for i, x in enumerate(xyzf["runid"]) if str(x[0]) + "_" + str(x[1]) == run ] runposreco = { "ev": [xyzf["ev"][indices]], "x": [xyzf["bubX"][indices]], "y": [xyzf["bubY"][indices]], "z": [xyzf["bubZ"][indices]] } runrawpath = "/bluearc/storage/SBC-17-data/%s/" % run runreconpath = "/pnfs/coupp/persistent/grid_output/SBC-17/output/%s/" % run acousticfilename = runreconpath + "AcousticAnalysis_%s.bin" % run a = sbc.DataHandling.ReadBinary.ReadBlock(acousticfilename) bubt0 = a["bubble_t0"] events = [ evnt for evnt in listdir(runrawpath) if not isfile(join(runrawpath, evnt)) ] for j in [0, 1]: with open( "/nashome/b/bressler/sbcoutput/%s_PMTmatching_ch%s.txt" % (run, str(j)), "w+") as f, open( "/nashome/b/bressler/sbcoutput/%s_muonCoincidences.txt" % run, 'w+') as fmu: f.write( "run event PMT_t0_index PMT_t0_-at0_us PMT_t0 at0 phe z\n") fmu.write("run event phe\n") for x in events: oktokeepgoing = False if int(x) < len(runposreco["z"][0]) - 1: oktokeepgoing = True totevents[j] += 1 if oktokeepgoing and not np.isnan( runposreco["z"][0][int(x)]): totbub[j] += 1 e = sbc.DataHandling.GetSBCEvent.GetEvent( runrawpath, x) veto = e["fastDAQ"]["VetoCoinc"] fdt = e["fastDAQ"]["time"] muon = False pmttracetime = e["PMTtraces"]["t0_sec"][:, 0] + e[ "PMTtraces"]["t0_frac"][:, 0] d = sbc.AnalysisModules.PMTfastDAQalignment.PMTandFastDAQalignment( e) pmtalign = d["PMT_trigt0_sec"] + d["PMT_trigt0_frac"] tracetimes = pmttracetime - pmtalign at0 = bubt0[int(x), j] i = 0 candidate = 0 candidate_time = 0 candidate_PMTtime = 0 candidate_index = 0 for t in (tracetimes - at0): # loop through every PMT trace for the event if t < PMTsearchwindow[1] and t > PMTsearchwindow[ 0]: # if the trace time is in the window if max(veto) > 0.1: if fdt[list(veto).index(max( veto))] - at0 < PMTsearchwindow[ 1] and fdt[list(veto).index( max(veto) )] - at0 > PMTsearchwindow[0]: print("Veto Coincidence: event " + run + "-" + str(x)) muon = True ntotcoinc[j] += 1 pmtdiffs.append(t) #take abs to get positive area: trace = np.fabs(e["PMTtraces"]["traces"][i][0]) #if ch0 saturated, stitch in low res channel: if max(trace) == 128: trace = pi.stitchTraces( trace, np.fabs( e["PMTtraces"]["traces"][i][1])) dt = e["PMTtraces"]["dt"][i][0] #integrate and convert to phe: [phe, n, totInt, pktimes] = pi.SBC_pulse_integrator_bressler( trace, dt) if phe != None: phe /= m #keep track of largest candidate: if phe > candidate: candidate = phe candidate_time = t candidate_PMTtime = t + at0 candidate_index = i i += 1 #i.e. if there is a candidate PMT trace with area greater than zero if candidate > 0: Ncoinc[j] += 1 ind = candidate_index pmtt = candidate_PMTtime diffs[j].append(candidate_time) goodz[j].append(runposreco["z"][0][int(x)]) coincspec[j].append(candidate) f.write( "%s %s %d %f %f %f %f %f\n" % (run, x, ind, candidate_time * 1e6, pmtt, at0, candidate, runposreco["z"][0][int(x)])) if muon: fmu.write("%s %s %f\n" % (run, x, candidate)) gc.collect() print("run " + run + " file %s written" % str(j)) print("total number of events: " + str(totevents)) print("total number of bubbles: " + str(totbub)) print("total coincident triggers: " + str(ntotcoinc)) print("total coincident bubbles with scintillation greater than 0phe: " + str(Ncoinc)) print( "fraction of bubbles with a coincident scintillation signal greater than 0phe: " + str(sum(Ncoinc) * 100 / sum(totbub)) + "%")
def PMTandPiezoPlot(datadir, run, event, gain): """ Plots the piezo trace from piezo 0 and PMT pulse sizes near the acoustic signal on one figure. The green line indicates the time of acoustic t0. The red line indicates the time and size of the PMT t0 chosen by Matt's analysis. The yellow lines indicate the times and sizes of other PMT pulses. Also plots in separate windows the PMT traces for pulses 500 microseconds or less before acoustic t0. """ en = event mu = gain e = sbc.DataHandling.GetSBCEvent.GetEvent(datadir + '/' + run, en) print(e["fastDAQ"].keys()) cgate = e["fastDAQ"]["CAMgate"] dcam = np.diff(cgate) p0 = e["fastDAQ"]["Piezo1"] p1 = e["fastDAQ"]["Piezo2"] fdt = e["fastDAQ"]["time"] runreconpath = "/pnfs/coupp/persistent/grid_output/SBC-17/output/%s/" % run pmtdiffs = [] diffs = [] camOnTimes = [fdt[i] for i in range(len(dcam)) if dcam[i] < -0.5] camOffTimes = [fdt[i] for i in range(len(dcam)) if dcam[i] > 0.5] print(len(camOnTimes)) print(len(camOffTimes)) acousticfilename = runreconpath + "AcousticAnalysis_%s.bin" % run a = sbc.DataHandling.ReadBinary.ReadBlock(acousticfilename) bubt0 = a["bubble_t0"] pmttracetime = e["PMTtraces"]["t0_sec"][:, 0] + e["PMTtraces"]["t0_frac"][:, 0] d = sbc.AnalysisModules.PMTfastDAQalignment.PMTandFastDAQalignment(e) pmtalign = d["PMT_trigt0_sec"] + d["PMT_trigt0_frac"] tracetimes = pmttracetime - pmtalign at0 = bubt0[en, 0] at0_1 = bubt0[en, 1] allxyzfname = "/pnfs/coupp/persistent/grid_output/SBC-17/output/SimpleXYZ_all.bin" xyzf = sbc.DataHandling.ReadBinary.ReadBlock(allxyzfname) indices = [ i for i, x in enumerate(xyzf["runid"]) if str(x[0]) + "_" + str(x[1]) == run ] xyz_reconstructed = True if len(indices) > 0: runposreco = { "ev": [xyzf["ev"][indices]], "x": [xyzf["bubX"][indices]], "y": [xyzf["bubY"][indices]], "z": [xyzf["bubZ"][indices]] } z = runposreco["z"][0][int(int(en))] else: print("no handscan?") z = 1.5 xyz_reconstructed = False lag_expected = (-23.387649 * z - 261.020495) * 1e-6 # fit from other analysis t0_expected_p0 = at0 + lag_expected t0_expected_p1 = at0_1 + lag_expected i = 0 candidates = [] candidate_times = [] for t in (tracetimes - at0): if t < 0.2 and t > -0.2: lastCamOff = 0 for k in range(len(camOffTimes)): if t + at0 > camOffTimes[k]: lastCamOff = camOffTimes[k] elif t + at0 < camOffTimes[k]: break if t + at0 - lastCamOff > 25e-6: pmtdiffs.append(t) trace = np.fabs(e["PMTtraces"]["traces"][i][0]) if max(trace) == 128: trace = pi.stitchTraces( trace, np.fabs(e["PMTtraces"]["traces"][i][1])) dt = e["PMTtraces"]["dt"][i][0] #baseline = np.mean(trace[0:50]) #trace = trace - baseline [phe, n, totInt, pktimes] = pi.SBC_pulse_integrator_bressler(trace, dt) if phe != None: phe /= mu candidates.append(phe) candidate_times.append(t) i += 1 candidate_phe = 0 the_index = 0 i = 0 near_trace_indices = [] for t in candidate_times: if t > -500e-6 and t < 0: near_trace_indices.append(list(tracetimes - at0).index(t)) if candidates[i] > candidate_phe: candidate_phe = candidates[i] the_index = i i += 1 if len(candidates) != 0: if max(candidates) > 0: diffs.append(candidate_times[candidates.index(max(candidates))]) fig, ax1 = plt.subplots() ax2 = ax1.twinx() ax1.plot(fdt, p0, 'b', alpha=0.6, label='piezo 0') ax1.plot(fdt, p1, 'k', alpha=0.2, label='piezo 1') for i in range(len(candidates)): if i == the_index: ax2.plot([candidate_times[i] + at0, candidate_times[i] + at0], [0, candidates[i]], 'r', lw=4) else: ax2.plot([candidate_times[i] + at0, candidate_times[i] + at0], [0, candidates[i]], 'y', lw=4) #ax2.plot([min(candidate_times),max(candidate_times)],[0,0],linewidth=2) ax1.plot([at0, at0], [-0.5, 0.5], 'b', linewidth=2, label='acoustic t0, p0') ax1.plot([at0_1, at0_1], [-0.5, 0.5], 'k', linewidth=2, label='acoustic t0, p1') """ if xyz_reconstructed: ax1.plot([t0_expected_p0,t0_expected_p0],[-0.5,0.5],'b:',linewidth=2, label = 'expected PMT t0, p0') ax1.plot([t0_expected_p1,t0_expected_p1],[-0.5,0.5],'k:',linewidth=2, label = 'expected PMT t0, p1') else: ax1.plot([t0_expected_p0,t0_expected_p0],[-0.5,0.5],'b:',linewidth=2, label = 'expected PMT t0, p0, center of chamber') ax1.plot([t0_expected_p1,t0_expected_p1],[-0.5,0.5],'k:',linewidth=2, label = 'expected PMT t0, p1, center of chamber') """ ax1.plot(fdt, cgate, 'c') ax1.plot(fdt[:-1], dcam, 'm') ax2.set_ylabel('pmt signal (phe)', fontsize=20) ax1.set_xlabel('time (s)', fontsize=20) ax1.set_ylabel('Acoustic signa(V)', fontsize=20) ax1.set_ylim([min(p1), max(p1)]) ax2.set_xlim([-0.1, 0.1]) #ax2.set_ylim([0,5]) ax1.legend() plt.show for j in near_trace_indices: trace = e["PMTtraces"]["traces"][j][0] dt = e["PMTtraces"]["dt"] dt_tr = dt[j][0] tPMT = np.arange(len(trace)) * dt_tr plt.figure() plt.plot(tPMT, trace) plt.xlabel("t (s)") plt.ylabel("PMT signal") plt.show plt.figure() plt.plot(e["fastDAQ"]["time"], e["fastDAQ"]["VetoCoinc"]) plt.ylabel("Veto Coincidence signal", fontsize=18) plt.xlabel("time (s)") plt.show
i = 0 print(n) indices = [i for i, x in enumerate(pmt["ev"]) if int(x) == n] #print(indices) areas = pmt["PMT_pulse_area"][indices] print(len(areas)) e = sbc.DataHandling.GetSBCEvent.GetEvent(runpath, n) #print(len(e["PMTtraces"]["traces"])) for k in range(len(e["PMTtraces"]["traces"])): trace = np.fabs(e["PMTtraces"]["traces"][k][0]) #if ch0 saturated, stitch in low res channel: if max(trace) == 128: trace = pi.stitchTraces(trace, np.fabs(e["PMTtraces"]["traces"][k][1])) dt = e["PMTtraces"]["dt"][k][0] #integrate and convert to phe: [a, n, totInt, pktimes] = pi.SBC_pulse_integrator_bressler(trace, dt) myphe[i] = a theirphe[i] = -areas[i] * CONVERSION_TO_CHARGE i += 1 gc.collect() plt.figure() plt.scatter(myphe, theirphe) plt.show() plt.figure() plt.hist(theirphe, 30) plt.show()
def check_multibub_scintillation(run, event, at0, PMTgain, PMTwindow): tstart = PMTwindow[0] t_end = PMTwindow[1] scintillation_signal = 0 datadir = '/bluearc/storage/SBC-17-data' e = sbc.DataHandling.GetSBCEvent.GetEvent(datadir + '/' + run, event) cgate = e["fastDAQ"]["CAMgate"] fdt = e["fastDAQ"]["time"] LED_on = [fdt[i] for i in range(len(cgate)) if cgate[i] < -0.5] look_times = [x for x in LED_on if (x < 0 and abs(x - at0) < tstart)] #print(str(len(LED_on)/len(fdt))) if len(look_times) > 0: LED_during_window = True else: LED_during_window = False dcam = np.diff(cgate) fdt = e["fastDAQ"]["time"] camOffTimes = [fdt[i] for i in range(len(dcam)) if dcam[i] > 0.5] pmttracetime = e["PMTtraces"]["t0_sec"][:, 0] + e["PMTtraces"][ "t0_frac"][:, 0] d = sbc.AnalysisModules.PMTfastDAQalignment.PMTandFastDAQalignment(e) pmtalign = d["PMT_trigt0_sec"] + d["PMT_trigt0_frac"] tracetimes = pmttracetime - pmtalign i = 0 # to match the indexing of the pre-made code I had 1??? candidate = 0 for t in (tracetimes - at0): # loop through every PMT trace for the event if t < t_end and t > tstart: # if the trace time is within 500 microsec before acoustic t0 """ lastCamOff = 0 for k in range(len(camOffTimes)): if t+at0 > camOffTimes[k]: lastCamOff = camOffTimes[k] elif t+at0 < camOffTimes[k]: break if t+at0-lastCamOff > 25e-6: # if the trace time is more than 25 microseconds away from a camera gate rise """ #take abs to get positive area: trace = np.fabs(e["PMTtraces"]["traces"][i][0]) #if ch0 saturated, stitch in low res channel: if max(trace) == 128: trace = pi.stitchTraces( trace, np.fabs(e["PMTtraces"]["traces"][i][1])) dt = e["PMTtraces"]["dt"][i][0] #integrate and convert to phe: [phe, n, totInt, pktimes] = pi.SBC_pulse_integrator_bressler(trace, dt) if phe != None: phe /= PMTgain #keep track of largest candidate: if phe > candidate: candidate = phe i += 1 #i.e. if there is a candidate PMT trace with area greater than zero if candidate > 0: scintillation_signal = candidate gc.collect() return [LED_during_window, scintillation_signal]