JHUGen MELA  v2.4.1
Matrix element calculations as used in JHUGen. MELA is an important tool that was used for the Higgs boson discovery and for precise measurements of its structure and interactions. Please see the website https://spin.pha.jhu.edu/ and papers cited there for more details, and kindly cite those papers when using this code.
testME_all.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import argparse
4 import os
5 import random
6 import re
7 import sys
8 
9 from collections import defaultdict
10 
11 p = argparse.ArgumentParser()
12 #https://stackoverflow.com/a/5012617/5228524
13 p.add_argument("seed_for_sort", type=int, default=random.randrange(sys.maxsize), nargs="?")
14 args = p.parse_args()
15 random.seed(args.seed_for_sort)
16 print("Seed:", args.seed_for_sort)
17 
18 import ROOT
19 
20 ROOT.gROOT.Macro("loadMELA.C")
21 ROOT.gROOT.LoadMacro("testME_v2.c+")
22 
24  return defaultdict(set)
25 
26 ratiosMCFMJHUGenVBF = defaultdict(set)
27 ratiosMCFMJHUGenLepZH = defaultdict(set)
28 ratiosMCFMJHUGenLepWH = defaultdict(set)
29 ratiosMCFMJHUGenHadZH = defaultdict(set)
30 ratiosMCFMJHUGenHadWH = defaultdict(set)
31 
32 badbkgratios = set()
33 different = set()
34 badangles = set()
35 badselfD = set()
36 messedup = set()
37 
38 referencefiles = os.listdir("reference")
39 #first sort alphabetically to make it deterministic given the seed
40 referencefiles.sort()
41 #then shuffle them
42 random.shuffle(referencefiles)
43 
44 def unifycontent(content):
45  """
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
49  """
50  content = re.sub("0x[0-9a-f]+", "0xPOINTER", content)
51  return content
52 
53 melaptr = ROOT.makemelaptr(13, 125, ROOT.TVar.ERROR)
54 
55 for j, ref in enumerate(referencefiles, start=1):
56  match = re.match("(testME_.*_Ping)_?(.*).ref", ref)
57  if not match:
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")
63  if arguments:
64  arguments = [int(_.replace("TeV", "")) for _ in arguments.split("_")] + [melaptr]
65  else:
66  arguments = [melaptr]
67 
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)
75 
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"
80 
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)
88 
89  if functionname == "testME_VH_JHUGen_13TeV_Ping":
90  functionname = "testME_VH_JHUGen_Ping"
91  arguments.insert(0, 13)
92  arguments.insert(1, 0)
93 
94  try:
95  function = getattr(ROOT, functionname)
96  function(*arguments)
97  except:
98  print("trying to call: {}(*{})".format(functionname, arguments))
99  raise
100 
101  newfile = ref.replace(".ref", ".out")
102 
103  with open(newfile) as f:
104  content = unifycontent(f.read())
105  with open(newfile, 'w') as f:
106  f.write(content)
107 
108  with open("reference/"+ref) as f:
109  refcontent = unifycontent(f.read())
110 
111  if refcontent != content:
112  different.add(newfile)
113 
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
126  else:
127  assert False, production
128 
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):
134  #go until we find something that's not a number
135  try:
136  ratio = float(number)
137  except ValueError:
138  break
139  if ratio != 0:
140  ratios[ratio].add(newfile)
141  assert i > 1
142 
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()):
146  #go until we find something that's not a number
147  try:
148  ratio = float(number)
149  except ValueError:
150  break
151  if ratio != 0 and ratio != 4:
152  badbkgratios.add(newfile)
153  assert i > 1
154 
155  if "angles" in content:
156  for line in content.split("\n"):
157  match = re.search(r"TUtil (.* angles)", line)
158  if match:
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)
163 
164  if "_selfD:" in content:
165  pendingselfD = {}
166  iline=0
167  for line in content.split("\n"):
168  iline=iline+1
169  if "hadronic Z-BF" in line: break
170  match = re.match("(p.*)_selfD: ([0-9.e+-]*)", line)
171  if match:
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)
177  else:
178  match = re.match("(p.*): ([0-9.e+-]*)", line)
179  if match:
180  pendingselfD[match.group(1)] = float(match.group(2))
181 
182  print(j, "/", len(referencefiles), ref)
183 
184 errors = []
185 if different:
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))
197 if badbkgratios:
198  errors.append("The following files have bad ratios between manual and automatic background:\n "+"\n ".join(sorted(badbkgratios)))
199 if badangles:
200  errors.append("The following files have inconsistent angles between MELA and TUtil:\n "+"\n ".join(sorted(badangles)))
201 if badselfD:
202  errors.append("The following files have inconsistent MEs between predefined and selfD hypotheses:\n "+"\n ".join(sorted(badselfD)))
203 
204 if errors:
205  raise RuntimeError("\n\n\n".join(errors))
testME_all.function
function
Definition: testME_all.py:95
testME_all.unifycontent
def unifycontent(content)
Definition: testME_all.py:44
testME_all.defaultdictset
def defaultdictset()
Definition: testME_all.py:23
set
set(CMAKE_MACOSX_RPATH 1) set(CMAKE_CACHEFILE_DIR CMakeFiles/) cmake_minimum_required(VERSION 2.8) project(collier) enable_language(Fortran) get_filename_component(Fortran_COMPILER_NAME $
Definition: CMakeLists.txt:65
testME_all.int
int
Definition: testME_all.py:13
open
with open("/mnt/sda1/RandomRantings/JHU/Andrei_Research/DocumentingMELA/raw_couplings.txt") as f
Definition: write_bindings.txt:1