Ejemplo n.º 1
0
def compare_flavour_fraction_hists_vs_pt_from_contribs(
        contribs,
        flav,
        output_filename,
        title="",
        xtitle="p_{T}^{jet} [GeV]",
        **plot_kwargs):
    """Plot a specified flavour fraction vs pT for several sources.

    TODO: use this one more often - compare_flavour_fractions_vs_pt() is almost identical but has to deal with npartons
    """
    flav_str = FLAV_STR_DICT[flav]
    ytitle = "Fraction of %s %ss" % (flav_str.lower(), get_jet_str(''))
    p = Plot(contribs,
             what='graph',
             xtitle=xtitle,
             ytitle=ytitle,
             title=title,
             xlim=(50, 2000),
             ylim=(0, 1),
             has_data=False,
             **plot_kwargs)
    p.default_canvas_size = (600, 600)
    try:
        p.plot("AP")
        p.main_pad.SetBottomMargin(0.16)
        p.get_modifier().GetXaxis().SetTitleOffset(1.4)
        p.get_modifier().GetXaxis().SetTitleSize(.045)
        p.legend.SetX1(0.56)
        p.legend.SetY1(0.65)
        p.legend.SetY2(0.87)
        if len(contribs) >= 4:
            p.legend.SetY1(0.7)
            p.legend.SetX1(0.5)
            p.legend.SetNColumns(2)
        p.set_logx(do_more_labels=True, do_exponent=False)
        p.save(output_filename)
    except ZeroContributions:
        warnings.warn("No contributions for %s" % output_filename)
Ejemplo n.º 2
0
def do_flavour_fraction_vs_eta(input_file,
                               dirname,
                               eta_bins,
                               output_filename,
                               title="",
                               var_prepend="",
                               which_jet="both",
                               append=""):
    """Plot all flavour fractions vs eta for one input file & dirname in the ROOT file"""
    info = get_flavour_efficiencies(
        input_file,
        bins=eta_bins,
        hist_name=get_flavour_hist_name(
            dirname=dirname,
            var_prepend=var_prepend,
            which_jet="both",  # since no jet/jet1/jet2 in hist name
            metric='eta' + append))

    leg_draw_opt = "LP"
    plot_u = Contribution(info['u'].CreateGraph(),
                          label="Up",
                          line_color=ROOT.kRed,
                          marker_color=ROOT.kRed,
                          marker_style=20,
                          leg_draw_opt=leg_draw_opt)
    plot_d = Contribution(info['d'].CreateGraph(),
                          label="Down",
                          line_color=ROOT.kBlue,
                          marker_color=ROOT.kBlue,
                          marker_style=21,
                          leg_draw_opt=leg_draw_opt)
    plot_s = Contribution(info['s'].CreateGraph(),
                          label="Strange",
                          line_color=ROOT.kBlack,
                          marker_color=ROOT.kBlack,
                          marker_style=22,
                          leg_draw_opt=leg_draw_opt)
    plot_c = Contribution(info['c'].CreateGraph(),
                          label="Charm",
                          line_color=ROOT.kGreen + 2,
                          marker_color=ROOT.kGreen + 2,
                          marker_style=23,
                          leg_draw_opt=leg_draw_opt)
    plot_b = Contribution(info['b'].CreateGraph(),
                          label="Bottom",
                          line_color=ROOT.kOrange - 3,
                          marker_color=ROOT.kOrange - 3,
                          marker_style=33,
                          leg_draw_opt=leg_draw_opt)
    plot_g = Contribution(info['g'].CreateGraph(),
                          label="Gluon",
                          line_color=ROOT.kViolet,
                          marker_color=ROOT.kViolet,
                          marker_style=29,
                          leg_draw_opt=leg_draw_opt)
    plot_unknown = Contribution(info['unknown'].CreateGraph(),
                                label="Unknown",
                                line_color=ROOT.kGray + 1,
                                marker_color=ROOT.kGray + 1,
                                marker_style=26,
                                leg_draw_opt=leg_draw_opt)

    p_flav = Plot(
        [plot_d, plot_u, plot_s, plot_c, plot_b, plot_g, plot_unknown],
        what='graph',
        xtitle="y^{%s}" % get_jet_str(''),
        ytitle="Fraction",
        title=title,
        xlim=(eta_bins[0][0], eta_bins[-1][1]),
        ylim=[0, 1],
        has_data=False)
    p_flav.default_canvas_size = (600, 600)
    p_flav.plot("AP")
    p_flav.main_pad.SetBottomMargin(0.16)
    p_flav.get_modifier().GetXaxis().SetTitleOffset(1.4)
    p_flav.get_modifier().GetXaxis().SetTitleSize(.045)
    p_flav.legend.SetX1(0.55)
    p_flav.legend.SetY1(0.72)
    p_flav.legend.SetY2(0.85)
    p_flav.legend.SetNColumns(2)
    p_flav.save(output_filename)
Ejemplo n.º 3
0
def do_flavour_fraction_vs_pt(input_file,
                              hist_name,
                              pt_bins,
                              output_filename,
                              title=""):
    """Plot all flavour fractions vs PT for one input file & hist_name in the ROOT file"""
    info = get_flavour_efficiencies(input_file,
                                    bins=pt_bins,
                                    hist_name=hist_name)

    leg_draw_opt = "LP"
    plot_u = Contribution(info['u'].CreateGraph(),
                          label="Up",
                          line_color=ROOT.kRed,
                          marker_color=ROOT.kRed,
                          marker_style=20,
                          leg_draw_opt=leg_draw_opt)
    plot_d = Contribution(info['d'].CreateGraph(),
                          label="Down",
                          line_color=ROOT.kBlue,
                          marker_color=ROOT.kBlue,
                          marker_style=21,
                          leg_draw_opt=leg_draw_opt)
    plot_s = Contribution(info['s'].CreateGraph(),
                          label="Strange",
                          line_color=ROOT.kBlack,
                          marker_color=ROOT.kBlack,
                          marker_style=22,
                          leg_draw_opt=leg_draw_opt)
    plot_c = Contribution(info['c'].CreateGraph(),
                          label="Charm",
                          line_color=ROOT.kGreen + 2,
                          marker_color=ROOT.kGreen + 2,
                          marker_style=23,
                          leg_draw_opt=leg_draw_opt)
    plot_b = Contribution(info['b'].CreateGraph(),
                          label="Bottom",
                          line_color=ROOT.kOrange - 3,
                          marker_color=ROOT.kOrange - 3,
                          marker_style=33,
                          leg_draw_opt=leg_draw_opt)
    plot_g = Contribution(info['g'].CreateGraph(),
                          label="Gluon",
                          line_color=ROOT.kViolet,
                          marker_color=ROOT.kViolet,
                          marker_style=29,
                          leg_draw_opt=leg_draw_opt)
    plot_unknown = Contribution(info['unknown'].CreateGraph(),
                                label="Unknown",
                                line_color=ROOT.kGray + 1,
                                marker_color=ROOT.kGray + 1,
                                marker_style=26,
                                leg_draw_opt=leg_draw_opt)

    p_flav = Plot(
        [plot_d, plot_u, plot_s, plot_c, plot_b, plot_g, plot_unknown],
        what='graph',
        xtitle="p_{T}^{%s} [GeV]" % get_jet_str(''),
        ytitle="Fraction",
        title=title,
        xlim=(pt_bins[0][0], pt_bins[-1][1]),
        ylim=[0, 1],
        has_data=False)
    p_flav.default_canvas_size = (600, 600)
    p_flav.plot("AP")
    p_flav.main_pad.SetBottomMargin(0.16)
    p_flav.get_modifier().GetXaxis().SetTitleOffset(1.4)
    p_flav.get_modifier().GetXaxis().SetTitleSize(.045)
    p_flav.set_logx(do_more_labels=True, do_exponent=False)
    p_flav.legend.SetX1(0.55)
    p_flav.legend.SetY1(0.72)
    p_flav.legend.SetY2(0.85)
    p_flav.legend.SetNColumns(2)
    p_flav.save(output_filename)
Ejemplo n.º 4
0
def compare_flavour_fraction_hists_vs_pt(input_files,
                                         hist_names,
                                         pt_bins,
                                         labels,
                                         flav,
                                         output_filename,
                                         title="",
                                         xtitle="p_{T}^{jet} [GeV]",
                                         is_preliminary=True):
    """Plot a specified flavour fraction vs pT for several sources.
    Each entry in input_files, dirnames, and labels corresponds to one line
    n_partons can be a str, 'all', '1', etc, or a list of str to include

    TODO: use this one more often - compare_flavour_fractions_vs_pt() is almost identical but has to deal with npartons
    """
    bin_centers = [0.5 * (x[0] + x[1]) for x in pt_bins]
    bin_widths = [0.5 * (x[1] - x[0]) for x in pt_bins]

    contribs = []
    info = [
        get_flavour_efficiencies(ifile, bins=pt_bins, hist_name=hname)
        for ifile, hname in zip(input_files, hist_names)
    ]
    N = len(bin_centers)

    colours = [ROOT.kBlack, ROOT.kBlue, ROOT.kRed, ROOT.kGreen + 2]

    for i, fdict in enumerate(info):
        if flav in ['u', 'd', 's', 'c', 'b', 't', 'g']:
            obj = fdict[flav].CreateGraph()
        else:
            raise RuntimeError("Robin broke 1-X functionality")
            obj = ROOT.TGraphErrors(
                N, np.array(bin_centers),
                1. - np.array(fdict[flav.replace("1-", '')]),
                np.array(bin_widths), np.zeros(N))
        if obj.GetN() == 0:
            continue
        c = Contribution(obj,
                         label=labels[i],
                         line_color=colours[i],
                         line_width=1,
                         line_style=1,
                         marker_style=20 + i,
                         marker_color=colours[i],
                         marker_size=1,
                         leg_draw_opt="LP")
        contribs.append(c)

    flav_str = FLAV_STR_DICT[flav]
    ytitle = "Fraction of %s %ss" % (flav_str.lower(), get_jet_str(''))
    p = Plot(contribs,
             what='graph',
             xtitle=xtitle,
             ytitle=ytitle,
             title=title,
             xlim=(50, 2000),
             ylim=(0, 1),
             has_data=False,
             is_preliminary=is_preliminary)
    p.default_canvas_size = (600, 600)
    try:
        p.plot("AP")
        p.main_pad.SetBottomMargin(0.16)
        p.get_modifier().GetXaxis().SetTitleOffset(1.4)
        p.get_modifier().GetXaxis().SetTitleSize(.045)
        p.legend.SetX1(0.56)
        p.legend.SetY1(0.65)
        p.legend.SetY2(0.87)
        p.set_logx(do_more_labels=True, do_exponent=False)
        p.save(output_filename)
    except ZeroContributions:
        pass
Ejemplo n.º 5
0
def compare_flavour_fractions_vs_pt(input_files,
                                    dirnames,
                                    pt_bins,
                                    labels,
                                    flav,
                                    output_filename,
                                    title="",
                                    var_prepend="",
                                    which_jet="both",
                                    xtitle="p_{T}^{jet} [GeV]",
                                    n_partons='all',
                                    is_preliminary=True):
    """Plot a specified flavour fraction vs pT for several sources.
    Each entry in input_files, dirnames, and labels corresponds to one line
    n_partons can be a str, 'all', '1', etc, or a list of str to include

    TODO: fix this - bit stupid input format
    """
    bin_centers = [0.5 * (x[0] + x[1]) for x in pt_bins]
    bin_widths = [0.5 * (x[1] - x[0]) for x in pt_bins]

    if isinstance(n_partons, str):
        n_partons = [n_partons]

    contribs = []
    for n_parton_ind, n_parton in enumerate(n_partons):
        metric = 'pt'
        if n_parton.lower() != 'all':
            metric = 'pt_npartons_%s' % n_parton
        info = [
            get_flavour_efficiencies(
                ifile,
                bins=pt_bins,
                hist_name=get_flavour_hist_name(
                    dirname=dname,
                    var_prepend=var_prepend,
                    which_jet=(which_jet if "Dijet" in dname else "both"),
                    metric=metric))
            for ifile, dname in zip(input_files, dirnames)
        ]
        N = len(bin_centers)

        colours = [ROOT.kBlack, ROOT.kBlue, ROOT.kRed, ROOT.kGreen + 2]

        for i, fdict in enumerate(info):
            if flav in ['u', 'd', 's', 'c', 'b', 't', 'g']:
                obj = fdict[flav].CreateGraph()
            else:
                raise RuntimeError("Robin broke 1-X functionality")
                obj = ROOT.TGraphErrors(
                    N, np.array(bin_centers),
                    1. - np.array(fdict[flav.replace("1-", '')]),
                    np.array(bin_widths), np.zeros(N))
            if obj.GetN() == 0:
                continue
            n_parton_str = "" if n_parton == "all" else " (%s-parton)" % n_parton
            c = Contribution(obj,
                             label="%s%s" % (labels[i], n_parton_str),
                             line_color=colours[i] + n_parton_ind,
                             line_width=1,
                             line_style=n_parton_ind + 1,
                             marker_style=20 + i,
                             marker_color=colours[i] + n_parton_ind,
                             marker_size=1,
                             leg_draw_opt="LP")
            contribs.append(c)

    flav_str = FLAV_STR_DICT[flav]
    ytitle = "Fraction of %s %ss" % (flav_str.lower(), get_jet_str(''))
    p = Plot(contribs,
             what='graph',
             xtitle=xtitle,
             ytitle=ytitle,
             title=title,
             xlim=(pt_bins[0][0], pt_bins[-1][1]),
             ylim=(0, 1),
             has_data=False,
             is_preliminary=is_preliminary)
    p.default_canvas_size = (600, 600)
    try:
        p.plot("AP")
        p.main_pad.SetBottomMargin(0.16)
        p.get_modifier().GetXaxis().SetTitleOffset(1.4)
        p.get_modifier().GetXaxis().SetTitleSize(.045)
        p.legend.SetX1(0.56)
        p.legend.SetY1(0.65)
        p.legend.SetY2(0.87)
        p.set_logx(do_more_labels=True, do_exponent=False)
        p.save(output_filename)
    except ZeroContributions:
        pass