ATLAS Offline Software
Loading...
Searching...
No Matches
python.MadGraphSystematicsUtils Namespace Reference

Functions

 get_pdf_and_systematic_settings (the_base_fragment, isNLO, useNLOotf=False)
 convertSysCalcArguments (extras)
 write_systematics_arguments (systematics_arguments)
 parse_systematics_arguments (sys_args)
 parse_systematics_argument (sys_arg)
 systematics_run_card_options (isNLO)

Variables

 mgsyslog = Logging.logging.getLogger('MadGraphSysUtils')
str SYSTEMATICS_WEIGHT_INFO = "MUR%(mur).1f_MUF%(muf).1f_PDF%(pdf)i"
str SYSTEMATICS_WEIGHT_INFO_ALTDYNSCALES = "MUR%(mur).1f_MUF%(muf).1f_DYNSCALE%(dyn)i_PDF%(pdf)i"

Function Documentation

◆ convertSysCalcArguments()

python.MadGraphSystematicsUtils.convertSysCalcArguments ( extras)

Definition at line 164 of file MadGraphSystematicsUtils.py.

164def convertSysCalcArguments(extras):
165 if 'systematics_program' in extras:
166 if extras['systematics_program'].lower=='none':
167 mgsyslog.warning('no need to convert systematics arguments if systematcs are not run')
168 return
169 if extras['systematics_program'].lower=='syscalc':
170 mgsyslog.warning('systematics already correct for chosen systematics program SysCalc')
171 return
172
173 if 'systematics_arguments' in extras:
174 mgsyslog.warning('systematics_arguments already defined, will be overwritten')
175 systematics_arguments={}
176 systematics_arguments['dyn']='-1'
177 systematics_arguments['mur']='1'
178 systematics_arguments['muf']='1'
179
180 if 'sys_scalefact' in extras:
181 sys_scalefact=extras['sys_scalefact']
182 extras.pop('sys_scalefact')
183 if len(sys_scalefact.split())>0:
184 systematics_arguments['mur']=','.join(sys_scalefact.split())
185 systematics_arguments['muf']=','.join(sys_scalefact.split())
186
187 systematics_arguments['pdf']='central'
188 if 'sys_pdf' in extras:
189 sys_pdf=extras['sys_pdf']
190 extras.pop('sys_pdf')
191 spl=sys_pdf.replace('&&',' ').split()
192 i=0
193 pdfs=[]
194 while i <len(spl):
195 pdfs.append(spl[i])
196 if i+1<len(spl) and spl[i+1].isdigit() and int(spl[i+1])<1000:
197 pdfs[-1]+='@'+str(int(spl[i+1])-1)
198 i+=1
199 i+=1
200 if len(pdfs)>0:
201 systematics_arguments['pdf']=','.join(pdfs)
202 systematics_arguments['weight_info']=SYSTEMATICS_WEIGHT_INFO
203 extras['systematics_arguments']=write_systematics_arguments(systematics_arguments)
204 return extras['systematics_arguments']
205
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ get_pdf_and_systematic_settings()

python.MadGraphSystematicsUtils.get_pdf_and_systematic_settings ( the_base_fragment,
isNLO,
useNLOotf = False )

Definition at line 21 of file MadGraphSystematicsUtils.py.

21def get_pdf_and_systematic_settings(the_base_fragment,isNLO,useNLOotf=False):
22
23 if not isNLO:
24 useNLOotf=False
25
26
27 runcard_settings={}
28 runcard_systematics_arguments={}
29
30 basefragment_settings={}
31 basefragment_settings['central_pdf']=None
32 basefragment_settings['alternative_pdfs']=None
33 basefragment_settings['pdf_variations']=None
34 basefragment_settings['scale_variations']=None
35 basefragment_settings['alternative_dynamic_scales']=None
36 for s in basefragment_settings:
37 if s in the_base_fragment:
38 if isinstance(basefragment_settings[s],list) and len(basefragment_settings[s])==0:
39 continue
40 basefragment_settings[s]=the_base_fragment[s]
41 else:
42 if s=='central_pdf':
43 raise RuntimeError('No "central_pdf" configured in base fragment')
44 if s=='alternative_dynamic_scales':
45 continue
46 mgsyslog.warning('base fragment or pdf settings does not define "'+s+'"')
47
48
49 for s in basefragment_settings:
50 if s=='central_pdf':
51 if not isinstance(basefragment_settings[s],int):
52 raise RuntimeError(s+', configured in base fragment, has to be an integer')
53 continue
54 if basefragment_settings[s] is None:
55 continue
56 if s=='scale_variations':
57 if not isinstance(basefragment_settings[s],list):
58 raise RuntimeError(s+', configured in base fragment, has to be a list of numbers')
59 for pdf in basefragment_settings[s]:
60 if not isinstance(pdf,float) and not isinstance(pdf,int):
61 raise RuntimeError(s+', configured in base fragment, has to be a list of numbers')
62 else:
63 if not isinstance(basefragment_settings[s],list):
64 raise RuntimeError(s+', configured in base fragment, has to be a list of integers')
65 for element in basefragment_settings[s]:
66 if not isinstance(element,int) or not element>0:
67 raise RuntimeError(s+', configured in base fragment, has to be a list of positive integers')
68
69
70 if basefragment_settings['alternative_pdfs'] is not None:
71 # if a PDF set is included as variation (i.e. nominal + error pdf) there is no need to have it as alternative pdf (i.e. only nominal)
72 if basefragment_settings['pdf_variations'] is not None:
73 basefragment_settings['alternative_pdfs']=[ a for a in basefragment_settings['alternative_pdfs'] if a not in basefragment_settings['pdf_variations'] ]
74 # the central pdf does not need to be included as alternative PDF
75 if basefragment_settings['central_pdf'] in basefragment_settings['alternative_pdfs']:
76 basefragment_settings['alternative_pdfs'].remove(basefragment_settings['central_pdf'])
77
78
79 runcard_settings['pdlabel']='lhapdf'
80 runcard_settings['lhaid']=str(basefragment_settings['central_pdf'])
81
82 # turn on LO systematics and use new systematics script
83 if not useNLOotf:
84 if basefragment_settings['alternative_dynamic_scales'] is not None:
85 runcard_systematics_arguments['weight_info']=SYSTEMATICS_WEIGHT_INFO_ALTDYNSCALES
86 else:
87 runcard_systematics_arguments['weight_info']=SYSTEMATICS_WEIGHT_INFO
88 runcard_systematics_arguments['remove_wgts']='".*MUR0.5_MUF2.0.*|.*MUR2.0_MUF0.5.*"'
89
90 runcard_settings['systematics_program']='none'
91 for s in ['alternative_pdfs','pdf_variations','scale_variations']:
92 if basefragment_settings[s] is not None and len(basefragment_settings[s])>0:
93 # set use_syst true if some variations are used
94 if isNLO:
95 runcard_settings['store_rwgt_info']='True'
96 else:
97 runcard_settings['use_syst']='True'
98 # use the MadGraph systematics program != syscalc
99 runcard_settings['systematics_program']='systematics'
100 break
101
102
103 if useNLOotf:
104 # pdf weights with NLO syntax
105 if basefragment_settings['pdf_variations'] is not None and basefragment_settings['central_pdf'] in basefragment_settings['pdf_variations']:
106 runcard_settings['reweight_PDF']='True'
107 else:
108 runcard_settings['reweight_PDF']='False'
109 if basefragment_settings['pdf_variations'] is not None:
110 for v in basefragment_settings['pdf_variations']:
111 if v==basefragment_settings['central_pdf']:
112 continue
113 runcard_settings['lhaid']+=' '+str(v)
114 runcard_settings['reweight_PDF']+=' True'
115 if basefragment_settings['alternative_pdfs'] is not None:
116 for a in basefragment_settings['alternative_pdfs']:
117 runcard_settings['lhaid']+=' '+str(a)
118 runcard_settings['reweight_PDF']+=' False'
119
120 else: #use the new python systematics module
121 sys_pdfs=[]
122 if basefragment_settings['pdf_variations'] is not None:
123 for v in basefragment_settings['pdf_variations']:
124 sys_pdfs.append(get_lhapdf_id_and_name(v)[1])
125 if basefragment_settings['alternative_pdfs'] is not None:
126 for a in basefragment_settings['alternative_pdfs']:
127 sys_pdfs.append(get_lhapdf_id_and_name(a)[1]+'@0')
128 if len(sys_pdfs)>0:
129 runcard_systematics_arguments['pdf']=','.join(sys_pdfs)
130 if isNLO:
131 runcard_settings['reweight_PDF']='False'
132
133
134
135 if basefragment_settings['scale_variations'] is None and isNLO:
136 runcard_settings['reweight_scale']='False'
137 if basefragment_settings['scale_variations'] is not None:
138 if useNLOotf:
139 runcard_settings['reweight_scale']='True'
140 runcard_settings['rw_rscale']=' '.join([str(s) for s in basefragment_settings['scale_variations']])
141 runcard_settings['rw_fscale']=' '.join([str(s) for s in basefragment_settings['scale_variations']])
142 else:
143 runcard_systematics_arguments['muf']=','.join([str(s) for s in basefragment_settings['scale_variations']])
144 runcard_systematics_arguments['mur']=','.join([str(s) for s in basefragment_settings['scale_variations']])
145 runcard_systematics_arguments['dyn']='-1'
146 if isNLO:
147 runcard_settings['reweight_scale']='False'
148
149 if basefragment_settings['alternative_dynamic_scales'] is not None:
150 if useNLOotf:
151 raise RuntimeError('Cannot reweight to alternative dynamic scales using the NLO OTF module')
152 else:
153 runcard_systematics_arguments['dyn']=','.join([str(s) for s in [-1]+basefragment_settings['alternative_dynamic_scales']])
154
155 if not useNLOotf:
156 runcard_settings['systematics_arguments']=write_systematics_arguments(runcard_systematics_arguments)
157
158 return runcard_settings
159
160
161#==================================================================================
162# convert settings from the syscalc syntax to the new systematics syntax which is steered via "systematics_arguments"
163# will modify the dict and also return new setting

◆ parse_systematics_argument()

python.MadGraphSystematicsUtils.parse_systematics_argument ( sys_arg)

Definition at line 223 of file MadGraphSystematicsUtils.py.

223def parse_systematics_argument(sys_arg):
224 spl=sys_arg.strip().split('=')
225 return (spl[0].strip()[2:],spl[1].strip())
226
227#==================================================================================
228# these arguments steer systematics

◆ parse_systematics_arguments()

python.MadGraphSystematicsUtils.parse_systematics_arguments ( sys_args)

Definition at line 211 of file MadGraphSystematicsUtils.py.

211def parse_systematics_arguments(sys_args):
212 parsed={}
213 if sys_args.strip().startswith('['):
214 argument_list = ast.literal_eval(sys_args)
215 for a in argument_list:
216 key,value=parse_systematics_argument(a)
217 parsed[key]=value
218 else:
219 arg=sys_args.replace("'",'').replace('"','')
220 key,value=parse_systematics_argument(arg)
221 return parsed
222
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310

◆ systematics_run_card_options()

python.MadGraphSystematicsUtils.systematics_run_card_options ( isNLO)

Definition at line 229 of file MadGraphSystematicsUtils.py.

229def systematics_run_card_options(isNLO):
230 if isNLO:
231 return ['pdlabel','lhaid','reweight_PDF','reweight_scale','rw_rscale','rw_fscale','store_rwgt_info','systematics_arguments' ]
232 else:
233 return ['pdlabel','lhaid','use_syst','sys_scalefact','sys_pdf','systematics_arguments']

◆ write_systematics_arguments()

python.MadGraphSystematicsUtils.write_systematics_arguments ( systematics_arguments)

Definition at line 206 of file MadGraphSystematicsUtils.py.

206def write_systematics_arguments(systematics_arguments):
207 return '['+','.join(["'--"+k+"="+systematics_arguments[k]+"'" for k in systematics_arguments])+']'
208
209#==================================================================================
210# create a map from the 'systematics_arguments' run card argument

Variable Documentation

◆ mgsyslog

python.MadGraphSystematicsUtils.mgsyslog = Logging.logging.getLogger('MadGraphSysUtils')

Definition at line 10 of file MadGraphSystematicsUtils.py.

◆ SYSTEMATICS_WEIGHT_INFO

str python.MadGraphSystematicsUtils.SYSTEMATICS_WEIGHT_INFO = "MUR%(mur).1f_MUF%(muf).1f_PDF%(pdf)i"

Definition at line 12 of file MadGraphSystematicsUtils.py.

◆ SYSTEMATICS_WEIGHT_INFO_ALTDYNSCALES

str python.MadGraphSystematicsUtils.SYSTEMATICS_WEIGHT_INFO_ALTDYNSCALES = "MUR%(mur).1f_MUF%(muf).1f_DYNSCALE%(dyn)i_PDF%(pdf)i"

Definition at line 13 of file MadGraphSystematicsUtils.py.