Skip to content
Snippets Groups Projects

Update JetAnalysisCommon

Merged Pierre Antoine Delsart requested to merge delsart/athena:testAB into master
All threads resolved!
@@ -10,6 +10,9 @@ they are replacing, so athena-style configuration can be used unchanged in Analy
This module is thus designed ONLY for AnalysisBase and to run EventLoop jobs.
IMPORTANT : this module is only designed so the jet configuration works. There's no guarantee it won't mess up
when used with other part of Athena configuration.
Internally, the athena-style configurations of algorithms are translated to AnaReentrantAlgorithmConfig or
AnaAlgorithmConfig. The configuration of AsgTools are translated to call to AnaAlgorithmConfig.addPrivateTool()
or AnaAlgorithmConfig.setPropertyFromString()
@@ -76,6 +79,40 @@ class SystemOfUnits:
PeV = petaelectronvolt
from enum import Enum
+3
class BeamType(Enum):
"""Recopied from AthenaConfiguration.Enums."""
Collisions = 'collisions'
SingleBeam = 'singlebeam'
Cosmics = 'cosmics'
class Project(Enum):
"""Recopied from AthenaConfiguration.Enums."""
Athena = 'Athena'
AthAnalysis = 'AthAnalysis'
AthDerivation = 'AthDerivation'
AthGeneration = 'AthGeneration'
AthSimulation = 'AthSimulation'
AnalysisBase = 'AnalysisBase'
@classmethod
def determine(cls):
import os
if "AthSimulation_DIR" in os.environ:
return cls.AthSimulation
if "AthGeneration_DIR" in os.environ:
return cls.AthGeneration
if "AthAnalysis_DIR" in os.environ:
return cls.AthAnalysis
if "AthDerivation_DIR" in os.environ:
return cls.AthDerivation
if "AnalysisBase_DIR" in os.environ:
return cls.AnalysisBase
return cls.Athena
Enums_mock = ModuleType("Enum")
Enums_mock.BeamType = BeamType
Enums_mock.Project = Project
#*******************************************************************
@@ -216,7 +253,9 @@ class Configured:
# any other type :
alg.setPropertyFromString(self.prefixed(k) , stringPropValue( v ) )
def getType(self):
return self.type
def generateConfigured(classname, cppclass, prefix=""):
import cppyy
@@ -291,15 +330,37 @@ CompFactory.addNameSpaces( 'Analysis', 'Trk', 'Jet', 'Sim')
ComponentFactory = ModuleType("ComponentFactory")
ComponentFactory.CompFactory = CompFactory
ComponentFactory.isRun3Cfg = lambda : True
#*******************************************************************
# replacements for ConfigFlags
ConfigFlags = SimpleNamespace(
Input = SimpleNamespace(),
class AthConfigFlags_mock(SimpleNamespace):
def addFlag(self, name, value ):
keys = name.split('.')
namespace = self
for k in keys[:-1]:
# build nested namespace if needed
namespace2 = getattr(namespace, k,None )
if namespace2 is None:
namespace2 = AthConfigFlags_mock()
setattr(namespace,k, namespace2 )
namespace = namespace2
# set the value on the last key
setattr(namespace,keys[-1], value)
# setup a default ConfigFlags and a few default values needed for running jets
ConfigFlags = AthConfigFlags_mock(
Input = AthConfigFlags_mock(),
)
ConfigFlags.addFlag("Beam.Type", BeamType.Collisions)
ConfigFlags.addFlag("Concurrency.NumThreads",0)
# put it in a fake module
AllConfigFlags = ModuleType("AllConfigFlags")
AllConfigFlags.ConfigFlags= ConfigFlags
AllConfigFlags.AthConfigFlags = AthConfigFlags_mock # alias for AthConfigFlags
def setupFlags(inputFiles, ):
"""Setup the ConfigFlags according to the input files content.
@@ -310,6 +371,12 @@ def setupFlags(inputFiles, ):
tree = f.CollectionTree
ConfigFlags.Input.Collections = [br.GetName() for br in tree.GetListOfBranches() if '.' not in br.GetName()]
# terrible hack to have truth jets working :
ConfigFlags.Input.TypedCollections = []
if "GEN_EVENT" in ConfigFlags.Input.Collections:
ConfigFlags.Input.TypedCollections = ["McEventCollection#GEN_EVENT"]
return ConfigFlags
@@ -378,13 +445,23 @@ sys.modules['AthenaCommon.SystemOfUnits'] = JetAnalysisCommon.SystemOfUnits
sys.modules['AthenaConfiguration'] = JetAnalysisCommon
sys.modules['AthenaConfiguration.ComponentFactory'] = JetAnalysisCommon.ComponentFactory
sys.modules['AthenaConfiguration.ComponentAccumulator'] = JetAnalysisCommon.ComponentAccumulator
sys.modules['AthenaConfiguration.Enums'] = JetAnalysisCommon.Enums_mock
sys.modules['AthenaCommon.CFElements'] = JetAnalysisCommon.CFElements
sys.modules['AthenaConfiguration.AllConfigFlags'] = JetAnalysisCommon.AllConfigFlags
sys.modules['AthenaConfiguration.AthConfigFlags'] = JetAnalysisCommon.AllConfigFlags
def mock_JetRecTools():
sys.modules['JetRecTools'] = ModuleType('JetRecTools')
sys.modules['JetRecTools.JetRecToolsConfig'] = ModuleType('JetRecToolsConfig')
#*******************************************************************
# hack specific to jets
from JetRecConfig.JetConfigFlags import createJetConfigFlags
# copy standard jet flags
ConfigFlags.Jet = createJetConfigFlags().Jet
import JetRecConfig.JetRecConfig as JetRecConfig
# In Athena the jet config relies on the automatic scheduling of algorithms
@@ -407,6 +484,8 @@ def JetRecCfg_reorder(jetdef, configFlags, returnFinalJetDef=False):
# ************
# reorder EventDensity and PseudoJetAlg
if not hasattr(ROOT, 'EventDensityAthAlg'):
return res
evtDensityAlgs = [ (i,alg) for (i,alg) in enumerate(algs) if alg._cppclass == ROOT.EventDensityAthAlg ]
pjAlgs = [ (i,alg) for (i,alg) in enumerate(algs) if alg._cppclass == ROOT.PseudoJetAlgorithm ]
pairsToswap = []
Loading