def do_plots(root_dir): # QG variable plots pt_bins = qgc.PT_BINS[:] var_list = qgc.COMMON_VARS var_prepend = "" radius, pus = cu.get_jet_config_from_dirname(root_dir) jet_str = "AK%s PF %s" % (radius.upper(), pus.upper()) for gr_append in ["", "_groomed"][:1]: if gr_append == "_groomed": print("Doing groomed plots...") else: print("Doing ungroomed plots...") zpj_dirname = "ZPlusJets_QG%s" % (gr_append) dj_cen_dirname = "Dijet_QG_central_tighter%s" % (gr_append) dj_fwd_dirname = "Dijet_QG_forward_tighter%s" % (gr_append) # tfiles = { # "data_run_B": cu.open_root_file(os.path.join(root_dir, "uhh2.AnalysisModuleRunner.DATA.Data_JetHT_RunB.root")), # "data_run_C": cu.open_root_file(os.path.join(root_dir, "uhh2.AnalysisModuleRunner.DATA.Data_JetHT_RunC.root")), # "data_run_D": cu.open_root_file(os.path.join(root_dir, "uhh2.AnalysisModuleRunner.DATA.Data_JetHT_RunD.root")), # "data_run_E": cu.open_root_file(os.path.join(root_dir, "uhh2.AnalysisModuleRunner.DATA.Data_JetHT_RunE.root")), # "data_run_F": cu.open_root_file(os.path.join(root_dir, "uhh2.AnalysisModuleRunner.DATA.Data_JetHT_RunF.root")), # "data_run_G": cu.open_root_file(os.path.join(root_dir, "uhh2.AnalysisModuleRunner.DATA.Data_JetHT_RunG.root")), # "data_run_H": cu.open_root_file(os.path.join(root_dir, "uhh2.AnalysisModuleRunner.DATA.Data_JetHT_RunH.root")), # } tfiles = { "data_run_B": cu.open_root_file( os.path.join( root_dir, "uhh2.AnalysisModuleRunner.DATA.Data_JetHT_ZeroBias_RunB.root" )), "data_run_C": cu.open_root_file( os.path.join( root_dir, "uhh2.AnalysisModuleRunner.DATA.Data_JetHT_ZeroBias_RunC.root" )), "data_run_D": cu.open_root_file( os.path.join( root_dir, "uhh2.AnalysisModuleRunner.DATA.Data_JetHT_ZeroBias_RunD.root" )), "data_run_E": cu.open_root_file( os.path.join( root_dir, "uhh2.AnalysisModuleRunner.DATA.Data_JetHT_ZeroBias_RunE.root" )), "data_run_F": cu.open_root_file( os.path.join( root_dir, "uhh2.AnalysisModuleRunner.DATA.Data_JetHT_ZeroBias_RunF.root" )), "data_run_G": cu.open_root_file( os.path.join( root_dir, "uhh2.AnalysisModuleRunner.DATA.Data_JetHT_ZeroBias_RunG.root" )), "data_run_H": cu.open_root_file( os.path.join( root_dir, "uhh2.AnalysisModuleRunner.DATA.Data_JetHT_ZeroBias_RunH.root" )), } for ang in var_list[:]: print("...Doing", ang.name) v = "%s%s_vs_pt" % (var_prepend, ang.var) zpj_1d_entries = [] dijet_cen_1d_entries = [] dijet_fwd_1d_entries = [] for pt_ind, (start_val, end_val) in enumerate(pt_bins): entries = [] zpj_entries = [] dijet_cen_entries = [] dijet_fwd_entries = [] # Get all plots lw = 2 msize = 1.1 data_line_width = lw colours = [ ROOT.kBlack, ROOT.kRed, ROOT.kBlue, ROOT.kGreen + 2, ROOT.kOrange + 1, ROOT.kAzure + 1, ROOT.kGreen + 3 ] # -------------------------------------------------------------- # Create reference hists, for Run G+H # -------------------------------------------------------------- #################### # DIJET CENTRAL REGION #################### h2d_qcd_cen_data_g = cu.get_from_tfile( tfiles['data_run_G'], "%s/%s" % (dj_cen_dirname, v)) h2d_qcd_cen_data_h = cu.get_from_tfile( tfiles['data_run_H'], "%s/%s" % (dj_cen_dirname, v)) colour = colours[0] qcd_cen_kwargs_data = dict(line_color=colour, line_width=data_line_width, fill_color=colour, marker_color=colour, marker_style=cu.Marker.get( qgc.QCD_MARKER), marker_size=0, label="Runs G+H") dijet_cen_data_hist_g = qgp.get_projection_plot( h2d_qcd_cen_data_g, start_val, end_val) dijet_cen_data_hist_h = qgp.get_projection_plot( h2d_qcd_cen_data_h, start_val, end_val) dijet_cen_data_hist_g.Add(dijet_cen_data_hist_h) dijet_cen_entries.append( (dijet_cen_data_hist_g, qcd_cen_kwargs_data)) #################### # DIJET FORWARD REGION #################### h2d_qcd_fwd_data_g = cu.get_from_tfile( tfiles['data_run_G'], "%s/%s" % (dj_fwd_dirname, v)) h2d_qcd_fwd_data_h = cu.get_from_tfile( tfiles['data_run_H'], "%s/%s" % (dj_fwd_dirname, v)) qcd_fwd_kwargs_data = dict(line_color=colour, line_width=data_line_width, fill_color=colour, marker_color=colour, marker_style=cu.Marker.get( qgc.QCD_MARKER), marker_size=0, label="Runs G+H") dijet_fwd_data_hist_g = qgp.get_projection_plot( h2d_qcd_fwd_data_g, start_val, end_val) dijet_fwd_data_hist_h = qgp.get_projection_plot( h2d_qcd_fwd_data_h, start_val, end_val) dijet_fwd_data_hist_g.Add(dijet_fwd_data_hist_h) dijet_fwd_entries.append( (dijet_fwd_data_hist_g, qcd_fwd_kwargs_data)) # -------------------------------------------------------------- # FOR SUMMED B-F: # -------------------------------------------------------------- dijet_cen_data_hist_btof, dijet_fwd_data_hist_btof = None, None runs = ["B", "C", "D", "E", "F"] for run in runs: # DIJET CENTRAL REGION h2d_qcd_cen_data = cu.get_from_tfile( tfiles['data_run_%s' % run], "%s/%s" % (dj_cen_dirname, v)) this_dijet_cen_data_hist = qgp.get_projection_plot( h2d_qcd_cen_data, start_val, end_val) if dijet_cen_data_hist_btof is None: dijet_cen_data_hist_btof = this_dijet_cen_data_hist.Clone( ) else: dijet_cen_data_hist_btof.Add(this_dijet_cen_data_hist) # DIJET FORWARD REGION h2d_qcd_fwd_data = cu.get_from_tfile( tfiles['data_run_%s' % run], "%s/%s" % (dj_fwd_dirname, v)) # use already merged jetht+zb this_dijet_fwd_data_hist = qgp.get_projection_plot( h2d_qcd_fwd_data, start_val, end_val) if dijet_fwd_data_hist_btof is None: dijet_fwd_data_hist_btof = this_dijet_fwd_data_hist.Clone( ) else: dijet_fwd_data_hist_btof.Add(this_dijet_fwd_data_hist) colour = colours[1] mark = cu.Marker.get('circle') btof_cen_kwargs_data = dict(line_color=colour, line_width=data_line_width, fill_color=colour, marker_color=colour, marker_style=mark, marker_size=msize, label="Runs %s-%s" % (runs[0], runs[-1]), subplot=dijet_cen_data_hist_g) dijet_cen_entries.append( (dijet_cen_data_hist_btof, btof_cen_kwargs_data)) btof_fwd_kwargs_data = dict(line_color=colour, line_width=data_line_width, fill_color=colour, marker_color=colour, marker_style=mark, marker_size=msize, label="Runs %s-%s" % (runs[0], runs[-1]), subplot=dijet_fwd_data_hist_g) dijet_fwd_entries.append( (dijet_fwd_data_hist_btof, btof_fwd_kwargs_data)) # FOR INDIVIDUAL RUN PERIODS: # runs = ["B", "C", "D", "E", "F"] # for run, colour, mark in zip(runs, colours[1:], cu.Marker().cycle()): # #################### # # DIJET CENTRAL REGION # #################### # # JETHT DATA # h2d_qcd_cen_data = cu.get_from_tfile(tfiles['data_run_%s' % run], "%s/%s" % (dj_cen_dirname, v)) # qcd_cen_kwargs_data = dict(line_color=colour, line_width=data_line_width, fill_color=colour, # marker_color=colour, marker_style=mark, marker_size=msize, # label="Run %s" % run, # subplot=dijet_cen_data_hist_g) # dijet_cen_data_hist = qgp.get_projection_plot(h2d_qcd_cen_data, start_val, end_val) # dijet_cen_entries.append((dijet_cen_data_hist, qcd_cen_kwargs_data)) # #################### # # DIJET FORWARD REGION # #################### # # JETHT DATA # h2d_qcd_fwd_data = cu.get_from_tfile(tfiles['data_run_%s' % run], "%s/%s" % (dj_fwd_dirname, v)) # use already merged jetht+zb # qcd_fwd_kwargs_data = dict(line_color=colour, line_width=data_line_width, fill_color=colour, # marker_color=colour, marker_style=mark, marker_size=msize, # label="Run %s" % run, # subplot=dijet_fwd_data_hist_g) # dijet_fwd_data_hist = qgp.get_projection_plot(h2d_qcd_fwd_data, start_val, end_val) # dijet_fwd_entries.append((dijet_fwd_data_hist, qcd_fwd_kwargs_data)) # #################### # # Z+JETS REGION # #################### # # SINGLE MU DATA # # h2d_dyj_data = cu.get_from_tfile(os.path.join(root_dir, "uhh2.AnalysisModuleRunner.DATA.Data_SingleMu_Run%s.root" % run), "%s/%s" % (zpj_dirname, v)) # # dy_kwargs_data = dict(line_color=qgc.colour, line_width=data_line_width, fill_color=qgc.colour, # # marker_color=qgc.colour, marker_style=cu.Marker.get(qgc.DY_MARKER), marker_size=msize, # # label="SingleMu Run %s" % run) # # zpj_data_hist = qgp.get_projection_plot(h2d_dyj_data, start_val, end_val) # # zpj_entries.append((zpj_data_hist, dy_kwargs_data)) ################# # SETUP PLOTTING ################# rebin = 2 v_lower = v.lower() if "multiplicity" in v_lower: rebin = 2 elif "flavour" in v_lower or "thrust" in v_lower: rebin = 1 elif 'ptd' in v_lower: rebin = 2 xlim = None if "width" in v_lower or "ptd" in v_lower: xlim = (0, 1) elif "thrust" in v_lower: xlim = (0, 0.5) elif "multiplicity" in v_lower and "ak4" in root_dir.lower(): if end_val <= 150: xlim = (0, 50) else: xlim = (0, 80) ylim = None if "flavour" in v_lower: ylim = (0, 1) # elif "lha" in v_lower: # ylim = (0, 5) plot_dir = os.path.join(root_dir, "plots_run_dependent%s" % (gr_append)) plot_dir = os.path.join( root_dir, "plots_run_dependent_btof%s" % (gr_append)) subplot_title = "Run * / G+H" subplot_title = "B-F / G+H" subplot_limits = (0.5, 1.5) xlabel = ang.name + " (" + ang.lambda_str + ")" if gr_append is not "": xlabel = "Groomed " + ang.name + " (" + ang.lambda_str + ")" # dj central only dijet_cen_entries = dijet_cen_entries[1:] + dijet_cen_entries[ 0:1] # move G+H to last qgp.do_comparison_plot( dijet_cen_entries, "%s/ptBinned/%s_pt%dto%d_dijet_central.%s" % (plot_dir, v, start_val, end_val, OUTPUT_FMT), rebin=rebin, title="%d < p_{T}^{jet} < %d GeV\n%s\n%s" % (start_val, end_val, jet_str, qgc.Dijet_CEN_LABEL), xtitle=xlabel, xlim=xlim, ylim=ylim, subplot_type='ratio', subplot_title=subplot_title, subplot_limits=subplot_limits) # dj forward only dijet_fwd_entries = dijet_fwd_entries[1:] + dijet_fwd_entries[ 0:1] # move G+H to last qgp.do_comparison_plot( dijet_fwd_entries, "%s/ptBinned/%s_pt%dto%d_dijet_forward.%s" % (plot_dir, v, start_val, end_val, OUTPUT_FMT), rebin=rebin, title="%d < p_{T}^{jet} < %d GeV\n%s\n%s" % (start_val, end_val, jet_str, qgc.Dijet_FWD_LABEL), xtitle=xlabel, xlim=xlim, ylim=ylim, subplot_type='ratio', subplot_title=subplot_title, subplot_limits=subplot_limits)
def do_plots(root_dir): # QG variable plots pt_bins = qgc.PT_BINS[:] var_list = qgc.COMMON_VARS var_prepend = "" radius, pus = cu.get_jet_config_from_dirname(root_dir) jet_str = "AK%s PF %s" % (radius.upper(), pus.upper()) for gr_append in ["", "_groomed"]: if gr_append == "_groomed": print("Doing groomed plots...") else: print("Doing ungroomed plots...") if gr_append == "": make_1d_plot(root_dir, "Dijet_gen/pt_dijet_ave", jet_str, gen_only=True) make_1d_plot(root_dir, "Dijet_tighter/pt_jet", jet_str) dj_cen_dirname = "Dijet_QG_central_tighter%s" % (gr_append) dj_fwd_dirname = "Dijet_QG_forward_tighter%s" % (gr_append) for ang in var_list[:]: print("...Doing", ang.name) v = "%s%s_vs_pt" % (var_prepend, ang.var) dijet_cen_2d_entries = [] dijet_fwd_2d_entries = [] dijet_cen_1d_entries = [] dijet_fwd_1d_entries = [] for pt_ind, (start_val, end_val) in enumerate(pt_bins): entries = [] dijet_cen_entries = [] dijet_fwd_entries = [] # Get all plots lw = 2 msize = 1.1 data_line_width = lw #################### # DIJET CENTRAL REGION #################### # JETHT/ZEROBIAS DATA h2d_qcd_cen_data = grab_obj( os.path.join(root_dir, qgc.JETHT_ZB_FILENAME), "%s/%s" % (dj_cen_dirname, v)) # use already merged jetht+zb qcd_cen_kwargs_data = dict(line_color=qgc.JETHT_COLOUR, line_width=data_line_width, fill_color=qgc.JETHT_COLOUR, marker_color=qgc.JETHT_COLOUR, marker_style=cu.Marker.get( qgc.QCD_MARKER), marker_size=msize, label="Data") dijet_cen_data_hist = qgp.get_projection_plot( h2d_qcd_cen_data, start_val, end_val) entries.append((dijet_cen_data_hist, qcd_cen_kwargs_data)) dijet_cen_entries.append( (dijet_cen_data_hist, qcd_cen_kwargs_data)) if pt_ind == 0: dijet_cen_2d_entries.append( (h2d_qcd_cen_data, qcd_cen_kwargs_data)) # MG+PYTHIA QCD MC h2d_qcd_cen_mc = grab_obj( os.path.join(root_dir, qgc.QCD_FILENAME), "%s/%s" % (dj_cen_dirname, v)) qcd_cen_kwargs_mc = dict(line_color=qgc.QCD_COLOUR, line_width=lw, fill_color=qgc.QCD_COLOUR, marker_color=qgc.QCD_COLOUR, marker_style=cu.Marker.get( qgc.QCD_MARKER), marker_size=0, label="MG+PY8", subplot=dijet_cen_data_hist) # h2d_qcd_cen_mc.Scale(35860) dijet_mgpy_hist = qgp.get_projection_plot( h2d_qcd_cen_mc, start_val, end_val) entries.append((dijet_mgpy_hist, qcd_cen_kwargs_mc)) dijet_cen_entries.append((dijet_mgpy_hist, qcd_cen_kwargs_mc)) if pt_ind == 0: dijet_cen_2d_entries.append( (h2d_qcd_cen_mc, qcd_cen_kwargs_mc)) # PYTHIA ONLY # col = qgc.QCD_COLOURS[2] # h2d_qcd_cen_mc2 = grab_obj(os.path.join(root_dir, qgc.QCD_PYTHIA_ONLY_FILENAME), "%s/%s" % (dj_cen_dirname, v)) # qcd_cen_kwargs_mc2 = dict(line_color=col, line_width=lw, fill_color=col, # marker_color=col, marker_style=cu.Marker.get(qgc.QCD_MARKER), marker_size=0, # label="PY8", # subplot=dijet_cen_data_hist) # # h2d_qcd_cen_mc2.Scale(35860) # entries.append((qgp.get_projection_plot(h2d_qcd_cen_mc2, start_val, end_val), qcd_cen_kwargs_mc2)) # dijet_cen_entries.append((qgp.get_projection_plot(h2d_qcd_cen_mc2, start_val, end_val), qcd_cen_kwargs_mc2)) # if pt_ind == 0: # dijet_cen_2d_entries.append((h2d_qcd_cen_mc2, qcd_cen_kwargs_mc2)) # HERWIG++ QCD col2 = qgc.QCD_COLOURS[3] h2d_qcd_cen_mc3 = grab_obj( os.path.join(root_dir, qgc.QCD_HERWIG_FILENAME), "%s/%s" % (dj_cen_dirname, v)) qcd_cen_kwargs_mc3 = dict(line_color=col2, line_width=lw, fill_color=col2, marker_color=col2, marker_style=cu.Marker.get( qgc.QCD_MARKER), marker_size=0, label="H++", subplot=dijet_cen_data_hist) h2d_qcd_cen_mc3.Scale(TOTAL_LUMI) dijet_hpp_hist = qgp.get_projection_plot( h2d_qcd_cen_mc3, start_val, end_val) entries.append((dijet_hpp_hist, qcd_cen_kwargs_mc3)) dijet_cen_entries.append((dijet_hpp_hist, qcd_cen_kwargs_mc3)) if pt_ind == 0: dijet_cen_2d_entries.append( (h2d_qcd_cen_mc3, qcd_cen_kwargs_mc3)) # HERWIG++ QCD WITH PT REWEIGHT col3 = ROOT.kRed h2d_qcd_cen_mc4 = grab_obj( os.path.join( root_dir, "uhh2.AnalysisModuleRunner.MC.MC_HERWIG_QCD_PtReweight.root" ), "%s/%s" % (dj_cen_dirname, v)) qcd_cen_kwargs_mc4 = dict(line_color=col3, line_width=lw, fill_color=col3, marker_color=col3, marker_style=cu.Marker.get( qgc.QCD_MARKER), marker_size=0, label="H++ (p_{T} reweighted)", subplot=dijet_cen_data_hist) h2d_qcd_cen_mc4.Scale(TOTAL_LUMI) dijet_hpp_hist_reweight = qgp.get_projection_plot( h2d_qcd_cen_mc4, start_val, end_val) entries.append((dijet_hpp_hist_reweight, qcd_cen_kwargs_mc4)) dijet_cen_entries.append( (dijet_hpp_hist_reweight, qcd_cen_kwargs_mc4)) if pt_ind == 0: dijet_cen_2d_entries.append( (h2d_qcd_cen_mc4, qcd_cen_kwargs_mc4)) #################### # DIJET FORWARD REGION #################### # JETHT/ZEROBIAS DATA h2d_qcd_fwd_data = grab_obj( os.path.join(root_dir, qgc.JETHT_ZB_FILENAME), "%s/%s" % (dj_fwd_dirname, v)) # use already merged jetht+zb # h2d_zb_data = grab_obj(os.path.join(root_dir, qgc.ZB_FILENAME), "%s/%s" % (dj_cen_dirname, v)) # h2d_zb_data.Scale(1235009.27580634) # h2d_qcd_cen_data.Add(h2d_zb_data) qcd_fwd_kwargs_data = dict(line_color=qgc.JETHT_COLOUR, line_width=data_line_width, fill_color=qgc.JETHT_COLOUR, marker_color=qgc.JETHT_COLOUR, marker_style=cu.Marker.get( qgc.QCD_MARKER), marker_size=msize, label="Data") dijet_fwd_data_hist = qgp.get_projection_plot( h2d_qcd_fwd_data, start_val, end_val) entries.append((dijet_fwd_data_hist, qcd_fwd_kwargs_data)) dijet_fwd_entries.append( (dijet_fwd_data_hist, qcd_fwd_kwargs_data)) if pt_ind == 0: dijet_fwd_2d_entries.append( (h2d_qcd_fwd_data, qcd_fwd_kwargs_data)) # MG+PYTHIA QCD MC h2d_qcd_fwd_mc = grab_obj( os.path.join(root_dir, qgc.QCD_FILENAME), "%s/%s" % (dj_fwd_dirname, v)) qcd_fwd_kwargs_mc = dict(line_color=qgc.QCD_COLOUR, line_width=lw, fill_color=qgc.QCD_COLOUR, marker_color=qgc.QCD_COLOUR, marker_style=cu.Marker.get( qgc.QCD_MARKER), marker_size=0, label="MG+PY8", subplot=dijet_fwd_data_hist) # h2d_qcd_fwd_mc.Scale(35860) dijet_mgpy_hist = qgp.get_projection_plot( h2d_qcd_fwd_mc, start_val, end_val) entries.append((dijet_mgpy_hist, qcd_fwd_kwargs_mc)) dijet_fwd_entries.append((dijet_mgpy_hist, qcd_fwd_kwargs_mc)) if pt_ind == 0: dijet_fwd_2d_entries.append( (h2d_qcd_fwd_mc, qcd_fwd_kwargs_mc)) # PYTHIA ONLY # col = qgc.QCD_COLOURS[2] # h2d_qcd_fwd_mc2 = grab_obj(os.path.join(root_dir, qgc.QCD_PYTHIA_ONLY_FILENAME), "%s/%s" % (dj_fwd_dirname, v)) # qcd_fwd_kwargs_mc2 = dict(line_color=col, line_width=lw, fill_color=col, # marker_color=col, marker_style=cu.Marker.get(qgc.QCD_MARKER), marker_size=0, # label="PY8", # subplot=dijet_fwd_data_hist) # # h2d_qcd_fwd_mc2.Scale(35860) # entries.append((qgp.get_projection_plot(h2d_qcd_fwd_mc2, start_val, end_val), qcd_fwd_kwargs_mc2)) # dijet_fwd_entries.append((qgp.get_projection_plot(h2d_qcd_fwd_mc2, start_val, end_val), qcd_fwd_kwargs_mc2)) # if pt_ind == 0: # dijet_fwd_2d_entries.append((h2d_qcd_fwd_mc2, qcd_fwd_kwargs_mc2)) # HERWIG++ QCD col2 = qgc.QCD_COLOURS[3] h2d_qcd_fwd_mc3 = grab_obj( os.path.join(root_dir, qgc.QCD_HERWIG_FILENAME), "%s/%s" % (dj_fwd_dirname, v)) qcd_fwd_kwargs_mc3 = dict(line_color=col2, line_width=lw, fill_color=col2, marker_color=col2, marker_style=cu.Marker.get( qgc.QCD_MARKER), marker_size=0, label="H++", subplot=dijet_fwd_data_hist) h2d_qcd_fwd_mc3.Scale(TOTAL_LUMI) dijet_hpp_hist = qgp.get_projection_plot( h2d_qcd_fwd_mc3, start_val, end_val) entries.append((dijet_hpp_hist, qcd_fwd_kwargs_mc3)) dijet_fwd_entries.append((dijet_hpp_hist, qcd_fwd_kwargs_mc3)) if pt_ind == 0: dijet_fwd_2d_entries.append( (h2d_qcd_fwd_mc3, qcd_fwd_kwargs_mc3)) col3 = ROOT.kRed h2d_qcd_fwd_mc4 = grab_obj( os.path.join( root_dir, "uhh2.AnalysisModuleRunner.MC.MC_HERWIG_QCD_PtReweight.root" ), "%s/%s" % (dj_fwd_dirname, v)) qcd_fwd_kwargs_mc4 = dict(line_color=col3, line_width=lw, fill_color=col3, marker_color=col3, marker_style=cu.Marker.get( qgc.QCD_MARKER), marker_size=0, label="H++ (p_{T} reweighted)", subplot=dijet_fwd_data_hist) h2d_qcd_fwd_mc4.Scale(TOTAL_LUMI) dijet_hpp_hist_reweight = qgp.get_projection_plot( h2d_qcd_fwd_mc4, start_val, end_val) entries.append((dijet_hpp_hist_reweight, qcd_fwd_kwargs_mc4)) dijet_fwd_entries.append( (dijet_hpp_hist_reweight, qcd_fwd_kwargs_mc4)) if pt_ind == 0: dijet_fwd_2d_entries.append( (h2d_qcd_fwd_mc4, qcd_fwd_kwargs_mc4)) dijet_cen_1d_entries.append(dijet_cen_entries) dijet_fwd_1d_entries.append(dijet_fwd_entries) ################# # SETUP PLOTTING ################# rebin = 2 v_lower = v.lower() if "multiplicity" in v_lower: rebin = 2 elif "flavour" in v_lower or "thrust" in v_lower: rebin = 1 elif 'ptd' in v_lower: rebin = 2 xlim = None if "width" in v_lower or "ptd" in v_lower: xlim = (0, 1) elif "thrust" in v_lower: xlim = (0, 0.5) elif "multiplicity" in v_lower and "ak4" in root_dir.lower(): if end_val <= 150: xlim = (0, 50) else: xlim = (0, 80) ylim = None if "flavour" in v_lower: ylim = (0, 1) # elif "lha" in v_lower: # ylim = (0, 5) plot_dir = os.path.join( root_dir, "plots_dijet_vs_qcd_mc_vs_data%s_pt_reweight" % (gr_append)) subplot_title = "MC / Data" subplot_limits = (0.5, 1.5) xlabel = ang.name + " (" + ang.lambda_str + ")" if gr_append is not "": xlabel = "Groomed " + ang.name + " (" + ang.lambda_str + ")" # dj+zpj # qgp.do_comparison_plot(entries, # "%s/ptBinned/%s_pt%dto%d.%s" % (plot_dir, v, start_val, end_val, OUTPUT_FMT), # rebin=rebin, # title="%d < p_{T}^{jet} < %d GeV\n%s" % (start_val, end_val, jet_str), # xtitle=ang.name + " (" + ang.lambda_str + ")", # xlim=xlim, ylim=ylim, # subplot_type='ratio', # subplot_title=subplot_title, # subplot_limits=subplot_limits) # dj central only qgp.do_comparison_plot( dijet_cen_entries, "%s/ptBinned/%s_pt%dto%d_dijet_central.%s" % (plot_dir, v, start_val, end_val, OUTPUT_FMT), rebin=rebin, title="%d < p_{T}^{jet} < %d GeV\n%s\n%s" % (start_val, end_val, jet_str, qgc.Dijet_CEN_LABEL), xtitle=xlabel, xlim=xlim, ylim=ylim, subplot_type='ratio', subplot_title=subplot_title, subplot_limits=subplot_limits) # dj forward only qgp.do_comparison_plot( dijet_fwd_entries, "%s/ptBinned/%s_pt%dto%d_dijet_forward.%s" % (plot_dir, v, start_val, end_val, OUTPUT_FMT), rebin=rebin, title="%d < p_{T}^{jet} < %d GeV\n%s\n%s" % (start_val, end_val, jet_str, qgc.Dijet_FWD_LABEL), xtitle=xlabel, xlim=xlim, ylim=ylim, subplot_type='ratio', subplot_title=subplot_title, subplot_limits=subplot_limits) # Do overall summary plots across all pt bins # ------------------------------------------------------------------ ylim_mean = None if "width" in v_lower or "ptd" in v_lower: ylim_mean = (0, 0.4) elif "thrust" in v_lower: ylim_mean = (0, 0.5) elif "multiplicity" in v_lower and "ak4" in root_dir.lower(): ylim_mean = (0, 100) ylim_mean = (0, 80) if end_val < 150: ylim_mean = (0, 50) ylim_mean = None ylim_rms = None # Setup variable names for MPL marker = "" if "_" in ang.name or "^" in ang.name: marker = "$" var_label = marker + ang.name + marker + " ($%s$)" % ang.lambda_str if gr_append != "": var_label = "Groomed " + marker + ang.name + marker + " ($%s$)" % ang.lambda_str qgp.do_mean_rms_summary_plot( dijet_cen_1d_entries[:], pt_bins[:], "%s/ptBinned/%s_box_dijet_cen_mpl.%s" % (plot_dir, v, OUTPUT_FMT), var_label=var_label, xlim=(50, 2000), ylim_mean=ylim_mean, ylim_rms=ylim_rms, region_title="%s jets in dijet (central)" % (jet_str)) qgp.do_mean_rms_summary_plot( dijet_fwd_1d_entries[:], pt_bins[:], "%s/ptBinned/%s_box_dijet_fwd_mpl.%s" % (plot_dir, v, OUTPUT_FMT), var_label=var_label, xlim=(50, 2000), ylim_mean=ylim_mean, ylim_rms=ylim_rms, region_title="%s jets in dijet (forward)" % (jet_str))
def do_component_plots(mgpythia_dir, pythia_only_dir, plot_dir): # Do 2D plots for diff ptMin folders jet_flavs = ["", "g", "q"] ptmin_vals = [50, 100, 200, 400, 800] ptmin_vals = [100, 800] # first the pt vs ones: plotnames = [ "genjet_pt_vs_constituent_pt", "genjet_pt_vs_constituent_zi", "genjet_pt_vs_constituent_deta", "genjet_pt_vs_constituent_dphi", "genjet_pt_vs_constituent_dr" ] for plotname, ptmin, renorm, logz, flav in product(plotnames, ptmin_vals, ['Y', None], [True, False], jet_flavs): rebin = [1, 1] ylim = [ptmin, 2000] dirname = "Dijet_genjet_ptMin_%d" % ptmin this_hist = os.path.join(dirname, flav + plotname) log_append = "_logZ" if logz else "" qgg.do_2D_plot( grab_obj(os.path.join(mgpythia_dir, qgc.QCD_FILENAME), this_hist), output_filename= "%s/constituent_plots/ptMin_%d/%s_mgpythia_norm%s%s.%s" % (plot_dir, ptmin, flav + plotname, renorm, log_append, OUTPUT_FMT), renorm_axis=renorm, title="MG+Pythia", rebin=rebin, recolour=True, ylim=ylim, logz=logz) qgg.do_2D_plot( grab_obj(os.path.join(pythia_only_dir, qgc.QCD_FILENAME), this_hist), output_filename= "%s/constituent_plots/ptMin_%d/%s_pythiaOnly_norm%s%s.%s" % (plot_dir, ptmin, flav + plotname, renorm, log_append, OUTPUT_FMT), renorm_axis=renorm, title="Pythia only", rebin=rebin, recolour=True, ylim=ylim, logz=logz) # Now LHA vs X ones plotnames = ["genjet_LHA_vs_zi", "genjet_LHA_vs_thetai"] for plotname, ptmin, renorm, logz, flav in product(plotnames, ptmin_vals, ['X', 'Y', None], [True, False], jet_flavs): rebin = [4, 4] xlim = [0, 0.5] if ("zi" in plotname and renorm != "X") else None ylim = None dirname = "Dijet_genjet_ptMin_%d" % ptmin this_hist = os.path.join(dirname, flav + plotname) log_append = "_logZ" if logz else "" qgg.do_2D_plot( grab_obj(os.path.join(mgpythia_dir, qgc.QCD_FILENAME), this_hist), output_filename= "%s/constituent_plots/ptMin_%d/%s_mgpythia_norm%s%s.%s" % (plot_dir, ptmin, flav + plotname, renorm, log_append, OUTPUT_FMT), renorm_axis=renorm, title="MG+Pythia, %s-jet, ptMin = %d GeV" % (flav, ptmin), rebin=rebin, recolour=True, xlim=xlim, ylim=ylim, logz=logz) qgg.do_2D_plot( grab_obj(os.path.join(pythia_only_dir, qgc.QCD_FILENAME), this_hist), output_filename= "%s/constituent_plots/ptMin_%d/%s_pythiaOnly_norm%s%s.%s" % (plot_dir, ptmin, flav + plotname, renorm, log_append, OUTPUT_FMT), renorm_axis=renorm, title="Pythia only, %s-jet, ptMin = %d GeV" % (flav, ptmin), rebin=rebin, recolour=True, xlim=xlim, ylim=ylim, logz=logz) def do_2D_plot_with_contours(obj, contour_obj, output_filename, renorm_axis=None, title=None, rebin=None, recolour=True, xlim=None, ylim=None, logx=False, logy=False, logz=False): """Like normal 2D plotter but contour_obj will be plotted using contours""" if rebin: obj.Rebin2D(*rebin) if renorm_axis: obj_renorm = cu.make_normalised_TH2(obj, renorm_axis, recolour) else: obj_renorm = obj if title: obj_renorm.SetTitle(title) canvas = ROOT.TCanvas(ROOT.TUUID().AsString(), "", 800, 800) canvas.SetTicks(1, 1) canvas.SetLeftMargin(0.13) canvas.SetBottomMargin(0.11) if logx: canvas.SetLogx(1) if logy: canvas.SetLogy(1) if logz: canvas.SetLogz(1) obj_renorm.Draw("COLZ") if xlim is not None: obj_renorm.GetXaxis().SetRangeUser(*xlim) if ylim is not None: obj_renorm.GetYaxis().SetRangeUser(*ylim) obj_renorm.GetYaxis().SetTitleOffset(1.7) obj_renorm.GetXaxis().SetTitleOffset(1.2) if contour_obj: contour_obj.Draw("CONT3 SAME") output_filename = os.path.abspath(output_filename) odir = os.path.dirname(output_filename) if not os.path.isdir(odir): os.makedirs(odir) canvas.SaveAs(output_filename) # Do 2D plots for premade jet pt cut objs jet_pt_vals = [(100, 200), (800, 1000)] for (jet_pt_min, jet_pt_max), renorm, logz in product(jet_pt_vals, ['X', 'Y', None][2:], [True, False]): rebin = [1, 1] xlim = [0, 1] ylim = [0, 0.05] dirname = "Dijet_genjet" jet_type = "g" plotname = jet_type + "genjet_constituent_zi_vs_constituent_thetai_pt%dto%d" % ( jet_pt_min, jet_pt_max) this_hist = os.path.join(dirname, plotname) log_append = "_logZ" if logz else "" contour_hist = grab_obj(os.path.join(mgpythia_dir, qgc.QCD_FILENAME), this_hist).Clone("contours") for xbin in range(1, contour_hist.GetNbinsX() + 1): for ybin in range(1, contour_hist.GetNbinsY() + 1): xval = 0.5 * (contour_hist.GetXaxis().GetBinCenter(xbin) + contour_hist.GetXaxis().GetBinCenter(xbin + 1)) yval = 0.5 * (contour_hist.GetYaxis().GetBinCenter(ybin) + contour_hist.GetYaxis().GetBinCenter(ybin + 1)) contour_hist.SetBinContent(xbin, ybin, math.sqrt(xval / 0.4) * yval) levels = array('d', [0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5]) contour_hist.SetContour(len(levels), levels) contour_hist.SetLineColor(ROOT.kRed) do_2D_plot_with_contours( grab_obj(os.path.join(mgpythia_dir, qgc.QCD_FILENAME), this_hist), contour_hist, output_filename="%s/constituent_plots/%s_mgpythia_norm%s%s.%s" % (plot_dir, plotname, renorm, log_append, OUTPUT_FMT), renorm_axis=renorm, title="MG+Pythia, %d < p_{T}^{j} < %d GeV" % (jet_pt_min, jet_pt_max), rebin=rebin, recolour=True, xlim=xlim, ylim=ylim, logz=logz) do_2D_plot_with_contours( grab_obj(os.path.join(pythia_only_dir, qgc.QCD_FILENAME), this_hist), contour_hist, output_filename="%s/constituent_plots/%s_pythiaOnly_norm%s%s.%s" % (plot_dir, plotname, renorm, log_append, OUTPUT_FMT), renorm_axis=renorm, title="Pythia only, %d < p_{T}^{j} < %d GeV" % (jet_pt_min, jet_pt_max), rebin=rebin, recolour=True, xlim=xlim, ylim=ylim, logz=logz) # Do 1D projection plots for (jet_pt_min, jet_pt_max) in jet_pt_vals: lw = 2 dirname = "Dijet_genjet" jet_type = "g" plotname = jet_type + "genjet_constituent_zi_vs_constituent_thetai_pt%dto%d" % ( jet_pt_min, jet_pt_max) this_hist = os.path.join(dirname, plotname) # Do projection plots for various zi bins cut_zi_bins = [(0, 0.001), (0, 0.005), (0, 0.01), (0, 0.05), (0.05, 0.1), (0, 0.1), (0.1, 0.2), (0.3, 0.4), (0.4, 0.5), (0.8, 1.0), (0, 1)] for i, (start_val, end_val) in enumerate(cut_zi_bins): entries_normal = [] h2d_mgpythia = grab_obj( os.path.join(mgpythia_dir, qgc.QCD_FILENAME), this_hist) mgpythia_kwargs = dict(line_color=qgc.QCD_COLOUR, fill_color=qgc.QCD_COLOUR, label="MG+Pythia", line_width=lw) entries_normal.append( (qgg.get_projection_plot(h2d_mgpythia, start_val, end_val, 'y'), mgpythia_kwargs)) h2d_pythiaonly = grab_obj( os.path.join(pythia_only_dir, qgc.QCD_FILENAME), this_hist) pythiaonly_kwargs = dict(line_color=ROOT.kRed, fill_color=ROOT.kRed, label="Pythia only", line_width=lw) entries_normal.append( (qgg.get_projection_plot(h2d_pythiaonly, start_val, end_val, 'y'), pythiaonly_kwargs)) ofilename = jet_type + "genjet_constituent_thetai_binned_zi%gto%g_jetPt%dto%d" % ( start_val, end_val, jet_pt_min, jet_pt_max) rebin = 5 if end_val <= 0.1 else 2 xlim = None if end_val <= 0.1 else [0, 0.6] if end_val >= 1: rebin = 4 xlim = [0, 1.2] qgg.do_comparison_plot( entries_normal, "%s/constituent_plots/%s.%s" % (plot_dir, ofilename, OUTPUT_FMT), rebin=rebin, title="%g < z_{i} < %g, %d < p_{T}^{jet} < %d GeV" % (start_val, end_val, jet_pt_min, jet_pt_max), xtitle="#theta_{i}", xlim=xlim, ylim=None, subplot_type="ratio", subplot_title="#splitline{Ratio wrt}{MG+Pythia}") # Do projections hists for various theta_i bins cut_thetai_bins = [(0, 0.01), (0.01, 0.02), (0.02, 0.05), (0.05, 0.10), (0.1, 0.15), (0.15, 0.2), (0.2, 0.3), (0.3, 0.4), (0.4, 0.6), (0.6, 0.8), (0.8, 1), (1, 1.5), (0, 2)][-1:] deltas = [] delta_components = [] colours = [ ROOT.kBlue, ROOT.kRed, ROOT.kGreen + 2, ROOT.kOrange - 3, ROOT.kMagenta, ROOT.kAzure + 1 ] for i, (start_val, end_val) in enumerate(cut_thetai_bins[::]): entries_normal = [] h2d_mgpythia = grab_obj( os.path.join(mgpythia_dir, qgc.QCD_FILENAME), this_hist) mgpythia_kwargs = dict(line_color=qgc.QCD_COLOUR, fill_color=qgc.QCD_COLOUR, label="MG+Pythia", line_width=lw) h_mgpythia = qgg.get_projection_plot(h2d_mgpythia, start_val, end_val, 'x') h_mgpythia.Rebin(4) entries_normal.append( (h_mgpythia.Clone(ROOT.TUUID().AsString()), mgpythia_kwargs)) h2d_pythiaonly = grab_obj( os.path.join(pythia_only_dir, qgc.QCD_FILENAME), this_hist) pythiaonly_kwargs = dict(line_color=ROOT.kRed, fill_color=ROOT.kRed, label="Pythia only", line_width=lw) h_pythiaonly = qgg.get_projection_plot(h2d_pythiaonly, start_val, end_val, 'x') h_pythiaonly.Rebin(4) entries_normal.append((h_pythiaonly.Clone(ROOT.TUUID().AsString()), pythiaonly_kwargs)) # rebin = 5 if end_val <= 0.1 else 2 rebin = None xlim = [0, 0.5] if end_val <= 0.1 else [0, 0.2] if end_val == 2: xlim = [0, 0.2] ofilename = jet_type + "genjet_constituent_zi_binned_thetai%gto%g_jetPt%dto%d" % ( start_val, end_val, jet_pt_min, jet_pt_max) qgg.do_comparison_plot( entries_normal, "%s/constituent_plots/%s.%s" % (plot_dir, ofilename, OUTPUT_FMT), rebin=rebin, title="%g < #theta_{i} < %g, %d < p_{T}^{jet} < %d GeV" % (start_val, end_val, jet_pt_min, jet_pt_max), xtitle="z_{i}", xlim=xlim, subplot_type="ratio", subplot_title="#splitline{Ratio wrt}{MG+Pythia}") ddelta_hist = qgd.get_ddelta_plot(h_mgpythia, h_pythiaonly) this_colour = colours[i % len(colours)] line_style = 1 + i // len(colours) c = Contribution(ddelta_hist, label="%g-%g" % (start_val, end_val), line_width=1, line_style=line_style, marker_color=this_colour, line_color=this_colour, fill_color=this_colour) delta_components.append(c) deltas.append(qgd.calculate_delta(ddelta_hist)) p = Plot(delta_components, what="hist", ytitle="p.d.f", xlim=[0, 0.2], title="%d < p_{T}^{jet} < %d GeV" % (jet_pt_min, jet_pt_max)) p.plot("NOSTACK HISTE") p.save("%s/constituent_plots/ddelta_thetai_jetPt%dto%d.%s" % (plot_dir, jet_pt_min, jet_pt_max, OUTPUT_FMT)) gr = qgd.construct_deltas_graph(deltas[::]) c = Contribution(gr, label="BLAH", marker_style=0) graph_contribs = [] graph_contribs.append(c) bin_labels = ["{:g} - {:g}".format(*b) for b in cut_thetai_bins] qgd.do_deltas_plot(graph_contribs, "%s/constituent_plots/delta_thetai_jetPt%dto%d.%s" % (plot_dir, jet_pt_min, jet_pt_max, OUTPUT_FMT), bin_labels=bin_labels, title="%d < p_{T}^{jet} < %d GeV" % (jet_pt_min, jet_pt_max), xtitle="#theta_{i}")
def do_plots(root_dir, title): # QG variable plots pt_bins = qgc.PT_BINS[:] var_list = qgc.COMMON_VARS var_prepend = "" radius, pus = cu.get_jet_config_from_dirname(root_dir) jet_str = "AK%s PF %s" % (radius.upper(), pus.upper()) for gr_append in ["", "_groomed"][:1]: if gr_append == "_groomed": print("Doing groomed plots...") else: print("Doing ungroomed plots...") zpj_dirname = "ZPlusJets_QG%s" % (gr_append) dj_cen_dirname = "Dijet_QG_central_tighter%s" % (gr_append) dj_fwd_dirname = "Dijet_QG_forward_tighter%s" % (gr_append) for ang in var_list[:]: print("...Doing", ang.name) v = "%s%s_vs_pt" % (var_prepend, ang.var) zpj_2d_entries = [] dijet_cen_2d_entries = [] dijet_fwd_2d_entries = [] zpj_1d_entries = [] dijet_cen_1d_entries = [] dijet_fwd_1d_entries = [] for pt_ind, (start_val, end_val) in enumerate(pt_bins): entries = [] zpj_entries = [] dijet_cen_entries = [] dijet_fwd_entries = [] # Get all plots lw = 2 msize = 1.1 data_line_width = lw mc_msize = 1E-3 # small enough to not be seen but not 0 - otherwise the horizontal lines on error bars don't get drawn mgpy_label = "MG5+Pythia8" hpp_label = "Herwig++" #################### # Z+JETS REGION #################### # TODO: add these # SINGLE MU DATA # if os.path.isfile(os.path.join(root_dir, qgc.SINGLE_MU_FILENAME)): # h2d_dyj_data = grab_obj(os.path.join(root_dir, qgc.SINGLE_MU_FILENAME), "%s/%s" % (zpj_dirname, v)) # dy_kwargs_data = dict(line_color=qgc.SINGLE_MU_COLOUR, line_width=data_line_width, fill_color=qgc.SINGLE_MU_COLOUR, # marker_color=qgc.SINGLE_MU_COLOUR, marker_style=cu.Marker.get(qgc.DY_MARKER), marker_size=msize*0.7, # label="Data") # zpj_data_hist = qgp.get_projection_plot(h2d_dyj_data, start_val, end_val) # entries.append((zpj_data_hist, dy_kwargs_data)) # zpj_entries.append((zpj_data_hist, dy_kwargs_data)) # if pt_ind == 0: # zpj_2d_entries.append((h2d_dyj_data, dy_kwargs_data)) # # PYTHIA DY MC # if os.path.isfile(os.path.join(root_dir, qgc.DY_FILENAME)): # h2d_dyj_mc = grab_obj(os.path.join(root_dir, qgc.DY_FILENAME), "%s/%s" % (zpj_dirname, v)) # dy_kwargs_mc = dict(line_color=qgc.DY_COLOUR, line_width=lw, fill_color=qgc.DY_COLOUR, # marker_color=qgc.DY_COLOUR, marker_style=cu.Marker.get(qgc.DY_MARKER), marker_size=mc_msize, # label=mgpy_label, # subplot=zpj_data_hist) # entries.append((qgp.get_projection_plot(h2d_dyj_mc, start_val, end_val), dy_kwargs_mc)) # zpj_entries.append((qgp.get_projection_plot(h2d_dyj_mc, start_val, end_val), dy_kwargs_mc)) # if pt_ind == 0: # zpj_2d_entries.append((h2d_dyj_mc, dy_kwargs_mc)) # # HERWIG++ DY # if os.path.isfile(os.path.join(root_dir, qgc.DY_HERWIG_FILENAME)): # h2d_dyj_mc_hpp = grab_obj(os.path.join(root_dir, qgc.DY_HERWIG_FILENAME), "%s/%s" % (zpj_dirname, v)) # col_hpp = qgc.DY_COLOURS[2] # dy_kwargs_mc_hpp = dict(line_color=col_hpp, line_width=lw, fill_color=col_hpp, # marker_color=col_hpp, marker_style=cu.Marker.get(qgc.DY_MARKER), marker_size=mc_msize, # label=hpp_label, # subplot=zpj_data_hist) # entries.append((qgp.get_projection_plot(h2d_dyj_mc_hpp, start_val, end_val), dy_kwargs_mc_hpp)) # zpj_entries.append((qgp.get_projection_plot(h2d_dyj_mc_hpp, start_val, end_val), dy_kwargs_mc_hpp)) # if pt_ind == 0: # zpj_2d_entries.append((h2d_dyj_mc_hpp, dy_kwargs_mc_hpp)) # MG+HERWIG++ DY # if end_val < 151: # h2d_dyj_mc3 = grab_obj(os.path.join(root_dir, qgc.DY_MG_HERWIG_FILENAME), "%s/%s" % (zpj_dirname, v)) # col4 = qgc.DY_COLOURS[3] # dy_kwargs_mc3 = dict(line_color=col4, line_width=lw, fill_color=col4, # marker_color=col4, marker_style=cu.Marker.get(qgc.DY_MARKER), marker_size=0, # label="MG+Herwig++", # subplot=zpj_data_hist) # entries.append((qgp.get_projection_plot(h2d_dyj_mc3, start_val, end_val), dy_kwargs_mc3)) # zpj_entries.append((qgp.get_projection_plot(h2d_dyj_mc3, start_val, end_val), dy_kwargs_mc3)) # if pt_ind == 0: # zpj_2d_entries.append((h2d_dyj_mc3, dy_kwargs_mc3)) # else: # zpj_entries.append(None) #################### # DIJET CENTRAL REGION #################### # JETHT/ZEROBIAS DATA if os.path.isfile(os.path.join(root_dir, qgc.JETHT_ZB_FILENAME)): h2d_qcd_cen_data = grab_obj( os.path.join(root_dir, qgc.JETHT_ZB_FILENAME), "%s/%s" % (dj_cen_dirname, v)) # use already merged jetht+zb qcd_cen_kwargs_data = dict(line_color=qgc.JETHT_COLOUR, line_width=data_line_width, fill_color=qgc.JETHT_COLOUR, marker_color=qgc.JETHT_COLOUR, marker_style=cu.Marker.get( qgc.QCD_MARKER), marker_size=msize, label="Data") dijet_cen_data_hist = qgp.get_projection_plot( h2d_qcd_cen_data, start_val, end_val) entries.append((dijet_cen_data_hist, qcd_cen_kwargs_data)) dijet_cen_entries.append( (dijet_cen_data_hist, qcd_cen_kwargs_data)) if pt_ind == 0: dijet_cen_2d_entries.append( (h2d_qcd_cen_data, qcd_cen_kwargs_data)) # MG+PYTHIA QCD MC if os.path.isfile(os.path.join(root_dir, qgc.QCD_FILENAME)): h2d_qcd_cen_mc = grab_obj( os.path.join(root_dir, qgc.QCD_FILENAME), "%s/%s" % (dj_cen_dirname, v)) qcd_cen_kwargs_mc = dict( line_color=qgc.QCD_COLOUR, line_width=lw, fill_color=qgc.QCD_COLOUR, marker_color=qgc.QCD_COLOUR, marker_style=cu.Marker.get(qgc.QCD_MARKER), marker_size=mc_msize, label=mgpy_label + "\n[NNPDF30_lo_as_0130, default]", subplot=dijet_cen_data_hist) dijet_mgpy_hist = qgp.get_projection_plot( h2d_qcd_cen_mc, start_val, end_val) entries.append((dijet_mgpy_hist, qcd_cen_kwargs_mc)) dijet_cen_entries.append( (dijet_mgpy_hist, qcd_cen_kwargs_mc)) if pt_ind == 0: dijet_cen_2d_entries.append( (h2d_qcd_cen_mc, qcd_cen_kwargs_mc)) # Add NNPDF30_lo_as_0118 fname = "uhh2.AnalysisModuleRunner.MC.MC_QCD_NNPDF30_lo_as_0118.root" if os.path.isfile(os.path.join(root_dir, fname)): h2d_qcd_cen_mc_pdf2 = grab_obj( os.path.join(root_dir, fname), "%s/%s" % (dj_cen_dirname, v)) col = qgc.QCD_COLOURS[4] qcd_cen_kwargs_mc2 = dict( line_color=col, line_width=lw, fill_color=col, marker_color=col, marker_style=cu.Marker.get(qgc.QCD_MARKER), marker_size=mc_msize, label=mgpy_label + "\n[NNPDF30_lo_as_0118]", subplot=dijet_cen_data_hist) dijet_mgpy_hist2 = qgp.get_projection_plot( h2d_qcd_cen_mc_pdf2, start_val, end_val) entries.append((dijet_mgpy_hist2, qcd_cen_kwargs_mc2)) dijet_cen_entries.append( (dijet_mgpy_hist2, qcd_cen_kwargs_mc2)) if pt_ind == 0: dijet_cen_2d_entries.append( (h2d_qcd_cen_mc_pdf2, qcd_cen_kwargs_mc2)) # Add HERAPDF20_LO_EIG fname = "uhh2.AnalysisModuleRunner.MC.MC_QCD_HERAPDF20_LO_EIG.root" if os.path.isfile(os.path.join(root_dir, fname)): h2d_qcd_cen_mc_pdf3 = grab_obj( os.path.join(root_dir, fname), "%s/%s" % (dj_cen_dirname, v)) col = qgc.QCD_COLOURS[5] qcd_cen_kwargs_mc3 = dict( line_color=col, line_width=lw, fill_color=col, marker_color=col, marker_style=cu.Marker.get(qgc.QCD_MARKER), marker_size=mc_msize, label=mgpy_label + "\n[HERAPDF20_LO_EIG]", subplot=dijet_cen_data_hist) dijet_mgpy_hist3 = qgp.get_projection_plot( h2d_qcd_cen_mc_pdf3, start_val, end_val) entries.append((dijet_mgpy_hist3, qcd_cen_kwargs_mc3)) dijet_cen_entries.append( (dijet_mgpy_hist3, qcd_cen_kwargs_mc3)) if pt_ind == 0: dijet_cen_2d_entries.append( (h2d_qcd_cen_mc_pdf3, qcd_cen_kwargs_mc3)) # Add CT14lo fname = "uhh2.AnalysisModuleRunner.MC.MC_QCD_CT14lo.root" if os.path.isfile(os.path.join(root_dir, fname)): h2d_qcd_cen_mc_pdf4 = grab_obj( os.path.join(root_dir, fname), "%s/%s" % (dj_cen_dirname, v)) col = qgc.QCD_COLOURS[6] qcd_cen_kwargs_mc4 = dict(line_color=col, line_width=lw, fill_color=col, marker_color=col, marker_style=cu.Marker.get( qgc.QCD_MARKER), marker_size=mc_msize, label=mgpy_label + "\n[CT14lo]", subplot=dijet_cen_data_hist) dijet_mgpy_hist4 = qgp.get_projection_plot( h2d_qcd_cen_mc_pdf4, start_val, end_val) entries.append((dijet_mgpy_hist4, qcd_cen_kwargs_mc4)) dijet_cen_entries.append( (dijet_mgpy_hist4, qcd_cen_kwargs_mc4)) if pt_ind == 0: dijet_cen_2d_entries.append( (h2d_qcd_cen_mc_pdf4, qcd_cen_kwargs_mc4)) # PYTHIA ONLY # if os.path.isfile(os.path.join(root_dir, qgc.QCD_PYTHIA_ONLY_FILENAME)): # col = qgc.QCD_COLOURS[2] # h2d_qcd_cen_mc2 = grab_obj(os.path.join(root_dir, qgc.QCD_PYTHIA_ONLY_FILENAME), "%s/%s" % (dj_cen_dirname, v)) # qcd_cen_kwargs_mc2 = dict(line_color=col, line_width=lw, fill_color=col, # marker_color=col, marker_style=cu.Marker.get(qgc.QCD_MARKER), marker_size=mc_msize, # label="Pythia8", # subplot=dijet_cen_data_hist) # entries.append((qgp.get_projection_plot(h2d_qcd_cen_mc2, start_val, end_val), qcd_cen_kwargs_mc2)) # dijet_cen_entries.append((qgp.get_projection_plot(h2d_qcd_cen_mc2, start_val, end_val), qcd_cen_kwargs_mc2)) # if pt_ind == 0: # dijet_cen_2d_entries.append((h2d_qcd_cen_mc2, qcd_cen_kwargs_mc2)) # HERWIG++ QCD if os.path.isfile( os.path.join(root_dir, qgc.QCD_HERWIG_FILENAME)): col_hpp = qgc.QCD_COLOURS[3] h2d_qcd_cen_mc_hpp = grab_obj( os.path.join(root_dir, qgc.QCD_HERWIG_FILENAME), "%s/%s" % (dj_cen_dirname, v)) qcd_cen_kwargs_mc_hpp = dict(line_color=col_hpp, line_width=lw, fill_color=col_hpp, marker_color=col_hpp, marker_style=cu.Marker.get( qgc.QCD_MARKER), marker_size=mc_msize, label=hpp_label, subplot=dijet_cen_data_hist) dijet_hpp_hist = qgp.get_projection_plot( h2d_qcd_cen_mc_hpp, start_val, end_val) entries.append((dijet_hpp_hist, qcd_cen_kwargs_mc_hpp)) dijet_cen_entries.append( (dijet_hpp_hist, qcd_cen_kwargs_mc_hpp)) if pt_ind == 0: dijet_cen_2d_entries.append( (h2d_qcd_cen_mc_hpp, qcd_cen_kwargs_mc_hpp)) #################### # DIJET FORWARD REGION #################### # JETHT/ZEROBIAS DATA if os.path.isfile(os.path.join(root_dir, qgc.JETHT_ZB_FILENAME)): h2d_qcd_fwd_data = grab_obj( os.path.join(root_dir, qgc.JETHT_ZB_FILENAME), "%s/%s" % (dj_fwd_dirname, v)) # use already merged jetht+zb qcd_fwd_kwargs_data = dict( line_color=qgc.JETHT_COLOUR, line_width=data_line_width, fill_color=qgc.JETHT_COLOUR, marker_color=qgc.JETHT_COLOUR, marker_style=cu.Marker.get('triangleDown'), marker_size=msize, label="Data") dijet_fwd_data_hist = qgp.get_projection_plot( h2d_qcd_fwd_data, start_val, end_val) entries.append((dijet_fwd_data_hist, qcd_fwd_kwargs_data)) dijet_fwd_entries.append( (dijet_fwd_data_hist, qcd_fwd_kwargs_data)) if pt_ind == 0: dijet_fwd_2d_entries.append( (h2d_qcd_fwd_data, qcd_fwd_kwargs_data)) # MG+PYTHIA QCD MC if os.path.isfile(os.path.join(root_dir, qgc.QCD_FILENAME)): h2d_qcd_fwd_mc = grab_obj( os.path.join(root_dir, qgc.QCD_FILENAME), "%s/%s" % (dj_fwd_dirname, v)) qcd_fwd_kwargs_mc = dict( line_color=qgc.QCD_COLOUR, line_width=lw, fill_color=qgc.QCD_COLOUR, marker_color=qgc.QCD_COLOUR, marker_style=cu.Marker.get(qgc.QCD_MARKER), marker_size=mc_msize, label=mgpy_label + "\n[NNPDF30_lo_as_0130, default]", subplot=dijet_fwd_data_hist) dijet_mgpy_hist = qgp.get_projection_plot( h2d_qcd_fwd_mc, start_val, end_val) entries.append((dijet_mgpy_hist, qcd_fwd_kwargs_mc)) dijet_fwd_entries.append( (dijet_mgpy_hist, qcd_fwd_kwargs_mc)) if pt_ind == 0: dijet_fwd_2d_entries.append( (h2d_qcd_fwd_mc, qcd_fwd_kwargs_mc)) # Add NNPDF30_lo_as_0118 fname = "uhh2.AnalysisModuleRunner.MC.MC_QCD_NNPDF30_lo_as_0118.root" if os.path.isfile(os.path.join(root_dir, fname)): h2d_qcd_fwd_mc_pdf2 = grab_obj( os.path.join(root_dir, fname), "%s/%s" % (dj_fwd_dirname, v)) col = qgc.QCD_COLOURS[4] qcd_fwd_kwargs_mc2 = dict( line_color=col, line_width=lw, fill_color=col, marker_color=col, marker_style=cu.Marker.get(qgc.QCD_MARKER), marker_size=mc_msize, label=mgpy_label + "\n[NNPDF30_lo_as_0118]", subplot=dijet_fwd_data_hist) dijet_mgpy_hist2 = qgp.get_projection_plot( h2d_qcd_fwd_mc_pdf2, start_val, end_val) entries.append((dijet_mgpy_hist2, qcd_fwd_kwargs_mc2)) dijet_fwd_entries.append( (dijet_mgpy_hist2, qcd_fwd_kwargs_mc2)) if pt_ind == 0: dijet_fwd_2d_entries.append( (h2d_qcd_fwd_mc_pdf2, qcd_fwd_kwargs_mc2)) # Add HERAPDF20_LO_EIG fname = "uhh2.AnalysisModuleRunner.MC.MC_QCD_HERAPDF20_LO_EIG.root" if os.path.isfile(os.path.join(root_dir, fname)): h2d_qcd_fwd_mc_pdf3 = grab_obj( os.path.join(root_dir, fname), "%s/%s" % (dj_fwd_dirname, v)) col = qgc.QCD_COLOURS[5] qcd_fwd_kwargs_mc3 = dict( line_color=col, line_width=lw, fill_color=col, marker_color=col, marker_style=cu.Marker.get(qgc.QCD_MARKER), marker_size=mc_msize, label=mgpy_label + "\n[HERAPDF20_LO_EIG]", subplot=dijet_fwd_data_hist) dijet_mgpy_hist3 = qgp.get_projection_plot( h2d_qcd_fwd_mc_pdf3, start_val, end_val) entries.append((dijet_mgpy_hist3, qcd_fwd_kwargs_mc3)) dijet_fwd_entries.append( (dijet_mgpy_hist3, qcd_fwd_kwargs_mc3)) if pt_ind == 0: dijet_fwd_2d_entries.append( (h2d_qcd_fwd_mc_pdf3, qcd_fwd_kwargs_mc3)) # Add CT14lo fname = "uhh2.AnalysisModuleRunner.MC.MC_QCD_CT14lo.root" if os.path.isfile(os.path.join(root_dir, fname)): h2d_qcd_fwd_mc_pdf4 = grab_obj( os.path.join(root_dir, fname), "%s/%s" % (dj_fwd_dirname, v)) col = qgc.QCD_COLOURS[6] qcd_fwd_kwargs_mc4 = dict(line_color=col, line_width=lw, fill_color=col, marker_color=col, marker_style=cu.Marker.get( qgc.QCD_MARKER), marker_size=mc_msize, label=mgpy_label + "\n[CT14lo]", subplot=dijet_fwd_data_hist) dijet_mgpy_hist4 = qgp.get_projection_plot( h2d_qcd_fwd_mc_pdf4, start_val, end_val) entries.append((dijet_mgpy_hist4, qcd_fwd_kwargs_mc4)) dijet_fwd_entries.append( (dijet_mgpy_hist4, qcd_fwd_kwargs_mc4)) if pt_ind == 0: dijet_fwd_2d_entries.append( (h2d_qcd_fwd_mc_pdf4, qcd_fwd_kwargs_mc4)) # PYTHIA ONLY # if os.path.isfile(os.path.join(root_dir, qgc.QCD_PYTHIA_ONLY_FILENAME)): # col = qgc.QCD_COLOURS[2] # h2d_qcd_fwd_mc2 = grab_obj(os.path.join(root_dir, qgc.QCD_PYTHIA_ONLY_FILENAME), "%s/%s" % (dj_fwd_dirname, v)) # qcd_fwd_kwargs_mc2 = dict(line_color=col, line_width=lw, fill_color=col, # marker_color=col, marker_style=cu.Marker.get(qgc.QCD_MARKER), marker_size=mc_msize, # label="Pythia8", # subplot=dijet_fwd_data_hist) # entries.append((qgp.get_projection_plot(h2d_qcd_fwd_mc2, start_val, end_val), qcd_fwd_kwargs_mc2)) # dijet_fwd_entries.append((qgp.get_projection_plot(h2d_qcd_fwd_mc2, start_val, end_val), qcd_fwd_kwargs_mc2)) # if pt_ind == 0: # dijet_fwd_2d_entries.append((h2d_qcd_fwd_mc2, qcd_fwd_kwargs_mc2)) # HERWIG++ QCD if os.path.isfile( os.path.join(root_dir, qgc.QCD_HERWIG_FILENAME)): col_hpp = qgc.QCD_COLOURS[3] h2d_qcd_fwd_mc_hpp = grab_obj( os.path.join(root_dir, qgc.QCD_HERWIG_FILENAME), "%s/%s" % (dj_fwd_dirname, v)) qcd_fwd_kwargs_mc_hpp = dict(line_color=col_hpp, line_width=lw, fill_color=col_hpp, marker_color=col_hpp, marker_style=cu.Marker.get( qgc.QCD_MARKER), marker_size=mc_msize, label=hpp_label, subplot=dijet_fwd_data_hist) dijet_hpp_hist = qgp.get_projection_plot( h2d_qcd_fwd_mc_hpp, start_val, end_val) entries.append((dijet_hpp_hist, qcd_fwd_kwargs_mc_hpp)) dijet_fwd_entries.append( (dijet_hpp_hist, qcd_fwd_kwargs_mc_hpp)) if pt_ind == 0: dijet_fwd_2d_entries.append( (h2d_qcd_fwd_mc_hpp, qcd_fwd_kwargs_mc_hpp)) zpj_1d_entries.append(zpj_entries) dijet_cen_1d_entries.append(dijet_cen_entries) dijet_fwd_1d_entries.append(dijet_fwd_entries) ################# # SETUP PLOTTING ################# rebin = 2 v_lower = v.lower() # if "multiplicity" in v_lower: # rebin = 1 # elif "flavour" in v_lower or "thrust" in v_lower: # rebin = 1 # elif 'ptd' in v_lower: # rebin = 4 # elif 'lha_charged' in v_lower: # rebin = 4 # rebin = 1 xlim = None if "width" in v_lower or "ptd" in v_lower: xlim = (0, 1) elif "thrust" in v_lower: xlim = (0, 0.5) elif "multiplicity" in v_lower and "ak4" in root_dir.lower(): if end_val <= 150: xlim = (0, 50) else: xlim = (0, 80) auto_xlim = False if "multiplicity" in v_lower or "thrust" in v_lower: auto_xlim = True ylim = [0, None] if "flavour" in v_lower: ylim = (0, 1) # elif "lha" in v_lower: # ylim = (0, 5) plot_dir = os.path.join( root_dir, "plots_lambda_mc_vs_data%s_pdf_compare" % (gr_append)) subplot_title = "Simulation / Data" subplot_limits = (0, 2) xlabel = ang.name + " (" + ang.lambda_str + ")" if gr_append is not "": xlabel = "Groomed " + ang.name + " (" + ang.lambda_str + ")" def _title(region_str, start_val, end_val): pt_var_str = "p_{T}^{jet}" s = (("{jet_algo}\n" "{region_label}\n" "{bin_edge_low:g} < {pt_str} < {bin_edge_high:g} GeV" ).format(jet_algo=jet_str, region_label=region_str, pt_str=pt_var_str, bin_edge_low=start_val, bin_edge_high=end_val)) if title is not None: s = "%s\n%s" % (s, title) return s has_data = True draw_opt = "NOSTACK HIST E1" # dj central only # dont' try to do multiple signal regions per plot, it looks rubbish if len(dijet_cen_entries) > 0: qgp.do_comparison_plot( dijet_cen_entries, "%s/ptBinned/%s_pt%dto%d_dijet_central.%s" % (plot_dir, v, start_val, end_val, OUTPUT_FMT), rebin=rebin, draw_opt=draw_opt, title=_title(qgc.Dijet_CEN_LABEL, start_val, end_val), xtitle=xlabel, xlim=qgp.calc_auto_xlim([ d[0] for d in dijet_cen_entries ]) if auto_xlim else xlim, ylim=ylim, data_first=has_data, mean_rel_error=0.4, subplot_type='ratio', subplot_title=subplot_title, subplot_limits=subplot_limits) # dj forward only if len(dijet_fwd_entries) > 0: qgp.do_comparison_plot( dijet_fwd_entries, "%s/ptBinned/%s_pt%dto%d_dijet_forward.%s" % (plot_dir, v, start_val, end_val, OUTPUT_FMT), rebin=rebin, draw_opt=draw_opt, title=_title(qgc.Dijet_FWD_LABEL, start_val, end_val), xtitle=xlabel, xlim=qgp.calc_auto_xlim([ d[0] for d in dijet_fwd_entries ]) if auto_xlim else xlim, ylim=ylim, data_first=has_data, mean_rel_error=0.4, subplot_type='ratio', subplot_title=subplot_title, subplot_limits=subplot_limits) # zpj only if len(zpj_entries) > 0: if start_val > 149: # rebin *= 2 rebin += 1 # find nearest divisor while (zpj_entries[0][0].GetNbinsX() % rebin != 0): rebin += 1 if "multiplicity" in v_lower: if start_val > 300: rebin += 1 # find nearest divisor while (zpj_entries[0][0].GetNbinsX() % rebin != 0): rebin += 1 qgp.do_comparison_plot( zpj_entries, "%s/ptBinned/%s_pt%dto%d_zpj.%s" % (plot_dir, v, start_val, end_val, OUTPUT_FMT), rebin=rebin, draw_opt=draw_opt, title=_title(qgc.ZpJ_LABEL, start_val, end_val), xtitle=xlabel, xlim=qgp.calc_auto_xlim([d[0] for d in zpj_entries]) if auto_xlim else xlim, ylim=ylim, data_first=has_data, mean_rel_error=0.4, subplot_type='ratio', subplot_title=subplot_title, subplot_limits=subplot_limits) # Do overall summary plots across all pt bins # ------------------------------------------------------------------ ylim_mean = None if "width" in v_lower or "ptd" in v_lower: ylim_mean = (0, 0.4) elif "thrust" in v_lower: ylim_mean = (0, 0.5) elif "multiplicity" in v_lower and "ak4" in root_dir.lower(): ylim_mean = (0, 100) ylim_mean = (0, 80) if end_val < 150: ylim_mean = (0, 50) ylim_mean = None ylim_rms = None # Setup variable names for MPL marker = "" if "_" in ang.name or "^" in ang.name: marker = "$" var_label = marker + ang.name + marker + " ($%s$)" % ang.lambda_str if gr_append != "": var_label = "Groomed " + marker + ang.name + marker + " ($%s$)" % ang.lambda_str
def do_plots(root_dir): # QG variable plots pt_bins = qgc.PT_BINS[:] var_list = qgc.COMMON_VARS radius, pus = cu.get_jet_config_from_dirname(root_dir) jet_str = "AK%s" % (radius.upper()) dy_tfile, qcd_tfile = None, None if os.path.isfile(os.path.join(root_dir, qgc.DY_FILENAME)): dy_tfile = cu.TFileCacher(os.path.join(root_dir, qgc.DY_FILENAME)) if os.path.isfile(os.path.join(root_dir, qgc.QCD_FILENAME)): qcd_tfile = cu.TFileCacher(os.path.join(root_dir, qgc.QCD_FILENAME)) for gr_append in ["", "_groomed"]: if gr_append == "_groomed": print("Doing groomed plots...") else: print("Doing ungroomed plots...") # GEnJets matched to recojet, reco selection zpj_dirname = "ZPlusJets_QG%s" % (gr_append) dj_cen_dirname = "Dijet_QG_central_tighter%s" % (gr_append) dj_fwd_dirname = "Dijet_QG_forward_tighter%s" % (gr_append) # Gen Jets from gen selection zpj_dirname = "ZPlusJets_QG_gen%s" % (gr_append) dj_cen_dirname = "Dijet_QG_gen_central%s" % (gr_append) dj_fwd_dirname = "Dijet_QG_gen_forward%s" % (gr_append) for ang in var_list[:]: print("...Doing", ang.name) var_template = "{prefix}%s_vs_pt" % (ang.var ) # {prefix} is for flavour for pt_ind, (start_val, end_val) in enumerate(pt_bins): zpj_entries = [] dijet_cen_entries = [] dijet_fwd_entries = [] # Get all plots lw = 2 msize = 1.1 mc_msize = 1E-3 # small enough to not be seen but not 0 - otherwise the horizontal lines on error bars don't get drawn mc_msize = msize # small enough to not be seen but not 0 - otherwise the horizontal lines on error bars don't get drawn flavours_dicts = [ { "prefix": "q", "label": "u/d/s" }, { "prefix": "g", "label": "g" }, { "prefix": "bc", "label": "b/c" }, ] if dy_tfile: # Z+JETS REGION marker = cu.Marker(qgc.DY_MARKER) for flav_dict, color, mark in zip(flavours_dicts, qgc.DY_COLOURS, marker.cycle()): h2d_dyj_mc = dy_tfile.get( "%s/%s" % (zpj_dirname, var_template.format(**flav_dict))) dy_kwargs_mc = dict(line_color=color, line_width=lw, fill_color=color, marker_color=color, marker_style=mark, marker_size=mc_msize, label="%s flavour" % (flav_dict['label']), subplot=None) zpj_entries.append( (qgp.get_projection_plot(h2d_dyj_mc, start_val, end_val), dy_kwargs_mc)) if qcd_tfile: # DIJET CENTRAL REGION marker = cu.Marker(qgc.QCD_MARKER) for flav_dict, color, mark in zip(flavours_dicts, qgc.QCD_COLOURS, marker.cycle()): h2d_qcd_cen_mc = qcd_tfile.get( "%s/%s" % (dj_cen_dirname, var_template.format(**flav_dict))) qcd_cen_kwargs_mc = dict(line_color=color, line_width=lw, fill_color=color, marker_color=color, marker_style=mark, marker_size=mc_msize, label="%s flavour" % (flav_dict['label']), subplot=None) dijet_mgpy_hist = qgp.get_projection_plot( h2d_qcd_cen_mc, start_val, end_val) dijet_cen_entries.append( (dijet_mgpy_hist, qcd_cen_kwargs_mc)) # DIJET FORWARD REGION marker = cu.Marker(qgc.QCD_MARKER) for flav_dict, color, mark in zip(flavours_dicts, qgc.QCD_COLOURS, marker.cycle()): h2d_qcd_fwd_mc = qcd_tfile.get( "%s/%s" % (dj_fwd_dirname, var_template.format(**flav_dict))) qcd_fwd_kwargs_mc = dict(line_color=color, line_width=lw, fill_color=color, marker_color=color, marker_style=mark, marker_size=mc_msize, label="%s flavour" % (flav_dict['label']), subplot=None) dijet_mgpy_hist = qgp.get_projection_plot( h2d_qcd_fwd_mc, start_val, end_val) dijet_fwd_entries.append( (dijet_mgpy_hist, qcd_fwd_kwargs_mc)) ################# # SETUP PLOTTING ################# rebin = 2 v_lower = var_template.lower() if "multiplicity" in v_lower: rebin = 1 # elif "flavour" in v_lower or "thrust" in v_lower: # rebin = 1 # elif 'ptd' in v_lower: # rebin = 4 # elif 'lha_charged' in v_lower: # rebin = 4 # rebin = 1 xlim = None if "width" in v_lower or "ptd" in v_lower: xlim = (0, 1) elif "thrust" in v_lower: xlim = (0, 0.5) # elif "multiplicity" in v_lower and "ak4" in root_dir.lower(): # if end_val <= 150: # xlim = (0, 50) # else: # xlim = (0, 80) auto_xlim = False if "multiplicity" in v_lower or "thrust" in v_lower: auto_xlim = True ylim = [0, None] if "flavour" in v_lower: ylim = (0, 1) # elif "lha" in v_lower: # ylim = (0, 5) plot_dir = os.path.join( root_dir, "plots_gen_lambda_flav_comparison%s" % (gr_append)) subplot_title = "Simulation / Data" subplot_limits = (0, 2) xlabel = ang.name + " (" + ang.lambda_str + ")" if gr_append is not "": xlabel = "Groomed " + ang.name + " (" + ang.lambda_str + ")" def _title(region_str, start_val, end_val): pt_var_str = "p_{T}^{jet}" s = (("{jet_algo}\n" "{region_label}\n" "{mc_sample}\n" "{bin_edge_low:g} < {pt_str} < {bin_edge_high:g} GeV" ).format(jet_algo=jet_str, region_label=region_str, mc_sample="MG5+Pythia8", pt_str=pt_var_str, bin_edge_low=start_val, bin_edge_high=end_val)) return s has_data = False draw_opt = "NOSTACK HIST E1" # dj central only # dont' try to do multiple signal regions per plot, it looks rubbish if len(dijet_cen_entries) > 0: qgp.do_comparison_plot( dijet_cen_entries, "%s/ptBinned/%s_pt%dto%d_dijet_central.%s" % (plot_dir, ang.var, start_val, end_val, OUTPUT_FMT), rebin=rebin, draw_opt=draw_opt, title=_title(qgc.Dijet_CEN_LABEL, start_val, end_val), xtitle=xlabel, xlim='auto' if auto_xlim else xlim, # don't use calc_auto_xlim, since do_comparison_plot will rebin it anyway ylim=ylim, data_first=has_data, mean_rel_error=0.4, subplot_type=None, lumi=cu.get_lumi_str( do_dijet=False, do_zpj=True)) # full lumi as just MC # dj forward only if len(dijet_fwd_entries) > 0: qgp.do_comparison_plot( dijet_fwd_entries, "%s/ptBinned/%s_pt%dto%d_dijet_forward.%s" % (plot_dir, ang.var, start_val, end_val, OUTPUT_FMT), rebin=rebin, draw_opt=draw_opt, title=_title(qgc.Dijet_FWD_LABEL, start_val, end_val), xtitle=xlabel, xlim='auto' if auto_xlim else xlim, ylim=ylim, data_first=has_data, mean_rel_error=0.4, subplot_type=None, lumi=cu.get_lumi_str( do_dijet=False, do_zpj=True)) # full lumi as just MC # zpj only if len(zpj_entries) > 0: if start_val > 149: # rebin *= 2 rebin += 1 # find nearest divisor while (zpj_entries[0][0].GetNbinsX() % rebin != 0): rebin += 1 if "multiplicity" in v_lower: if start_val > 300: rebin += 1 # find nearest divisor while (zpj_entries[0][0].GetNbinsX() % rebin != 0): rebin += 1 qgp.do_comparison_plot( zpj_entries, "%s/ptBinned/%s_pt%dto%d_zpj.%s" % (plot_dir, ang.var, start_val, end_val, OUTPUT_FMT), rebin=rebin, draw_opt=draw_opt, title=_title(qgc.ZpJ_LABEL, start_val, end_val), xtitle=xlabel, xlim=qgp.calc_auto_xlim([d[0] for d in zpj_entries]) if auto_xlim else xlim, ylim=ylim, data_first=has_data, mean_rel_error=0.4, subplot_type=None, lumi=cu.get_lumi_str(do_dijet=False, do_zpj=True))
def do_1D_plot(hists, components_styles_dicts, output_filename, do_ratio=True, logx=False, logy=False, normalise_hists=True, title="", xtitle=None, mean_rel_error=0.4, data_first=True, show_integrals=False, lumi=cu.get_lumi_str(do_dijet=False, do_zpj=True)): if (len(hists) != len(components_styles_dicts)): raise RuntimeError("# hists != # components_styles_dicts (%d vs %d)" % (len(hists), len(components_styles_dicts))) if len(hists) == 0: return # Ignore if all empty objs total_entries = sum(h.GetEntries() for h in hists) if total_entries == 0: print("WARNING: all plots have 0 entries") return do_ratio = (do_ratio and len(hists) > 1) entries = [] components_styles_dicts = deepcopy(components_styles_dicts) for h, csd in zip(hists, components_styles_dicts): if show_integrals: csd['label'] += "\nIntegral = {:.4g}".format(h.Integral()) entries.append((h.Clone(cu.get_unique_str()), csd)) # print("Auto y limits:", min_val, max_val) ylim = None # if not normalise_hists: # min_val, min_bin, max_val, max_bin = cu.get_min_max_bin_contents_multiple_hists(hists) # if logy: # ylim = [0.5*min_val, 50*max_val] # else: # # ylim = [0.5*min_val, 1.5*max_val] # ylim = [0, 1.5*max_val] xlim = "auto" # Auto calc x limits to avoid lots of empty bins draw_opt = "NOSTACK HIST E1" subplot_title = "Simulation / Data" subplot_limits = (0, 2) if logy else (0.5, 1.5) # subplot_limits = [0.5, None] subplot_limits = None qgp.do_comparison_plot( entries, output_filename, # rebin=rebin, normalise_hist=normalise_hists, draw_opt=draw_opt, title=title, xtitle=xtitle, xlim=xlim, ylim=ylim, logx=logx, logy=logy, mean_rel_error=mean_rel_error, data_first=data_first, subplot_type='ratio' if do_ratio else None, subplot_title=subplot_title, subplot=entries[0][0] if do_ratio else None, subplot_limits=subplot_limits, lumi=lumi)
subplot_title = "Nominal / No SF" subplot_limits = (0.5, 1.5) xlabel = ang.name + " (" + ang.lambda_str + ")" if gr_append is not "": xlabel = "Groomed " + ang.name + " (" + ang.lambda_str + ")" # dj central only qgp.do_comparison_plot( dijet_cen_no_vs_nominal_sf_entries, "%s/ptBinned/%s_pt%dto%d_dijet_central.%s" % (plot_dir, v, start_val, end_val, OUTPUT_FMT), rebin=rebin, title="%d < p_{T}^{jet} < %d GeV\n%s\n%s" % (start_val, end_val, jet_str, qgc.Dijet_CEN_LABEL), xtitle=xlabel, xlim=xlim, ylim=ylim, has_data=False, subplot_type='ratio', subplot_title=subplot_title, subplot_limits=subplot_limits) # dj forward only qgp.do_comparison_plot( dijet_fwd_no_vs_nominal_sf_entries, "%s/ptBinned/%s_pt%dto%d_dijet_forward.%s" % (plot_dir, v, start_val, end_val, OUTPUT_FMT), rebin=rebin, title="%d < p_{T}^{jet} < %d GeV\n%s\n%s" % (start_val, end_val, jet_str, qgc.Dijet_FWD_LABEL),
def do_wrong_plots(root_dir, var_prepend="", plot_dir="wrong_flavs", zpj_dirname="ZPlusJets_QG", dj_dirname="Dijet_QG", pt_bins=None, title=""): """Plot all the sample/selection/flavour combinations to check distributions indep of sample""" pt_bins = pt_bins or qgc.THEORY_PT_BINS plot_vars = [ 'jet_LHA', 'jet_pTD', 'jet_width', 'jet_thrust', 'jet_multiplicity' ] if "puppi" in root_dir.lower(): plot_vars.append('jet_puppiMultiplicity') for v in plot_vars: v = "%s%s_vs_pt" % (var_prepend, v) h2d_dyj_chs = grab_obj(os.path.join(root_dir, qgc.DY_FILENAME), "%s/q%s" % (zpj_dirname, v)) h2d_dyj_wrong_chs = grab_obj(os.path.join(root_dir, qgc.DY_FILENAME), "%s/g%s" % (zpj_dirname, v)) h2d_dyj_qcd_chs = grab_obj(os.path.join(root_dir, qgc.DY_FILENAME), "%s/q%s" % (dj_dirname, v)) h2d_dyj_qcd_wrong_chs = grab_obj( os.path.join(root_dir, qgc.DY_FILENAME), "%s/g%s" % (dj_dirname, v)) h2d_qcd_chs = grab_obj(os.path.join(root_dir, qgc.QCD_FILENAME), "%s/g%s" % (dj_dirname, v)) h2d_qcd_wrong_chs = grab_obj(os.path.join(root_dir, qgc.QCD_FILENAME), "%s/q%s" % (dj_dirname, v)) lw = 1 dy_kwargs_chs = dict(line_color=qgc.DY_COLOUR, fill_color=qgc.DY_COLOUR, label=qgc.DY_ZpJ_QFLAV_LABEL, line_width=lw, marker_style=20, marker_color=qgc.DY_COLOUR) dy_kwargs_wrong_chs = dict(line_color=qgc.DY_COLOUR + 4, fill_color=qgc.DY_COLOUR + 4, label=qgc.DY_ZpJ_GFLAV_LABEL, line_width=lw, line_style=1, marker_style=21, marker_color=qgc.DY_COLOUR + 4) dy_kwargs_qcd_chs = dict(line_color=ROOT.kGreen + 2, fill_color=ROOT.kGreen + 2, label=qgc.DY_Dijet_QFLAV_LABEL, line_width=lw, line_style=1, marker_style=22, marker_color=ROOT.kGreen + 2) dy_kwargs_qcd_wrong_chs = dict(line_color=ROOT.kOrange - 1, fill_color=ROOT.kOrange - 1, label=qgc.DY_Dijet_GFLAV_LABEL, line_width=lw, line_style=1, marker_style=23, marker_color=ROOT.kOrange - 1) qcd_kwargs_chs = dict(line_color=qgc.QCD_COLOUR, fill_color=qgc.QCD_COLOUR, label=qgc.QCD_Dijet_GFLAV_LABEL, line_width=lw, marker_style=25, marker_color=qgc.QCD_COLOUR) qcd_kwargs_wrong_chs = dict(line_color=ROOT.kRed, fill_color=ROOT.kRed, label=qgc.QCD_Dijet_QFLAV_LABEL, line_width=lw, line_style=1, marker_style=24, marker_color=ROOT.kRed) rebin = 2 xlim = None if "thrust" in v: rebin = 1 xlim = (0, 0.5) if "multiplicity" in v.lower(): rebin = 2 xlim = (0, 100) for (start_val, end_val) in pt_bins: entries = [ (qgg.get_projection_plot(h2d_dyj_chs, start_val, end_val), dy_kwargs_chs), (qgg.get_projection_plot(h2d_dyj_wrong_chs, start_val, end_val), dy_kwargs_wrong_chs), # (qgg.get_projection_plot(h2d_dyj_qcd_chs, start_val, end_val), dy_kwargs_qcd_chs), # (qgg.get_projection_plot(h2d_dyj_qcd_wrong_chs, start_val, end_val), dy_kwargs_qcd_wrong_chs), (qgg.get_projection_plot(h2d_qcd_wrong_chs, start_val, end_val), qcd_kwargs_wrong_chs), (qgg.get_projection_plot(h2d_qcd_chs, start_val, end_val), qcd_kwargs_chs), ] this_title = "%d < p_{T}^{jet} < %d GeV" % (start_val, end_val) if title != "": this_title += ", %s" % title qgg.do_comparison_plot( entries, "%s/%s/%s_pt%dto%d_flavMatched.%s" % (root_dir, plot_dir, v, start_val, end_val, OUTPUT_FMT), rebin=rebin, title=this_title, xlim=xlim)
def do_plots(root_dir, title): # QG variable plots pt_bins = qgc.PT_BINS[:] print(pt_bins) var_list = qgc.COMMON_VARS var_prepend = "" radius, pus = cu.get_jet_config_from_dirname(root_dir) jet_str = "AK%s PF %s" % (radius.upper(), pus.upper()) if radius == "8": pt_bins = qgc.PT_BINS[2:] print(pt_bins) single_mu_tfile = cu.TFileCacher(os.path.join(root_dir, qgc.SINGLE_MU_FILENAME)) dy_tfile = cu.TFileCacher(os.path.join(root_dir, qgc.DY_FILENAME)) dy_hpp_tfile = cu.TFileCacher(os.path.join(root_dir, qgc.DY_HERWIG_FILENAME)) jetht_zb_tfile = cu.TFileCacher(os.path.join(root_dir, qgc.JETHT_ZB_FILENAME)) qcd_tfile = cu.TFileCacher(os.path.join(root_dir, qgc.QCD_FILENAME)) qcd_hpp_tfile = cu.TFileCacher(os.path.join(root_dir, qgc.QCD_HERWIG_FILENAME)) for gr_append in ["", "_groomed"]: if gr_append == "_groomed": print("Doing groomed plots...") else: print("Doing ungroomed plots...") zpj_dirname = "ZPlusJets_QG%s" % (gr_append) dj_cen_dirname = "Dijet_QG_central_tighter%s" % (gr_append) dj_fwd_dirname = "Dijet_QG_forward_tighter%s" % (gr_append) for ang in var_list[:]: print("...Doing", ang.name) v = "%s%s_vs_pt" % (var_prepend, ang.var) zpj_2d_entries = [] dijet_cen_2d_entries = [] dijet_fwd_2d_entries = [] zpj_1d_entries = [] dijet_cen_1d_entries = [] dijet_fwd_1d_entries = [] for pt_ind, (start_val, end_val) in enumerate(pt_bins): entries = [] zpj_entries = [] dijet_cen_entries = [] dijet_fwd_entries = [] # Get all plots lw = 2 msize = 1.1 data_line_width = lw mc_msize = 1E-3 # small enough to not be seen but not 0 - otherwise the horizontal lines on error bars don't get drawn mgpy_label = "MG5+Pythia8" hpp_label = "Herwig++" #################### # Z+JETS REGION #################### # SINGLE MU DATA if single_mu_tfile: h2d_dyj_data = single_mu_tfile.get("%s/%s" % (zpj_dirname, v)) dy_kwargs_data = dict(line_color=qgc.SINGLE_MU_COLOUR, line_width=data_line_width, fill_color=qgc.SINGLE_MU_COLOUR, marker_color=qgc.SINGLE_MU_COLOUR, marker_style=cu.Marker.get(qgc.DY_MARKER), marker_size=msize*0.7, label="Data") zpj_data_hist = qgp.get_projection_plot(h2d_dyj_data, start_val, end_val) entries.append((zpj_data_hist, dy_kwargs_data)) zpj_entries.append((zpj_data_hist, dy_kwargs_data)) if pt_ind == 0: zpj_2d_entries.append((h2d_dyj_data, dy_kwargs_data)) # PYTHIA DY MC if dy_tfile: h2d_dyj_mc = dy_tfile.get("%s/%s" % (zpj_dirname, v)) dy_kwargs_mc = dict(line_color=qgc.DY_COLOUR, line_width=lw, fill_color=qgc.DY_COLOUR, marker_color=qgc.DY_COLOUR, marker_style=cu.Marker.get(qgc.DY_MARKER), marker_size=mc_msize, label=mgpy_label, subplot=zpj_data_hist) entries.append((qgp.get_projection_plot(h2d_dyj_mc, start_val, end_val), dy_kwargs_mc)) zpj_entries.append((qgp.get_projection_plot(h2d_dyj_mc, start_val, end_val), dy_kwargs_mc)) if pt_ind == 0: zpj_2d_entries.append((h2d_dyj_mc, dy_kwargs_mc)) # HERWIG++ DY if dy_hpp_tfile: h2d_dyj_mc_hpp = dy_hpp_tfile.get("%s/%s" % (zpj_dirname, v)) col_hpp = qgc.DY_COLOURS[2] dy_kwargs_mc_hpp = dict(line_color=col_hpp, line_width=lw, fill_color=col_hpp, marker_color=col_hpp, marker_style=cu.Marker.get(qgc.DY_MARKER), marker_size=mc_msize, label=hpp_label, subplot=zpj_data_hist) entries.append((qgp.get_projection_plot(h2d_dyj_mc_hpp, start_val, end_val), dy_kwargs_mc_hpp)) zpj_entries.append((qgp.get_projection_plot(h2d_dyj_mc_hpp, start_val, end_val), dy_kwargs_mc_hpp)) if pt_ind == 0: zpj_2d_entries.append((h2d_dyj_mc_hpp, dy_kwargs_mc_hpp)) # MG+HERWIG++ DY # if end_val < 151: # h2d_dyj_mc3 = get("%s/%s" % (zpj_dirname, v)) # col4 = qgc.DY_COLOURS[3] # dy_kwargs_mc3 = dict(line_color=col4, line_width=lw, fill_color=col4, # marker_color=col4, marker_style=cu.Marker.get(qgc.DY_MARKER), marker_size=0, # label="MG+Herwig++", # subplot=zpj_data_hist) # entries.append((qgp.get_projection_plot(h2d_dyj_mc3, start_val, end_val), dy_kwargs_mc3)) # zpj_entries.append((qgp.get_projection_plot(h2d_dyj_mc3, start_val, end_val), dy_kwargs_mc3)) # if pt_ind == 0: # zpj_2d_entries.append((h2d_dyj_mc3, dy_kwargs_mc3)) # else: # zpj_entries.append(None) #################### # DIJET CENTRAL REGION #################### # JETHT/ZEROBIAS DATA if jetht_zb_tfile: h2d_qcd_cen_data = jetht_zb_tfile.get("%s/%s" % (dj_cen_dirname, v)) # use already merged jetht+zb qcd_cen_kwargs_data = dict(line_color=qgc.JETHT_COLOUR, line_width=data_line_width, fill_color=qgc.JETHT_COLOUR, marker_color=qgc.JETHT_COLOUR, marker_style=cu.Marker.get(qgc.QCD_MARKER), marker_size=msize, label="Data") dijet_cen_data_hist = qgp.get_projection_plot(h2d_qcd_cen_data, start_val, end_val) entries.append((dijet_cen_data_hist, qcd_cen_kwargs_data)) dijet_cen_entries.append((dijet_cen_data_hist, qcd_cen_kwargs_data)) if pt_ind == 0: dijet_cen_2d_entries.append((h2d_qcd_cen_data, qcd_cen_kwargs_data)) # MG+PYTHIA QCD MC if qcd_tfile: h2d_qcd_cen_mc = qcd_tfile.get("%s/%s" % (dj_cen_dirname, v)) qcd_cen_kwargs_mc = dict(line_color=qgc.QCD_COLOUR, line_width=lw, fill_color=qgc.QCD_COLOUR, marker_color=qgc.QCD_COLOUR, marker_style=cu.Marker.get(qgc.QCD_MARKER), marker_size=mc_msize, label=mgpy_label, subplot=dijet_cen_data_hist) dijet_mgpy_hist = qgp.get_projection_plot(h2d_qcd_cen_mc, start_val, end_val) entries.append((dijet_mgpy_hist, qcd_cen_kwargs_mc)) dijet_cen_entries.append((dijet_mgpy_hist, qcd_cen_kwargs_mc)) if pt_ind == 0: dijet_cen_2d_entries.append((h2d_qcd_cen_mc, qcd_cen_kwargs_mc)) # PYTHIA ONLY # if qcd_py_tfile: # col = qgc.QCD_COLOURS[2] # h2d_qcd_cen_mc2 = qcd_py_tfile.get("%s/%s" % (dj_cen_dirname, v)) # qcd_cen_kwargs_mc2 = dict(line_color=col, line_width=lw, fill_color=col, # marker_color=col, marker_style=cu.Marker.get(qgc.QCD_MARKER), marker_size=mc_msize, # label="Pythia8", # subplot=dijet_cen_data_hist) # entries.append((qgp.get_projection_plot(h2d_qcd_cen_mc2, start_val, end_val), qcd_cen_kwargs_mc2)) # dijet_cen_entries.append((qgp.get_projection_plot(h2d_qcd_cen_mc2, start_val, end_val), qcd_cen_kwargs_mc2)) # if pt_ind == 0: # dijet_cen_2d_entries.append((h2d_qcd_cen_mc2, qcd_cen_kwargs_mc2)) # HERWIG++ QCD if qcd_hpp_tfile: h2d_qcd_cen_mc_hpp = qcd_hpp_tfile.get("%s/%s" % (dj_cen_dirname, v)) qcd_cen_kwargs_mc_hpp = dict(line_color=qgc.HERWIGPP_QCD_COLOUR, line_width=lw, fill_color=qgc.HERWIGPP_QCD_COLOUR, marker_color=qgc.HERWIGPP_QCD_COLOUR, marker_style=cu.Marker.get(qgc.QCD_MARKER), marker_size=mc_msize, label=hpp_label, subplot=dijet_cen_data_hist) dijet_hpp_hist = qgp.get_projection_plot(h2d_qcd_cen_mc_hpp, start_val, end_val) entries.append((dijet_hpp_hist, qcd_cen_kwargs_mc_hpp)) dijet_cen_entries.append((dijet_hpp_hist, qcd_cen_kwargs_mc_hpp)) if pt_ind == 0: dijet_cen_2d_entries.append((h2d_qcd_cen_mc_hpp, qcd_cen_kwargs_mc_hpp)) #################### # DIJET FORWARD REGION #################### # JETHT/ZEROBIAS DATA if jetht_zb_tfile: h2d_qcd_fwd_data = jetht_zb_tfile.get("%s/%s" % (dj_fwd_dirname, v)) # use already merged jetht+zb qcd_fwd_kwargs_data = dict(line_color=qgc.JETHT_COLOUR, line_width=data_line_width, fill_color=qgc.JETHT_COLOUR, marker_color=qgc.JETHT_COLOUR, marker_style=cu.Marker.get('triangleDown'), marker_size=msize, label="Data") dijet_fwd_data_hist = qgp.get_projection_plot(h2d_qcd_fwd_data, start_val, end_val) entries.append((dijet_fwd_data_hist, qcd_fwd_kwargs_data)) dijet_fwd_entries.append((dijet_fwd_data_hist, qcd_fwd_kwargs_data)) if pt_ind == 0: dijet_fwd_2d_entries.append((h2d_qcd_fwd_data, qcd_fwd_kwargs_data)) # MG+PYTHIA QCD MC if qcd_tfile: h2d_qcd_fwd_mc = qcd_tfile.get("%s/%s" % (dj_fwd_dirname, v)) qcd_fwd_kwargs_mc = dict(line_color=qgc.QCD_COLOUR, line_width=lw, fill_color=qgc.QCD_COLOUR, marker_color=qgc.QCD_COLOUR, marker_style=cu.Marker.get(qgc.QCD_MARKER), marker_size=mc_msize, label=mgpy_label, subplot=dijet_fwd_data_hist) dijet_mgpy_hist = qgp.get_projection_plot(h2d_qcd_fwd_mc, start_val, end_val) entries.append((dijet_mgpy_hist, qcd_fwd_kwargs_mc)) dijet_fwd_entries.append((dijet_mgpy_hist, qcd_fwd_kwargs_mc)) if pt_ind == 0: dijet_fwd_2d_entries.append((h2d_qcd_fwd_mc, qcd_fwd_kwargs_mc)) # PYTHIA ONLY # if qcd_py_tfile: # col = qgc.QCD_COLOURS[2] # h2d_qcd_fwd_mc2 = qcd_py_tfile.get("%s/%s" % (dj_fwd_dirname, v)) # qcd_fwd_kwargs_mc2 = dict(line_color=col, line_width=lw, fill_color=col, # marker_color=col, marker_style=cu.Marker.get(qgc.QCD_MARKER), marker_size=mc_msize, # label="Pythia8", # subplot=dijet_fwd_data_hist) # entries.append((qgp.get_projection_plot(h2d_qcd_fwd_mc2, start_val, end_val), qcd_fwd_kwargs_mc2)) # dijet_fwd_entries.append((qgp.get_projection_plot(h2d_qcd_fwd_mc2, start_val, end_val), qcd_fwd_kwargs_mc2)) # if pt_ind == 0: # dijet_fwd_2d_entries.append((h2d_qcd_fwd_mc2, qcd_fwd_kwargs_mc2)) # HERWIG++ QCD if qcd_hpp_tfile: h2d_qcd_fwd_mc_hpp = qcd_hpp_tfile.get("%s/%s" % (dj_fwd_dirname, v)) qcd_fwd_kwargs_mc_hpp = dict(line_color=qgc.HERWIGPP_QCD_COLOUR, line_width=lw, fill_color=qgc.HERWIGPP_QCD_COLOUR, marker_color=qgc.HERWIGPP_QCD_COLOUR, marker_style=cu.Marker.get(qgc.QCD_MARKER), marker_size=mc_msize, label=hpp_label, subplot=dijet_fwd_data_hist) dijet_hpp_hist = qgp.get_projection_plot(h2d_qcd_fwd_mc_hpp, start_val, end_val) entries.append((dijet_hpp_hist, qcd_fwd_kwargs_mc_hpp)) dijet_fwd_entries.append((dijet_hpp_hist, qcd_fwd_kwargs_mc_hpp)) if pt_ind == 0: dijet_fwd_2d_entries.append((h2d_qcd_fwd_mc_hpp, qcd_fwd_kwargs_mc_hpp)) zpj_1d_entries.append(zpj_entries) dijet_cen_1d_entries.append(dijet_cen_entries) dijet_fwd_1d_entries.append(dijet_fwd_entries) ################# # SETUP PLOTTING ################# rebin = 2 v_lower = v.lower() if "multiplicity" in v_lower: rebin = 1 # elif "flavour" in v_lower or "thrust" in v_lower: # rebin = 1 # elif 'ptd' in v_lower: # rebin = 4 # elif 'lha_charged' in v_lower: # rebin = 4 # rebin = 1 xlim = None if "width" in v_lower or "ptd" in v_lower: xlim = (0, 1) elif "thrust" in v_lower: xlim = (0, 0.5) # elif "multiplicity" in v_lower and "ak4" in root_dir.lower(): # if end_val <= 150: # xlim = (0, 50) # else: # xlim = (0, 80) auto_xlim = False if "multiplicity" in v_lower or "thrust" in v_lower: auto_xlim = True ylim = [0, None] if "flavour" in v_lower: ylim = (0, 1) # elif "lha" in v_lower: # ylim = (0, 5) plot_dir = os.path.join(root_dir, "plots_lambda_mc_vs_data%s" % (gr_append)) subplot_title = "Simulation / Data" subplot_limits = (0, 2) xlabel = ang.name + " (" + ang.lambda_str + ")" if gr_append is not "": xlabel = "Groomed " + ang.name + " (" + ang.lambda_str + ")" def _title(region_str, start_val, end_val): pt_var_str = "p_{T}^{jet}" s = (("{jet_algo}\n" "{region_label}\n" "{bin_edge_low:g} < {pt_str} < {bin_edge_high:g} GeV") .format( jet_algo=jet_str, region_label=region_str, pt_str=pt_var_str, bin_edge_low=start_val, bin_edge_high=end_val)) if title is not None: s = "%s\n%s" % (s, title) return s has_data = True draw_opt = "NOSTACK HIST E1" # dj central only # dont' try to do multiple signal regions per plot, it looks rubbish if len(dijet_cen_entries) > 0: qgp.do_comparison_plot(dijet_cen_entries, "%s/ptBinned/%s_pt%dto%d_dijet_central.%s" % (plot_dir, v, start_val, end_val, OUTPUT_FMT), rebin=rebin, draw_opt=draw_opt, title=_title(qgc.Dijet_CEN_LABEL, start_val, end_val), xtitle=xlabel, xlim='auto' if auto_xlim else xlim, # don't use calc_auto_xlim, since do_comparison_plot will rebin it anyway ylim=ylim, data_first=has_data, mean_rel_error=0.4, subplot_type='ratio', subplot_title=subplot_title, subplot_limits=subplot_limits, lumi=cu.get_lumi_str(do_dijet=True, do_zpj=False)) # dj forward only if len(dijet_fwd_entries) > 0: qgp.do_comparison_plot(dijet_fwd_entries, "%s/ptBinned/%s_pt%dto%d_dijet_forward.%s" % (plot_dir, v, start_val, end_val, OUTPUT_FMT), rebin=rebin, draw_opt=draw_opt, title=_title(qgc.Dijet_FWD_LABEL, start_val, end_val), xtitle=xlabel, xlim='auto' if auto_xlim else xlim, ylim=ylim, data_first=has_data, mean_rel_error=0.4, subplot_type='ratio', subplot_title=subplot_title, subplot_limits=subplot_limits, lumi=cu.get_lumi_str(do_dijet=True, do_zpj=False)) # zpj only if len(zpj_entries) > 0: if start_val > 149: # rebin *= 2 rebin += 1 # find nearest divisor while (zpj_entries[0][0].GetNbinsX() % rebin != 0): rebin += 1 if "multiplicity" in v_lower: if start_val > 300: rebin += 1 # find nearest divisor while (zpj_entries[0][0].GetNbinsX() % rebin != 0): rebin += 1 qgp.do_comparison_plot(zpj_entries, "%s/ptBinned/%s_pt%dto%d_zpj.%s" % (plot_dir, v, start_val, end_val, OUTPUT_FMT), rebin=rebin, draw_opt=draw_opt, title=_title(qgc.ZpJ_LABEL, start_val, end_val), xtitle=xlabel, xlim=qgp.calc_auto_xlim([d[0] for d in zpj_entries]) if auto_xlim else xlim, ylim=ylim, data_first=has_data, mean_rel_error=0.4, subplot_type='ratio', subplot_title=subplot_title, subplot_limits=subplot_limits, lumi=cu.get_lumi_str(do_dijet=False, do_zpj=True)) # Do overall summary plots across all pt bins # ------------------------------------------------------------------ ylim_mean = None if "width" in v_lower or "ptd" in v_lower: ylim_mean = (0, 0.4) elif"thrust" in v_lower: ylim_mean = (0, 0.5) elif "multiplicity" in v_lower and "ak4" in root_dir.lower(): ylim_mean = (0, 100) ylim_mean = (0, 80) if end_val < 150: ylim_mean = (0, 50) ylim_mean=None ylim_rms=None # Setup variable names for MPL marker = "" if "_" in ang.name or "^" in ang.name: marker = "$" var_label = marker + ang.name + marker + " ($%s$)" % ang.lambda_str if gr_append != "": var_label = "Groomed " + marker + ang.name + marker + " ($%s$)" % ang.lambda_str # construct a dataframe from the hists # df = construct_dataframe_from_hists(dijet_cen_entries=dijet_cen_1d_entries, # dijet_fwd_entries=dijet_fwd_entries, # zpj_entries=zpj_entries) # pt_low = 88 if "8" in radius else 50 pt_low = pt_bins[0][0] qgp.do_mean_rms_summary_plot(dijet_cen_1d_entries, pt_bins, "%s/ptBinned/%s_box_dijet_cen_mpl.%s" % (plot_dir, v, OUTPUT_FMT), var_label=var_label, xlim=(pt_low, 4000), ylim_mean=ylim_mean, ylim_rms=ylim_rms, region_title="%s jets in %s" % (jet_str, qgc.Dijet_CEN_LABEL.lower())) qgp.do_mean_rms_summary_plot(dijet_fwd_1d_entries, pt_bins, "%s/ptBinned/%s_box_dijet_fwd_mpl.%s" % (plot_dir, v, OUTPUT_FMT), var_label=var_label, xlim=(pt_low, 4000), ylim_mean=ylim_mean, ylim_rms=ylim_rms, region_title="%s jets in %s" % (jet_str, qgc.Dijet_FWD_LABEL.lower())) # zpj_1d_entries[i][j] is the jth sample in the ith pt bin qgp.do_mean_rms_summary_plot(zpj_1d_entries, pt_bins, "%s/ptBinned/%s_box_zpj_mpl.%s" % (plot_dir, v, OUTPUT_FMT), var_label=var_label, xlim=(pt_low, 800), ylim_mean=ylim_mean, ylim_rms=ylim_rms, region_title="%s jets in %s" % (jet_str, qgc.ZpJ_LABEL))
def do_plots(root_dir): # QG variable plots pt_bins = qgc.PT_BINS[:] var_list = qgc.COMMON_VARS var_prepend = "" radius, pus = cu.get_jet_config_from_dirname(root_dir) jet_str = "AK%s PF %s" % (radius.upper(), pus.upper()) for gr_append in ["", "_groomed"]: if gr_append == "_groomed": print("Doing groomed plots...") else: print("Doing ungroomed plots...") # do a pt plot just for sanity if gr_append == "": make_1d_plot(root_dir, "ZPlusJets_gen/pt_jet1", jet_str, gen_only=True) make_1d_plot(root_dir, "ZPlusJets_gen/pt_mumu", jet_str, gen_only=True) make_1d_plot(root_dir, "ZPlusJets/pt_jet1", jet_str) make_1d_plot(root_dir, "ZPlusJets/pt_mumu", jet_str) continue zpj_dirname = "ZPlusJets_QG%s" % (gr_append) for ang in var_list[:]: print("...Doing", ang.name) v = "%s%s_vs_pt" % (var_prepend, ang.var) zpj_2d_entries = [] zpj_1d_entries = [] for pt_ind, (start_val, end_val) in enumerate(pt_bins): entries = [] zpj_entries = [] # Get all plots lw = 2 msize = 1.1 data_line_width = 0 #################### # Z+JETS REGION #################### # SINGLE MU DATA h2d_dyj_data = grab_obj(os.path.join(root_dir, qgc.SINGLE_MU_FILENAME), "%s/%s" % (zpj_dirname, v)) dy_kwargs_data = dict(line_color=qgc.SINGLE_MU_COLOUR, line_width=data_line_width, fill_color=qgc.SINGLE_MU_COLOUR, marker_color=qgc.SINGLE_MU_COLOUR, marker_style=cu.Marker.get(qgc.DY_MARKER), marker_size=msize, label="Data") zpj_data_hist = qgp.get_projection_plot(h2d_dyj_data, start_val, end_val) entries.append((zpj_data_hist, dy_kwargs_data)) zpj_entries.append((zpj_data_hist, dy_kwargs_data)) if pt_ind == 0: zpj_2d_entries.append((h2d_dyj_data, dy_kwargs_data)) # PYTHIA DY MC WITH k FACTORS h2d_dyj_mc = grab_obj(os.path.join(root_dir, qgc.DY_FILENAME), "%s/%s" % (zpj_dirname, v)) dy_kwargs_mc = dict(line_color=qgc.DY_COLOUR, line_width=lw, fill_color=qgc.DY_COLOUR, marker_color=qgc.DY_COLOUR, marker_style=cu.Marker.get(qgc.DY_MARKER), marker_size=0, label="MG+PY8 (w/ k-factor)", subplot=zpj_data_hist) entries.append((qgp.get_projection_plot(h2d_dyj_mc, start_val, end_val), dy_kwargs_mc)) zpj_entries.append((qgp.get_projection_plot(h2d_dyj_mc, start_val, end_val), dy_kwargs_mc)) if pt_ind == 0: zpj_2d_entries.append((h2d_dyj_mc, dy_kwargs_mc)) # WIHTOUT K FACTORS h2d_dyj_mc_noWeight = grab_obj(os.path.join(root_dir, "uhh2.AnalysisModuleRunner.MC.MC_DYJetsToLL_noZReweight.root"), "%s/%s" % (zpj_dirname, v)) dy_kwargs_mc_noWeight = dict(line_color=qgc.DY_COLOURS[0], line_width=lw, fill_color=qgc.DY_COLOURS[0], line_style=2, marker_color=qgc.DY_COLOURS[0], marker_style=cu.Marker.get(qgc.DY_MARKER), marker_size=0, label="MG+PY8 (w/out k-factor)", subplot=zpj_data_hist) entries.append((qgp.get_projection_plot(h2d_dyj_mc_noWeight, start_val, end_val), dy_kwargs_mc_noWeight)) zpj_entries.append((qgp.get_projection_plot(h2d_dyj_mc_noWeight, start_val, end_val), dy_kwargs_mc_noWeight)) if pt_ind == 0: zpj_2d_entries.append((h2d_dyj_mc_noWeight, dy_kwargs_mc_noWeight)) # HERWIG++ DY # if end_val < 255: # h2d_dyj_mc2 = grab_obj(os.path.join(root_dir, qgc.DY_HERWIG_FILENAME), "%s/%s" % (zpj_dirname, v)) # col3 = qgc.DY_COLOURS[2] # dy_kwargs_mc2 = dict(line_color=col3, line_width=lw, fill_color=col3, # marker_color=col3, marker_style=cu.Marker.get(qgc.DY_MARKER), marker_size=0, # label="H++", # subplot=zpj_data_hist) # entries.append((qgp.get_projection_plot(h2d_dyj_mc2, start_val, end_val), dy_kwargs_mc2)) # zpj_entries.append((qgp.get_projection_plot(h2d_dyj_mc2, start_val, end_val), dy_kwargs_mc2)) # if pt_ind == 0: # zpj_2d_entries.append((h2d_dyj_mc2, dy_kwargs_mc2)) # else: # zpj_entries.append(None) # MG+HERWIG++ DY # if end_val < 151: # h2d_dyj_mc3 = grab_obj(os.path.join(root_dir, qgc.DY_MG_HERWIG_FILENAME), "%s/%s" % (zpj_dirname, v)) # col4 = qgc.DY_COLOURS[3] # dy_kwargs_mc3 = dict(line_color=col4, line_width=lw, fill_color=col4, # marker_color=col4, marker_style=cu.Marker.get(qgc.DY_MARKER), marker_size=0, # label="MG+H++", # subplot=zpj_data_hist) # entries.append((qgp.get_projection_plot(h2d_dyj_mc3, start_val, end_val), dy_kwargs_mc3)) # zpj_entries.append((qgp.get_projection_plot(h2d_dyj_mc3, start_val, end_val), dy_kwargs_mc3)) # if pt_ind == 0: # zpj_2d_entries.append((h2d_dyj_mc3, dy_kwargs_mc3)) # else: # zpj_entries.append(None) zpj_1d_entries.append(zpj_entries) ################# # SETUP PLOTTING ################# rebin = 2 v_lower = v.lower() if "multiplicity" in v_lower: rebin = 2 elif "flavour" in v_lower or "thrust" in v_lower: rebin = 1 elif 'ptd' in v_lower: rebin = 2 xlim = None if "width" in v_lower or "ptd" in v_lower: xlim = (0, 1) elif"thrust" in v_lower: xlim = (0, 0.5) elif "multiplicity" in v_lower and "ak4" in root_dir.lower(): if end_val <= 150: xlim = (0, 50) else: xlim = (0, 80) ylim = None if "flavour" in v_lower: ylim = (0, 1) # elif "lha" in v_lower: # ylim = (0, 5) plot_dir = os.path.join(root_dir, "plots_dy_vs_qcd_mc_vs_data%s_z_reweight" % (gr_append)) subplot_title = "MC / Data" subplot_limits = (0.5, 1.5) xlabel = ang.name + " (" + ang.lambda_str + ")" if gr_append is not "": xlabel = "Groomed " + ang.name + " (" + ang.lambda_str + ")" # zpj only qgp.do_comparison_plot(zpj_entries, "%s/ptBinned/%s_pt%dto%d_zpj.%s" % (plot_dir, v, start_val, end_val, OUTPUT_FMT), rebin=rebin, title="%d < p_{T}^{jet} < %d GeV\n%s\n%s" % (start_val, end_val, jet_str, qgc.ZpJ_LABEL), xtitle=xlabel, xlim=xlim, ylim=ylim, subplot_type='ratio', subplot_title=subplot_title, subplot_limits=subplot_limits) # Do overall summary plots across all pt bins # ------------------------------------------------------------------ ylim_mean = None if "width" in v_lower or "ptd" in v_lower: ylim_mean = (0, 0.4) elif"thrust" in v_lower: ylim_mean = (0, 0.5) elif "multiplicity" in v_lower and "ak4" in root_dir.lower(): ylim_mean = (0, 100) ylim_mean = (0, 80) if end_val < 150: ylim_mean = (0, 50) ylim_mean=None ylim_rms=None # Setup variable names for MPL marker = "" if "_" in ang.name or "^" in ang.name: marker = "$" var_label = marker + ang.name + marker + " ($%s$)" % ang.lambda_str if gr_append != "": var_label = "Groomed " + marker + ang.name + marker + " ($%s$)" % ang.lambda_str # zpj_1d_entries[i][j] is the jth sample in the ith pt bin qgp.do_mean_rms_summary_plot(zpj_1d_entries[:], pt_bins[:], "%s/ptBinned/%s_box_zpj_mpl.%s" % (plot_dir, v, OUTPUT_FMT), var_label=var_label, xlim=(50, 614), ylim_mean=ylim_mean, ylim_rms=ylim_rms, region_title="%s jets in %s" % (jet_str, qgc.ZpJ_LABEL))
def do_gen_reco_comparison_plots(root_dir, var_list=None, gen_var_prepend="gen", reco_var_prepend="", plot_dir="plot_reco_gen", zpj_reco_dirname=qgc.ZPJ_RECOJET_RDIR, dj_reco_dirname=qgc.DJ_RECOJET_RDIR, zpj_gen_dirname=qgc.ZPJ_GENJET_RDIR, dj_gen_dirname=qgc.DJ_GENJET_RDIR, pt_bins=qgc.THEORY_PT_BINS, subplot_type=None): var_list = var_list or qgc.COMMON_VARS for ang in var_list: v_reco = "%s%s_vs_pt" % (reco_var_prepend, ang.var) v_gen = "%s%s_vs_pt" % (gen_var_prepend, ang.var) h2d_dyj_reco = grab_obj(os.path.join(root_dir, qgc.DY_FILENAME), "%s/%s" % (zpj_reco_dirname, v_reco)) h2d_qcd_reco = grab_obj(os.path.join(root_dir, qgc.QCD_FILENAME), "%s/%s" % (dj_reco_dirname, v_reco)) h2d_dyj_gen = grab_obj(os.path.join(root_dir, qgc.DY_FILENAME), "%s/%s" % (zpj_gen_dirname, v_gen)) h2d_qcd_gen = grab_obj(os.path.join(root_dir, qgc.QCD_FILENAME), "%s/%s" % (dj_gen_dirname, v_gen)) if "flavour" not in v_reco: h2d_dyj_reco_q = grab_obj(os.path.join(root_dir, qgc.DY_FILENAME), "%s/q%s" % (zpj_reco_dirname, v_reco)) h2d_qcd_reco_g = grab_obj(os.path.join(root_dir, qgc.QCD_FILENAME), "%s/g%s" % (dj_reco_dirname, v_reco)) h2d_dyj_gen_q = grab_obj(os.path.join(root_dir, qgc.DY_FILENAME), "%s/q%s" % (zpj_gen_dirname, v_gen)) h2d_qcd_gen_g = grab_obj(os.path.join(root_dir, qgc.QCD_FILENAME), "%s/g%s" % (dj_gen_dirname, v_gen)) for (start_val, end_val) in pt_bins: lw = 2 dy_reco_kwargs = dict(line_color=qgc.DY_COLOUR, fill_color=qgc.DY_COLOUR, label=qgc.DY_ZpJ_LABEL + " [RecoJet]", line_width=lw) qcd_reco_kwargs = dict(line_color=qgc.QCD_COLOUR, fill_color=qgc.QCD_COLOUR, label=qgc.QCD_Dijet_LABEL + " [RecoJet]", line_width=lw) dy_gen_kwargs = dict(line_color=qgc.DY_COLOUR, fill_color=qgc.DY_COLOUR, label=qgc.DY_ZpJ_LABEL + " [GenJet]", line_width=lw, line_style=2) qcd_gen_kwargs = dict(line_color=qgc.QCD_COLOUR, fill_color=qgc.QCD_COLOUR, label=qgc.QCD_Dijet_LABEL + " [GenJet]", line_width=lw, line_style=2) entries = [(qgg.get_projection_plot(h2d_dyj_reco, start_val, end_val), dy_reco_kwargs), (qgg.get_projection_plot(h2d_qcd_reco, start_val, end_val), qcd_reco_kwargs), (qgg.get_projection_plot(h2d_dyj_gen, start_val, end_val), dy_gen_kwargs), (qgg.get_projection_plot(h2d_qcd_gen, start_val, end_val), qcd_gen_kwargs)] rebin = 2 xlim = None ylim = None if "flavour" in v_reco: rebin = 1 ylim = (0, 1) if "thrust" in v_reco: xlim = (0, 0.5) qgg.do_comparison_plot( entries, "%s/%s/%s_pt%dto%d.%s" % (root_dir, plot_dir, ang.var, start_val, end_val, OUTPUT_FMT), rebin=rebin, title="%d < p_{T}^{jet} < %d GeV" % (start_val, end_val), xtitle=ang.name + " (" + ang.lambda_str + ")", xlim=xlim, ylim=ylim, subplot_type=subplot_type) # Do flavour-tagged comparison if "flavour" in v_reco: continue dy_reco_kwargs['label'] = qgc.DY_ZpJ_QFLAV_LABEL + " [RecoJet]" qcd_reco_kwargs['label'] = qgc.QCD_Dijet_GFLAV_LABEL + " [RecoJet]" dy_gen_kwargs['label'] = qgc.DY_ZpJ_QFLAV_LABEL + " [GenJet]" qcd_gen_kwargs['label'] = qgc.QCD_Dijet_GFLAV_LABEL + " [GenJet]" entries = [(qgg.get_projection_plot(h2d_dyj_reco_q, start_val, end_val), dy_reco_kwargs), (qgg.get_projection_plot(h2d_qcd_reco_g, start_val, end_val), qcd_reco_kwargs), (qgg.get_projection_plot(h2d_dyj_gen_q, start_val, end_val), dy_gen_kwargs), (qgg.get_projection_plot(h2d_qcd_gen_g, start_val, end_val), qcd_gen_kwargs)] qgg.do_comparison_plot( entries, "%s/%s/%s_flavMatched_pt%dto%d.%s" % (root_dir, plot_dir, ang.var, start_val, end_val, OUTPUT_FMT), rebin=rebin, title="%d < p_{T}^{jet} < %d GeV" % (start_val, end_val), xtitle=ang.name + " (" + ang.lambda_str + ")", xlim=xlim, ylim=ylim, subplot_type=subplot_type)