ATLAS Offline Software
Loading...
Searching...
No Matches
python.AsgAnalysisConfig.PileupReweightingBlock Class Reference
Inheritance diagram for python.AsgAnalysisConfig.PileupReweightingBlock:
Collaboration diagram for python.AsgAnalysisConfig.PileupReweightingBlock:

Public Member Functions

 __init__ (self)
 instanceName (self)
 makeAlgs (self, config)

Public Attributes

 writeColumnarToolVariables
 alternativeConfig
 files = config.flags.Input.Files
 useDefaultConfig
 postfix

Detailed Description

the ConfigBlock for pileup reweighting

Definition at line 185 of file AsgAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.AsgAnalysisConfig.PileupReweightingBlock.__init__ ( self)

Definition at line 188 of file AsgAnalysisConfig.py.

188 def __init__ (self) :
189 super (PileupReweightingBlock, self).__init__ ()
190 self.addOption ('campaign', None, type=None,
191 info="the MC campaign for the PRW auto-configuration.")
192 self.addOption ('files', None, type=None,
193 info="the input files being processed (list of strings). "
194 "Alternative to auto-configuration.")
195 self.addOption ('useDefaultConfig', True, type=bool,
196 info="whether to use the central PRW files. The default is True.")
197 self.addOption ('userLumicalcFiles', None, type=None,
198 info="user-provided lumicalc files (list of strings). Alternative "
199 "to auto-configuration.")
200 self.addOption ('userLumicalcFilesPerCampaign', None, type=None,
201 info="user-provided lumicalc files (dictionary of list of strings, "
202 "with MC campaigns as the keys). Alternative to auto-configuration.")
203 self.addOption ('userPileupConfigs', None, type=None,
204 info="user-provided PRW files (list of strings). Alternative to "
205 "auto-configuration. Alternative to auto-configuration.")
206 self.addOption ('userPileupConfigsPerCampaign', None, type=None,
207 info="user-provided PRW files (dictionary of list of strings, with "
208 "MC campaigns as the keys)")
209 self.addOption ('postfix', '', type=str,
210 info="a postfix to apply to decorations and algorithm names. "
211 "Typically not needed unless several instances of PileupReweighting are scheduled.")
212 self.addOption ('alternativeConfig', False, type=bool,
213 info="whether this is used as an additional alternative config for PileupReweighting. "
214 "Will only store the alternative pile up weight in that case.")
215 self.addOption ('writeColumnarToolVariables', False, type=bool,
216 info="whether to add EventInfo variables needed for running the columnar tool(s) on the output n-tuple. (EXPERIMENTAL)",
217 expertMode=True)
218

Member Function Documentation

◆ instanceName()

python.AsgAnalysisConfig.PileupReweightingBlock.instanceName ( self)
Return the instance name for this block

Definition at line 219 of file AsgAnalysisConfig.py.

219 def instanceName (self) :
220 """Return the instance name for this block"""
221 return self.postfix
222

◆ makeAlgs()

python.AsgAnalysisConfig.PileupReweightingBlock.makeAlgs ( self,
config )

Definition at line 223 of file AsgAnalysisConfig.py.

223 def makeAlgs (self, config) :
224
225 from Campaigns.Utils import Campaign
226
227 log = logging.getLogger('makePileupAnalysisSequence')
228
229 eventInfoVar = ['runNumber', 'eventNumber', 'actualInteractionsPerCrossing', 'averageInteractionsPerCrossing']
230 if config.dataType() is not DataType.Data:
231 eventInfoVar += ['mcChannelNumber']
232 if self.writeColumnarToolVariables:
233 # This is not strictly necessary, as the columnar users
234 # could recreate this, but it is also a single constant int,
235 # that should compress exceedingly well.
236 eventInfoVar += ['eventTypeBitmask']
237
238 if config.isPhyslite() and not self.alternativeConfig:
239 # PHYSLITE already has these variables defined, just need to copy them to the output
240 log.info(f'Physlite does not need pileup reweighting. Variables will be copied from input instead. {config.isPhyslite}')
241 for var in eventInfoVar:
242 config.addOutputVar ('EventInfo', var, var, noSys=True)
243
244 if config.dataType() is not DataType.Data:
245 config.addOutputVar ('EventInfo', 'PileupWeight_%SYS%', 'weight_pileup')
246 if config.geometry() is LHCPeriod.Run2:
247 config.addOutputVar ('EventInfo', 'beamSpotWeight', 'weight_beamspot', noSys=True)
248 return
249
250 # check files from flags
251 if self.files is None and config.flags is not None:
252 self.files = config.flags.Input.Files
253
254 campaign = self.campaign
255 # if user didn't explicitly configure campaign, let's try setting it from metadata
256 # only needed on MC
257 if config.dataType() is not DataType.Data and self.campaign is None:
258 # if we used flags, campaign is auto-determined
259 if config.campaign() is not None and config.campaign() is not Campaign.Unknown:
260 campaign = config.campaign()
261 log.info(f'Auto-configuring campaign for PRW from flags: {campaign.value}')
262 else:
263 # we try to determine campaign from files if above failed
264 if self.files is not None:
265 from Campaigns.Utils import getMCCampaign
266 campaign = getMCCampaign(self.files)
267 if campaign and campaign is not Campaign.Unknown:
268 log.info(f'Auto-configuring campaign for PRW from files: {campaign.value}')
269 else:
270 log.info('Campaign could not be determined.')
271
272
273 toolConfigFiles = []
274 toolLumicalcFiles = []
275
276 # PRW config files should only be configured if we run on MC
277 # Run 4 not supported yet
278 if (config.dataType() is not DataType.Data and
279 config.geometry() is not LHCPeriod.Run4):
280 # check if user provides per-campaign pileup config list
281 if self.userPileupConfigs is not None and self.userPileupConfigsPerCampaign is not None:
282 raise ValueError('Both userPileupConfigs and userPileupConfigsPerCampaign specified, '
283 'use only one of the options!')
284 if self.userPileupConfigsPerCampaign is not None:
285 if not campaign:
286 raise Exception('userPileupConfigsPerCampaign requires campaign to be configured!')
287 if campaign is Campaign.Unknown:
288 raise Exception('userPileupConfigsPerCampaign used, but campaign = Unknown!')
289 try:
290 toolConfigFiles = self.userPileupConfigsPerCampaign[campaign.value][:]
291 log.info('Using user provided per-campaign PRW configuration')
292 except KeyError as e:
293 raise KeyError(f'Unconfigured campaign {e} for userPileupConfigsPerCampaign!')
294
295 elif self.userPileupConfigs is not None:
296 toolConfigFiles = self.userPileupConfigs[:]
297 log.info('Using user provided PRW configuration')
298
299 else:
300 if self.useDefaultConfig and self.files is None:
301 raise ValueError('useDefaultConfig requires files to be configured! '
302 'Either pass them as an option or use flags.')
303
304 from PileupReweighting.AutoconfigurePRW import getConfigurationFiles
305 if campaign and campaign is not Campaign.Unknown:
306 toolConfigFiles = getConfigurationFiles(campaign=campaign,
307 files=self.files,
308 useDefaultConfig=self.useDefaultConfig,
309 data_type=config.dataType())
310 if self.useDefaultConfig:
311 log.info('Auto-configuring universal/default PRW config')
312 else:
313 log.info('Auto-configuring per-sample PRW config files based on input files')
314 else:
315 log.info('No campaign specified, no PRW config files configured')
316
317 # check if user provides per-campaign lumical config list
318 if self.userLumicalcFilesPerCampaign is not None and self.userLumicalcFiles is not None:
319 raise ValueError('Both userLumicalcFiles and userLumicalcFilesYear specified, '
320 'use only one of the options!')
321 if self.userLumicalcFilesPerCampaign is not None:
322 try:
323 toolLumicalcFiles = self.userLumicalcFilesPerCampaign[campaign.value][:]
324 log.info('Using user-provided per-campaign lumicalc files')
325 except KeyError as e:
326 raise KeyError(f'Unconfigured campaign {e} for userLumicalcFilesPerCampaign!')
327 elif self.userLumicalcFiles is not None:
328 toolLumicalcFiles = self.userLumicalcFiles[:]
329 log.info('Using user-provided lumicalc files')
330 else:
331 if campaign and campaign is not Campaign.Unknown:
332 from PileupReweighting.AutoconfigurePRW import getLumicalcFiles
333 toolLumicalcFiles = getLumicalcFiles(campaign)
334 log.info('Using auto-configured lumicalc files')
335 else:
336 log.info('No campaign specified, no lumicalc files configured for PRW')
337 else:
338 log.info('Data needs no lumicalc and PRW configuration files')
339
340 # Set up the only algorithm of the sequence:
341 if config.geometry() is LHCPeriod.Run4:
342 log.warning ('Pileup reweighting is not yet supported for Run 4 geometry')
343 alg = config.createAlgorithm( 'CP::EventDecoratorAlg', 'EventDecoratorAlg' )
344 alg.uint32Decorations = { 'RandomRunNumber' :
345 config.flags.Input.RunNumbers[0] }
346
347 else:
348 alg = config.createAlgorithm( 'CP::PileupReweightingAlg',
349 'PileupReweightingAlg' )
350 config.addPrivateTool( 'pileupReweightingTool', 'CP::PileupReweightingTool' )
351 alg.pileupReweightingTool.ConfigFiles = toolConfigFiles
352 if not toolConfigFiles and config.dataType() is not DataType.Data:
353 log.info("No PRW config files provided. Disabling reweighting")
354 # Setting the weight decoration to the empty string disables the reweighting
355 alg.pileupWeightDecoration = ""
356 else:
357 alg.pileupWeightDecoration = "PileupWeight" + self.postfix + "_%SYS%"
358 alg.pileupReweightingTool.LumiCalcFiles = toolLumicalcFiles
359
360 if not self.alternativeConfig:
361 for var in eventInfoVar:
362 config.addOutputVar ('EventInfo', var, var, noSys=True)
363
364 if config.dataType() is not DataType.Data and config.geometry() is LHCPeriod.Run2:
365 config.addOutputVar ('EventInfo', 'beamSpotWeight', 'weight_beamspot', noSys=True)
366
367 if config.dataType() is not DataType.Data and toolConfigFiles:
368 config.addOutputVar ('EventInfo', 'PileupWeight' + self.postfix + '_%SYS%',
369 'weight_pileup'+self.postfix)
370
371

Member Data Documentation

◆ alternativeConfig

python.AsgAnalysisConfig.PileupReweightingBlock.alternativeConfig

Definition at line 238 of file AsgAnalysisConfig.py.

◆ files

python.AsgAnalysisConfig.PileupReweightingBlock.files = config.flags.Input.Files

Definition at line 252 of file AsgAnalysisConfig.py.

◆ postfix

python.AsgAnalysisConfig.PileupReweightingBlock.postfix

Definition at line 369 of file AsgAnalysisConfig.py.

◆ useDefaultConfig

python.AsgAnalysisConfig.PileupReweightingBlock.useDefaultConfig

Definition at line 310 of file AsgAnalysisConfig.py.

◆ writeColumnarToolVariables

python.AsgAnalysisConfig.PileupReweightingBlock.writeColumnarToolVariables

Definition at line 232 of file AsgAnalysisConfig.py.


The documentation for this class was generated from the following file: