Skip to content

Commit 96d6d52

Browse files
benedikt-voelkelBenedikt Volkel
andauthored
Dump full database in data result dir in analysis (#658)
* Dump full database in data result dir in analysis * Create MC result dir in analyzer if not existing Co-authored-by: Benedikt Volkel <[email protected]>
1 parent 7db8182 commit 96d6d52

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

machine_learning_hep/analysis/analyzer.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,28 @@
1212
## along with this program. if not, see <https://www.gnu.org/licenses/>. ##
1313
#############################################################################
1414

15+
from os.path import exists, join
16+
from os import makedirs
17+
1518
# HF specific imports
1619
from machine_learning_hep.workflow.workflow_base import WorkflowBase
20+
from machine_learning_hep.io import dump_yaml_from_dict
1721

1822

1923
class Analyzer(WorkflowBase):
2024
def __init__(self, datap, case, typean, period):
2125
super().__init__(datap, case, typean, period)
2226

27+
# The only thing here is to dump the database in the data analysis directory
28+
for mcordata in ("mc", "data"):
29+
results_dir = datap["analysis"][typean][mcordata]["results"][period] \
30+
if period is not None else datap["analysis"][typean][mcordata]["resultsallp"]
31+
if not exists(results_dir):
32+
# create otput directories in case they do not exist
33+
makedirs(results_dir)
34+
if mcordata == "data":
35+
dump_yaml_from_dict({case: datap},
36+
join(results_dir, f"database_{case}_{typean}.yml"))
2337

2438

2539
class AnalyzerAfterBurner(WorkflowBase):

machine_learning_hep/analysis/analyzer_jet.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from ROOT import gROOT, gStyle
3030
from ROOT import RooUnfoldBayes
3131
# HF specific imports
32-
from machine_learning_hep.utilities import folding, equal_binning_lists, make_message_notfound, checkmakedir
32+
from machine_learning_hep.utilities import folding, equal_binning_lists, make_message_notfound
3333
from machine_learning_hep.analysis.analyzer import Analyzer
3434
from machine_learning_hep.utilities import setup_histogram, setup_canvas, get_colour, get_marker, get_y_window_gr, get_y_window_his, get_plot_range
3535
from machine_learning_hep.utilities import setup_legend, setup_tgraph, draw_latex, tg_sys
@@ -215,10 +215,6 @@ def __init__(self, datap, case, typean, period):
215215
if period is not None else datap["analysis"][typean]["mc"]["resultsallp"]
216216
self.d_resultsallpdata = datap["analysis"][typean]["data"]["results"][period] \
217217
if period is not None else datap["analysis"][typean]["data"]["resultsallp"]
218-
# create otput directories in case they do not exist
219-
for dir_out in [self.d_resultsallpmc, self.d_resultsallpdata]:
220-
if not os.path.exists(dir_out):
221-
checkmakedir(dir_out)
222218

223219
# input directories (processor output)
224220
self.d_resultsallpmc_proc = self.d_resultsallpmc
@@ -245,10 +241,6 @@ def __init__(self, datap, case, typean, period):
245241
self.efficiency_filename = "efficiencies"
246242
self.sideband_subtracted_filename = "sideband_subtracted"
247243

248-
# Save the database in the results directory.
249-
path_db_out = os.path.join(self.d_resultsallpdata, "database_%s_%s.yml" % (self.case, self.typean))
250-
with open(path_db_out, "w") as file_db_out:
251-
yaml.safe_dump(datap, file_db_out, default_flow_style=False)
252244

253245
def fit(self):
254246
self.loadstyle()

0 commit comments

Comments
 (0)