Ejemplo n.º 1
0
def test_atlas():

    style = get_style('ATLAS')
    with style:
        hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution")
        ROOT.gRandom.SetSeed()
        for i in xrange(1000):
            hpx.Fill(ROOT.gRandom.Gaus())
        hpx.GetXaxis().SetTitle("random variable [unit]")
        hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]")
        hpx.SetMaximum(80.)
        hpx.Draw()
        ATLAS_label(.4, .8)
Ejemplo n.º 2
0
def category_lumi_atlas(pad,
                        category_label=None,
                        data_info=None,
                        atlas_label=None,
                        textsize=22):

    left, right, bottom, top = pad.margin_pixels
    height = float(pad.height_pixels)

    # draw the category label
    if category_label:
        label = ROOT.TLatex(1. - pad.GetRightMargin(),
                            1. - (textsize - 2) / height, category_label)
        label.SetNDC()
        label.SetTextFont(43)
        label.SetTextSize(textsize)
        label.SetTextAlign(31)
        with pad:
            label.Draw()
        keepalive(pad, label)

    # draw the luminosity label
    if data_info is not None:
        plabel = ROOT.TLatex(1. - pad.GetRightMargin() - 0.03,
                             1. - (top + textsize + 15) / height,
                             str(data_info))
        plabel.SetNDC()
        plabel.SetTextFont(43)
        plabel.SetTextSize(textsize)
        plabel.SetTextAlign(31)
        with pad:
            plabel.Draw()
        keepalive(pad, plabel)

    # draw the ATLAS label
    if atlas_label is not False:
        label = atlas_label or ATLAS_LABEL
        ATLAS_label(pad.GetLeftMargin() + 0.03,
                    1. - (top + textsize + 15) / height,
                    sep=0.132,
                    pad=pad,
                    sqrts=None,
                    text=label,
                    textsize=textsize)
    pad.Update()
    pad.Modified()
Ejemplo 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
Ejemplo n.º 4
0
def draw_shape(a,
               b,
               field,
               category,
               textsize=22,
               optional_label_text=None,
               normalize=True,
               logy=False):
    """
    Draw a canvas with two Hists normalized to unity
    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 = SimplePlot(
        xtitle=xtitle,
        ytitle='{0}Events'.format('Normalized ' if normalize else ''),
        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.))
    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
        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
Ejemplo n.º 5
0
    return pad, graphs


if __name__ == '__main__':
    from rootpy.plotting import Canvas, Legend, get_style
    from rootpy.plotting.style.atlas.labels import ATLAS_label

    mass_points = [100, 105, 120, 125, 130, 135, 140, 145, 150]
    pvalues = [
        [0.5, 0.25, 0.15, 0.05, 0.03, 0.01, 0.03, 0.05, 0.15, 0.25, 0.5],
        [0.4, 0.3, 0.17, 0.02, 0.01, 0.008, 0.08, 0.06, 0.14, 0.2, 0.2],
    ]
    names = ['A', 'B']
    style = get_style('ATLAS', shape='rect')
    # allow space for sigma labels on right
    style.SetPadRightMargin(0.05)
    with style:
        c = Canvas()
        _, graphs = pvalue_plot(mass_points,
                                pvalues,
                                pad=c,
                                xtitle='m_{H} [GeV]',
                                linestyle=['dashed', 'solid'])
        for name, graph in zip(names, graphs):
            graph.title = name
            graph.legendstyle = 'L'
        leg = Legend(graphs, leftmargin=0.4, topmargin=0.2)
        leg.Draw()
        ATLAS_label(0.57, 0.88, text="Internal 2012", sqrts=8, pad=c, sep=0.09)
        c.SaveAs('pvalue_plot.png')