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

Source Code for Module madgraph.various.shower_card

  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 -class ShowerCardError(Exception):
24 pass
25
26 -class ShowerCard(dict):
27 """ """ 28 true = ['.true.', 't', 'true', '1'] 29 false = ['.false.', 'f', 'false', '0'] 30 logical_vars = ['ue_enabled', 'hadronize', 'b_stable', 'pi_stable', 'wp_stable', 31 'wm_stable', 'z_stable', 'h_stable', 'tap_stable', 'tam_stable', 32 'mup_stable', 'mum_stable', 'is_4lep', 'is_bbar', 'combine_td'] 33 string_vars = ['extralibs', 'extrapaths', 'includepaths', 'analyse'] 34 for i in range(1,100): 35 dmstring='dm_'+str(i) 36 string_vars.append(dmstring) 37 int_vars = ['nsplit_jobs', 'maxprint', 'nevents', 'pdfcode', 'rnd_seed', 'rnd_seed2', 'njmax'] 38 float_vars = ['maxerrs', 'lambda_5', 'b_mass', 'qcut'] 39 40 # names_dict has the following structure: 41 # var : {PYTHIA6: varpy6, HERWIG6: varhw6, HERWIGPP: varhwpp, PYTHIA8: varpy8} 42 # where varpy, varhw6 and varhwpp are mc_dependent names 43 # if a mc is not there, that variable is not supposed to be 44 # used / written for thar mc 45 names_dict = {\ 46 'ue_enabled' : {'HERWIG6':'lhsoft', 'PYTHIA6': 'mstp_81', 'HERWIGPP': 'ue_hwpp', 'PYTHIA8': 'ue_py8'}, 47 'pdfcode' : {'HERWIG6':'pdfcode', 'PYTHIA6': 'pdfcode', 'HERWIGPP': 'pdfcode', 'PYTHIA8': 'pdfcode'}, 48 'nevents' : {'HERWIG6':'nevents', 'PYTHIA6': 'nevents', 'HERWIGPP': 'nevents', 'PYTHIA8': 'nevents'}, 49 'hadronize' : {'PYTHIA6': 'mstp_111', 'HERWIGPP': 'hadronize_hwpp', 'PYTHIA8': 'hadronize_py8'}, 50 'b_stable' : {'HERWIG6':'b_stable_hw', 'PYTHIA6': 'b_stable_py', 'HERWIGPP': 'b_stable_hwpp', 'PYTHIA8': 'b_stable_py8'}, 51 'pi_stable' : {'HERWIG6':'pi_stable_hw', 'PYTHIA6': 'pi_stable_py', 'HERWIGPP': 'pi_stable_hwpp', 'PYTHIA8': 'pi_stable_py8'}, 52 'wp_stable' : {'HERWIG6':'wp_stable_hw', 'PYTHIA6': 'wp_stable_py', 'HERWIGPP': 'wp_stable_hwpp', 'PYTHIA8': 'wp_stable_py8'}, 53 'wm_stable' : {'HERWIG6':'wm_stable_hw', 'PYTHIA6': 'wm_stable_py', 'HERWIGPP': 'wm_stable_hwpp', 'PYTHIA8': 'wm_stable_py8'}, 54 'z_stable' : {'HERWIG6':'z_stable_hw', 'PYTHIA6': 'z_stable_py', 'HERWIGPP': 'z_stable_hwpp', 'PYTHIA8': 'z_stable_py8'}, 55 'h_stable' : {'HERWIG6':'h_stable_hw', 'PYTHIA6': 'h_stable_py', 'HERWIGPP': 'h_stable_hwpp', 'PYTHIA8': 'h_stable_py8'}, 56 'tap_stable' : {'HERWIG6':'taup_stable_hw', 'PYTHIA6': 'taup_stable_py', 'HERWIGPP': 'taup_stable_hwpp', 'PYTHIA8': 'taup_stable_py8'}, 57 'tam_stable' : {'HERWIG6':'taum_stable_hw', 'PYTHIA6': 'taum_stable_py', 'HERWIGPP': 'taum_stable_hwpp', 'PYTHIA8': 'taum_stable_py8'}, 58 'mup_stable' : {'HERWIG6':'mup_stable_hw', 'PYTHIA6': 'mup_stable_py', 'HERWIGPP': 'mup_stable_hwpp', 'PYTHIA8': 'mup_stable_py8'}, 59 'mum_stable' : {'HERWIG6':'mum_stable_hw', 'PYTHIA6': 'mum_stable_py', 'HERWIGPP': 'mum_stable_hwpp', 'PYTHIA8': 'mum_stable_py8'}, 60 'is_4lep' : {'PYTHIA6':'is_4l_py'}, 61 'is_bbar' : {'HERWIG6':'is_bb_hw'}, 62 'maxprint' : {'HERWIG6':'maxpr_hw', 'PYTHIA6': 'maxpr_py', 'HERWIGPP': 'maxpr_hwpp', 'PYTHIA8': 'maxpr_py8'}, 63 'rnd_seed' : {'HERWIG6':'rndevseed1_hw', 'PYTHIA6': 'rndevseed_py', 'HERWIGPP': 'rndevseed_hwpp', 'PYTHIA8': 'rndevseed_py8'}, 64 'rnd_seed2' : {'HERWIG6':'rndevseed2_hw'}, 65 'maxerrs' : {'HERWIG6':'err_fr_hw', 'PYTHIA6': 'err_fr_py', 'HERWIGPP': 'err_fr_hwpp', 'PYTHIA8': 'err_fr_py8'}, 66 'lambda_5' : {'HERWIG6':'lambdaherw', 'PYTHIA6': 'lambdapyth', 'HERWIGPP': 'lambdaherw', 'PYTHIA8': 'lambdapyth'}, 67 'b_mass' : {'HERWIG6':'b_mass', 'PYTHIA6': 'b_mass', 'HERWIGPP': 'b_mass', 'PYTHIA8': 'b_mass'}, 68 'analyse' : {'HERWIG6':'hwuti', 'PYTHIA6':'pyuti', 'HERWIGPP':'hwpputi', 'PYTHIA8':'py8uti'}, 69 'qcut' : {'PYTHIA8':'qcut'}, 70 'njmax' : {'PYTHIA8':'njmax'}} 71 72 stdhep_dict = {'HERWIG6':'mcatnlo_hwan_stdhep.o', 'PYTHIA6':'mcatnlo_pyan_stdhep.o'} 73
74 - def __init__(self, card=None, testing=False):
75 """ if testing, card is the content""" 76 self.testing = testing 77 dict.__init__(self) 78 self.keylist = self.keys() 79 80 if card: 81 self.read_card(card)
82 83
84 - def read_card(self, card_path):
85 """read the shower_card, if testing card_path is the content""" 86 if not self.testing: 87 content = open(card_path).read() 88 else: 89 content = card_path 90 lines = [l for l in content.split('\n') \ 91 if '=' in l and not l.startswith('#')] 92 for l in lines: 93 args = l.split('#')[0].split('=') 94 key = args[0].strip().lower() 95 value = args[1].strip() 96 #key 97 if key in self.logical_vars: 98 if value.lower() in self.true: 99 self[key] = True 100 elif value.lower() in self.false: 101 self[key] = False 102 else: 103 raise ShowerCardError('%s is not a valid value for %s' % \ 104 (value, key)) 105 elif key in self.string_vars: 106 if value.lower() == 'none': 107 self[key] = '' 108 else: 109 self[key] = value 110 elif key in self.int_vars: 111 try: 112 self[key] = int(value) 113 except ValueError: 114 raise ShowerCardError('%s is not a valid value for %s. An integer number is expected' % \ 115 (key, value)) 116 elif key in self.float_vars: 117 try: 118 self[key] = float(value) 119 except ValueError: 120 raise ShowerCardError('%s is not a valid value for %s. A floating point number is expected' % \ 121 (key, value)) 122 else: 123 raise ShowerCardError('Unknown entry: %s = %s' % (key, value)) 124 self.keylist.append(key)
125 126 127
128 - def write_card(self, shower, card_path):
129 """write the shower_card for shower in card_path. 130 if self.testing, card_path takes the value of the string""" 131 132 shower = shower.upper() 133 if shower.startswith('PYTHIA6'): 134 self.shower = 'PYTHIA6' 135 else: 136 self.shower = shower 137 lines = [] 138 bool_dict = {True: '.true.', False: '.false.'} 139 bool_dict_num = {True: '1', False: '0'} 140 for key in self.keylist: 141 value = self[key] 142 if key in self.logical_vars: 143 # deal with special case for pythia: 144 if key in ['ue_enabled', 'hadronize'] and self.shower == 'PYTHIA6': 145 value = bool_dict_num[value] 146 else: 147 value = bool_dict[value] 148 elif key in self.string_vars: 149 # deal in a special way with analyse 150 if key == 'analyse': 151 if value is None or not value: 152 try: 153 value = self.stdhep_dict[self.shower] 154 except KeyError: 155 pass 156 try: 157 line = '%s="%s"' % (self.names_dict[key][self.shower].upper(), value) 158 lines.append(line) 159 continue 160 except KeyError: 161 continue 162 if value is None or not value: 163 value = '' 164 else: 165 value = '"%s"' % value 166 167 line = '%s=%s' % (key.upper(), value) 168 lines.append(line) 169 continue 170 elif key in self.int_vars: 171 value = '%d' % value 172 elif key in self.float_vars: 173 value = '%4.3f' % value 174 else: 175 raise ShowerCardError('Unknown key: %s = %s' % (key, value)) 176 try: 177 line = '%s=%s' % (self.names_dict[key][self.shower].upper(), value.upper()) 178 lines.append(line) 179 except KeyError: 180 pass 181 182 if self.testing: 183 return ('\n'.join(lines) + '\n') 184 else: 185 open(card_path, 'w').write(('\n'.join(lines) + '\n'))
186