All tables are generated in this notebook from processed data in processeddata.zip
##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)
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
from uncertainties import unumpy
import ProcessingCTRData as pc
print("Complete")
Complete
LeftData = {'Threshold (V)': (1.64, 1.56), 'Bias (V)' : 72.6, 'Overvoltage (V)' : 2.2}
RightData = {'Threshold (V)': (1.64, 1.56), 'Bias (V)' : 72.7, 'Overvoltage (V)' : 2.2}
Data = {'Left Detector':LeftData, 'Right Detector':RightData}
df = pds.DataFrame(Data)
df = df.T
def tidythreshold(astr):
a, b = astr
return "{0} , {1}".format(a,b)
df['Threshold (V)'] = df['Threshold (V)'].apply(tidythreshold)
print(df.to_latex())
\begin{tabular}{llll} \toprule {} & Bias (V) & Overvoltage (V) & Threshold (V) \\ \midrule Left Detector & 72.6 & 2.2 & 1.64 , 1.56 \\ Right Detector & 72.7 & 2.2 & 1.64 , 1.56 \\ \bottomrule \end{tabular}
Care has been taken to actually match the above values to the data collected.
Most files the correct data is from num = 1, HOWEVER some files were conducted with different initial conditions. See raw data input... files for fairness
df = pds.read_csv('standarddata.csv')
df['configuration'] = 'wrapped'
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)) ]
## Combine data back together
for col in df.columns:
if col.endswith('err'):
df[col[:-3]] = df.apply(lambda srs : unc.ufloat(srs[col[:-3]],srs[col]),axis=1)
df = df.drop(col,1)
df['ggevents'] = unumpy.uarray(list(df.numofsamples),list(sqrt(df.numofsamples)))
##
Person = {'SW' : 'Wrap 2','MW' : ' Wrap 1'}
df['Wrapped By'] = df.person.apply(lambda astr : Person[astr])
df = df.sort(['length','CTR', 'person'], ascending=[True,False,True])
for col in df.columns:
if col in ['length', 'ggevents']:
ff = "{0:.0f}"
elif col in ['ERleft','ERright']:
ff = "{0:.2f}"
else:
ff = "{0:.1f}"
try:
df[col] = [ff.format(val).replace("+/-","$\pm$") for val in df[col]]
except ValueError:
continue
print(df.to_latex(float_format=lambda x: '%10.1f' % x, index=False,columns=['Wrapped By','length',"ERleft","ERright","ggevents","location","CTR","chisquared"]))
\begin{tabular}{llllllll} \toprule Wrapped By & length & ERleft & ERright & ggevents & location & CTR & chisquared \\ \midrule Wrap 1 & 5 & 7.05$\pm$0.07 & 9.44$\pm$0.09 & 856$\pm$29 & -68.8$\pm$2.4 & 154.9$\pm$4.9 & 1.2 \\ Wrap 2 & 5 & 6.33$\pm$0.08 & 7.36$\pm$0.09 & 361$\pm$19 & -68.8$\pm$3.4 & 140.8$\pm$6.5 & 0.6 \\ Wrap 2 & 5 & 6.89$\pm$0.05 & 7.29$\pm$0.05 & 1526$\pm$39 & -64.8$\pm$1.6 & 139.9$\pm$3.0 & 1.2 \\ Wrap 1 & 10 & 8.24$\pm$0.06 & 9.63$\pm$0.07 & 1032$\pm$32 & -124.4$\pm$2.6 & 185.6$\pm$5.0 & 0.8 \\ Wrap 2 & 10 & 6.66$\pm$0.05 & 7.59$\pm$0.05 & 515$\pm$23 & -168.4$\pm$3.6 & 169.7$\pm$7.0 & 0.9 \\ Wrap 1 & 15 & 9.05$\pm$0.05 & 9.07$\pm$0.05 & 1875$\pm$43 & -176.0$\pm$2.1 & 201.9$\pm$4.1 & 0.8 \\ Wrap 2 & 15 & 6.82$\pm$0.04 & 7.67$\pm$0.04 & 1569$\pm$40 & -108.8$\pm$2.0 & 178.2$\pm$3.6 & 1.0 \\ Wrap 2 & 20 & 6.99$\pm$0.03 & 9.27$\pm$0.04 & 2003$\pm$45 & -131.1$\pm$2.1 & 205.5$\pm$4.5 & 1.1 \\ Wrap 1 & 20 & 10.97$\pm$0.05 & 9.85$\pm$0.05 & 1731$\pm$42 & -85.2$\pm$2.2 & 202.7$\pm$4.0 & 1.4 \\ Wrap 1 & 30 & 10.94$\pm$0.04 & 13.07$\pm$0.06 & 3382$\pm$58 & -58.6$\pm$1.8 & 237.7$\pm$3.3 & 2.1 \\ Wrap 2 & 30 & 9.73$\pm$0.04 & 10.79$\pm$0.05 & 3502$\pm$59 & -70.6$\pm$1.6 & 212.4$\pm$3.0 & 1.4 \\ Wrap 2 & 30 & 9.52$\pm$0.05 & 10.72$\pm$0.06 & 2369$\pm$49 & -67.9$\pm$1.9 & 209.6$\pm$3.8 & 1.3 \\ \bottomrule \end{tabular}
df = pds.read_csv('referencedata.csv')
df['num'] = df.uniquename.apply(lambda astr : int(astr.split('_')[-1]))
df = df[df.num == 1]
#initial DOI measurement removed to reduce confusion - value should be valid!
df = df[df.uniquename.apply(lambda astr : astr.find("6th") < 0)]
## Combine data back together
for col in df.columns:
if col.endswith('err'):
df[col[:-3]] = df.apply(lambda srs : unc.ufloat(srs[col[:-3]],srs[col]),axis=1)
df = df.drop(col,1)
df['ggevents'] = unumpy.uarray(list(df.numofsamples),list(sqrt(df.numofsamples)))
##
expr = {0: "Standard", 1: "DOI"}
df['DOI'] = df.uniquename.apply(lambda astr : expr[astr.find("DOI")>0])
df['configuration'] = 'wrapped'
df = df.sort('length')
for col in df.columns:
if col in ['length', 'ggevents']:
ff = "{0:.0f}"
else:
ff = "{0:.1f}"
try:
df[col] = [ff.format(val).replace("+/-","$\pm$") for val in df[col]]
except ValueError:
continue
print(df.to_latex(float_format=lambda x: '%10.1f' % x, index=False,columns=["uniquename","ERleft","ERright","ggevents","location","TimeResolution","chisquared"]))
#print(pc.GenerateLaTeXTable(df,sortby=['length'],cols=["configuration","DOI","energyresolutionLeft","energyresolution","ggevents","loc","ctr","chisquared"]))
\begin{tabular}{lllllll} \toprule uniquename & ERleft & ERright & ggevents & location & TimeResolution & chisquared \\ \midrule Run\_23972vs24044Reference\_00001 & 7.8$\pm$0.1 & 9.8$\pm$0.1 & 637$\pm$25 & -77.5$\pm$2.3 & 39.3$\pm$1.2 & 0.4 \\ Run\_23972vs24044\_ReferenceDOI7th\_00001 & 10.5$\pm$0.1 & 12.7$\pm$0.1 & 1498$\pm$39 & -14.0$\pm$1.5 & 39.6$\pm$0.9 & 1.3 \\ \bottomrule \end{tabular}
df = pds.read_csv('alldata.csv',index_col=[0,1])
df = df[df.length == 20]
df = df[df.SampleB == '2396']
df = df[df.CTR < 300]
chifit = [pc.getchi(grp,plot=False) for key, grp in df.groupby(['SampleB','configuration'])]
for col in df.columns:
if col.endswith('err'):
df[col[:-3]] = df.apply(lambda srs : unc.ufloat(srs[col[:-3]],srs[col]),axis=1)
df = df.drop(col,1)
df['ggevents'] = unumpy.uarray(list(df.numofsamples),list(sqrt(df.numofsamples)))
def ProperMean(agrp):
if isinstance(agrp.dtype,object):
return mean(list(agrp))
else:
return mean(agrp)
df = df.groupby(['SampleB','configuration']).aggregate(ProperMean)
df['chifit'] = chifit
df = df.sort('CTR',ascending=False)
for col in df.columns:
if col in ['length', 'ggevents']:
ff = "{0:.0f}"
elif col in ['ERleft','ERright']:
ff = "{0:.2f}"
else:
ff = "{0:.1f}"
try:
df[col] = [ff.format(val).replace("+/-","$\pm$") for val in df[col]]
except ValueError:
continue
print(df.to_latex(float_format=lambda x: '%10.1f' % x, index=True,columns=["ERleft","ERright","ggevents","location","CTR","chisquared","chifit"]))
\begin{tabular}{llllllll} \toprule {} & ERleft & ERright & ggevents & location & CTR & chisquared & chifit \\ SampleB configuration & & & & & & & \\ \midrule 2396 unwrapped & 10.13$\pm$0.02 & 19.99$\pm$0.03 & 3412$\pm$24 & 148.9$\pm$0.9 & 240.0$\pm$3.5 & 1.6 & 1.1 \\ partialwrap & 9.89$\pm$0.01 & 17.27$\pm$0.02 & 4879$\pm$23 & 162.9$\pm$0.4 & 222.1$\pm$1.5 & 1.5 & 2.0 \\ wrapped & 9.57$\pm$0.01 & 14.20$\pm$0.01 & 4887$\pm$23 & 128.7$\pm$0.4 & 198.3$\pm$1.5 & 1.6 & 1.5 \\ \bottomrule \end{tabular}
df = pds.read_csv('alldata.csv')
df = df[df.length == 20]
df = df[df.SampleB == '2396']
df = df[df.CTR < 300]
grp = df.groupby(['SampleB','configuration']).mean()
params, grp['$\chi^2_\text{nofit}$'] = zip(*[pc.getchi(agrp, dist='nofit', verbose=0, plot=False, fetchparam=True) for key, agrp in df.groupby(['SampleB','configuration'])])
grp['intercept-nofit'] = [pc.tidystring(astr) for astr in params]
params, grp['$\chi^2_\text{linear}$'] = zip(*[pc.getchi(agrp, dist='linear', verbose=0, plot=False, fetchparam=True) for key, agrp in df.groupby(['SampleB','configuration'])])
m, c = zip(*params)
grp['intercept-linearfit'] = [pc.tidystring(astr) for astr in m]
grp['gradient-linearfit'] = [pc.tidystring(astr) for astr in c]
grp['ptpchange'] = pc.CalculatePTP(df)
grp['std'] = pc.CalculateSTD(df)
grp['specialkey'] = 'normal'
print(pc.GenerateLaTeXTable(grp,index=True,sortby=None,cols=["energyresolutionLeft","energyresolution","ggevents","loc","ctr","chisquared"]))
print(pc.GenerateLaTeXTable(grp,index=True,sortby=None,cols=['std','ptpchange','intercept-nofit',"$\chi^2_\text{nofit}$",'intercept-linearfit','gradient-linearfit','$\chi^2_\text{linear}$']))
\begin{tabular}{lllllllr} \toprule {} & energyresolutionLeft & energyresolution & ggevents & rploc & loc & ctr & chisquared \\ SampleB configuration & & & & & & & \\ \midrule 2396 partialwrap & 9.89$\pm$0.04 & 17.27$\pm$0.05 & 4878$\pm$69 & 0.4$\pm$0.0 & 162.9$\pm$1.2 & 222.1$\pm$4.4 & 1.47 \\ unwrapped & 10.13$\pm$0.04 & 19.99$\pm$0.07 & 3411$\pm$58 & 0.3$\pm$0.0 & 148.9$\pm$1.9 & 240.0$\pm$7.4 & 1.56 \\ wrapped & 9.57$\pm$0.03 & 14.2$\pm$0.04 & 4887$\pm$69 & 0.5$\pm$0.0 & 128.7$\pm$1.1 & 198.3$\pm$4.4 & 1.58 \\ \bottomrule \end{tabular} \begin{tabular}{llllrllr} \toprule {} & std & ptpchange & intercept-nofit & $\chi^2\_\text{nofit}$ & intercept-linearfit & gradient-linearfit & $\chi^2\_\text{linear}$ \\ SampleB configuration & & & & & & & \\ \midrule 2396 partialwrap & 5.99$\pm$1.42 & 21.24$\pm$5.88 & 221.91$\pm$4.70 & 1.99 & 0.43$\pm$0.12 & 217.82$\pm$15.28 & 1.47 \\ unwrapped & 7.73$\pm$3.97 & 20.95$\pm$10.32 & 236.07$\pm$6.42 & 1.14 & 1.08$\pm$0.81 & 231.63$\pm$19.60 & 0.72 \\ wrapped & 5.33$\pm$1.47 & 17.93$\pm$6.40 & 198.44$\pm$3.50 & 1.48 & -0.16$\pm$0.10 & 199.96$\pm$13.60 & 1.28 \\ \bottomrule \end{tabular}
df = pds.read_csv('alldata.csv',index_col=[0,1])
df = df[df.length == 30]
df = df[df.CTR < 300]
df = df[df.specialkey == 'normal']
chifit = [pc.getchi(grp,plot=False) for key, grp in df.groupby(['SampleB','configuration'])]
for col in df.columns:
if col.endswith('err'):
df[col[:-3]] = df.apply(lambda srs : unc.ufloat(srs[col[:-3]],srs[col]),axis=1)
df = df.drop(col,1)
df['ggevents'] = unumpy.uarray(list(df.numofsamples),list(sqrt(df.numofsamples)))
def ProperMean(agrp):
if isinstance(agrp.dtype,object):
return mean(list(agrp))
else:
return mean(agrp)
df = df.groupby(['SampleB','configuration']).aggregate(ProperMean)
print(df.CTR)
df['chifit'] = chifit
fdf = list(df.CTR)
#df = df.sort('CTR',ascending=False)
for col in df.columns:
if col in ['length', 'ggevents']:
ff = "{0:.0f}"
elif col in ['ERleft','ERright']:
ff = "{0:.2f}"
else:
ff = "{0:.1f}"
try:
df[col] = [ff.format(val).replace("+/-","$\pm$") for val in df[col]]
except ValueError:
continue
print(df.to_latex(float_format=lambda x: '%10.1f' % x, index=True,columns=["ERleft","ERright","ggevents","location","CTR","chisquared","chifit"]))
SampleB configuration 30A unwrapped 260.7+/-2.2 wrapped 246.0+/-2.3 30B unwrapped 257+/-5 wrapped 231.7+/-2.9 Name: CTR, dtype: object \begin{tabular}{llllllll} \toprule {} & ERleft & ERright & ggevents & location & CTR & chisquared & chifit \\ SampleB configuration & & & & & & & \\ \midrule 30A unwrapped & 10.75$\pm$0.02 & 15.76$\pm$0.02 & 3532$\pm$24 & 316.9$\pm$0.7 & 260.7$\pm$2.2 & 2.0 & 3.4 \\ wrapped & 10.03$\pm$0.02 & 13.84$\pm$0.02 & 3360$\pm$24 & 321.4$\pm$0.6 & 246.0$\pm$2.3 & 1.6 & 3.6 \\ 30B unwrapped & 10.64$\pm$0.02 & 17.17$\pm$0.03 & 2735$\pm$20 & 306.0$\pm$1.3 & 256.9$\pm$5.3 & 1.6 & 0.6 \\ wrapped & 10.02$\pm$0.02 & 13.98$\pm$0.02 & 2816$\pm$20 & 293.6$\pm$0.8 & 231.7$\pm$2.9 & 1.6 & 1.7 \\ \bottomrule \end{tabular}