hit_resolution_plots.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. # coding: utf-8
  2. import os
  3. import sys
  4. import matplotlib as mpl
  5. import matplotlib.pyplot as plt
  6. sys.path.append("../filval/python/")
  7. from utils import ResultSet
  8. from plotter import plot_histogram, plot_histogram2d
  9. mpl.rc('text', usetex=True)
  10. mpl.rc('savefig', dpi=180)
  11. mpl.rc('savefig', transparent=True)
  12. # First create a ResultSet object which loads all of the objects from output.root
  13. # into memory and makes them available as attributes
  14. rs = ResultSet("DY2LL", "/home/caleb/Sources/EGamma/build/output.root")
  15. try:
  16. os.mkdir('figures')
  17. except FileExistsError:
  18. pass
  19. scale = 0.85
  20. plt.figure(figsize=(scale*10, scale*10))
  21. plt.subplot(321)
  22. plot_histogram2d(rs.dphi_v_eta_first_hits_in_B1,
  23. ylabel="$\\Delta \\phi_1$(rad)",
  24. title="BPIX - Layer 1")
  25. plt.subplot(322)
  26. plot_histogram2d(rs.dphi_v_eta_first_hits_in_B2,
  27. title="BPIX - Layer 2")
  28. plt.subplot(323)
  29. plot_histogram2d(rs.dz_v_eta_first_hits_in_B1,
  30. ylabel="$\\Delta \\textrm{z}_1$(cm)")
  31. plt.subplot(324)
  32. plot_histogram2d(rs.dz_v_eta_first_hits_in_B2)
  33. plt.subplot(325)
  34. plot_histogram2d(rs.dr_v_eta_first_hits_in_B1,
  35. ylabel="$\\Delta r_1$(cm)",
  36. xlabel="$\\eta$")
  37. plt.subplot(326)
  38. plot_histogram2d(rs.dr_v_eta_first_hits_in_B2,
  39. xlabel="$\\eta$")
  40. plt.tight_layout()
  41. plt.savefig("figures/first_hits_v_eta.png")
  42. plt.clf()
  43. plt.subplot(321)
  44. plot_histogram2d(rs.dphi_v_eta_second_hits_in_B2,
  45. ylabel="$\\Delta \\phi_2$(rad)",
  46. title="BPIX - Layer 2")
  47. plt.subplot(322)
  48. plot_histogram2d(rs.dphi_v_eta_second_hits_in_B3,
  49. title="BPIX - Layer 3")
  50. plt.subplot(323)
  51. plot_histogram2d(rs.dz_v_eta_second_hits_in_B2,
  52. ylabel="$\\Delta \\textrm{z}_2$(cm)")
  53. plt.subplot(324)
  54. plot_histogram2d(rs.dz_v_eta_second_hits_in_B3)
  55. plt.subplot(325)
  56. plot_histogram2d(rs.dr_v_eta_second_hits_in_B2,
  57. ylabel="$\\Delta r_2$(cm)",
  58. xlabel="$\\eta$")
  59. plt.subplot(326)
  60. plot_histogram2d(rs.dr_v_eta_second_hits_in_B3,
  61. xlabel="$\\eta$")
  62. plt.tight_layout()
  63. plt.savefig("figures/second_hits_v_eta.png")
  64. plt.clf()
  65. plt.subplot(321)
  66. plot_histogram(rs.dphi_v_eta_first_hits_in_B1.ProjectionY(),
  67. include_errors=True, xlabel="$\\Delta \\phi_1$(rad)",
  68. title="BPIX - Layer 1")
  69. plt.subplot(322)
  70. plot_histogram(rs.dphi_v_eta_first_hits_in_B2.ProjectionY(), include_errors=True,
  71. xlabel="$\\Delta \\phi_1$(rad)",
  72. title="BPIX - Layer 2")
  73. plt.subplot(323)
  74. plot_histogram(rs.dz_v_eta_first_hits_in_B1.ProjectionY(), include_errors=True,
  75. xlabel="$\\Delta z_1$(cm)")
  76. plt.subplot(324)
  77. plot_histogram(rs.dz_v_eta_first_hits_in_B2.ProjectionY(), include_errors=True,
  78. xlabel="$\\Delta z_1$(cm)")
  79. plt.subplot(325)
  80. plot_histogram(rs.dr_v_eta_first_hits_in_B1.ProjectionY(), include_errors=True,
  81. xlabel="$\\Delta r_1$(cm)")
  82. plt.subplot(326)
  83. plot_histogram(rs.dr_v_eta_first_hits_in_B2.ProjectionY(), include_errors=True,
  84. xlabel="$\\Delta r_1$(cm)")
  85. plt.tight_layout()
  86. plt.savefig("figures/first_hits.png")
  87. plt.clf()
  88. plt.subplot(321)
  89. plot_histogram(rs.dphi_v_eta_second_hits_in_B2.ProjectionY(), include_errors=True,
  90. xlabel="$\\Delta \\phi_2$(rad)",
  91. title="BPIX - Layer 2")
  92. plt.subplot(322)
  93. plot_histogram(rs.dphi_v_eta_second_hits_in_B3.ProjectionY(), include_errors=True,
  94. xlabel="$\\Delta \\phi_2$(rad)",
  95. title="BPIX - Layer 3")
  96. plt.subplot(323)
  97. plot_histogram(rs.dz_v_eta_second_hits_in_B2.ProjectionY(), include_errors=True,
  98. xlabel="$\\Delta z_2$(cm)")
  99. plt.subplot(324)
  100. plot_histogram(rs.dz_v_eta_second_hits_in_B3.ProjectionY(), include_errors=True,
  101. xlabel="$\\Delta z_2$(cm)")
  102. plt.subplot(325)
  103. plot_histogram(rs.dr_v_eta_second_hits_in_B2.ProjectionY(), include_errors=True,
  104. xlabel="$\\Delta r_2$(cm)")
  105. plt.subplot(326)
  106. plot_histogram(rs.dr_v_eta_second_hits_in_B3.ProjectionY(), include_errors=True,
  107. xlabel="$\\Delta r_2$(cm)")
  108. plt.tight_layout()
  109. plt.savefig("figures/second_hits.png")
  110. def even_odd_plot(even, odd, var, scale, unit, **kwargs):
  111. even_dist = even.ProjectionY()
  112. odd_dist = odd.ProjectionY()
  113. plot_histogram(even_dist, include_errors=True, label="even ladders")
  114. plot_histogram(odd_dist, include_errors=True, color='r', label="odd ladders",
  115. **kwargs)
  116. even_mean = even_dist.GetMean()*scale
  117. odd_mean = odd_dist.GetMean()*scale
  118. axes = plt.gca()
  119. txt = r"$ \hat{{\Delta {0} }}_{{1,\textrm{{ {1} }} }}={2:4.2g}${3}"
  120. axes.text(0.05, .7, txt.format(var, "odd", odd_mean, unit), transform=axes.transAxes)
  121. axes.text(0.05, .6, txt.format(var, "even", even_mean, unit), transform=axes.transAxes)
  122. plt.clf()
  123. plt.subplot(221)
  124. even_odd_plot(rs.dphi_v_eta_first_hits_in_B1_even_ladder, rs.dphi_v_eta_first_hits_in_B1_odd_ladder,
  125. r"\phi", 10**6, "urad", xlabel=r"$\Delta \phi_1$(rad)", title="BPIX - Layer 1")
  126. plt.subplot(222)
  127. even_odd_plot(rs.dphi_v_eta_first_hits_in_B2_even_ladder, rs.dphi_v_eta_first_hits_in_B2_odd_ladder,
  128. r"\phi", 10**6, "urad", xlabel=r"$\Delta \phi_1$(rad)", title="BPIX - Layer 2")
  129. plt.legend()
  130. plt.subplot(223)
  131. even_odd_plot(rs.dz_v_eta_first_hits_in_B1_even_ladder, rs.dz_v_eta_first_hits_in_B1_odd_ladder,
  132. "z", 10**4, "um", xlabel=r"$\Delta z_1$(cm)")
  133. plt.subplot(224)
  134. even_odd_plot(rs.dz_v_eta_first_hits_in_B2_even_ladder, rs.dz_v_eta_first_hits_in_B2_odd_ladder,
  135. "z", 10**4, "um", xlabel=r"$\Delta z_1$(cm)")
  136. plt.tight_layout()
  137. plt.savefig("figures/delta_phi_z_v_ladder.png")