Package madgraph :: Package various :: Module banner
[hide private]
[frames] | no frames]

Source Code for Module madgraph.various.banner

   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  """A File for splitting""" 
  16   
  17  import sys 
  18  import re 
  19  import os 
  20   
  21  pjoin = os.path.join 
  22   
  23  try: 
  24      import madgraph.various.misc as misc 
  25      import madgraph.iolibs.file_writers as file_writers 
  26      import madgraph.iolibs.files as files  
  27      import models.check_param_card as param_card_reader 
  28      from madgraph import MG5DIR, InvalidCmd 
  29      MADEVENT = False 
  30  except ImportError: 
  31      MADEVENT = True 
  32      import internal.file_writers as file_writers 
  33      import internal.files as files 
  34      import internal.check_param_card as param_card_reader 
  35      import internal.misc as misc 
  36      from internal import InvalidCmd 
  37       
  38      MEDIR = os.path.split(os.path.dirname(os.path.realpath( __file__ )))[0] 
  39      MEDIR = os.path.split(MEDIR)[0] 
  40   
  41  import logging 
  42   
  43  logger = logging.getLogger('madevent.cards') 
 496   
497 498 499 -def split_banner(banner_path, me_dir, proc_card=True):
500 """a simple way to split a banner""" 501 502 banner = Banner(banner_path) 503 banner.split(me_dir, proc_card)
504
505 -def recover_banner(results_object, level, run=None, tag=None):
506 """as input we receive a gen_crossxhtml.AllResults object. 507 This define the current banner and load it 508 """ 509 510 if not run: 511 try: 512 tag = results_object.current['tag'] 513 except Exception: 514 return Banner() 515 if not tag: 516 try: 517 tag = results_object[run].tags[-1] 518 except Exception,error: 519 return Banner() 520 path = results_object.path 521 banner_path = pjoin(path,'Events',run,'%s_%s_banner.txt' % (run, tag)) 522 523 if not os.path.exists(banner_path): 524 # security if the banner was remove (or program canceled before created it) 525 return Banner() 526 banner = Banner(banner_path) 527 528 529 530 if level == 'pythia': 531 if 'mgpythiacard' in banner: 532 del banner['mgpythiacard'] 533 if level in ['pythia','pgs','delphes']: 534 for tag in ['mgpgscard', 'mgdelphescard', 'mgdelphestrigger']: 535 if tag in banner: 536 del banner[tag] 537 return banner
538
539 540 541 -class InvalidRunCard(InvalidCmd):
542 pass
543
544 -class RunCard(dict):
545 """A class object for the run_card""" 546 547 #list of paramater which are allowed BUT not present in the _default file. 548 hidden_param = ['lhaid', 'gridrun', 'fixed_couplings'] 549 true = ['true', 'True','.true.','T', True, 1,'TRUE'] 550
551 - def __init__(self, run_card):
552 """ """ 553 554 if isinstance(run_card, str): 555 run_card = file(run_card,'r') 556 else: 557 pass # use in banner loading 558 559 for line in run_card: 560 line = line.split('#')[0] 561 line = line.split('!')[0] 562 line = line.split('=') 563 if len(line) != 2: 564 continue 565 self[line[1].strip()] = line[0].replace('\'','').strip()
566
567 - def get_default(self, name, default, log_level):
568 """return self[name] if exist otherwise default. log control if we 569 put a warning or not if we use the default value""" 570 571 try: 572 return self[name] 573 except KeyError: 574 if log_level: 575 logger.log(log_level, 'run_card missed argument %s. Takes default: %s' 576 % (name, default)) 577 self[name] = default 578 return default
579 580 @staticmethod
581 - def format(format, value):
582 """format the value""" 583 584 if format == 'bool': 585 if str(value) in ['1','T','.true.','True']: 586 return '.true.' 587 else: 588 return '.false.' 589 590 elif format == 'int': 591 return str(int(value)) 592 593 elif format == 'float': 594 if isinstance(value, str): 595 value = value.replace('d','e') 596 return ('%.10e' % float(value)).replace('e','d') 597 598 elif format == 'str': 599 return "'%s'" % value
600 601 602
603 - def write(self, output_file, template=None):
604 """Write the run_card in output_file according to template 605 (a path to a valid run_card)""" 606 607 if not template: 608 template = output_file 609 610 text = "" 611 for line in file(template,'r'): 612 nline = line.split('#')[0] 613 nline = nline.split('!')[0] 614 comment = line[len(nline):] 615 nline = nline.split('=') 616 if len(nline) != 2: 617 text += line 618 elif nline[1].strip() in self: 619 text += ' %s\t= %s %s' % (self[nline[1].strip()],nline[1], comment) 620 else: 621 logger.info('Adding missing parameter %s to current run_card (with default value)' % nline[1].strip()) 622 text += line 623 624 for param in self.hidden_param: 625 if param in self: 626 text += ' %s\t= %s \n' % (self[param],param) 627 628 fsock = open(output_file,'w') 629 fsock.write(text) 630 fsock.close()
631 632
633 - def write_include_file(self, output_path):
634 """writing the run_card.inc file""" 635 636 self.fsock = file_writers.FortranWriter(output_path) 637 ################################################################################ 638 # Writing the lines corresponding to the cuts 639 ################################################################################ 640 # Frixione photon isolation 641 self.add_line('ptgmin', 'float', 0.0) 642 self.add_line('R0gamma', 'float', 0.4) 643 self.add_line('xn', 'float', 1.0) 644 self.add_line('epsgamma', 'float', 1.0) 645 self.add_line('isoEM', 'bool', True) 646 # Cut that need to be deactivated in presence of isolation 647 if 'ptgmin' in self and float(self['ptgmin'])>0: 648 if float(self['pta']) > 0: 649 logger.warning('pta cut discarded since photon isolation is used') 650 self['pta'] = '0' 651 if float(self['draj']) > 0: 652 logger.warning('draj cut discarded since photon isolation is used') 653 self['draj'] = '0' 654 655 self.add_line('maxjetflavor', 'int', 4) 656 if int(self['maxjetflavor']) > 6: 657 raise InvalidRunCard, 'maxjetflavor should be lower than 5! (6 is partly supported)' 658 self.add_line('auto_ptj_mjj', 'bool', True) 659 self.add_line('cut_decays', 'bool', True) 660 # minimum pt 661 self.add_line('ptj', 'float', 20) 662 self.add_line('ptb', 'float', 20) 663 self.add_line('pta', 'float', 20) 664 self.add_line('ptl', 'float', 20) 665 self.add_line('misset', 'float', 0) 666 self.add_line('ptonium', 'float', 0.0) 667 # maximal pt 668 self.add_line('ptjmax', 'float', -1) 669 self.add_line('ptbmax', 'float', -1) 670 self.add_line('ptamax', 'float', -1) 671 self.add_line('ptlmax', 'float', -1) 672 self.add_line('missetmax', 'float', -1) 673 # maximal rapidity (absolute value) 674 self.add_line('etaj', 'float', 4.0) 675 self.add_line('etab', 'float', 4.0) 676 self.add_line('etaa', 'float', 4.0) 677 self.add_line('etal', 'float', 4.0) 678 # minimal rapidity (absolute value) 679 self.add_line('etajmin', 'float', 0.0) 680 self.add_line('etabmin', 'float', 0.0) 681 self.add_line('etaamin', 'float', 0.0) 682 self.add_line('etalmin', 'float', 0.0) 683 self.add_line('etaonium', 'float', 100.0) 684 # Minimul E's 685 self.add_line('ej', 'float', 0.0) 686 self.add_line('eb', 'float', 0.0) 687 self.add_line('ea', 'float', 0.0) 688 self.add_line('el', 'float', 0.0) 689 # Maximum E's 690 self.add_line('ejmax', 'float', -1) 691 self.add_line('ebmax', 'float', -1) 692 self.add_line('eamax', 'float', -1) 693 self.add_line('elmax', 'float', -1) 694 # minimum delta_r 695 self.add_line('drjj', 'float', 0.4) 696 self.add_line('drbb', 'float', 0.4) 697 self.add_line('drll', 'float', 0.4) 698 self.add_line('draa', 'float', 0.4) 699 self.add_line('drbj', 'float', 0.4) 700 self.add_line('draj', 'float', 0.4) 701 self.add_line('drjl', 'float', 0.4) 702 self.add_line('drab', 'float', 0.4) 703 self.add_line('drbl', 'float', 0.4) 704 self.add_line('dral', 'float', 0.4) 705 # maximum delta_r 706 self.add_line('drjjmax', 'float', -1) 707 self.add_line('drbbmax', 'float', -1) 708 self.add_line('drllmax', 'float', -1) 709 self.add_line('draamax', 'float', -1) 710 self.add_line('drbjmax', 'float', -1) 711 self.add_line('drajmax', 'float', -1) 712 self.add_line('drjlmax', 'float', -1) 713 self.add_line('drabmax', 'float', -1) 714 self.add_line('drblmax', 'float', -1) 715 self.add_line('dralmax', 'float', -1) 716 # minimum invariant mass for pairs 717 self.add_line('mmjj', 'float', 0.0) 718 self.add_line('mmbb', 'float', 0.0) 719 self.add_line('mmaa', 'float', 0.0) 720 self.add_line('mmll', 'float', 0.0) 721 # maximum invariant mall for pairs 722 self.add_line('mmjjmax', 'float', -1) 723 self.add_line('mmbbmax', 'float', -1) 724 self.add_line('mmaamax', 'float', -1) 725 self.add_line('mmllmax', 'float', -1) 726 #Min Maxi invariant mass for all leptons 727 self.add_line("mmnl", 'float', 0.0) 728 self.add_line("mmnlmax", 'float', -1) 729 #inclusive cuts 730 self.add_line("xptj", 'float', 0.0) 731 self.add_line("xptb", 'float', 0.0) 732 self.add_line("xpta", 'float', 0.0) 733 self.add_line("xptl", 'float', 0.0) 734 self.add_line("xmtcentral", 'float', 0.0, fortran_name='xmtc', log=10) 735 # WBT cuts 736 self.add_line("xetamin", 'float', 0.0) 737 self.add_line("deltaeta", 'float', 0.0) 738 # Jet measure cuts 739 self.add_line("xqcut", 'float', 0.0) 740 self.add_line("d", 'float', 1.0, log=10) 741 # Set min pt of one heavy particle 742 self.add_line("ptheavy", 'float', 0.0) 743 # Pt of pairs of leptons (CHARGED AND NEUTRALS) 744 self.add_line("ptllmin", "float", 0.0) 745 self.add_line("ptllmax", "float", -1) 746 # Check the pt's of the jets sorted by pt 747 self.add_line("ptj1min", "float", 0.0) 748 self.add_line("ptj1max", "float", -1) 749 self.add_line("ptj2min", "float", 0.0) 750 self.add_line("ptj2max", "float", -1) 751 self.add_line("ptj3min", "float", 0.0) 752 self.add_line("ptj3max", "float", -1) 753 self.add_line("ptj4min", "float", 0.0) 754 self.add_line("ptj4max", "float", -1) 755 self.add_line("cutuse", "float", 0.0) 756 # Check the pt's of leptons sorted by pt 757 self.add_line("ptl1min", "float", 0.0) 758 self.add_line("ptl1max", "float", -1) 759 self.add_line("ptl2min", "float", 0.0) 760 self.add_line("ptl2max", "float", -1) 761 self.add_line("ptl3min", "float", 0.0) 762 self.add_line("ptl3max", "float", -1) 763 self.add_line("ptl4min", "float", 0.0) 764 self.add_line("ptl4max", "float", -1) 765 # Check Ht 766 self.add_line("ht2min", 'float', 0.0) 767 self.add_line("ht3min", 'float', 0.0) 768 self.add_line("ht4min", 'float', 0.0) 769 self.add_line("ht2max", 'float', -1) 770 self.add_line("ht3max", 'float', -1) 771 self.add_line("ht4max", 'float', -1) 772 self.add_line("htjmin", 'float', 0.0) 773 self.add_line("htjmax", 'float', -1) 774 self.add_line("ihtmin", 'float', 0.0) 775 self.add_line("ihtmax", 'float', -1) 776 # kt_ durham 777 self.add_line('ktdurham', 'float', -1, fortran_name='kt_durham') 778 self.add_line('dparameter', 'float', 0.4, fortran_name='d_parameter') 779 780 781 ################################################################################ 782 # Writing the lines corresponding to anything but cuts 783 ################################################################################ 784 # lhe output format 785 self.add_line("lhe_version", "float", 2.0) #if not specify assume old standard 786 # seed 787 self.add_line("gridpack","bool", False) 788 self.add_line("gridrun",'bool', False, log=10) 789 if str(self['gridrun']) in ['1','T','.true','True'] and \ 790 str(self['gridpack']) in ['1','T','.true','True']: 791 self.add_line('gseed', 'int', 0, fortran_name='iseed') 792 else: 793 self.add_line('iseed', 'int', 0, fortran_name='iseed') 794 #number of events 795 self.add_line('nevents', 'int', 10000) 796 #self.add_line('gevents', 'int', 2000, log=10) 797 798 # Renormalizrion and factorization scales 799 self.add_line('fixed_ren_scale', 'bool', True) 800 self.add_line('fixed_fac_scale', 'bool', True) 801 self.add_line('scale', 'float', 'float', 91.188) 802 self.add_line('dsqrt_q2fact1','float', 91.188, fortran_name='sf1') 803 self.add_line('dsqrt_q2fact2', 'float', 91.188, fortran_name='sf2') 804 805 self.add_line('use_syst', 'bool', False) 806 #if use_syst is True, some parameter are automatically fixed. 807 if self['use_syst'] in self.true: 808 value = self.format('float',self.get_default('scalefact', 1.0, 30)) 809 if value != self.format('float', 1.0): 810 logger.warning('Since use_syst=T, We change the value of \'scalefact\' to 1') 811 self['scalefact'] = 1.0 812 self.add_line('scalefact', 'float', 1.0) 813 814 self.add_line('fixed_couplings', 'bool', True, log=10) 815 self.add_line('ickkw', 'int', 0) 816 self.add_line('chcluster', 'bool', False) 817 self.add_line('ktscheme', 'int', 1) 818 self.add_line('asrwgtflavor', 'int', 5) 819 820 #CKKW TREATMENT! 821 if int(self['ickkw'])>0: 822 #if use_syst is True, some parameter are automatically fixed. 823 if self['use_syst'] in self.true: 824 value = self.format('float',self.get_default('alpsfact', 1.0, 30)) 825 if value != self.format('float', 1.0): 826 logger.warning('Since use_syst=T, We change the value of \'alpsfact\' to 1') 827 self['alpsfact'] = 1.0 828 if int(self['maxjetflavor']) == 6: 829 raise InvalidRUnCard, 'maxjetflavor at 6 is NOT supported for matching!' 830 self.add_line('alpsfact', 'float', 1.0) 831 self.add_line('pdfwgt', 'bool', True) 832 self.add_line('clusinfo', 'bool', False) 833 # check that DRJJ and DRJL are set to 0 and MMJJ 834 if self.format('float', self['drjj']) != self.format('float', 0.): 835 logger.warning('Since icckw>0, We change the value of \'drjj\' to 0') 836 if self.format('float', self['drjl']) != self.format('float', 0.): 837 logger.warning('Since icckw>0, We change the value of \'drjl\' to 0') 838 if self.format('bool', self['auto_ptj_mjj']) == '.false.': 839 #ensure formatting 840 mmjj = self['mmjj'] 841 if isinstance(mmjj,str): 842 mmjj = float(mmjj.replace('d','e')) 843 xqcut = self['xqcut'] 844 if isinstance(xqcut,str): 845 xqcut = float(xqcut.replace('d','e')) 846 847 if mmjj > xqcut: 848 logger.warning('mmjj > xqcut (and auto_ptj_mjj = F). MMJJ set to 0') 849 self.add_line('mmjj','float',0) 850 851 if int(self['ickkw'])==2: 852 self.add_line('highestmult','int', 0, fortran_name='nhmult') 853 self.add_line('issgridfile','str','issudgrid.dat') 854 855 # Collider energy and type 856 self.add_line('lpp1', 'int', 1, fortran_name='lpp(1)') 857 self.add_line('lpp2', 'int', 1, fortran_name='lpp(2)') 858 self.add_line('ebeam1', 'float', 7000, fortran_name='ebeam(1)') 859 self.add_line('ebeam2', 'float', 7000, fortran_name='ebeam(2)') 860 # Beam polarization 861 self.add_line('polbeam1', 'float', 0.0, fortran_name='pb1') 862 self.add_line('polbeam2', 'float', 0.0, fortran_name='pb2') 863 # BW cutoff (M+/-bwcutoff*Gamma) 864 self.add_line('bwcutoff', 'float', 15.0) 865 # Collider pdf 866 self.add_line('pdlabel','str','cteq6l1') 867 868 # check validity of the pdf set 869 possible_set = ['lhapdf','mrs02nl','mrs02nn', 'mrs0119','mrs0117','mrs0121','mrs01_j', 'mrs99_1','mrs99_2','mrs99_3','mrs99_4','mrs99_5','mrs99_6', 'mrs99_7','mrs99_8','mrs99_9','mrs9910','mrs9911','mrs9912', 'mrs98z1','mrs98z2','mrs98z3','mrs98z4','mrs98z5','mrs98ht', 'mrs98l1','mrs98l2','mrs98l3','mrs98l4','mrs98l5', 'cteq3_m','cteq3_l','cteq3_d', 'cteq4_m','cteq4_d','cteq4_l','cteq4a1','cteq4a2', 'cteq4a3','cteq4a4','cteq4a5','cteq4hj','cteq4lq', 'cteq5_m','cteq5_d','cteq5_l','cteq5hj','cteq5hq', 'cteq5f3','cteq5f4','cteq5m1','ctq5hq1','cteq5l1', 'cteq6_m','cteq6_d','cteq6_l','cteq6l1', 'nn23lo','nn23lo1','nn23nlo'] 870 if self['pdlabel'] not in possible_set: 871 raise InvalidRunCard, 'Invalid PDF set (argument of pdlabel) possible choice are:\n %s' % ','.join(possible_set) 872 873 if self['pdlabel'] == 'lhapdf': 874 self.add_line('lhaid', 'int', 10042) 875 else: 876 self.add_line('lhaid', 'int', 10042, log=10) 877 878 self.fsock.close()
879 880 881 882
883 - def add_line(self, card_name, type, default, log=30, fortran_name=None):
884 """get the line for the .inc file""" 885 886 value = self.get_default(card_name, default, log) 887 if not fortran_name: 888 fortran_name = card_name 889 self.fsock.writelines(' %s = %s \n' % (fortran_name, self.format(type, value)))
890
891 892 -class RunCardNLO(RunCard):
893 """A class object for the run_card for a (aMC@)NLO pocess""" 894 895
896 - def write_include_file(self, output_path):
897 """writing the run_card.inc file""" 898 899 # For FxFx merging, make sure that the following parameters are set correctly: 900 true = ['true', 'True','.true.','T', True, 1,'TRUE'] 901 if int(self['ickkw']) == 3: 902 # 1. Renormalization and factorization (and ellis-sexton scales) are not fixed 903 scales=['fixed_ren_scale','fixed_fac_scale','fixed_QES_scale'] 904 for scale in scales: 905 if self[scale] in true : 906 logger.info('''For consistency in the FxFx merging, \'%s\' has been set to false''' 907 % scale,'$MG:color:BLACK') 908 self[scale]='F' 909 # 2. Use kT algorithm for jets with pseudo-code size R=1.0 910 jetparams=['jetradius','jetalgo'] 911 for jetparam in jetparams: 912 if float(self[jetparam]) != 1.0: 913 logger.info('''For consistency in the FxFx merging, \'%s\' has been set to 1.0''' 914 % jetparam ,'$MG:color:BLACK') 915 self[jetparam]='1.0' 916 917 #ensure that iappl is present in the card! 918 self.get_default('iappl', '0', log_level=10) 919 # For interface to APPLGRID, need to use LHAPDF and reweighting to get scale uncertainties 920 if self['iappl'] != '0' and self['pdlabel'].lower() != 'lhapdf': 921 raise self.InvalidCmd('APPLgrid generation only possible with the use of LHAPDF') 922 if self['iappl'] != '0' and self['reweight_scale'] not in true: 923 raise self.InvalidCmd('APPLgrid generation only possible with including' +\ 924 ' the reweighting to get scale dependence') 925 926 self.fsock = file_writers.FortranWriter(output_path) 927 ################################################################################ 928 # Writing the lines corresponding to the cuts 929 ################################################################################ 930 931 self.add_line('maxjetflavor', 'int', 4) 932 # minimum pt 933 self.add_line('ptj', 'float', 20) 934 self.add_line('etaj', 'float', -1.0) 935 self.add_line('ptl', 'float', 20) 936 self.add_line('etal', 'float', -1.0) 937 # minimum delta_r 938 self.add_line('drll', 'float', 0.4) 939 self.add_line('drll_sf', 'float', 0.4) 940 # minimum invariant mass for pairs 941 self.add_line('mll', 'float', 0.0) 942 self.add_line('mll_sf', 'float', 0.0) 943 #inclusive cuts 944 # Jet measure cuts 945 self.add_line("jetradius", 'float', 0.7, log=10) 946 947 ################################################################################ 948 # Writing the lines corresponding to anything but cuts 949 ################################################################################ 950 # seed 951 self.add_line('iseed', 'int', 0) 952 self.add_line('parton_shower', 'str', 'HERWIG6', fortran_name='shower_mc') 953 self.add_line('nevents', 'int', 10000) 954 self.add_line('event_norm', 'str', 'average', fortran_name='event_norm') 955 # Renormalizrion and factorization scales 956 self.add_line('fixed_ren_scale', 'bool', True) 957 self.add_line('fixed_fac_scale', 'bool', True) 958 self.add_line('fixed_QES_scale', 'bool', True) 959 self.add_line('muR_ref_fixed', 'float', 91.188) 960 self.add_line('muF1_ref_fixed','float', 91.188) 961 self.add_line('muF2_ref_fixed', 'float', 91.188) 962 self.add_line('QES_ref_fixed', 'float', 91.188) 963 self.add_line('muR_over_ref', 'float', 1.0) 964 self.add_line('muF1_over_ref', 'float', 1.0) 965 self.add_line('muF2_over_ref', 'float', 1.0) 966 self.add_line('QES_over_ref', 'float', 1.0) 967 #reweight block 968 self.add_line('reweight_scale', 'bool', True, fortran_name='do_rwgt_scale') 969 self.add_line('rw_Rscale_up', 'float', 2.0) 970 self.add_line('rw_Rscale_down', 'float', 0.5) 971 self.add_line('rw_Fscale_up', 'float', 2.0) 972 self.add_line('rw_Fscale_down', 'float', 0.5) 973 self.add_line('reweight_PDF', 'bool', True, fortran_name='do_rwgt_pdf') 974 self.add_line('PDF_set_min', 'int', 21101) 975 self.add_line('PDF_set_max', 'int', 21140) 976 self.add_line('iappl', 'int', 0) 977 # FxFx merging stuff 978 self.add_line('ickkw', 'int', 0) 979 self.add_line('jetalgo', 'float', 1.0) 980 # Collider energy and type 981 self.add_line('lpp1', 'int', 1, fortran_name='lpp(1)') 982 self.add_line('lpp2', 'int', 1, fortran_name='lpp(2)') 983 self.add_line('ebeam1', 'float', 4000, fortran_name='ebeam(1)') 984 self.add_line('ebeam2', 'float', 4000, fortran_name='ebeam(2)') 985 # BW cutoff (M+/-bwcutoff*Gamma) 986 self.add_line('bwcutoff', 'float', 15.0) 987 # Photon isolation 988 self.add_line('ptgmin', 'float', 10.0) 989 self.add_line('etagamma', 'float', -1.0) 990 self.add_line('R0gamma', 'float', 0.4) 991 self.add_line('xn', 'float', 1.0) 992 self.add_line('epsgamma', 'float', 1.0) 993 self.add_line('isoEM', 'bool', True) 994 # Collider pdf 995 self.add_line('pdlabel','str','cteq6_m') 996 # check validity of the pdf set 997 possible_set = ['lhapdf','mrs02nl','mrs02nn', 'mrs0119','mrs0117','mrs0121','mrs01_j', 'mrs99_1','mrs99_2','mrs99_3','mrs99_4','mrs99_5','mrs99_6', 'mrs99_7','mrs99_8','mrs99_9','mrs9910','mrs9911','mrs9912', 'mrs98z1','mrs98z2','mrs98z3','mrs98z4','mrs98z5','mrs98ht', 'mrs98l1','mrs98l2','mrs98l3','mrs98l4','mrs98l5', 'cteq3_m','cteq3_l','cteq3_d', 'cteq4_m','cteq4_d','cteq4_l','cteq4a1','cteq4a2', 'cteq4a3','cteq4a4','cteq4a5','cteq4hj','cteq4lq', 'cteq5_m','cteq5_d','cteq5_l','cteq5hj','cteq5hq', 'cteq5f3','cteq5f4','cteq5m1','ctq5hq1','cteq5l1', 'cteq6_m','cteq6_d','cteq6_l','cteq6l1', 'nn23lo','nn23lo1','nn23nlo'] 998 if self['pdlabel'] not in possible_set: 999 raise InvalidRunCard, 'Invalid PDF set (argument of pdlabel) possible choice are:\n %s' % ','.join(possible_set) 1000 1001 1002 1003 if self['pdlabel'] == 'lhapdf': 1004 self.add_line('lhaid', 'int', 21100) 1005 else: 1006 self.add_line('lhaid', 'int', 21100, log=10) 1007 1008 self.fsock.close()
1009
1010 -class ProcCard(list):
1011 """Basic Proccard object""" 1012 1013 history_header = \ 1014 '#************************************************************\n' + \ 1015 '#* MadGraph5_aMC@NLO *\n' + \ 1016 '#* *\n' + \ 1017 "#* * * *\n" + \ 1018 "#* * * * * *\n" + \ 1019 "#* * * * * 5 * * * * *\n" + \ 1020 "#* * * * * *\n" + \ 1021 "#* * * *\n" + \ 1022 "#* *\n" + \ 1023 "#* *\n" + \ 1024 "%(info_line)s" +\ 1025 "#* *\n" + \ 1026 "#* The MadGraph5_aMC@NLO Development Team - Find us at *\n" + \ 1027 "#* https://server06.fynu.ucl.ac.be/projects/madgraph *\n" + \ 1028 '#* *\n' + \ 1029 '#************************************************************\n' + \ 1030 '#* *\n' + \ 1031 '#* Command File for MadGraph5_aMC@NLO *\n' + \ 1032 '#* *\n' + \ 1033 '#* run as ./bin/mg5_aMC filename *\n' + \ 1034 '#* *\n' + \ 1035 '#************************************************************\n' 1036 1037 1038 1039
1040 - def __init__(self, init=None):
1041 """ initialize a basic proc_card""" 1042 self.info = {'model': 'sm', 'generate':None, 1043 'full_model_line':'import model sm'} 1044 list.__init__(self) 1045 if init: 1046 self.read(init)
1047 1048
1049 - def read(self, init):
1050 """read the proc_card and save the information""" 1051 1052 if isinstance(init, str): #path to file 1053 init = file(init, 'r') 1054 1055 store_line = '' 1056 for line in init: 1057 line = line.strip() 1058 if line.endswith('\\'): 1059 store_line += line[:-1] 1060 else: 1061 self.append(store_line + line) 1062 store_line = "" 1063 if store_line: 1064 raise Exception, "WRONG CARD FORMAT"
1065 - def move_to_last(self, cmd):
1066 """move an element to the last history.""" 1067 for line in self[:]: 1068 if line.startswith(cmd): 1069 self.remove(line) 1070 list.append(self, line)
1071
1072 - def append(self, line):
1073 """"add a line in the proc_card perform automatically cleaning""" 1074 1075 line = line.strip() 1076 cmds = line.split() 1077 if len(cmds) == 0: 1078 return 1079 1080 list.append(self, line) 1081 1082 # command type: 1083 cmd = cmds[0] 1084 1085 if cmd == 'output': 1086 # Remove previous outputs from history 1087 self.clean(allow_for_removal = ['output'], keep_switch=True, 1088 remove_bef_last='output') 1089 elif cmd == 'generate': 1090 # Remove previous generations from history 1091 self.clean(remove_bef_last='generate', keep_switch=True, 1092 allow_for_removal= ['generate', 'add process', 'output']) 1093 self.info['generate'] = ' '.join(cmds[1:]) 1094 elif cmd == 'add' and cmds[1] == 'process' and not self.info['generate']: 1095 self.info['generate'] = ' '.join(cmds[2:]) 1096 elif cmd == 'import': 1097 if len(cmds) < 2: 1098 return 1099 if cmds[1].startswith('model'): 1100 self.info['full_model_line'] = line 1101 self.clean(remove_bef_last='import', keep_switch=True, 1102 allow_for_removal=['generate', 'add process', 'add model', 'output']) 1103 if cmds[1] == 'model': 1104 self.info['model'] = cmds[2] 1105 else: 1106 self.info['model'] = None # not UFO model 1107 elif cmds[1] == 'proc_v4': 1108 #full cleaning 1109 self[:] = []
1110 1111
1112 - def clean(self, to_keep=['set','add','load'], 1113 remove_bef_last=None, 1114 to_remove=['open','display','launch', 'check','history'], 1115 allow_for_removal=None, 1116 keep_switch=False):
1117 """Remove command in arguments from history. 1118 All command before the last occurrence of 'remove_bef_last' 1119 (including it) will be removed (but if another options tells the opposite). 1120 'to_keep' is a set of line to always keep. 1121 'to_remove' is a set of line to always remove (don't care about remove_bef_ 1122 status but keep_switch acts.). 1123 if 'allow_for_removal' is define only the command in that list can be 1124 remove of the history for older command that remove_bef_lb1. all parameter 1125 present in to_remove are always remove even if they are not part of this 1126 list. 1127 keep_switch force to keep the statement remove_bef_??? which changes starts 1128 the removal mode. 1129 """ 1130 1131 #check consistency 1132 if __debug__ and allow_for_removal: 1133 for arg in to_keep: 1134 assert arg not in allow_for_removal 1135 1136 1137 nline = -1 1138 removal = False 1139 #looping backward 1140 while nline > -len(self): 1141 switch = False # set in True when removal pass in True 1142 1143 #check if we need to pass in removal mode 1144 if not removal and remove_bef_last: 1145 if self[nline].startswith(remove_bef_last): 1146 removal = True 1147 switch = True 1148 1149 # if this is the switch and is protected pass to the next element 1150 if switch and keep_switch: 1151 nline -= 1 1152 continue 1153 1154 # remove command in to_remove (whatever the status of removal) 1155 if any([self[nline].startswith(arg) for arg in to_remove]): 1156 self.pop(nline) 1157 continue 1158 1159 # Only if removal mode is active! 1160 if removal: 1161 if allow_for_removal: 1162 # Only a subset of command can be removed 1163 if any([self[nline].startswith(arg) 1164 for arg in allow_for_removal]): 1165 self.pop(nline) 1166 continue 1167 elif not any([self[nline].startswith(arg) for arg in to_keep]): 1168 # All command have to be remove but protected 1169 self.pop(nline) 1170 continue 1171 1172 # update the counter to pass to the next element 1173 nline -= 1
1174
1175 - def __getattr__(self, tag, default=None):
1176 if isinstance(tag, int): 1177 list.__getattr__(self, tag) 1178 elif tag == 'info' or tag == "__setstate__": 1179 return default #for pickle 1180 else: 1181 return self.info[tag]
1182
1183 - def write(self, path):
1184 """write the proc_card to a given path""" 1185 1186 fsock = open(path, 'w') 1187 fsock.write(self.history_header) 1188 for line in self: 1189 while len(line) > 70: 1190 sub, line = line[:70]+"\\" , line[70:] 1191 fsock.write(sub+"\n") 1192 else: 1193 fsock.write(line+"\n")
1194