def make_table():

    xparam = 'kappa_V'
    yparam = 'kappa_F'

    # Load results + xsbr data
    inputMode = "kappas"
    translatePOIs = LoadTranslations("translate/pois_%s.json" % inputMode)

    # Extract observed results
    fobs = "/afs/cern.ch/work/j/jlangfor/hgg/legacy/FinalFits/UL/Dec20/CMSSW_10_2_13/src/flashggFinalFit/Combine/runFits_UL_redo_kVkF/output_scan2D_syst_fixedMH_v2_obs_kappa_V_vs_kappa_F.root"
    f_in = ROOT.TFile(fobs)
    t_in = f_in.Get("limit")
    xvals, yvals, deltaNLL = [], [], []
    ev_idx = 0
    for ev in t_in:
        xvals.append(getattr(ev, xparam))
        yvals.append(getattr(ev, yparam))
        deltaNLL.append(getattr(ev, "deltaNLL"))

    # Convert to numpy arrays as required for interpolation
    x = np.asarray(xvals)
    y = np.asarray(yvals)
    dnll = np.asarray(deltaNLL)
    v = 2 * (deltaNLL - np.min(deltaNLL))

    # Make table of results
    table = Table("Kappas 2D: vector boson and fermion")
    table.description = "Observed likelihood surface."
    table.location = "Results from Figure 22"
    table.keywords["reactions"] = ["P P --> H ( --> GAMMA GAMMA ) X"]

    pois_x = Variable(str(Translate(xparam, translatePOIs)),
                      is_independent=True,
                      is_binned=False)
    pois_y = Variable(str(Translate(yparam, translatePOIs)),
                      is_independent=True,
                      is_binned=False)
    q = Variable("Observed -2$\\Delta$NLL",
                 is_independent=False,
                 is_binned=False)
    q.add_qualifier("SQRT(S)", 13, "TeV")
    q.add_qualifier("MH", '125.38', "GeV")

    pois_x.values = x
    pois_y.values = y
    q.values = np.round(np.array(v), 2)

    # Add variables to table
    table.add_variable(pois_x)
    table.add_variable(pois_y)
    table.add_variable(q)

    # Add figure
    table.add_image(
        "/afs/cern.ch/work/j/jlangfor/hgg/legacy/FinalFits/UL/Dec20/CMSSW_10_2_13/src/OtherScripts/HEPdata/hepdata_lib/hig-19-015/inputs/scan2D_syst_obs_kappa_V_vs_kappa_F.pdf"
    )

    return table
Exemplo n.º 2
0
def make_table():
    params = ['r_ggH', 'r_VBF', 'r_VH', 'r_top']

    # Load results + xsbr data
    inputMode = "mu"
    translatePOIs = LoadTranslations("translate/pois_%s.json" % inputMode)
    with open(
            "/afs/cern.ch/work/j/jlangfor/hgg/legacy/FinalFits/UL/Dec20/CMSSW_10_2_13/src/OtherScripts/HEPdata/hepdata_lib/hig-19-015/inputs/correlations_mu.json",
            "r") as jf:
        correlations = json.load(jf)
    with open(
            "/afs/cern.ch/work/j/jlangfor/hgg/legacy/FinalFits/UL/Dec20/CMSSW_10_2_13/src/OtherScripts/HEPdata/hepdata_lib/hig-19-015/inputs/correlations_expected_mu.json",
            "r") as jf:
        correlations_exp = json.load(jf)

    # Make table of results
    table = Table("Correlations: production mode signal strength")
    table.description = "Observed and expected correlations between the parameters in the production mode signal strength fit."
    table.location = "Results from additional material"
    table.keywords["reactions"] = ["P P --> H ( --> GAMMA GAMMA ) X"]

    pois_x = Variable("Parameter (x)", is_independent=True, is_binned=False)
    pois_y = Variable("Parameter (y)", is_independent=True, is_binned=False)
    c = Variable("Observed correlation", is_independent=False, is_binned=False)
    c.add_qualifier("SQRT(S)", 13, "TeV")
    c.add_qualifier("MH", '125.38', "GeV")
    c_exp = Variable("Expected correlation",
                     is_independent=False,
                     is_binned=False)
    c_exp.add_qualifier("SQRT(S)", 13, "TeV")
    c_exp.add_qualifier("MH", '125.38', "GeV")

    poiNames_x = []
    poiNames_y = []
    corr = []
    corr_exp = []
    for ipoi in params:
        for jpoi in params:
            poiNames_x.append(str(Translate(ipoi, translatePOIs)))
            poiNames_y.append(str(Translate(jpoi, translatePOIs)))
            # Extract correlation coefficient
            corr.append(correlations["%s__%s" % (ipoi, jpoi)])
            corr_exp.append(correlations_exp["%s__%s" % (ipoi, jpoi)])
    pois_x.values = poiNames_x
    pois_y.values = poiNames_y
    c.values = np.round(np.array(corr), 3)
    c_exp.values = np.round(np.array(corr_exp), 3)

    # Add variables to table
    table.add_variable(pois_x)
    table.add_variable(pois_y)
    table.add_variable(c)
    table.add_variable(c_exp)

    # Add figure
    table.add_image(
        "/afs/cern.ch/work/j/jlangfor/hgg/legacy/FinalFits/UL/Dec20/CMSSW_10_2_13/src/OtherScripts/HEPdata/hepdata_lib/hig-19-015/inputs/perproc_mu_corr.pdf"
    )

    return table
Exemplo n.º 3
0
    def test_make_dict(self):
        """Test the make_dict function."""
        # pylint: disable=no-self-use
        var = Variable("testvar")

        # With or without units
        for units in ["", "GeV"]:
            var.units = units

            # Binned
            var.is_binned = False
            var.values = [1, 2, 3]
            var.make_dict()

            # Unbinned
            var.is_binned = True
            var.values = [(0, 1), (1, 2), (2, 3)]
            var.make_dict()

        # With symmetric uncertainty
        unc1 = Uncertainty("unc1")
        unc1.is_symmetric = True
        unc1.values = [random.random() for _ in range(len(var.values))]
        var.add_uncertainty(unc1)
        var.make_dict()

        # With asymmetric uncertainty
        unc2 = Uncertainty("unc2")
        unc2.is_symmetric = False
        unc2.values = [(-random.random(), random.random())
                       for _ in range(len(var.values))]
        var.add_uncertainty(unc2)
        var.make_dict()

        # With qualifiers (which only apply to dependent variables)
        var.is_independent = False
        var.add_qualifier("testqualifier1", 1, units="GeV")
        var.add_qualifier("testqualifier2", 1, units="")
        var.make_dict()
Exemplo n.º 4
0
def convertCorrMatrixToYaml( rootfile, label, variablex, variabley, unit, object="output_corr_matrix_syst", var="Syst. correlation" ):

    tab = Table(label)

    reader = RootFileReader(rootfile)

    cov = reader.read_hist_2d(object)

    xbins = Variable( variablex, is_independent=True, is_binned=True, units=unit)
    xbins.values = cov["x_edges"]
    ybins = Variable( variabley, is_independent=True, is_binned=True, units=unit)
    ybins.values = cov["y_edges"]

    data = Variable( var, is_independent=False, is_binned=False, units="%")
    data.values = cov["z"]
    data.add_qualifier("SQRT(S)","13","TeV")
    data.add_qualifier("LUMINOSITY","137","fb$^{-1}$")

    tab.add_variable(xbins)
    tab.add_variable(ybins)
    tab.add_variable(data)

    return tab
Exemplo n.º 5
0
    def test_add_qualifier(self):
        """Test the 'add_qualifier' function"""

        # Initialize dependent variable
        var = Variable("testvar")
        var.is_binned = False
        var.values = range(5)
        var.is_independent = False

        # This should work fine
        try:
            var.add_qualifier("Some Name 1", "Some value 1", "Some unit 1")
            var.add_qualifier("Some Name 2", "Some value 2")
        except RuntimeError:
            self.fail(
                "Variable.add_qualifier raised an unexpected RuntimeError.")

        # For an independent variable, an exception should be raised
        var.is_independent = True
        with self.assertRaises(RuntimeError):
            var.add_qualifier("Some Name 3", "Some value 3")
        with self.assertRaises(RuntimeError):
            var.add_qualifier("Some Name 4", "Some value 4", "Some unit 4")
Exemplo n.º 6
0
def convertSRHistToYaml( rootfile, label, variable, unit ):

    tab = Table(label)

    reader = RootFileReader(rootfile)

    data = reader.read_hist_1d("dataAR")
    gen = reader.read_hist_1d("TTG_centralnoChgIsoNoSieiephotoncat0")
    had = reader.read_hist_1d("TTG_centralnoChgIsoNoSieiephotoncat134")
    misID = reader.read_hist_1d("TTG_centralnoChgIsoNoSieiephotoncat2")
    qcd = reader.read_hist_1d("QCD")
    uncUp = reader.read_hist_1d("totalUncertainty_up")
    uncDown = reader.read_hist_1d("totalUncertainty_down")

    rootfile = ROOT.TFile(rootfile,"READ")
    statHist = rootfile.Get("dataAR")

    unc = []
    statunc = []
    relunc = []
    tot = []
    for i, i_up in enumerate(uncUp["y"]):
        stat = statHist.GetBinError(i+1)
        u = abs(i_up-uncDown["y"][i])*0.5
        sim = sum([ gen["y"][i], had["y"][i], misID["y"][i], qcd["y"][i] ])
        unc.append(u)
        statunc.append(stat)
        tot.append(sim)
        relunc.append(u*100./sim)

    xbins = Variable( variable, is_independent=True, is_binned=True, units=unit)
    xbins.values = data["x_edges"]
    ydata = Variable( "Observed", is_independent=False, is_binned=False)
    ydata.values = data["y"]
    ydata.add_qualifier("CHANNEL","l+jets")
    ydata.add_qualifier("SQRT(S)","13","TeV")
    ydata.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ytot = Variable( "Total simulation", is_independent=False, is_binned=False)
    ytot.values = tot
    ytot.add_qualifier("CHANNEL","l+jets")
    ytot.add_qualifier("SQRT(S)","13","TeV")
    ytot.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ygen = Variable( "Genuine $\gamma$", is_independent=False, is_binned=False)
    ygen.values = gen["y"]
    ygen.add_qualifier("CHANNEL","l+jets")
    ygen.add_qualifier("SQRT(S)","13","TeV")
    ygen.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yhad = Variable( "Hadronic $\gamma$", is_independent=False, is_binned=False)
    yhad.values = had["y"]
    yhad.add_qualifier("CHANNEL","l+jets")
    yhad.add_qualifier("SQRT(S)","13","TeV")
    yhad.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ymisID = Variable( "Misid. e", is_independent=False, is_binned=False)
    ymisID.values = misID["y"]
    ymisID.add_qualifier("CHANNEL","l+jets")
    ymisID.add_qualifier("SQRT(S)","13","TeV")
    ymisID.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yqcd = Variable( "Multijet", is_independent=False, is_binned=False)
    yqcd.values = qcd["y"]
    yqcd.add_qualifier("CHANNEL","l+jets")
    yqcd.add_qualifier("SQRT(S)","13","TeV")
    yqcd.add_qualifier("LUMINOSITY","137","fb$^{-1}$")

    yunc = Uncertainty( "syst" )
    yunc.is_symmetric = True
    yunc.values = unc

    ystatunc = Uncertainty( "stat" )
    ystatunc.is_symmetric = True
    ystatunc.values = statunc

    ydata.uncertainties.append(ystatunc)
    ytot.uncertainties.append(yunc)

    tab.add_variable(xbins)
    tab.add_variable(ydata)
    tab.add_variable(ytot)
    tab.add_variable(ygen)
    tab.add_variable(yhad)
    tab.add_variable(ymisID)
    tab.add_variable(yqcd)

    return tab
Exemplo n.º 7
0
def makeCutFlow(submission, config):
    table = Table(config["name"])
    table.description = config["description"]
    table.location = config["location"]
    #table.keywords["observables"] = ["SIG"]
    #table.keywords["reactions"] = ["P P --> TOP --> tt + 6j"]

    data1 = config["data1"]
    error1 = config["error1"]
    data2 = config["data2"]
    error2 = config["error2"]

    #####################################################################################
    d = Variable("Step", is_independent=True, is_binned=False, units="")
    d.values = np.array(list(i for i in range(0, data1.size)))

    cuts = Variable("Selection requirement",
                    is_independent=False,
                    is_binned=False,
                    units="")
    cuts.values = config["cutnames"]
    cuts.add_qualifier("SQRT(S)", 13, "TeV")
    cuts.add_qualifier("LUMINOSITY", config["lumi"], "fb$^{-1}$")

    obs1 = Variable("RPV $m_{\\tilde{t}}$ = 450 GeV",
                    is_independent=False,
                    is_binned=False,
                    units="")
    obs1.values = data1
    obs1.add_qualifier("SQRT(S)", 13, "TeV")
    obs1.add_qualifier("LUMINOSITY", config["lumi"], "fb$^{-1}$")

    unc_obs1 = Uncertainty("1 s.d.", is_symmetric=True)
    unc_obs1.values = error1
    obs1.add_uncertainty(unc_obs1)

    obs2 = Variable("SYY $m_{\\tilde{t}}$ = 850 GeV",
                    is_independent=False,
                    is_binned=False,
                    units="")
    obs2.values = data2
    obs2.add_qualifier("SQRT(S)", 13, "TeV")
    obs2.add_qualifier("LUMINOSITY", config["lumi"], "fb$^{-1}$")

    unc_obs2 = Uncertainty("1 s.d.", is_symmetric=True)
    unc_obs2.values = error2
    obs2.add_uncertainty(unc_obs2)

    table.add_variable(d)
    table.add_variable(cuts)
    table.add_variable(obs1)
    table.add_variable(obs2)
    submission.add_table(table)
Exemplo n.º 8
0
def convertMlgHistToYaml( rootfile, label, variable, channel ):

    tab = Table(label)

    reader = RootFileReader(rootfile)

    data = reader.read_hist_1d("dataAR")
    misID = reader.read_hist_1d("TTG_centralnoChgIsoNoSieiephotoncat2")
    wg = reader.read_hist_1d("WG_centralnoChgIsoNoSieiephotoncat0")
    zg = reader.read_hist_1d("ZG_centralnoChgIsoNoSieiephotoncat0")
    other = reader.read_hist_1d("TTG_centralnoChgIsoNoSieiephotoncat0")
    had = reader.read_hist_1d("TTG_centralnoChgIsoNoSieiephotoncat134")
    qcd = reader.read_hist_1d("QCD")

    uncUp = reader.read_hist_1d("totalUncertainty_up")
    uncDown = reader.read_hist_1d("totalUncertainty_down")

    rootfile = ROOT.TFile(rootfile,"READ")
    statHist = rootfile.Get("dataAR")

    unc = []
    statunc = []
    relunc = []
    tot = []
    for i, i_up in enumerate(uncUp["y"]):
        stat = statHist.GetBinError(i+1)
        u = abs(i_up-uncDown["y"][i])*0.5
        all = [ misID["y"][i], wg["y"][i], zg["y"][i], other["y"][i], had["y"][i], qcd["y"][i] ]
        sim = sum(all)
        unc.append(u)
        statunc.append(stat)
        tot.append(sim)
        relunc.append(u*100./sim)

    xbins = Variable( variable, is_independent=True, is_binned=True, units="GeV")
    xbins.values = data["x_edges"]
    ydata = Variable( "Observed", is_independent=False, is_binned=False)
    ydata.values = data["y"]
    ydata.add_qualifier("CHANNEL",channel)
    ydata.add_qualifier("SQRT(S)","13","TeV")
    ydata.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ytot = Variable( "Total simulation", is_independent=False, is_binned=False)
    ytot.values = tot
    ytot.add_qualifier("CHANNEL",channel)
    ytot.add_qualifier("SQRT(S)","13","TeV")
    ytot.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ymisID = Variable( "Misid. e", is_independent=False, is_binned=False)
    ymisID.values = misID["y"]
    ymisID.add_qualifier("CHANNEL",channel)
    ymisID.add_qualifier("SQRT(S)","13","TeV")
    ymisID.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yhad = Variable( "Hadronic $\gamma$", is_independent=False, is_binned=False)
    yhad.values = had["y"]
    yhad.add_qualifier("CHANNEL",channel)
    yhad.add_qualifier("SQRT(S)","13","TeV")
    yhad.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ywg = Variable( "W$\gamma$", is_independent=False, is_binned=False)
    ywg.values = wg["y"]
    ywg.add_qualifier("CHANNEL",channel)
    ywg.add_qualifier("SQRT(S)","13","TeV")
    ywg.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yzg = Variable( "Z$\gamma$", is_independent=False, is_binned=False)
    yzg.values = zg["y"]
    yzg.add_qualifier("CHANNEL",channel)
    yzg.add_qualifier("SQRT(S)","13","TeV")
    yzg.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yother = Variable( "Other", is_independent=False, is_binned=False)
    yother.values = other["y"]
    yother.add_qualifier("CHANNEL",channel)
    yother.add_qualifier("SQRT(S)","13","TeV")
    yother.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yqcd = Variable( "Multijet", is_independent=False, is_binned=False)
    yqcd.values = qcd["y"]
    yqcd.add_qualifier("CHANNEL",channel)
    yqcd.add_qualifier("SQRT(S)","13","TeV")
    yqcd.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
#    yunc = Variable( "Total systematic uncertainty", is_independent=False, is_binned=False)
#    yunc.values = unc
#    yunc.add_qualifier("SQRT(S)","13","TeV")
#    yunc.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    #yrelunc = Variable( "Rel. uncertainty (%)", is_independent=False, is_binned=False)
    #yrelunc.values = relunc

    yunc = Uncertainty( "syst" )
    yunc.is_symmetric = True
    yunc.values = unc

    ystatunc = Uncertainty( "stat" )
    ystatunc.is_symmetric = True
    ystatunc.values = statunc

    ydata.uncertainties.append(ystatunc)
    ytot.uncertainties.append(yunc)

    tab.add_variable(xbins)
    tab.add_variable(ydata)
    tab.add_variable(ytot)
    tab.add_variable(ymisID)
    tab.add_variable(ywg)
    tab.add_variable(yzg)
    tab.add_variable(yother)
    tab.add_variable(yhad)
    tab.add_variable(yqcd)
#    tab.add_variable(yunc)

    return tab
Exemplo n.º 9
0
def convertSRPlotToYaml():

    tab = Table("Figure 6")

    reader = RootFileReader("../regionPlots/SR_incl.root")

    data = reader.read_hist_1d("0dc_2016data")
    tot = reader.read_hist_1d("0dc_2016total")
    totbkg = reader.read_hist_1d("0dc_2016total_background")
    ttg = reader.read_hist_1d("0dc_2016signal")
    misID = reader.read_hist_1d("0dc_2016misID")
    had = reader.read_hist_1d("0dc_2016fakes")
    other = reader.read_hist_1d("0dc_2016other")
    wg = reader.read_hist_1d("0dc_2016WG")
    qcd = reader.read_hist_1d("0dc_2016QCD")
    zg = reader.read_hist_1d("0dc_2016ZG")

    rootfile = ROOT.TFile("../regionPlots/SR_incl.root","READ")
    totHist = rootfile.Get("0dc_2016total")
    datHist = rootfile.Get("0dc_2016data")

    unc = []
    statunc = []
    relunc = []
    for i, i_tot in enumerate(tot["y"]):
        u = totHist.GetBinError(i+1)
        ustat = datHist.GetBinError(i+1)
        unc.append(u)
        statunc.append(ustat)
        relunc.append(u*100./i_tot)

    crBinLabel = [
            "SR3, e, $M_{3}$ $<$ 280 GeV",
            "SR3, e, 280 $\leq$ $M_{3}$ $<$ 420 GeV",
            "SR3, e, $M_{3}$ $\geq$ 420 GeV",
            "SR3, $\mu$, $M_{3}$ $<$ 280 GeV",
            "SR3, $\mu$, 280 $\leq$ $M_{3}$ $<$ 420 GeV",
            "SR3, $\mu$, $M_{3}$ $\geq$ 420 GeV",
            "SR4p, e, $M_{3}$ $<$ 280 GeV",
            "SR4p, e, 280 $\leq$ $M_{3}$ $<$ 420 GeV",
            "SR4p, e, $M_{3}$ $\geq$ 420 GeV",
            "SR4p, $\mu$, $M_{3}$ $<$ 280 GeV",
            "SR4p, $\mu$, 280 $\leq$ $M_{3}$ $<$ 420 GeV",
            "SR4p, $\mu$, $M_{3}$ $\geq$ 420 GeV",
            ]
    xbins = Variable( "Bin", is_independent=True, is_binned=False)
    xbins.values = crBinLabel
    ydata = Variable( "Observed", is_independent=False, is_binned=False)
    ydata.values = data["y"]
    ydata.add_qualifier("SQRT(S)","13","TeV")
    ydata.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ytot = Variable( "Total simulation", is_independent=False, is_binned=False)
    ytot.values = tot["y"]
    ytot.add_qualifier("SQRT(S)","13","TeV")
    ytot.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ytotbkg = Variable( "Total background", is_independent=False, is_binned=False)
    ytotbkg.values = totbkg["y"]
    ytotbkg.add_qualifier("SQRT(S)","13","TeV")
    ytotbkg.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ywg = Variable( "$W\gamma$", is_independent=False, is_binned=False)
    ywg.values = wg["y"]
    ywg.add_qualifier("SQRT(S)","13","TeV")
    ywg.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yzg = Variable( "$Z\gamma$", is_independent=False, is_binned=False)
    yzg.values = zg["y"]
    yzg.add_qualifier("SQRT(S)","13","TeV")
    yzg.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ymisID = Variable( "Misid. e", is_independent=False, is_binned=False)
    ymisID.values = misID["y"]
    ymisID.add_qualifier("SQRT(S)","13","TeV")
    ymisID.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yhad = Variable( "Hadronic $\gamma$", is_independent=False, is_binned=False)
    yhad.values = had["y"]
    yhad.add_qualifier("SQRT(S)","13","TeV")
    yhad.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yqcd = Variable( "Multijet", is_independent=False, is_binned=False)
    yqcd.values = qcd["y"]
    yqcd.add_qualifier("SQRT(S)","13","TeV")
    yqcd.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yttg = Variable( "tt$\gamma$", is_independent=False, is_binned=False)
    yttg.values = ttg["y"]
    yttg.add_qualifier("SQRT(S)","13","TeV")
    yttg.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yother = Variable( "Other", is_independent=False, is_binned=False)
    yother.values = other["y"]
    yother.add_qualifier("SQRT(S)","13","TeV")
    yother.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
#    yunc = Variable( "Total uncertainty", is_independent=False, is_binned=False)
#    yunc.values = unc
#    yunc.add_qualifier("SQRT(S)","13","TeV")
#    yunc.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    #yrelunc = Variable( "Rel. uncertainty (%)", is_independent=False, is_binned=False)
    #yrelunc.values = relunc

    yunc = Uncertainty( "syst" )
    yunc.is_symmetric = True
    yunc.values = unc

    ystatunc = Uncertainty( "stat" )
    ystatunc.is_symmetric = True
    ystatunc.values = statunc

    ydata.uncertainties.append(ystatunc)
    ytot.uncertainties.append(yunc)


    tab.add_variable(xbins)
    tab.add_variable(ydata)
    tab.add_variable(ytot)
    tab.add_variable(ytotbkg)
    tab.add_variable(yttg)
    tab.add_variable(ymisID)
    tab.add_variable(yhad)
    tab.add_variable(yother)
    tab.add_variable(ywg)
    tab.add_variable(yqcd)
    tab.add_variable(yzg)
#    tab.add_variable(yunc)

    return tab
table4.location = "Data from Table 4"

table4.keywords["observables"] = ["Uncertainty"]
table4.keywords["reactions"] = ["P P --> W W j j"]
table4.keywords["phrases"] = ["VBS", "Polarized", "Same-sign WW"]

data4 = np.loadtxt("HEPData/inputs/smp20006/systematics.txt", dtype='string', skiprows=2)

print(data4)

table4_data = Variable("Source of uncertainty", is_independent=True, is_binned=False, units="")
table4_data.values = [str(x) for x in data4[:,0]]

table4_yields0 = Variable("Uncertainty", is_independent=False, is_binned=False, units="")
table4_yields0.values = [float(x) for x in data4[:,1]]
table4_yields0.add_qualifier("Source of uncertainty", "$\mathrm{W}^\pm_{\mathrm{L}}\mathrm{W}^\pm_{\mathrm{L}}$")
table4_yields0.add_qualifier("SQRT(S)", 13, "TeV")
table4_yields0.add_qualifier("L$_{\mathrm{int}}$", 137, "fb$^{-1}$")

table4_yields1 = Variable("Uncertainty", is_independent=False, is_binned=False, units="")
table4_yields1.values = [float(x) for x in data4[:,2]]
table4_yields1.add_qualifier("Source of uncertainty", "$\mathrm{W}^\pm_{\mathrm{X}}\mathrm{W}^\pm_{\mathrm{T}}$")
table4_yields1.add_qualifier("SQRT(S)", 13, "TeV")
table4_yields1.add_qualifier("L$_{\mathrm{int}}$", 137, "fb$^{-1}$")

table4_yields2 = Variable("Uncertainty", is_independent=False, is_binned=False, units="")
table4_yields2.values = [float(x) for x in data4[:,3]]
table4_yields2.add_qualifier("Source of uncertainty", "$\mathrm{W}^\pm_{\mathrm{L}}\mathrm{W}^\pm_{\mathrm{X}}$")
table4_yields2.add_qualifier("SQRT(S)", 13, "TeV")
table4_yields2.add_qualifier("L$_{\mathrm{int}}$", 137, "fb$^{-1}$")
def make_table():
    params = ['r_ggH', 'r_VBF', 'r_VH', 'r_top', 'r_inclusive']

    # Load results + xsbr data
    inputExpResultsJson = '/afs/cern.ch/work/j/jlangfor/hgg/legacy/FinalFits/UL/Dec20/CMSSW_10_2_13/src/flashggFinalFit/Plots/expected_UL_redo.json'
    inputObsResultsJson = '/afs/cern.ch/work/j/jlangfor/hgg/legacy/FinalFits/UL/Dec20/CMSSW_10_2_13/src/flashggFinalFit/Plots/observed_UL_redo.json'
    inputMode = "mu"

    translatePOIs = LoadTranslations("translate/pois_%s.json" % inputMode)
    observed = CopyDataFromJsonFile(inputObsResultsJson, inputMode, params)
    expected = CopyDataFromJsonFile(inputExpResultsJson, inputMode, params)

    # Make table of results
    table = Table("Signal strengths")
    table.description = "Best-fit values and 68% confidence intervals for the signal strength modifiers. The uncertainty is decomposed ino the theoretical systematic, experimental systematic and statistical components. Additionally, the expected uncertainties derived using an asimov dataset are provided."
    table.location = "Results from Figure 16"
    table.keywords["reactions"] = ["P P --> H ( --> GAMMA GAMMA ) X"]

    pois = Variable("Parameter", is_independent=True, is_binned=False)
    poiNames = []
    for poi in params:
        poiNames.append(str(Translate(poi, translatePOIs)))
    pois.values = poiNames

    # Dependent variables

    # Observed values
    obs = Variable("Observed", is_independent=False, is_binned=False, units='')
    obs.add_qualifier("SQRT(S)", 13, "TeV")
    obs.add_qualifier("MH", '125.38', "GeV")
    # Add uncertainties
    tot = Uncertainty("Total", is_symmetric=False)
    th = Uncertainty("Th. syst", is_symmetric=False)
    exp = Uncertainty("Exp. syst", is_symmetric=False)
    stat = Uncertainty("Stat only", is_symmetric=False)

    vals = []
    hi_tot, lo_tot = [], []
    hi_th, lo_th = [], []
    hi_exp, lo_exp = [], []
    hi_stat, lo_stat = [], []
    for poi in params:
        vals.append(observed[poi]['Val'])
        hi_tot.append(abs(observed[poi]['ErrorHi']))
        lo_tot.append(-1 * abs(observed[poi]['ErrorLo']))
        hi_th.append(abs(observed[poi]['TheoryHi']))
        lo_th.append(-1 * abs(observed[poi]['TheoryLo']))
        hi_exp.append(abs(observed[poi]['SystHi']))
        lo_exp.append(-1 * abs(observed[poi]['SystLo']))
        hi_stat.append(abs(observed[poi]['StatHi']))
        lo_stat.append(-1 * abs(observed[poi]['StatLo']))

    tot.values = zip(np.round(np.array(lo_tot), 3),
                     np.round(np.array(hi_tot), 3))
    th.values = zip(np.round(np.array(lo_th), 3), np.round(np.array(hi_th), 3))
    exp.values = zip(np.round(np.array(lo_exp), 3),
                     np.round(np.array(hi_exp), 3))
    stat.values = zip(np.round(np.array(lo_stat), 3),
                      np.round(np.array(hi_stat), 3))

    obs.values = np.round(np.array(vals), 3)
    obs.add_uncertainty(tot)
    obs.add_uncertainty(th)
    obs.add_uncertainty(exp)
    obs.add_uncertainty(stat)

    # Expected values
    ex = Variable("Expected", is_independent=False, is_binned=False, units='')
    ex.add_qualifier("SQRT(S)", 13, "TeV")
    ex.add_qualifier("MH", '125.38', "GeV")
    # Add uncertainties
    etot = Uncertainty("Total", is_symmetric=False)
    eth = Uncertainty("Th. syst", is_symmetric=False)
    eexp = Uncertainty("Exp. syst", is_symmetric=False)
    estat = Uncertainty("Stat only", is_symmetric=False)

    vals = []
    hi_tot, lo_tot = [], []
    hi_th, lo_th = [], []
    hi_exp, lo_exp = [], []
    hi_stat, lo_stat = [], []
    for poi in params:
        vals.append(1.00)
        hi_tot.append(abs(expected[poi]['ErrorHi']))
        lo_tot.append(-1 * abs(expected[poi]['ErrorLo']))
        hi_th.append(abs(expected[poi]['TheoryHi']))
        lo_th.append(-1 * abs(expected[poi]['TheoryLo']))
        hi_exp.append(abs(expected[poi]['SystHi']))
        lo_exp.append(-1 * abs(expected[poi]['SystLo']))
        hi_stat.append(abs(expected[poi]['StatHi']))
        lo_stat.append(-1 * abs(expected[poi]['StatLo']))

    etot.values = zip(np.round(np.array(lo_tot), 3),
                      np.round(np.array(hi_tot), 3))
    eth.values = zip(np.round(np.array(lo_th), 3),
                     np.round(np.array(hi_th), 3))
    eexp.values = zip(np.round(np.array(lo_exp), 3),
                      np.round(np.array(hi_exp), 3))
    estat.values = zip(np.round(np.array(lo_stat), 3),
                       np.round(np.array(hi_stat), 3))

    ex.values = np.round(np.array(vals), 3)
    ex.add_uncertainty(etot)
    ex.add_uncertainty(eth)
    ex.add_uncertainty(eexp)
    ex.add_uncertainty(estat)

    # Add variables to table
    table.add_variable(pois)
    table.add_variable(obs)
    table.add_variable(ex)

    # Add figure
    table.add_image(
        "/afs/cern.ch/work/j/jlangfor/hgg/legacy/FinalFits/UL/Dec20/CMSSW_10_2_13/src/OtherScripts/HEPdata/hepdata_lib/hig-19-015/inputs/perproc_mu_coloured.pdf"
    )

    return table
Exemplo n.º 12
0
def addLimitPlot(submission, config):
    table = Table(config["name"])
    table.description = config["description"]
    table.location = config["location"]
    table.keywords["observables"] = ["SIG"]
    table.keywords["reactions"] = ["P P --> TOP --> tt + 6j"]
    table.add_image(config["image"])

    reader = RootFileReader(config["inputData"])
    data = reader.read_limit_tree()
    stop_pair_Br = np.array([
        10.00, 4.43, 2.15, 1.11, 0.609, 0.347, 0.205, 0.125, 0.0783, 0.0500,
        0.0326, 0.0216, 0.0145, 0.00991, 0.00683, 0.00476, 0.00335, 0.00238,
        0.00170, 0.00122, 0.000887, 0.000646, 0.000473
    ])
    stop_pair_Br1SPpercent = np.array([
        6.65, 6.79, 6.99, 7.25, 7.530, 7.810, 8.120, 8.450, 8.8000, 9.1600,
        9.5300, 9.9300, 10.3300, 10.76, 11.2, 11.65, 12.12, 12.62, 13.13,
        13.66, 14.21, 14.78, 15.37
    ])
    stop_pair_unc = stop_pair_Br * stop_pair_Br1SPpercent / 100.0
    stop_pair_up = stop_pair_Br + stop_pair_unc
    stop_pair_down = stop_pair_Br - stop_pair_unc

    nData = len(data)
    for mass_id in range(0, nData):
        data[mass_id][1:] = stop_pair_Br[mass_id] * data[mass_id][1:]

    #####################################################################################
    d = Variable("Top squark mass",
                 is_independent=True,
                 is_binned=False,
                 units="GeV")
    d.values = data[:, 0]

    sig = Variable("Top squark cross section",
                   is_independent=False,
                   is_binned=False,
                   units="pb")
    sig.values = np.array(stop_pair_Br[:nData])
    sig.add_qualifier("Limit", "")
    sig.add_qualifier("SQRT(S)", 13, "TeV")
    sig.add_qualifier("LUMINOSITY", 137, "fb$^{-1}$")

    obs = Variable("Observed cross section upper limit at 95% CL",
                   is_independent=False,
                   is_binned=False,
                   units="pb")
    obs.values = data[:, 6]
    obs.add_qualifier("Limit", "Observed")
    obs.add_qualifier("SQRT(S)", 13, "TeV")
    obs.add_qualifier("LUMINOSITY", 137, "fb$^{-1}$")

    exp = Variable("Expected cross section upper limit at 95% CL",
                   is_independent=False,
                   is_binned=False,
                   units="pb")
    exp.values = data[:, 3]
    exp.add_qualifier("Limit", "Expected")
    exp.add_qualifier("SQRT(S)", 13, "TeV")
    exp.add_qualifier("LUMINOSITY", 137, "fb$^{-1}$")

    unc_sig = Uncertainty("1 s.d.", is_symmetric=False)
    unc_sig.set_values_from_intervals(zip(stop_pair_up[:nData],
                                          stop_pair_down[:nData]),
                                      nominal=sig.values)
    sig.add_uncertainty(unc_sig)

    # +/- 1 sigma
    unc_1s = Uncertainty("1 s.d.", is_symmetric=False)
    unc_1s.set_values_from_intervals(zip(data[:, 2], data[:, 4]),
                                     nominal=exp.values)
    exp.add_uncertainty(unc_1s)

    # +/- 2 sigma
    unc_2s = Uncertainty("2 s.d.", is_symmetric=False)
    unc_2s.set_values_from_intervals(zip(data[:, 1], data[:, 5]),
                                     nominal=exp.values)
    exp.add_uncertainty(unc_2s)

    table.add_variable(d)
    table.add_variable(sig)
    table.add_variable(obs)
    table.add_variable(exp)
    submission.add_table(table)
Exemplo n.º 13
0
def convertWJetsHistToYaml( rootfile, label, channel ):

    tab = Table(label)

    reader = RootFileReader(rootfile)

    data = reader.read_hist_1d("dataAR")
#    ttg = reader.read_hist_1d("TTG_centralall")
    top = reader.read_hist_1d("Top_centralall")
    dy = reader.read_hist_1d("DY_LO_centralall")
    wjets = reader.read_hist_1d("WJets_centralall")
#    wg = reader.read_hist_1d("WG_centralall")
#    zg = reader.read_hist_1d("ZG_centralall")
    other = reader.read_hist_1d("other_centralall")
    qcd = reader.read_hist_1d("QCD")

    uncUp = reader.read_hist_1d("totalUncertainty_up")
    uncDown = reader.read_hist_1d("totalUncertainty_down")

    rootfile = ROOT.TFile(rootfile,"READ")
    statHist = rootfile.Get("dataAR")

    unc = []
    statunc = []
    relunc = []
    tot = []
    for i, i_up in enumerate(uncUp["y"]):
        stat = statHist.GetBinError(i+1)
        u = abs(i_up-uncDown["y"][i])*0.5
#        all = [ ttg["y"][i], top["y"][i], dy["y"][i], wjets["y"][i], wg["y"][i], zg["y"][i], other["y"][i], qcd["y"][i] ]
        all = [ top["y"][i], dy["y"][i], wjets["y"][i], other["y"][i], qcd["y"][i] ]
        sim = sum(all)
        unc.append(u)
        statunc.append(stat)
        tot.append(sim)
        relunc.append(u*100./sim)

    xbins = Variable( "$m_{T}(W)$", is_independent=True, is_binned=True, units="GeV")
    xbins.values = data["x_edges"]
    ydata = Variable( "Observed", is_independent=False, is_binned=False)
    ydata.values = data["y"]
    ydata.add_qualifier("CHANNEL",channel)
    ydata.add_qualifier("SQRT(S)","13","TeV")
    ydata.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ytot = Variable( "Total simulation", is_independent=False, is_binned=False)
    ytot.values = tot
    ytot.add_qualifier("CHANNEL",channel)
    ytot.add_qualifier("SQRT(S)","13","TeV")
    ytot.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
#    yttg = Variable( "tt$\gamma$", is_independent=False, is_binned=False)
#    yttg.values = ttg["y"]
#    yttg.add_qualifier("CHANNEL",channel)
#    yttg.add_qualifier("SQRT(S)","13","TeV")
#    yttg.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ytop = Variable( "t/tt", is_independent=False, is_binned=False)
    ytop.values = top["y"]
    ytop.add_qualifier("CHANNEL",channel)
    ytop.add_qualifier("SQRT(S)","13","TeV")
    ytop.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ydy = Variable( "Drell-Yan", is_independent=False, is_binned=False)
    ydy.values = dy["y"]
    ydy.add_qualifier("CHANNEL",channel)
    ydy.add_qualifier("SQRT(S)","13","TeV")
    ydy.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ywjets = Variable( "W+jets", is_independent=False, is_binned=False)
    ywjets.values = wjets["y"]
    ywjets.add_qualifier("CHANNEL",channel)
    ywjets.add_qualifier("SQRT(S)","13","TeV")
    ywjets.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
#    ywg = Variable( "W$\gamma$", is_independent=False, is_binned=False)
#    ywg.values = wg["y"]
#    ywg.add_qualifier("CHANNEL",channel)
#    ywg.add_qualifier("SQRT(S)","13","TeV")
#    ywg.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
#    yzg = Variable( "Z$\gamma$", is_independent=False, is_binned=False)
#    yzg.values = zg["y"]
#    yzg.add_qualifier("CHANNEL",channel)
#    yzg.add_qualifier("SQRT(S)","13","TeV")
#    yzg.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yother = Variable( "Other", is_independent=False, is_binned=False)
    yother.values = other["y"]
    yother.add_qualifier("CHANNEL",channel)
    yother.add_qualifier("SQRT(S)","13","TeV")
    yother.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yqcd = Variable( "Multijet", is_independent=False, is_binned=False)
    yqcd.values = qcd["y"]
    yqcd.add_qualifier("CHANNEL",channel)
    yqcd.add_qualifier("SQRT(S)","13","TeV")
    yqcd.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
#    yunc = Variable( "Total systematic uncertainty", is_independent=False, is_binned=False)
#    yunc.values = unc
#    yunc.add_qualifier("SQRT(S)","13","TeV")
#    yunc.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    #yrelunc = Variable( "Rel. uncertainty (%)", is_independent=False, is_binned=False)
    #yrelunc.values = relunc

    yunc = Uncertainty( "syst" )
    yunc.is_symmetric = True
    yunc.values = unc

    ystatunc = Uncertainty( "stat" )
    ystatunc.is_symmetric = True
    ystatunc.values = statunc

    ydata.uncertainties.append(ystatunc)
    ytot.uncertainties.append(yunc)

    tab.add_variable(xbins)
    tab.add_variable(ydata)
    tab.add_variable(ytot)
    tab.add_variable(ywjets)
    tab.add_variable(yqcd)
    tab.add_variable(ydy)
    tab.add_variable(ytop)
    tab.add_variable(yother)
#    tab.add_variable(ywg)
#    tab.add_variable(yzg)
#    tab.add_variable(yttg)
#    tab.add_variable(yunc)

    return tab
Exemplo n.º 14
0
tabSF.description = "Extracted scale factors for the contribution from misidentified electrons for the three data-taking periods, and the Z$\gamma$, W$\gamma$ simulations."
tabSF.location = "Table 4"

sfType = Variable("Scale factor",
                  is_independent=True,
                  is_binned=False,
                  units="")
sfType.values = [
    "Misidentified electrons (2016)", "Misidentified electrons (2017)",
    "Misidentified electrons (2018)", "Z$\gamma$ normalization",
    "W$\gamma$ normalization"
]
value = Variable("Value", is_independent=False, is_binned=False, units="")
value.values = [2.25, 2.00, 1.52, 1.01, 1.13]
value.add_qualifier("SQRT(S)", "13", "TeV")
value.add_qualifier("LUMINOSITY", "137", "fb$^{-1}$")
unc = Uncertainty("total")
unc.is_symmetric = True
unc.values = [0.29, 0.27, 0.17, 0.10, 0.08]
value.uncertainties.append(unc)

tabSF.add_variable(sfType)
tabSF.add_variable(value)

tabSF.keywords["reactions"] = [
    "P P --> TOP TOPBAR X", "P P --> TOP TOPBAR GAMMA"
]
tabSF.keywords["cmenergies"] = [13000.0]
tabSF.keywords["phrases"] = [
    "Top", "Quark", "Photon", "lepton+jets", "semileptonic", "Cross Section",
Exemplo n.º 15
0
                   skiprows=2)

print(data2)

table2_data = Variable("Process",
                       is_independent=True,
                       is_binned=False,
                       units="none")
table2_data.values = [str(x) for x in data2[:, 0]]

table2_yields1 = Variable("WV events",
                          is_independent=False,
                          is_binned=False,
                          units="")
table2_yields1.values = [float(x) for x in data2[:, 1]]
table2_yields1.add_qualifier("Expected events", "WV selection")
table2_yields1.add_qualifier("SQRT(S)", 13, "TeV")
table2_yields1.add_qualifier("L$_{\mathrm{int}}$", 36.9, "fb$^{-1}$")

table2_unc1 = Uncertainty("stat,syst", is_symmetric=True)
table2_unc1.values = [float(x) for x in data2[:, 2]]

table2_yields2 = Variable("ZV events",
                          is_independent=False,
                          is_binned=False,
                          units="")
table2_yields2.values = [float(x) for x in data2[:, 3]]
table2_yields2.add_qualifier("Expected events", "ZV selection")
table2_yields2.add_qualifier("SQRT(S)", 13, "TeV")

table2_unc2 = Uncertainty("stat,syst", is_symmetric=True)
Exemplo n.º 16
0
                   skiprows=2)

print(data2)

table2_data = Variable("Source of uncertainty",
                       is_independent=True,
                       is_binned=False,
                       units="")
table2_data.values = [str(x) for x in data2[:, 0]]

table2_yields0 = Variable("Uncertainty",
                          is_independent=False,
                          is_binned=False,
                          units="")
table2_yields0.values = [float(x) for x in data2[:, 1]]
table2_yields0.add_qualifier("Source of uncertainty",
                             "$\Delta \mu$ for background-only")
table2_yields0.add_qualifier("SQRT(S)", 13, "TeV")
table2_yields0.add_qualifier("L$_{\mathrm{int}}$", 137, "fb$^{-1}$")

table2_yields1 = Variable("Uncertainty",
                          is_independent=False,
                          is_binned=False,
                          units="")
table2_yields1.values = [float(x) for x in data2[:, 2]]
table2_yields1.add_qualifier(
    "Source of uncertainty",
    "$\Delta \mu$ for $s_{\mathrm{H}}=1.0$ and $m_{\mathrm{H}_{5}}=500~\mathrm{GeV}$"
)
table2_yields1.add_qualifier("SQRT(S)", 13, "TeV")
table2_yields1.add_qualifier("L$_{\mathrm{int}}$", 137, "fb$^{-1}$")
print(data)

### Variable
from hepdata_lib import Variable
d = Variable("Resonance mass",
             is_independent=True,
             is_binned=False,
             units="GeV")
d.values = data[:, 0]

BulkG = Variable("Efficiency times acceptance",
                 is_independent=False,
                 is_binned=False,
                 units="")
BulkG.values = data[:, 1]
BulkG.add_qualifier("Efficiency times acceptance", "Bulk graviton --> WW")
BulkG.add_qualifier("SQRT(S)", 13, "TeV")

Wprime = Variable("Efficiency times acceptance",
                  is_independent=False,
                  is_binned=False,
                  units="")
Wprime.values = data[:, 2]
Wprime.add_qualifier("Efficiency times acceptance", "Wprime --> WZ")
Wprime.add_qualifier("SQRT(S)", 13, "TeV")

table.add_variable(d)
table.add_variable(BulkG)
table.add_variable(Wprime)

table.add_image("hepdata_lib/examples/example_inputs/signalEffVsMass.pdf")
figure2_load = np.loadtxt("HEPData/inputs/smp18003/cross_section_results.txt",
                          dtype='string',
                          skiprows=2)

print(figure2_load)

figure2_data = Variable("", is_independent=True, is_binned=False, units="")
figure2_data.values = [str(x) for x in figure2_load[:, 0]]

figure2_yields1 = Variable("Cross Section",
                           is_independent=False,
                           is_binned=False,
                           units="")
figure2_yields1.digits = 0
figure2_yields1.values = [int(x) for x in figure2_load[:, 1]]
figure2_yields1.add_qualifier("", "Cross Section (fb)")

figure2_yields2 = Variable("Positive uncertainty",
                           is_independent=False,
                           is_binned=False,
                           units="")
figure2_yields2.digits = 0
figure2_yields2.values = [int(x) for x in figure2_load[:, 2]]
figure2_yields2.add_qualifier("", "Cross Section (fb)")

figure2_yields3 = Variable("Negative uncertainty",
                           is_independent=False,
                           is_binned=False,
                           units="")
figure2_yields3.digits = 0
figure2_yields3.values = [int(x) for x in figure2_load[:, 3]]
Exemplo n.º 19
0
def convertUnfoldingHistToYaml( rootfile, label, variable, unit ):

    tab = Table(label)

    reader = RootFileReader(rootfile)

    data = reader.read_hist_1d("unfoled_spectrum")
    simP8 = reader.read_hist_1d("fiducial_spectrum")
    simHpp = reader.read_hist_1d("fiducial_spectrum_Hpp")
    simH7 = reader.read_hist_1d("fiducial_spectrum_H7")
    totalUncUp = reader.read_hist_1d("totalUncertainty_up")
    mcstatUncUp = reader.read_hist_1d("mcStat_up")
    matrixUncUp = reader.read_hist_1d("totalMatrixVariationUnc_up")
    statUncUp = reader.read_hist_1d("stat_up")

    totunc = []
    reltotunc = []
    statunc = []
    relstatunc = []
    for i, i_up in enumerate(totalUncUp["y"]):
        tot = data["y"][i]
        utot = (i_up - tot)**2
        utot += (mcstatUncUp["y"][i] - tot)**2
        utot += matrixUncUp["y"][i]**2
        utot = sqrt(utot)
        ustat = statUncUp["y"][i] - tot
        totunc.append(utot)
        statunc.append(ustat)
        reltotunc.append(utot*100./tot)
        relstatunc.append(ustat*100./tot)

    xbins = Variable( variable, is_independent=True, is_binned=True, units=unit)
    xbins.values = data["x_edges"]
    ydata = Variable( "Observed", is_independent=False, is_binned=False)
    ydata.values = data["y"]
    ydata.add_qualifier("SQRT(S)","13","TeV")
    ydata.add_qualifier("LUMINOSITY","137","fb$^{-1}$")


    yunc = Uncertainty( "total" )
    yunc.is_symmetric = True
    yunc.values = totunc

    ystatunc = Uncertainty( "stat" )
    ystatunc.is_symmetric = True
    ystatunc.values = statunc

#    ydata.uncertainties.append(ystatunc)
#    ydata.uncertainties.append(yunc)


    ysimP8 = Variable( "Simulation MG5_aMC + Pythia8", is_independent=False, is_binned=False)
    ysimP8.values = simP8["y"]
    ysimP8.add_qualifier("SQRT(S)","13","TeV")
    ysimP8.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ysimH7 = Variable( "Simulation MG5_aMC + Herwig7", is_independent=False, is_binned=False)
    ysimH7.values = simH7["y"]
    ysimH7.add_qualifier("SQRT(S)","13","TeV")
    ysimH7.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ysimHpp = Variable( "Simulation MG5_aMC + Herwig++", is_independent=False, is_binned=False)
    ysimHpp.values = simHpp["y"]
    ysimHpp.add_qualifier("SQRT(S)","13","TeV")
    ysimHpp.add_qualifier("LUMINOSITY","137","fb$^{-1}$")

    tab.add_variable(xbins)
    tab.add_variable(ydata)
    tab.add_variable(ysimP8)
    tab.add_variable(ysimH7)
    tab.add_variable(ysimHpp)

    return tab
Exemplo n.º 20
0
                      units="FB")
xsecs_meas.values = data_xsecs_meas[:, 0]

xsecs_meas_stat = Uncertainty("stat", is_symmetric=False)
xsecs_meas_stat.values = zip(data_xsecs_meas[:, 1], data_xsecs_meas[:, 2])
xsecs_meas.add_uncertainty(xsecs_meas_stat)

xsecs_meas_syst = Uncertainty("syst", is_symmetric=False)
xsecs_meas_syst.values = zip(data_xsecs_meas[:, 3], data_xsecs_meas[:, 4])
xsecs_meas.add_uncertainty(xsecs_meas_syst)

xsecs_meas_pdf = Uncertainty("PDF + scale")
xsecs_meas_pdf.values = [float(x) for x in data_xsecs_meas[:, 5]]
xsecs_meas.add_uncertainty(xsecs_meas_pdf)

xsecs_meas.add_qualifier("SQRT(S)", 13, "TeV")

xsecs_theo = Variable("SIG (theory)",
                      is_independent=False,
                      is_binned=False,
                      units="FB")
xsecs_theo.values = data_xsecs_theo[:, 0]

xsecs_theo_stat = Uncertainty("stat", is_symmetric=True)
xsecs_theo_stat.values = [float(x) for x in data_xsecs_theo[:, 1]]
xsecs_theo.add_uncertainty(xsecs_theo_stat)

xsecs_theo_pdf = Uncertainty("PDF + scale", is_symmetric=True)
xsecs_theo_pdf.values = [float(x) for x in data_xsecs_theo[:, 2]]
xsecs_theo.add_uncertainty(xsecs_theo_pdf)
Exemplo n.º 21
0
def convertEFTPtHistToYaml( rootfile, label, channel ):

    tab = Table(label)

    reader = RootFileReader(rootfile)

    data = reader.read_hist_1d("data")
    tot = reader.read_hist_1d("total")
    totbkg = reader.read_hist_1d("total_background")
    ttg = reader.read_hist_1d("signal")
    misID = reader.read_hist_1d("misID")
    had = reader.read_hist_1d("fakes")
    other = reader.read_hist_1d("other")
    wg = reader.read_hist_1d("WG")
    qcd = reader.read_hist_1d("QCD")
    zg = reader.read_hist_1d("ZG")

    eftbf = reader.read_hist_1d("bestFit")
    eftctZ045 = reader.read_hist_1d("ctZ0.45")
    eftctZI045 = reader.read_hist_1d("ctZI0.45")
    eftctZm045 = reader.read_hist_1d("ctZ-0.45")

    rootfile = ROOT.TFile(rootfile,"READ")
    totHist = rootfile.Get("total")
    datHist = rootfile.Get("data")

    unc = []
    statunc = []
    relunc = []
    for i, i_tot in enumerate(tot["y"]):
        u = totHist.GetBinError(i+1)
        ustat = datHist.GetBinError(i+1)
        unc.append(u)
        statunc.append(ustat)
        relunc.append(u*100./i_tot)


    xbins = Variable( "$p_{T}(\gamma)$", is_independent=True, is_binned=True, units="GeV")
    xbins.values = data["x_edges"]
    ydata = Variable( "Observed", is_independent=False, is_binned=False)
    ydata.values = data["y"]
    ydata.add_qualifier("CHANNEL",channel)
    ydata.add_qualifier("SQRT(S)","13","TeV")
    ydata.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ytot = Variable( "Total simulation", is_independent=False, is_binned=False)
    ytot.values = tot["y"]
    ytot.add_qualifier("CHANNEL",channel)
    ytot.add_qualifier("SQRT(S)","13","TeV")
    ytot.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ytotbkg = Variable( "Total background", is_independent=False, is_binned=False)
    ytotbkg.values = totbkg["y"]
    ytotbkg.add_qualifier("CHANNEL",channel)
    ytotbkg.add_qualifier("SQRT(S)","13","TeV")
    ytotbkg.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ywg = Variable( "$W\gamma$", is_independent=False, is_binned=False)
    ywg.values = wg["y"]
    ywg.add_qualifier("CHANNEL",channel)
    ywg.add_qualifier("SQRT(S)","13","TeV")
    ywg.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yzg = Variable( "$Z\gamma$", is_independent=False, is_binned=False)
    yzg.values = zg["y"]
    yzg.add_qualifier("CHANNEL",channel)
    yzg.add_qualifier("SQRT(S)","13","TeV")
    yzg.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    ymisID = Variable( "Misid. e", is_independent=False, is_binned=False)
    ymisID.values = misID["y"]
    ymisID.add_qualifier("CHANNEL",channel)
    ymisID.add_qualifier("SQRT(S)","13","TeV")
    ymisID.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yhad = Variable( "Hadronic $\gamma$", is_independent=False, is_binned=False)
    yhad.values = had["y"]
    yhad.add_qualifier("CHANNEL",channel)
    yhad.add_qualifier("SQRT(S)","13","TeV")
    yhad.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yqcd = Variable( "Multijet", is_independent=False, is_binned=False)
    yqcd.values = qcd["y"]
    yqcd.add_qualifier("CHANNEL",channel)
    yqcd.add_qualifier("SQRT(S)","13","TeV")
    yqcd.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yttg = Variable( "tt$\gamma$", is_independent=False, is_binned=False)
    yttg.values = ttg["y"]
    yttg.add_qualifier("CHANNEL",channel)
    yttg.add_qualifier("SQRT(S)","13","TeV")
    yttg.add_qualifier("LUMINOSITY","137","fb$^{-1}$")
    yother = Variable( "Other", is_independent=False, is_binned=False)
    yother.values = other["y"]
    yother.add_qualifier("CHANNEL",channel)
    yother.add_qualifier("SQRT(S)","13","TeV")
    yother.add_qualifier("LUMINOSITY","137","fb$^{-1}$")

    yeftbf = Variable( "SM-EFT best fit", is_independent=False, is_binned=False)
    yeftbf.values = eftbf["y"]
    yeftbf.add_qualifier("CHANNEL",channel)
    yeftbf.add_qualifier("SQRT(S)","13","TeV")
    yeftbf.add_qualifier("LUMINOSITY","137","fb$^{-1}$")

    yeftctZ045 = Variable( "$c_{tZ} = 0.45$", is_independent=False, is_binned=False,  units="($\Lambda$/TeV)$^2$")
    yeftctZ045.values = eftctZ045["y"]
    yeftctZ045.add_qualifier("CHANNEL",channel)
    yeftctZ045.add_qualifier("SQRT(S)","13","TeV")
    yeftctZ045.add_qualifier("LUMINOSITY","137","fb$^{-1}$")

    yeftctZI045 = Variable( "$c^I_{tZ} = 0.45$", is_independent=False, is_binned=False,  units="($\Lambda$/TeV)$^2$")
    yeftctZI045.values = eftctZI045["y"]
    yeftctZI045.add_qualifier("CHANNEL",channel)
    yeftctZI045.add_qualifier("SQRT(S)","13","TeV")
    yeftctZI045.add_qualifier("LUMINOSITY","137","fb$^{-1}$")

    yeftctZm045 = Variable( "$c_{tZ} = -0.45$", is_independent=False, is_binned=False,  units="($\Lambda$/TeV)$^2$")
    yeftctZm045.values = eftctZm045["y"]
    yeftctZm045.add_qualifier("CHANNEL",channel)
    yeftctZm045.add_qualifier("SQRT(S)","13","TeV")
    yeftctZm045.add_qualifier("LUMINOSITY","137","fb$^{-1}$")

    yunc = Uncertainty( "syst" )
    yunc.is_symmetric = True
    yunc.values = unc

    ystatunc = Uncertainty( "stat" )
    ystatunc.is_symmetric = True
    ystatunc.values = statunc

    ydata.uncertainties.append(ystatunc)
    ytot.uncertainties.append(yunc)

    tab.add_variable(xbins)
    tab.add_variable(ydata)
    tab.add_variable(ytot)
    tab.add_variable(yeftbf)
    tab.add_variable(yeftctZ045)
    tab.add_variable(yeftctZI045)
    tab.add_variable(yeftctZm045)
    tab.add_variable(ytotbkg)
    tab.add_variable(yttg)
    tab.add_variable(yhad)
    tab.add_variable(ymisID)
    tab.add_variable(yother)
    tab.add_variable(ywg)
    tab.add_variable(yqcd)
    tab.add_variable(yzg)

    return tab
Exemplo n.º 22
0
def make_table():
    params = [
        'r_ggH_0J_low', 'r_ggH_0J_high', 'r_ggH_1J_low', 'r_ggH_1J_med',
        'r_ggH_1J_high', 'r_ggH_2J_low', 'r_ggH_2J_med', 'r_ggH_2J_high',
        'r_ggH_BSM_low', 'r_ggH_BSM_med', 'r_ggH_BSM_high',
        'r_qqH_low_mjj_low_pthjj', 'r_qqH_low_mjj_high_pthjj',
        'r_qqH_high_mjj_low_pthjj', 'r_qqH_high_mjj_high_pthjj', 'r_qqH_VHhad',
        'r_qqH_BSM', 'r_WH_lep_low', 'r_WH_lep_med', 'r_WH_lep_high',
        'r_ZH_lep', 'r_ttH_low', 'r_ttH_medlow', 'r_ttH_medhigh', 'r_ttH_high',
        'r_ttH_veryhigh', 'r_tH'
    ]

    # Load results + xsbr data
    inputXSBRjson = "/afs/cern.ch/work/j/jlangfor/hgg/legacy/FinalFits/UL/Dec20/CMSSW_10_2_13/src/flashggFinalFit/Plots/jsons/xsbr_theory_stage1p2_extended_125p38.json"
    inputExpResultsJson = '/afs/cern.ch/work/j/jlangfor/hgg/legacy/FinalFits/UL/Dec20/CMSSW_10_2_13/src/flashggFinalFit/Plots/expected_UL_redo.json'
    inputObsResultsJson = '/afs/cern.ch/work/j/jlangfor/hgg/legacy/FinalFits/UL/Dec20/CMSSW_10_2_13/src/flashggFinalFit/Plots/observed_UL_redo.json'
    inputMode = "stage1p2_extended"

    translatePOIs = LoadTranslations("translate/pois_%s.json" % inputMode)
    with open(inputXSBRjson, "r") as jsonfile:
        xsbr_theory = json.load(jsonfile)
    observed = CopyDataFromJsonFile(inputObsResultsJson, inputMode, params)
    expected = CopyDataFromJsonFile(inputExpResultsJson, inputMode, params)
    mh = float(re.sub("p", ".",
                      inputXSBRjson.split("_")[-1].split(".json")[0]))

    # Make table of results
    table = Table("STXS stage 1.2 minimal merging scheme")
    table.description = "Results of the minimal merging scheme STXS fit. The best fit cross sections are shown together with the respective 68% C.L. intervals. The uncertainty is decomposed into the systematic and statistical components. The expected uncertainties on the fitted parameters are given in brackets. Also listed are the SM predictions for the cross sections and the theoretical uncertainty in those predictions."
    table.location = "Results from Figure 20 and Table 13"
    table.keywords["reactions"] = ["P P --> H ( --> GAMMA GAMMA ) X"]

    pois = Variable("STXS region", is_independent=True, is_binned=False)
    poiNames = []
    for poi in params:
        poiNames.append(str(Translate(poi, translatePOIs)))
    pois.values = poiNames

    # Dependent variables

    # SM predict
    xsbr_sm = Variable("SM predicted cross section times branching ratio",
                       is_independent=False,
                       is_binned=False,
                       units='fb')
    xsbr_sm.add_qualifier("SQRT(S)", 13, "TeV")
    xsbr_sm.add_qualifier("ABS(YRAP(HIGGS))", '<2.5')
    xsbr_sm.add_qualifier("MH", '125.38', "GeV")
    theory = Uncertainty("Theory", is_symmetric=False)
    xsbr_vals = []
    xsbr_hi_th, xsbr_lo_th = [], []
    for poi in params:
        xsbr_vals.append(xsbr_theory[poi]['nominal'])
        xsbr_hi_th.append(xsbr_theory[poi]['High01Sigma'])
        xsbr_lo_th.append(-1 * abs(xsbr_theory[poi]['Low01Sigma']))
    xsbr_sm.values = np.round(np.array(xsbr_vals), 3)
    theory.values = zip(np.round(np.array(xsbr_lo_th), 3),
                        np.round(np.array(xsbr_hi_th), 3))
    xsbr_sm.add_uncertainty(theory)

    # Observed cross section
    xsbr = Variable("Observed cross section times branching ratio",
                    is_independent=False,
                    is_binned=False,
                    units='fb')
    xsbr.add_qualifier("SQRT(S)", 13, "TeV")
    xsbr.add_qualifier("ABS(YRAP(HIGGS))", '<2.5')
    xsbr.add_qualifier("MH", '125.38', "GeV")
    # Add uncertainties
    tot = Uncertainty("Total", is_symmetric=False)
    stat = Uncertainty("Stat only", is_symmetric=False)
    syst = Uncertainty("Syst", is_symmetric=False)

    xsbr_vals = []
    xsbr_hi_tot, xsbr_lo_tot = [], []
    xsbr_hi_stat, xsbr_lo_stat = [], []
    xsbr_hi_syst, xsbr_lo_syst = [], []
    for poi in params:
        xsbr_vals.append(xsbr_theory[poi]['nominal'] * observed[poi]['Val'])
        xsbr_hi_tot.append(
            abs(xsbr_theory[poi]['nominal'] * observed[poi]['ErrorHi']))
        xsbr_lo_tot.append(
            -1 * abs(xsbr_theory[poi]['nominal'] * observed[poi]['ErrorLo']))
        xsbr_hi_stat.append(
            abs(xsbr_theory[poi]['nominal'] * observed[poi]['StatHi']))
        xsbr_lo_stat.append(
            -1 * abs(xsbr_theory[poi]['nominal'] * observed[poi]['StatLo']))
        xsbr_hi_syst.append(
            abs(xsbr_theory[poi]['nominal'] * observed[poi]['SystHi']))
        xsbr_lo_syst.append(
            -1 * abs(xsbr_theory[poi]['nominal'] * observed[poi]['SystLo']))

    tot.values = zip(np.round(np.array(xsbr_lo_tot), 3),
                     np.round(np.array(xsbr_hi_tot), 3))
    stat.values = zip(np.round(np.array(xsbr_lo_stat), 3),
                      np.round(np.array(xsbr_hi_stat), 3))
    syst.values = zip(np.round(np.array(xsbr_lo_syst), 3),
                      np.round(np.array(xsbr_hi_syst), 3))

    xsbr.values = np.round(np.array(xsbr_vals), 3)
    xsbr.add_uncertainty(tot)
    xsbr.add_uncertainty(stat)
    xsbr.add_uncertainty(syst)

    # Observed ratio to SM
    xsbrr = Variable("Observed ratio to SM",
                     is_independent=False,
                     is_binned=False,
                     units='')
    xsbrr.add_qualifier("SQRT(S)", 13, "TeV")
    xsbrr.add_qualifier("ABS(YRAP(HIGGS))", '<2.5')
    xsbrr.add_qualifier("MH", '125.38', "GeV")
    # Add uncertainties
    totr = Uncertainty("Total", is_symmetric=False)
    statr = Uncertainty("Stat only", is_symmetric=False)
    systr = Uncertainty("Syst", is_symmetric=False)

    xsbr_vals = []
    xsbr_hi_tot, xsbr_lo_tot = [], []
    xsbr_hi_stat, xsbr_lo_stat = [], []
    xsbr_hi_syst, xsbr_lo_syst = [], []
    for poi in params:
        xsbr_vals.append(observed[poi]['Val'])
        xsbr_hi_tot.append(abs(observed[poi]['ErrorHi']))
        xsbr_lo_tot.append(-1 * abs(observed[poi]['ErrorLo']))
        xsbr_hi_stat.append(abs(observed[poi]['StatHi']))
        xsbr_lo_stat.append(-1 * abs(observed[poi]['StatLo']))
        xsbr_hi_syst.append(abs(observed[poi]['SystHi']))
        xsbr_lo_syst.append(-1 * abs(observed[poi]['SystLo']))

    totr.values = zip(np.round(np.array(xsbr_lo_tot), 3),
                      np.round(np.array(xsbr_hi_tot), 3))
    statr.values = zip(np.round(np.array(xsbr_lo_stat), 3),
                       np.round(np.array(xsbr_hi_stat), 3))
    systr.values = zip(np.round(np.array(xsbr_lo_syst), 3),
                       np.round(np.array(xsbr_hi_syst), 3))

    xsbrr.values = np.round(np.array(xsbr_vals), 3)
    xsbrr.add_uncertainty(totr)
    xsbrr.add_uncertainty(statr)
    xsbrr.add_uncertainty(systr)

    # Expected cross section
    xsbr_exp = Variable("Expected cross section times branching ratio",
                        is_independent=False,
                        is_binned=False,
                        units='fb')
    xsbr_exp.add_qualifier("SQRT(S)", 13, "TeV")
    xsbr_exp.add_qualifier("ABS(YRAP(HIGGS))", '<2.5')
    xsbr_exp.add_qualifier("MH", '125.38', "GeV")
    # Add uncertainties
    tot_exp = Uncertainty("Total", is_symmetric=False)
    stat_exp = Uncertainty("Stat only", is_symmetric=False)
    syst_exp = Uncertainty("Syst", is_symmetric=False)

    xsbr_vals = []
    xsbr_hi_tot, xsbr_lo_tot = [], []
    xsbr_hi_stat, xsbr_lo_stat = [], []
    xsbr_hi_syst, xsbr_lo_syst = [], []
    for poi in params:
        xsbr_vals.append(xsbr_theory[poi]['nominal'])
        xsbr_hi_tot.append(
            abs(xsbr_theory[poi]['nominal'] * expected[poi]['ErrorHi']))
        xsbr_lo_tot.append(
            -1 * abs(xsbr_theory[poi]['nominal'] * expected[poi]['ErrorLo']))
        xsbr_hi_stat.append(
            abs(xsbr_theory[poi]['nominal'] * expected[poi]['StatHi']))
        xsbr_lo_stat.append(
            -1 * abs(xsbr_theory[poi]['nominal'] * expected[poi]['StatLo']))
        xsbr_hi_syst.append(
            abs(xsbr_theory[poi]['nominal'] * expected[poi]['SystHi']))
        xsbr_lo_syst.append(
            -1 * abs(xsbr_theory[poi]['nominal'] * expected[poi]['SystLo']))

    tot_exp.values = zip(np.round(np.array(xsbr_lo_tot), 3),
                         np.round(np.array(xsbr_hi_tot), 3))
    stat_exp.values = zip(np.round(np.array(xsbr_lo_stat), 3),
                          np.round(np.array(xsbr_hi_stat), 3))
    syst_exp.values = zip(np.round(np.array(xsbr_lo_syst), 3),
                          np.round(np.array(xsbr_hi_syst), 3))

    xsbr_exp.values = np.round(np.array(xsbr_vals), 3)
    xsbr_exp.add_uncertainty(tot_exp)
    xsbr_exp.add_uncertainty(stat_exp)
    xsbr_exp.add_uncertainty(syst_exp)

    # Expected ratio to SM
    xsbrr_exp = Variable("Expected ratio to SM",
                         is_independent=False,
                         is_binned=False,
                         units='')
    xsbrr_exp.add_qualifier("SQRT(S)", 13, "TeV")
    xsbrr_exp.add_qualifier("ABS(YRAP(HIGGS))", '<2.5')
    xsbrr_exp.add_qualifier("MH", '125.38', "GeV")
    # Add uncertainties
    totr_exp = Uncertainty("Total", is_symmetric=False)
    statr_exp = Uncertainty("Stat only", is_symmetric=False)
    systr_exp = Uncertainty("Syst", is_symmetric=False)

    xsbr_vals = []
    xsbr_hi_tot, xsbr_lo_tot = [], []
    xsbr_hi_stat, xsbr_lo_stat = [], []
    xsbr_hi_syst, xsbr_lo_syst = [], []
    for poi in params:
        xsbr_vals.append(1.00)
        xsbr_hi_tot.append(abs(expected[poi]['ErrorHi']))
        xsbr_lo_tot.append(-1 * abs(expected[poi]['ErrorLo']))
        xsbr_hi_stat.append(abs(expected[poi]['StatHi']))
        xsbr_lo_stat.append(-1 * abs(expected[poi]['StatLo']))
        xsbr_hi_syst.append(abs(expected[poi]['SystHi']))
        xsbr_lo_syst.append(-1 * abs(expected[poi]['SystLo']))

    totr_exp.values = zip(np.round(np.array(xsbr_lo_tot), 3),
                          np.round(np.array(xsbr_hi_tot), 3))
    statr_exp.values = zip(np.round(np.array(xsbr_lo_stat), 3),
                           np.round(np.array(xsbr_hi_stat), 3))
    systr_exp.values = zip(np.round(np.array(xsbr_lo_syst), 3),
                           np.round(np.array(xsbr_hi_syst), 3))

    xsbrr_exp.values = np.round(np.array(xsbr_vals), 3)
    xsbrr_exp.add_uncertainty(totr_exp)
    xsbrr_exp.add_uncertainty(statr_exp)
    xsbrr_exp.add_uncertainty(systr_exp)

    # Add variables to table
    table.add_variable(pois)
    table.add_variable(xsbr_sm)
    table.add_variable(xsbr)
    table.add_variable(xsbrr)
    table.add_variable(xsbr_exp)
    table.add_variable(xsbrr_exp)

    # Add figure
    table.add_image(
        "/afs/cern.ch/work/j/jlangfor/hgg/legacy/FinalFits/UL/Dec20/CMSSW_10_2_13/src/OtherScripts/HEPdata/hepdata_lib/hig-19-015/inputs/stxs_dist_stage1p2_minimal.pdf"
    )

    return table
Exemplo n.º 23
0
def add_limit_to_submission(c,submission):
    from hepdata_lib import Table
    from hepdata_lib.c_file_reader import CFileReader
    from hepdata_lib import Variable, Uncertainty
    
    table = Table(c.y_var)
    table.description = 'Exclusion limit for '+c.y_var

    reader = CFileReader(c.outputPath)
    graphs = reader.get_graphs()

    d = Variable(c.x_var, is_independent=True, is_binned=False, units=c.x_unit)
    d.values = graphs["Graph2"]['x']

    obs = Variable(c.y_var, is_independent=False, is_binned=False, units=c.y_unit)
    obs.values = graphs["Graph3"]['y']
    obs.add_qualifier("Limit", "Observed")

    exp = Variable(c.y_var, is_independent=False, is_binned=False, units=c.y_unit)
    exp.values = graphs["Graph2"]['y']
    exp.add_qualifier("Limit", "Expected")

    up2 = Variable(c.y_var, is_independent=False, is_binned=False, units=c.y_unit)
    up2.values = graphs["Graph0"]['y']
    up2.add_qualifier("Limit", "+2sigma")

    up1 = Variable(c.y_var, is_independent=False, is_binned=False, units=c.y_unit)
    up1.values = graphs["Graph1"]['y']
    up1.add_qualifier("Limit", "+1sigma")

    down1 = Variable(c.y_var, is_independent=False, is_binned=False, units=c.y_unit)
    down1.values = graphs["Graph4"]['y']
    down1.add_qualifier("Limit", "-1sigma")

    down2 = Variable(c.y_var, is_independent=False, is_binned=False, units=c.y_unit)
    down2.values = graphs["Graph5"]['y']
    down2.add_qualifier("Limit", "-2sigma")

    table.add_variable(d)
    table.add_variable(up2)
    table.add_variable(up1)
    table.add_variable(obs)
    table.add_variable(exp)
    table.add_variable(down1)
    table.add_variable(down2)
    submission.add_table(table)
def make_table():
    params = [
        'r_ggH_0J_low', 'r_ggH_0J_high', 'r_ggH_1J_low', 'r_ggH_1J_med',
        'r_ggH_1J_high', 'r_ggH_2J_low', 'r_ggH_2J_med', 'r_ggH_2J_high',
        'r_ggH_VBFlike', 'r_ggH_BSM', 'r_qqH_VBFlike', 'r_qqH_VHhad',
        'r_qqH_BSM', 'r_WH_lep', 'r_ZH_lep', 'r_ttH', 'r_tH'
    ]

    # Load results + xsbr data
    inputMode = "stage1p2_maximal"
    translatePOIs = LoadTranslations("translate/pois_%s.json" % inputMode)
    with open(
            "/afs/cern.ch/work/j/jlangfor/hgg/legacy/FinalFits/UL/Dec20/CMSSW_10_2_13/src/OtherScripts/HEPdata/hepdata_lib/hig-19-015/inputs/correlations_stage1p2_maximal.json",
            "r") as jf:
        correlations = json.load(jf)
    with open(
            "/afs/cern.ch/work/j/jlangfor/hgg/legacy/FinalFits/UL/Dec20/CMSSW_10_2_13/src/OtherScripts/HEPdata/hepdata_lib/hig-19-015/inputs/correlations_expected_stage1p2_maximal.json",
            "r") as jf:
        correlations_exp = json.load(jf)

    # Make table of results
    table = Table("Correlations: STXS stage 1.2 maximal merging scheme")
    table.description = "Observed and expected correlations between the parameters in the STXS stage 1.2 maximal merging fit."
    table.location = "Results from Figure 19"
    table.keywords["reactions"] = ["P P --> H ( --> GAMMA GAMMA ) X"]

    pois_x = Variable("STXS region (x)", is_independent=True, is_binned=False)
    pois_y = Variable("STXS region (y)", is_independent=True, is_binned=False)
    c = Variable("Observed correlation", is_independent=False, is_binned=False)
    c.add_qualifier("SQRT(S)", 13, "TeV")
    c.add_qualifier("ABS(YRAP(HIGGS))", '<2.5')
    c.add_qualifier("MH", '125.38', "GeV")

    c_exp = Variable("Expected correlation",
                     is_independent=False,
                     is_binned=False)
    c_exp.add_qualifier("SQRT(S)", 13, "TeV")
    c_exp.add_qualifier("ABS(YRAP(HIGGS))", '<2.5')
    c_exp.add_qualifier("MH", '125.38', "GeV")

    poiNames_x = []
    poiNames_y = []
    corr = []
    corr_exp = []
    for ipoi in params:
        for jpoi in params:
            poiNames_x.append(str(Translate(ipoi, translatePOIs)))
            poiNames_y.append(str(Translate(jpoi, translatePOIs)))
            # Extract correlation coefficient
            corr.append(correlations["%s__%s" % (ipoi, jpoi)])
            corr_exp.append(correlations_exp["%s__%s" % (ipoi, jpoi)])
    pois_x.values = poiNames_x
    pois_y.values = poiNames_y
    c.values = np.round(np.array(corr), 3)
    c_exp.values = np.round(np.array(corr_exp), 3)

    # Add variables to table
    table.add_variable(pois_x)
    table.add_variable(pois_y)
    table.add_variable(c)
    table.add_variable(c_exp)

    # Add figure
    table.add_image(
        "/afs/cern.ch/work/j/jlangfor/hgg/legacy/FinalFits/UL/Dec20/CMSSW_10_2_13/src/OtherScripts/HEPdata/hepdata_lib/hig-19-015/inputs/corrMatrix_stage1p2_maximal.pdf"
    )

    return table