1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 from __future__ import absolute_import
18 import string
19 import os
20 import re
21 import sys
22
23 import madgraph.various.misc as misc
24 from six.moves import range
25
26 template_text= string.Template("""
27 <HTML>
28 <HEAD>
29 <TITLE>Detail on the Generation</TITLE>
30 <META $meta ></HEAD>
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
56 <BODY>
57 <P> <H2 ALIGN=CENTER> SubProcesses and Feynman diagrams </H2>
58
59 <TABLE BORDER=2 ALIGN=CENTER class=processes>
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>
70 <br><br><br>
71 <TABLE ALIGN=CENTER>
72 $log
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
77 </TABLE><br>
78 <center>
79 <H3>Back to <A HREF="../index.html">Process main page</A></H3>
80 </center>
81 </BODY>
82
83 </HTML>""")
84
85
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
148
150
151 self.dir = cur_dir
152
153
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()
158 self.rep_rule['model_info']= self.give_model_info()
159 self.rep_rule['log'] = self.check_log()
160 self.write()
161
162
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>
174 <TD> Interactions file used for code generation.</TD>
175 </TR>"""
176 else:
177 return ''
178
179
187
188
190 """define the information table"""
191
192 line_template = string.Template("""
193 <TR class=$class> $first
194 <TD> $diag </TD>
195 <TD> $subproc </TD>
196 <TD> <A HREF="../SubProcesses/$processdir/diagrams.html#$id" >html</A> $postscript
197 </TD><TD class=$class>
198 <SPAN style="white-space: nowrap;"> $subprocesslist</SPAN>
199 </TD></TR>""")
200
201
202 text = ''
203
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)
212
213 for id in range(1,len(idnames)+1):
214
215 if id == 1:
216
217 line_dict = {'processdir': proc,
218 'class': 'first'}
219 line_dict['first']= '<TD class=$class rowspan=%s> %s </TD>' % (len(idnames), proc)
220 else:
221 line_dict = {'processdir': proc,
222 'class': 'second'}
223 line_dict['first'] = ''
224 try:
225 names = idnames[id]
226 except Exception:
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']
234 line_dict['subprocesslist'] = ', <br>'.join([' </SPAN> , <SPAN style="white-space: nowrap;"> '.join(info) for info in names])
235 line_dict['postscript'] = self.check_postcript(proc, id)
236
237 text += line_template.substitute(line_dict)
238 return text
239
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+)''' )
246 if not os.path.exists(path):
247 path = os.path.join(self.dir, 'SubProcesses', proc, 'matrix%s_orig.f' % id)
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
257 """ return the list of processes with their name"""
258
259
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
272 if line[8:].strip() == 'none':
273 continue
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(',')]
284
285
286 return names
287
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 ''
311
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 ''
321
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
332
333
335 """define the information table"""
336
337
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
350 text = ''
351
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]
379 except Exception:
380 names = idnames['']
381 id = ''
382 line_dict['type'] = type
383 line_dict['id'] = str(id)
384 line_dict['diag'] = self.get_diagram_nb_from_file(proc, file.replace('.f', '.ps'))
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)
390
391 text += line_template.substitute(line_dict)
392 return text
393
394
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
405 start= 0
406 for line in open(path):
407 if line.startswith('C Process:'):
408 found += 1
409 names[''][0].append(line[15:-1])
410 start =1
411 elif found >0 and 'IMPLICIT NONE' in line:
412 break
413 elif start:
414 names[''][0][-1] += line[2:-1].strip()
415 return names
416
417
419
420 path = os.path.join(self.dir, 'SubProcesses', proc, filename)
421 nb_diag = 0
422
423 pat = re.compile(r'''diagram (\d+)''' )
424
425 text = open(path).read()
426 for match in re.finditer(pat, text):
427 pass
428 try:
429 nb_diag += int(match.groups()[0])
430 except Exception:
431 pass
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
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)
453