From 49cfc906d0669903f29e2a05724739b3e6ecf5aa Mon Sep 17 00:00:00 2001 From: Dimitrios Iliadis <dimitrios.iliadis@cern.ch> Date: Tue, 5 Mar 2024 20:15:59 +0100 Subject: [PATCH] Adding TEST7.py with skimming code for DAODs to D2AODs Adding TEST7.py with skimming code for DAODs to D2AODs --- .../python/DerivationConfigList.py | 6 +- .../python/TEST7.py | 70 +++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 PhysicsAnalysis/DerivationFramework/DerivationFrameworkExamples/python/TEST7.py diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkConfiguration/python/DerivationConfigList.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkConfiguration/python/DerivationConfigList.py index daf63b2251aa..881990da943b 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkConfiguration/python/DerivationConfigList.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkConfiguration/python/DerivationConfigList.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # All derivation framework formats must be listed here # Example formats @@ -14,6 +14,8 @@ from DerivationFrameworkExamples.TEST4 import TEST4Cfg from DerivationFrameworkExamples.TEST5 import TEST5Cfg # Pre-selection example from DerivationFrameworkExamples.TEST6 import TEST6Cfg +# Skimming DAOD->D2AOD with strings +from DerivationFrameworkExamples.TEST7 import TEST7Cfg # Truth (EVNT->xAOD) formats # TRUTH0 - complete copy of HepMC to xAOD truth @@ -137,7 +139,7 @@ from DerivationFrameworkNCB.NCB1 import NCB1Cfg # Avoids compilation warnings from Flake8 -__all__ = ['TEST1Cfg','TEST2Cfg','TEST3Cfg','TEST4Cfg','TEST5Cfg','TEST6Cfg', +__all__ = ['TEST1Cfg','TEST2Cfg','TEST3Cfg','TEST4Cfg','TEST5Cfg','TEST6Cfg','TEST7Cfg', 'TRUTH0Cfg','TRUTH1Cfg','TRUTH3Cfg', 'PHYSCfg','PHYSLITECfg', 'PHYSVALCfg', diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkExamples/python/TEST7.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkExamples/python/TEST7.py new file mode 100644 index 000000000000..0fc9a212fed6 --- /dev/null +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkExamples/python/TEST7.py @@ -0,0 +1,70 @@ +# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration +#!/usr/bin/env python +# TEST7.py - derivation framework example demonstrating skimming via means of string + +from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator +from AthenaConfiguration.ComponentFactory import CompFactory +from AthenaCommon.CFElements import seqAND + +def TEST7SkimmingToolCfg(flags): + """Configure the example skimming tool""" + from TrigDecisionTool.TrigDecisionToolConfig import TrigDecisionToolCfg + acc = ComponentAccumulator() + tdt = acc.getPrimaryAndMerge(TrigDecisionToolCfg(flags)) + acc.addPublicTool(CompFactory.DerivationFramework.xAODStringSkimmingTool(name = "TEST7StringSkimmingTool", + expression = "( count(Muons.pt > (6 * GeV)) + count(Electrons.pt > (6 * GeV)) ) >= 3", + TrigDecisionTool=tdt), + primary = True) + return(acc) + +def TEST7KernelCfg(flags, name='TEST7Kernel', **kwargs): + """Configure the derivation framework driving algorithm (kernel)""" + acc = ComponentAccumulator() + # The next three lines are necessary in case the string skimming tool accesses containers which haven't + # previously been accessed via ReadHandles (as here). One must create a new sequence, list all of the + # accessed container types and keys as ExtraDataForDynamicConsumers (just Muons here) and then set the property + # ProcessDynamicDataDependencies to True for that sequence. The relevant skimming tools must then be attached + # to this sequence. The use of seqAND here isn't relevant since there is only one sequence in use. + # This step isn't needed in case the common augmentations are run first (e.g. with PHYS/PHYSLITE etc). In + # such cases one can omit the next three lines and the sequenceName argument in addEventAlgo. + acc.addSequence( seqAND("TEST7Sequence") ) + acc.getSequence("TEST7Sequence").ExtraDataForDynamicConsumers = ['xAOD::MuonContainer/Muons','xAOD::ElectronContainer/Electrons'] + acc.getSequence("TEST7Sequence").ProcessDynamicDataDependencies = True + skimmingTool = acc.getPrimaryAndMerge(TEST7SkimmingToolCfg(flags)) + DerivationKernel = CompFactory.DerivationFramework.DerivationKernel + acc.addEventAlgo(DerivationKernel(name, SkimmingTools = [skimmingTool]), sequenceName="TEST7Sequence") + return acc + + +def TEST7Cfg(ConfigFlags): + + acc = ComponentAccumulator() + acc.merge(TEST7KernelCfg(ConfigFlags, name="TEST7Kernel")) + + from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg + from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg + from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper + TEST7SlimmingHelper = SlimmingHelper("TEST7SlimmingHelper", NamesAndTypes = ConfigFlags.Input.TypedCollections, ConfigFlags = ConfigFlags) + TEST7SlimmingHelper.SmartCollections = ["EventInfo", + "Electrons", + "Photons", + "Muons", + "PrimaryVertices", + "InDetTrackParticles", + "AntiKt4EMTopoJets", + "AntiKt4EMPFlowJets", + "BTagging_AntiKt4EMPFlow", + "BTagging_AntiKtVR30Rmax4Rmin02Track", + "MET_Baseline_AntiKt4EMTopo", + "MET_Baseline_AntiKt4EMPFlow", + "TauJets", + "DiTauJets", + "DiTauJetsLowPt", + "AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets", + "AntiKtVR30Rmax4Rmin02PV0TrackJets"] + TEST7ItemList = TEST7SlimmingHelper.GetItemList() + + acc.merge(OutputStreamCfg(ConfigFlags, "D2AOD_TEST7", ItemList=TEST7ItemList, AcceptAlgs=["TEST7Kernel"])) + acc.merge(SetupMetaDataForStreamCfg(ConfigFlags, "D2AOD_TEST7", AcceptAlgs=["TEST7Kernel"], propagateMetadataFromInput=True)) + + return acc -- GitLab