##Preamble from __future__ import division,print_function import pandas as pds rc('figure',figsize=(12,4)) rc('legend',loc='best') rc('font',size = 14.0) rc('font', family='serif') rc('text', usetex=False) rc('lines', markersize=10) import os from os.path import expanduser %load_ext autoreload %autoreload 2 import scipy.optimize as opt from scipy import stats import uncertainties as unc import ProcessingCTRData as pc print("Complete") #Global Properties aloc = '/home/mbrown/Desktop/doipaper/figures/' #files saved here! wrapdict = {'wrapped':'r','unwrapped':'b','partialwrap':cm.gist_rainbow(0.4)} errwrapdict = {'wrapped':'r','unwrapped':'b','partialwrap':'g'} savefigures = True df = pds.read_csv('alldata.csv') fig, ax = subplots() ax.grid() crystaldict = {"30A":"*","30B":"^"} df = df[df.length == 30] df = df[df.specialkey == 'normal'] pp = lambda aval : '{:1.2f}'.format(aval) for config, grp in df.groupby('configuration'): for key, grp in grp.groupby('SampleB'): print(config,key) ax.errorbar(grp.DOI,grp.CTR,yerr=grp.CTRerr,fmt='.',marker=crystaldict[key],color=wrapdict[config],ecolor=errwrapdict[config],label=key+' '+config) m,b = polyfit(grp.DOI,grp.CTR,1,w=grp.CTRerr) #ax.hlines(b,0,30,color='k',linestyles='dashed') print("covariance",pp(m)) print("intercept",pp(b)) m,c,b = polyfit(grp.DOI,grp.CTR,2,w=grp.CTRerr) print("covariance",pp(m)) print("Gradient",pp(c),"intercept",pp(b)) ax.set_xlabel("Depth of Interaction (mm)") ax.set_ylabel("Coincidence Time Resolution (ps)") ax.set_xlim(-2,32) ax.set_ylim(160,300) ax.legend(ncol=2) fig.tight_layout() if savefigures: pc.savefigureadir('ctrdoi',aloc,fig) show() df = pds.read_csv('alldata.csv') rc('text', usetex=True) rc('font', family='serif') fig, ax = subplots() ax.grid() crystaldict = {"30A":"*","30B":"^"} df = df[df.length == 30] df = df[df.specialkey == 'normal'] for config, grp in df.groupby('configuration'): for key, grp in grp.groupby('SampleB'): ax.errorbar(grp.DOI,grp.numofsamples,yerr=sqrt(grp.numofsamples),fmt='.',marker=crystaldict[key],color=wrapdict[config],ecolor=errwrapdict[config],label=key+' '+config) ax.set_xlim(-2,32) step = lambda x, xmin, xmax : 1/(xmax-xmin)*((x>=xmin) & (x<=xmax)) x = linspace(-5,40,500) xs = linspace(-5,5) y = convolve(step(x,0,30),stats.norm(scale=1/2.355).pdf(xs),mode='same') y*=3360/max(y) ax.plot(x,y,'k--') ax.set_xlabel("Depth of Interaction (mm)") ax.set_ylabel("Number of $\gamma\gamma$ events detected") ax.legend(ncol=2) fig.tight_layout() if savefigures: pc.savefigureadir('numberofsamples',aloc,fig) #pc.savefigureadir('numberofsamples','/home/mbrown/Desktop/figures-svg',fig,ext='svg') show() rc('text', usetex=False) df = pds.read_csv('alldata.csv') fig, ax = subplots() ax.grid() crystaldict = {"30A":"*","30B":"^"} df = df[df.length == 30] df = df[df.specialkey == 'normal'] for config, grp in df.groupby('configuration'): for key, grp in grp.groupby('SampleB'): ax.errorbar(grp.DOI,grp.location,yerr=grp.locationerr,fmt='.',marker=crystaldict[key],color=wrapdict[config],ecolor=errwrapdict[config],label=key+' '+config) vals = [unc.ufloat(a,b) for a,b in zip(grp.location, grp.locationerr)] print(ptp(vals),"ps") linear = lambda xdata, m,c: m*xdata+c for reducelim in [30,25,20,15,12]: fgrp = grp[grp.DOI < reducelim] (m,c), err = opt.curve_fit(linear,array(fgrp['DOI']),array(fgrp['location']),sigma=fgrp['locationerr']) merr,cerr = err.diagonal() #X = linspace(0,30) #Y = linear(X,m,c) #ax.plot(X,Y,'k--') factor = 3E-1 print(config,"<",reducelim,"n", unc.ufloat(m,merr)*factor) ax.set_xlabel("Depth of Interaction (mm)") ax.set_ylabel("Delay Peak Centroid (ps)") ax.set_xlim(-2,32) ax.set_ylim(100,400) ax.legend(ncol=2) fig.tight_layout() if savefigures: pc.savefigureadir('centroidposition',aloc,fig) #pc.savefigureadir('centroidposition','/home/mbrown/Desktop/figures-svg',fig,ext='svg') show() df = pds.read_csv('alldata.csv') fig, ax = subplots() ax.grid() crystaldict = {"30A":"*","30B":"^"} df = df[df.length == 30] df = df[df.specialkey == 'normal'] for config, grp in df.groupby('configuration'): for key, grp in grp.groupby('SampleB'): ax.errorbar(grp.DOI,grp.ERright,yerr=grp.ERrighterr,fmt='.',marker=crystaldict[key],color=wrapdict[config],ecolor=errwrapdict[config],label=key+' '+config) ax.set_xlabel("Depth of Interaction (mm)") ax.set_ylabel("Energy Resolution (%)") ax.set_xlim(-2,32) ax.legend(ncol=2) DOI = linspace(2,30,1000) Y = lambda xdata, m, c,A : c+A/(xdata-m)**2 fdf = df[df.configuration == 'unwrapped'] param, err = opt.curve_fit(Y,fdf.DOI,fdf.ERright,sigma=fdf.ERrighterr) for p,e in zip(param,err.diagonal()): val = unc.ufloat(p,e) print(val) #ax.plot(DOI,Y(DOI,*param),'k--') fig.tight_layout() if savefigures: pc.savefigureadir('energyresolution',aloc,fig) #pc.savefigureadir('energyresolution','/home/mbrown/Desktop/figures-svg',fig,ext='svg') show() df = pds.read_csv('alldata.csv') fig, ax = subplots() ax.grid() crystaldict = {"30A":"*","30B":"^"} df = df[df.length == 30] df = df[df.specialkey == 'normal'] for config, grp in df.groupby('configuration'): for key, grp in grp.groupby('SampleB'): ax.errorbar(grp.DOI,grp.RPloc,yerr=grp.RPlocerr,fmt='.',marker=crystaldict[key],color=wrapdict[config],ecolor=errwrapdict[config],label=key+' '+config) ax.set_xlabel("Depth of Interaction (mm)") ax.set_ylabel("Right Photopeak Centroid (Arb.)") ax.set_xlim(-2,32) ax.set_ylim(0.3,0.65) ax.legend(ncol=2) fig.tight_layout() if savefigures: pc.savefigureadir('lightoutput',aloc,fig) #pc.savefigureadir('lightoutput','/home/mbrown/Desktop/figures-svg',fig,ext='svg') show() markerdict = {'wrapped':'*','unwrapped':'^','partialwrap':'.'} df = pds.read_csv('alldata.csv') fig, ax = subplots() ax.grid() df = df[df.length == 20] df = df[df.SampleB == '2396'] df = df[df.specialkey == 'normal'] df = df[df.CTR < 300] lbl = {"partialwrap":"Partially Wrapped","wrapped":"Wrapped","unwrapped":"Unwrapped"} for config, grp in df.groupby('configuration'): for key, grp in grp.groupby('SampleB'): ax.errorbar(grp.DOI,grp.CTR,yerr=grp.CTRerr, fmt='.', marker=markerdict[config],color=wrapdict[config],ecolor=errwrapdict[config],label=lbl[config]) print(config,key,grp.CTR.mean(),grp.CTRerr.mean()) ax.set_xlabel("Depth of Interaction (mm)") ax.set_ylabel("Coincidence Time Resolution (ps)") ax.set_xlim(-1,21) ax.set_ylim(180,290) leg = ax.legend(ncol=3) fig.tight_layout() if savefigures: pc.savefigureadir('ctrdoi-20',aloc,fig) #pc.savefigureadir('ctrdoi-20','/home/mbrown/Desktop/figures-svg',fig,ext='svg') show() df = pds.read_csv('alldata.csv') rc('text', usetex=True) fig, ax = subplots() ax.grid() df = df[df.length == 20] df = df[df.SampleB == '2396'] df = df[df.specialkey == 'normal'] for config, grp in df.groupby('configuration'): for key, grp in grp.groupby('SampleB'): ax.errorbar(grp.DOI,grp.numofsamples,yerr=sqrt(grp.numofsamples),fmt='.',marker=markerdict[config],color=wrapdict[config],ecolor=errwrapdict[config],label=lbl[config]) ax.set_xlim(-1,21) ax.set_ylim(0,7000) step = lambda x, xmin, xmax : 1/(xmax-xmin)*((x>=xmin) & (x<=xmax)) x = linspace(-5,40,500) xs = linspace(-5,5) y = convolve(step(x,0,20),stats.norm(scale=1/2.355).pdf(xs),mode='same') y*=5000/max(y) ax.plot(x,y,'k--') ax.set_xlabel("Depth of Interaction (mm)") ax.set_ylabel("Number of $\gamma\gamma$ events detected") ax.legend(ncol=3) fig.tight_layout() if savefigures: pc.savefigureadir('numberofsamples-20',aloc,fig) #pc.savefigureadir('numberofsamples-20','/home/mbrown/Desktop/figures-svg',fig,ext='svg') show() rc('text', usetex=False) df = pds.read_csv('alldata.csv') fig, ax = subplots() ax.grid() df = df[df.length == 20] df = df[df.SampleB == '2396'] df = df[df.specialkey == 'normal'] for config, grp in df.groupby('configuration'): for key, grp in grp.groupby('SampleB'): ax.errorbar(grp.DOI,grp.location,yerr=grp.locationerr,fmt='.',marker=markerdict[config],color=wrapdict[config],ecolor=errwrapdict[config],label=lbl[config]) vals = [unc.ufloat(a,b) for a,b in zip(grp.location, grp.locationerr)] print(ptp(vals),"ps") for reducelim in [20,15,10,8]: fgrp = grp[grp.DOI < reducelim] (m,c), err = opt.curve_fit(linear,array(fgrp['DOI']),array(fgrp['location']),sigma=fgrp['locationerr']) merr,cerr = err.diagonal() #X = linspace(0,30) #Y = linear(X,m,c) #ax.plot(X,Y,'k--') factor = 3E-1 print(config,"<",reducelim,"n", unc.ufloat(m,merr)*factor) ax.set_xlabel("Depth of Interaction (mm)") ax.set_ylabel("Delay Peak Centroid (ps)") ax.set_xlim(-1,21) ax.set_ylim(0,250) ax.legend(ncol=3) fig.tight_layout() if savefigures: pc.savefigureadir('centroidposition-20',aloc,fig) #pc.savefigureadir('centroidposition-20','/home/mbrown/Desktop/figures-svg',fig,ext='svg') show() df = pds.read_csv('alldata.csv') fig, ax = subplots() ax.grid() df = df[df.length == 20] df = df[df.SampleB == '2396'] df = df[df.specialkey == 'normal'] for config, grp in df.groupby('configuration'): for key, grp in grp.groupby('SampleB'): ax.errorbar(grp.DOI,grp.ERright,yerr=grp.ERrighterr,fmt='.',marker=markerdict[config],color=wrapdict[config],ecolor=errwrapdict[config],label=lbl[config]) ax.set_xlabel("Depth of Interaction (mm)") ax.set_ylabel("Energy Resolution (%)") ax.set_xlim(-1,21) ax.set_ylim(8,25) ax.legend(ncol=3) fig.tight_layout() if savefigures: pc.savefigureadir('energyresolution-20',aloc,fig) #pc.savefigureadir('energyresolution-20','/home/mbrown/Desktop/figures-svg',fig,ext='svg') show() df = pds.read_csv('alldata.csv') fig, ax = subplots() ax.grid() df = df[df.length == 20] df = df[df.SampleB == '2396'] df = df[df.specialkey == 'normal'] for config, grp in df.groupby('configuration'): for key, grp in grp.groupby('SampleB'): ax.errorbar(grp.DOI,grp.RPloc,yerr=grp.RPlocerr,fmt='.',marker=markerdict[config],color=wrapdict[config],ecolor=errwrapdict[config],label=lbl[config]) ax.set_xlabel("Depth of Interaction (mm)") ax.set_ylabel("Right Photopeak Centroid (Arb.)") ax.set_xlim(-1,21) ax.set_ylim(0.3,0.5) ax.legend(ncol=3) fig.tight_layout() if savefigures: pc.savefigureadir('lightoutput-20',aloc,fig) show() df = pds.read_csv('standarddata.csv') df["person"] = df.uniquename.apply(lambda astr : astr.split('_')[-2]) df['num'] = df.uniquename.apply(lambda astr : int(astr.split('_')[-1])) df = df[((df.person == 'MW') & (df.num == 1)) | (df.length == 5) & (df.person == 'SW') & ((df.num == 4) | (df.num==25)) | (df.length == 10) & (df.person == 'SW') & (df.num == 1) | (df.length == 15) & (df.person == 'SW') & (df.num == 1) | (df.length == 20) & (df.person == 'SW') & ((df.num == 1) | (df.num==9)) | (df.length == 30) & (df.person == 'SW') & ((df.num == 1) | (df.num==9)) ] grp = df.groupby(['length']) fdf = grp.aggregate(np.mean) fdf['DOI'] = 1 fdf['configuration'] = 'wrapped' fdf['length'] = [5,10,15,20,30] fig, ax = subplots() ax.grid() Cols = {'MW':'b','SW':'r'} Marker = {'MW':'*','SW':'^'} Lbl = {'MW' : 'Wrap 1', 'SW' : 'Wrap 2'} for key, grp in df.groupby('person'): ax.errorbar(grp.length, grp.CTR, yerr=grp.CTRerr, fmt=Marker[key], color=Cols[key],label=Lbl[key]) #ax.errorbar(fdf.length, fdf.CTR, yerr=fdf.CTRError, fmt='.', color='b') ax.set_xlim(-2,32) ax.set_ylim(120,250) ax.set_xlabel("Scintillator Crystal Length (mm)") ax.set_ylabel("Coincidence Time Resolution (ps)") ax.legend() fig.tight_layout() if savefigures: pc.savefigureadir('standardctr',aloc,fig) show()