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 197 of file AsgAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.AsgAnalysisConfig.PileupReweightingBlock.__init__ ( self)

Definition at line 200 of file AsgAnalysisConfig.py.

200 def __init__ (self) :
201 super (PileupReweightingBlock, self).__init__ ()
202 self.addOption ('campaign', None, type=None,
203 info="the MC campaign for the PRW auto-configuration.")
204 self.addOption ('files', None, type=list,
205 info="the input files being processed (list of strings). "
206 "Alternative to auto-configuration.")
207 self.addOption ('useDefaultConfig', True, type=bool,
208 info="whether to use the central PRW files.")
209 self.addOption ('userLumicalcFiles', None, type=list,
210 info="user-provided lumicalc files (list of strings). Alternative "
211 "to auto-configuration.")
212 self.addOption ('userLumicalcFilesPerCampaign', None, type=dict,
213 info="user-provided lumicalc files (dictionary of list of strings, "
214 "with MC campaigns as the keys). Alternative to auto-configuration.")
215 self.addOption ('userPileupConfigs', None, type=list,
216 info="user-provided PRW files (list of strings). Alternative to "
217 "auto-configuration.")
218 self.addOption ('userPileupConfigsPerCampaign', None, type=dict,
219 info="user-provided PRW files (dictionary of list of strings, with "
220 "MC campaigns as the keys).")
221 self.addOption ('postfix', '', type=str,
222 info="a postfix to apply to decorations and algorithm names. "
223 "Typically not needed unless several instances of `PileupReweighting` are scheduled.")
224 self.addOption ('alternativeConfig', False, type=bool,
225 info="whether this is used as an additional alternative config for `PileupReweighting`. "
226 "Will only store the alternative pileup weight in that case.")
227 self.addOption ('unrepresentedDataWarningThreshold', 1e-4, type=float,
228 info="suppress the unrepresented-data WARNING when the unrepresented "
229 "fraction is below this value (default 0.01%). Set to 0 to always "
230 "warn.")
231 self.addOption ('writeColumnarToolVariables', False, type=bool,
232 info="whether to add `EventInfo` variables needed for running the columnar tool(s) on the output n-tuple. (EXPERIMENTAL).",
233 expertMode=True)
234

Member Function Documentation

◆ instanceName()

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

Definition at line 235 of file AsgAnalysisConfig.py.

235 def instanceName (self) :
236 """Return the instance name for this block"""
237 return self.postfix
238

◆ makeAlgs()

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

Definition at line 239 of file AsgAnalysisConfig.py.

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

Member Data Documentation

◆ alternativeConfig

python.AsgAnalysisConfig.PileupReweightingBlock.alternativeConfig

Definition at line 254 of file AsgAnalysisConfig.py.

◆ files

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

Definition at line 268 of file AsgAnalysisConfig.py.

◆ postfix

python.AsgAnalysisConfig.PileupReweightingBlock.postfix

Definition at line 389 of file AsgAnalysisConfig.py.

◆ useDefaultConfig

python.AsgAnalysisConfig.PileupReweightingBlock.useDefaultConfig

Definition at line 326 of file AsgAnalysisConfig.py.

◆ writeColumnarToolVariables

python.AsgAnalysisConfig.PileupReweightingBlock.writeColumnarToolVariables

Definition at line 248 of file AsgAnalysisConfig.py.


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