1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import string
18 import os
19 import re
20 import sys
21
22 import madgraph.various.misc as misc
23
24 template_text= string.Template("""
25 <HTML>
26 <HEAD>
27 <TITLE>Detail on the Generation</TITLE>
28 <META $meta ></HEAD>
29
30 <style type="text/css">
31
32 table.processes { border-collapse: collapse;
33 border: solid}
34
35 .processes td {
36 padding: 2 5 2 5;
37 border: solid thin;
38 }
39
40 th{
41 border-top: solid;
42 border-bottom: solid;
43 }
44
45 .first td{
46 border-top: solid;
47 }
48
49
50
51
52 </style>
53
54 <BODY>
55 <P> <H2 ALIGN=CENTER> SubProcesses and Feynman diagrams </H2>
56
57 <TABLE BORDER=2 ALIGN=CENTER class=processes>
58 <TR>
59 <TH>Directory</TH>
60 <TH NOWRAP># Diagrams </TH>
61 <TH NOWRAP># Subprocesses </TH>
62 <TH>FEYNMAN DIAGRAMS</TH>
63 <TH> SUBPROCESS </TH>
64 </TR>
65 $info_lines
66 </TABLE><BR>
67 <CENTER> $nb_diag diagrams ($nb_gen_diag independent).</CENTER>
68 <br><br><br>
69 <TABLE ALIGN=CENTER>
70 $log
71 <TR>
72 <TD ALIGN=CENTER> <A HREF="../Cards/proc_card_mg5.dat">proc_card_mg5.dat</A> </TD>
73 <TD> Input file used for code generation.
74 $model_info
75 </TABLE><br>
76 <center>
77 <H3>Back to <A HREF="../index.html">Process main page</A></H3>
78 </center>
79 </BODY>
80
81 </HTML>""")
82
83
84 template_text_nlo= string.Template("""
85 <HTML>
86 <HEAD>
87 <TITLE>Detail on the Generation</TITLE>
88 <META $meta ></HEAD>
89
90 <style type="text/css">
91
92 table.processes { border-collapse: collapse;
93 border: solid}
94
95 .processes td {
96 padding: 2 5 2 5;
97 border: solid thin;
98 }
99
100 th{
101 border-top: solid;
102 border-bottom: solid;
103 }
104
105 .first td{
106 border-top: solid;
107 }
108
109
110
111
112 </style>
113
114 <BODY>
115 <P> <H2 ALIGN=CENTER> SubProcesses and Feynman diagrams </H2>
116
117 <TABLE BORDER=2 ALIGN=CENTER class=processes>
118 <TR>
119 <TH>Directory</TH>
120 <TH NOWRAP>Type</TH>
121 <TH NOWRAP># Diagrams </TH>
122 <TH NOWRAP># Subprocesses </TH>
123 <TH>FEYNMAN DIAGRAMS</TH>
124 <TH> SUBPROCESS </TH>
125 </TR>
126 $info_lines
127 </TABLE><BR>
128 <CENTER> $nb_diag diagrams ($nb_gen_diag independent).</CENTER>
129 <br><br><br>
130 <TABLE ALIGN=CENTER>
131 $log
132 <TR>
133 <TD ALIGN=CENTER> <A HREF="../Cards/proc_card_mg5.dat">proc_card_mg5.dat</A> </TD>
134 <TD> Input file used for code generation.
135 $model_info
136 </TABLE><br>
137 <center>
138 <H3>Back to <A HREF="../index.html">Process main page</A></H3>
139 </center>
140 </BODY>
141
142 </HTML>""")
143
144
146
148
149 self.dir = cur_dir
150
151
152 self.rep_rule = {'nb_diag': 0, 'nb_gen_diag': 0}
153
154 self.define_meta()
155 self.rep_rule['info_lines'] = self.define_info_tables()
156 self.rep_rule['model_info']= self.give_model_info()
157 self.rep_rule['log'] = self.check_log()
158 self.write()
159
160
162 """find path for the model"""
163
164 path = os.path.join(self.dir, 'Source','MODEL','particles.dat')
165 if os.path.exists(path):
166 return """<TR>
167 <TD ALIGN=CENTER> <A HREF="../Source/MODEL/particles.dat">particles</A></TD>
168 <TD> Particles file used for code generation.</TD>
169 </TR>
170 <TR>
171 <TD ALIGN=CENTER> <A HREF="../Source/MODEL/interactions.dat">interactions</A></TD>
172 <TD> Interactions file used for code generation.</TD>
173 </TR>"""
174 else:
175 return ''
176
177
185
186
188 """define the information table"""
189
190 line_template = string.Template("""
191 <TR class=$class> $first
192 <TD> $diag </TD>
193 <TD> $subproc </TD>
194 <TD> <A HREF="../SubProcesses/$processdir/diagrams.html#$id" >html</A> $postscript
195 </TD><TD class=$class>
196 <SPAN style="white-space: nowrap;"> $subprocesslist</SPAN>
197 </TD></TR>""")
198
199
200 text = ''
201
202 subproc = [content for content in os.listdir(os.path.join(self.dir,'SubProcesses'))
203 if content.startswith('P') and
204 os.path.isdir(os.path.join(self.dir,'SubProcesses',content))
205 and os.path.exists(os.path.join(self.dir,'SubProcesses',content,'auto_dsig.f'))]
206
207 for proc in subproc:
208
209 idnames = self.get_subprocesses_info(proc)
210
211 for id in range(1,len(idnames)+1):
212
213 if id == 1:
214
215 line_dict = {'processdir': proc,
216 'class': 'first'}
217 line_dict['first']= '<TD class=$class rowspan=%s> %s </TD>' % (len(idnames), proc)
218 else:
219 line_dict = {'processdir': proc,
220 'class': 'second'}
221 line_dict['first'] = ''
222 try:
223 names = idnames[id]
224 except Exception:
225 names = idnames['']
226 id = ''
227 line_dict['id'] = str(id)
228 line_dict['diag'] = self.get_diagram_nb(proc, id)
229 line_dict['subproc'] = sum([len(data) for data in names])
230 self.rep_rule['nb_diag'] += line_dict['diag'] * line_dict['subproc']
231 self.rep_rule['nb_gen_diag'] += line_dict['diag']
232 line_dict['subprocesslist'] = ', <br>'.join([' </SPAN> , <SPAN style="white-space: nowrap;"> '.join(info) for info in names])
233 line_dict['postscript'] = self.check_postcript(proc, id)
234
235 text += line_template.substitute(line_dict)
236 return text
237
239
240 path = os.path.join(self.dir, 'SubProcesses', proc, 'matrix%s.f' % id)
241 nb_diag = 0
242
243 pat = re.compile(r'''Amplitude\(s\) for diagram number (\d+)''' )
244
245 text = open(path).read()
246 for match in re.finditer(pat, text):
247 pass
248 nb_diag += int(match.groups()[0])
249
250 return nb_diag
251
252
254 """ return the list of processes with their name"""
255
256
257 path = os.path.join(self.dir, 'SubProcesses', proc)
258 nb_sub = 0
259 names = {}
260 old_main = ''
261
262 if not os.path.exists(os.path.join(path,'processes.dat')):
263 return self.get_subprocess_info_v4(proc)
264
265 for line in open(os.path.join(path,'processes.dat')):
266 main = line[:8].strip()
267 if main == 'mirror':
268 main = old_main
269 if line[8:].strip() == 'none':
270 continue
271 else:
272 main = int(main)
273 old_main = main
274
275 sub_proccess = line[8:]
276 nb_sub += sub_proccess.count(',') + 1
277 if main in names:
278 names[main] += [sub_proccess.split(',')]
279 else:
280 names[main]= [sub_proccess.split(',')]
281
282
283 return names
284
286 """ return the list of processes with their name in case without grouping """
287
288 nb_sub = 0
289 names = {'':[[]]}
290 path = os.path.join(self.dir, 'SubProcesses', proc,'auto_dsig.f')
291 found = 0
292 for line in open(path):
293 if line.startswith('C Process:'):
294 found += 1
295 names[''][0].append(line[15:])
296 elif found >1:
297 break
298 return names
299
300 - def check_postcript(self, proc, id):
301 """ check if matrix.ps is defined """
302 path = os.path.join(self.dir, 'SubProcesses', proc,'matrix%s.f' % id)
303 if os.path.exists(path):
304 return "<A HREF=\"../SubProcesses/%s/matrix%s.ps\" >postscript </A>" % \
305 (proc, id)
306 else:
307 return ''
308
310 path = os.path.join(self.dir, 'proc_log.txt')
311 if os.path.exists(path):
312 return """<TR>
313 <TD ALIGN=CENTER> <A HREF="../proc_log.txt">proc_log.txt</A> </TD>
314 <TD> Log file from MadGraph code generation. </TD>
315 </TR>"""
316 else:
317 return ''
318
320 """write the info.html file"""
321
322 fsock = open(os.path.join(self.dir,'HTML','info.html'),'w')
323 text = template_text.substitute(self.rep_rule)
324 fsock.write(text)
325
326
327
329
330
332 """define the information table"""
333
334
335 line_template = string.Template("""
336 <TR class=$class> $first
337 <TD> $type </TD>
338 <TD> $diag </TD>
339 <TD> $subproc </TD>
340 <TD>$postscript </TD>
341 <TD class=$class>
342 <SPAN style="white-space: nowrap;"> $subprocesslist</SPAN>
343 </TD></TR>""")
344
345
346
347 text = ''
348
349 subproc = [content for content in os.listdir(os.path.join(self.dir,'SubProcesses'))
350 if content.startswith('P') and
351 os.path.isdir(os.path.join(self.dir,'SubProcesses',content))
352 and os.path.islink(os.path.join(self.dir,'SubProcesses',content,'fks_singular.f'))]
353
354 for proc in subproc:
355 files_dict = {'born': ['born.f'],
356 'virt': [os.path.join('V' + proc[1:], 'loop_matrix.f')],
357 'real': [file for file in os.listdir(os.path.join(self.dir,'SubProcesses', proc)) if
358 file.startswith('matrix_') and file.endswith('.f')]}
359
360 for type in ['born', 'virt', 'real']:
361 for file in files_dict[type]:
362 idnames = self.get_subprocesses_info_from_file(proc, file)
363
364 for id in range(1,len(idnames)+1):
365
366 if type == 'born':
367 line_dict = {'processdir': proc,
368 'class': 'first'}
369 line_dict['first']= '<TD class=$class rowspan=%s> %s </TD>' % (len(idnames), proc)
370 else:
371 line_dict = {'processdir': 'proc',
372 'class': 'second'}
373 line_dict['first'] = '<TD class=$class rowspan=%s> </TD>' % (len(idnames))
374 try:
375 names = idnames[id]
376 except Exception:
377 names = idnames['']
378 id = ''
379 line_dict['type'] = type
380 line_dict['id'] = str(id)
381 line_dict['diag'] = self.get_diagram_nb_from_file(proc, file.replace('.f', '.ps'))
382 line_dict['subproc'] = sum([len(data) for data in names])
383 self.rep_rule['nb_diag'] += line_dict['diag'] * line_dict['subproc']
384 self.rep_rule['nb_gen_diag'] += line_dict['diag']
385 line_dict['subprocesslist'] = ', <br>'.join([' </SPAN> , <SPAN style="white-space: nowrap;"> '.join(info) for info in names])
386 line_dict['postscript'] = self.check_postcript_from_file(proc, file)
387
388 text += line_template.substitute(line_dict)
389 return text
390
391
393 """ return the list of processes with their name in case without grouping
394 type can be 0 for born, i > 0 for ith real and -1 for virtual"""
395
396 nb_sub = 0
397 names = {'':[[]]}
398 path = os.path.join(self.dir, 'SubProcesses', proc, filename)
399 if not os.path.exists(path):
400 return []
401 found = 0
402 start= 0
403 for line in open(path):
404 if line.startswith('C Process:'):
405 found += 1
406 names[''][0].append(line[15:-1])
407 start =1
408 elif found >0 and 'IMPLICIT NONE' in line:
409 break
410 elif start:
411 names[''][0][-1] += line[2:-1].strip()
412 return names
413
414
416
417 path = os.path.join(self.dir, 'SubProcesses', proc, filename)
418 nb_diag = 0
419
420 pat = re.compile(r'''diagram (\d+)''' )
421
422 text = open(path).read()
423 for match in re.finditer(pat, text):
424 pass
425 try:
426 nb_diag += int(match.groups()[0])
427 except Exception:
428 pass
429
430 return nb_diag
431
432
433 - def check_postcript_from_file(self, proc, filename):
434 """ check if matrix.ps is defined """
435 psname = filename[:-1] + 'ps'
436 path = os.path.join(self.dir, 'SubProcesses', proc, psname)
437 if os.path.exists(path):
438 return "<A HREF=\"../SubProcesses/%s/%s\" >postscript </A>" % \
439 (proc, psname)
440 else:
441 return ''
442
443
445 """write the info.html file"""
446
447 fsock = open(os.path.join(self.dir,'HTML','info.html'),'w')
448 text = template_text_nlo.substitute(self.rep_rule)
449 fsock.write(text)
450