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

Constructor & Destructor Documentation

◆ __init__()

python.AsgAnalysisConfig.PileupReweightingBlock.__init__ ( self)

Definition at line 198 of file AsgAnalysisConfig.py.

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

Member Function Documentation

◆ instanceName()

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

Definition at line 229 of file AsgAnalysisConfig.py.

229 def instanceName (self) :
230 """Return the instance name for this block"""
231 return self.postfix
232

◆ makeAlgs()

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

Definition at line 233 of file AsgAnalysisConfig.py.

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

Member Data Documentation

◆ alternativeConfig

python.AsgAnalysisConfig.PileupReweightingBlock.alternativeConfig

Definition at line 248 of file AsgAnalysisConfig.py.

◆ files

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

Definition at line 262 of file AsgAnalysisConfig.py.

◆ postfix

python.AsgAnalysisConfig.PileupReweightingBlock.postfix

Definition at line 379 of file AsgAnalysisConfig.py.

◆ useDefaultConfig

python.AsgAnalysisConfig.PileupReweightingBlock.useDefaultConfig

Definition at line 320 of file AsgAnalysisConfig.py.

◆ writeColumnarToolVariables

python.AsgAnalysisConfig.PileupReweightingBlock.writeColumnarToolVariables

Definition at line 242 of file AsgAnalysisConfig.py.


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