Skip to content

Commit

Permalink
Save histograms when save_hists is True
Browse files Browse the repository at this point in the history
  • Loading branch information
haddadanas committed Nov 7, 2024
1 parent 69343b8 commit b763659
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion columnflow/tasks/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,23 @@ 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,
ShiftTask,
):
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,
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit b763659

Please sign in to comment.