18 from __future__
import print_function
24 import Alignment.MillePedeAlignmentAlgorithm.mpslib.tools
as mps_tools
25 import Alignment.MillePedeAlignmentAlgorithm.mpslib.Mpslibclass
as mpslib
30 """Main routine of the script.
33 - `argv`: arguments passed to the main routine
39 parser = argparse.ArgumentParser(description=
"Analysis pede histogram file")
40 parser.add_argument(
"-d",
"--mps-db", dest=
"mps_db", required=
True,
41 metavar=
"PATH", help=
"MPS database file ('mps.db')")
42 parser.add_argument(
"--his", dest=
"his_file", required=
True,
43 metavar=
"PATH", help=
"pede histogram file")
44 parser.add_argument(
"-c",
"--cfg", dest=
"cfg", metavar=
"PATH", required=
True,
45 help=
"python configuration file of pede job")
46 parser.add_argument(
"-b",
"--no-binary-check", dest=
"no_binary_check",
47 default=
False, action=
"store_true",
48 help=(
"skip check for existing binaries "
49 "(possibly needed if used interactively)"))
50 args = parser.parse_args(argv)
53 for input_file
in (args.mps_db, args.his_file, args.cfg):
54 if not os.path.exists(input_file):
55 print(
"Could not find input file:", input_file)
62 if len(his_data) != len(used_binaries):
63 print(
"The number of used binaries is", len(used_binaries), end=
' ')
64 print(
"whereas in contrast, however, the <chi2/ndf> histogram in Pede has", end=
' ')
65 print(len(his_data),
"bins (Pede version >= rev92 might help if #bins < #binaries).", end=
' ')
69 with open(
"chi2pedehis.txt",
"w")
as f:
70 for i, b
in enumerate(used_binaries):
73 f.write(
" ".
join([name,
"{:03d}".
format(b), his_data[i]])+
"\n")
78 """Returns two lists containing the mille job IDs and the associated names.
81 - `mps_db`: path to the MPS database file
84 lib = mpslib.jobdatabase()
87 ids = lib.JOBNUMBER[:lib.nJobs]
88 names = lib.JOBSP3[:lib.nJobs]
94 """Returns list of used binary IDs.
97 - `cfg`: python config used to run the pede job
98 - `no_binary_check`: if 'True' a check for file existence is skipped
101 cms_process = mps_tools.get_process_object(cfg)
103 binaries = cms_process.AlignmentProducer.algoConfig.mergeBinaryFiles
105 used_binaries = binaries
108 used_binaries = [b
for b
in binaries
109 if os.path.exists(os.path.join(os.path.dirname(cfg), b))]
111 used_binaries = [
int(re.sub(
r"milleBinary(\d+)\.dat",
r"\1", b))
112 for b
in used_binaries]
118 """Parse the pede histogram file.
121 - `his_file`: pede histogram file
125 with open(his_file,
"r")
as his:
126 found_chi2_start =
False;
129 if r"final <Chi^2/Ndf> from accepted local fits vs file number" in line:
130 found_chi2_start =
True
131 if not found_chi2_start:
134 if r"end of xy-data" in line:
break
135 if not re.search(
"\d", line):
continue
136 if re.search(
r"[a-z]", line):
continue
137 splitted = line.split()
138 his_data.append(splitted[-1])
144 if __name__ ==
"__main__":