41
41
if self.path != pjoin(MG5DIR, "tmp_lhe_test"):
42
42
shutil.rmtree(self.path)
46
def test_parsing_lo_weight(self):
47
"""test that our parser can handle a large range of lo_weight format"""
49
def parse_lo_weight_old(evt):
50
"""parsing for unittest onlyx"""
53
start, stop = evt.tag.find('<mgrwt>'), evt.tag.find('</mgrwt>')
55
if start != -1 != stop :
56
text = evt.tag[start+8:stop]
57
#<rscale> 3 0.29765919e+03</rscale>
59
#<pdfrwt beam="1"> 1 21 0.15134321e+00 0.29765919e+03</pdfrwt>
60
#<pdfrwt beam="2"> 1 21 0.38683649e-01 0.29765919e+03</pdfrwt>
61
#<totfact> 0.17315115e+03</totfact>
63
for line in text.split('\n'):
64
line = line.replace('<', ' <').replace("'",'"')
66
_, nqcd, scale, _ = line.split()
67
evt.loweight['n_qcd'] = int(nqcd)
68
evt.loweight['ren_scale'] = float(scale)
69
elif '<pdfrwt beam="1"' in line:
71
evt.loweight['n_pdfrw1'] = int(args[2])
72
npdf = evt.loweight['n_pdfrw1']
73
evt.loweight['pdf_pdg_code1'] = [int(i) for i in args[3:3+npdf]]
74
evt.loweight['pdf_x1'] = [float(i) for i in args[3+npdf:3+2*npdf]]
75
evt.loweight['pdf_q1'] = [float(i) for i in args[3+2*npdf:3+3*npdf]]
76
elif '<pdfrwt beam="2"' in line:
78
evt.loweight['n_pdfrw2'] = int(args[2])
79
npdf = evt.loweight['n_pdfrw2']
80
evt.loweight['pdf_pdg_code2'] = [int(i) for i in args[3:3+npdf]]
81
evt.loweight['pdf_x2'] = [float(i) for i in args[3+npdf:3+2*npdf]]
82
evt.loweight['pdf_q2'] = [float(i) for i in args[3+2*npdf:3+3*npdf]]
83
elif '<asrwt>' in line:
84
args = line.replace('>','> ').split()
86
evt.loweight['asrwt'] = [float(a) for a in args[2:2+nalps]]
88
elif 'totfact' in line:
89
args = line.replace('>','> ').split()
90
evt.loweight['tot_fact'] = float(args[1])
98
4 0 +1.7208000e-01 1.00890300e+02 7.95774700e-02 1.27947900e-01
99
-1 -1 0 0 0 501 +0.0000000e+00 +0.0000000e+00 +1.1943355e+01 1.19433546e+01 0.00000000e+00 0.0000e+00 1.0000e+00
100
2 -1 0 0 501 0 +0.0000000e+00 +0.0000000e+00 -1.0679326e+03 1.06793262e+03 0.00000000e+00 0.0000e+00 -1.0000e+00
101
24 1 1 2 0 0 +6.0417155e+00 +4.2744556e+01 -7.9238049e+02 7.97619997e+02 8.04190073e+01 3.4933e-25 -1.0000e+00
102
23 1 1 2 0 0 -6.0417155e+00 -4.2744556e+01 -2.6360878e+02 2.82255979e+02 9.11880035e+01 1.8975e-26 1.0000e+00
106
4 0 +1.7208000e-01 1.00890300e+02 7.95774700e-02 1.27947900e-01
107
-1 -1 0 0 0 501 +0.0000000e+00 +0.0000000e+00 +1.1943355e+01 1.19433546e+01 0.00000000e+00 0.0000e+00 1.0000e+00
108
2 -1 0 0 501 0 +0.0000000e+00 +0.0000000e+00 -1.0679326e+03 1.06793262e+03 0.00000000e+00 0.0000e+00 -1.0000e+00
109
24 1 1 2 0 0 +6.0417155e+00 +4.2744556e+01 -7.9238049e+02 7.97619997e+02 8.04190073e+01 3.4933e-25 -1.0000e+00
110
23 1 1 2 0 0 -6.0417155e+00 -4.2744556e+01 -2.6360878e+02 2.82255979e+02 9.11880035e+01 1.8975e-26 1.0000e+00
112
<rscale> 2 0.12500000E+03</rscale>
114
<pdfrwt beam="1"> 1 4 0.11319990E+00 0.12500000E+03</pdfrwt>
115
<pdfrwt beam="2"> 1 -1 0.59528052E+00 0.12500000E+03</pdfrwt>
116
<totfact>-0.27352270E-03</totfact>
121
4 0 +1.7208000e-01 1.00890300e+02 7.95774700e-02 1.27947900e-01
122
-1 -1 0 0 0 501 +0.0000000e+00 +0.0000000e+00 +1.1943355e+01 1.19433546e+01 0.00000000e+00 0.0000e+00 1.0000e+00
123
2 -1 0 0 501 0 +0.0000000e+00 +0.0000000e+00 -1.0679326e+03 1.06793262e+03 0.00000000e+00 0.0000e+00 -1.0000e+00
124
24 1 1 2 0 0 +6.0417155e+00 +4.2744556e+01 -7.9238049e+02 7.97619997e+02 8.04190073e+01 3.4933e-25 -1.0000e+00
125
23 1 1 2 0 0 -6.0417155e+00 -4.2744556e+01 -2.6360878e+02 2.82255979e+02 9.11880035e+01 1.8975e-26 1.0000e+00
127
<rscale> 2 0.12500000E+03</rscale>
128
<asrwt> 1 0.11 </asrwt>
129
<pdfrwt beam='1'> 1 4 0.11319990E+00 0.12500000E+03</pdfrwt>
130
<pdfrwt beam=2> 2 1 -1 0.2 0.11e-02 0.59528052E+00 0.12500000E+03</pdfrwt>
131
<totfact> 115 </totfact>
135
4 0 +1.7208000e-01 1.00890300e+02 7.95774700e-02 1.27947900e-01
136
-1 -1 0 0 0 501 +0.0000000e+00 +0.0000000e+00 +1.1943355e+01 1.19433546e+01 0.00000000e+00 0.0000e+00 1.0000e+00
137
2 -1 0 0 501 0 +0.0000000e+00 +0.0000000e+00 -1.0679326e+03 1.06793262e+03 0.00000000e+00 0.0000e+00 -1.0000e+00
138
24 1 1 2 0 0 +6.0417155e+00 +4.2744556e+01 -7.9238049e+02 7.97619997e+02 8.04190073e+01 3.4933e-25 -1.0000e+00
139
23 1 1 2 0 0 -6.0417155e+00 -4.2744556e+01 -2.6360878e+02 2.82255979e+02 9.11880035e+01 1.8975e-26 1.0000e+00
141
<rscale>2 0.12500000E+03</rscale>
142
<asrwt>1 0.11 </asrwt>
143
<pdfrwt beam='1'> 1 4 0.11319990E+00 0.12500000e+03 </pdfrwt>
144
<pdfrwt beam=2> 2 1 -1 0.2 0.11e-02 0.59528052E+00 0.12500000E+03 </pdfrwt>
145
<totfact> 115.001 </totfact>
149
4 0 +1.7208000e-01 1.00890300e+02 7.95774700e-02 1.27947900e-01
150
-1 -1 0 0 0 501 +0.0000000e+00 +0.0000000e+00 +1.1943355e+01 1.19433546e+01 0.00000000e+00 0.0000e+00 1.0000e+00
151
2 -1 0 0 501 0 +0.0000000e+00 +0.0000000e+00 -1.0679326e+03 1.06793262e+03 0.00000000e+00 0.0000e+00 -1.0000e+00
152
24 1 1 2 0 0 +6.0417155e+00 +4.2744556e+01 -7.9238049e+02 7.97619997e+02 8.04190073e+01 3.4933e-25 -1.0000e+00
153
23 1 1 2 0 0 -6.0417155e+00 -4.2744556e+01 -2.6360878e+02 2.82255979e+02 9.11880035e+01 1.8975e-26 1.0000e+00
155
<rscale>2 0.12500000E+03</rscale>
156
<asrwt>1 0.11 </asrwt>
157
<pdfrwt beam='1'> 1 4 0.11319990E+00 0.12500000e+03 </pdfrwt>
158
<pdfrwt beam=2> 2 1 -1 0.2 0.11e-02 0.59528052E+00 0.12500000E+03 </pdfrwt>
159
<totfact> 115.001 </totfact>
164
{'pdf_pdg_code1': [4], 'asrwt': [], 'pdf_pdg_code2': [-1], 'pdf_q1': [125.0], 'pdf_q2': [125.0], 'n_pdfrw1': 1, 'n_pdfrw2': 1, 'tot_fact': -0.0002735227, 'pdf_x2': [0.59528052], 'pdf_x1': [0.1131999], 'n_qcd': 2, 'ren_scale': 125.0},
165
{'pdf_pdg_code1': [4], 'asrwt': [0.11], 'pdf_pdg_code2': [1, -1], 'pdf_q1': [125.0], 'pdf_q2': [0.59528052, 125.0], 'ren_scale': 125.0, 'n_pdfrw1': 1, 'n_pdfrw2': 2, 'pdf_x2': [0.2, 0.0011], 'pdf_x1': [0.1131999], 'n_qcd': 2, 'tot_fact': 115.0},
166
{'pdf_pdg_code1': [4], 'asrwt': [0.11], 'pdf_pdg_code2': [1, -1], 'pdf_q1': [125.0], 'pdf_q2': [0.59528052, 125.0], 'ren_scale': 125.0, 'n_pdfrw1': 1, 'n_pdfrw2': 2, 'pdf_x2': [0.2, 0.0011], 'pdf_x1': [0.1131999], 'n_qcd': 2, 'tot_fact': 115.001},
167
{'pdf_pdg_code1': [4], 'asrwt': [0.11], 'pdf_pdg_code2': [1, -1], 'pdf_q1': [125.0], 'pdf_q2': [0.59528052, 125.0], 'ren_scale': 125.0, 'n_pdfrw1': 1, 'n_pdfrw2': 2, 'pdf_x2': [0.2, 0.0011], 'pdf_x1': [0.1131999], 'n_qcd': 2, 'tot_fact': 115.001},
168
{'pdf_pdg_code1': [4], 'asrwt': [0.11], 'pdf_pdg_code2': [1, -1], 'pdf_q1': [125.0], 'pdf_q2': [0.59528052, 125.0], 'ren_scale': 125.0, 'n_pdfrw1': 1, 'n_pdfrw2': 2, 'pdf_x2': [0.2, 0.0011], 'pdf_x1': [0.1131999], 'n_qcd': 2, 'tot_fact': 115.001}]
170
for i,evt in enumerate(events):
171
evt1 = lhe_parser.Event(evt)
172
evt2 = lhe_parser.Event(evt)
173
lo = evt1.parse_lo_weight()
175
lo2 = parse_lo_weight_old(evt2)
181
self.assertEqual(lo[key], lo2[key])
182
self.assertEqual(lo, solutions[i])
44
189
def test_read_write_lhe(self):
45
190
"""test that we can read/write an lhe event file"""