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

Member Function Documentation

◆ instanceName()

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

Definition at line 238 of file AsgAnalysisConfig.py.

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

◆ makeAlgs()

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

Definition at line 242 of file AsgAnalysisConfig.py.

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

Member Data Documentation

◆ alternativeConfig

python.AsgAnalysisConfig.PileupReweightingBlock.alternativeConfig

Definition at line 260 of file AsgAnalysisConfig.py.

◆ files

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

Definition at line 274 of file AsgAnalysisConfig.py.

◆ postfix

python.AsgAnalysisConfig.PileupReweightingBlock.postfix

Definition at line 396 of file AsgAnalysisConfig.py.

◆ useDefaultConfig

python.AsgAnalysisConfig.PileupReweightingBlock.useDefaultConfig

Definition at line 333 of file AsgAnalysisConfig.py.

◆ writeColumnarToolVariables

python.AsgAnalysisConfig.PileupReweightingBlock.writeColumnarToolVariables

Definition at line 254 of file AsgAnalysisConfig.py.


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