import argparse import os import matplotlib.pyplot as plt import numpy as np from glob import glob import matplotlib as mpl import matplotlib.gridspec as gridspec import re from readers.topreader import TopReader from plotters.histoplotter import HistoPlotter from typing import Dict from readers.mocanloreader import MocanloReader keys_to_plot = { "ptj1": "histogram_transverse_momentum_j1", "ptj2": "histogram_transverse_momentum_j2", "mjj": "histogram_invariant_mass_mjj12", "yjj": "histogram_rapidity_j1j2", "ptH": "histogram_transverse_momentum_h1", "ptHjj": "histogram_transverse_momentum_jjh", "yj1": "histogram_rapidity_j1", "yj2": "histogram_rapidity_j2", "yH": "histogram_rapidity_h1" } # reference_list is just a settings json for plotting # label_mapping is a dict to rename data["data"].keys() in the plot proVBF_setup = "bigstxs" default_reference_list = [ {"data_ind": ["%s_central_scale_proVBFH_LO"%proVBF_setup, "best_prediction_final"],#"best_prediction_1", "best_prediction_2", "best_prediction_3"], "error_bands": True, "label": "$\dfrac{d \sigma}{d M_{j_1 j_2}} $ [pb]" #"y_scale": (10**(-8),5*10**(-3)), }, {"data_ind": ["%s_central_scale_proVBFH_NLO_ratio"%proVBF_setup, "%s_central_scale_proVBFH_LO_ratio"%proVBF_setup, "%s_central_scale_proVBFH_NNLO_ratio"%proVBF_setup, "%s_proVBFH_NNLO_nonfact_ratio"%proVBF_setup], #"reference_ind": "bigstxs_postprocessed_proVBFH_NLO", "error_bands": True, "horizontal_line": False, #"plot_label_for_reference": True, "label": "ratio to\nVBF NLO QCD", #"y_scale": (0.4,1.53), }, {"data_ind": ["full_nlo_ew_photon_only", "full_nlo_ew_w_photon"], "error_bands": False, "horizontal_line": True, "label": "Full\n NLO EW/LO", #"y_scale": (0.65,1.02), }, {"data_ind": ["MoCaNLO_NLO_QCD_ratio", "MoCaNLO_LO_QCD_ratio"], "error_bands": True, "label": "Full/VBF", "horizontal_line": True, #"y_scale": (0.0000,6.3000), }, {"data_ind": ["MoCaNLO_loop_induced", "MoCaNLO_loop_induced_2"],#, "MoCaNLO_ggF_LO"], "reference_ind": "MoCaNLO_LO", "horizontal_line": False, "label": "Loop-induced/LO", #"y_scale": (-0.005,0.7000), "error_bands": True, }, {"data_ind": ["MoCaNLO_ggF_LO"],#, "MoCaNLO_ggF_LO"], "reference_ind": "MoCaNLO_LO", "horizontal_line": False, "label": "ggF/LO", #"y_scale": (-0.0,10.5000), "error_bands": True, } ] default_label_mapping = { "full_nlo_ew_photon_only": "Photon only", "full_nlo_ew_w_photon": "NLO with photon", "best_prediction_final": "Best prediction", "MoCaNLO_NLO_EW_photon_only": "Photon only", "best_prediction_1": "without photon", "best_prediction_2" : "photon only correction", "best_prediction_3" : "EW NLO with photon - EW NLO without photon", "bigstxs_postprocessed_proVBFH_LO": "LO", "bigstxs_postprocessed_proVBFH_NLO": "NLO QCD", "STXS_proVBFH_NNLO_EW": "Best prediction", "bigstxs_postprocessed_proVBFH_LO_ratio": "LO", "bigstxs_postprocessed_proVBFH_NLO_ratio": "NLO", "bigstxs_postprocessed_proVBFH_NNLO_ratio": "NNLO", "bigstxs_postprocessed_proVBFH_NNLO": "NNLO QCD", "%s_central_scale_proVBFH_LO"%proVBF_setup: "LO", "%s_central_scale_proVBFH_NLO"%proVBF_setup: "NLO", "%s_central_scale_proVBFH_NNLO"%proVBF_setup: "NNLO", "%s_proVBFH_NNLO_nonfact_ratio"%proVBF_setup: "NF", "%s_central_scale_proVBFH_LO_ratio"%proVBF_setup: "LO", "%s_central_scale_proVBFH_NLO_ratio"%proVBF_setup: "NLO", "%s_central_scale_proVBFH_NNLO_ratio"%proVBF_setup: "NNLO", "full_nlo_qcd_correction": "NLO", "mocanlo_qcd_nlo_prediction": "NLO", "mocanlo_nlo_qcd_born": "LO", "MoCaNLO_NLO_EW": "", "MoCaNLO_NLO_QCD_ratio": "NLO", "MoCaNLO_LO_QCD_ratio": "LO", "MoCaNLO_loop_induced": "Loop-induced interference", "MoCaNLO_loop_induced_2": "Loop-induced squared", "MoCaNLO_ggF_LO": "LO ggF" } default_color_mapping = { "full_nlo_ew_photon_only": "#E1C16E", #Brass "full_nlo_ew_w_photon": "#6F4E37", #coffee "best_prediction_final": "#50C878", #Emerald Green "MoCaNLO_NLO_EW_photon_only": "", "best_prediction_1": "", "best_prediction_2" : "", "best_prediction_3" : "", "%s_central_scale_proVBFH_LO"%proVBF_setup: "#0096FF", #bright blue "%s_central_scale_proVBFH_NLO"%proVBF_setup: "#5F9EA0", #Cadet Blue "STXS_proVBFH_NNLO_EW": "", "%s_central_scale_proVBFH_LO_ratio"%proVBF_setup: "#0096FF", "%s_central_scale_proVBFH_NLO_ratio"%proVBF_setup: "#5F9EA0", #Cadet Blue "full_nlo_qcd_correction": "#5F9EA0", #Cadet Blue "mocanlo_qcd_nlo_prediction": "#5F9EA0", "mocanlo_nlo_qcd_born": "#0096FF", "%s_central_scale_proVBFH_NNLO_ratio"%proVBF_setup: "#C30000", #"#5D3FD3",#Iris "%s_proVBFH_NNLO_nonfact_ratio"%proVBF_setup: "#F5CF9F", #light orange "MoCaNLO_NLO_EW": "", "MoCaNLO_NLO_QCD_ratio": "#988558", #Dark Tan "MoCaNLO_LO_QCD_ratio": "#CD7F32", #Bronze "MoCaNLO_loop_induced": "#708090",#Slate Gray "MoCaNLO_loop_induced_2": "#8A9A5B",#Sage Green "MoCaNLO_ggF_LO":"#F5CF9F" } default_settings = { "x_param_labelpad": 0, "x_param_label": "$M_{jj}$", "x_param_position": 1,#-0.03, "left_title": r"pp $\longrightarrow$ H + 2j", "right_title": r"$\sqrt{S} = 13.6\,\mathrm{TeV}$", } def plot_fo_1d(key_to_plot: str, setup: str, x_min: int, x_max: int, provbf_mapping: Dict, data_abs_path: str, save_path: str, reference_list=default_reference_list, label_mapping=default_label_mapping, color_mapping=default_color_mapping, settings=default_settings, denormalise_flag=False, separated_subplots_flag=False): reader = TopReader(mapping=provbf_mapping, denormalise_flag=denormalise_flag) red = MocanloReader() ( mocanlo_nlo_qcd_born, mocanlo_nlo_qcd_nlo, mocanlo_nlo_ew_w_photon_born, mocanlo_nlo_ew_w_photon_nlo, mocanlo_loop_induced, mocanlo_loop_induced_2, mocanlo_nlo_ew_no_photon_nlo, mocanlo_nlo_ew_photon_only, mocanlo_ggF_born ) = red.get_mocanlo_data_from_file_path( data_abs_path, keys_to_plot[key_to_plot], setup, denormalise_flag ) settings["separated_subplots_flag"] = separated_subplots_flag # Getting ptH data from top reader bigstxs_list = list(filter(lambda x: "bigstxs" in x or ("stxs" in x and "nonfact" in x),dir(reader))) top_data_dict = {} for bigstxt in bigstxs_list: try: top_data_dict[bigstxt] = list(filter(lambda x: x["x_param"] == key_to_plot,getattr(reader, bigstxt)))[0]["data"] except: pass # Using a dictionary comprehension to filter out items with empty lists filtered_top_data = {key: value for key, value in top_data_dict.items() if value} data = {} data["x_param"] = mocanlo_nlo_ew_w_photon_born["x_param"] data["data"] = filtered_top_data data["other_params"] = [] proVBF_setup = "bigstxs" #sigma_qcd_nlo mocanlo_qcd_nlo_prediction = red.sum_mocanlo_data(mocanlo_nlo_qcd_born["data"], mocanlo_nlo_qcd_nlo["data"]) #(1+deltaNNLO QCD) delta_vbf = red.delta_mocanlo(red.sum_mocanlo_data( data["data"]["%s_proVBFH_NNLO_nonfact"%proVBF_setup], red.minus_mocanlo_data(data["data"]["%s_central_scale_proVBFH_NNLO"%proVBF_setup],data["data"]["%s_central_scale_proVBFH_NLO"%proVBF_setup])), data["data"]["%s_central_scale_proVBFH_LO"%proVBF_setup] ) one = [(i[0], i[1], 1, 0, 0) for i in delta_vbf] one_plus_delta_vbf = red.sum_mocanlo_data(one, delta_vbf) #(1+deltaNLO EW) delta_ew = red.sum_mocanlo_data(one, mocanlo_nlo_ew_no_photon_nlo["data"]) ##Delta photon (quick and dirty rescaling) #delta_ew_photon_only_1 = mocanlo_nlo_ew_photon_only["data"] #mocanlo_nlo_ew_photon_only['data'] = [ # (entry[0], entry[1], entry[2] / 200., entry[3]/200., entry[4]/200.) # for entry in mocanlo_nlo_ew_photon_only['data'] #] best_2 = red.sum_mocanlo_data(red.product_top_mocanlo(mocanlo_qcd_nlo_prediction, red.product_top_mocanlo(one_plus_delta_vbf, delta_ew)), mocanlo_nlo_ew_photon_only) #################################################################################################################### full_nlo_ew_w_photon = red.sum_mocanlo_data(one, red.delta_mocanlo(mocanlo_nlo_ew_w_photon_nlo["data"], mocanlo_nlo_ew_w_photon_born["data"])) full_nlo_ew_photon_only = red.sum_mocanlo_data(one, red.delta_mocanlo(mocanlo_nlo_ew_photon_only["data"],mocanlo_nlo_ew_w_photon_born["data"])) mocanlo_correction_and_born = red.sum_mocanlo_data(mocanlo_nlo_qcd_nlo["data"], mocanlo_nlo_qcd_born["data"]) data["data"]["MoCaNLO_LO"] = mocanlo_nlo_ew_w_photon_born["data"] #delta_ew_photon_only_1 = mocanlo_nlo_ew_photon_only["data"] #mocanlo_nlo_ew_w_photon_born['data'] = [ # (entry[0], entry[1], entry[2] / 200., entry[3]/200., entry[4]/200.) # for entry in mocanlo_nlo_ew_w_photon_born['data'] #] data["data"]["MoCaNLO_NLO_QCD_ratio"] = red.delta_mocanlo(mocanlo_correction_and_born, data["data"]["%s_central_scale_proVBFH_NLO"%proVBF_setup]) data["data"]["MoCaNLO_LO_QCD_ratio"] = red.delta_mocanlo(mocanlo_nlo_ew_w_photon_born["data"], data["data"]["%s_central_scale_proVBFH_LO"%proVBF_setup]) data["data"]["MoCaNLO_loop_induced"] = mocanlo_loop_induced["data"] data["data"]["MoCaNLO_loop_induced_2"] = mocanlo_loop_induced_2["data"] data["data"]["MoCaNLO_ggF_LO"] = mocanlo_ggF_born["data"] data["data"]["best_prediction_final"] = best_2 data["data"]["full_nlo_ew_w_photon"] = full_nlo_ew_w_photon data["data"]["full_nlo_ew_photon_only"] = full_nlo_ew_photon_only data["data"]["%s_central_scale_proVBFH_LO_ratio"%proVBF_setup] = red.delta_mocanlo(data["data"]["%s_central_scale_proVBFH_LO"%proVBF_setup], data["data"]["%s_central_scale_proVBFH_NLO"%proVBF_setup]) data["data"]["%s_central_scale_proVBFH_NLO_ratio"%proVBF_setup] = red.delta_mocanlo(data["data"]["%s_central_scale_proVBFH_NLO"%proVBF_setup], data["data"]["%s_central_scale_proVBFH_NLO"%proVBF_setup]) data["data"]["%s_central_scale_proVBFH_NNLO_ratio"%proVBF_setup] = red.delta_mocanlo(data["data"]["%s_central_scale_proVBFH_NNLO"%proVBF_setup], data["data"]["%s_central_scale_proVBFH_NLO"%proVBF_setup]) data["data"]["%s_proVBFH_NNLO_nonfact_ratio"%proVBF_setup] = red.sum_mocanlo_data(one, red.delta_mocanlo(data["data"]["%s_proVBFH_NNLO_nonfact"%proVBF_setup], data["data"]["%s_central_scale_proVBFH_NLO"%proVBF_setup]) ) plotter = HistoPlotter(reader) fig = plotter.get_bigstxs_complex_histogram_histogramlike(data, reference_list, label_mapping, x_min, x_max, 0, custom_color_map=color_mapping, settings=settings) fig.savefig(save_path)