the ConfigBlock for pileup reweighting
Definition at line 128 of file AsgAnalysisConfig.py.
◆ __init__()
def python.AsgAnalysisConfig.PileupReweightingBlock.__init__ |
( |
|
self | ) |
|
Definition at line 131 of file AsgAnalysisConfig.py.
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)")
◆ 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"""
◆ makeAlgs()
def python.AsgAnalysisConfig.PileupReweightingBlock.makeAlgs |
( |
|
self, |
|
|
|
config |
|
) |
| |
Definition at line 165 of file AsgAnalysisConfig.py.
165 def makeAlgs (self, config) :
167 from Campaigns.Utils
import Campaign
170 from AthenaCommon.Logging
import logging
173 log = logging.getLogger(
'makePileupAnalysisSequence')
175 eventInfoVar = [
'runNumber',
'eventNumber',
'actualInteractionsPerCrossing',
'averageInteractionsPerCrossing']
176 if config.dataType()
is not DataType.Data:
177 eventInfoVar += [
'mcChannelNumber']
178 if self.writeColumnarToolVariables:
182 eventInfoVar += [
'eventTypeBitmask']
184 if config.isPhyslite()
and not self.alternativeConfig:
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)
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)
197 if self.files
is None and config.flags
is not None:
198 self.files = config.flags.Input.Files
200 campaign = self.campaign
203 if config.dataType()
is not DataType.Data
and self.campaign
is None:
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}')
210 if self.files
is not None:
211 from Campaigns.Utils
import getMCCampaign
213 if campaign
and campaign
is not Campaign.Unknown:
214 log.info(f
'Auto-configuring campaign for PRW from files: {campaign.value}')
216 log.info(
'Campaign could not be determined.')
220 toolLumicalcFiles = []
224 if (config.dataType()
is not DataType.Data
and
225 config.geometry()
is not LHCPeriod.Run4):
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:
232 raise Exception(
'userPileupConfigsPerCampaign requires campaign to be configured!')
233 if campaign
is Campaign.Unknown:
234 raise Exception(
'userPileupConfigsPerCampaign used, but campaign = Unknown!')
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!')
241 elif self.userPileupConfigs
is not None:
242 toolConfigFiles = self.userPileupConfigs[:]
243 log.info(
'Using user provided PRW configuration')
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.')
250 from PileupReweighting.AutoconfigurePRW
import getConfigurationFiles
251 if campaign
and campaign
is not Campaign.Unknown:
254 useDefaultConfig=self.useDefaultConfig,
255 data_type=config.dataType())
256 if self.useDefaultConfig:
257 log.info(
'Auto-configuring universal/default PRW config')
259 log.info(
'Auto-configuring per-sample PRW config files based on input files')
261 log.info(
'No campaign specified, no PRW config files configured')
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:
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')
277 if campaign
and campaign
is not Campaign.Unknown:
278 from PileupReweighting.AutoconfigurePRW
import getLumicalcFiles
280 log.info(
'Using auto-configured lumicalc files')
282 log.info(
'No campaign specified, no lumicalc files configured for PRW')
284 log.info(
'Data needs no lumicalc and PRW configuration files')
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] }
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")
301 alg.pileupWeightDecoration =
""
303 alg.pileupWeightDecoration =
"PileupWeight" + self.postfix +
"_%SYS%"
304 alg.pileupReweightingTool.LumiCalcFiles = toolLumicalcFiles
306 if not self.alternativeConfig:
307 for var
in eventInfoVar:
308 config.addOutputVar (
'EventInfo', var, var, noSys=
True)
310 if config.dataType()
is not DataType.Data
and config.geometry()
is LHCPeriod.Run2:
311 config.addOutputVar (
'EventInfo',
'beamSpotWeight',
'weight_beamspot', noSys=
True)
313 if config.dataType()
is not DataType.Data
and toolConfigFiles:
314 config.addOutputVar (
'EventInfo',
'PileupWeight' + self.postfix +
'_%SYS%',
315 'weight_pileup'+self.postfix)
◆ files
python.AsgAnalysisConfig.PileupReweightingBlock.files |
The documentation for this class was generated from the following file: