Several samples, normalised, with a ratio panel¶
A {label: file} mapping gives one histogram per sample with a binning shared by
all. An integer bins infers the range from every sample at once, cutting the thin
end of the tail. normalize=True scales each to unit area and ratio=True adds a
panel with every sample divided by the first, uncertainties propagated.

import rootfig as rf
style = rf.Style()
rf.plot(
{"Signal": "signal.root", "Z + jets": "background.root"},
"Muon_pt",
tree="events",
selection="Muon_isTight and abs(Muon_eta) < 2.5",
weight="weight",
bins=40,
unit="GeV",
normalize=True,
ratio=True,
style=style,
)

import rootfig as rf
style = rf.Style(experiment="ATLAS", status="Internal", lumi=140, com=13.6)
rf.plot(
{"Signal": "signal.root", "Z + jets": "background.root"},
"Muon_pt",
tree="events",
selection="Muon_isTight and abs(Muon_eta) < 2.5",
weight="weight",
bins=40,
unit="GeV",
normalize=True,
ratio=True,
style=style,
)

import rootfig as rf
style = rf.Style(experiment="CMS", status="Preliminary", lumi=138, com=13.6)
rf.plot(
{"Signal": "signal.root", "Z + jets": "background.root"},
"Muon_pt",
tree="events",
selection="Muon_isTight and abs(Muon_eta) < 2.5",
weight="weight",
bins=40,
unit="GeV",
normalize=True,
ratio=True,
style=style,
)

import rootfig as rf
style = rf.Style(experiment="LHCb", status="Preliminary", lumi=9, com=13.6)
rf.plot(
{"Signal": "signal.root", "Z + jets": "background.root"},
"Muon_pt",
tree="events",
selection="Muon_isTight and abs(Muon_eta) < 2.5",
weight="weight",
bins=40,
unit="GeV",
normalize=True,
ratio=True,
style=style,
)

import rootfig as rf
style = rf.Style(experiment="ALICE", status="Preliminary")
rf.plot(
{"Signal": "signal.root", "Z + jets": "background.root"},
"Muon_pt",
tree="events",
selection="Muon_isTight and abs(Muon_eta) < 2.5",
weight="weight",
bins=40,
unit="GeV",
normalize=True,
ratio=True,
style=style,
)

import rootfig as rf
style = rf.Style(experiment="DUNE", status="Preliminary")
rf.plot(
{"Signal": "signal.root", "Z + jets": "background.root"},
"Muon_pt",
tree="events",
selection="Muon_isTight and abs(Muon_eta) < 2.5",
weight="weight",
bins=40,
unit="GeV",
normalize=True,
ratio=True,
style=style,
)
Setup
The code reads the toy dataset. In a checkout of rootfig, python examples/gallery writes it to examples/out/ in a few seconds; run the code inside that directory.