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

Constructor & Destructor Documentation

◆ __init__()

python.AsgAnalysisConfig.PileupReweightingBlock.__init__ ( self)

Definition at line 202 of file AsgAnalysisConfig.py.

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

Member Function Documentation

◆ instanceName()

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

Definition at line 240 of file AsgAnalysisConfig.py.

240 def instanceName (self) :
241 """Return the instance name for this block"""
242 return self.postfix
243

◆ makeAlgs()

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

Definition at line 244 of file AsgAnalysisConfig.py.

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

Member Data Documentation

◆ alternativeConfig

python.AsgAnalysisConfig.PileupReweightingBlock.alternativeConfig

Definition at line 262 of file AsgAnalysisConfig.py.

◆ files

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

Definition at line 276 of file AsgAnalysisConfig.py.

◆ postfix

python.AsgAnalysisConfig.PileupReweightingBlock.postfix

Definition at line 398 of file AsgAnalysisConfig.py.

◆ useDefaultConfig

python.AsgAnalysisConfig.PileupReweightingBlock.useDefaultConfig

Definition at line 335 of file AsgAnalysisConfig.py.

◆ writeColumnarToolVariables

python.AsgAnalysisConfig.PileupReweightingBlock.writeColumnarToolVariables

Definition at line 256 of file AsgAnalysisConfig.py.


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