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.

44 lines
1.3 KiB

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