Browse Source

Updates to plots

Caleb Fangmeier 6 years ago
parent
commit
54bfe7b8bb
2 changed files with 399 additions and 147 deletions
  1. 398 146
      plotting/eff_plots.py
  2. 1 1
      plotting/filval-python

+ 398 - 146
plotting/eff_plots.py

@@ -7,6 +7,215 @@ from filval.histogram import hist, hist_integral, hist2d, hist2d_percent_contour
 from filval.plotting import (decl_plot, render_plots, hist_plot, hist2d_plot,
                              Plot, generate_dashboard, simple_plot)
 
+matching_cuts = {
+    'extra-narrow-window': [
+        dict(
+            dPhiMaxHighEt=0.025,
+            dPhiMaxHighEtThres=20.0,
+            dPhiMaxLowEtGrad=-0.002,
+            dRzMaxHighEt=9999.0,
+            dRzMaxHighEtThres=0.0,
+            dRzMaxLowEtGrad=0.0,
+        ),
+        dict(
+            dPhiMaxHighEt=0.0015,
+            dPhiMaxHighEtThres=0.0,
+            dPhiMaxLowEtGrad=0.0,
+            dRzMaxHighEt=0.025,
+            dRzMaxHighEtThres=30.0,
+            dRzMaxLowEtGrad=-0.002,
+        ),
+        dict(
+            dPhiMaxHighEt=0.0015,
+            dPhiMaxHighEtThres=0.0,
+            dPhiMaxLowEtGrad=0.0,
+            dRzMaxHighEt=0.025,
+            dRzMaxHighEtThres=30.0,
+            dRzMaxLowEtGrad=-0.002,
+        )
+    ],
+    'narrow-window': [
+        dict(
+            dPhiMaxHighEt=0.05,
+            dPhiMaxHighEtThres=20.0,
+            dPhiMaxLowEtGrad=-0.002,
+            dRzMaxHighEt=9999.0,
+            dRzMaxHighEtThres=0.0,
+            dRzMaxLowEtGrad=0.0,
+        ),
+        dict(
+            dPhiMaxHighEt=0.003,
+            dPhiMaxHighEtThres=0.0,
+            dPhiMaxLowEtGrad=0.0,
+            dRzMaxHighEt=0.05,
+            dRzMaxHighEtThres=30.0,
+            dRzMaxLowEtGrad=-0.002,
+        ),
+        dict(
+            dPhiMaxHighEt=0.003,
+            dPhiMaxHighEtThres=0.0,
+            dPhiMaxLowEtGrad=0.0,
+            dRzMaxHighEt=0.05,
+            dRzMaxHighEtThres=30.0,
+            dRzMaxLowEtGrad=-0.002,
+        )
+    ],
+    'wide-window': [
+        dict(
+            dPhiMaxHighEt=0.10,
+            dPhiMaxHighEtThres=20.0,
+            dPhiMaxLowEtGrad=-0.002,
+            dRzMaxHighEt=9999.0,
+            dRzMaxHighEtThres=0.0,
+            dRzMaxLowEtGrad=0.0,
+        ),
+        dict(
+            dPhiMaxHighEt=0.006,
+            dPhiMaxHighEtThres=0.0,
+            dPhiMaxLowEtGrad=0.0,
+            dRzMaxHighEt=0.10,
+            dRzMaxHighEtThres=30.0,
+            dRzMaxLowEtGrad=-0.002,
+        ),
+        dict(
+            dPhiMaxHighEt=0.006,
+            dPhiMaxHighEtThres=0.0,
+            dPhiMaxLowEtGrad=0.0,
+            dRzMaxHighEt=0.10,
+            dRzMaxHighEtThres=30.0,
+            dRzMaxLowEtGrad=-0.002,
+        )
+    ],
+    'extra-wide-window': [
+        dict(
+            dPhiMaxHighEt=0.15,
+            dPhiMaxHighEtThres=20.0,
+            dPhiMaxLowEtGrad=-0.002,
+            dRzMaxHighEt=9999.0,
+            dRzMaxHighEtThres=0.0,
+            dRzMaxLowEtGrad=0.0,
+        ),
+        dict(
+            dPhiMaxHighEt=0.009,
+            dPhiMaxHighEtThres=0.0,
+            dPhiMaxLowEtGrad=0.0,
+            dRzMaxHighEt=0.15,
+            dRzMaxHighEtThres=30.0,
+            dRzMaxLowEtGrad=-0.002,
+        ),
+        dict(
+            dPhiMaxHighEt=0.009,
+            dPhiMaxHighEtThres=0.0,
+            dPhiMaxLowEtGrad=0.0,
+            dRzMaxHighEt=0.15,
+            dRzMaxHighEtThres=30.0,
+            dRzMaxLowEtGrad=-0.002,
+        )
+    ],
+    'nwp-tight-window': [
+        dict(
+            dPhiMaxHighEt=0.025,
+            dPhiMaxHighEtThres=20.0,
+            dPhiMaxLowEtGrad=-0.002,
+            dRzMaxHighEt=9999.0,
+            dRzMaxHighEtThres=0.0,
+            dRzMaxLowEtGrad=0.0,
+        ),
+        dict(
+            dPhiMaxHighEt=0.005,
+            dPhiMaxHighEtThres=0.0,
+            dPhiMaxLowEtGrad=0.0,
+            dRzMaxHighEt=0.07,
+            dRzMaxHighEtThres=30.0,
+            dRzMaxLowEtGrad=-0.002,
+        ),
+        dict(
+            dPhiMaxHighEt=0.006,
+            dPhiMaxHighEtThres=20.0,
+            dPhiMaxLowEtGrad=-0.0001,
+            dRzMaxHighEt=0.08,
+            dRzMaxHighEtThres=30.0,
+            dRzMaxLowEtGrad=-0.002,
+        )
+    ],
+    'nwp-window': [
+        dict(
+            dPhiMaxHighEt=0.05,
+            dPhiMaxHighEtThres=20.0,
+            dPhiMaxLowEtGrad=-0.002,
+            dRzMaxHighEt=9999.0,
+            dRzMaxHighEtThres=0.0,
+            dRzMaxLowEtGrad=0.0,
+        ),
+        dict(
+            dPhiMaxHighEt=0.005,
+            dPhiMaxHighEtThres=0.0,
+            dPhiMaxLowEtGrad=0.0,
+            dRzMaxHighEt=0.07,
+            dRzMaxHighEtThres=30.0,
+            dRzMaxLowEtGrad=-0.002,
+        ),
+        dict(
+            dPhiMaxHighEt=0.006,
+            dPhiMaxHighEtThres=20.0,
+            dPhiMaxLowEtGrad=-0.0001,
+            dRzMaxHighEt=0.08,
+            dRzMaxHighEtThres=30.0,
+            dRzMaxLowEtGrad=-0.002,
+        )
+    ],
+    'nwp-eta-breakdown': [
+        dict(
+            dPhiMaxHighEt=[0.05, 0.07, 0.06],
+            dPhiMaxHighEtThres=[25.0, 25.0, 25.0],
+            dPhiMaxLowEtGrad=[-0.002, -0.006, -0.002],
+            dRzMaxHighEt=[9999.0, 9999.0, 9999.0],
+            dRzMaxHighEtThres=[0.0, 0.0, 0.0],
+            dRzMaxLowEtGrad=[0.0, 0.0, 0.0],
+            etaBins = [1.1, 1.8]
+        ),
+        dict(
+            dPhiMaxHighEt=[0.0035, 0.006, 0.007],
+            dPhiMaxHighEtThres=[0.0, 0.0, 0.0],
+            dPhiMaxLowEtGrad=[0.0, 0.0, 0.0],
+            dRzMaxHighEt=[0.045, 0.08, 0.045],
+            dRzMaxHighEtThres=[30.0, 30.0, 30.0],
+            dRzMaxLowEtGrad=[-0.002, -0.006, -0.002],
+            etaBins=[1.4, 2.3]
+        ),
+        dict(
+            dPhiMaxHighEt=[0.006, 0.007, 0.007],
+            dPhiMaxHighEtThres=[0.0, 20, 20],
+            dPhiMaxLowEtGrad=[0.0, -0.0002, -0.0002],
+            dRzMaxHighEt=[0.04, 0.10, 0.60],
+            dRzMaxHighEtThres=[25.0, 25.0, 25.0],
+            dRzMaxLowEtGrad=[-0.007, -0.007, -0.007],
+            etaBins=[1.0, 2.0]
+        )
+    ],
+}
+
+
+def calc_window(et, eta, hit, variable, cut_sel):
+    idx = min(hit-1, 2)
+    cuts = matching_cuts[cut_sel][idx]
+    if 'etaBins' in cuts:
+        for eta_idx, bin_high in enumerate(cuts['etaBins']):
+            if eta < bin_high:
+                high_et = cuts[f'{variable}MaxHighEt'][eta_idx]
+                high_et_thres = cuts[f'{variable}MaxHighEtThres'][eta_idx]
+                low_et_grad = cuts[f'{variable}MaxLowEtGrad'][eta_idx]
+                break
+        else:  # highest bin
+            high_et = cuts[f'{variable}MaxHighEt'][-1]
+            high_et_thres = cuts[f'{variable}MaxHighEtThres'][-1]
+            low_et_grad = cuts[f'{variable}MaxLowEtGrad'][-1]
+    else:
+        high_et = cuts[f'{variable}MaxHighEt']
+        high_et_thres = cuts[f'{variable}MaxHighEtThres']
+        low_et_grad = cuts[f'{variable}MaxLowEtGrad']
+    return high_et + min(0, et-high_et_thres)*low_et_grad
+
 
 def center_text(x, y, txt, **kwargs):
     plt.text(x, y, txt,
@@ -22,124 +231,44 @@ def hist_integral_ratio(num, den):
     error = np.sqrt(den_int) / den_int  # TODO: Check this definition of error
     return ratio, error
 
+
 @decl_plot
-def plot_residuals(rs, layer, hit, variable, subdet, plot_cuts=True, cut_sel='tight'):
-    matching_cuts = {
-        'extra-narrow': [
-            dict(
-                dPhiMaxHighEt=0.025,
-                dPhiMaxHighEtThres=20.0,
-                dPhiMaxLowEtGrad=-0.002,
-                dRzMaxHighEt=9999.0,
-                dRzMaxHighEtThres=0.0,
-                dRzMaxLowEtGrad=0.0,
-            ),
-            dict(
-                dPhiMaxHighEt=0.0015,
-                dPhiMaxHighEtThres=0.0,
-                dPhiMaxLowEtGrad=0.0,
-                dRzMaxHighEt=0.025,
-                dRzMaxHighEtThres=30.0,
-                dRzMaxLowEtGrad=-0.002,
-            ),
-            dict(
-                dPhiMaxHighEt=0.0015,
-                dPhiMaxHighEtThres=0.0,
-                dPhiMaxLowEtGrad=0.0,
-                dRzMaxHighEt=0.025,
-                dRzMaxHighEtThres=30.0,
-                dRzMaxLowEtGrad=-0.002,
-            )
-        ],
-        'narrow': [
-            dict(
-                dPhiMaxHighEt=0.05,
-                dPhiMaxHighEtThres=20.0,
-                dPhiMaxLowEtGrad=-0.002,
-                dRzMaxHighEt=9999.0,
-                dRzMaxHighEtThres=0.0,
-                dRzMaxLowEtGrad=0.0,
-            ),
-            dict(
-                dPhiMaxHighEt=0.003,
-                dPhiMaxHighEtThres=0.0,
-                dPhiMaxLowEtGrad=0.0,
-                dRzMaxHighEt=0.05,
-                dRzMaxHighEtThres=30.0,
-                dRzMaxLowEtGrad=-0.002,
-            ),
-            dict(
-                dPhiMaxHighEt=0.003,
-                dPhiMaxHighEtThres=0.0,
-                dPhiMaxLowEtGrad=0.0,
-                dRzMaxHighEt=0.05,
-                dRzMaxHighEtThres=30.0,
-                dRzMaxLowEtGrad=-0.002,
-            )
-        ],
-        'wide': [
-            dict(
-                dPhiMaxHighEt=0.10,
-                dPhiMaxHighEtThres=20.0,
-                dPhiMaxLowEtGrad=-0.002,
-                dRzMaxHighEt=9999.0,
-                dRzMaxHighEtThres=0.0,
-                dRzMaxLowEtGrad=0.0,
-            ),
-            dict(
-                dPhiMaxHighEt=0.006,
-                dPhiMaxHighEtThres=0.0,
-                dPhiMaxLowEtGrad=0.0,
-                dRzMaxHighEt=0.10,
-                dRzMaxHighEtThres=30.0,
-                dRzMaxLowEtGrad=-0.002,
-            ),
-            dict(
-                dPhiMaxHighEt=0.006,
-                dPhiMaxHighEtThres=0.0,
-                dPhiMaxLowEtGrad=0.0,
-                dRzMaxHighEt=0.10,
-                dRzMaxHighEtThres=30.0,
-                dRzMaxLowEtGrad=-0.002,
-            )
-        ],
-        'extra-wide': [
-            dict(
-                dPhiMaxHighEt=0.15,
-                dPhiMaxHighEtThres=20.0,
-                dPhiMaxLowEtGrad=-0.002,
-                dRzMaxHighEt=9999.0,
-                dRzMaxHighEtThres=0.0,
-                dRzMaxLowEtGrad=0.0,
-            ),
-            dict(
-                dPhiMaxHighEt=0.009,
-                dPhiMaxHighEtThres=0.0,
-                dPhiMaxLowEtGrad=0.0,
-                dRzMaxHighEt=0.15,
-                dRzMaxHighEtThres=30.0,
-                dRzMaxLowEtGrad=-0.002,
-            ),
-            dict(
-                dPhiMaxHighEt=0.009,
-                dPhiMaxHighEtThres=0.0,
-                dPhiMaxLowEtGrad=0.0,
-                dRzMaxHighEt=0.15,
-                dRzMaxHighEtThres=30.0,
-                dRzMaxLowEtGrad=-0.002,
-            )
-        ]
-    }
-
-    h = hist2d(getattr(rs, f'{variable}_{subdet}_L{layer}_H{hit}_v_Et'))
-
-    def calc_window(et):
-        idx = min(hit-1, 2)
-        cuts = matching_cuts[cut_sel]
-        high_et = cuts[idx][f'{variable}MaxHighEt']
-        high_et_thres = cuts[idx][f'{variable}MaxHighEtThres']
-        low_et_grad = cuts[idx][f'{variable}MaxLowEtGrad']
-        return high_et + min(0, et-high_et_thres)*low_et_grad
+def plot_residuals(rs, layer, hit, variable, subdet, cut_sel=None):
+
+    h_real = hist2d(getattr(rs, f'{variable}_{subdet}_L{layer}_H{hit}_v_Et'))
+    h_fake = hist2d(getattr(rs, f'{variable}_{subdet}_L{layer}_H{hit}_v_Et_fake'))
+
+
+    def do_plot(h):
+        hist2d_plot(h, colorbar=True)
+
+        xs, ys = hist2d_percent_contour(h, .90, 'x')
+        plt.plot(xs, ys, color='green', label='90\% contour')
+        xs, ys = hist2d_percent_contour(h, .995, 'x')
+        plt.plot(xs, ys, color='darkgreen', label='99.5\% contour')
+
+        if cut_sel:
+            ets = h[3][:, 0]
+            cuts = [calc_window(et, 0, hit, variable, cut_sel) for et in ets]
+            plt.plot(cuts, ets, color='red', label='Cut Value')
+        plt.xlabel({'dPhi': r'$\delta \phi$ (rads)',
+                    'dRz': r'$\delta R/z$ (cm)'}[variable])
+
+    plt.sca(plt.subplot(1, 2, 1))
+    do_plot(h_real)
+    plt.title('Truth-Matched Seeds')
+    plt.ylabel('$E_T$ (GeV)')
+
+    plt.sca(plt.subplot(1, 2, 2))
+    do_plot(h_fake)
+    plt.title('Not Truth-Matched Seeds')
+    plt.legend(loc='upper right')
+
+
+@decl_plot
+def plot_residuals_eta(rs, hit, variable):
+
+    h = hist2d(getattr(rs, f'{variable}_residuals_v_eta_H{hit}'))
 
     hist2d_plot(h, colorbar=True)
 
@@ -148,15 +277,9 @@ def plot_residuals(rs, layer, hit, variable, subdet, plot_cuts=True, cut_sel='ti
     xs, ys = hist2d_percent_contour(h, .995, 'x')
     plt.plot(xs, ys, color='darkgreen', label='99.5\% contour')
 
-    if plot_cuts:
-        ets = h[3][:, 0]
-        cuts = [calc_window(et) for et in ets]
-        plt.plot(cuts, ets, color='red', label='Cut Value')
-        plt.legend(loc='upper right')
-
     plt.xlabel({'dPhi': r'$\delta \phi$ (rads)',
                 'dRz': r'$\delta R/z$ (cm)'}[variable])
-    plt.ylabel('$E_T$ (GeV)')
+    plt.ylabel(r'$\eta$ (GeV)')
 
 
 @decl_plot
@@ -310,7 +433,7 @@ def plot_hit_vs_layer(rs, region):
 
 
 def single_cut_plots(cut_sel):
-    rs = ResultSet(f'{cut_sel}-window', f'../hists/{cut_sel}-window.root')
+    rs = ResultSet(f'{cut_sel}', f'../hists/{cut_sel}.root')
 
     seed_eff = plot_seed_eff, (rs,)
     tracking_eff = plot_tracking_eff, (rs,)
@@ -324,15 +447,23 @@ def single_cut_plots(cut_sel):
     BPIX_residuals_L2_H2_dPhi = plot_residuals, (rs, 2, 2, 'dPhi', 'BPIX'), dict(cut_sel=cut_sel)
     BPIX_residuals_L3_H3_dPhi = plot_residuals, (rs, 3, 3, 'dPhi', 'BPIX'), dict(cut_sel=cut_sel)
 
-    BPIX_residuals_L1_H1_dRz = plot_residuals, (rs, 1, 1, 'dRz', 'BPIX'), {'plot_cuts': False}
+    BPIX_residuals_L1_H1_dRz = plot_residuals, (rs, 1, 1, 'dRz', 'BPIX')
     BPIX_residuals_L2_H2_dRz = plot_residuals, (rs, 2, 2, 'dRz', 'BPIX'), dict(cut_sel=cut_sel)
     BPIX_residuals_L3_H3_dRz = plot_residuals, (rs, 3, 3, 'dRz', 'BPIX'), dict(cut_sel=cut_sel)
 
+    BPIX_residuals_L2_H1_dPhi = plot_residuals, (rs, 2, 1, 'dPhi', 'BPIX'), dict(cut_sel=cut_sel)
+    BPIX_residuals_L3_H2_dPhi = plot_residuals, (rs, 3, 2, 'dPhi', 'BPIX'), dict(cut_sel=cut_sel)
+    BPIX_residuals_L4_H3_dPhi = plot_residuals, (rs, 4, 3, 'dPhi', 'BPIX'), dict(cut_sel=cut_sel)
+
+    BPIX_residuals_L2_H1_dRz = plot_residuals, (rs, 2, 1, 'dRz', 'BPIX')
+    BPIX_residuals_L3_H2_dRz = plot_residuals, (rs, 3, 2, 'dRz', 'BPIX'), dict(cut_sel=cut_sel)
+    BPIX_residuals_L4_H3_dRz = plot_residuals, (rs, 4, 3, 'dRz', 'BPIX'), dict(cut_sel=cut_sel)
+
     FPIX_residuals_L1_H1_dPhi = plot_residuals, (rs, 1, 1, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
     FPIX_residuals_L2_H2_dPhi = plot_residuals, (rs, 2, 2, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
     FPIX_residuals_L3_H3_dPhi = plot_residuals, (rs, 3, 3, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
 
-    FPIX_residuals_L1_H1_dRz = plot_residuals, (rs, 1, 1, 'dRz', 'FPIX'), {'plot_cuts': False}
+    FPIX_residuals_L1_H1_dRz = plot_residuals, (rs, 1, 1, 'dRz', 'FPIX')
     FPIX_residuals_L2_H2_dRz = plot_residuals, (rs, 2, 2, 'dRz', 'FPIX'), dict(cut_sel=cut_sel)
     FPIX_residuals_L3_H3_dRz = plot_residuals, (rs, 3, 3, 'dRz', 'FPIX'), dict(cut_sel=cut_sel)
 
@@ -347,18 +478,33 @@ def single_cut_plots(cut_sel):
     hit_vs_layer_barrel = plot_hit_vs_layer, (rs, 'barrel')
     hit_vs_layer_forward = plot_hit_vs_layer, (rs, 'forward')
 
+    dRz_residuals_v_eta_H1 = plot_residuals_eta, (rs, 1, 'dRz')
+    dRz_residuals_v_eta_H2 = plot_residuals_eta, (rs, 2, 'dRz')
+    dRz_residuals_v_eta_H3 = plot_residuals_eta, (rs, 3, 'dRz')
+
+    dPhi_residuals_v_eta_H1 = plot_residuals_eta, (rs, 1, 'dPhi')
+    dPhi_residuals_v_eta_H2 = plot_residuals_eta, (rs, 2, 'dPhi')
+    dPhi_residuals_v_eta_H3 = plot_residuals_eta, (rs, 3, 'dPhi')
+
     plots = [
         Plot(BPIX_residuals_L1_H1_dPhi, 'Phi Residuals Layer 1 Hit 1 - BPIX'),
         Plot(BPIX_residuals_L2_H2_dPhi, 'Phi Residuals Layer 2 Hit 2 - BPIX'),
         Plot(BPIX_residuals_L3_H3_dPhi, 'Phi Residuals Layer 3 Hit 3 - BPIX'),
-        Plot(BPIX_residuals_L1_H1_dRz, 'dZ Residuals Layer 1 Hit 1 w/o cuts - BPIX'),
+        Plot(BPIX_residuals_L1_H1_dRz, 'dZ Residuals Layer 1 Hit 1 without cuts - BPIX'),
         Plot(BPIX_residuals_L2_H2_dRz, 'dZ Residuals Layer 2 Hit 2 - BPIX'),
         Plot(BPIX_residuals_L3_H3_dRz, 'dZ Residuals Layer 3 Hit 3 - BPIX'),
 
+        Plot(BPIX_residuals_L2_H1_dPhi, 'Phi Residuals Layer 2 Hit 1 - BPIX'),
+        Plot(BPIX_residuals_L3_H2_dPhi, 'Phi Residuals Layer 3 Hit 2 - BPIX'),
+        Plot(BPIX_residuals_L4_H3_dPhi, 'Phi Residuals Layer 4 Hit 3 - BPIX'),
+        Plot(BPIX_residuals_L2_H1_dRz, 'dZ Residuals Layer 2 Hit 1 without cuts - BPIX'),
+        Plot(BPIX_residuals_L3_H2_dRz, 'dZ Residuals Layer 3 Hit 2 - BPIX'),
+        Plot(BPIX_residuals_L4_H3_dRz, 'dZ Residuals Layer 4 Hit 3 - BPIX'),
+
         Plot(FPIX_residuals_L1_H1_dPhi, 'Phi Residuals Layer 1 Hit 1 - FPIX'),
         Plot(FPIX_residuals_L2_H2_dPhi, 'Phi Residuals Layer 2 Hit 2 - FPIX'),
         Plot(FPIX_residuals_L3_H3_dPhi, 'Phi Residuals Layer 3 Hit 3 - FPIX'),
-        Plot(FPIX_residuals_L1_H1_dRz, 'dR Residuals Layer 1 Hit 1 w/o cuts - FPIX'),
+        Plot(FPIX_residuals_L1_H1_dRz, 'dR Residuals Layer 1 Hit 1 without cuts - FPIX'),
         Plot(FPIX_residuals_L2_H2_dRz, 'dR Residuals Layer 2 Hit 2 - FPIX'),
         Plot(FPIX_residuals_L3_H3_dRz, 'dR Residuals Layer 3 Hit 3 - FPIX'),
 
@@ -377,13 +523,52 @@ def single_cut_plots(cut_sel):
         Plot(track_pur, 'GSF Track Purity'),
         Plot(track_pur_seed_match , 'GSF Track Purity (Seed Truth Match)'),
         simple_plot(rs.gsf_tracks_nmatch_sim_tracks, log='y'),
+        Plot(dRz_residuals_v_eta_H1, 'dRz Hit 1 Residuals v eta'),
+        Plot(dRz_residuals_v_eta_H2, 'dRz Hit 2 Residuals v eta'),
+        Plot(dRz_residuals_v_eta_H3, 'dRz Hit 3 Residuals v eta'),
+        Plot(dPhi_residuals_v_eta_H1, 'dPhi Hit 1 Residuals v eta'),
+        Plot(dPhi_residuals_v_eta_H2, 'dPhi Hit 2 Residuals v eta'),
+        Plot(dPhi_residuals_v_eta_H3, 'dPhi Hit 3 Residuals v eta'),
     ]
 
-    render_plots(plots, to_disk=False)
-    generate_dashboard(plots, 'Seeding Efficiency',
-                       output=f'{rs.sample_name}.html',
-                       source=__file__,
-                       config=rs.config)
+    render_plots(plots, directory='output/figures/'+rs.sample_name, to_disk=to_disk)
+    if not to_disk:
+        generate_dashboard(plots, 'Seeding Efficiency',
+                           output=f'{rs.sample_name}.html',
+                           source=__file__,
+                           config=rs.config)
+
+
+def eta_region_plots(cut_sel):
+    rs = ResultSet(f'{cut_sel}', f'../hists/{cut_sel}.root')
+
+    @decl_plot
+    def residual_in_region(var, hit):
+        for region in (1, 2, 3):
+            h = hist2d(getattr(rs, f'{var}_residuals_H{hit}_R{region}'))
+
+            xs, ys = hist2d_percent_contour(h, .99, 'x')
+            plt.plot(xs, ys, label=f'99\%, Region {region}')
+        plt.legend()
+
+        plt.xlabel({'dPhi': r'$\delta \phi$ (rads)',
+                    'dRz': r'$\delta R/z$ (cm)'}[var])
+        plt.ylabel('$E_T$ (GeV)')
+
+    plots = []
+    for hit in (1, 2, 3):
+        plt_tup = residual_in_region, ('dPhi', hit)
+        plots.append(Plot(plt_tup, f'dPhi residuals, hit {hit}'))
+
+        plt_tup = residual_in_region, ('dRz', hit)
+        plots.append(Plot(plt_tup, f'dRz residuals, hit {hit}'))
+
+    render_plots(plots, directory='output/figures/'+rs.sample_name, to_disk=to_disk)
+    if not to_disk:
+        generate_dashboard(plots, 'Breakdown by Eta Region',
+                           output=f'{rs.sample_name}-eta-regions.html',
+                           source=__file__,
+                           config=rs.config)
 
 
 @decl_plot
@@ -395,7 +580,10 @@ def plot_seed_roc_curve(rss):
     for rs in rss:
         eff, eff_err = get_num_den(rs, 'seed_eff_v_phi')
         pur, pur_err = get_num_den(rs, 'seed_pur_v_phi')
-        plt.errorbar([pur], [eff], xerr=[pur_err], yerr=[eff_err], label=rs.sample_name)
+        if rs.sample_name == 'old-seeding':
+            plt.errorbar([pur], [eff], xerr=[pur_err], yerr=[eff_err], label=rs.sample_name, color='k', marker='o')
+        else:
+            plt.errorbar([pur], [eff], xerr=[pur_err], yerr=[eff_err], label=rs.sample_name[:-7], marker='o')
     center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
     plt.axis('equal')
     plt.xlim((0.8, 1.0))
@@ -477,7 +665,10 @@ def plot_tracking_roc_curve(rss, ext=''):
     for rs in rss:
         eff, eff_err = get_num_den(rs, 'tracking_eff_v_phi')
         pur, pur_err = get_num_den(rs, 'tracking_pur_v_phi')
-        plt.errorbar([pur], [eff], xerr=[pur_err], yerr=[eff_err], label=rs.sample_name)
+        if rs.sample_name == 'old-seeding':
+            plt.errorbar([pur], [eff], xerr=[pur_err], yerr=[eff_err], label=rs.sample_name, color='k', marker='o')
+        else:
+            plt.errorbar([pur], [eff], xerr=[pur_err], yerr=[eff_err], label=rs.sample_name[:-7], marker='o')
     center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
     plt.axis('equal')
     plt.xlim((0.8, 1.0))
@@ -557,8 +748,43 @@ def plot_ecal_rel_res(rss):
     plt.xlabel(r"ECAL $E_T$ relative error")
     plt.legend()
 
+
+@decl_plot
+def plot_res_contour(rss, hit_number, var, layers):
+    from itertools import chain
+    _, axs = plt.subplots(2, 3)
+    axs_all = list(chain(*axs))
+
+    def do_plot(ax, rs):
+        plt.sca(ax)
+        plt.title(rs.sample_name)
+        h = None
+        for layer in layers:
+            subdet = 'BPIX' if layer[0]=='B' else 'FPIX'
+            h = hist2d(getattr(rs, f'{var}_{subdet}_L{layer[1]}_H{hit_number}_v_Et'))
+            pass
+            xs, ys = hist2d_percent_contour(h, .99, 'x')
+            plt.plot(xs, ys, label=f'{subdet} - L{layer[1]}')
+
+        ets = h[3][:, 0]
+        cuts = [calc_window(et, 0, hit_number, var, rs.sample_name) for et in ets]
+        plt.plot(cuts, ets, color='red', label='Cut Value')
+
+    max_x = 0
+    for ax, rs in zip(axs_all, rss):
+        do_plot(ax, rs)
+        _, x_up = ax.get_xlim()
+        max_x = max((max_x, x_up))
+
+    plt.sca(axs[0][-1])
+    plt.legend(loc='best')
+
+    for ax in axs_all:
+        ax.set_xlim((None, max_x))
+
+
 def all_cut_plots(cuts):
-    rss = [ResultSet(f'{cut_sel}-window', f'../hists/{cut_sel}-window.root') for cut_sel in cuts]
+    rss = [ResultSet(f'{cut_sel}', f'../hists/{cut_sel}.root') for cut_sel in cuts]
 
     tracking_roc_curve = plot_tracking_roc_curve, (rss,)
     tracking_eff_all = plot_tracking_eff_all, (rss,)
@@ -573,6 +799,13 @@ def all_cut_plots(cuts):
 
     ecal_rel_res = plot_ecal_rel_res, (rss,)
 
+    res_contour_dphi_H1 = plot_res_contour, (rss, 1, 'dPhi', ['B1', 'B2', 'F1'])
+    res_contour_dphi_H2 = plot_res_contour, (rss, 2, 'dPhi', ['B2', 'B3', 'B4', 'F1', 'F2'])
+    res_contour_dRz_H2 = plot_res_contour, (rss, 2, 'dRz', ['B2', 'B3', 'B4', 'F1', 'F2'])
+
+    res_contour_dphi_H3 = plot_res_contour, (rss, 3, 'dPhi', ['B3', 'B4''F1', 'F2', 'F3'])
+    res_contour_dRz_H3 = plot_res_contour, (rss, 3, 'dRz', ['B3', 'B4''F1', 'F2', 'F3'])
+
     plots = [
         Plot(tracking_roc_curve, 'Tracking ROC Curve'),
         Plot(tracking_eff_all, 'Tracking Efficiency'),
@@ -584,17 +817,36 @@ def all_cut_plots(cuts):
         Plot(seed_eff_all, 'ECAL-Driven Seeding Efficiency'),
         Plot(seed_pur_all, 'ECAL-Driven Seeding Purity'),
         Plot(ecal_rel_res, 'ECAL ET Relative Resolution'),
+
+        Plot(res_contour_dphi_H1, 'dPhi Residual 99% Contours - Hit 1'),
+        Plot(res_contour_dphi_H2, 'dPhi Residual 99% Contours - Hit 2'),
+        Plot(res_contour_dRz_H2, 'dRz  Residual 99% Contours - Hit 2'),
+        Plot(res_contour_dphi_H3, 'dPhi Residual 99% Contours - Hit 3'),
+        Plot(res_contour_dRz_H3, 'dRz  Residual 99% Contours - Hit 3'),
     ]
 
-    render_plots(plots, to_disk=False)
-    generate_dashboard(plots, 'Comparisons',
-                       output='comparisons.html',
-                       source=__file__,
-                       config=rss[0].config)
+    render_plots(plots, to_disk=to_disk)
+    if not to_disk:
+        generate_dashboard(plots, 'Comparisons',
+                           output='comparisons.html',
+                           source=__file__,
+                           config=rss[0].config)
 
 
 if __name__ == '__main__':
-    cuts = ['extra-narrow', 'narrow', 'wide', 'extra-wide']
-    all_cut_plots(cuts)
-    for cut in cuts:
-        single_cut_plots(cut)
+    to_disk = False
+    all_cuts = [
+        'extra-narrow-window',
+        'narrow-window',
+        'wide-window',
+        'extra-wide-window',
+        'nwp-window',
+        'nwp-tight-window',
+        'nwp-eta-breakdown',
+    ]
+    all_cut_plots(all_cuts + ['old-seeding'])
+    single_cut_plots('extra-wide-window')
+    # for cut in all_cuts:
+    #     single_cut_plots(cut)
+
+    # eta_region_plots('extra-wide-window')

+ 1 - 1
plotting/filval-python

@@ -1 +1 @@
-Subproject commit 0cf8a45d1318c5fc3c4f9c1508317ad36d3ef420
+Subproject commit a181009b251c6b28d21a65c6d480c116e72384e1