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

Template histogram visualization from workspace input #523

Open
alexander-held opened this issue Mar 14, 2025 · 1 comment
Open

Template histogram visualization from workspace input #523

alexander-held opened this issue Mar 14, 2025 · 1 comment
Labels
enhancement New feature or request visualization Related to visualization

Comments

@alexander-held
Copy link
Member

cabinetry.visualize.templates relies on the cabinetry configuration file and input histograms to visualize pre-/post-modification histograms and include histogram axis information. It would be useful to have the same visualization also accessible from a pure workspace input.

@alexander-held alexander-held added enhancement New feature or request visualization Related to visualization labels Mar 14, 2025
@alexander-held
Copy link
Member Author

alexander-held commented Mar 14, 2025

Small example with basic functionality:

import pathlib

import cabinetry
import numpy as np


ws = cabinetry.workspace.load("workspaces/example_workspace.json")


for channel in ws["channels"]:
    for sample in channel["samples"]:
        sample_yield = np.asarray(sample["data"])
        nominal_histo = {"yields": sample_yield, "stdev": np.zeros_like(sample_yield)}  # ignore uncertainty

        for modifier in sample["modifiers"]:
            if modifier["type"] == "normsys":
                up_histo_orig = {"yields": sample_yield*modifier["data"]["hi"], "stdev": np.zeros_like(sample_yield)}
                down_histo_orig = {"yields": sample_yield*modifier["data"]["lo"], "stdev": np.zeros_like(sample_yield)}

            elif modifier["type"] == "histosys":
                up_histo_orig = {"yields": modifier["data"]["hi_data"], "stdev": np.zeros_like(sample_yield)}
                down_histo_orig = {"yields": modifier["data"]["lo_data"], "stdev": np.zeros_like(sample_yield)}

            else:
                continue

            figure_name = (
                    f"{channel['name']}_{sample['name']}_{modifier['name']}.pdf"
                ).replace(" ", "-")
            figure_path = pathlib.Path("figures") / figure_name

            figure_label = (
                f"region: {channel['name']}\nsample: {sample['name']}"
                f"\nsystematic: {modifier['name']}"
            )

            cabinetry.visualize.plot_model.templates(
                nominal_histo,
                {},
                {},
                up_histo_orig,
                down_histo_orig,
                np.linspace(0, len(sample_yield), len(sample_yield)+1),  # workspace does not contain binning information
                "observable",  # workspace does not contain observable name
                figure_path=figure_path,
                label=figure_label
            )

For the implementation we may want to consider using pyhf API functionality of the model to read all this data instead in a more generic way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request visualization Related to visualization
Projects
None yet
Development

No branches or pull requests

1 participant