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

Adding documentation for Data/MC Plots #211

Merged
merged 2 commits into from
Sep 26, 2023
Merged
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
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### [Latest]

- Adding documentation for Data/MC plots [!211](https://github.com/umami-hep/puma/pull/211)
- Update linters [!210](https://github.com/umami-hep/puma/pull/210)
- Fix tagger discriminant bug, add future imports [!209](https://github.com/umami-hep/puma/pull/209)
- Add weight support for efficiency calculation [!206](https://github.com/umami-hep/puma/pull/206)
Expand Down
16 changes: 16 additions & 0 deletions docs/source/examples/histograms.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,20 @@ underflow/overflow bins.

```py
§§§examples/plot_histogram_underoverflow.py§§§
```

## Data/MC histograms

To visualize the agreement of the Monte-Carlo with data, `puma` is also able to produce
so-called Data/MC histograms. They show the data as a dot histogram while the MC is still
a stacked histogram. An example of this plot can be seen here:

<img src=https://github.com/umami-hep/puma/raw/examples-material/data_mc_example.png width=500>

The code to create this example can be found in the `examples` folder in the `plot_data_mc.py`.
Similar to the rest of the `Puma.HistogramPlot` examples shown here, a lot of more optional
argument can be passed.

```py
§§§examples/plot_data_mc.py§§§
```
19 changes: 16 additions & 3 deletions examples/plot_data_mc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,33 @@

from puma import Histogram, HistogramPlot

# Generate two MC contributions and data
rng = np.random.default_rng(42)
mc1 = rng.normal(size=10_000)
mc2 = rng.normal(size=20_000)
data = rng.normal(size=30_000)

# Set up the real plot
data_mc_plot = HistogramPlot(
bins_range=[-2, 2],
n_ratio_panels=1,
stacked=True,
norm=False,
)

# Set the plot title
data_mc_plot.title = "Test Data/MC Plot"
data_mc_plot.add(Histogram(mc1, label="MC Process 1", colour="b"))
data_mc_plot.add(Histogram(mc2, label="MC Process 2", colour="r"))
data_mc_plot.add(Histogram(data, label="MC Process 2", is_data=True, colour="k"))

# Add the different MC contributions to the plot
data_mc_plot.add(Histogram(mc1, label="MC Process 1"))
data_mc_plot.add(Histogram(mc2, label="MC Process 2"))

# Add the data
data_mc_plot.add(Histogram(data, label="Data", is_data=True, colour="k"))

# Draw the plot
data_mc_plot.draw()

# Add the bin width to the y-axis label
data_mc_plot.add_bin_width_to_ylabel()
data_mc_plot.savefig("data_mc_example.png")