the ConfigBlock for pileup reweighting
Definition at line 185 of file AsgAnalysisConfig.py.
◆ __init__()
| def python.AsgAnalysisConfig.PileupReweightingBlock.__init__ |
( |
|
self | ) |
|
Definition at line 188 of file AsgAnalysisConfig.py.
189 super (PileupReweightingBlock, self).__init__ ()
190 self.addOption (
'campaign',
None, type=
None,
191 info=
"the MC campaign for the PRW auto-configuration.")
192 self.addOption (
'files',
None, type=
None,
193 info=
"the input files being processed (list of strings). "
194 "Alternative to auto-configuration.")
195 self.addOption (
'useDefaultConfig',
True, type=bool,
196 info=
"whether to use the central PRW files. The default is True.")
197 self.addOption (
'userLumicalcFiles',
None, type=
None,
198 info=
"user-provided lumicalc files (list of strings). Alternative "
199 "to auto-configuration.")
200 self.addOption (
'userLumicalcFilesPerCampaign',
None, type=
None,
201 info=
"user-provided lumicalc files (dictionary of list of strings, "
202 "with MC campaigns as the keys). Alternative to auto-configuration.")
203 self.addOption (
'userPileupConfigs',
None, type=
None,
204 info=
"user-provided PRW files (list of strings). Alternative to "
205 "auto-configuration. Alternative to auto-configuration.")
206 self.addOption (
'userPileupConfigsPerCampaign',
None, type=
None,
207 info=
"user-provided PRW files (dictionary of list of strings, with "
208 "MC campaigns as the keys)")
209 self.addOption (
'postfix',
'', type=str,
210 info=
"a postfix to apply to decorations and algorithm names. "
211 "Typically not needed unless several instances of PileupReweighting are scheduled.")
212 self.addOption (
'alternativeConfig',
False, type=bool,
213 info=
"whether this is used as an additional alternative config for PileupReweighting. "
214 "Will only store the alternative pile up weight in that case.")
215 self.addOption (
'writeColumnarToolVariables',
False, type=bool,
216 info=
"whether to add EventInfo variables needed for running the columnar tool(s) on the output n-tuple. (EXPERIMENTAL)",
◆ instanceName()
| def python.AsgAnalysisConfig.PileupReweightingBlock.instanceName |
( |
|
self | ) |
|
Return the instance name for this block
Definition at line 219 of file AsgAnalysisConfig.py.
219 def instanceName (self) :
220 """Return the instance name for this block"""
◆ makeAlgs()
| def python.AsgAnalysisConfig.PileupReweightingBlock.makeAlgs |
( |
|
self, |
|
|
|
config |
|
) |
| |
Definition at line 223 of file AsgAnalysisConfig.py.
223 def makeAlgs (self, config) :
225 from Campaigns.Utils
import Campaign
227 log = logging.getLogger(
'makePileupAnalysisSequence')
229 eventInfoVar = [
'runNumber',
'eventNumber',
'actualInteractionsPerCrossing',
'averageInteractionsPerCrossing']
230 if config.dataType()
is not DataType.Data:
231 eventInfoVar += [
'mcChannelNumber']
232 if self.writeColumnarToolVariables:
236 eventInfoVar += [
'eventTypeBitmask']
238 if config.isPhyslite()
and not self.alternativeConfig:
240 log.info(f
'Physlite does not need pileup reweighting. Variables will be copied from input instead. {config.isPhyslite}')
241 for var
in eventInfoVar:
242 config.addOutputVar (
'EventInfo', var, var, noSys=
True)
244 if config.dataType()
is not DataType.Data:
245 config.addOutputVar (
'EventInfo',
'PileupWeight_%SYS%',
'weight_pileup')
246 if config.geometry()
is LHCPeriod.Run2:
247 config.addOutputVar (
'EventInfo',
'beamSpotWeight',
'weight_beamspot', noSys=
True)
251 if self.files
is None and config.flags
is not None:
252 self.files = config.flags.Input.Files
254 campaign = self.campaign
257 if config.dataType()
is not DataType.Data
and self.campaign
is None:
259 if config.campaign()
is not None and config.campaign()
is not Campaign.Unknown:
260 campaign = config.campaign()
261 log.info(f
'Auto-configuring campaign for PRW from flags: {campaign.value}')
264 if self.files
is not None:
265 from Campaigns.Utils
import getMCCampaign
267 if campaign
and campaign
is not Campaign.Unknown:
268 log.info(f
'Auto-configuring campaign for PRW from files: {campaign.value}')
270 log.info(
'Campaign could not be determined.')
274 toolLumicalcFiles = []
278 if (config.dataType()
is not DataType.Data
and
279 config.geometry()
is not LHCPeriod.Run4):
281 if self.userPileupConfigs
is not None and self.userPileupConfigsPerCampaign
is not None:
282 raise ValueError(
'Both userPileupConfigs and userPileupConfigsPerCampaign specified, '
283 'use only one of the options!')
284 if self.userPileupConfigsPerCampaign
is not None:
286 raise Exception(
'userPileupConfigsPerCampaign requires campaign to be configured!')
287 if campaign
is Campaign.Unknown:
288 raise Exception(
'userPileupConfigsPerCampaign used, but campaign = Unknown!')
290 toolConfigFiles = self.userPileupConfigsPerCampaign[campaign.value][:]
291 log.info(
'Using user provided per-campaign PRW configuration')
292 except KeyError
as e:
293 raise KeyError(f
'Unconfigured campaign {e} for userPileupConfigsPerCampaign!')
295 elif self.userPileupConfigs
is not None:
296 toolConfigFiles = self.userPileupConfigs[:]
297 log.info(
'Using user provided PRW configuration')
300 if self.useDefaultConfig
and self.files
is None:
301 raise ValueError(
'useDefaultConfig requires files to be configured! '
302 'Either pass them as an option or use flags.')
304 from PileupReweighting.AutoconfigurePRW
import getConfigurationFiles
305 if campaign
and campaign
is not Campaign.Unknown:
308 useDefaultConfig=self.useDefaultConfig,
309 data_type=config.dataType())
310 if self.useDefaultConfig:
311 log.info(
'Auto-configuring universal/default PRW config')
313 log.info(
'Auto-configuring per-sample PRW config files based on input files')
315 log.info(
'No campaign specified, no PRW config files configured')
318 if self.userLumicalcFilesPerCampaign
is not None and self.userLumicalcFiles
is not None:
319 raise ValueError(
'Both userLumicalcFiles and userLumicalcFilesYear specified, '
320 'use only one of the options!')
321 if self.userLumicalcFilesPerCampaign
is not None:
323 toolLumicalcFiles = self.userLumicalcFilesPerCampaign[campaign.value][:]
324 log.info(
'Using user-provided per-campaign lumicalc files')
325 except KeyError
as e:
326 raise KeyError(f
'Unconfigured campaign {e} for userLumicalcFilesPerCampaign!')
327 elif self.userLumicalcFiles
is not None:
328 toolLumicalcFiles = self.userLumicalcFiles[:]
329 log.info(
'Using user-provided lumicalc files')
331 if campaign
and campaign
is not Campaign.Unknown:
332 from PileupReweighting.AutoconfigurePRW
import getLumicalcFiles
334 log.info(
'Using auto-configured lumicalc files')
336 log.info(
'No campaign specified, no lumicalc files configured for PRW')
338 log.info(
'Data needs no lumicalc and PRW configuration files')
341 if config.geometry()
is LHCPeriod.Run4:
342 log.warning (
'Pileup reweighting is not yet supported for Run 4 geometry')
343 alg = config.createAlgorithm(
'CP::EventDecoratorAlg',
'EventDecoratorAlg' )
344 alg.uint32Decorations = {
'RandomRunNumber' :
345 config.flags.Input.RunNumbers[0] }
348 alg = config.createAlgorithm(
'CP::PileupReweightingAlg',
349 'PileupReweightingAlg' )
350 config.addPrivateTool(
'pileupReweightingTool',
'CP::PileupReweightingTool' )
351 alg.pileupReweightingTool.ConfigFiles = toolConfigFiles
352 if not toolConfigFiles
and config.dataType()
is not DataType.Data:
353 log.info(
"No PRW config files provided. Disabling reweighting")
355 alg.pileupWeightDecoration =
""
357 alg.pileupWeightDecoration =
"PileupWeight" + self.postfix +
"_%SYS%"
358 alg.pileupReweightingTool.LumiCalcFiles = toolLumicalcFiles
360 if not self.alternativeConfig:
361 for var
in eventInfoVar:
362 config.addOutputVar (
'EventInfo', var, var, noSys=
True)
364 if config.dataType()
is not DataType.Data
and config.geometry()
is LHCPeriod.Run2:
365 config.addOutputVar (
'EventInfo',
'beamSpotWeight',
'weight_beamspot', noSys=
True)
367 if config.dataType()
is not DataType.Data
and toolConfigFiles:
368 config.addOutputVar (
'EventInfo',
'PileupWeight' + self.postfix +
'_%SYS%',
369 'weight_pileup'+self.postfix)
◆ files
| python.AsgAnalysisConfig.PileupReweightingBlock.files |
The documentation for this class was generated from the following file: