123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601 |
- #!/usr/bin/env python
- import numpy as np
- import matplotlib.pyplot as plt
- from filval.result_set import ResultSet
- 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)
- def center_text(x, y, txt, **kwargs):
- plt.text(x, y, txt,
- horizontalalignment='center', verticalalignment='center',
- transform=plt.gca().transAxes, **kwargs)
- def hist_integral_ratio(num, den):
- num_int = hist_integral(num, times_bin_width=False)
- den_int = hist_integral(den, times_bin_width=False)
- ratio = num_int / den_int
- 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
- 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 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)')
- @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
- an associated Seed, matched via rechit-simhit associations in the pixel detector. Cuts are on simtrack quantities.
- """
- ax_pt = plt.subplot(221)
- ax_eta = plt.subplot(222)
- ax_phi = plt.subplot(223)
- errors = True
- plt.sca(ax_pt)
- 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(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.sca(ax_phi)
- 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_tracking_eff(rs):
- r"""## GSF Tracking Efficiency
- The proportion of electrons origination in the luminous region from the that have
- an associated GSF track. Cuts are on simtrack quantities.
- """
- ax_pt = plt.subplot(221)
- ax_eta = plt.subplot(222)
- ax_phi = plt.subplot(223)
- ax_eta_pt = plt.subplot(224)
- errors = True
- plt.sca(ax_pt)
- 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.sca(ax_eta)
- 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.sca(ax_phi)
- 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.sca(ax_eta_pt)
- hist2d_plot(hist2d(rs.tracking_eff_v_eta_pt))
- plt.xlabel(r"Sim-Track $\eta$")
- plt.ylabel(r"Sim-Track $p_T$")
- plt.colorbar()
- @decl_plot
- 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
- the luminous region. Cuts are on seed quantities.
- """
- ax_pt = plt.subplot(221)
- ax_eta = plt.subplot(222)
- ax_phi = plt.subplot(223)
- def get_hist(base_name):
- return hist(getattr(rs, base_name+ext))
- errors = True
- plt.sca(ax_pt)
- 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("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.sca(ax_phi)
- 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:
- plt.ylim((0, 1.1))
- @decl_plot
- 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
- the luminous region. Cuts are on GSF track quantities.
- """
- ax_pt = plt.subplot(221)
- ax_eta = plt.subplot(222)
- ax_phi = plt.subplot(223)
- def get_hist( base_name):
- return hist(getattr(rs, base_name+ext))
- errors = True
- plt.sca(ax_pt)
- 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$")
- plt.ylim((0, 1.1))
- plt.sca(ax_eta)
- 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$")
- plt.ylim((0, 1.1))
- plt.sca(ax_phi)
- 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$")
- plt.ylim((0, 1.1))
- @decl_plot
- 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 \#')
- def single_cut_plots(cut_sel):
- rs = ResultSet(f'{cut_sel}-window', f'../hists/{cut_sel}-window.root')
- seed_eff = plot_seed_eff, (rs,)
- tracking_eff = plot_tracking_eff, (rs,)
- seed_pur = plot_seed_purity, (rs,)
- track_pur = plot_track_purity, (rs,)
- track_pur_seed_match = plot_track_purity, (rs,), dict(ext='2')
- BPIX_residuals_L1_H1_dPhi = plot_residuals, (rs, 1, 1, 'dPhi', 'BPIX'), dict(cut_sel=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_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)
- 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_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)
- FPIX_residuals_L1_H2_dPhi = plot_residuals, (rs, 1, 2, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
- FPIX_residuals_L1_H3_dPhi = plot_residuals, (rs, 1, 3, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
- FPIX_residuals_L2_H3_dPhi = plot_residuals, (rs, 2, 3, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
- FPIX_residuals_L1_H2_dRz = plot_residuals, (rs, 1, 2, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
- FPIX_residuals_L1_H3_dRz = plot_residuals, (rs, 1, 3, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
- FPIX_residuals_L2_H3_dRz = plot_residuals, (rs, 2, 3, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
- hit_vs_layer_barrel = plot_hit_vs_layer, (rs, 'barrel')
- hit_vs_layer_forward = plot_hit_vs_layer, (rs, 'forward')
- 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_L2_H2_dRz, 'dZ Residuals Layer 2 Hit 2 - BPIX'),
- Plot(BPIX_residuals_L3_H3_dRz, 'dZ Residuals Layer 3 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_L2_H2_dRz, 'dR Residuals Layer 2 Hit 2 - FPIX'),
- Plot(FPIX_residuals_L3_H3_dRz, 'dR Residuals Layer 3 Hit 3 - FPIX'),
- Plot(FPIX_residuals_L1_H2_dPhi, 'Phi Residuals Layer 1 Hit 2 - FPIX'),
- Plot(FPIX_residuals_L1_H3_dPhi, 'Phi Residuals Layer 1 Hit 3 - FPIX'),
- Plot(FPIX_residuals_L2_H3_dPhi, 'Phi Residuals Layer 2 Hit 3 - FPIX'),
- Plot(FPIX_residuals_L1_H2_dRz, 'dR Residuals Layer 1 Hit 2 - FPIX'),
- Plot(FPIX_residuals_L1_H3_dRz, 'dR Residuals Layer 1 Hit 3 - FPIX'),
- Plot(FPIX_residuals_L2_H3_dRz, 'dR Residuals Layer 2 Hit 3 - FPIX'),
- 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(seed_pur, 'ECAL-Driven Seeding Purity'),
- 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'),
- ]
- render_plots(plots, to_disk=False)
- generate_dashboard(plots, 'Seeding Efficiency',
- output=f'{rs.sample_name}.html',
- source=__file__,
- config=rs.config)
- @decl_plot
- def plot_seed_roc_curve(rss):
- def get_num_den(rs, basename):
- num = hist(getattr(rs, f'{basename}_num'))
- den = hist(getattr(rs, f'{basename}_den'))
- return hist_integral_ratio(num, den)
- 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)
- center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
- plt.axis('equal')
- plt.xlim((0.8, 1.0))
- plt.ylim((0.8, 1.0))
- plt.xlabel('ECAL-Driven Seeding Purity')
- plt.ylabel('ECAL-Driven Seeding Efficiency')
- plt.grid()
- plt.legend()
- @decl_plot
- def plot_seed_eff_all(rss):
- ax_pt = plt.subplot(221)
- ax_eta = plt.subplot(222)
- ax_phi = plt.subplot(223)
- errors = True
- for rs in rss:
- plt.sca(ax_pt)
- hist_plot(hist(rs.seed_eff_v_pt), include_errors=errors, label=rs.sample_name)
- plt.sca(ax_eta)
- hist_plot(hist(rs.seed_eff_v_eta), include_errors=errors, label=rs.sample_name)
- plt.sca(ax_phi)
- hist_plot(hist(rs.seed_eff_v_phi), include_errors=errors, label=rs.sample_name)
- plt.sca(ax_pt)
- 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)
- center_text(0.5, 0.3, r'$p_T>20$')
- plt.xlabel(r"Sim-Track $\eta$")
- plt.ylim((0, 1.1))
- plt.legend(loc='lower right')
- plt.sca(ax_phi)
- 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_seed_pur_all(rss):
- ax_pt = plt.subplot(221)
- ax_eta = plt.subplot(222)
- ax_phi = plt.subplot(223)
- errors = True
- for rs in rss:
- plt.sca(ax_pt)
- hist_plot(hist(rs.seed_pur_v_pt), include_errors=errors, label=rs.sample_name)
- plt.sca(ax_eta)
- hist_plot(hist(rs.seed_pur_v_eta), include_errors=errors, label=rs.sample_name)
- plt.sca(ax_phi)
- hist_plot(hist(rs.seed_pur_v_phi), include_errors=errors, label=rs.sample_name)
- plt.sca(ax_pt)
- center_text(0.5, 0.3, r'$|\eta|<2.4$')
- plt.xlabel(r"Seed $p_T$")
- plt.ylim((0, 1.1))
- plt.sca(ax_eta)
- center_text(0.5, 0.3, r'$p_T>20$')
- plt.xlabel(r"Seed $\eta$")
- plt.ylim((0, 1.1))
- plt.legend(loc='lower right')
- plt.sca(ax_phi)
- center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
- plt.xlabel(r"Seed $\phi$")
- plt.ylim((0, 1.1))
- @decl_plot
- def plot_tracking_roc_curve(rss, ext=''):
- def get_num_den(rs, basename):
- num = hist(getattr(rs, f'{basename}{ext}_num'))
- den = hist(getattr(rs, f'{basename}{ext}_den'))
- return hist_integral_ratio(num, den)
- 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)
- center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
- plt.axis('equal')
- plt.xlim((0.8, 1.0))
- plt.ylim((0.8, 1.0))
- plt.xlabel('GSF-Track Purity')
- plt.ylabel('GSF-Track Efficiency')
- plt.grid()
- plt.legend()
- @decl_plot
- def plot_tracking_eff_all(rss, ext=''):
- ax_pt = plt.subplot(221)
- ax_eta = plt.subplot(222)
- ax_phi = plt.subplot(223)
- errors = True
- for rs in rss:
- plt.sca(ax_pt)
- hist_plot(hist(getattr(rs, f'tracking_eff_v_pt{ext}')), include_errors=errors, label=rs.sample_name)
- plt.sca(ax_eta)
- hist_plot(hist(getattr(rs, f'tracking_eff_v_eta{ext}')), include_errors=errors, label=rs.sample_name)
- plt.sca(ax_phi)
- hist_plot(hist(getattr(rs, f'tracking_eff_v_phi{ext}')), include_errors=errors, label=rs.sample_name)
- plt.sca(ax_pt)
- 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)
- center_text(0.5, 0.3, r'$p_T>20$')
- plt.xlabel(r"Sim-Track $\eta$")
- plt.ylim((0, 1.1))
- plt.legend(loc='lower right')
- plt.sca(ax_phi)
- 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_tracking_pur_all(rss, ext=''):
- ax_pt = plt.subplot(221)
- ax_eta = plt.subplot(222)
- ax_phi = plt.subplot(223)
- errors = True
- for rs in rss:
- plt.sca(ax_pt)
- hist_plot(hist(getattr(rs, f'tracking_pur_v_pt{ext}')), include_errors=errors, label=rs.sample_name)
- plt.sca(ax_eta)
- hist_plot(hist(getattr(rs, f'tracking_pur_v_eta{ext}')), include_errors=errors, label=rs.sample_name)
- plt.sca(ax_phi)
- hist_plot(hist(getattr(rs, f'tracking_pur_v_phi{ext}')), include_errors=errors, label=rs.sample_name)
- plt.sca(ax_pt)
- center_text(0.5, 0.3, r'$|\eta|<2.4$')
- plt.xlabel(r"GSF-Track $p_T$")
- plt.ylim((0, 1.1))
- plt.sca(ax_eta)
- center_text(0.5, 0.3, r'$p_T>20$')
- plt.xlabel(r"GSF-Track $\eta$")
- plt.ylim((0, 1.1))
- plt.legend(loc='lower right')
- plt.sca(ax_phi)
- center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
- plt.xlabel(r"GSF-Track $\phi$")
- plt.ylim((0, 1.1))
- @decl_plot
- def plot_ecal_rel_res(rss):
- for rs in rss:
- hist_plot(hist(rs.ecal_energy_resolution), label=rs.sample_name)
- plt.xlabel(r"ECAL $E_T$ relative error")
- plt.legend()
- def all_cut_plots(cuts):
- rss = [ResultSet(f'{cut_sel}-window', f'../hists/{cut_sel}-window.root') for cut_sel in cuts]
- tracking_roc_curve = plot_tracking_roc_curve, (rss,)
- tracking_eff_all = plot_tracking_eff_all, (rss,)
- tracking_pur_all = plot_tracking_pur_all, (rss,)
- tracking_roc_curve2 = plot_tracking_roc_curve, (rss, '2')
- tracking_eff_all2 = plot_tracking_eff_all, (rss, '2')
- tracking_pur_all2 = plot_tracking_pur_all, (rss, '2')
- seed_roc_curve = plot_seed_roc_curve, (rss,)
- seed_eff_all = plot_seed_eff_all, (rss,)
- seed_pur_all = plot_seed_pur_all, (rss,)
- ecal_rel_res = plot_ecal_rel_res, (rss,)
- plots = [
- Plot(tracking_roc_curve, 'Tracking ROC Curve'),
- Plot(tracking_eff_all, 'Tracking Efficiency'),
- Plot(tracking_pur_all, 'Tracking Purity'),
- Plot(tracking_roc_curve2, 'Tracking ROC Curve (Seed Matched)'),
- Plot(tracking_eff_all2, 'Tracking Efficiency (Seed Matched)'),
- Plot(tracking_pur_all2, 'Tracking Purity (Seed Matched)'),
- Plot(seed_roc_curve, 'Seeding ROC Curve'),
- Plot(seed_eff_all, 'ECAL-Driven Seeding Efficiency'),
- Plot(seed_pur_all, 'ECAL-Driven Seeding Purity'),
- Plot(ecal_rel_res, 'ECAL ET Relative Resolution'),
- ]
- render_plots(plots, to_disk=False)
- 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)
|