diff --git a/columnflow/tasks/plotting.py b/columnflow/tasks/plotting.py index 3f62693eb..e90eb6420 100644 --- a/columnflow/tasks/plotting.py +++ b/columnflow/tasks/plotting.py @@ -190,6 +190,11 @@ def run(self): for outp in self.output()["plots"]: outp.dump(fig, formatter="mpl") + # save the histograms + if self.save_hists: + for outp in self.output()["hists"]: + outp.dump(hists, formatter="pickle") + class PlotVariablesBaseSingleShift( PlotVariablesBase, @@ -197,6 +202,11 @@ class PlotVariablesBaseSingleShift( ): exclude_index = True + save_hists = luigi.BoolParameter( + default=False, + description="when True, the histograms are saved as pickle files; default: False", + ) + # upstream requirements reqs = Requirements( PlotVariablesBase.reqs, @@ -245,9 +255,14 @@ def plot_parts(self) -> law.util.InsertableDict: return parts def output(self): - return { + output = { "plots": [self.target(name) for name in self.get_plot_names("plot")], } + if self.save_hists: + output["hists"] = [ + self.target(self.get_plot_names("hist")[0].replace(self.file_types[0], "pickle")), + ] + return output def store_parts(self): parts = super().store_parts()