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 makeAlgs (self, config)
 

Public Attributes

 files
 

Detailed Description

the ConfigBlock for pileup reweighting

Definition at line 98 of file AsgAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

def python.AsgAnalysisConfig.PileupReweightingBlock.__init__ (   self)

Definition at line 101 of file AsgAnalysisConfig.py.

101  def __init__ (self) :
102  super (PileupReweightingBlock, self).__init__ ()
103  self.addOption ('campaign', None, type=None,
104  info="the MC campaign for the PRW auto-configuration.")
105  self.addOption ('files', None, type=None,
106  info="the input files being processed (list of strings). "
107  "Alternative to auto-configuration.")
108  self.addOption ('useDefaultConfig', True, type=bool,
109  info="whether to use the central PRW files. The default is True.")
110  self.addOption ('userLumicalcFiles', None, type=None,
111  info="user-provided lumicalc files (list of strings). Alternative "
112  "to auto-configuration.")
113  self.addOption ('userLumicalcFilesPerCampaign', None, type=None,
114  info="user-provided lumicalc files (dictionary of list of strings, "
115  "with MC campaigns as the keys). Alternative to auto-configuration.")
116  self.addOption ('userPileupConfigs', None, type=None,
117  info="user-provided PRW files (list of strings). Alternative to "
118  "auto-configuration. Alternative to auto-configuration.")
119  self.addOption ('userPileupConfigsPerCampaign', None, type=None,
120  info="user-provided PRW files (dictionary of list of strings, with "
121  "MC campaigns as the keys)")
122  self.addOption ('postfix', '', type=str,
123  info="a postfix to apply to decorations and algorithm names. "
124  "Typically not needed unless several instances of PileupReweighting are scheduled.")
125  self.addOption ('alternativeConfig', False, type=bool,
126  info="whether this is used as an additional alternative config for PileupReweighting. "
127  "Will only store the alternative pile up weight in that case.")
128 
129 

Member Function Documentation

◆ makeAlgs()

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

Definition at line 130 of file AsgAnalysisConfig.py.

130  def makeAlgs (self, config) :
131 
132  from Campaigns.Utils import Campaign
133 
134  try:
135  from AthenaCommon.Logging import logging
136  except ImportError:
137  import logging
138  log = logging.getLogger('makePileupAnalysisSequence')
139 
140  if config.isPhyslite() and not self.alternativeConfig:
141  # PHYSLITE already has these variables defined, just need to copy them to the output
142  log.info(f'Physlite does not need pileup reweighting. Variables will be copied from input instead. {config.isPhyslite}')
143  config.addOutputVar ('EventInfo', 'runNumber', 'runNumber', noSys=True)
144  config.addOutputVar ('EventInfo', 'eventNumber', 'eventNumber', noSys=True)
145  if config.dataType() is not DataType.Data:
146  config.addOutputVar ('EventInfo', 'mcChannelNumber', 'mcChannelNumber', noSys=True)
147  config.addOutputVar ('EventInfo', 'PileupWeight_%SYS%', 'weight_pileup')
148  if config.geometry() is LHCPeriod.Run2:
149  config.addOutputVar ('EventInfo', 'beamSpotWeight', 'weight_beamspot', noSys=True)
150  return
151 
152  # check files from autoconfig flags
153  if self.files is None and config.autoconfigFlags() is not None:
154  self.files = config.autoconfigFlags().Input.Files
155 
156  campaign = self.campaign
157  # if user didn't explicitly configure campaign, let's try setting it from metadata
158  # only needed on MC
159  if config.dataType() is not DataType.Data and self.campaign is None:
160  # if we used autoconfigflags, campaign is auto-determined
161  if config.campaign() is not None and config.campaign() is not Campaign.Unknown:
162  campaign = config.campaign()
163  log.info(f'Auto-configuring campaign for PRW from flags: {campaign.value}')
164  else:
165  # we try to determine campaign from files if above failed
166  if self.files is not None:
167  from Campaigns.Utils import getMCCampaign
168  campaign = getMCCampaign(self.files)
169  if campaign and campaign is not Campaign.Unknown:
170  log.info(f'Auto-configuring campaign for PRW from files: {campaign.value}')
171  else:
172  log.info('Campaign could not be determined.')
173 
174 
175  toolConfigFiles = []
176  toolLumicalcFiles = []
177 
178  # PRW config files should only be configured if we run on MC
179  # Run 4 not supported yet
180  if (config.dataType() is not DataType.Data and
181  config.geometry() is not LHCPeriod.Run4):
182  # check if user provides per-campaign pileup config list
183  if self.userPileupConfigs is not None and self.userPileupConfigsPerCampaign is not None:
184  raise ValueError('Both userPileupConfigs and userPileupConfigsPerCampaign specified, '
185  'use only one of the options!')
186  if self.userPileupConfigsPerCampaign is not None:
187  if not campaign:
188  raise Exception('userPileupConfigsPerCampaign requires campaign to be configured!')
189  if campaign is Campaign.Unknown:
190  raise Exception('userPileupConfigsPerCampaign used, but campaign = Unknown!')
191  try:
192  toolConfigFiles = self.userPileupConfigsPerCampaign[campaign.value][:]
193  log.info('Using user provided per-campaign PRW configuration')
194  except KeyError as e:
195  raise KeyError(f'Unconfigured campaign {e} for userPileupConfigsPerCampaign!')
196 
197  elif self.userPileupConfigs is not None:
198  toolConfigFiles = self.userPileupConfigs[:]
199  log.info('Using user provided PRW configuration')
200 
201  else:
202  if self.useDefaultConfig and self.files is None:
203  raise ValueError('useDefaultConfig requires files to be configured! '
204  'Either pass them as an option or use flags.')
205 
206  from PileupReweighting.AutoconfigurePRW import getConfigurationFiles
207  if campaign and campaign is not Campaign.Unknown:
208  toolConfigFiles = getConfigurationFiles(campaign=campaign,
209  files=self.files,
210  useDefaultConfig=self.useDefaultConfig,
211  data_type=config.dataType())
212  if self.useDefaultConfig:
213  log.info('Auto-configuring universal/default PRW config')
214  else:
215  log.info('Auto-configuring per-sample PRW config files based on input files')
216  else:
217  log.info('No campaign specified, no PRW config files configured')
218 
219  # check if user provides per-campaign lumical config list
220  if self.userLumicalcFilesPerCampaign is not None and self.userLumicalcFiles is not None:
221  raise ValueError('Both userLumicalcFiles and userLumicalcFilesYear specified, '
222  'use only one of the options!')
223  if self.userLumicalcFilesPerCampaign is not None:
224  try:
225  toolLumicalcFiles = self.userLumicalcFilesPerCampaign[campaign.value][:]
226  log.info('Using user-provided per-campaign lumicalc files')
227  except KeyError as e:
228  raise KeyError(f'Unconfigured campaign {e} for userLumicalcFilesPerCampaign!')
229  elif self.userLumicalcFiles is not None:
230  toolLumicalcFiles = self.userLumicalcFiles[:]
231  log.info('Using user-provided lumicalc files')
232  else:
233  if campaign and campaign is not Campaign.Unknown:
234  from PileupReweighting.AutoconfigurePRW import getLumicalcFiles
235  toolLumicalcFiles = getLumicalcFiles(campaign)
236  log.info('Using auto-configured lumicalc files')
237  else:
238  log.info('No campaign specified, no lumicalc files configured for PRW')
239  else:
240  log.info('Data needs no lumicalc and PRW configuration files')
241 
242  # Set up the only algorithm of the sequence:
243  if config.geometry() is LHCPeriod.Run4:
244  log.warning ('Pileup reweighting is not yet supported for Run 4 geometry')
245  alg = config.createAlgorithm( 'CP::EventDecoratorAlg', 'EventDecoratorAlg'+self.postfix )
246  alg.uint32Decorations = { 'RandomRunNumber' :
247  config.autoconfigFlags().Input.RunNumbers[0] }
248 
249  else:
250  alg = config.createAlgorithm( 'CP::PileupReweightingAlg',
251  'PileupReweightingAlg'+self.postfix )
252  config.addPrivateTool( 'pileupReweightingTool', 'CP::PileupReweightingTool' )
253  alg.pileupReweightingTool.ConfigFiles = toolConfigFiles
254  if not toolConfigFiles and config.dataType() is not DataType.Data:
255  log.info("No PRW config files provided. Disabling reweighting")
256  # Setting the weight decoration to the empty string disables the reweighting
257  alg.pileupWeightDecoration = ""
258  else:
259  alg.pileupWeightDecoration = "PileupWeight" + self.postfix + "_%SYS%"
260  alg.pileupReweightingTool.LumiCalcFiles = toolLumicalcFiles
261 
262  if not self.alternativeConfig:
263  config.addOutputVar ('EventInfo', 'runNumber', 'runNumber', noSys=True)
264  config.addOutputVar ('EventInfo', 'eventNumber', 'eventNumber', noSys=True)
265 
266  if config.dataType() is not DataType.Data:
267  config.addOutputVar ('EventInfo', 'mcChannelNumber', 'mcChannelNumber', noSys=True)
268  if config.geometry() is LHCPeriod.Run2:
269  config.addOutputVar ('EventInfo', 'beamSpotWeight', 'weight_beamspot', noSys=True)
270 
271  if config.dataType() is not DataType.Data and toolConfigFiles:
272  config.addOutputVar ('EventInfo', 'PileupWeight' + self.postfix + '_%SYS%',
273  'weight_pileup'+self.postfix)
274 
275 

Member Data Documentation

◆ files

python.AsgAnalysisConfig.PileupReweightingBlock.files

Definition at line 154 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:27