159 def makeAlgs (self, config) :
161 from Campaigns.Utils
import Campaign
164 from AthenaCommon.Logging
import logging
167 log = logging.getLogger(
'makePileupAnalysisSequence')
169 eventInfoVar = [
'runNumber',
'eventNumber',
'actualInteractionsPerCrossing',
'averageInteractionsPerCrossing']
170 if config.dataType()
is not DataType.Data:
171 eventInfoVar += [
'mcChannelNumber']
172 if self.writeColumnarToolVariables:
176 eventInfoVar += [
'eventTypeBitmask']
178 if config.isPhyslite()
and not self.alternativeConfig:
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)
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)
191 if self.files
is None and config.autoconfigFlags()
is not None:
192 self.files = config.autoconfigFlags().Input.Files
194 campaign = self.campaign
197 if config.dataType()
is not DataType.Data
and self.campaign
is None:
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}')
204 if self.files
is not None:
205 from Campaigns.Utils
import getMCCampaign
207 if campaign
and campaign
is not Campaign.Unknown:
208 log.info(f
'Auto-configuring campaign for PRW from files: {campaign.value}')
210 log.info(
'Campaign could not be determined.')
214 toolLumicalcFiles = []
218 if (config.dataType()
is not DataType.Data
and
219 config.geometry()
is not LHCPeriod.Run4):
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:
226 raise Exception(
'userPileupConfigsPerCampaign requires campaign to be configured!')
227 if campaign
is Campaign.Unknown:
228 raise Exception(
'userPileupConfigsPerCampaign used, but campaign = Unknown!')
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!')
235 elif self.userPileupConfigs
is not None:
236 toolConfigFiles = self.userPileupConfigs[:]
237 log.info(
'Using user provided PRW configuration')
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.')
244 from PileupReweighting.AutoconfigurePRW
import getConfigurationFiles
245 if campaign
and campaign
is not Campaign.Unknown:
248 useDefaultConfig=self.useDefaultConfig,
249 data_type=config.dataType())
250 if self.useDefaultConfig:
251 log.info(
'Auto-configuring universal/default PRW config')
253 log.info(
'Auto-configuring per-sample PRW config files based on input files')
255 log.info(
'No campaign specified, no PRW config files configured')
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:
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')
271 if campaign
and campaign
is not Campaign.Unknown:
272 from PileupReweighting.AutoconfigurePRW
import getLumicalcFiles
274 log.info(
'Using auto-configured lumicalc files')
276 log.info(
'No campaign specified, no lumicalc files configured for PRW')
278 log.info(
'Data needs no lumicalc and PRW configuration files')
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] }
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")
295 alg.pileupWeightDecoration =
""
297 alg.pileupWeightDecoration =
"PileupWeight" + self.postfix +
"_%SYS%"
298 alg.pileupReweightingTool.LumiCalcFiles = toolLumicalcFiles
300 if not self.alternativeConfig:
301 for var
in eventInfoVar:
302 config.addOutputVar (
'EventInfo', var, var, noSys=
True)
304 if config.dataType()
is not DataType.Data
and config.geometry()
is LHCPeriod.Run2:
305 config.addOutputVar (
'EventInfo',
'beamSpotWeight',
'weight_beamspot', noSys=
True)
307 if config.dataType()
is not DataType.Data
and toolConfigFiles:
308 config.addOutputVar (
'EventInfo',
'PileupWeight' + self.postfix +
'_%SYS%',
309 'weight_pileup'+self.postfix)