13from pathlib
import Path
17import matplotlib.pyplot
as plt
19from prompt
import ValidationSettings
25r.PyConfig.IgnoreCommandLineOptions =
True
29plt.style.use(
"belle2")
32settings = ValidationSettings(name=
"Full VXD and CDC Alignment",
39 '''job_path will be replaced with path/to/calibration_results
40 input_data_path will be replaced with path/to/data_path used for calibration
41 e.g. /group/belle2/dataprod/Data/PromptSkim/'''
43 collector_output_dir_cosmic = Path(job_path) /
'VXDCDCalignment_validation/0/collector_output/cosmic/'
44 collector_output_dir_mumu = Path(job_path) /
'VXDCDCalignment_validation/0/collector_output/mumu/'
46 output_dir = Path(kwargs.get(
'output_dir',
'VXDCDCAlignmentValidation_output'))
48 output_dir.mkdir(parents=
True, exist_ok=
True)
50 pattern_cosmic = str(collector_output_dir_cosmic) +
"/*/cosmic_ana.root"
51 pattern_mumu = str(collector_output_dir_mumu) +
"/*/dimuon_ana.root"
53 def hadd_and_get_merged_file(filenames_pattern, input_type):
54 root_files = glob(filenames_pattern)
55 merged_file = output_dir / f
"{input_type}.root"
57 if len(root_files) > 1:
58 os.system(f
"hadd -f {merged_file} {' '.join(root_files)}")
59 elif len(root_files) == 1:
60 os.system(f
"cp {root_files[0]} {merged_file}")
62 raise FileNotFoundError(f
"No root files found for pattern: {filenames_pattern}")
64 return str(merged_file)
66 cosmic_file = hadd_and_get_merged_file(pattern_cosmic,
"cosmics")
67 mumu_file = hadd_and_get_merged_file(pattern_mumu,
"dimuon")
69 print(f
"Merged ntuples saved in {cosmic_file} and {mumu_file}")
70 print(
"Running validation...")
72 cosmicval.run_validation([cosmic_file], output_dir=str(output_dir /
"cosmics/"))
73 dimuonval.run_validation([mumu_file], output_dir=str(output_dir /
"dimuon/"))
76 histo_pattern_cosmic = str(collector_output_dir_cosmic) +
"/*/CollectorOutput.root"
77 histo_pattern_mumu = str(collector_output_dir_mumu) +
"/*/CollectorOutput.root"
79 histo_cosmic = hadd_and_get_merged_file(histo_pattern_cosmic,
"cosmic_CollectorOutput")
80 histo_mumu = hadd_and_get_merged_file(histo_pattern_mumu,
"dimuon_CollectorOutput")
82 print(f
"Merged CollectorOutput histograms saved in {histo_cosmic} and {histo_mumu}")
84 print(
"Alignment validation completed.")
87if __name__ ==
'__main__':
88 parser = argparse.ArgumentParser(description=__doc__,
89 formatter_class=argparse.RawTextHelpFormatter)
94 parser.add_argument(
'calibration_results_dir',
95 help=
'The directory that contains the collector outputs',
98 parser.add_argument(
'-o',
'--output_dir',
99 help=
'The directory where all the output will be saved',
100 default=
'VXDCDCAlignmentValidation_output')
101 args = parser.parse_args()
103 run_validation(args.calibration_results_dir[0], output_dir=args.output_dir)