77 parser = argparse.ArgumentParser(description="NTUPLE PHYSVAL Histogram Post-processing Tool")
78 parser.add_argument("files", nargs="*", help="Input ROOT file and optionally output file name")
79 parser.add_argument("--domain", type=str, help="Specific domain to process (e.g., Electron, Photon, BTag)")
80 parser.add_argument("--crash_on_error", action="store_true", help="Crash on first error instead of just warning")
81 args = parser.parse_args()
82
83 physvalPostProcessingTools.crash_on_error = args.crash_on_error
84
85 if len(args.files) == 1:
86 input_file = args.files[0]
87 output_file = os.path.splitext(input_file)[0] + "_after_post_process.root"
88 elif len(args.files) == 2:
89 input_file, output_file = args.files
90 else:
91 logging.error("You must provide 1 or 2 positional arguments: <input_file> [output_file]")
92 exit(1)
93
94 config_manager = ConfigManager()
95 config_manager.add_configuration("Electron", electron_config)
96 config_manager.add_configuration("Photon", photon_config)
97 config_manager.add_configuration("BTag", btag_config)
98
99 logging.info(f"Input: {input_file}")
100 logging.info(f"Output: {output_file}")
101
102 root_file = create_output_file(input_file, output_file)
103 if not root_file:
104 exit(1)
105
106 logging.info("Post Processing started...")
107 if args.domain:
108 process_domain(root_file, config_manager.get_config(args.domain), args.domain)
109 else:
110 for domain, domain_config in config_manager.get_all_configs():
111 process_domain(root_file, domain_config, domain)
112
113 try:
114 root_file.Close()
115 logging.info(f"Postprocessing complete. Output saved to: {output_file}")
116 except Exception as e:
117 logging.error(f"Failed to close ROOT file: {e}")
118 exit(1)
119