Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify call to RunGraphs using new feature in ROOT's master branch #33

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions analyses/cms-open-data-ttbar/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ def book_histos(
nominal_histo = df.Histo1D(histo_model, observable, "Weights")

if variation == "nominal":
results.append(AGCResult(nominal_histo, region, process, variation, nominal_histo, should_vary=True))
results.append(AGCResult(nominal_histo, region, process, variation, should_vary=True))
else:
results.append(AGCResult(nominal_histo, region, process, variation, nominal_histo, should_vary=False))
results.append(AGCResult(nominal_histo, region, process, variation, should_vary=False))
print(f"Booked histogram {histo_model.fName}")

ml_results: list[AGCResult] = []
Expand All @@ -300,11 +300,11 @@ def book_histos(

if variation == "nominal":
ml_results.append(
AGCResult(nominal_histo, feature.name, process, variation, nominal_histo, should_vary=True)
AGCResult(nominal_histo, feature.name, process, variation, should_vary=True)
)
else:
ml_results.append(
AGCResult(nominal_histo, feature.name, process, variation, nominal_histo, should_vary=False)
AGCResult(nominal_histo, feature.name, process, variation, should_vary=False)
)
print(f"Booked histogram {histo_model.fName}")

Expand Down Expand Up @@ -391,8 +391,8 @@ def main() -> None:

# Run the event loops for all processes and variations here
run_graphs_start = time()
run_graphs([r.nominal_histo for r in results + ml_results])

n_computation_graphs_run = run_graphs([r.histo for r in results + ml_results])
assert n_computation_graphs_run == 9
print(f"Executing the computation graphs took {time() - run_graphs_start:.2f} seconds")
if client is not None:
client.close()
Expand Down
12 changes: 2 additions & 10 deletions analyses/cms-open-data-ttbar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ class AGCResult:
region: str
process: str
variation: str
# We keep around the nominal RResultPtr even when `histo` is a RResultMap:
# in v6.28 we need a RResultPtr to pass to RDF.RunGraphs in order to trigger the event loop.
# In later versions RunGraphs accepts RResultMaps as well, and we don't need this data attribute.
nominal_histo: ROOT.RDF.RResultPtr[ROOT.TH1D]
# Whether we should call VariationsFor over histo to produce variations
should_vary: bool = False

Expand Down Expand Up @@ -122,9 +118,7 @@ def postprocess_results(results: list[AGCResult]):
if hasattr(res.histo, "GetValue"): # RResultPtr or distrdf equivalent
# just extract the histogram from the RResultPtr
h = res.histo.GetValue()
new_results.append(
AGCResult(h, res.region, res.process, res.variation, res.nominal_histo)
)
new_results.append(AGCResult(h, res.region, res.process, res.variation))
else:
resmap = res.histo
assert hasattr(resmap, "GetKeys") # RResultMap or distrdf equivalent
Expand All @@ -135,9 +129,7 @@ def postprocess_results(results: list[AGCResult]):
variation_name = str(variation).split(":")[-1]
new_name = h.GetName().replace("nominal", variation_name)
h.SetName(new_name)
new_results.append(
AGCResult(h, res.region, res.process, variation_name, res.nominal_histo)
)
new_results.append(AGCResult(h, res.region, res.process, variation_name))

return new_results

Expand Down
7 changes: 0 additions & 7 deletions environment.yml

This file was deleted.