Selaa lähdekoodia

New plots for presentation and update to filval

Caleb Fangmeier 7 vuotta sitten
vanhempi
commit
a2b7e61b39
2 muutettua tiedostoa jossa 96 lisäystä ja 61 poistoa
  1. 95 60
      analysis/plots.py
  2. 1 1
      filval

+ 95 - 60
analysis/plots.py

@@ -4,12 +4,12 @@ import sys
 import matplotlib.pyplot as plt
 
 from filval.result_set import ResultSet
-from filval.histogram_utils import hist, hist2d, hist_slice
+from filval.histogram_utils import hist, hist2d, hist_slice, hist_add
 from filval.plotter import (decl_plot, save_plots, hist_plot, hist2d_plot, Plot)
 
 
 @decl_plot
-def plot_residual(rs, var, layer, hit, projection=None):
+def plot_residual(rs, var, layer, hit, projection=None, display_layer=True):
     r'''
     Plots of $\Delta \phi$, $\Delta z$, or $\Delta r$ (vs $\eta$) between RecHit
     and SimHit for the nth hit in the matched seed.
@@ -23,25 +23,26 @@ def plot_residual(rs, var, layer, hit, projection=None):
          ('phi', 'B2', 2): rs.dphi_v_eta_second_hits_in_B2,
          ('phi', 'B3', 2): rs.dphi_v_eta_second_hits_in_B3,
          }[(var, layer, hit)]
-    varlabel = {('z', 1): r"$\Delta z_1(\mu \mathrm{m})$",
-                ('z', 2): r"$\Delta z_2(\mu \mathrm{m})$",
-                ('phi', 1): r"$\Delta \phi_1(\mathrm{millirad})$",
-                ('phi', 2): r"$\Delta \phi_2(\mathrm{millirad})$"
+    varlabel = {('z', 1): r"$\Delta z_1^{\textrm{sim}}(\mu \mathrm{m})$",
+                ('z', 2): r"$\Delta z_2^{\textrm{sim}}(\mu \mathrm{m})$",
+                ('phi', 1): r"$\Delta \phi_1^{\textrm{sim}}(\mathrm{millirad})$",
+                ('phi', 2): r"$\Delta \phi_2^{\textrm{sim}}(\mathrm{millirad})$"
                 }[(var, hit)]
     scale = {'z': 10**4,  # cm -> um
              'phi': 10**3  # rad -> millirad
              }[var]
     if projection == 'y':  # projecting onto var axis
         h = h.ProjectionY()
-        hist_plot(hist(h, rescale_x=scale), xlabel=varlabel)
+        hist_plot(hist(h, rescale_x=scale), xlabel=varlabel, title='Layer - ' + layer)
     elif projection == 'x':  # projecting onto eta axis
         h = h.ProjectionX()
-        hist_plot(hist(h), xlabel=r'$\eta$')
+        hist_plot(hist(h), xlabel=r'$\eta$', title=layer)
     else:
         hist2d_plot(hist2d(h, rescale_y=scale), ylabel=varlabel, xlabel=r"$\eta$")
-    plt.text(0.9, 0.9, layer,
-             bbox={'facecolor': 'white', 'alpha': 0.7},
-             transform=plt.gca().transAxes)
+    # if display_layer:
+    #     plt.text(0.9, 0.9, layer,
+    #              bbox={'facecolor': 'white', 'alpha': 0.7},
+    #              transform=plt.gca().transAxes)
 
 
 @decl_plot
@@ -78,7 +79,7 @@ def plot_residuals_v_ladder(rs, var, layer):
 
 
 @decl_plot
-def sc_extrapolation_first(rs, var, layer, hit, even_odd, log=False, norm=None, cut=None):
+def sc_extrapolation_first(rs, var, layer, hit, even_odd, log=False, norm=None, cut=None, display_layer=True):
     ''' Raphael's plots '''
 
     # def preproc(h):
@@ -90,14 +91,14 @@ def sc_extrapolation_first(rs, var, layer, hit, even_odd, log=False, norm=None,
     #           xlabel=r"$\Delta z_1$(cm)",
     #           title="BPIX - Layer 1")
 
-    h = {('phi', 'B1', 1, 'either'): rs.sc_first_hits_in_B1_dphi_either,
-         ('phi', 'B2', 1, 'either'): rs.sc_first_hits_in_B2_dphi_either,
-         ('z', 'B1', 1, 'either'): rs.sc_first_hits_in_B1_dz_either,
-         ('z', 'B2', 1, 'either'): rs.sc_first_hits_in_B2_dz_either,
-         ('phi', 'B2', 2, 'either'): rs.sc_second_hits_in_B2_dphi_either,
-         ('phi', 'B3', 2, 'either'): rs.sc_second_hits_in_B3_dphi_either,
-         ('z', 'B2', 2, 'either'): rs.sc_second_hits_in_B2_dz_either,
-         ('z', 'B3', 2, 'either'): rs.sc_second_hits_in_B3_dz_either,
+    h = {('phi', 'B1', 1, 'either'): (rs.sc_first_hits_in_B1_dphi_even, rs.sc_first_hits_in_B1_dphi_odd),
+         ('phi', 'B2', 1, 'either'): (rs.sc_first_hits_in_B2_dphi_even, rs.sc_first_hits_in_B1_dphi_odd),
+         ('z', 'B1', 1, 'either'): (rs.sc_first_hits_in_B1_dz_even, rs.sc_first_hits_in_B1_dz_odd),
+         ('z', 'B2', 1, 'either'): (rs.sc_first_hits_in_B2_dz_even, rs.sc_first_hits_in_B2_dz_odd),
+         ('phi', 'B2', 2, 'either'): (rs.sc_second_hits_in_B2_dphi_even, rs.sc_second_hits_in_B2_dphi_odd),
+         ('phi', 'B3', 2, 'either'): (rs.sc_second_hits_in_B3_dphi_even, rs.sc_second_hits_in_B3_dphi_odd),
+         ('z', 'B2', 2, 'either'): (rs.sc_second_hits_in_B2_dz_even, rs.sc_second_hits_in_B2_dz_odd),
+         ('z', 'B3', 2, 'either'): (rs.sc_second_hits_in_B3_dz_even, rs.sc_second_hits_in_B3_dz_odd),
 
          ('phi', 'B1', 1, 'even'): rs.sc_first_hits_in_B1_dphi_even,
          ('phi', 'B2', 1, 'even'): rs.sc_first_hits_in_B2_dphi_even,
@@ -126,14 +127,22 @@ def sc_extrapolation_first(rs, var, layer, hit, even_odd, log=False, norm=None,
                 ('phi', 2): r"$\Delta \phi_2(\mathrm{millirad})$"
                 }[(var, hit)]
 
-    h = hist(h.ProjectionY(), rescale_x=scale)
+    try:
+        h = hist(h.ProjectionY(), rescale_x=scale)
+    except AttributeError:
+        h = hist_add(hist(h[0].ProjectionY(), rescale_x=scale), hist(h[1].ProjectionY(), rescale_x=scale))
     if cut:
         h = hist_slice(h, (-cut, cut))
     hist_plot(h,
               include_errors=True,
               log=log,
               norm=norm,
-              xlabel=varlabel)
+              xlabel=varlabel,
+              title='Layer - ' + layer)
+    # if display_layer:
+    #     plt.text(0.9, 0.9, layer,
+    #              bbox={'facecolor': 'white', 'alpha': 0.7},
+    #              transform=plt.gca().transAxes)
 
 
 def generate_dashboard(plots):
@@ -206,53 +215,79 @@ if __name__ == '__main__':
     dz1_v_ladder_B1 = (plot_residuals_v_ladder, (rs, 'z', 'B1'), {})
     dz1_v_ladder_B2 = (plot_residuals_v_ladder, (rs, 'z', 'B2'), {})
 
-    opts = {'log': False, 'norm': 1.0, 'cut': 25}
-    dphi1_sc_ex_B1 = (sc_extrapolation_first, (rs, 'phi', 'B1', 1, 'either'), opts )
+    opts = {'log': False, 'norm': None, 'cut': 150}
+    dphi1_sc_ex_B1 = (sc_extrapolation_first, (rs, 'phi', 'B1', 1, 'either'), opts)
     dphi1_sc_ex_B2 = (sc_extrapolation_first, (rs, 'phi', 'B2', 1, 'either'), opts)
-    dz1_sc_ex_B1 = (sc_extrapolation_first, (rs, 'z', 'B1', 1, 'either'), {'norm': 1.0})
-    dz1_sc_ex_B2 = (sc_extrapolation_first, (rs, 'z', 'B2', 1, 'either'), {'norm': 1.0})
+    dz1_sc_ex_B1 = (sc_extrapolation_first, (rs, 'z', 'B1', 1, 'either'), {})
+    dz1_sc_ex_B2 = (sc_extrapolation_first, (rs, 'z', 'B2', 1, 'either'), {})
+
+    dphi2_sc_ex_B1 = (sc_extrapolation_first, (rs, 'phi', 'B1', 2, 'either'), opts)
+    dphi2_sc_ex_B2 = (sc_extrapolation_first, (rs, 'phi', 'B2', 2, 'either'), opts)
+    dz2_sc_ex_B1 = (sc_extrapolation_first, (rs, 'z', 'B1', 2, 'either'), {})
+    dz2_sc_ex_B2 = (sc_extrapolation_first, (rs, 'z', 'B2', 2, 'either'), {})
 
     dphi1_sc_ex_B1_even = (sc_extrapolation_first, (rs, 'phi', 'B1', 1, 'even'), opts)
     dphi1_sc_ex_B2_even = (sc_extrapolation_first, (rs, 'phi', 'B2', 1, 'even'), opts)
-    dz1_sc_ex_B1_even = (sc_extrapolation_first, (rs, 'z', 'B1', 1, 'even'), {'norm': 1.0})
-    dz1_sc_ex_B2_even = (sc_extrapolation_first, (rs, 'z', 'B2', 1, 'even'), {'norm': 1.0})
+    dz1_sc_ex_B1_even = (sc_extrapolation_first, (rs, 'z', 'B1', 1, 'even'), {})
+    dz1_sc_ex_B2_even = (sc_extrapolation_first, (rs, 'z', 'B2', 1, 'even'), {})
 
     dphi1_sc_ex_B1_odd = (sc_extrapolation_first, (rs, 'phi', 'B1', 1, 'odd'), opts)
     dphi1_sc_ex_B2_odd = (sc_extrapolation_first, (rs, 'phi', 'B2', 1, 'odd'), opts)
-    dz1_sc_ex_B1_odd = (sc_extrapolation_first, (rs, 'z', 'B1', 1, 'odd'), {'norm': 1.0})
-    dz1_sc_ex_B2_odd = (sc_extrapolation_first, (rs, 'z', 'B2', 1, 'odd'), {'norm': 1.0})
+    dz1_sc_ex_B1_odd = (sc_extrapolation_first, (rs, 'z', 'B1', 1, 'odd'), {})
+    dz1_sc_ex_B2_odd = (sc_extrapolation_first, (rs, 'z', 'B2', 1, 'odd'), {})
 
     # Now assemble the plots into figures.
-    plots = [Plot([[dphi1_v_eta_B1, dphi1_v_eta_B2],
-                   [dz1_v_eta_B1,   dz1_v_eta_B2  ]],
-                  'res1_v_eta'),
-             Plot([[dphi2_v_eta_B2, dphi2_v_eta_B3],
-                   [dz2_v_eta_B2,   dz2_v_eta_B3  ]],
-                  'res2_v_eta'),
-             Plot([[dphi1_B1, dphi1_B2],
-                   [dz1_B1,   dz1_B2  ]],
-                  'res1'),
-             Plot([[eta1_B1, eta1_B2],
-                   [eta2_B2, eta2_B3  ]],
-                  'eta_dist'),
-             Plot([[dphi2_B2, dphi2_B3],
-                   [dz2_B2,   dz2_B3  ]],
-                  'res2'),
-             Plot([[dphi1_v_ladder_B1, dphi1_v_ladder_B2],
-                   [dz1_v_ladder_B1,   dz1_v_ladder_B2]],
-                  'res_v_ladder'),
-             Plot([[dphi1_sc_ex_B1, dphi1_sc_ex_B2],
-                   [dz1_sc_ex_B1, dz1_sc_ex_B2]],
-                  'sc_ex_1'),
-             Plot([[dphi1_sc_ex_B1_even, dphi1_sc_ex_B2_even],
-                   [dz1_sc_ex_B1_even, dz1_sc_ex_B2_even]],
-                  'sc_ex_1_even'),
-             Plot([[dphi1_sc_ex_B1_odd, dphi1_sc_ex_B2_odd],
-                   [dz1_sc_ex_B1_odd, dz1_sc_ex_B2_odd]],
-                  'sc_ex_1_odd'),
-             Plot([[[dphi1_sc_ex_B1_odd, dphi1_sc_ex_B1_even], "FL"],
-                   [dz1_sc_ex_B1_odd, dz1_sc_ex_B1_even]],
-                  'sc_ex_1_odd_v_even'),
+    plots = [
+             # Plot([[dphi1_v_eta_B1, dphi1_v_eta_B2],
+             #       [dz1_v_eta_B1,   dz1_v_eta_B2  ]],
+             #      'res1_v_eta'),
+             # Plot([[dphi2_v_eta_B2, dphi2_v_eta_B3],
+             #       [dz2_v_eta_B2,   dz2_v_eta_B3  ]],
+             #      'res2_v_eta'),
+             # Plot([[dphi1_B1, dphi1_B2],
+             #       [dz1_B1,   dz1_B2  ]],
+             #      'res1'),
+             # Plot([[eta1_B1, eta1_B2],
+             #       [eta2_B2, eta2_B3  ]],
+             #      'eta_dist'),
+             # Plot([[dphi2_B2, dphi2_B3],
+             #       [dz2_B2,   dz2_B3  ]],
+             #      'res2'),
+             # Plot([[dphi1_v_ladder_B1, dphi1_v_ladder_B2],
+             #       [dz1_v_ladder_B1,   dz1_v_ladder_B2]],
+             #      'res_v_ladder'),
+             # Plot([[dphi1_sc_ex_B1, dphi1_sc_ex_B2],
+             #       [dz1_sc_ex_B1, dz1_sc_ex_B2]],
+             #      'sc_ex_1'),
+             # Plot([[dphi1_sc_ex_B1_even, dphi1_sc_ex_B2_even],
+             #       [dz1_sc_ex_B1_even, dz1_sc_ex_B2_even]],
+             #      'sc_ex_1_even'),
+             # Plot([[dphi1_sc_ex_B1_odd, dphi1_sc_ex_B2_odd],
+             #       [dz1_sc_ex_B1_odd, dz1_sc_ex_B2_odd]],
+             #      'sc_ex_1_odd'),
+             # Plot([[(dphi1_sc_ex_B1_odd, dphi1_sc_ex_B1_even), "FL"],
+             #       [dz1_sc_ex_B1_odd, dz1_sc_ex_B1_even]],
+             #      'sc_ex_1_odd_v_even'),
+
+             Plot([[dphi1_sc_ex_B1],
+                   [dphi1_B1]],
+                  'sc_ex_v_sim_phi1_B1'),
+             Plot([[dphi1_sc_ex_B2],
+                   [dphi1_B2]],
+                  'sc_ex_v_sim_phi1_B2'),
+             Plot([[dphi2_sc_ex_B2],
+                   [dphi2_B2]],
+                  'sc_ex_v_sim_phi2_B2'),
+             Plot([[dz1_sc_ex_B1],
+                   [dz1_B1]],
+                  'sc_ex_v_sim_z1_B1'),
+             Plot([[dz2_sc_ex_B2],
+                   [dz2_B2]],
+                  'sc_ex_v_sim_z2_B2'),
+             Plot([[dz1_sc_ex_B1],
+                   [dz1_sc_ex_B1_even],
+                   [dz1_sc_ex_B1_odd]],
+                  'even_odd'),
              ]
 
     # Finally, render and save the plots and generate the html+bootstrap

+ 1 - 1
filval

@@ -1 +1 @@
-Subproject commit 0bd6e917d03ec47d93a19bfa1599fd3dc4b6cbdb
+Subproject commit 9a6a227982091f200e56402c9b808f3d2d4894e3