|
@@ -3,9 +3,9 @@ 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, hist_scale, hist2d
|
|
|
-from filval.plotter import (decl_plot, render_plots, hist_plot, hist2d_plot,
|
|
|
- hist_plot_stack, Plot, generate_dashboard)
|
|
|
+from filval.histogram import hist, hist_add, hist_norm, hist_scale, hist2d
|
|
|
+from filval.plotting import (decl_plot, render_plots, hist_plot, hist2d_plot,
|
|
|
+ Plot, generate_dashboard, simple_plot)
|
|
|
|
|
|
|
|
|
def center_text(x, y, txt, **kwargs):
|
|
@@ -15,7 +15,59 @@ def center_text(x, y, txt, **kwargs):
|
|
|
|
|
|
|
|
|
@decl_plot
|
|
|
-def plot_seed_eff(old_seeds, new_seeds):
|
|
|
+def plot_residuals(rs, layer, hit, variable, plot_cuts=True):
|
|
|
+ matching_cuts = [
|
|
|
+ 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,
|
|
|
+ )
|
|
|
+ ]
|
|
|
+
|
|
|
+ h = hist2d(getattr(rs, f'{variable}_BPIX_L{layer}_H{hit}_v_Et'))
|
|
|
+
|
|
|
+ def calc_window(et):
|
|
|
+ idx = min(hit-1, 2)
|
|
|
+ high_et = matching_cuts[idx][f'{variable}MaxHighEt']
|
|
|
+ high_et_thres = matching_cuts[idx][f'{variable}MaxHighEtThres']
|
|
|
+ low_et_grad = matching_cuts[idx][f'{variable}MaxLowEtGrad']
|
|
|
+ return high_et + min(0, et-high_et_thres)*low_et_grad
|
|
|
+
|
|
|
+ hist2d_plot(h, colorbar=True)
|
|
|
+
|
|
|
+ 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()
|
|
|
+
|
|
|
+ plt.xlabel({'dPhi': r'$\delta \phi$ (rads)',
|
|
|
+ 'dRz': r'$\delta R/z$ (cm)'}[variable])
|
|
|
+ plt.ylabel('$E_T$ (GeV)')
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+@decl_plot
|
|
|
+def plot_seed_eff(rs):
|
|
|
r"""## ECAL-Driven Seeding Efficiency
|
|
|
|
|
|
The proportion of gen-level electrons originating in the luminous region that have
|
|
@@ -25,33 +77,28 @@ def plot_seed_eff(old_seeds, new_seeds):
|
|
|
ax_eta = plt.subplot(222)
|
|
|
ax_phi = plt.subplot(223)
|
|
|
|
|
|
-
|
|
|
errors = True
|
|
|
plt.sca(ax_pt)
|
|
|
- hist_plot(hist(new_seeds.seed_eff_v_pt), include_errors=errors, label='New')
|
|
|
- hist_plot(hist(old_seeds.seed_eff_v_pt), include_errors=errors, label='Old')
|
|
|
+ hist_plot(hist(rs.seed_eff_v_pt), include_errors=errors)
|
|
|
center_text(0.5, 0.3, r'$|\eta|<2.4$')
|
|
|
plt.xlabel(r"Sim-Track $p_T$")
|
|
|
plt.ylim((0, 1.1))
|
|
|
|
|
|
plt.sca(ax_eta)
|
|
|
- hist_plot(hist(new_seeds.seed_eff_v_eta), include_errors=errors, label='New')
|
|
|
- hist_plot(hist(old_seeds.seed_eff_v_eta), include_errors=errors, label='Old')
|
|
|
+ hist_plot(hist(rs.seed_eff_v_eta), include_errors=errors)
|
|
|
center_text(0.5, 0.3, r'$p_T>20$')
|
|
|
plt.xlabel(r"Sim-Track $\eta$")
|
|
|
plt.ylim((0, 1.1))
|
|
|
- plt.legend()
|
|
|
|
|
|
plt.sca(ax_phi)
|
|
|
- hist_plot(hist(new_seeds.seed_eff_v_phi), include_errors=errors, label='New')
|
|
|
- hist_plot(hist(old_seeds.seed_eff_v_phi), include_errors=errors, label='Old')
|
|
|
+ hist_plot(hist(rs.seed_eff_v_phi), include_errors=errors)
|
|
|
center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
|
|
|
plt.xlabel(r"Sim-Track $\phi$")
|
|
|
plt.ylim((0, 1.1))
|
|
|
|
|
|
|
|
|
@decl_plot
|
|
|
-def plot_track_eff(old_seeds, new_seeds):
|
|
|
+def plot_tracking_eff(rs):
|
|
|
r"""## GSF Tracking Efficiency
|
|
|
|
|
|
The proportion of electrons origination in the luminous region from the that have
|
|
@@ -63,30 +110,26 @@ def plot_track_eff(old_seeds, new_seeds):
|
|
|
|
|
|
errors = True
|
|
|
plt.sca(ax_pt)
|
|
|
- hist_plot(hist(new_seeds.track_eff_v_pt), include_errors=errors, label='New')
|
|
|
- hist_plot(hist(old_seeds.track_eff_v_pt), include_errors=errors, label='Old')
|
|
|
+ hist_plot(hist(rs.tracking_eff_v_pt), include_errors=errors)
|
|
|
center_text(0.5, 0.3, r'$|\eta|<2.4$')
|
|
|
plt.xlabel(r"Sim-Track $p_T$")
|
|
|
- plt.ylim((0, 1.1))
|
|
|
+ # plt.ylim((0, 1.1))
|
|
|
|
|
|
plt.sca(ax_eta)
|
|
|
- hist_plot(hist(new_seeds.track_eff_v_eta), include_errors=errors, label='New')
|
|
|
- hist_plot(hist(old_seeds.track_eff_v_eta), include_errors=errors, label='Old')
|
|
|
+ hist_plot(hist(rs.tracking_eff_v_eta), include_errors=errors)
|
|
|
center_text(0.5, 0.3, r'$p_T>20$')
|
|
|
plt.xlabel(r"Sim-Track $\eta$")
|
|
|
- plt.ylim((0, 1.1))
|
|
|
- plt.legend()
|
|
|
+ # plt.ylim((0, 1.1))
|
|
|
|
|
|
plt.sca(ax_phi)
|
|
|
- hist_plot(hist(new_seeds.track_eff_v_phi), include_errors=errors, label='New')
|
|
|
- hist_plot(hist(old_seeds.track_eff_v_phi), include_errors=errors, label='Old')
|
|
|
+ hist_plot(hist(rs.tracking_eff_v_phi), include_errors=errors)
|
|
|
center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
|
|
|
plt.xlabel(r"Sim-Track $\phi$")
|
|
|
- plt.ylim((0, 1.1))
|
|
|
+ # plt.ylim((0, 1.1))
|
|
|
|
|
|
|
|
|
@decl_plot
|
|
|
-def plot_seed_purity(old_seeds, new_seeds, ext=""):
|
|
|
+def plot_seed_purity(rs, ext=""):
|
|
|
r"""## ECAL-Driven Seed Purity
|
|
|
|
|
|
The proportion of ECAL-driven seeds that have a matched gen-level electron originating in
|
|
@@ -96,30 +139,26 @@ def plot_seed_purity(old_seeds, new_seeds, ext=""):
|
|
|
ax_eta = plt.subplot(222)
|
|
|
ax_phi = plt.subplot(223)
|
|
|
|
|
|
- def get_hist(rs, base_name):
|
|
|
+ def get_hist(base_name):
|
|
|
return hist(getattr(rs, base_name+ext))
|
|
|
|
|
|
errors = True
|
|
|
plt.sca(ax_pt)
|
|
|
- hist_plot(get_hist(new_seeds, "seed_pur_v_pt"), include_errors=errors, label='New')
|
|
|
- hist_plot(get_hist(old_seeds, "seed_pur_v_pt"), include_errors=errors, label='Old')
|
|
|
+ hist_plot(get_hist("seed_pur_v_pt"), include_errors=errors)
|
|
|
center_text(0.5, 0.3, r'$|\eta|<2.4$')
|
|
|
plt.xlabel(r"Seed $p_T$")
|
|
|
if not ext:
|
|
|
plt.ylim((0, 1.1))
|
|
|
|
|
|
plt.sca(ax_eta)
|
|
|
- hist_plot(get_hist(new_seeds, "seed_pur_v_eta"), include_errors=errors, label='New')
|
|
|
- hist_plot(get_hist(old_seeds, "seed_pur_v_eta"), include_errors=errors, label='Old')
|
|
|
+ hist_plot(get_hist("seed_pur_v_eta"), include_errors=errors)
|
|
|
center_text(0.5, 0.3, r'$p_T>20$')
|
|
|
plt.xlabel(r"Seed $\eta$")
|
|
|
if not ext:
|
|
|
plt.ylim((0, 1.1))
|
|
|
- plt.legend()
|
|
|
|
|
|
plt.sca(ax_phi)
|
|
|
- hist_plot(get_hist(new_seeds, "seed_pur_v_phi"), include_errors=errors, label='New')
|
|
|
- hist_plot(get_hist(old_seeds, "seed_pur_v_phi"), include_errors=errors, label='Old')
|
|
|
+ hist_plot(get_hist("seed_pur_v_phi"), include_errors=errors)
|
|
|
center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
|
|
|
plt.xlabel(r"Seed $\phi$")
|
|
|
if not ext:
|
|
@@ -127,7 +166,7 @@ def plot_seed_purity(old_seeds, new_seeds, ext=""):
|
|
|
|
|
|
|
|
|
@decl_plot
|
|
|
-def plot_track_purity(old_seeds, new_seeds, ext=""):
|
|
|
+def plot_track_purity(rs, ext=""):
|
|
|
r"""## GSF Track Purity
|
|
|
|
|
|
The proportion of GSF-tracks w\ ECAL-driven seeds that have a matched gen-level electron originating in
|
|
@@ -137,30 +176,26 @@ def plot_track_purity(old_seeds, new_seeds, ext=""):
|
|
|
ax_eta = plt.subplot(222)
|
|
|
ax_phi = plt.subplot(223)
|
|
|
|
|
|
- def get_hist(rs, base_name):
|
|
|
+ def get_hist( base_name):
|
|
|
return hist(getattr(rs, base_name+ext))
|
|
|
|
|
|
errors = True
|
|
|
plt.sca(ax_pt)
|
|
|
- hist_plot(get_hist(new_seeds, "track_pur_v_pt"), include_errors=errors, label='New')
|
|
|
- hist_plot(get_hist(old_seeds, "track_pur_v_pt"), include_errors=errors, label='Old')
|
|
|
+ hist_plot(get_hist("tracking_pur_v_pt"), include_errors=errors)
|
|
|
center_text(0.5, 0.3, r'$|\eta|<2.4$')
|
|
|
plt.xlabel(r"GSF-Track $p_T$")
|
|
|
if not ext:
|
|
|
plt.ylim((0, 1.1))
|
|
|
|
|
|
plt.sca(ax_eta)
|
|
|
- hist_plot(get_hist(new_seeds, "track_pur_v_eta"), include_errors=errors, label='New')
|
|
|
- hist_plot(get_hist(old_seeds, "track_pur_v_eta"), include_errors=errors, label='Old')
|
|
|
+ hist_plot(get_hist("tracking_pur_v_eta"), include_errors=errors)
|
|
|
center_text(0.5, 0.3, r'$p_T>20$')
|
|
|
plt.xlabel(r"GSF-Track $\eta$")
|
|
|
if not ext:
|
|
|
plt.ylim((0, 1.1))
|
|
|
- plt.legend()
|
|
|
|
|
|
plt.sca(ax_phi)
|
|
|
- hist_plot(get_hist(new_seeds, "track_pur_v_phi"), include_errors=errors, label='New')
|
|
|
- hist_plot(get_hist(old_seeds, "track_pur_v_phi"), include_errors=errors, label='Old')
|
|
|
+ hist_plot(get_hist("tracking_pur_v_phi"), include_errors=errors)
|
|
|
center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
|
|
|
plt.xlabel(r"GSF-Track $\phi$")
|
|
|
if not ext:
|
|
@@ -168,79 +203,65 @@ def plot_track_purity(old_seeds, new_seeds, ext=""):
|
|
|
|
|
|
|
|
|
@decl_plot
|
|
|
-def plot_nhits(old_seeds, new_seeds):
|
|
|
- ax_sim = plt.subplot(211)
|
|
|
- ax_rec_new = plt.subplot(223)
|
|
|
- ax_rec_old = plt.subplot(224)
|
|
|
-
|
|
|
- def _plot(histo):
|
|
|
- hit_hist2d = hist2d(histo)
|
|
|
- hist2d_plot(hit_hist2d)
|
|
|
- weights, _, xs, ys = hit_hist2d
|
|
|
- hits = (ys[1:, :-1] + ys[:-1, :-1])/2
|
|
|
- etas = (xs[0, :-1] + xs[0, 1:])/2
|
|
|
- avg_hits = np.ma.average(hits, axis=0, weights=weights)
|
|
|
- plt.plot(etas, avg_hits, 'wo', label=r'Average in $\eta$ bin')
|
|
|
- plt.xlabel(r'Track $\eta$')
|
|
|
- plt.ylabel(r'\# of pixel layers with Hit')
|
|
|
-
|
|
|
- plt.sca(ax_sim)
|
|
|
- _plot(new_seeds.simpixlay_v_eta)
|
|
|
- plt.legend()
|
|
|
- plt.colorbar()
|
|
|
- center_text(0.5, 0.1, "Sim Tracks", bbox=dict(facecolor='white', alpha=0.5))
|
|
|
- plt.sca(ax_rec_old)
|
|
|
- _plot(old_seeds.recpixlay_v_eta)
|
|
|
- plt.colorbar()
|
|
|
- center_text(0.5, 0.1, "GSF-Tracks (Old Seeding)", bbox=dict(facecolor='white', alpha=0.5))
|
|
|
- plt.sca(ax_rec_new)
|
|
|
- _plot(new_seeds.recpixlay_v_eta)
|
|
|
- plt.colorbar()
|
|
|
- center_text(0.5, 0.1, "GSF-Tracks (New Seeding)", bbox=dict(facecolor='white', alpha=0.5))
|
|
|
+def plot_hit_vs_layer(rs, region):
|
|
|
+
|
|
|
+ h = hist2d(getattr(rs, f'hit_vs_layer_{region}'))
|
|
|
+
|
|
|
+ hist2d_plot(h, txt_format='{:2.0f}')
|
|
|
+ plt.xlabel('Layer \#')
|
|
|
+ plt.ylabel('Hit \#')
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
- old_seeds = ResultSet("old_seeds", 'old_seeding2.root')
|
|
|
- new_seeds = ResultSet("new_seeds", 'new_seeding2.root')
|
|
|
+ rs = ResultSet('seeds', '../hists/new_seeding.root')
|
|
|
|
|
|
# Next, declare all of the (sub)plots that will be assembled into full
|
|
|
# figures later
|
|
|
- seed_eff = plot_seed_eff, (old_seeds, new_seeds)
|
|
|
- track_eff = plot_track_eff, (old_seeds, new_seeds)
|
|
|
+ seed_eff = plot_seed_eff, (rs, )
|
|
|
+ tracking_eff = plot_tracking_eff, (rs,)
|
|
|
+
|
|
|
+ seed_pur = plot_seed_purity, rs
|
|
|
+ seed_pur_num = plot_seed_purity, (rs,), {'ext': '_num'}
|
|
|
+ seed_pur_den = plot_seed_purity, (rs,), {'ext': '_den'}
|
|
|
+
|
|
|
+ track_pur = plot_track_purity, (rs,)
|
|
|
+ track_pur_num = plot_track_purity, (rs,), {'ext': '_num'}
|
|
|
+ track_pur_den = plot_track_purity, (rs,), {'ext': '_den'}
|
|
|
|
|
|
- seed_pur = plot_seed_purity, (old_seeds, new_seeds)
|
|
|
- seed_pur_num = plot_seed_purity, (old_seeds, new_seeds), {'ext': '_num'}
|
|
|
- seed_pur_den = plot_seed_purity, (old_seeds, new_seeds), {'ext': '_den'}
|
|
|
+ residuals_L1_H1_dPhi = plot_residuals, (rs, 1, 1, 'dPhi')
|
|
|
+ residuals_L2_H2_dPhi = plot_residuals, (rs, 2, 2, 'dPhi')
|
|
|
+ residuals_L3_H3_dPhi = plot_residuals, (rs, 3, 3, 'dPhi')
|
|
|
|
|
|
- track_pur = plot_track_purity, (old_seeds, new_seeds)
|
|
|
- track_pur_num = plot_track_purity, (old_seeds, new_seeds), {'ext': '_num'}
|
|
|
- track_pur_den = plot_track_purity, (old_seeds, new_seeds), {'ext': '_den'}
|
|
|
+ residuals_L1_H1_dRz = plot_residuals, (rs, 1, 1, 'dRz')
|
|
|
+ residuals_L1_H1_dRz_no_cuts = plot_residuals, (rs, 1, 1, 'dRz'), {'plot_cuts': False}
|
|
|
+ residuals_L2_H2_dRz = plot_residuals, (rs, 2, 2, 'dRz')
|
|
|
+ residuals_L3_H3_dRz = plot_residuals, (rs, 3, 3, 'dRz')
|
|
|
|
|
|
- nHits = (plot_nhits, (old_seeds, new_seeds), {})
|
|
|
+ hit_vs_layer_barrel = plot_hit_vs_layer, (rs, 'barrel')
|
|
|
+ hit_vs_layer_forward = plot_hit_vs_layer, (rs, 'forward')
|
|
|
|
|
|
# Now assemble the plots into figures.
|
|
|
plots = [
|
|
|
- Plot([[seed_eff]],
|
|
|
- 'ECAL-Driven Seeding Efficiency'),
|
|
|
- Plot([[seed_pur]],
|
|
|
- 'ECAL-Driven Seed Purity'),
|
|
|
- Plot([[seed_pur_num]],
|
|
|
- 'ECAL-Driven Seed Purity Numerator'),
|
|
|
- Plot([[seed_pur_den]],
|
|
|
- 'ECAL-Driven Seed Purity Denominator'),
|
|
|
- Plot([[track_eff]],
|
|
|
- 'GSF Tracking Efficiency'),
|
|
|
- Plot([[track_pur]],
|
|
|
- 'GSF Track Purity'),
|
|
|
- Plot([[track_pur_num]],
|
|
|
- 'GSF Track Purity Numerator'),
|
|
|
- Plot([[track_pur_den]],
|
|
|
- 'GSF Track Purity Denominator'),
|
|
|
- Plot([[nHits]],
|
|
|
- 'Hits'),
|
|
|
+ Plot(residuals_L1_H1_dPhi, 'Phi Residuals Layer 1 Hit 1'),
|
|
|
+ Plot(residuals_L2_H2_dPhi, 'Phi Residuals Layer 2 Hit 2'),
|
|
|
+ Plot(residuals_L3_H3_dPhi, 'Phi Residuals Layer 3 Hit 3'),
|
|
|
+ Plot(residuals_L1_H1_dRz, 'dZ Residuals Layer 1 Hit 1'),
|
|
|
+ Plot(residuals_L1_H1_dRz_no_cuts, 'dZ Residuals Layer 1 Hit 1 w/o cuts'),
|
|
|
+ Plot(residuals_L2_H2_dRz, 'dZ Residuals Layer 2 Hit 2'),
|
|
|
+ Plot(residuals_L3_H3_dRz, 'dZ Residuals Layer 3 Hit 3'),
|
|
|
+ Plot(seed_eff, 'ECAL-Driven Seeding Efficiency'),
|
|
|
+ Plot(tracking_eff, 'GSF Tracking Efficiency'),
|
|
|
+ Plot(hit_vs_layer_barrel, 'Hit vs Layer - Barrel'),
|
|
|
+ Plot(hit_vs_layer_forward, 'Hit vs Layer - Forward'),
|
|
|
+ Plot(track_pur, 'GSF Track Purity'),
|
|
|
+ Plot(track_pur_num, 'GSF Track Purity Numerator'),
|
|
|
+ Plot(track_pur_den, 'GSF Track Purity Denominator'),
|
|
|
]
|
|
|
|
|
|
# Finally, render and save the plots and generate the html+bootstrap
|
|
|
# dashboard to view them
|
|
|
render_plots(plots, to_disk=False)
|
|
|
- generate_dashboard(plots, 'Seeding Efficiency', output='eff_plots.html', source_file=__file__)
|
|
|
+ generate_dashboard(plots, 'Seeding Efficiency',
|
|
|
+ output='eff_plots.html',
|
|
|
+ source=__file__,
|
|
|
+ config=rs.config)
|