eff_plots.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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 import hist, hist_integral, hist2d, hist2d_percent_contour
  6. from filval.plotting import (decl_plot, render_plots, hist_plot, hist2d_plot,
  7. Plot, generate_dashboard, simple_plot)
  8. def center_text(x, y, txt, **kwargs):
  9. plt.text(x, y, txt,
  10. horizontalalignment='center', verticalalignment='center',
  11. transform=plt.gca().transAxes, **kwargs)
  12. def hist_integral_ratio(num, den):
  13. num_int = hist_integral(num, times_bin_width=False)
  14. den_int = hist_integral(den, times_bin_width=False)
  15. ratio = num_int / den_int
  16. error = np.sqrt(den_int) / den_int # TODO: Check this definition of error
  17. return ratio, error
  18. @decl_plot
  19. def plot_residuals(rs, layer, hit, variable, subdet, plot_cuts=True, cut_sel='tight'):
  20. matching_cuts = {
  21. 'extra-narrow': [
  22. dict(
  23. dPhiMaxHighEt=0.025,
  24. dPhiMaxHighEtThres=20.0,
  25. dPhiMaxLowEtGrad=-0.002,
  26. dRzMaxHighEt=9999.0,
  27. dRzMaxHighEtThres=0.0,
  28. dRzMaxLowEtGrad=0.0,
  29. ),
  30. dict(
  31. dPhiMaxHighEt=0.0015,
  32. dPhiMaxHighEtThres=0.0,
  33. dPhiMaxLowEtGrad=0.0,
  34. dRzMaxHighEt=0.025,
  35. dRzMaxHighEtThres=30.0,
  36. dRzMaxLowEtGrad=-0.002,
  37. ),
  38. dict(
  39. dPhiMaxHighEt=0.0015,
  40. dPhiMaxHighEtThres=0.0,
  41. dPhiMaxLowEtGrad=0.0,
  42. dRzMaxHighEt=0.025,
  43. dRzMaxHighEtThres=30.0,
  44. dRzMaxLowEtGrad=-0.002,
  45. )
  46. ],
  47. 'narrow': [
  48. dict(
  49. dPhiMaxHighEt=0.05,
  50. dPhiMaxHighEtThres=20.0,
  51. dPhiMaxLowEtGrad=-0.002,
  52. dRzMaxHighEt=9999.0,
  53. dRzMaxHighEtThres=0.0,
  54. dRzMaxLowEtGrad=0.0,
  55. ),
  56. dict(
  57. dPhiMaxHighEt=0.003,
  58. dPhiMaxHighEtThres=0.0,
  59. dPhiMaxLowEtGrad=0.0,
  60. dRzMaxHighEt=0.05,
  61. dRzMaxHighEtThres=30.0,
  62. dRzMaxLowEtGrad=-0.002,
  63. ),
  64. dict(
  65. dPhiMaxHighEt=0.003,
  66. dPhiMaxHighEtThres=0.0,
  67. dPhiMaxLowEtGrad=0.0,
  68. dRzMaxHighEt=0.05,
  69. dRzMaxHighEtThres=30.0,
  70. dRzMaxLowEtGrad=-0.002,
  71. )
  72. ],
  73. 'wide': [
  74. dict(
  75. dPhiMaxHighEt=0.10,
  76. dPhiMaxHighEtThres=20.0,
  77. dPhiMaxLowEtGrad=-0.002,
  78. dRzMaxHighEt=9999.0,
  79. dRzMaxHighEtThres=0.0,
  80. dRzMaxLowEtGrad=0.0,
  81. ),
  82. dict(
  83. dPhiMaxHighEt=0.006,
  84. dPhiMaxHighEtThres=0.0,
  85. dPhiMaxLowEtGrad=0.0,
  86. dRzMaxHighEt=0.10,
  87. dRzMaxHighEtThres=30.0,
  88. dRzMaxLowEtGrad=-0.002,
  89. ),
  90. dict(
  91. dPhiMaxHighEt=0.006,
  92. dPhiMaxHighEtThres=0.0,
  93. dPhiMaxLowEtGrad=0.0,
  94. dRzMaxHighEt=0.10,
  95. dRzMaxHighEtThres=30.0,
  96. dRzMaxLowEtGrad=-0.002,
  97. )
  98. ],
  99. 'extra-wide': [
  100. dict(
  101. dPhiMaxHighEt=0.15,
  102. dPhiMaxHighEtThres=20.0,
  103. dPhiMaxLowEtGrad=-0.002,
  104. dRzMaxHighEt=9999.0,
  105. dRzMaxHighEtThres=0.0,
  106. dRzMaxLowEtGrad=0.0,
  107. ),
  108. dict(
  109. dPhiMaxHighEt=0.009,
  110. dPhiMaxHighEtThres=0.0,
  111. dPhiMaxLowEtGrad=0.0,
  112. dRzMaxHighEt=0.15,
  113. dRzMaxHighEtThres=30.0,
  114. dRzMaxLowEtGrad=-0.002,
  115. ),
  116. dict(
  117. dPhiMaxHighEt=0.009,
  118. dPhiMaxHighEtThres=0.0,
  119. dPhiMaxLowEtGrad=0.0,
  120. dRzMaxHighEt=0.15,
  121. dRzMaxHighEtThres=30.0,
  122. dRzMaxLowEtGrad=-0.002,
  123. )
  124. ]
  125. }
  126. h = hist2d(getattr(rs, f'{variable}_{subdet}_L{layer}_H{hit}_v_Et'))
  127. def calc_window(et):
  128. idx = min(hit-1, 2)
  129. cuts = matching_cuts[cut_sel]
  130. high_et = cuts[idx][f'{variable}MaxHighEt']
  131. high_et_thres = cuts[idx][f'{variable}MaxHighEtThres']
  132. low_et_grad = cuts[idx][f'{variable}MaxLowEtGrad']
  133. return high_et + min(0, et-high_et_thres)*low_et_grad
  134. hist2d_plot(h, colorbar=True)
  135. xs, ys = hist2d_percent_contour(h, .90, 'x')
  136. plt.plot(xs, ys, color='green', label='90\% contour')
  137. xs, ys = hist2d_percent_contour(h, .995, 'x')
  138. plt.plot(xs, ys, color='darkgreen', label='99.5\% contour')
  139. if plot_cuts:
  140. ets = h[3][:, 0]
  141. cuts = [calc_window(et) for et in ets]
  142. plt.plot(cuts, ets, color='red', label='Cut Value')
  143. plt.legend(loc='upper right')
  144. plt.xlabel({'dPhi': r'$\delta \phi$ (rads)',
  145. 'dRz': r'$\delta R/z$ (cm)'}[variable])
  146. plt.ylabel('$E_T$ (GeV)')
  147. @decl_plot
  148. def plot_seed_eff(rs):
  149. r"""## ECAL-Driven Seeding Efficiency
  150. The proportion of gen-level electrons originating in the luminous region that have
  151. an associated Seed, matched via rechit-simhit associations in the pixel detector. Cuts are on simtrack quantities.
  152. """
  153. ax_pt = plt.subplot(221)
  154. ax_eta = plt.subplot(222)
  155. ax_phi = plt.subplot(223)
  156. errors = True
  157. plt.sca(ax_pt)
  158. hist_plot(hist(rs.seed_eff_v_pt), include_errors=errors)
  159. center_text(0.5, 0.3, r'$|\eta|<2.4$')
  160. plt.xlabel(r"Sim-Track $p_T$")
  161. plt.ylim((0, 1.1))
  162. plt.sca(ax_eta)
  163. hist_plot(hist(rs.seed_eff_v_eta), include_errors=errors)
  164. center_text(0.5, 0.3, r'$p_T>20$')
  165. plt.xlabel(r"Sim-Track $\eta$")
  166. plt.ylim((0, 1.1))
  167. plt.sca(ax_phi)
  168. hist_plot(hist(rs.seed_eff_v_phi), include_errors=errors)
  169. center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
  170. plt.xlabel(r"Sim-Track $\phi$")
  171. plt.ylim((0, 1.1))
  172. @decl_plot
  173. def plot_tracking_eff(rs):
  174. r"""## GSF Tracking Efficiency
  175. The proportion of electrons origination in the luminous region from the that have
  176. an associated GSF track. Cuts are on simtrack quantities.
  177. """
  178. ax_pt = plt.subplot(221)
  179. ax_eta = plt.subplot(222)
  180. ax_phi = plt.subplot(223)
  181. ax_eta_pt = plt.subplot(224)
  182. errors = True
  183. plt.sca(ax_pt)
  184. hist_plot(hist(rs.tracking_eff_v_pt), include_errors=errors)
  185. center_text(0.5, 0.3, r'$|\eta|<2.4$')
  186. plt.xlabel(r"Sim-Track $p_T$")
  187. plt.ylim((0, 1.1))
  188. plt.sca(ax_eta)
  189. hist_plot(hist(rs.tracking_eff_v_eta), include_errors=errors)
  190. center_text(0.5, 0.3, r'$p_T>20$')
  191. plt.xlabel(r"Sim-Track $\eta$")
  192. plt.ylim((0, 1.1))
  193. plt.sca(ax_phi)
  194. hist_plot(hist(rs.tracking_eff_v_phi), include_errors=errors)
  195. center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
  196. plt.xlabel(r"Sim-Track $\phi$")
  197. plt.ylim((0, 1.1))
  198. plt.sca(ax_eta_pt)
  199. hist2d_plot(hist2d(rs.tracking_eff_v_eta_pt))
  200. plt.xlabel(r"Sim-Track $\eta$")
  201. plt.ylabel(r"Sim-Track $p_T$")
  202. plt.colorbar()
  203. @decl_plot
  204. def plot_seed_purity(rs, ext=""):
  205. r"""## ECAL-Driven Seed Purity
  206. The proportion of ECAL-driven seeds that have a matched gen-level electron originating in
  207. the luminous region. Cuts are on seed quantities.
  208. """
  209. ax_pt = plt.subplot(221)
  210. ax_eta = plt.subplot(222)
  211. ax_phi = plt.subplot(223)
  212. def get_hist(base_name):
  213. return hist(getattr(rs, base_name+ext))
  214. errors = True
  215. plt.sca(ax_pt)
  216. hist_plot(get_hist("seed_pur_v_pt"), include_errors=errors)
  217. center_text(0.5, 0.3, r'$|\eta|<2.4$')
  218. plt.xlabel(r"Seed $p_T$")
  219. if not ext:
  220. plt.ylim((0, 1.1))
  221. plt.sca(ax_eta)
  222. hist_plot(get_hist("seed_pur_v_eta"), include_errors=errors)
  223. center_text(0.5, 0.3, r'$p_T>20$')
  224. plt.xlabel(r"Seed $\eta$")
  225. if not ext:
  226. plt.ylim((0, 1.1))
  227. plt.sca(ax_phi)
  228. hist_plot(get_hist("seed_pur_v_phi"), include_errors=errors)
  229. center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
  230. plt.xlabel(r"Seed $\phi$")
  231. if not ext:
  232. plt.ylim((0, 1.1))
  233. @decl_plot
  234. def plot_track_purity(rs, ext=""):
  235. r"""## GSF Track Purity
  236. The proportion of GSF-tracks w\ ECAL-driven seeds that have a matched gen-level electron originating in
  237. the luminous region. Cuts are on GSF track quantities.
  238. """
  239. ax_pt = plt.subplot(221)
  240. ax_eta = plt.subplot(222)
  241. ax_phi = plt.subplot(223)
  242. def get_hist( base_name):
  243. return hist(getattr(rs, base_name+ext))
  244. errors = True
  245. plt.sca(ax_pt)
  246. hist_plot(get_hist("tracking_pur_v_pt"), include_errors=errors)
  247. center_text(0.5, 0.3, r'$|\eta|<2.4$')
  248. plt.xlabel(r"GSF-Track $p_T$")
  249. plt.ylim((0, 1.1))
  250. plt.sca(ax_eta)
  251. hist_plot(get_hist("tracking_pur_v_eta"), include_errors=errors)
  252. center_text(0.5, 0.3, r'$p_T>20$')
  253. plt.xlabel(r"GSF-Track $\eta$")
  254. plt.ylim((0, 1.1))
  255. plt.sca(ax_phi)
  256. hist_plot(get_hist("tracking_pur_v_phi"), include_errors=errors)
  257. center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
  258. plt.xlabel(r"GSF-Track $\phi$")
  259. plt.ylim((0, 1.1))
  260. @decl_plot
  261. def plot_hit_vs_layer(rs, region):
  262. h = hist2d(getattr(rs, f'hit_vs_layer_{region}'))
  263. hist2d_plot(h, txt_format='{:2.0f}')
  264. plt.xlabel('Layer \#')
  265. plt.ylabel('Hit \#')
  266. def single_cut_plots(cut_sel):
  267. rs = ResultSet(f'{cut_sel}-window', f'../hists/{cut_sel}-window.root')
  268. seed_eff = plot_seed_eff, (rs,)
  269. tracking_eff = plot_tracking_eff, (rs,)
  270. seed_pur = plot_seed_purity, (rs,)
  271. track_pur = plot_track_purity, (rs,)
  272. track_pur_seed_match = plot_track_purity, (rs,), dict(ext='2')
  273. BPIX_residuals_L1_H1_dPhi = plot_residuals, (rs, 1, 1, 'dPhi', 'BPIX'), dict(cut_sel=cut_sel)
  274. BPIX_residuals_L2_H2_dPhi = plot_residuals, (rs, 2, 2, 'dPhi', 'BPIX'), dict(cut_sel=cut_sel)
  275. BPIX_residuals_L3_H3_dPhi = plot_residuals, (rs, 3, 3, 'dPhi', 'BPIX'), dict(cut_sel=cut_sel)
  276. BPIX_residuals_L1_H1_dRz = plot_residuals, (rs, 1, 1, 'dRz', 'BPIX'), {'plot_cuts': False}
  277. BPIX_residuals_L2_H2_dRz = plot_residuals, (rs, 2, 2, 'dRz', 'BPIX'), dict(cut_sel=cut_sel)
  278. BPIX_residuals_L3_H3_dRz = plot_residuals, (rs, 3, 3, 'dRz', 'BPIX'), dict(cut_sel=cut_sel)
  279. FPIX_residuals_L1_H1_dPhi = plot_residuals, (rs, 1, 1, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
  280. FPIX_residuals_L2_H2_dPhi = plot_residuals, (rs, 2, 2, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
  281. FPIX_residuals_L3_H3_dPhi = plot_residuals, (rs, 3, 3, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
  282. FPIX_residuals_L1_H1_dRz = plot_residuals, (rs, 1, 1, 'dRz', 'FPIX'), {'plot_cuts': False}
  283. FPIX_residuals_L2_H2_dRz = plot_residuals, (rs, 2, 2, 'dRz', 'FPIX'), dict(cut_sel=cut_sel)
  284. FPIX_residuals_L3_H3_dRz = plot_residuals, (rs, 3, 3, 'dRz', 'FPIX'), dict(cut_sel=cut_sel)
  285. FPIX_residuals_L1_H2_dPhi = plot_residuals, (rs, 1, 2, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
  286. FPIX_residuals_L1_H3_dPhi = plot_residuals, (rs, 1, 3, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
  287. FPIX_residuals_L2_H3_dPhi = plot_residuals, (rs, 2, 3, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
  288. FPIX_residuals_L1_H2_dRz = plot_residuals, (rs, 1, 2, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
  289. FPIX_residuals_L1_H3_dRz = plot_residuals, (rs, 1, 3, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
  290. FPIX_residuals_L2_H3_dRz = plot_residuals, (rs, 2, 3, 'dPhi', 'FPIX'), dict(cut_sel=cut_sel)
  291. hit_vs_layer_barrel = plot_hit_vs_layer, (rs, 'barrel')
  292. hit_vs_layer_forward = plot_hit_vs_layer, (rs, 'forward')
  293. plots = [
  294. Plot(BPIX_residuals_L1_H1_dPhi, 'Phi Residuals Layer 1 Hit 1 - BPIX'),
  295. Plot(BPIX_residuals_L2_H2_dPhi, 'Phi Residuals Layer 2 Hit 2 - BPIX'),
  296. Plot(BPIX_residuals_L3_H3_dPhi, 'Phi Residuals Layer 3 Hit 3 - BPIX'),
  297. Plot(BPIX_residuals_L1_H1_dRz, 'dZ Residuals Layer 1 Hit 1 w/o cuts - BPIX'),
  298. Plot(BPIX_residuals_L2_H2_dRz, 'dZ Residuals Layer 2 Hit 2 - BPIX'),
  299. Plot(BPIX_residuals_L3_H3_dRz, 'dZ Residuals Layer 3 Hit 3 - BPIX'),
  300. Plot(FPIX_residuals_L1_H1_dPhi, 'Phi Residuals Layer 1 Hit 1 - FPIX'),
  301. Plot(FPIX_residuals_L2_H2_dPhi, 'Phi Residuals Layer 2 Hit 2 - FPIX'),
  302. Plot(FPIX_residuals_L3_H3_dPhi, 'Phi Residuals Layer 3 Hit 3 - FPIX'),
  303. Plot(FPIX_residuals_L1_H1_dRz, 'dR Residuals Layer 1 Hit 1 w/o cuts - FPIX'),
  304. Plot(FPIX_residuals_L2_H2_dRz, 'dR Residuals Layer 2 Hit 2 - FPIX'),
  305. Plot(FPIX_residuals_L3_H3_dRz, 'dR Residuals Layer 3 Hit 3 - FPIX'),
  306. Plot(FPIX_residuals_L1_H2_dPhi, 'Phi Residuals Layer 1 Hit 2 - FPIX'),
  307. Plot(FPIX_residuals_L1_H3_dPhi, 'Phi Residuals Layer 1 Hit 3 - FPIX'),
  308. Plot(FPIX_residuals_L2_H3_dPhi, 'Phi Residuals Layer 2 Hit 3 - FPIX'),
  309. Plot(FPIX_residuals_L1_H2_dRz, 'dR Residuals Layer 1 Hit 2 - FPIX'),
  310. Plot(FPIX_residuals_L1_H3_dRz, 'dR Residuals Layer 1 Hit 3 - FPIX'),
  311. Plot(FPIX_residuals_L2_H3_dRz, 'dR Residuals Layer 2 Hit 3 - FPIX'),
  312. Plot(seed_eff, 'ECAL-Driven Seeding Efficiency'),
  313. Plot(tracking_eff, 'GSF Tracking Efficiency'),
  314. Plot(hit_vs_layer_barrel, 'Hit vs Layer - Barrel'),
  315. Plot(hit_vs_layer_forward, 'Hit vs Layer - Forward'),
  316. Plot(seed_pur, 'ECAL-Driven Seeding Purity'),
  317. Plot(track_pur, 'GSF Track Purity'),
  318. Plot(track_pur_seed_match , 'GSF Track Purity (Seed Truth Match)'),
  319. simple_plot(rs.gsf_tracks_nmatch_sim_tracks, log='y'),
  320. ]
  321. render_plots(plots, to_disk=False)
  322. generate_dashboard(plots, 'Seeding Efficiency',
  323. output=f'{rs.sample_name}.html',
  324. source=__file__,
  325. config=rs.config)
  326. @decl_plot
  327. def plot_seed_roc_curve(rss):
  328. def get_num_den(rs, basename):
  329. num = hist(getattr(rs, f'{basename}_num'))
  330. den = hist(getattr(rs, f'{basename}_den'))
  331. return hist_integral_ratio(num, den)
  332. for rs in rss:
  333. eff, eff_err = get_num_den(rs, 'seed_eff_v_phi')
  334. pur, pur_err = get_num_den(rs, 'seed_pur_v_phi')
  335. plt.errorbar([pur], [eff], xerr=[pur_err], yerr=[eff_err], label=rs.sample_name)
  336. center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
  337. plt.axis('equal')
  338. plt.xlim((0.8, 1.0))
  339. plt.ylim((0.8, 1.0))
  340. plt.xlabel('ECAL-Driven Seeding Purity')
  341. plt.ylabel('ECAL-Driven Seeding Efficiency')
  342. plt.grid()
  343. plt.legend()
  344. @decl_plot
  345. def plot_seed_eff_all(rss):
  346. ax_pt = plt.subplot(221)
  347. ax_eta = plt.subplot(222)
  348. ax_phi = plt.subplot(223)
  349. errors = True
  350. for rs in rss:
  351. plt.sca(ax_pt)
  352. hist_plot(hist(rs.seed_eff_v_pt), include_errors=errors, label=rs.sample_name)
  353. plt.sca(ax_eta)
  354. hist_plot(hist(rs.seed_eff_v_eta), include_errors=errors, label=rs.sample_name)
  355. plt.sca(ax_phi)
  356. hist_plot(hist(rs.seed_eff_v_phi), include_errors=errors, label=rs.sample_name)
  357. plt.sca(ax_pt)
  358. center_text(0.5, 0.3, r'$|\eta|<2.4$')
  359. plt.xlabel(r"Sim-Track $p_T$")
  360. plt.ylim((0, 1.1))
  361. plt.sca(ax_eta)
  362. center_text(0.5, 0.3, r'$p_T>20$')
  363. plt.xlabel(r"Sim-Track $\eta$")
  364. plt.ylim((0, 1.1))
  365. plt.legend(loc='lower right')
  366. plt.sca(ax_phi)
  367. center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
  368. plt.xlabel(r"Sim-Track $\phi$")
  369. plt.ylim((0, 1.1))
  370. @decl_plot
  371. def plot_seed_pur_all(rss):
  372. ax_pt = plt.subplot(221)
  373. ax_eta = plt.subplot(222)
  374. ax_phi = plt.subplot(223)
  375. errors = True
  376. for rs in rss:
  377. plt.sca(ax_pt)
  378. hist_plot(hist(rs.seed_pur_v_pt), include_errors=errors, label=rs.sample_name)
  379. plt.sca(ax_eta)
  380. hist_plot(hist(rs.seed_pur_v_eta), include_errors=errors, label=rs.sample_name)
  381. plt.sca(ax_phi)
  382. hist_plot(hist(rs.seed_pur_v_phi), include_errors=errors, label=rs.sample_name)
  383. plt.sca(ax_pt)
  384. center_text(0.5, 0.3, r'$|\eta|<2.4$')
  385. plt.xlabel(r"Seed $p_T$")
  386. plt.ylim((0, 1.1))
  387. plt.sca(ax_eta)
  388. center_text(0.5, 0.3, r'$p_T>20$')
  389. plt.xlabel(r"Seed $\eta$")
  390. plt.ylim((0, 1.1))
  391. plt.legend(loc='lower right')
  392. plt.sca(ax_phi)
  393. center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
  394. plt.xlabel(r"Seed $\phi$")
  395. plt.ylim((0, 1.1))
  396. @decl_plot
  397. def plot_tracking_roc_curve(rss, ext=''):
  398. def get_num_den(rs, basename):
  399. num = hist(getattr(rs, f'{basename}{ext}_num'))
  400. den = hist(getattr(rs, f'{basename}{ext}_den'))
  401. return hist_integral_ratio(num, den)
  402. for rs in rss:
  403. eff, eff_err = get_num_den(rs, 'tracking_eff_v_phi')
  404. pur, pur_err = get_num_den(rs, 'tracking_pur_v_phi')
  405. plt.errorbar([pur], [eff], xerr=[pur_err], yerr=[eff_err], label=rs.sample_name)
  406. center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
  407. plt.axis('equal')
  408. plt.xlim((0.8, 1.0))
  409. plt.ylim((0.8, 1.0))
  410. plt.xlabel('GSF-Track Purity')
  411. plt.ylabel('GSF-Track Efficiency')
  412. plt.grid()
  413. plt.legend()
  414. @decl_plot
  415. def plot_tracking_eff_all(rss, ext=''):
  416. ax_pt = plt.subplot(221)
  417. ax_eta = plt.subplot(222)
  418. ax_phi = plt.subplot(223)
  419. errors = True
  420. for rs in rss:
  421. plt.sca(ax_pt)
  422. hist_plot(hist(getattr(rs, f'tracking_eff_v_pt{ext}')), include_errors=errors, label=rs.sample_name)
  423. plt.sca(ax_eta)
  424. hist_plot(hist(getattr(rs, f'tracking_eff_v_eta{ext}')), include_errors=errors, label=rs.sample_name)
  425. plt.sca(ax_phi)
  426. hist_plot(hist(getattr(rs, f'tracking_eff_v_phi{ext}')), include_errors=errors, label=rs.sample_name)
  427. plt.sca(ax_pt)
  428. center_text(0.5, 0.3, r'$|\eta|<2.4$')
  429. plt.xlabel(r"Sim-Track $p_T$")
  430. plt.ylim((0, 1.1))
  431. plt.sca(ax_eta)
  432. center_text(0.5, 0.3, r'$p_T>20$')
  433. plt.xlabel(r"Sim-Track $\eta$")
  434. plt.ylim((0, 1.1))
  435. plt.legend(loc='lower right')
  436. plt.sca(ax_phi)
  437. center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
  438. plt.xlabel(r"Sim-Track $\phi$")
  439. plt.ylim((0, 1.1))
  440. @decl_plot
  441. def plot_tracking_pur_all(rss, ext=''):
  442. ax_pt = plt.subplot(221)
  443. ax_eta = plt.subplot(222)
  444. ax_phi = plt.subplot(223)
  445. errors = True
  446. for rs in rss:
  447. plt.sca(ax_pt)
  448. hist_plot(hist(getattr(rs, f'tracking_pur_v_pt{ext}')), include_errors=errors, label=rs.sample_name)
  449. plt.sca(ax_eta)
  450. hist_plot(hist(getattr(rs, f'tracking_pur_v_eta{ext}')), include_errors=errors, label=rs.sample_name)
  451. plt.sca(ax_phi)
  452. hist_plot(hist(getattr(rs, f'tracking_pur_v_phi{ext}')), include_errors=errors, label=rs.sample_name)
  453. plt.sca(ax_pt)
  454. center_text(0.5, 0.3, r'$|\eta|<2.4$')
  455. plt.xlabel(r"GSF-Track $p_T$")
  456. plt.ylim((0, 1.1))
  457. plt.sca(ax_eta)
  458. center_text(0.5, 0.3, r'$p_T>20$')
  459. plt.xlabel(r"GSF-Track $\eta$")
  460. plt.ylim((0, 1.1))
  461. plt.legend(loc='lower right')
  462. plt.sca(ax_phi)
  463. center_text(0.5, 0.3, r'$p_T>20$ and $|\eta|<2.4$')
  464. plt.xlabel(r"GSF-Track $\phi$")
  465. plt.ylim((0, 1.1))
  466. @decl_plot
  467. def plot_ecal_rel_res(rss):
  468. for rs in rss:
  469. hist_plot(hist(rs.ecal_energy_resolution), label=rs.sample_name)
  470. plt.xlabel(r"ECAL $E_T$ relative error")
  471. plt.legend()
  472. def all_cut_plots(cuts):
  473. rss = [ResultSet(f'{cut_sel}-window', f'../hists/{cut_sel}-window.root') for cut_sel in cuts]
  474. tracking_roc_curve = plot_tracking_roc_curve, (rss,)
  475. tracking_eff_all = plot_tracking_eff_all, (rss,)
  476. tracking_pur_all = plot_tracking_pur_all, (rss,)
  477. tracking_roc_curve2 = plot_tracking_roc_curve, (rss, '2')
  478. tracking_eff_all2 = plot_tracking_eff_all, (rss, '2')
  479. tracking_pur_all2 = plot_tracking_pur_all, (rss, '2')
  480. seed_roc_curve = plot_seed_roc_curve, (rss,)
  481. seed_eff_all = plot_seed_eff_all, (rss,)
  482. seed_pur_all = plot_seed_pur_all, (rss,)
  483. ecal_rel_res = plot_ecal_rel_res, (rss,)
  484. plots = [
  485. Plot(tracking_roc_curve, 'Tracking ROC Curve'),
  486. Plot(tracking_eff_all, 'Tracking Efficiency'),
  487. Plot(tracking_pur_all, 'Tracking Purity'),
  488. Plot(tracking_roc_curve2, 'Tracking ROC Curve (Seed Matched)'),
  489. Plot(tracking_eff_all2, 'Tracking Efficiency (Seed Matched)'),
  490. Plot(tracking_pur_all2, 'Tracking Purity (Seed Matched)'),
  491. Plot(seed_roc_curve, 'Seeding ROC Curve'),
  492. Plot(seed_eff_all, 'ECAL-Driven Seeding Efficiency'),
  493. Plot(seed_pur_all, 'ECAL-Driven Seeding Purity'),
  494. Plot(ecal_rel_res, 'ECAL ET Relative Resolution'),
  495. ]
  496. render_plots(plots, to_disk=False)
  497. generate_dashboard(plots, 'Comparisons',
  498. output='comparisons.html',
  499. source=__file__,
  500. config=rss[0].config)
  501. if __name__ == '__main__':
  502. cuts = ['extra-narrow', 'narrow', 'wide', 'extra-wide']
  503. all_cut_plots(cuts)
  504. for cut in cuts:
  505. single_cut_plots(cut)