~maddevelopers/mg5amcnlo/3.0.2-alpha0-merged3.2.0

74.4.7 by Olivier Mattelaer
modify the script for writing info.html
1
#! /usr/bin/env python
2
################################################################################
3
#
78.169.1 by Valentin Hirschi
1. Changed python module headers
4
# Copyright (c) 2009 The MadGraph5_aMC@NLO Development team and Contributors
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
5
#
78.169.1 by Valentin Hirschi
1. Changed python module headers
6
# This file is a part of the MadGraph5_aMC@NLO project, an application which 
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
7
# automatically generates Feynman diagrams and matrix elements for arbitrary
8
# high-energy processes in the Standard Model and beyond.
9
#
78.169.1 by Valentin Hirschi
1. Changed python module headers
10
# It is subject to the MadGraph5_aMC@NLO license which should accompany this 
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
11
# distribution.
12
#
78.169.1 by Valentin Hirschi
1. Changed python module headers
13
# For more information, visit madgraph.phys.ucl.ac.be and amcatnlo.web.cern.ch
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
14
#
15
################################################################################
16
78.426.2 by olivier-mattelaer
simple run of modernise
17
from __future__ import absolute_import
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
18
import string
19
import os
20
import re
21
import sys
22
78.294.61 by olivier Mattelaer
fix the problem of html in FKS
23
import madgraph.various.misc as misc
78.426.2 by olivier-mattelaer
simple run of modernise
24
from six.moves import range
78.294.61 by olivier Mattelaer
fix the problem of html in FKS
25
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
26
template_text= string.Template("""
27
<HTML> 
28
<HEAD> 
29
<TITLE>Detail on the Generation</TITLE> 
30
<META $meta ></HEAD> 
74.4.9 by Olivier Mattelaer
improve the style of info.html
31
32
<style type="text/css">
33
34
table.processes { border-collapse: collapse;
35
                  border: solid}
36
37
.processes td {
38
padding: 2 5 2 5;
39
border: solid thin;
40
}
41
42
th{
43
border-top: solid;
44
border-bottom: solid;
45
}
46
47
.first td{
48
border-top: solid;
49
}
50
51
52
53
54
</style>
55
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
56
<BODY> 
57
    <P> <H2 ALIGN=CENTER> SubProcesses and Feynman diagrams </H2>
58
    
74.4.9 by Olivier Mattelaer
improve the style of info.html
59
    <TABLE BORDER=2 ALIGN=CENTER class=processes> 
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
60
        <TR>
61
           <TH>Directory</TH> 
62
           <TH NOWRAP># Diagrams </TH>
63
           <TH NOWRAP># Subprocesses </TH>
64
           <TH>FEYNMAN DIAGRAMS</TH> 
65
           <TH> SUBPROCESS </TH>
66
        </TR> 
67
        $info_lines
68
    </TABLE><BR> 
69
    <CENTER> $nb_diag diagrams ($nb_gen_diag independent).</CENTER>
74.4.9 by Olivier Mattelaer
improve the style of info.html
70
    <br><br><br>
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
71
    <TABLE ALIGN=CENTER>
74.4.9 by Olivier Mattelaer
improve the style of info.html
72
    $log
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
73
    <TR> 
74
        <TD ALIGN=CENTER> <A HREF="../Cards/proc_card_mg5.dat">proc_card_mg5.dat</A> </TD>
75
        <TD> Input file used for code generation.
76
    $model_info
74.1.61 by Johan Alwall
Added link to main page in info.html page
77
    </TABLE><br>
78
    <center>
79
    <H3>Back to <A HREF="../index.html">Process main page</A></H3>
80
    </center>
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
81
 </BODY> 
82
83
</HTML>""")
84
85
306 by Marco Zaro
the generated events are stored in Events/run_i (as for LO)
86
template_text_nlo= string.Template("""
87
<HTML> 
88
<HEAD> 
89
<TITLE>Detail on the Generation</TITLE> 
90
<META $meta ></HEAD> 
91
92
<style type="text/css">
93
94
table.processes { border-collapse: collapse;
95
                  border: solid}
96
97
.processes td {
98
padding: 2 5 2 5;
99
border: solid thin;
100
}
101
102
th{
103
border-top: solid;
104
border-bottom: solid;
105
}
106
107
.first td{
108
border-top: solid;
109
}
110
111
112
113
114
</style>
115
116
<BODY> 
117
    <P> <H2 ALIGN=CENTER> SubProcesses and Feynman diagrams </H2>
118
    
119
    <TABLE BORDER=2 ALIGN=CENTER class=processes> 
120
        <TR>
121
           <TH>Directory</TH> 
122
           <TH NOWRAP>Type</TH>
123
           <TH NOWRAP># Diagrams </TH>
124
           <TH NOWRAP># Subprocesses </TH>
125
           <TH>FEYNMAN DIAGRAMS</TH> 
126
           <TH> SUBPROCESS </TH>
127
        </TR> 
128
        $info_lines
129
    </TABLE><BR> 
130
    <CENTER> $nb_diag diagrams ($nb_gen_diag independent).</CENTER>
131
    <br><br><br>
132
    <TABLE ALIGN=CENTER>
133
    $log
134
    <TR> 
135
        <TD ALIGN=CENTER> <A HREF="../Cards/proc_card_mg5.dat">proc_card_mg5.dat</A> </TD>
136
        <TD> Input file used for code generation.
137
    $model_info
138
    </TABLE><br>
139
    <center>
140
    <H3>Back to <A HREF="../index.html">Process main page</A></H3>
141
    </center>
142
 </BODY> 
143
144
</HTML>""")
145
146
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
147
class make_info_html:
148
149
    def __init__(self, cur_dir='./'):
78.294.61 by olivier Mattelaer
fix the problem of html in FKS
150
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
151
        self.dir = cur_dir
152
        
78.294.61 by olivier Mattelaer
fix the problem of html in FKS
153
        
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
154
        self.rep_rule = {'nb_diag': 0, 'nb_gen_diag': 0}
155
        
156
        self.define_meta()
157
        self.rep_rule['info_lines'] = self.define_info_tables()
74.4.9 by Olivier Mattelaer
improve the style of info.html
158
        self.rep_rule['model_info']= self.give_model_info()
159
        self.rep_rule['log'] = self.check_log() 
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
160
        self.write()
161
        
162
        
163
    def give_model_info(self):
164
        """find path for the model"""
165
        
166
        path = os.path.join(self.dir, 'Source','MODEL','particles.dat')
167
        if os.path.exists(path):
168
            return """<TR> 
169
        <TD ALIGN=CENTER> <A HREF="../Source/MODEL/particles.dat">particles</A></TD> 
170
        <TD> Particles file used for code generation.</TD>
171
    </TR>
172
    <TR> 
173
        <TD ALIGN=CENTER> <A HREF="../Source/MODEL/interactions.dat">interactions</A></TD> 
78.7.6 by Johan Alwall
Fixed double main page link in info.html
174
        <TD> Interactions file used for code generation.</TD>
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
175
    </TR>"""
176
        else:
177
            return ''
178
        
179
        
180
    def define_meta(self):
181
        """add the meta in the replacement rule"""
182
        
183
        if os.path.exists(os.path.join(self.dir,'SubProcesses','done')):
78.109.22 by olivier Mattelaer
not clean but working version
184
            self.rep_rule['meta'] = 'HTTP-EQUIV=\"REFRESH\" CONTENT=\"30\"'
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
185
        else:
466.23.13 by olivier Mattelaer
add more update for MadSpin.
186
            self.rep_rule['meta'] = "HTTP-EQUIV=\"EXPIRES\" CONTENT=\"20\""
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
187
        
188
189
    def define_info_tables(self):
190
        """define the information table"""
191
        
192
        line_template = string.Template("""
74.4.9 by Olivier Mattelaer
improve the style of info.html
193
        <TR class=$class> $first 
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
194
<TD> $diag </TD> 
195
<TD> $subproc </TD> 
196
<TD> <A HREF="../SubProcesses/$processdir/diagrams.html#$id" >html</A> $postscript
74.4.9 by Olivier Mattelaer
improve the style of info.html
197
</TD><TD class=$class>
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
198
<SPAN style="white-space: nowrap;"> $subprocesslist</SPAN>
199
</TD></TR>""")
200
        
201
        #output text
202
        text = ''
203
        # list of valid P directory
204
        subproc = [content for content in os.listdir(os.path.join(self.dir,'SubProcesses'))
205
                                if content.startswith('P') and 
206
                                os.path.isdir(os.path.join(self.dir,'SubProcesses',content))
207
                                and os.path.exists(os.path.join(self.dir,'SubProcesses',content,'auto_dsig.f'))]
208
        
209
        for proc in subproc:
210
            
211
            idnames = self.get_subprocesses_info(proc)
74.4.9 by Olivier Mattelaer
improve the style of info.html
212
               
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
213
            for id in range(1,len(idnames)+1):
214
215
                if id == 1:
74.4.9 by Olivier Mattelaer
improve the style of info.html
216
                    
217
                    line_dict = {'processdir': proc,
218
                                 'class': 'first'}
219
                    line_dict['first']= '<TD class=$class rowspan=%s> %s </TD>' % (len(idnames), proc)
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
220
                else:
74.4.9 by Olivier Mattelaer
improve the style of info.html
221
                    line_dict = {'processdir': proc,
222
                                 'class': 'second'}
223
                    line_dict['first'] = ''
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
224
                try:
225
                    names = idnames[id]
466.1.45 by olivier Mattelaer
secure most of the try:...except:...
226
                except Exception:
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
227
                    names = idnames['']
228
                    id = ''
229
                line_dict['id'] = str(id)     
230
                line_dict['diag'] = self.get_diagram_nb(proc, id)
231
                line_dict['subproc'] = sum([len(data) for data in names])
232
                self.rep_rule['nb_diag'] += line_dict['diag'] * line_dict['subproc']
233
                self.rep_rule['nb_gen_diag'] += line_dict['diag']
74.4.9 by Olivier Mattelaer
improve the style of info.html
234
                line_dict['subprocesslist'] = ', <br>'.join([' </SPAN> , <SPAN style="white-space: nowrap;"> '.join(info) for info in names])
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
235
                line_dict['postscript'] = self.check_postcript(proc, id)
236
                
237
                text += line_template.substitute(line_dict)
238
        return text
239
    
240
    def get_diagram_nb(self, proc, id):
241
        
242
        path = os.path.join(self.dir, 'SubProcesses', proc, 'matrix%s.f' % id)
243
        nb_diag = 0
244
                
245
        pat = re.compile(r'''Amplitude\(s\) for diagram number (\d+)''' )
78.440.2 by olivier-mattelaer
create a template for helicity_recycling code
246
        if not os.path.exists(path):
247
            path = os.path.join(self.dir, 'SubProcesses', proc, 'matrix%s_orig.f' % id)
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
248
        text = open(path).read()
249
        for match in re.finditer(pat, text):
250
            pass
251
        nb_diag += int(match.groups()[0])
252
        
253
        return nb_diag
254
            
255
            
256
    def get_subprocesses_info(self, proc):
257
        """ return the list of processes with their name"""    
258
        
78.294.61 by olivier Mattelaer
fix the problem of html in FKS
259
        #no python information available (should not happen anymore)
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
260
        path = os.path.join(self.dir, 'SubProcesses', proc)        
261
        nb_sub = 0
262
        names = {}
263
        old_main = ''
264
        
265
        if not os.path.exists(os.path.join(path,'processes.dat')):
266
            return self.get_subprocess_info_v4(proc)
267
        
268
        for line in open(os.path.join(path,'processes.dat')):
269
            main = line[:8].strip()
270
            if main == 'mirror':
271
                main = old_main
74.4.9 by Olivier Mattelaer
improve the style of info.html
272
                if line[8:].strip() == 'none':
273
                    continue 
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
274
            else:
275
                main = int(main)
276
                old_main = main
277
278
            sub_proccess = line[8:]
279
            nb_sub += sub_proccess.count(',') + 1
280
            if main in names:
281
                names[main] += [sub_proccess.split(',')]
282
            else: 
283
                names[main]= [sub_proccess.split(',')]
78.294.61 by olivier Mattelaer
fix the problem of html in FKS
284
    
285
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
286
        return names
287
288
    def get_subprocess_info_v4(self, proc):
289
        """ return the list of processes with their name in case without grouping """
290
        
291
        nb_sub = 0
292
        names = {'':[[]]}
293
        path = os.path.join(self.dir, 'SubProcesses', proc,'auto_dsig.f')
294
        found = 0
295
        for line in open(path):
296
            if line.startswith('C     Process:'):
297
                found += 1
298
                names[''][0].append(line[15:])
299
            elif found >1:
300
                break    
301
        return names    
302
    
303
    def check_postcript(self, proc, id):
304
        """ check if matrix.ps is defined """
305
        path = os.path.join(self.dir, 'SubProcesses', proc,'matrix%s.f' % id) 
306
        if os.path.exists(path):
307
            return "<A HREF=\"../SubProcesses/%s/matrix%s.ps\" >postscript </A>" % \
308
                    (proc, id)
309
        else:
310
            return ''
74.4.9 by Olivier Mattelaer
improve the style of info.html
311
312
    def check_log(self):
313
        path = os.path.join(self.dir, 'proc_log.txt') 
314
        if os.path.exists(path):
315
            return """<TR> 
316
        <TD ALIGN=CENTER> <A HREF="../proc_log.txt">proc_log.txt</A> </TD>
317
        <TD> Log file from MadGraph code generation. </TD>
318
        </TR>"""
319
        else:
320
            return ''
78.294.61 by olivier Mattelaer
fix the problem of html in FKS
321
        
74.4.7 by Olivier Mattelaer
modify the script for writing info.html
322
    def write(self):
323
        """write the info.html file"""
324
        
325
        fsock = open(os.path.join(self.dir,'HTML','info.html'),'w')
326
        text = template_text.substitute(self.rep_rule)
327
        fsock.write(text)
328
329
    
330
306 by Marco Zaro
the generated events are stored in Events/run_i (as for LO)
331
class make_info_html_nlo(make_info_html):
332
333
334
    def define_info_tables(self):
335
        """define the information table"""
336
        
337
        # we do not export the diagrams.html so far
338
        line_template = string.Template("""
339
        <TR class=$class> $first 
340
<TD> $type </TD>
341
<TD> $diag </TD> 
342
<TD> $subproc </TD> 
343
<TD>$postscript </TD>
344
<TD class=$class>
345
<SPAN style="white-space: nowrap;"> $subprocesslist</SPAN>
346
</TD></TR>""")
347
        
348
349
        #output text
350
        text = ''
351
        # list of valid P directory
352
        subproc = [content for content in os.listdir(os.path.join(self.dir,'SubProcesses'))
353
                                if content.startswith('P') and 
354
                                os.path.isdir(os.path.join(self.dir,'SubProcesses',content))
355
                                and os.path.islink(os.path.join(self.dir,'SubProcesses',content,'fks_singular.f'))]
356
        
357
        for proc in subproc:
358
            files_dict = {'born': ['born.f'], 
359
                          'virt': [os.path.join('V' + proc[1:], 'loop_matrix.f')],
360
                          'real': [file for file in os.listdir(os.path.join(self.dir,'SubProcesses', proc)) if 
361
                                   file.startswith('matrix_') and file.endswith('.f')]}
362
            
363
            for type in ['born', 'virt', 'real']:
364
                for file in files_dict[type]:
365
                    idnames = self.get_subprocesses_info_from_file(proc, file)
366
               
367
                    for id in range(1,len(idnames)+1):
368
369
                        if type == 'born':
370
                            line_dict = {'processdir': proc,
371
                                         'class': 'first'}
372
                            line_dict['first']= '<TD class=$class rowspan=%s> %s </TD>' % (len(idnames), proc)
373
                        else:
374
                            line_dict = {'processdir': 'proc',
375
                                         'class': 'second'}
376
                            line_dict['first'] = '<TD class=$class rowspan=%s>  </TD>' % (len(idnames))
377
                        try:
378
                            names = idnames[id]
466.1.45 by olivier Mattelaer
secure most of the try:...except:...
379
                        except Exception:
306 by Marco Zaro
the generated events are stored in Events/run_i (as for LO)
380
                            names = idnames['']
381
                            id = ''
382
                        line_dict['type'] = type
383
                        line_dict['id'] = str(id)     
408 by Marco Zaro
fixed the determination of the number of diagrams in info.html
384
                        line_dict['diag'] = self.get_diagram_nb_from_file(proc, file.replace('.f', '.ps'))
306 by Marco Zaro
the generated events are stored in Events/run_i (as for LO)
385
                        line_dict['subproc'] = sum([len(data) for data in names])
386
                        self.rep_rule['nb_diag'] += line_dict['diag'] * line_dict['subproc']
387
                        self.rep_rule['nb_gen_diag'] += line_dict['diag']
388
                        line_dict['subprocesslist'] = ', <br>'.join([' </SPAN> , <SPAN style="white-space: nowrap;"> '.join(info) for info in names])
389
                        line_dict['postscript'] = self.check_postcript_from_file(proc, file)
466.1.104 by Marco Zaro
small fixes:
390
                       
306 by Marco Zaro
the generated events are stored in Events/run_i (as for LO)
391
                        text += line_template.substitute(line_dict)
392
        return text
393
394
395
    def get_subprocesses_info_from_file(self, proc, filename):
396
        """ return the list of processes with their name in case without grouping
397
         type can be 0 for born, i > 0 for ith real and -1 for virtual"""
398
399
        nb_sub = 0
400
        names = {'':[[]]}
401
        path = os.path.join(self.dir, 'SubProcesses', proc, filename)
402
        if not os.path.exists(path):
403
            return []
404
        found = 0
78.294.61 by olivier Mattelaer
fix the problem of html in FKS
405
        start= 0
306 by Marco Zaro
the generated events are stored in Events/run_i (as for LO)
406
        for line in open(path):
407
            if line.startswith('C     Process:'):
408
                found += 1
78.294.61 by olivier Mattelaer
fix the problem of html in FKS
409
                names[''][0].append(line[15:-1])
410
                start =1
78.216.17 by Marco Zaro
fix to bug
411
            elif found >0 and 'IMPLICIT NONE' in line:
306 by Marco Zaro
the generated events are stored in Events/run_i (as for LO)
412
                break    
78.294.61 by olivier Mattelaer
fix the problem of html in FKS
413
            elif start:
414
                names[''][0][-1] += line[2:-1].strip()
306 by Marco Zaro
the generated events are stored in Events/run_i (as for LO)
415
        return names    
416
417
418
    def get_diagram_nb_from_file(self, proc, filename):
419
        
420
        path = os.path.join(self.dir, 'SubProcesses', proc, filename)
421
        nb_diag = 0
422
                
408 by Marco Zaro
fixed the determination of the number of diagrams in info.html
423
        pat = re.compile(r'''diagram (\d+)''' )
306 by Marco Zaro
the generated events are stored in Events/run_i (as for LO)
424
       
425
        text = open(path).read()
426
        for match in re.finditer(pat, text):
427
            pass
329.1.5 by Marco Zaro
added interactive mode option (-i) to launch command which will just change the interface to aMCatNLO_run
428
        try:
429
            nb_diag += int(match.groups()[0])
466.1.45 by olivier Mattelaer
secure most of the try:...except:...
430
        except Exception:
329.1.5 by Marco Zaro
added interactive mode option (-i) to launch command which will just change the interface to aMCatNLO_run
431
            pass
306 by Marco Zaro
the generated events are stored in Events/run_i (as for LO)
432
        
433
        return nb_diag
434
435
436
    def check_postcript_from_file(self, proc, filename):
437
        """ check if matrix.ps is defined """
438
        psname = filename[:-1] + 'ps'
439
        path = os.path.join(self.dir, 'SubProcesses', proc, psname) 
440
        if os.path.exists(path):
441
            return "<A HREF=\"../SubProcesses/%s/%s\" >postscript </A>" % \
442
                    (proc, psname)
443
        else:
444
            return ''
445
            
446
447
    def write(self):
448
        """write the info.html file"""
449
        
450
        fsock = open(os.path.join(self.dir,'HTML','info.html'),'w')
451
        text = template_text_nlo.substitute(self.rep_rule)
452
        fsock.write(text)