{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#Generate Tables#\n", "All tables are generated in this notebook from processed data in *processeddata.zip*" ] }, { "cell_type": "code", "collapsed": false, "input": [ "##Preamble\n", "from __future__ import division,print_function\n", "import pandas as pds\n", "\n", "rc('figure',figsize=(12,4))\n", "rc('legend',loc='best')\n", "rc('font',size = 14.0)\n", "import os\n", "from os.path import expanduser\n", "\n", "%load_ext autoreload\n", "%autoreload 2\n", "\n", "import scipy.optimize as opt\n", "from scipy import stats\n", "import uncertainties as unc\n", "from uncertainties import unumpy\n", "\n", "import ProcessingCTRData as pc\n", "\n", "print(\"Complete\")" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Complete\n" ] } ], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Voltage Table##" ] }, { "cell_type": "code", "collapsed": false, "input": [ "LeftData = {'Threshold (V)': (1.64, 1.56), 'Bias (V)' : 72.6, 'Overvoltage (V)' : 2.2}\n", "RightData = {'Threshold (V)': (1.64, 1.56), 'Bias (V)' : 72.7, 'Overvoltage (V)' : 2.2} \n", "\n", "Data = {'Left Detector':LeftData, 'Right Detector':RightData}\n", "\n", "df = pds.DataFrame(Data)\n", "df = df.T\n", "\n", "def tidythreshold(astr):\n", " a, b = astr\n", " return \"{0} , {1}\".format(a,b)\n", "\n", "df['Threshold (V)'] = df['Threshold (V)'].apply(tidythreshold)\n", "\n", "print(df.to_latex())\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\\begin{tabular}{llll}\n", "\\toprule\n", "{} & Bias (V) & Overvoltage (V) & Threshold (V) \\\\\n", "\\midrule\n", "Left Detector & 72.6 & 2.2 & 1.64 , 1.56 \\\\\n", "Right Detector & 72.7 & 2.2 & 1.64 , 1.56 \\\\\n", "\\bottomrule\n", "\\end{tabular}\n", "\n" ] } ], "prompt_number": 7 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Standard CTR Table##\n", "Care has been taken to actually match the above values to the data collected.\n", "\n", "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" ] }, { "cell_type": "code", "collapsed": false, "input": [ "df = pds.read_csv('standarddata.csv')\n", "\n", "df['configuration'] = 'wrapped'\n", "df[\"person\"] = df.uniquename.apply(lambda astr : astr.split('_')[-2])\n", "df['num'] = df.uniquename.apply(lambda astr : int(astr.split('_')[-1]))\n", "\n", "df = df[((df.person == 'MW') & (df.num == 1)) | \n", " (df.length == 5) & (df.person == 'SW') & ((df.num == 4) | (df.num==25)) |\n", " (df.length == 10) & (df.person == 'SW') & (df.num == 1) |\n", " (df.length == 15) & (df.person == 'SW') & (df.num == 1) |\n", " (df.length == 20) & (df.person == 'SW') & ((df.num == 1) | (df.num==9)) |\n", " (df.length == 30) & (df.person == 'SW') & ((df.num == 1) | (df.num==9)) ]\n", "\n", "## Combine data back together\n", "\n", "for col in df.columns:\n", " if col.endswith('err'):\n", " df[col[:-3]] = df.apply(lambda srs : unc.ufloat(srs[col[:-3]],srs[col]),axis=1)\n", " df = df.drop(col,1)\n", " \n", "df['ggevents'] = unumpy.uarray(list(df.numofsamples),list(sqrt(df.numofsamples)))\n", "\n", "##\n", "Person = {'SW' : 'Wrap 2','MW' : ' Wrap 1'}\n", "df['Wrapped By'] = df.person.apply(lambda astr : Person[astr])\n", "\n", "\n", "df = df.sort(['length','CTR', 'person'], ascending=[True,False,True])\n", "\n", "for col in df.columns:\n", " if col in ['length', 'ggevents']:\n", " ff = \"{0:.0f}\"\n", " elif col in ['ERleft','ERright']:\n", " ff = \"{0:.2f}\"\n", " else:\n", " ff = \"{0:.1f}\"\n", " try:\n", " df[col] = [ff.format(val).replace(\"+/-\",\"$\\pm$\") for val in df[col]]\n", " except ValueError:\n", " continue\n", " \n", " \n", "print(df.to_latex(float_format=lambda x: '%10.1f' % x, index=False,columns=['Wrapped By','length',\"ERleft\",\"ERright\",\"ggevents\",\"location\",\"CTR\",\"chisquared\"]))" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\\begin{tabular}{llllllll}\n", "\\toprule\n", "Wrapped By & length & ERleft & ERright & ggevents & location & CTR & chisquared \\\\\n", "\\midrule\n", " 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 \\\\\n", " 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 \\\\\n", " 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 \\\\\n", " 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 \\\\\n", " 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 \\\\\n", " 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 \\\\\n", " 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 \\\\\n", " 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 \\\\\n", " 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 \\\\\n", " 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 \\\\\n", " 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 \\\\\n", " 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 \\\\\n", "\\bottomrule\n", "\\end{tabular}\n", "\n" ] } ], "prompt_number": 39 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Reference Data Table##" ] }, { "cell_type": "code", "collapsed": false, "input": [ "df = pds.read_csv('referencedata.csv')\n", "\n", "df['num'] = df.uniquename.apply(lambda astr : int(astr.split('_')[-1]))\n", "\n", "df = df[df.num == 1]\n", "\n", "#initial DOI measurement removed to reduce confusion - value should be valid!\n", "df = df[df.uniquename.apply(lambda astr : astr.find(\"6th\") < 0)] \n", "\n", "## Combine data back together\n", "\n", "for col in df.columns:\n", " if col.endswith('err'):\n", " df[col[:-3]] = df.apply(lambda srs : unc.ufloat(srs[col[:-3]],srs[col]),axis=1)\n", " df = df.drop(col,1)\n", " \n", "df['ggevents'] = unumpy.uarray(list(df.numofsamples),list(sqrt(df.numofsamples)))\n", "\n", "##\n", "\n", "expr = {0: \"Standard\", 1: \"DOI\"}\n", "df['DOI'] = df.uniquename.apply(lambda astr : expr[astr.find(\"DOI\")>0])\n", "\n", "df['configuration'] = 'wrapped'\n", "df = df.sort('length')\n", "\n", "for col in df.columns:\n", " if col in ['length', 'ggevents']:\n", " ff = \"{0:.0f}\"\n", " else:\n", " ff = \"{0:.1f}\"\n", " try:\n", " df[col] = [ff.format(val).replace(\"+/-\",\"$\\pm$\") for val in df[col]]\n", " except ValueError:\n", " continue\n", "\n", "print(df.to_latex(float_format=lambda x: '%10.1f' % x, index=False,columns=[\"uniquename\",\"ERleft\",\"ERright\",\"ggevents\",\"location\",\"TimeResolution\",\"chisquared\"]))\n", "#print(pc.GenerateLaTeXTable(df,sortby=['length'],cols=[\"configuration\",\"DOI\",\"energyresolutionLeft\",\"energyresolution\",\"ggevents\",\"loc\",\"ctr\",\"chisquared\"]))" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\\begin{tabular}{lllllll}\n", "\\toprule\n", " uniquename & ERleft & ERright & ggevents & location & TimeResolution & chisquared \\\\\n", "\\midrule\n", " 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 \\\\\n", " 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 \\\\\n", "\\bottomrule\n", "\\end{tabular}\n", "\n" ] } ], "prompt_number": 47 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##20mm Tables##" ] }, { "cell_type": "code", "collapsed": false, "input": [ "df = pds.read_csv('alldata.csv',index_col=[0,1])\n", "\n", "df = df[df.length == 20]\n", "df = df[df.SampleB == '2396']\n", "df = df[df.CTR < 300]\n", "\n", "chifit = [pc.getchi(grp,plot=False) for key, grp in df.groupby(['SampleB','configuration'])]\n", "\n", "for col in df.columns:\n", " if col.endswith('err'):\n", " df[col[:-3]] = df.apply(lambda srs : unc.ufloat(srs[col[:-3]],srs[col]),axis=1)\n", " df = df.drop(col,1)\n", " \n", "df['ggevents'] = unumpy.uarray(list(df.numofsamples),list(sqrt(df.numofsamples)))\n", "\n", "def ProperMean(agrp):\n", " if isinstance(agrp.dtype,object):\n", " return mean(list(agrp))\n", " else:\n", " return mean(agrp)\n", " \n", " \n", "df = df.groupby(['SampleB','configuration']).aggregate(ProperMean)\n", "df['chifit'] = chifit\n", "\n", "df = df.sort('CTR',ascending=False)\n", "\n", "\n", "for col in df.columns:\n", " if col in ['length', 'ggevents']:\n", " ff = \"{0:.0f}\"\n", " elif col in ['ERleft','ERright']:\n", " ff = \"{0:.2f}\"\n", " else:\n", " ff = \"{0:.1f}\"\n", " try:\n", " df[col] = [ff.format(val).replace(\"+/-\",\"$\\pm$\") for val in df[col]]\n", " except ValueError:\n", " continue\n", "\n", "print(df.to_latex(float_format=lambda x: '%10.1f' % x, index=True,columns=[\"ERleft\",\"ERright\",\"ggevents\",\"location\",\"CTR\",\"chisquared\",\"chifit\"]))\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\\begin{tabular}{llllllll}\n", "\\toprule\n", "{} & ERleft & ERright & ggevents & location & CTR & chisquared & chifit \\\\\n", "SampleB configuration & & & & & & & \\\\\n", "\\midrule\n", "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 \\\\\n", " 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 \\\\\n", " 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 \\\\\n", "\\bottomrule\n", "\\end{tabular}\n", "\n" ] } ], "prompt_number": 15 }, { "cell_type": "code", "collapsed": false, "input": [ "df = pds.read_csv('alldata.csv')\n", "\n", "df = df[df.length == 20]\n", "df = df[df.SampleB == '2396']\n", "df = df[df.CTR < 300]\n", " \n", "grp = df.groupby(['SampleB','configuration']).mean()\n", "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'])])\n", "\n", "grp['intercept-nofit'] = [pc.tidystring(astr) for astr in params]\n", "\n", "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'])])\n", "\n", "m, c = zip(*params)\n", "\n", "grp['intercept-linearfit'] = [pc.tidystring(astr) for astr in m]\n", "grp['gradient-linearfit'] = [pc.tidystring(astr) for astr in c]\n", "grp['ptpchange'] = pc.CalculatePTP(df)\n", "grp['std'] = pc.CalculateSTD(df)\n", "\n", "grp['specialkey'] = 'normal'\n", "\n", "print(pc.GenerateLaTeXTable(grp,index=True,sortby=None,cols=[\"energyresolutionLeft\",\"energyresolution\",\"ggevents\",\"loc\",\"ctr\",\"chisquared\"]))\n", "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}$']))\n", " \n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\\begin{tabular}{lllllllr}\n", "\\toprule\n", "{} & energyresolutionLeft & energyresolution & ggevents & rploc & loc & ctr & chisquared \\\\\n", "SampleB configuration & & & & & & & \\\\\n", "\\midrule\n", "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 \\\\\n", " 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 \\\\\n", " 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 \\\\\n", "\\bottomrule\n", "\\end{tabular}\n", "\n", "\\begin{tabular}{llllrllr}\n", "\\toprule\n", "{} & std & ptpchange & intercept-nofit & $\\chi^2\\_\\text{nofit}$ & intercept-linearfit & gradient-linearfit & $\\chi^2\\_\\text{linear}$ \\\\\n", "SampleB configuration & & & & & & & \\\\\n", "\\midrule\n", "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 \\\\\n", " 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 \\\\\n", " 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 \\\\\n", "\\bottomrule\n", "\\end{tabular}\n", "\n" ] } ], "prompt_number": 7 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##30mm Tables##" ] }, { "cell_type": "code", "collapsed": false, "input": [ "df = pds.read_csv('alldata.csv',index_col=[0,1])\n", "\n", "df = df[df.length == 30]\n", "df = df[df.CTR < 300]\n", "df = df[df.specialkey == 'normal']\n", "\n", "chifit = [pc.getchi(grp,plot=False) for key, grp in df.groupby(['SampleB','configuration'])]\n", "\n", "for col in df.columns:\n", " if col.endswith('err'):\n", " df[col[:-3]] = df.apply(lambda srs : unc.ufloat(srs[col[:-3]],srs[col]),axis=1)\n", " df = df.drop(col,1)\n", " \n", "df['ggevents'] = unumpy.uarray(list(df.numofsamples),list(sqrt(df.numofsamples)))\n", "\n", "def ProperMean(agrp):\n", " if isinstance(agrp.dtype,object):\n", " return mean(list(agrp))\n", " else:\n", " return mean(agrp)\n", " \n", "\n", "df = df.groupby(['SampleB','configuration']).aggregate(ProperMean)\n", "print(df.CTR)\n", "\n", "df['chifit'] = chifit\n", "\n", "fdf = list(df.CTR)\n", "#df = df.sort('CTR',ascending=False)\n", "\n", "\n", "for col in df.columns:\n", " if col in ['length', 'ggevents']:\n", " ff = \"{0:.0f}\"\n", " elif col in ['ERleft','ERright']:\n", " ff = \"{0:.2f}\"\n", " else:\n", " ff = \"{0:.1f}\"\n", " try:\n", " df[col] = [ff.format(val).replace(\"+/-\",\"$\\pm$\") for val in df[col]]\n", " except ValueError:\n", " continue\n", "\n", "print(df.to_latex(float_format=lambda x: '%10.1f' % x, index=True,columns=[\"ERleft\",\"ERright\",\"ggevents\",\"location\",\"CTR\",\"chisquared\",\"chifit\"]))\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "SampleB configuration\n", "30A unwrapped 260.7+/-2.2\n", " wrapped 246.0+/-2.3\n", "30B unwrapped 257+/-5\n", " wrapped 231.7+/-2.9\n", "Name: CTR, dtype: object\n", "\\begin{tabular}{llllllll}\n", "\\toprule\n", "{} & ERleft & ERright & ggevents & location & CTR & chisquared & chifit \\\\\n", "SampleB configuration & & & & & & & \\\\\n", "\\midrule\n", "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 \\\\\n", " 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 \\\\\n", "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 \\\\\n", " 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 \\\\\n", "\\bottomrule\n", "\\end{tabular}\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] } ], "prompt_number": 9 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }