Example #1
0
def plot_hg_radiative(fin,outpath):
	"""h-g radiative corrections for comparison with Albert's numbers"""
	Q = QFile(fin)
	ep = Q.getItemF("decayInfo","endpt")
	corrs = [spectrumCorrs(m) for m in Q.dat["spectrumPoint"]]
	ghg=graph.graphxy(width=24,height=16,
			   x=graph.axis.lin(title="Kinetic Energy [keV]",min=500,max=1300),
			   y=graph.axis.lin(title="Relative Asymmetry Correction",min=0,max=0.003),
			   key = graph.key.key(pos="mr"))
	setTexrunner(ghg)

	ghg.plot(graph.data.points([(c.energy+511,c.hmg) for c in corrs],x=1,y=2,title="Radiative $h - g$ (Shann/Sirlin)"),
		    [graph.style.line([style.linewidth.Thick,rgb.blue])])

	ghg.writetofile(outpath+"/Radiative_h-g.pdf")
Example #2
0
def alpha_eloss_plot(basePath = os.environ["UCNA_ANA_PLOTS"]+"/test/"):
	
	dat = QFile(basePath+"/AlphaEnergyLossSim.txt").dat["alpha_eloss"]
	for d in dat:
		d.loadFloats()

	e0 = 5485.56
	gdat = [(2*d.thickness,(5485.6-d.mean)/1000) for d in dat]

	g=graph.graphxy(width=15,height=15,
			   x=graph.axis.lin(title="Mylar foil thickness [$\\mu$m]",parter=graph.axis.parter.linear(tickdists=[5,1])),
			   y=graph.axis.lin(title="$^{241}$Am $\\alpha$ energy loss [MeV]"),
			   key = graph.key.key(pos="tl"))
	setTexrunner(g)

	g.plot(graph.data.points(gdat,x=1,y=2,title="Geant4 prediction"),[graph.style.symbol(symbol.circle,size=0.15)])

	LF = LinearFitter(terms=[polyterm(i) for i in range(3)])
	LF.fit(gdat)
	g.plot(graph.data.points(LF.fitcurve(0,20,200),x=1,y=2,title="$\\Delta E = %.2f + %.3f \\cdot l + %.4f \\cdot l^2$"%tuple(LF.coeffs)),[graph.style.line([style.linestyle.dashed])])

	g.plot(graph.data.points([[6,0.690]],x=1,y=2,title="Nominal 6$\\mu$m foil, 0.69 MeV measured"),[graph.style.symbol(symbol.plus,size=0.3,symbolattrs=[style.linewidth.Thick])])

	x0 = inverseFunction(LF,(1,15))(1.120)
	g.plot(graph.data.points([[x0,LF(x0)]],x=1,y=2,title="Source foil: 1.12 MeV loss $\\Rightarrow$ $l = %.1f$ $\\mu$m"%x0),[graph.style.symbol(symbol.diamond,size=0.3,symbolattrs=[style.linewidth.Thick])])


	print "6 um ->",LF(6)
	
	g.writetofile(basePath+"/AlphaEnergyLossSim.pdf")
Example #3
0
def offsetPlot(basedir,fname):
	
	poffs = [posOffset(p) for p in QFile(basedir+"/"+fname).dat["posOffset"]]
	(xShift,yShift,sinTh,LFx,LFy) = fitOffsets(poffs)
	
	print "Average offset:",(xShift,yShift),sinTh
	
	gwid = 15
	rwid = 50
	lscale = gwid/(2.*rwid)*unit.v_cm
	gOffs=graph.graphxy(width=gwid,height=gwid,
						x=graph.axis.lin(title = "x [mm]",min=-rwid,max=rwid),
						y=graph.axis.lin(title="y [mm]",min=-rwid,max=rwid),
						key = None)
	setTexrunner(gOffs)
	
	gdat = [(p.x,p.y,p.dr,p.theta*180/pi) for p in poffs]
	
	for p in poffs:
		p.applyFit(LFx,LFy);
	fdat = [(p.x,p.y,p.dr,p.theta*180/pi) for p in poffs]
	
	gOffs.plot(graph.data.points(fdat,x=1,y=2,size=3,angle=4),
			   [graph.style.arrow(linelength=lscale,arrowsize=0.7*lscale,lineattrs=[style.linewidth.THIck,rgb.red])])
	gOffs.plot(graph.data.points(gdat,x=1,y=2,size=3,angle=4),
			   [graph.style.arrow(linelength=lscale,arrowsize=0.7*lscale,lineattrs=[style.linewidth.THIck])])
	
	
	gOffs.writetofile(basedir+"/MWPCOffsets.pdf")
Example #4
0
def thesisCorrsPlot(fin,outpath):
	
	Q = QFile(fin)
	A = Q.getItemF("decayInfo","A")
	Z = Q.getItemF("decayInfo","Z")
	ep = Q.getItemF("decayInfo","endpt")
	corrs = [spectrumCorrs(m) for m in Q.dat["spectrumPoint"]]
		
	##############
	# Fine spectrum shape corrections
	##############
	
	gWC=graph.graphxy(width=16,height=8,
			x=graph.axis.lin(title="Kinetic Energy [keV]",min=0,max=ep),
			y=graph.axis.lin(title="Spectrum Correction"),
			key = graph.key.key(pos="bc",columns=3))
	setTexrunner(gWC)
				
	gWC.plot(graph.data.points([(c.energy,c.g) for c in corrs],x=1,y=2,title="$g \\alpha/2\\pi$"),[graph.style.line([style.linestyle.dashdotted,style.linewidth.THick])])

	gWC.plot(graph.data.points([(c.energy,c.ACm1+c.L0m1) for c in corrs],x=1,y=2,title="${^AC}L_0-1$"),[graph.style.line([style.linewidth.Thick])])
	gWC.plot(graph.data.points([(c.energy,c.VCm1+c.L0m1) for c in corrs],x=1,y=2,title="${^VC} L_0-1$"),[graph.style.line([style.linestyle.dotted,style.linewidth.Thick])])
	
	gWC.writetofile(outpath+"/ThesisSpecCorr_%i_%i_%f.pdf"%(A,Z,ep))

	###############
	# spectrum shapes
	###############
	
	gSpec=graph.graphxy(width=10,height=8,
						x=graph.axis.lin(title="Kinetic Energy [keV]",min=0,max=ep),
						y=graph.axis.lin(title="Decay Rate",min=0,max=1.1),
						key = graph.key.key(pos="bc"))
	setTexrunner(gSpec)

	gdat = [[c.energy,c.S0,c.S0*(1+c.F0m1)*(1+c.L0m1)*(1+c.VCm1)*(1+c.g)] for c in corrs]
	gdat.sort()
	print "Uncorrected beta energy:",sum([g[0]*g[1] for g in gdat])/sum([g[1] for g in gdat])
	print "Average beta energy:",sum([g[0]*g[2] for g in gdat])/sum([g[2] for g in gdat])
	vnorm = 1./max([g[1] for g in gdat])
	snorm = sum([g[1] for g in gdat])/sum([g[2] for g in gdat])*vnorm
	gdat = [ (g[0],g[1]*vnorm,g[2]*snorm) for g in gdat]
	
	gSpec.plot(graph.data.points(gdat,x=1,y=2,title="plain phase space"),[graph.style.line([style.linestyle.dotted,style.linewidth.Thick])])
	gSpec.plot(graph.data.points(gdat,x=1,y=3,title="corrected"),[graph.style.line([style.linewidth.Thick])])
	gSpec.writetofile(outpath+"/Thesis_Spectrum_%i_%i_%f.pdf"%(A,Z,ep))
Example #5
0
def load_octetruns(fname, tplist=octSegments[0]):
    rnlist = []
    for m in QFile(fname).dat.get("Octet", []):
        for k in m.dat:
            if k in tplist:
                for rns in m.dat[k]:
                    for rn in rns.split(","):
                        rnlist.append(int(rn))
    return rnlist
Example #6
0
def plot_hg_radiative(fin, outpath):
    """h-g radiative corrections for comparison with Albert's numbers"""
    Q = QFile(fin)
    ep = Q.getItemF("decayInfo", "endpt")
    corrs = [spectrumCorrs(m) for m in Q.dat["spectrumPoint"]]
    ghg = graph.graphxy(width=24,
                        height=16,
                        x=graph.axis.lin(title="Kinetic Energy [keV]",
                                         min=500,
                                         max=1300),
                        y=graph.axis.lin(title="Relative Asymmetry Correction",
                                         min=0,
                                         max=0.003),
                        key=graph.key.key(pos="mr"))
    setTexrunner(ghg)

    ghg.plot(
        graph.data.points([(c.energy + 511, c.hmg) for c in corrs],
                          x=1,
                          y=2,
                          title="Radiative $h - g$ (Shann/Sirlin)"),
        [graph.style.line([style.linewidth.Thick, rgb.blue])])

    ghg.writetofile(outpath + "/Radiative_h-g.pdf")
Example #7
0
def sep23effic(basedir=os.environ["UCNA_ANA_PLOTS"] + "/test/23Separation/"):
    cdat = [
        count23(c)
        for c in QFile(basedir + "/23Separation.txt").dat["23counts"]
    ]

    for s in ["East", "West"]:
        gdat = [(c.e0, c.e1, c.total, c.II / c.total, c.IIIx / c.total,
                 c.III / c.total, c.IIx / c.total, 0.5 * (c.e0 + c.e1))
                for c in cdat if c.side == s]
        gdat.sort()

        g23 = graph.graphxy(width=10,
                            height=7,
                            x=graph.axis.lin(title="Energy [keV]",
                                             min=0,
                                             max=700),
                            y=graph.axis.lin(title="Fraction of II+III",
                                             min=0,
                                             max=1),
                            key=graph.key.key(pos="tc", columns=2))
        setTexrunner(g23)

        print gdat

        iiCol, iiiCol = rgb.red, rgb.blue
        iiCol, iiiCol = rgb.black, rgb.black

        g23.plot(graph.data.points(gdat, x=-1, y=4, title="II"),
                 [graph.style.line(lineattrs=[iiCol, style.linestyle.dashed])])
        g23.plot(
            graph.data.points(gdat, x=-1, y=5, title="III*"),
            [graph.style.line(lineattrs=[iiiCol, style.linestyle.dashdotted])])
        g23.plot(graph.data.points(gdat, x=-1, y=6, title="III"),
                 [graph.style.line(lineattrs=[iiiCol, style.linestyle.solid])])
        g23.plot(graph.data.points(gdat, x=-1, y=7, title="II*"),
                 [graph.style.line(lineattrs=[iiCol, style.linestyle.dotted])])

        g23.writetofile(basedir + "frac23_%s.pdf" % s)
def XenonEnergyShift():
    baseDir = os.environ["UCNA_ANA_PLOTS"] + "/SimSpectrum/XenonEndpoint/"
    kFits = QFile(baseDir + "/EndpointEnergyShift.txt").dat["kurieFit"]

    gHeight = 12
    g = graph.graphxy(width=20,
                      height=gHeight,
                      x=graph.axis.lin(title="energy nonuniformity",
                                       min=-0.06,
                                       max=0.06),
                      y=graph.axis.lin(title="simulated endpoint shift [keV]"),
                      key=graph.key.key(pos="tl"))
    setTexrunner(g)

    sigmas = []
    for s in ["E", "W"]:
        for t in range(4):
            shdat = {}
            for k in kFits:
                k.loadFloats(["endpoint", "dendpoint", "shift", "tube"])
                k.loadStrings(["side"])
                if not k.tube == t and k.side == s:
                    continue
                shdat.setdefault(k.shift, []).append(k.endpoint)

            gdat = [[
                k,
            ] + musigma(shdat[k]) for k in shdat]
            sigmas.append(gdat[0][2])
            QF = LinearFitter([polyterm(i) for i in range(2)])
            QF.fit(gdat, cols=(0, 1))
            print "Shift factor", QF.toLatex()
            g.plot(graph.data.points(gdat, x=1, y=2, dy=3, title=None),
                   [graph.style.symbol(symbol.circle)])

    g.writetofile(baseDir + "EndpointShift.pdf")
    print sigmas, musigma(sigmas)
Example #9
0
def thesisCorrsPlot(fin, outpath):

    Q = QFile(fin)
    A = Q.getItemF("decayInfo", "A")
    Z = Q.getItemF("decayInfo", "Z")
    ep = Q.getItemF("decayInfo", "endpt")
    corrs = [spectrumCorrs(m) for m in Q.dat["spectrumPoint"]]

    ##############
    # Fine spectrum shape corrections
    ##############

    gWC = graph.graphxy(width=16,
                        height=8,
                        x=graph.axis.lin(title="Kinetic Energy [keV]",
                                         min=0,
                                         max=ep),
                        y=graph.axis.lin(title="Spectrum Correction"),
                        key=graph.key.key(pos="bc", columns=3))
    setTexrunner(gWC)

    gWC.plot(
        graph.data.points([(c.energy, c.g) for c in corrs],
                          x=1,
                          y=2,
                          title="$g \\alpha/2\\pi$"),
        [
            graph.style.line(
                [style.linestyle.dashdotted, style.linewidth.THick])
        ])

    gWC.plot(
        graph.data.points([(c.energy, c.ACm1 + c.L0m1) for c in corrs],
                          x=1,
                          y=2,
                          title="${^AC}L_0-1$"),
        [graph.style.line([style.linewidth.Thick])])
    gWC.plot(
        graph.data.points([(c.energy, c.VCm1 + c.L0m1) for c in corrs],
                          x=1,
                          y=2,
                          title="${^VC} L_0-1$"),
        [graph.style.line([style.linestyle.dotted, style.linewidth.Thick])])

    gWC.writetofile(outpath + "/ThesisSpecCorr_%i_%i_%f.pdf" % (A, Z, ep))

    ###############
    # spectrum shapes
    ###############

    gSpec = graph.graphxy(width=10,
                          height=8,
                          x=graph.axis.lin(title="Kinetic Energy [keV]",
                                           min=0,
                                           max=ep),
                          y=graph.axis.lin(title="Decay Rate", min=0, max=1.1),
                          key=graph.key.key(pos="bc"))
    setTexrunner(gSpec)

    gdat = [[
        c.energy, c.S0,
        c.S0 * (1 + c.F0m1) * (1 + c.L0m1) * (1 + c.VCm1) * (1 + c.g)
    ] for c in corrs]
    gdat.sort()
    print "Uncorrected beta energy:", sum([g[0] * g[1] for g in gdat]) / sum(
        [g[1] for g in gdat])
    print "Average beta energy:", sum([g[0] * g[2] for g in gdat]) / sum(
        [g[2] for g in gdat])
    vnorm = 1. / max([g[1] for g in gdat])
    snorm = sum([g[1] for g in gdat]) / sum([g[2] for g in gdat]) * vnorm
    gdat = [(g[0], g[1] * vnorm, g[2] * snorm) for g in gdat]

    gSpec.plot(
        graph.data.points(gdat, x=1, y=2, title="plain phase space"),
        [graph.style.line([style.linestyle.dotted, style.linewidth.Thick])])
    gSpec.plot(graph.data.points(gdat, x=1, y=3, title="corrected"),
               [graph.style.line([style.linewidth.Thick])])
    gSpec.writetofile(outpath + "/Thesis_Spectrum_%i_%i_%f.pdf" % (A, Z, ep))
Example #10
0
def plotWilkinsonCorrs(fin, outpath):

    #os.system("mkdir -p %s"%outpath)
    #os.system("cd ..; ./UCNAnalyzer rc x");

    Q = QFile(fin)
    A = Q.getItemF("decayInfo", "A")
    Z = Q.getItemF("decayInfo", "Z")
    ep = Q.getItemF("decayInfo", "endpt")
    corrs = [spectrumCorrs(m) for m in Q.dat["spectrumPoint"]]

    ##############
    # individual spectrum shape corrections
    ##############

    gWC = graph.graphxy(
        width=18,
        height=12,
        x=graph.axis.lin(title="Energy [keV]", min=0, max=ep),  #max=ep*1.25),
        #y=graph.axis.log(title="Spectrum Correction",min=5e-6,max=0.5),
        y=graph.axis.log(title="Spectrum Correction", min=5e-6),
        key=graph.key.key(pos="tc", columns=4))
    setTexrunner(gWC)

    gdat = [
        [
            c.energy,  # 0
            c.F0m1,  # 1
            abs(c.L0m1),  # 2
            -c.Qm1,  # 3
            c.RVm1,  # 4
            c.RAm1,  # 5
            abs(c.BiRWM),  # 6
            -c.VCm1,  # 7
            -c.ACm1,  # 8
            c.g,  # 9
            0.000401,  # 10
            0.0004 * (1 + 0.2 * sin(c.energy / 30)),  # 11
            -c.Cm1,  # 12
            c.Rm1  # 13
        ] for c in corrs
    ]

    gWC.plot(
        graph.data.points([(c.energy, c.F0m1) for c in corrs],
                          x=1,
                          y=2,
                          title="$F_0-1$"),
        [graph.style.line([style.linewidth.THICk])])
    gWC.plot(
        graph.data.points([(c.energy, abs(c.g)) for c in corrs],
                          x=1,
                          y=2,
                          title="$|g \\alpha/2\\pi|$"),
        [graph.style.line([style.linestyle.dashed, style.linewidth.THick])])
    gWC.plot(
        graph.data.points([(c.energy, abs(c.BiRWM)) for c in corrs],
                          x=1,
                          y=2,
                          title="$|R+{\\rm WM}|$"),
        [graph.style.line([style.linestyle.dotted, style.linewidth.THIck])])
    #gWC.plot(graph.data.points([(c.energy,-c.ACm1) for c in corrs],x=1,y=2,title="$1-{^AC}$"),[graph.style.line([style.linewidth.thick])])
    #gWC.plot(graph.data.points([(c.energy,-c.VCm1) for c in corrs],x=1,y=2,title="$1-{^VC}$"),[graph.style.line([style.linestyle.dashdotted,style.linewidth.thick])])
    gWC.plot(
        graph.data.points([(c.energy, -c.Cm1) for c in corrs],
                          x=1,
                          y=2,
                          title="$1-C$"),
        [
            graph.style.line(
                [style.linestyle.dashdotted, style.linewidth.thick])
        ])
    gWC.plot(
        graph.data.points([(c.energy, -c.L0m1) for c in corrs],
                          x=1,
                          y=2,
                          title="$1-L_0$"),
        [graph.style.line([style.linestyle.dashed, style.linewidth.thick])])
    gWC.plot(
        graph.data.points([(c.energy, -c.Qm1) for c in corrs],
                          x=1,
                          y=2,
                          title="$1-Q$"),
        [graph.style.line([style.linestyle.dotted, style.linewidth.thick])])

    #gWC.writetofile(outpath+"/WilkinsonCorrs_%i_%i_%f.pdf"%(A,Z,ep))

    ###############
    # spectrum shapes
    ###############

    gSpec = graph.graphxy(width=10,
                          height=8,
                          x=graph.axis.lin(title="Kinetic Energy [keV]",
                                           min=0,
                                           max=ep),
                          y=graph.axis.lin(title="Decay Rate", min=0),
                          key=graph.key.key(pos="tr"))
    setTexrunner(gSpec)
    gdat = [[c.energy, c.S0, c.S] for c in corrs]
    gdat.sort()
    print "Uncorrected beta energy:", sum([g[0] * g[1] for g in gdat]) / sum(
        [g[1] for g in gdat])
    print "Average beta energy:", sum([g[0] * g[2] for g in gdat]) / sum(
        [g[2] for g in gdat])
    snorm = sum([g[1] for g in gdat]) / sum([g[2] for g in gdat])
    gdat = [g + [
        g[2] * snorm,
    ] for g in gdat]
    if 1 / 1.2 < snorm < 1.2:
        gSpec.plot(graph.data.points(gdat, x=1, y=3, title="Corrected"), [
            graph.style.line(
                [style.linestyle.dashed, rgb.blue, style.linewidth.Thick])
        ])
        gSpec.plot(graph.data.points(gdat, x=1, y=4, title="Normalized"),
                   [graph.style.line([rgb.red, style.linewidth.Thick])])
    else:
        gSpec.plot(graph.data.points(gdat, x=1, y=4, title="Corrected"), [
            graph.style.line(
                [style.linestyle.dashed, rgb.blue, style.linewidth.Thick])
        ])
    gSpec.plot(
        graph.data.points(gdat, x=1, y=2, title="Plain"),
        [graph.style.line([style.linestyle.dotted, style.linewidth.Thick])])
    #gSpec.writetofile(outpath+"/BetaSpectrum_%i_%i_%f.pdf"%(A,Z,ep))

    if A != 1:
        return

    ##############
    # total spectrum shape corrections
    ##############

    gWCTot = graph.graphxy(width=20,
                           height=10,
                           x=graph.axis.lin(title="Kinetic Energy [keV]",
                                            min=0,
                                            max=783),
                           y=graph.axis.lin(
                               title="Total spectrum correction factor",
                               min=1.0,
                               max=1.2),
                           key=graph.key.key(pos="tr"))
    setTexrunner(gWCTot)
    gdat = [[c.energy, c.S / c.S0] for c in corrs if c.S0]
    gdat.sort()
    gWCTot.plot(graph.data.points(gdat, x=1, y=2, title=None),
                [graph.style.line([style.linewidth.Thick])])
    #gWCTot.writetofile(outpath+"/WilkinsonCorrsTot.pdf")

    ################
    # Asymmetry corrections
    ################

    gWCA = graph.graphxy(width=15,
                         height=7,
                         x=graph.axis.lin(title="Kinetic Energy [keV]",
                                          min=0,
                                          max=782),
                         y=graph.axis.lin(title="$(A-A_0)/A_0$ [\\%]",
                                          min=0.0000),
                         key=graph.key.key(pos="tl"))
    setTexrunner(gWCA)
    gWCA.plot(
        graph.data.points([(c.energy, c.RWM * 100) for c in corrs],
                          x=1,
                          y=2,
                          title="Recoil order"),
        [graph.style.line([style.linewidth.Thick, style.linestyle.dashed])])
    gWCA.plot(
        graph.data.points([(c.energy, c.hmg * 100) for c in corrs],
                          x=1,
                          y=2,
                          title="${\\alpha \\over 2\\pi}(h - g)$"),
        [graph.style.line([style.linewidth.Thick])])
    if 0:

        def gluckx2E(x):
            return x * (782.6 + 511.) - 511.

        gluck_da = [[gluckx2E(0.4), 0.03 / 1.66], [gluckx2E(0.5), 0.01 / 6.55],
                    [gluckx2E(0.6), 0.01 / 8.08], [gluckx2E(0.7), 0.01 / 8.90],
                    [gluckx2E(0.8), 0.01 / 9.41], [gluckx2E(0.9), 0.01 / 9.76]]

        gluck_hmg = [[gluckx2E(0.4), 0.005 / 1.731],
                     [gluckx2E(0.5), 0.014 / 6.961],
                     [gluckx2E(0.6), 0.013 / 8.553],
                     [gluckx2E(0.7), 0.011 / 9.383],
                     [gluckx2E(0.8), 0.009 / 9.884],
                     [gluckx2E(0.9), 0.008 / 10.214]]

        #gWCA.plot(graph.data.points(gluck_da,x=1,y=2,title='Gl\\"uck 1992 $\\delta \\alpha_e$ table'),[graph.style.symbol(symbolattrs=[rgb.green])])
        gWCA.plot(
            graph.data.points(gluck_hmg,
                              x=1,
                              y=2,
                              title='Gl\\"uck private communication'),
            [graph.style.symbol(symbolattrs=[rgb.green])])
    gWCA.writetofile(outpath + "/A_Rad_Corrections.pdf")
    return

    ################
    # Asymmetry curves
    ################

    gAsym = graph.graphxy(width=10,
                          height=8,
                          x=graph.axis.lin(title="Kinetic Energy [keV]",
                                           min=0,
                                           max=800),
                          y=graph.axis.lin(title="Asymmetry $A(E)\\beta/2$"),
                          key=graph.key.key(pos="tr"))
    setTexrunner(gAsym)
    gdat = [[c.energy, c.A0, c.A] for c in corrs if c.energy < 783]
    gAsym.plot(graph.data.points(gdat, x=1, y=2, title="$A(E)=A_0$"),
               [graph.style.line([style.linewidth.Thick])])
    gAsym.plot(graph.data.points(gdat, x=1, y=3, title="Corrected"), [
        graph.style.line(
            [rgb.red, style.linestyle.dashdotted, style.linewidth.Thick])
    ])
    gAsym.writetofile(outpath + "/Asymmetry.pdf")

    ################
    # shape of tensor coupling corrections to A
    ################

    def tensorCoeff(E):
        m_e = 511.
        l = 1.2694
        return 2 / (1 + 3 * l)**2 / 938000 * (
            m_e**2. / E * l**2 * (1 - l) + 782 *
            (l**2 + 2. / 3. * l - 1. / 3.) + E * 2. / 3. *
            (1 + l + 3 * l**2 + 3 * l**3)) * (1 + 3. * l**2) / (2 * l *
                                                                (1 - l))

    gT = graph.graphxy(width=20,
                       height=10,
                       x=graph.axis.lin(title="Kinetic Energy [keV]",
                                        min=0,
                                        max=800),
                       y=graph.axis.lin(
                           title="$\\Delta A/A$ for $g_{II}/g_V=1$",
                           min=-0.01,
                           max=0.01),
                       key=graph.key.key(pos="tr"))
    setTexrunner(gT)
    gT.plot(
        graph.data.points([(c.energy, tensorCoeff(c.energy)) for c in corrs],
                          x=1,
                          y=2,
                          title=None),
        [graph.style.line([style.linewidth.Thick])])
    gT.writetofile(outpath + "/GardnerTensor.pdf")
Example #11
0
 def __init__(self, fname):
     rcals = [runCal(r) for r in QFile(fname).dat.get("runcal", [])]
     self.runcals = dict([(r.run, r) for r in rcals])
     self.runs = self.runcals.keys()
     self.runs.sort()
Example #12
0
def plotWilkinsonCorrs(fin,outpath):

	#os.system("mkdir -p %s"%outpath)
	#os.system("cd ..; ./UCNAnalyzer rc x");
	
	Q = QFile(fin)
	A = Q.getItemF("decayInfo","A")
	Z = Q.getItemF("decayInfo","Z")
	ep = Q.getItemF("decayInfo","endpt")
	corrs = [spectrumCorrs(m) for m in Q.dat["spectrumPoint"]]
		
	##############
	# individual spectrum shape corrections
	##############
	
	gWC=graph.graphxy(width=18,height=12,
			x=graph.axis.lin(title="Energy [keV]",min=0,max=ep), #max=ep*1.25),
			#y=graph.axis.log(title="Spectrum Correction",min=5e-6,max=0.5),
			y=graph.axis.log(title="Spectrum Correction",min=5e-6),
			key = graph.key.key(pos="tc",columns=4))
	setTexrunner(gWC)

	gdat = [ [	c.energy,			# 0
				c.F0m1,			# 1
				abs(c.L0m1),		# 2
				-c.Qm1,			# 3
				c.RVm1,			# 4
				c.RAm1,			# 5
				abs(c.BiRWM),		# 6
				-c.VCm1,			# 7
				-c.ACm1,			# 8
				c.g,				# 9
				0.000401,			# 10
				0.0004*(1+0.2*sin(c.energy/30)), # 11
				-c.Cm1,			# 12
				c.Rm1			# 13
			] for c in corrs]
			
	gWC.plot(graph.data.points([(c.energy,c.F0m1) for c in corrs],x=1,y=2,title="$F_0-1$"),[graph.style.line([style.linewidth.THICk])])
	gWC.plot(graph.data.points([(c.energy,abs(c.g)) for c in corrs],x=1,y=2,title="$|g \\alpha/2\\pi|$"),[graph.style.line([style.linestyle.dashed,style.linewidth.THick])])
	gWC.plot(graph.data.points([(c.energy,abs(c.BiRWM)) for c in corrs],x=1,y=2,title="$|R+{\\rm WM}|$"),[graph.style.line([style.linestyle.dotted,style.linewidth.THIck])])
	#gWC.plot(graph.data.points([(c.energy,-c.ACm1) for c in corrs],x=1,y=2,title="$1-{^AC}$"),[graph.style.line([style.linewidth.thick])])
	#gWC.plot(graph.data.points([(c.energy,-c.VCm1) for c in corrs],x=1,y=2,title="$1-{^VC}$"),[graph.style.line([style.linestyle.dashdotted,style.linewidth.thick])])
	gWC.plot(graph.data.points([(c.energy,-c.Cm1) for c in corrs],x=1,y=2,title="$1-C$"),[graph.style.line([style.linestyle.dashdotted,style.linewidth.thick])])
	gWC.plot(graph.data.points([(c.energy,-c.L0m1) for c in corrs],x=1,y=2,title="$1-L_0$"),[graph.style.line([style.linestyle.dashed,style.linewidth.thick])])
	gWC.plot(graph.data.points([(c.energy,-c.Qm1) for c in corrs],x=1,y=2,title="$1-Q$"),[graph.style.line([style.linestyle.dotted,style.linewidth.thick])])
	

	#gWC.writetofile(outpath+"/WilkinsonCorrs_%i_%i_%f.pdf"%(A,Z,ep))
	
	###############
	# spectrum shapes
	###############
	
	gSpec=graph.graphxy(width=10,height=8,
						x=graph.axis.lin(title="Kinetic Energy [keV]",min=0,max=ep),
						y=graph.axis.lin(title="Decay Rate",min=0),
						key = graph.key.key(pos="tr"))
	setTexrunner(gSpec)
	gdat = [[c.energy,c.S0,c.S] for c in corrs]
	gdat.sort()
	print "Uncorrected beta energy:",sum([g[0]*g[1] for g in gdat])/sum([g[1] for g in gdat])
	print "Average beta energy:",sum([g[0]*g[2] for g in gdat])/sum([g[2] for g in gdat])
	snorm = sum([g[1] for g in gdat])/sum([g[2] for g in gdat])
	gdat = [g+[g[2]*snorm,] for g in gdat]
	if 1/1.2 < snorm < 1.2:
		gSpec.plot(graph.data.points(gdat,x=1,y=3,title="Corrected"),[graph.style.line([style.linestyle.dashed,rgb.blue,style.linewidth.Thick])])
		gSpec.plot(graph.data.points(gdat,x=1,y=4,title="Normalized"),[graph.style.line([rgb.red,style.linewidth.Thick])])
	else:
		gSpec.plot(graph.data.points(gdat,x=1,y=4,title="Corrected"),[graph.style.line([style.linestyle.dashed,rgb.blue,style.linewidth.Thick])])
	gSpec.plot(graph.data.points(gdat,x=1,y=2,title="Plain"),[graph.style.line([style.linestyle.dotted,style.linewidth.Thick])])
	#gSpec.writetofile(outpath+"/BetaSpectrum_%i_%i_%f.pdf"%(A,Z,ep))

	if A != 1:
		return
	
	##############
	# total spectrum shape corrections
	##############
	
	gWCTot=graph.graphxy(width=20,height=10,
			x=graph.axis.lin(title="Kinetic Energy [keV]",min=0,max=783),
			y=graph.axis.lin(title="Total spectrum correction factor",min=1.0,max=1.2),
			key = graph.key.key(pos="tr"))
	setTexrunner(gWCTot)
	gdat = [[c.energy,c.S/c.S0] for c in corrs if c.S0]
	gdat.sort()
	gWCTot.plot(graph.data.points(gdat,x=1,y=2,title=None),[graph.style.line([style.linewidth.Thick])])
	#gWCTot.writetofile(outpath+"/WilkinsonCorrsTot.pdf")
	
	################
	# Asymmetry corrections
	################
	
	gWCA=graph.graphxy(width=15,height=7,
			x=graph.axis.lin(title="Kinetic Energy [keV]",min=0,max=782),
			y=graph.axis.lin(title="$(A-A_0)/A_0$ [\\%]",min=0.0000),
			key = graph.key.key(pos="tl"))
	setTexrunner(gWCA)
	gWCA.plot(graph.data.points([(c.energy,c.RWM*100) for c in corrs],x=1,y=2,title="Recoil order"),[graph.style.line([style.linewidth.Thick,style.linestyle.dashed])])
	gWCA.plot(graph.data.points([(c.energy,c.hmg*100) for c in corrs],x=1,y=2,title="${\\alpha \\over 2\\pi}(h - g)$"),[graph.style.line([style.linewidth.Thick])])
	if 0:
		def gluckx2E(x):
			return x*(782.6+511.)-511.
		gluck_da = [ [gluckx2E(0.4),0.03/1.66],[gluckx2E(0.5),0.01/6.55],[gluckx2E(0.6),0.01/8.08],
						[gluckx2E(0.7),0.01/8.90],[gluckx2E(0.8),0.01/9.41],[gluckx2E(0.9),0.01/9.76]]

		gluck_hmg = [ [gluckx2E(0.4),0.005/1.731],[gluckx2E(0.5),0.014/6.961],[gluckx2E(0.6),0.013/8.553],
				   [gluckx2E(0.7),0.011/9.383],[gluckx2E(0.8),0.009/9.884],[gluckx2E(0.9),0.008/10.214]]

		#gWCA.plot(graph.data.points(gluck_da,x=1,y=2,title='Gl\\"uck 1992 $\\delta \\alpha_e$ table'),[graph.style.symbol(symbolattrs=[rgb.green])])
		gWCA.plot(graph.data.points(gluck_hmg,x=1,y=2,title='Gl\\"uck private communication'),[graph.style.symbol(symbolattrs=[rgb.green])])
	gWCA.writetofile(outpath+"/A_Rad_Corrections.pdf")
	return

	################
	# Asymmetry curves
	################
	
	gAsym=graph.graphxy(width=10,height=8,
			x=graph.axis.lin(title="Kinetic Energy [keV]",min=0,max=800),
			y=graph.axis.lin(title="Asymmetry $A(E)\\beta/2$"),
			key = graph.key.key(pos="tr"))
	setTexrunner(gAsym)
	gdat = [[c.energy,c.A0,c.A] for c in corrs if c.energy<783]
	gAsym.plot(graph.data.points(gdat,x=1,y=2,title="$A(E)=A_0$"),[graph.style.line([style.linewidth.Thick])])
	gAsym.plot(graph.data.points(gdat,x=1,y=3,title="Corrected"),[graph.style.line([rgb.red,style.linestyle.dashdotted,style.linewidth.Thick])])
	gAsym.writetofile(outpath+"/Asymmetry.pdf")

	
	
	################
	# shape of tensor coupling corrections to A
	################
	
	def tensorCoeff(E):
		m_e = 511.
		l = 1.2694
		return 2/(1+3*l)**2/938000*(m_e**2./E*l**2*(1-l)+782*(l**2+2./3.*l-1./3.)+E*2./3.*(1+l+3*l**2+3*l**3))*(1+3.*l**2)/(2*l*(1-l))
	gT=graph.graphxy(width=20,height=10,
			x=graph.axis.lin(title="Kinetic Energy [keV]",min=0,max=800),
			y=graph.axis.lin(title="$\\Delta A/A$ for $g_{II}/g_V=1$",min=-0.01,max=0.01),
			key = graph.key.key(pos="tr"))
	setTexrunner(gT)
	gT.plot(graph.data.points([(c.energy,tensorCoeff(c.energy)) for c in corrs],x=1,y=2,title=None),[graph.style.line([style.linewidth.Thick])])
	gT.writetofile(outpath+"/GardnerTensor.pdf")
def EndpointSmearingDat():
    baseDir = os.environ["UCNA_ANA_PLOTS"] + "/SimSpectrum/EndpointSmear/"
    #kFits = QFile(baseDir+"/EndpointSmear_150-XXX.txt").dat["kurieFit"] # <--
    kFits = QFile(baseDir + "/EndpointSmear_XXX-635.txt").dat["kurieFit"]

    gHeight = 12
    g = graph.graphxy(width=20,
                      height=gHeight,
                      x=graph.axis.lin(
                          title="PMT average energy resolution [keV at 1 MeV]",
                          min=40,
                          max=200),
                      y=graph.axis.lin(title="simulated endpoint shift [keV]"),
                      key=graph.key.key(pos="tl"))
    setTexrunner(g)

    ep0 = 710

    sens = []
    nn = 0
    pmtRes = [75, 100, 125]
    resSty = [[style.linestyle.dashed, style.linewidth.THick],
              [style.linestyle.solid, style.linewidth.THick],
              [style.linestyle.dotted, style.linewidth.THick]]

    #for fitEnd in [600,620,640,660,680,700,720][::-1]:
    for fitStart in [100, 120, 140, 160, 180, 200, 220, 240][::-1]:

        lsty = [[style.linestyle.solid], [style.linestyle.dashed],
                [style.linestyle.dotted], [style.linestyle.dashdotted],
                [style.linestyle.solid, style.linewidth.THick],
                [style.linestyle.dashed, style.linewidth.THick],
                [style.linestyle.dotted, style.linewidth.THick],
                [style.linestyle.dashdotted, style.linewidth.THick]
                #][::-1][nn+1] # <--
                ][::-1][nn]  # <--
        nn += 1

        resPts = {}
        for k in kFits:
            k.loadFloats()
            #if k.fitEnd != fitEnd: # <--
            if k.fitStart != fitStart:  # <--
                continue
            k.endpoint = k.endpoint - ep0
            resPts.setdefault(k.PEperMEV, []).append(k)
        avgd = [[1000 / sqrt(k)] + mu_uncert([c.endpoint for c in resPts[k]])
                for k in resPts]
        avgd.sort()
        if not avgd:
            continue

        QF = LinearFitter([polyterm(i) for i in range(3)])
        QF.fit(avgd, cols=(0, 1, 2), errorbarWeights=False)
        #sens.append([fitEnd,] + [nderiv(QF,x) for x in pmtRes])	# <--
        sens.append([
            fitStart,
        ] + [nderiv(QF, x) for x in pmtRes])  # <--
        print sens[-1][0], "100keV Res Sensitivity dy/dx =", sens[-1][1]

        g.plot(graph.data.points(avgd, x=1, y=2, dy=3, title=None), [
            graph.style.errorbar(),
            graph.style.symbol(symbol.circle, size=0.15)
        ])
        #g.plot(graph.data.points(QF.fitcurve(40,200,200),x=1,y=2,title="150--%i keV"%fitEnd),[graph.style.line(lsty)]) # <--
        g.plot(
            graph.data.points(QF.fitcurve(40, 200, 200),
                              x=1,
                              y=2,
                              title="%i--635 keV" % fitStart),
            [graph.style.line(lsty)])  # <--

    #g.writetofile(baseDir+"Endpoint_End.pdf") # <--
    g.writetofile(baseDir + "Endpoint_Start.pdf")  # <--

    if 0:
        g = graph.graphxy(
            width=gHeight,
            height=gHeight,
            #x=graph.axis.lin(title="Kurie fit window end [keV]"), # <--
            x=graph.axis.lin(
                title="Kurie fit window end [keV]",
                min=100,
                max=240,
                parter=graph.axis.parter.linear(tickdists=[20, 5])),  # <--
            y=graph.axis.lin(title="sensitivity to energy resolution keV/keV"),
            key=graph.key.key(pos="tl"))
        setTexrunner(g)

        for (n, p0) in enumerate(pmtRes):
            QF = LinearFitter([polyterm(i) for i in range(3)])
            QF.fit(sens, cols=(0, n + 1))
            g.plot(graph.data.points(sens, x=1, y=n + 2, title=None),
                   [graph.style.symbol(symbol.circle)])
            g.plot(
                graph.data.points(QF.fitcurve(600, 720, 200),
                                  x=1,
                                  y=2,
                                  title="%i keV @ 1 MeV" % p0),
                [graph.style.line(resSty[n])])  # <--

        #g.writetofile(baseDir+"Endpoint_EndSens.pdf") # <--
        g.writetofile(baseDir + "Endpoint_StartSens.pdf")  # <--

    if 0:
        g = graph.graphxy(width=15,
                          height=8,
                          x=graph.axis.lin(title="predicted sigma"),
                          y=graph.axis.lin(title="observed sigma"))
        setTexrunner(g)
        g.plot(graph.data.points(avgd, x=4, y=3),
               [graph.style.symbol(symbol.circle)])
        g.writetofile(baseDir + "EndpointSigma.pdf")
Example #14
0
def paperFig1(inColor=False):
    pdat = [
        asymplot(a) for a in QFile(os.environ["UCNA_ANA_PLOTS"] +
                                   "/Paper/PlotData.txt").dat["asymplot"]
    ]

    xrange = (0, 800)
    gwid = 12

    gCorr = graph.graphxy(width=gwid,
                          height=0.2 * gwid,
                          x=graph.axis.lin(title="Reconstructed Energy [keV]",
                                           min=xrange[0],
                                           max=xrange[1]),
                          y=graph.axis.lin(title="\\% Corr.", min=-5, max=5),
                          key=graph.key.key(pos="tl"))
    setTexrunner(gCorr)

    gAsym = graph.graphxy(width=gwid,
                          height=0.4 * gwid,
                          ypos=gCorr.height + 0.5,
                          x=graph.axis.linkedaxis(gCorr.axes["x"]),
                          y=graph.axis.lin(title="$A_0$", min=-0.14,
                                           max=-0.10),
                          key=graph.key.key(pos="tr"))
    setTexrunner(gAsym)

    gSpec = graph.graphxy(width=gwid,
                          height=0.5 * gwid,
                          ypos=gCorr.height + gAsym.height + 1.0,
                          x=graph.axis.linkedaxis(gCorr.axes["x"]),
                          y=graph.axis.lin(title="Decay Rate [Hz/keV]",
                                           min=0,
                                           max=0.065),
                          key=graph.key.key(pos="tr"))
    setTexrunner(gSpec)

    cnvs = canvas.canvas()
    cnvs.insert(gCorr)
    cnvs.insert(gAsym)
    cnvs.insert(gSpec)

    specCircAttrs = None
    bgCircAttrs = [deco.filled]
    if inColor:
        specCircAttrs = [color.rgb.blue]
        bgCircAttrs += [color.rgb(0, 0.7, 0)]

    gSpec.plot(
        graph.data.points([(p.KE, p.ssfg) for p in pdat],
                          x=1,
                          y=2,
                          title="Data"),
        [
            graph.style.symbol(
                symbol.circle, size=0.1, symbolattrs=specCircAttrs),
        ])
    gSpec.plot(
        graph.data.points([(p.KE, p.ssMC) for p in pdat],
                          x=1,
                          y=2,
                          title="Geant4 MC"), [
                              graph.style.line(),
                          ])
    gSpec.plot(
        graph.data.points([(p.KE, p.ssbg) for p in pdat],
                          x=1,
                          y=2,
                          title="Background"),
        [
            graph.style.symbol(
                symbol.circle, size=0.1, symbolattrs=bgCircAttrs),
        ])

    pdat = [p for p in pdat if p.KE > 60]

    area = errorBand([(p.KE, 100. * p.corr, 100. * p.dcorr) for p in pdat], 0,
                     1, 2)
    asLineAttrs = [style.linewidth.THick]
    if inColor:
        gCorr.fill(area, [deco.filled([color.rgb(0.5, 0.5, 1)])])
        asLineAttrs += [color.rgb.green]
    else:
        gCorr.fill(area, [pattern.hatched(0.10, -45)])
        gCorr.fill(area, [pattern.hatched(0.10, 45)])

    gCorr.plot(
        graph.data.points([(p.KE, 100. * p.corr, 100. * p.dcorr)
                           for p in pdat],
                          x=1,
                          y=2,
                          dy=3,
                          title=None), [
                              graph.style.line(asLineAttrs),
                          ]
    )  #[graph.style.symbol(symbol.circle,size=0.1), ]) #graph.style.errorbar()])
    for y in [-2.5, 0, 2.5]:
        gCorr.plot(graph.data.points([(0, y), (800, y)], x=1, y=2, title=None),
                   [graph.style.line([style.linestyle.dashed])])

    if False:
        d = gCorr.plot(
            graph.data.points([(p.KE, 100. * p.dcorr) for p in pdat],
                              x=1,
                              y=2,
                              title=None), [graph.style.line()])

        gCorr.finish()
        p = d.path

        pa = gCorr.xgridpath(100)
        pb = gCorr.xgridpath(750)
        p0 = gCorr.ygridpath(0)
        (splita, ), (splitpa, ) = p.intersect(pa)
        (splitb, ), (splitpb, ) = p.intersect(pb)
        splitp0a = p0.intersect(pa)[1][0]
        splitp0b = p0.intersect(pb)[1][0]

        area = (
            pa.split([splitp0a, splitpa])[1] << p.split([splita, splitb])[1] <<
            pb.split([splitp0b, splitpb])[1].reversed())
        area[-1].close()
        gCorr.stroke(area, [deco.filled([color.gray(0.8)])])

    asymBarAttrs = None
    asymCircAttrs = [deco.filled([color.gray(1.0)])]
    asymFitAttrs = [style.linewidth.THIck]
    if inColor:
        asymBarAttrs = [color.rgb.blue]
        asymCircAttrs += [color.rgb.blue]
        asymFitAttrs += [color.rgb(0, 0.7, 0)]

    gAsym.plot(
        graph.data.points([(p.KE, p.A0, p.dA0) for p in pdat],
                          x=1,
                          y=2,
                          dy=3,
                          title=None),
        [
            graph.style.errorbar(errorbarattrs=asymBarAttrs),
            graph.style.symbol(
                symbol.circle, size=0.1, symbolattrs=asymCircAttrs)
        ])
    A0 = -0.11954
    gAsym.plot(graph.data.points([(220, A0), (670, A0)], x=1, y=2, title=None),
               [graph.style.line(asymFitAttrs)])

    # different fit ranges
    for (e0, e1) in [
        (220, 670),
    ] + [(200 - 10 * x, 700 + 10 * x) for x in range(11)]:
        LF = LinearFitter(terms=[polyterm(0)])
        fdat = [(p.KE, p.A0, p.dA0) for p in pdat if e0 < p.KE < e1]
        LF.fit(fdat, cols=(0, 1, 2), errorbarWeights=True)
        print "<A0> [%i,%i] =" % (
            e0, e1), LF.coeffs[0], "chi^2/ndf =", LF.chisquared(), LF.nu()

    cnvs.writetofile(os.environ["UCNA_ANA_PLOTS"] + "/Paper/Fig1_new.pdf")

    if False:
        fgtot = bgtot = 0
        for p in pdat:
            if 100 < p.KE and p.KE < 800:
                print p.KE, p.ssbg, p.ssfg, p.ssfg / p.ssbg
            if True or (220 < p.KE and p.KE < 670):
                fgtot += p.ssfg
                bgtot += p.ssbg
        print "\n\n", fgtot, bgtot, fgtot / bgtot
Example #15
0
 def __init__(self):
     self.dat = dict([(int(x.getFirst("Z")), x) for x in QFile(
         os.environ["UCNA_AUX"] +
         "/NuclearDecays/ElectronBindingEnergy.txt").dat["binding"]])
Example #16
0
def EQ2ET(fbase, conn=None):
	
	f = QFile(fbase+"/Evis2ETrue.txt")
	epts = [EnergyPoint(m) for m in f.dat.get("spectrumInfo",[])]
	
	#scols = {"East":rgb.red,"West":rgb.blue}
	scols = {"East":rgb.black,"West":rgb.black}
	typeSymbs = {0:symbol.circle,1:symbol.triangle,2:symbol.square,3:symbol.cross}
	typeLines = {0:style.linestyle.solid,1:style.linestyle.dashed,2:style.linestyle.dotted,3:style.linestyle.dashdotted}
	typeNames = {0:"0",1:"I",2:"II/III",3:"III"}
	
	for forward in [True,]:
	
		xtitle = "mean $E_{\\rm vis}$ [keV]"
		#ytitle = "True Initial Energy [keV]"
		ytitle = "initial energy $E_{\\rm true}$ [keV]"
		if not forward:
			xtitle = "Mean True Energy [keV]"
			ytitle = "Observed Quenched Energy [keV]"
		residTitle = "Residuals [keV]"
		
		gResid = []
		gWidth = 12
		
		gResid.append(graph.graphxy(width=gWidth,height=(gWidth-2.)/3.,
				x=graph.axis.lin(title=xtitle,min=0,max=800),
				y=graph.axis.lin(title=residTitle,min=-5,max=5),
				key = graph.key.key(pos="br")))
		setTexrunner(gResid[-1]) #.texrunner.set(lfs='10ptex')
		for i in range(2):
			gResid.append(graph.graphxy(width=gResid[0].width,height=gResid[0].height,ypos=(gResid[0].height+1.0)*(i+1),
				x=graph.axis.linkedaxis(gResid[0].axes["x"]),
				y=graph.axis.lin(title=residTitle,min=-5,max=5),
				key = graph.key.key(pos="br")))
			setTexrunner(gResid[-1])
		
		#gEn=graph.graphxy(width=gResid.width,height=gResid.width,ypos=gResid.height+0.5,
		#		x=graph.axis.linkedaxis(gResid[0].axes["x"]),
		#		y=graph.axis.lin(title=ytitle,min=0,max=800),
		#		key = graph.key.key(pos="tl"))
		#setTexrunner(gEn) #.texrunner.set(lfs='10ptex')
		gEn=graph.graphxy(width=gResid[0].width,height=gResid[0].width,
				x=graph.axis.lin(title=xtitle,min=0,max=800),
				y=graph.axis.lin(title=ytitle,min=0,max=800),
				key = graph.key.key(pos="tl"))
		setTexrunner(gEn)
		
		cnvs = canvas.canvas()
		#cnvs.insert(gResid)
		#cnvs.insert(gEn)
		for i in range(3):
			cnvs.insert(gResid[i])
		
		types = typeSymbs.keys()
		types.sort()
		
		for tp in types:
			
			combodat = []
			
			for s in scols:
			
				gdat = []
				if forward:
					gdat = [ (p.evis_avg,p.etrue_input,p.evis_rms/sqrt(p.evis_counts)) for p in epts if p.side==s and p.type==tp and p.evis_counts > 50 ]
				else:
					gdat = [ (p.etrue_avg,p.evis_input,p.etrue_rms/sqrt(p.etrue_counts)) for p in epts if p.side==s and p.type==tp and p.etrue_counts > 50 ]
				combodat += gdat
		
				gEn.plot(graph.data.points(gdat,x=1,y=2,dx=3,title=None),
					[graph.style.symbol(typeSymbs[tp],size=0.20,symbolattrs=[scols[s],]),graph.style.errorbar(errorbarattrs=[scols[s]])])
			
			combodat.sort()
			if not combodat:
				print "Missing data for type",tp
				continue
			LF = LinearFitter(terms=[polyterm(0),polyterm(1),polyterm(-1),polyterm(-2)])
			LF.fit([c for c in combodat],cols=(0,1))
			print s,LF.toLatex()
			LF = piecewiseExtender(LF,combodat[1][0],900)
			
			if forward and conn:
				uploadEQ2ET(conn,tp,LF)
				
			gEn.plot(graph.data.points(LF.fitcurve(1,1000,400),x=1,y=2,title=None),
				[graph.style.line([typeLines[tp],style.linewidth.Thick])])
			
			# empty plots... for type name labels
			ctitle = "Type %s"%typeNames[tp]
			#ctitle += ": $E_T = %s$"%LF.toLatex("E_Q")
			gEn.plot(graph.data.points([(-1,-1),],x=1,y=2,title=ctitle),
				[graph.style.line([typeLines[tp],style.linewidth.Thick]),graph.style.symbol(typeSymbs[tp],size=0.20)])
				
			gResid[tp].plot(graph.data.points([ (g[0],g[1]-LF(g[0])) for g in combodat],x=1,y=2,title=ctitle),
				[graph.style.symbol(typeSymbs[tp],size=0.15)])
		
		if forward:
			cnvs.writetofile(fbase+"/EvisToETrue_resid.pdf")
			gEn.writetofile(fbase+"/EvisToETrue.pdf")
		else:
			cnvs.writetofile(fbase+"/EtrueToEvis.pdf")