Angular analysis of B+->K*+(K+pi0)mumu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
3.0 KiB

  1. import os
  2. import dotenv
  3. import sys
  4. import argparse
  5. import mplhep
  6. import numpy as np
  7. import pandas as pd
  8. import matplotlib.pyplot as plt
  9. dotenv.load_dotenv('../properties.env')
  10. sys.path.insert(0, os.getenv('SYS_PATH'))
  11. from analysis.efficiency import get_efficiency_model_class
  12. from hep_analytics.processing.extract import FileManager
  13. from hep_analytics.processing.transform import select_feature
  14. FILE_MC_PHSP = os.getenv('MC_PHSP_FILE')
  15. def main():
  16. parser = argparse.ArgumentParser()
  17. parser.add_argument('--q2bin', dest ='q2bin', default = 0)
  18. args = parser.parse_args()
  19. Q2BIN = int(args.q2bin)
  20. mplhep.style.use("LHCb2")
  21. bin_ranges = [(0.25, 4.00), (4.00, 8.00), (11.00, 12.50), (15.00, 18.00), (1.10, 6.00), (1.1, 2.5), (2.5, 4.0), (4.0, 6.0), (6.0, 8.0)]
  22. print(f"Selected Q2 Bin Range is {bin_ranges[Q2BIN]}")
  23. filemanager = FileManager(file = FILE_MC_PHSP, tree = "Events", branches = ["q2", "costhetak", "costhetal", "phi"])
  24. mc_phsp_data = filemanager.extract_data()
  25. q2_mc_phsp, theta_k_mc_phsp, theta_l_mc_phsp, phi_mc_phsp = mc_phsp_data[0], mc_phsp_data[1], mc_phsp_data[2], mc_phsp_data[3]
  26. q2_mc_phsp, indices = select_feature(feature = q2_mc_phsp, limits = bin_ranges[Q2BIN])
  27. phi_mc_phsp = phi_mc_phsp[indices]
  28. theta_l_mc_phsp = theta_l_mc_phsp[indices]
  29. theta_k_mc_phsp = theta_k_mc_phsp[indices]
  30. lower_costhetak_cut = float(os.getenv('LOWER_COSTHETAK_CUT'))
  31. upper_costhetak_cut = float(os.getenv('UPPER_COSTHETAK_CUT'))
  32. theta_k_mc_phsp, indices = select_feature(feature = theta_k_mc_phsp, limits = (lower_costhetak_cut, upper_costhetak_cut))
  33. q2_mc_phsp = q2_mc_phsp[indices]
  34. phi_mc_phsp = phi_mc_phsp[indices]
  35. theta_l_mc_phsp = theta_l_mc_phsp[indices]
  36. data_mc_phsp = [phi_mc_phsp, theta_l_mc_phsp, theta_k_mc_phsp, q2_mc_phsp]
  37. df = pd.DataFrame({'ctl': data_mc_phsp[1], 'ctk': data_mc_phsp[2], 'phi': data_mc_phsp[0], 'q2': q2_mc_phsp})
  38. orders = {"ctl": 4, "ctk": 6, "phi": 2}
  39. ranges = {"ctl": [-1.0, 1.0], "ctk": [lower_costhetak_cut, upper_costhetak_cut], "phi": [-np.pi, np.pi]}
  40. EffClass = get_efficiency_model_class('legendre')
  41. eff = EffClass.fit(df, ['ctl', 'ctk', 'phi'], ranges = ranges,
  42. legendre_orders = orders, calculate_cov = False, chunk_size = 2000)
  43. out_file = eff.write_to_disk(f'acc_3d_JpsiKstMC_{Q2BIN}_bin.yaml')
  44. print(out_file)
  45. labels = {'ctl': r'$\cos \theta_L$', 'ctk': r'$\cos \theta_K$', 'phi': '$\phi$', 'q2': '$q^2$ [GeV$^2$]'}
  46. for v in ['ctl', 'ctk', 'phi']:
  47. plt.subplots(figsize = (15, 10))
  48. plt.xlim(*ranges[v])
  49. x, y = eff.project_efficiency(v, n_points = 1000)
  50. plt.plot(x, y, 'b-')
  51. plt.hist(df[v], density = True, bins = 50, color = 'grey', alpha = 0.5)
  52. plt.ylabel("a.u.", horizontalalignment = 'right', y = 1.0)
  53. plt.xlabel(labels[v], horizontalalignment = 'right', x = 1.0)
  54. plt.savefig(f'acc_3d_JpsiKstMC_phsp_mc_{v}_{Q2BIN}_bin.pdf')
  55. plt.close()
  56. if __name__ == "__main__":
  57. main()