EGamma_TrackingValidation.py 5.5 KB

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