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

Constructor & Destructor Documentation

◆ __init__()

def python.AsgAnalysisConfig.PileupReweightingBlock.__init__ (   self)

Definition at line 125 of file AsgAnalysisConfig.py.

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

Member Function Documentation

◆ instanceName()

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

Definition at line 155 of file AsgAnalysisConfig.py.

155  def instanceName (self) :
156  """Return the instance name for this block"""
157  return self.postfix
158 

◆ makeAlgs()

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

Definition at line 159 of file AsgAnalysisConfig.py.

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

Member Data Documentation

◆ files

python.AsgAnalysisConfig.PileupReweightingBlock.files

Definition at line 192 of file AsgAnalysisConfig.py.


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