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