Esempio n. 1
0
def config_hists(hists, **kw):

    #
    #  Read the congif
    #
    #title             = kw.get('title',             ROOTHelp.default)
    y_min = kw.get('min', None)
    y_max = kw.get('max', ROOTHelp.default)
    x_min = kw.get("x_min", None)
    x_max = kw.get("x_max", None)
    z_min = kw.get("z_min", None)
    z_max = kw.get("z_max", None)
    log_y = kw.get('logy', False)

    fill_colors = kw.get('fill_colors', [ROOT.kBlack, ROOT.kYellow, ROOT.kRed])
    fill_style = kw.get('fill_style', [ROOTHelp.default, ROOTHelp.default])
    line_colors = kw.get('line_colors', [ROOT.kBlack, ROOT.kBlack, ROOT.kRed])
    marker_styles = kw.get(
        'marker_styles',
        [ROOTHelp.default, ROOTHelp.default, ROOTHelp.default])
    styles = kw.get('styles', [ROOT.kSolid, ROOT.kSolid, ROOT.kSolid])
    widths = kw.get('widths',
                    [ROOTHelp.default, ROOTHelp.default, ROOTHelp.default])

    #
    #  Congigure the plots
    #
    for i, h in enumerate(hists):
        opt = dict()
        opt['line_color'] = line_colors[i]
        opt['marker_color'] = line_colors[i]
        opt['line_style'] = styles[i]
        opt['line_width'] = widths[i]
        opt['fill_color'] = fill_colors[i]
        opt['fill_style'] = fill_style[i]
        opt['marker_style'] = marker_styles[i]
        plot_options = PlotOptions(**opt)
        plot_options.configure(h)

    #
    # Find the global min/max
    #
    set_min(hists, y_min, log_y=log_y)
    set_max(hists, y_max, log_y=log_y)

    #
    # Draw
    #
    for i, h in enumerate(hists):

        if x_min or x_max:
            setXMinMax(h, x_min, x_max)

        if z_min or z_max:
            setZMinMax(h, z_min, z_max)

    return {'hists': hists}
Esempio n. 2
0
def stack_no_data(mc, name, **kw):

    #
    # defaults
    #
    title = kw.get('title', ROOTHelp.default)
    ymin = kw.get('min', None)
    ymax = kw.get('max', ROOTHelp.default)
    plot_options = kw.get('plot_options', None)
    canvas_options = kw.get('canvas_options', ROOTHelp.default)
    draw_options = kw.get('draw_options', 'hist')
    show_stats = kw.get('show_stats', False)
    max_factor = kw.get('max_factor', None)
    x_min = kw.get("x_min", None)
    x_max = kw.get("x_max", None)

    plot = stack_hists(
        hists=mc,
        name=name,
        title=title,
        min=None,
        max=None,
        plot_options=plot_options,
        canvas_options=canvas_options,
        draw_options=draw_options,
        show_stats=show_stats,
        x_min=x_min,
        x_max=x_max,
    )

    # make the stack sum
    stacksum = mc[0].Clone("tmp")
    stacksum.Reset()
    for h in mc:
        stacksum.Add(h)

    # make stack plot
    stack = plot['stack']

    # set min/max
    if canvas_options.log_y:
        for b in range(1, stacksum.GetNbinsX() + 1):
            if stacksum.GetBinContent(b) > 0.0:
                if ymin == None:
                    ymin = 1e10
                ymin = ymin  #(ymin,0.1*stacksum.GetBinContent(b))

    set_min([stack, stacksum], ymin, log_y=canvas_options.log_y)
    set_max([stack, stacksum], ymax, log_y=canvas_options.log_y)

    plot['canvas'].Update()
    plot['sum'] = stacksum
    return plot
Esempio n. 3
0
def stack_with_data_and_ratio(data, mc, name, **kw):
    canvas_options = kw.get('canvas_options', ROOTHelp.default)

    x_title = data.GetXaxis().GetTitle()

    #
    # make stack
    #
    stack = stack_with_data(data, mc, name, **kw)

    #
    # make ratio
    #
    data = stack['data']
    ratio = data.Clone(data.GetName() + "_ratio")
    ratio.Divide(stack['sum'])
    ratio_plot_options = PlotOptions()
    ratio_plot_options.configure(ratio)
    ratio.GetYaxis().SetTitle("Data/MC")
    ratio.GetXaxis().SetTitle(x_title)
    ratio.GetYaxis().SetNdivisions(507)

    #    set_min_max_ratio([ratio],2.0)
    rMin = kw.get("rMin", ROOTHelp.default)
    rMax = kw.get("rMax", ROOTHelp.default)
    set_min([ratio], rMin, log_y=canvas_options.log_y)
    set_max([ratio], rMax, log_y=canvas_options.log_y)
    stack['ratio'] = ratio

    x_min = kw.get("x_min", None)
    x_max = kw.get("x_max", None)

    # draw ratio

    canvas_options.log_y = False
    ratio_canvas = canvas_options.create(name + "_ratio")

    if x_min or x_max:
        setXMinMax(ratio, x_min, x_max)

    ratio.Draw("PE")
    line = ROOT.TLine()
    a = ratio.GetXaxis()
    if x_min or x_max:
        x_min, x_max = getXMinMax(ratio, x_min, x_max)
        line.DrawLine(x_min, 1.0, x_max, 1.0)
    else:
        line.DrawLine(a.GetXmin(), 1.0, a.GetXmax(), 1.0)

    shared = plot_shared_axis(stack['canvas'],
                              ratio_canvas,
                              name + "_with_ratio",
                              split=0.3,
                              axissep=0.04,
                              ndivs=[505, 503])
    #stack['top_canvas']=stack['canvas']
    #stack['bottom_canvas']=ratio_canvas
    stack['top_pad'] = shared['top_pad']
    stack['bottom_pad'] = shared['bottom_pad']
    stack['canvas'] = shared['canvas']

    return stack
Esempio n. 4
0
def stack_with_data(data, mc, name, **kw):

    #
    # defaults
    #
    title = kw.get('title', ROOTHelp.default)
    ymin = kw.get('min', None)
    ymax = kw.get('max', ROOTHelp.default)
    plot_options = kw.get('plot_options', None)
    canvas_options = kw.get('canvas_options', ROOTHelp.default)
    draw_options = kw.get('draw_options', 'hist')
    show_stats = kw.get('show_stats', False)
    max_factor = kw.get('max_factor', None)
    data_plot_options = kw.get('data_plot_options', None)
    x_min = kw.get("x_min", None)
    x_max = kw.get("x_max", None)

    plot = stack_hists(
        hists=mc,
        name=name,
        title=title,
        min=None,
        max=None,
        plot_options=plot_options,
        canvas_options=canvas_options,
        draw_options=draw_options,
        show_stats=show_stats,
        x_min=x_min,
        x_max=x_max,
    )

    # make the stack sum
    stacksum = mc[0].Clone("tmp")
    stacksum.Reset()
    for h in mc:
        stacksum.Add(h)

    # make stack plot
    stack = plot['stack']

    # set min/max
    if canvas_options.log_y:
        for b in range(1, data.GetNbinsX() + 1):
            if data.GetBinContent(b) > 0.0:
                if ymin == None:
                    ymin = 1e10
                ymin = min(ymin, 0.1 * data.GetBinContent(b))

    set_min([data, stack, stacksum], ymin, log_y=canvas_options.log_y)
    set_max([data, stack, stacksum], ymax, log_y=canvas_options.log_y)

    # draw data
    if data_plot_options:
        data_plot_options.configure(data)
    # data.GetXaxis().SetTitle("")
    # data.GetYaxis().SetTitle("")
    data.Draw('PE same')

    plot['canvas'].Update()
    plot['data'] = data
    plot['sum'] = stacksum
    return plot