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
 writeDetailedPileupValues
 files = config.flags.Input.Files
 useDefaultConfig

Detailed Description

the ConfigBlock for pileup reweighting

Definition at line 213 of file AsgAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.AsgAnalysisConfig.PileupReweightingBlock.__init__ ( self)

Definition at line 216 of file AsgAnalysisConfig.py.

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

Member Function Documentation

◆ instanceName()

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

Definition at line 256 of file AsgAnalysisConfig.py.

256 def instanceName (self) :
257 """Return the instance name for this block"""
258 return self.postfix
259

◆ makeAlgs()

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

Definition at line 260 of file AsgAnalysisConfig.py.

260 def makeAlgs (self, config) :
261
262 from Campaigns.Utils import Campaign
263
264 log = logging.getLogger("makePileupAnalysisSequence")
265
266 eventInfoVar = [
267 ("runNumber", "unsigned"),
268 ("eventNumber", "unsigned_long"),
269 ]
270 if config.dataType() is not DataType.Data:
271 eventInfoVar.extend([
272 ("mcChannelNumber", "unsigned"),
273 ])
274 # for now still write the average and actual pileup values until the new p-tag is available
275 eventInfoVar.extend([
276 ("averageInteractionsPerCrossing", "float"),
277 ("actualInteractionsPerCrossing", "float"),
278 ])
279 if self.writeColumnarToolVariables:
280 # This is not strictly necessary, as the columnar users
281 # could recreate this, but it is also a single constant int,
282 # that should compress exceedingly well.
283 eventInfoVar.extend([
284 ("eventTypeBitmask", "int"),
285 ])
286
287 if config.isPhyslite() and not self.alternativeConfig:
288 # PHYSLITE already has these variables defined, just need to copy them to the output
289 log.info("Physlite does not need pileup reweighting. Variables will be copied from input instead.")
290 if self.writeDetailedPileupValues:
291 log.warning("writeDetailedPileupValues is set to True, but Physlite does not have these variables. They will not be written to the output.")
292
293 eventInfoVar.extend([
294 ("correctedScaledInteractionsPerCrossing", "float"),
295 ])
296 for var_name, var_type in eventInfoVar:
297 config.addOutputVar("EventInfo", var_name, var_name, noSys=True, auxType=var_type)
298
299 if config.dataType() is not DataType.Data:
300 config.addOutputVar("EventInfo", "PileupWeight_%SYS%", "weight_pileup", auxType="float")
301 if config.geometry() is LHCPeriod.Run2:
302 config.addOutputVar("EventInfo", "beamSpotWeight", "weight_beamspot", noSys=True, auxType="float")
303 return
304
305 # check files from flags
306 if self.files is None and config.flags is not None:
307 self.files = config.flags.Input.Files
308
309 campaign = self.campaign
310 # if user didn't explicitly configure campaign, let's try setting it from metadata
311 if self.campaign is None:
312 # if we used flags, campaign is auto-determined
313 if config.campaign() is not None and config.campaign() is not Campaign.Unknown:
314 campaign = config.campaign()
315 log.info("Auto-configuring campaign for PRW from flags: %s", campaign.value)
316 elif config.dataType() is DataType.Data:
317 log.info("Inferring campaign from data year: %d", config.dataYear())
318 campaign = {
319 2015: Campaign.MC20a,
320 2016: Campaign.MC20a,
321 2017: Campaign.MC20d,
322 2018: Campaign.MC20e,
323 2022: Campaign.MC23a,
324 2023: Campaign.MC23d,
325 2024: Campaign.MC23e,
326 2025: Campaign.MC23g,
327 2026: Campaign.MC23g,
328 }.get(config.dataYear(), Campaign.Unknown)
329 else:
330 # we try to determine campaign from files if above failed
331 if self.files is not None:
332 from Campaigns.Utils import getMCCampaign
333 campaign = getMCCampaign(self.files)
334 if campaign and campaign is not Campaign.Unknown:
335 log.info("Auto-configuring campaign for PRW from files: %s", campaign.value)
336 else:
337 log.info("Campaign could not be determined.")
338
339
340 toolConfigFiles = []
341 toolLumicalcFiles = []
342
343 # PRW config files should only be configured if we run on MC
344 # Run 4 not supported yet
345 if (config.dataType() is not DataType.Data and
346 config.geometry() is not LHCPeriod.Run4):
347 # check if user provides per-campaign pileup config list
348 if self.userPileupConfigs is not None and self.userPileupConfigsPerCampaign is not None:
349 raise ValueError("Both userPileupConfigs and userPileupConfigsPerCampaign specified,"
350 " use only one of the options!")
351 if self.userPileupConfigsPerCampaign is not None:
352 if not campaign:
353 raise Exception("userPileupConfigsPerCampaign requires campaign to be configured!")
354 if campaign is Campaign.Unknown:
355 raise Exception("userPileupConfigsPerCampaign used, but campaign = Unknown!")
356 try:
357 toolConfigFiles = self.userPileupConfigsPerCampaign[campaign.value][:]
358 log.info("Using user provided per-campaign PRW configuration")
359 except KeyError as e:
360 raise KeyError(f"Unconfigured campaign {e} for userPileupConfigsPerCampaign!")
361
362 elif self.userPileupConfigs is not None:
363 toolConfigFiles = self.userPileupConfigs[:]
364 log.info("Using user provided PRW configuration")
365
366 else:
367 if self.useDefaultConfig and self.files is None:
368 raise ValueError("useDefaultConfig requires files to be configured!"
369 " Either pass them as an option or use flags.")
370
371 from PileupReweighting.AutoconfigurePRW import getConfigurationFiles
372 if campaign and campaign is not Campaign.Unknown:
373 toolConfigFiles = getConfigurationFiles(campaign=campaign,
374 files=self.files,
375 useDefaultConfig=self.useDefaultConfig,
376 data_type=config.dataType(),
377 GRLSuffixDict=self.GRLSuffixDict)
378 if self.useDefaultConfig:
379 log.info("Auto-configuring universal/default PRW config")
380 else:
381 log.info("Auto-configuring per-sample PRW config files based on input files")
382 else:
383 log.info("No campaign specified, no PRW config files configured")
384
385
386 # check if user provides per-campaign lumical config list
387 if self.userLumicalcFilesPerCampaign is not None and self.userLumicalcFiles is not None:
388 raise ValueError("Both userLumicalcFiles and userLumicalcFilesPerCampaign specified,"
389 " use only one of the options!")
390 if self.userLumicalcFilesPerCampaign is not None:
391 if not campaign:
392 raise Exception('userLumicalcFilesPerCampaign requires campaign to be configured!')
393 if campaign is Campaign.Unknown:
394 raise Exception('userLumicalcFilesPerCampaign used, but campaign = Unknown!')
395 try:
396 toolLumicalcFiles = self.userLumicalcFilesPerCampaign[campaign.value][:]
397 log.info("Using user-provided per-campaign lumicalc files")
398 except KeyError as e:
399 raise KeyError(f"Unconfigured campaign {e} for userLumicalcFilesPerCampaign!")
400 elif self.userLumicalcFiles is not None:
401 toolLumicalcFiles = self.userLumicalcFiles[:]
402 log.info("Using user-provided lumicalc files")
403 else:
404 if campaign and campaign not in {Campaign.Unknown, Campaign.PhaseII}:
405 from PileupReweighting.AutoconfigurePRW import getLumicalcFiles
406 toolLumicalcFiles = getLumicalcFiles(campaign, self.GRLSuffixDict)
407 log.info("Using auto-configured lumicalc files")
408 else:
409 log.info("No campaign specified, no lumicalc files configured for PRW")
410
411 # Set up the only algorithm of the sequence:
412 if config.geometry() is LHCPeriod.Run4:
413 warnings.warn_explicit(
414 "Pileup reweighting is not yet supported for Run 4 geometry",
415 Run4FallbackWarning, filename="", lineno=0)
416 alg = config.createAlgorithm("CP::EventDecoratorAlg", "EventDecoratorAlg")
417 alg.uint32Decorations = {
418 "RandomRunNumber": config.flags.Input.RunNumbers[0]
419 }
420
421 else:
422 alg = config.createAlgorithm("CP::PileupReweightingAlg", "PileupReweightingAlg")
423 config.addPrivateTool("pileupReweightingTool", "CP::PileupReweightingTool")
424 alg.pileupReweightingTool.ConfigFiles = toolConfigFiles
425 if not toolConfigFiles and config.dataType() is not DataType.Data:
426 log.info("No PRW config files provided. Disabling reweighting")
427 # Setting the weight decoration to the empty string disables the reweighting
428 alg.pileupWeightDecoration = ""
429 else:
430 alg.pileupWeightDecoration = f"PileupWeight{self.postfix}_%SYS%"
431 alg.pileupReweightingTool.LumiCalcFiles = toolLumicalcFiles
432 alg.pileupReweightingTool.UnrepresentedDataWarningThreshold = (
433 self.unrepresentedDataWarningThreshold)
434
435 # pile-up values
436 if not self.alternativeConfig:
437 if self.writeDetailedPileupValues:
438 alg.correctedScaledAverageMuDecoration = "correctedScaledAverageInteractionsPerCrossing"
439 alg.correctedScaledActualMuDecoration = "correctedScaledActualInteractionsPerCrossing"
440 alg.correctedAverageMuDecoration = "correctedUnscaledAverageInteractionsPerCrossing"
441 alg.correctedActualMuDecoration = "correctedUnscaledActualInteractionsPerCrossing"
442
443 eventInfoVar.extend([
444 ("correctedScaledAverageInteractionsPerCrossing", "float"),
445 ("correctedScaledActualInteractionsPerCrossing", "float"),
446 ("correctedUnscaledAverageInteractionsPerCrossing", "float"),
447 ("correctedUnscaledActualInteractionsPerCrossing", "float"),
448 ])
449
450 if campaign is Campaign.MC20a:
451 config.addOutputVar("EventInfo", "correctedScaledAverageInteractionsPerCrossing", "correctedScaledInteractionsPerCrossing", noSys=True, auxType="float")
452 elif campaign >= Campaign.MC20d and config.geometry() is not LHCPeriod.Run4:
453 config.addOutputVar("EventInfo", "correctedScaledActualInteractionsPerCrossing", "correctedScaledInteractionsPerCrossing", noSys=True, auxType="float")
454 else:
455 if campaign is Campaign.MC20a:
456 alg.correctedScaledAverageMuDecoration = "correctedScaledInteractionsPerCrossing"
457 elif campaign >= Campaign.MC20d:
458 alg.correctedScaledActualMuDecoration = "correctedScaledInteractionsPerCrossing"
459 eventInfoVar.extend([
460 ("correctedScaledInteractionsPerCrossing", "float"),
461 ])
462
463 if not self.alternativeConfig:
464 for var_name, var_type in eventInfoVar:
465 config.addOutputVar("EventInfo", var_name, var_name, noSys=True, auxType=var_type)
466
467 if config.dataType() is not DataType.Data and config.geometry() is LHCPeriod.Run2:
468 config.addOutputVar("EventInfo", "beamSpotWeight", "weight_beamspot", noSys=True, auxType="float")
469
470 if config.dataType() is not DataType.Data and toolConfigFiles:
471 config.addOutputVar("EventInfo", f"PileupWeight{self.postfix}_%SYS%",
472 f"weight_pileup{self.postfix}", auxType="float")
473
474
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:132

Member Data Documentation

◆ alternativeConfig

python.AsgAnalysisConfig.PileupReweightingBlock.alternativeConfig

Definition at line 287 of file AsgAnalysisConfig.py.

◆ files

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

Definition at line 307 of file AsgAnalysisConfig.py.

◆ useDefaultConfig

python.AsgAnalysisConfig.PileupReweightingBlock.useDefaultConfig

Definition at line 378 of file AsgAnalysisConfig.py.

◆ writeColumnarToolVariables

python.AsgAnalysisConfig.PileupReweightingBlock.writeColumnarToolVariables

Definition at line 279 of file AsgAnalysisConfig.py.

◆ writeDetailedPileupValues

python.AsgAnalysisConfig.PileupReweightingBlock.writeDetailedPileupValues

Definition at line 290 of file AsgAnalysisConfig.py.


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