Belle II Software development
invariant_mass_plot.py
1#!/usr/bin/env python3
2
3
10
11import matplotlib as mpl
12import matplotlib.pyplot as plt
13import uproot
14
15# Only include this line if you're running from ipython an a remote server
16mpl.use("Agg")
17
18plt.style.use("belle2") # use the official Belle II plotting style
19
20# Declare list of variables
21var_list = ['Jpsi_isSignal', 'Jpsi_M_uncorrected', 'Jpsi_M']
22
23# Make sure that the .root file is in the same directory to find it
24df = uproot.open("Bd2JpsiKS.root:tree").arrays(var_list, library='pd')
25
26# Let's only consider signal J/Psi
27df_signal_only = df.query("Jpsi_isSignal == 1")
28
29fig, ax = plt.subplots()
30
31ax.hist(df_signal_only["Jpsi_M_uncorrected"], label="w/o brems corr", alpha=0.5, range=(1.7, 3.2))
32ax.hist(df_signal_only["Jpsi_M"], label="with brems corr", alpha=0.5, range=(1.7, 3.2))
33
34ax.set_yscale("log") # set a logarithmic scale in the y-axis
35ax.set_xlabel("Invariant mass of the J/Psi [GeV]")
36ax.set_xlim(1.5, 3.5)
37ax.set_ylabel("Events")
38ax.legend() # show legend
39
40plt.savefig("brems_corr_invariant_mass.png")