Example #1
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."
                )
Example #2
0
def makeCutFlow(submission, config):
    table = Table(config["name"])
    table.description = config["description"]
    table.location = config["location"]
    #table.keywords["observables"] = ["SIG"]
    #table.keywords["reactions"] = ["P P --> TOP --> tt + 6j"]

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

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

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

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

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

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

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

    table.add_variable(d)
    table.add_variable(cuts)
    table.add_variable(obs1)
    table.add_variable(obs2)
    submission.add_table(table)
Example #3
0
def make_table():

    xparam = 'kappa_V'
    yparam = 'kappa_F'

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

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

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

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

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

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

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

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

    return table
Example #4
0
    def test_add_image(self):
        """Get test PDF"""
        # Get test PDF
        some_pdf = "%s/minimal.pdf" % os.path.dirname(__file__)

        test_table = Table("Some Table")

        # This should work fine
        try:
            try:
                test_table.add_image(some_pdf)
            except RuntimeError:
                self.fail("Table.add_image raised an unexpected RuntimeError.")
        except TypeError:
            self.fail("Table.add_image raised an unexpected TypeError.")

        # Try wrong argument types
        wrong_type = [None, 5, {}, []]
        for argument in wrong_type:
            with self.assertRaises(TypeError):
                test_table.add_image(argument)

        # Try non-existing paths:
        nonexisting = ["/a/b/c/d/e", "./daskjl/aksj/asdasd.pdf"]
        for argument in nonexisting:
            with self.assertRaises(RuntimeError):
                test_table.add_image(argument)
Example #5
0
    def test_write_images(self):
        """Test the write_images function."""

        test_table = Table("Some Table")

        # Get test PDF
        some_pdf = "%s/minimal.pdf" % os.path.dirname(__file__)

        # This should work fine
        test_table.add_image(some_pdf)
        testdir = tmp_directory_name()
        self.addCleanup(shutil.rmtree, testdir)
        try:
            test_table.write_images(testdir)
        except TypeError:
            self.fail("Table.write_images raised an unexpected TypeError.")

        # Check that output file exists
        expected_file = os.path.join(testdir, "minimal.png")
        self.assertTrue(os.path.exists(expected_file))

        # Try wrong type of input argument
        bad_arguments = [None, 5, {}, []]
        for argument in bad_arguments:
            with self.assertRaises(TypeError):
                test_table.write_images(argument)
        self.doCleanups()
Example #6
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))
Example #7
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()
Example #8
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()
Example #9
0
    def test_write_yaml(self):
        """Test write_yaml() for Table."""

        test_table = Table("Some Table")
        test_variable = Variable("Some Variable")
        test_table.add_variable(test_variable)
        try:
            test_table.write_yaml("test_output")
        except TypeError:
            self.fail("Table.write_yaml raised an unexpected TypeError.")
        with self.assertRaises(TypeError):
            test_table.write_yaml(None)
Example #10
0
    def test_write_images_multiple_executions(self):
        """
        write_images is supposed to only recreate output PNG
        files if the output file does not yet exist or is outdated
        relative to the input file.
        """

        test_table = Table("Some Table")
        some_pdf = "%s/minimal.pdf" % os.path.dirname(__file__)
        test_table.add_image(some_pdf)
        testdir = "test_output"
        self.addCleanup(shutil.rmtree, testdir)

        expected_main_file = os.path.join(testdir, "minimal.png")
        expected_thumbnail_file = os.path.join(testdir, "thumb_minimal.png")

        # Output files should not yet exist
        self.assertTrue(not os.path.exists(expected_main_file))
        self.assertTrue(not os.path.exists(expected_thumbnail_file))

        # Run the function
        test_table.write_images(testdir)

        # Output files now exist
        self.assertTrue(os.path.exists(expected_main_file))
        self.assertTrue(os.path.exists(expected_thumbnail_file))

        # Make sure that output is not recreated if input file is unchanged
        modified_time_main = os.path.getmtime(expected_main_file)
        modified_time_thumbnail = os.path.getmtime(expected_thumbnail_file)
        test_table.write_images(testdir)
        self.assertEqual(modified_time_main, os.path.getmtime(expected_main_file))
        self.assertEqual(modified_time_thumbnail, os.path.getmtime(expected_thumbnail_file))


        # Make sure that a change in input file triggers recreation
        os.utime(some_pdf, None)
        test_table.write_images(testdir)
        self.assertTrue(modified_time_main < os.path.getmtime(expected_main_file))
        self.assertTrue(modified_time_thumbnail < os.path.getmtime(expected_thumbnail_file))
Example #11
0
    def test_name_checks(self):
        """Test the table name checks."""

        # This should work fine
        good_name = "64 characters or fewer"
        try:
            good_table = Table(good_name)
        except ValueError:
            self.fail("Table initializer raised unexpected ValueError.")

        self.assertEqual(good_name, good_table.name)

        # Check name that is too long
        too_long_name = "x"*100

        # In the initializer
        with self.assertRaises(ValueError):
            _bad_table = Table(too_long_name)

        # Using the setter
        with self.assertRaises(ValueError):
            good_table.name = too_long_name
Example #12
0
    def test_write_yaml(self):
        """Test write_yaml() for Table."""

        test_table = Table("Some Table")
        test_variable = Variable("Some Variable")
        test_table.add_variable(test_variable)
        testdir = tmp_directory_name()
        self.addCleanup(shutil.rmtree, testdir)
        try:
            test_table.write_yaml(testdir)
        except TypeError:
            self.fail("Table.write_yaml raised an unexpected TypeError.")
        with self.assertRaises(TypeError):
            test_table.write_yaml(None)
        self.doCleanups()
Example #13
0
    def test_copy_files(self):
        """Test the copy_files function."""
        test_table = Table("Some Table")
        some_pdf = "%s/minimal.pdf" % os.path.dirname(__file__)
        testdir = tmp_directory_name()
        self.addCleanup(shutil.rmtree, testdir)
        os.makedirs(testdir)

        test_table.add_additional_resource("a plot",some_pdf, copy_file=True)
        test_table.copy_files(testdir)
Example #14
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)
Example #15
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
Example #16
0
tableF4b.keywords["reactions"] = [
    "P P --> TOP TOPBAR X", "P P --> TOP TOPBAR GAMMA"
]
tableF4b.keywords["cmenergies"] = [13000.0]
tableF4b.keywords["observables"] = ["N"]
tableF4b.keywords["phrases"] = [
    "Top", "Quark", "Photon", "lepton+jets", "semileptonic", "Cross Section",
    "Proton-Proton Scattering", "Inclusive", "Differential"
]
#tableF4b.keywords()
submission.add_table(tableF4b)

###
### SF table
###
tabSF = Table("Table 4")

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

sfType = Variable("Scale factor",
                  is_independent=True,
                  is_binned=False,
                  units="")
sfType.values = [
    "Misidentified electrons (2016)", "Misidentified electrons (2017)",
    "Misidentified electrons (2018)", "Z$\gamma$ normalization",
    "W$\gamma$ normalization"
]
value = Variable("Value", is_independent=False, is_binned=False, units="")
value.values = [2.25, 2.00, 1.52, 1.01, 1.13]
def Plot_pp_pPb_Avg_FF_and_Ratio(Comb_Dict):
    
    label_size=22
    axis_size=34
    plot_power = False
    Colors = ["red","blue"]
    Markers = ["s","o"]
    fig = plt.figure(figsize=(8,8))
    pp_sys_Error = 0
    p_Pb_sys_Error = 0
    fig.add_axes((0.1,0.3,0.88,0.6))
    for SYS,sys_col,marker in zip(reversed(Systems),reversed(Colors),reversed(Markers)):

        #Systematics
        Efficiency_Uncertainty = 0.056*Comb_Dict["%s_Combined_FF"%(SYS)]
        
        Eta_Cor = Eta_Correction #see default_value.py for value
        Eta_Cor_Uncertainty = Eta_Correction_Uncertainty*Comb_Dict["%s_Combined_FF"%(SYS)]
        if not(Apply_Eta_Correction and SYS=="p-Pb"):
            Eta_Cor_Uncertainty = 0  #2% otherwise
        
        FF_Central = Comb_Dict["%s_Combined_FF"%(SYS)] #Eta Correction is applied when creating Dictionary!
        Sys_Uncertainty = np.sqrt(Efficiency_Uncertainty**2 + Comb_Dict["%s_purity_Uncertainty"%(SYS)]**2 + Eta_Cor_Uncertainty**2)
        
        if (SYS=="pp"):
            pp_sys_Error = Sys_Uncertainty
        elif (SYS=="p-Pb"):
            p_Pb_sys_Error=Sys_Uncertainty
        #Plots
        if (SYS=="pp"):
            leg_string = SYS
        if (SYS=="p-Pb"):
            leg_string = "p$-$Pb"
        plt.errorbar(zT_centers[:NzT-ZT_OFF_PLOT], Comb_Dict["%s_Combined_FF"%(SYS)][:NzT-ZT_OFF_PLOT],xerr=zT_widths[:NzT-ZT_OFF_PLOT]*0,
        yerr=Comb_Dict["%s_Combined_FF_Errors"%(SYS)][:NzT-ZT_OFF_PLOT],linewidth=1, fmt=marker,color=sys_col,capsize=0)#for lines

        plt.plot(zT_centers[:NzT-ZT_OFF_PLOT], Comb_Dict["%s_Combined_FF"%(SYS)][:NzT-ZT_OFF_PLOT],marker,linewidth=0,color=sys_col,
        label=leg_string)#for legend without lines
        
        if (SYS == "pp"):
            Sys_Plot_pp = plt.bar(zT_centers[:NzT-ZT_OFF_PLOT], Sys_Uncertainty[:NzT-ZT_OFF_PLOT]+Sys_Uncertainty[:NzT-ZT_OFF_PLOT],
            bottom=Comb_Dict["%s_Combined_FF"%(SYS)][:NzT-ZT_OFF_PLOT]-Sys_Uncertainty[:NzT-ZT_OFF_PLOT],width=zT_widths[:NzT-ZT_OFF_PLOT]*2, align='center',color=sys_col,alpha=0.3,edgecolor=sys_col)
        else:
            Sys_Plot_pp = plt.bar(zT_centers[:NzT-ZT_OFF_PLOT], Sys_Uncertainty[:NzT-ZT_OFF_PLOT]+Sys_Uncertainty[:NzT-ZT_OFF_PLOT],
            bottom=Comb_Dict["%s_Combined_FF"%(SYS)][:NzT-ZT_OFF_PLOT]-Sys_Uncertainty[:NzT-ZT_OFF_PLOT],width=zT_widths[:NzT-ZT_OFF_PLOT]*2,align='center',color=sys_col,fill=False,edgecolor="blue")
        
        if (plot_power):
            model,p,chi2dof = Fit_FF_PowerLaw(Comb_Dict,SYS)
            plt.plot(zT_centers[:NzT-ZT_OFF_PLOT], model, sys_col,label=r"%s $\alpha = %1.2f\pm 0.1 \chi^2 = %1.2f$"%(SYS,p,chi2dof))
    
    if (Use_MC):
        plt.plot(zT_centers[:NzT-ZT_OFF_PLOT],pythia_FF,'--',color="forestgreen",label="PYTHIA 8.2 Monash")
        plt.errorbar(zT_centers[:NzT-ZT_OFF_PLOT],pythia_FF,yerr=pythia_FF_Errors,fmt='--',color="forestgreen",capsize=0) 
    
    
    plt.yscale('log')                             
    plt.ylabel(r"$\frac{1}{N_{\mathrm{\gamma}}}\frac{\mathrm{d}^3N}{\mathrm{d}z_{\mathrm{T}}\mathrm{d}|\Delta\varphi|\mathrm{d}\Delta\eta}$",fontsize=axis_size,y=0.76)
    plt.ylim(0.037,15)
    plt.yticks(fontsize=20)
    plt.xticks(fontsize=0)
    plt.xlim(0,0.65)
    plt.tick_params(which='both',direction='in',right=True,top=True,bottom=False,length=10)
    plt.tick_params(which='minor',length=5)

    #pp_sys_Error = (Comb_Dict["pp_Combined_FF"][:NzT-ZT_OFF_PLOT])*math.sqrt(Rel_pUncert["pp"]**2+0.056**2)
    #p_Pb_sys_Error = (Comb_Dict["p-Pb_Combined_FF"][:NzT-ZT_OFF_PLOT])*math.sqrt(Rel_pUncert["p-Pb"]**2+0.056**2+Eta_Cor**2)
    
    Chi2,NDF,Pval = Get_pp_pPb_List_Chi2(Comb_Dict["pp_Combined_FF"][:NzT-ZT_OFF_PLOT],
                                         Comb_Dict["pp_Combined_FF_Errors"][:NzT-ZT_OFF_PLOT],
                                         pp_sys_Error,
                                         Comb_Dict["p-Pb_Combined_FF"][:NzT-ZT_OFF_PLOT],
                                         Comb_Dict["p-Pb_Combined_FF_Errors"][:NzT-ZT_OFF_PLOT],
                                         p_Pb_sys_Error)

    leg = plt.legend(numpoints=1,frameon=True,edgecolor='white', framealpha=0.0, fontsize=label_size,handlelength=1,labelspacing=0.2,loc='lower left',bbox_to_anchor=(0.001, 0.05))


    plt.annotate(r"ALICE, $\sqrt{s_{\mathrm{_{NN}}}}=5.02$ TeV",xy=(0.115,0.008),xycoords='axes fraction', ha='left',va='bottom',fontsize=label_size)
    plt.annotate(r"%1.0f < $p_\mathrm{T}^{\gamma}$ < %1.0f GeV/$c$"%(pTbins[0],pTbins[N_pT_Bins]),xy=(0.97, 0.81), xycoords='axes fraction', ha='right', va='top', fontsize=label_size)
    plt.annotate(r"%1.1f < $p_\mathrm{T}^\mathrm{h}$ < %1.1f GeV/$c$"%(Min_Hadron_pT,Max_Hadron_pT),xy=(0.97, 0.89), xycoords='axes fraction', ha='right', va='top', fontsize=label_size)
    plt.annotate("$\chi^2/\mathrm{ndf}$ = %1.1f/%i, $p$ = %1.2f"%(Chi2*NDF,NDF,Pval), xy=(0.97, 0.97), xycoords='axes fraction', ha='right', va='top', fontsize=label_size)



#HEP FF
    Fig5 = Table("Figure 5 Top Panel")
    Fig5.description = "$\gamma^\mathrm{iso}$-tagged fragmentation function for pp (red) and p$-$Pb data (blue) at $\sqrt{s_\mathrm{NN}}$ = 5.02 TeV as measured by the ALICE detector. The boxes represent the systematic uncertainties while the vertical bars indicate the statistical uncertainties. The dashed green line corresponds to PYTHIA 8.2 Monash Tune. The $\chi^2$ test for the comparison of pp and p$-$Pb data incorporates correlations among different $z_\mathrm{T}$ intervals. A constant that was fit to the ratio is shown as grey band, with the width indicating the uncertainty on the fit."
    Fig5.location = "Data from Figure 5 Top Panel, Page 15"
    Fig5.keywords["observables"] = ["$\frac{1}{N_{\mathrm{\gamma}}}\frac{\mathrm{d}^3N}{\mathrm{d}z_{\mathrm{T}}\mathrm{d}\Delta\varphi\mathrm{d}\Delta\eta}$"]
    Fig5.add_image("./pics/LO/zT_Rebin_8_006zT06zT13fnew/Final_FFunction_and_Ratio.pdf")
    
    # x-axis: zT
    zt = Variable(r"$z_\mathrm{T}$", is_independent=True, is_binned=True, units="")
    zt.values = zT_edges
    Fig5.add_variable(zt)

    # y-axis: p-Pb Yields
    pPb_data = Variable("p$-$Pb conditional yield of associated hadrons", is_independent=False, is_binned=False, units="")
    pPb_data.values = Comb_Dict["p-Pb_Combined_FF"]
    
    pPb_sys = Uncertainty("p-Pb Systematic", is_symmetric=True)
    pPb_sys.values = p_Pb_sys_Error
    pPb_stat = Uncertainty("p-Pb Statistical", is_symmetric=True)
    pPb_stat.values = Comb_Dict["p-Pb_Combined_FF_Errors"]
    pPb_data.add_uncertainty(pPb_sys)
    pPb_data.add_uncertainty(pPb_stat)    

    # y-axis: pp Yields
    pp_data = Variable("pp conditional yield of associated hadrons", is_independent=False, is_binned=False, units="")
    pp_data.values = Comb_Dict["pp_Combined_FF"]
    
    pp_sys = Uncertainty("pp Systematic", is_symmetric=True)
    pp_sys.values = pp_sys_Error
    pp_stat = Uncertainty("pp Statistical", is_symmetric=True)
    pp_stat.values = Comb_Dict["pp_Combined_FF_Errors"]
    pp_data.add_uncertainty(pp_sys)
    pp_data.add_uncertainty(pp_stat)

    # y-axis: PYTHIA Yields
    pythia_data = Variable("PYTHIA conditional yield of associated hadrons", is_independent=False, is_binned=False, units="")
    pythia_data.values = pythia_FF
    
    pythia_stat = Uncertainty("PYTHIA Statistical", is_symmetric=True)
    pythia_stat.values = pythia_FF_Errors
    pythia_data.add_uncertainty(pythia_stat)

    #Add everything to the HEP Table
    Fig5.add_variable(pPb_data)
    Fig5.add_variable(pp_data)
    Fig5.add_variable(pythia_data)

    submission.add_table(Fig5)

    #RATIO SECOND Y_AXIS
    fig.add_axes((0.1,0.1,0.88,0.2))

    pPb_Combined = Comb_Dict["p-Pb_Combined_FF"]
    pPb_Combined_Errors = Comb_Dict["p-Pb_Combined_FF_Errors"]
    pPb_purity_Uncertainty = Comb_Dict["p-Pb_purity_Uncertainty"]
    
    pp_Combined = Comb_Dict["pp_Combined_FF"]
    pp_Combined_Errors = Comb_Dict["pp_Combined_FF_Errors"]
    pp_purity_Uncertainty = Comb_Dict["pp_purity_Uncertainty"]
    
    Ratio = pPb_Combined/pp_Combined
    Ratio_Error = np.sqrt((pPb_Combined_Errors/pPb_Combined)**2 + (pp_Combined_Errors/pp_Combined)**2)*Ratio
    Ratio_Plot = plt.errorbar(zT_centers[:NzT-ZT_OFF_PLOT], Ratio[:NzT-ZT_OFF_PLOT], yerr=Ratio_Error[:NzT-ZT_OFF_PLOT],xerr=zT_widths[:NzT-ZT_OFF_PLOT]*0, fmt='ko',capsize=0, ms=6,lw=1)
    
        #Save
    np.save("npy_files/%s_Averaged_FF_Ratio_%s.npy"%(Shower,description_string),Ratio)
    np.save("npy_files/%s_Averaged_FF_Ratio_Errors_%s.npy"%(Shower,description_string),Ratio_Error)
    
    Purity_Uncertainty = np.sqrt((pp_purity_Uncertainty/pp_Combined)**2 + (pPb_purity_Uncertainty/pPb_Combined)**2)*Ratio
    Efficiency_Uncertainty = np.ones(len(pPb_Combined))*0.056*math.sqrt(2)*Ratio 
    Eta_Cor_Uncertainty = Eta_Correction_Uncertainty/Comb_Dict["p-Pb_Combined_FF"]*Ratio
    if (CorrectedP):
        Ratio_Systematic = np.sqrt(Purity_Uncertainty**2 + Efficiency_Uncertainty**2 + Eta_Cor_Uncertainty**2)
        
    Sys_Plot = plt.bar(zT_centers[:NzT-ZT_OFF_PLOT], Ratio_Systematic[:NzT-ZT_OFF_PLOT]+Ratio_Systematic[:NzT-ZT_OFF_PLOT],
            bottom=Ratio[:NzT-ZT_OFF_PLOT]-Ratio_Systematic[:NzT-ZT_OFF_PLOT], width=zT_widths[:NzT-ZT_OFF_PLOT]*2, align='center',color='black',alpha=0.25)
    
    ### ROOT LINEAR and CONSTANT FITS ###
    Ratio_TGraph = TGraphErrors()
    for izt in range (len(Ratio)-ZT_OFF_PLOT):
        Ratio_TGraph.SetPoint(izt,zT_centers[izt],Ratio[izt])
        Ratio_TGraph.SetPointError(izt,0,Ratio_Error[izt])

    Ratio_TGraph.Fit("pol0","S")
    f = Ratio_TGraph.GetFunction("pol0")
    chi2_red  = f.GetChisquare()/f.GetNDF()
    pval = f.GetProb()
    p0 = f.GetParameter(0)
    p0e = f.GetParError(0)
    p0col = "grey"
    Show_Fits = True
    if (Show_Fits):
        sys_const = 0.19 #23% relative from purity + tracking
        #sys_const = 0.504245 #IRC
        plt.annotate("$c = {0:.2f} \pm {1:.2f} \pm {2:.2f}$".format(p0,p0e,sys_const), xy=(0.98, 0.9), xycoords='axes fraction', ha='right', va='top', color="black",fontsize=label_size,alpha=.9)
        plt.annotate(r"$p = %1.2f$"%(pval), xy=(0.98, 0.75), xycoords='axes fraction', ha='right', va='top', color="black",fontsize=label_size,alpha=.9)

        c_error = math.sqrt(p0e**2 + sys_const**2)
        plt.fill_between(np.arange(0,1.1,0.1), p0+c_error, p0-c_error,color=p0col,alpha=.3)
    
    ###LABELS/AXES###
    plt.axhline(y=1, color='k', linestyle='--')
    
    plt.xlabel("${z_\mathrm{T}} = p_\mathrm{T}^{\mathrm{h}}/p_\mathrm{T}^\gamma$",fontsize=axis_size-8,x=0.9)
    plt.ylabel(r"$\frac{\mathrm{p-Pb}}{\mathrm{pp}}$",fontsize=axis_size,y=0.5)
    plt.ylim((-0.0, 2.8))
    plt.xticks(fontsize=20)
    plt.yticks([0.5,1.0,1.5,2.0,2.5],fontsize=20)
    plt.xlim(0,0.65)
    plt.tick_params(which='both',direction='in',right=True,bottom=True,top=True,length=10)
    plt.tick_params(which='both',direction='in',top=True,length=5)

    plt.savefig("pics/%s/%s/Final_FFunction_and_Ratio.pdf"%(Shower,description_string), bbox_inches = "tight")
    plt.show()

#RATIO HEP
    FigRatio = Table("Figure 5 Bottom Panel")
    FigRatio.description = r"$\gamma^\mathrm{iso}$-tagged fragmentation function for pp (red) and p$-$Pb data (blue) at $\sqrt{s_\mathrm{NN}}$ = 5.02 TeV as measured by the ALICE detector. The boxes represent the systematic uncertainties while the vertical bars indicate the statistical uncertainties. The dashed green line corresponds to PYTHIA 8.2 Monash Tune. The $\chi^2$ test for the comparison of pp and p$-$Pb data incorporates correlations among different $z_\mathrm{T}$ intervals. A constant that was fit to the ratio is shown as grey band, with the width indicating the uncertainty on the fit."
    FigRatio.location = "Data from Figure 5, Bottom Panel, Page 15"
    FigRatio.keywords["observables"] = [r"$\frac{1}{N_{\mathrm{\gamma}}}\frac{\mathrm{d}^3N}{\mathrm{d}z_{\mathrm{T}}\mathrm{d}\Delta\varphi\mathrm{d}\Delta\eta}$"]
    FigRatio.add_image("./pics/LO/zT_Rebin_8_006zT06zT13fnew/Final_FFunction_and_Ratio.pdf")

    # x-axis: zT     
    zt_ratio = Variable(r"$z_\mathrm{T}$", is_independent=True, is_binned=True, units="")
    zt_ratio.values = zT_edges
    FigRatio.add_variable(zt_ratio)

    # y-axis: p-Pb Yields
    Ratio_HEP = Variable("Ratio conditional yield of associated hadrons in pp and p$-$Pb", is_independent=False, is_binned=False, units="")
    Ratio_HEP.values = Ratio
    Ratio_sys = Uncertainty("Ratio Systematic", is_symmetric=True)
    Ratio_sys.values = Ratio_Systematic
    Ratio_stat = Uncertainty("Ratio Statistical", is_symmetric=True)
    Ratio_stat.values = Ratio_Error
    Ratio_HEP.add_uncertainty(Ratio_stat)
    Ratio_HEP.add_uncertainty(Ratio_sys)
    FigRatio.add_variable(Ratio_HEP)
    submission.add_table(FigRatio)
Example #18
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
Example #19
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
Example #20
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
Example #21
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
Example #22
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
Example #23
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
Example #24
0
    "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")
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)
Example #25
0
def make_table():
    params = ['r_ggH', 'r_VBF', 'r_VH', 'r_top']

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

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

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

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

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

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

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

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

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

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

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

    # Dependent variables

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    return table
Example #27
0
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,
                      is_binned=False,
                      units="GeV")
fig2_ul_pt.values = fig2_ul_in[:, 0]
Example #28
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"]:
from hepdata_lib import Submission

import numpy as np
submission = Submission()

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
table = Table("Additional Figure 1")
table.description = "Signal selection efficiency times acceptance as a function of resonance mass for a spin-2 bulk graviton decaying to WW and a spin-1 W' decaying to WZ."
table.location = "Data from additional Figure 1"

table.keywords["observables"] = ["ACC", "EFF"]
table.keywords["reactions"] = [
    "P P --> GRAVITON --> W+ W-", "P P --> WPRIME --> W+/W- Z0"
]

data = np.loadtxt("hepdata_lib/examples/example_inputs/effacc_signal.txt",
                  skiprows=2)

print(data)

### Variable
from hepdata_lib import Variable
Example #30
0
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"

table2.keywords["observables"] = ["Uncertainty"]
table2.keywords["reactions"] = ["P P --> W W j j", "P P --> W Z j j"]
table2.keywords["phrases"] = [
    "Same-sign WW", "WZ", "Georgi-Machacek", "Charged Higgs", "VBF"
]

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

print(data2)