Bläddra i källkod

Updates to include event observable plots

Caleb Fangmeier 6 år sedan
förälder
incheckning
561e378774
2 ändrade filer med 47 tillägg och 25 borttagningar
  1. 1 1
      filval
  2. 46 24
      yields.py

+ 1 - 1
filval

@@ -1 +1 @@
-Subproject commit 0bb6b949edecb235d3b7932b59c098b1748a9e9b
+Subproject commit 7824f845e477f6b37413bed3bfcc2df78eb84d51

+ 46 - 24
yields.py

@@ -3,7 +3,7 @@ import numpy as np
 import matplotlib.pyplot as plt
 
 from filval.result_set import ResultSet
-from filval.histogram_utils import hist, hist_add, hist_normalize
+from filval.histogram_utils import hist, hist_add, hist_normalize, hist_scale
 from filval.plotter import (decl_plot, render_plots, hist_plot, hist_plot_stack, Plot, generate_dashboard)
 
 
@@ -66,16 +66,11 @@ def plot_yield_stack(rss):
 
 
 @decl_plot
-def plot_lep_multi(rss, use_mc_reweight, dataset):
+def plot_lep_multi(rss, 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))
+    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)
@@ -111,7 +106,7 @@ def plot_event_obs(rss, dataset):
     r"""
 
     """
-    _, ((ax_ht, ax_met), (ax_njet, ax_nbjet)) = plt.subplots(2, 2)
+    _, ((ax_njet, ax_nbjet), (ax_ht, ax_met)) = plt.subplots(2, 2)
     # ft, ttw, ttz, tth = map(lambda rs: hist(rs.SRs), rss)
     ft, ttw, ttz, tth = rss
     rs = {'TTTT': ft,
@@ -121,17 +116,40 @@ def plot_event_obs(rss, dataset):
 
     def _plot(ax, obs):
         plt.sca(ax)
-        h = {'MET': rs.met,
-             'HT': rs.ht,
-             'NJET': rs.njet,
-             'NBJET': rs.nbjet}[obs]
+        h = {'MET': rs.met_in_SR,
+             'HT': rs.ht_in_SR,
+             'NJET': rs.njet_in_SR,
+             'NBJET': rs.nbjet_in_SR}[obs]
         hist_plot(hist(h), stats=False, label=dataset, xlabel=obs)
 
+    _plot(ax_njet, 'NJET')
+    _plot(ax_nbjet, 'NBJET')
     _plot(ax_ht, 'HT')
     _plot(ax_met, 'MET')
+
+@decl_plot
+def plot_event_obs_stack(rss):
+    r"""
+
+    """
+    _, ((ax_njet, ax_nbjet), (ax_ht, ax_met)) = plt.subplots(2, 2)
+
+    def _plot(ax, obs):
+        plt.sca(ax)
+        attr = {'MET': 'met_in_SR',
+                'HT': 'ht_in_SR',
+                'NJET': 'njet_in_SR',
+                'NBJET': 'nbjet_in_SR'}[obs]
+        ft, ttw, ttz, tth = map(lambda rs: hist(getattr(rs, attr)), rss)
+        hist_plot_stack([ttw, ttz, tth], labels=["TTW", "TTZ", "TTH"])
+        hist_plot(hist_scale(ft, 5), label="TTTT (x5)", color='k')
+        plt.xlabel(obs)
+
     _plot(ax_njet, 'NJET')
     _plot(ax_nbjet, 'NBJET')
-
+    plt.legend()
+    _plot(ax_ht, 'HT')
+    _plot(ax_met, 'MET')
 
 @decl_plot
 def plot_tau_purity(rss):
@@ -177,15 +195,17 @@ if __name__ == '__main__':
     sig_strength_tau = (plot_sig_strength, (rss,), {})
     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_lep_multi = (plot_lep_multi, (rss, 'TTTT'), {})
+    ttw_lep_multi = (plot_lep_multi, (rss, 'TTW'), {})
+    ttz_lep_multi = (plot_lep_multi, (rss, 'TTZ'), {})
+    tth_lep_multi = (plot_lep_multi, (rss, 'TTH'), {})
+
+    ft_event_obs = (plot_event_obs, (rss_notau, 'TTTT'), {})
+    ttw_event_obs = (plot_event_obs, (rss_notau, 'TTW'), {})
+    ttz_event_obs = (plot_event_obs, (rss_notau, 'TTZ'), {})
+    tth_event_obs = (plot_event_obs, (rss_notau, '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'), {})
+    event_obs_stack = (plot_event_obs_stack, (rss_notau,), {})
 
     tau_purity = (plot_tau_purity, (rss,), {})
 
@@ -221,6 +241,8 @@ if __name__ == '__main__':
              'TTZ - Event Observables'),
         Plot([[tth_event_obs]],
              'TTH - Event Observables'),
+        Plot([[event_obs_stack]],
+             'Event Observables'),
         Plot([[tau_purity]],
              'Tau Purity'),
     ]