23 import Alignment.MillePedeAlignmentAlgorithm.mpslib.Mpslibclass
as mpslib
28 """Main routine of the script.
31 - `argv`: arguments passed to the main routine
38 parser.add_argument(
"-d",
"--mps-db", dest=
"mps_db", required=
True,
39 metavar=
"PATH", help=
"MPS database file ('mps.db')")
40 parser.add_argument(
"--his", dest=
"his_file", required=
True,
41 metavar=
"PATH", help=
"pede histogram file")
42 parser.add_argument(
"-c",
"--cfg", dest=
"cfg", metavar=
"PATH", required=
True,
43 help=
"python configuration file of pede job")
44 parser.add_argument(
"-b",
"--no-binary-check", dest=
"no_binary_check",
45 default=
False, action=
"store_true",
46 help=(
"skip check for existing binaries "
47 "(possibly needed if used interactively)"))
48 args = parser.parse_args(argv)
51 for input_file
in (args.mps_db, args.his_file, args.cfg):
52 if not os.path.exists(input_file):
53 print "Could not find input file:", input_file
60 if len(his_data) != len(used_binaries):
61 print "The number of used binaries is", len(used_binaries),
62 print "whereas in contrast, however, the <chi2/ndf> histogram in Pede has",
63 print len(his_data),
"bins (Pede version >= rev92 might help if #bins < #binaries).",
67 with open(
"chi2pedehis.txt",
"w")
as f:
68 for i, b
in enumerate(used_binaries):
71 f.write(
" ".
join([name,
"{:03d}".
format(b), his_data[i]])+
"\n")
76 """Returns two lists containing the mille job IDs and the associated names.
79 - `mps_db`: path to the MPS database file
82 lib = mpslib.jobdatabase()
85 ids = lib.JOBNUMBER[:lib.nJobs]
86 names = lib.JOBSP3[:lib.nJobs]
92 """Returns list of used binary IDs.
95 - `cfg`: python config used to run the pede job
96 - `no_binary_check`: if 'True' a check for file existence is skipped
99 sys.path.append(os.path.dirname(cfg))
101 cache_stdout = sys.stdout
102 sys.stdout = open(os.devnull,
"w")
103 from alignment_merge
import process.AlignmentProducer.algoConfig
104 sys.stdout = cache_stdout
106 binaries = algoConfig.mergeBinaryFiles
108 used_binaries = binaries
111 used_binaries = [b
for b
in binaries
112 if os.path.exists(os.path.join(os.path.dirname(cfg), b))]
114 used_binaries = [int(re.sub(
r"milleBinary(\d+)\.dat",
r"\1", b))
115 for b
in used_binaries]
122 """Parse the pede histogram file.
125 - `his_file`: pede histogram file
129 with open(his_file,
"r") as his:
130 found_chi2_start = False;
133 if r"final <Chi^2/Ndf> from accepted local fits vs file number" in line:
134 found_chi2_start =
True
135 if not found_chi2_start:
138 if r"end of xy-data" in line:
break
139 if not re.search(
"\d", line):
continue
140 if re.search(
r"[a-z]", line):
continue
141 splitted = line.split()
142 his_data.append(splitted[-1])
148 if __name__ ==
"__main__":
static std::string join(char **cmd)