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 elif name == 'cross' and run[name] != 0: 379 run['prev_' + name] = run[name] 380 run[name] = float(value) 381 else: 382 run[name] = float(value)
383
384 - def get_detail(self, name, run=None, tag=None):
385 """ add information to current run (cross/error/event)""" 386 assert name in AllResults._run_entries 387 388 if not run and not self.current: 389 return None 390 391 if not run: 392 run = self.current 393 else: 394 run = self[run].return_tag(tag) 395 396 return run[name]
397
398 - def output(self):
399 """ write the output file """ 400 401 # 1) Create the text for the status directory 402 if self.status and self.current: 403 if isinstance(self.status, str): 404 status = '<td ROWSPAN=2 colspan=4>%s</td>' % self.status 405 else: 406 s = list(self.status) 407 if s[0] == '$events': 408 if self.current['nb_event']: 409 nevent = self.current['nb_event'] 410 else: 411 nevent = self[self.current['run_name']][0]['nb_event'] 412 if nevent: 413 s[0] = nevent - int(s[1]) -int(s[2]) 414 else: 415 s[0] = '' 416 status ='''<td> %s </td> <td> %s </td> <td> %s </td> 417 </tr><tr><td colspan=3><center> %s </center></td>''' % (s[0],s[1], s[2], s[3]) 418 419 420 status_dict = {'status': status, 421 'cross': self.current['cross'], 422 'error': self.current['error'], 423 'run_name': self.current['run_name'], 424 'tag_name': self.current['tag'], 425 'unit': self[self.current['run_name']].info['unit']} 426 # add the run_mode_string for amcatnlo_run 427 if 'run_mode' in self.current.keys(): 428 run_mode_string = {'aMC@NLO': '(aMC@NLO)', 429 'aMC@LO': '(aMC@LO)', 430 'noshower': '(aMC@NLO)', 431 'noshowerLO': '(aMC@LO)', 432 'NLO': '(NLO f.o.)', 433 'LO': '(LO f.o.)', 434 'madevent':'' 435 } 436 status_dict['run_mode_string'] = run_mode_string[self.current['run_mode']] 437 else: 438 status_dict['run_mode_string'] = '' 439 440 441 if exists(pjoin(self.path, 'HTML',self.current['run_name'], 442 'results.html')): 443 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 444 else: 445 status_dict['results'] = "No results yet" 446 if exists(pjoin(self.path, 'Cards', 'plot_card.dat')): 447 status_dict['plot_card'] = """ <a href="./Cards/plot_card.dat">plot_card</a><BR>""" 448 else: 449 status_dict['plot_card'] = "" 450 if exists(pjoin(self.path, 'Cards', 'pythia_card.dat')): 451 status_dict['pythia_card'] = """ <a href="./Cards/pythia_card.dat">pythia_card</a><BR>""" 452 else: 453 status_dict['pythia_card'] = "" 454 if exists(pjoin(self.path, 'Cards', 'pgs_card.dat')): 455 status_dict['pgs_card'] = """ <a href="./Cards/pgs_card.dat">pgs_card</a><BR>""" 456 else: 457 status_dict['pgs_card'] = "" 458 if exists(pjoin(self.path, 'Cards', 'delphes_card.dat')): 459 status_dict['delphes_card'] = """ <a href="./Cards/delphes_card.dat">delphes_card</a><BR>""" 460 else: 461 status_dict['delphes_card'] = "" 462 if exists(pjoin(self.path, 'Cards', 'shower_card.dat')): 463 status_dict['shower_card'] = """ <a href="./Cards/shower_card.dat">shower_card</a><BR>""" 464 else: 465 status_dict['shower_card'] = "" 466 if exists(pjoin(self.path, 'Cards', 'FO_analyse_card.dat')): 467 status_dict['fo_analyse_card'] = """ <a href="./Cards/FO_analyse_card.dat">FO_analyse_card</a><BR>""" 468 else: 469 status_dict['fo_analyse_card'] = "" 470 471 if self.web: 472 status_dict['stop_form'] = """ 473 <TR ALIGN=CENTER><TD COLSPAN=7 text-align=center> 474 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 475 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 476 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="stop_job"> 477 <INPUT TYPE=SUBMIT VALUE="Stop Current Job"> 478 </FORM></TD></TR>""" % {'me_dir': self.path, 'web': self.web} 479 else: 480 status_dict['stop_form'] = "" 481 482 483 status = status_template % status_dict 484 refresh = "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"10\">" 485 else: 486 status ='' 487 refresh = '' 488 489 490 # See if we need to incorporate the button for submission 491 if os.path.exists(pjoin(self.path, 'RunWeb')): 492 running = True 493 else: 494 running = False 495 496 # 2) Create the text for the old run: 497 old_run = '' 498 for key in self.order: 499 old_run += self[key].get_html(self.path, web=self.web, running=running) 500 501 text_dict = {'process': self.process, 502 'model': self.model, 503 'status': status, 504 'old_run': old_run, 505 'refresh': refresh, 506 'numerical_title': self.unit == 'pb' and 'Cross section (pb)'\ 507 or 'Width (GeV)'} 508 509 text = crossxhtml_template % text_dict 510 open(pjoin(self.path,'crossx.html'),'w').write(text)
511 512
513 -class AllResultsNLO(AllResults):
514 """Store the results for a NLO run of a given directory""" 515
516 - def __init__(self,model, process, path, recreateold=False):
517 return AllResults.__init__(self, model, process, path, recreateold=recreateold)
518 519
520 -class RunResults(list):
521 """The list of all OneTagResults""" 522
523 - def __init__(self, run_name, run_card, process, path):
524 """initialize the object""" 525 526 self.info = {'run_name': run_name,'me_dir':path} 527 self.tags = [run_card['run_tag']] 528 529 # Set the collider information 530 data = process.split('>',1)[0].split() 531 if len(data) == 2: 532 name1,name2 = data 533 if run_card['lpp1'] == -1: 534 name1 = ' p~' 535 elif run_card['lpp1'] == 1: 536 name1 = ' p' 537 elif run_card['lpp1'] in [2,3]: 538 name1 = ' a' 539 if run_card['lpp2'] == -1: 540 name2 = 'p~' 541 elif run_card['lpp2'] == 1: 542 name2 = ' p' 543 elif run_card['lpp2'] == [2,3]: 544 name2 = ' a' 545 self.info['collider'] = '''%s %s <br> %s x %s GeV''' % \ 546 (name1, name2, run_card['ebeam1'], run_card['ebeam2']) 547 self.info['unit'] = 'pb' 548 elif len(data) == 1: 549 self.info['collider'] = 'decay' 550 self.info['unit'] = 'GeV' 551 else: 552 self.info['collider'] = 'special mode' 553 self.info['unit'] = '' 554 555 self.append(OneTagResults(run_name, run_card, path))
556 557
558 - def get_html(self, output_path, **opt):
559 """WRITE HTML OUTPUT""" 560 561 try: 562 self.web = opt['web'] 563 self.info['web'] = self.web 564 except Exception: 565 self.web = False 566 567 # check if more than one parton output except for tags corresponding 568 # to different MA5 parton-level runs. 569 parton = [r for r in self if (r.parton and 'lhe' in r.parton)] 570 # clean wrong previous run link 571 if len(parton)>1: 572 for p in parton[:-1]: 573 # Do not remove the MA5 parton level results. 574 for res in p.parton: 575 if not res.startswith('ma5'): 576 p.parton.remove(res) 577 578 dico = self.info 579 dico['run_span'] = sum([tag.get_nb_line() for tag in self], 1) -1 580 dico['tag_data'] = '\n'.join([tag.get_html(self) for tag in self]) 581 text = """ 582 <tr> 583 <td rowspan=%(run_span)s>%(run_name)s</td> 584 <td rowspan=%(run_span)s><center> %(collider)s </center></td> 585 %(tag_data)s 586 </tr> 587 """ % dico 588 589 if self.web: 590 591 text = text % self.info 592 593 return text
594 595
596 - def return_tag(self, name):
597 598 for data in self: 599 if data['tag'] == name: 600 return data 601 602 if name is None: 603 # return last entry 604 return self[-1] 605 606 raise Exception, '%s is not a valid tag' % name
607
608 - def recreate(self, banner):
609 """Fully recreate the information due to a hard removal of the db 610 Work for LO ONLY!""" 611 612 run_name = self.info["run_name"] 613 run_card = banner.get("run_card") 614 path = self.info["me_dir"] 615 # Recover the main information (cross-section/number of event) 616 informations = banner['mggenerationinfo'] 617 #number of events 618 nb_event = re.search(r"Number\s*of\s*Events\s*:\s*(\d*)", informations) 619 if nb_event: 620 nb_event = int(nb_event.group(1)) 621 else: 622 nb_event = 0 623 624 # cross-section 625 cross = re.search(r"Integrated\s*weight\s*\(\s*pb\s*\)\s*:\s*([\+\-\d.e]+)", informations, 626 re.I) 627 if cross: 628 cross = float(cross.group(1)) 629 else: 630 cross = 0 631 632 # search pythia file for tag: tag_1_pythia.log 633 path = pjoin(self.info['me_dir'],'Events', self.info['run_name']) 634 files = [pjoin(path, f) for f in os.listdir(path) if 635 os.path.isfile(pjoin(path,f)) and f.endswith('pythia.log')] 636 #order them by creation date. 637 files.sort(key=lambda x: os.path.getmtime(x)) 638 tags = [os.path.basename(name[:-11]) for name in files] 639 640 641 # No pythia only a single run: 642 if not tags: 643 self[-1]['nb_event'] = nb_event 644 self[-1]['cross'] = cross 645 646 #Loop over pythia run 647 for tag in tags: 648 if tag not in self.tags: 649 tagresult = OneTagResults(run_name, run_card, path) 650 tagresult['tag'] = tag 651 self.add(tagresult) 652 else: 653 tagresult = self.return_tag(tag) 654 tagresult['nb_event'] = nb_event 655 tagresult['cross'] = cross 656 if run_card['ickkw'] != 0: 657 #parse the file to have back the information 658 pythia_log = misc.BackRead(pjoin(path, '%s_pythia.log' % tag)) 659 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") 660 for line in pythia_log: 661 info = pythiare.search(line) 662 if not info: 663 continue 664 try: 665 # Pythia cross section in mb, we want pb 666 sigma_m = float(info.group('xsec').replace('D','E')) *1e9 667 Nacc = int(info.group('generated')) 668 except ValueError: 669 # xsec is not float - this should not happen 670 tagresult['cross_pythia'] = 0 671 tagresult['nb_event_pythia'] = 0 672 tagresult['error_pythia'] = 0 673 else: 674 tagresult['cross_pythia'] = sigma_m 675 tagresult['nb_event_pythia'] = Nacc 676 tagresult['error_pythia'] = 0 677 break 678 pythia_log.close()
679 680
681 - def is_empty(self):
682 """Check if this run contains smtg else than html information""" 683 684 if not self: 685 return True 686 if len(self) > 1: 687 return False 688 689 data = self[0] 690 if data.parton or data.pythia or data.pgs or data.delphes: 691 return False 692 else: 693 return True
694
695 - def add(self, obj):
696 """ """ 697 698 assert isinstance(obj, OneTagResults) 699 tag = obj['tag'] 700 assert tag not in self.tags 701 self.tags.append(tag) 702 self.append(obj)
703
704 - def get_last_pythia(self):
705 for i in range(1, len(self)+1): 706 if self[-i].pythia or self[-i].pythia8: 707 return self[-i]['tag']
708
709 - def get_current_info(self):
710 711 output = {} 712 current = self[-1] 713 # Check that cross/nb_event/error are define 714 if current.pythia and not current['nb_event'] and len(self) > 1: 715 output['nb_event'] = self[-2]['nb_event'] 716 output['cross'] = self[-2]['cross'] 717 output['error'] = self[-2]['error'] 718 elif (current.pgs or current.delphes) and not current['nb_event'] and len(self) > 1: 719 if self[-2]['cross_pythia'] and self[-2]['nb_event_pythia']: 720 output['cross'] = self[-2]['cross_pythia'] 721 output['nb_event'] = self[-2]['nb_event_pythia'] 722 output['error'] = self[-2]['error_pythia'] 723 else: 724 output['nb_event'] = self[-2]['nb_event'] 725 output['cross'] = self[-2]['cross'] 726 output['error'] = self[-2]['error'] 727 elif current['cross']: 728 return current 729 elif len(self) > 1: 730 output['nb_event'] = self[-2]['nb_event'] 731 output['cross'] = self[-2]['cross'] 732 output['error'] = self[-2]['error'] 733 else: 734 output['nb_event'] = 0 735 output['cross'] = 0 736 output['error'] = 1e-99 737 return output
738 739
740 - def remove(self, tag):
741 742 assert tag in self.tags 743 744 obj = [o for o in self if o['tag']==tag][0] 745 self.tags.remove(tag) 746 list.remove(self, obj)
747 748 749
750 -class OneTagResults(dict):
751 """ Store the results of a specific run """ 752
753 - def __init__(self, run_name, run_card, path):
754 """initialize the object""" 755 756 # define at run_result 757 self['run_name'] = run_name 758 self['tag'] = run_card['run_tag'] 759 self['event_norm'] = run_card['event_norm'] 760 self.event_path = pjoin(path,'Events') 761 self.me_dir = path 762 self.debug = None 763 764 # Default value 765 self['nb_event'] = 0 766 self['cross'] = 0 767 self['cross_pythia'] = '' 768 self['nb_event_pythia'] = 0 769 self['error'] = 0 770 self['run_mode'] = 'madevent' 771 self.parton = [] 772 self.reweight = [] 773 self.pythia = [] 774 self.pythia8 = [] 775 self.madanalysis5_hadron = [] 776 # This is just a container that contain 'done' when the parton level MA5 777 # analysis is done, so that set_run_name knows when to update the tag 778 self.madanalysis5_parton = [] 779 self.pgs = [] 780 self.delphes = [] 781 self.shower = [] 782 783 self.level_modes = ['parton', 'pythia', 'pythia8', 784 'pgs', 'delphes','reweight','shower', 785 'madanalysis5_hadron','madanalysis5_parton'] 786 # data 787 self.status = '' 788 789 # Dictionary with (Pdir,G) as keys and sum_html.RunStatistics instances 790 # as values 791 self['run_statistics'] = {}
792 793
794 - def update_status(self, level='all', nolevel=[]):
795 """update the status of the current run """ 796 exists = os.path.exists 797 run = self['run_name'] 798 tag =self['tag'] 799 800 path = pjoin(self.event_path, run) 801 html_path = pjoin(self.event_path, os.pardir, 'HTML', run) 802 803 # Check if the output of the last status exists 804 if level in ['gridpack','all']: 805 if 'gridpack' not in self.parton and \ 806 exists(pjoin(path,os.pardir ,os.pardir,"%s_gridpack.tar.gz" % run)): 807 self.parton.append('gridpack') 808 # Check if the output of the last status exists 809 if level in ['reweight','all']: 810 if 'plot' not in self.reweight and \ 811 exists(pjoin(html_path,"plots_%s.html" % tag)): 812 self.reweight.append('plot') 813 814 # We also trigger parton for madanalysis5_parton because its results 815 # must be added to self.parton 816 if level in ['parton','all'] and 'parton' not in nolevel: 817 818 if 'lhe' not in self.parton and \ 819 (exists(pjoin(path,"unweighted_events.lhe.gz")) or 820 exists(pjoin(path,"unweighted_events.lhe")) or 821 exists(pjoin(path,"events.lhe.gz")) or 822 exists(pjoin(path,"events.lhe"))): 823 self.parton.append('lhe') 824 825 if 'root' not in self.parton and \ 826 exists(pjoin(path,"unweighted_events.root")): 827 self.parton.append('root') 828 829 if 'plot' not in self.parton and \ 830 exists(pjoin(html_path,"plots_parton.html")): 831 self.parton.append('plot') 832 833 if 'param_card' not in self.parton and \ 834 exists(pjoin(path, "param_card.dat")): 835 self.parton.append('param_card') 836 837 if 'syst' not in self.parton and \ 838 exists(pjoin(path, "parton_systematics.log")): 839 self.parton.append('syst') 840 841 for kind in ['top','HwU','pdf','ps']: 842 if misc.glob("*.%s" % kind, path): 843 if self['run_mode'] in ['LO', 'NLO']: 844 self.parton.append('%s' % kind) 845 if exists(pjoin(path,'summary.txt')): 846 self.parton.append('summary.txt') 847 848 849 if level in ['madanalysis5_parton','all'] and 'madanalysis5_parton' not in nolevel: 850 851 if 'ma5_plot' not in self.parton and \ 852 misc.glob("%s_MA5_parton_analysis_*.pdf"%self['tag'], path): 853 self.parton.append('ma5_plot') 854 855 if 'ma5_html' not in self.parton and \ 856 misc.glob(pjoin('%s_MA5_PARTON_ANALYSIS_*'%self['tag'],'Output','HTML','MadAnalysis5job_0','index.html'),html_path): 857 self.parton.append('ma5_html') 858 859 if 'ma5_card' not in self.parton and \ 860 misc.glob(pjoin('%s_MA5_PARTON_ANALYSIS_*'%self['tag'],'history.ma5'),html_path): 861 self.parton.append('ma5_card') 862 863 if 'done' not in self.madanalysis5_parton and \ 864 any(res in self.parton for res in ['ma5_plot','ma5_html','ma5_card']): 865 self.madanalysis5_parton.append('done') 866 867 if level in ['madanalysis5_hadron','all'] and 'madanalysis5_hadron' not in nolevel: 868 869 if 'ma5_plot' not in self.madanalysis5_hadron and \ 870 misc.glob(pjoin("%s_MA5_hadron_analysis_*.pdf"%self['tag']),path): 871 self.madanalysis5_hadron.append('ma5_plot') 872 873 if 'ma5_html' not in self.madanalysis5_hadron and \ 874 misc.glob(pjoin('%s_MA5_HADRON_ANALYSIS_*'%self['tag'],'Output','HTML','MadAnalysis5job_0','index.html'),html_path): 875 self.madanalysis5_hadron.append('ma5_html') 876 877 if 'ma5_cls' not in self.madanalysis5_hadron and \ 878 os.path.isfile(pjoin(path,"%s_MA5_CLs.dat"%self['tag'])): 879 self.madanalysis5_hadron.append('ma5_cls') 880 881 if 'ma5_card' not in self.madanalysis5_hadron and \ 882 misc.glob(pjoin('%s_MA5_PARTON_ANALYSIS_*'%self['tag'],'history.ma5'),html_path): 883 self.madanalysis5_hadron.append('ma5_card') 884 885 if level in ['shower','all'] and 'shower' not in nolevel \ 886 and self['run_mode'] != 'madevent': 887 # this is for hep/top/HwU files from amcatnlo 888 if misc.glob("*.hep", path) + \ 889 misc.glob("*.hep.gz", path): 890 self.shower.append('hep') 891 892 if 'plot' not in self.shower and \ 893 exists(pjoin(html_path,"plots_shower_%s.html" % tag)): 894 self.shower.append('plot') 895 896 if misc.glob("*.hepmc", path) + \ 897 misc.glob("*.hepmc.gz", path): 898 self.shower.append('hepmc') 899 900 for kind in ['top','HwU','pdf','ps']: 901 if misc.glob('*.' + kind, path): 902 if self['run_mode'] in ['LO', 'NLO']: 903 self.parton.append('%s' % kind) 904 else: 905 self.shower.append('%s' % kind) 906 if level in ['pythia', 'all']: 907 908 909 # Do not include the lhe in the html anymore 910 #if 'lhe' not in self.pythia and \ 911 # (exists(pjoin(path,"%s_pythia_events.lhe.gz" % tag)) or 912 # exists(pjoin(path,"%s_pythia_events.lhe" % tag))): 913 # self.pythia.append('lhe') 914 915 916 if 'hep' not in self.pythia and \ 917 (exists(pjoin(path,"%s_pythia_events.hep.gz" % tag)) or 918 exists(pjoin(path,"%s_pythia_events.hep" % tag))): 919 self.pythia.append('hep') 920 if 'log' not in self.pythia and \ 921 exists(pjoin(path,"%s_pythia.log" % tag)): 922 self.pythia.append('log') 923 924 # pointless to check the following if not hep output 925 if 'hep' in self.pythia: 926 if 'plot' not in self.pythia and \ 927 exists(pjoin(html_path,"plots_pythia_%s.html" % tag)): 928 self.pythia.append('plot') 929 930 if 'rwt' not in self.pythia and \ 931 (exists(pjoin(path,"%s_syscalc.dat.gz" % tag)) or 932 exists(pjoin(path,"%s_syscalc.dat" % tag))): 933 self.pythia.append('rwt') 934 935 if 'root' not in self.pythia and \ 936 exists(pjoin(path,"%s_pythia_events.root" % tag)): 937 self.pythia.append('root') 938 939 #if 'lheroot' not in self.pythia and \ 940 # exists(pjoin(path,"%s_pythia_lhe_events.root" % tag)): 941 # self.pythia.append('lheroot') 942 943 944 945 946 if level in ['pythia8', 'all']: 947 948 if 'hepmc' not in self.pythia8 and \ 949 (exists(pjoin(path,"%s_pythia8_events.hepmc.gz" % tag)) or 950 exists(pjoin(path,"%s_pythia8_events.hepmc" % tag))): 951 self.pythia8.append('hepmc') 952 953 if 'log' not in self.pythia8 and \ 954 exists(pjoin(path,"%s_pythia8.log" % tag)): 955 self.pythia8.append('log') 956 957 if 'hepmc' in self.pythia8: 958 if 'plot' not in self.pythia8 and 'hepmc' in self.pythia8 and \ 959 exists(pjoin(html_path,"plots_pythia_%s.html" % tag)): 960 self.pythia8.append('plot') 961 962 if 'merged_xsec' not in self.pythia8 and \ 963 exists(pjoin(path,"%s_merged_xsecs.txt" % tag)): 964 self.pythia8.append('merged_xsec') 965 966 if 'djr_plot' not in self.pythia8 and \ 967 exists(pjoin(html_path,'%s_PY8_plots'%tag,'index.html')): 968 self.pythia8.append('djr_plot') 969 970 if level in ['pgs', 'all']: 971 972 if 'plot' not in self.pgs and \ 973 exists(pjoin(html_path,"plots_pgs_%s.html" % tag)): 974 self.pgs.append('plot') 975 976 if 'lhco' not in self.pgs and \ 977 (exists(pjoin(path,"%s_pgs_events.lhco.gz" % tag)) or 978 exists(pjoin(path,"%s_pgs_events.lhco." % tag))): 979 self.pgs.append('lhco') 980 981 if 'root' not in self.pgs and \ 982 exists(pjoin(path,"%s_pgs_events.root" % tag)): 983 self.pgs.append('root') 984 985 if 'log' not in self.pgs and \ 986 exists(pjoin(path,"%s_pgs.log" % tag)): 987 self.pgs.append('log') 988 989 if level in ['delphes', 'all']: 990 991 if 'plot' not in self.delphes and \ 992 exists(pjoin(html_path,"plots_delphes_%s.html" % tag)): 993 self.delphes.append('plot') 994 995 if 'lhco' not in self.delphes and \ 996 (exists(pjoin(path,"%s_delphes_events.lhco.gz" % tag)) or 997 exists(pjoin(path,"%s_delphes_events.lhco" % tag))): 998 self.delphes.append('lhco') 999 1000 if 'root' not in self.delphes and \ 1001 exists(pjoin(path,"%s_delphes_events.root" % tag)): 1002 self.delphes.append('root') 1003 1004 if 'log' not in self.delphes and \ 1005 exists(pjoin(path,"%s_delphes.log" % tag)): 1006 self.delphes.append('log') 1007 1008 if level in ['madanlysis5_hadron','all']: 1009 pass
1010 1017 1022 1210 1211 1212
1213 - def get_action(self, ttype, local_dico, runresults):
1214 # Fill the actions 1215 if ttype == 'parton': 1216 if runresults.web: 1217 action = """ 1218 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1219 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1220 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level"> 1221 <INPUT TYPE=HIDDEN NAME=level VALUE="all"> 1222 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\"> 1223 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1224 <INPUT TYPE=SUBMIT VALUE="Remove run"> 1225 </FORM> 1226 1227 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1228 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1229 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="pythia"> 1230 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1231 <INPUT TYPE=SUBMIT VALUE="Run Pythia"> 1232 </FORM>""" 1233 else: 1234 action = self.command_suggestion_html('remove %s parton --tag=%s' \ 1235 % (self['run_name'], self['tag'])) 1236 # this the detector simulation and pythia should be available only for madevent 1237 if self['run_mode'] == 'madevent': 1238 action += self.command_suggestion_html('pythia %s ' % self['run_name']) 1239 else: 1240 pass 1241 1242 elif ttype == 'shower': 1243 if runresults.web: 1244 action = """ 1245 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1246 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1247 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level"> 1248 <INPUT TYPE=HIDDEN NAME=level VALUE="all"> 1249 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\"> 1250 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1251 <INPUT TYPE=SUBMIT VALUE="Remove run"> 1252 </FORM> 1253 1254 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1255 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1256 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="pythia"> 1257 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1258 <INPUT TYPE=SUBMIT VALUE="Run Pythia"> 1259 </FORM>""" 1260 else: 1261 action = self.command_suggestion_html('remove %s parton --tag=%s' \ 1262 % (self['run_name'], self['tag'])) 1263 # this the detector simulation and pythia should be available only for madevent 1264 if self['run_mode'] == 'madevent': 1265 action += self.command_suggestion_html('pythia %s ' % self['run_name']) 1266 else: 1267 pass 1268 1269 elif ttype in ['pythia', 'pythia8']: 1270 if self['tag'] == runresults.get_last_pythia(): 1271 if runresults.web: 1272 action = """ 1273 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1274 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1275 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level"> 1276 <INPUT TYPE=HIDDEN NAME=level VALUE="pythia"> 1277 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1278 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\"> 1279 <INPUT TYPE=SUBMIT VALUE="Remove pythia"> 1280 </FORM> 1281 1282 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1283 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1284 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="pgs"> 1285 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1286 <INPUT TYPE=SUBMIT VALUE="Run Detector"> 1287 </FORM>""" 1288 else: 1289 action = self.command_suggestion_html( 1290 'remove %s pythia --tag=%s' % \ 1291 (self['run_name'], self['tag'])) 1292 action += self.command_suggestion_html( 1293 'delphes %(1)s' % {'1': self['run_name']}) 1294 else: 1295 if runresults.web: 1296 action = '' 1297 else: 1298 action = self.command_suggestion_html('remove %s pythia --tag=%s'\ 1299 % (self['run_name'], self['tag'])) 1300 elif ttype in ['madanalysis5_hadron']: 1301 # For now, nothing special needs to be done since we don't 1302 # support actions for madanalysis5. 1303 action = '' 1304 1305 else: 1306 if runresults.web: 1307 action = """ 1308 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1309 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1310 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level"> 1311 <INPUT TYPE=HIDDEN NAME=level VALUE=\"""" + str(type) + """\"> 1312 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\"> 1313 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1314 <INPUT TYPE=SUBMIT VALUE="Remove """ + str(ttype) + """\"> 1315 </FORM>""" 1316 else: 1317 action = self.command_suggestion_html('remove %s %s --tag=%s' %\ 1318 (self['run_name'], ttype, self['tag'])) 1319 return action
1320 1321
1322 - def get_nb_line(self):
1323 1324 nb_line = 0 1325 self.nb_line = nb_line 1326 for key in ['parton', 'reweight', 'pythia', 'pythia8', 'pgs', 1327 'delphes', 'shower', 'madanalysis5_hadron']: 1328 if len(getattr(self, key)): 1329 nb_line += 1 1330 if nb_line ==0 and not os.path.exists(pjoin(self.me_dir, "Events", self["run_name"], "%(run)s_%(tag)s_banner.txt)" % \ 1331 {"run":self["run_name"], 'tag': self["tag"]})): 1332 return 0 1333 return max([nb_line,1])
1334 1335
1336 - def get_html(self, runresults):
1337 """create the html output linked to the this tag 1338 RunResults is given in case of cross-section need to be taken 1339 from a previous run 1340 """ 1341 1342 tag_template = """ 1343 <td rowspan=%(tag_span)s> <a href="./Events/%(run)s/%(run)s_%(tag)s_banner.txt">%(tag)s</a>%(debug)s</td> 1344 %(subruns)s""" 1345 1346 # Compute the text for eachsubpart 1347 1348 sub_part_template_parton = """ 1349 <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> 1350 <td rowspan=%(cross_span)s><center> %(nb_event)s<center></td><td> %(type)s </td> 1351 <td> %(links)s</td> 1352 <td> %(action)s</td> 1353 </tr>""" 1354 sub_part_template_parton_no_results = """ 1355 <td rowspan=%(cross_span)s><center><a> %(cross).4g <font face=symbol>&#177;</font> %(err).2g %(bias)s</a> %(syst)s </center></td> 1356 <td rowspan=%(cross_span)s><center> %(nb_event)s<center></td><td> %(type)s </td> 1357 <td> %(links)s</td> 1358 <td> %(action)s</td> 1359 </tr>""" 1360 1361 1362 sub_part_template_py8 = """ 1363 <td rowspan=%(cross_span)s><center><a href="./Events/%(run)s/%(tag)s_merged_xsecs.txt"> merged xsection</a> %(syst)s </center></td> 1364 <td rowspan=%(cross_span)s><center> %(nb_event)s<center></td><td> %(type)s </td> 1365 <td> %(links)s</td> 1366 <td> %(action)s</td> 1367 </tr>""" 1368 1369 sub_part_template_reweight = """ 1370 <td rowspan=%(cross_span)s><center> %(cross).4g </center></td> 1371 <td rowspan=%(cross_span)s><center> %(nb_event)s<center></td><td> %(type)s </td> 1372 <td> %(links)s</td> 1373 <td> %(action)s</td> 1374 </tr>""" 1375 1376 sub_part_template_pgs = """ 1377 <td> %(type)s </td> 1378 <td> %(links)s</td> 1379 <td> %(action)s</td> 1380 </tr>""" 1381 1382 sub_part_template_shower = """ 1383 <td> %(type)s %(run_mode)s </td> 1384 <td> %(links)s</td> 1385 <td> %(action)s</td> 1386 </tr>""" 1387 1388 # Compute the HTMl output for subpart 1389 nb_line = self.get_nb_line() 1390 if nb_line == 0: 1391 return "" 1392 # Check that cross/nb_event/error are define 1393 if self.pythia and not self['nb_event']: 1394 try: 1395 self['nb_event'] = runresults[-2]['nb_event'] 1396 self['cross'] = runresults[-2]['cross'] 1397 self['error'] = runresults[-2]['error'] 1398 except Exception: 1399 pass 1400 elif self.pythia8 and not self['nb_event']: 1401 try: 1402 self['nb_event'] = runresults[-2]['nb_event'] 1403 self['cross'] = runresults[-2]['cross'] 1404 self['error'] = runresults[-2]['error'] 1405 except Exception: 1406 pass 1407 1408 elif (self.pgs or self.delphes) and not self['nb_event'] and \ 1409 len(runresults) > 1: 1410 if runresults[-2]['cross_pythia'] and runresults[-2]['cross']: 1411 self['cross'] = runresults[-2]['cross_pythia'] 1412 self['error'] = runresults[-2]['error_pythia'] 1413 self['nb_event'] = runresults[-2]['nb_event_pythia'] 1414 else: 1415 self['nb_event'] = runresults[-2]['nb_event'] 1416 self['cross'] = runresults[-2]['cross'] 1417 self['error'] = runresults[-2]['error'] 1418 1419 1420 first = None 1421 subresults_html = '' 1422 for ttype in self.level_modes: 1423 data = getattr(self, ttype) 1424 if not data: 1425 continue 1426 1427 if ttype == 'madanalysis5_parton': 1428 # The 'done' store in madanalysis5_parton is just a placeholder 1429 # it doesn't have a corresponding line 1430 continue 1431 local_dico = {'type': ttype, 'run': self['run_name'], 'syst': '', 1432 'tag': self['tag']} 1433 if self['event_norm'].lower()=='bias': 1434 local_dico['bias']='(biased, do not use)' 1435 else: 1436 local_dico['bias']='' 1437 1438 if 'run_mode' in self.keys(): 1439 local_dico['run_mode'] = self['run_mode'] 1440 else: 1441 local_dico['run_mode'] = "" 1442 if not first: 1443 if ttype == 'reweight': 1444 template = sub_part_template_reweight 1445 elif ttype=='pythia8' and self['cross_pythia'] == -1: 1446 template = sub_part_template_py8 1447 else: 1448 if os.path.exists(pjoin(self.me_dir,'HTML', self['run_name'],'results.html')): 1449 template = sub_part_template_parton 1450 else: 1451 template = sub_part_template_parton_no_results 1452 first = ttype 1453 if ttype=='parton' and self['cross_pythia']: 1454 local_dico['cross_span'] = 1 1455 local_dico['cross'] = self['cross'] 1456 local_dico['err'] = self['error'] 1457 local_dico['nb_event'] = self['nb_event'] 1458 if 'syst' in self.parton: 1459 local_dico['syst'] = '<font face=symbol>&#177;</font> <a href="./Events/%(run_name)s/parton_systematics.log">systematics</a>' \ 1460 % {'run_name':self['run_name']} 1461 1462 elif self['cross_pythia']: 1463 if self.parton: 1464 local_dico['cross_span'] = nb_line -1 1465 else: 1466 local_dico['cross_span'] = nb_line 1467 if self['nb_event_pythia']: 1468 local_dico['nb_event'] = self['nb_event_pythia'] 1469 else: 1470 local_dico['nb_event'] = 0 1471 local_dico['cross'] = self['cross_pythia'] 1472 local_dico['err'] = self['error_pythia'] 1473 if 'rwt' in self.pythia: 1474 local_dico['syst'] = '<font face=symbol>&#177;</font> <a href="./Events/%(run_name)s/%(tag)s_Pythia_syscalc.log">systematics</a>' \ 1475 % {'run_name':self['run_name'], 'tag': self['tag']} 1476 else: 1477 if 'lhe' not in self.parton and self.madanalysis5_parton: 1478 local_dico['type'] += ' MA5' 1479 elif ttype=='madanalysis5_hadron' and self.madanalysis5_hadron: 1480 local_dico['type'] = 'hadron MA5' 1481 else: 1482 local_dico['type'] += ' %s' % self['run_mode'] 1483 1484 local_dico['cross_span'] = nb_line 1485 local_dico['cross'] = self['cross'] 1486 local_dico['err'] = self['error'] 1487 local_dico['nb_event'] = self['nb_event'] 1488 if 'syst' in self.parton: 1489 local_dico['syst'] = '<font face=symbol>&#177;</font> <a href="./Events/%(run_name)s/parton_systematics.log">systematics</a>' \ 1490 % {'run_name':self['run_name'], 'tag': self['tag']} 1491 elif ttype == 'pythia8' and self['cross_pythia'] ==-1 and 'merged_xsec' in self.pythia8: 1492 template = sub_part_template_py8 1493 if self.parton: 1494 local_dico['cross_span'] = nb_line - 1 1495 local_dico['nb_event'] = self['nb_event_pythia'] 1496 else: 1497 local_dico['cross_span'] = nb_line 1498 local_dico['nb_event'] = self['nb_event_pythia'] 1499 elif ttype in ['pythia','pythia8'] and self['cross_pythia']: 1500 template = sub_part_template_parton 1501 if self.parton: 1502 local_dico['cross_span'] = nb_line - 1 1503 if self['nb_event_pythia']: 1504 local_dico['nb_event'] = self['nb_event_pythia'] 1505 else: 1506 local_dico['nb_event'] = 0 1507 else: 1508 local_dico['cross_span'] = nb_line 1509 local_dico['nb_event'] = self['nb_event'] 1510 if 'rwt' in self.pythia: 1511 local_dico['syst'] = '<font face=symbol>&#177;</font> <a href="./Events/%(run_name)s/%(tag)s_Pythia_syscalc.log">systematics</a>' \ 1512 % {'run_name':self['run_name'], 'tag': self['tag']} 1513 local_dico['cross'] = self['cross_pythia'] 1514 local_dico['err'] = self['error_pythia'] 1515 1516 elif ttype in ['madanalysis5_hadron']: 1517 # We can use the same template as pgs here 1518 template = sub_part_template_pgs 1519 local_dico['type'] = 'hadron MA5' 1520 # Nothing else needs to be done for now, since only type and 1521 # run_mode must be defined in local_dict and this has already 1522 # been done. 1523 1524 elif ttype == 'shower': 1525 template = sub_part_template_shower 1526 if self.parton: 1527 local_dico['cross_span'] = nb_line - 1 1528 else: 1529 local_dico['cross_span'] = nb_line 1530 else: 1531 template = sub_part_template_pgs 1532 1533 # Fill the links/actions 1534 local_dico['links'] = self.get_links(ttype) 1535 local_dico['action'] = self.get_action(ttype, local_dico, runresults) 1536 # create the text 1537 subresults_html += template % local_dico 1538 1539 if subresults_html == '': 1540 if runresults.web: 1541 action = """ 1542 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1543 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1544 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level"> 1545 <INPUT TYPE=HIDDEN NAME=level VALUE="banner"> 1546 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\"> 1547 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1548 <INPUT TYPE=SUBMIT VALUE="Remove Banner"> 1549 </FORM> 1550 1551 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1552 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1553 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="banner"> 1554 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1555 <INPUT TYPE=SUBMIT VALUE="Run the banner"> 1556 </FORM>""" 1557 else: 1558 action = self.command_suggestion_html('remove %s banner --tag=%s' \ 1559 % (self['run_name'], self['tag'])) 1560 action += self.command_suggestion_html('banner_run %s ' % self['run_name']) 1561 1562 1563 1564 subresults_html = sub_part_template_parton % \ 1565 {'type': '', 1566 'run': self['run_name'], 1567 'cross_span': 1, 1568 'cross': self['cross'], 1569 'err': self['error'], 1570 'nb_event': self['nb_event'] and self['nb_event'] or 'No events yet', 1571 'links': 'banner only', 1572 'action': action, 1573 'run_mode': '', 1574 'syst':'', 1575 'bias':'' 1576 } 1577 1578 if self.debug is KeyboardInterrupt: 1579 debug = '<br><font color=red>Interrupted</font>' 1580 elif isinstance(self.debug, basestring): 1581 if not os.path.isabs(self.debug) and not self.debug.startswith('./'): 1582 self.debug = './' + self.debug 1583 elif os.path.isabs(self.debug): 1584 self.debug = os.path.relpath(self.debug, self.me_dir) 1585 debug = '<br> <a href=\'%s\'> <font color=red>ERROR</font></a>' \ 1586 % (self.debug) 1587 elif self.debug: 1588 text = str(self.debug).replace('. ','.<br>') 1589 if 'http' in text: 1590 pat = re.compile('(http[\S]*)') 1591 text = pat.sub(r'<a href=\1> here </a>', text) 1592 debug = '<br><font color=red>%s<BR>%s</font>' % \ 1593 (self.debug.__class__.__name__, text) 1594 else: 1595 debug = '' 1596 text = tag_template % {'tag_span': nb_line, 1597 'run': self['run_name'], 'tag': self['tag'], 1598 'subruns' : subresults_html, 1599 'debug':debug} 1600 1601 return text
1602 1603
1604 - def command_suggestion_html(self, command):
1605 """return html button with code suggestion""" 1606 1607 if command.startswith('pythia'): 1608 button = 'launch pythia' 1609 if command.startswith('shower'): 1610 button = 'shower events' 1611 elif command.startswith('remove banner'): 1612 button = 'remove banner' 1613 elif command.startswith('remove'): 1614 button = 'remove run' 1615 elif command.startswith('banner_run'): 1616 button = 're-run from the banner' 1617 else: 1618 button = 'launch detector simulation' 1619 if self['run_mode'] == 'madevent': 1620 header = 'Launch ./bin/madevent in a shell, and run the following command: ' 1621 else: 1622 header = 'Launch ./bin/aMCatNLO in a shell, and run the following command: ' 1623 1624 return "<INPUT TYPE=SUBMIT VALUE='%s' onClick=\"alert('%s')\">" % (button, header + command) 1625 1626 1627 return + '<br>'
1628