|
@@ -3,37 +3,8 @@ import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
from filval.result_set import ResultSet
|
|
from filval.result_set import ResultSet
|
|
-from filval.histogram_utils import hist, hist_add
|
|
|
|
-from filval.plotter import (decl_plot, render_plots, hist_plot, hist_plot_stack, Plot)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-def generate_dashboard(plots, output='dashboard.htm'):
|
|
|
|
- from jinja2 import Environment, PackageLoader, select_autoescape
|
|
|
|
- from os.path import join
|
|
|
|
- from urllib.parse import quote
|
|
|
|
-
|
|
|
|
- env = Environment(
|
|
|
|
- loader=PackageLoader('plots', 'templates'),
|
|
|
|
- autoescape=select_autoescape(['htm', 'html', 'xml']),
|
|
|
|
- )
|
|
|
|
- env.globals.update({'quote': quote,
|
|
|
|
- 'enumerate': enumerate,
|
|
|
|
- 'zip': zip,
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- def render_to_file(template_name, **kwargs):
|
|
|
|
- with open(join('output', output), 'w') as tempout:
|
|
|
|
- template = env.get_template(template_name)
|
|
|
|
- tempout.write(template.render(**kwargs))
|
|
|
|
-
|
|
|
|
- def get_by_n(objs, n=2):
|
|
|
|
- objs = list(objs)
|
|
|
|
- while objs:
|
|
|
|
- yield objs[:n]
|
|
|
|
- objs = objs[n:]
|
|
|
|
-
|
|
|
|
- render_to_file('dashboard.htm', plots=get_by_n(plots, 3),
|
|
|
|
- outdir="figures/")
|
|
|
|
|
|
+from filval.histogram_utils import hist, hist_add, hist_normalize
|
|
|
|
+from filval.plotter import (decl_plot, render_plots, hist_plot, hist_plot_stack, Plot, generate_dashboard)
|
|
|
|
|
|
|
|
|
|
@decl_plot
|
|
@decl_plot
|
|
@@ -46,18 +17,36 @@ def plot_yield_grid(rss):
|
|
"""
|
|
"""
|
|
_, ((ax_tttt, ax_ttw), (ax_ttz, ax_tth)) = plt.subplots(2, 2)
|
|
_, ((ax_tttt, ax_ttw), (ax_ttz, ax_tth)) = plt.subplots(2, 2)
|
|
ft, ttw, ttz, tth = map(lambda rs: hist(rs.SRs), rss)
|
|
ft, ttw, ttz, tth = map(lambda rs: hist(rs.SRs), rss)
|
|
|
|
+ # ft, ttw = map(lambda rs: hist(rs.SRs), rss[:2])
|
|
plt.sca(ax_tttt)
|
|
plt.sca(ax_tttt)
|
|
- hist_plot(ft, title='TTTT', stats=False)
|
|
|
|
|
|
+ an = ((0.47, 0.33, 0.18, 0.78, 0.49, 0.52, 0.33, 0.49),
|
|
|
|
+ (0, 0, 0, 0, 0, 0, 0, 0), [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5])
|
|
|
|
+ hist_plot(ft, title='TTTT', stats=False, label='Mock')
|
|
|
|
+ hist_plot(an, title='TTTT', stats=False, label='AN')
|
|
|
|
+
|
|
plt.sca(ax_ttw)
|
|
plt.sca(ax_ttw)
|
|
- hist_plot(ttw, title='TTW', stats=False)
|
|
|
|
|
|
+ an = ([2.29663, 0.508494, 0.161166, 1.03811, 0.256401, 0.127582, 0.181522, 0.141659],
|
|
|
|
+ [0, 0, 0, 0, 0, 0, 0, 0], [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5])
|
|
|
|
+ hist_plot(ttw, title='TTW', stats=False, label='Mock')
|
|
|
|
+ hist_plot(an, title='TTW', stats=False, label='AN')
|
|
|
|
+ plt.legend()
|
|
|
|
+
|
|
plt.sca(ax_ttz)
|
|
plt.sca(ax_ttz)
|
|
- hist_plot(ttz, title='TTZ', stats=False)
|
|
|
|
- plt.sca(ax_tth)
|
|
|
|
- hist_plot(tth, title='TTH', stats=False)
|
|
|
|
|
|
+ an = ([0.974751, 0.269195, 1e-06, 0.395831, 0.0264703, 0.06816, 0.8804, 0.274265],
|
|
|
|
+ [0, 0, 0, 0, 0, 0, 0, 0], [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5])
|
|
|
|
+ hist_plot(ttz, title='TTZ', stats=False, label='Mock')
|
|
|
|
+ hist_plot(an, title='TTZ', stats=False, label='AN')
|
|
|
|
+ plt.xlabel('Signal Region')
|
|
|
|
|
|
|
|
+ plt.sca(ax_tth)
|
|
|
|
+ an = ([1.13826, 0.361824, 0.162123, 0.683917, 0.137608, 0.0632719, 0.554491, 0.197864],
|
|
|
|
+ [0, 0, 0, 0, 0, 0, 0, 0], [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5])
|
|
|
|
+ hist_plot(tth, title='TTH', stats=False, label='Mock')
|
|
|
|
+ hist_plot(an, title='TTH', stats=False, label='AN')
|
|
plt.xlabel('Signal Region')
|
|
plt.xlabel('Signal Region')
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
@decl_plot
|
|
@decl_plot
|
|
def plot_yield_stack(rss):
|
|
def plot_yield_stack(rss):
|
|
r"""## Event Yield - Stacked
|
|
r"""## Event Yield - Stacked
|
|
@@ -71,11 +60,40 @@ def plot_yield_stack(rss):
|
|
ft = ft[0]*10, ft[1], ft[2]
|
|
ft = ft[0]*10, ft[1], ft[2]
|
|
hist_plot(ft, label='TTTT (x10)', stats=False, color='k')
|
|
hist_plot(ft, label='TTTT (x10)', stats=False, color='k')
|
|
|
|
|
|
- plt.ylim((0, 160))
|
|
|
|
|
|
+ plt.ylim((0, 60))
|
|
plt.xlabel('Signal Region')
|
|
plt.xlabel('Signal Region')
|
|
plt.legend()
|
|
plt.legend()
|
|
|
|
|
|
|
|
|
|
|
|
+@decl_plot
|
|
|
|
+def plot_lep_multi(rss, use_mc_reweight, dataset):
|
|
|
|
+ _, (ax_els, ax_mus, ax_taus) = plt.subplots(3, 1)
|
|
|
|
+ if use_mc_reweight:
|
|
|
|
+ els = list(map(lambda rs: hist_normalize(hist(rs.nEls_mc)), rss))
|
|
|
|
+ mus = list(map(lambda rs: hist_normalize(hist(rs.nMus_mc)), rss))
|
|
|
|
+ taus = list(map(lambda rs: hist_normalize(hist(rs.nTaus_mc)), rss))
|
|
|
|
+ else:
|
|
|
|
+ els = list(map(lambda rs: hist_normalize(hist(rs.nEls)), rss))
|
|
|
|
+ mus = list(map(lambda rs: hist_normalize(hist(rs.nMus)), rss))
|
|
|
|
+ taus = list(map(lambda rs: hist_normalize(hist(rs.nTaus)), rss))
|
|
|
|
+
|
|
|
|
+ def _plot(ax, procs):
|
|
|
|
+ plt.sca(ax)
|
|
|
|
+ ft, ttw, ttz, tth = procs
|
|
|
|
+ h = {'TTTT': ft,
|
|
|
|
+ 'TTW': ttw,
|
|
|
|
+ 'TTZ': ttz,
|
|
|
|
+ 'TTH': tth}[dataset]
|
|
|
|
+ hist_plot(h, stats=False, label=dataset)
|
|
|
|
+
|
|
|
|
+ _plot(ax_els, els)
|
|
|
|
+ plt.xlabel('\\# Good Electrons')
|
|
|
|
+ plt.legend()
|
|
|
|
+ _plot(ax_mus, mus)
|
|
|
|
+ plt.xlabel('\\# Good Muons')
|
|
|
|
+ _plot(ax_taus, taus)
|
|
|
|
+ plt.xlabel('\\# Good Taus')
|
|
|
|
+
|
|
@decl_plot
|
|
@decl_plot
|
|
def plot_sig_strength(rss):
|
|
def plot_sig_strength(rss):
|
|
r""" The signal strength of the TTTT signal defined as
|
|
r""" The signal strength of the TTTT signal defined as
|
|
@@ -88,12 +106,55 @@ def plot_sig_strength(rss):
|
|
strength = ft[0] / np.sqrt(ft[0] + bg[0])
|
|
strength = ft[0] / np.sqrt(ft[0] + bg[0])
|
|
hist_plot((strength, ft[1], ft[2]), stats=False)
|
|
hist_plot((strength, ft[1], ft[2]), stats=False)
|
|
|
|
|
|
|
|
+@decl_plot
|
|
|
|
+def plot_event_obs(rss, dataset):
|
|
|
|
+ r"""
|
|
|
|
+
|
|
|
|
+ """
|
|
|
|
+ _, ((ax_ht, ax_met), (ax_njet, ax_nbjet)) = plt.subplots(2, 2)
|
|
|
|
+ # ft, ttw, ttz, tth = map(lambda rs: hist(rs.SRs), rss)
|
|
|
|
+ ft, ttw, ttz, tth = rss
|
|
|
|
+ rs = {'TTTT': ft,
|
|
|
|
+ 'TTW': ttw,
|
|
|
|
+ 'TTZ': ttz,
|
|
|
|
+ 'TTH': tth}[dataset]
|
|
|
|
+
|
|
|
|
+ def _plot(ax, obs):
|
|
|
|
+ plt.sca(ax)
|
|
|
|
+ h = {'MET': rs.met,
|
|
|
|
+ 'HT': rs.ht,
|
|
|
|
+ 'NJET': rs.njet,
|
|
|
|
+ 'NBJET': rs.nbjet}[obs]
|
|
|
|
+ hist_plot(hist(h), stats=False, label=dataset, xlabel=obs)
|
|
|
|
+
|
|
|
|
+ _plot(ax_ht, 'HT')
|
|
|
|
+ _plot(ax_met, 'MET')
|
|
|
|
+ _plot(ax_njet, 'NJET')
|
|
|
|
+ _plot(ax_nbjet, 'NBJET')
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@decl_plot
|
|
|
|
+def plot_fake_taus(rss):
|
|
|
|
+ _, ((ax_ft, ax_ttw), (ax_ttz, ax_tth)) = plt.subplots(2, 2)
|
|
|
|
+ ft, ttw, ttz, tth = list(map(lambda rs: hist(rs.tau_fakes_v_pt), rss))
|
|
|
|
+
|
|
|
|
+ def _plot(ax, dataset):
|
|
|
|
+ plt.sca(ax)
|
|
|
|
+ h = {'TTTT': ft,
|
|
|
|
+ 'TTW': ttw,
|
|
|
|
+ 'TTZ': ttz,
|
|
|
|
+ 'TTH': tth}[dataset]
|
|
|
|
+ hist_plot(h, stats=False, label=dataset)
|
|
|
|
+
|
|
|
|
+ _plot(ax_ft, 'TTTT')
|
|
|
|
+ _plot(ax_ttw, 'TTW')
|
|
|
|
+ _plot(ax_ttz, 'TTZ')
|
|
|
|
+ _plot(ax_tth, 'TTH')
|
|
|
|
+
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
# First create a ResultSet object which loads all of the objects from output.root
|
|
# First create a ResultSet object which loads all of the objects from output.root
|
|
# into memory and makes them available as attributes
|
|
# into memory and makes them available as attributes
|
|
- # if len(sys.argv) != 2:
|
|
|
|
- # raise ValueError("please supply root file")
|
|
|
|
rss = (ResultSet("ft", 'data/yield_ft.root'),
|
|
rss = (ResultSet("ft", 'data/yield_ft.root'),
|
|
ResultSet("ttw", 'data/yield_ttw.root'),
|
|
ResultSet("ttw", 'data/yield_ttw.root'),
|
|
ResultSet("ttz", 'data/yield_ttz.root'),
|
|
ResultSet("ttz", 'data/yield_ttz.root'),
|
|
@@ -113,25 +174,56 @@ if __name__ == '__main__':
|
|
|
|
|
|
sig_strength_tau = (plot_sig_strength, (rss,), {})
|
|
sig_strength_tau = (plot_sig_strength, (rss,), {})
|
|
sig_strength_notau = (plot_sig_strength, (rss_notau,), {})
|
|
sig_strength_notau = (plot_sig_strength, (rss_notau,), {})
|
|
|
|
+
|
|
|
|
+ ft_lep_multi = (plot_lep_multi, (rss, True, 'TTTT'), {})
|
|
|
|
+ ttw_lep_multi = (plot_lep_multi, (rss, True, 'TTW'), {})
|
|
|
|
+ ttz_lep_multi = (plot_lep_multi, (rss, True, 'TTZ'), {})
|
|
|
|
+ tth_lep_multi = (plot_lep_multi, (rss, True, 'TTH'), {})
|
|
|
|
+
|
|
|
|
+ ft_event_obs = (plot_event_obs, (rss, 'TTTT'), {})
|
|
|
|
+ ttw_event_obs = (plot_event_obs, (rss, 'TTW'), {})
|
|
|
|
+ ttz_event_obs = (plot_event_obs, (rss, 'TTZ'), {})
|
|
|
|
+ tth_event_obs = (plot_event_obs, (rss, 'TTH'), {})
|
|
|
|
+
|
|
|
|
+ fake_taus = (plot_fake_taus, (rss,), {})
|
|
|
|
+
|
|
# Now assemble the plots into figures.
|
|
# Now assemble the plots into figures.
|
|
plots = [
|
|
plots = [
|
|
Plot([[yield_tau]],
|
|
Plot([[yield_tau]],
|
|
'Yield With Tau'),
|
|
'Yield With Tau'),
|
|
Plot([[yield_notau]],
|
|
Plot([[yield_notau]],
|
|
'Yield Without Tau'),
|
|
'Yield Without Tau'),
|
|
- # Plot([[yield_tau_stack]],
|
|
|
|
- # 'Yield With Tau Stacked'),
|
|
|
|
- # Plot([[yield_notau_stack]],
|
|
|
|
- # 'Yield Without Tau Stacked'),
|
|
|
|
|
|
+ Plot([[yield_tau_stack]],
|
|
|
|
+ 'Yield With Tau Stacked'),
|
|
|
|
+ Plot([[yield_notau_stack]],
|
|
|
|
+ 'Yield Without Tau Stacked'),
|
|
Plot([[yield_tau_stack],
|
|
Plot([[yield_tau_stack],
|
|
[yield_notau_stack]],
|
|
[yield_notau_stack]],
|
|
- 'Event Yield, top: with tau, bottom, no tau'),
|
|
|
|
|
|
+ 'Event Yield, top: with tau, bottom: no tau'),
|
|
Plot([[sig_strength_tau],
|
|
Plot([[sig_strength_tau],
|
|
[sig_strength_notau]],
|
|
[sig_strength_notau]],
|
|
- 'Signal Strength')
|
|
|
|
|
|
+ 'Signal Strength'),
|
|
|
|
+ Plot([[ft_lep_multi]],
|
|
|
|
+ 'Lepton Multiplicity - TTTT'),
|
|
|
|
+ Plot([[ttw_lep_multi]],
|
|
|
|
+ 'Lepton Multiplicity - TTW'),
|
|
|
|
+ Plot([[ttz_lep_multi]],
|
|
|
|
+ 'Lepton Multiplicity - TTZ'),
|
|
|
|
+ Plot([[tth_lep_multi]],
|
|
|
|
+ 'Lepton Multiplicity - TTH'),
|
|
|
|
+ Plot([[ft_event_obs]],
|
|
|
|
+ 'TTTT - Event Observables'),
|
|
|
|
+ Plot([[ttw_event_obs]],
|
|
|
|
+ 'TTW - Event Observables'),
|
|
|
|
+ Plot([[ttz_event_obs]],
|
|
|
|
+ 'TTZ - Event Observables'),
|
|
|
|
+ Plot([[tth_event_obs]],
|
|
|
|
+ 'TTH - Event Observables'),
|
|
|
|
+ Plot([[fake_taus]],
|
|
|
|
+ 'Hadronic Tau fake-rate'),
|
|
]
|
|
]
|
|
|
|
|
|
# Finally, render and save the plots and generate the html+bootstrap
|
|
# Finally, render and save the plots and generate the html+bootstrap
|
|
# dashboard to view them
|
|
# dashboard to view them
|
|
render_plots(plots, to_disk=False)
|
|
render_plots(plots, to_disk=False)
|
|
- generate_dashboard(plots, output='yield.html')
|
|
|
|
|
|
+ generate_dashboard(plots, 'TTTT Yields', output='yield2.html', source_file=__file__)
|