from pyhs3.distributions import HistFactoryDistChannel

# Create a HistFactory channel with multiple samples
channel = HistFactoryDistChannel(
    name="SR",
    axes=[{"name": "mass", "min": 100.0, "max": 150.0, "nbins": 5}],
    samples=[
        {
            "name": "signal",
            "data": {"contents": [5.0, 8.0, 12.0, 7.0, 3.0], "errors": [2.0, 2.5, 3.0, 2.3, 1.5]},
            "modifiers": []
        },
        {
            "name": "background",
            "data": {"contents": [15.0, 18.0, 14.0, 16.0, 12.0], "errors": [3.5, 4.0, 3.7, 3.9, 3.2]},
            "modifiers": []
        }
    ]
)

# Convert to hist - creates histogram with categorical "process" axis
h = channel.to_hist()

# Plot both samples from the single histogram
h["signal", :].plot(histtype="step", linewidth=2, label="Signal")
h["background", :].plot(histtype="step", linewidth=2, label="Background")
plt.xlabel("mass [GeV]")
plt.ylabel("Events")
plt.legend()
plt.title("HistFactory Channel")