1 import os, re, subprocess, shutil
4 mgmodels=
'/cvmfs/atlas.cern.ch/repo/sw/Generators/madgraph/models/latest/'
10 for s
in physics_short.split(
'_'):
12 reweight_name=s.replace(
'rwgt',
'')
13 physics_short=physics_short.replace(
'_'+s,
'')
18 for s
in physics_short.split(
'_'):
20 param_name=s.replace(
'param',
'')
21 physics_short=physics_short.replace(
'_'+s,
'')
24 if reweight_name!=
None and param_name!=
None:
25 raise RuntimeError(
"Can only do either reweighting or use a specific param card")
29 if reweight_name==
None and param_name==
None:
30 params_re=
r"_(?P<param>[A-Za-z0-9]+)_(?P<value>[-+]?\d+p?\d*)"
31 eft_params_list=re.findall(params_re,physics_short)
33 for e
in eft_params_list:
34 eft_params[e[0]]=e[1].
replace(
'p',
'.')
35 physics_short=re.sub(params_re,
"",physics_short)
39 jobconfig_tokens=physics_short.split(
'_')
40 print jobconfig_tokens
41 model_token=jobconfig_tokens[-3]
42 process_token=jobconfig_tokens[-2]
43 eft_order_token=jobconfig_tokens[-1]
46 eft_order=eft_order_token.replace(
'SQ',
'^2').
replace(
'lq',
'<=').
replace(
'eq',
'==')
48 for x
in re.findall(
r"\d[A-Za-z]",eft_order):
49 eft_order.replace(x,x[0]+
' '+x[1])
51 if not process_token
in processes:
52 raise RuntimeError(
"Unkown process "+process_token)
53 elif not "EFTORDER" in processes[process_token]:
54 raise RuntimeError(
"No EFTORDER in process")
56 process=processes[process_token].
replace(
"EFTORDER",eft_order)
58 return model_token,process,param_name,reweight_name,eft_params
63 model_nick,process,param_name,reweight_name,eft_params=
parse_SMEFT_JO(physics_short,processes)
64 return setup_SMEFT(process,model_nick,param_name,reweight_name,eft_params)
66 def setup_SMEFT(process,model_nick,param_name,reweight_name,eft_params):
68 if model_nick==
"EFTAaUm":
69 model=
"SMEFTsim_A_U35_alphaScheme_UFO"
70 eft_parameter_block=
'frblock'
72 sm_restriction=
'SMlimit'
73 elif model_nick==
"EFTAWUm":
74 model=
"SMEFTsim_A_U35_MwScheme_UFO"
75 eft_parameter_block=
'frblock'
77 sm_restriction=
'SMlimit'
78 elif model_nick==
"EFTBaUm":
79 model=
"SMEFT_alpha_FLU_UFO"
80 eft_parameter_block=
'NEWCOUP'
83 elif model_nick==
"EFTBWUm":
84 model=
"SMEFT_mW_FLU_UFO"
85 eft_parameter_block=
'NEWCOUP'
88 elif model_nick==
"EFTAaU":
89 model=
"SMEFTsim_A_U35_alphaScheme_UFO"
90 eft_parameter_block=
'frblock'
91 restriction=
'massless'
92 sm_restriction=
'SMlimit_massless'
93 elif model_nick==
"EFTAWU":
94 model=
"SMEFTsim_A_U35_MwScheme_UFO"
95 eft_parameter_block=
'frblock'
96 restriction=
'massless'
97 sm_restriction=
'SMlimit_massless'
100 raise RuntimeError(
"Unkown model: "+model_nick)
103 reweight_card_loc=
None
104 if reweight_name!=
None:
105 param_card_loc=
'MadGraph_param_card_'+model_nick+
'_reweight'+reweight_name+
'.dat'
106 restrict_card_loc=
'MadGraph_restrict_card_'+model_nick+
'_reweight'+reweight_name+
'.dat'
107 reweight_card_loc=
'MadGraph_reweight_card_'+model_nick+
'_'+reweight_name+
'.dat'
108 get_param_file = subprocess.Popen([
'get_files',
'-data', param_card_loc])
109 get_param_file.wait()
110 if not os.path.exists(param_card_loc):
111 raise RuntimeError(
"Cannot find "+param_card_loc)
112 get_restrict_file = subprocess.Popen([
'get_files',
'-data', restrict_card_loc])
113 get_restrict_file.wait()
114 if not os.path.exists(restrict_card_loc):
115 print 'running without user defined restriction card'
116 restrict_card_loc=
None
117 get_reweight_file = subprocess.Popen([
'get_files',
'-data', reweight_card_loc])
118 get_reweight_file.wait()
119 if not os.path.exists(reweight_card_loc):
120 raise RuntimeError(
"Cannot find "+reweight_card_loc)
124 elif param_name!=
None:
125 param_card_loc=
'MadGraph_param_card_'+model_nick+
'_'+param_name+
'.dat'
126 restrict_card_loc=
'MadGraph_restrict_card_'+model_nick+
'_'+param_name+
'.dat'
127 get_param_file = subprocess.Popen([
'get_files',
'-data', param_card_loc])
128 get_param_file.wait()
129 if not os.path.exists(param_card_loc):
130 raise RuntimeError(
"Cannot find "+param_card_loc)
131 get_restrict_file = subprocess.Popen([
'get_files',
'-data', restrict_card_loc])
132 get_restrict_file.wait()
133 if not os.path.exists(restrict_card_loc):
134 print 'running without user defined restriction card'
135 restrict_card_loc=
None
140 param_card_default=
'MadGraph_param_card_'+model_nick+
'.dat'
141 param_card_loc=param_card_default.replace(
'.dat',
'_updated.dat')
142 modify_param_card(param_card_default,output_location=param_card_loc,params={eft_parameter_block:eft_params})
143 if os.path.exists(
'mgmodels_local'):
144 shutil.rmtree(
'mgmodels_local')
145 os.mkdir(
'mgmodels_local')
146 restricted_model=
'mgmodels_local/'+model
147 shutil.copytree(mgmodels+model,restricted_model)
148 eft_params_to_keep=eft_params
149 for p
in eft_params_to_keep:
150 eft_params_to_keep[p]=
'9.999999e-01'
151 if len(eft_params_to_keep)==0:
152 process=process.replace(
'NP==0',
'')
153 restriction=
'without_irrelevant_couplings'
154 if len(eft_params_to_keep)>0:
155 modify_param_card(param_card_default,output_location=restricted_model+
'/'+
'restrict_'+restriction+
'.dat',params={eft_parameter_block:eft_params_to_keep})
157 shutil.copy(param_card_default,restricted_model+
'/'+
'restrict_'+restriction+
'.dat')
158 model=
'./'+restricted_model
159 restrict_card_loc=
None
161 if restrict_card_loc!=
None and (reweight_name!=
None or param_name!=
None):
162 if os.path.exists(
'mgmodels_local'):
163 shutil.rmtree(
'mgmodels_local')
164 os.mkdir(
'mgmodels_local')
165 restricted_model=
'mgmodels_local/'+model
166 shutil.copytree(mgmodels+model,restricted_model)
167 restriction=
'without_irrelevant_couplings'
168 shutil.copy(restrict_card_loc,restricted_model+
'/'+
'restrict_'+restriction+
'.dat')
169 model=
'./'+restricted_model
172 proc_card=
"import model "+model
173 if restriction!=
None:
174 proc_card+=
'-'+restriction
176 proc_card+=process+
"\noutput -f\n"
179 if param_card_loc!=
None:
180 shutil.move(param_card_loc,process_dir+
'/Cards/param_card.dat')
181 if reweight_card_loc!=
None:
182 shutil.move(reweight_card_loc,process_dir+
'/Cards/reweight_card.dat')