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.

76 lines
2.7 KiB

  1. import os
  2. import dotenv
  3. import sys
  4. import argparse
  5. import pandas as pd
  6. import mplhep
  7. import zfit
  8. from prettytable import PrettyTable
  9. dotenv.load_dotenv('../properties.env')
  10. sys.path.insert(0, os.getenv('SYS_PATH'))
  11. from b2kstll.models.angular import B2Kstll
  12. from b2kstll.plot import plot_distributions
  13. from hep_analytics.processing.extract import FileManager
  14. from hep_analytics.processing.transform import select_feature
  15. FILE_MC = os.getenv('MC_FILE')
  16. def main():
  17. parser = argparse.ArgumentParser()
  18. parser.add_argument('--q2bin', dest ='q2bin', default = 0)
  19. args = parser.parse_args()
  20. Q2BIN = int(args.q2bin)
  21. mplhep.style.use("LHCb2")
  22. 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)]
  23. print(f"Selected Q2 Bin Range is {bin_ranges[Q2BIN]}")
  24. filemanager = FileManager(file = FILE_MC, tree = "Events", branches = ["q2", "costhetak", "costhetal", "phi"])
  25. mc_data = filemanager.extract_data()
  26. q2_mc, theta_k_mc, theta_l_mc, phi_mc = mc_data[0], mc_data[1], mc_data[2], mc_data[3]
  27. q2_mc, indices = select_feature(feature = q2_mc, limits = bin_ranges[Q2BIN])
  28. phi_mc = phi_mc[indices]
  29. theta_l_mc = theta_l_mc[indices]
  30. theta_k_mc = theta_k_mc[indices]
  31. lower_costhetak_cut = float(os.getenv('LOWER_COSTHETAK_CUT'))
  32. upper_costhetak_cut = float(os.getenv('UPPER_COSTHETAK_CUT'))
  33. theta_k_mc, indices = select_feature(feature = theta_k_mc, limits = (lower_costhetak_cut, upper_costhetak_cut))
  34. q2_mc = q2_mc[indices]
  35. phi_mc = phi_mc[indices]
  36. theta_l_mc = theta_l_mc[indices]
  37. angular_data = pd.DataFrame({'ctl': theta_l_mc, 'ctk': theta_k_mc, 'phi': phi_mc})
  38. angular_data.to_csv(f"ang_fit_mc_{Q2BIN}_bin.csv", index = False)
  39. x = B2Kstll('ctl','ctk','phi')
  40. x.set_acc(f"./acc_3d_JpsiKstMC_{Q2BIN}_bin.yaml")
  41. obs, pdf, params = x.get_pdf('PWave')
  42. datazfit = zfit.Data.from_pandas(df = angular_data, obs = obs)
  43. nll = zfit.loss.UnbinnedNLL(model = pdf, data = datazfit)
  44. minimizer = zfit.minimize.Minuit()
  45. result = minimizer.minimize(nll)
  46. param_errors, _ = result.errors()
  47. print(param_errors)
  48. info_table = PrettyTable(["Variable", "Value", "Lower Error", "Upper Error"])
  49. fit_labels = ["AFB", "FL", "S3", "S4", "S5", "S7", "S8", "S9"]
  50. for name in fit_labels:
  51. value = result.params[name]["value"]
  52. lower = result.params[name]["minuit_minos"]["lower"]
  53. upper = result.params[name]["minuit_minos"]["upper"]
  54. info_table.add_row([name, value, lower, upper])
  55. print(info_table)
  56. plot_distributions(result, suffix = f"accPwavePDF_mc_ang_fit_{Q2BIN}_bin")
  57. if __name__ == "__main__":
  58. main()