Skip to content
Snippets Groups Projects
Commit 11eb2884 authored by Edward Moyse's avatar Edward Moyse
Browse files

Merge branch 'SelectionDecorationBlock' into 'main'

Added selection decoration block config for CP algs

See merge request atlas/athena!70133
parents 67909e9b 10d4ba84
No related branches found
No related tags found
No related merge requests found
...@@ -130,6 +130,14 @@ Trigger: ...@@ -130,6 +130,14 @@ Trigger:
photons: 'AnaPhotons' photons: 'AnaPhotons'
muons: 'AnaMuons' muons: 'AnaMuons'
SelectionDecoration:
containers:
- 'OutMuons'
- 'OutElectrons'
- 'OutPhotons'
- 'OutTauJets'
- 'OutJets'
# After configuring each container, many variables will be saved automatically. # After configuring each container, many variables will be saved automatically.
Output: Output:
treeName: 'analysis' treeName: 'analysis'
......
...@@ -102,6 +102,14 @@ Thinning: ...@@ -102,6 +102,14 @@ Thinning:
outputName: 'OutTauJets' outputName: 'OutTauJets'
selectionName: 'tight' selectionName: 'tight'
SelectionDecoration:
containers:
- 'OutMuons'
- 'OutElectrons'
- 'OutPhotons'
- 'OutTauJets'
- 'OutJets'
# After configuring each container, many variables will be saved automatically. # After configuring each container, many variables will be saved automatically.
Output: Output:
treeName: 'analysis' treeName: 'analysis'
......
...@@ -314,6 +314,11 @@ class ConfigFactory(): ...@@ -314,6 +314,11 @@ class ConfigFactory():
self.addAlgConfigBlock(algName="Thinning", alg=OutputThinningBlock, self.addAlgConfigBlock(algName="Thinning", alg=OutputThinningBlock,
defaults={'configName': 'Thinning'}) defaults={'configName': 'Thinning'})
# selection decorations
from AsgAnalysisAlgorithms.AsgAnalysisConfig import SelectionDecorationBlock
self.addAlgConfigBlock(algName='SelectionDecoration',
alg=SelectionDecorationBlock)
# output # output
from AsgAnalysisAlgorithms.OutputAnalysisConfig import OutputAnalysisConfig from AsgAnalysisAlgorithms.OutputAnalysisConfig import OutputAnalysisConfig
self.addAlgConfigBlock(algName="Output", alg=OutputAnalysisConfig, self.addAlgConfigBlock(algName="Output", alg=OutputAnalysisConfig,
......
...@@ -987,6 +987,9 @@ def makeSequenceBlocks (dataType, algSeq, forCompare, isPhyslite, ...@@ -987,6 +987,9 @@ def makeSequenceBlocks (dataType, algSeq, forCompare, isPhyslite,
configSeq.setOptionValue ('.nReplicas', 2000 ) configSeq.setOptionValue ('.nReplicas', 2000 )
configSeq.setOptionValue ('.runOnMC', True ) configSeq.setOptionValue ('.runOnMC', True )
configSeq += config.makeConfig ('SelectionDecoration', containers = [
'OutMuons', 'OutElectrons', 'OutPhotons', 'OutTauJets', 'OutJets'])
configSeq += config.makeConfig ('Output') configSeq += config.makeConfig ('Output')
configSeq.setOptionValue ('.treeName', 'analysis') configSeq.setOptionValue ('.treeName', 'analysis')
configSeq.setOptionValue ('.vars', vars) configSeq.setOptionValue ('.vars', vars)
......
# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
# AnaAlgorithm import(s): # AnaAlgorithm import(s):
from AnalysisAlgorithmsConfig.ConfigBlock import ConfigBlock from AnalysisAlgorithmsConfig.ConfigBlock import ConfigBlock
...@@ -415,6 +415,35 @@ class PerEventSFBlock (ConfigBlock): ...@@ -415,6 +415,35 @@ class PerEventSFBlock (ConfigBlock):
alg.scaleFactorOutputDecoration.split("_%SYS%")[0]) alg.scaleFactorOutputDecoration.split("_%SYS%")[0])
class SelectionDecorationBlock (ConfigBlock):
"""the ConfigBlock to add selection decoration to a container"""
def __init__ (self, containers) :
super (SelectionDecorationBlock, self).__init__ ()
self.containers = containers
self.addOption ('selectionFlagPrefix', 'select', type=str)
def makeAlgs(self, config):
for container in self.containers:
originContainerName = config.getOutputContainerOrigin(container)
selectionNames = config.getSelectionNames(originContainerName)
for selectionName in selectionNames:
# skip default selection
if selectionName == '':
continue
alg = config.createAlgorithm(
'CP::AsgSelectionAlg',
f'SelectionDecoration_{originContainerName}_{selectionName}')
selectionDecoration = f'baselineSelection_{selectionName}_%SYS%'
alg.selectionDecoration = f'{selectionDecoration},as_char'
alg.particles = config.readName (originContainerName)
alg.preselection = config.getFullSelection (originContainerName,
selectionName)
config.addOutputVar(
originContainerName, selectionDecoration,
self.selectionFlagPrefix + '_' + selectionName)
def makeCommonServicesConfig( seq ): def makeCommonServicesConfig( seq ):
"""Create the common services config""" """Create the common services config"""
......
# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
# AnaAlgorithm import(s): # AnaAlgorithm import(s):
from AnalysisAlgorithmsConfig.ConfigBlock import ConfigBlock from AnalysisAlgorithmsConfig.ConfigBlock import ConfigBlock
...@@ -18,8 +18,6 @@ class OutputAnalysisConfig (ConfigBlock): ...@@ -18,8 +18,6 @@ class OutputAnalysisConfig (ConfigBlock):
self.addOption ('containersOnlyForMC', [], type=None) self.addOption ('containersOnlyForMC', [], type=None)
self.addOption ('treeName', 'analysis', type=str) self.addOption ('treeName', 'analysis', type=str)
self.addOption ('metTermName', 'Final', type=str) self.addOption ('metTermName', 'Final', type=str)
self.addOption ('storeSelectionFlags', True, type=bool)
self.addOption ('selectionFlagPrefix', 'select', type=str)
self.addOption ('commands', [], type=None, self.addOption ('commands', [], type=None,
info="a list of commands for branch selection/configuration") info="a list of commands for branch selection/configuration")
...@@ -33,9 +31,6 @@ class OutputAnalysisConfig (ConfigBlock): ...@@ -33,9 +31,6 @@ class OutputAnalysisConfig (ConfigBlock):
self.vars |= self.varsOnlyForMC self.vars |= self.varsOnlyForMC
self.containers.update(self.containersOnlyForMC) self.containers.update(self.containersOnlyForMC)
if self.storeSelectionFlags:
self.createSelectionFlagBranches(config)
outputConfigs = {} outputConfigs = {}
for prefix in self.containers.keys() : for prefix in self.containers.keys() :
containerName = self.containers[prefix] containerName = self.containers[prefix]
...@@ -116,39 +111,3 @@ class OutputAnalysisConfig (ConfigBlock): ...@@ -116,39 +111,3 @@ class OutputAnalysisConfig (ConfigBlock):
treeFiller = config.createAlgorithm( 'CP::TreeFillerAlg', 'TreeFiller' + postfix ) treeFiller = config.createAlgorithm( 'CP::TreeFillerAlg', 'TreeFiller' + postfix )
treeFiller.TreeName = self.treeName treeFiller.TreeName = self.treeName
def createSelectionFlagBranches(self, config):
"""
For each container and for each selection, create a single pass variable in output NTuple,
which aggregates all the selections flag of the given selection. For example, this can include
pT, eta selections, some object ID selection, overlap removal, etc.
The goal is to have only one flag per object and working point in the output NTuple.
"""
for prefix in self.containers.keys() :
outputContainerName = self.containers[prefix]
containerName = config.getOutputContainerOrigin(outputContainerName)
# EventInfo is one obvious example of a container that has no object selections
if containerName == 'EventInfo':
continue
selectionNames = config.getSelectionNames(containerName)
for selectionName in selectionNames:
# skip default selection
if selectionName == '':
continue
self.makeSelectionSummaryAlg(config, containerName, selectionName)
def makeSelectionSummaryAlg(self, config, containerName, selectionName):
"""
Schedule an algorithm to pick up all cut flags for a given selectionName.
The summary selection flag is written to output as selectionFlagPrefix_selectionName.
"""
alg = config.createAlgorithm( 'CP::AsgSelectionAlg',
f'ObjectSelectionSummary_{containerName}_{selectionName}')
selectionDecoration = f'baselineSelection_{selectionName}_%SYS%'
alg.selectionDecoration = f'{selectionDecoration},as_char'
alg.particles = config.readName (containerName)
alg.preselection = config.getFullSelection (containerName, selectionName)
config.addOutputVar (containerName, selectionDecoration, self.selectionFlagPrefix + '_' + selectionName)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment