""" plot__sipm_pde python script to access the halld_sipm data base (created by Yi) and plot SiPM properties The values are then histogramed. """ import os import subprocess import numpy from matplotlib import pyplot as plt from datetime import datetime, date, time, timedelta from matplotlib.backends.backend_pdf import PdfPages Vover = 1.2 # create list of file names filenames = [] figs = [] # create text file with data from sipm_dpe table. nfiles = 0 filenames.append("sipmfiles/sipm_V"+str(int(10*Vover))+".dat") command =["mysql","-hhallddb.jlab.org","-uhalld","-pGlueX_00","halld_sipm","-e","select * from sipm_pde where voltage_offset="+str(Vover-0.9)+";"] print "command=",command fout = open(filenames[nfiles],"w") subprocess.call(command,stdout=fout) fout.close() # create text file from data base first fin = open(filenames[0],"r") sn_in = [] temp_in = [] voltage_in = [] pde_in = [] DR_in = [] gain_in = [] xtalk_in = [] entries = 0 nplots = 0 for line in fin: entries += 1 linew = line.split() if entries == 1: for token in linew: print "First line dump, num tokens=",len(linew)," token=",token continue # discard first entry Iover = int(float(linew[2])*10) IVover = int((Vover-0.9 + 0.001)*10) if IVover < 0: IVover = IVover -1 # print "Iover=",Iover," IVover=",IVover if Iover == IVover: # make integer instead of floating comparison sn_in.append(float(linew[0])) temp_in.append(float(linew[1])) voltage_in.append(float(linew[5])) pde_in.append(float(linew[8])) DR_in.append(float(linew[6])) gain_in.append(float(linew[10])) xtalk_in.append(float(linew[12])) entries -= 1 print "\nNumber of entries=",entries," for ",fin print "Number of entries for pde=",len(pde_in) # print "pde=",pde_in fin.close() # convert to numpy arrays for plotting sn = numpy.array(sn_in) temp = numpy.array(temp_in) voltage = numpy.array(voltage_in) pde = numpy.array(pde_in) DR = numpy.array(DR_in) gain = numpy.array(gain_in) xtalk = numpy.array(xtalk_in) numpy.set_printoptions(threshold='nan') # print "Length pde=",len(pde),"pde=", pde,"\n\n" fig = plt.figure(1) figs.append(fig) nbins = 100 nsub = 1 xmin = 0 xmax = 5000 plt.subplot(2,2,nsub) binwidth = (xmax-xmin)/float(nbins) n, bins, patches = plt.hist(sn,bins=numpy.arange(xmin,xmax,binwidth),histtype='step',color='black',log=False) plt.ylabel("Entries") plt.xlabel("Serial Number") plt.title("Vover="+str(Vover)+" V") plt.axis([xmin,xmax,0,10000]) plt.autoscale(enable=True,axis='y') nbins = 100 nsub = 2 xmin = 0 xmax = 30 plt.subplot(2,2,nsub) binwidth = (xmax-xmin)/float(nbins) n, bins, patches = plt.hist(temp,bins=numpy.arange(xmin,xmax,binwidth),histtype='step',color='black',log=False) plt.ylabel("Entries") plt.xlabel("Temperature (degC)") plt.title("Vover="+str(Vover)+" V") plt.axis([xmin,xmax,0,10000]) plt.autoscale(enable=True,axis='y') nbins = 100 nsub = 3 xmin = 65 xmax = 80 plt.subplot(2,2,nsub) binwidth = (xmax-xmin)/float(nbins) n, bins, patches = plt.hist(voltage,bins=numpy.arange(xmin,xmax,binwidth),histtype='step',color='black',log=False) plt.ylabel("Entries") plt.xlabel("Vop (V)") plt.title("Vover="+str(Vover)+" V. Mean="+'{:.3f}'.format(numpy.average(voltage))) plt.axis([xmin,xmax,0,10000]) plt.autoscale(enable=True,axis='y') plt.tight_layout() fig = plt.figure(2) figs.append(fig) nsub = 1 xmin = 0 xmax = 10 plt.subplot(2,2,nsub) binwidth = (xmax-xmin)/float(nbins) n, bins, patches = plt.hist(gain,bins=numpy.arange(xmin,xmax,binwidth),histtype='step',color='black',log=False) plt.ylabel("Entries") plt.xlabel("Gain (10^5)") plt.title("Vover="+str(Vover)+" V") plt.title("Vover="+str(Vover)+" V. Mean="+'{:.3f}'.format(numpy.average(gain))) plt.axis([xmin,xmax,0,10000]) plt.autoscale(enable=True,axis='y') nsub = 2 xmin = 0 xmax = 0.3 plt.subplot(2,2,nsub) binwidth = (xmax-xmin)/float(nbins) n, bins, patches = plt.hist(pde,bins=numpy.arange(xmin,xmax,binwidth),histtype='step',color='black',log=False) plt.ylabel("Entries") plt.xlabel("PDE") plt.title("Vover="+str(Vover)+" V. Mean="+'{:.3f}'.format(numpy.average(pde))) plt.axis([xmin,xmax,0,10000]) plt.autoscale(enable=True,axis='y') # plt.figtext(0.2,0.8,'example text') nsub = 3 xmin = 0 xmax = 3 plt.subplot(2,2,nsub) binwidth = (xmax-xmin)/float(nbins) n, bins, patches = plt.hist(DR,bins=numpy.arange(xmin,xmax,binwidth),histtype='step',color='black',log=False) plt.ylabel("Entries") plt.xlabel("Dark Rate (MHz)") plt.title("Vover="+str(Vover)+" V. Mean="+'{:.3f}'.format(numpy.average(DR))) plt.axis([xmin,xmax,0,10000]) plt.autoscale(enable=True,axis='y') nsub = 4 xmin = 0 xmax = 1 plt.subplot(2,2,nsub) binwidth = (xmax-xmin)/float(nbins) n, bins, patches = plt.hist(xtalk,bins=numpy.arange(xmin,xmax,binwidth),histtype='step',color='black',log=False) plt.ylabel("Entries") plt.xlabel("Cross Talk") plt.title("Vover="+str(Vover)+" V. Mean="+'{:.3f}'.format(numpy.average(xtalk))) plt.axis([xmin,xmax,0,10000]) plt.autoscale(enable=True,axis='y') plt.tight_layout() # plt.show() pdfname = "plot_sipm_pde_V"+str(int(10*Vover))+".pdf" print "PDF filename=",pdfname with PdfPages(pdfname) as pdf: for fig in figs: pdf.savefig(fig)