7 from MadGraphControl.MadGraphUtilsHelpers
import checkSetting,checkSettingExists
10 from AthenaCommon
import Logging
11 mgsyslog = Logging.logging.getLogger(
'MadGraphSysUtils')
13 SYSTEMATICS_WEIGHT_INFO=
"MUR%(mur).1f_MUF%(muf).1f_PDF%(pdf)i"
14 SYSTEMATICS_WEIGHT_INFO_ALTDYNSCALES=
"MUR%(mur).1f_MUF%(muf).1f_DYNSCALE%(dyn)i_PDF%(pdf)i"
29 runcard_systematics_arguments={}
31 basefragment_settings={}
32 basefragment_settings[
'central_pdf']=
None
33 basefragment_settings[
'alternative_pdfs']=
None
34 basefragment_settings[
'pdf_variations']=
None
35 basefragment_settings[
'scale_variations']=
None
36 basefragment_settings[
'alternative_dynamic_scales']=
None
37 for s
in basefragment_settings:
38 if s
in the_base_fragment:
39 if isinstance(basefragment_settings[s],list)
and len(basefragment_settings[s])==0:
41 basefragment_settings[s]=the_base_fragment[s]
44 raise RuntimeError(
'No "central_pdf" configured in base fragment')
45 if s==
'alternative_dynamic_scales':
47 mgsyslog.warning(
'base fragment or pdf settings does not define "'+s+
'"')
50 for s
in basefragment_settings:
52 if not isinstance(basefragment_settings[s],int):
53 raise RuntimeError(s+
', configured in base fragment, has to be an integer')
55 if basefragment_settings[s]
is None:
57 if s==
'scale_variations':
58 if not isinstance(basefragment_settings[s],list):
59 raise RuntimeError(s+
', configured in base fragment, has to be a list of numbers')
60 for pdf
in basefragment_settings[s]:
61 if not isinstance(pdf,float)
and not isinstance(pdf,int):
62 raise RuntimeError(s+
', configured in base fragment, has to be a list of numbers')
64 if not isinstance(basefragment_settings[s],list):
65 raise RuntimeError(s+
', configured in base fragment, has to be a list of integers')
66 for element
in basefragment_settings[s]:
67 if not isinstance(element,int)
or not element>0:
68 raise RuntimeError(s+
', configured in base fragment, has to be a list of positive integers')
71 if basefragment_settings[
'alternative_pdfs']
is not None:
73 if basefragment_settings[
'pdf_variations']
is not None:
74 basefragment_settings[
'alternative_pdfs']=[ a
for a
in basefragment_settings[
'alternative_pdfs']
if a
not in basefragment_settings[
'pdf_variations'] ]
76 if basefragment_settings[
'central_pdf']
in basefragment_settings[
'alternative_pdfs']:
77 basefragment_settings[
'alternative_pdfs'].
remove(basefragment_settings[
'central_pdf'])
80 runcard_settings[
'pdlabel']=
'lhapdf'
81 runcard_settings[
'lhaid']=
str(basefragment_settings[
'central_pdf'])
85 if basefragment_settings[
'alternative_dynamic_scales']
is not None:
86 runcard_systematics_arguments[
'weight_info']=SYSTEMATICS_WEIGHT_INFO_ALTDYNSCALES
88 runcard_systematics_arguments[
'weight_info']=SYSTEMATICS_WEIGHT_INFO
89 runcard_systematics_arguments[
'remove_wgts']=
'".*MUR0.5_MUF2.0.*|.*MUR2.0_MUF0.5.*"'
91 runcard_settings[
'systematics_program']=
'none'
92 for s
in [
'alternative_pdfs',
'pdf_variations',
'scale_variations']:
93 if basefragment_settings[s]
is not None and len(basefragment_settings[s])>0:
96 runcard_settings[
'store_rwgt_info']=
'True'
98 runcard_settings[
'use_syst']=
'True'
100 runcard_settings[
'systematics_program']=
'systematics'
106 if basefragment_settings[
'pdf_variations']
is not None and basefragment_settings[
'central_pdf']
in basefragment_settings[
'pdf_variations']:
107 runcard_settings[
'reweight_pdf']=
'True'
109 runcard_settings[
'reweight_pdf']=
'False'
110 if basefragment_settings[
'pdf_variations']
is not None:
111 for v
in basefragment_settings[
'pdf_variations']:
112 if v==basefragment_settings[
'central_pdf']:
114 runcard_settings[
'lhaid']+=
' '+
str(v)
115 runcard_settings[
'reweight_pdf']+=
' True'
116 if basefragment_settings[
'alternative_pdfs']
is not None:
117 for a
in basefragment_settings[
'alternative_pdfs']:
118 runcard_settings[
'lhaid']+=
' '+
str(a)
119 runcard_settings[
'reweight_pdf']+=
' False'
123 if basefragment_settings[
'pdf_variations']
is not None:
124 for v
in basefragment_settings[
'pdf_variations']:
126 if basefragment_settings[
'alternative_pdfs']
is not None:
127 for a
in basefragment_settings[
'alternative_pdfs']:
130 runcard_systematics_arguments[
'pdf']=
','.
join(sys_pdfs)
132 runcard_settings[
'reweight_pdf']=
'False'
136 if basefragment_settings[
'scale_variations']
is None and isNLO:
137 runcard_settings[
'reweight_scale']=
'False'
138 if basefragment_settings[
'scale_variations']
is not None:
140 runcard_settings[
'reweight_scale']=
'True'
141 runcard_settings[
'rw_rscale']=
' '.
join([
str(s)
for s
in basefragment_settings[
'scale_variations']])
142 runcard_settings[
'rw_fscale']=
' '.
join([
str(s)
for s
in basefragment_settings[
'scale_variations']])
144 runcard_systematics_arguments[
'muf']=
','.
join([
str(s)
for s
in basefragment_settings[
'scale_variations']])
145 runcard_systematics_arguments[
'mur']=
','.
join([
str(s)
for s
in basefragment_settings[
'scale_variations']])
146 runcard_systematics_arguments[
'dyn']=
'-1'
148 runcard_settings[
'reweight_scale']=
'False'
150 if basefragment_settings[
'alternative_dynamic_scales']
is not None:
152 raise RuntimeError(
'Cannot reweight to alternative dynamic scales using the NLO OTF module')
154 runcard_systematics_arguments[
'dyn']=
','.
join([
str(s)
for s
in [-1]+basefragment_settings[
'alternative_dynamic_scales']])
159 return runcard_settings
171 extras[k_clean]=extras[k]
180 raise RuntimeError(
'Error, you tried to set "'+
str(o)+
'" by hand, but you should trust the base fragment with the following options: '+
', '.
join(
systematics_run_card_options(isNLO)))
185 user_set_extras=dict(extras)
186 for s
in new_settings:
188 extras[s]=new_settings[s]
191 mgsyslog.info(
'PDF and scale settings were set as follows:')
194 if p
in user_set_extras:
195 user_set=
str(user_set_extras[p])
198 new_value=
str(extras[p])
199 mgsyslog.info(
'MadGraphUtils set '+
str(p)+
' to "'+new_value+
'", was set to "'+user_set+
'"')
210 if the_base_fragment
is None:
211 mgsyslog.warning(
'!!! No pdf base fragment was included in your job options. PDFs should be set with an include file. You might be unable to follow the PDF4LHC uncertainty prescription. Let\'s hope you know what you doing !!!')
213 mgsyslog.warning(
'!!! No pdf base fragment was included in your job options and you did not specify a LHAPDF yourself -- in the future, this will cause an error !!!')
221 for s
in correct_settings:
222 if s
is None and s
in extras:
225 if s
not in extras
or extras[s]!=correct_settings[s]:
237 if 'systematics_program' in extras:
238 if extras[
'systematics_program'].lower==
'none':
239 mgsyslog.warning(
'no need to convert systematics arguments if systematcs are not run')
241 if extras[
'systematics_program'].lower==
'syscalc':
242 mgsyslog.warning(
'systematics already correct for chosen systematics program SysCalc')
245 if 'systematics_arguments' in extras:
246 mgsyslog.warning(
'systematics_arguments already defined, will be overwritten')
247 systematics_arguments={}
248 systematics_arguments[
'dyn']=
'-1'
249 systematics_arguments[
'mur']=
'1'
250 systematics_arguments[
'muf']=
'1'
252 if 'sys_scalefact' in extras:
253 sys_scalefact=extras[
'sys_scalefact']
254 extras.pop(
'sys_scalefact')
255 if len(sys_scalefact.split())>0:
256 systematics_arguments[
'mur']=
','.
join(sys_scalefact.split())
257 systematics_arguments[
'muf']=
','.
join(sys_scalefact.split())
259 systematics_arguments[
'pdf']=
'central'
260 if 'sys_pdf' in extras:
261 sys_pdf=extras[
'sys_pdf']
262 extras.pop(
'sys_pdf')
263 spl=sys_pdf.replace(
'&&',
' ').
split()
268 if i+1<len(spl)
and spl[i+1].isdigit()
and int(spl[i+1])<1000:
269 pdfs[-1]+=
'@'+
str(
int(spl[i+1])-1)
273 systematics_arguments[
'pdf']=
','.
join(pdfs)
274 systematics_arguments[
'weight_info']=SYSTEMATICS_WEIGHT_INFO
276 return extras[
'systematics_arguments']
279 return '['+
','.
join([
"'--"+k+
"="+systematics_arguments[k]+
"'" for k
in systematics_arguments])+
']'
285 if sys_args.strip().startswith(
'['):
286 argument_list = ast.literal_eval(sys_args)
287 for a
in argument_list:
291 arg=sys_args.replace(
"'",
'').
replace(
'"',
'')
296 spl=sys_arg.strip().
split(
'=')
297 return (spl[0].strip()[2:],spl[1].strip())
303 return [
'pdlabel',
'lhaid',
'reweight_pdf',
'reweight_scale',
'rw_rscale',
'rw_fscale',
'store_rwgt_info',
'systematics_arguments' ]
305 return [
'pdlabel',
'lhaid',
'use_syst',
'sys_scalefact',
'sys_pdf',
'systematics_arguments']