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.

45 lines
1.3 KiB

10 months ago
10 months ago
10 months ago
  1. # flake8: noqa
  2. import ROOT
  3. def preselection(
  4. cuts: str = "",
  5. input_file: str = None,
  6. outfile_postfix: str = "selected",
  7. tree_name: str = "PrParameterisationData_2ece6184.PrDebugTrackingTool/Tuple",
  8. ) -> str:
  9. """Function that apply a selection to given data.
  10. Args:
  11. cuts (str, optional): String specifying the selection. Defaults to "".
  12. input_file (str, optional): Defaults to None.
  13. outfile_postfix (str, optional): Defaults to "selected".
  14. tree_name (str, optional): Defaults to "PrParameterisationData_2ece6184.PrDebugTrackingTool/Tuple".
  15. Returns:
  16. str: Path to the output file.
  17. """
  18. rdf = ROOT.RDataFrame(tree_name, input_file)
  19. rdf = rdf.Filter(cuts, "Selection")
  20. out_file = input_file.strip(".root") + f"_{outfile_postfix}.root"
  21. rdf.Snapshot("Selected", out_file)
  22. return out_file
  23. if __name__ == "__main__":
  24. import argparse
  25. parser = argparse.ArgumentParser()
  26. parser.add_argument(
  27. "--input-file",
  28. type=str,
  29. help="Path to the input file",
  30. )
  31. parser.add_argument(
  32. "--cuts",
  33. type=str,
  34. default="chi2_comb < 5 && pt > 10 && p > 1500 && p < 100000 && pid != 11",
  35. help="Cuts of the preselection",
  36. )
  37. args = parser.parse_args()
  38. preselection(**vars(args))