5if __name__ ==
"__main__":
6 parser = argparse.ArgumentParser(description=
'Sample TFlaT training data')
11 help=
'Path to directory where sampled root files will be saved to'
17 help=
'Path to directory where .mdst (.root) files are stored'
21 dest=
'uniqueIdentifier',
23 default=
"TFlaT_Belle_light_2601_hyperion",
24 help=
'Name of both the config .yaml to be used and the produced weightfile'
31 help=
'If True, sample .mdst files with Belle MC'
39 help=
'Sampler channel: nunu or jpsiks'
42 args, _ = parser.parse_known_args()
43 output_dir = args.output_dir
44 input_dir = args.input_dir
45 uniqueIdentifier = args.uniqueIdentifier
46 is_belle = args.is_belle
47 channel = args.channel
51 files = sorted(glob.glob(os.path.join(input_dir,
"*.mdst")))
53 files = sorted(glob.glob(os.path.join(input_dir,
"*.root")))
55 print(f
"Found {len(files)} files for sampling")
57 log_dir = os.path.join(output_dir,
'logs')
59 os.makedirs(log_dir, exist_ok=
True)
62 for sampler_id, file
in enumerate(files):
65 output_file_name = os.path.join(output_dir, uniqueIdentifier + f
'_training_data{sampler_id}.root')
66 log_file_name = f
'{log_dir}/{uniqueIdentifier}_{sampler_id}.log'
67 if os.path.isfile(output_file_name)
and os.path.isfile(log_file_name):
68 with open(log_file_name,
'r')
as log_file:
69 content = log_file.read()
70 if '\nSuccessfully completed.\n' in content:
73 if os.path.isfile(log_file_name):
74 os.remove(log_file_name)
77 if os.path.isfile(output_file_name):
78 os.remove(output_file_name)
82 f
'bsub -q s -o {log_file_name} python3 sampler.py --uniqueIdentifier {uniqueIdentifier}'
83 f
' --inputfile {file} --working_dir {output_dir} --BELLE {str(is_belle)} --sampler_id {sampler_id}'
84 f
' --channel {channel}')
88 if njobs == len(files):
89 print(f
"Submitted {njobs} jobs to queue to create {njobs} output files")
91 print(f
"Submitted {njobs} jobs to queue to create {njobs} missing output files."
92 f
" {len(files)-njobs} existing files skipped.")