##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 == 'extended'] 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() 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 == 'extended'] 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*=3000/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() 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 == 'extended'] 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]: 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(-150,100) ax.legend(ncol=2) fig.tight_layout() show() df = pds.read_csv('alldata.csv') fig, ax = subplots() ax.grid() crystaldict = {"30A":"*","30B":"^"} df = df[df.length == 30] df = df[df.specialkey == 'extended'] 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() show() df = pds.read_csv('alldata.csv') fig, ax = subplots() ax.grid() crystaldict = {"30A":"*","30B":"^"} df = df[df.length == 30] df = df[df.specialkey == 'extended'] 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() 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'] df = df[df.CTR < 300] crystaldict = {"20A":"*","20B":"^"} 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=crystaldict[key],color=wrapdict[config],ecolor=errwrapdict[config],label=key+' '+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(-2,20) ax.set_ylim(160,280) leg = ax.legend(ncol=3) fig.tight_layout() 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=crystaldict[key],color=wrapdict[config],ecolor=errwrapdict[config],label=key+' '+config) ax.set_xlim(-2,20) 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.5,19.5),stats.norm(scale=2/2.355).pdf(xs),mode='same') y*=3000/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() 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=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") 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(-2,20) ax.set_ylim(100,300) ax.legend(ncol=3) fig.tight_layout() 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=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,20) ax.set_ylim(10,20) ax.legend(ncol=3) fig.tight_layout() show() data = "1.640 1.560 1.640 1.560 72.4 72.7 5 1.640 1.560 1.700 1.500 72.4 72.7 20 1.640 1.560 1.900 1.300 72.4 72.7 20 1.640 1.560 2.100 1.100 72.4 72.7 20" data = array([row.split('\t') for row in data.split(' ')],dtype=float) Voltages = (data[:,2]-data[:,3])*1e3 Voltages df = pds.read_csv('alldata.csv') fig, ax = subplots() ax.grid() crystaldict = {"30A":"*","30B":"^","2396":"."} wrapdict = {'wrapped':'g','unwrapped':'r','partialwrap':'b'} fdf = df[(df.specialkey == 'normal') & (df.SampleB == '2396') & (df.configuration == 'wrapped')] firstvalue = fdf.location.min() #ax.errorbar(fdf.DOI,fdf.location/firstvalue,yerr=fdf.locationerr/firstvalue,fmt='.',label=str(80)+'mV') df = df[df.length == 30] #df = df[df.SampleB == '2396'] df = df[df.specialkey == 'threshold'] df['threshold'] = df.uniquename.apply(lambda astr : Voltages[int(astr.split('_')[-1])]) for config, grp in df.groupby('configuration'): linear = lambda xdata, m,c: m*xdata+c Y = array(grp[grp.threshold < 100].DOI) for key, grp in grp.groupby('threshold'): #if key < 100: #skips 5 minute measurement # continue #print(list(grp.DOI)) firstvalue = grp.location.min() (m,c), err = opt.curve_fit(linear,array(grp['DOI']),array(grp['location']),sigma=grp['locationerr']) merr,cerr = err.diagonal() factor = 3E-1 print(str(int(key+0.6))+'mV',"<",reducelim,"n", unc.ufloat(m,merr)*factor) ax.errorbar(grp.DOI,grp.location,yerr=grp.locationerr,fmt='.',label=str(int(key+0.6))+'mV') ax.set_xlabel("Depth of Interaction (mm)") ax.set_ylabel("Delay Peak Centroid (ps)") ax.set_xlim(-1,21) ax.set_ylim(100,1200) ax.legend(ncol=4) fig.tight_layout() show() df = pds.read_csv('alldata.csv') fig, ax = subplots() ax.grid() crystaldict = {"30A":"*","30B":"^","2396":"."} wrapdict = {'wrapped':'g','unwrapped':'r','partialwrap':'b'} df = df[df.length == 30] #df = df[df.SampleB == '2396'] df = df[df.specialkey == 'threshold'] df['threshold'] = df.uniquename.apply(lambda astr : Voltages[int(astr.split('_')[-1])]) for config, grp in df.groupby('configuration'): linear = lambda xdata, m,c: m*xdata+c for key, grp in grp.groupby('threshold'): if key < 100: continue ax.errorbar(grp.DOI,grp.numofsamples,yerr=sqrt(grp.numofsamples),fmt='.',label=str(int(key+0.6))+'mV') ax.set_xlabel("Depth of Interaction (mm)") ax.set_xlim(-1,21) #ax.set_ylim(0.9,2.1) ax.legend(ncol=3) fig.tight_layout() show()