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_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." )
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_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()
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)
# 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") table_covariance_XSRatio_mm_Pt.description = "Covariance matrix for normalized cross sections using dressed level leptons for all bins used in bins of Z pt in the dimuon final state." table_covariance_XSRatio_mm_Pt.location = "Supplementary material" for var in [x_covariance_mm_Pt, y_covariance_mm_Pt, z_covariance_mm_Pt]: table_covariance_XSRatio_mm_Pt.add_variable(var) submission.add_table(table_covariance_XSRatio_mm_Pt) # Create a reader for the input file reader_covariance_mm_Rap = RootFileReader( "HEPData/inputs/smp17010/folders_dressedleptons/output_root/matrix03__XSRatioSystRap.root" ) # Read the histogram data_covariance_mm_Rap = reader_covariance_mm_Rap.read_hist_2d( "covariance_totsum_0") # Create variable objects x_covariance_mm_Rap = Variable("Bin X", is_independent=True, is_binned=True) x_covariance_mm_Rap.values = data_covariance_mm_Rap["x_edges"] y_covariance_mm_Rap = Variable("Bin Y", is_independent=True, is_binned=False) y_covariance_mm_Rap.values = data_covariance_mm_Rap["y"] z_covariance_mm_Rap = Variable("covariance Matrix", is_independent=False,
is_binned=False, units="Events per bin") fig2_ul_Mjets.values = fig2_ul_in[:, 9] fig2_ul_Mjets_stat = Uncertainty("stat", is_symmetric=True) fig2_ul_Mjets_stat.values = fig2_ul_in[:, 10] fig2_ul_Mjets.add_uncertainty(fig2_ul_Mjets_stat) fig2_ul.add_variable(fig2_ul_pt) fig2_ul.add_variable(fig2_ul_Data) fig2_ul.add_variable(fig2_ul_Wgg) fig2_ul.add_variable(fig2_ul_Mele) fig2_ul.add_variable(fig2_ul_Others) fig2_ul.add_variable(fig2_ul_Mjets) fig2_ul.add_image("input/Figure_002-a.pdf") submission.add_table(fig2_ul) #FIGURE 2 UPPER RIGHT fig2_ur = Table("Figure 2 (upper right)") fig2_ur.description = "Distribution of the transverse momentum of the diphoton system for the $\mathrm{W}\gamma\gamma$ muon 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_ur.location = "Data from Figure 2 on Page 6 of the preprint" fig2_ur.keywords["observables"] = ["Diphoton pT"] fig2_ur.keywords["reactions"] = [ "P P --> W GAMMA GAMMA --> MUON NU GAMMA GAMMA" ] fig2_ur_in = np.loadtxt("input/fig2_ur.txt", skiprows=1) #diphoton pT fig2_ur_pt = Variable("$p_T^{\gamma\gamma}$", is_independent=True,
if fig["type_stat"].lower() == "tgraphasymmerrors": y_stat = Uncertainty("stat. uncertainty", is_symmetric=False) y_stat.values = stat["dy"] y.add_uncertainty(y_stat) elif fig["type_stat"].lower() in ["tgrapherrors", "th1"]: y_stat = Uncertainty("stat. uncertainty", is_symmetric=True) y_stat.values = stat["dy"] y.add_uncertainty(y_stat) if fig["type_syst"].lower() == "tgraphasymmerrors": y_syst = Uncertainty("syst. uncertainty", is_symmetric=False) y_syst.values = syst["dy"] y.add_uncertainty(y_syst) elif fig["type_syst"].lower() in ["tgrapherrors", "th1"]: y_syst = Uncertainty("syst. uncertainty", is_symmetric=True) y_syst.values = syst["dy"] y.add_uncertainty(y_syst) # write table if fig["type_stat"].lower() == "th2": table.add_variable(x1) table.add_variable(x2) table.add_variable(y) else: table.add_variable(x1) table.add_variable(y) submission.add_table(table) submission.create_files("output")
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", "$m_{T}(W)$", "GeV") tableF2b.description = "Distribution of $m_{T}(W)$ in the $N_{jet}\geq 3$ signal region." tableF2b.location = "Data from Figure 2 (top center)" tableF2b.add_image("../figures/mT.png") tableF2b.keywords["reactions"] = [ "P P --> TOP TOPBAR X", "P P --> TOP TOPBAR GAMMA" ] tableF2b.keywords["cmenergies"] = [13000.0] tableF2b.keywords["observables"] = ["N"]
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}$") table2.add_variable(table2_data) table2.add_variable(table2_yields0) table2.add_variable(table2_yields1) submission.add_table(table2) for table2 in submission.tables: table2.keywords["cmenergies"] = [13000] ### End Table 2 ### Begin Table 3 table3 = Table("Table 3") table3.description = "Expected signal and background yields from various SM processes and observed data events in all regions used in the analysis. The expected background yields are shown with their 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. The expected signal yields are shown for $s_{\mathrm{H}}=1.0$ in the GM model. The combination of the statistical and systematic uncertainties is shown." table3.location = "Data from Table 3" table3.keywords["observables"] = ["Events"] table3.keywords["reactions"] = ["P P --> W W j j", "P P --> W Z j j"] table3.keywords["phrases"] = [ "Same-sign WW", "WZ", "Georgi-Machacek", "Charged Higgs", "VBF"
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]] figure2_yields3.add_qualifier("", "Cross Section (fb)") figure2.add_variable(figure2_data) figure2.add_variable(figure2_yields1) figure2.add_variable(figure2_yields2) figure2.add_variable(figure2_yields3) submission.add_table(figure2) for figure2 in submission.tables: figure2.keywords["cmenergies"] = [13000] ### End Figure 2 ### Begin Table 2 table2 = Table("Table 2") table2.description = "Experimental uncertainties affecting transfer factors in the analysis that is used to estimate the W background in the signal region (SR). The number of W boson events are denoted as $W_{SR}$ for the SR and in analogy as $W_{\mu\\nu}$ ($W_{e\\nu}$) for the single-muon (single-electron) control region (CR)." table2.location = "Data from Table 2" table2.keywords["observables"] = ["Uncertainty"] table2.keywords["phrases"] = [ "Electroweak", "Cross Section", "Proton-Proton", "Z boson production" ]
from data.results_stage0 import * table_stage0 = make_table() from data.correlations_stage0 import * table_correlations_stage0 = make_table() from data.results_stage1p2_maximal_2d_vbflike import * table_stage1p2_maximal_2d_vbflike = make_table() from data.results_stage1p2_maximal_2d_vbflike_exp import * table_stage1p2_maximal_2d_vbflike_expected = make_table() from data.results_stage1p2_maximal_2d_top import * table_stage1p2_maximal_2d_top = make_table() from data.results_stage1p2_maximal_2d_top_exp import * table_stage1p2_maximal_2d_top_expected = make_table() # Add table to submission submission.add_table(table_mu) submission.add_table(table_correlations_mu) submission.add_table(table_maximal) submission.add_table(table_correlations_stage1p2_maximal) submission.add_table(table_minimal) submission.add_table(table_correlations_stage1p2_minimal) submission.add_table(table_kappas) submission.add_table(table_kappas_expected) submission.add_table(table_kVkF) submission.add_table(table_kVkF_expected) submission.add_table(table_stage0) submission.add_table(table_correlations_stage0)
table4_yields2.add_qualifier("SQRT(S)", 13, "TeV") table4_yields2.add_qualifier("L$_{\mathrm{int}}$", 137, "fb$^{-1}$") table4_yields3 = Variable("Uncertainty", is_independent=False, is_binned=False, units="") table4_yields3.values = [float(x) for x in data4[:,4]] table4_yields3.add_qualifier("Source of uncertainty", "$\mathrm{W}^\pm_{\mathrm{T}}\mathrm{W}^\pm_{\mathrm{T}}$") table4_yields3.add_qualifier("SQRT(S)", 13, "TeV") table4_yields3.add_qualifier("L$_{\mathrm{int}}$", 137, "fb$^{-1}$") table4.add_variable(table4_data) table4.add_variable(table4_yields0) table4.add_variable(table4_yields1) table4.add_variable(table4_yields2) table4.add_variable(table4_yields3) submission.add_table(table4) for table4 in submission.tables: table4.keywords["cmenergies"] = [13000] ### End Table 4 ### Begin Table 5 table5 = Table("Table 5") table5.description = "Expected yields from various SM processes and observed data events in WW SR. The combination of the statistical and systematic uncertainties is shown. The expected yields are shown with their best fit normalizations from the simultaneous fit for the $\mathrm{W}^\pm_{\mathrm{L}}\mathrm{W}^\pm_{\mathrm{L}}$ and $\mathrm{W}^\pm_{\mathrm{X}}\mathrm{W}^\pm_{\mathrm{T}}$ cross sections. The $\mathrm{W}^\pm_{\mathrm{L}}\mathrm{W}^\pm_{\mathrm{T}}$ and $\mathrm{W}^\pm_{\mathrm{T}}\mathrm{W}^\pm_{\mathrm{T}}$ yields are obtained from the $\mathrm{W}^\pm_{\mathrm{X}}\mathrm{W}^\pm_{\mathrm{T}}$ yield assuming the SM prediction for the ratio of the yields. The tVx background yield includes the contributions from tt$\mathrm{V}$ and tZq processes." table5.location = "Data from Table 5" table5.keywords["observables"] = ["Events"] table5.keywords["reactions"] = ["P P --> W W j j"] table5.keywords["phrases"] = ["VBS", "Polarized", "Same-sign WW"]
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) table2_unc2.values = [float(x) for x in data2[:, 4]] table2_yields1.add_uncertainty(table2_unc1) table2_yields2.add_uncertainty(table2_unc2) table2.add_variable(table2_data) table2.add_variable(table2_yields1) table2.add_variable(table2_yields2) submission.add_table(table2) for table2 in submission.tables: table2.keywords["cmenergies"] = [13000] ### End Table 2 ### Begin Table 3 table3 = Table("Table 3") table3.description = "Observed and expected lower and upper 95\% CL limits on the parameters of the quartic operators S0, S1, M0, M1, M6, M7, T0, T1, and T2 in $\mathrm{WV}$ and $\mathrm{ZV}$ channels. The last two columns show the observed and expected limits for the combination of the $\mathrm{WV}$ and $\mathrm{ZV}$ channels." table3.location = "Data from Table 3" table3.keywords["observables"] = ["Limits"] data3 = np.loadtxt("HEPData/inputs/smp18006/limits.txt", dtype='string',