Ejemplo n.º 1
0
def do_mc_pt_comparison_plot(dirname_label_pairs, output_filename,
                             qcd_filename, **plot_kwargs):
    # qcd_files = [cu.open_root_file(os.path.join(dl[0], qgc.QCD_FILENAME)) for dl in dirname_label_pairs]
    qcd_files = [
        cu.open_root_file(os.path.join(dl[0], qgc.QCD_PYTHIA_ONLY_FILENAME))
        for dl in dirname_label_pairs
    ]
    histname = "Dijet_tighter/pt_jet1"
    qcd_hists = [cu.get_from_tfile(qf, histname) for qf in qcd_files]
    N = len(dirname_label_pairs)
    conts = [
        Contribution(qcd_hists[i],
                     label=lab,
                     marker_color=cu.get_colour_seq(i, N),
                     line_color=cu.get_colour_seq(i, N),
                     line_style=(i % 3) + 1,
                     line_width=2,
                     rebin_hist=1,
                     subplot=qcd_hists[0] if i != 0 else None)
        for i, (d, lab) in enumerate(dirname_label_pairs)
    ]
    plot = Plot(conts,
                what='hist',
                ytitle="N",
                subplot_limits=(0.5, 1.5),
                subplot_type="ratio",
                subplot_title="* / %s" % (dirname_label_pairs[0][1]),
                **plot_kwargs)
    plot.y_padding_max_log = 500
    plot.legend.SetY1(0.7)
    plot.plot("NOSTACK HIST E")
    plot.set_logx(do_more_labels=False)
    plot.set_logy(do_more_labels=False)

    plot.save(output_filename)
def do_jet_pt_rel_error_with_var_cuts(histname, cuts, input_filename, output_filename):
    ROOT.gStyle.SetPalette(palette_1D)
    tf = cu.open_root_file(input_filename)
    h3d = cu.get_from_tfile(tf, histname)
    if h3d.GetEntries() == 0:
        return
    pt_hists = []
    for cut in cuts:
        max_bin = h3d.GetZaxis().FindFixBin(cut)
        # print("cut:", cut, "bin:", max_bin)
        h = h3d.ProjectionY("pt_var_lt_%g" % cut, 0, -1, 0, max_bin, "e")
        h2 = h.Clone()
        h2.Rebin(2)
        if h.GetEntries() > 0:
            h3 = qgp.hist_divide_bin_width(h2)
        # convert bin contents to bin error/bin contents
        for ibin in range(1, h2.GetNbinsX()+1):
            if h3.GetBinContent(ibin) == 0:
                continue
            h3.SetBinContent(ibin, h3.GetBinError(ibin) / h3.GetBinContent(ibin))
            h3.SetBinError(ibin, 0)
        pt_hists.append(h3)

    line_styles = [1, 2, 3]
    n_line_styles = len(line_styles)
    conts = [Contribution(h, label=" < %g" % cut,
                          line_color=cu.get_colour_seq(ind, len(cuts)),
                          line_style=line_styles[ind % n_line_styles],
                          line_width=2,
                          marker_color=cu.get_colour_seq(ind, len(cuts)),
                          subplot=pt_hists[-1])
             for ind, (h, cut) in enumerate(zip(pt_hists, cuts))]

    jet_str = pt_genjet_str if "_vs_pt_genjet_vs_" in histname else pt_str
    weight_str = "(unweighted)" if "unweighted" in histname else "(weighted)"
    ratio_lims = (0.98, 1.02) if "unweighted" in histname else None
    plot = Plot(conts, what='hist',
                title='%s for cuts on %s %s' % (jet_str, get_var_str(histname), weight_str),
                xtitle=None,
                ytitle='Relative error',
                # xlim=None, ylim=None,
                legend=True,
                subplot_type='ratio',
                subplot_title='* / var < %g' % cuts[-1],
                subplot_limits=ratio_lims,
                has_data=False)
    plot.y_padding_max_log = 200
    plot.subplot_maximum_ceil = 2
    plot.subplot_maximum_floor = 1.02
    plot.subplot_minimum_ceil = 0.98
    plot.legend.SetY1(0.7)
    plot.legend.SetY2(0.89)
    plot.legend.SetX1(0.78)
    plot.legend.SetX2(0.88)
    plot.plot("NOSTACK HISTE", "NOSTACK HIST")
    plot.set_logx(True, do_more_labels=True)
    plot.set_logy(True, do_more_labels=False)
    plot.save(output_filename)
Ejemplo n.º 3
0
def do_pthat_comparison_plot(dirname_label_pairs, output_filename,
                             **plot_kwargs):
    qcd_files = [
        cu.open_root_file(os.path.join(dl[0], qgc.QCD_PYTHIA_ONLY_FILENAME))
        for dl in dirname_label_pairs
    ]
    histname = "Dijet_gen/ptHat"
    qcd_hists = [cu.get_from_tfile(qf, histname) for qf in qcd_files]
    N = len(dirname_label_pairs)
    pthat_rebin = array('d', [
        15, 30, 50, 80, 120, 170, 300, 470, 600, 800, 1000, 1400, 1800, 2400,
        3200, 5000
    ])
    nbins = len(pthat_rebin) - 1
    qcd_hists = [
        h.Rebin(nbins, cu.get_unique_str(), pthat_rebin) for h in qcd_hists
    ]
    conts = [
        Contribution(qcd_hists[i],
                     label=lab,
                     marker_color=cu.get_colour_seq(i, N),
                     line_color=cu.get_colour_seq(i, N),
                     line_style=i + 1,
                     line_width=2,
                     subplot=qcd_hists[0] if i != 0 else None)
        for i, (d, lab) in enumerate(dirname_label_pairs)
    ]
    plot = Plot(conts,
                what='hist',
                ytitle="N",
                subplot_limits=(0.75, 1.25),
                subplot_type="ratio",
                subplot_title="* / %s" % (dirname_label_pairs[0][1]),
                **plot_kwargs)
    plot.y_padding_max_log = 500
    plot.legend.SetY1(0.7)
    plot.plot("NOSTACK HIST E")
    plot.set_logx(do_more_labels=False)
    plot.set_logy(do_more_labels=False)

    plot.save(output_filename)
Ejemplo n.º 4
0
def do_genht_comparison_plot(dirname_label_pairs, output_filename,
                             **plot_kwargs):
    """Like do_genht but for multiple samples"""
    qcd_files = [
        cu.open_root_file(os.path.join(dl[0], qgc.QCD_FILENAME))
        for dl in dirname_label_pairs
    ]
    histname = "Dijet_gen/gen_ht"
    qcd_hists = [cu.get_from_tfile(qf, histname) for qf in qcd_files]
    N = len(dirname_label_pairs)
    conts = [
        Contribution(qcd_hists[i],
                     label=lab,
                     marker_color=cu.get_colour_seq(i, N),
                     line_color=cu.get_colour_seq(i, N),
                     line_style=i + 1,
                     line_width=2,
                     subplot=qcd_hists[0] if i != 0 else None)
        for i, (d, lab) in enumerate(dirname_label_pairs)
    ]
    plot = Plot(
        conts,
        what='hist',
        ytitle="N",
        # subplot_limits=(0.75, 1.25),
        subplot_type="ratio",
        subplot_title="* / %s" % (dirname_label_pairs[0][1]),
        ylim=[1E6, None],
        **plot_kwargs)
    plot.y_padding_max_log = 500
    plot.legend.SetY1(0.7)
    plot.subplot_maximum_ceil = 5
    plot.plot("NOSTACK HIST E")
    plot.set_logx(do_more_labels=False)
    plot.set_logy(do_more_labels=False)

    plot.save(output_filename)
def do_jet_pt_with_var_cuts(histname, cuts, input_filename, output_filename):
    ROOT.gStyle.SetPalette(palette_1D)
    total = len(cuts) - 1 + .1 # slight offset to not hit the maximum or minimum
    # if len(cuts) <= 3:
        # ROOT.gStyle.SetPalette(ROOT.kCool)
        # num_colours = ROOT.TColor.GetPalette().fN - 1
        # print('num_colours:', num_colours)
        # for index in range(len(cuts)):
        #     print(num_colours, index, len(cuts), index / len(cuts), num_colours * index / total)
        #     print(index, ROOT.TColor.GetColorPalette(int(num_colours * 1. * index / total)))
    tf = cu.open_root_file(input_filename)
    h3d = cu.get_from_tfile(tf, histname)
    if h3d.GetEntries() == 0:
        return
    pt_hists = []
    for cut in cuts:
        max_bin = h3d.GetZaxis().FindFixBin(cut)
        # print("cut:", cut, "bin:", max_bin)
        h = h3d.ProjectionY("pt_var_lt_%g" % cut, 0, -1, 0, max_bin, "e")
        h2 = h.Clone()
        h2.Rebin(2)
        if h.GetEntries() > 0:
            h3 = qgp.hist_divide_bin_width(h2)
        pt_hists.append(h3)

    line_styles = [1, 2, 3]
    if len(cuts) <= 3:
        line_styles = [1]
    n_line_styles = len(line_styles)
    ref_ind = 0
    conts = [Contribution(h, label=" < %g" % cut,
                          line_color=cu.get_colour_seq(ind, total),
                          line_style=line_styles[ind % n_line_styles],
                          line_width=2,
                          marker_color=cu.get_colour_seq(ind, total),
                          subplot=pt_hists[ref_ind] if ind != ref_ind else None)
             for ind, (h, cut) in enumerate(zip(pt_hists, cuts))]

    jet_str = pt_genjet_str if "_vs_pt_genjet_vs_" in histname else pt_str
    weight_str = "(unweighted)" if "unweighted" in histname else "(weighted)"
    ratio_lims = (0.5, 2.5)
    ratio_lims = (0.5, 1.1)
    plot = Plot(conts, what='hist',
                title='%s for cuts on %s %s' % (jet_str, get_var_str(histname), weight_str),
                xtitle=None,
                ytitle='N',
                # xlim=None, ylim=None,
                legend=True,
                subplot_type='ratio',
                subplot_title='* / var < %g' % cuts[ref_ind],
                subplot_limits=ratio_lims,
                has_data=False)
    plot.y_padding_max_log = 200
    plot.subplot_maximum_ceil = 4
    plot.subplot_maximum_floor = 1.02
    plot.subplot_minimum_ceil = 0.98
    plot.legend.SetY1(0.7)
    plot.legend.SetY2(0.89)
    plot.legend.SetX1(0.78)
    plot.legend.SetX2(0.88)
    plot.plot("NOSTACK HISTE", "NOSTACK HIST")
    plot.set_logx(True, do_more_labels=True)
    plot.set_logy(True, do_more_labels=False)
    plot.save(output_filename)
def do_comparison_plots(workdir_label_pairs, output_dir):
    dirnames = [w[0] for w in workdir_label_pairs]

    # templates, we'll change the filename/dir as per instance
    total_len = len(workdir_label_pairs)
    mark = cu.Marker()
    sources = [{
        "root_dir": wd,
        'label': label,
        "style": {
            'line_style': 1,
            'line_color': cu.get_colour_seq(ind, total_len),
            'marker_color': cu.get_colour_seq(ind, total_len),
            'marker_style': m,
            'marker_size': 0.75,
        }
    } for ind, ((wd, label), m) in enumerate(
        zip(workdir_label_pairs, mark.cycle(cycle_filling=True)))]
    # print(sources)

    # COMPARE NOMINAL QCD
    if exists_in_all(qgc.QCD_FILENAME, dirnames):
        # qgp.do_all_exclusive_plots_comparison(sources,
        #                                       var_list=qgc.COMMON_VARS,
        #                                       pt_bins=qgc.PT_BINS,
        #                                       qcd_filename=qgc.QCD_FILENAME,
        #                                       dj_cen_dirname="Dijet_QG_central_tighter",
        #                                       dj_fwd_dirname=None,
        #                                       zpj_dirname=None,
        #                                       plot_dir=os.path.join(output_dir, "plots_qcd_compare_dijet_central"),
        #                                       subplot_type="ratio", # will use the 1st entry by default
        #                                       subplot_title="* / %s" % (sources[0]['label']),
        #                                       do_flav_tagged=False,
        #                                       has_data=False)

        # qgp.do_all_exclusive_plots_comparison(sources,
        #                                       var_list=qgc.COMMON_VARS,
        #                                       pt_bins=qgc.PT_BINS,
        #                                       qcd_filename=qgc.QCD_FILENAME,
        #                                       dj_cen_dirname=None,
        #                                       dj_fwd_dirname="Dijet_QG_forward_tighter",
        #                                       zpj_dirname=None,
        #                                       plot_dir=os.path.join(output_dir, "plots_qcd_compare_dijet_forward"),
        #                                       subplot_type="ratio", # will use the 1st entry by default
        #                                       subplot_title="* / %s" % (sources[0]['label']),
        #                                       do_flav_tagged=False,
        #                                       has_data=False)

        # do both dijet jets together
        # add gen level
        gen_qcd_sources = [deepcopy(sources[0])]  # only 1st one for now
        for gd in gen_qcd_sources:
            gd.update({
                'dj_fwd_dirname': 'Dijet_QG_gen',
                'label': gd['label'] + ' [Gen]'
            })
            style_dict = gd['style']
            style_dict.update({'line_style': 2})
            style_dict.update({'line_color': style_dict['line_color'] + 5})
            style_dict.update({'marker_color': style_dict['marker_color'] + 5})
            style_dict.update({'marker_style': style_dict['marker_style'] + 1})

        qgp.do_all_exclusive_plots_comparison(
            sources + gen_qcd_sources,
            var_list=qgc.COMMON_VARS,
            pt_bins=qgc.PT_BINS,
            qcd_filename=qgc.QCD_FILENAME,
            dj_cen_dirname=None,
            dj_fwd_dirname="Dijet_QG_tighter",
            zpj_dirname=None,
            plot_dir=os.path.join(output_dir, "plots_qcd_compare_dijet"),
            subplot_type="ratio",  # will use the 1st entry by default
            subplot_title="* / %s" % (sources[0]['label']),
            do_flav_tagged=False,
            has_data=False,
            title=qgc.Dijet_LABEL,
            show_region_labels=False)

    # COMPARE NOMINAL DY
    if exists_in_all(qgc.DY_FILENAME, dirnames):
        qgp.do_all_exclusive_plots_comparison(
            sources,
            var_list=qgc.COMMON_VARS,
            pt_bins=qgc.PT_BINS,
            qcd_filename=qgc.DY_FILENAME,
            dj_cen_dirname=None,
            dj_fwd_dirname=None,
            zpj_dirname="ZPlusJets_QG",
            plot_dir=os.path.join(output_dir, "plots_dy_compare"),
            subplot_type="ratio",  # will use the 1st entry by default
            subplot_title="* / %s" % (sources[0]['label']),
            do_flav_tagged=False,
            has_data=False,
            title=qgc.ZpJ_LABEL,
            show_region_labels=False)

    # COMPARE JETHT+ZEROBIAS
    if exists_in_all(qgc.JETHT_ZB_FILENAME, dirnames):
        qgp.do_all_exclusive_plots_comparison(
            sources,
            var_list=qgc.COMMON_VARS,
            pt_bins=qgc.PT_BINS,
            qcd_filename=qgc.JETHT_ZB_FILENAME,
            dj_cen_dirname="Dijet_QG_central_tighter",
            dj_fwd_dirname=None,
            zpj_dirname=None,
            plot_dir=os.path.join(output_dir,
                                  "plots_jetht_zb_compare_dijet_central"),
            subplot_type="ratio",  # will use the 1st entry by default
            subplot_title="* / %s" % (sources[0]['label']),
            do_flav_tagged=False,
            has_data=True)

        qgp.do_all_exclusive_plots_comparison(
            sources,
            var_list=qgc.COMMON_VARS,
            pt_bins=qgc.PT_BINS,
            qcd_filename=qgc.JETHT_ZB_FILENAME,
            dj_cen_dirname=None,
            dj_fwd_dirname="Dijet_QG_forward_tighter",
            zpj_dirname=None,
            plot_dir=os.path.join(output_dir,
                                  "plots_jetht_zb_compare_dijet_forward"),
            subplot_type="ratio",  # will use the 1st entry by default
            subplot_title="* / %s" % (sources[0]['label']),
            do_flav_tagged=False,
            has_data=True)

    # COMPARE SINGLEMU

    # COMPARE HERWIG++ QCD
    if exists_in_all(qgc.QCD_HERWIG_FILENAME, dirnames):
        qgp.do_all_exclusive_plots_comparison(
            sources,
            var_list=qgc.COMMON_VARS,
            pt_bins=qgc.PT_BINS,
            qcd_filename=qgc.QCD_HERWIG_FILENAME,
            dj_cen_dirname="Dijet_QG_central_tighter",
            dj_fwd_dirname=None,
            zpj_dirname=None,
            plot_dir=os.path.join(output_dir,
                                  "plots_qcd_herwig_compare_dijet_central"),
            subplot_type="ratio",  # will use the 1st entry by default
            subplot_title="* / %s" % (sources[0]['label']),
            subplot_limits=[0.9, 1.1],
            do_flav_tagged=False,
            has_data=False)

        qgp.do_all_exclusive_plots_comparison(
            sources,
            var_list=qgc.COMMON_VARS,
            pt_bins=qgc.PT_BINS,
            qcd_filename=qgc.QCD_HERWIG_FILENAME,
            dj_cen_dirname=None,
            dj_fwd_dirname="Dijet_QG_forward_tighter",
            zpj_dirname=None,
            plot_dir=os.path.join(output_dir,
                                  "plots_qcd_herwig_compare_dijet_forward"),
            subplot_type="ratio",  # will use the 1st entry by default
            subplot_title="* / %s" % (sources[0]['label']),
            subplot_limits=[0.9, 1.1],
            do_flav_tagged=False,
            has_data=False)
def do_comparison_plots(workdir_label_pairs, output_dir):
    dirnames = [w[0] for w in workdir_label_pairs]

    # templates, we'll change the filename/dir as per instance
    total_len = len(workdir_label_pairs)
    mark = cu.Marker()
    sources = [
       {
           # "root_dir": wd,
           'label': label,
           "style": {
               'line_style': 1,
               'line_color': cu.get_colour_seq(ind, total_len),
               'marker_color': cu.get_colour_seq(ind, total_len),
               'marker_style': m,
               'marker_size': 0.75,
           }

       }
       for ind, ((wd, label), m) in enumerate(zip(workdir_label_pairs, mark.cycle(cycle_filling=True)))
    ]

    jet_config_str = qgc.extract_jet_config(dirnames[0])
    if len(dirnames) >1 and qgc.extract_jet_config(dirnames[1]) != jet_config_str:
        print("Conflicting jet config str, not adding")
        jet_config_str = None

    # COMPARE NOMINAL QCD
    if exists_in_all(qgc.QCD_FILENAME, dirnames):
        print("Found", qgc.QCD_FILENAME, "in all dirs")
        root_files = [cu.open_root_file(os.path.join(d, qgc.QCD_FILENAME)) for d in dirnames]
        directories = [cu.get_from_tfile(rf, "Dijet_tighter") for rf in root_files]

        this_sources = deepcopy(sources)
        for s in this_sources:
            s['label'] = "QCD [MG+PY8] [%s]" % s['label']

        do_all_1D_projection_plots_in_dir(directories=directories,
                                          components_styles_dicts=this_sources,
                                          output_dir=os.path.join(output_dir, "plots_qcd_compare_dijet_tighter_kinematics_normalised"),
                                          jet_config_str=jet_config_str,
                                          normalise_hists=True,
                                          bin_by='ave')

        directories = [cu.get_from_tfile(rf, "Dijet_eta_ordered") for rf in root_files]
        do_all_1D_projection_plots_in_dir(directories=directories,
                                          components_styles_dicts=this_sources,
                                          output_dir=os.path.join(output_dir, "plots_qcd_compare_dijet_eta_ordered_kinematics_normalised"),
                                          jet_config_str=jet_config_str,
                                          normalise_hists=True,
                                          bin_by='ave')


    # COMPARE NOMINAL DY
    if exists_in_all(qgc.DY_FILENAME, dirnames):
        root_files = [cu.open_root_file(os.path.join(d, qgc.DY_FILENAME)) for d in dirnames]
        directories = [cu.get_from_tfile(rf, "ZPlusJets") for rf in root_files]

        this_sources = deepcopy(sources)
        for s in this_sources:
            s['label'] = "Z+Jet [MG+PY8] [%s]" % s['label']

        do_all_1D_projection_plots_in_dir(directories=directories,
                                          components_styles_dicts=this_sources,
                                          output_dir=os.path.join(output_dir, "plots_dy_compare_kinematics_absolute"),
                                          jet_config_str=jet_config_str,
                                          normalise_hists=False,
                                          bin_by='Z')
        
        do_all_1D_projection_plots_in_dir(directories=directories,
                                          components_styles_dicts=this_sources,
                                          output_dir=os.path.join(output_dir, "plots_dy_compare_kinematics_normalised"),
                                          jet_config_str=jet_config_str,
                                          normalise_hists=True,
                                          bin_by='Z')

    # COMPARE JETHT+ZEROBIAS
    if exists_in_all(qgc.JETHT_ZB_FILENAME, dirnames):
        print("Found", qgc.JETHT_ZB_FILENAME, "in all dirs")
        root_files = [cu.open_root_file(os.path.join(d, qgc.JETHT_ZB_FILENAME)) for d in dirnames]
        directories = [cu.get_from_tfile(rf, "Dijet_tighter") for rf in root_files]

        this_sources = deepcopy(sources)
        for s in this_sources:
            s['label'] = "Data [%s]" % s['label']

        directories = [cu.get_from_tfile(rf, "Dijet_Presel") for rf in root_files]
        do_all_1D_projection_plots_in_dir(directories=directories,
                                          components_styles_dicts=this_sources,
                                          output_dir=os.path.join(output_dir, "plots_jetht_zb_compare_dijet_presel_kinematics_normalised"),
                                          jet_config_str=jet_config_str,
                                          normalise_hists=False,
                                          bin_by='ave')

        directories = [cu.get_from_tfile(rf, "Dijet_tighter") for rf in root_files]
        do_all_1D_projection_plots_in_dir(directories=directories,
                                          components_styles_dicts=this_sources,
                                          output_dir=os.path.join(output_dir, "plots_jetht_zb_compare_dijet_tighter_kinematics_normalised"),
                                          jet_config_str=jet_config_str,
                                          normalise_hists=True,
                                          bin_by='ave')

        do_all_1D_projection_plots_in_dir(directories=directories,
                                          components_styles_dicts=this_sources,
                                          output_dir=os.path.join(output_dir, "plots_jetht_zb_compare_dijet_tighter_kinematics_abs"),
                                          jet_config_str=jet_config_str,
                                          normalise_hists=False,
                                          bin_by='ave')


    # COMPARE SINGLEMU

    # COMPARE HERWIG++ QCD
    if exists_in_all(qgc.QCD_HERWIG_FILENAME, dirnames):
        root_files = [cu.open_root_file(os.path.join(d, qgc.QCD_HERWIG_FILENAME)) for d in dirnames]
        directories = [cu.get_from_tfile(rf, "Dijet_tighter") for rf in root_files]

        this_sources = deepcopy(sources)
        for s in this_sources:
            s['label'] = "QCD [H++] [%s]" % s['label']

        # do_all_1D_projection_plots_in_dir(directories=directories,
        #                                   components_styles_dicts=this_sources,
        #                                   output_dir=os.path.join(output_dir, "plots_qcd_hpp_compare_dijet_tighter_kinematics_normalised"),
        #                                   jet_config_str=jet_config_str,
        #                                   normalise_hists=True,
        #                                   bin_by='ave')

        # directories = [cu.get_from_tfile(rf, "Dijet_eta_ordered") for rf in root_files]
        # do_all_1D_projection_plots_in_dir(directories=directories,
        #                                   components_styles_dicts=this_sources,
        #                                   output_dir=os.path.join(output_dir, "plots_qcd_hpp_compare_dijet_eta_ordered_kinematics_normalised"),
        #                                   jet_config_str=jet_config_str,
        #                                   normalise_hists=True,
        #                                   bin_by='ave')
        
        do_all_1D_projection_plots_in_dir(directories=directories,
                                          components_styles_dicts=this_sources,
                                          output_dir=os.path.join(output_dir, "plots_qcd_hpp_compare_dijet_tighter_kinematics_absolute"),
                                          jet_config_str=jet_config_str,
                                          normalise_hists=False,
                                          bin_by='ave')

        directories = [cu.get_from_tfile(rf, "Dijet_eta_ordered") for rf in root_files]
        do_all_1D_projection_plots_in_dir(directories=directories,
                                          components_styles_dicts=this_sources,
                                          output_dir=os.path.join(output_dir, "plots_qcd_hpp_compare_dijet_eta_ordered_kinematics_absolute"),
                                          jet_config_str=jet_config_str,
                                          normalise_hists=False,
                                          bin_by='ave')

    # COMPARE HERWIG++ DY
    if exists_in_all(qgc.DY_HERWIG_FILENAME, dirnames):
        root_files = [cu.open_root_file(os.path.join(d, qgc.DY_HERWIG_FILENAME)) for d in dirnames]
        directories = [cu.get_from_tfile(rf, "ZPlusJets") for rf in root_files]

        this_sources = deepcopy(sources)
        for s in this_sources:
            s['label'] = "Z+Jet [H++] [%s]" % s['label']

        do_all_1D_projection_plots_in_dir(directories=directories,
                                          components_styles_dicts=this_sources,
                                          output_dir=os.path.join(output_dir, "plots_dy_hpp_compare_kinematics_absolute"),
                                          jet_config_str=jet_config_str,
                                          normalise_hists=False,
                                          bin_by='Z')
        
        do_all_1D_projection_plots_in_dir(directories=directories,
                                          components_styles_dicts=this_sources,
                                          output_dir=os.path.join(output_dir, "plots_dy_hpp_compare_kinematics_normalised"),
                                          jet_config_str=jet_config_str,
                                          normalise_hists=True,
                                          bin_by='Z')
Ejemplo n.º 8
0
def do_pileup_plot(input_dir, trigger_names, output_filename):
    # get histograms
    hists = [
        cu.grab_obj_from_file(
            os.path.join(input_dir, 'MyDataPileupHistogram_%s.root' % t),
            'pileup') for t in trigger_names
    ]
    h_up = cu.grab_obj_from_file(
        os.path.join(input_dir, 'MyDataPileupHistogram_PFJet500_72383.root'),
        'pileup')
    h_down = cu.grab_obj_from_file(
        os.path.join(input_dir, 'MyDataPileupHistogram_PFJet500_66017.root'),
        'pileup')
    h_down3 = cu.grab_obj_from_file(
        os.path.join(input_dir, 'MyDataPileupHistogram_PFJet500_59650.root'),
        'pileup')
    ratio_up = h_up.Clone()
    ratio_up.Divide(hists[-1])
    ratio_down = h_down.Clone()
    ratio_down.Divide(hists[-1])
    # hists.append(h_up)
    # hists.append(h_down)
    # trigger_names.append('72.383')
    # trigger_names.append('66.017')
    # Create contributions
    mark = cu.Marker()
    n_hists = len(hists)
    conts = [
        Contribution(h,
                     label=t,
                     line_width=2,
                     line_color=cu.get_colour_seq(ind, n_hists),
                     marker_color=cu.get_colour_seq(ind, n_hists),
                     marker_style=m,
                     normalise_hist=True)
        for ind, (h, t, m) in enumerate(
            zip(hists, trigger_names, mark.cycle(cycle_filling=True)))
    ]

    conts.insert(
        -1,
        Contribution(
            h_up,
            label='72.383 (+4.6%)',
            line_width=2,
            line_color=ROOT.kRed,
            marker_color=ROOT.kRed,
            normalise_hist=True,
        ))
    conts.insert(
        -1,
        Contribution(
            h_down,
            label='66.017 (-4.6%)',
            line_width=2,
            line_color=ROOT.kMagenta,
            marker_color=ROOT.kMagenta,
            normalise_hist=True,
        ))
    conts.insert(
        -1,
        Contribution(
            h_down3,
            label='59.650 (-13.8%)',
            line_width=2,
            line_style=1,
            line_color=ROOT.kMagenta + 3,
            marker_color=ROOT.kMagenta + 3,
            normalise_hist=True,
        ))
    print([h.Integral() for h in hists])
    plot = Plot(
        conts,
        what='hist',
        xtitle='Pileup',
        lumi=cu.get_lumi_str(do_dijet=True, do_zpj=True),
        subplot_type='ratio',
        subplot=conts[-1],
    )
    plot.subplot_maximum_ceil = 4.5
    plot.plot("NOSTACK HISTE", "NOSTACK HIST")
    plot.subplot_pad.cd()

    # To shade region between up and down hists, need to create graph with
    # the error bars as the up/down variations

    x_low = np.array([
        ratio_up.GetBinLowEdge(i) for i in range(1,
                                                 ratio_up.GetNbinsX() + 1)
    ],
                     dtype=float)
    x_high = np.array([
        ratio_up.GetBinLowEdge(i) for i in range(2,
                                                 ratio_up.GetNbinsX() + 2)
    ],
                      dtype=float)
    x_mid = 0.5 * (x_low + x_high)
    x_err = x_high - x_low

    y_high = np.array([
        max(ratio_up.GetBinContent(i), ratio_down.GetBinContent(i))
        for i in range(1,
                       ratio_up.GetNbinsX() + 1)
    ])
    y_high -= 1
    y_low = np.array([
        min(ratio_up.GetBinContent(i), ratio_down.GetBinContent(i))
        for i in range(1,
                       ratio_up.GetNbinsX() + 1)
    ])
    y_low = 1 - y_low
    y_mid = np.array([1. for i in range(1, ratio_up.GetNbinsX() + 1)])

    gr = ROOT.TGraphAsymmErrors(len(x_mid), x_mid, y_mid, x_err, x_err, y_low,
                                y_high)
    gr.SetFillColor(ROOT.kGray + 2)
    gr.SetFillStyle(3254)
    gr.Draw('2 SAME')
    plot.subplot_container.Draw("SAME NOSTACK HIST")
    plot.subplot_line.Draw()
    plot.save(output_filename)