Пример #1
0
def mult(runs,mergedfilename,Qbins,FeedbackTransducer, lightBins, binsname, LED_INDUCED_DEAD_TIME_FRACTION):
    if FeedbackTransducer == "PT4":
        pt = 3
    elif FeedbackTransducer == "PT6":
        pt = 5
    spectrumFile = open('/nashome/b/bressler/sbcoutput/'+mergedfilename+"%s_coincident_spectrum.txt"%binsname,'w')
    separator = '\t'
    spectrumFile.write("lightBin\t"+separator.join(["Q=%.1f-%.1fkeV"%(Qbins[i],
                                                                      Qbins[i+1]) for i in range(len(Qbins)-1)])+"\n")
    spectrumFile_multiples = open('/nashome/b/bressler/sbcoutput/'+mergedfilename+"%s_coincident_spectrum_multibub.txt"%binsname,'w')
    spectrumFile_multiples.write("lightBin\t"+separator.join(["Q=%.1f-%.1fkeV"%(Qbins[i],
                                                                      Qbins[i+1]) for i in range(len(Qbins)-1)])+"\n")
    fractionFile = open('/nashome/b/bressler/sbcoutput/'+mergedfilename+"%s_coincident_spectrum_fraction.txt"%binsname,'w')
    fractionFile.write("lightBin\t"+separator.join(["Q=%.1f-%.1fkeV"%(Qbins[i],
                                                                      Qbins[i+1]) for i in range(len(Qbins)-1)])+"\n")
    
    #with open("/nashome/b/bressler/sbcoutput/%s_merged_oldPMT.txt"%mergedfilename,"r") as fin:
    with open("/nashome/b/bressler/sbcoutput/%s_merged.txt"%mergedfilename,"r") as fin:
        data = fin.readlines()
        
    headers = data[0].split()
    runind = headers.index("run")
    eventind = headers.index("event")
    xind = headers.index("x")
    yind = headers.index("y")
    zind = headers.index("z")
    lagind = headers.index("lag")
    spectind = headers.index("PMTphe")
    blockedind = headers.index('isBlocked')
    nbubind = headers.index('nbub')
    x=[]
    y=[]
    z=[]
    evid = []
    lag = []
    spect = []
    isblocked = []
    nbub = []
    i=0
    for line in data:
        if i>0:
            split_line = line.split()
            evid.append(split_line[runind]+"-"+split_line[eventind])
            isblocked.append(float(split_line[blockedind]))
            x.append(float(split_line[xind]))
            y.append(float(split_line[yind]))
            z.append(float(split_line[zind]))
            lag.append(float(split_line[lagind]))
            spect.append(float(split_line[spectind]))
            nbub.append(float(split_line[nbubind]))
    
        i+=1

    counts = []
    nbubs = []
    didntpass = 0
    bubInfo = []
    eventcount = np.zeros(87)
    spectra = [[] for i in range(87)]
    twobub_spectra = [[] for i in range(87)]
    threebub_spectra = [[] for i in range(87)]
    LT = np.zeros(87)
    LT_by_Q = np.zeros(len(Qbins)-1)
    expand_times = [[] for i in range(87)]
    totbub = 0
    onebubcount = np.zeros(87)
    twobubcount = np.zeros(87)
    threebubcount = np.zeros(87)
    setpoints = []
    elt = 0
    temps = []
        
    for run in runs:
        print(run)
        z_low = -4
        z_high = 0
        preq = 1
        runrawpath = '/bluearc/storage/SBC-17-data/'+run
        events = [evnt for evnt in listdir(runrawpath) if not isfile(join(runrawpath,evnt))]
        Nevents = len(events)
        runreconpath = "/pnfs/coupp/persistent/grid_output/SBC-17/output/%s/"%run
        historyfilename = runreconpath+"HistoryAnalysis_%s.bin"%run
        history = sbc.DataHandling.ReadBinary.ReadBlock(historyfilename)
        getbubfile = "/coupp/data/home/coupp/HumanGetBub_output_SBC-17/HumanGetBub_%s.bin"%run
        c = sbc.DataHandling.ReadBinary.ReadBlock(getbubfile)

        eventn = c["ev"]
        count = Counter(eventn)
        edges = history["PressureEdge"][pt]
        centersp = [(edges[i]+edges[i+1])/2 for i in range(len(edges)-1)]
        #centers = Qvals
        e0 = sbc.DataHandling.GetSBCEvent.GetEvent(runrawpath,0,"slowDAQ")
        T=np.mean(e0["slowDAQ"]["T1"])
        temps.append(T)
        sm = SeitzModel(list(edges),T,'xenon')
        edges_by_Q = sm.Q
        centers = [(edges_by_Q[i] + edges_by_Q[i+1])/2 for i in range(len(edges_by_Q)-1)]

        print("T=%f C"%T)
        
        for c in count:
            N = count[c]
            counts.append(N)
            """
            if N%2 != 0 and N != 1:
                print("lines isn't even")
                print(c)
                print(N)
            elif N%2 == 0:
                n = N/2
                nbubs.append(n)
                """
        for eventn in range(Nevents):
            try:
                indices_back = 30
                event_ID = run+"-"+str(eventn)
                mergedind = evid.index(event_ID)
                bl = isblocked[mergedind]
                light = spect[mergedind]
                ev_z = z[mergedind]
                if np.isnan(light):
                    light = 0
                ev_z = z[mergedind]
                #onebub = not np.isnan(runposreco["z"][0][int(eventn)])
                n_from_merged = nbub[mergedind]
                n = 0
                N = count[eventn]
                if N%2 == 0:
                    n = N/2
                    nbubs.append(n)
                
                if n_from_merged != n:
                    print('n and merged n dont match')
                    print("n here: %d"%n)
                    print("n from merged: %d"%n_from_merged)
                e = sbc.DataHandling.GetSBCEvent.GetEvent(runrawpath,eventn,"slowDAQ","event")
                t = e["slowDAQ"]["elapsed_time"]
                tcenters = [(t[i+1] + t[i])/2 for i in range(len(t)-1)]
                trig_time = t[list(e["slowDAQ"]["TriggerOut"]).index(1.0)-indices_back]
                pslope = np.diff(e["slowDAQ"][FeedbackTransducer])
                expstartind = list(pslope).index(min(list(pslope)))
                exp_start = tcenters[expstartind]
                trig_pressure = e["slowDAQ"][FeedbackTransducer][list(e["slowDAQ"]["TriggerOut"]).index(1.0)-indices_back]
                T = np.mean(e["slowDAQ"]["T1"])
                SM = SeitzModel(trig_pressure,T,'xenon')
                Q = (SM.Q)
                #print(Q[0])
                pset = e["event"]["Pset"]
                ev_lt = e["event"]['livetime']
                elt += ev_lt
                if pset not in setpoints:
                    setpoints.append(pset)
                    #print(pset)
                #print(len(history["PressureBins"][eventn]))
                times = history["PressureBins"][eventn][pt][:]
                """
                plt.figure()
                plt.plot([trig_time,trig_time],[0,200],label="Bubble time")
                plt.plot([exp_start,exp_start],[0,200],label="Expansion start")
                plt.plot([0,max(t)],[trig_pressure,trig_pressure],label="Bubble pressure")
                plt.plot(t,e["slowDAQ"]["PT6"],label="PT6")
                plt.plot(tcenters,pslope,label="Pressure slope")
                plt.xlabel("time",fontsize=18)
                plt.ylabel("signal",fontsize=18)
                plt.legend(fontsize=18)
                plt.show
                """
                if n == 1 and ev_lt > 20:
                    totbub += 1
                    for i in range(len(centers)):
                        if trig_time > exp_start:
                            #print(trig_pressure)
                            #print(pset)
                            if (trig_pressure >= edges[i] 
                                and trig_pressure <= edges[i+1]) and abs(trig_pressure-pset)<preq/2:
                                onebubcount[i] += 1
                                eventcount[i] += 1
                                if not bl:
                                    spectra[i].append(light)
                                    #if light < 1:
                                        #print("%s-%d is passing single not blocked and light < 1"%(run, eventn))
                                bubInfo.append([n,Q,bl,light,ev_z])
                                #print("added %s-%d to bubInfo"%(run,eventn))
                                expand_times[i].append(ev_lt)
                            if abs(centersp[i]-pset)<preq/2:
                                LT[i] += times[i]*(1-LED_INDUCED_DEAD_TIME_FRACTION)
                                for j in range(len(Qbins)-1):
                                    if Q >= Qbins[j] and Q <= Qbins[j+1]:
                                        LT_by_Q[j] += times[i]*(1-LED_INDUCED_DEAD_TIME_FRACTION)
                    if Q>1.5 and Q<2 and abs(trig_pressure-pset)<preq/2 and trig_time > exp_start:
                        print(event_ID)
                        print(Q)
                    
                        
                        
                elif n == 2 and ev_lt > 20:
                    totbub += 1
                    for i in range(len(centers)):
                        if trig_time > exp_start:
                            if (trig_pressure >= edges[i] 
                                and trig_pressure <= edges[i+1]) and abs(trig_pressure-pset)<preq/2:
                                eventcount[i] += 1
                                twobubcount[i] += 1
                                expand_times[i].append(ev_lt)
                                bubInfo.append([n,Q,bl,light,ev_z])
                                if not bl:
                                    twobub_spectra[i].append(light)
                                print("%s-%d multibubble event: %d bubbles, %.2f phe"%(run, eventn, n, light))
                            if abs(centersp[i]-pset)<preq/2:
                                LT[i] += times[i]*(1-LED_INDUCED_DEAD_TIME_FRACTION)
                                for j in range(len(Qbins)-1):
                                    if Q >= Qbins[j] and Q <= Qbins[j+1]:
                                        LT_by_Q[j] += times[i]*(1-LED_INDUCED_DEAD_TIME_FRACTION)

                elif n >= 3 and ev_lt > 20:
                    for i in range(len(centers)):
                        if trig_time > exp_start:
                            if (trig_pressure >= edges[i] 
                                and trig_pressure <= edges[i+1]) and abs(trig_pressure-pset)<preq/2:
                                eventcount[i] += 1
                                threebubcount[i] += 1
                                expand_times[i].append(ev_lt)
                                bubInfo.append([n,Q,bl,light,ev_z])
                                if not bl:
                                    threebub_spectra[i].append(light)
                                print("%s-%d multibubble event: %d bubbles, %.2f phe"%(run, eventn, n, light))
                            if abs(centersp[i]-pset)<preq/2:
                                LT[i] += times[i]*(1-LED_INDUCED_DEAD_TIME_FRACTION)
                                for j in range(len(Qbins)-1):
                                    if Q >= Qbins[j] and Q <= Qbins[j+1]:
                                        LT_by_Q[j] += times[i]*(1-LED_INDUCED_DEAD_TIME_FRACTION)

                else:
                    if n>0:
                        didntpass += 1
                    for i in range(len(centers)):
                        if trig_time > exp_start and ev_lt > 20:
                            if (trig_pressure >= edges[i] 
                                and trig_pressure <= edges[i+1]) and abs(trig_pressure-pset)<preq/2:
                                eventcount[i] += 1
                                expand_times[i].append(ev_lt)
                                bubInfo.append([n,Q,bl,light,ev_z])
                            if abs(centersp[i]-pset)<preq/2:
                                LT[i] += times[i]*(1-LED_INDUCED_DEAD_TIME_FRACTION)
                                for j in range(len(Qbins)-1):
                                    if Q >= Qbins[j] and Q <= Qbins[j+1]:
                                        LT_by_Q[j] += times[i]*(1-LED_INDUCED_DEAD_TIME_FRACTION)

                #if (ev_z > z_low and ev_z < z_high):                    
                    
        
            except Exception as x:
                print(x)
                #break
        
    blockedEvents = [x for x in bubInfo if x[2] == 1]
    print("fraction of LED-blocked bubbles: "+str(len(blockedEvents)/len([x for x in bubInfo if x[0]>0])))
    print("Number of single-bubble zero phe non-blocked events:" + str(len([x for x in bubInfo if x[0]==1 and x[2] == 0 and (x[3]>0 and x[3] <1)])))
    print("Number of single-bubble one phe non-blocked events:" + str(len([x for x in bubInfo if x[0]==1 and x[2] == 0 and (x[3]>1 and x[3] <2)])))
    print("Number of single-bubble two phe non-blocked events:" + str(len([x for x in bubInfo if x[0]==1 and x[2] == 0 and (x[3]>2 and x[3] <3)])))

    rateList1 = [onebubcount[i]/LT[i] for i in range(len(onebubcount))]
    rateErrList1h = [(0.5+np.sqrt(onebubcount[i]+0.25))/LT[i] for i in range(len(onebubcount))]
    rateErrList1l = [(-0.5+np.sqrt(onebubcount[i]+0.25))/LT[i] for i in range(len(onebubcount))]
    standard_error1 = [np.sqrt(onebubcount[i])/LT[i] for i in range(len(onebubcount))]


    rateList2 = [twobubcount[i]/LT[i] for i in range(len(twobubcount))]
    rateErrList2h = [(0.5+np.sqrt(twobubcount[i]+0.25))/LT[i] for i in range(len(twobubcount))]
    rateErrList2l = [(-0.5+np.sqrt(twobubcount[i]+0.25))/LT[i] for i in range(len(twobubcount))]
    
    rateList3 = [threebubcount[i]/LT[i] for i in range(len(threebubcount))]
    rateErrList3h = [(0.5+np.sqrt(threebubcount[i]+0.25))/LT[i] for i in range(len(threebubcount))]
    rateErrList3l = [(-0.5+np.sqrt(threebubcount[i]+0.25))/LT[i] for i in range(len(threebubcount))]
    
    rateListE = [eventcount[i]/LT[i] for i in range(len(eventcount))]
    rateErrListEh = [(0.5+np.sqrt(eventcount[i]+0.25))/LT[i] for i in range(len(eventcount))]
    rateErrListEl = [(-0.5+np.sqrt(eventcount[i]+0.25))/LT[i] for i in range(len(eventcount))]
    """
    plt.figure()
    q = [bub[1] for bub in bubInfo]
    plt.hist(q,int(np.ceil(np.sqrt(len(q)))))
    plt.xlabel('Seitz Threshold')
    plt.ylabel('Count')
    plt.show()
    
    #Threshold:
    plt.figure()
    plt.errorbar(centers,rateList1,[rateErrList1l,rateErrList1h],fmt='ro',label='Single Bubbles')
    plt.errorbar(centers,rateList2,[rateErrList2l,rateErrList2h],fmt='go',label='Double Bubbles')
    plt.errorbar(centers,rateList3,[rateErrList3l,rateErrList3h],fmt='bo',label='Triple Bubbles')
    plt.errorbar(centers,rateListE,[rateErrListEl,rateErrListEh],fmt='ko',label='All Events')
    #plt.yscale('log')
    plt.ylim([1e-4,0.1])
    plt.xlabel('Seitz Threshold [keV]',fontsize=18)
    plt.ylabel('Rate [Hz]', fontsize=18)
    plt.legend(fontsize=18)
    plt.grid()
    plt.show
    
    #single bubbles
    def line(x,m,b):
        return m*x + b
    
    QForFit = []
    RForFit = []
    errForFit = []
    for i in range(len(rateList1)):
        if (not np.isnan(rateList1[i])) and (not np.isinf(rateList1[i])) and rateList1[i] != 0:
            QForFit.append(centers[i])
            RForFit.append(rateList1[i])
            errForFit.append(standard_error1[i])

    popt,pcov = scipy.optimize.curve_fit(line,QForFit,RForFit,p0=[0.005,0.01],sigma=errForFit)
    plt.figure()
    plt.errorbar(QForFit,RForFit,yerr=errForFit,fmt="ro")
    xfine = np.linspace(min(centers),3,50)
    y1 = line(xfine,popt[0]+pcov[0,0]**0.5, popt[1]-pcov[1,1]**0.5)
    y2 = line(xfine,popt[0]-pcov[0,0]**0.5, popt[1]+pcov[1,1]**0.5)
    plt.plot(xfine,line(xfine,popt[0],popt[1]),'k-')
    plt.plot(xfine,y1,'k--')
    plt.plot(xfine,y2,'k--')
    plt.plot([0,5],[0,0],'b-')
    plt.fill_between(xfine,y1,y2,facecolor='gray',alpha=0.1)
    plt.ylabel('Rate [Hz]',fontsize=18)
    plt.xlabel('Seitz Threshold [keV]',fontsize=18)
    plt.title('Crosses x-axis at %f'%(-popt[1]/popt[0]))
    plt.show
    """
    
    totbub = len(nbubs)
    print("total number of bubbles: %d"%totbub)
    print("total number of events: %d" %len(counts))
    print("didn't pass: %d"%didntpass)
    m = max(nbubs)
    for i in range(len(nbubs)):
        if nbubs[i]>3:
            nbubs[i] = 3
            
    binedges = [0.5,1.5,2.5,3.5] #bins for bubble multiplicity
    bincenters = [1,2,3]
    plt.figure()
    ns, _ = np.histogram(nbubs,binedges)
    print("bubble counts: ")
    print(ns)
    plt.errorbar(bincenters,ns,np.sqrt(ns),fmt='o')
    plt.yscale('log')
    plt.title("Max Nbub: %d"%int(m),fontsize=20)
    plt.xlabel("Nbub",fontsize=18)
    plt.ylabel("counts",fontsize=18)
    plt.xlim(0.5,3.5)
    plt.grid()
    plt.show
    
    f = [ns[i]/totbub for i in range(len(ns))]
    ferrh = [(0.5+np.sqrt(ns[i]+0.25))/totbub for i in range(len(ns))]
    ferrl = [(-0.5+np.sqrt(ns[i]+0.25))/totbub for i in range(len(ns))]

    plt.figure()
    plt.errorbar(bincenters,f,[ferrl,ferrh],fmt='o')
    plt.xlabel("Nbub",fontsize=18)
    plt.ylabel("fraction of bubbles",fontsize=18)
    plt.xlim([0.5,3.5])
    plt.grid()
    plt.show
    
    """
    #Pressure
    plt.figure()
    plt.errorbar(centersp,rateList1,[rateErrList1l,rateErrList1h],fmt='ro',label='Single Bubbles')
    plt.errorbar(centersp,rateList2,[rateErrList2l,rateErrList2h],fmt='go',label='Double Bubbles')
    plt.errorbar(centersp,rateList3,[rateErrList3l,rateErrList3h],fmt='bo',label='Triple Bubbles')
    plt.errorbar(centersp,rateListE,[rateErrListEl,rateErrListEh],fmt='ko',label='All Events')
    plt.yscale('log')
    plt.xlabel('Pressure [psia]',fontsize=18)
    plt.ylabel('Rate [Hz]', fontsize=18)
    plt.legend(fontsize=18)
    plt.grid()
    plt.show
    
    plt.figure()
    hy = []
    hx = []
    for i in range(len(expand_times)):
        if len(expand_times[i])>0:
            for j in range(len(expand_times[i])):
                hx.append(centersp[i])
                hy.append(expand_times[i][j])

    plt.hist2d(hx,hy,bins=(len(centers),30),cmap='magma')
    plt.colorbar()
    plt.xlabel('PT6 [psia]',fontsize=18)
    plt.ylabel('Total time since expansion [s]',fontsize=18)
    plt.show
    
        
    hy = []
    hx = []
    for i in range(len(expand_times)):
        if len(spectra[i])>0:
            for j in range(len(spectra[i])):
                hx.append(centersp[i])
                hy.append(spectra[i][j])
    plt.figure()
    plt.hist2d(hx,hy,bins=(40,int(max(hy))),cmap='Greys')
    plt.colorbar()
    plt.xlabel('PT6 [psia]',fontsize=18)
    plt.ylabel('Light collected [phe]',fontsize=18)
    plt.yscale('symlog',linthreshy = 0.9)
    plt.show
    
    
    
    xedges = np.arange(88)
    #yedges = np.arange(int(max(hy))+1)
    bins = [10**i+0.5 for i in range(5)] # light bins
    #bins = np.arange(0.5,1+np.ceil(max(spect)))
    bins = np.insert(bins,0,0.5)
    bins=np.insert(bins,0,-0.5)
    bins=np.insert(bins,0,-1.5)
    H, xedges, yedges = np.histogram2d(hx,hy,bins=(xedges,bins))
    for i in range(len(xedges)-1):
        for j in range(len(H[i,:])):
            #print(LT[i])
            H[i,j] = H[i,j]/LT[i]
    print("max rate: %f"%np.amax(H))
            
    fig = plt.figure()
    ax = fig.add_subplot(1,1,1)
    X,Y = np.meshgrid(xedges,yedges)

    im=ax.pcolormesh(X,Y,H.T,cmap="magma")
    plt.yscale('symlog',linthreshy = 0.9)
    fig.colorbar(im,ax=ax)
    plt.show()
    """
    hy = []
    hx = []
    hy_multi = []
    hx_multi = []
    for bubble in bubInfo:
        if bubble[0]==1 and bubble[2] == 0:
        #if bubble[0]==1:
            hx.append(bubble[1]) # Seitz threshold
            hy.append(bubble[3]) # phe
        elif (bubble[0] == 2 or bubble[0] == 3):
            hx_multi.append(bubble[1])
            hy_multi.append(bubble[3])
    plt.figure()
    plt.hist2d(hx,hy,bins=(40,int(max(hy))),cmap='Greys')
    plt.colorbar()
    plt.xlabel('Q [keV]',fontsize=18)
    plt.ylabel('Light collected [phe]',fontsize=18)
    plt.yscale('symlog',linthreshy = 0.9)
    plt.show
    
    #print(temps)
    
    xedges = edges
    Qedges = np.zeros(np.shape(xedges))
    for i in range(1,len(xedges)):
        SM = SeitzModel(float(xedges[i]),np.mean(temps),'xenon')
        if SM is not None:
            Qedges[i]=SM.Q
    
    OArateQ = [(Qbins[i]+Qbins[i+1])/2 for i in range(len(Qbins)-1)]
    OArate_multi = []
    OArateErr_multi = []
    OArate_singles = []
    OArateErr_singles = []
    Qedges = Qbins    
    #print(Qbins)
    #yedges = np.arange(int(max(hy))+1)
    
    bins = lightBins # light bins
    #bins = np.arange(1,int(1+np.ceil(max(spect))))
    bins = np.insert(bins,0,0.5)
    bins=np.insert(bins,0,-0.5)
    #bins=np.insert(bins,0,-1.5)
    
    #bins = [-0.5, 2**9+0.5, 2**13+0.5]
    binc=[(bins[i+1]+bins[i])/2 for i in range(len(bins)-1)]
    binwidths = [bins[i+1]-bins[i] for i in range(len(bins)-1)]
    print(binwidths)
    H, Qedges, yedges = np.histogram2d(hx,hy,bins=(Qedges,bins)) # using hx and hy defined a few lines above in the previous plot section
    H_multi, Qedges, yedges_multi = np.histogram2d(hx_multi, hy_multi, bins=(Qedges, bins))
    multi_ns = H_multi.copy()
    ns = H.copy()
    errorbararray_upper = np.zeros_like(H)
    errorbararray_lower = np.zeros_like(H)
    errorbararray_multi_upper = np.zeros_like(H_multi)
    errorbararray_multi_lower = np.zeros_like(H_multi)
    print("total number of events in H: %d"%np.sum(H))
    print("total number of multiples in H_multi: %d"%np.sum(H_multi))
    for i in range(len(LT_by_Q)):
        OArate_singles.append(sum(H[i,:])/LT_by_Q[i])
        OArateErr_singles.append(np.sqrt(sum(H[i,:]))/LT_by_Q[i])
        for j in range(len(H[i,:])):
            H[i,j] = H[i,j]/LT_by_Q[i]
            if ns[i,j] > 10:
                errorbararray_upper[i,j]= np.sqrt(ns[i,j])/LT_by_Q[i]
                errorbararray_lower[i,j]= np.sqrt(ns[i,j])/LT_by_Q[i]
            else:
                errorbararray_upper[i,j]= (0.5+np.sqrt(ns[i,j]+0.25))/LT_by_Q[i]
                errorbararray_lower[i,j]= (-0.5+np.sqrt(ns[i,j]+0.25))/LT_by_Q[i]
            #print(H[i,j])
            #print(errorbararray[i,j])
            if np.isnan(H[i,j]):
                H[i,j]=0
                errorbararray_upper[i,j] = 0
                errorbararray_lower[i,j] = 0
        OArate_multi.append(sum(H_multi[i,:])/LT_by_Q[i])
        OArateErr_multi.append(np.sqrt(sum(H_multi[i,:]))/LT_by_Q[i])
        for j in range(len(H_multi[i,:])):
            H_multi[i,j] = H_multi[i,j]/LT_by_Q[i]
            if multi_ns[i,j] > 10:
               errorbararray_multi_upper[i,j]= np.sqrt(multi_ns[i,j])/LT_by_Q[i]
               errorbararray_multi_lower[i,j]= np.sqrt(multi_ns[i,j])/LT_by_Q[i]
            else:
               errorbararray_multi_upper[i,j]= (0.5+np.sqrt(multi_ns[i,j] + 0.25))/LT_by_Q[i]
               errorbararray_multi_lower[i,j]= (-0.5+np.sqrt(multi_ns[i,j] + 0.25))/LT_by_Q[i]
            #print(H[i,j])
            #print(errorbararray[i,j])
            if np.isnan(H_multi[i,j]):
                H_multi[i,j]=0
                errorbararray_multi_upper[i,j] = 0
                errorbararray_multi_lower[i,j] = 0
    #print(sum(H))
    #print(OArate)
    print("singles:")
    print(ns)
    print("multiples:")
    print(multi_ns)
    
    plt.figure()
    plt.errorbar(OArateQ,OArate_singles,OArateErr_singles,marker='v',linestyle='')
    plt.grid()
    plt.xlabel('Seitz Threshold [keV]')
    plt.ylabel('Rate [Hz]')
    plt.show()
    
    print("max rate: %f"%np.amax(H))
    print("number in onebubcount: %f"%np.sum(onebubcount))
    print(np.sum([rateList1[i] * LT[i] for i in range(len(rateList1)) if not np.isnan(rateList1[i])]))
    fig = plt.figure()
    ax = fig.add_subplot(1,2,1)
    ax.title.set_text('Rates [Hz/bin]')
    X,Y = np.meshgrid(Qedges,yedges)

    im=ax.pcolormesh(X,Y,H.T,cmap="Greys")
    plt.yscale('symlog',linthreshy = 0.9)
    plt.ylabel("Collected light [phe]")
    plt.xlabel("Seitz Threshold [keV]")
    fig.colorbar(im,ax=ax)
    
    ax2 = fig.add_subplot(1,2,2)
    ax2.title.set_text('Number of bubbles in each bin')
    im2=ax2.pcolormesh(X,Y,ns.T,cmap="Blues")
    plt.yscale('symlog',linthreshy = 0.9)
    plt.ylabel("Collected light [phe]")
    plt.xlabel("Seitz Threshold [keV]")
    fig.colorbar(im2,ax=ax2)
    #plt.show()
    
    fig = plt.figure()
    ax3 = fig.add_subplot(1,1,1)
    ax3.title.set_text("Rates per Scintillation: fraction")
    for k in range(len(Qedges)-1):
        print("%f-%f keV: %f bubbles in %f seconds"%(Qedges[k],Qedges[k+1],sum(ns[k,:]),LT_by_Q[k]))
        if LT_by_Q[k]>100:
            ax3.errorbar(binc,H[k,:]/OArate_singles[k],[(errorbararray_upper[k,:]/OArate_singles[k]),(errorbararray_lower[k,:]/OArate_singles[k])],marker='.',markersize=7,
                         linestyle='none',label="%f-%f keV"%(Qedges[k],Qedges[k+1]))
    for l in range(len(bins)-1):
        fractionFile.write("%.1f-%.1fphe\t"%(bins[l],bins[l+1]))
        for k in range(len(Qedges)-1):
            fractionFile.write("%f,%f,%f\t"%(H[k,l]/OArate_singles[k], errorbararray_upper[k,l]/OArate_singles[k], errorbararray_lower[k,l]/OArate_singles[k]))
        fractionFile.write('\n')
    plt.xscale('symlog',linthreshx=0.5)
    #plt.yscale('symlog',linthreshy=0.0001)
    plt.legend(fontsize=15)
    plt.xlabel("collected light [phe]")
    plt.ylabel("Fraction")
    #plt.ylim([0,0.1])
    plt.grid(which='both',axis='both')
    plt.show()
    
    fig = plt.figure()
    ax3 = fig.add_subplot(1,2,1)
    #ax3.title.set_text("Rates per Scintillation")
    ax4 = fig.add_subplot(1,2,2)
    for k in range(len(Qedges)-1):
        print("%f-%f keV: %f seconds"%(Qedges[k],Qedges[k+1],LT_by_Q[k]))
        if LT_by_Q[k]>100:
            ax3.errorbar(binc,H[k,:],[errorbararray_upper[k,:], errorbararray_lower[k,:]],marker='.',markersize=7,
                         linestyle='none',label="%f-%f keV"%(Qedges[k],Qedges[k+1]))
            Hnew = []
            errorbarnew_upper = []
            errorbarnew_lower = []
            for l in range(len(binwidths)):
                Hnew.append(np.divide(H[k,l],binwidths[l]))
                errorbarnew_upper.append(np.divide(errorbararray_upper[k,l],binwidths[l]))
                errorbarnew_lower.append(np.divide(errorbararray_lower[k,l],binwidths[l]))
            ax4.errorbar(binc, Hnew, [errorbarnew_upper, errorbarnew_lower],
                         marker='.', markersize=7, linestyle='none',
                         label='%f-%f keV'%(Qedges[k],Qedges[k+1]))
    for l in range(len(bins)-1):
        spectrumFile.write("%.1f-%.1fphe\t"%(bins[l],bins[l+1]))
        for k in range(len(Qedges)-1):
            spectrumFile.write("%f,%f,%f\t"%(H[k,l],errorbararray_upper[k,l], errorbararray_lower[k,l]))
        spectrumFile.write('\n')
    ax3.set_xscale('symlog',linthreshx=0.5)
    ax4.set_xscale('symlog',linthreshx=0.5)
    ax3.set_yscale('log')
    ax4.set_yscale('log')
    #plt.yscale('symlog',linthreshy=0.0001)
    ax3.legend(fontsize=15)
    ax4.legend(fontsize=15)
    plt.xlabel("collected light [phe]")
    ax3.set_ylabel("Rate per bin [Hz]")
    ax4.set_ylabel("rate per phe [Hz/phe]")
    #plt.ylim([0,0.1])
    ax3.grid(which='both',axis='both')
    ax4.grid(which='both',axis='both')
    plt.show()
    
    fig = plt.figure()
    ax3 = fig.add_subplot(1,2,1)
    ax3.title.set_text("Rates per Scintillation, multiples")
    ax4 = fig.add_subplot(1,2,2)
    for k in range(len(Qedges)-1):
        print("%f-%f keV: %f seconds"%(Qedges[k],Qedges[k+1],LT_by_Q[k]))
        if LT_by_Q[k]>100:
            ax3.errorbar(binc,H_multi[k,:],[errorbararray_multi_upper[k,:], errorbararray_multi_upper[k,:]],marker='.',markersize=7,
                         linestyle='none',label="%f-%f keV"%(Qedges[k],Qedges[k+1]))
            Hnew_multi = []
            errorbarnew_multi_upper = []
            errorbarnew_multi_lower = []
            for l in range(len(binwidths)):
                Hnew_multi.append(np.divide(H_multi[k,l],binwidths[l]))
                errorbarnew_multi_upper.append(np.divide(errorbararray_multi_upper[k,l],binwidths[l]))
                errorbarnew_multi_lower.append(np.divide(errorbararray_multi_lower[k,l],binwidths[l]))
            ax4.errorbar(binc, Hnew_multi, [errorbarnew_multi_upper, errorbarnew_multi_lower],
                         marker='.', markersize=7, linestyle='none',
                         label='%f-%f keV'%(Qedges[k],Qedges[k+1]))
    for l in range(len(bins)-1):
        spectrumFile_multiples.write("%.1f-%.1fphe\t"%(bins[l],bins[l+1]))
        for k in range(len(Qedges)-1):
            spectrumFile_multiples.write("%f,%f,%f\t"%(H_multi[k,l],errorbararray_multi_upper[k,l], errorbararray_multi_lower[k,l]))
        spectrumFile_multiples.write('\n')
    ax3.set_xscale('symlog',linthreshx=0.5)
    ax4.set_xscale('symlog',linthreshx=0.5)
    ax3.set_yscale('log')
    ax4.set_yscale('log')
    #plt.yscale('symlog',linthreshy=0.0001)
    ax3.legend(fontsize=15)
    ax4.legend(fontsize=15)
    plt.xlabel("collected light [phe]")
    ax3.set_ylabel("Rate per bin [Hz]")
    ax4.set_ylabel("rate per phe [Hz/phe]")
    #plt.ylim([0,0.1])
    ax3.grid(which='both',axis='both')
    ax4.grid(which='both',axis='both')
    plt.show()


    
    plt.figure()
    plt.scatter([x[1] for x in bubInfo],[x[3] for x in bubInfo])
    plt.yscale('symlog',linthreshy=0.5)
    plt.xlabel('Seitz Threshold [keV]')
    plt.ylabel('collected light [phe]')
    plt.show

    
    fig,ax1 = plt.subplots()
    ax2 = ax1.twinx()
    ax1.set_xlabel('Seitz Threshold (keV)',fontsize=18)
    ax1.set_ylabel('Live time (s)',fontsize=18)
    ax2.set_ylabel('Number of bubbles',fontsize=18)
    ax1.scatter(centers,LT,20,'r')
    ax2.scatter(centers,onebubcount,20,'b')
    plt.show
    
    

    
    spectrumFile.close() 
    spectrumFile_multiples.close()       
    fractionFile.close()
Пример #2
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 11 10:29:20 2019

@author: bressler
"""

from PICOcode.REFPROP.SeitzModel import SeitzModel
import numpy as np

T = np.arange(-180,-150,5)
print(T)

for t in T:
    print(t)
    m=SeitzModel(30,float(t),'argon')
    print(m.Q[0])
def xeSoundSpeed(runs, mergedfilename, Qbins, FeedbackTransducer):
    if FeedbackTransducer == "PT4":
        pt = 3
    elif FeedbackTransducer == "PT6":
        pt = 5

    #with open("/nashome/b/bressler/sbcoutput/%s_merged_oldPMT.txt"%mergedfilename,"r") as fin:
    with open("/nashome/b/bressler/sbcoutput/%s_merged.txt" % mergedfilename,
              "r") as fin:
        data = fin.readlines()

    headers = data[0].split()
    runind = headers.index("run")
    eventind = headers.index("event")
    xind = headers.index("x")
    yind = headers.index("y")
    zind = headers.index("z")
    lagind = headers.index("lag")
    spectind = headers.index("PMTphe")
    blockedind = headers.index('isBlocked')
    nbubind = headers.index('nbub')
    x = []
    y = []
    z = []
    evid = []
    lag = []
    spect = []
    isblocked = []
    nbub = []
    i = 0
    for line in data:
        if i > 0:
            split_line = line.split()
            evid.append(split_line[runind] + "-" + split_line[eventind])
            isblocked.append(float(split_line[blockedind]))
            x.append(float(split_line[xind]))
            y.append(float(split_line[yind]))
            z.append(float(split_line[zind]))
            lag.append(float(split_line[lagind]))
            spect.append(float(split_line[spectind]))
            nbub.append(float(split_line[nbubind]))

        i += 1

    counts = []
    nbubs = []
    didntpass = 0
    bubInfo = []
    eventcount = np.zeros(87)
    spectra = [[] for i in range(87)]

    LT = np.zeros(87)
    LT_by_Q = np.zeros(len(Qbins) - 1)
    expand_times = [[] for i in range(87)]
    totbub = 0
    onebubcount = np.zeros(87)
    twobubcount = np.zeros(87)
    threebubcount = np.zeros(87)
    setpoints = []
    elt = 0
    temps = []

    passing_lag = []
    passing_z = []

    for run in runs:
        print(run)
        tcut = 0  # was 20
        z_low = -4
        z_high = 0
        preq = 1
        runrawpath = '/bluearc/storage/SBC-17-data/' + run
        events = [
            evnt for evnt in listdir(runrawpath)
            if not isfile(join(runrawpath, evnt))
        ]
        Nevents = len(events)
        runreconpath = "/pnfs/coupp/persistent/grid_output/SBC-17/output/%s/" % run
        historyfilename = runreconpath + "HistoryAnalysis_%s.bin" % run
        history = sbc.DataHandling.ReadBinary.ReadBlock(historyfilename)
        getbubfile = "/coupp/data/home/coupp/HumanGetBub_output_SBC-17/HumanGetBub_%s.bin" % run
        c = sbc.DataHandling.ReadBinary.ReadBlock(getbubfile)

        eventn = c["ev"]
        count = Counter(eventn)
        edges = history["PressureEdge"][pt]
        centersp = [(edges[i] + edges[i + 1]) / 2
                    for i in range(len(edges) - 1)]
        #centers = Qvals
        e0 = sbc.DataHandling.GetSBCEvent.GetEvent(runrawpath, 0, "slowDAQ")
        T = np.mean(e0["slowDAQ"]["T1"])
        temps.append(T)
        sm = SeitzModel(list(edges), T, 'xenon')
        edges_by_Q = sm.Q
        centers = [(edges_by_Q[i] + edges_by_Q[i + 1]) / 2
                   for i in range(len(edges_by_Q) - 1)]

        print("T=%f C" % T)

        for c in count:
            N = count[c]
            counts.append(N)
            """
            if N%2 != 0 and N != 1:
                print("lines isn't even")
                print(c)
                print(N)
            elif N%2 == 0:
                n = N/2
                nbubs.append(n)
                """
        for eventn in range(Nevents):
            try:
                indices_back = 30
                event_ID = run + "-" + str(eventn)
                mergedind = evid.index(event_ID)
                bl = isblocked[mergedind]
                light = spect[mergedind]
                ev_z = z[mergedind]
                if np.isnan(light):
                    light = 0
                ev_z = z[mergedind]
                ev_lag = lag[mergedind]
                #onebub = not np.isnan(runposreco["z"][0][int(eventn)])
                n_from_merged = nbub[mergedind]
                n = 0
                N = count[eventn]
                if N % 2 == 0:
                    n = N / 2
                    nbubs.append(n)

                if n_from_merged != n:
                    print('n and merged n dont match')
                    print("n here: %d" % n)
                    print("n from merged: %d" % n_from_merged)
                e = sbc.DataHandling.GetSBCEvent.GetEvent(
                    runrawpath, eventn, "slowDAQ", "event")
                t = e["slowDAQ"]["elapsed_time"]
                tcenters = [(t[i + 1] + t[i]) / 2 for i in range(len(t) - 1)]
                trig_time = t[list(e["slowDAQ"]["TriggerOut"]).index(1.0) -
                              indices_back]
                pslope = np.diff(e["slowDAQ"][FeedbackTransducer])
                expstartind = list(pslope).index(min(list(pslope)))
                exp_start = tcenters[expstartind]
                trig_pressure = e["slowDAQ"][FeedbackTransducer][
                    list(e["slowDAQ"]["TriggerOut"]).index(1.0) - indices_back]
                T = np.mean(e["slowDAQ"]["T1"])

                #print(Q[0])
                pset = e["event"]["Pset"]
                ev_lt = e["event"]['livetime']
                elt += ev_lt
                if pset not in setpoints:
                    setpoints.append(pset)
                    #print(pset)
                #print(len(history["PressureBins"][eventn]))
                """
                plt.figure()
                plt.plot([trig_time,trig_time],[0,200],label="Bubble time")
                plt.plot([exp_start,exp_start],[0,200],label="Expansion start")
                plt.plot([0,max(t)],[trig_pressure,trig_pressure],label="Bubble pressure")
                plt.plot(t,e["slowDAQ"]["PT6"],label="PT6")
                plt.plot(tcenters,pslope,label="Pressure slope")
                plt.xlabel("time",fontsize=18)
                plt.ylabel("signal",fontsize=18)
                plt.legend(fontsize=18)
                plt.show
                """
                if n == 1 and ev_lt > 20 and pset == 25:
                    totbub += 1
                    for i in range(len(centers)):
                        if trig_time > exp_start + tcut:
                            #print(trig_pressure)
                            #print(pset)
                            if (trig_pressure >= edges[i]
                                    and trig_pressure <= edges[i + 1]
                                ) and abs(trig_pressure - pset) < preq / 2:
                                onebubcount[i] += 1
                                eventcount[i] += 1
                                if not bl and not np.isnan(light):
                                    if light > 0:
                                        spectra[i].append(light)
                                        passing_lag.append(ev_lag)
                                        passing_z.append(ev_z)
            except Exception as x:
                print(x)

    plt.figure()
    plt.scatter(passing_z, passing_lag, 20)
    plt.xlabel('z [cm]', fontsize=19)
    plt.ylabel('lag [microseconds]', fontsize=19)
    plt.show()

    def gaussian(x, mu, sigma, amplitude):
        return amplitude * np.exp(-((x - mu) / (np.sqrt(2) * sigma))**2)

    def lin(x, m, b):
        return m * x + b

    zbinedges = np.arange(-2.75, 0.25, 0.25)
    zpts = [(zbinedges[i] + zbinedges[i + 1]) / 2
            for i in range(len(zbinedges) - 1)]
    zbinlags = [[] for i in range(len(zbinedges) - 1)]
    print(zbinlags)
    for j in range(len(passing_lag)):
        for i in range(len(zbinedges) - 1):
            if passing_z[j] >= zbinedges[i] and passing_z[j] < zbinedges[
                    i + 1] and passing_lag[j] > -275:
                zbinlags[i].append(passing_lag[j])
    """
    params, params_cov = scipy.optimize.curve_fit(fit_fun, ch1zs, ch1lags)
    
    fitx = np.arange(-3,0,0.1)
    ft = [fit_fun(fitx[i], params[0], params[1], params[2],
                  params[3], params[4]) for i in range(len(fitx))]
    
    ss = (-1/params[3])*10000
    """

    avgs = []
    avgs_std = []

    gausfitx = np.arange(-400, 0, 0.1)

    for j in range(len(zpts)):
        Nbins = int(np.ceil(np.sqrt(len(zbinlags[j]))))
        print(Nbins)
        if Nbins == 0:
            Nbins = 1
        if len(zbinlags[j]) > 0:
            print(zbinlags[j])
            #avgs.append(np.mean(zbinlags[j]))
            gparams = [np.mean(zbinlags[j]), np.std(zbinlags[j]), 10]
            """
            dat,bins = np.histogram(zbinlags[j],Nbins)
            bincenters = [(bins[i]+bins[i+1])/2 for i in range(len(bins)-1)]
            try:
                gparams,gparams_cov = scipy.optimize.curve_fit(gaussian,bincenters,dat,
                                                                   p0=(-250,50,10))
            except Exception as ex:
                print(ex)
                gparams = [np.mean(zbinlags[j]), np.std(zbinlags[j]), 10]
                print("bin centered on z=%.2f uses numpy mean and std"%zpts[j])
                print(gparams)
            """
            avgs.append(gparams[0])
            avgs_std.append(gparams[1])

            gausfit = [
                gaussian(gausfitx[i], gparams[0], gparams[1], gparams[2])
                for i in range(len(gausfitx))
            ]

    lfitx = np.arange(-3, 0, 0.1)
    print(zpts)
    print(avgs)
    print(avgs_std)
    lparams, lparams_cov = scipy.optimize.curve_fit(lin,
                                                    zpts[:-1],
                                                    avgs[:-1],
                                                    sigma=avgs_std[:-1],
                                                    p0=[50, -50])
    ss = (1 / abs(lparams[0])) * 10000
    ss_err = 10000 * max(
        abs(1 / abs(lparams[0]) - 1 /
            (abs(lparams[0]) + np.sqrt(lparams_cov[0][0]))),
        abs(1 / abs(lparams[0]) - 1 /
            (abs(lparams[0]) - np.sqrt(lparams_cov[0][0]))))
    plt.figure()
    plt.grid()
    plt.scatter(passing_z, passing_lag)
    plt.plot(
        lfitx,
        lparams[0] * lfitx + lparams[1],
        color="g",
        linewidth=4,
        label=r"fit line: $\Delta t_0 = (%.2f \pm %.2f)z +(%.2f \pm %.2f)$" %
        (lparams[0], np.sqrt(
            lparams_cov[0][0]), lparams[1], np.sqrt(lparams_cov[1][1])))
    #plt.plot(fitx,params[3]*fitx + params[4],color = 'g',linewidth=4,
    #         label = "Linear part of fit, dt = %fz+%f"%(params[3],params[4]))
    #plt.plot(fitx,ft,color='r',linewidth=5,
    #         label = "Fit: dt = %fcos(%fz+%f) + %fz +%f"%(params[0],
    #                                 params[1],params[2],params[3],params[4]))
    plt.errorbar(zpts,
                 avgs,
                 avgs_std,
                 color='c',
                 marker='o',
                 markersize=10,
                 linestyle='none')
    plt.xlabel("z position [cm]", fontsize=20)
    plt.ylabel(r"$\Delta t_0 = t_{PMT} - t_{Piezo}$ [$\mu$s]", fontsize=20)
    plt.title(r"Channel 0, $v_s=%.2f \pm %.2f$ m/s" % (ss, ss_err),
              fontsize=20)
    plt.legend(fontsize=18)
    plt.show

    plt.figure()
    plt.hist(spect, int(np.floor(np.sqrt(len(spect)))))
    plt.show
Пример #4
0
def getRate(xyzf, runs, LTpreq, PT):
    LT = []
    totbub = 0
    bubperpset = []
    doublesperpset = []
    triplesperpset = []
    setpoints = []
    elt = 0
    feedbackTransducer = int(PT[-1]) - 1
    temperatures = []
    counts = []

    event_livetimes = []
    event_counter = 0
    for run in runs:
        runpath = '/bluearc/storage/SBC-17-data/' + run + '/'
        events = [
            evnt for evnt in listdir(runpath)
            if not isfile(join(runpath, evnt))
        ]
        Nevents = len(events)
        print("run " + run + ": %d events" % Nevents)
        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/' + run
        runreconpath = "/pnfs/coupp/persistent/grid_output/SBC-17/output/%s/" % run
        historyfilename = runreconpath + "HistoryAnalysis_%s.bin" % run
        history = sbc.DataHandling.ReadBinary.ReadBlock(historyfilename)

        getbubfile = "/coupp/data/home/coupp/HumanGetBub_output_SBC-17/HumanGetBub_%s.bin" % run
        c = sbc.DataHandling.ReadBinary.ReadBlock(getbubfile)
        #print(c.keys())
        evn = c["ev"]
        #print(evn)
        #print(c["nbubimage"])
        count = Counter(evn)
        #print(count)
        nbubs = np.zeros(Nevents)
        #print(len(nbubs))
        for c in count:
            #print(c)
            N = count[c]
            #print(N)
            counts.append(N)
            if N % 2 != 0 and N != 1:
                print("lines isn't even")
                print(c)
                print(N)
            elif N % 2 == 0:
                n = N / 2
                nbubs[c] = n
        e0 = sbc.DataHandling.GetSBCEvent.GetEvent(runrawpath, 0, "slowDAQ",
                                                   "event")
        T25 = np.mean(e0["slowDAQ"]["T1"])
        seitz25 = SeitzModel(25, T25, 'xenon')
        Q25 = seitz25.Q
        #print(nbubs)
        for eventn in range(Nevents):
            try:
                nobub = np.isnan(runposreco["z"][0][int(eventn)])
                n = nbubs[int(eventn)]
                #print("n=%d"%n)

                if nobub and n == 1:
                    print("nobub and n=1: " + run + '-' + str(eventn))
                """
                elif (not nobub) and n==1:
                    print("(not nobub) and n = 1: " + run + '-'+str(eventn))
                elif n != 1 and nobub:
                    print("nobub and n != 1: "+run+'-'+str(eventn))
                elif n !=1 and not nobub:
                    print("not nobub and n != 1: "+run+'-'+str(eventn))
                """
                #print(n==1)
                e = sbc.DataHandling.GetSBCEvent.GetEvent(
                    runrawpath, eventn, "slowDAQ", "event")
                lt_event = e["event"]["livetime"]
                if (lt_event > 800):
                    if run + '-' + str(eventn) not in OKLONGEVENTS:
                        print("check long event, excluding now: " + run + "-" +
                              str(eventn))
                        continue
                event_livetimes.append(lt_event)
                event_counter += 1
                if lt_event < 20:
                    #print("short event excluded")
                    continue
                T = np.mean(e["slowDAQ"]["T1"])
                #print(T)
                if T > -1000:
                    temperatures.append(T)
                else:
                    print("Not including unpysical temperature %f C" % T)
                pset = e["event"]["Pset"]
                #seitz = SeitzModel(pset,T,'xenon')
                #Q = seitz.Q
                elt += e["event"]["livetime"]
                if pset not in setpoints:
                    setpoints.append(pset)
                    LT.append(0)
                    bubperpset.append(0)
                    doublesperpset.append(0)
                    triplesperpset.append(0)
                ind = setpoints.index(pset)

                indices_back = 30
                trig_pressure = e["slowDAQ"][PT][
                    list(e["slowDAQ"]["TriggerOut"]).index(1.0) - indices_back]

                #if not nobub:
                #print("adding bubble at P = %f"%trig_pressure)
                if n > 0:
                    totbub += 1
                if (np.abs(trig_pressure - pset) < LTpreq / 2):
                    if n == 1: bubperpset[ind] += 1
                    elif n == 2: doublesperpset[ind] += 1
                    elif n == 3: triplesperpset[ind] += 1

                edges = history["PressureEdge"][feedbackTransducer]
                times = history["PressureBins"][eventn][feedbackTransducer][:]
                centers = [(edges[i] + edges[i + 1]) / 2
                           for i in range(len(edges) - 1)]
                #print(edges)
                for i in range(len(centers)):
                    if abs(centers[i] - pset) < LTpreq / 2:
                        LT[ind] += times[i]

            except Exception as x:
                print(x)
                break
    totlt = sum(LT)
    r = totbub / totlt
    rerr = np.sqrt(totbub) / totlt

    rperpset = np.divide(bubperpset, LT)
    r_err_perpset = np.divide(np.sqrt(bubperpset), LT)

    for i in range(len(rperpset)):
        if LT[i] > 50:
            seitz = SeitzModel(setpoints[i], np.mean(temperatures), 'xenon')
            #print(setpoints[i])
            #print(min(temperatures))
            #print(temperatures)
            #print(seitz)
            print("@@@@@@@@@@@@@@@@@@@@@@@@@@")
            print("Pressure bin: " + str(setpoints[i]))
            print("Live Time: " + str(LT[i]))
            print("Single Bubbles: " + str(bubperpset[i]))
            print("Singles Rate: " + str(rperpset[i]) + "+/-" +
                  str(r_err_perpset[i]))
            print("Double Bubbles: %d" % doublesperpset[i])
            print("Doubles Rate: %.2e" % (doublesperpset[i] / LT[i]))
            print("Triple Bubbles: %d" % triplesperpset[i])
            print("Triples Rate: %.2e" % (triplesperpset[i] / LT[i]))
            print("Seitz Threshold: %f keV" % seitz.Q)
            print("Temperature: %.2fC" % np.mean(temperatures))
            print("\n")
    if 25.0 in setpoints:
        print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
        print("25 psia bin: ")
        print(str(LT[setpoints.index(25.0)]) + "s")
        print(str(bubperpset[setpoints.index(25.0)]) + " bubbles")
        print(str(Q25) + " keV")
        print(str(T25) + " Celsius")
        print("rate: " + str(rperpset[setpoints.index(25.0)]) + "+/-" +
              str(r_err_perpset[setpoints.index(25.0)]) + " Hz")
        print("\n")
        print("overall rate: " + str(r) + "+/-" + str(rerr) + "Hz")
        print("total events: %d" % event_counter)
        print("total bubbles: " + str(totbub))
        print("fraction of events with bubbles: %f" % (totbub / event_counter))
        print("total live time: " + str(totlt))
        print("total live time from events: " + str(elt))
        print("mean live time: %f sec" % np.mean(event_livetimes))
        print("trigger rate: %f Hz" % (1 / float(np.mean(event_livetimes))))
        print("bubble rate from bub fraction  and LT: %f Hz" % (float(
            (totbub / event_counter)) / float(np.mean(event_livetimes))))
        print("\n")
    plt.figure()
    plt.scatter(np.arange(event_counter),
                event_livetimes,
                facecolor='none',
                edgecolor='b')
    plt.grid()
    plt.xlabel('event count')
    plt.ylabel('event livetime (s)')
    plt.show()
    plt.figure()
    plt.hist(event_livetimes, int(np.ceil(np.sqrt(len(event_livetimes)))))
    plt.show()
    return [totbub, totlt, rperpset, r_err_perpset, r, rerr, setpoints]
Пример #5
0
LTpreq=5
indices_back=30
triggerp = []
for run in runs:
    runrawpath = '/bluearc/storage/SBC-17-data/'+run
    runreconpath = "/pnfs/coupp/persistent/grid_output/SBC-17/output/%s/"%run
    historyfilename = runreconpath+"HistoryAnalysis_%s.bin"%run
    history = sbc.DataHandling.ReadBinary.ReadBlock(historyfilename)
    for eventn in range(10):
        try:     
            e = sbc.DataHandling.GetSBCEvent.GetEvent(runrawpath,eventn,"slowDAQ","event")
            T = np.mean(e["slowDAQ"]["T1"])
            t = e["slowDAQ"]["elapsed_time"]
            print(T)
            pset = e["event"]["Pset"]
            seitz = SeitzModel(pset,T,'xenon')
            Q = seitz.Q
            PT6 = e["slowDAQ"]["PT6"]
            PT5 = e["slowDAQ"]["PT5"]
            plt.figure()
            PT4 = e["slowDAQ"]["PT4"]
            plt.plot(t,PT6,label="PT6")
            plt.plot(t,PT5,label="PT5")
            plt.plot(t,PT4,label="PT4")
            plt.plot([t[0],t[-1]],[pset,pset],label="pset")
            plt.legend()
            print("event livetime: "+str(e["event"]["livetime"]))
            trig_pressure = e["slowDAQ"]["PT6"][list(e["slowDAQ"]["TriggerOut"]).index(1.0)-indices_back]
            
            edges = history["PressureEdge"][5]
            times = history["PressureBins"][eventn][5][:]
for run in runs:
    print(run)
    tcut = 0

    runrawpath = '/bluearc/storage/SBC-17-data/' + run
    runreconpath = "/pnfs/coupp/persistent/grid_output/SBC-17/output/%s/" % run
    historyfilename = runreconpath + "HistoryAnalysis_%s.bin" % run
    history = sbc.DataHandling.ReadBinary.ReadBlock(historyfilename)

    edges = history["PressureEdge"][5]
    centersp = [(edges[i] + edges[i + 1]) / 2 for i in range(len(edges) - 1)]
    #centers = Qvals
    e0 = sbc.DataHandling.GetSBCEvent.GetEvent(runrawpath, 0, "slowDAQ")
    T = np.mean(e0["slowDAQ"]["T1"])
    temps.append(T)
    sm = SeitzModel(list(edges), T, 'xenon')
    edges_by_Q = sm.Q
    centers = [(edges_by_Q[i] + edges_by_Q[i + 1]) / 2
               for i in range(len(edges_by_Q) - 1)]

    print("T=%f C" % T)

    for eventn in range(101):
        try:
            indices_back = 30
            event_ID = run + "-" + str(eventn)
            e = sbc.DataHandling.GetSBCEvent.GetEvent(runrawpath, eventn)
            acousticfilename = runreconpath + "AcousticAnalysis_%s.bin" % run
            a = sbc.DataHandling.ReadBinary.ReadBlock(acousticfilename)
            bubt0 = a["bubble_t0"]
Пример #7
0
@author: bressler
"""

from PICOcode.REFPROP.SeitzModel import SeitzModel
import numpy as np
import matplotlib.pyplot as plt

T = np.arange(-153, -138, 1)
#T=[-143]
print(T)
P = np.arange(15, 382, 2)

QperT = [[] for i in range(len(T))]
RperT = [[] for i in range(len(T))]

for i in range(len(T)):
    print(T[i])
    for j in range(len(P)):
        m = SeitzModel(float(P[j]), float(T[i]), 'argon')
        QperT[i].append(m.Q[0])
        RperT[i].append(m.Rc[0])

plt.figure()
for i in range(len(T)):
    plt.plot(QperT[i], RperT[i], label="T=%f K" % (T[i] + 273.15))
plt.xlim([0.01, 0.5])
plt.ylim([0, 15])
plt.xlabel("Seitz Threshold [keV]")
plt.ylabel("Critical Radius [nm]")
plt.legend()
plt.show()