瀏覽代碼

Additional yield plots, adds src code to generated dashboard

Caleb Fangmeier 6 年之前
父節點
當前提交
b75dff7474
共有 3 個文件被更改,包括 163 次插入48 次删除
  1. 1 1
      filval
  2. 24 1
      templates/dashboard.htm
  3. 138 46
      yields.py

+ 1 - 1
filval

@@ -1 +1 @@
-Subproject commit 7206f9c742acf25fa94e351679781b5d67117fa1
+Subproject commit 0bb6b949edecb235d3b7932b59c098b1748a9e9b

+ 24 - 1
templates/dashboard.htm

@@ -1,13 +1,19 @@
 <!DOCTYPE html>
 <html lang="en">
 <head>
-  <title>TTTT Dashboard</title>
+  <title>{{ title }}</title>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=2">
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
 
+  <script src="https://tttt.fangmeier.tech/hl/shCore.js"         type="text/javascript"></script>
+  <script src="https://tttt.fangmeier.tech/hl/shBrushPython.js" type="text/javascript"></script>
+  <link href="https://tttt.fangmeier.tech/hl/shCore.css"          rel="stylesheet" type="text/css" />
+  <link href="https://tttt.fangmeier.tech/hl/shThemeDefault.css"  rel="stylesheet" type="text/css" />
+  <script src="https://tttt.fangmeier.tech/hl/shAutoloader.js" type="text/javascript"></script>
+
 <script type="text/x-mathjax-config">
 MathJax.Hub.Config({
   config: ["MMLorHTML.js"],
@@ -68,6 +74,22 @@ MathJax.Hub.Config({
   {% endfor %}
   </div>
 {% endfor %}
+  <div class="row">
+    <div class="col-12-lg">
+      <div class="panel-group" id="accordion">
+        <div class="panel-heading">
+          <h4 class="panel-title" style="text-align:center">
+            <button data-toggle="collapse" data-parent="#accordion" class="btn btn-default" href="#collapseSrc">Figure Source Code</button>
+          </h4>
+        </div>
+        <div id="collapseSrc" class="panel-collapse collapse">
+          <div class="panel-body">
+<script type="syntaxhighlighter" class="brush: python"><![CDATA[ {{ source|safe}} ]]></script>
+          </div>
+        </div>
+      </div>
+    </div>
+  </div>
 </div>
 <div id="myModal" class="modal fade" tabindex="-1" role="dialog">
   <div class="modal-dialog modal-lg">
@@ -96,5 +118,6 @@ $('.thumbnail').click(function(){
     $($(this).parents('div').html()).appendTo('.modal-body');
     $('#myModal').modal({show:true});
 });
+SyntaxHighlighter.all()
 </script>
 </html>

+ 138 - 46
yields.py

@@ -3,37 +3,8 @@ import numpy as np
 import matplotlib.pyplot as plt
 
 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
@@ -46,18 +17,36 @@ def plot_yield_grid(rss):
     """
     _, ((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 = map(lambda rs: hist(rs.SRs), rss[:2])
     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)
-    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)
-    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')
 
 
+
 @decl_plot
 def plot_yield_stack(rss):
     r"""## Event Yield - Stacked
@@ -71,11 +60,40 @@ def plot_yield_stack(rss):
     ft = ft[0]*10, ft[1], ft[2]
     hist_plot(ft, label='TTTT (x10)', stats=False, color='k')
 
-    plt.ylim((0, 160))
+    plt.ylim((0, 60))
     plt.xlabel('Signal Region')
     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
 def plot_sig_strength(rss):
     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])
     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__':
     # First create a ResultSet object which loads all of the objects from output.root
     # 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'),
            ResultSet("ttw", 'data/yield_ttw.root'),
            ResultSet("ttz", 'data/yield_ttz.root'),
@@ -113,25 +174,56 @@ 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_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.
     plots = [
         Plot([[yield_tau]],
              'Yield With Tau'),
         Plot([[yield_notau]],
              '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],
               [yield_notau_stack]],
-             'Event Yield, top: with tau, bottom, no tau'),
+             'Event Yield, top: with tau, bottom: no tau'),
         Plot([[sig_strength_tau],
               [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
     # dashboard to view them
     render_plots(plots, to_disk=False)
-    generate_dashboard(plots, output='yield.html')
+    generate_dashboard(plots, 'TTTT Yields', output='yield2.html', source_file=__file__)