def write_out(self): with open(self.plot_output_dir + "cutflow_table.txt", "w") as f: f.writelines(self.table_lines) wrp = wrappers.Wrapper(name="CutflowTableTxt") for i, line in enumerate(self.table_lines): setattr(wrp, "line_%2d"%i, line) diskio.write(wrp, self.plot_output_dir + "cutflow_table.info")
def store_result(self, result, formula): wrp = wrappers.Wrapper(name=self.name) wrp.__dict__.update(result) settings.persistent_dict[self.name] = wrp wrp.formula = formula diskio.write(wrp, settings.dir_result + "sys_uncert_result.info") self.message("INFO Group uncertainty results: " + str(wrp))
def finish_with_systematic(self): wrp = wrappers.Wrapper(name=self.name) wrp.formula = "abs(new - old) / old" for calc in xsec_calc_name_iter(): self.calc_uncert(calc, wrp) diskio.write(wrp, settings.dir_result + "sys_uncert_result.info") settings.persistent_dict[self.name] = wrp
def test_canvas_info_file(self): fname = "test/cnv_save.info" self.test_canvasBuilder_make() diskio.write(self.test_wrp, fname) # file should have 23 lines (with history written out) with open(fname) as fhandle: self.assertEqual(len(list(fhandle)), 23)
def test_write(self): fname = "test/wrp_save.info" diskio.write(self.test_wrp, fname) # file should exist self.assertTrue(os.path.exists(fname)) # file should have 7 lines (with history written out) with open(fname) as fhandle: n_lines = len(list(fhandle)) self.assertEqual(n_lines, 21)
def test_write(self): fname = "test/wrp_save.info" diskio.write(self.test_wrp, fname) # file should exist self.assertTrue( os.path.exists(fname) ) # file should have 7 lines (with history written out) with open(fname) as fhandle: n_lines = len(list(fhandle)) self.assertEqual(n_lines, 21)
def test_read(self): fname = "test/wrp_load.info" diskio.write(self.test_wrp, fname) loaded = diskio.read(fname) self.test_wrp.history = str(self.test_wrp.history) # check names self.assertEqual(self.test_wrp.all_writeable_info(), loaded.all_writeable_info()) # check histograms (same integral, different instance) self.assertEqual(self.test_wrp.histo.Integral(), loaded.histo.Integral()) self.assertNotEqual(str(self.test_wrp.histo), str(loaded.histo))
def test_read(self): fname = "test/wrp_load.info" diskio.write(self.test_wrp, fname) loaded = diskio.read(fname) self.test_wrp.history = str(self.test_wrp.history) # check names self.assertEqual( self.test_wrp.all_writeable_info(), loaded.all_writeable_info() ) # check histograms (same integral, different instance) self.assertEqual(self.test_wrp.histo.Integral(), loaded.histo.Integral()) self.assertNotEqual(str(self.test_wrp.histo), str(loaded.histo))
def write_out(self): with open(self.plot_output_dir + "cutflow_tabular.tex", "w") as f: f.writelines(map(lambda l: l + "\n", self.table_lines)) with open(self.plot_output_dir + "cutflow.tex", "w") as f: f.writelines(map(lambda l: l + "\n", tex_template)) # subprocess.call( # ["pdflatex", "cutflow.tex"], # cwd=self.plot_output_dir # ) wrp = wrappers.Wrapper(name="CutflowTableTex") for i, line in enumerate(self.table_lines): setattr(wrp, "line_%2d"%i, line) diskio.write(wrp, self.plot_output_dir + "cutflow_table.info")
def build_fit_function(self, fitted, mc_tmplts, x_min, x_max): combine_cfg = [ ] # save histos to root file combine_root_wrp = wrp.Wrapper( name="CombineHistos", data_obs=fitted.histo, signal=mc_tmplts[1].histo, background=mc_tmplts[0].histo, n_data_obs=fitted.histo.Integral(), n_signal=mc_tmplts[1].histo.Integral(), n_background=mc_tmplts[0].histo.Integral(), ) diskio.write(combine_root_wrp) raise Exception("STOP!")
def write_snippets_for_latexit(self): res = self.result wrp = wrappers.Wrapper( name="LatexitSnippets", xsec_ttgam= r"\sigma_{t \bar t+\gamma} \;&=\; R\;\cdot \;\sigma_{t\bar t} \\ &=\; " + (r"%.1f" % res.xsec) + (r"\;\pm \;%.1f{\rm (stat.)}" % res.xsec_err_stat) + (r" \;\pm \;%.1f{\rm (syst.)} \,\tn{pb}" % res.xsec_err_sys), R_result= r"\begin{align*} " + (r"\pi_{t\bar t} = N^{presel}_{t\bar t} / N^{presel} = %.1f" % (res.pur_tt*100)) + r"\,\% \\ " + (r"\epsilon_\gamma^{\rm vis} = N^{vis}_{{t\bar t}+\gamma} / N^{presel}_{{t\bar t}+\gamma} = %.1f" % (res.eff_gamma_fid*100)) + r"\,\% \\ " + (r"\epsilon_\gamma = N^{sel}_{{t\bar t}+\gamma} / N^{vis}_{{t\bar t}+\gamma} = %.1f" % (res.eff_gamma*100)) + r"\,\% \\ " + (r"\Rightarrow R \;=\;(%.2f " % (res.R*100)) + (r"\;\pm %.2f^\tn{fit})\cdot 10^{-2} " % (res.R_err_stat*100)) + r"\end{align*} ", ) diskio.write(wrp) with open(self.plot_output_dir + "__LATEXIT_xsec.tex", "w") as f: f.write(wrp.xsec_ttgam + "\n") with open(self.plot_output_dir + "__LATEXIT_R.tex", "w") as f: f.write(wrp.R_result + "\n")
def save_histos(wrps): for wrp in wrps: w = wrp[0] name = settings.dir_result + w.analyzer diskio.write(w, name + ".info") yield wrp