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