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
247 text = open(path).read()
248 for match in re.finditer(pat, text):
249 pass
250 nb_diag += int(match.groups()[0])
251
252 return nb_diag
253
254
256 """ return the list of processes with their name"""
257
258
259 path = os.path.join(self.dir, 'SubProcesses', proc)
260 nb_sub = 0
261 names = {}
262 old_main = ''
263
264 if not os.path.exists(os.path.join(path,'processes.dat')):
265 return self.get_subprocess_info_v4(proc)
266
267 for line in open(os.path.join(path,'processes.dat')):
268 main = line[:8].strip()
269 if main == 'mirror':
270 main = old_main
271 if line[8:].strip() == 'none':
272 continue
273 else:
274 main = int(main)
275 old_main = main
276
277 sub_proccess = line[8:]
278 nb_sub += sub_proccess.count(',') + 1
279 if main in names:
280 names[main] += [sub_proccess.split(',')]
281 else:
282 names[main]= [sub_proccess.split(',')]
283
284
285 return names
286
288 """ return the list of processes with their name in case without grouping """
289
290 nb_sub = 0
291 names = {'':[[]]}
292 path = os.path.join(self.dir, 'SubProcesses', proc,'auto_dsig.f')
293 found = 0
294 for line in open(path):
295 if line.startswith('C Process:'):
296 found += 1
297 names[''][0].append(line[15:])
298 elif found >1:
299 break
300 return names
301
302 - def check_postcript(self, proc, id):
303 """ check if matrix.ps is defined """
304 path = os.path.join(self.dir, 'SubProcesses', proc,'matrix%s.f' % id)
305 if os.path.exists(path):
306 return "<A HREF=\"../SubProcesses/%s/matrix%s.ps\" >postscript </A>" % \
307 (proc, id)
308 else:
309 return ''
310
312 path = os.path.join(self.dir, 'proc_log.txt')
313 if os.path.exists(path):
314 return """<TR>
315 <TD ALIGN=CENTER> <A HREF="../proc_log.txt">proc_log.txt</A> </TD>
316 <TD> Log file from MadGraph code generation. </TD>
317 </TR>"""
318 else:
319 return ''
320
322 """write the info.html file"""
323
324 fsock = open(os.path.join(self.dir,'HTML','info.html'),'w')
325 text = template_text.substitute(self.rep_rule)
326 fsock.write(text)
327
328
329
331
332
334 """define the information table"""
335
336
337 line_template = string.Template("""
338 <TR class=$class> $first
339 <TD> $type </TD>
340 <TD> $diag </TD>
341 <TD> $subproc </TD>
342 <TD>$postscript </TD>
343 <TD class=$class>
344 <SPAN style="white-space: nowrap;"> $subprocesslist</SPAN>
345 </TD></TR>""")
346
347
348
349 text = ''
350
351 subproc = [content for content in os.listdir(os.path.join(self.dir,'SubProcesses'))
352 if content.startswith('P') and
353 os.path.isdir(os.path.join(self.dir,'SubProcesses',content))
354 and os.path.islink(os.path.join(self.dir,'SubProcesses',content,'fks_singular.f'))]
355
356 for proc in subproc:
357 files_dict = {'born': ['born.f'],
358 'virt': [os.path.join('V' + proc[1:], 'loop_matrix.f')],
359 'real': [file for file in os.listdir(os.path.join(self.dir,'SubProcesses', proc)) if
360 file.startswith('matrix_') and file.endswith('.f')]}
361
362 for type in ['born', 'virt', 'real']:
363 for file in files_dict[type]:
364 idnames = self.get_subprocesses_info_from_file(proc, file)
365
366 for id in range(1,len(idnames)+1):
367
368 if type == 'born':
369 line_dict = {'processdir': proc,
370 'class': 'first'}
371 line_dict['first']= '<TD class=$class rowspan=%s> %s </TD>' % (len(idnames), proc)
372 else:
373 line_dict = {'processdir': 'proc',
374 'class': 'second'}
375 line_dict['first'] = '<TD class=$class rowspan=%s> </TD>' % (len(idnames))
376 try:
377 names = idnames[id]
378 except Exception:
379 names = idnames['']
380 id = ''
381 line_dict['type'] = type
382 line_dict['id'] = str(id)
383 line_dict['diag'] = self.get_diagram_nb_from_file(proc, file.replace('.f', '.ps'))
384 line_dict['subproc'] = sum([len(data) for data in names])
385 self.rep_rule['nb_diag'] += line_dict['diag'] * line_dict['subproc']
386 self.rep_rule['nb_gen_diag'] += line_dict['diag']
387 line_dict['subprocesslist'] = ', <br>'.join([' </SPAN> , <SPAN style="white-space: nowrap;"> '.join(info) for info in names])
388 line_dict['postscript'] = self.check_postcript_from_file(proc, file)
389
390 text += line_template.substitute(line_dict)
391 return text
392
393
395 """ return the list of processes with their name in case without grouping
396 type can be 0 for born, i > 0 for ith real and -1 for virtual"""
397
398 nb_sub = 0
399 names = {'':[[]]}
400 path = os.path.join(self.dir, 'SubProcesses', proc, filename)
401 if not os.path.exists(path):
402 return []
403 found = 0
404 start= 0
405 for line in open(path):
406 if line.startswith('C Process:'):
407 found += 1
408 names[''][0].append(line[15:-1])
409 start =1
410 elif found >0 and 'IMPLICIT NONE' in line:
411 break
412 elif start:
413 names[''][0][-1] += line[2:-1].strip()
414 return names
415
416
418
419 path = os.path.join(self.dir, 'SubProcesses', proc, filename)
420 nb_diag = 0
421
422 pat = re.compile(r'''diagram (\d+)''' )
423
424 text = open(path).read()
425 for match in re.finditer(pat, text):
426 pass
427 try:
428 nb_diag += int(match.groups()[0])
429 except Exception:
430 pass
431
432 return nb_diag
433
434
435 - def check_postcript_from_file(self, proc, filename):
436 """ check if matrix.ps is defined """
437 psname = filename[:-1] + 'ps'
438 path = os.path.join(self.dir, 'SubProcesses', proc, psname)
439 if os.path.exists(path):
440 return "<A HREF=\"../SubProcesses/%s/%s\" >postscript </A>" % \
441 (proc, psname)
442 else:
443 return ''
444
445
447 """write the info.html file"""
448
449 fsock = open(os.path.join(self.dir,'HTML','info.html'),'w')
450 text = template_text_nlo.substitute(self.rep_rule)
451 fsock.write(text)
452