the ConfigBlock for pileup reweighting
Definition at line 161 of file AsgAnalysisConfig.py.
◆ __init__()
| def python.AsgAnalysisConfig.PileupReweightingBlock.__init__ |
( |
|
self | ) |
|
Definition at line 164 of file AsgAnalysisConfig.py.
165 super (PileupReweightingBlock, self).__init__ ()
166 self.addOption (
'campaign',
None, type=
None,
167 info=
"the MC campaign for the PRW auto-configuration.")
168 self.addOption (
'files',
None, type=
None,
169 info=
"the input files being processed (list of strings). "
170 "Alternative to auto-configuration.")
171 self.addOption (
'useDefaultConfig',
True, type=bool,
172 info=
"whether to use the central PRW files. The default is True.")
173 self.addOption (
'userLumicalcFiles',
None, type=
None,
174 info=
"user-provided lumicalc files (list of strings). Alternative "
175 "to auto-configuration.")
176 self.addOption (
'userLumicalcFilesPerCampaign',
None, type=
None,
177 info=
"user-provided lumicalc files (dictionary of list of strings, "
178 "with MC campaigns as the keys). Alternative to auto-configuration.")
179 self.addOption (
'userPileupConfigs',
None, type=
None,
180 info=
"user-provided PRW files (list of strings). Alternative to "
181 "auto-configuration. Alternative to auto-configuration.")
182 self.addOption (
'userPileupConfigsPerCampaign',
None, type=
None,
183 info=
"user-provided PRW files (dictionary of list of strings, with "
184 "MC campaigns as the keys)")
185 self.addOption (
'postfix',
'', type=str,
186 info=
"a postfix to apply to decorations and algorithm names. "
187 "Typically not needed unless several instances of PileupReweighting are scheduled.")
188 self.addOption (
'alternativeConfig',
False, type=bool,
189 info=
"whether this is used as an additional alternative config for PileupReweighting. "
190 "Will only store the alternative pile up weight in that case.")
191 self.addOption (
'writeColumnarToolVariables',
False, type=bool,
192 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 195 of file AsgAnalysisConfig.py.
195 def instanceName (self) :
196 """Return the instance name for this block"""
◆ makeAlgs()
| def python.AsgAnalysisConfig.PileupReweightingBlock.makeAlgs |
( |
|
self, |
|
|
|
config |
|
) |
| |
Definition at line 199 of file AsgAnalysisConfig.py.
199 def makeAlgs (self, config) :
201 from Campaigns.Utils
import Campaign
203 log = logging.getLogger(
'makePileupAnalysisSequence')
205 eventInfoVar = [
'runNumber',
'eventNumber',
'actualInteractionsPerCrossing',
'averageInteractionsPerCrossing']
206 if config.dataType()
is not DataType.Data:
207 eventInfoVar += [
'mcChannelNumber']
208 if self.writeColumnarToolVariables:
212 eventInfoVar += [
'eventTypeBitmask']
214 if config.isPhyslite()
and not self.alternativeConfig:
216 log.info(f
'Physlite does not need pileup reweighting. Variables will be copied from input instead. {config.isPhyslite}')
217 for var
in eventInfoVar:
218 config.addOutputVar (
'EventInfo', var, var, noSys=
True)
220 if config.dataType()
is not DataType.Data:
221 config.addOutputVar (
'EventInfo',
'PileupWeight_%SYS%',
'weight_pileup')
222 if config.geometry()
is LHCPeriod.Run2:
223 config.addOutputVar (
'EventInfo',
'beamSpotWeight',
'weight_beamspot', noSys=
True)
227 if self.files
is None and config.flags
is not None:
228 self.files = config.flags.Input.Files
230 campaign = self.campaign
233 if config.dataType()
is not DataType.Data
and self.campaign
is None:
235 if config.campaign()
is not None and config.campaign()
is not Campaign.Unknown:
236 campaign = config.campaign()
237 log.info(f
'Auto-configuring campaign for PRW from flags: {campaign.value}')
240 if self.files
is not None:
241 from Campaigns.Utils
import getMCCampaign
243 if campaign
and campaign
is not Campaign.Unknown:
244 log.info(f
'Auto-configuring campaign for PRW from files: {campaign.value}')
246 log.info(
'Campaign could not be determined.')
250 toolLumicalcFiles = []
254 if (config.dataType()
is not DataType.Data
and
255 config.geometry()
is not LHCPeriod.Run4):
257 if self.userPileupConfigs
is not None and self.userPileupConfigsPerCampaign
is not None:
258 raise ValueError(
'Both userPileupConfigs and userPileupConfigsPerCampaign specified, '
259 'use only one of the options!')
260 if self.userPileupConfigsPerCampaign
is not None:
262 raise Exception(
'userPileupConfigsPerCampaign requires campaign to be configured!')
263 if campaign
is Campaign.Unknown:
264 raise Exception(
'userPileupConfigsPerCampaign used, but campaign = Unknown!')
266 toolConfigFiles = self.userPileupConfigsPerCampaign[campaign.value][:]
267 log.info(
'Using user provided per-campaign PRW configuration')
268 except KeyError
as e:
269 raise KeyError(f
'Unconfigured campaign {e} for userPileupConfigsPerCampaign!')
271 elif self.userPileupConfigs
is not None:
272 toolConfigFiles = self.userPileupConfigs[:]
273 log.info(
'Using user provided PRW configuration')
276 if self.useDefaultConfig
and self.files
is None:
277 raise ValueError(
'useDefaultConfig requires files to be configured! '
278 'Either pass them as an option or use flags.')
280 from PileupReweighting.AutoconfigurePRW
import getConfigurationFiles
281 if campaign
and campaign
is not Campaign.Unknown:
284 useDefaultConfig=self.useDefaultConfig,
285 data_type=config.dataType())
286 if self.useDefaultConfig:
287 log.info(
'Auto-configuring universal/default PRW config')
289 log.info(
'Auto-configuring per-sample PRW config files based on input files')
291 log.info(
'No campaign specified, no PRW config files configured')
294 if self.userLumicalcFilesPerCampaign
is not None and self.userLumicalcFiles
is not None:
295 raise ValueError(
'Both userLumicalcFiles and userLumicalcFilesYear specified, '
296 'use only one of the options!')
297 if self.userLumicalcFilesPerCampaign
is not None:
299 toolLumicalcFiles = self.userLumicalcFilesPerCampaign[campaign.value][:]
300 log.info(
'Using user-provided per-campaign lumicalc files')
301 except KeyError
as e:
302 raise KeyError(f
'Unconfigured campaign {e} for userLumicalcFilesPerCampaign!')
303 elif self.userLumicalcFiles
is not None:
304 toolLumicalcFiles = self.userLumicalcFiles[:]
305 log.info(
'Using user-provided lumicalc files')
307 if campaign
and campaign
is not Campaign.Unknown:
308 from PileupReweighting.AutoconfigurePRW
import getLumicalcFiles
310 log.info(
'Using auto-configured lumicalc files')
312 log.info(
'No campaign specified, no lumicalc files configured for PRW')
314 log.info(
'Data needs no lumicalc and PRW configuration files')
317 if config.geometry()
is LHCPeriod.Run4:
318 log.warning (
'Pileup reweighting is not yet supported for Run 4 geometry')
319 alg = config.createAlgorithm(
'CP::EventDecoratorAlg',
'EventDecoratorAlg' )
320 alg.uint32Decorations = {
'RandomRunNumber' :
321 config.flags.Input.RunNumbers[0] }
324 alg = config.createAlgorithm(
'CP::PileupReweightingAlg',
325 'PileupReweightingAlg' )
326 config.addPrivateTool(
'pileupReweightingTool',
'CP::PileupReweightingTool' )
327 alg.pileupReweightingTool.ConfigFiles = toolConfigFiles
328 if not toolConfigFiles
and config.dataType()
is not DataType.Data:
329 log.info(
"No PRW config files provided. Disabling reweighting")
331 alg.pileupWeightDecoration =
""
333 alg.pileupWeightDecoration =
"PileupWeight" + self.postfix +
"_%SYS%"
334 alg.pileupReweightingTool.LumiCalcFiles = toolLumicalcFiles
336 if not self.alternativeConfig:
337 for var
in eventInfoVar:
338 config.addOutputVar (
'EventInfo', var, var, noSys=
True)
340 if config.dataType()
is not DataType.Data
and config.geometry()
is LHCPeriod.Run2:
341 config.addOutputVar (
'EventInfo',
'beamSpotWeight',
'weight_beamspot', noSys=
True)
343 if config.dataType()
is not DataType.Data
and toolConfigFiles:
344 config.addOutputVar (
'EventInfo',
'PileupWeight' + self.postfix +
'_%SYS%',
345 'weight_pileup'+self.postfix)
◆ files
| python.AsgAnalysisConfig.PileupReweightingBlock.files |
The documentation for this class was generated from the following file: