Example #1
0
File: eff.py Project: yiiyama/MonoX
            canvas.legend.Clear()
            if title:
                canvas.legend.add('eff',
                                  title=title,
                                  opt='LP',
                                  color=ROOT.kBlack,
                                  mstyle=8)
                canvas.legend.apply('eff', eff)
            else:
                eff.SetMarkerColor(ROOT.kBlack)
                eff.SetMarkerStyle(8)

            canvas.addHistogram(eff, drawOpt='EP', clone=False)

            canvas.xtitle = vtitle
            canvas.ylimits = (0., 1.1)

            canvas.Update()

            if type(binning) is tuple:
                eff.GetXaxis().SetLimits(binning[1], binning[2])
                eff.GetXaxis().SetRangeUser(binning[1], binning[2])
            else:
                eff.GetXaxis().SetLimits(binning[0], binning[-1])
                eff.GetXaxis().SetRangeUser(binning[0], binning[-1])

            eff.GetYaxis().SetRangeUser(0., 1.2)

            #            if tname == 'sph165abs' and vname.startswith('pt'):
            #                canvas.addLine(175., canvas.ylimits[0], 175., canvas.ylimits[1], color = ROOT.kRed, width = 2, style = ROOT.kDashed)
Example #2
0
frate.Write()
yields['ee'].Write()
yields['eg'].Write()

lumi = 0.
for sname in lumiSamples:
    lumi += allsamples[sname].lumi

canvas = SimpleCanvas(lumi = lumi, sim = (dataType == 'mc'))
canvas.legend.setPosition(0.7, 0.8, 0.9, 0.9)
canvas.legend.add('frate', 'R_{e}', opt = 'LP', color = ROOT.kBlack, mstyle = 8)
canvas.legend.apply('frate', frate)
canvas.ylimits = (0., 0.03)
canvas.addHistogram(frate, drawOpt = 'EP')

canvas.xtitle = binningTitle
canvas.printWeb('efake', 'frate_' + dataType + '_' + binningName, logy = False)

for iBin, (binName, cut) in enumerate(fitBins):
    if dataType == 'mc':
        print '%15s [%.3f +- %.3f (stat.) +- %.3f (syst.)] x 10^{-2} (mc %.3f)' % (binName, contents[iBin] * 100., staterrs[iBin] * 100., systerrs[iBin] * 100., mctruth[iBin] * 100.)
    else:
        print '%15s [%.3f +- %.3f (stat.) +- %.3f (syst.)] x 10^{-2}' % (binName, contents[iBin] * 100., staterrs[iBin] * 100., systerrs[iBin] * 100.)

if toyUncert and binningName == 'pt':
    binName = 'pt_160_6500'
    for conf in ['ee', 'eg']:
        canvas.Clear(full = True)
        canvas.ylimits = (0., 0.05)
        canvas.xtitle = 'N_{Z}'
Example #3
0
    outputFile.cd()
    eff.Write(vname + '_' + tname + '_' + sname)

canvas.SetGrid()

canvas.legend.Clear()
if title:
    canvas.legend.add('eff', title = title, opt = 'LP', color = ROOT.kBlack, mstyle = 8)
    canvas.legend.apply('eff', eff)
else:
    eff.SetMarkerColor(ROOT.kBlack)
    eff.SetMarkerStyle(8)

canvas.addHistogram(eff, drawOpt = 'EP')

canvas.xtitle = vtitle
canvas.ylimits = (0., 1.2)

canvas.Update()

if type(binning) is tuple:
    canvas.addLine(binning[0], 1., binning[2], 1.)
    eff.GetXaxis().SetLimits(binning[1], binning[2])
else:
    canvas.addLine(binning[0], 1., binning[-1], 1.)
    eff.GetXaxis().SetLimits(binning[0], binning[-1])

eff.GetYaxis().SetRangeUser(0., 1.2)

canvas.printWeb('trigger', vname + '_' + tname + '_' + sname + '_' + oname, logy = False)
Example #4
0
                gSF.SetPoint(iB, center, sf)
                gSF.SetPointError(iB, exl, exh, sfErrLow, sfErrHigh)

                print sf, sfErrLow, sfErrLow / sf

            rcanvas.legend.add("mc", title = "MC", mcolor = r.kRed, lcolor = r.kRed, lwidth = 2)
            rcanvas.legend.apply("mc", mcEff)
            rcanvas.addHistogram(mcEff, drawOpt = 'EP')

            rcanvas.legend.add("data", title = "Data", lcolor = r.kBlack, lwidth = 2)
            rcanvas.legend.apply("data", dataEff)
            rcanvas.addHistogram(dataEff, drawOpt = 'EP')

            rcanvas.ylimits = (0.0, 1.1)
            rcanvas.ytitle = 'Photon Efficiency'
            rcanvas.xtitle = 'E_{T}^{#gamma} (GeV)'

            plotName = "efficiency_"+str(loc)+"_"+str(pid)
            rcanvas.printWeb('purity/'+s.Version+'/ScaleFactors', plotName, logy = False)
                
            canvas.legend.add(loc+'-'+pid, title = loc+'-'+pid, color = r.kBlack, lwidth = 2)
            canvas.legend.apply(loc+'-'+pid, gSF)
            canvas.addHistogram(gSF, drawOpt = 'EP')
            
            canvas.ylimits = (0.0, 2.0)
            canvas.ytitle = 'Photon Scale Factor'
            canvas.xtitle = 'E_{T}^{#gamma} (GeV)'

            plotName = "scalefactor_"+str(loc)+"_"+str(pid)
            canvas.printWeb('purity/'+s.Version+'/ScaleFactors', plotName, logy = False)
Example #5
0
    reweighted += efficiency.GetBinContent(iX) * nproxy

    tpDist.SetBinContent(iX, ntp)

original /= tpDist.GetSumOfWeights() # should in principle match the nominal pT > 40 GeV efficiency
reweighted /= proxyDist.GetSumOfWeights()

print 'Original fake rate =', 1. / original - 1.
print 'Reweighted fake rate =', 1. / reweighted - 1.

proxyDist.Scale(1., 'width')
tpDist.Scale(1., 'width')
proxyDist.Scale(8. / proxyDist.GetSumOfWeights())
tpDist.Scale(8. / tpDist.GetSumOfWeights())

canvas = SimpleCanvas()
canvas.legend.setPosition(0.6, 0.7, 0.9, 0.9)
canvas.legend.add('inefficiency', title = '1 - #epsilon_{e}', opt = 'LP', mstyle = 8, color = ROOT.kBlack)
canvas.legend.add('tp', title = 'T&P sample', opt = 'LF', color = ROOT.kRed - 7, fstyle = 3003, lwidth = 2)
canvas.legend.add('proxy', title = 'W#rightarrowe#nu', opt = 'LF', color = ROOT.kBlue - 7, fstyle = 3003, lwidth = 2)

canvas.addHistogram(inefficiency, drawOpt = 'EP')
canvas.addHistogram(tpDist)
canvas.addHistogram(proxyDist)
canvas.applyStyles()

canvas.ytitle = '1 - #epsilon (%)'
canvas.xtitle = title

canvas.printWeb('efake', 'convolution_' + variable, logy = False)
Example #6
0
            #  if not 'max' in mod:
                canvas.legend.add(base + mod,
                                  title=base + mod,
                                  mcolor=r.kBlue + iMod,
                                  lcolor=r.kBlue + iMod,
                                  lwidth=2)
                canvas.legend.apply(base + mod, pGraph)
                canvas.addHistogram(pGraph, drawOpt='EP')

                outFile.cd()
                pGraph.Write()

            canvas.ylimits = (0.0, 15.0)
            canvas.ytitle = 'Photon Impurity'
            canvas.xtitle = 'E_{T}^{#gamma} (GeV)'
            canvas.SetGridy(True)

            plotName = 'Plot_' + tune + '_impurity_' + str(metCut) + '_' + str(
                loc) + '_' + str(base)
            canvas.printWeb('purity/' + s.Version + '/Fitting',
                            plotName,
                            logy=False)

outFile.Close()

for loc in s.Locations[:1]:
    for base in bases:
        for metCut in MetSels:
            for iMod, mod in enumerate(mods):
Example #7
0
    linear.SetParameters(1., 0.01)
    linear.SetParLimits(0, 0.95, 1.05)
    linear.SetParLimits(1, -0.0001, 0.0001)

    sfTruth.Fit(linear)
    canvas.addObject(linear)

    text = 'flat = %.3f #pm %.3f' % (flat.GetParameter(0), flat.GetParError(0))
    canvas.addText(text, 0.3, 0.25, 0.5, 0.2)

    text = 'line = %.6f + %.6f * p_{T}' % (linear.GetParameter(0), linear.GetParameter(1))
    canvas.addText(text, 0.3, 0.35, 0.5, 0.25)



canvas.xtitle = binningTitle
canvas.printWeb(outputName, 'scaleFactor_' + binningName, logy = False)


print 'Fit Results:'
for iBin, (bin, _) in enumerate(fitBins):
    print '%15s [%.3f +- %.3f]' % (bin, scaleFactor.GetBinContent(iBin + 1), scaleFactor.GetBinError(iBin + 1))

print '\nTruth Results:'
for iBin, (bin, _) in enumerate(fitBins):
    print '%15s [%.3f +- %.3f]' % (bin, sfTruth.GetBinContent(iBin + 1), sfTruth.GetBinError(iBin + 1))

outFileName = 'table_' + binningName + '.tex'
outDir = WEBDIR + '/' + outputName
outFilePath = outDir + '/' + outFileName
outFile = open(outFilePath, 'w')
Example #8
0
    gup.SetLineStyle(ROOT.kDashed)
    gup.SetLineColor(power.GetLineColor())
    gup.SetLineWidth(power.GetLineWidth())
    canvas.addHistogram(gup, drawOpt='CL')

    gdown.SetLineStyle(ROOT.kDashed)
    gdown.SetLineColor(power.GetLineColor())
    gdown.SetLineWidth(power.GetLineWidth())
    canvas.addHistogram(gdown, drawOpt='CL')

    outputFile.cd()
    gup.Write(PRODUCT + '_fitUp')
    gdown.Write(PRODUCT + '_fitDown')

canvas.xtitle = binningTitle
canvas.printWeb(outputName,
                PRODUCT + '_' + dataType + '_' + binningName,
                logy=False)

for iBin, (bin, _) in enumerate(fitBins):
    if dataType == 'mc':
        print '%15s [%.3f +- %.3f (stat.) +- %.3f (syst.)] x 10^{-2} (mc %.3f)' % (
            bin, result.GetBinContent(iBin + 1) * 100., staterrs[iBin] * 100.,
            systerrs[iBin] * 100., trueResult.GetBinContent(iBin + 1) * 100.)
    else:
        print '%15s [%.3f +- %.3f (stat.) +- %.3f (syst.)] x 10^{-2}' % (
            bin, result.GetBinContent(iBin + 1) * 100., staterrs[iBin] * 100.,
            systerrs[iBin] * 100.)

if uncSource:
Example #9
0
        yieldDiff = toyResult.nReal - nominalResult.nReal
        print "Yield diff is:", yieldDiff
        toyPlotYield.Fill(yieldDiff)

    bkgdUncertainty = toyPlot.GetStdDev()
    bkgdUncYield = toyPlotYield.GetStdDev()

    tcanvas = SimpleCanvas(lumi = s.sphLumi, name = 'toys')
    toyPlot.SetTitle('')

    tcanvas.legend.add('toys', title = 'toys', opt = 'L', lcolor = ROOT.kBlue, lwidth = 2, lstyle = ROOT.kSolid)
    tcanvas.legend.apply('toys', toyPlot)
    tcanvas.addHistogram(toyPlot)

    tcanvas.xtitle = 'Impurity Difference (%)'
    tcanvas.ytitle = '# of Toys'
    
    tcanvas.printWeb(plotDir, 'ssfit_toy_dist', logy = False)
    
    tcanvas.Clear()
    toyPlotYield.SetTitle('')
    
    tcanvas.legend.apply('toys', toyPlotYield)
    tcanvas.addHistogram(toyPlotYield)

    tcanvas.xtitle = '#Delta(# of True Photons)'
    tcanvas.ytitle = '# of Toys'
    
    tcanvas.printWeb(plotDir, 'ssfit_toyyield_dist', logy = False)
    
Example #10
0
    result.Fit(power)
    canvas.addObject(power)

    for ibin, err in errors.items():
        result.SetBinError(ibin, err)

    text = 'f = %.4f + #frac{%.3f}{(p_{T} - %.0f)' % (
        power.GetParameter(0), power.GetParameter(1), binning[0])
    if power.GetParameter(2) >= 0.:
        text += ' - %.2f}' % power.GetParameter(2)
    else:
        text += ' + %.2f}' % (-power.GetParameter(2))

    canvas.addText(text, 0.3, 0.3, 0.5, 0.2)

canvas.xtitle = binningTitle
canvas.printWeb(outputName,
                PRODUCT + '_' + dataType + '_' + binningName,
                logy=False)

for iBin, (bin, _) in enumerate(fitBins):
    if dataType == 'mc':
        print '%15s [%.3f +- %.3f (stat.) +- %.3f (syst.)] x 10^{-2} (mc %.3f)' % (
            bin, result.GetBinContent(iBin + 1) * 100., staterrs[iBin] * 100.,
            systerrs[iBin] * 100., trueResult.GetBinContent(iBin + 1) * 100.)
    else:
        print '%15s [%.3f +- %.3f (stat.) +- %.3f (syst.)] x 10^{-2}' % (
            bin, result.GetBinContent(iBin + 1) * 100., staterrs[iBin] * 100.,
            systerrs[iBin] * 100.)

if uncSource:
Example #11
0
stack.Add(sig)

bkgTrue.Scale(1., 'width')
bkgTrue.SetLineColor(ROOT.kGreen + 2)
bkgTrue.SetLineWidth(2)

fakeTrue.Scale(fakeNorm / fakeTrue.GetSumOfWeights(), 'width')
fakeTrue.SetLineColor(ROOT.kRed + 2)
fakeTrue.SetLineWidth(2)

sigTrue.Scale(sigScale, 'width')
sigTrue.SetLineColor(ROOT.kBlue + 2)
sigTrue.SetLineWidth(2)

data.SetMarkerStyle(8)
data.SetLineColor(ROOT.kBlack)
data.SetLineWidth(1)

canvas.title = '#sigma#timesBR = %.2f, N_{fake} = %.0f' % (originalMu *
                                                           sigScale, fakeNorm)
canvas.xtitle = 'm_{T} (GeV)'
canvas.ytitle = 'Events / GeV'

canvas.addHistogram(stack, drawOpt='HIST')
canvas.addHistogram(bkgTrue, drawOpt='HIST')
canvas.addHistogram(fakeTrue, drawOpt='HIST')
canvas.addHistogram(sigTrue, drawOpt='HIST')
canvas.addHistogram(data, drawOpt='EP')

canvas.printWeb('monophoton/fakemet', name, logy=False)
Example #12
0
            if y > 5.:
                y = 5.
            if y < -5.:
                y = -5.

            graph.SetPoint(ip, x, y)

        graph.SetTitle('')

        outputFile.cd()
        graph.Write('%s_%s' % (sigs, faken))

        graphs.append(graph)

        canvas.legend.apply('n%s' % faken, graph)
        canvas.addHistogram(graph, drawOpt='P')

    canvas.addLine(-5., 0., 5., 0., style=ROOT.kDashed)
    canvas.addLine(0., -5., 0., 5., style=ROOT.kDashed)
    canvas.xlimits = (-5., 5.)
    canvas.ylimits = (-5., 5.)

    canvas.title = '#sigma#timesBR = %.2f' % mu
    canvas.xtitle = 'Fake E_{T}^{miss}: (N_{fit} - N_{true})/#sigma_{fit}'
    canvas.ytitle = 'Signal: (N_{fit} - N_{true})/#sigma_{fit}'

    canvas.printWeb('monophoton/fakemet', sourceName + '_' + sigs, logy=False)
    canvas.Clear()

outputFile.Close()
Example #13
0
from plotstyle import SimpleCanvas
canvas = SimpleCanvas(lumi = sum(t.lumi for t in targs))
plotName = 'fit'

### fit to halo distribution and parametrize

# draw
dataTree.Draw(phimpipi + '>>haloTemp(40,-{pi},{pi})'.format(pi = math.pi), 'photons.mipEnergy > 4.9 && photons.isEB && photons.scRawPt > 175. && t1Met.met > 140. && photons.chWorstIso < 1.37 && photons.nhIso < 1.06', 'goff')

haloTemp = ROOT.gDirectory.Get('haloTemp')
haloTemp.SetLineColor(ROOT.kBlack)
haloTemp.SetLineWidth(2)
haloTemp.SetTitle(';#phi\'')

canvas.addHistogram(haloTemp)
canvas.xtitle = '#phi\''
canvas.printWeb('monophoton/halo', 'haloTemp', logy = False)
canvas.Clear()

# first get the halo phi values
nHalo = dataTree.Draw(phivar + '>>haloTemp(40,-{pi},{pi})'.format(pi = math.pi), 'photons.mipEnergy > 4.9 && photons.isEB && photons.scRawPt > 175. && t1Met.met > 140. && photons.chWorstIso < 1.37 && photons.nhIso < 1.06', 'goff')
print nHalo, 'halo events'

# dump them into a RooDataSet
haloData = ROOT.RooDataSet('halo', 'halo', phiset)
haloPhi = dataTree.GetV1()
for iHalo in range(nHalo):
    phi.setVal(haloPhi[iHalo])
    haloData.add(phiset)

# then fit with gaus + gaus + uniform
Example #14
0
            if x > 2.:
                x = 2.
            if y > 2.:
                y = 2.

            graph.SetPoint(ip, x, y)

        graph.SetTitle('')

        outputFile.cd()
        graph.Write('%s_%s' % (sigs, faken))

        graphs.append(graph)

        canvas.legend.apply('n%s' % faken, graph)
        canvas.addHistogram(graph, drawOpt='P')

    canvas.addLine(0., 1., 2., 1., style=ROOT.kDashed)
    canvas.addLine(1., 0., 1., 2., style=ROOT.kDashed)
    canvas.xlimits = (0., 2.)
    canvas.ylimits = (0., 2.)

    canvas.title = '#sigma#timesBR = %.2f' % mu
    canvas.xtitle = 'Fake E_{T}^{miss} extracted / injected'
    canvas.ytitle = 'Signal extracted / injected'

    canvas.printWeb('monophoton/fakemet', sigs, logy=False)
    canvas.Clear()

outputFile.Close()