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