Package madgraph :: Package madevent :: Module gen_crossxhtml
[hide private]
[frames] | no frames]

Source Code for Module madgraph.madevent.gen_crossxhtml

   1  ################################################################################ 
   2  # 
   3  # Copyright (c) 2011 The MadGraph5_aMC@NLO Development team and Contributors 
   4  # 
   5  # This file is a part of the MadGraph5_aMC@NLO project, an application which  
   6  # automatically generates Feynman diagrams and matrix elements for arbitrary 
   7  # high-energy processes in the Standard Model and beyond. 
   8  # 
   9  # It is subject to the MadGraph5_aMC@NLO license which should accompany this  
  10  # distribution. 
  11  # 
  12  # For more information, visit madgraph.phys.ucl.ac.be and amcatnlo.web.cern.ch 
  13  # 
  14  ################################################################################ 
  15  """ Create gen_crossxhtml """ 
  16   
  17   
  18  from __future__ import absolute_import 
  19  import os 
  20  import math 
  21  import re 
  22  import pickle 
  23  import re 
  24  import glob 
  25  import logging 
  26  import six 
  27  from six.moves import range 
  28   
  29  try: 
  30      import madgraph 
  31  except ImportError: 
  32      import internal.files as files 
  33      import internal.save_load_object as save_load_object 
  34      import internal.lhe_parser as lhe_parser 
  35      import internal.misc as misc 
  36      import internal.banner as bannerlib 
  37  else: 
  38      import madgraph.iolibs.files as files 
  39      import madgraph.iolibs.save_load_object as save_load_object 
  40      import madgraph.various.lhe_parser as lhe_parser 
  41      import madgraph.various.misc as misc 
  42      import madgraph.various.banner as bannerlib 
  43   
  44  pjoin = os.path.join 
  45  exists = os.path.exists 
  46  logger = logging.getLogger('madgraph.stdout') # -> stdout 
  47   
  48   
  49   
  50  crossxhtml_template = """ 
  51  <HTML>  
  52  <HEAD>  
  53      %(refresh)s  
  54      <META HTTP-EQUIV="EXPIRES" CONTENT="20" >  
  55      <TITLE>Online Event Generation</TITLE> 
  56      <link rel=stylesheet href="./HTML/mgstyle.css" type="text/css"> 
  57  </HEAD> 
  58  <BODY> 
  59  <script type="text/javascript"> 
  60  function UrlExists(url) { 
  61    var http = new XMLHttpRequest(); 
  62    http.open('HEAD', url, false); 
  63    try{ 
  64       http.send() 
  65       } 
  66    catch(err){ 
  67     return 1==2; 
  68    } 
  69    return http.status!=404; 
  70  } 
  71  </script>     
  72      <H2 align=center> Results in the %(model)s for %(process)s </H2>  
  73      <HR> 
  74      %(status)s 
  75      <br> 
  76      <br> 
  77      <H2 align="center"> Available Results </H2> 
  78          <TABLE BORDER=2 align="center">   
  79              <TR align="center"> 
  80                  <TH>Run</TH>  
  81                  <TH>Collider</TH>  
  82                  <TH> Banner </TH> 
  83                  <TH> %(numerical_title)s </TH>  
  84                  <TH> Events  </TH> 
  85                  <TH> Data </TH>   
  86                  <TH>Output</TH> 
  87                  <TH>Action</TH>  
  88              </TR>       
  89              %(old_run)s 
  90          </TABLE> 
  91      <H3 align=center><A HREF="./index.html"> Main Page </A></H3> 
  92  </BODY>  
  93  </HTML>  
  94  """ 
  95   
  96  status_template = """ 
  97  <H2 ALIGN=CENTER> Currently Running %(run_mode_string)s</H2> 
  98  <TABLE BORDER=2 ALIGN=CENTER> 
  99      <TR ALIGN=CENTER> 
 100          <TH nowrap ROWSPAN=2 font color="#0000FF"> Run Name </TH> 
 101          <TH nowrap ROWSPAN=2 font color="#0000FF"> Tag Name </TH> 
 102          <TH nowrap ROWSPAN=2 font color="#0000FF"> Cards </TH>    
 103          <TH nowrap ROWSPAN=2 font color="#0000FF"> Results </TH>  
 104          <TH nowrap ROWSPAN=1 COLSPAN=3 font color="#0000FF"> Status/Jobs </TH> 
 105      </TR> 
 106          <TR>  
 107              <TH>   Queued </TH> 
 108              <TH>  Running </TH> 
 109              <TH> Done  </TH> 
 110          </TR> 
 111      <TR ALIGN=CENTER>  
 112          <TD nowrap ROWSPAN=2> %(run_name)s </TD> 
 113          <TD nowrap ROWSPAN=2> %(tag_name)s </TD> 
 114          <TD nowrap ROWSPAN=2> <a href="./Cards/param_card.dat">param_card</a><BR> 
 115                      <a href="./Cards/run_card.dat">run_card</a><BR> 
 116                      %(plot_card)s 
 117                      %(pythia_card)s 
 118                      %(pgs_card)s 
 119                      %(delphes_card)s 
 120                      %(shower_card)s 
 121                      %(fo_analyse_card)s 
 122          </TD> 
 123          <TD nowrap ROWSPAN=2> %(results)s </TD>  
 124          %(status)s 
 125   </TR> 
 126   <TR></TR> 
 127     %(stop_form)s 
 128   </TABLE> 
 129  """ 
 130   
131 -class AllResults(dict):
132 """Store the results for all the run of a given directory""" 133 134 web = False 135 136 _run_entries = ['cross', 'error','nb_event_pythia','run_mode','run_statistics', 137 'nb_event','cross_pythia','error_pythia', 138 'nb_event_pythia8','cross_pythia8','error_pythia8', 'shower_dir'] 139
140 - def __init__(self, model, process, path, recreateold=True):
141 142 dict.__init__(self) 143 self.order = [] 144 self.lastrun = None 145 self.process = ', '.join(process) 146 if len(self.process) > 60: 147 pos = self.process[50:].find(',') 148 if pos != -1: 149 self.process = self.process[:50+pos] + ', ...' 150 self.path = path 151 self.model = model 152 self.status = '' 153 self.unit = 'pb' 154 self.current = None 155 156 # Check if some directory already exists and if so add them 157 runs = [d for d in os.listdir(pjoin(path, 'Events')) if 158 os.path.isdir(pjoin(path, 'Events', d))] 159 160 if runs: 161 if recreateold: 162 for run in runs: 163 self.readd_old_run(run) 164 if self.order: 165 self.current = self[self.order[-1]] 166 else: 167 logger.warning("Previous runs exists but they will not be present in the html output.")
168
169 - def readd_old_run(self, run_name):
170 """ re-create the data-base from scratch if the db was remove """ 171 172 event_path = pjoin(self.path, "Events", run_name, "unweighted_events.lhe") 173 174 try: 175 import internal 176 except ImportError: 177 import madgraph.various.banner as bannerlib 178 else: 179 import internal.banner as bannerlib 180 181 if os.path.exists("%s.gz" % event_path): 182 misc.gunzip(event_path, keep=True) 183 if not os.path.exists(event_path): 184 return 185 banner = bannerlib.Banner(event_path) 186 187 # load the information to add a new Run: 188 run_card = banner.charge_card("run_card") 189 process = banner.get_detail("proc_card", "generate") 190 #create the new object 191 run = RunResults(run_name, run_card, process, self.path) 192 run.recreate(banner) 193 self[run_name] = run 194 self.order.append(run_name)
195 196
197 - def def_current(self, run, tag=None):
198 """define the name of the current run 199 The first argument can be a OneTagResults 200 """ 201 202 if isinstance(run, OneTagResults): 203 self.current = run 204 self.lastrun = run['run_name'] 205 return 206 207 assert run in self or run == None 208 self.lastrun = run 209 if run: 210 if not tag: 211 self.current = self[run][-1] 212 else: 213 assert tag in self[run].tags 214 index = self[run].tags.index(tag) 215 self.current = self[run][index] 216 217 else: 218 self.current = None
219
220 - def delete_run(self, run_name, tag=None):
221 """delete a run from the database""" 222 223 assert run_name in self 224 225 if not tag : 226 if self.current and self.current['run_name'] == run_name: 227 self.def_current(None) 228 del self[run_name] 229 self.order.remove(run_name) 230 if self.lastrun == run_name: 231 self.lastrun = None 232 else: 233 assert tag in [a['tag'] for a in self[run_name]] 234 RUN = self[run_name] 235 if len(RUN) == 1: 236 self.delete_run(run_name) 237 return 238 RUN.remove(tag) 239 240 #update the html 241 self.output()
242
243 - def def_web_mode(self, web):
244 """define if we are in web mode or not """ 245 if web is True: 246 try: 247 web = os.environ['SERVER_NAME'] 248 except Exception: 249 web = 'my_computer' 250 self['web'] = web 251 self.web = web
252
253 - def add_run(self, name, run_card, current=True):
254 """ Adding a run to this directory""" 255 256 tag = run_card['run_tag'] 257 if name in self.order: 258 #self.order.remove(name) # Reorder the run to put this one at the end 259 if tag in self[name].tags: 260 if self[name].return_tag(tag).parton and len(self[name]) > 1: 261 #move the parton information before the removr 262 self[name].return_tag(self[name][1]['tag']).parton = \ 263 self[name].return_tag(tag).parton 264 if len(self[name]) > 1: 265 self[name].remove(tag) # Remove previous tag if define 266 self[name].add(OneTagResults(name, run_card, self.path)) 267 else: 268 #add the new tag run 269 self[name].add(OneTagResults(name, run_card, self.path)) 270 new = self[name] 271 else: 272 new = RunResults(name, run_card, self.process, self.path) 273 self[name] = new 274 self.order.append(name) 275 276 if current: 277 self.def_current(name) 278 if new.info['unit'] == 'GeV': 279 self.unit = 'GeV'
280
281 - def update(self, status, level, makehtml=True, error=False):
282 """update the current run status""" 283 if self.current: 284 self.current.update_status(level) 285 self.status = status 286 if self.current and self.current.debug and self.status and not error: 287 self.current.debug = None 288 289 if makehtml: 290 self.output()
291
292 - def resetall(self, main_path=None):
293 """check the output status of all run 294 main_path redefines the path associated to the run (allowing to move 295 the directory) 296 """ 297 298 self.path = main_path 299 300 for key,run in self.items(): 301 if key == 'web': 302 continue 303 for i,subrun in enumerate(run): 304 self.def_current(subrun) 305 self.clean() 306 self.current.event_path = pjoin(main_path,'Events') 307 self.current.me_dir = main_path 308 if i==0: 309 self.current.update_status() 310 else: 311 self.current.update_status(nolevel='parton') 312 self.output()
313
314 - def clean(self, levels = ['all'], run=None, tag=None):
315 """clean the run for the levels""" 316 317 if not run and not self.current: 318 return 319 to_clean = self.current 320 if run and not tag: 321 for tagrun in self[run]: 322 self.clean(levels, run, tagrun['tag']) 323 return 324 325 if run: 326 to_clean = self[run].return_tag(tag) 327 else: 328 run = to_clean['run_name'] 329 330 if 'all' in levels: 331 levels = ['parton', 'pythia', 'pgs', 'delphes', 'channel'] 332 333 if 'parton' in levels: 334 to_clean.parton = [] 335 if 'pythia' in levels: 336 to_clean.pythia = [] 337 if 'pgs' in levels: 338 to_clean.pgs = [] 339 if 'delphes' in levels: 340 to_clean.delphes = []
341 342
343 - def save(self):
344 """Save the results of this directory in a pickle file""" 345 filename = pjoin(self.path, 'HTML', 'results.pkl') 346 save_load_object.save_to_file(filename, self)
347
348 - def add_detail(self, name, value, run=None, tag=None):
349 """ add information to current run (cross/error/event)""" 350 assert name in AllResults._run_entries 351 352 if not run and not self.current: 353 return 354 355 if not run: 356 run = self.current 357 else: 358 run = self[run].return_tag(tag) 359 360 if name in ['cross_pythia']: 361 run[name] = float(value) 362 elif name in ['nb_event']: 363 run[name] = int(value) 364 elif name in ['nb_event_pythia']: 365 run[name] = int(value) 366 elif name in ['run_mode','run_statistics']: 367 run[name] = value 368 elif name in ['shower_dir']: 369 run[name] = value 370 elif name == 'cross' and run[name] != 0: 371 run['prev_' + name] = run[name] 372 run[name] = float(value) 373 else: 374 run[name] = float(value)
375
376 - def get_detail(self, name, run=None, tag=None):
377 """ add information to current run (cross/error/event)""" 378 assert name in AllResults._run_entries 379 380 if not run and not self.current: 381 return None 382 383 if not run: 384 run = self.current 385 else: 386 run = self[run].return_tag(tag) 387 388 return run[name]
389
390 - def output(self):
391 """ write the output file """ 392 393 # 1) Create the text for the status directory 394 if self.status and self.current: 395 if isinstance(self.status, str): 396 status = '<td ROWSPAN=2 colspan=4>%s</td>' % self.status 397 else: 398 s = list(self.status) 399 if s[0] == '$events': 400 if self.current['nb_event']: 401 nevent = self.current['nb_event'] 402 else: 403 nevent = self[self.current['run_name']][0]['nb_event'] 404 if nevent: 405 s[0] = nevent - int(s[1]) -int(s[2]) 406 else: 407 s[0] = '' 408 status ='''<td> %s </td> <td> %s </td> <td> %s </td> 409 </tr><tr><td colspan=3><center> %s </center></td>''' % (s[0],s[1], s[2], s[3]) 410 411 412 status_dict = {'status': status, 413 'cross': self.current['cross'], 414 'error': self.current['error'], 415 'run_name': self.current['run_name'], 416 'tag_name': self.current['tag'], 417 'unit': self[self.current['run_name']].info['unit']} 418 # add the run_mode_string for amcatnlo_run 419 if 'run_mode' in list(self.current.keys()): 420 run_mode_string = {'aMC@NLO': '(aMC@NLO)', 421 'aMC@LO': '(aMC@LO)', 422 'noshower': '(aMC@NLO)', 423 'noshowerLO': '(aMC@LO)', 424 'NLO': '(NLO f.o.)', 425 'LO': '(LO f.o.)', 426 'madevent':'' 427 } 428 status_dict['run_mode_string'] = run_mode_string[self.current['run_mode']] 429 else: 430 status_dict['run_mode_string'] = '' 431 432 433 if exists(pjoin(self.path, 'HTML',self.current['run_name'], 434 'results.html')): 435 status_dict['results'] = """<A HREF="./HTML/%(run_name)s/results.html">%(cross).4g <font face=symbol>&#177;</font> %(error).4g (%(unit)s)</A>""" % status_dict 436 else: 437 status_dict['results'] = "No results yet" 438 if exists(pjoin(self.path, 'Cards', 'plot_card.dat')): 439 status_dict['plot_card'] = """ <a href="./Cards/plot_card.dat">plot_card</a><BR>""" 440 else: 441 status_dict['plot_card'] = "" 442 if exists(pjoin(self.path, 'Cards', 'pythia_card.dat')): 443 status_dict['pythia_card'] = """ <a href="./Cards/pythia_card.dat">pythia_card</a><BR>""" 444 else: 445 status_dict['pythia_card'] = "" 446 if exists(pjoin(self.path, 'Cards', 'pgs_card.dat')): 447 status_dict['pgs_card'] = """ <a href="./Cards/pgs_card.dat">pgs_card</a><BR>""" 448 else: 449 status_dict['pgs_card'] = "" 450 if exists(pjoin(self.path, 'Cards', 'delphes_card.dat')): 451 status_dict['delphes_card'] = """ <a href="./Cards/delphes_card.dat">delphes_card</a><BR>""" 452 else: 453 status_dict['delphes_card'] = "" 454 if exists(pjoin(self.path, 'Cards', 'shower_card.dat')): 455 status_dict['shower_card'] = """ <a href="./Cards/shower_card.dat">shower_card</a><BR>""" 456 else: 457 status_dict['shower_card'] = "" 458 if exists(pjoin(self.path, 'Cards', 'FO_analyse_card.dat')): 459 status_dict['fo_analyse_card'] = """ <a href="./Cards/FO_analyse_card.dat">FO_analyse_card</a><BR>""" 460 else: 461 status_dict['fo_analyse_card'] = "" 462 463 if self.web: 464 status_dict['stop_form'] = """ 465 <TR ALIGN=CENTER><TD COLSPAN=7 text-align=center> 466 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 467 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 468 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="stop_job"> 469 <INPUT TYPE=SUBMIT VALUE="Stop Current Job"> 470 </FORM></TD></TR>""" % {'me_dir': self.path, 'web': self.web} 471 else: 472 status_dict['stop_form'] = "" 473 474 475 status = status_template % status_dict 476 refresh = "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"10\">" 477 else: 478 status ='' 479 refresh = '' 480 481 482 # See if we need to incorporate the button for submission 483 if os.path.exists(pjoin(self.path, 'RunWeb')): 484 running = True 485 else: 486 running = False 487 488 # 2) Create the text for the old run: 489 old_run = '' 490 for key in self.order: 491 old_run += self[key].get_html(self.path, web=self.web, running=running) 492 493 text_dict = {'process': self.process, 494 'model': self.model, 495 'status': status, 496 'old_run': old_run, 497 'refresh': refresh, 498 'numerical_title': self.unit == 'pb' and 'Cross section (pb)'\ 499 or 'Width (GeV)'} 500 501 text = crossxhtml_template % text_dict 502 open(pjoin(self.path,'crossx.html'),'w').write(text)
503 504
505 -class AllResultsNLO(AllResults):
506 """Store the results for a NLO run of a given directory""" 507
508 - def __init__(self,model, process, path, recreateold=False):
509 return AllResults.__init__(self, model, process, path, recreateold=recreateold)
510 511
512 -class RunResults(list):
513 """The list of all OneTagResults""" 514
515 - def __init__(self, run_name, run_card, process, path):
516 """initialize the object""" 517 518 self.info = {'run_name': run_name,'me_dir':path} 519 self.tags = [run_card['run_tag']] 520 521 # Set the collider information 522 data = process.split('>',1)[0].split() 523 if len(data) == 2: 524 name1,name2 = data 525 if run_card['lpp1'] == -1: 526 name1 = ' p~' 527 elif run_card['lpp1'] == 1: 528 name1 = ' p' 529 elif run_card['lpp1'] in [2,3]: 530 name1 = ' a' 531 if run_card['lpp2'] == -1: 532 name2 = 'p~' 533 elif run_card['lpp2'] == 1: 534 name2 = ' p' 535 elif run_card['lpp2'] == [2,3]: 536 name2 = ' a' 537 self.info['collider'] = '''%s %s <br> %s x %s GeV''' % \ 538 (name1, name2, run_card['ebeam1'], run_card['ebeam2']) 539 self.info['unit'] = 'pb' 540 elif len(data) == 1: 541 self.info['collider'] = 'decay' 542 self.info['unit'] = 'GeV' 543 else: 544 self.info['collider'] = 'special mode' 545 self.info['unit'] = '' 546 547 self.append(OneTagResults(run_name, run_card, path))
548 549
550 - def get_html(self, output_path, **opt):
551 """WRITE HTML OUTPUT""" 552 553 try: 554 self.web = opt['web'] 555 self.info['web'] = self.web 556 except Exception: 557 self.web = False 558 559 # check if more than one parton output except for tags corresponding 560 # to different MA5 parton-level runs. 561 parton = [r for r in self if (r.parton and 'lhe' in r.parton)] 562 # clean wrong previous run link 563 if len(parton)>1: 564 for p in parton[:-1]: 565 # Do not remove the MA5 parton level results. 566 for res in p.parton: 567 if not res.startswith('ma5'): 568 p.parton.remove(res) 569 570 dico = self.info 571 dico['run_span'] = sum([tag.get_nb_line() for tag in self], 1) -1 572 dico['tag_data'] = '\n'.join([tag.get_html(self) for tag in self]) 573 text = """ 574 <tr> 575 <td rowspan=%(run_span)s>%(run_name)s</td> 576 <td rowspan=%(run_span)s><center> %(collider)s </center></td> 577 %(tag_data)s 578 </tr> 579 """ % dico 580 581 if self.web: 582 583 text = text % self.info 584 585 return text
586 587
588 - def return_tag(self, name):
589 590 for data in self: 591 if data['tag'] == name: 592 return data 593 594 if name is None: 595 # return last entry 596 return self[-1] 597 598 raise Exception('%s is not a valid tag' % name)
599
600 - def recreate(self, banner):
601 """Fully recreate the information due to a hard removal of the db 602 Work for LO ONLY!""" 603 604 run_name = self.info["run_name"] 605 run_card = banner.get("run_card") 606 path = self.info["me_dir"] 607 # Recover the main information (cross-section/number of event) 608 informations = banner['mggenerationinfo'] 609 #number of events 610 nb_event = re.search(r"Number\s*of\s*Events\s*:\s*(\d*)", informations) 611 if nb_event: 612 nb_event = int(nb_event.group(1)) 613 else: 614 nb_event = 0 615 616 # cross-section 617 cross = re.search(r"Integrated\s*weight\s*\(\s*pb\s*\)\s*:\s*([\+\-\d.e]+)", informations, 618 re.I) 619 if cross: 620 cross = float(cross.group(1)) 621 else: 622 cross = 0 623 624 # search pythia file for tag: tag_1_pythia.log 625 path = pjoin(self.info['me_dir'],'Events', self.info['run_name']) 626 files = [pjoin(path, f) for f in os.listdir(path) if 627 os.path.isfile(pjoin(path,f)) and f.endswith('pythia.log')] 628 #order them by creation date. 629 files.sort(key=lambda x: os.path.getmtime(x)) 630 tags = [os.path.basename(name[:-11]) for name in files] 631 632 633 # No pythia only a single run: 634 if not tags: 635 self[-1]['nb_event'] = nb_event 636 self[-1]['cross'] = cross 637 638 #Loop over pythia run 639 for tag in tags: 640 if tag not in self.tags: 641 tagresult = OneTagResults(run_name, run_card, path) 642 tagresult['tag'] = tag 643 self.add(tagresult) 644 else: 645 tagresult = self.return_tag(tag) 646 tagresult['nb_event'] = nb_event 647 tagresult['cross'] = cross 648 if run_card['ickkw'] != 0: 649 #parse the file to have back the information 650 pythia_log = misc.BackRead(pjoin(path, '%s_pythia.log' % tag)) 651 pythiare = re.compile("\s*I\s+0 All included subprocesses\s+I\s+(?P<generated>\d+)\s+(?P<tried>\d+)\s+I\s+(?P<xsec>[\d\.D\-+]+)\s+I") 652 for line in pythia_log: 653 info = pythiare.search(line) 654 if not info: 655 continue 656 try: 657 # Pythia cross section in mb, we want pb 658 sigma_m = float(info.group('xsec').replace('D','E')) *1e9 659 Nacc = int(info.group('generated')) 660 except ValueError: 661 # xsec is not float - this should not happen 662 tagresult['cross_pythia'] = 0 663 tagresult['nb_event_pythia'] = 0 664 tagresult['error_pythia'] = 0 665 else: 666 tagresult['cross_pythia'] = sigma_m 667 tagresult['nb_event_pythia'] = Nacc 668 tagresult['error_pythia'] = 0 669 break 670 pythia_log.close()
671 672
673 - def is_empty(self):
674 """Check if this run contains smtg else than html information""" 675 676 if not self: 677 return True 678 if len(self) > 1: 679 return False 680 681 data = self[0] 682 if data.parton or data.pythia or data.pgs or data.delphes: 683 return False 684 else: 685 return True
686
687 - def add(self, obj):
688 """ """ 689 690 assert isinstance(obj, OneTagResults) 691 tag = obj['tag'] 692 assert tag not in self.tags 693 self.tags.append(tag) 694 self.append(obj)
695
696 - def get_last_pythia(self):
697 for i in range(1, len(self)+1): 698 if self[-i].pythia or self[-i].pythia8: 699 return self[-i]['tag']
700
701 - def get_current_info(self):
702 703 output = {} 704 current = self[-1] 705 # Check that cross/nb_event/error are define 706 if current.pythia and not current['nb_event'] and len(self) > 1: 707 output['nb_event'] = self[-2]['nb_event'] 708 output['cross'] = self[-2]['cross'] 709 output['error'] = self[-2]['error'] 710 elif (current.pgs or current.delphes) and not current['nb_event'] and len(self) > 1: 711 if self[-2]['cross_pythia'] and self[-2]['nb_event_pythia']: 712 output['cross'] = self[-2]['cross_pythia'] 713 output['nb_event'] = self[-2]['nb_event_pythia'] 714 output['error'] = self[-2]['error_pythia'] 715 else: 716 output['nb_event'] = self[-2]['nb_event'] 717 output['cross'] = self[-2]['cross'] 718 output['error'] = self[-2]['error'] 719 elif current['cross']: 720 return current 721 elif len(self) > 1: 722 output['nb_event'] = self[-2]['nb_event'] 723 output['cross'] = self[-2]['cross'] 724 output['error'] = self[-2]['error'] 725 else: 726 output['nb_event'] = 0 727 output['cross'] = 0 728 output['error'] = 1e-99 729 return output
730 731
732 - def remove(self, tag):
733 734 assert tag in self.tags 735 736 obj = [o for o in self if o['tag']==tag][0] 737 self.tags.remove(tag) 738 list.remove(self, obj)
739 740 741
742 -class OneTagResults(dict):
743 """ Store the results of a specific run """ 744
745 - def __init__(self, run_name, run_card, path):
746 """initialize the object""" 747 748 # define at run_result 749 self['run_name'] = run_name 750 self['tag'] = run_card['run_tag'] 751 self['event_norm'] = run_card['event_norm'] 752 self.event_path = pjoin(path,'Events') 753 self.me_dir = path 754 self.debug = None 755 756 # Default value 757 self['nb_event'] = 0 758 self['cross'] = 0 759 self['cross_pythia'] = '' 760 self['nb_event_pythia'] = 0 761 self['error'] = 0 762 self['run_mode'] = 'madevent' 763 self.parton = [] 764 self.reweight = [] 765 self.pythia = [] 766 self.pythia8 = [] 767 self.madanalysis5_hadron = [] 768 # This is just a container that contain 'done' when the parton level MA5 769 # analysis is done, so that set_run_name knows when to update the tag 770 self.madanalysis5_parton = [] 771 self.pgs = [] 772 self.delphes = [] 773 self.shower = [] 774 775 self.level_modes = ['parton', 'pythia', 'pythia8', 776 'pgs', 'delphes','reweight','shower', 777 'madanalysis5_hadron','madanalysis5_parton'] 778 # data 779 self.status = '' 780 781 # Dictionary with (Pdir,G) as keys and sum_html.RunStatistics instances 782 # as values 783 self['run_statistics'] = {}
784 785
786 - def update_status(self, level='all', nolevel=[]):
787 """update the status of the current run """ 788 exists = os.path.exists 789 run = self['run_name'] 790 tag =self['tag'] 791 792 path = pjoin(self.event_path, run) 793 html_path = pjoin(self.event_path, os.pardir, 'HTML', run) 794 795 # Check if the output of the last status exists 796 if level in ['gridpack','all']: 797 if 'gridpack' not in self.parton and \ 798 exists(pjoin(path,os.pardir ,os.pardir,"%s_gridpack.tar.gz" % run)): 799 self.parton.append('gridpack') 800 # Check if the output of the last status exists 801 if level in ['reweight','all']: 802 if 'plot' not in self.reweight and \ 803 exists(pjoin(html_path,"plots_%s.html" % tag)): 804 self.reweight.append('plot') 805 806 # We also trigger parton for madanalysis5_parton because its results 807 # must be added to self.parton 808 if level in ['parton','all'] and 'parton' not in nolevel: 809 810 if 'lhe' not in self.parton and \ 811 (exists(pjoin(path,"unweighted_events.lhe.gz")) or 812 exists(pjoin(path,"unweighted_events.lhe")) or 813 exists(pjoin(path,"events.lhe.gz")) or 814 exists(pjoin(path,"events.lhe"))): 815 self.parton.append('lhe') 816 817 if 'root' not in self.parton and \ 818 exists(pjoin(path,"unweighted_events.root")): 819 self.parton.append('root') 820 821 if 'plot' not in self.parton and \ 822 exists(pjoin(html_path,"plots_parton.html")): 823 self.parton.append('plot') 824 825 if 'param_card' not in self.parton and \ 826 exists(pjoin(path, "param_card.dat")): 827 self.parton.append('param_card') 828 829 if 'syst' not in self.parton and \ 830 exists(pjoin(path, "parton_systematics.log")): 831 self.parton.append('syst') 832 833 for kind in ['top','HwU','pdf','ps']: 834 if misc.glob("*.%s" % kind, path): 835 if self['run_mode'] in ['LO', 'NLO']: 836 self.parton.append('%s' % kind) 837 if exists(pjoin(path,'summary.txt')): 838 self.parton.append('summary.txt') 839 840 841 if level in ['madanalysis5_parton','all'] and 'madanalysis5_parton' not in nolevel: 842 843 if 'ma5_plot' not in self.parton and \ 844 misc.glob("%s_MA5_parton_analysis_*.pdf"%self['tag'], path): 845 self.parton.append('ma5_plot') 846 847 if 'ma5_html' not in self.parton and \ 848 misc.glob(pjoin('%s_MA5_PARTON_ANALYSIS_*'%self['tag'],'Output','HTML','MadAnalysis5job_0','index.html'),html_path): 849 self.parton.append('ma5_html') 850 851 if 'ma5_card' not in self.parton and \ 852 misc.glob(pjoin('%s_MA5_PARTON_ANALYSIS_*'%self['tag'],'history.ma5'),html_path): 853 self.parton.append('ma5_card') 854 855 if 'done' not in self.madanalysis5_parton and \ 856 any(res in self.parton for res in ['ma5_plot','ma5_html','ma5_card']): 857 self.madanalysis5_parton.append('done') 858 859 if level in ['madanalysis5_hadron','all'] and 'madanalysis5_hadron' not in nolevel: 860 861 if 'ma5_plot' not in self.madanalysis5_hadron and \ 862 misc.glob(pjoin("%s_MA5_hadron_analysis_*.pdf"%self['tag']),path): 863 self.madanalysis5_hadron.append('ma5_plot') 864 865 if 'ma5_html' not in self.madanalysis5_hadron and \ 866 misc.glob(pjoin('%s_MA5_HADRON_ANALYSIS_*'%self['tag'],'Output','HTML','MadAnalysis5job_0','index.html'),html_path): 867 self.madanalysis5_hadron.append('ma5_html') 868 869 if 'ma5_cls' not in self.madanalysis5_hadron and \ 870 os.path.isfile(pjoin(path,"%s_MA5_CLs.dat"%self['tag'])): 871 self.madanalysis5_hadron.append('ma5_cls') 872 873 if 'ma5_card' not in self.madanalysis5_hadron and \ 874 misc.glob(pjoin('%s_MA5_PARTON_ANALYSIS_*'%self['tag'],'history.ma5'),html_path): 875 self.madanalysis5_hadron.append('ma5_card') 876 877 if level in ['shower','all'] and 'shower' not in nolevel \ 878 and self['run_mode'] != 'madevent': 879 # this is for hep/top/HwU files from amcatnlo 880 if misc.glob("*.hep", path) + \ 881 misc.glob("*.hep.gz", path): 882 self.shower.append('hep') 883 884 if 'plot' not in self.shower and \ 885 exists(pjoin(html_path,"plots_shower_%s.html" % tag)): 886 self.shower.append('plot') 887 888 if misc.glob("*.hepmc", path) + \ 889 misc.glob("*.hepmc.gz", path): 890 self.shower.append('hepmc') 891 892 for kind in ['top','HwU','pdf','ps']: 893 if misc.glob('*.' + kind, path): 894 if self['run_mode'] in ['LO', 'NLO']: 895 self.parton.append('%s' % kind) 896 else: 897 self.shower.append('%s' % kind) 898 if level in ['pythia', 'all']: 899 900 901 # Do not include the lhe in the html anymore 902 #if 'lhe' not in self.pythia and \ 903 # (exists(pjoin(path,"%s_pythia_events.lhe.gz" % tag)) or 904 # exists(pjoin(path,"%s_pythia_events.lhe" % tag))): 905 # self.pythia.append('lhe') 906 907 908 if 'hep' not in self.pythia and \ 909 (exists(pjoin(path,"%s_pythia_events.hep.gz" % tag)) or 910 exists(pjoin(path,"%s_pythia_events.hep" % tag))): 911 self.pythia.append('hep') 912 if 'log' not in self.pythia and \ 913 exists(pjoin(path,"%s_pythia.log" % tag)): 914 self.pythia.append('log') 915 916 # pointless to check the following if not hep output 917 if 'hep' in self.pythia: 918 if 'plot' not in self.pythia and \ 919 exists(pjoin(html_path,"plots_pythia_%s.html" % tag)): 920 self.pythia.append('plot') 921 922 if 'rwt' not in self.pythia and \ 923 (exists(pjoin(path,"%s_syscalc.dat.gz" % tag)) or 924 exists(pjoin(path,"%s_syscalc.dat" % tag))): 925 self.pythia.append('rwt') 926 927 if 'root' not in self.pythia and \ 928 exists(pjoin(path,"%s_pythia_events.root" % tag)): 929 self.pythia.append('root') 930 931 #if 'lheroot' not in self.pythia and \ 932 # exists(pjoin(path,"%s_pythia_lhe_events.root" % tag)): 933 # self.pythia.append('lheroot') 934 935 936 937 938 if level in ['pythia8', 'all']: 939 940 if 'hepmc' not in self.pythia8 and \ 941 (exists(pjoin(path,"%s_pythia8_events.hepmc.gz" % tag)) or 942 exists(pjoin(path,"%s_pythia8_events.hepmc" % tag))): 943 self.pythia8.append('hepmc') 944 945 if 'log' not in self.pythia8 and \ 946 exists(pjoin(path,"%s_pythia8.log" % tag)): 947 self.pythia8.append('log') 948 949 if 'hepmc' in self.pythia8: 950 if 'plot' not in self.pythia8 and 'hepmc' in self.pythia8 and \ 951 exists(pjoin(html_path,"plots_pythia_%s.html" % tag)): 952 self.pythia8.append('plot') 953 954 if 'merged_xsec' not in self.pythia8 and \ 955 exists(pjoin(path,"%s_merged_xsecs.txt" % tag)): 956 self.pythia8.append('merged_xsec') 957 958 if 'djr_plot' not in self.pythia8 and \ 959 exists(pjoin(html_path,'%s_PY8_plots'%tag,'index.html')): 960 self.pythia8.append('djr_plot') 961 962 if level in ['pgs', 'all']: 963 964 if 'plot' not in self.pgs and \ 965 exists(pjoin(html_path,"plots_pgs_%s.html" % tag)): 966 self.pgs.append('plot') 967 968 if 'lhco' not in self.pgs and \ 969 (exists(pjoin(path,"%s_pgs_events.lhco.gz" % tag)) or 970 exists(pjoin(path,"%s_pgs_events.lhco." % tag))): 971 self.pgs.append('lhco') 972 973 if 'root' not in self.pgs and \ 974 exists(pjoin(path,"%s_pgs_events.root" % tag)): 975 self.pgs.append('root') 976 977 if 'log' not in self.pgs and \ 978 exists(pjoin(path,"%s_pgs.log" % tag)): 979 self.pgs.append('log') 980 981 if level in ['delphes', 'all']: 982 983 if 'plot' not in self.delphes and \ 984 exists(pjoin(html_path,"plots_delphes_%s.html" % tag)): 985 self.delphes.append('plot') 986 987 if 'lhco' not in self.delphes and \ 988 (exists(pjoin(path,"%s_delphes_events.lhco.gz" % tag)) or 989 exists(pjoin(path,"%s_delphes_events.lhco" % tag))): 990 self.delphes.append('lhco') 991 992 if 'root' not in self.delphes and \ 993 exists(pjoin(path,"%s_delphes_events.root" % tag)): 994 self.delphes.append('root') 995 996 if 'log' not in self.delphes and \ 997 exists(pjoin(path,"%s_delphes.log" % tag)): 998 self.delphes.append('log') 999 1000 if level in ['madanlysis5_hadron','all']: 1001 pass
1002 1008 #return " <a id='%(id)s' href='%(link)s.gz' onClick=\"check_link('%(link)s.gz','%(link)s','%(id)s')\">%(name)s</a>" \ 1009 # % {'link': link, 'id': id, 'name':name} 1010 1014 #return " <a id='%(id)s' href='%(link2)s' onClick=\"check_link('%(link1)s','%(link2)s','%(id)s')\">%(name)s</a>" \ 1015 # % {'link1': link1, 'link2':link2, 'id': id, 'name':name} 1016 1204 1205 1206
1207 - def get_action(self, ttype, local_dico, runresults):
1208 # Fill the actions 1209 if ttype == 'parton': 1210 if runresults.web: 1211 action = """ 1212 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1213 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1214 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level"> 1215 <INPUT TYPE=HIDDEN NAME=level VALUE="all"> 1216 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\"> 1217 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1218 <INPUT TYPE=SUBMIT VALUE="Remove run"> 1219 </FORM> 1220 1221 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1222 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1223 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="pythia"> 1224 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1225 <INPUT TYPE=SUBMIT VALUE="Run Pythia"> 1226 </FORM>""" 1227 else: 1228 action = self.command_suggestion_html('remove %s parton --tag=%s' \ 1229 % (self['run_name'], self['tag'])) 1230 # this the detector simulation and pythia should be available only for madevent 1231 if self['run_mode'] == 'madevent': 1232 action += self.command_suggestion_html('pythia %s ' % self['run_name']) 1233 else: 1234 pass 1235 1236 elif ttype == 'shower': 1237 if runresults.web: 1238 action = """ 1239 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1240 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1241 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level"> 1242 <INPUT TYPE=HIDDEN NAME=level VALUE="all"> 1243 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\"> 1244 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1245 <INPUT TYPE=SUBMIT VALUE="Remove run"> 1246 </FORM> 1247 1248 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1249 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1250 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="pythia"> 1251 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1252 <INPUT TYPE=SUBMIT VALUE="Run Pythia"> 1253 </FORM>""" 1254 else: 1255 action = self.command_suggestion_html('remove %s parton --tag=%s' \ 1256 % (self['run_name'], self['tag'])) 1257 # this the detector simulation and pythia should be available only for madevent 1258 if self['run_mode'] == 'madevent': 1259 action += self.command_suggestion_html('pythia %s ' % self['run_name']) 1260 else: 1261 pass 1262 1263 elif ttype in ['pythia', 'pythia8']: 1264 if self['tag'] == runresults.get_last_pythia(): 1265 if runresults.web: 1266 action = """ 1267 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1268 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1269 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level"> 1270 <INPUT TYPE=HIDDEN NAME=level VALUE="pythia"> 1271 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1272 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\"> 1273 <INPUT TYPE=SUBMIT VALUE="Remove pythia"> 1274 </FORM> 1275 1276 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1277 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1278 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="pgs"> 1279 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1280 <INPUT TYPE=SUBMIT VALUE="Run Detector"> 1281 </FORM>""" 1282 else: 1283 action = self.command_suggestion_html( 1284 'remove %s pythia --tag=%s' % \ 1285 (self['run_name'], self['tag'])) 1286 action += self.command_suggestion_html( 1287 'delphes %(1)s' % {'1': self['run_name']}) 1288 else: 1289 if runresults.web: 1290 action = '' 1291 else: 1292 action = self.command_suggestion_html('remove %s pythia --tag=%s'\ 1293 % (self['run_name'], self['tag'])) 1294 elif ttype in ['madanalysis5_hadron']: 1295 # For now, nothing special needs to be done since we don't 1296 # support actions for madanalysis5. 1297 action = '' 1298 1299 else: 1300 if runresults.web: 1301 action = """ 1302 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1303 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1304 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level"> 1305 <INPUT TYPE=HIDDEN NAME=level VALUE=\"""" + str(type) + """\"> 1306 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\"> 1307 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1308 <INPUT TYPE=SUBMIT VALUE="Remove """ + str(ttype) + """\"> 1309 </FORM>""" 1310 else: 1311 action = self.command_suggestion_html('remove %s %s --tag=%s' %\ 1312 (self['run_name'], ttype, self['tag'])) 1313 return action
1314 1315
1316 - def get_nb_line(self):
1317 1318 nb_line = 0 1319 self.nb_line = nb_line 1320 for key in ['parton', 'reweight', 'pythia', 'pythia8', 'pgs', 1321 'delphes', 'shower', 'madanalysis5_hadron']: 1322 if len(getattr(self, key)): 1323 nb_line += 1 1324 if nb_line ==0 and not os.path.exists(pjoin(self.me_dir, "Events", self["run_name"], "%(run)s_%(tag)s_banner.txt)" % \ 1325 {"run":self["run_name"], 'tag': self["tag"]})): 1326 return 0 1327 return max([nb_line,1])
1328 1329
1330 - def get_html(self, runresults):
1331 """create the html output linked to the this tag 1332 RunResults is given in case of cross-section need to be taken 1333 from a previous run 1334 """ 1335 1336 tag_template = """ 1337 <td rowspan=%(tag_span)s> <a href="./Events/%(run)s/%(run)s_%(tag)s_banner.txt">%(tag)s</a>%(debug)s</td> 1338 %(subruns)s""" 1339 1340 # Compute the text for eachsubpart 1341 1342 sub_part_template_parton = """ 1343 <td rowspan=%(cross_span)s><center><a href="./HTML/%(run)s/results.html"> %(cross).4g <font face=symbol>&#177;</font> %(err).2g %(bias)s</a> %(syst)s </center></td> 1344 <td rowspan=%(cross_span)s><center> %(nb_event)s<center></td><td> %(type)s </td> 1345 <td> %(links)s</td> 1346 <td> %(action)s</td> 1347 </tr>""" 1348 sub_part_template_parton_no_results = """ 1349 <td rowspan=%(cross_span)s><center><a> %(cross).4g <font face=symbol>&#177;</font> %(err).2g %(bias)s</a> %(syst)s </center></td> 1350 <td rowspan=%(cross_span)s><center> %(nb_event)s<center></td><td> %(type)s </td> 1351 <td> %(links)s</td> 1352 <td> %(action)s</td> 1353 </tr>""" 1354 1355 1356 sub_part_template_py8 = """ 1357 <td rowspan=%(cross_span)s><center><a href="./Events/%(run)s/%(tag)s_merged_xsecs.txt"> merged xsection</a> %(syst)s </center></td> 1358 <td rowspan=%(cross_span)s><center> %(nb_event)s<center></td><td> %(type)s </td> 1359 <td> %(links)s</td> 1360 <td> %(action)s</td> 1361 </tr>""" 1362 1363 sub_part_template_reweight = """ 1364 <td rowspan=%(cross_span)s><center> %(cross).4g </center></td> 1365 <td rowspan=%(cross_span)s><center> %(nb_event)s<center></td><td> %(type)s </td> 1366 <td> %(links)s</td> 1367 <td> %(action)s</td> 1368 </tr>""" 1369 1370 sub_part_template_pgs = """ 1371 <td> %(type)s </td> 1372 <td> %(links)s</td> 1373 <td> %(action)s</td> 1374 </tr>""" 1375 1376 sub_part_template_shower = """ 1377 <td> %(type)s %(run_mode)s </td> 1378 <td> %(links)s</td> 1379 <td> %(action)s</td> 1380 </tr>""" 1381 1382 sub_part_template_fxfx = """ 1383 <td rowspan=%(cross_span)s><center><a href="./MCATNLO/%(shower_dir)s/mcatnlo_run.log"> %(cross).4g </a> </center></td> 1384 <td rowspan=%(cross_span)s><center> %(nb_event)s<center></td><td> %(type)s %(run_mode)s </td> 1385 <td> %(links)s</td> 1386 <td> %(action)s</td> 1387 </tr>""" 1388 1389 # Compute the HTMl output for subpart 1390 nb_line = self.get_nb_line() 1391 if nb_line == 0: 1392 return "" 1393 # Check that cross/nb_event/error are define 1394 if self.pythia and not self['nb_event']: 1395 try: 1396 self['nb_event'] = runresults[-2]['nb_event'] 1397 self['cross'] = runresults[-2]['cross'] 1398 self['error'] = runresults[-2]['error'] 1399 except Exception: 1400 pass 1401 elif self.pythia8 and not self['nb_event']: 1402 try: 1403 self['nb_event'] = runresults[-2]['nb_event'] 1404 self['cross'] = runresults[-2]['cross'] 1405 self['error'] = runresults[-2]['error'] 1406 except Exception: 1407 pass 1408 1409 elif (self.pgs or self.delphes) and not self['nb_event'] and \ 1410 len(runresults) > 1: 1411 if runresults[-2]['cross_pythia'] and runresults[-2]['cross']: 1412 self['cross'] = runresults[-2]['cross_pythia'] 1413 self['error'] = runresults[-2]['error_pythia'] 1414 self['nb_event'] = runresults[-2]['nb_event_pythia'] 1415 else: 1416 self['nb_event'] = runresults[-2]['nb_event'] 1417 self['cross'] = runresults[-2]['cross'] 1418 self['error'] = runresults[-2]['error'] 1419 1420 1421 first = None 1422 subresults_html = '' 1423 for ttype in self.level_modes: 1424 data = getattr(self, ttype) 1425 if not data: 1426 continue 1427 1428 if ttype == 'madanalysis5_parton': 1429 # The 'done' store in madanalysis5_parton is just a placeholder 1430 # it doesn't have a corresponding line 1431 continue 1432 local_dico = {'type': ttype, 'run': self['run_name'], 'syst': '', 1433 'tag': self['tag']} 1434 if self['event_norm'].lower()=='bias': 1435 local_dico['bias']='(biased, do not use)' 1436 else: 1437 local_dico['bias']='' 1438 1439 if 'run_mode' in list(self.keys()): 1440 local_dico['run_mode'] = self['run_mode'] 1441 else: 1442 local_dico['run_mode'] = "" 1443 if not first: 1444 if ttype == 'reweight': 1445 template = sub_part_template_reweight 1446 elif ttype=='pythia8' and self['cross_pythia'] == -1: 1447 template = sub_part_template_py8 1448 else: 1449 if os.path.exists(pjoin(self.me_dir,'HTML', self['run_name'],'results.html')): 1450 template = sub_part_template_parton 1451 else: 1452 template = sub_part_template_parton_no_results 1453 first = ttype 1454 if ttype=='parton' and self['cross_pythia']: 1455 local_dico['cross_span'] = 1 1456 local_dico['cross'] = self['cross'] 1457 local_dico['err'] = self['error'] 1458 local_dico['nb_event'] = self['nb_event'] 1459 if 'syst' in self.parton: 1460 local_dico['syst'] = '<font face=symbol>&#177;</font> <a href="./Events/%(run_name)s/parton_systematics.log">systematics</a>' \ 1461 % {'run_name':self['run_name']} 1462 1463 elif self['cross_pythia']: 1464 if self.parton: 1465 local_dico['cross_span'] = nb_line -1 1466 else: 1467 local_dico['cross_span'] = nb_line 1468 if self['nb_event_pythia']: 1469 local_dico['nb_event'] = self['nb_event_pythia'] 1470 else: 1471 local_dico['nb_event'] = 0 1472 local_dico['cross'] = self['cross_pythia'] 1473 local_dico['err'] = self['error_pythia'] 1474 if 'rwt' in self.pythia: 1475 local_dico['syst'] = '<font face=symbol>&#177;</font> <a href="./Events/%(run_name)s/%(tag)s_Pythia_syscalc.log">systematics</a>' \ 1476 % {'run_name':self['run_name'], 'tag': self['tag']} 1477 else: 1478 if 'lhe' not in self.parton and self.madanalysis5_parton: 1479 local_dico['type'] += ' MA5' 1480 elif ttype=='madanalysis5_hadron' and self.madanalysis5_hadron: 1481 local_dico['type'] = 'hadron MA5' 1482 else: 1483 local_dico['type'] += ' %s' % self['run_mode'] 1484 1485 local_dico['cross_span'] = nb_line 1486 local_dico['cross'] = self['cross'] 1487 local_dico['err'] = self['error'] 1488 local_dico['nb_event'] = self['nb_event'] 1489 if 'syst' in self.parton: 1490 local_dico['syst'] = '<font face=symbol>&#177;</font> <a href="./Events/%(run_name)s/parton_systematics.log">systematics</a>' \ 1491 % {'run_name':self['run_name'], 'tag': self['tag']} 1492 elif ttype == 'pythia8' and self['cross_pythia'] ==-1 and 'merged_xsec' in self.pythia8: 1493 template = sub_part_template_py8 1494 if self.parton: 1495 local_dico['cross_span'] = nb_line - 1 1496 local_dico['nb_event'] = self['nb_event_pythia'] 1497 else: 1498 local_dico['cross_span'] = nb_line 1499 local_dico['nb_event'] = self['nb_event_pythia'] 1500 elif ttype in ['pythia','pythia8'] and self['cross_pythia']: 1501 template = sub_part_template_parton 1502 if self.parton: 1503 local_dico['cross_span'] = nb_line - 1 1504 if self['nb_event_pythia']: 1505 local_dico['nb_event'] = self['nb_event_pythia'] 1506 else: 1507 local_dico['nb_event'] = 0 1508 else: 1509 local_dico['cross_span'] = nb_line 1510 local_dico['nb_event'] = self['nb_event'] 1511 if 'rwt' in self.pythia: 1512 local_dico['syst'] = '<font face=symbol>&#177;</font> <a href="./Events/%(run_name)s/%(tag)s_Pythia_syscalc.log">systematics</a>' \ 1513 % {'run_name':self['run_name'], 'tag': self['tag']} 1514 local_dico['cross'] = self['cross_pythia'] 1515 local_dico['err'] = self['error_pythia'] 1516 1517 elif ttype in ['madanalysis5_hadron']: 1518 # We can use the same template as pgs here 1519 template = sub_part_template_pgs 1520 local_dico['type'] = 'hadron MA5' 1521 # Nothing else needs to be done for now, since only type and 1522 # run_mode must be defined in local_dict and this has already 1523 # been done. 1524 1525 elif ttype == 'shower': 1526 if self.parton: 1527 local_dico['cross_span'] = nb_line - 1 1528 else: 1529 local_dico['cross_span'] = nb_line 1530 1531 if self['cross_pythia']: 1532 if self['nb_event_pythia']: 1533 local_dico['nb_event'] = self['nb_event_pythia'] 1534 else: 1535 local_dico['nb_event'] = 0 1536 local_dico['cross'] = self['cross_pythia'] 1537 local_dico['err'] = self['error_pythia'] 1538 local_dico['shower_dir'] = self['shower_dir'] 1539 1540 template = sub_part_template_fxfx 1541 else: 1542 template = sub_part_template_shower 1543 1544 else: 1545 template = sub_part_template_pgs 1546 1547 # Fill the links/actions 1548 local_dico['links'] = self.get_links(ttype) 1549 local_dico['action'] = self.get_action(ttype, local_dico, runresults) 1550 # create the text 1551 subresults_html += template % local_dico 1552 1553 if subresults_html == '': 1554 if runresults.web: 1555 action = """ 1556 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1557 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1558 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level"> 1559 <INPUT TYPE=HIDDEN NAME=level VALUE="banner"> 1560 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\"> 1561 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1562 <INPUT TYPE=SUBMIT VALUE="Remove Banner"> 1563 </FORM> 1564 1565 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1566 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1567 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="banner"> 1568 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1569 <INPUT TYPE=SUBMIT VALUE="Run the banner"> 1570 </FORM>""" 1571 else: 1572 action = self.command_suggestion_html('remove %s banner --tag=%s' \ 1573 % (self['run_name'], self['tag'])) 1574 action += self.command_suggestion_html('banner_run %s ' % self['run_name']) 1575 1576 1577 1578 subresults_html = sub_part_template_parton % \ 1579 {'type': '', 1580 'run': self['run_name'], 1581 'cross_span': 1, 1582 'cross': self['cross'], 1583 'err': self['error'], 1584 'nb_event': self['nb_event'] and self['nb_event'] or 'No events yet', 1585 'links': 'banner only', 1586 'action': action, 1587 'run_mode': '', 1588 'syst':'', 1589 'bias':'' 1590 } 1591 1592 if self.debug is KeyboardInterrupt: 1593 debug = '<br><font color=red>Interrupted</font>' 1594 elif isinstance(self.debug, six.string_types): 1595 if not os.path.isabs(self.debug) and not self.debug.startswith('./'): 1596 self.debug = './' + self.debug 1597 elif os.path.isabs(self.debug): 1598 self.debug = os.path.relpath(self.debug, self.me_dir) 1599 debug = '<br> <a href=\'%s\'> <font color=red>ERROR</font></a>' \ 1600 % (self.debug) 1601 elif self.debug: 1602 text = str(self.debug).replace('. ','.<br>') 1603 if 'http' in text: 1604 pat = re.compile('(http[\S]*)') 1605 text = pat.sub(r'<a href=\1> here </a>', text) 1606 debug = '<br><font color=red>%s<BR>%s</font>' % \ 1607 (self.debug.__class__.__name__, text) 1608 else: 1609 debug = '' 1610 text = tag_template % {'tag_span': nb_line, 1611 'run': self['run_name'], 'tag': self['tag'], 1612 'subruns' : subresults_html, 1613 'debug':debug} 1614 1615 return text
1616 1617
1618 - def command_suggestion_html(self, command):
1619 """return html button with code suggestion""" 1620 1621 if command.startswith('pythia'): 1622 button = 'launch pythia' 1623 if command.startswith('shower'): 1624 button = 'shower events' 1625 elif command.startswith('remove banner'): 1626 button = 'remove banner' 1627 elif command.startswith('remove'): 1628 button = 'remove run' 1629 elif command.startswith('banner_run'): 1630 button = 're-run from the banner' 1631 else: 1632 button = 'launch detector simulation' 1633 if self['run_mode'] == 'madevent': 1634 header = 'Launch ./bin/madevent in a shell, and run the following command: ' 1635 else: 1636 header = 'Launch ./bin/aMCatNLO in a shell, and run the following command: ' 1637 1638 return "<INPUT TYPE=SUBMIT VALUE='%s' onClick=\"alert('%s')\">" % (button, header + command) 1639 1640 1641 return + '<br>'
1642