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

Constructor & Destructor Documentation

◆ __init__()

def python.AsgAnalysisConfig.PileupReweightingBlock.__init__ (   self)

Definition at line 131 of file AsgAnalysisConfig.py.

131  def __init__ (self) :
132  super (PileupReweightingBlock, self).__init__ ()
133  self.addOption ('campaign', None, type=None,
134  info="the MC campaign for the PRW auto-configuration.")
135  self.addOption ('files', None, type=None,
136  info="the input files being processed (list of strings). "
137  "Alternative to auto-configuration.")
138  self.addOption ('useDefaultConfig', True, type=bool,
139  info="whether to use the central PRW files. The default is True.")
140  self.addOption ('userLumicalcFiles', None, type=None,
141  info="user-provided lumicalc files (list of strings). Alternative "
142  "to auto-configuration.")
143  self.addOption ('userLumicalcFilesPerCampaign', None, type=None,
144  info="user-provided lumicalc files (dictionary of list of strings, "
145  "with MC campaigns as the keys). Alternative to auto-configuration.")
146  self.addOption ('userPileupConfigs', None, type=None,
147  info="user-provided PRW files (list of strings). Alternative to "
148  "auto-configuration. Alternative to auto-configuration.")
149  self.addOption ('userPileupConfigsPerCampaign', None, type=None,
150  info="user-provided PRW files (dictionary of list of strings, with "
151  "MC campaigns as the keys)")
152  self.addOption ('postfix', '', type=str,
153  info="a postfix to apply to decorations and algorithm names. "
154  "Typically not needed unless several instances of PileupReweighting are scheduled.")
155  self.addOption ('alternativeConfig', False, type=bool,
156  info="whether this is used as an additional alternative config for PileupReweighting. "
157  "Will only store the alternative pile up weight in that case.")
158  self.addOption ('writeColumnarToolVariables', False, type=bool,
159  info="whether to add EventInfo variables needed for running the columnar tool(s) on the output n-tuple. (EXPERIMENTAL)")
160 

Member Function Documentation

◆ instanceName()

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

Definition at line 161 of file AsgAnalysisConfig.py.

161  def instanceName (self) :
162  """Return the instance name for this block"""
163  return self.postfix
164 

◆ makeAlgs()

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

Definition at line 165 of file AsgAnalysisConfig.py.

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

Member Data Documentation

◆ files

python.AsgAnalysisConfig.PileupReweightingBlock.files

Definition at line 198 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