9 from collections
import defaultdict
11 p = argparse.ArgumentParser()
13 p.add_argument(
"seed_for_sort", type=int, default=random.randrange(sys.maxsize), nargs=
"?")
15 random.seed(args.seed_for_sort)
16 print(
"Seed:", args.seed_for_sort)
20 ROOT.gROOT.Macro(
"loadMELA.C")
21 ROOT.gROOT.LoadMacro(
"testME_v2.c+")
24 return defaultdict(set)
26 ratiosMCFMJHUGenVBF = defaultdict(set)
27 ratiosMCFMJHUGenLepZH = defaultdict(set)
28 ratiosMCFMJHUGenLepWH = defaultdict(set)
29 ratiosMCFMJHUGenHadZH = defaultdict(set)
30 ratiosMCFMJHUGenHadWH = defaultdict(set)
38 referencefiles = os.listdir(
"reference")
42 random.shuffle(referencefiles)
46 removes stuff from the reference file that would make
47 it different for each run for no real reason.
48 For example 0x1234567 --> 0xPOINTER
50 content = re.sub(
"0x[0-9a-f]+",
"0xPOINTER", content)
53 melaptr = ROOT.makemelaptr(13, 125, ROOT.TVar.ERROR)
55 for j, ref
in enumerate(referencefiles, start=1):
56 match = re.match(
"(testME_.*_Ping)_?(.*).ref", ref)
58 raise RuntimeError(
"Unknown filename {}".format(ref))
59 functionname = match.group(1)
60 arguments = match.group(2)
61 arguments = arguments.replace(
"2l2l",
"0")
62 arguments = arguments.replace(
"4l",
"1")
64 arguments = [
int(_.replace(
"TeV",
""))
for _
in arguments.split(
"_")] + [melaptr]
68 if functionname ==
"testME_ProdDec_MCFM_JHUGen_WBFZZ_Comparison_Ping":
69 functionname =
"testME_ProdDec_MCFM_JHUGen_WBFZZWW_Comparison_Ping"
70 arguments.insert(3, 1)
71 if functionname ==
"testME_ProdDec_MCFM_JHUGen_WBFWW_Comparison_Ping":
72 functionname =
"testME_ProdDec_MCFM_JHUGen_WBFZZWW_Comparison_Ping"
73 arguments.insert(3, 2)
74 arguments.insert(4, 0)
76 if functionname ==
"testME_ProdDec_MCFM_JHUGen_WBFZZ_TU_Comparison_Ping":
77 functionname =
"testME_ProdDec_MCFM_JHUGen_WBFZZWW_TU_Comparison_Ping"
78 if functionname ==
"testME_ProdDec_MCFM_JHUGen_WBFWW_TU_Comparison_Ping":
79 functionname =
"testME_ProdDec_MCFM_JHUGen_WBFZZWW_TU_Comparison_Ping"
81 if functionname ==
"testME_ProdDec_MCFM_JHUGen_JJQCDZZ_Comparison_Ping":
82 functionname =
"testME_ProdDec_MCFM_JHUGen_JJQCDZZWW_Comparison_Ping"
83 arguments.insert(1, 1)
84 if functionname ==
"testME_ProdDec_MCFM_JHUGen_JJQCDWW_Comparison_Ping":
85 functionname =
"testME_ProdDec_MCFM_JHUGen_JJQCDZZWW_Comparison_Ping"
86 arguments.insert(1, 2)
87 arguments.insert(2, 0)
89 if functionname ==
"testME_VH_JHUGen_13TeV_Ping":
90 functionname =
"testME_VH_JHUGen_Ping"
91 arguments.insert(0, 13)
92 arguments.insert(1, 0)
95 function = getattr(ROOT, functionname)
98 print(
"trying to call: {}(*{})".format(functionname, arguments))
101 newfile = ref.replace(
".ref",
".out")
103 with open(newfile)
as f:
105 with open(newfile,
'w')
as f:
108 with open(
"reference/"+ref)
as f:
111 if refcontent != content:
112 different.add(newfile)
114 if "JHUGen/MCFM Ratio" in content:
115 production = content.split(
"\n")[0].split()[3]
116 if production ==
"JJVBF":
117 ratios = ratiosMCFMJHUGenVBF
118 elif production ==
"Had_ZH":
119 ratios = ratiosMCFMJHUGenHadZH
120 elif production
in "Had_WH":
121 ratios = ratiosMCFMJHUGenHadWH
122 elif production ==
"Lep_ZH":
123 ratios = ratiosMCFMJHUGenLepZH
124 elif production
in "Lep_WH":
125 ratios = ratiosMCFMJHUGenLepWH
127 assert False, production
129 assert "Arrays:" in content
130 sections = content.split(
"JHUGen/MCFM Ratio")
131 for section
in sections[1:]:
132 sectioncontent = section.split()
133 for i, number
in enumerate(sectioncontent):
136 ratio = float(number)
140 ratios[ratio].add(newfile)
143 if "MCFM Bkg (re-sum)/Bkg Ratio" in content:
144 ratiopart = content.split(
"MCFM Bkg (re-sum)/Bkg Ratio")[1]
145 for i, number
in enumerate(ratiopart.split()):
148 ratio = float(number)
151 if ratio != 0
and ratio != 4:
152 badbkgratios.add(newfile)
155 if "angles" in content:
156 for line
in content.split(
"\n"):
157 match = re.search(
r"TUtil (.* angles)", line)
159 tutilline = line.split(
": ")[1]
160 melaline = {line
for line
in content.split(
"\n")
if "MELA " + match.group(1)
in line}.pop().split(
": ")[1]
161 if tutilline != melaline:
162 badangles.add(newfile)
164 if "_selfD:" in content:
167 for line
in content.split(
"\n"):
169 if "hadronic Z-BF" in line:
break
170 match = re.match(
"(p.*)_selfD: ([0-9.e+-]*)", line)
172 if float(match.group(2)) != pendingselfD.get(match.group(1)):
173 print(match.group(1), float(match.group(2)), pendingselfD.get(match.group(1)))
174 if float(match.group(2)) != pendingselfD.pop(match.group(1),
None):
175 print(
"Bad selfD file due to line",line,
" [line=",iline,
"]")
176 badselfD.add(newfile)
178 match = re.match(
"(p.*): ([0-9.e+-]*)", line)
180 pendingselfD[match.group(1)] = float(match.group(2))
182 print(j,
"/", len(referencefiles), ref)
186 errors.append(
"The following files are not the same as the reference files:\n "+
"\n ".join(sorted(different)))
187 if len(ratiosMCFMJHUGenVBF)>1:
188 errors.append(
"There are multiple different ratios between MCFM and JHUGen for VBF:\n" +
", ".join(str(_)
for _
in ratiosMCFMJHUGenVBF))
189 if len(ratiosMCFMJHUGenHadZH)>1:
190 errors.append(
"There are multiple different ratios between MCFM and JHUGen for hadronic ZH:\n" +
", ".join(str(_)
for _
in ratiosMCFMJHUGenHadZH))
191 if len(ratiosMCFMJHUGenHadWH)>1:
192 errors.append(
"There are multiple different ratios between MCFM and JHUGen for hadronic WH:\n" +
", ".join(str(_)
for _
in ratiosMCFMJHUGenHadWH))
193 if len(ratiosMCFMJHUGenLepZH)>1:
194 errors.append(
"There are multiple different ratios between MCFM and JHUGen for leptonic ZH:\n" +
", ".join(str(_)
for _
in ratiosMCFMJHUGenLepZH))
195 if len(ratiosMCFMJHUGenLepWH)>1:
196 errors.append(
"There are multiple different ratios between MCFM and JHUGen for leptonic WH:\n" +
", ".join(str(_)
for _
in ratiosMCFMJHUGenLepWH))
198 errors.append(
"The following files have bad ratios between manual and automatic background:\n "+
"\n ".join(sorted(badbkgratios)))
200 errors.append(
"The following files have inconsistent angles between MELA and TUtil:\n "+
"\n ".join(sorted(badangles)))
202 errors.append(
"The following files have inconsistent MEs between predefined and selfD hypotheses:\n "+
"\n ".join(sorted(badselfD)))
205 raise RuntimeError(
"\n\n\n".join(errors))