ATLAS Offline Software
setupEFT.py
Go to the documentation of this file.
1 import os, re, subprocess, shutil
2 from MadGraphControl.MadGraphUtils import modify_param_card
3 from MCJobOptionUtils.JOsupport import get_physics_short
4 
5 mgmodels='/cvmfs/atlas.cern.ch/repo/sw/Generators/madgraph/models/latest/'
6 
7 def parse_SMEFT_JO(physics_short,processes):
8 
9  # check if reweighting required
10  reweight_name=None
11  for s in physics_short.split('_'):
12  if 'rwgt' in s:
13  reweight_name=s.replace('rwgt','')
14  physics_short=physics_short.replace('_'+s,'')
15  break
16 
17  # check if custom param card needed
18  param_name=None
19  for s in physics_short.split('_'):
20  if 'param' in s:
21  param_name=s.replace('param','')
22  physics_short=physics_short.replace('_'+s,'')
23  break
24 
25  if reweight_name!=None and param_name!=None:
26  raise RuntimeError("Can only do either reweighting or use a specific param card")
27 
28  # find list of non-zero parameters (if not doing reweighting or getting parameters from param card)
29  eft_params=None
30  if reweight_name==None and param_name==None:
31  params_re=r"_(?P<param>[A-Za-z0-9]+)_(?P<value>[-+]?\d+p?\d*)"
32  eft_params_list=re.findall(params_re,physics_short)
33  eft_params={}
34  for e in eft_params_list:
35  eft_params[e[0]]=e[1].replace('p','.')
36  physics_short=re.sub(params_re,"",physics_short)
37 
38  # the last three blocks in name, except for reweight and eft parameters
39  # TODO: update to be more robust and allow e.g. for filters in the name
40  jobconfig_tokens=physics_short.split('_')
41  print jobconfig_tokens
42  model_token=jobconfig_tokens[-3]
43  process_token=jobconfig_tokens[-2]
44  eft_order_token=jobconfig_tokens[-1]
45 
46  # determine process (and EFT order)
47  eft_order=eft_order_token.replace('SQ','^2').replace('lq','<=').replace('eq','==')
48  # add space between number and letter
49  for x in re.findall(r"\d[A-Za-z]",eft_order):
50  eft_order.replace(x,x[0]+' '+x[1])
51 
52  if not process_token in processes:
53  raise RuntimeError("Unkown process "+process_token)
54  elif not "EFTORDER" in processes[process_token]:
55  raise RuntimeError("No EFTORDER in process")
56  else:
57  process=processes[process_token].replace("EFTORDER",eft_order)
58 
59  return model_token,process,param_name,reweight_name,eft_params
60 
61 # build proc, param, and reweight card from 4 last blocks of job config name and 'processes' dict
62 def setup_SMEFT_from_JOname(processes):
63  physics_short=get_physics_short()
64  model_nick,process,param_name,reweight_name,eft_params=parse_SMEFT_JO(physics_short,processes)
65  return setup_SMEFT(process,model_nick,param_name,reweight_name,eft_params)
66 
67 def setup_SMEFT(process,model_nick,param_name,reweight_name,eft_params):
68 
69  if model_nick=="EFTAaUm":
70  model="SMEFTsim_A_U35_alphaScheme_UFO"
71  eft_parameter_block='frblock'
72  restriction=None
73  sm_restriction='SMlimit'
74  elif model_nick=="EFTAWUm":
75  model="SMEFTsim_A_U35_MwScheme_UFO"
76  eft_parameter_block='frblock'
77  restriction=None
78  sm_restriction='SMlimit'
79  elif model_nick=="EFTBaUm":
80  model="SMEFT_alpha_FLU_UFO"
81  eft_parameter_block='NEWCOUP'
82  restriction=None
83  sm_restriction='SM'
84  elif model_nick=="EFTBWUm":
85  model="SMEFT_mW_FLU_UFO"
86  eft_parameter_block='NEWCOUP'
87  restriction=None
88  sm_restriction='SM'
89  elif model_nick=="EFTAaU":
90  model="SMEFTsim_A_U35_alphaScheme_UFO"
91  eft_parameter_block='frblock'
92  restriction='massless'
93  sm_restriction='SMlimit_massless'
94  elif model_nick=="EFTAWU":
95  model="SMEFTsim_A_U35_MwScheme_UFO"
96  eft_parameter_block='frblock'
97  restriction='massless'
98  sm_restriction='SMlimit_massless'
99 
100  else:
101  raise RuntimeError("Unkown model: "+model_nick)
102 
103  # get reweight card and param card for reweighting
104  reweight_card_loc=None
105  if reweight_name!=None:
106  param_card_loc='MadGraph_param_card_'+model_nick+'_reweight'+reweight_name+'.dat'
107  restrict_card_loc='MadGraph_restrict_card_'+model_nick+'_reweight'+reweight_name+'.dat'
108  reweight_card_loc='MadGraph_reweight_card_'+model_nick+'_'+reweight_name+'.dat'
109  get_param_file = subprocess.Popen(['get_files','-data', param_card_loc])
110  get_param_file.wait()
111  if not os.path.exists(param_card_loc):
112  raise RuntimeError("Cannot find "+param_card_loc)
113  get_restrict_file = subprocess.Popen(['get_files','-data', restrict_card_loc])
114  get_restrict_file.wait()
115  if not os.path.exists(restrict_card_loc):
116  print 'running without user defined restriction card'
117  restrict_card_loc=None
118  get_reweight_file = subprocess.Popen(['get_files','-data', reweight_card_loc])
119  get_reweight_file.wait()
120  if not os.path.exists(reweight_card_loc):
121  raise RuntimeError("Cannot find "+reweight_card_loc)
122  eft_params=None
123 
124  # get param card and set non-zero parameters
125  elif param_name!=None:
126  param_card_loc='MadGraph_param_card_'+model_nick+'_'+param_name+'.dat'
127  restrict_card_loc='MadGraph_restrict_card_'+model_nick+'_'+param_name+'.dat'
128  get_param_file = subprocess.Popen(['get_files','-data', param_card_loc])
129  get_param_file.wait()
130  if not os.path.exists(param_card_loc):
131  raise RuntimeError("Cannot find "+param_card_loc)
132  get_restrict_file = subprocess.Popen(['get_files','-data', restrict_card_loc])
133  get_restrict_file.wait()
134  if not os.path.exists(restrict_card_loc):
135  print 'running without user defined restriction card'
136  restrict_card_loc=None
137 
138  # set only one or a few parameter non-zero
139  # dynamically create restricted model that only contains the relevant operators
140  else:
141  param_card_default='MadGraph_param_card_'+model_nick+'.dat'
142  param_card_loc=param_card_default.replace('.dat','_updated.dat')
143  modify_param_card(param_card_default,output_location=param_card_loc,params={eft_parameter_block:eft_params})
144  if os.path.exists('mgmodels_local'):
145  shutil.rmtree('mgmodels_local')
146  os.mkdir('mgmodels_local')
147  restricted_model='mgmodels_local/'+model
148  shutil.copytree(mgmodels+model,restricted_model)
149  eft_params_to_keep=eft_params
150  for p in eft_params_to_keep:
151  eft_params_to_keep[p]='9.999999e-01'
152  if len(eft_params_to_keep)==0:
153  process=process.replace('NP==0','')
154  restriction='without_irrelevant_couplings'
155  if len(eft_params_to_keep)>0:
156  modify_param_card(param_card_default,output_location=restricted_model+'/'+'restrict_'+restriction+'.dat',params={eft_parameter_block:eft_params_to_keep})
157  else:
158  shutil.copy(param_card_default,restricted_model+'/'+'restrict_'+restriction+'.dat')
159  model='./'+restricted_model
160  restrict_card_loc=None
161 
162  if restrict_card_loc!=None and (reweight_name!=None or param_name!=None):
163  if os.path.exists('mgmodels_local'):
164  shutil.rmtree('mgmodels_local')
165  os.mkdir('mgmodels_local')
166  restricted_model='mgmodels_local/'+model
167  shutil.copytree(mgmodels+model,restricted_model)
168  restriction='without_irrelevant_couplings'
169  shutil.copy(restrict_card_loc,restricted_model+'/'+'restrict_'+restriction+'.dat')
170  model='./'+restricted_model
171 
172  # write process card
173  proc_card="import model "+model
174  if restriction!=None:
175  proc_card+='-'+restriction
176  proc_card+="\n"
177  proc_card+=process+"\noutput -f\n"
178  process_dir=new_process(proc_card)
179 
180  if param_card_loc!=None:
181  shutil.move(param_card_loc,process_dir+'/Cards/param_card.dat')
182  if reweight_card_loc!=None:
183  shutil.move(reweight_card_loc,process_dir+'/Cards/reweight_card.dat')
184 
185  return process_dir
186 
187 
188 
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
MadGraphUtils
python.MadGraphUtils.modify_param_card
def modify_param_card(param_card_input=None, param_card_backup=None, process_dir=MADGRAPH_GRIDPACK_LOCATION, params={}, output_location=None)
Definition: MadGraphUtils.py:1443
python.MadGraphUtils.new_process
def new_process(process='generate p p > t t~\noutput -f', plugin=None, keepJpegs=False, usePMGSettings=False)
Definition: MadGraphUtils.py:81
setupEFT.setup_SMEFT
def setup_SMEFT(process, model_nick, param_name, reweight_name, eft_params)
Definition: setupEFT.py:67
setupEFT.parse_SMEFT_JO
def parse_SMEFT_JO(physics_short, processes)
Definition: setupEFT.py:7
setupEFT.setup_SMEFT_from_JOname
def setup_SMEFT_from_JOname(processes)
Definition: setupEFT.py:62
python.JOsupport.get_physics_short
def get_physics_short()
Definition: JOsupport.py:12