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

Constructor & Destructor Documentation

◆ __init__()

python.AsgAnalysisConfig.PileupReweightingBlock.__init__ ( self)

Definition at line 190 of file AsgAnalysisConfig.py.

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

Member Function Documentation

◆ instanceName()

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

Definition at line 221 of file AsgAnalysisConfig.py.

221 def instanceName (self) :
222 """Return the instance name for this block"""
223 return self.postfix
224

◆ makeAlgs()

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

Definition at line 225 of file AsgAnalysisConfig.py.

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

Member Data Documentation

◆ alternativeConfig

python.AsgAnalysisConfig.PileupReweightingBlock.alternativeConfig

Definition at line 240 of file AsgAnalysisConfig.py.

◆ files

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

Definition at line 254 of file AsgAnalysisConfig.py.

◆ postfix

python.AsgAnalysisConfig.PileupReweightingBlock.postfix

Definition at line 371 of file AsgAnalysisConfig.py.

◆ useDefaultConfig

python.AsgAnalysisConfig.PileupReweightingBlock.useDefaultConfig

Definition at line 312 of file AsgAnalysisConfig.py.

◆ writeColumnarToolVariables

python.AsgAnalysisConfig.PileupReweightingBlock.writeColumnarToolVariables

Definition at line 234 of file AsgAnalysisConfig.py.


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