1 import os, re, subprocess, shutil
3 from MCJobOptionUtils.JOsupport
import get_physics_short
5 mgmodels=
'/cvmfs/atlas.cern.ch/repo/sw/Generators/madgraph/models/latest/'
11 for s
in physics_short.split(
'_'):
13 reweight_name=s.replace(
'rwgt',
'')
14 physics_short=physics_short.replace(
'_'+s,
'')
19 for s
in physics_short.split(
'_'):
21 param_name=s.replace(
'param',
'')
22 physics_short=physics_short.replace(
'_'+s,
'')
25 if reweight_name!=
None and param_name!=
None:
26 raise RuntimeError(
"Can only do either reweighting or use a specific param card")
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)
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)
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]
47 eft_order=eft_order_token.replace(
'SQ',
'^2').
replace(
'lq',
'<=').
replace(
'eq',
'==')
49 for x
in re.findall(
r"\d[A-Za-z]",eft_order):
50 eft_order.replace(x,x[0]+
' '+x[1])
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")
57 process=processes[process_token].
replace(
"EFTORDER",eft_order)
59 return model_token,process,param_name,reweight_name,eft_params
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)
67 def setup_SMEFT(process,model_nick,param_name,reweight_name,eft_params):
69 if model_nick==
"EFTAaUm":
70 model=
"SMEFTsim_A_U35_alphaScheme_UFO"
71 eft_parameter_block=
'frblock'
73 sm_restriction=
'SMlimit'
74 elif model_nick==
"EFTAWUm":
75 model=
"SMEFTsim_A_U35_MwScheme_UFO"
76 eft_parameter_block=
'frblock'
78 sm_restriction=
'SMlimit'
79 elif model_nick==
"EFTBaUm":
80 model=
"SMEFT_alpha_FLU_UFO"
81 eft_parameter_block=
'NEWCOUP'
84 elif model_nick==
"EFTBWUm":
85 model=
"SMEFT_mW_FLU_UFO"
86 eft_parameter_block=
'NEWCOUP'
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'
101 raise RuntimeError(
"Unkown model: "+model_nick)
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)
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
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})
158 shutil.copy(param_card_default,restricted_model+
'/'+
'restrict_'+restriction+
'.dat')
159 model=
'./'+restricted_model
160 restrict_card_loc=
None
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
173 proc_card=
"import model "+model
174 if restriction!=
None:
175 proc_card+=
'-'+restriction
177 proc_card+=process+
"\noutput -f\n"
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')