Beispiel #1
0
    def test_create_files(self):
        """Test create_files() for Submission."""

        test_submission = Submission()

        try:
            test_submission.create_files("test_output")
        except TypeError:
            self.fail(
                "Submission.create_files raised an unexpected TypeError.")
    def test_create_files(self):
        """Test create_files() for Submission."""

        testdir = "test_output"
        test_submission = Submission()
        self.addCleanup(os.remove, "submission.tar.gz")
        self.addCleanup(shutil.rmtree, testdir)

        test_submission.create_files(testdir)

        self.doCleanups()
Beispiel #3
0
    def test_create_files_with_removal(self):
        """Test the removal of old files in create_files()"""
        testdir = tmp_directory_name()

        # Step 1: Create test directory containing random file
        os.makedirs(testdir)
        self.addCleanup(shutil.rmtree, testdir)
        testfile = os.path.join(testdir, "test.txt")
        with open(testfile, "w") as f:
            f.write("test")
        self.assertTrue(os.path.isfile(testfile))

        # Step 2: Create submission and write output to test directory
        # Without overwriting of files
        test_submission = Submission()
        tab = Table("test")
        test_submission.add_table(tab)
        test_submission.create_files(testdir, remove_old=False)

        # Test file should still exist
        self.assertTrue(os.path.isfile(testfile))

        # Step 3: Recreate submission files with removal
        test_submission.create_files(testdir, remove_old=True)

        # Test file should no longer exist
        self.assertFalse(os.path.isfile(testfile))
    def test_read_abstract(self):
        """Test read_abstract function."""
        some_string = string.ascii_lowercase

        testfile = "testfile.txt"
        self.addCleanup(os.remove, testfile)

        with open(testfile, "w") as f:
            f.write(some_string)

        test_submission = Submission()
        test_submission.read_abstract(testfile)

        self.assertEqual(test_submission.comment, some_string)

        self.doCleanups()
Beispiel #5
0
    def test_nested_files_to_copy(self):
        """Test that file copying works when tables have files."""
        # Create random test file
        testfile = "testfile.txt"
        with open(testfile, "w") as f:
            f.write("test")
        self.addCleanup(os.remove, testfile)

        # Output files
        testdirectory = "./testout"
        self.addCleanup(shutil.rmtree, testdirectory)
        self.addCleanup(os.remove, "submission.tar.gz")

        # Add resource to table, add table to Submission
        sub = Submission()
        tab = Table('test')
        tab.add_additional_resource("a_resource", testfile, True)
        sub.add_table(tab)

        # Write outputs
        sub.create_files(testdirectory)

        # Check that test file is actually in the tar ball
        with tarfile.open("submission.tar.gz", "r:gz") as tar:
            try:
                tar.getmember(testfile)
            except KeyError:
                self.fail(
                    "Submission.create_files failed to write all files to tar ball."
                )
Beispiel #6
0
    def test_create_files(self):
        """Test create_files() for Submission."""

        testdir = tmp_directory_name()
        test_submission = Submission()
        tab = Table("test")
        test_submission.add_table(tab)
        test_submission.create_files(testdir)

        self.doCleanups()
    def test_additional_resource_size(self):
        """Test the file checks in the add_additional_variable function."""

        testpath = "./testfile.dat"
        test_submission = Submission()
        self.addCleanup(os.remove, testpath)

        # Check with non-existant file
        with self.assertRaises(RuntimeError):
            test_submission.add_additional_resource("Some description",
                                                    testpath,
                                                    copy_file=True)

        # Check with file that is too big
        size = int(2e8)  # bytes in 200 MB
        with open(testpath, "wb") as testfile:
            testfile.write(bytes("\0" * size, "utf-8"))
        with self.assertRaises(RuntimeError):
            test_submission.add_additional_resource("Some description",
                                                    testpath,
                                                    copy_file=True)

        # Clean up
        os.remove(testpath)

        # Check with file that is not too big.
        size = int(5e7)  # bytes in 50 MB
        with open(testpath, "wb") as testfile:
            testfile.write(bytes("\0" * size, "utf-8"))
        try:
            test_submission.add_additional_resource("Some description",
                                                    testpath,
                                                    copy_file=True)
        except RuntimeError:
            self.fail(
                "Submission.add_additional_resource raised an unexpected RuntimeError."
            )

        # Clean up
        self.doCleanups()
Beispiel #8
0
    def test_yaml_output(self):
        """Test yaml dump"""
        tmp_dir = tmp_directory_name()

        # Create test dictionary
        testlist = [("x", 1.2), ("x", 2.2), ("y", 0.12), ("y", 0.22)]
        testdict = defaultdict(list)
        for key, value in testlist:
            testdict[key].append(value)

        # Create test submission
        test_submission = Submission()
        test_table = Table("TestTable")
        x_variable = Variable("X", is_independent=True, is_binned=False)
        x_variable.values = testdict['x']
        y_variable = Variable("Y", is_independent=False, is_binned=False)
        y_variable.values = testdict['y']
        test_table.add_variable(x_variable)
        test_table.add_variable(y_variable)
        test_submission.add_table(test_table)
        test_submission.create_files(tmp_dir)

        # Test read yaml file
        table_file = os.path.join(tmp_dir, "testtable.yaml")
        try:
            with open(table_file, 'r') as testfile:
                testyaml = yaml.safe_load(testfile)
        except yaml.YAMLError as exc:
            print(exc)

        # Test compare yaml file to string
        testtxt = (
            "dependent_variables:\n- header:\n    name: Y\n  values:\n" +
            "  - value: 0.12\n  - value: 0.22\nindependent_variables:\n" +
            "- header:\n    name: X\n  values:\n  - value: 1.2\n  - value: 2.2\n"
        )
        with open(table_file, 'r') as testfile:
            testyaml = testfile.read()

        self.assertEqual(str(testyaml), testtxt)
        self.addCleanup(os.remove, "submission.tar.gz")
        self.addCleanup(shutil.rmtree, tmp_dir)
        self.doCleanups()
Beispiel #9
0
    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)

if __name__ == "__main__":
    submission = Submission()
    
    for c in config:
        outdict = read_limit_from_pickle(c.picklePath)
        draw_limit_with_dict(c,outdict)
        add_limit_to_submission(c,submission)
    
    submission.create_files(out_name)
Beispiel #10
0
    def test_add_table_typechecks(self):
        """Test the type checks in the add_table function."""

        # Verify that the type check works
        test_submission = Submission()
        test_table = Table("Some Table")
        test_variable = Variable("Some Variable")
        test_uncertainty = Uncertainty("Some Uncertainty")
        try:
            test_submission.add_table(test_table)
        except TypeError:
            self.fail("Submission.add_table raised an unexpected TypeError.")

        with self.assertRaises(TypeError):
            test_submission.add_table(5)
        with self.assertRaises(TypeError):
            test_submission.add_table([1, 3, 5])
        with self.assertRaises(TypeError):
            test_submission.add_table("a string")
        with self.assertRaises(TypeError):
            test_submission.add_table(test_variable)
        with self.assertRaises(TypeError):
            test_submission.add_table(test_uncertainty)
import numpy as np
import math
import ROOT
import scipy.stats
from hepdata_lib import Submission
submission = Submission()
#####CASE SWITCHING#####

#Shower = "NN"
Shower = "LO"
Use_Weights = True  #BKR pT Weight
Use_P_Weights = True
CorrectedP = True  # FALSE FOR HARDPROBES
Use_MC = True
pT_Rebin = False
N_dPhi_Bins = 8
Ped_Sub_First = False  #Important after weight implementation
Average_UE = False
Show_Fits = True
Uncorr_Estimate = "ZYAM"

#rad_start = 1.6
#Phi_String = "\pi/2"

#rad_start = 1.9
#Phi_String = "5\pi/8"

#rad_start = 2.3
#Phi_String = "3\pi/4"

#rad_start = 2.15
Beispiel #12
0
#!/usr/bin/python

from __future__ import print_function
from hepdata_lib import Variable, Uncertainty
from hepdata_lib import Uncertainty

import hepdata_lib
from hepdata_lib import Submission

import numpy as np
submission = Submission()

lumi_sf = 1.0 / 35800.0

submission.read_abstract("hepdata_lib/examples/example_inputs/abstract.txt")
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"
Beispiel #13
0
from __future__ import print_function
import os
import numpy as np
from hepdata_lib import Submission, Table, Variable, Uncertainty

#INITIALIZE
submission = Submission()

#ABSTRACT
submission.read_abstract("input/abstract.txt")
submission.add_link(
    "Webpage with all figures and tables",
    "https://cms-results.web.cern.ch/cms-results/public-results/publications/SMP-19-013/"
)
submission.add_link("arXiv", "http://arxiv.org/abs/arXiv:2105.12780")
submission.add_record_id(1865855, "inspire")

#FIGURE 2 UPPER LEFT
fig2_ul = Table("Figure 2 (upper left)")
fig2_ul.description = "Distribution of the transverse momentum of the diphoton system for the $\mathrm{W}\gamma\gamma$ electron channel. The predicted yields are shown with their pre-fit normalisations. The observed data, the expected signal contribution and the background estimates are presented with error bars showing the corresponding statistical uncertainties."
fig2_ul.location = "Data from Figure 2 on Page 6 of the preprint"
fig2_ul.keywords["observables"] = ["Diphoton pT"]
fig2_ul.keywords["reactions"] = [
    "P P --> W GAMMA GAMMA --> ELECTRON NU GAMMA GAMMA"
]

fig2_ul_in = np.loadtxt("input/fig2_ul.txt", skiprows=1)

#diphoton pT
fig2_ul_pt = Variable("$p_T^{\gamma\gamma}$",
                      is_independent=True,
Beispiel #14
0
import pandas as pd

from hepdata_lib import Submission
from hepdata_lib import Table
from hepdata_lib import RootFileReader
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"]:
Beispiel #15
0
import numpy as np
from hepdata_lib import Submission, Table, Variable, RootFileReader, Uncertainty
from helpers import *

submission = Submission()

###
### Fig 2a
###

tableF2a = convertSRHistToYaml("../systPlots/SR3p_PhotonGood0_pt_all.root",
                               "Figure 2a", "$p_{T}(\gamma)$", "GeV")
tableF2a.description = "Distribution of $p_{T}(\gamma)$ in the $N_{jet}\geq 3$ signal region."
tableF2a.location = "Data from Figure 2 (top left) "
tableF2a.add_image("../figures/PhotonGood0_pt.png")
tableF2a.keywords["reactions"] = [
    "P P --> TOP TOPBAR X", "P P --> TOP TOPBAR GAMMA"
]
tableF2a.keywords["cmenergies"] = [13000.0]
tableF2a.keywords["observables"] = ["N"]
tableF2a.keywords["phrases"] = [
    "Top", "Quark", "Photon", "lepton+jets", "semileptonic", "Cross Section",
    "Proton-Proton Scattering", "Inclusive", "Differential"
]
submission.add_table(tableF2a)

###
### Fig 2b
###

tableF2b = convertSRHistToYaml("../systPlots/SR3p_mT_all.root", "Figure 2b",
Beispiel #16
0
#!/usr/bin/python

from __future__ import print_function
from hepdata_lib import Variable, Uncertainty
from hepdata_lib import Uncertainty
from hepdata_lib import RootFileReader

import hepdata_lib
from hepdata_lib import Submission

from hepdata_lib import Table
from hepdata_lib import Variable

import numpy as np

submission = Submission()

sig_digits = 3

submission.read_abstract("HEPData/inputs/hig20017/abstract.txt")
submission.add_link(
    "Webpage with all figures and tables",
    "http://cms-results.web.cern.ch/cms-results/public-results/publications/HIG-20-017/index.html"
)
#submission.add_link("arXiv", "http://arxiv.org/abs/arXiv:xxxx.xxxxx")
#submission.add_record_id(1818160, "inspire")

### Begin Table 2
table2 = Table("Table 2")
table2.description = "Summary of the impact of the systematic uncertainties on the extracted signal strength; for the case of a background-only simulated data set, i.e., assuming no contributions from the $\mathrm{H}^{\pm}$ and $\mathrm{H}^{\pm\pm}$ processes, and including a charged Higgs boson signal for values of $s_{\mathrm{H}}=1.0$ and $m_{\mathrm{H}_{5}}=500$ GeV in the GM model."
table2.location = "Data from Table 2"
#!/usr/bin/python

from __future__ import print_function
from hepdata_lib import Variable, Uncertainty
from hepdata_lib import Uncertainty
from hepdata_lib import RootFileReader

import hepdata_lib
from hepdata_lib import Submission

from hepdata_lib import Table
from hepdata_lib import Variable

import numpy as np
submission = Submission()


submission.read_abstract("HEPData/inputs/smp20006/abstract.txt")
submission.add_link("Webpage with all figures and tables", "http://cms-results.web.cern.ch/cms-results/public-results/publications/SMP-20-006/index.html")
submission.add_link("arXiv", "http://arxiv.org/abs/arXiv:2009.09429")
submission.add_record_id(1818160, "inspire")


### Begin Table 4
table4 = Table("Table 4")
table4.description = "Systematic uncertainties of the $\mathrm{W}^\pm_{\mathrm{L}}\mathrm{W}^\pm_{\mathrm{L}}$ and $\mathrm{W}^\pm_{\mathrm{X}}\mathrm{W}^\pm_{\mathrm{T}}$, and $\mathrm{W}^\pm_{\mathrm{L}}\mathrm{W}^\pm_{\mathrm{X}}$ and $\mathrm{W}^\pm_{\mathrm{T}}\mathrm{W}^\pm_{\mathrm{T}}$ cross section measurements in units of percent."
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"]
Beispiel #18
0
#!/usr/bin/python

from __future__ import print_function
from hepdata_lib import Variable, Uncertainty
from hepdata_lib import Uncertainty
from hepdata_lib import RootFileReader

import hepdata_lib
from hepdata_lib import Submission

from hepdata_lib import Table
from hepdata_lib import Variable

import numpy as np
submission = Submission()

sig_digits = 3
sig_digits2 = 2

submission.read_abstract("HEPData/inputs/smp18006/abstract.txt")
submission.add_link(
    "Webpage with all figures and tables",
    "http://cms-results.web.cern.ch/cms-results/public-results/publications/SMP-18-006/index.html"
)
submission.add_link("arXiv", "http://arxiv.org/abs/arXiv:1905.07445")
submission.add_record_id(1735737, "inspire")

### Begin Table 2
table2 = Table("Table 2")
table2.description = "Expected yields from various background processes in $\mathrm{WV}$ and $\mathrm{ZV}$ final states. The combination of the statistical and systematic uncertainties are shown. The predicted yields are shown with their best-fit normalizations from the background-only fit. The aQGC signal yields are shown for two aQGC scenarios with $f_{T2}/ \Lambda^{4} = -0.5$ TeV$^{-4}$ and $f_{T2}/ \Lambda^{4} = -2.5$ TeV$^{-4}$ for the  $\mathrm{WV}$ and $\mathrm{ZV}$ channels, respectively. The charged Higgs boson signal yields are also shown for values of $s_{\mathrm{H}}=0.5$ and $m_{\mathrm{H}_{5}}=500$ GeV in the GM model. The statistical uncertainties are shown for the expected signal yields."
table2.location = "Data from Table 2"
Beispiel #19
0
import hepdata_lib
import json
from collections import OrderedDict as od
import re
import sys

from hepdata_lib import Submission
submission = Submission()

# Make table of results
from data.results_mu import *
table_mu = make_table()
from data.correlations_mu import *
table_correlations_mu = make_table()

from data.results_stage1p2_maximal import *
table_maximal = make_table()
from data.correlations_stage1p2_maximal import *
table_correlations_stage1p2_maximal = make_table()

from data.results_stage1p2_minimal import *
table_minimal = make_table()
from data.correlations_stage1p2_minimal import *
table_correlations_stage1p2_minimal = make_table()

from data.results_kappas import *
table_kappas = make_table()
from data.results_kappas_expected import *
table_kappas_expected = make_table()
from data.results_kVkF import *
table_kVkF = make_table()
Beispiel #20
0
                    h = files[year].read_hist_1d(
                        "%s_%s_%s" % (proc, year.replace("A", "pre").replace(
                            "B", "post"), nnBin))

                varArr += h["y"]

                # For the fit and data graphs, there is an associated uncertainty
                # So add that uncertainty to the Fit and Nobs variables
                if proc == "Fit" or proc == "Nobs":
                    uncArr += h["dy"]

            v.values = varArr

            if proc == "Fit" or proc == "Nobs":
                uncVals, isSymm = makeUncArray(uncArr)
                unc = U("unc.", is_symmetric=isSymm)
                unc.values = uncVals
                v.add_uncertainty(unc)

            # Add each sig1, sig2, fit, data variable to the corresponding table
            tmap[year].add_variable(v)

    for year, t in sorted(tmap.items()):
        sub.add_table(t)


if __name__ == "__main__":
    sub = Submission()
    makeFitPlotHEPData(sub)
    sub.create_files("output")
#!/usr/bin/python

from __future__ import print_function
from hepdata_lib import Variable, Uncertainty
from hepdata_lib import Uncertainty
from hepdata_lib import RootFileReader

import hepdata_lib
from hepdata_lib import Submission

from hepdata_lib import Table
from hepdata_lib import Variable

import numpy as np
submission = Submission()

submission.read_abstract("HEPData/inputs/smp18003/abstract.txt")
submission.add_link(
    "Webpage with all figures and tables",
    "https://cms-results.web.cern.ch/cms-results/public-results/publications/SMP-18-003/"
)
submission.add_link("arXiv", "https://arxiv.org/abs/2012.09254")
submission.add_record_id(999999999, "inspire")

### Begin Figure 2
figure2 = Table("Figure 2")
figure2.description = "The measured and predicted inclusive fiducial cross sections in fb. The experimental measurement includes both statistical and systematics uncertainties. The theoretical prediction includes both the QCD scale and PDF uncertainties."
figure2.location = "Data from Figure 2"

figure2.keywords["observables"] = ["SIG"]
figure2.keywords["phrases"] = [