ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
python.AsgAnalysisConfig.PileupReweightingBlock Class Reference
Inheritance diagram for python.AsgAnalysisConfig.PileupReweightingBlock:
Collaboration diagram for python.AsgAnalysisConfig.PileupReweightingBlock:

Public Member Functions

def __init__ (self)
 
def instanceName (self)
 
def makeAlgs (self, config)
 

Public Attributes

 files
 

Detailed Description

the ConfigBlock for pileup reweighting

Definition at line 161 of file AsgAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

def python.AsgAnalysisConfig.PileupReweightingBlock.__init__ (   self)

Definition at line 164 of file AsgAnalysisConfig.py.

164  def __init__ (self) :
165  super (PileupReweightingBlock, self).__init__ ()
166  self.addOption ('campaign', None, type=None,
167  info="the MC campaign for the PRW auto-configuration.")
168  self.addOption ('files', None, type=None,
169  info="the input files being processed (list of strings). "
170  "Alternative to auto-configuration.")
171  self.addOption ('useDefaultConfig', True, type=bool,
172  info="whether to use the central PRW files. The default is True.")
173  self.addOption ('userLumicalcFiles', None, type=None,
174  info="user-provided lumicalc files (list of strings). Alternative "
175  "to auto-configuration.")
176  self.addOption ('userLumicalcFilesPerCampaign', None, type=None,
177  info="user-provided lumicalc files (dictionary of list of strings, "
178  "with MC campaigns as the keys). Alternative to auto-configuration.")
179  self.addOption ('userPileupConfigs', None, type=None,
180  info="user-provided PRW files (list of strings). Alternative to "
181  "auto-configuration. Alternative to auto-configuration.")
182  self.addOption ('userPileupConfigsPerCampaign', None, type=None,
183  info="user-provided PRW files (dictionary of list of strings, with "
184  "MC campaigns as the keys)")
185  self.addOption ('postfix', '', type=str,
186  info="a postfix to apply to decorations and algorithm names. "
187  "Typically not needed unless several instances of PileupReweighting are scheduled.")
188  self.addOption ('alternativeConfig', False, type=bool,
189  info="whether this is used as an additional alternative config for PileupReweighting. "
190  "Will only store the alternative pile up weight in that case.")
191  self.addOption ('writeColumnarToolVariables', False, type=bool,
192  info="whether to add EventInfo variables needed for running the columnar tool(s) on the output n-tuple. (EXPERIMENTAL)",
193  expertMode=True)
194 

Member Function Documentation

◆ instanceName()

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

Definition at line 195 of file AsgAnalysisConfig.py.

195  def instanceName (self) :
196  """Return the instance name for this block"""
197  return self.postfix
198 

◆ makeAlgs()

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

Definition at line 199 of file AsgAnalysisConfig.py.

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

Member Data Documentation

◆ files

python.AsgAnalysisConfig.PileupReweightingBlock.files

Definition at line 228 of file AsgAnalysisConfig.py.


The documentation for this class was generated from the following file:
python.processes.powheg.ZZj_MiNNLO.ZZj_MiNNLO.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZj_MiNNLO.py:18
python.AutoconfigurePRW.getConfigurationFiles
def getConfigurationFiles(campaign=None, dsid=None, data_type=None, files=None, useDefaultConfig=False)
Definition: AutoconfigurePRW.py:127
python.AutoconfigurePRW.getLumicalcFiles
def getLumicalcFiles(campaign)
Definition: AutoconfigurePRW.py:6
python.Utils.getMCCampaign
def getMCCampaign(files)
Definition: Tools/Campaigns/python/Utils.py:38