~maddevelopers/mg5amcnlo/PY8_counterterm

« back to all changes in this revision

Viewing changes to tests/unit_tests/various/test_lhe_parser.py

  • Committer: olivier-mattelaer
  • Date: 2017-03-28 15:31:53 UTC
  • mfrom: (270.1.17 2.5.4)
  • Revision ID: olivier-mattelaer-20170328153153-kk81pvnwheh7hia1
pass to 2.5.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
        if self.path != pjoin(MG5DIR, "tmp_lhe_test"):
42
42
            shutil.rmtree(self.path)
43
43
 
 
44
 
 
45
 
 
46
    def test_parsing_lo_weight(self):
 
47
        """test that our parser can handle a large range of lo_weight format"""
 
48
 
 
49
        def parse_lo_weight_old(evt):
 
50
            """parsing for unittest onlyx"""
 
51
 
 
52
            
 
53
            start, stop = evt.tag.find('<mgrwt>'), evt.tag.find('</mgrwt>')
 
54
    
 
55
            if start != -1 != stop :
 
56
                text = evt.tag[start+8:stop]
 
57
    #<rscale>  3 0.29765919e+03</rscale>
 
58
    #<asrwt>0</asrwt>
 
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>
 
62
                evt.loweight={}
 
63
                for line in text.split('\n'):
 
64
                    line = line.replace('<', ' <').replace("'",'"')
 
65
                    if 'rscale' in line:
 
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:
 
70
                        args = line.split()
 
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:
 
77
                        args = line.split()
 
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()
 
85
                        nalps = int(args[1])
 
86
                        evt.loweight['asrwt'] = [float(a) for a in args[2:2+nalps]] 
 
87
                        
 
88
                    elif 'totfact' in line:
 
89
                        args = line.replace('>','> ').split()
 
90
                        evt.loweight['tot_fact'] = float(args[1])
 
91
            else:
 
92
                return None
 
93
            return evt.loweight
 
94
 
 
95
        
 
96
        events=["""
 
97
<event>
 
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
 
103
</event>
 
104
""","""
 
105
<event>
 
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
 
111
<mgrwt>
 
112
<rscale>  2 0.12500000E+03</rscale>
 
113
<asrwt>0</asrwt>
 
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>
 
117
</mgrwt>
 
118
</event>""",
 
119
"""
 
120
<event>
 
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
 
126
<mgrwt>
 
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>
 
132
</mgrwt>
 
133
</event>""",
 
134
"""<event>
 
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
 
140
<mgrwt>
 
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>
 
146
</mgrwt>
 
147
</event>""",
 
148
"""<event>
 
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
 
154
<mgrwt>
 
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>
 
160
</mgrwt>
 
161
</event>"""]
 
162
     
 
163
        solutions = [None, 
 
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}]
 
169
     
 
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()
 
174
            try:
 
175
                lo2 = parse_lo_weight_old(evt2)
 
176
            except:
 
177
                pass
 
178
            else:
 
179
                if lo:
 
180
                    for key in lo2:
 
181
                        self.assertEqual(lo[key], lo2[key])
 
182
            self.assertEqual(lo, solutions[i])
 
183
         
 
184
     
 
185
     
 
186
        
 
187
        
 
188
 
44
189
    def test_read_write_lhe(self):
45
190
        """test that we can read/write an lhe event file"""
46
191