Esempio n. 1
0
def selectLowMass(row):
    return row.MassDREtFSR < 110.

for ana in ['full', 'z4l']:
    
    if ana == 'z4l':
        selector = selectLowMass
    else:
        selector = lambda *args: True

    g = {}
    for ch in plotter.channels:
        g[ch] = Graph(plotter.ntuples['data']['data'][ch].GetEntries(), title=titles[ch])
        g[ch].color = colors[ch]
        g[ch].markerstyle = markers[ch]
        g[ch].drawstyle = 'P'
        g[ch].SetMarkerSize(g[ch].GetMarkerSize()*1.5)
        if ch == 'mmmm':
            g[ch].SetMarkerSize(g[ch].GetMarkerSize()*1.18)
    
    for ch in plotter.channels:
        #nWithFSR = 0
        for i, row in enumerate(plotter.ntuples['data']['data'][ch]):
            if selector(row):
                g[ch].SetPoint(i, getMZ1[ch](row), getMZ2[ch](row))
            #if row.Mass != row.MassDREtFSR:
            #    nWithFSR += 1
        #print "%s: %d / %d"%(ch, nWithFSR, int(plotter.ntuples['data']['data'][ch].GetEntries()))
    
    #for gr in g.values():
    #    gr.yaxis.SetTitleOffset(gr.yaxis.GetTitleOffset()*0.8)
Esempio n. 2
0
def main(args):

    fileList = glob('/data/nawoods/lepsForSIP/*.root')
    files = {int(f.split('_M')[1].split('.')[0]) : f for f in fileList}

    checkers = {m : MuonSIPChecker('m={}'.format(m), [f]) for m,f in files.iteritems()}
    sipRMS = Graph(len(fileList), type='errors')
    sipHists = []
    dxyRMS = Graph(len(fileList), type='errors')
    dxyHists = []
    dzRMS = Graph(len(fileList), type='errors')
    dzHists = []

    ipHists = []
    ipErrHists = []

    fracFailing = Graph(len(fileList), type='errors')
    for i, m in enumerate(sorted(files.keys())):

        checkers[m].processSample()

        checkers[m].hists['sip'].Sumw2()
        sipRMS.SetPoint(i, float(m), checkers[m].hists['sip'].GetRMS())
        sipRMS.SetPointError(i, 0., checkers[m].hists['sip'].GetRMSError())
        sipHists.append(checkers[m].hists['sip'])
        sipHists[-1].color = getColor(m)
        sipHists[-1].title = "m_{{H}} = {}".format(m)
        sipHists[-1].drawstyle = 'hist'
        sipHists[-1].legendstyle = 'L'
        sipHists[-1].linewidth = 2
        sipHists[-1].scale(1./sipHists[-1].integral())

        ipHists.append(checkers[m].hists['ip'])
        ipHists[-1].color = getColor(m)
        ipHists[-1].title = "m_{{H}} = {}".format(m)
        ipHists[-1].drawstyle = 'hist'
        ipHists[-1].legendstyle = 'L'
        ipHists[-1].linewidth = 2
        ipHists[-1].scale(1./ipHists[-1].integral())

        ipErrHists.append(checkers[m].hists['ipErr'])
        ipErrHists[-1].color = getColor(m)
        ipErrHists[-1].title = "m_{{H}} = {}".format(m)
        ipErrHists[-1].drawstyle = 'hist'
        ipErrHists[-1].legendstyle = 'L'
        ipErrHists[-1].linewidth = 2
        ipErrHists[-1].scale(1./ipErrHists[-1].integral())

        checkers[m].hists['dxy'].Sumw2()
        dxyRMS.SetPoint(i, float(m), checkers[m].hists['dxy'].GetRMS())
        dxyRMS.SetPointError(i, 0., checkers[m].hists['dxy'].GetRMSError())
        dxyHists.append(checkers[m].hists['dxy'])
        dxyHists[-1].color = getColor(m)
        dxyHists[-1].title = "m_{{H}} = {}".format(m)
        dxyHists[-1].drawstyle = 'hist'
        dxyHists[-1].legendstyle = 'L'
        dxyHists[-1].linewidth = 2
        dxyHists[-1].scale(1./dxyHists[-1].integral())
        
        checkers[m].hists['dz'].Sumw2()
        dzRMS.SetPoint(i, float(m), checkers[m].hists['dz'].GetRMS())
        dzRMS.SetPointError(i, 0., checkers[m].hists['dz'].GetRMSError())
        dzHists.append(checkers[m].hists['dz'])
        dzHists[-1].color = getColor(m)
        dzHists[-1].title = "m_{{H}} = {}".format(m)
        dzHists[-1].drawstyle = 'hist'
        dzHists[-1].legendstyle = 'L'
        dzHists[-1].linewidth = 2
        dzHists[-1].scale(1./dzHists[-1].integral())

        fracFailing.SetPoint(i, float(m),
                             1. - float(checkers[m].nPassSIP) / checkers[m].nTot)

    
    cSIP = Canvas(1000,1000)
    draw(sipHists, cSIP, xtitle='#frac{IP_{3D}}{#sigma_{IP_{3D}}}',
         ytitle='arb.')
    legSIP = Legend(sipHists, cSIP, textsize=.03, entrysep=0.015, leftmargin=0.6, entryheight=0.04)
    legSIP.Draw("same")
    cSIP.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/sips.png')
    cSIPLog = Canvas(1000,1000)
    draw(sipHists, cSIPLog, xtitle='#frac{IP_{3D}}{#sigma_{IP_{3D}}}',
         ytitle='arb.', logy=True)
    legSIPLog = Legend(sipHists, cSIPLog, textsize=.027, entrysep=0.012, leftmargin=0.6, entryheight=0.03)
    legSIPLog.Draw("same")
    cSIPLog.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/sipsLog.png')
    
    cSIPRMS = Canvas(1000, 1000)
    sipRMS.color = 'b'
    sipRMS.drawstyle = 'PE'
    sipRMS.legendstyle = 'PE'
    draw(sipRMS, cSIPRMS, xtitle="m_{H}", ytitle="RMS(SIP_{3D})", xlimits=(0.,2600.))
    cSIPRMS.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/sipRMS.png')
    
    cIP = Canvas(1000,1000)
    draw(ipHists, cIP, xtitle='IP_{3D}',
         ytitle='arb.')
    legIP = Legend(ipHists, cIP, textsize=.03, entrysep=0.015, leftmargin=0.6, entryheight=0.04)
    legIP.Draw("same")
    cIP.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/ips.png')
    cIPLog = Canvas(1000,1000)
    draw(ipHists, cIPLog, xtitle='#frac{IP_{3D}}{#sigma_{IP_{3D}}}',
         ytitle='arb.', logy=True)
    legIPLog = Legend(ipHists, cIPLog, textsize=.027, entrysep=0.012, leftmargin=0.6, entryheight=0.03)
    legIPLog.Draw("same")
    cIPLog.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/ipsLog.png')
    
    cIPErr = Canvas(1000,1000)
    draw(ipErrHists, cIPErr, xtitle='#sigma_{IP_{3D}}',
         ytitle='arb.')
    legIPErr = Legend(ipErrHists, cIPErr, textsize=.03, entrysep=0.015, leftmargin=0.6, entryheight=0.04)
    legIPErr.Draw("same")
    cIPErr.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/ipErrs.png')
    cIPErrLog = Canvas(1000,1000)
    draw(ipErrHists, cIPErrLog, xtitle='#sigma_{IP_{3D}}',
         ytitle='arb.', logy=True)
    legIPErrLog = Legend(ipErrHists, cIPErrLog, textsize=.027, entrysep=0.012, leftmargin=0.6, entryheight=0.03)
    legIPErrLog.Draw("same")
    cIPErrLog.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/ipErrsLog.png')
    
    cFail = Canvas(1000, 1000)
    fracFailing.color = 'b'
    fracFailing.drawstyle = 'PE'
    fracFailing.legendstyle = 'PE'
    draw(fracFailing, cSIPRMS, xtitle="m_{H}", ytitle="Fraction failing SIP", xlimits=(0.,2600.))
    cSIPRMS.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/fracFailing.png')
    
    cDXY = Canvas(1000,1000)
    draw(dxyHists, cDXY, xtitle='#Delta_{xy}',
         ytitle='arb.')
    legDXY = Legend(dxyHists, cDXY, textsize=.03, entrysep=0.015, leftmargin=0.6, entryheight=0.04)
    legDXY.Draw("same")
    cDXY.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/dxys.png')

    cDXYRMS = Canvas(1000, 1000)
    dxyRMS.color = 'b'
    dxyRMS.drawstyle = 'PE'
    dxyRMS.legendstyle = 'PE'
    draw(dxyRMS, cDXYRMS, xtitle="m_{H}", ytitle="RMS(#Delta_{xy})", xlimits=(0.,2600.))
    cDXYRMS.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/dxyRMS.png')
    
    cDZ = Canvas(1000,1000)
    draw(dzHists, cDZ, xtitle='#Delta_{z}',
         ytitle='arb.')
    legDZ = Legend(dzHists, cDZ, textsize=.03, entrysep=0.015, leftmargin=0.6, entryheight=0.04)
    legDZ.Draw("same")
    cDZ.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/dzs.png')

    cDZRMS = Canvas(1000, 1000)
    dzRMS.color = 'b'
    dzRMS.drawstyle = 'PE'
    dzRMS.legendstyle = 'PE'
    draw(dzRMS, cDZRMS, xtitle="m_{H}", ytitle="RMS(#Delta_{z})", xlimits=(0.,2600.))
    cDZRMS.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/dzRMS.png')
Esempio n. 3
0
def draw_ratio(a,
               b,
               field,
               category,
               textsize=22,
               ratio_range=(0, 2),
               ratio_line_values=[0.5, 1, 1.5],
               optional_label_text=None,
               normalize=True,
               logy=False):
    """
    Draw a canvas with two Hists normalized to unity on top
    and a ratio plot between the two hist
    Parameters:
    - a: Nominal Hist (denominator in the ratio)
    - b: Shifted Hist (numerator in the ratio)
    - field: variable field (see variables.py)
    - category: analysis category (see categories/*)
    """
    if field in VARIABLES:
        xtitle = VARIABLES[field]['root']
    else:
        xtitle = field
    plot = RatioPlot(
        xtitle=xtitle,
        ytitle='{0}Events'.format('Normalized ' if normalize else ''),
        ratio_title='A / B',
        ratio_limits=ratio_range,
        ratio_line_values=ratio_line_values,
        logy=logy)
    if normalize:
        a_integral = a.integral()
        if a_integral != 0:
            a /= a_integral
        b_integral = b.integral()
        if b_integral != 0:
            b /= b_integral
    a.title = 'A: ' + a.title
    b.title = 'B: ' + b.title
    a.color = 'black'
    b.color = 'red'
    a.legendstyle = 'L'
    b.legendstyle = 'L'
    a.markersize = 0
    b.markersize = 0
    a.linewidth = 2
    b.linewidth = 2
    a.fillstyle = 'hollow'
    b.fillstyle = 'hollow'
    a.linestyle = 'solid'
    b.linestyle = 'dashed'
    a.drawstyle = 'hist E0'
    b.drawstyle = 'hist E0'
    plot.draw('main', [a, b], ypadding=(0.3, 0.))
    ratio = Hist.divide(a, b, fill_value=-1)
    ratio.drawstyle = 'hist'
    ratio.color = 'black'
    ratio_band = Graph(ratio, fillstyle='/', fillcolor='black', linewidth=0)
    ratio_band.drawstyle = '20'
    plot.draw('ratio', [ratio_band, ratio])
    with plot.pad('main') as pad:
        # legend
        leg = Legend([a, b], 0.2, 0.2, 0.45, margin=0.35, textsize=textsize)
        leg.Draw()
        # draw the category label
        if category is not None:
            label = ROOT.TLatex(pad.GetLeftMargin() + 0.04, 0.87,
                                category.label)
            label.SetNDC()
            label.SetTextFont(43)
            label.SetTextSize(textsize)
            label.Draw()
        # show p-value and chi^2
        pvalue = a.Chi2Test(b, 'WW')
        pvalue_label = ROOT.TLatex(pad.GetLeftMargin() + 0.04, 0.8,
                                   "p-value={0:.2f}".format(pvalue))
        pvalue_label.SetNDC(True)
        pvalue_label.SetTextFont(43)
        pvalue_label.SetTextSize(textsize)
        pvalue_label.Draw()
        chi2 = a.Chi2Test(b, 'WW CHI2/NDF')
        chi2_label = ROOT.TLatex(
            pad.GetLeftMargin() + 0.04, 0.72,
            "#frac{{#chi^{{2}}}}{{ndf}}={0:.2f}".format(chi2))
        chi2_label.SetNDC(True)
        chi2_label.SetTextFont(43)
        chi2_label.SetTextSize(textsize)
        chi2_label.Draw()
        if optional_label_text is not None:
            optional_label = ROOT.TLatex(pad.GetLeftMargin() + 0.55, 0.87,
                                         optional_label_text)
            optional_label.SetNDC(True)
            optional_label.SetTextFont(43)
            optional_label.SetTextSize(textsize)
            optional_label.Draw()
        if ATLAS_LABEL.lower() == 'internal':
            x = 0.67
            y = 1 - pad.GetTopMargin() + 0.005
        else:
            x = (1. - pad.GetRightMargin() - 0.03) - len(ATLAS_LABEL) * 0.025
            y = 1 - pad.GetTopMargin() + 0.01
        ATLAS_label(x,
                    y,
                    sep=0.132,
                    pad=pad,
                    sqrts=None,
                    text=ATLAS_LABEL,
                    textsize=textsize)
    return plot
Esempio n. 4
0
def draw_ratio(a, b, field, category,
               textsize=22,
               ratio_range=(0, 2),
               ratio_line_values=[0.5, 1, 1.5],
               optional_label_text=None,
               normalize=True,
               logy=False):
    """
    Draw a canvas with two Hists normalized to unity on top
    and a ratio plot between the two hist
    Parameters:
    - a: Nominal Hist (denominator in the ratio)
    - b: Shifted Hist (numerator in the ratio)
    - field: variable field (see variables.py)
    - category: analysis category (see categories/*)
    """
    xtitle = get_xtitle(field)

    plot = RatioPlot(xtitle=xtitle,
                     ytitle='{0}Events'.format(
                         'Normalized ' if normalize else ''),
                     ratio_title='A / B',
                     ratio_limits=ratio_range,
                     ratio_line_values=ratio_line_values,
                     logy=logy)
    if normalize:
        a_integral = a.integral()
        if a_integral != 0:
            a /= a_integral
        b_integral = b.integral()
        if b_integral != 0:
            b /= b_integral
    a.title = 'A: ' + a.title
    b.title = 'B: ' + b.title
    a.color = 'black'
    b.color = 'red'
    a.legendstyle = 'L'
    b.legendstyle = 'L'
    a.markersize = 0
    b.markersize = 0
    a.linewidth = 2
    b.linewidth = 2
    a.fillstyle = 'hollow'
    b.fillstyle = 'hollow'
    a.linestyle = 'solid'
    b.linestyle = 'dashed'
    a.drawstyle='hist E0'
    b.drawstyle='hist E0'
    plot.draw('main', [a, b], ypadding=(0.3, 0.))
    ratio = Hist.divide(a, b, fill_value=-1)
    ratio.drawstyle = 'hist'
    ratio.color = 'black'
    ratio_band = Graph(ratio, fillstyle='/', fillcolor='black', linewidth=0)
    ratio_band.drawstyle = '20'
    plot.draw('ratio', [ratio_band, ratio])
    with plot.pad('main') as pad:
        # legend
        #         leg = Legend([a, b], 0.2, 0.2, 0.45,
        #                      margin=0.35, textsize=textsize)
        leg = Legend([a, b])
        leg.Draw()
        # draw the category label
        if category is not None:
            label = ROOT.TLatex(
                pad.GetLeftMargin() + 0.04, 0.87,
                category.label)
            label.SetNDC()
            label.SetTextFont(43)
            label.SetTextSize(textsize)
            label.Draw()
        # show p-value and chi^2
        if a.integral() != 0 and b.integral() != 0:
            pvalue = a.Chi2Test(b, 'WW')
            chi2 = a.Chi2Test(b, 'WW CHI2/NDF')
        else:
            pvalue = -9999.
            chi2 = -9999.
        pvalue_label = ROOT.TLatex(
            pad.GetLeftMargin() + 0.04, 0.8,
            "p-value={0:.2f}".format(pvalue))
        pvalue_label.SetNDC(True)
        pvalue_label.SetTextFont(43)
        pvalue_label.SetTextSize(textsize)
        pvalue_label.Draw()
        
        chi2_label = ROOT.TLatex(
            pad.GetLeftMargin() + 0.04, 0.72,
            "#frac{{#chi^{{2}}}}{{ndf}}={0:.2f}".format(chi2))
        chi2_label.SetNDC(True)
        chi2_label.SetTextFont(43)
        chi2_label.SetTextSize(textsize)
        chi2_label.Draw()
        if optional_label_text is not None:
            optional_label = ROOT.TLatex(pad.GetLeftMargin()+0.01, 1 - pad.GetTopMargin() + 0.005,
                                         optional_label_text )
            optional_label.SetNDC(True)
            optional_label.SetTextFont(43)
            optional_label.SetTextSize(textsize)
            optional_label.Draw()
        if ATLAS_LABEL.lower() == 'internal':
            x = 0.67
            y = 1-pad.GetTopMargin()+0.005
        else:
            x = (1. - pad.GetRightMargin() - 0.03) - len(ATLAS_LABEL) * 0.025
            y = 1-pad.GetTopMargin()+0.01
        ATLAS_label(x, y,
                    sep=0.132, pad=pad, sqrts=None,
                    text=ATLAS_LABEL,
                    textsize=textsize)
    return plot