eff_plots.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/usr/bin/env python
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. from filval.result_set import ResultSet
  5. from filval.histogram_utils import hist, hist_add, hist_normalize, hist_scale
  6. from filval.plotter import (decl_plot, render_plots, hist_plot, hist_plot_stack, Plot, generate_dashboard)
  7. @decl_plot
  8. def plot_seed_eff(old_seeds, new_seeds):
  9. r"""## Seeding Efficiency
  10. The proportion of gen-level electrons origination in $\rho<1$cm and $|z|<10$cm from the beam spot that have
  11. an associated Seed, matched via rechit-simhit associations in the pixel detector.
  12. """
  13. _, ((ax_pt, ax_eta), (ax_phi, _)) = plt.subplots(2, 2)
  14. errors = True
  15. plt.sca(ax_pt)
  16. hist_plot(hist(new_seeds.seed_eff_v_pt), include_errors=errors, label='New')
  17. hist_plot(hist(old_seeds.seed_eff_v_pt), include_errors=errors, title='Efficiency vs. Pt', label='Old')
  18. plt.xlabel("Pt")
  19. plt.ylim((0, 1.1))
  20. plt.sca(ax_eta)
  21. hist_plot(hist(new_seeds.seed_eff_v_eta), include_errors=errors, label='New')
  22. hist_plot(hist(old_seeds.seed_eff_v_eta), include_errors=errors, title='Efficiency vs. Eta', label='Old')
  23. plt.xlabel("Eta")
  24. plt.ylim((0, 1.1))
  25. plt.legend()
  26. plt.sca(ax_phi)
  27. hist_plot(hist(new_seeds.seed_eff_v_phi), include_errors=errors, label='New')
  28. hist_plot(hist(old_seeds.seed_eff_v_phi), include_errors=errors, title='Efficiency vs. Phi', label='Old')
  29. plt.xlabel("Phi")
  30. plt.ylim((0, 1.1))
  31. @decl_plot
  32. def plot_track_eff(old_seeds, new_seeds):
  33. r"""## Tracking Efficiency
  34. The proportion of gen-level electrons origination in $\rho<1$cm and $|z|<10$cm from the beam spot that have
  35. an associated GSF reconstructed electron.
  36. """
  37. _, ((ax_pt, ax_eta), (ax_phi, _)) = plt.subplots(2, 2)
  38. errors = True
  39. plt.sca(ax_pt)
  40. hist_plot(hist(new_seeds.track_eff_v_pt), include_errors=errors, label='New')
  41. hist_plot(hist(old_seeds.track_eff_v_pt), include_errors=errors, title='Efficiency vs. Pt', label='Old')
  42. plt.xlabel("Pt")
  43. plt.ylim((0, 1.1))
  44. plt.sca(ax_eta)
  45. hist_plot(hist(new_seeds.track_eff_v_eta), include_errors=errors, label='New')
  46. hist_plot(hist(old_seeds.track_eff_v_eta), include_errors=errors, title='Efficiency vs. Eta', label='Old')
  47. plt.xlabel("Eta")
  48. plt.ylim((0, 1.1))
  49. plt.legend()
  50. plt.sca(ax_phi)
  51. hist_plot(hist(new_seeds.track_eff_v_phi), include_errors=errors, label='New')
  52. hist_plot(hist(old_seeds.track_eff_v_phi), include_errors=errors, title='Efficiency vs. Phi', label='Old')
  53. plt.xlabel("Phi")
  54. plt.ylim((0, 1.1))
  55. @decl_plot
  56. def plot_seed_purity(old_seeds, new_seeds):
  57. r"""## Seed Purity
  58. The proportion of ECAL-driven seeds that have a matched gen-level electron originating in
  59. $\rho<1$cm and $|z|<10$cm from the beam spot.
  60. """
  61. _, ((ax_pt, ax_eta), (ax_phi, _)) = plt.subplots(2, 2)
  62. errors = True
  63. plt.sca(ax_pt)
  64. hist_plot(hist(new_seeds.seed_pur_v_pt), include_errors=errors, label='New')
  65. hist_plot(hist(old_seeds.seed_pur_v_pt), include_errors=errors, title='Purity vs. Pt', label='Old')
  66. plt.xlabel("Pt")
  67. plt.ylim((0, 1.1))
  68. plt.sca(ax_eta)
  69. hist_plot(hist(new_seeds.seed_pur_v_eta), include_errors=errors, label='New')
  70. hist_plot(hist(old_seeds.seed_pur_v_eta), include_errors=errors, title='Purity vs. Eta', label='Old')
  71. plt.xlabel("Eta")
  72. plt.ylim((0, 1.1))
  73. plt.legend()
  74. plt.sca(ax_phi)
  75. hist_plot(hist(new_seeds.seed_pur_v_phi), include_errors=errors, label='New')
  76. hist_plot(hist(old_seeds.seed_pur_v_phi), include_errors=errors, title='Purity vs. Phi', label='Old')
  77. plt.xlabel("Phi")
  78. plt.ylim((0, 1.1))
  79. if __name__ == '__main__':
  80. old_seeds = ResultSet("old_seeds", 'build/old_seeding.root')
  81. new_seeds = ResultSet("new_seeds", 'build/new_seeding.root')
  82. # Next, declare all of the (sub)plots that will be assembled into full
  83. # figures later
  84. seed_eff = (plot_seed_eff, (old_seeds, new_seeds), {})
  85. track_eff = (plot_track_eff, (old_seeds, new_seeds), {})
  86. seed_pur = (plot_seed_purity, (old_seeds, new_seeds), {})
  87. # Now assemble the plots into figures.
  88. plots = [
  89. Plot([[seed_eff]],
  90. 'Seeding Efficiency'),
  91. Plot([[track_eff]],
  92. 'Tracking Efficiency'),
  93. Plot([[seed_pur]],
  94. 'ECAL-Driven Seed Purity'),
  95. ]
  96. # Finally, render and save the plots and generate the html+bootstrap
  97. # dashboard to view them
  98. render_plots(plots, to_disk=False)
  99. generate_dashboard(plots, 'Seeding Efficiency', output='eff_plots.html', source_file=__file__)