Beispiel #1
0
    def test_read_graph_tgraph(self):
        """
        Test the behavior of the read_graph function
        when reading a TGraph from file.
        """
        N = 20
        filepath = "testfile.root"
        name = "testgraph"

        x = np.random.uniform(-1e3, 1e3, N)
        y = np.random.uniform(-1e3, 1e3, N)

        # Create a graph and write to file
        g = ROOT.TGraph()
        for i, (ix, iy) in enumerate(zip(x, y)):
            g.SetPoint(i, ix, iy)

        f = ROOT.TFile(filepath, "RECREATE")
        f.cd()
        g.Write(name)
        f.Close()

        # Read graph back from file
        reader = RootFileReader(filepath)
        data = reader.read_graph(name)

        self.assertTrue(set(data.keys()) == set(["x", "y"]))
        self.assertTrue(all(data["x"] == x))
        self.assertTrue(all(data["y"] == y))

        # Clean up
        os.remove(filepath)
Beispiel #2
0
    def test_read_hist_1d_symmetric_errors(self):
        """Test the read_hist_1d function for a histogram with symmetric errors."""
        fpath = "testfile.root"

        # Create test histogram
        N = 100
        x_values = [0.5 + x for x in range(N)]
        y_values = list(np.random.uniform(-1e3, 1e3, N))
        dy_values = list(np.random.uniform(0, 1e3, N))

        hist = ROOT.TH1D("test1d_symm", "test1d_symm", N, 0, N)
        for i in range(1, hist.GetNbinsX() + 1):
            hist.SetBinContent(i, y_values[i - 1])
            hist.SetBinError(i, dy_values[i - 1])

        f = ROOT.TFile(fpath, "RECREATE")
        hist.SetDirectory(f)
        hist.Write("test")
        f.Close()

        reader = RootFileReader(fpath)
        points = reader.read_hist_1d("test")

        self.assertTrue(set(["x", "y", "x_edges", "dy"]) == set(points.keys()))

        self.assertTrue(
            all(float_compare(*tup) for tup in zip(points["x"], x_values)))
        self.assertTrue(
            all(float_compare(*tup) for tup in zip(points["y"], y_values)))
        self.assertTrue(
            all(float_compare(*tup) for tup in zip(points["dy"], dy_values)))

        # Clean up
        os.remove(fpath)
Beispiel #3
0
    def test_read_hist_2d_symmetric_errors(self):
        """Test the read_hist_2d function with symmetric errors."""
        fpath = "testfile.root"

        # Create test histogram
        NX = 100
        NY = 100
        x_values = [0.5 + x for x in range(NX)]
        y_values = [0.5 + x for x in range(NY)]
        z_values = np.random.uniform(-1e3, 1e3, (NX, NY))
        dz_values = np.random.uniform(0, 1e3, (NX, NY))

        hist = ROOT.TH2D("test2d_sym", "test2d_sym", NX, 0, NX, NY, 0, NY)

        for ix in range(1, hist.GetNbinsX() + 1):
            for iy in range(1, hist.GetNbinsY() + 1):
                ibin = hist.GetBin(ix, iy)
                hist.SetBinContent(ibin, z_values[ix - 1][iy - 1])
                hist.SetBinError(ibin, dz_values[ix - 1][iy - 1])

        backup_hist = hist.Clone("backup")
        rfile = ROOT.TFile(fpath, "RECREATE")
        hist.SetDirectory(rfile)
        hist.Write("test2d_sym")
        rfile.Close()

        reader = RootFileReader(fpath)
        points = reader.read_hist_2d("test2d_sym")

        # Check keys
        self.assertTrue(
            set(["x", "y", "z", "x_edges", "y_edges", "dz"]) == set(
                points.keys()))

        # Check length
        for v in points.values():
            self.assertTrue(len(v) == NX * NY)

        # Check unordered contents
        self.assertTrue(set(points["x"]) == set(x_values))
        self.assertTrue(set(points["y"]) == set(y_values))

        # Look up original bins and compare
        for x, y, z, dz in zip(points["x"], points["y"], points["z"],
                               points["dz"]):
            ibin = backup_hist.Fill(x, y, 0)
            ibinx = ctypes.c_int()
            ibiny = ctypes.c_int()
            ibinz = ctypes.c_int()
            backup_hist.GetBinXYZ(ibin, ibinx, ibiny, ibinz)
            self.assertTrue(
                float_compare(backup_hist.GetXaxis().GetBinCenter(ibinx.value),
                              x))
            self.assertTrue(
                float_compare(backup_hist.GetYaxis().GetBinCenter(ibiny.value),
                              y))
            self.assertTrue(float_compare(backup_hist.GetBinContent(ibin), z))
            self.assertTrue(float_compare(backup_hist.GetBinError(ibin), dz))
        # Clean up
        os.remove(fpath)
Beispiel #4
0
    def test_read_hist_2d_asymmetric_errors(self):
        """Test the read_hist_2d function with asymmetric errors."""
        fpath = "testfile.root"

        # Create test histogram
        NX = 17
        NY = 17
        Nfill = 1000

        hist = ROOT.TH2D("test2d_asym", "test2d_asym", NX, 0, 1, NY, 0, 1)
        hist.SetBinErrorOption(ROOT.TH1.kPoisson)
        for val in np.random.normal(loc=0.5, scale=0.15, size=(Nfill, 2)):
            hist.Fill(*val)

        backup_hist = hist.Clone("backup")

        # Write to file
        rfile = ROOT.TFile(fpath, "RECREATE")
        hist.SetDirectory(rfile)
        hist.Write("test2d_asym")
        rfile.Close()

        # Read back
        reader = RootFileReader(fpath)
        points = reader.read_hist_2d("test2d_asym")

        # Check keys
        self.assertTrue(
            set(["x", "y", "z", "x_edges", "y_edges", "dz"]) == set(
                points.keys()))

        # Check length
        for v in points.values():
            self.assertTrue(len(v) == NX * NY)

        # Look up original bins and compare
        for x, y, z, dz in zip(points["x"], points["y"], points["z"],
                               points["dz"]):
            ibin = backup_hist.Fill(x, y, 0)
            ibinx = ctypes.c_int()
            ibiny = ctypes.c_int()
            ibinz = ctypes.c_int()
            backup_hist.GetBinXYZ(ibin, ibinx, ibiny, ibinz)
            self.assertTrue(
                float_compare(backup_hist.GetXaxis().GetBinCenter(ibinx.value),
                              x))
            self.assertTrue(
                float_compare(backup_hist.GetYaxis().GetBinCenter(ibiny.value),
                              y))
            self.assertTrue(float_compare(backup_hist.GetBinContent(ibin), z))
            self.assertTrue(
                tuple_compare(
                    (-backup_hist.GetBinErrorLow(ibinx.value, ibiny.value),
                     backup_hist.GetBinErrorUp(ibinx.value, ibiny.value)), dz))
        # Clean up
        os.remove(fpath)
Beispiel #5
0
    def test_read_hist_1d_asymmetric_errors(self):
        """Test the read_hist_1d function for a histogram with asymmetric errors."""
        fpath = "testfile.root"

        # Create test histogram
        Nbin = 17
        Nfill = 1000
        hist = ROOT.TH1D("test1d_asymm", "test1d_asymm", Nbin, 0, 1)
        hist.SetBinErrorOption(ROOT.TH1.kPoisson)

        for val in np.random.normal(loc=0.5, scale=0.15, size=Nfill):
            hist.Fill(val)

        # Extract values
        x_values = []
        y_values = []
        dy_values = []
        for i in range(1, hist.GetNbinsX()):
            x_values.append(hist.GetBinCenter(i))
            y_values.append(hist.GetBinContent(i))
            dy_values.append((-hist.GetBinErrorLow(i), hist.GetBinErrorUp(i)))

        # Write to file
        f = ROOT.TFile(fpath, "RECREATE")
        hist.SetDirectory(f)
        hist.Write("test")
        f.Close()

        # Read back
        reader = RootFileReader(fpath)
        points = reader.read_hist_1d("test")

        # Check consistency
        self.assertTrue(set(["x", "y", "x_edges", "dy"]) == set(points.keys()))

        self.assertTrue(
            all(float_compare(*tup) for tup in zip(points["x"], x_values)))
        self.assertTrue(
            all(float_compare(*tup) for tup in zip(points["y"], y_values)))
        self.assertTrue(
            all(tuple_compare(*tup) for tup in zip(points["dy"], dy_values)))

        # Clean up
        os.remove(fpath)
Beispiel #6
0
    def test_read_graph_tgrapherrors2(self):
        """
        Test the behavior of the read_graph function
        when reading a TGraphAsymmErrors from file.
        """
        N = 20
        filepath = "testfile.root"
        name = "testgraph"

        x = np.random.uniform(-1e3, 1e3, N)
        dx1 = np.random.uniform(0, 1e3, N)
        dx2 = np.random.uniform(0, 1e3, N)
        y = np.random.uniform(-1e3, 1e3, N)
        dy1 = np.random.uniform(0, 1e3, N)
        dy2 = np.random.uniform(0, 1e3, N)

        # Create a graph and write to file
        g = ROOT.TGraphAsymmErrors()
        for i, (ix, iy, idx1, idx2, idy1,
                idy2) in enumerate(zip(x, y, dx1, dx2, dy1, dy2)):
            g.SetPoint(i, ix, iy)
            g.SetPointError(i, idx1, idx2, idy1, idy2)
        f = ROOT.TFile(filepath, "RECREATE")
        f.cd()
        g.Write(name)
        f.Close()

        # Read graph back from file
        reader = RootFileReader(filepath)
        data = reader.read_graph(name)

        self.assertTrue(set(data.keys()) == set(["x", "y", "dx", "dy"]))
        self.assertTrue(all(data["x"] == x))
        self.assertTrue(all(data["y"] == y))

        # Downward error has a minus sign -> flip
        self.assertTrue(data["dx"] == list(zip([-tmp for tmp in dx1], dx2)))
        self.assertTrue(data["dy"] == list(zip([-tmp for tmp in dy1], dy2)))

        # Clean up
        os.remove(filepath)
Beispiel #7
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
Beispiel #8
0
    def test_read_tree(self):
        """Test the read_tree function."""

        Nfill = 1000
        fpath = "testfile.root"
        branchname = "testbranch"
        path_to_tree = "testpath"
        # Set up some test data, put into TTree and write to file
        data = np.random.normal(loc=0.5, scale=0.15, size=Nfill)

        number = array("f", [0])
        tree = ROOT.TTree()
        tree.Branch(branchname, number, "test/F")
        for inumber in data:
            number[0] = inumber
            tree.Fill()

        rootfile = ROOT.TFile(fpath, "RECREATE")
        tree.Write(path_to_tree)
        if (rootfile): rootfile.Close()

        # Read data back and check consistency
        reader = RootFileReader(fpath)
        try:
            data_readback = reader.read_tree(path_to_tree, branchname)
        except RuntimeError:
            self.fail(
                "RootFileReader.read_tree raised an unexpected RuntimeError!")
        self.assertIsInstance(data_readback, list)
        self.assertTrue(
            all([
                float_compare(values[0], values[1])
                for values in zip(data, data_readback)
            ]))

        # Try reading a nonexistant branch from an existing tree
        with self.assertRaises(RuntimeError):
            reader.read_tree(path_to_tree, "some_random_name")

        # Try reading a nonexistant tree
        with self.assertRaises(RuntimeError):
            reader.read_tree("some/random/path", "some_random_name")
Beispiel #9
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
Beispiel #10
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
Beispiel #11
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
table5_yields2.values = [str(x) for x in data5[:, 3]]
table5_yields2.add_qualifier("Z $p_{T}$ (GeV)", "Z -> ll+$\\nu\\nu$")

table5.add_variable(table5_data)
table5.add_variable(table5_yields0)
table5.add_variable(table5_yields1)
table5.add_variable(table5_yields2)

submission.add_table(table5)

for table5 in submission.tables:
    table5.keywords["cmenergies"] = [13000]
### End Table 5

### Begin FigAux1a
reader_FigAux1a = RootFileReader("HEPData/inputs/smp18003/ZnnSystHist.root")

tableFigAux1a = Table("Figure Aux1a")
tableFigAux1a.description = "The relative statistical and systematic uncertainties from various sources for the absolute cross section measurements in bins of Z $p_{T}$ on charged leptons."
tableFigAux1a.location = "Data from Figure Aux1a"
tableFigAux1a.keywords["observables"] = ["uncertainties"]
tableFigAux1a.keywords["phrases"] = [
    "Electroweak", "Cross Section", "Proton-Proton", "Z boson production"
]
tableFigAux1a.keywords["reactions"] = ["PP -> Z"]
tableFigAux1a.keywords["cmenergies"] = [13000]

histoSystPlot_0 = reader_FigAux1a.read_hist_1d("histoResult_0_4")
histoSystPlot_1 = reader_FigAux1a.read_hist_1d("histoResult_1_4")
histoSystPlot_2 = reader_FigAux1a.read_hist_1d("histoResult_2_4")
histoSystPlot_3 = reader_FigAux1a.read_hist_1d("histoResult_3_4")
Beispiel #13
0
from hepdata_lib import Variable
from hepdata_lib import Uncertainty

submission = Submission()

df = pd.read_csv("input.csv")
df = df.fillna("")
for index, fig in df.iterrows():
	print(fig["figure_name"])
	# create a table
	table = Table(fig["figure_name"])
	table.description = fig["description"]
	table.location = fig["paper_location"]

	# read figures
	reader = RootFileReader(fig["file_location"])
	if fig["type_stat"].lower() in ["tgraph", "tgrapherrors", "tgraphasymmerrors"]:
		stat = reader.read_graph(fig["name_stat"])
	elif fig["type_stat"].lower() == "th1":
		stat = reader.read_hist_1d(fig["name_stat"])
	elif fig["type_stat"].lower() == "th2":
		stat = reader.read_hist_2d(fig["name_stat"])
	else:
		print("ERROR: {}, type not recognized!".format(fig["figure_name"]))
	
	if fig["type_syst"].lower() in ["tgraph", "tgrapherrors", "tgraphasymmerrors"]:
		syst = reader.read_graph(fig["name_syst"])
	elif fig["type_syst"].lower() == "th1":
		syst = reader.read_hist_1d(fig["name_syst"])
	elif fig["type_syst"].lower() == "th2":
		syst = reader.read_hist_2d(fig["name_syst"])
Beispiel #14
0
table_limits4.add_variable(mass_limits4)
table_limits4.add_variable(obs_limits4)
table_limits4.add_variable(exp_limits4)
table_limits4.add_variable(minus2sigma_limits4)
table_limits4.add_variable(minus1sigma_limits4)
table_limits4.add_variable(plus1sigma_limits4)
table_limits4.add_variable(plus2sigma_limits4)

submission.add_table(table_limits4)

for table_limits4 in submission.tables:
    table_limits4.keywords["cmenergies"] = [13000]

### Begin WV histograms
reader_wv = RootFileReader("HEPData/inputs/smp18006/wv_hist.root")

tableWV = Table("Figure 4-a")
tableWV.description = "$\mathrm{m_{\mathrm{WV}}}$ distribution in the $\mathrm{WV}$ channel. The predicted yields are shown with their best-fit normalizations from the background-only fit."
tableWV.location = "Data from Figure 4-a"
tableWV.keywords["observables"] = ["Events"]
tableWV.keywords["reactions"] = ["P P --> W V j j"]
tableWV.keywords["phrases"] = ["Yields"]

histo_data_wv = reader_wv.read_hist_1d("hdata")
histo_vvjjqcd_wv = reader_wv.read_hist_1d("hVVjjQCD")
histo_vjet_wv = reader_wv.read_hist_1d("hwjet")
histo_vvjj_wv = reader_wv.read_hist_1d("hdiboson")
histo_top_wv = reader_wv.read_hist_1d("htop")
histo_bkg_wv = reader_wv.read_hist_1d("hbkg")
Beispiel #15
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
Beispiel #16
0
    def test_read_hist_1d_range(self):
        """Test the read_hist_1d function for a histogram with symmetric errors."""
        fpath = "testfile.root"

        # Create test histogram
        N = 100
        xmin = 20
        xmax = 80
        x_values = [0.5 + x for x in range(xmin, xmax)]
        y_values = list(np.random.uniform(-1e3, 1e3, xmax - xmin))
        dy_values = list(np.random.uniform(0, 1e3, xmax - xmin))

        hist = ROOT.TH1D("test1d_symm", "test1d_symm", N, 0, N)
        for i in range(xmin, xmax):
            hist.SetBinContent(i + 1, y_values[i - xmin])
            hist.SetBinError(i + 1, dy_values[i - xmin])

        f = ROOT.TFile(fpath, "RECREATE")
        hist.SetDirectory(f)
        hist.Write("test")
        f.Close()

        reader = RootFileReader(fpath)

        # pass too many axis limits
        with self.assertRaises(TypeError):
            reader.read_hist_1d("test", xlim=(xmin, xmax), ylim=(xmin, xmax))
        # pass wrong axis limits or parameter
        with self.assertRaises(TypeError):
            reader.read_hist_1d("test", ylim=(xmin, xmax))
        # pass xmax < xmin (wrong ordering)
        with self.assertRaises(AssertionError):
            reader.read_hist_1d("test", xlim=(xmax, xmin))
        # pass too many parameters as single axis limit
        with self.assertRaises(AssertionError):
            reader.read_hist_1d("test", xlim=(xmin, xmax, 5))
        # pass non-float/-int as first item
        with self.assertRaises(AssertionError):
            reader.read_hist_1d("test", xlim=("5", xmax))
        # pass non-float/-int as second item
        with self.assertRaises(AssertionError):
            reader.read_hist_1d("test", xlim=(xmin, "12"))
        # pass set instance (needs to be ordered tuple or list)
        with self.assertRaises(AssertionError):
            reader.read_hist_1d("test", xlim={xmin, xmax})
        # pass wrong instance
        with self.assertRaises(AssertionError):
            reader.read_hist_1d("test", xlim="some string")

        points = reader.read_hist_1d("test", xlim=(xmin, xmax))

        self.assertTrue(set(["x", "y", "x_edges", "dy"]) == set(points.keys()))

        self.assertTrue(
            all(float_compare(*tup) for tup in zip(points["x"], x_values)))
        self.assertTrue(
            all(float_compare(*tup) for tup in zip(points["y"], y_values)))
        self.assertTrue(
            all(float_compare(*tup) for tup in zip(points["dy"], dy_values)))

        # Clean up
        os.remove(fpath)
from hepdata_lib import Submission
submission = Submission()

from hepdata_lib import Table
table = Table("pa all")
table.description = "description."
table.location = "upper left."
table.keywords["observables"] = ["pa"]

from hepdata_lib import RootFileReader
reader = RootFileReader("root://eosuser.cern.ch//eos/user/v/vveckaln/analysis_MC13TeV_TTJets/plots/plotter.root")
Data = reader.read_hist_1d("L_pull_angle_allconst_reco_leading_jet_scnd_leading_jet_DeltaRgt1p0/L_pull_angle_allconst_reco_leading_jet_scnd_leading_jet_DeltaRgt1p0")
Unc = reader.read_hist_1d("L_pull_angle_allconst_reco_leading_jet_scnd_leading_jet_DeltaRgt1p0/L_pull_angle_allconst_reco_leading_jet_scnd_leading_jet_DeltaRgt1p0_totalMCUncShape")

from hepdata_lib import Variable, Uncertainty

mmed = Variable("pa", is_independent=True, is_binned=False, units="rad")
mmed.values = signal["x"]

data = Variable("N", is_independent=False, is_binned=False, units="")
data.values = Data["y"]

unc = Uncertainty("Total", is_symmetric=True)
unc.values = Unc["dy"]
data.add_uncertainty(unc)

table.add_variable(mmed)
table.add_variable(data)

submission.add_table(table)
for table in submission.tables:
    table.keywords["cmenergies"] = [13000]

### Histogram
from hepdata_lib import Table
table2 = Table("Figure 4a")
table2.description = "Distribution in the reconstructed B quark mass, after applying all selections to events with no forward jet, compared to the background distributions estimated before fitting. The plot refers to the low-mass mB analysis. The expectations for signal MC events are given by the blue histogram lines. Different contributions to background are indicated by the colour-filled histograms. The grey-hatched error band shows total uncertainties in the background expectation. The ratio of observations to background expectations is given in the lower panel, together with the total uncertainties prior to fitting, indicated by the grey-hatched band."
table2.location = "Data from Figure 4 (upper left), located on page 12."
table2.keywords["observables"] = ["N"]
table2.add_image(
    "hepdata_lib/examples/example_inputs/CMS-B2G-17-009_Figure_004-a.pdf")

from hepdata_lib import RootFileReader

reader = RootFileReader(
    "hepdata_lib/examples/example_inputs/mlfit_lm_1000.root")
reader_data = RootFileReader(
    "hepdata_lib/examples/example_inputs/Data_cat0_singleH.root")
reader_signal = RootFileReader(
    "hepdata_lib/examples/example_inputs/BprimeBToHB1000_cat0_singleH.root")

TotalBackground = reader.read_hist_1d(
    "shapes_prefit/cat0_singleH/total_background")
TT = reader.read_hist_1d("shapes_prefit/cat0_singleH/TT")
QCD = reader.read_hist_1d("shapes_prefit/cat0_singleH/QCDTT")
WJets = reader.read_hist_1d("shapes_prefit/cat0_singleH/WJets")
ZJets = reader.read_hist_1d("shapes_prefit/cat0_singleH/ZJets")

Data = reader_data.read_hist_1d("h_bprimemass_SRlm")

signal = reader_signal.read_hist_1d("h_bprimemass_SRlm")
Beispiel #19
0
submission.add_link(
    "Webpage with all figures and tables",
    "https://cms-results.web.cern.ch/cms-results/public-results/publications/B2G-16-029/"
)
submission.add_link("arXiv", "http://arxiv.org/abs/arXiv:1802.09407")
submission.add_record_id(1657397, "inspire")

### Table
from hepdata_lib import Table
from hepdata_lib import Variable
from hepdata_lib import RootFileReader

### Begin covariance mumu dressed
# Create a reader for the input file
reader_covariance_mm_Pt = RootFileReader(
    "HEPData/inputs/smp17010/folders_dressedleptons/output_root/matrix03__XSRatioSystPt.root"
)
# Read the histogram
data_covariance_mm_Pt = reader_covariance_mm_Pt.read_hist_2d(
    "covariance_totsum_0")
# Create variable objects
x_covariance_mm_Pt = Variable("Bin X", is_independent=True, is_binned=True)
x_covariance_mm_Pt.values = data_covariance_mm_Pt["x_edges"]
y_covariance_mm_Pt = Variable("Bin Y", is_independent=True, is_binned=False)
y_covariance_mm_Pt.values = data_covariance_mm_Pt["y"]
z_covariance_mm_Pt = Variable("covariance Matrix",
                              is_independent=False,
                              is_binned=False)
z_covariance_mm_Pt.values = data_covariance_mm_Pt["z"]

table_covariance_XSRatio_mm_Pt = Table("cov matr norm xs aux 1a")
Beispiel #20
0
    def test_read_hist_2d_range(self):
        """Test the read_hist_2d function with symmetric errors."""
        fpath = "testfile.root"

        # Create test histogram
        NX = 100
        NY = 100
        xmin = 20
        xmax = 80
        ymin = 30
        ymax = 90
        x_values = [0.5 + x for x in range(xmin, xmax)]
        y_values = [0.5 + x for x in range(ymin, ymax)]
        z_values = np.random.uniform(-1e3, 1e3, (xmax - xmin, ymax - ymin))
        dz_values = np.random.uniform(0, 1e3, (xmax - xmin, ymax - ymin))

        hist = ROOT.TH2D("test2d_sym", "test2d_sym", NX, 0, NX, NY, 0, NY)

        for ix in range(xmin, xmax):
            for iy in range(ymin, ymax):
                ibin = hist.GetBin(ix + 1, iy + 1)
                hist.SetBinContent(ibin, z_values[ix - xmin][iy - ymin])
                hist.SetBinError(ibin, dz_values[ix - xmin][iy - ymin])

        backup_hist = hist.Clone("backup")
        rfile = ROOT.TFile(fpath, "RECREATE")
        hist.SetDirectory(rfile)
        hist.Write("test2d_sym")
        rfile.Close()

        reader = RootFileReader(fpath)

        # pass too many axis limits
        with self.assertRaises(TypeError):
            reader.read_hist_2d("test",
                                xlim=(xmin, xmax),
                                ylim=(ymin, ymax),
                                zlim=(ymin, ymax))
        # pass non-existing axis limit/parameter
        with self.assertRaises(TypeError):
            reader.read_hist_2d("test", zlim=(xmin, xmax))
        # pass wrong order (xmax < xmin)
        with self.assertRaises(AssertionError):
            reader.read_hist_2d("test", ylim=(xmax, xmin))
        # pass too many parameters as single axis limit
        with self.assertRaises(AssertionError):
            reader.read_hist_2d("test", ylim=(xmin, xmax, 5))
        # pass wrong type as first item
        with self.assertRaises(AssertionError):
            reader.read_hist_2d("test", ylim=("5", xmax))
        # pass wrong type as second item
        with self.assertRaises(AssertionError):
            reader.read_hist_2d("test", ylim=(xmin, "12"))
        # pass set instance (needs ordered datatype: tuple or list)
        with self.assertRaises(AssertionError):
            reader.read_hist_2d("test", xlim={xmin, xmax})
        # pass wrong instance
        with self.assertRaises(AssertionError):
            reader.read_hist_2d("test", xlim="some string")

        points = reader.read_hist_2d("test2d_sym",
                                     xlim=(xmin, xmax),
                                     ylim=(ymin, ymax))

        # Check keys
        self.assertTrue(
            set(["x", "y", "z", "x_edges", "y_edges", "dz"]) == set(
                points.keys()))

        # Check length
        for v in points.values():
            self.assertTrue(len(v) == (xmax - xmin) * (ymax - ymin))

        # Check unordered contents
        self.assertTrue(set(points["x"]) == set(x_values))
        self.assertTrue(set(points["y"]) == set(y_values))

        # Look up original bins and compare
        for x, y, z, dz in zip(points["x"], points["y"], points["z"],
                               points["dz"]):
            ibin = backup_hist.Fill(x, y, 0)
            ibinx = ctypes.c_int()
            ibiny = ctypes.c_int()
            ibinz = ctypes.c_int()
            backup_hist.GetBinXYZ(ibin, ibinx, ibiny, ibinz)
            self.assertTrue(
                float_compare(backup_hist.GetXaxis().GetBinCenter(ibinx.value),
                              x))
            self.assertTrue(
                float_compare(backup_hist.GetYaxis().GetBinCenter(ibiny.value),
                              y))
            self.assertTrue(float_compare(backup_hist.GetBinContent(ibin), z))
            self.assertTrue(float_compare(backup_hist.GetBinError(ibin), dz))
        # Clean up
        os.remove(fpath)
Beispiel #21
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
Beispiel #22
0
table3.add_variable(table3_data)
table3.add_variable(table3_yields0)
table3.add_variable(table3_yields1)
table3.add_variable(table3_yields2)
table3.add_variable(table3_yields3)
table3.add_variable(table3_yields4)

submission.add_table(table3)

for table3 in submission.tables:
    table3.keywords["cmenergies"] = [13000]

### End Table 2

### Begin Fig4
reader_Fig4 = RootFileReader(
    "HEPData/inputs/hig20017/histoDatacard_hpp_hp_fiducial6_mH500_2019.root")
reader_fit = RootFileReader(
    "HEPData/inputs/hig20017/fitDiagnosticsssww_2019_fiducial6_mH500_obs.root")

tableFig4 = Table("Figure 4")
tableFig4.description = "Distributions for signal, backgrounds, and data for the bins used in the simultaneous fit. The bins 1--32 (4$\\times$8) show the events in the WW SR ($m_{\mathrm{jj}} \\times m_{\mathrm{T}}$), the bins 33--46 (2$\\times$7) show the events in the WZ SR ($m_{\mathrm{jj}} \\times m_{\mathrm{T}}$), the 4 bins 47--50 show the events in the nonprompt lepton CR ($m_{\mathrm{jj}}$), the 4 bins 51--54 show the events in the tZq CR ($m_{\mathrm{jj}}$), and the 4 bins 55--58 show the events in the ZZ CR ($m_{\mathrm{jj}}$). The predicted yields are shown with their best fit normalizations from the simultaneous fit  for the background-only hypothesis, i.e., assuming no contributions from the  $\mathrm{H}^{\pm}$ and $\mathrm{H}^{\pm\pm}$ processes. Vertical bars on data points represent the statistical uncertainty in the data. The histograms for tVx backgrounds include the contributions from ttV and tZq processes. The histograms for other backgrounds  include the contributions from double parton scattering, VVV, and from oppositely charged dilepton final states from tt, tW, $\mathrm{W}^{+}\mathrm{W}^{-}$, and Drell--Yan processes. The overflow is included in the last bin in each corresponding region. The lower panels show the ratio of the number of events observed in data to that of the total SM prediction. The hatched gray bands represent the uncertainties in the predicted yields. The solid lines show the signal predictions for values of $s_{\mathrm{H}}=1.0$ and $m_{\mathrm{H}_{5}}=500$ GeV in the GM model."
tableFig4.location = "Data from Figure 4"
tableFig4.keywords["observables"] = ["Events"]
tableFig4.keywords["reactions"] = ["P P --> W W j j", "P P --> W Z j j"]
tableFig4.keywords["phrases"] = [
    "Same-sign WW", "WZ", "Georgi-Machacek", "Charged Higgs", "VBF"
]

histo0_Fig4 = reader_Fig4.read_hist_1d("histo0")  # data
histo5_Fig4 = reader_Fig4.read_hist_1d("histo5")  # WpWp
histo8_Fig4 = reader_Fig4.read_hist_1d("histo8")  # WZ
Beispiel #23
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
Beispiel #24
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)