Skip to content

Ratio to a chosen sample, per-sample drawing styles

ratio="Z + jets" picks the reference sample by label; ratio_ylim and ratio_label override the automatic range and label. A Sample can carry its own color and histtype; the reference takes the text colour, like data points, so it stays visible on light and dark pages.

import matplotlib.pyplot as plt
import rootfig as rf

style = rf.Style()

rf.plot(
    [
        zjets.replace(color=plt.rcParams["text.color"], histtype="errorbar"),
        diboson.replace(color="#d95f02"),
        signal.replace(color="#1b9e77", histtype="fill"),
    ],
    rf.Variable("nJet", bins=(9, -0.5, 8.5), label="Jet multiplicity"),
    normalize=True,
    ratio="Z + jets",
    ratio_ylim=(0, 3),
    ratio_label="Ratio to Z + jets",
    style=style,
)
import matplotlib.pyplot as plt
import rootfig as rf

style = rf.Style(experiment="ATLAS", status="Internal", lumi=140, com=13.6)

rf.plot(
    [
        zjets.replace(color=plt.rcParams["text.color"], histtype="errorbar"),
        diboson.replace(color="#d95f02"),
        signal.replace(color="#1b9e77", histtype="fill"),
    ],
    rf.Variable("nJet", bins=(9, -0.5, 8.5), label="Jet multiplicity"),
    normalize=True,
    ratio="Z + jets",
    ratio_ylim=(0, 3),
    ratio_label="Ratio to Z + jets",
    style=style,
)
import matplotlib.pyplot as plt
import rootfig as rf

style = rf.Style(experiment="CMS", status="Preliminary", lumi=138, com=13.6)

rf.plot(
    [
        zjets.replace(color=plt.rcParams["text.color"], histtype="errorbar"),
        diboson.replace(color="#d95f02"),
        signal.replace(color="#1b9e77", histtype="fill"),
    ],
    rf.Variable("nJet", bins=(9, -0.5, 8.5), label="Jet multiplicity"),
    normalize=True,
    ratio="Z + jets",
    ratio_ylim=(0, 3),
    ratio_label="Ratio to Z + jets",
    style=style,
)
import matplotlib.pyplot as plt
import rootfig as rf

style = rf.Style(experiment="LHCb", status="Preliminary", lumi=9, com=13.6)

rf.plot(
    [
        zjets.replace(color=plt.rcParams["text.color"], histtype="errorbar"),
        diboson.replace(color="#d95f02"),
        signal.replace(color="#1b9e77", histtype="fill"),
    ],
    rf.Variable("nJet", bins=(9, -0.5, 8.5), label="Jet multiplicity"),
    normalize=True,
    ratio="Z + jets",
    ratio_ylim=(0, 3),
    ratio_label="Ratio to Z + jets",
    style=style,
)
import matplotlib.pyplot as plt
import rootfig as rf

style = rf.Style(experiment="ALICE", status="Preliminary")

rf.plot(
    [
        zjets.replace(color=plt.rcParams["text.color"], histtype="errorbar"),
        diboson.replace(color="#d95f02"),
        signal.replace(color="#1b9e77", histtype="fill"),
    ],
    rf.Variable("nJet", bins=(9, -0.5, 8.5), label="Jet multiplicity"),
    normalize=True,
    ratio="Z + jets",
    ratio_ylim=(0, 3),
    ratio_label="Ratio to Z + jets",
    style=style,
)
import matplotlib.pyplot as plt
import rootfig as rf

style = rf.Style(experiment="DUNE", status="Preliminary")

rf.plot(
    [
        zjets.replace(color=plt.rcParams["text.color"], histtype="errorbar"),
        diboson.replace(color="#d95f02"),
        signal.replace(color="#1b9e77", histtype="fill"),
    ],
    rf.Variable("nJet", bins=(9, -0.5, 8.5), label="Jet multiplicity"),
    normalize=True,
    ratio="Z + jets",
    ratio_ylim=(0, 3),
    ratio_label="Ratio to Z + jets",
    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.

It uses these samples and variables, shared by the gallery examples (see Samples, variables, cuts and styles):

signal = rf.Sample("signal.root", tree="events", label="Signal", weight="weight", scale=0.03)
zjets = rf.Sample("background.root", tree="events", label="Z + jets", weight="weight")
diboson = rf.Sample("diboson.root", tree="events", label="Diboson", weight="weight", scale=0.15)
data = rf.Sample("data.root", tree="events", label="Data", is_data=True)
mc = [zjets, diboson, signal]  # stacked bottom to top

pt = rf.Variable("Muon_pt", bins=(30, 0, 300), label=r"$p_T^{\mu}$", unit="GeV")
mll = rf.Variable("m_ll", bins=(70, 50, 260), label=r"$m_{\ell\ell}$", unit="GeV")
met = rf.Variable("MET", bins=(40, 0, 400), label=r"$E_T^{miss}$", unit="GeV")