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

Member Data Documentation

◆ alternativeConfig

python.AsgAnalysisConfig.PileupReweightingBlock.alternativeConfig

Definition at line 257 of file AsgAnalysisConfig.py.

◆ files

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

Definition at line 271 of file AsgAnalysisConfig.py.

◆ postfix

python.AsgAnalysisConfig.PileupReweightingBlock.postfix

Definition at line 392 of file AsgAnalysisConfig.py.

◆ useDefaultConfig

python.AsgAnalysisConfig.PileupReweightingBlock.useDefaultConfig

Definition at line 329 of file AsgAnalysisConfig.py.

◆ writeColumnarToolVariables

python.AsgAnalysisConfig.PileupReweightingBlock.writeColumnarToolVariables

Definition at line 251 of file AsgAnalysisConfig.py.


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