From 3f6f2099a23c0491f48a373942c88f62504f7ba1 Mon Sep 17 00:00:00 2001 From: Giovanni Marchiori <giovanni.marchiori@cern.ch> Date: Fri, 23 Jun 2023 17:58:38 +0200 Subject: [PATCH] pip8 and flake fixes for python scripts in DerivationFrameworkEGamma pip8 and flake fixes for python scripts in DerivationFrameworkEGamma --- .../DerivationFrameworkEGamma/python/EGAM1.py | 743 ++++++++------- .../python/EGAM10.py | 495 +++++----- .../python/EGAM11.py | 744 ++++++++------- .../python/EGAM12.py | 570 ++++++----- .../DerivationFrameworkEGamma/python/EGAM2.py | 542 ++++++----- .../DerivationFrameworkEGamma/python/EGAM3.py | 690 ++++++++------ .../DerivationFrameworkEGamma/python/EGAM4.py | 547 ++++++----- .../DerivationFrameworkEGamma/python/EGAM5.py | 542 ++++++----- .../DerivationFrameworkEGamma/python/EGAM7.py | 559 ++++++----- .../DerivationFrameworkEGamma/python/EGAM8.py | 619 ++++++------ .../DerivationFrameworkEGamma/python/EGAM9.py | 507 +++++----- .../python/EGammaCommonConfig.py | 889 +++++++++++------- .../python/EGammaDFConfigFlags.py | 10 +- .../python/EGammaIsoConfig.py | 50 +- .../python/EGammaLRTConfig.py | 147 +-- .../python/EGammaToolsConfig.py | 46 +- .../python/ElectronsCPDetailedContent.py | 52 +- .../python/PhotonsCPDetailedContent.py | 12 +- .../src/EGCrackVetoCleaningTool.cxx | 4 +- 19 files changed, 4459 insertions(+), 3309 deletions(-) diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM1.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM1.py index f335f56b619d..0f3f1fe35743 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM1.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM1.py @@ -1,11 +1,10 @@ # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration -#!/usr/bin/env python -#==================================================================== +# ==================================================================== # EGAM1.py # This defines DAOD_EGAM1, a skimmed DAOD format for Run 3. # Z->ee reduction for central electrons - for electron ID and calibration -# It requires the flag EGAM1 in Derivation_tf.py -#==================================================================== +# It requires the flag EGAM1 in Derivation_tf.py +# ==================================================================== from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory @@ -14,37 +13,43 @@ from AthenaConfiguration.Enums import MetadataCategory from AthenaCommon.SystemOfUnits import MeV from DerivationFrameworkEGamma.PhotonsCPDetailedContent import ( - PhotonsCPDetailedContent ) + PhotonsCPDetailedContent, +) from DerivationFrameworkEGamma.TriggerContent import ( - ExtraContainersTrigger, ExtraContainersElectronTrigger ) - + ExtraContainersTrigger, + ExtraContainersElectronTrigger, +) def EGAM1SkimmingToolCfg(flags): - '''Configure the EGAM1 skimming tool''' + """Configure the EGAM1 skimming tool""" acc = ComponentAccumulator() - expression = ' || '.join([ - '(count( EGAM1_DiElectronMass1 > 50.0*GeV ) >= 1)', - '(count( EGAM1_DiElectronMass2 > 50.0*GeV ) >= 1)', - '(count( EGAM1_DiElectronMass3 > 50.0*GeV ) >= 1)', - '(count( EGAM1_ElectronPhotonMass > 50.0*GeV )>=1)' - ]) - print('EGAM1 skimming expression: ', expression) + expression = " || ".join( + [ + "(count( EGAM1_DiElectronMass1 > 50.0*GeV ) >= 1)", + "(count( EGAM1_DiElectronMass2 > 50.0*GeV ) >= 1)", + "(count( EGAM1_DiElectronMass3 > 50.0*GeV ) >= 1)", + "(count( EGAM1_ElectronPhotonMass > 50.0*GeV )>=1)", + ] + ) + print("EGAM1 skimming expression: ", expression) + + acc.setPrivateTools( + CompFactory.DerivationFramework.xAODStringSkimmingTool( + name="EGAM1SkimmingTool", expression=expression + ) + ) - acc.setPrivateTools( CompFactory.DerivationFramework.xAODStringSkimmingTool( - name = 'EGAM1SkimmingTool', - expression = expression) ) - - return(acc) + return acc def EGAM1ZeeMassTool1Cfg(flags): - '''Configure the EGAM1 ee invariant mass augmentation tool 1''' + """Configure the EGAM1 ee invariant mass augmentation tool 1""" acc = ComponentAccumulator() - # ==================================================================== + # ==================================================================== # 1. di-electron invariant mass for events passing the Z->ee # selection for the e-gamma calibration, based on single e trigger # @@ -54,32 +59,37 @@ def EGAM1ZeeMassTool1Cfg(flags): # mee>50 GeV (cut applied in skimming step later) # ==================================================================== - requirement_tag = ' && '.join(['(Electrons.DFCommonElectronsLHTight)', - '(Electrons.pt > 24.5*GeV)']) - - requirement_probe = ' && '.join(['(Electrons.DFCommonElectronsLHMedium)', - '(Electrons.pt > 19.5*GeV)']) - - acc.setPrivateTools( CompFactory.DerivationFramework.EGInvariantMassTool( - name = 'EGAM1_ZEEMassTool1', - Object1Requirements = requirement_tag, - Object2Requirements = requirement_probe, - StoreGateEntryName = 'EGAM1_DiElectronMass1', - Mass1Hypothesis = 0.511*MeV, - Mass2Hypothesis = 0.511*MeV, - Container1Name = 'Electrons', - Container2Name = 'Electrons', - CheckCharge = True, - DoTransverseMass = False, - MinDeltaR=0.0) ) + requirement_tag = " && ".join( + ["(Electrons.DFCommonElectronsLHTight)", "(Electrons.pt > 24.5*GeV)"] + ) + + requirement_probe = " && ".join( + ["(Electrons.DFCommonElectronsLHMedium)", "(Electrons.pt > 19.5*GeV)"] + ) + + acc.setPrivateTools( + CompFactory.DerivationFramework.EGInvariantMassTool( + name="EGAM1_ZEEMassTool1", + Object1Requirements=requirement_tag, + Object2Requirements=requirement_probe, + StoreGateEntryName="EGAM1_DiElectronMass1", + Mass1Hypothesis=0.511 * MeV, + Mass2Hypothesis=0.511 * MeV, + Container1Name="Electrons", + Container2Name="Electrons", + CheckCharge=True, + DoTransverseMass=False, + MinDeltaR=0.0, + ) + ) return acc def EGAM1ZeeMassTool2Cfg(flags): - '''Configure the EGAM1 ee invariant mass augmentation tool 2''' + """Configure the EGAM1 ee invariant mass augmentation tool 2""" acc = ComponentAccumulator() - + # ==================================================================== # 2. di-electron invariant mass for events passing the Z->e selection # for the e-gamma calibration, based on di-electron triggers @@ -89,27 +99,31 @@ def EGAM1ZeeMassTool2Cfg(flags): # mee>50 GeV (cut applied in skimming step later) # ==================================================================== - requirement = ' && '.join(['(Electrons.DFCommonElectronsLHMedium)', - '(Electrons.pt > 19.5*GeV)']) - - acc.setPrivateTools( CompFactory.DerivationFramework.EGInvariantMassTool( - name = 'EGAM1_ZEEMassTool2', - Object1Requirements = requirement, - Object2Requirements = requirement, - StoreGateEntryName = 'EGAM1_DiElectronMass2', - Mass1Hypothesis = 0.511*MeV, - Mass2Hypothesis = 0.511*MeV, - Container1Name = 'Electrons', - Container2Name = 'Electrons', - CheckCharge = True, - DoTransverseMass = False, - MinDeltaR = 0.0) ) + requirement = " && ".join( + ["(Electrons.DFCommonElectronsLHMedium)", "(Electrons.pt > 19.5*GeV)"] + ) + + acc.setPrivateTools( + CompFactory.DerivationFramework.EGInvariantMassTool( + name="EGAM1_ZEEMassTool2", + Object1Requirements=requirement, + Object2Requirements=requirement, + StoreGateEntryName="EGAM1_DiElectronMass2", + Mass1Hypothesis=0.511 * MeV, + Mass2Hypothesis=0.511 * MeV, + Container1Name="Electrons", + Container2Name="Electrons", + CheckCharge=True, + DoTransverseMass=False, + MinDeltaR=0.0, + ) + ) return acc def EGAM1ZeeMassTool3Cfg(flags): - '''Configure the EGAM1 ee invariant mass augmentation tool 3''' + """Configure the EGAM1 ee invariant mass augmentation tool 3""" acc = ComponentAccumulator() # ==================================================================== @@ -123,29 +137,33 @@ def EGAM1ZeeMassTool3Cfg(flags): # mee>50 GeV (cut applied in skimming step later) # ==================================================================== - requirement_tag = ' && '.join(['(Electrons.DFCommonElectronsLHMedium)', - '(Electrons.pt > 24.5*GeV)']) - - requirement_probe = 'Electrons.pt > 4*GeV' - - acc.setPrivateTools( CompFactory.DerivationFramework.EGInvariantMassTool( - name = 'EGAM1_ZEEMassTool3', - Object1Requirements = requirement_tag, - Object2Requirements = requirement_probe, - StoreGateEntryName = 'EGAM1_DiElectronMass3', - Mass1Hypothesis = 0.511*MeV, - Mass2Hypothesis = 0.511*MeV, - Container1Name = 'Electrons', - Container2Name = 'Electrons', - CheckCharge = False, - DoTransverseMass = False, - MinDeltaR = 0.0) ) + requirement_tag = " && ".join( + ["(Electrons.DFCommonElectronsLHMedium)", "(Electrons.pt > 24.5*GeV)"] + ) + + requirement_probe = "Electrons.pt > 4*GeV" + + acc.setPrivateTools( + CompFactory.DerivationFramework.EGInvariantMassTool( + name="EGAM1_ZEEMassTool3", + Object1Requirements=requirement_tag, + Object2Requirements=requirement_probe, + StoreGateEntryName="EGAM1_DiElectronMass3", + Mass1Hypothesis=0.511 * MeV, + Mass2Hypothesis=0.511 * MeV, + Container1Name="Electrons", + Container2Name="Electrons", + CheckCharge=False, + DoTransverseMass=False, + MinDeltaR=0.0, + ) + ) return acc - + def EGAM1ZegMassToolCfg(flags): - '''Configure the EGAM1 e+photon mass augmentation tool''' + """Configure the EGAM1 e+photon mass augmentation tool""" acc = ComponentAccumulator() # ==================================================================== @@ -160,60 +178,64 @@ def EGAM1ZegMassToolCfg(flags): # mey>50 GeV (cut applied in skimming step later) # ==================================================================== - requirement_tag = ' && '.join(['(Electrons.DFCommonElectronsLHMedium)', - '(Electrons.pt > 24.5*GeV)']) - - requirement_probe = 'DFCommonPhotons_et > 14.5*GeV' - - acc.setPrivateTools( CompFactory.DerivationFramework.EGInvariantMassTool( - name = 'EGAM1_ZEGMassTool', - Object1Requirements = requirement_tag, - Object2Requirements = requirement_probe, - StoreGateEntryName = 'EGAM1_ElectronPhotonMass', - Mass1Hypothesis = 0.511*MeV, - Mass2Hypothesis = 0.511*MeV, - Container1Name = 'Electrons', - Container2Name = 'Photons', - Pt2BranchName = 'DFCommonPhotons_et', - Eta2BranchName = 'DFCommonPhotons_eta', - Phi2BranchName = 'DFCommonPhotons_phi', - CheckCharge = False, - DoTransverseMass = False, - MinDeltaR = 0.0) ) + requirement_tag = " && ".join( + ["(Electrons.DFCommonElectronsLHMedium)", "(Electrons.pt > 24.5*GeV)"] + ) + + requirement_probe = "DFCommonPhotons_et > 14.5*GeV" + + acc.setPrivateTools( + CompFactory.DerivationFramework.EGInvariantMassTool( + name="EGAM1_ZEGMassTool", + Object1Requirements=requirement_tag, + Object2Requirements=requirement_probe, + StoreGateEntryName="EGAM1_ElectronPhotonMass", + Mass1Hypothesis=0.511 * MeV, + Mass2Hypothesis=0.511 * MeV, + Container1Name="Electrons", + Container2Name="Photons", + Pt2BranchName="DFCommonPhotons_et", + Eta2BranchName="DFCommonPhotons_eta", + Phi2BranchName="DFCommonPhotons_phi", + CheckCharge=False, + DoTransverseMass=False, + MinDeltaR=0.0, + ) + ) return acc - # Main algorithm config -def EGAM1KernelCfg(ConfigFlags, name='EGAM1Kernel', **kwargs): - '''Configure the derivation framework driving algorithm (kernel) - for EGAM1''' +def EGAM1KernelCfg(ConfigFlags, name="EGAM1Kernel", **kwargs): + """Configure the derivation framework driving algorithm (kernel) + for EGAM1""" acc = ComponentAccumulator() - # Schedule extra jets collections from JetRecConfig.StandardSmallRJets import AntiKt4PV0Track from JetRecConfig.JetRecConfig import JetRecCfg from JetRecConfig.JetConfigFlags import jetInternalFlags + jetList = [AntiKt4PV0Track] jetInternalFlags.isRecoJob = True - for jd in jetList: acc.merge(JetRecCfg(ConfigFlags,jd)) - + for jd in jetList: + acc.merge(JetRecCfg(ConfigFlags, jd)) # Common augmentations - from DerivationFrameworkPhys.PhysCommonConfig import ( - PhysCommonAugmentationsCfg ) - acc.merge( PhysCommonAugmentationsCfg( - ConfigFlags, - TriggerListsHelper = kwargs['TriggerListsHelper'] ) ) - + from DerivationFrameworkPhys.PhysCommonConfig import PhysCommonAugmentationsCfg + + acc.merge( + PhysCommonAugmentationsCfg( + ConfigFlags, TriggerListsHelper=kwargs["TriggerListsHelper"] + ) + ) # EGAM1 augmentations augmentationTools = [] - #==================================================================== + # ==================================================================== # ee and egamma invariant masses - #==================================================================== + # ==================================================================== EGAM1ZeeMassTool1 = acc.popToolsAndMerge(EGAM1ZeeMassTool1Cfg(ConfigFlags)) acc.addPublicTool(EGAM1ZeeMassTool1) augmentationTools.append(EGAM1ZeeMassTool1) @@ -229,12 +251,14 @@ def EGAM1KernelCfg(ConfigFlags, name='EGAM1Kernel', **kwargs): EGAM1ZegMassTool = acc.popToolsAndMerge(EGAM1ZegMassToolCfg(ConfigFlags)) acc.addPublicTool(EGAM1ZegMassTool) augmentationTools.append(EGAM1ZegMassTool) - - #==================================================================== + + # ==================================================================== # Max Cell energy and time - #==================================================================== + # ==================================================================== from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - MaxCellDecoratorCfg ) + MaxCellDecoratorCfg, + ) + MaxCellDecorator = acc.popToolsAndMerge(MaxCellDecoratorCfg(ConfigFlags)) acc.addPublicTool(MaxCellDecorator) augmentationTools.append(MaxCellDecorator) @@ -242,42 +266,43 @@ def EGAM1KernelCfg(ConfigFlags, name='EGAM1Kernel', **kwargs): # ==================================================================== # Cell reweighter # ==================================================================== - # ==================================================================== # Gain and cluster energies per layer decoration tool # ==================================================================== from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - GainDecoratorCfg, ClusterEnergyPerLayerDecoratorCfg ) + GainDecoratorCfg, + ClusterEnergyPerLayerDecoratorCfg, + ) + GainDecoratorTool = acc.popToolsAndMerge(GainDecoratorCfg(ConfigFlags)) acc.addPublicTool(GainDecoratorTool) augmentationTools.append(GainDecoratorTool) - # might need some modification when cell-level reweighting is implemented + # might need some modification when cell-level reweighting is implemented # (see share/EGAM1.py) - cluster_sizes = (3,7), (5,5), (7,11) + cluster_sizes = (3, 7), (5, 5), (7, 11) for neta, nphi in cluster_sizes: - cename = 'ClusterEnergyPerLayerDecorator_%sx%s' % (neta, nphi) + cename = "ClusterEnergyPerLayerDecorator_%sx%s" % (neta, nphi) ClusterEnergyPerLayerDecorator = acc.popToolsAndMerge( ClusterEnergyPerLayerDecoratorCfg( - ConfigFlags, - neta = neta, - nphi=nphi, - name=cename )) + ConfigFlags, neta=neta, nphi=nphi, name=cename + ) + ) acc.addPublicTool(ClusterEnergyPerLayerDecorator) augmentationTools.append(ClusterEnergyPerLayerDecorator) - # thinning tools thinningTools = [] - streamName = kwargs['StreamName'] + streamName = kwargs["StreamName"] # Track thinning if ConfigFlags.Derivation.Egamma.doTrackThinning: - from DerivationFrameworkInDet.InDetToolsConfig import ( - TrackParticleThinningCfg, MuonTrackParticleThinningCfg, - TauTrackParticleThinningCfg ) + TrackParticleThinningCfg, + MuonTrackParticleThinningCfg, + TauTrackParticleThinningCfg, + ) TrackThinningKeepElectronTracks = True TrackThinningKeepPhotonTracks = True @@ -288,169 +313,206 @@ def EGAM1KernelCfg(ConfigFlags, name='EGAM1Kernel', **kwargs): TrackThinningKeepPVTracks = True # Tracks associated with Electrons - if (TrackThinningKeepElectronTracks): - EGAM1ElectronTPThinningTool = \ + if TrackThinningKeepElectronTracks: + EGAM1ElectronTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM1ElectronTPThinningTool', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM1ElectronTPThinningTool", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM1ElectronTPThinningTool) thinningTools.append(EGAM1ElectronTPThinningTool) # Tracks associated with Electrons (all tracks, large cone, for track # isolation studies of the selected electrons) - if (TrackThinningKeepAllElectronTracks): - EGAM1ElectronTPThinningTool2 = \ + if TrackThinningKeepAllElectronTracks: + EGAM1ElectronTPThinningTool2 = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM1ElectronTPThinningTool2', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 4*GeV', - BestMatchOnly = False, - ConeSize = 0.6) + name="EGAM1ElectronTPThinningTool2", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 4*GeV", + BestMatchOnly=False, + ConeSize=0.6, + ) + ) acc.addPublicTool(EGAM1ElectronTPThinningTool2) thinningTools.append(EGAM1ElectronTPThinningTool2) - + # Tracks associated with Photons - if (TrackThinningKeepPhotonTracks): - EGAM1PhotonTPThinningTool = \ + if TrackThinningKeepPhotonTracks: + EGAM1PhotonTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM1PhotonTPThinningTool', - StreamName = streamName, - SGKey = 'Photons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - GSFConversionVerticesKey = 'GSFConversionVertices', - SelectionString = 'Photons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM1PhotonTPThinningTool", + StreamName=streamName, + SGKey="Photons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + GSFConversionVerticesKey="GSFConversionVertices", + SelectionString="Photons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM1PhotonTPThinningTool) thinningTools.append(EGAM1PhotonTPThinningTool) # Tracks associated with Jets - if (TrackThinningKeepJetTracks): - EGAM1JetTPThinningTool = \ + if TrackThinningKeepJetTracks: + EGAM1JetTPThinningTool = ( CompFactory.DerivationFramework.JetTrackParticleThinning( - name = 'EGAM1JetTPThinningTool', - StreamName = streamName, - JetKey = 'AntiKt4EMPFlowJets', - InDetTrackParticlesKey = 'InDetTrackParticles') + name="EGAM1JetTPThinningTool", + StreamName=streamName, + JetKey="AntiKt4EMPFlowJets", + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) acc.addPublicTool(EGAM1JetTPThinningTool) thinningTools.append(EGAM1JetTPThinningTool) # Tracks associated with Muons - if (TrackThinningKeepMuonTracks): - EGAM1MuonTPThinningTool = \ - acc.getPrimaryAndMerge(MuonTrackParticleThinningCfg( + if TrackThinningKeepMuonTracks: + EGAM1MuonTPThinningTool = acc.getPrimaryAndMerge( + MuonTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM1MuonTPThinningTool', - StreamName = streamName, - MuonKey = 'Muons', - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM1MuonTPThinningTool", + StreamName=streamName, + MuonKey="Muons", + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM1MuonTPThinningTool) # Tracks associated with Taus - if (TrackThinningKeepTauTracks): - EGAM1TauTPThinningTool = \ - acc.getPrimaryAndMerge(TauTrackParticleThinningCfg( + if TrackThinningKeepTauTracks: + EGAM1TauTPThinningTool = acc.getPrimaryAndMerge( + TauTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM1TauTPThinningTool', - StreamName = streamName, - TauKey = 'TauJets', - ConeSize = 0.6, - InDetTrackParticlesKey = 'InDetTrackParticles', - DoTauTracksThinning = True, - TauTracksKey = 'TauTracks') ) + name="EGAM1TauTPThinningTool", + StreamName=streamName, + TauKey="TauJets", + ConeSize=0.6, + InDetTrackParticlesKey="InDetTrackParticles", + DoTauTracksThinning=True, + TauTracksKey="TauTracks", + ) + ) thinningTools.append(EGAM1TauTPThinningTool) # Tracks from primary vertex - thinning_expression = ' && '.join([ - '(InDetTrackParticles.DFCommonTightPrimary)', - '(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta) < 3.0*mm)', - '(InDetTrackParticles.pt > 10*GeV)']) - if (TrackThinningKeepPVTracks): - EGAM1TPThinningTool = \ - acc.getPrimaryAndMerge(TrackParticleThinningCfg( + thinning_expression = " && ".join( + [ + "(InDetTrackParticles.DFCommonTightPrimary)", + "(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3*mm)", + "(InDetTrackParticles.pt>10*GeV)", + ] + ) + if TrackThinningKeepPVTracks: + EGAM1TPThinningTool = acc.getPrimaryAndMerge( + TrackParticleThinningCfg( ConfigFlags, - name = 'EGAM1TPThinningTool', - StreamName = streamName, - SelectionString = thinning_expression, - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM1TPThinningTool", + StreamName=streamName, + SelectionString=thinning_expression, + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM1TPThinningTool) - # keep topoclusters around electrons from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - CaloClusterThinningCfg ) - EGAM1CCTCThinningTool = acc.getPrimaryAndMerge(CaloClusterThinningCfg( - ConfigFlags, - name = 'EGAM1CCTCThinningTool', - StreamName = streamName, - SGKey = 'Electrons', - SelectionString = 'Electrons.pt>4*GeV', - TopoClCollectionSGKey = 'CaloCalTopoClusters', - ConeSize = 0.5) ) + CaloClusterThinningCfg, + ) + + EGAM1CCTCThinningTool = acc.getPrimaryAndMerge( + CaloClusterThinningCfg( + ConfigFlags, + name="EGAM1CCTCThinningTool", + StreamName=streamName, + SGKey="Electrons", + SelectionString="Electrons.pt>4*GeV", + TopoClCollectionSGKey="CaloCalTopoClusters", + ConeSize=0.5, + ) + ) thinningTools.append(EGAM1CCTCThinningTool) - # truth thinning if ConfigFlags.Input.isMC: # W, Z and Higgs - truth_cond_WZH = ' && '.join(['(abs(TruthParticles.pdgId) >= 23)', - '(abs(TruthParticles.pdgId) <= 25)']) + truth_cond_WZH = " && ".join( + ["(abs(TruthParticles.pdgId) >= 23)", "(abs(TruthParticles.pdgId) <= 25)"] + ) # Leptons - truth_cond_lep = ' && '.join(['(abs(TruthParticles.pdgId) >= 11)', - '(abs(TruthParticles.pdgId) <= 16)']) + truth_cond_lep = " && ".join( + ["(abs(TruthParticles.pdgId) >= 11)", "(abs(TruthParticles.pdgId) <= 16)"] + ) # Top quark - truth_cond_top = '(abs(TruthParticles.pdgId) == 6)' + truth_cond_top = "(abs(TruthParticles.pdgId) == 6)" # Photon - truth_cond_gam = ' && '.join(['(abs(TruthParticles.pdgId) == 22)', - '(TruthParticles.pt > 1*GeV)']) + truth_cond_gam = " && ".join( + ["(abs(TruthParticles.pdgId) == 22)", "(TruthParticles.pt > 1*GeV)"] + ) # stable particles - truth_cond_finalState = ' && '.join(['(TruthParticles.status == 1)', - '(TruthParticles.barcode < 200000)']) - truth_expression = '( ' + truth_cond_WZH + ' ) || ' + \ - '( ' + truth_cond_lep + ' ) || ' + \ - '( ' + truth_cond_top + ' ) || ' + \ - '( ' + truth_cond_gam + ' ) || ' + \ - '( ' + truth_cond_finalState + ' )' - print('EGAM1 truth thinning expression: ', truth_expression) - - EGAM1TruthThinningTool = \ - CompFactory.DerivationFramework.GenericTruthThinning( - name = 'EGAM1TruthThinningTool', - StreamName = streamName, - ParticleSelectionString = truth_expression, - PreserveDescendants = False, - PreserveGeneratorDescendants = True, - PreserveAncestors = True) + truth_cond_finalState = " && ".join( + ["(TruthParticles.status == 1)", "(TruthParticles.barcode < 200000)"] + ) + truth_expression = ( + "( " + + truth_cond_WZH + + " ) || " + + "( " + + truth_cond_lep + + " ) || " + + "( " + + truth_cond_top + + " ) || " + + "( " + + truth_cond_gam + + " ) || " + + "( " + + truth_cond_finalState + + " )" + ) + print("EGAM1 truth thinning expression: ", truth_expression) + + EGAM1TruthThinningTool = CompFactory.DerivationFramework.GenericTruthThinning( + name="EGAM1TruthThinningTool", + StreamName=streamName, + ParticleSelectionString=truth_expression, + PreserveDescendants=False, + PreserveGeneratorDescendants=True, + PreserveAncestors=True, + ) acc.addPublicTool(EGAM1TruthThinningTool) thinningTools.append(EGAM1TruthThinningTool) - # skimming skimmingTool = acc.popToolsAndMerge(EGAM1SkimmingToolCfg(ConfigFlags)) acc.addPublicTool(skimmingTool) - # setup the kernel - acc.addEventAlgo(CompFactory.DerivationFramework.DerivationKernel(name, - SkimmingTools = [skimmingTool], - AugmentationTools = augmentationTools, - ThinningTools = thinningTools) ) + acc.addEventAlgo( + CompFactory.DerivationFramework.DerivationKernel( + name, + SkimmingTools=[skimmingTool], + AugmentationTools=augmentationTools, + ThinningTools=thinningTools, + ) + ) return acc def EGAM1Cfg(ConfigFlags): - acc = ComponentAccumulator() # Get the lists of triggers needed for trigger matching. @@ -459,25 +521,31 @@ def EGAM1Cfg(ConfigFlags): # it here and pass it down # TODO: this should ideally be called higher up to avoid it being run # multiple times in a train - + from DerivationFrameworkPhys.TriggerListsHelper import TriggerListsHelper + EGAM1TriggerListsHelper = TriggerListsHelper(ConfigFlags) # configure skimming/thinning/augmentation tools - acc.merge(EGAM1KernelCfg(ConfigFlags, - name = 'EGAM1Kernel', - StreamName = 'StreamDAOD_EGAM1', - TriggerListsHelper = EGAM1TriggerListsHelper)) - + acc.merge( + EGAM1KernelCfg( + ConfigFlags, + name="EGAM1Kernel", + StreamName="StreamDAOD_EGAM1", + TriggerListsHelper=EGAM1TriggerListsHelper, + ) + ) # configure slimming from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper + EGAM1SlimmingHelper = SlimmingHelper( - 'EGAM1SlimmingHelper', - NamesAndTypes = ConfigFlags.Input.TypedCollections, - ConfigFlags = ConfigFlags) + "EGAM1SlimmingHelper", + NamesAndTypes=ConfigFlags.Input.TypedCollections, + ConfigFlags=ConfigFlags, + ) # ------------------------------------------ # containers for which we save all variables @@ -485,83 +553,94 @@ def EGAM1Cfg(ConfigFlags): # baseline EGAM1SlimmingHelper.AllVariables = [ - 'Electrons', - 'GSFTrackParticles', - 'egammaClusters', - 'CaloCalTopoClusters' ] - + "Electrons", + "GSFTrackParticles", + "egammaClusters", + "CaloCalTopoClusters", + ] + # for trigger studies we also add trigger containers MenuType = None if ConfigFlags.Trigger.EDMVersion == 2: - MenuType = 'Run2' + MenuType = "Run2" elif ConfigFlags.Trigger.EDMVersion == 3: - MenuType = 'Run3' + MenuType = "Run3" else: - MenuType = '' + MenuType = "" EGAM1SlimmingHelper.AllVariables += ExtraContainersTrigger[MenuType] EGAM1SlimmingHelper.AllVariables += ExtraContainersElectronTrigger[MenuType] - + # and on MC we also add: if ConfigFlags.Input.isMC: - EGAM1SlimmingHelper.AllVariables +=[ - 'TruthEvents', - 'TruthParticles', - 'TruthVertices', - 'egammaTruthParticles' + EGAM1SlimmingHelper.AllVariables += [ + "TruthEvents", + "TruthParticles", + "TruthVertices", + "egammaTruthParticles", ] - # ------------------------------------------- # containers that we slim # ------------------------------------------- - # first add variables from smart-slimming + # first add variables from smart-slimming # adding only also those for which we add all variables since - # the XXXCPContent.py files also bring in some extra variables + # the XXXCPContent.py files also bring in some extra variables # for other collections - EGAM1SlimmingHelper.SmartCollections = ['Electrons', - 'Photons', - 'Muons', - 'TauJets', - 'PrimaryVertices', - 'InDetTrackParticles', - 'AntiKt4EMPFlowJets', - 'BTagging_AntiKt4EMPFlow', - 'MET_Baseline_AntiKt4EMPFlow', - ] + EGAM1SlimmingHelper.SmartCollections = [ + "Electrons", + "Photons", + "Muons", + "TauJets", + "PrimaryVertices", + "InDetTrackParticles", + "AntiKt4EMPFlowJets", + "BTagging_AntiKt4EMPFlow", + "MET_Baseline_AntiKt4EMPFlow", + ] if ConfigFlags.Input.isMC: - EGAM1SlimmingHelper.SmartCollections += ['AntiKt4TruthJets', - 'AntiKt4TruthDressedWZJets'] + EGAM1SlimmingHelper.SmartCollections += [ + "AntiKt4TruthJets", + "AntiKt4TruthDressedWZJets", + ] # then add extra variables: # muons EGAM1SlimmingHelper.ExtraVariables += [ - 'Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40' ] + "Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40" + ] # conversion vertices EGAM1SlimmingHelper.ExtraVariables += [ - 'GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo', - 'GSFConversionVertices.trackParticleLinks' ] + "GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo", + "GSFConversionVertices.trackParticleLinks", + ] # primary vertices - EGAM1SlimmingHelper.ExtraVariables += [ - 'PrimaryVertices.sumPt2' ] + EGAM1SlimmingHelper.ExtraVariables += ["PrimaryVertices.sumPt2"] # track jets EGAM1SlimmingHelper.ExtraVariables += [ - 'AntiKt4PV0TrackJets.pt.eta.phi.e.m.btaggingLink.constituentLinks' ] + "AntiKt4PV0TrackJets.pt.eta.phi.e.m.btaggingLink.constituentLinks" + ] # energy density - EGAM1SlimmingHelper.ExtraVariables += [ - 'TopoClusterIsoCentralEventShape.Density', - 'TopoClusterIsoForwardEventShape.Density', - 'NeutralParticleFlowIsoCentralEventShape.Density', - 'NeutralParticleFlowIsoForwardEventShape.Density'] + EGAM1SlimmingHelper.ExtraVariables += [ + "TopoClusterIsoCentralEventShape.Density", + "TopoClusterIsoForwardEventShape.Density", + "NeutralParticleFlowIsoCentralEventShape.Density", + "NeutralParticleFlowIsoForwardEventShape.Density", + ] from DerivationFrameworkEGamma import EGammaIsoConfig - pflowIsoVar,densityList,densityDict,acc1 = \ - EGammaIsoConfig.makeEGammaCommonIsoCfg(ConfigFlags) + + ( + pflowIsoVar, + densityList, + densityDict, + acc1, + ) = EGammaIsoConfig.makeEGammaCommonIsoCfg(ConfigFlags) acc.merge(acc1) EGAM1SlimmingHelper.AppendToDictionary.update(densityDict) EGAM1SlimmingHelper.ExtraVariables += densityList @@ -571,28 +650,32 @@ def EGAM1Cfg(ConfigFlags): # photons: gain and cluster energy per layer from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - getGainDecorations, getClusterEnergyPerLayerDecorations ) - gainDecorations = getGainDecorations(acc, 'EGAM1Kernel') - print('EGAM1 gain decorations: ', gainDecorations) + getGainDecorations, + getClusterEnergyPerLayerDecorations, + ) + + gainDecorations = getGainDecorations(acc, "EGAM1Kernel") + print("EGAM1 gain decorations: ", gainDecorations) EGAM1SlimmingHelper.ExtraVariables.extend(gainDecorations) - clusterEnergyDecorations = getClusterEnergyPerLayerDecorations( - acc, 'EGAM1Kernel' ) - print('EGAM1 cluster energy decorations: ', clusterEnergyDecorations) + clusterEnergyDecorations = getClusterEnergyPerLayerDecorations(acc, "EGAM1Kernel") + print("EGAM1 cluster energy decorations: ", clusterEnergyDecorations) EGAM1SlimmingHelper.ExtraVariables.extend(clusterEnergyDecorations) # truth if ConfigFlags.Input.isMC: EGAM1SlimmingHelper.ExtraVariables += [ - 'MuonTruthParticles.e.px.py.pz.status.pdgId.truthOrigin.truthType' ] + "MuonTruthParticles.e.px.py.pz.status.pdgId.truthOrigin.truthType" + ] EGAM1SlimmingHelper.ExtraVariables += [ - 'Photons.truthOrigin.truthType.truthParticleLink' ] + "Photons.truthOrigin.truthType.truthParticleLink" + ] # Add event info if ConfigFlags.Derivation.Egamma.doEventInfoSlimming: - EGAM1SlimmingHelper.SmartCollections.append('EventInfo') + EGAM1SlimmingHelper.SmartCollections.append("EventInfo") else: - EGAM1SlimmingHelper.AllVariables += ['EventInfo'] + EGAM1SlimmingHelper.AllVariables += ["EventInfo"] # Add egamma trigger objects EGAM1SlimmingHelper.IncludeEGammaTriggerContent = True @@ -601,39 +684,57 @@ def EGAM1Cfg(ConfigFlags): # Run 2 if ConfigFlags.Trigger.EDMVersion == 2: from DerivationFrameworkPhys.TriggerMatchingCommonConfig import ( - AddRun2TriggerMatchingToSlimmingHelper ) + AddRun2TriggerMatchingToSlimmingHelper, + ) + AddRun2TriggerMatchingToSlimmingHelper( - SlimmingHelper = EGAM1SlimmingHelper, - OutputContainerPrefix = 'TrigMatch_', - TriggerList = EGAM1TriggerListsHelper.Run2TriggerNamesNoTau) + SlimmingHelper=EGAM1SlimmingHelper, + OutputContainerPrefix="TrigMatch_", + TriggerList=EGAM1TriggerListsHelper.Run2TriggerNamesNoTau, + ) # Run 3 if ConfigFlags.Trigger.EDMVersion == 3: from TrigNavSlimmingMT.TrigNavSlimmingMTConfig import ( - AddRun3TrigNavSlimmingCollectionsToSlimmingHelper ) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper, + ) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper(EGAM1SlimmingHelper) # Run 2 is added here temporarily to allow testing/comparison/debugging from DerivationFrameworkPhys.TriggerMatchingCommonConfig import ( - AddRun2TriggerMatchingToSlimmingHelper ) + AddRun2TriggerMatchingToSlimmingHelper, + ) + AddRun2TriggerMatchingToSlimmingHelper( - SlimmingHelper = EGAM1SlimmingHelper, - OutputContainerPrefix = 'TrigMatch_', - TriggerList = EGAM1TriggerListsHelper.Run3TriggerNamesNoTau) + SlimmingHelper=EGAM1SlimmingHelper, + OutputContainerPrefix="TrigMatch_", + TriggerList=EGAM1TriggerListsHelper.Run3TriggerNamesNoTau, + ) # Add full CellContainer EGAM1SlimmingHelper.StaticContent = [ - 'CaloCellContainer#AllCalo', - 'CaloClusterCellLinkContainer#egammaClusters_links'] - + "CaloCellContainer#AllCalo", + "CaloClusterCellLinkContainer#egammaClusters_links", + ] + EGAM1ItemList = EGAM1SlimmingHelper.GetItemList() - acc.merge(OutputStreamCfg(ConfigFlags, - 'DAOD_EGAM1', - ItemList = EGAM1ItemList, - AcceptAlgs = ['EGAM1Kernel'])) - acc.merge(SetupMetaDataForStreamCfg(ConfigFlags, 'DAOD_EGAM1', - AcceptAlgs=['EGAM1Kernel'], - createMetadata=[ - MetadataCategory.CutFlowMetaData, - MetadataCategory.TruthMetaData, - ])) + acc.merge( + OutputStreamCfg( + ConfigFlags, + "DAOD_EGAM1", + ItemList=EGAM1ItemList, + AcceptAlgs=["EGAM1Kernel"], + ) + ) + acc.merge( + SetupMetaDataForStreamCfg( + ConfigFlags, + "DAOD_EGAM1", + AcceptAlgs=["EGAM1Kernel"], + createMetadata=[ + MetadataCategory.CutFlowMetaData, + MetadataCategory.TruthMetaData, + ], + ) + ) return acc diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM10.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM10.py index fa2df4cac153..a12711c65212 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM10.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM10.py @@ -1,239 +1,256 @@ # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration -#!/usr/bin/env python -#==================================================================== +# ==================================================================== # EGAM10.py # This defines DAOD_EGAM10, a skimmed DAOD format for Run 3. -# Inclusive photon reduction - for e/gamma photon studies +# Inclusive photon reduction - for e/gamma photon studies # (migrated from r21 STDM2) -# It requires the flag EGAM10 in Derivation_tf.py -#==================================================================== +# It requires the flag EGAM10 in Derivation_tf.py +# ==================================================================== from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory from AthenaConfiguration.Enums import MetadataCategory from DerivationFrameworkEGamma.PhotonsCPDetailedContent import ( - PhotonsCPDetailedContent ) + PhotonsCPDetailedContent, +) from DerivationFrameworkEGamma.TriggerContent import ( - singlePhotonTriggers, diPhotonTriggers, - triPhotonTriggers, noalgTriggers ) - -electronRequirements = ' && '.join(['(Electrons.pt > 15*GeV)', - '(abs(Electrons.eta) < 2.5)', - '(Electrons.DFCommonElectronsLHLoose)']) -photonRequirements = ' && '.join(['(DFCommonPhotons_et >= 15*GeV)', - '(abs(DFCommonPhotons_eta) < 2.5)']) + singlePhotonTriggers, + diPhotonTriggers, + triPhotonTriggers, + noalgTriggers, +) + +electronRequirements = " && ".join( + [ + "(Electrons.pt > 15*GeV)", + "(abs(Electrons.eta) < 2.5)", + "(Electrons.DFCommonElectronsLHLoose)", + ] +) +photonRequirements = " && ".join( + ["(DFCommonPhotons_et >= 15*GeV)", "(abs(DFCommonPhotons_eta) < 2.5)"] +) def PhotonPointingToolCfg(ConfigFlags): acc = ComponentAccumulator() - acc.setPrivateTools( CompFactory.CP.PhotonPointingTool( - name = 'EGAM10_PhotonPointingTool', - isSimulation = ConfigFlags.Input.isMC ) ) + acc.setPrivateTools( + CompFactory.CP.PhotonPointingTool( + name="EGAM10_PhotonPointingTool", isSimulation=ConfigFlags.Input.isMC + ) + ) return acc def PhotonVertexSelectionWrapperCfg(ConfigFlags, **kwargs): acc = ComponentAccumulator() if "PhotonPointingTool" not in kwargs: - photonPointingTool = acc.popToolsAndMerge( - PhotonPointingToolCfg(ConfigFlags) ) + photonPointingTool = acc.popToolsAndMerge(PhotonPointingToolCfg(ConfigFlags)) kwargs.setdefault("PhotonPointingTool", photonPointingTool) - acc.setPrivateTools( - CompFactory.DerivationFramework.PhotonVertexSelectionWrapper( **kwargs ) + acc.setPrivateTools( + CompFactory.DerivationFramework.PhotonVertexSelectionWrapper(**kwargs) ) return acc def EGAM10SkimmingToolCfg(flags): - '''Configure the EGAM10 skimming tool''' + """Configure the EGAM10 skimming tool""" acc = ComponentAccumulator() # off-line based selection - photonSelection = '(count(' + photonRequirements + ') >= 1)' - print('EGAM10 offline skimming expression: ', photonSelection) - EGAM10_OfflineSkimmingTool = \ - CompFactory.DerivationFramework.xAODStringSkimmingTool( - name = 'EGAM10_OfflineSkimmingTool', - expression = photonSelection) + photonSelection = "(count(" + photonRequirements + ") >= 1)" + print("EGAM10 offline skimming expression: ", photonSelection) + EGAM10_OfflineSkimmingTool = CompFactory.DerivationFramework.xAODStringSkimmingTool( + name="EGAM10_OfflineSkimmingTool", expression=photonSelection + ) # trigger-based selection MenuType = None if flags.Trigger.EDMVersion == 2: - MenuType = 'Run2' + MenuType = "Run2" elif flags.Trigger.EDMVersion == 3: - MenuType = 'Run3' + MenuType = "Run3" else: - MenuType = '' - allTriggers = singlePhotonTriggers[MenuType] + diPhotonTriggers[MenuType] +\ - triPhotonTriggers[MenuType] + noalgTriggers[MenuType] - #remove duplicates + MenuType = "" + allTriggers = ( + singlePhotonTriggers[MenuType] + + diPhotonTriggers[MenuType] + + triPhotonTriggers[MenuType] + + noalgTriggers[MenuType] + ) + # remove duplicates allTriggers = list(set(allTriggers)) - # can't use trigger API (https://twiki.cern.ch/twiki/bin/view/Atlas/TriggerAPI) because we also need prescaled triggers - print('EGAM10 trigger skimming list (OR): ', allTriggers) - EGAM10_TriggerSkimmingTool = \ - CompFactory.DerivationFramework.TriggerSkimmingTool( - name = 'EGAM10_TriggerSkimmingTool', - TriggerListOR = allTriggers) + print("EGAM10 trigger skimming list (OR): ", allTriggers) + EGAM10_TriggerSkimmingTool = CompFactory.DerivationFramework.TriggerSkimmingTool( + name="EGAM10_TriggerSkimmingTool", TriggerListOR=allTriggers + ) # do the AND of trigger-based and offline-based selection - print('EGAM10 skimming is logical AND of previous selections') + print("EGAM10 skimming is logical AND of previous selections") EGAM10_SkimmingTool = CompFactory.DerivationFramework.FilterCombinationAND( - name = 'EGAM10_SkimmingTool', - FilterList=[EGAM10_OfflineSkimmingTool, EGAM10_TriggerSkimmingTool]) + name="EGAM10_SkimmingTool", + FilterList=[EGAM10_OfflineSkimmingTool, EGAM10_TriggerSkimmingTool], + ) acc.addPublicTool(EGAM10_OfflineSkimmingTool) - acc.addPublicTool(EGAM10_TriggerSkimmingTool) - acc.addPublicTool(EGAM10_SkimmingTool, primary = True) - + acc.addPublicTool(EGAM10_TriggerSkimmingTool) + acc.addPublicTool(EGAM10_SkimmingTool, primary=True) + return acc -def EGAM10KernelCfg(ConfigFlags, name='EGAM10Kernel', **kwargs): - '''Configure the derivation framework driving algorithm (kernel) - for EGAM10''' +def EGAM10KernelCfg(ConfigFlags, name="EGAM10Kernel", **kwargs): + """Configure the derivation framework driving algorithm (kernel) + for EGAM10""" acc = ComponentAccumulator() - # Common augmentations - from DerivationFrameworkPhys.PhysCommonConfig import ( - PhysCommonAugmentationsCfg ) - acc.merge( PhysCommonAugmentationsCfg( - ConfigFlags, - TriggerListsHelper = kwargs['TriggerListsHelper'] ) ) - + from DerivationFrameworkPhys.PhysCommonConfig import PhysCommonAugmentationsCfg + + acc.merge( + PhysCommonAugmentationsCfg( + ConfigFlags, TriggerListsHelper=kwargs["TriggerListsHelper"] + ) + ) # EGAM10 augmentations augmentationTools = [] - #==================================================================== + # ==================================================================== # Max Cell energy and time - #==================================================================== + # ==================================================================== from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - MaxCellDecoratorCfg ) + MaxCellDecoratorCfg, + ) + MaxCellDecorator = acc.popToolsAndMerge(MaxCellDecoratorCfg(ConfigFlags)) acc.addPublicTool(MaxCellDecorator) - augmentationTools.append(MaxCellDecorator) - - + augmentationTools.append(MaxCellDecorator) - #==================================================================== + # ==================================================================== # PhotonVertexSelectionWrapper decoration tool - needs PhotonPointing tool - #==================================================================== - EGAM10_PhotonPointingTool = acc.popToolsAndMerge( - PhotonPointingToolCfg(ConfigFlags)) - + # ==================================================================== + EGAM10_PhotonPointingTool = acc.popToolsAndMerge(PhotonPointingToolCfg(ConfigFlags)) + EGAM10_PhotonVertexSelectionWrapper = acc.popToolsAndMerge( PhotonVertexSelectionWrapperCfg( ConfigFlags, - name = 'EGAM10_PhotonVertexSelectionWrapper', - PhotonPointingTool = EGAM10_PhotonPointingTool, - DecorationPrefix = 'EGAM10', - PhotonContainer = 'Photons', - VertexContainer = 'PrimaryVertices') ) + name="EGAM10_PhotonVertexSelectionWrapper", + PhotonPointingTool=EGAM10_PhotonPointingTool, + DecorationPrefix="EGAM10", + PhotonContainer="Photons", + VertexContainer="PrimaryVertices", + ) + ) acc.addPublicTool(EGAM10_PhotonVertexSelectionWrapper) augmentationTools += [EGAM10_PhotonVertexSelectionWrapper] - # ==================================================================== # Gain and cluster energies per layer decoration tool # ==================================================================== from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - GainDecoratorCfg, ClusterEnergyPerLayerDecoratorCfg ) + GainDecoratorCfg, + ClusterEnergyPerLayerDecoratorCfg, + ) + GainDecoratorTool = acc.popToolsAndMerge(GainDecoratorCfg(ConfigFlags)) acc.addPublicTool(GainDecoratorTool) augmentationTools.append(GainDecoratorTool) - cluster_sizes = (3,7), (5,5), (7,11) + cluster_sizes = (3, 7), (5, 5), (7, 11) for neta, nphi in cluster_sizes: - cename = 'ClusterEnergyPerLayerDecorator_%sx%s' % (neta, nphi) + cename = "ClusterEnergyPerLayerDecorator_%sx%s" % (neta, nphi) ClusterEnergyPerLayerDecorator = acc.popToolsAndMerge( ClusterEnergyPerLayerDecoratorCfg( - ConfigFlags, - neta = neta, - nphi=nphi, - name=cename )) + ConfigFlags, neta=neta, nphi=nphi, name=cename + ) + ) acc.addPublicTool(ClusterEnergyPerLayerDecorator) augmentationTools.append(ClusterEnergyPerLayerDecorator) - # thinning tools thinningTools = [] - streamName = kwargs['StreamName'] + streamName = kwargs["StreamName"] # Track thinning if ConfigFlags.Derivation.Egamma.doTrackThinning: - TrackThinningKeepElectronTracks = True TrackThinningKeepPhotonTracks = True TrackThinningKeepAllElectronTracks = True # Tracks associated with high-pT Electrons (deltaR=0.6) - if (TrackThinningKeepElectronTracks): - EGAM10ElectronTPThinningTool = \ + if TrackThinningKeepElectronTracks: + EGAM10ElectronTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM10ElectronTPThinningTool', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = electronRequirements, - BestMatchOnly = True, - ConeSize = 0.6) + name="EGAM10ElectronTPThinningTool", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString=electronRequirements, + BestMatchOnly=True, + ConeSize=0.6, + ) + ) acc.addPublicTool(EGAM10ElectronTPThinningTool) thinningTools.append(EGAM10ElectronTPThinningTool) # Tracks associated with Photons - if (TrackThinningKeepPhotonTracks): - EGAM10PhotonTPThinningTool = \ + if TrackThinningKeepPhotonTracks: + EGAM10PhotonTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM10PhotonTPThinningTool', - StreamName = streamName, - SGKey = 'Photons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - GSFConversionVerticesKey = 'GSFConversionVertices', - SelectionString = photonRequirements, - BestMatchOnly = False, - ConeSize = 0.6) + name="EGAM10PhotonTPThinningTool", + StreamName=streamName, + SGKey="Photons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + GSFConversionVerticesKey="GSFConversionVertices", + SelectionString=photonRequirements, + BestMatchOnly=False, + ConeSize=0.6, + ) + ) acc.addPublicTool(EGAM10PhotonTPThinningTool) thinningTools.append(EGAM10PhotonTPThinningTool) # Tracks associated with all Electrons (for ambiguity resolver tool) - if (TrackThinningKeepAllElectronTracks): - EGAM10ElectronTPThinningToolAR = \ + if TrackThinningKeepAllElectronTracks: + EGAM10ElectronTPThinningToolAR = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM10ElectronTPThinningToolAR', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = electronRequirements, - BestMatchOnly = True) + name="EGAM10ElectronTPThinningToolAR", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString=electronRequirements, + BestMatchOnly=True, + ) + ) acc.addPublicTool(EGAM10ElectronTPThinningToolAR) thinningTools.append(EGAM10ElectronTPThinningToolAR) - # skimming skimmingTool = acc.getPrimaryAndMerge(EGAM10SkimmingToolCfg(ConfigFlags)) # setup the kernel - acc.addEventAlgo(CompFactory.DerivationFramework.DerivationKernel(name, - SkimmingTools = [skimmingTool], - AugmentationTools = augmentationTools, - ThinningTools = thinningTools) ) + acc.addEventAlgo( + CompFactory.DerivationFramework.DerivationKernel( + name, + SkimmingTools=[skimmingTool], + AugmentationTools=augmentationTools, + ThinningTools=thinningTools, + ) + ) return acc - def EGAM10Cfg(ConfigFlags): - acc = ComponentAccumulator() - # Get the lists of triggers needed for trigger matching. # This is needed at this scope (for the slimming) and further down # in the config chain for actually configuring the matching, so we create @@ -242,58 +259,62 @@ def EGAM10Cfg(ConfigFlags): # multiple times in a train. # TODO: restrict it to relevant triggers from DerivationFrameworkPhys.TriggerListsHelper import TriggerListsHelper + EGAM10TriggerListsHelper = TriggerListsHelper(ConfigFlags) # configure skimming/thinning/augmentation tools - acc.merge(EGAM10KernelCfg(ConfigFlags, - name = 'EGAM10Kernel', - StreamName = 'StreamDAOD_EGAM10', - TriggerListsHelper = EGAM10TriggerListsHelper)) - + acc.merge( + EGAM10KernelCfg( + ConfigFlags, + name="EGAM10Kernel", + StreamName="StreamDAOD_EGAM10", + TriggerListsHelper=EGAM10TriggerListsHelper, + ) + ) # configure slimming from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper - EGAM10SlimmingHelper = SlimmingHelper( - 'EGAM10SlimmingHelper', - NamesAndTypes = ConfigFlags.Input.TypedCollections, - ConfigFlags = ConfigFlags ) + EGAM10SlimmingHelper = SlimmingHelper( + "EGAM10SlimmingHelper", + NamesAndTypes=ConfigFlags.Input.TypedCollections, + ConfigFlags=ConfigFlags, + ) # ------------------------------------------ # containers for which we save all variables # ------------------------------------------- # baseline - EGAM10SlimmingHelper.AllVariables =[ - 'CaloCalTopoClusters'] + EGAM10SlimmingHelper.AllVariables = ["CaloCalTopoClusters"] # and on MC we also add: if ConfigFlags.Input.isMC: EGAM10SlimmingHelper.AppendToDictionary.update( - {"TruthIsoCentralEventShape" : "xAOD::EventShape", - "TruthIsoCentralEventShapeAux" : "xAOD::EventShapeAuxInfo", - "TruthIsoForwardEventShape" : "xAOD::EventShape", - "TruthIsoForwardEventShapeAux" : "xAOD::EventShapeAuxInfo"} + { + "TruthIsoCentralEventShape": "xAOD::EventShape", + "TruthIsoCentralEventShapeAux": "xAOD::EventShapeAuxInfo", + "TruthIsoForwardEventShape": "xAOD::EventShape", + "TruthIsoForwardEventShapeAux": "xAOD::EventShapeAuxInfo", + } ) EGAM10SlimmingHelper.AllVariables += [ - 'TruthEvents', - 'TruthParticles', - 'TruthVertices', - 'TruthMuons', - 'TruthElectrons', - 'TruthPhotons', - 'TruthNeutrinos', - 'TruthTaus', - 'AntiKt4TruthJets', - 'AntiKt4TruthDressedWZJets', - 'egammaTruthParticles', - 'TruthIsoCentralEventShape', - 'TruthIsoForwardEventShape'] - - - + "TruthEvents", + "TruthParticles", + "TruthVertices", + "TruthMuons", + "TruthElectrons", + "TruthPhotons", + "TruthNeutrinos", + "TruthTaus", + "AntiKt4TruthJets", + "AntiKt4TruthDressedWZJets", + "egammaTruthParticles", + "TruthIsoCentralEventShape", + "TruthIsoForwardEventShape", + ] # ------------------------------------------- # containers that we slim @@ -301,109 +322,129 @@ def EGAM10Cfg(ConfigFlags): # first add variables from smart-slimming # adding only also those for which we add all variables since - # the XXXCPContent.py files also bring in some extra variables + # the XXXCPContent.py files also bring in some extra variables # for other collections # muons, tau, MET, b-tagging could be switched off if not needed # and use too much space - EGAM10SlimmingHelper.SmartCollections = ['Electrons', - 'Photons', - 'InDetTrackParticles', - 'PrimaryVertices', - 'AntiKt4EMPFlowJets' ] + EGAM10SlimmingHelper.SmartCollections = [ + "Electrons", + "Photons", + "InDetTrackParticles", + "PrimaryVertices", + "AntiKt4EMPFlowJets", + ] if ConfigFlags.Input.isMC: - EGAM10SlimmingHelper.SmartCollections += ['AntiKt4TruthJets', - 'AntiKt4TruthDressedWZJets'] + EGAM10SlimmingHelper.SmartCollections += [ + "AntiKt4TruthJets", + "AntiKt4TruthDressedWZJets", + ] # then add extra variables: # egamma clusters EGAM10SlimmingHelper.ExtraVariables += [ - 'egammaClusters.PHI2CALOFRAME.ETA2CALOFRAME.phi_sampl'] + "egammaClusters.PHI2CALOFRAME.ETA2CALOFRAME.phi_sampl" + ] # photons EGAM10SlimmingHelper.ExtraVariables += [ - 'Photons.ptcone30.ptcone40.f3.f3core', - 'Photons.maxEcell_time.maxEcell_energy.maxEcell_gain.maxEcell_onlId', - 'Photons.maxEcell_x.maxEcell_y.maxEcell_z', - 'Photons.ptcone40_Nonprompt_All_MaxWeightTTVA_pt1000', - 'Photons.ptcone40_Nonprompt_All_MaxWeightTTVA_pt500', - 'Photons.ptcone20_Nonprompt_All_MaxWeightTTVA_pt500', - 'Photons.ptvarcone30_Nonprompt_All_MaxWeightTTVA_pt1000', - 'Photons.ptvarcone30_Nonprompt_All_MaxWeightTTVA_pt500'] + "Photons.ptcone30.ptcone40.f3.f3core", + "Photons.maxEcell_time.maxEcell_energy.maxEcell_gain.maxEcell_onlId", + "Photons.maxEcell_x.maxEcell_y.maxEcell_z", + "Photons.ptcone40_Nonprompt_All_MaxWeightTTVA_pt1000", + "Photons.ptcone40_Nonprompt_All_MaxWeightTTVA_pt500", + "Photons.ptcone20_Nonprompt_All_MaxWeightTTVA_pt500", + "Photons.ptvarcone30_Nonprompt_All_MaxWeightTTVA_pt1000", + "Photons.ptvarcone30_Nonprompt_All_MaxWeightTTVA_pt500", + ] # electrons EGAM10SlimmingHelper.ExtraVariables += [ - 'Electrons.topoetcone30.topoetcone40.ptcone20.ptcone30', - 'Electrons.ptcone40.maxEcell_time.maxEcell_energy.maxEcell_gain', - 'Electrons.maxEcell_onlId.maxEcell_x.maxEcell_y.maxEcell_z'] + "Electrons.topoetcone30.topoetcone40.ptcone20.ptcone30", + "Electrons.ptcone40.maxEcell_time.maxEcell_energy.maxEcell_gain", + "Electrons.maxEcell_onlId.maxEcell_x.maxEcell_y.maxEcell_z", + ] # primary vertices EGAM10SlimmingHelper.ExtraVariables += [ - 'PrimaryVertices.covariance.trackWeights.sumPt2.EGAM10_sumPt', - 'PrimaryVertices.EGAM10_sumPt2.EGAM10_pt.EGAM10_eta.EGAM10_phi'] + "PrimaryVertices.covariance.trackWeights.sumPt2.EGAM10_sumPt", + "PrimaryVertices.EGAM10_sumPt2.EGAM10_pt.EGAM10_eta.EGAM10_phi", + ] # tracks EGAM10SlimmingHelper.ExtraVariables += [ - 'InDetTrackParticles.TTVA_AMVFVertices.TTVA_AMVFWeights'] + "InDetTrackParticles.TTVA_AMVFVertices.TTVA_AMVFWeights" + ] # photons and electrons: detailed shower shape variables and track variables EGAM10SlimmingHelper.ExtraVariables += PhotonsCPDetailedContent - + # photons: gain and cluster energy per layer from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - getGainDecorations, getClusterEnergyPerLayerDecorations ) - gainDecorations = getGainDecorations(acc, 'EGAM10Kernel') - print('EGAM10 gain decorations: ', gainDecorations) + getGainDecorations, + getClusterEnergyPerLayerDecorations, + ) + + gainDecorations = getGainDecorations(acc, "EGAM10Kernel") + print("EGAM10 gain decorations: ", gainDecorations) EGAM10SlimmingHelper.ExtraVariables.extend(gainDecorations) - clusterEnergyDecorations = getClusterEnergyPerLayerDecorations( - acc, 'EGAM10Kernel' ) - print('EGAM10 cluster energy decorations: ', clusterEnergyDecorations) + clusterEnergyDecorations = getClusterEnergyPerLayerDecorations(acc, "EGAM10Kernel") + print("EGAM10 cluster energy decorations: ", clusterEnergyDecorations) EGAM10SlimmingHelper.ExtraVariables.extend(clusterEnergyDecorations) # energy density - EGAM10SlimmingHelper.ExtraVariables += [ - 'TopoClusterIsoCentralEventShape.Density', - 'TopoClusterIsoForwardEventShape.Density', + EGAM10SlimmingHelper.ExtraVariables += [ + "TopoClusterIsoCentralEventShape.Density", + "TopoClusterIsoForwardEventShape.Density", ] from DerivationFrameworkEGamma import EGammaIsoConfig - pflowIsoVar,densityList,densityDict,acc1 = \ - EGammaIsoConfig.makeEGammaCommonIsoCfg(ConfigFlags) + + ( + pflowIsoVar, + densityList, + densityDict, + acc1, + ) = EGammaIsoConfig.makeEGammaCommonIsoCfg(ConfigFlags) acc.merge(acc1) EGAM10SlimmingHelper.AppendToDictionary.update(densityDict) - EGAM10SlimmingHelper.ExtraVariables += \ - densityList + [f'Photons{pflowIsoVar}'] + EGAM10SlimmingHelper.ExtraVariables += densityList + [f"Photons{pflowIsoVar}"] # To have ptcone40, needed for efficiency measurement with MM from IsolationAlgs.DerivationTrackIsoConfig import DerivationTrackIsoCfg - acc.merge(DerivationTrackIsoCfg(ConfigFlags, - object_types = ('Photons',), - ptCuts = (500,1000), - postfix = 'Extra')) + + acc.merge( + DerivationTrackIsoCfg( + ConfigFlags, object_types=("Photons",), ptCuts=(500, 1000), postfix="Extra" + ) + ) # truth if ConfigFlags.Input.isMC: EGAM10SlimmingHelper.ExtraVariables += [ - 'Electrons.truthOrigin.truthType.truthParticleLink.truthPdgId', - 'Electrons.lastEgMotherTruthType.lastEgMotherTruthOrigin', - 'Electrons.lastEgMotherTruthParticleLink.lastEgMotherPdgId', - 'Electrons.firstEgMotherTruthType.firstEgMotherTruthOrigin', - 'Electrons.firstEgMotherTruthParticleLink.firstEgMotherPdgId'] + "Electrons.truthOrigin.truthType.truthParticleLink.truthPdgId", + "Electrons.lastEgMotherTruthType.lastEgMotherTruthOrigin", + "Electrons.lastEgMotherTruthParticleLink.lastEgMotherPdgId", + "Electrons.firstEgMotherTruthType.firstEgMotherTruthOrigin", + "Electrons.firstEgMotherTruthParticleLink.firstEgMotherPdgId", + ] EGAM10SlimmingHelper.ExtraVariables += [ - 'Photons.truthOrigin.truthType.truthParticleLink' ] + "Photons.truthOrigin.truthType.truthParticleLink" + ] EGAM10SlimmingHelper.ExtraVariables += [ - 'TruthIsoCentralEventShape.DensitySigma.Density.DensityArea', - 'TruthIsoForwardEventShape.DensitySigma.Density.DensityArea'] + "TruthIsoCentralEventShape.DensitySigma.Density.DensityArea", + "TruthIsoForwardEventShape.DensitySigma.Density.DensityArea", + ] # Add event info if ConfigFlags.Derivation.Egamma.doEventInfoSlimming: - EGAM10SlimmingHelper.SmartCollections.append('EventInfo') + EGAM10SlimmingHelper.SmartCollections.append("EventInfo") else: - EGAM10SlimmingHelper.AllVariables += ['EventInfo'] - + EGAM10SlimmingHelper.AllVariables += ["EventInfo"] + # Add egamma trigger objects EGAM10SlimmingHelper.IncludeEGammaTriggerContent = True @@ -411,29 +452,41 @@ def EGAM10Cfg(ConfigFlags): # Run 2 if ConfigFlags.Trigger.EDMVersion == 2: from DerivationFrameworkPhys.TriggerMatchingCommonConfig import ( - AddRun2TriggerMatchingToSlimmingHelper ) + AddRun2TriggerMatchingToSlimmingHelper, + ) + AddRun2TriggerMatchingToSlimmingHelper( - SlimmingHelper = EGAM10SlimmingHelper, - OutputContainerPrefix = 'TrigMatch_', - TriggerList = EGAM10TriggerListsHelper.Run2TriggerNamesNoTau) + SlimmingHelper=EGAM10SlimmingHelper, + OutputContainerPrefix="TrigMatch_", + TriggerList=EGAM10TriggerListsHelper.Run2TriggerNamesNoTau, + ) # Run 3 if ConfigFlags.Trigger.EDMVersion == 3: from TrigNavSlimmingMT.TrigNavSlimmingMTConfig import ( - AddRun3TrigNavSlimmingCollectionsToSlimmingHelper ) - AddRun3TrigNavSlimmingCollectionsToSlimmingHelper(EGAM10SlimmingHelper) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper, + ) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper(EGAM10SlimmingHelper) EGAM10ItemList = EGAM10SlimmingHelper.GetItemList() - acc.merge(OutputStreamCfg(ConfigFlags, - 'DAOD_EGAM10', - ItemList = EGAM10ItemList, - AcceptAlgs = ['EGAM10Kernel'])) - acc.merge(SetupMetaDataForStreamCfg(ConfigFlags, 'DAOD_EGAM10', - AcceptAlgs=['EGAM10Kernel'], - createMetadata=[ - MetadataCategory.CutFlowMetaData, - MetadataCategory.TruthMetaData, - ])) + acc.merge( + OutputStreamCfg( + ConfigFlags, + "DAOD_EGAM10", + ItemList=EGAM10ItemList, + AcceptAlgs=["EGAM10Kernel"], + ) + ) + acc.merge( + SetupMetaDataForStreamCfg( + ConfigFlags, + "DAOD_EGAM10", + AcceptAlgs=["EGAM10Kernel"], + createMetadata=[ + MetadataCategory.CutFlowMetaData, + MetadataCategory.TruthMetaData, + ], + ) + ) return acc - diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM11.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM11.py index 04db404e04f2..8b86a2dd4d8a 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM11.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM11.py @@ -1,12 +1,11 @@ # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration -#!/usr/bin/env python -#==================================================================== +# ==================================================================== # EGAM11.py # This defines DAOD_EGAM11, a skimmed DAOD format for Run 3. # Z->ee reduction for central electrons - for electron ID and calibration # Adaptation of EGAM1 for heavy ions -# It requires the flag EGAM11 in Derivation_tf.py -#==================================================================== +# It requires the flag EGAM11 in Derivation_tf.py +# ==================================================================== from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory @@ -15,35 +14,38 @@ from AthenaConfiguration.Enums import MetadataCategory from AthenaCommon.SystemOfUnits import MeV from DerivationFrameworkEGamma.PhotonsCPDetailedContent import ( - PhotonsCPDetailedContent ) - + PhotonsCPDetailedContent, +) def EGAM11SkimmingToolCfg(flags): - '''Configure the EGAM11 skimming tool''' + """Configure the EGAM11 skimming tool""" acc = ComponentAccumulator() - expression = ' || '.join([ - '(count( EGAM11_DiElectronMass1 > 50.0*GeV ) >= 1)', - '(count( EGAM11_DiElectronMass2 > 50.0*GeV ) >= 1)', - '(count( EGAM11_DiElectronMass3 > 50.0*GeV ) >= 1)', - '(count( EGAM11_ElectronPhotonMass > 50.0*GeV )>=1)' - ]) - print('EGAM11 skimming expression: ', expression) + expression = " || ".join( + [ + "(count( EGAM11_DiElectronMass1 > 50.0*GeV ) >= 1)", + "(count( EGAM11_DiElectronMass2 > 50.0*GeV ) >= 1)", + "(count( EGAM11_DiElectronMass3 > 50.0*GeV ) >= 1)", + "(count( EGAM11_ElectronPhotonMass > 50.0*GeV )>=1)", + ] + ) + print("EGAM11 skimming expression: ", expression) + + acc.setPrivateTools( + CompFactory.DerivationFramework.xAODStringSkimmingTool( + name="EGAM11SkimmingTool", expression=expression, TrigDecisionTool="" + ) + ) - acc.setPrivateTools( CompFactory.DerivationFramework.xAODStringSkimmingTool( - name = 'EGAM11SkimmingTool', - expression = expression, - TrigDecisionTool = "") ) - - return(acc) + return acc def EGAM11ZeeMassTool1Cfg(flags): - '''Configure the EGAM11 ee invariant mass augmentation tool 1''' + """Configure the EGAM11 ee invariant mass augmentation tool 1""" acc = ComponentAccumulator() - # ==================================================================== + # ==================================================================== # 1. di-electron invariant mass for events passing the Z->ee # selection for the e-gamma calibration # @@ -53,32 +55,37 @@ def EGAM11ZeeMassTool1Cfg(flags): # mee>50 GeV (cut applied in skimming step later) # ==================================================================== - requirement_tag = ' && '.join(['(Electrons.DFCommonElectronsLHTight)', - '(Electrons.pt > 24.5*GeV)']) - - requirement_probe = ' && '.join(['(Electrons.DFCommonElectronsLHMedium)', - '(Electrons.pt > 19.5*GeV)']) - - acc.setPrivateTools( CompFactory.DerivationFramework.EGInvariantMassTool( - name = 'EGAM11_ZEEMassTool1', - Object1Requirements = requirement_tag, - Object2Requirements = requirement_probe, - StoreGateEntryName = 'EGAM11_DiElectronMass1', - Mass1Hypothesis = 0.511*MeV, - Mass2Hypothesis = 0.511*MeV, - Container1Name = 'Electrons', - Container2Name = 'Electrons', - CheckCharge = True, - DoTransverseMass = False, - MinDeltaR=0.0) ) + requirement_tag = " && ".join( + ["(Electrons.DFCommonElectronsLHTight)", "(Electrons.pt > 24.5*GeV)"] + ) + + requirement_probe = " && ".join( + ["(Electrons.DFCommonElectronsLHMedium)", "(Electrons.pt > 19.5*GeV)"] + ) + + acc.setPrivateTools( + CompFactory.DerivationFramework.EGInvariantMassTool( + name="EGAM11_ZEEMassTool1", + Object1Requirements=requirement_tag, + Object2Requirements=requirement_probe, + StoreGateEntryName="EGAM11_DiElectronMass1", + Mass1Hypothesis=0.511 * MeV, + Mass2Hypothesis=0.511 * MeV, + Container1Name="Electrons", + Container2Name="Electrons", + CheckCharge=True, + DoTransverseMass=False, + MinDeltaR=0.0, + ) + ) return acc def EGAM11ZeeMassTool2Cfg(flags): - '''Configure the EGAM11 ee invariant mass augmentation tool 2''' + """Configure the EGAM11 ee invariant mass augmentation tool 2""" acc = ComponentAccumulator() - + # ==================================================================== # 2. di-electron invariant mass for events passing the Z->e selection # for the e-gamma calibration @@ -88,27 +95,31 @@ def EGAM11ZeeMassTool2Cfg(flags): # mee>50 GeV (cut applied in skimming step later) # ==================================================================== - requirement = ' && '.join(['(Electrons.DFCommonElectronsLHMedium)', - '(Electrons.pt > 19.5*GeV)']) - - acc.setPrivateTools( CompFactory.DerivationFramework.EGInvariantMassTool( - name = 'EGAM11_ZEEMassTool2', - Object1Requirements = requirement, - Object2Requirements = requirement, - StoreGateEntryName = 'EGAM11_DiElectronMass2', - Mass1Hypothesis = 0.511*MeV, - Mass2Hypothesis = 0.511*MeV, - Container1Name = 'Electrons', - Container2Name = 'Electrons', - CheckCharge = True, - DoTransverseMass = False, - MinDeltaR = 0.0) ) + requirement = " && ".join( + ["(Electrons.DFCommonElectronsLHMedium)", "(Electrons.pt > 19.5*GeV)"] + ) + + acc.setPrivateTools( + CompFactory.DerivationFramework.EGInvariantMassTool( + name="EGAM11_ZEEMassTool2", + Object1Requirements=requirement, + Object2Requirements=requirement, + StoreGateEntryName="EGAM11_DiElectronMass2", + Mass1Hypothesis=0.511 * MeV, + Mass2Hypothesis=0.511 * MeV, + Container1Name="Electrons", + Container2Name="Electrons", + CheckCharge=True, + DoTransverseMass=False, + MinDeltaR=0.0, + ) + ) return acc def EGAM11ZeeMassTool3Cfg(flags): - '''Configure the EGAM11 ee invariant mass augmentation tool 3''' + """Configure the EGAM11 ee invariant mass augmentation tool 3""" acc = ComponentAccumulator() # ==================================================================== @@ -121,29 +132,33 @@ def EGAM11ZeeMassTool3Cfg(flags): # mee>50 GeV (cut applied in skimming step later) # ==================================================================== - requirement_tag = ' && '.join(['(Electrons.DFCommonElectronsLHMedium)', - '(Electrons.pt > 24.5*GeV)']) - - requirement_probe = 'Electrons.pt > 4*GeV' - - acc.setPrivateTools( CompFactory.DerivationFramework.EGInvariantMassTool( - name = 'EGAM11_ZEEMassTool3', - Object1Requirements = requirement_tag, - Object2Requirements = requirement_probe, - StoreGateEntryName = 'EGAM11_DiElectronMass3', - Mass1Hypothesis = 0.511*MeV, - Mass2Hypothesis = 0.511*MeV, - Container1Name = 'Electrons', - Container2Name = 'Electrons', - CheckCharge = False, - DoTransverseMass = False, - MinDeltaR = 0.0) ) + requirement_tag = " && ".join( + ["(Electrons.DFCommonElectronsLHMedium)", "(Electrons.pt > 24.5*GeV)"] + ) + + requirement_probe = "Electrons.pt > 4*GeV" + + acc.setPrivateTools( + CompFactory.DerivationFramework.EGInvariantMassTool( + name="EGAM11_ZEEMassTool3", + Object1Requirements=requirement_tag, + Object2Requirements=requirement_probe, + StoreGateEntryName="EGAM11_DiElectronMass3", + Mass1Hypothesis=0.511 * MeV, + Mass2Hypothesis=0.511 * MeV, + Container1Name="Electrons", + Container2Name="Electrons", + CheckCharge=False, + DoTransverseMass=False, + MinDeltaR=0.0, + ) + ) return acc - + def EGAM11ZegMassToolCfg(flags): - '''Configure the EGAM11 e+photon mass augmentation tool''' + """Configure the EGAM11 e+photon mass augmentation tool""" acc = ComponentAccumulator() # ==================================================================== @@ -158,45 +173,48 @@ def EGAM11ZegMassToolCfg(flags): # mey>50 GeV (cut applied in skimming step later) # ==================================================================== - requirement_tag = ' && '.join(['(Electrons.DFCommonElectronsLHMedium)', - '(Electrons.pt > 24.5*GeV)']) - - requirement_probe = 'DFCommonPhotons_et > 14.5*GeV' - - acc.setPrivateTools( CompFactory.DerivationFramework.EGInvariantMassTool( - name = 'EGAM11_ZEGMassTool', - Object1Requirements = requirement_tag, - Object2Requirements = requirement_probe, - StoreGateEntryName = 'EGAM11_ElectronPhotonMass', - Mass1Hypothesis = 0.511*MeV, - Mass2Hypothesis = 0.511*MeV, - Container1Name = 'Electrons', - Container2Name = 'Photons', - Pt2BranchName = 'DFCommonPhotons_et', - Eta2BranchName = 'DFCommonPhotons_eta', - Phi2BranchName = 'DFCommonPhotons_phi', - CheckCharge = False, - DoTransverseMass = False, - MinDeltaR = 0.0) ) + requirement_tag = " && ".join( + ["(Electrons.DFCommonElectronsLHMedium)", "(Electrons.pt > 24.5*GeV)"] + ) + + requirement_probe = "DFCommonPhotons_et > 14.5*GeV" + + acc.setPrivateTools( + CompFactory.DerivationFramework.EGInvariantMassTool( + name="EGAM11_ZEGMassTool", + Object1Requirements=requirement_tag, + Object2Requirements=requirement_probe, + StoreGateEntryName="EGAM11_ElectronPhotonMass", + Mass1Hypothesis=0.511 * MeV, + Mass2Hypothesis=0.511 * MeV, + Container1Name="Electrons", + Container2Name="Photons", + Pt2BranchName="DFCommonPhotons_et", + Eta2BranchName="DFCommonPhotons_eta", + Phi2BranchName="DFCommonPhotons_phi", + CheckCharge=False, + DoTransverseMass=False, + MinDeltaR=0.0, + ) + ) return acc - # Main algorithm config -def EGAM11KernelCfg(ConfigFlags, name='EGAM11Kernel', **kwargs): - '''Configure the derivation framework driving algorithm (kernel) - for EGAM11''' +def EGAM11KernelCfg(ConfigFlags, name="EGAM11Kernel", **kwargs): + """Configure the derivation framework driving algorithm (kernel) + for EGAM11""" acc = ComponentAccumulator() - # Schedule extra jets collections from JetRecConfig.StandardSmallRJets import AntiKt4PV0Track, AntiKt4EMTopo from JetRecConfig.JetRecConfig import JetRecCfg from JetRecConfig.JetConfigFlags import jetInternalFlags + jetList = [AntiKt4PV0Track, AntiKt4EMTopo] jetInternalFlags.isRecoJob = True - for jd in jetList: acc.merge(JetRecCfg(ConfigFlags,jd)) - + for jd in jetList: + acc.merge(JetRecCfg(ConfigFlags, jd)) # Common augmentations # cannot use PhysCommon sequence because @@ -206,62 +224,93 @@ def EGAM11KernelCfg(ConfigFlags, name='EGAM11Kernel', **kwargs): from DerivationFrameworkInDet.InDetCommonConfig import InDetCommonCfg from DerivationFrameworkMuons.MuonsCommonConfig import MuonsCommonCfg from DerivationFrameworkEGamma.EGammaCommonConfig import EGammaCommonCfg - acc.merge(InDetCommonCfg(ConfigFlags, - DoVertexFinding = ConfigFlags.Tracking.doVertexFinding, - AddPseudoTracks = ConfigFlags.Tracking.doPseudoTracking, - DecoLRTTTVA = False, - DoR3LargeD0 = ConfigFlags.Tracking.doLargeD0, - StoreSeparateLargeD0Container = ConfigFlags.Tracking.storeSeparateLargeD0Container, - MergeLRT = False)) + + TrackingFlags = ConfigFlags.Tracking + acc.merge( + InDetCommonCfg( + ConfigFlags, + DoVertexFinding=TrackingFlags.doVertexFinding, + AddPseudoTracks=TrackingFlags.doPseudoTracking, + DecoLRTTTVA=False, + DoR3LargeD0=ConfigFlags.Tracking.doLargeD0, + StoreSeparateLargeD0Container=TrackingFlags.storeSeparateLargeD0Container, + MergeLRT=False, + ) + ) acc.merge(MuonsCommonCfg(ConfigFlags)) acc.merge(EGammaCommonCfg(ConfigFlags)) - + # jet cleaning # standard way in PhysCommon is # - calculate tau ID (needed for default jet OR) # - decorate jets with overlap removal # - do event cleaning # but taus are missing in HI derivations so need to do differently - + # Decorate if jet passed JVT criteria from JetJvtEfficiency.JetJvtEfficiencyToolConfig import getJvtEffToolCfg + algName = "DFJet_EventCleaning_passJvtAlg" - passJvtTool = acc.popToolsAndMerge(getJvtEffToolCfg(ConfigFlags, 'AntiKt4EMTopo')) + passJvtTool = acc.popToolsAndMerge(getJvtEffToolCfg(ConfigFlags, "AntiKt4EMTopo")) passJvtTool.PassJVTKey = "AntiKt4EMTopoJets.DFCommonJets_passJvt" - acc.addEventAlgo(CompFactory.JetDecorationAlg(algName, JetContainer='AntiKt4EMTopoJets', Decorators=[passJvtTool])) + acc.addEventAlgo( + CompFactory.JetDecorationAlg( + algName, JetContainer="AntiKt4EMTopoJets", Decorators=[passJvtTool] + ) + ) # Decorate if jet passes OR and save decoration DFCommonJets_passOR - # Use modified OR that does not check overlaps with tauls + # Use modified OR that does not check overlaps with tauls from AssociationUtils.AssociationUtilsConfig import OverlapRemovalToolCfg - outputLabel = 'DFCommonJets_passOR' - bJetLabel = '' #default - tauLabel = '' #workaround for missing taus - tauKey = '' #workaround for missing taus - orTool = acc.popToolsAndMerge(OverlapRemovalToolCfg(ConfigFlags,outputLabel=outputLabel,bJetLabel=bJetLabel,doTaus=False)) - algOR = CompFactory.OverlapRemovalGenUseAlg('OverlapRemovalGenUseAlg', - OverlapLabel=outputLabel, - OverlapRemovalTool=orTool, - TauKey=tauKey, - TauLabel=tauLabel, - BJetLabel=bJetLabel) + + outputLabel = "DFCommonJets_passOR" + bJetLabel = "" # default + tauLabel = "" # workaround for missing taus + tauKey = "" # workaround for missing taus + orTool = acc.popToolsAndMerge( + OverlapRemovalToolCfg( + ConfigFlags, outputLabel=outputLabel, bJetLabel=bJetLabel, doTaus=False + ) + ) + algOR = CompFactory.OverlapRemovalGenUseAlg( + "OverlapRemovalGenUseAlg", + OverlapLabel=outputLabel, + OverlapRemovalTool=orTool, + TauKey=tauKey, + TauLabel=tauLabel, + BJetLabel=bJetLabel, + ) acc.addEventAlgo(algOR) # Do the cleaning - from JetSelectorTools.JetSelectorToolsConfig import EventCleaningToolCfg,JetCleaningToolCfg - workingPoints = ['Loose'] + from JetSelectorTools.JetSelectorToolsConfig import ( + EventCleaningToolCfg, + JetCleaningToolCfg, + ) + + workingPoints = ["Loose"] prefix = "DFCommonJets_" for wp in workingPoints: - - cleaningLevel = wp + 'Bad' + cleaningLevel = wp + "Bad" # LLP WPs have a slightly different name format - if 'LLP' in wp: - cleaningLevel = wp.replace('LLP', 'BadLLP') - - jetCleaningTool = acc.popToolsAndMerge(JetCleaningToolCfg(ConfigFlags, 'JetCleaningTool_'+cleaningLevel, 'AntiKt4EMTopoJets', cleaningLevel, False)) + if "LLP" in wp: + cleaningLevel = wp.replace("LLP", "BadLLP") + + jetCleaningTool = acc.popToolsAndMerge( + JetCleaningToolCfg( + ConfigFlags, + "JetCleaningTool_" + cleaningLevel, + "AntiKt4EMTopoJets", + cleaningLevel, + False, + ) + ) acc.addPublicTool(jetCleaningTool) - ecTool = acc.popToolsAndMerge(EventCleaningToolCfg(ConfigFlags,'EventCleaningTool_' + wp, cleaningLevel)) + ecTool = acc.popToolsAndMerge( + EventCleaningToolCfg(ConfigFlags, "EventCleaningTool_" + wp, cleaningLevel) + ) ecTool.JetCleanPrefix = prefix ecTool.JetContainer = "AntiKt4EMTopoJets" ecTool.JetCleaningTool = jetCleaningTool @@ -269,21 +318,22 @@ def EGAM11KernelCfg(ConfigFlags, name='EGAM11Kernel', **kwargs): # Alg to calculate event-level and jet-level cleaning variables # Only store event-level flags for Loose* WPs - eventCleanAlg = CompFactory.EventCleaningTestAlg('EventCleaningTestAlg_'+wp, - EventCleaningTool=ecTool, - JetCollectionName="AntiKt4EMTopoJets", - EventCleanPrefix=prefix, - CleaningLevel=cleaningLevel, - doEvent = ('Loose' in wp)) + eventCleanAlg = CompFactory.EventCleaningTestAlg( + "EventCleaningTestAlg_" + wp, + EventCleaningTool=ecTool, + JetCollectionName="AntiKt4EMTopoJets", + EventCleanPrefix=prefix, + CleaningLevel=cleaningLevel, + doEvent=("Loose" in wp), + ) acc.addEventAlgo(eventCleanAlg) - # EGAM11 augmentations augmentationTools = [] - #==================================================================== + # ==================================================================== # ee and egamma invariant masses - #==================================================================== + # ==================================================================== EGAM11ZeeMassTool1 = acc.popToolsAndMerge(EGAM11ZeeMassTool1Cfg(ConfigFlags)) acc.addPublicTool(EGAM11ZeeMassTool1) augmentationTools.append(EGAM11ZeeMassTool1) @@ -299,18 +349,18 @@ def EGAM11KernelCfg(ConfigFlags, name='EGAM11Kernel', **kwargs): EGAM11ZegMassTool = acc.popToolsAndMerge(EGAM11ZegMassToolCfg(ConfigFlags)) acc.addPublicTool(EGAM11ZegMassTool) augmentationTools.append(EGAM11ZegMassTool) - # thinning tools thinningTools = [] - streamName = kwargs['StreamName'] + streamName = kwargs["StreamName"] # Track thinning if ConfigFlags.Derivation.Egamma.doTrackThinning: - from DerivationFrameworkInDet.InDetToolsConfig import ( - TrackParticleThinningCfg, MuonTrackParticleThinningCfg, - TauTrackParticleThinningCfg ) + TrackParticleThinningCfg, + MuonTrackParticleThinningCfg, + TauTrackParticleThinningCfg, + ) TrackThinningKeepElectronTracks = True TrackThinningKeepPhotonTracks = True @@ -321,186 +371,228 @@ def EGAM11KernelCfg(ConfigFlags, name='EGAM11Kernel', **kwargs): TrackThinningKeepPVTracks = True # Tracks associated with Electrons - if (TrackThinningKeepElectronTracks): - EGAM11ElectronTPThinningTool = \ + if TrackThinningKeepElectronTracks: + EGAM11ElectronTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM11ElectronTPThinningTool', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM11ElectronTPThinningTool", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM11ElectronTPThinningTool) thinningTools.append(EGAM11ElectronTPThinningTool) # Tracks associated with Electrons (all tracks, large cone, for track # isolation studies of the selected electrons) - if (TrackThinningKeepAllElectronTracks): - EGAM11ElectronTPThinningTool2 = \ + if TrackThinningKeepAllElectronTracks: + EGAM11ElectronTPThinningTool2 = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM11ElectronTPThinningTool2', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 4*GeV', - BestMatchOnly = False, - ConeSize = 0.6) + name="EGAM11ElectronTPThinningTool2", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 4*GeV", + BestMatchOnly=False, + ConeSize=0.6, + ) + ) acc.addPublicTool(EGAM11ElectronTPThinningTool2) thinningTools.append(EGAM11ElectronTPThinningTool2) - + # Tracks associated with Photons - if (TrackThinningKeepPhotonTracks): - EGAM11PhotonTPThinningTool = \ + if TrackThinningKeepPhotonTracks: + EGAM11PhotonTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM11PhotonTPThinningTool', - StreamName = streamName, - SGKey = 'Photons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - GSFConversionVerticesKey = 'GSFConversionVertices', - SelectionString = 'Photons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM11PhotonTPThinningTool", + StreamName=streamName, + SGKey="Photons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + GSFConversionVerticesKey="GSFConversionVertices", + SelectionString="Photons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM11PhotonTPThinningTool) thinningTools.append(EGAM11PhotonTPThinningTool) # Tracks associated with Jets - if (TrackThinningKeepJetTracks): - EGAM11JetTPThinningTool = \ + if TrackThinningKeepJetTracks: + EGAM11JetTPThinningTool = ( CompFactory.DerivationFramework.JetTrackParticleThinning( - name = 'EGAM11JetTPThinningTool', - StreamName = streamName, - JetKey = 'AntiKt4EMTopoJets', - InDetTrackParticlesKey = 'InDetTrackParticles') + name="EGAM11JetTPThinningTool", + StreamName=streamName, + JetKey="AntiKt4EMTopoJets", + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) acc.addPublicTool(EGAM11JetTPThinningTool) thinningTools.append(EGAM11JetTPThinningTool) # Tracks associated with Muons - if (TrackThinningKeepMuonTracks): - EGAM11MuonTPThinningTool = \ - acc.getPrimaryAndMerge(MuonTrackParticleThinningCfg( + if TrackThinningKeepMuonTracks: + EGAM11MuonTPThinningTool = acc.getPrimaryAndMerge( + MuonTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM11MuonTPThinningTool', - StreamName = streamName, - MuonKey = 'Muons', - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM11MuonTPThinningTool", + StreamName=streamName, + MuonKey="Muons", + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM11MuonTPThinningTool) # Tracks associated with Taus - if (TrackThinningKeepTauTracks): - EGAM11TauTPThinningTool = \ - acc.getPrimaryAndMerge(TauTrackParticleThinningCfg( + if TrackThinningKeepTauTracks: + EGAM11TauTPThinningTool = acc.getPrimaryAndMerge( + TauTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM11TauTPThinningTool', - StreamName = streamName, - TauKey = 'TauJets', - ConeSize = 0.6, - InDetTrackParticlesKey = 'InDetTrackParticles', - DoTauTracksThinning = True, - TauTracksKey = 'TauTracks') ) + name="EGAM11TauTPThinningTool", + StreamName=streamName, + TauKey="TauJets", + ConeSize=0.6, + InDetTrackParticlesKey="InDetTrackParticles", + DoTauTracksThinning=True, + TauTracksKey="TauTracks", + ) + ) thinningTools.append(EGAM11TauTPThinningTool) # Tracks from primary vertex - thinning_expression = ' && '.join([ - '(InDetTrackParticles.DFCommonTightPrimary)', - '(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta) < 3.0*mm)', - '(InDetTrackParticles.pt > 10*GeV)']) - if (TrackThinningKeepPVTracks): - EGAM11TPThinningTool = \ - acc.getPrimaryAndMerge(TrackParticleThinningCfg( + thinning_expression = " && ".join( + [ + "(InDetTrackParticles.DFCommonTightPrimary)", + "(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3mm)", + "(InDetTrackParticles.pt>10*GeV)", + ] + ) + if TrackThinningKeepPVTracks: + EGAM11TPThinningTool = acc.getPrimaryAndMerge( + TrackParticleThinningCfg( ConfigFlags, - name = 'EGAM11TPThinningTool', - StreamName = streamName, - SelectionString = thinning_expression, - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM11TPThinningTool", + StreamName=streamName, + SelectionString=thinning_expression, + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM11TPThinningTool) - # keep topoclusters around electrons from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - CaloClusterThinningCfg ) - EGAM11CCTCThinningTool = acc.getPrimaryAndMerge(CaloClusterThinningCfg( - ConfigFlags, - name = 'EGAM11CCTCThinningTool', - StreamName = streamName, - SGKey = 'Electrons', - SelectionString = 'Electrons.pt>4*GeV', - TopoClCollectionSGKey = 'CaloCalTopoClusters', - ConeSize = 0.5) ) + CaloClusterThinningCfg, + ) + + EGAM11CCTCThinningTool = acc.getPrimaryAndMerge( + CaloClusterThinningCfg( + ConfigFlags, + name="EGAM11CCTCThinningTool", + StreamName=streamName, + SGKey="Electrons", + SelectionString="Electrons.pt>4*GeV", + TopoClCollectionSGKey="CaloCalTopoClusters", + ConeSize=0.5, + ) + ) thinningTools.append(EGAM11CCTCThinningTool) - # truth thinning if ConfigFlags.Input.isMC: # W, Z and Higgs - truth_cond_WZH = ' && '.join(['(abs(TruthParticles.pdgId) >= 23)', - '(abs(TruthParticles.pdgId) <= 25)']) + truth_cond_WZH = " && ".join( + ["(abs(TruthParticles.pdgId) >= 23)", "(abs(TruthParticles.pdgId) <= 25)"] + ) # Leptons - truth_cond_lep = ' && '.join(['(abs(TruthParticles.pdgId) >= 11)', - '(abs(TruthParticles.pdgId) <= 16)']) + truth_cond_lep = " && ".join( + ["(abs(TruthParticles.pdgId) >= 11)", "(abs(TruthParticles.pdgId) <= 16)"] + ) # Top quark - truth_cond_top = '(abs(TruthParticles.pdgId) == 6)' + truth_cond_top = "(abs(TruthParticles.pdgId) == 6)" # Photon - truth_cond_gam = ' && '.join(['(abs(TruthParticles.pdgId) == 22)', - '(TruthParticles.pt > 1*GeV)']) + truth_cond_gam = " && ".join( + ["(abs(TruthParticles.pdgId) == 22)", "(TruthParticles.pt > 1*GeV)"] + ) # stable particles - truth_cond_finalState = ' && '.join(['(TruthParticles.status == 1)', - '(TruthParticles.barcode < 200000)']) - truth_expression = '( ' + truth_cond_WZH + ' ) || ' + \ - '( ' + truth_cond_lep + ' ) || ' + \ - '( ' + truth_cond_top + ' ) || ' + \ - '( ' + truth_cond_gam + ' ) || ' + \ - '( ' + truth_cond_finalState + ' )' - print('EGAM11 truth thinning expression: ', truth_expression) - - EGAM11TruthThinningTool = \ - CompFactory.DerivationFramework.GenericTruthThinning( - name = 'EGAM11TruthThinningTool', - StreamName = streamName, - ParticleSelectionString = truth_expression, - PreserveDescendants = False, - PreserveGeneratorDescendants = True, - PreserveAncestors = True) + truth_cond_finalState = " && ".join( + ["(TruthParticles.status == 1)", "(TruthParticles.barcode < 200000)"] + ) + truth_expression = ( + "( " + + truth_cond_WZH + + " ) || " + + "( " + + truth_cond_lep + + " ) || " + + "( " + + truth_cond_top + + " ) || " + + "( " + + truth_cond_gam + + " ) || " + + "( " + + truth_cond_finalState + + " )" + ) + print("EGAM11 truth thinning expression: ", truth_expression) + + EGAM11TruthThinningTool = CompFactory.DerivationFramework.GenericTruthThinning( + name="EGAM11TruthThinningTool", + StreamName=streamName, + ParticleSelectionString=truth_expression, + PreserveDescendants=False, + PreserveGeneratorDescendants=True, + PreserveAncestors=True, + ) acc.addPublicTool(EGAM11TruthThinningTool) thinningTools.append(EGAM11TruthThinningTool) - # skimming skimmingTool = acc.popToolsAndMerge(EGAM11SkimmingToolCfg(ConfigFlags)) acc.addPublicTool(skimmingTool) - # setup the kernel - acc.addEventAlgo(CompFactory.DerivationFramework.DerivationKernel(name, - SkimmingTools = [skimmingTool], - AugmentationTools = augmentationTools, - ThinningTools = thinningTools) ) + acc.addEventAlgo( + CompFactory.DerivationFramework.DerivationKernel( + name, + SkimmingTools=[skimmingTool], + AugmentationTools=augmentationTools, + ThinningTools=thinningTools, + ) + ) return acc def EGAM11Cfg(ConfigFlags): - acc = ComponentAccumulator() # configure skimming/thinning/augmentation tools - acc.merge(EGAM11KernelCfg(ConfigFlags, - name = 'EGAM11Kernel', - StreamName = 'StreamDAOD_EGAM11', - TriggerListsHelper = None)) - + acc.merge( + EGAM11KernelCfg( + ConfigFlags, + name="EGAM11Kernel", + StreamName="StreamDAOD_EGAM11", + TriggerListsHelper=None, + ) + ) # configure slimming from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper + EGAM11SlimmingHelper = SlimmingHelper( - 'EGAM11SlimmingHelper', - NamesAndTypes = ConfigFlags.Input.TypedCollections, - ConfigFlags = ConfigFlags) + "EGAM11SlimmingHelper", + NamesAndTypes=ConfigFlags.Input.TypedCollections, + ConfigFlags=ConfigFlags, + ) # ------------------------------------------ # containers for which we save all variables @@ -508,64 +600,69 @@ def EGAM11Cfg(ConfigFlags): # baseline EGAM11SlimmingHelper.AllVariables = [ - 'Electrons', - 'GSFTrackParticles', - 'egammaClusters', - 'CaloCalTopoClusters' ] - + "Electrons", + "GSFTrackParticles", + "egammaClusters", + "CaloCalTopoClusters", + ] + # on MC we also add: if ConfigFlags.Input.isMC: - EGAM11SlimmingHelper.AllVariables +=[ - 'TruthEvents', - 'TruthParticles', - 'TruthVertices', - 'egammaTruthParticles' + EGAM11SlimmingHelper.AllVariables += [ + "TruthEvents", + "TruthParticles", + "TruthVertices", + "egammaTruthParticles", ] - # ------------------------------------------- # containers that we slim # ------------------------------------------- - # first add variables from smart-slimming + # first add variables from smart-slimming # adding only also those for which we add all variables since - # the XXXCPContent.py files also bring in some extra variables + # the XXXCPContent.py files also bring in some extra variables # for other collections - EGAM11SlimmingHelper.SmartCollections = ['Electrons', - 'Photons', - 'Muons', - 'TauJets', - 'PrimaryVertices', - 'InDetTrackParticles', - 'AntiKt4EMTopoJets', - ] + EGAM11SlimmingHelper.SmartCollections = [ + "Electrons", + "Photons", + "Muons", + "TauJets", + "PrimaryVertices", + "InDetTrackParticles", + "AntiKt4EMTopoJets", + ] if ConfigFlags.Input.isMC: - EGAM11SlimmingHelper.SmartCollections += ['AntiKt4TruthJets', - 'AntiKt4TruthDressedWZJets'] + EGAM11SlimmingHelper.SmartCollections += [ + "AntiKt4TruthJets", + "AntiKt4TruthDressedWZJets", + ] # then add extra variables: # muons EGAM11SlimmingHelper.ExtraVariables += [ - 'Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40' ] + "Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40" + ] # conversion vertices EGAM11SlimmingHelper.ExtraVariables += [ - 'GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo', - 'GSFConversionVertices.trackParticleLinks' ] + "GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo", + "GSFConversionVertices.trackParticleLinks", + ] # primary vertices - EGAM11SlimmingHelper.ExtraVariables += [ - 'PrimaryVertices.sumPt2' ] + EGAM11SlimmingHelper.ExtraVariables += ["PrimaryVertices.sumPt2"] # track jets EGAM11SlimmingHelper.ExtraVariables += [ - 'AntiKt4PV0TrackJets.pt.eta.phi.e.m.btaggingLink.constituentLinks' ] + "AntiKt4PV0TrackJets.pt.eta.phi.e.m.btaggingLink.constituentLinks" + ] # energy density - EGAM11SlimmingHelper.ExtraVariables += [ - 'TopoClusterIsoCentralEventShape.Density', - 'TopoClusterIsoForwardEventShape.Density', + EGAM11SlimmingHelper.ExtraVariables += [ + "TopoClusterIsoCentralEventShape.Density", + "TopoClusterIsoForwardEventShape.Density", ] # photons: detailed shower shape variables @@ -574,37 +671,48 @@ def EGAM11Cfg(ConfigFlags): # truth if ConfigFlags.Input.isMC: EGAM11SlimmingHelper.ExtraVariables += [ - 'MuonTruthParticles.e.px.py.pz.status.pdgId.truthOrigin.truthType' ] + "MuonTruthParticles.e.px.py.pz.status.pdgId.truthOrigin.truthType" + ] EGAM11SlimmingHelper.ExtraVariables += [ - 'Photons.truthOrigin.truthType.truthParticleLink' ] + "Photons.truthOrigin.truthType.truthParticleLink" + ] # Add event info if ConfigFlags.Derivation.Egamma.doEventInfoSlimming: - EGAM11SlimmingHelper.SmartCollections.append('EventInfo') + EGAM11SlimmingHelper.SmartCollections.append("EventInfo") else: - EGAM11SlimmingHelper.AllVariables += ['EventInfo'] + EGAM11SlimmingHelper.AllVariables += ["EventInfo"] # Add HIEventShape and CaloSums variables for heavy ions - EGAM11SlimmingHelper.AllVariables += ['HIEventShape'] - EGAM11SlimmingHelper.AllVariables += ['CaloSums'] + EGAM11SlimmingHelper.AllVariables += ["HIEventShape"] + EGAM11SlimmingHelper.AllVariables += ["CaloSums"] # Add full CellContainer EGAM11SlimmingHelper.StaticContent = [ - 'CaloCellContainer#AllCalo', - 'CaloClusterCellLinkContainer#egammaClusters_links'] - - EGAM11ItemList = EGAM11SlimmingHelper.GetItemList() - acc.merge(OutputStreamCfg(ConfigFlags, - 'DAOD_EGAM11', - ItemList = EGAM11ItemList, - AcceptAlgs = ['EGAM11Kernel'])) - acc.merge(SetupMetaDataForStreamCfg(ConfigFlags, 'DAOD_EGAM11', - AcceptAlgs=['EGAM11Kernel'], - createMetadata=[ - MetadataCategory.CutFlowMetaData, - MetadataCategory.TruthMetaData, - ])) + "CaloCellContainer#AllCalo", + "CaloClusterCellLinkContainer#egammaClusters_links", + ] + EGAM11ItemList = EGAM11SlimmingHelper.GetItemList() + acc.merge( + OutputStreamCfg( + ConfigFlags, + "DAOD_EGAM11", + ItemList=EGAM11ItemList, + AcceptAlgs=["EGAM11Kernel"], + ) + ) + acc.merge( + SetupMetaDataForStreamCfg( + ConfigFlags, + "DAOD_EGAM11", + AcceptAlgs=["EGAM11Kernel"], + createMetadata=[ + MetadataCategory.CutFlowMetaData, + MetadataCategory.TruthMetaData, + ], + ) + ) return acc diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM12.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM12.py index b31db40fc044..f4a490373a6b 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM12.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM12.py @@ -1,21 +1,21 @@ # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration -#!/usr/bin/env python -#==================================================================== +# ==================================================================== # EGAM12.py # This defines DAOD_EGAM12, a skimmed DAOD format for Run 3. # Keep events passing OR of electron triggers, or inclusive # electron selection, to retain fake electron candidates -# Adaptation of EGAM7 format for heavy ion runs (no triggers, no pflow +# Adaptation of EGAM7 format for heavy ion runs (no triggers, no pflow # jets, extra containers) -# It requires the flag EGAM12 in Derivation_tf.py -#==================================================================== +# It requires the flag EGAM12 in Derivation_tf.py +# ==================================================================== from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory from AthenaConfiguration.Enums import MetadataCategory from DerivationFrameworkEGamma.PhotonsCPDetailedContent import ( - PhotonsCPDetailedContent ) + PhotonsCPDetailedContent, +) # some info missing to calculate extra decorations @@ -24,36 +24,40 @@ addMaxCellDecorations = False def EGAM12SkimmingToolCfg(flags): - '''Configure the EGAM12 skimming tool''' + """Configure the EGAM12 skimming tool""" acc = ComponentAccumulator() # off-line based selection - expression = 'count(Electrons.pt > 4.5*GeV) >= 1' - print('EGAM12 offline skimming expression: ', expression) - EGAM12_OfflineSkimmingTool = \ - CompFactory.DerivationFramework.xAODStringSkimmingTool( - name = 'EGAM12_OfflineSkimmingTool', - expression = expression, - TrigDecisionTool = "") + expression = "count(Electrons.pt > 4.5*GeV) >= 1" + print("EGAM12 offline skimming expression: ", expression) + EGAM12_OfflineSkimmingTool = CompFactory.DerivationFramework.xAODStringSkimmingTool( + name="EGAM12_OfflineSkimmingTool", expression=expression, TrigDecisionTool="" + ) - acc.addPublicTool(EGAM12_OfflineSkimmingTool, primary = True) + acc.addPublicTool(EGAM12_OfflineSkimmingTool, primary=True) return acc -def EGAM12KernelCfg(ConfigFlags, name='EGAM12Kernel', **kwargs): - '''Configure the derivation framework driving algorithm (kernel) - for EGAM12''' +def EGAM12KernelCfg(ConfigFlags, name="EGAM12Kernel", **kwargs): + """Configure the derivation framework driving algorithm (kernel) + for EGAM12""" acc = ComponentAccumulator() # Schedule extra jets collections - from JetRecConfig.StandardSmallRJets import AntiKt4EMTopo, AntiKt4PV0Track, AntiKt4Truth + from JetRecConfig.StandardSmallRJets import ( + AntiKt4EMTopo, + AntiKt4PV0Track, + AntiKt4Truth, + ) from JetRecConfig.JetRecConfig import JetRecCfg from JetRecConfig.JetConfigFlags import jetInternalFlags - jetList = [AntiKt4EMTopo, AntiKt4PV0Track, AntiKt4Truth] + + jetList = [AntiKt4EMTopo, AntiKt4PV0Track, AntiKt4Truth] jetInternalFlags.isRecoJob = True - for jd in jetList: acc.merge(JetRecCfg(ConfigFlags,jd)) - JetKey = 'AntiKt4EMTopoJets' + for jd in jetList: + acc.merge(JetRecCfg(ConfigFlags, jd)) + JetKey = "AntiKt4EMTopoJets" # Common augmentations # cannot use PhysCommon sequence because @@ -63,13 +67,20 @@ def EGAM12KernelCfg(ConfigFlags, name='EGAM12Kernel', **kwargs): from DerivationFrameworkInDet.InDetCommonConfig import InDetCommonCfg from DerivationFrameworkMuons.MuonsCommonConfig import MuonsCommonCfg from DerivationFrameworkEGamma.EGammaCommonConfig import EGammaCommonCfg - acc.merge(InDetCommonCfg(ConfigFlags, - DoVertexFinding = ConfigFlags.Tracking.doVertexFinding, - AddPseudoTracks = ConfigFlags.Tracking.doPseudoTracking, - DecoLRTTTVA = False, - DoR3LargeD0 = ConfigFlags.Tracking.doLargeD0, - StoreSeparateLargeD0Container = ConfigFlags.Tracking.storeSeparateLargeD0Container, - MergeLRT = False)) + + TrackingFlags = ConfigFlags.Tracking + + acc.merge( + InDetCommonCfg( + ConfigFlags, + DoVertexFinding=TrackingFlags.doVertexFinding, + AddPseudoTracks=TrackingFlags.doPseudoTracking, + DecoLRTTTVA=False, + DoR3LargeD0=TrackingFlags.doLargeD0, + StoreSeparateLargeD0Container=TrackingFlags.storeSeparateLargeD0Container, + MergeLRT=False, + ) + ) acc.merge(MuonsCommonCfg(ConfigFlags)) acc.merge(EGammaCommonCfg(ConfigFlags)) # jet cleaning @@ -81,43 +92,68 @@ def EGAM12KernelCfg(ConfigFlags, name='EGAM12Kernel', **kwargs): # Decorate if jet passed JVT criteria from JetJvtEfficiency.JetJvtEfficiencyToolConfig import getJvtEffToolCfg + algName = "DFJet_EventCleaning_passJvtAlg" - passJvtTool = acc.popToolsAndMerge(getJvtEffToolCfg(ConfigFlags, 'AntiKt4EMTopo')) + passJvtTool = acc.popToolsAndMerge(getJvtEffToolCfg(ConfigFlags, "AntiKt4EMTopo")) passJvtTool.PassJVTKey = "AntiKt4EMTopoJets.DFCommonJets_passJvt" - acc.addEventAlgo(CompFactory.JetDecorationAlg(algName, JetContainer='AntiKt4EMTopoJets', Decorators=[passJvtTool])) - + acc.addEventAlgo( + CompFactory.JetDecorationAlg( + algName, JetContainer="AntiKt4EMTopoJets", Decorators=[passJvtTool] + ) + ) + # Decorate if jet passes OR and save decoration DFCommonJets_passOR - # Use modified OR that does not check overlaps with tauls + # Use modified OR that does not check overlaps with tauls from AssociationUtils.AssociationUtilsConfig import OverlapRemovalToolCfg - outputLabel = 'DFCommonJets_passOR' - bJetLabel = '' #default - tauLabel = '' #workaround for missing taus - tauKey = '' #workaround for missing taus - orTool = acc.popToolsAndMerge(OverlapRemovalToolCfg(ConfigFlags,outputLabel=outputLabel,bJetLabel=bJetLabel,doTaus=False)) - algOR = CompFactory.OverlapRemovalGenUseAlg('OverlapRemovalGenUseAlg', - OverlapLabel=outputLabel, - OverlapRemovalTool=orTool, - TauKey=tauKey, - TauLabel=tauLabel, - BJetLabel=bJetLabel) + + outputLabel = "DFCommonJets_passOR" + bJetLabel = "" # default + tauLabel = "" # workaround for missing taus + tauKey = "" # workaround for missing taus + orTool = acc.popToolsAndMerge( + OverlapRemovalToolCfg( + ConfigFlags, outputLabel=outputLabel, bJetLabel=bJetLabel, doTaus=False + ) + ) + algOR = CompFactory.OverlapRemovalGenUseAlg( + "OverlapRemovalGenUseAlg", + OverlapLabel=outputLabel, + OverlapRemovalTool=orTool, + TauKey=tauKey, + TauLabel=tauLabel, + BJetLabel=bJetLabel, + ) acc.addEventAlgo(algOR) # Do the cleaning - from JetSelectorTools.JetSelectorToolsConfig import EventCleaningToolCfg,JetCleaningToolCfg - workingPoints = ['Loose'] + from JetSelectorTools.JetSelectorToolsConfig import ( + EventCleaningToolCfg, + JetCleaningToolCfg, + ) + + workingPoints = ["Loose"] prefix = "DFCommonJets_" for wp in workingPoints: - - cleaningLevel = wp + 'Bad' + cleaningLevel = wp + "Bad" # LLP WPs have a slightly different name format - if 'LLP' in wp: - cleaningLevel = wp.replace('LLP', 'BadLLP') - - jetCleaningTool = acc.popToolsAndMerge(JetCleaningToolCfg(ConfigFlags, 'JetCleaningTool_'+cleaningLevel, 'AntiKt4EMTopoJets', cleaningLevel, False)) + if "LLP" in wp: + cleaningLevel = wp.replace("LLP", "BadLLP") + + jetCleaningTool = acc.popToolsAndMerge( + JetCleaningToolCfg( + ConfigFlags, + "JetCleaningTool_" + cleaningLevel, + "AntiKt4EMTopoJets", + cleaningLevel, + False, + ) + ) acc.addPublicTool(jetCleaningTool) - ecTool = acc.popToolsAndMerge(EventCleaningToolCfg(ConfigFlags,'EventCleaningTool_' + wp, cleaningLevel)) + ecTool = acc.popToolsAndMerge( + EventCleaningToolCfg(ConfigFlags, "EventCleaningTool_" + wp, cleaningLevel) + ) ecTool.JetCleanPrefix = prefix ecTool.JetContainer = "AntiKt4EMTopoJets" ecTool.JetCleaningTool = jetCleaningTool @@ -125,64 +161,69 @@ def EGAM12KernelCfg(ConfigFlags, name='EGAM12Kernel', **kwargs): # Alg to calculate event-level and jet-level cleaning variables # Only store event-level flags for Loose* WPs - eventCleanAlg = CompFactory.EventCleaningTestAlg('EventCleaningTestAlg_'+wp, - EventCleaningTool = ecTool, - JetCollectionName = "AntiKt4EMTopoJets", - EventCleanPrefix = prefix, - CleaningLevel = cleaningLevel, - doEvent = ('Loose' in wp)) + eventCleanAlg = CompFactory.EventCleaningTestAlg( + "EventCleaningTestAlg_" + wp, + EventCleaningTool=ecTool, + JetCollectionName="AntiKt4EMTopoJets", + EventCleanPrefix=prefix, + CleaningLevel=cleaningLevel, + doEvent=("Loose" in wp), + ) acc.addEventAlgo(eventCleanAlg) - # EGAM12 augmentations augmentationTools = [] - #==================================================================== + # ==================================================================== # Max Cell energy and time - #==================================================================== + # ==================================================================== if addMaxCellDecorations: from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - MaxCellDecoratorCfg ) + MaxCellDecoratorCfg, + ) + MaxCellDecorator = acc.popToolsAndMerge(MaxCellDecoratorCfg(ConfigFlags)) acc.addPublicTool(MaxCellDecorator) - augmentationTools.append(MaxCellDecorator) - + augmentationTools.append(MaxCellDecorator) + # ==================================================================== # Gain and cluster energies per layer decoration tool # ==================================================================== if addGainDecorations: from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - GainDecoratorCfg, ClusterEnergyPerLayerDecoratorCfg ) + GainDecoratorCfg, + ClusterEnergyPerLayerDecoratorCfg, + ) + EGAM12_GainDecoratorTool = acc.popToolsAndMerge( - GainDecoratorCfg(ConfigFlags, name = 'EGAM12_GainDecoratorTool' )) + GainDecoratorCfg(ConfigFlags, name="EGAM12_GainDecoratorTool") + ) acc.addPublicTool(EGAM12_GainDecoratorTool) augmentationTools.append(EGAM12_GainDecoratorTool) - # might need some modification when cell-level reweighting is implemented (see share/EGAM12.py) - cluster_sizes = (3,7), (5,5), (7,11) + # might need some modification if cell-level reweighting is implemented + cluster_sizes = (3, 7), (5, 5), (7, 11) for neta, nphi in cluster_sizes: - cename = 'EGAM12_ClusterEnergyPerLayerDecorator_%sx%s' % (neta, nphi) + cename = "EGAM12_ClusterEnergyPerLayerDecorator_%sx%s" % (neta, nphi) EGAM12_ClusterEnergyPerLayerDecorator = acc.popToolsAndMerge( ClusterEnergyPerLayerDecoratorCfg( - ConfigFlags, - neta = neta, - nphi = nphi, - name = cename )) + ConfigFlags, neta=neta, nphi=nphi, name=cename + ) + ) acc.addPublicTool(EGAM12_ClusterEnergyPerLayerDecorator) augmentationTools.append(EGAM12_ClusterEnergyPerLayerDecorator) - # thinning tools thinningTools = [] - streamName = kwargs['StreamName'] + streamName = kwargs["StreamName"] # Track thinning if ConfigFlags.Derivation.Egamma.doTrackThinning: - from DerivationFrameworkInDet.InDetToolsConfig import ( - TrackParticleThinningCfg, MuonTrackParticleThinningCfg, - TauTrackParticleThinningCfg ) - + TrackParticleThinningCfg, + MuonTrackParticleThinningCfg, + TauTrackParticleThinningCfg, + ) TrackThinningKeepElectronTracks = True TrackThinningKeepPhotonTracks = True @@ -193,237 +234,279 @@ def EGAM12KernelCfg(ConfigFlags, name='EGAM12Kernel', **kwargs): TrackThinningKeepPVTracks = False # Tracks associated with Electrons - if (TrackThinningKeepElectronTracks): - EGAM12ElectronTPThinningTool = \ + if TrackThinningKeepElectronTracks: + EGAM12ElectronTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM12ElectronTPThinningTool', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM12ElectronTPThinningTool", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM12ElectronTPThinningTool) thinningTools.append(EGAM12ElectronTPThinningTool) # Tracks associated with Electrons (all tracks, large cone, for track # isolation studies of the selected electrons) - if (TrackThinningKeepAllElectronTracks): - EGAM12ElectronTPThinningTool2 = CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM12ElectronTPThinningTool2', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 4*GeV', - BestMatchOnly = False, - ConeSize = 0.6) + if TrackThinningKeepAllElectronTracks: + EGAM12ElectronTPThinningTool2 = ( + CompFactory.DerivationFramework.EgammaTrackParticleThinning( + name="EGAM12ElectronTPThinningTool2", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 4*GeV", + BestMatchOnly=False, + ConeSize=0.6, + ) + ) acc.addPublicTool(EGAM12ElectronTPThinningTool2) thinningTools.append(EGAM12ElectronTPThinningTool2) # Tracks associated with Photons - if (TrackThinningKeepPhotonTracks): - EGAM12PhotonTPThinningTool = \ + if TrackThinningKeepPhotonTracks: + EGAM12PhotonTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM12PhotonTPThinningTool', - StreamName = streamName, - SGKey = 'Photons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - GSFConversionVerticesKey = 'GSFConversionVertices', - SelectionString = 'Photons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM12PhotonTPThinningTool", + StreamName=streamName, + SGKey="Photons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + GSFConversionVerticesKey="GSFConversionVertices", + SelectionString="Photons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM12PhotonTPThinningTool) thinningTools.append(EGAM12PhotonTPThinningTool) # Tracks associated with Jets - if (TrackThinningKeepJetTracks): - EGAM12JetTPThinningTool = \ + if TrackThinningKeepJetTracks: + EGAM12JetTPThinningTool = ( CompFactory.DerivationFramework.JetTrackParticleThinning( - name = 'EGAM12JetTPThinningTool', - StreamName = streamName, - JetKey = JetKey, - InDetTrackParticlesKey = 'InDetTrackParticles') + name="EGAM12JetTPThinningTool", + StreamName=streamName, + JetKey=JetKey, + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) acc.addPublicTool(EGAM12JetTPThinningTool) thinningTools.append(EGAM12JetTPThinningTool) # Tracks associated with Muons - if (TrackThinningKeepMuonTracks): + if TrackThinningKeepMuonTracks: EGAM12MuonTPThinningTool = acc.getPrimaryAndMerge( MuonTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM12MuonTPThinningTool', - StreamName = streamName, - MuonKey = 'Muons', - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM12MuonTPThinningTool", + StreamName=streamName, + MuonKey="Muons", + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM12MuonTPThinningTool) # Tracks associated with Taus - if (TrackThinningKeepTauTracks): - EGAM12TauTPThinningTool = \ - acc.getPrimaryAndMerge(TauTrackParticleThinningCfg( + if TrackThinningKeepTauTracks: + EGAM12TauTPThinningTool = acc.getPrimaryAndMerge( + TauTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM12TauTPThinningTool', - StreamName = streamName, - TauKey = 'TauJets', - ConeSize = 0.6, - InDetTrackParticlesKey = 'InDetTrackParticles', - DoTauTracksThinning = True, - TauTracksKey = 'TauTracks') ) + name="EGAM12TauTPThinningTool", + StreamName=streamName, + TauKey="TauJets", + ConeSize=0.6, + InDetTrackParticlesKey="InDetTrackParticles", + DoTauTracksThinning=True, + TauTracksKey="TauTracks", + ) + ) thinningTools.append(EGAM12TauTPThinningTool) # Tracks from primary vertex - thinning_expression = ' && '.join([ - '(InDetTrackParticles.DFCommonTightPrimary)', - '(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta) < 3.0*mm)', - '(InDetTrackParticles.pt > 10*GeV)']) - if (TrackThinningKeepPVTracks): + thinning_expression = " && ".join( + [ + "(InDetTrackParticles.DFCommonTightPrimary)", + "(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3*mm)", + "(InDetTrackParticles.pt>10*GeV)", + ] + ) + if TrackThinningKeepPVTracks: EGAM12TPThinningTool = acc.getPrimaryAndMerge( TrackParticleThinningCfg( ConfigFlags, - name = 'EGAM12TPThinningTool', - StreamName = streamName, - SelectionString = thinning_expression, - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM12TPThinningTool", + StreamName=streamName, + SelectionString=thinning_expression, + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM12TPThinningTool) - # truth thinning if ConfigFlags.Input.isMC: # W, Z and Higgs - truth_cond_WZH = ' && '.join(['(abs(TruthParticles.pdgId) >= 23)', - '(abs(TruthParticles.pdgId) <= 25)']) + truth_cond_WZH = " && ".join( + ["(abs(TruthParticles.pdgId) >= 23)", "(abs(TruthParticles.pdgId) <= 25)"] + ) # Leptons - truth_cond_lep = ' && '.join(['(abs(TruthParticles.pdgId) >= 11)', - '(abs(TruthParticles.pdgId) <= 16)']) + truth_cond_lep = " && ".join( + ["(abs(TruthParticles.pdgId) >= 11)", "(abs(TruthParticles.pdgId) <= 16)"] + ) # Top quark - truth_cond_top = '(abs(TruthParticles.pdgId) == 6)' + truth_cond_top = "(abs(TruthParticles.pdgId) == 6)" # Photon - truth_cond_gam = ' && '.join(['(abs(TruthParticles.pdgId) == 22)', - '(TruthParticles.pt > 1*GeV)']) + truth_cond_gam = " && ".join( + ["(abs(TruthParticles.pdgId) == 22)", "(TruthParticles.pt > 1*GeV)"] + ) # stable particles - truth_cond_finalState = ' && '.join(['(TruthParticles.status == 1)', - '(TruthParticles.barcode<200000)']) - truth_expression = '( ' + truth_cond_WZH + ' ) || ' + \ - '( ' + truth_cond_lep + ' ) || ' + \ - '( ' + truth_cond_top + ' ) || ' + \ - '( ' + truth_cond_gam + ' ) || ' + \ - '( ' + truth_cond_finalState + ' )' - print('EGAM12 truth thinning expression: ', truth_expression) - - EGAM12TruthThinningTool = \ - CompFactory.DerivationFramework.GenericTruthThinning( - name = 'EGAM12TruthThinningTool', - StreamName = streamName, - ParticleSelectionString = truth_expression, - PreserveDescendants = False, - PreserveGeneratorDescendants = True, - PreserveAncestors = True) + truth_cond_finalState = " && ".join( + ["(TruthParticles.status == 1)", "(TruthParticles.barcode<200000)"] + ) + truth_expression = ( + "( " + + truth_cond_WZH + + " ) || " + + "( " + + truth_cond_lep + + " ) || " + + "( " + + truth_cond_top + + " ) || " + + "( " + + truth_cond_gam + + " ) || " + + "( " + + truth_cond_finalState + + " )" + ) + print("EGAM12 truth thinning expression: ", truth_expression) + + EGAM12TruthThinningTool = CompFactory.DerivationFramework.GenericTruthThinning( + name="EGAM12TruthThinningTool", + StreamName=streamName, + ParticleSelectionString=truth_expression, + PreserveDescendants=False, + PreserveGeneratorDescendants=True, + PreserveAncestors=True, + ) acc.addPublicTool(EGAM12TruthThinningTool) thinningTools.append(EGAM12TruthThinningTool) - # skimming skimmingTool = acc.getPrimaryAndMerge(EGAM12SkimmingToolCfg(ConfigFlags)) - # setup the kernel - acc.addEventAlgo(CompFactory.DerivationFramework.DerivationKernel(name, - SkimmingTools = [skimmingTool], - AugmentationTools = augmentationTools, - ThinningTools = thinningTools) ) + acc.addEventAlgo( + CompFactory.DerivationFramework.DerivationKernel( + name, + SkimmingTools=[skimmingTool], + AugmentationTools=augmentationTools, + ThinningTools=thinningTools, + ) + ) return acc - def EGAM12Cfg(ConfigFlags): - acc = ComponentAccumulator() - JetKey = 'AntiKt4EMTopoJets' + JetKey = "AntiKt4EMTopoJets" EGAM12TriggerListsHelper = None # configure skimming/thinning/augmentation tools - acc.merge(EGAM12KernelCfg(ConfigFlags, - name = 'EGAM12Kernel', - StreamName = 'StreamDAOD_EGAM12', - TriggerListsHelper = EGAM12TriggerListsHelper)) - + acc.merge( + EGAM12KernelCfg( + ConfigFlags, + name="EGAM12Kernel", + StreamName="StreamDAOD_EGAM12", + TriggerListsHelper=EGAM12TriggerListsHelper, + ) + ) # configure slimming from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper - EGAM12SlimmingHelper = SlimmingHelper( - 'EGAM12SlimmingHelper', - NamesAndTypes = ConfigFlags.Input.TypedCollections, - ConfigFlags = ConfigFlags ) + EGAM12SlimmingHelper = SlimmingHelper( + "EGAM12SlimmingHelper", + NamesAndTypes=ConfigFlags.Input.TypedCollections, + ConfigFlags=ConfigFlags, + ) # ------------------------------------------ # containers for which we save all variables # ------------------------------------------- # baseline - EGAM12SlimmingHelper.AllVariables =[ - 'Electrons', - 'GSFTrackParticles', - 'egammaClusters' ] - + EGAM12SlimmingHelper.AllVariables = [ + "Electrons", + "GSFTrackParticles", + "egammaClusters", + ] + # on MC we also add: if ConfigFlags.Input.isMC: EGAM12SlimmingHelper.AllVariables += [ - 'TruthEvents', - 'TruthParticles', - 'TruthVertices', - 'egammaTruthParticles' + "TruthEvents", + "TruthParticles", + "TruthVertices", + "egammaTruthParticles", ] - - # ------------------------------------------- # containers that we slim # ------------------------------------------- # first add variables from smart-slimming # adding only also those for which we add all variables since - # the XXXCPContent.py files also bring in some extra variables + # the XXXCPContent.py files also bring in some extra variables # for other collections # muons, tau, MET, b-tagging could be switched off if not needed # and use too much space - EGAM12SlimmingHelper.SmartCollections = ['Electrons', - 'Photons', - 'Muons', - 'TauJets', - 'InDetTrackParticles', - 'PrimaryVertices', - JetKey] + EGAM12SlimmingHelper.SmartCollections = [ + "Electrons", + "Photons", + "Muons", + "TauJets", + "InDetTrackParticles", + "PrimaryVertices", + JetKey, + ] if ConfigFlags.Input.isMC: - EGAM12SlimmingHelper.SmartCollections += ['AntiKt4TruthJets', - 'AntiKt4TruthDressedWZJets'] + EGAM12SlimmingHelper.SmartCollections += [ + "AntiKt4TruthJets", + "AntiKt4TruthDressedWZJets", + ] # then add extra variables: # muons EGAM12SlimmingHelper.ExtraVariables += [ - 'Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40' ] + "Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40" + ] # conversion vertices EGAM12SlimmingHelper.ExtraVariables += [ - 'GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo', - 'GSFConversionVertices.trackParticleLinks' ] + "GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo", + "GSFConversionVertices.trackParticleLinks", + ] # primary vertices - EGAM12SlimmingHelper.ExtraVariables += [ - 'PrimaryVertices.x.y.sumPt2' ] + EGAM12SlimmingHelper.ExtraVariables += ["PrimaryVertices.x.y.sumPt2"] # track jets EGAM12SlimmingHelper.ExtraVariables += [ - 'AntiKt4PV0TrackJets.pt.eta.phi.e.m.btaggingLink.constituentLinks' ] + "AntiKt4PV0TrackJets.pt.eta.phi.e.m.btaggingLink.constituentLinks" + ] # photons: detailed shower shape variables EGAM12SlimmingHelper.ExtraVariables += PhotonsCPDetailedContent @@ -431,49 +514,64 @@ def EGAM12Cfg(ConfigFlags): # photons: gain and cluster energy per layer if addGainDecorations: from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - getGainDecorations, getClusterEnergyPerLayerDecorations ) - gainDecorations = getGainDecorations(acc, 'EGAM12Kernel') - print('EGAM12 gain decorations: ', gainDecorations) + getGainDecorations, + getClusterEnergyPerLayerDecorations, + ) + + gainDecorations = getGainDecorations(acc, "EGAM12Kernel") + print("EGAM12 gain decorations: ", gainDecorations) EGAM12SlimmingHelper.ExtraVariables.extend(gainDecorations) clusterEnergyDecorations = getClusterEnergyPerLayerDecorations( - acc, 'EGAM12Kernel' ) - print('EGAM12 cluster energy decorations: ', clusterEnergyDecorations) + acc, "EGAM12Kernel" + ) + print("EGAM12 cluster energy decorations: ", clusterEnergyDecorations) EGAM12SlimmingHelper.ExtraVariables.extend(clusterEnergyDecorations) # energy density - EGAM12SlimmingHelper.ExtraVariables += [ - 'TopoClusterIsoCentralEventShape.Density', - 'TopoClusterIsoForwardEventShape.Density' + EGAM12SlimmingHelper.ExtraVariables += [ + "TopoClusterIsoCentralEventShape.Density", + "TopoClusterIsoForwardEventShape.Density", ] # truth if ConfigFlags.Input.isMC: EGAM12SlimmingHelper.ExtraVariables += [ - 'MuonTruthParticles.e.px.py.pz.status.pdgId.truthOrigin.truthType' ] + "MuonTruthParticles.e.px.py.pz.status.pdgId.truthOrigin.truthType" + ] EGAM12SlimmingHelper.ExtraVariables += [ - 'Photons.truthOrigin.truthType.truthParticleLink' ] + "Photons.truthOrigin.truthType.truthParticleLink" + ] # Add event info if ConfigFlags.Derivation.Egamma.doEventInfoSlimming: - EGAM12SlimmingHelper.SmartCollections.append('EventInfo') + EGAM12SlimmingHelper.SmartCollections.append("EventInfo") else: - EGAM12SlimmingHelper.AllVariables += ['EventInfo'] - + EGAM12SlimmingHelper.AllVariables += ["EventInfo"] + # Add HIEventShape and CaloSums variables for heavy ions - EGAM12SlimmingHelper.AllVariables += ['HIEventShape'] - EGAM12SlimmingHelper.AllVariables += ['CaloSums'] + EGAM12SlimmingHelper.AllVariables += ["HIEventShape"] + EGAM12SlimmingHelper.AllVariables += ["CaloSums"] EGAM12ItemList = EGAM12SlimmingHelper.GetItemList() - acc.merge(OutputStreamCfg(ConfigFlags, - 'DAOD_EGAM12', - ItemList = EGAM12ItemList, - AcceptAlgs = ['EGAM12Kernel'])) - acc.merge(SetupMetaDataForStreamCfg(ConfigFlags, 'DAOD_EGAM12', - AcceptAlgs=['EGAM12Kernel'], - createMetadata=[ - MetadataCategory.CutFlowMetaData, - MetadataCategory.TruthMetaData, - ])) + acc.merge( + OutputStreamCfg( + ConfigFlags, + "DAOD_EGAM12", + ItemList=EGAM12ItemList, + AcceptAlgs=["EGAM12Kernel"], + ) + ) + acc.merge( + SetupMetaDataForStreamCfg( + ConfigFlags, + "DAOD_EGAM12", + AcceptAlgs=["EGAM12Kernel"], + createMetadata=[ + MetadataCategory.CutFlowMetaData, + MetadataCategory.TruthMetaData, + ], + ) + ) return acc diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM2.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM2.py index bfc7be7b64e4..6ab8d848ecc5 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM2.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM2.py @@ -1,11 +1,10 @@ # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration -#!/usr/bin/env python -#==================================================================== +# ==================================================================== # EGAM2.py # This defines DAOD_EGAM2, a skimmed DAOD format for Run 3. # J/psi->ee derivation for calibration -# It requires the flag EGAM2 in Derivation_tf.py -#==================================================================== +# It requires the flag EGAM2 in Derivation_tf.py +# ==================================================================== from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory @@ -14,62 +13,67 @@ from AthenaConfiguration.Enums import MetadataCategory from AthenaCommon.SystemOfUnits import MeV from DerivationFrameworkEGamma.PhotonsCPDetailedContent import ( - PhotonsCPDetailedContent ) + PhotonsCPDetailedContent, +) from DerivationFrameworkEGamma.TriggerContent import ( - ExtraContainersTrigger, ExtraContainersElectronTrigger, - JPsiTriggers ) - + ExtraContainersTrigger, + ExtraContainersElectronTrigger, + JPsiTriggers, +) def EGAM2SkimmingToolCfg(flags): - '''Configure the EGAM2 skimming tool''' + """Configure the EGAM2 skimming tool""" acc = ComponentAccumulator() # off-line based selection - expression_calib = '(count(EGAM2_DiElectronMass1 > 1.0*GeV && ' + \ - 'EGAM2_DiElectronMass1 < 5.0*GeV)>=1)' - expression_TP = '(count(EGAM2_DiElectronMass2 > 1.0*GeV && ' + \ - 'EGAM2_DiElectronMass2 < 6.0*GeV)>=1)' - expression = expression_calib + ' || ' + expression_TP - print('EGAM2 offline skimming expression: ', expression) - - EGAM2_OfflineSkimmingTool = \ - CompFactory.DerivationFramework.xAODStringSkimmingTool( - name = 'EGAM2_OfflineSkimmingTool', - expression = expression) + expression_calib = ( + "(count(EGAM2_DiElectronMass1 > 1.0*GeV && " + + "EGAM2_DiElectronMass1 < 5.0*GeV)>=1)" + ) + expression_TP = ( + "(count(EGAM2_DiElectronMass2 > 1.0*GeV && " + + "EGAM2_DiElectronMass2 < 6.0*GeV)>=1)" + ) + expression = expression_calib + " || " + expression_TP + print("EGAM2 offline skimming expression: ", expression) + + EGAM2_OfflineSkimmingTool = CompFactory.DerivationFramework.xAODStringSkimmingTool( + name="EGAM2_OfflineSkimmingTool", expression=expression + ) # trigger-based selection MenuType = None if flags.Trigger.EDMVersion == 2: - MenuType = 'Run2' + MenuType = "Run2" elif flags.Trigger.EDMVersion == 3: - MenuType = 'Run3' + MenuType = "Run3" else: - MenuType = '' + MenuType = "" triggers = JPsiTriggers[MenuType] - print('EGAM2 trigger skimming list (OR): ', triggers) - - EGAM2_TriggerSkimmingTool = \ - CompFactory.DerivationFramework.TriggerSkimmingTool( - name = 'EGAM2_TriggerSkimmingTool', - TriggerListOR = triggers) + print("EGAM2 trigger skimming list (OR): ", triggers) + + EGAM2_TriggerSkimmingTool = CompFactory.DerivationFramework.TriggerSkimmingTool( + name="EGAM2_TriggerSkimmingTool", TriggerListOR=triggers + ) # do the OR of trigger-based and offline-based selection - print('EGAM2 skimming is logical OR of previous selections') + print("EGAM2 skimming is logical OR of previous selections") EGAM2_SkimmingTool = CompFactory.DerivationFramework.FilterCombinationOR( - name = 'EGAM2_SkimmingTool', - FilterList=[EGAM2_OfflineSkimmingTool, EGAM2_TriggerSkimmingTool]) + name="EGAM2_SkimmingTool", + FilterList=[EGAM2_OfflineSkimmingTool, EGAM2_TriggerSkimmingTool], + ) acc.addPublicTool(EGAM2_OfflineSkimmingTool) - acc.addPublicTool(EGAM2_TriggerSkimmingTool) - acc.addPublicTool(EGAM2_SkimmingTool, primary = True) - + acc.addPublicTool(EGAM2_TriggerSkimmingTool) + acc.addPublicTool(EGAM2_SkimmingTool, primary=True) + return acc def EGAM2JpsieeMassTool1Cfg(flags): - '''Configure the EGAM2 ee invariant mass augmentation tool 1''' + """Configure the EGAM2 ee invariant mass augmentation tool 1""" acc = ComponentAccumulator() # ==================================================================== @@ -79,28 +83,33 @@ def EGAM2JpsieeMassTool1Cfg(flags): # 2 tight or medium e (depends on Run2 triggers..), pT>4.5 GeV, OS # 1<Mee<5 GeV (applied in skimming step later) # ==================================================================== - electronPtRequirement = '(Electrons.pt > 4.5*GeV)' - electronQualityRequirement = '(Electrons.DFCommonElectronsLHMedium)' - requirement_el = '(' + electronQualityRequirement + \ - '&&' + electronPtRequirement + ')' - - acc.setPrivateTools( CompFactory.DerivationFramework.EGInvariantMassTool( - name = 'EGAM2_JpsieeMassTool1', - Object1Requirements = requirement_el, - Object2Requirements = requirement_el, - StoreGateEntryName = 'EGAM2_DiElectronMass1', - Mass1Hypothesis = 0.511*MeV, - Mass2Hypothesis = 0.511*MeV, - Container1Name = 'Electrons', - Container2Name = 'Electrons', - CheckCharge = True, - DoTransverseMass = False, - MinDeltaR = 0.0) ) + electronPtRequirement = "(Electrons.pt > 4.5*GeV)" + electronQualityRequirement = "(Electrons.DFCommonElectronsLHMedium)" + requirement_el = ( + "(" + electronQualityRequirement + "&&" + electronPtRequirement + ")" + ) + + acc.setPrivateTools( + CompFactory.DerivationFramework.EGInvariantMassTool( + name="EGAM2_JpsieeMassTool1", + Object1Requirements=requirement_el, + Object2Requirements=requirement_el, + StoreGateEntryName="EGAM2_DiElectronMass1", + Mass1Hypothesis=0.511 * MeV, + Mass2Hypothesis=0.511 * MeV, + Container1Name="Electrons", + Container2Name="Electrons", + CheckCharge=True, + DoTransverseMass=False, + MinDeltaR=0.0, + ) + ) return acc + def EGAM2JpsieeMassTool2Cfg(flags): - '''Configure the EGAM2 ee invariant mass augmentation tool 2''' + """Configure the EGAM2 ee invariant mass augmentation tool 2""" acc = ComponentAccumulator() # ==================================================================== @@ -114,91 +123,94 @@ def EGAM2JpsieeMassTool2Cfg(flags): # dR>0.15 # 1<mee<6 GeV (applied in skimming step later) # ==================================================================== - requirement_el_tag = ' && '.join(['(Electrons.DFCommonElectronsLHTight)', - '(Electrons.pt > 4.5*GeV)']) - requirement_el_probe = 'Electrons.pt > 4.5*GeV' - - acc.setPrivateTools( CompFactory.DerivationFramework.EGInvariantMassTool( - name = 'EGAM2_JpsieeMassTool2', - Object1Requirements = requirement_el_tag, - Object2Requirements = requirement_el_probe, - StoreGateEntryName = 'EGAM2_DiElectronMass2', - Mass1Hypothesis = 0.511*MeV, - Mass2Hypothesis = 0.511*MeV, - Container1Name = 'Electrons', - Container2Name = 'Electrons', - CheckCharge = False, - DoTransverseMass = False, - MinDeltaR = 0.15) ) + requirement_el_tag = " && ".join( + ["(Electrons.DFCommonElectronsLHTight)", "(Electrons.pt > 4.5*GeV)"] + ) + requirement_el_probe = "Electrons.pt > 4.5*GeV" + + acc.setPrivateTools( + CompFactory.DerivationFramework.EGInvariantMassTool( + name="EGAM2_JpsieeMassTool2", + Object1Requirements=requirement_el_tag, + Object2Requirements=requirement_el_probe, + StoreGateEntryName="EGAM2_DiElectronMass2", + Mass1Hypothesis=0.511 * MeV, + Mass2Hypothesis=0.511 * MeV, + Container1Name="Electrons", + Container2Name="Electrons", + CheckCharge=False, + DoTransverseMass=False, + MinDeltaR=0.15, + ) + ) return acc -def EGAM2KernelCfg(ConfigFlags, name='EGAM2Kernel', **kwargs): - '''Configure the derivation framework driving algorithm (kernel) - for EGAM2''' +def EGAM2KernelCfg(ConfigFlags, name="EGAM2Kernel", **kwargs): + """Configure the derivation framework driving algorithm (kernel) + for EGAM2""" acc = ComponentAccumulator() - # Common augmentations - from DerivationFrameworkPhys.PhysCommonConfig import ( - PhysCommonAugmentationsCfg ) - acc.merge( PhysCommonAugmentationsCfg( - ConfigFlags, - TriggerListsHelper = kwargs['TriggerListsHelper'] ) ) - + from DerivationFrameworkPhys.PhysCommonConfig import PhysCommonAugmentationsCfg + + acc.merge( + PhysCommonAugmentationsCfg( + ConfigFlags, TriggerListsHelper=kwargs["TriggerListsHelper"] + ) + ) # EGAM2 augmentations augmentationTools = [] - - #==================================================================== + # ==================================================================== # ee invariant masses - #==================================================================== - EGAM2JpsieeMassTool1 = acc.popToolsAndMerge( - EGAM2JpsieeMassTool1Cfg(ConfigFlags) ) + # ==================================================================== + EGAM2JpsieeMassTool1 = acc.popToolsAndMerge(EGAM2JpsieeMassTool1Cfg(ConfigFlags)) acc.addPublicTool(EGAM2JpsieeMassTool1) augmentationTools.append(EGAM2JpsieeMassTool1) - EGAM2JpsieeMassTool2 = acc.popToolsAndMerge( - EGAM2JpsieeMassTool2Cfg(ConfigFlags) ) + EGAM2JpsieeMassTool2 = acc.popToolsAndMerge(EGAM2JpsieeMassTool2Cfg(ConfigFlags)) acc.addPublicTool(EGAM2JpsieeMassTool2) augmentationTools.append(EGAM2JpsieeMassTool2) - # ==================================================================== # Gain and cluster energies per layer decoration tool # ==================================================================== from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - GainDecoratorCfg, ClusterEnergyPerLayerDecoratorCfg ) + GainDecoratorCfg, + ClusterEnergyPerLayerDecoratorCfg, + ) + EGAM2_GainDecoratorTool = acc.popToolsAndMerge( - GainDecoratorCfg(ConfigFlags, name = 'EGAM2_GainDecoratorTool' )) + GainDecoratorCfg(ConfigFlags, name="EGAM2_GainDecoratorTool") + ) acc.addPublicTool(EGAM2_GainDecoratorTool) augmentationTools.append(EGAM2_GainDecoratorTool) - cluster_sizes = (3,7), (5,5), (7,11) + cluster_sizes = (3, 7), (5, 5), (7, 11) for neta, nphi in cluster_sizes: - cename = 'EGAM2_ClusterEnergyPerLayerDecorator_%sx%s' % (neta, nphi) + cename = "EGAM2_ClusterEnergyPerLayerDecorator_%sx%s" % (neta, nphi) EGAM2_ClusterEnergyPerLayerDecorator = acc.popToolsAndMerge( ClusterEnergyPerLayerDecoratorCfg( - ConfigFlags, - neta = neta, - nphi=nphi, - name=cename )) + ConfigFlags, neta=neta, nphi=nphi, name=cename + ) + ) acc.addPublicTool(EGAM2_ClusterEnergyPerLayerDecorator) augmentationTools.append(EGAM2_ClusterEnergyPerLayerDecorator) - # thinning tools thinningTools = [] - streamName = kwargs['StreamName'] + streamName = kwargs["StreamName"] # Track thinning if ConfigFlags.Derivation.Egamma.doTrackThinning: - from DerivationFrameworkInDet.InDetToolsConfig import ( - TrackParticleThinningCfg, MuonTrackParticleThinningCfg, - TauTrackParticleThinningCfg ) + TrackParticleThinningCfg, + MuonTrackParticleThinningCfg, + TauTrackParticleThinningCfg, + ) TrackThinningKeepElectronTracks = True TrackThinningKeepPhotonTracks = True @@ -209,120 +221,137 @@ def EGAM2KernelCfg(ConfigFlags, name='EGAM2Kernel', **kwargs): TrackThinningKeepPVTracks = False # Tracks associated with Electrons - if (TrackThinningKeepElectronTracks): - EGAM2ElectronTPThinningTool = \ + if TrackThinningKeepElectronTracks: + EGAM2ElectronTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM2ElectronTPThinningTool', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM2ElectronTPThinningTool", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM2ElectronTPThinningTool) thinningTools.append(EGAM2ElectronTPThinningTool) # Tracks associated with Electrons (all tracks, large cone, for track # isolation studies of the selected electrons) - if (TrackThinningKeepAllElectronTracks): - EGAM2ElectronTPThinningTool2 = \ + if TrackThinningKeepAllElectronTracks: + EGAM2ElectronTPThinningTool2 = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM2ElectronTPThinningTool2', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 4*GeV', - BestMatchOnly = False, - ConeSize = 0.6) + name="EGAM2ElectronTPThinningTool2", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 4*GeV", + BestMatchOnly=False, + ConeSize=0.6, + ) + ) acc.addPublicTool(EGAM2ElectronTPThinningTool2) thinningTools.append(EGAM2ElectronTPThinningTool2) # Tracks associated with Photons - if (TrackThinningKeepPhotonTracks): - EGAM2PhotonTPThinningTool = \ + if TrackThinningKeepPhotonTracks: + EGAM2PhotonTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM2PhotonTPThinningTool', - StreamName = streamName, - SGKey = 'Photons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - GSFConversionVerticesKey = 'GSFConversionVertices', - SelectionString = 'Photons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM2PhotonTPThinningTool", + StreamName=streamName, + SGKey="Photons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + GSFConversionVerticesKey="GSFConversionVertices", + SelectionString="Photons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM2PhotonTPThinningTool) thinningTools.append(EGAM2PhotonTPThinningTool) # Tracks associated with Jets - if (TrackThinningKeepJetTracks): - EGAM2JetTPThinningTool = \ + if TrackThinningKeepJetTracks: + EGAM2JetTPThinningTool = ( CompFactory.DerivationFramework.JetTrackParticleThinning( - name = 'EGAM2JetTPThinningTool', - StreamName = streamName, - JetKey = 'AntiKt4EMPFlowJets', - InDetTrackParticlesKey = 'InDetTrackParticles') + name="EGAM2JetTPThinningTool", + StreamName=streamName, + JetKey="AntiKt4EMPFlowJets", + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) acc.addPublicTool(EGAM2JetTPThinningTool) thinningTools.append(EGAM2JetTPThinningTool) # Tracks associated with Muons - if (TrackThinningKeepMuonTracks): + if TrackThinningKeepMuonTracks: EGAM2MuonTPThinningTool = acc.getPrimaryAndMerge( MuonTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM2MuonTPThinningTool', - StreamName = streamName, - MuonKey = 'Muons', - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM2MuonTPThinningTool", + StreamName=streamName, + MuonKey="Muons", + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM2MuonTPThinningTool) # Tracks associated with Taus - if (TrackThinningKeepTauTracks): + if TrackThinningKeepTauTracks: EGAM2TauTPThinningTool = acc.getPrimaryAndMerge( TauTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM2TauTPThinningTool', - StreamName = streamName, - TauKey = 'TauJets', - ConeSize = 0.6, - InDetTrackParticlesKey = 'InDetTrackParticles', - DoTauTracksThinning = True, - TauTracksKey = 'TauTracks') ) + name="EGAM2TauTPThinningTool", + StreamName=streamName, + TauKey="TauJets", + ConeSize=0.6, + InDetTrackParticlesKey="InDetTrackParticles", + DoTauTracksThinning=True, + TauTracksKey="TauTracks", + ) + ) thinningTools.append(EGAM2TauTPThinningTool) # Tracks from primary vertex - thinning_expression = ' && '.join([ - '(InDetTrackParticles.DFCommonTightPrimary)', - '(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta) < 3.0*mm)', - '(InDetTrackParticles.pt > 10*GeV)']) - if (TrackThinningKeepPVTracks): + thinning_expression = " && ".join( + [ + "(InDetTrackParticles.DFCommonTightPrimary)", + "(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3*mm)", + "(InDetTrackParticles.pt > 10*GeV)", + ] + ) + if TrackThinningKeepPVTracks: EGAM2TPThinningTool = acc.getPrimaryAndMerge( TrackParticleThinningCfg( ConfigFlags, - name = 'EGAM2TPThinningTool', - StreamName = streamName, - SelectionString = thinning_expression, - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM2TPThinningTool", + StreamName=streamName, + SelectionString=thinning_expression, + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM2TPThinningTool) - # skimming skimmingTool = acc.getPrimaryAndMerge(EGAM2SkimmingToolCfg(ConfigFlags)) - # setup the kernel - acc.addEventAlgo(CompFactory.DerivationFramework.DerivationKernel(name, - SkimmingTools = [skimmingTool], - AugmentationTools = augmentationTools, - ThinningTools = thinningTools) ) + acc.addEventAlgo( + CompFactory.DerivationFramework.DerivationKernel( + name, + SkimmingTools=[skimmingTool], + AugmentationTools=augmentationTools, + ThinningTools=thinningTools, + ) + ) return acc - def EGAM2Cfg(ConfigFlags): - acc = ComponentAccumulator() # Get the lists of triggers needed for trigger matching. @@ -333,132 +362,144 @@ def EGAM2Cfg(ConfigFlags): # multiple times in a train. # TODO: restrict it to relevant triggers from DerivationFrameworkPhys.TriggerListsHelper import TriggerListsHelper + EGAM2TriggerListsHelper = TriggerListsHelper(ConfigFlags) # configure skimming/thinning/augmentation tools - acc.merge(EGAM2KernelCfg(ConfigFlags, - name = 'EGAM2Kernel', - StreamName = 'StreamDAOD_EGAM2', - TriggerListsHelper = EGAM2TriggerListsHelper)) - + acc.merge( + EGAM2KernelCfg( + ConfigFlags, + name="EGAM2Kernel", + StreamName="StreamDAOD_EGAM2", + TriggerListsHelper=EGAM2TriggerListsHelper, + ) + ) # configure slimming from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper - EGAM2SlimmingHelper = SlimmingHelper( - 'EGAM2SlimmingHelper', - NamesAndTypes = ConfigFlags.Input.TypedCollections, - ConfigFlags = ConfigFlags ) + EGAM2SlimmingHelper = SlimmingHelper( + "EGAM2SlimmingHelper", + NamesAndTypes=ConfigFlags.Input.TypedCollections, + ConfigFlags=ConfigFlags, + ) # ------------------------------------------ # containers for which we save all variables # ------------------------------------------- # baseline - EGAM2SlimmingHelper.AllVariables =[ - 'Electrons', - 'GSFTrackParticles', - 'egammaClusters' ] + EGAM2SlimmingHelper.AllVariables = [ + "Electrons", + "GSFTrackParticles", + "egammaClusters", + ] # for trigger studies we also add: MenuType = None if ConfigFlags.Trigger.EDMVersion == 2: - MenuType = 'Run2' + MenuType = "Run2" elif ConfigFlags.Trigger.EDMVersion == 3: - MenuType = 'Run3' + MenuType = "Run3" else: - MenuType = '' + MenuType = "" EGAM2SlimmingHelper.AllVariables += ExtraContainersTrigger[MenuType] EGAM2SlimmingHelper.AllVariables += ExtraContainersElectronTrigger[MenuType] - + # and on MC we also add: if ConfigFlags.Input.isMC: EGAM2SlimmingHelper.AllVariables += [ - 'TruthEvents', - 'TruthParticles', - 'TruthVertices', - 'egammaTruthParticles' + "TruthEvents", + "TruthParticles", + "TruthVertices", + "egammaTruthParticles", ] - - # ------------------------------------------- # containers that we slim # ------------------------------------------- # first add variables from smart-slimming # adding only also those for which we add all variables since - # the XXXCPContent.py files also bring in some extra variables + # the XXXCPContent.py files also bring in some extra variables # for other collections - # muons, tau, MET, b-tagging could be switched off if not needed + # muons, tau, MET, b-tagging could be switched off if not needed # and use too much space - EGAM2SlimmingHelper.SmartCollections = ['Electrons', - 'Photons', - 'Muons', - 'TauJets', - 'InDetTrackParticles', - 'PrimaryVertices', - 'AntiKt4EMPFlowJets', - 'MET_Baseline_AntiKt4EMPFlow', - 'BTagging_AntiKt4EMPFlow' - ] + EGAM2SlimmingHelper.SmartCollections = [ + "Electrons", + "Photons", + "Muons", + "TauJets", + "InDetTrackParticles", + "PrimaryVertices", + "AntiKt4EMPFlowJets", + "MET_Baseline_AntiKt4EMPFlow", + "BTagging_AntiKt4EMPFlow", + ] if ConfigFlags.Input.isMC: - EGAM2SlimmingHelper.SmartCollections += ['AntiKt4TruthJets', - 'AntiKt4TruthDressedWZJets'] + EGAM2SlimmingHelper.SmartCollections += [ + "AntiKt4TruthJets", + "AntiKt4TruthDressedWZJets", + ] # then add extra variables: # muons EGAM2SlimmingHelper.ExtraVariables += [ - 'Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40' ] + "Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40" + ] # conversion vertices EGAM2SlimmingHelper.ExtraVariables += [ - 'GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo', - 'GSFConversionVertices.trackParticleLinks' ] + "GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo", + "GSFConversionVertices.trackParticleLinks", + ] # primary vertices - EGAM2SlimmingHelper.ExtraVariables += [ - 'PrimaryVertices.x.y.sumPt2' ] + EGAM2SlimmingHelper.ExtraVariables += ["PrimaryVertices.x.y.sumPt2"] # photons: detailed shower shape variables EGAM2SlimmingHelper.ExtraVariables += PhotonsCPDetailedContent - + # photons: gain and cluster energy per layer from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - getGainDecorations, getClusterEnergyPerLayerDecorations ) - gainDecorations = getGainDecorations(acc, 'EGAM2Kernel') - print('EGAM2 gain decorations: ', gainDecorations) + getGainDecorations, + getClusterEnergyPerLayerDecorations, + ) + + gainDecorations = getGainDecorations(acc, "EGAM2Kernel") + print("EGAM2 gain decorations: ", gainDecorations) EGAM2SlimmingHelper.ExtraVariables.extend(gainDecorations) - clusterEnergyDecorations = getClusterEnergyPerLayerDecorations( - acc, 'EGAM2Kernel' ) - print('EGAM2 cluster energy decorations: ', clusterEnergyDecorations) + clusterEnergyDecorations = getClusterEnergyPerLayerDecorations(acc, "EGAM2Kernel") + print("EGAM2 cluster energy decorations: ", clusterEnergyDecorations) EGAM2SlimmingHelper.ExtraVariables.extend(clusterEnergyDecorations) - # energy density - EGAM2SlimmingHelper.ExtraVariables += [ - 'TopoClusterIsoCentralEventShape.Density', - 'TopoClusterIsoForwardEventShape.Density', - 'NeutralParticleFlowIsoCentralEventShape.Density', - 'NeutralParticleFlowIsoForwardEventShape.Density'] + EGAM2SlimmingHelper.ExtraVariables += [ + "TopoClusterIsoCentralEventShape.Density", + "TopoClusterIsoForwardEventShape.Density", + "NeutralParticleFlowIsoCentralEventShape.Density", + "NeutralParticleFlowIsoForwardEventShape.Density", + ] # truth if ConfigFlags.Input.isMC: EGAM2SlimmingHelper.ExtraVariables += [ - 'MuonTruthParticles.e.px.py.pz.status.pdgId.truthOrigin.truthType' ] + "MuonTruthParticles.e.px.py.pz.status.pdgId.truthOrigin.truthType" + ] EGAM2SlimmingHelper.ExtraVariables += [ - 'Photons.truthOrigin.truthType.truthParticleLink' ] + "Photons.truthOrigin.truthType.truthParticleLink" + ] # Add event info if ConfigFlags.Derivation.Egamma.doEventInfoSlimming: - EGAM2SlimmingHelper.SmartCollections.append('EventInfo') + EGAM2SlimmingHelper.SmartCollections.append("EventInfo") else: - EGAM2SlimmingHelper.AllVariables += ['EventInfo'] - + EGAM2SlimmingHelper.AllVariables += ["EventInfo"] + # Add egamma trigger objects EGAM2SlimmingHelper.IncludeEGammaTriggerContent = True @@ -466,28 +507,41 @@ def EGAM2Cfg(ConfigFlags): # Run 2 if ConfigFlags.Trigger.EDMVersion == 2: from DerivationFrameworkPhys.TriggerMatchingCommonConfig import ( - AddRun2TriggerMatchingToSlimmingHelper ) + AddRun2TriggerMatchingToSlimmingHelper, + ) + AddRun2TriggerMatchingToSlimmingHelper( - SlimmingHelper = EGAM2SlimmingHelper, - OutputContainerPrefix = 'TrigMatch_', - TriggerList = EGAM2TriggerListsHelper.Run2TriggerNamesNoTau) + SlimmingHelper=EGAM2SlimmingHelper, + OutputContainerPrefix="TrigMatch_", + TriggerList=EGAM2TriggerListsHelper.Run2TriggerNamesNoTau, + ) # Run 3 if ConfigFlags.Trigger.EDMVersion == 3: from TrigNavSlimmingMT.TrigNavSlimmingMTConfig import ( - AddRun3TrigNavSlimmingCollectionsToSlimmingHelper ) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper, + ) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper(EGAM2SlimmingHelper) - EGAM2ItemList = EGAM2SlimmingHelper.GetItemList() - acc.merge(OutputStreamCfg(ConfigFlags, - 'DAOD_EGAM2', - ItemList = EGAM2ItemList, - AcceptAlgs = ['EGAM2Kernel'])) - acc.merge(SetupMetaDataForStreamCfg(ConfigFlags, 'DAOD_EGAM2', - AcceptAlgs=['EGAM2Kernel'], - createMetadata=[ - MetadataCategory.CutFlowMetaData, - MetadataCategory.TruthMetaData - ])) + acc.merge( + OutputStreamCfg( + ConfigFlags, + "DAOD_EGAM2", + ItemList=EGAM2ItemList, + AcceptAlgs=["EGAM2Kernel"], + ) + ) + acc.merge( + SetupMetaDataForStreamCfg( + ConfigFlags, + "DAOD_EGAM2", + AcceptAlgs=["EGAM2Kernel"], + createMetadata=[ + MetadataCategory.CutFlowMetaData, + MetadataCategory.TruthMetaData, + ], + ) + ) return acc diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM3.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM3.py index 694c3096c1e2..2b7ca04d4f9a 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM3.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM3.py @@ -1,11 +1,10 @@ # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration -#!/usr/bin/env python -#==================================================================== +# ==================================================================== # EGAM3.py # This defines DAOD_EGAM3, a skimmed DAOD format for Run 3. # Z->eegamma reduction for low-pT electron and photon studies -# It requires the flag EGAM3 in Derivation_tf.py -#==================================================================== +# It requires the flag EGAM3 in Derivation_tf.py +# ==================================================================== from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory @@ -14,119 +13,160 @@ from AthenaConfiguration.Enums import MetadataCategory from AthenaCommon.SystemOfUnits import MeV from DerivationFrameworkEGamma.ElectronsCPDetailedContent import ( - ElectronsCPDetailedContent, GSFTracksCPDetailedContent ) + ElectronsCPDetailedContent, + GSFTracksCPDetailedContent, +) from DerivationFrameworkEGamma.TriggerContent import ( - ExtraContainersTrigger, ExtraContainersPhotonTrigger, - ExtraContainersElectronTrigger, ExtraContainersTriggerDataOnly, - ExtraVariablesHLTPhotons ) + ExtraContainersTrigger, + ExtraContainersPhotonTrigger, + ExtraContainersElectronTrigger, + ExtraContainersTriggerDataOnly, + ExtraVariablesHLTPhotons, +) def EGAM3SkimmingToolCfg(flags): - '''Configure the EGAM3 skimming tool''' + """Configure the EGAM3 skimming tool""" acc = ComponentAccumulator() # eegamma or eee selection for photon efficiency studies, ee triggers - expression1a = ' && '.join(['(count(DFCommonPhotons_et>9.5*GeV)>=1)', - '(count(EGAM3_DiElectronMass1 > 40.0*GeV)>=1)']) - expression1b = ' && '.join(['(count(Electrons.pt>9.5*GeV)>=3)', - '(count(EGAM3_DiElectronMass1 > 40.0*GeV)>=1)']) + expression1a = " && ".join( + [ + "(count(DFCommonPhotons_et>9.5*GeV)>=1)", + "(count(EGAM3_DiElectronMass1 > 40.0*GeV)>=1)", + ] + ) + expression1b = " && ".join( + [ + "(count(Electrons.pt>9.5*GeV)>=3)", + "(count(EGAM3_DiElectronMass1 > 40.0*GeV)>=1)", + ] + ) # eegamma selection for low-pT central electron studies with T&P - expression2 = ' && '.join(['(count(DFCommonPhotons_et>9.5*GeV && ' + \ - 'Photons.DFCommonPhotonsIsEMTight)>=1)', - '(count(EGAM3_DiElectronMass2 > 40.0*GeV)>=1)']) + expression2 = " && ".join( + [ + "(count(DFCommonPhotons_et>9.5*GeV && " + + "Photons.DFCommonPhotonsIsEMTight)>=1)", + "(count(EGAM3_DiElectronMass2 > 40.0*GeV)>=1)", + ] + ) # eegamma selection for low-pT forward electron studies with T&P - expression3 = ' && '.join(['(count(DFCommonPhotons_et>9.5*GeV && ' + \ - 'Photons.DFCommonPhotonsIsEMTight)>=1)', - '(count(EGAM3_DiElectronMass3 > 40.0*GeV)>=1)']) + expression3 = " && ".join( + [ + "(count(DFCommonPhotons_et>9.5*GeV && " + + "Photons.DFCommonPhotonsIsEMTight)>=1)", + "(count(EGAM3_DiElectronMass3 > 40.0*GeV)>=1)", + ] + ) # take OR of previous selections - expression = '( ' + expression1a + ' ) || ' + \ - '( ' + expression1b + ' ) || ' + \ - '( ' + expression2 + ' ) || ' + \ - '( ' + expression3 + ' )' - print('EGAM3 skimming expression: ', expression) + expression = ( + "( " + + expression1a + + " ) || " + + "( " + + expression1b + + " ) || " + + "( " + + expression2 + + " ) || " + + "( " + + expression3 + + " )" + ) + print("EGAM3 skimming expression: ", expression) + + acc.setPrivateTools( + CompFactory.DerivationFramework.xAODStringSkimmingTool( + name="EGAM3SkimmingTool", expression=expression + ) + ) - acc.setPrivateTools( CompFactory.DerivationFramework.xAODStringSkimmingTool( - name = 'EGAM3SkimmingTool', - expression = expression) ) - - return(acc) + return acc def EGAM3eeMassTool1Cfg(flags): - '''Configure the EGAM3 ee invariant mass augmentation tool 1''' + """Configure the EGAM3 ee invariant mass augmentation tool 1""" acc = ComponentAccumulator() - # ==================================================================== + # ==================================================================== # 1. ee invariant mass of events passing eegamma or eee selection for # photon efficiency studies, di-electron triggers # # two opposite-sign medium el, pT>10 GeV, |eta|<2.5, mee>40 GeV # eegamma: one reco photon, ET>10 GeV< |eta|<2.5 # eee: 3 electrons, pT>10 GeV, mee>40 GeV - # if skim size too large either require tight electrons (at least one) + # if skim size too large either require tight electrons (at least one) # or raise electron pT threshold (at least one) # ==================================================================== - requirementElectrons = ' && '.join(['(Electrons.DFCommonElectronsLHMedium)', - '(Electrons.pt > 9.5*GeV)']) - - acc.setPrivateTools( CompFactory.DerivationFramework.EGInvariantMassTool( - name = 'EGAM3_EEMassTool11', - Object1Requirements = requirementElectrons, - Object2Requirements = requirementElectrons, - StoreGateEntryName = 'EGAM3_DiElectronMass1', - Mass1Hypothesis = 0.511*MeV, - Mass2Hypothesis = 0.511*MeV, - Container1Name = 'Electrons', - Container2Name = 'Electrons', - CheckCharge = True, - DoTransverseMass = False, - MinDeltaR=0.0) ) + requirementElectrons = " && ".join( + ["(Electrons.DFCommonElectronsLHMedium)", "(Electrons.pt > 9.5*GeV)"] + ) + + acc.setPrivateTools( + CompFactory.DerivationFramework.EGInvariantMassTool( + name="EGAM3_EEMassTool11", + Object1Requirements=requirementElectrons, + Object2Requirements=requirementElectrons, + StoreGateEntryName="EGAM3_DiElectronMass1", + Mass1Hypothesis=0.511 * MeV, + Mass2Hypothesis=0.511 * MeV, + Container1Name="Electrons", + Container2Name="Electrons", + CheckCharge=True, + DoTransverseMass=False, + MinDeltaR=0.0, + ) + ) return acc def EGAM3eeMassTool2Cfg(flags): - '''Configure the EGAM3 ee invariant mass augmentation tool 2''' + """Configure the EGAM3 ee invariant mass augmentation tool 2""" acc = ComponentAccumulator() - - #==================================================================== + + # ==================================================================== # 2. dielectron invariant mass for eegamma selection for low-pT # electron studies with T&P # # tag e: tight, |eta|<2.5, pT>25 GeV # probe e: reco, ET>7 GeV, central electron # gamma: tight, ET>10 GeV - #==================================================================== - # asymmetric electron cuts/single e trigger, low pT cut for subleading + # ==================================================================== + # asymmetric electron cuts/single e trigger, low pT cut for subleading # e (for e calibration studies at low pT) - requirementElectron1 = ' && '.join(['(Electrons.DFCommonElectronsLHTight)', - '(Electrons.pt > 24.5*GeV)']) - requirementElectron2 = '(Electrons.pt > 6.5*GeV)' - - acc.setPrivateTools( CompFactory.DerivationFramework.EGInvariantMassTool( - name = 'EGAM3_ZEEMassTool2', - Object1Requirements = requirementElectron1, - Object2Requirements = requirementElectron2, - StoreGateEntryName = 'EGAM3_DiElectronMass2', - Mass1Hypothesis = 0.511*MeV, - Mass2Hypothesis = 0.511*MeV, - Container1Name = 'Electrons', - Container2Name = 'Electrons', - CheckCharge = True, - DoTransverseMass = False, - MinDeltaR = 0.0) ) + requirementElectron1 = " && ".join( + ["(Electrons.DFCommonElectronsLHTight)", "(Electrons.pt > 24.5*GeV)"] + ) + requirementElectron2 = "(Electrons.pt > 6.5*GeV)" + + acc.setPrivateTools( + CompFactory.DerivationFramework.EGInvariantMassTool( + name="EGAM3_ZEEMassTool2", + Object1Requirements=requirementElectron1, + Object2Requirements=requirementElectron2, + StoreGateEntryName="EGAM3_DiElectronMass2", + Mass1Hypothesis=0.511 * MeV, + Mass2Hypothesis=0.511 * MeV, + Container1Name="Electrons", + Container2Name="Electrons", + CheckCharge=True, + DoTransverseMass=False, + MinDeltaR=0.0, + ) + ) return acc def EGAM3eeMassTool3Cfg(flags): - '''Configure the EGAM3 ee invariant mass augmentation tool 3''' + """Configure the EGAM3 ee invariant mass augmentation tool 3""" acc = ComponentAccumulator() # ==================================================================== @@ -136,49 +176,51 @@ def EGAM3eeMassTool3Cfg(flags): # gamma: tight, ET>10 GeV # ==================================================================== - requirementElectron1 = ' && '.join(['(Electrons.DFCommonElectronsLHTight)', - '(Electrons.pt > 24.5*GeV)']) - requirementElectron2 = '(ForwardElectrons.pt > 6.5*GeV)' - - acc.setPrivateTools( CompFactory.DerivationFramework.EGInvariantMassTool( - name = 'EGAM3_EEMassTool3', - Object1Requirements = requirementElectron1, - Object2Requirements = requirementElectron2, - StoreGateEntryName = 'EGAM3_DiElectronMass3', - Mass1Hypothesis = 0.511*MeV, - Mass2Hypothesis = 0.511*MeV, - Container1Name = 'Electrons', - Container2Name = 'ForwardElectrons', - CheckCharge = True, - DoTransverseMass = False, - MinDeltaR = 0.0) ) + requirementElectron1 = " && ".join( + ["(Electrons.DFCommonElectronsLHTight)", "(Electrons.pt > 24.5*GeV)"] + ) + requirementElectron2 = "(ForwardElectrons.pt > 6.5*GeV)" + + acc.setPrivateTools( + CompFactory.DerivationFramework.EGInvariantMassTool( + name="EGAM3_EEMassTool3", + Object1Requirements=requirementElectron1, + Object2Requirements=requirementElectron2, + StoreGateEntryName="EGAM3_DiElectronMass3", + Mass1Hypothesis=0.511 * MeV, + Mass2Hypothesis=0.511 * MeV, + Container1Name="Electrons", + Container2Name="ForwardElectrons", + CheckCharge=True, + DoTransverseMass=False, + MinDeltaR=0.0, + ) + ) return acc - - # Main algorithm config -def EGAM3KernelCfg(ConfigFlags, name='EGAM3Kernel', **kwargs): - '''Configure the derivation framework driving algorithm (kernel) - for EGAM3''' +def EGAM3KernelCfg(ConfigFlags, name="EGAM3Kernel", **kwargs): + """Configure the derivation framework driving algorithm (kernel) + for EGAM3""" acc = ComponentAccumulator() - # Common augmentations - from DerivationFrameworkPhys.PhysCommonConfig import ( - PhysCommonAugmentationsCfg ) - acc.merge( PhysCommonAugmentationsCfg( - ConfigFlags, - TriggerListsHelper = kwargs['TriggerListsHelper'] ) ) - + from DerivationFrameworkPhys.PhysCommonConfig import PhysCommonAugmentationsCfg + + acc.merge( + PhysCommonAugmentationsCfg( + ConfigFlags, TriggerListsHelper=kwargs["TriggerListsHelper"] + ) + ) # EGAM3 augmentations augmentationTools = [] - #==================================================================== + # ==================================================================== # ee and egamma invariant masses - #==================================================================== + # ==================================================================== EGAM3eeMassTool1 = acc.popToolsAndMerge(EGAM3eeMassTool1Cfg(ConfigFlags)) acc.addPublicTool(EGAM3eeMassTool1) augmentationTools.append(EGAM3eeMassTool1) @@ -191,12 +233,13 @@ def EGAM3KernelCfg(ConfigFlags, name='EGAM3Kernel', **kwargs): acc.addPublicTool(EGAM3eeMassTool3) augmentationTools.append(EGAM3eeMassTool3) - - #==================================================================== + # ==================================================================== # Max Cell energy and time - #==================================================================== - from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - MaxCellDecoratorCfg ) + # ==================================================================== + from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( + MaxCellDecoratorCfg, + ) + MaxCellDecorator = acc.popToolsAndMerge(MaxCellDecoratorCfg(ConfigFlags)) acc.addPublicTool(MaxCellDecorator) augmentationTools.append(MaxCellDecorator) @@ -204,43 +247,45 @@ def EGAM3KernelCfg(ConfigFlags, name='EGAM3Kernel', **kwargs): # ==================================================================== # Cell reweighter # ==================================================================== - # ==================================================================== # Gain and cluster energies per layer decoration tool # ==================================================================== from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - GainDecoratorCfg, ClusterEnergyPerLayerDecoratorCfg ) + GainDecoratorCfg, + ClusterEnergyPerLayerDecoratorCfg, + ) + EGAM3_GainDecoratorTool = acc.popToolsAndMerge( - GainDecoratorCfg(ConfigFlags, name = 'EGAM3_GainDecoratorTool' )) + GainDecoratorCfg(ConfigFlags, name="EGAM3_GainDecoratorTool") + ) acc.addPublicTool(EGAM3_GainDecoratorTool) augmentationTools.append(EGAM3_GainDecoratorTool) - # might need some modification when cell-level reweighting is implemented + # might need some modification when cell-level reweighting is implemented # (see share/EGAM3.py) - cluster_sizes = (3,7), (5,5), (7,11) + cluster_sizes = (3, 7), (5, 5), (7, 11) for neta, nphi in cluster_sizes: - cename = 'EGAM3_ClusterEnergyPerLayerDecorator_%sx%s' % (neta, nphi) + cename = "EGAM3_ClusterEnergyPerLayerDecorator_%sx%s" % (neta, nphi) EGAM3_ClusterEnergyPerLayerDecorator = acc.popToolsAndMerge( ClusterEnergyPerLayerDecoratorCfg( - ConfigFlags, - neta = neta, - nphi=nphi, - name=cename )) + ConfigFlags, neta=neta, nphi=nphi, name=cename + ) + ) acc.addPublicTool(EGAM3_ClusterEnergyPerLayerDecorator) augmentationTools.append(EGAM3_ClusterEnergyPerLayerDecorator) - # thinning tools thinningTools = [] - streamName = kwargs['StreamName'] - + streamName = kwargs["StreamName"] + # Track thinning if ConfigFlags.Derivation.Egamma.doTrackThinning: - from DerivationFrameworkInDet.InDetToolsConfig import ( - TrackParticleThinningCfg, MuonTrackParticleThinningCfg, - TauTrackParticleThinningCfg ) + TrackParticleThinningCfg, + MuonTrackParticleThinningCfg, + TauTrackParticleThinningCfg, + ) TrackThinningKeepElectronTracks = True TrackThinningKeepAllElectronTracks = False @@ -252,140 +297,159 @@ def EGAM3KernelCfg(ConfigFlags, name='EGAM3Kernel', **kwargs): TrackThinningKeepPVTracks = True # Tracks associated with Electrons - if (TrackThinningKeepElectronTracks): - EGAM3ElectronTPThinningTool = \ + if TrackThinningKeepElectronTracks: + EGAM3ElectronTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM3ElectronTPThinningTool', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM3ElectronTPThinningTool", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM3ElectronTPThinningTool) thinningTools.append(EGAM3ElectronTPThinningTool) # Tracks associated with Electrons (all tracks, large cone, for track # isolation studies of the selected electrons) - if (TrackThinningKeepAllElectronTracks): - EGAM3ElectronTPThinningTool2 = \ + if TrackThinningKeepAllElectronTracks: + EGAM3ElectronTPThinningTool2 = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM3ElectronTPThinningTool2', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 4*GeV', - BestMatchOnly = False, - ConeSize = 0.6) + name="EGAM3ElectronTPThinningTool2", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 4*GeV", + BestMatchOnly=False, + ConeSize=0.6, + ) + ) acc.addPublicTool(EGAM3ElectronTPThinningTool2) thinningTools.append(EGAM3ElectronTPThinningTool2) - + # Tracks associated with Photons - if (TrackThinningKeepPhotonTracks): - EGAM3PhotonTPThinningTool = \ + if TrackThinningKeepPhotonTracks: + EGAM3PhotonTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM3PhotonTPThinningTool', - StreamName = streamName, - SGKey = 'Photons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - GSFConversionVerticesKey = 'GSFConversionVertices', - SelectionString = 'Photons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM3PhotonTPThinningTool", + StreamName=streamName, + SGKey="Photons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + GSFConversionVerticesKey="GSFConversionVertices", + SelectionString="Photons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM3PhotonTPThinningTool) thinningTools.append(EGAM3PhotonTPThinningTool) - # Tracks associated with Photons (all tracks, large cone, + # Tracks associated with Photons (all tracks, large cone, # for track isolation studies of the selected photons) - if (TrackThinningKeepAllPhotonTracks): - EGAM3PhotonTPThinningTool2 = \ + if TrackThinningKeepAllPhotonTracks: + EGAM3PhotonTPThinningTool2 = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM3PhotonTPThinningTool2', - StreamName = streamName, - SGKey = 'Photons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - GSFConversionVerticesKey = 'GSFConversionVertices', - SelectionString = 'Photons.pt > 9.5*GeV', - BestMatchOnly = False, - ConeSize = 0.6) + name="EGAM3PhotonTPThinningTool2", + StreamName=streamName, + SGKey="Photons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + GSFConversionVerticesKey="GSFConversionVertices", + SelectionString="Photons.pt > 9.5*GeV", + BestMatchOnly=False, + ConeSize=0.6, + ) + ) acc.addPublicTool(EGAM3PhotonTPThinningTool2) thinningTools.append(EGAM3PhotonTPThinningTool2) # Tracks associated with Jets - if (TrackThinningKeepJetTracks): - EGAM3JetTPThinningTool = \ + if TrackThinningKeepJetTracks: + EGAM3JetTPThinningTool = ( CompFactory.DerivationFramework.JetTrackParticleThinning( - name = 'EGAM3JetTPThinningTool', - StreamName = streamName, - JetKey = 'AntiKt4EMPFlowJets', - InDetTrackParticlesKey = 'InDetTrackParticles') + name="EGAM3JetTPThinningTool", + StreamName=streamName, + JetKey="AntiKt4EMPFlowJets", + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) acc.addPublicTool(EGAM3JetTPThinningTool) thinningTools.append(EGAM3JetTPThinningTool) # Tracks associated with Muons - if (TrackThinningKeepMuonTracks): - EGAM3MuonTPThinningTool = \ - acc.getPrimaryAndMerge(MuonTrackParticleThinningCfg( + if TrackThinningKeepMuonTracks: + EGAM3MuonTPThinningTool = acc.getPrimaryAndMerge( + MuonTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM3MuonTPThinningTool', - StreamName = streamName, - MuonKey = 'Muons', - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM3MuonTPThinningTool", + StreamName=streamName, + MuonKey="Muons", + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM3MuonTPThinningTool) # Tracks associated with Taus - if (TrackThinningKeepTauTracks): - EGAM3TauTPThinningTool = \ - acc.getPrimaryAndMerge(TauTrackParticleThinningCfg( + if TrackThinningKeepTauTracks: + EGAM3TauTPThinningTool = acc.getPrimaryAndMerge( + TauTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM3TauTPThinningTool', - StreamName = streamName, - TauKey = 'TauJets', - ConeSize = 0.6, - InDetTrackParticlesKey = 'InDetTrackParticles', - DoTauTracksThinning = True, - TauTracksKey = 'TauTracks') ) + name="EGAM3TauTPThinningTool", + StreamName=streamName, + TauKey="TauJets", + ConeSize=0.6, + InDetTrackParticlesKey="InDetTrackParticles", + DoTauTracksThinning=True, + TauTracksKey="TauTracks", + ) + ) thinningTools.append(EGAM3TauTPThinningTool) # Tracks from primary vertex - thinning_expression = ' && '.join([ - '(InDetTrackParticles.DFCommonTightPrimary)', - '(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta) < 3.0*mm)', - '(InDetTrackParticles.pt > 10*GeV)']) - if (TrackThinningKeepPVTracks): - EGAM3TPThinningTool = \ - acc.getPrimaryAndMerge(TrackParticleThinningCfg( + thinning_expression = " && ".join( + [ + "(InDetTrackParticles.DFCommonTightPrimary)", + "(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3*mm)", + "(InDetTrackParticles.pt>10*GeV)", + ] + ) + if TrackThinningKeepPVTracks: + EGAM3TPThinningTool = acc.getPrimaryAndMerge( + TrackParticleThinningCfg( ConfigFlags, - name = 'EGAM3TPThinningTool', - StreamName = streamName, - SelectionString = thinning_expression, - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM3TPThinningTool", + StreamName=streamName, + SelectionString=thinning_expression, + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM3TPThinningTool) - # skimming - skimmingTool = acc.popToolsAndMerge( EGAM3SkimmingToolCfg(ConfigFlags)) + skimmingTool = acc.popToolsAndMerge(EGAM3SkimmingToolCfg(ConfigFlags)) acc.addPublicTool(skimmingTool) - # setup the kernel - acc.addEventAlgo(CompFactory.DerivationFramework.DerivationKernel(name, - SkimmingTools = [skimmingTool], - AugmentationTools = augmentationTools, - ThinningTools = thinningTools) ) + acc.addEventAlgo( + CompFactory.DerivationFramework.DerivationKernel( + name, + SkimmingTools=[skimmingTool], + AugmentationTools=augmentationTools, + ThinningTools=thinningTools, + ) + ) return acc def EGAM3Cfg(ConfigFlags): - acc = ComponentAccumulator() - # Get the lists of triggers needed for trigger matching. # This is needed at this scope (for the slimming) and further down # in the config chain for actually configuring the matching, so we create @@ -393,23 +457,29 @@ def EGAM3Cfg(ConfigFlags): # TODO: this should ideally be called higher up to avoid it being run # multiple times in a train from DerivationFrameworkPhys.TriggerListsHelper import TriggerListsHelper + EGAM3TriggerListsHelper = TriggerListsHelper(ConfigFlags) # configure skimming/thinning/augmentation tools - acc.merge(EGAM3KernelCfg(ConfigFlags, - name = 'EGAM3Kernel', - StreamName = 'StreamDAOD_EGAM3', - TriggerListsHelper = EGAM3TriggerListsHelper)) - + acc.merge( + EGAM3KernelCfg( + ConfigFlags, + name="EGAM3Kernel", + StreamName="StreamDAOD_EGAM3", + TriggerListsHelper=EGAM3TriggerListsHelper, + ) + ) # configure slimming from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper + EGAM3SlimmingHelper = SlimmingHelper( - 'EGAM3SlimmingHelper', - NamesAndTypes = ConfigFlags.Input.TypedCollections, - ConfigFlags = ConfigFlags ) + "EGAM3SlimmingHelper", + NamesAndTypes=ConfigFlags.Input.TypedCollections, + ConfigFlags=ConfigFlags, + ) # ------------------------------------------ # containers for which we save all variables @@ -417,20 +487,21 @@ def EGAM3Cfg(ConfigFlags): # baseline EGAM3SlimmingHelper.AllVariables = [ - 'Photons', - 'GSFTrackParticles', - 'egammaClusters', - 'ForwardElectrons', - 'ForwardElectronClusters' ] - + "Photons", + "GSFTrackParticles", + "egammaClusters", + "ForwardElectrons", + "ForwardElectronClusters", + ] + # for trigger studies we also add: MenuType = None if ConfigFlags.Trigger.EDMVersion == 2: - MenuType = 'Run2' + MenuType = "Run2" elif ConfigFlags.Trigger.EDMVersion == 3: - MenuType = 'Run3' + MenuType = "Run3" else: - MenuType = '' + MenuType = "" EGAM3SlimmingHelper.AllVariables += ExtraContainersTrigger[MenuType] EGAM3SlimmingHelper.AllVariables += ExtraContainersPhotonTrigger[MenuType] EGAM3SlimmingHelper.AllVariables += ExtraContainersElectronTrigger[MenuType] @@ -439,76 +510,86 @@ def EGAM3Cfg(ConfigFlags): # and on MC we also add: if ConfigFlags.Input.isMC: - EGAM3SlimmingHelper.AllVariables +=[ - 'TruthEvents', - 'TruthParticles', - 'TruthVertices', - 'egammaTruthParticles', - 'MuonTruthParticles' + EGAM3SlimmingHelper.AllVariables += [ + "TruthEvents", + "TruthParticles", + "TruthVertices", + "egammaTruthParticles", + "MuonTruthParticles", ] - # ------------------------------------------- # containers that we slim # ------------------------------------------- - # first add variables from smart-slimming + # first add variables from smart-slimming # adding only also those for which we add all variables since - # the XXXCPContent.py files also bring in some extra variables + # the XXXCPContent.py files also bring in some extra variables # for other collections - EGAM3SlimmingHelper.SmartCollections = ['Electrons', - 'Photons', - 'Muons', - 'TauJets', - 'PrimaryVertices', - 'InDetTrackParticles', - 'AntiKt4EMPFlowJets', - 'BTagging_AntiKt4EMPFlow', - 'MET_Baseline_AntiKt4EMPFlow', - ] + EGAM3SlimmingHelper.SmartCollections = [ + "Electrons", + "Photons", + "Muons", + "TauJets", + "PrimaryVertices", + "InDetTrackParticles", + "AntiKt4EMPFlowJets", + "BTagging_AntiKt4EMPFlow", + "MET_Baseline_AntiKt4EMPFlow", + ] if ConfigFlags.Input.isMC: - EGAM3SlimmingHelper.SmartCollections += ['AntiKt4TruthJets', - 'AntiKt4TruthDressedWZJets'] + EGAM3SlimmingHelper.SmartCollections += [ + "AntiKt4TruthJets", + "AntiKt4TruthDressedWZJets", + ] # then add extra variables: # electrons - EGAM3SlimmingHelper.ExtraVariables += [ - 'Electrons.Loose.Medium.Tight' ] + EGAM3SlimmingHelper.ExtraVariables += ["Electrons.Loose.Medium.Tight"] # muons EGAM3SlimmingHelper.ExtraVariables += [ - 'Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40' ] + "Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40" + ] # conversion vertices EGAM3SlimmingHelper.ExtraVariables += [ - 'GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo', - 'GSFConversionVertices.trackParticleLinks' ] + "GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo", + "GSFConversionVertices.trackParticleLinks", + ] # primary vertices - EGAM3SlimmingHelper.ExtraVariables += [ - 'PrimaryVertices.x.y.sumPt2' ] + EGAM3SlimmingHelper.ExtraVariables += ["PrimaryVertices.x.y.sumPt2"] # energy density - EGAM3SlimmingHelper.ExtraVariables += [ - 'TopoClusterIsoCentralEventShape.Density', - 'TopoClusterIsoForwardEventShape.Density', - 'NeutralParticleFlowIsoCentralEventShape.Density', - 'NeutralParticleFlowIsoForwardEventShape.Density'] + EGAM3SlimmingHelper.ExtraVariables += [ + "TopoClusterIsoCentralEventShape.Density", + "TopoClusterIsoForwardEventShape.Density", + "NeutralParticleFlowIsoCentralEventShape.Density", + "NeutralParticleFlowIsoForwardEventShape.Density", + ] from DerivationFrameworkEGamma import EGammaIsoConfig - pflowIsoVar,densityList,densityDict,acc1 = \ - EGammaIsoConfig.makeEGammaCommonIsoCfg(ConfigFlags) + + ( + pflowIsoVar, + densityList, + densityDict, + acc1, + ) = EGammaIsoConfig.makeEGammaCommonIsoCfg(ConfigFlags) acc.merge(acc1) EGAM3SlimmingHelper.AppendToDictionary.update(densityDict) EGAM3SlimmingHelper.ExtraVariables += densityList # To have ptcone40 from IsolationAlgs.DerivationTrackIsoConfig import DerivationTrackIsoCfg - acc.merge(DerivationTrackIsoCfg(ConfigFlags, - object_types = ('Photons',), - ptCuts = (500,1000), - postfix = 'Extra')) + + acc.merge( + DerivationTrackIsoCfg( + ConfigFlags, object_types=("Photons",), ptCuts=(500, 1000), postfix="Extra" + ) + ) # electrons: detailed shower shape and track variables EGAM3SlimmingHelper.ExtraVariables += ElectronsCPDetailedContent @@ -516,13 +597,15 @@ def EGAM3Cfg(ConfigFlags): # photons and electrons: gain and cluster energy per layer from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - getGainDecorations, getClusterEnergyPerLayerDecorations ) - gainDecorations = getGainDecorations(acc, 'EGAM3Kernel') - print('EGAM3 gain decorations: ', gainDecorations) + getGainDecorations, + getClusterEnergyPerLayerDecorations, + ) + + gainDecorations = getGainDecorations(acc, "EGAM3Kernel") + print("EGAM3 gain decorations: ", gainDecorations) EGAM3SlimmingHelper.ExtraVariables.extend(gainDecorations) - clusterEnergyDecorations = getClusterEnergyPerLayerDecorations( - acc, 'EGAM3Kernel' ) - print('EGAM3 cluster energy decorations: ', clusterEnergyDecorations) + clusterEnergyDecorations = getClusterEnergyPerLayerDecorations(acc, "EGAM3Kernel") + print("EGAM3 cluster energy decorations: ", clusterEnergyDecorations) EGAM3SlimmingHelper.ExtraVariables.extend(clusterEnergyDecorations) # photon HLT variables @@ -531,13 +614,14 @@ def EGAM3Cfg(ConfigFlags): # truth if ConfigFlags.Input.isMC: EGAM3SlimmingHelper.ExtraVariables += [ - 'Electrons.truthOrigin.truthType.truthParticleLink' ] + "Electrons.truthOrigin.truthType.truthParticleLink" + ] # Add event info if ConfigFlags.Derivation.Egamma.doEventInfoSlimming: - EGAM3SlimmingHelper.SmartCollections.append('EventInfo') + EGAM3SlimmingHelper.SmartCollections.append("EventInfo") else: - EGAM3SlimmingHelper.AllVariables += ['EventInfo'] + EGAM3SlimmingHelper.AllVariables += ["EventInfo"] # Add egamma trigger objects EGAM3SlimmingHelper.IncludeEGammaTriggerContent = True @@ -546,39 +630,57 @@ def EGAM3Cfg(ConfigFlags): # Run 2 if ConfigFlags.Trigger.EDMVersion == 2: from DerivationFrameworkPhys.TriggerMatchingCommonConfig import ( - AddRun2TriggerMatchingToSlimmingHelper ) + AddRun2TriggerMatchingToSlimmingHelper, + ) + AddRun2TriggerMatchingToSlimmingHelper( - SlimmingHelper = EGAM3SlimmingHelper, - OutputContainerPrefix = 'TrigMatch_', - TriggerList = EGAM3TriggerListsHelper.Run2TriggerNamesNoTau) + SlimmingHelper=EGAM3SlimmingHelper, + OutputContainerPrefix="TrigMatch_", + TriggerList=EGAM3TriggerListsHelper.Run2TriggerNamesNoTau, + ) # Run 3 if ConfigFlags.Trigger.EDMVersion == 3: from TrigNavSlimmingMT.TrigNavSlimmingMTConfig import ( - AddRun3TrigNavSlimmingCollectionsToSlimmingHelper ) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper, + ) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper(EGAM3SlimmingHelper) # Run 2 is added here temporarily to allow testing/comparison/debugging from DerivationFrameworkPhys.TriggerMatchingCommonConfig import ( - AddRun2TriggerMatchingToSlimmingHelper ) + AddRun2TriggerMatchingToSlimmingHelper, + ) + AddRun2TriggerMatchingToSlimmingHelper( - SlimmingHelper = EGAM3SlimmingHelper, - OutputContainerPrefix = 'TrigMatch_', - TriggerList = EGAM3TriggerListsHelper.Run3TriggerNamesNoTau) + SlimmingHelper=EGAM3SlimmingHelper, + OutputContainerPrefix="TrigMatch_", + TriggerList=EGAM3TriggerListsHelper.Run3TriggerNamesNoTau, + ) # Add full CellContainer EGAM3SlimmingHelper.StaticContent = [ - 'CaloCellContainer#AllCalo', - 'CaloClusterCellLinkContainer#egammaClusters_links'] - + "CaloCellContainer#AllCalo", + "CaloClusterCellLinkContainer#egammaClusters_links", + ] + EGAM3ItemList = EGAM3SlimmingHelper.GetItemList() - acc.merge(OutputStreamCfg(ConfigFlags, - 'DAOD_EGAM3', - ItemList = EGAM3ItemList, - AcceptAlgs = ['EGAM3Kernel'])) - acc.merge(SetupMetaDataForStreamCfg(ConfigFlags, 'DAOD_EGAM3', - AcceptAlgs=['EGAM3Kernel'], - createMetadata=[ - MetadataCategory.CutFlowMetaData, - MetadataCategory.TruthMetaData, - ])) + acc.merge( + OutputStreamCfg( + ConfigFlags, + "DAOD_EGAM3", + ItemList=EGAM3ItemList, + AcceptAlgs=["EGAM3Kernel"], + ) + ) + acc.merge( + SetupMetaDataForStreamCfg( + ConfigFlags, + "DAOD_EGAM3", + AcceptAlgs=["EGAM3Kernel"], + createMetadata=[ + MetadataCategory.CutFlowMetaData, + MetadataCategory.TruthMetaData, + ], + ) + ) return acc diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM4.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM4.py index b829bdc2a184..c75adb0ec029 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM4.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM4.py @@ -1,11 +1,10 @@ # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration -#!/usr/bin/env python -#==================================================================== +# ==================================================================== # EGAM4.py # This defines DAOD_EGAM4, a skimmed DAOD format for Run 3. # Z->mumugamma and mumue reduction for photon (and fake photon->e) studies -# It requires the flag EGAM4 in Derivation_tf.py -#==================================================================== +# It requires the flag EGAM4 in Derivation_tf.py +# ==================================================================== from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory @@ -14,94 +13,111 @@ from AthenaConfiguration.Enums import MetadataCategory from AthenaCommon.SystemOfUnits import MeV from DerivationFrameworkEGamma.ElectronsCPDetailedContent import ( - ElectronsCPDetailedContent, GSFTracksCPDetailedContent ) + ElectronsCPDetailedContent, + GSFTracksCPDetailedContent, +) from DerivationFrameworkEGamma.TriggerContent import ( - ExtraContainersTrigger, ExtraContainersPhotonTrigger, - ExtraContainersMuonTrigger, ExtraContainersTriggerDataOnly ) + ExtraContainersTrigger, + ExtraContainersPhotonTrigger, + ExtraContainersMuonTrigger, + ExtraContainersTriggerDataOnly, +) def EGAM4SkimmingToolCfg(flags): - '''Configure the EGAM4 skimming tool''' + """Configure the EGAM4 skimming tool""" acc = ComponentAccumulator() # mumugamma: one reco photon (ET>10 GeV) and OS muon pair w/ m>40 GeV - expression1a = ' && '.join(['(count(DFCommonPhotons_et>9.5*GeV)>=1)', - '(count(EGAM4_DiMuonMass > 40.0*GeV)>=1)']) - + expression1a = " && ".join( + [ + "(count(DFCommonPhotons_et>9.5*GeV)>=1)", + "(count(EGAM4_DiMuonMass > 40.0*GeV)>=1)", + ] + ) + # mumue: one reco e (ET>10 GeV) and OS muon pair w/ m>40 GeV - expression1b = ' && '.join(['(count(Electrons.pt>9.5*GeV)>=1)', - '(count(EGAM4_DiMuonMass > 40.0*GeV)>=1)']) - + expression1b = " && ".join( + ["(count(Electrons.pt>9.5*GeV)>=1)", "(count(EGAM4_DiMuonMass > 40.0*GeV)>=1)"] + ) + # take OR of previous selections - expression = '( ' + expression1a + ' ) || ( ' + expression1b + ' )' - print('EGAM4 skimming expression: ', expression) + expression = "( " + expression1a + " ) || ( " + expression1b + " )" + print("EGAM4 skimming expression: ", expression) - acc.setPrivateTools( CompFactory.DerivationFramework.xAODStringSkimmingTool( - name = 'EGAM4SkimmingTool', - expression = expression) ) - - return(acc) + acc.setPrivateTools( + CompFactory.DerivationFramework.xAODStringSkimmingTool( + name="EGAM4SkimmingTool", expression=expression + ) + ) + + return acc def EGAM4mumuMassToolCfg(flags): - '''Configure the EGAM4 mumu invariant mass augmentation tool''' + """Configure the EGAM4 mumu invariant mass augmentation tool""" acc = ComponentAccumulator() - # ==================================================================== + # ==================================================================== # invariant mass of two OS muons with pT>10 GeV passing preselection # ==================================================================== - requirementMuons = ' && '.join(['Muons.pt>9.5*GeV', - 'abs(Muons.eta)<2.7', - 'Muons.DFCommonMuonPassPreselection']) - - acc.setPrivateTools( CompFactory.DerivationFramework.EGInvariantMassTool( - name = 'EGAM4_MuMuMassTool', - Object1Requirements = requirementMuons, - Object2Requirements = requirementMuons, - StoreGateEntryName = 'EGAM4_DiMuonMass', - Mass1Hypothesis = 105*MeV, - Mass2Hypothesis = 105*MeV, - Container1Name = 'Muons', - Container2Name = 'Muons', - CheckCharge = True, - DoTransverseMass = False, - MinDeltaR=0.0) ) + requirementMuons = " && ".join( + ["Muons.pt>9.5*GeV", "abs(Muons.eta)<2.7", "Muons.DFCommonMuonPassPreselection"] + ) + + acc.setPrivateTools( + CompFactory.DerivationFramework.EGInvariantMassTool( + name="EGAM4_MuMuMassTool", + Object1Requirements=requirementMuons, + Object2Requirements=requirementMuons, + StoreGateEntryName="EGAM4_DiMuonMass", + Mass1Hypothesis=105 * MeV, + Mass2Hypothesis=105 * MeV, + Container1Name="Muons", + Container2Name="Muons", + CheckCharge=True, + DoTransverseMass=False, + MinDeltaR=0.0, + ) + ) return acc # Main algorithm config -def EGAM4KernelCfg(ConfigFlags, name='EGAM4Kernel', **kwargs): - '''Configure the derivation framework driving algorithm (kernel) - for EGAM4''' +def EGAM4KernelCfg(ConfigFlags, name="EGAM4Kernel", **kwargs): + """Configure the derivation framework driving algorithm (kernel) + for EGAM4""" acc = ComponentAccumulator() - # Common augmentations - from DerivationFrameworkPhys.PhysCommonConfig import ( - PhysCommonAugmentationsCfg ) - acc.merge( PhysCommonAugmentationsCfg( - ConfigFlags, - TriggerListsHelper = kwargs['TriggerListsHelper'] ) ) - + from DerivationFrameworkPhys.PhysCommonConfig import PhysCommonAugmentationsCfg + + acc.merge( + PhysCommonAugmentationsCfg( + ConfigFlags, TriggerListsHelper=kwargs["TriggerListsHelper"] + ) + ) # EGAM4 augmentations augmentationTools = [] - #==================================================================== + # ==================================================================== # ee and egamma invariant masses - #==================================================================== + # ==================================================================== EGAM4mumuMassTool = acc.popToolsAndMerge(EGAM4mumuMassToolCfg(ConfigFlags)) acc.addPublicTool(EGAM4mumuMassTool) augmentationTools.append(EGAM4mumuMassTool) - #==================================================================== + # ==================================================================== # Max Cell energy and time - #==================================================================== - from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - MaxCellDecoratorCfg ) + # ==================================================================== + from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( + MaxCellDecoratorCfg, + ) + MaxCellDecorator = acc.popToolsAndMerge(MaxCellDecoratorCfg(ConfigFlags)) acc.addPublicTool(MaxCellDecorator) augmentationTools.append(MaxCellDecorator) @@ -109,43 +125,45 @@ def EGAM4KernelCfg(ConfigFlags, name='EGAM4Kernel', **kwargs): # ==================================================================== # Cell reweighter # ==================================================================== - # ==================================================================== # Gain and cluster energies per layer decoration tool # ==================================================================== from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - GainDecoratorCfg, ClusterEnergyPerLayerDecoratorCfg ) + GainDecoratorCfg, + ClusterEnergyPerLayerDecoratorCfg, + ) + EGAM4_GainDecoratorTool = acc.popToolsAndMerge( - GainDecoratorCfg(ConfigFlags, name = 'EGAM4_GainDecoratorTool' )) + GainDecoratorCfg(ConfigFlags, name="EGAM4_GainDecoratorTool") + ) acc.addPublicTool(EGAM4_GainDecoratorTool) augmentationTools.append(EGAM4_GainDecoratorTool) - # might need some modification when cell-level reweighting is implemented + # might need some modification when cell-level reweighting is implemented # (see share/EGAM4.py) - cluster_sizes = (3,7), (5,5), (7,11) + cluster_sizes = (3, 7), (5, 5), (7, 11) for neta, nphi in cluster_sizes: - cename = 'EGAM4_ClusterEnergyPerLayerDecorator_%sx%s' % (neta, nphi) + cename = "EGAM4_ClusterEnergyPerLayerDecorator_%sx%s" % (neta, nphi) EGAM4_ClusterEnergyPerLayerDecorator = acc.popToolsAndMerge( ClusterEnergyPerLayerDecoratorCfg( - ConfigFlags, - neta = neta, - nphi=nphi, - name=cename )) + ConfigFlags, neta=neta, nphi=nphi, name=cename + ) + ) acc.addPublicTool(EGAM4_ClusterEnergyPerLayerDecorator) augmentationTools.append(EGAM4_ClusterEnergyPerLayerDecorator) - # thinning tools thinningTools = [] - streamName = kwargs['StreamName'] + streamName = kwargs["StreamName"] # Track thinning if ConfigFlags.Derivation.Egamma.doTrackThinning: - from DerivationFrameworkInDet.InDetToolsConfig import ( - TrackParticleThinningCfg, MuonTrackParticleThinningCfg, - TauTrackParticleThinningCfg ) + TrackParticleThinningCfg, + MuonTrackParticleThinningCfg, + TauTrackParticleThinningCfg, + ) TrackThinningKeepElectronTracks = True TrackThinningKeepAllElectronTracks = False @@ -157,140 +175,159 @@ def EGAM4KernelCfg(ConfigFlags, name='EGAM4Kernel', **kwargs): TrackThinningKeepPVTracks = True # Tracks associated with Electrons - if (TrackThinningKeepElectronTracks): - EGAM4ElectronTPThinningTool = \ + if TrackThinningKeepElectronTracks: + EGAM4ElectronTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM4ElectronTPThinningTool', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM4ElectronTPThinningTool", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM4ElectronTPThinningTool) thinningTools.append(EGAM4ElectronTPThinningTool) # Tracks associated with Electrons (all tracks, large cone, for track # isolation studies of the selected electrons) - if (TrackThinningKeepAllElectronTracks): - EGAM4ElectronTPThinningTool2 = \ + if TrackThinningKeepAllElectronTracks: + EGAM4ElectronTPThinningTool2 = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM4ElectronTPThinningTool2', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 4*GeV', - BestMatchOnly = False, - ConeSize = 0.6) + name="EGAM4ElectronTPThinningTool2", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 4*GeV", + BestMatchOnly=False, + ConeSize=0.6, + ) + ) acc.addPublicTool(EGAM4ElectronTPThinningTool2) thinningTools.append(EGAM4ElectronTPThinningTool2) - + # Tracks associated with Photons - if (TrackThinningKeepPhotonTracks): - EGAM4PhotonTPThinningTool = \ + if TrackThinningKeepPhotonTracks: + EGAM4PhotonTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM4PhotonTPThinningTool', - StreamName = streamName, - SGKey = 'Photons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - GSFConversionVerticesKey = 'GSFConversionVertices', - SelectionString = 'Photons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM4PhotonTPThinningTool", + StreamName=streamName, + SGKey="Photons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + GSFConversionVerticesKey="GSFConversionVertices", + SelectionString="Photons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM4PhotonTPThinningTool) thinningTools.append(EGAM4PhotonTPThinningTool) - # Tracks associated with Photons (all tracks, large cone, + # Tracks associated with Photons (all tracks, large cone, # for track isolation studies of the selected photons) - if (TrackThinningKeepAllPhotonTracks): - EGAM4PhotonTPThinningTool2 = \ + if TrackThinningKeepAllPhotonTracks: + EGAM4PhotonTPThinningTool2 = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM4PhotonTPThinningTool2', - StreamName = streamName, - SGKey = 'Photons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - GSFConversionVerticesKey = 'GSFConversionVertices', - SelectionString = 'Photons.pt > 9.5*GeV', - BestMatchOnly = False, - ConeSize = 0.6) + name="EGAM4PhotonTPThinningTool2", + StreamName=streamName, + SGKey="Photons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + GSFConversionVerticesKey="GSFConversionVertices", + SelectionString="Photons.pt > 9.5*GeV", + BestMatchOnly=False, + ConeSize=0.6, + ) + ) acc.addPublicTool(EGAM4PhotonTPThinningTool2) thinningTools.append(EGAM4PhotonTPThinningTool2) # Tracks associated with Jets - if (TrackThinningKeepJetTracks): - EGAM4JetTPThinningTool = \ + if TrackThinningKeepJetTracks: + EGAM4JetTPThinningTool = ( CompFactory.DerivationFramework.JetTrackParticleThinning( - name = 'EGAM4JetTPThinningTool', - StreamName = streamName, - JetKey = 'AntiKt4EMPFlowJets', - InDetTrackParticlesKey = 'InDetTrackParticles') + name="EGAM4JetTPThinningTool", + StreamName=streamName, + JetKey="AntiKt4EMPFlowJets", + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) acc.addPublicTool(EGAM4JetTPThinningTool) thinningTools.append(EGAM4JetTPThinningTool) # Tracks associated with Muons - if (TrackThinningKeepMuonTracks): - EGAM4MuonTPThinningTool = \ - acc.getPrimaryAndMerge(MuonTrackParticleThinningCfg( + if TrackThinningKeepMuonTracks: + EGAM4MuonTPThinningTool = acc.getPrimaryAndMerge( + MuonTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM4MuonTPThinningTool', - StreamName = streamName, - MuonKey = 'Muons', - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM4MuonTPThinningTool", + StreamName=streamName, + MuonKey="Muons", + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM4MuonTPThinningTool) # Tracks associated with Taus - if (TrackThinningKeepTauTracks): - EGAM4TauTPThinningTool = \ - acc.getPrimaryAndMerge(TauTrackParticleThinningCfg( + if TrackThinningKeepTauTracks: + EGAM4TauTPThinningTool = acc.getPrimaryAndMerge( + TauTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM4TauTPThinningTool', - StreamName = streamName, - TauKey = 'TauJets', - ConeSize = 0.6, - InDetTrackParticlesKey = 'InDetTrackParticles', - DoTauTracksThinning = True, - TauTracksKey = 'TauTracks') ) + name="EGAM4TauTPThinningTool", + StreamName=streamName, + TauKey="TauJets", + ConeSize=0.6, + InDetTrackParticlesKey="InDetTrackParticles", + DoTauTracksThinning=True, + TauTracksKey="TauTracks", + ) + ) thinningTools.append(EGAM4TauTPThinningTool) # Tracks from primary vertex - thinning_expression = ' && '.join([ - '(InDetTrackParticles.DFCommonTightPrimary)', - '(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta) < 3.0*mm)', - '(InDetTrackParticles.pt > 10*GeV)']) - if (TrackThinningKeepPVTracks): - EGAM4TPThinningTool = \ - acc.getPrimaryAndMerge(TrackParticleThinningCfg( + thinning_expression = " && ".join( + [ + "(InDetTrackParticles.DFCommonTightPrimary)", + "(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3*mm)", + "(InDetTrackParticles.pt>10*GeV)", + ] + ) + if TrackThinningKeepPVTracks: + EGAM4TPThinningTool = acc.getPrimaryAndMerge( + TrackParticleThinningCfg( ConfigFlags, - name = 'EGAM4TPThinningTool', - StreamName = streamName, - SelectionString = thinning_expression, - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM4TPThinningTool", + StreamName=streamName, + SelectionString=thinning_expression, + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM4TPThinningTool) - # skimming skimmingTool = acc.popToolsAndMerge(EGAM4SkimmingToolCfg(ConfigFlags)) acc.addPublicTool(skimmingTool) - # setup the kernel - acc.addEventAlgo(CompFactory.DerivationFramework.DerivationKernel(name, - SkimmingTools = [skimmingTool], - AugmentationTools = augmentationTools, - ThinningTools = thinningTools) ) + acc.addEventAlgo( + CompFactory.DerivationFramework.DerivationKernel( + name, + SkimmingTools=[skimmingTool], + AugmentationTools=augmentationTools, + ThinningTools=thinningTools, + ) + ) return acc def EGAM4Cfg(ConfigFlags): - acc = ComponentAccumulator() - # Get the lists of triggers needed for trigger matching. # This is needed at this scope (for the slimming) and further down # in the config chain for actually configuring the matching, so we create @@ -298,29 +335,38 @@ def EGAM4Cfg(ConfigFlags): # TODO: this should ideally be called higher up to avoid it being run # multiple times in a train from DerivationFrameworkPhys.TriggerListsHelper import TriggerListsHelper + EGAM4TriggerListsHelper = TriggerListsHelper(ConfigFlags) # configure skimming/thinning/augmentation tools - acc.merge(EGAM4KernelCfg(ConfigFlags, - name = 'EGAM4Kernel', - StreamName = 'StreamDAOD_EGAM4', - TriggerListsHelper = EGAM4TriggerListsHelper)) + acc.merge( + EGAM4KernelCfg( + ConfigFlags, + name="EGAM4Kernel", + StreamName="StreamDAOD_EGAM4", + TriggerListsHelper=EGAM4TriggerListsHelper, + ) + ) # To have ptcone40 from IsolationAlgs.DerivationTrackIsoConfig import DerivationTrackIsoCfg - acc.merge(DerivationTrackIsoCfg(ConfigFlags, - object_types = ('Photons',), - ptCuts = (500,1000), - postfix = 'Extra')) + + acc.merge( + DerivationTrackIsoCfg( + ConfigFlags, object_types=("Photons",), ptCuts=(500, 1000), postfix="Extra" + ) + ) # configure slimming from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper + EGAM4SlimmingHelper = SlimmingHelper( - 'EGAM4SlimmingHelper', - NamesAndTypes = ConfigFlags.Input.TypedCollections, - ConfigFlags = ConfigFlags ) + "EGAM4SlimmingHelper", + NamesAndTypes=ConfigFlags.Input.TypedCollections, + ConfigFlags=ConfigFlags, + ) # ------------------------------------------ # containers for which we save all variables @@ -328,18 +374,19 @@ def EGAM4Cfg(ConfigFlags): # baseline EGAM4SlimmingHelper.AllVariables = [ - 'Photons', - 'GSFTrackParticles', - 'egammaClusters'] - + "Photons", + "GSFTrackParticles", + "egammaClusters", + ] + # for trigger studies we also add: MenuType = None if ConfigFlags.Trigger.EDMVersion == 2: - MenuType = 'Run2' + MenuType = "Run2" elif ConfigFlags.Trigger.EDMVersion == 3: - MenuType = 'Run3' + MenuType = "Run3" else: - MenuType = '' + MenuType = "" EGAM4SlimmingHelper.AllVariables += ExtraContainersTrigger[MenuType] EGAM4SlimmingHelper.AllVariables += ExtraContainersPhotonTrigger[MenuType] EGAM4SlimmingHelper.AllVariables += ExtraContainersMuonTrigger[MenuType] @@ -348,62 +395,65 @@ def EGAM4Cfg(ConfigFlags): # and on MC we also add: if ConfigFlags.Input.isMC: - EGAM4SlimmingHelper.AllVariables +=[ - 'TruthEvents', - 'TruthParticles', - 'TruthVertices', - 'egammaTruthParticles', - 'MuonTruthParticles' + EGAM4SlimmingHelper.AllVariables += [ + "TruthEvents", + "TruthParticles", + "TruthVertices", + "egammaTruthParticles", + "MuonTruthParticles", ] - # ------------------------------------------- # containers that we slim # ------------------------------------------- - # first add variables from smart-slimming + # first add variables from smart-slimming # adding only also those for which we add all variables since - # the XXXCPContent.py files also bring in some extra variables + # the XXXCPContent.py files also bring in some extra variables # for other collections - EGAM4SlimmingHelper.SmartCollections = ['Electrons', - 'Photons', - 'Muons', - 'TauJets', - 'PrimaryVertices', - 'InDetTrackParticles', - 'AntiKt4EMPFlowJets', - 'BTagging_AntiKt4EMPFlow', - 'MET_Baseline_AntiKt4EMPFlow', - ] + EGAM4SlimmingHelper.SmartCollections = [ + "Electrons", + "Photons", + "Muons", + "TauJets", + "PrimaryVertices", + "InDetTrackParticles", + "AntiKt4EMPFlowJets", + "BTagging_AntiKt4EMPFlow", + "MET_Baseline_AntiKt4EMPFlow", + ] if ConfigFlags.Input.isMC: - EGAM4SlimmingHelper.SmartCollections += ['AntiKt4TruthJets', - 'AntiKt4TruthDressedWZJets'] + EGAM4SlimmingHelper.SmartCollections += [ + "AntiKt4TruthJets", + "AntiKt4TruthDressedWZJets", + ] # then add extra variables: # electrons - EGAM4SlimmingHelper.ExtraVariables += [ - 'Electrons.Loose.Medium.Tight' ] + EGAM4SlimmingHelper.ExtraVariables += ["Electrons.Loose.Medium.Tight"] # muons EGAM4SlimmingHelper.ExtraVariables += [ - 'Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40' ] + "Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40" + ] # conversion vertices EGAM4SlimmingHelper.ExtraVariables += [ - 'GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo', - 'GSFConversionVertices.trackParticleLinks' ] + "GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo", + "GSFConversionVertices.trackParticleLinks", + ] # primary vertices - EGAM4SlimmingHelper.ExtraVariables += [ - 'PrimaryVertices.x.y.sumPt2' ] + EGAM4SlimmingHelper.ExtraVariables += ["PrimaryVertices.x.y.sumPt2"] # energy density - EGAM4SlimmingHelper.ExtraVariables += [ - 'TopoClusterIsoCentralEventShape.Density', - 'TopoClusterIsoForwardEventShape.Density', - 'NeutralParticleFlowIsoCentralEventShape.Density', - 'NeutralParticleFlowIsoForwardEventShape.Density'] + EGAM4SlimmingHelper.ExtraVariables += [ + "TopoClusterIsoCentralEventShape.Density", + "TopoClusterIsoForwardEventShape.Density", + "NeutralParticleFlowIsoCentralEventShape.Density", + "NeutralParticleFlowIsoForwardEventShape.Density", + ] # electrons: detailed shower shape and track variables EGAM4SlimmingHelper.ExtraVariables += ElectronsCPDetailedContent @@ -412,25 +462,28 @@ def EGAM4Cfg(ConfigFlags): # photons and electrons: gain and cluster energy per layer # code would not be needed for photons since we save every photon variable from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - getGainDecorations, getClusterEnergyPerLayerDecorations ) - gainDecorations = getGainDecorations(acc, 'EGAM4Kernel') - print('EGAM4 gain decorations: ', gainDecorations) + getGainDecorations, + getClusterEnergyPerLayerDecorations, + ) + + gainDecorations = getGainDecorations(acc, "EGAM4Kernel") + print("EGAM4 gain decorations: ", gainDecorations) EGAM4SlimmingHelper.ExtraVariables.extend(gainDecorations) - clusterEnergyDecorations = getClusterEnergyPerLayerDecorations( - acc, 'EGAM4Kernel' ) - print('EGAM4 cluster energy decorations: ', clusterEnergyDecorations) + clusterEnergyDecorations = getClusterEnergyPerLayerDecorations(acc, "EGAM4Kernel") + print("EGAM4 cluster energy decorations: ", clusterEnergyDecorations) EGAM4SlimmingHelper.ExtraVariables.extend(clusterEnergyDecorations) # truth if ConfigFlags.Input.isMC: EGAM4SlimmingHelper.ExtraVariables += [ - 'Electrons.truthOrigin.truthType.truthParticleLink' ] + "Electrons.truthOrigin.truthType.truthParticleLink" + ] # Add event info if ConfigFlags.Derivation.Egamma.doEventInfoSlimming: - EGAM4SlimmingHelper.SmartCollections.append('EventInfo') + EGAM4SlimmingHelper.SmartCollections.append("EventInfo") else: - EGAM4SlimmingHelper.AllVariables += ['EventInfo'] + EGAM4SlimmingHelper.AllVariables += ["EventInfo"] # Add egamma trigger objects EGAM4SlimmingHelper.IncludeEGammaTriggerContent = True @@ -440,39 +493,57 @@ def EGAM4Cfg(ConfigFlags): # Run 2 if ConfigFlags.Trigger.EDMVersion == 2: from DerivationFrameworkPhys.TriggerMatchingCommonConfig import ( - AddRun2TriggerMatchingToSlimmingHelper ) + AddRun2TriggerMatchingToSlimmingHelper, + ) + AddRun2TriggerMatchingToSlimmingHelper( - SlimmingHelper = EGAM4SlimmingHelper, - OutputContainerPrefix = 'TrigMatch_', - TriggerList = EGAM4TriggerListsHelper.Run2TriggerNamesNoTau) + SlimmingHelper=EGAM4SlimmingHelper, + OutputContainerPrefix="TrigMatch_", + TriggerList=EGAM4TriggerListsHelper.Run2TriggerNamesNoTau, + ) # Run 3 if ConfigFlags.Trigger.EDMVersion == 3: from TrigNavSlimmingMT.TrigNavSlimmingMTConfig import ( - AddRun3TrigNavSlimmingCollectionsToSlimmingHelper ) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper, + ) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper(EGAM4SlimmingHelper) # Run 2 is added here temporarily to allow testing/comparison/debugging from DerivationFrameworkPhys.TriggerMatchingCommonConfig import ( - AddRun2TriggerMatchingToSlimmingHelper ) + AddRun2TriggerMatchingToSlimmingHelper, + ) + AddRun2TriggerMatchingToSlimmingHelper( - SlimmingHelper = EGAM4SlimmingHelper, - OutputContainerPrefix = 'TrigMatch_', - TriggerList = EGAM4TriggerListsHelper.Run3TriggerNamesNoTau) + SlimmingHelper=EGAM4SlimmingHelper, + OutputContainerPrefix="TrigMatch_", + TriggerList=EGAM4TriggerListsHelper.Run3TriggerNamesNoTau, + ) # Add full CellContainer EGAM4SlimmingHelper.StaticContent = [ - 'CaloCellContainer#AllCalo', - 'CaloClusterCellLinkContainer#egammaClusters_links'] - + "CaloCellContainer#AllCalo", + "CaloClusterCellLinkContainer#egammaClusters_links", + ] + EGAM4ItemList = EGAM4SlimmingHelper.GetItemList() - acc.merge(OutputStreamCfg(ConfigFlags, - 'DAOD_EGAM4', - ItemList = EGAM4ItemList, - AcceptAlgs = ['EGAM4Kernel'])) - acc.merge(SetupMetaDataForStreamCfg(ConfigFlags, 'DAOD_EGAM4', - AcceptAlgs=['EGAM4Kernel'], - createMetadata=[ - MetadataCategory.CutFlowMetaData, - MetadataCategory.TruthMetaData, - ])) + acc.merge( + OutputStreamCfg( + ConfigFlags, + "DAOD_EGAM4", + ItemList=EGAM4ItemList, + AcceptAlgs=["EGAM4Kernel"], + ) + ) + acc.merge( + SetupMetaDataForStreamCfg( + ConfigFlags, + "DAOD_EGAM4", + AcceptAlgs=["EGAM4Kernel"], + createMetadata=[ + MetadataCategory.CutFlowMetaData, + MetadataCategory.TruthMetaData, + ], + ) + ) return acc diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM5.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM5.py index 6808d278d0ae..980982838fd9 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM5.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM5.py @@ -1,11 +1,10 @@ # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration -#!/usr/bin/env python -#==================================================================== +# ==================================================================== # EGAM5.py # This defines DAOD_EGAM5, a skimmed DAOD format for Run 3. # W->enu derivation -# It requires the flag EGAM5 in Derivation_tf.py -#==================================================================== +# It requires the flag EGAM5 in Derivation_tf.py +# ==================================================================== from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory @@ -14,81 +13,87 @@ from AthenaConfiguration.Enums import MetadataCategory from AthenaCommon.SystemOfUnits import MeV, GeV from DerivationFrameworkEGamma.PhotonsCPDetailedContent import ( - PhotonsCPDetailedContent ) + PhotonsCPDetailedContent, +) from DerivationFrameworkEGamma.TriggerContent import ( - WTnPTriggers, ExtraContainersTrigger, - ExtraContainersElectronTrigger, ExtraContainersTriggerDataOnly ) - + WTnPTriggers, + ExtraContainersTrigger, + ExtraContainersElectronTrigger, + ExtraContainersTriggerDataOnly, +) def EGAM5SkimmingToolCfg(flags): - '''Configure the EGAM5 skimming tool''' + """Configure the EGAM5 skimming tool""" acc = ComponentAccumulator() - # 1st selection: trigger-based (WTP triggers) MenuType = None if flags.Trigger.EDMVersion == 2: - MenuType = 'Run2' + MenuType = "Run2" elif flags.Trigger.EDMVersion == 3: - MenuType = 'Run3' + MenuType = "Run3" else: - MenuType = '' + MenuType = "" triggers = WTnPTriggers[MenuType] - print('EGAM5 trigger skimming list (OR): ', triggers) - - EGAM5_TriggerSkimmingTool = \ - CompFactory.DerivationFramework.TriggerSkimmingTool( - name = 'EGAM5_TriggerSkimmingTool', - TriggerListOR = triggers) + print("EGAM5 trigger skimming list (OR): ", triggers) + EGAM5_TriggerSkimmingTool = CompFactory.DerivationFramework.TriggerSkimmingTool( + name="EGAM5_TriggerSkimmingTool", TriggerListOR=triggers + ) # 2nd selection: off-line, based on mT(enu) - expression2 = 'count(EGAM5_ENuTransverseMass > 40*GeV)>=1' - print('EGAM5 offline skimming expression: ', expression2) - EGAM5_OfflineSkimmingTool = \ - CompFactory.DerivationFramework.xAODStringSkimmingTool( - name = 'EGAM5_OfflineSkimmingTool', - expression = expression2) - + expression2 = "count(EGAM5_ENuTransverseMass > 40*GeV)>=1" + print("EGAM5 offline skimming expression: ", expression2) + EGAM5_OfflineSkimmingTool = CompFactory.DerivationFramework.xAODStringSkimmingTool( + name="EGAM5_OfflineSkimmingTool", expression=expression2 + ) # 3rd selection: mix of off-line and on-line criteria - expression3a = ' || '. join(['HLT_e60_lhloose_xe60noL1', - 'HLT_e120_lhloose', - 'HLT_j80_xe80', - 'HLT_xe70', - 'HLT_xe80_tc_lcw_L1XE50', - 'HLT_xe90_mht_L1XE50', - 'HLT_xe90_tc_lcw_wEFMu_L1XE50', - 'HLT_xe90_mht_wEFMu_L1XE50']) - expression3b = 'count(Electrons.pt > 14.5*GeV) >= 1' - expression3 = '( ' + expression3a + ' ) && ( ' + expression3b + ' )' - print('EGAM5 mixed offline-online skimming expression: ', expression3) - - EGAM5_OnlineOfflineSkimmingTool = \ + expression3a = " || ".join( + [ + "HLT_e60_lhloose_xe60noL1", + "HLT_e120_lhloose", + "HLT_j80_xe80", + "HLT_xe70", + "HLT_xe80_tc_lcw_L1XE50", + "HLT_xe90_mht_L1XE50", + "HLT_xe90_tc_lcw_wEFMu_L1XE50", + "HLT_xe90_mht_wEFMu_L1XE50", + ] + ) + expression3b = "count(Electrons.pt > 14.5*GeV) >= 1" + expression3 = "( " + expression3a + " ) && ( " + expression3b + " )" + print("EGAM5 mixed offline-online skimming expression: ", expression3) + + EGAM5_OnlineOfflineSkimmingTool = ( CompFactory.DerivationFramework.xAODStringSkimmingTool( - name = 'EGAM5_OnlineOfflineSkimmingTool', - expression = expression3) + name="EGAM5_OnlineOfflineSkimmingTool", expression=expression3 + ) + ) # do the OR of previous selections - print('EGAM5 skimming is logical OR of previous selections') + print("EGAM5 skimming is logical OR of previous selections") EGAM5_SkimmingTool = CompFactory.DerivationFramework.FilterCombinationOR( - name = 'EGAM5_SkimmingTool', - FilterList=[EGAM5_OfflineSkimmingTool, - EGAM5_TriggerSkimmingTool, - EGAM5_OnlineOfflineSkimmingTool]) + name="EGAM5_SkimmingTool", + FilterList=[ + EGAM5_OfflineSkimmingTool, + EGAM5_TriggerSkimmingTool, + EGAM5_OnlineOfflineSkimmingTool, + ], + ) acc.addPublicTool(EGAM5_OfflineSkimmingTool) acc.addPublicTool(EGAM5_TriggerSkimmingTool) acc.addPublicTool(EGAM5_OnlineOfflineSkimmingTool) - acc.addPublicTool(EGAM5_SkimmingTool, primary = True) + acc.addPublicTool(EGAM5_SkimmingTool, primary=True) return acc def EGAM5enuTransverseMassToolCfg(flags): - '''Configure the EGAM5 enu transverse mass augmentation tool''' + """Configure the EGAM5 enu transverse mass augmentation tool""" acc = ComponentAccumulator() # ==================================================================== @@ -96,93 +101,100 @@ def EGAM5enuTransverseMassToolCfg(flags): # # 1 tight electron with pT>25 GeV + MET > 25 GeV # ==================================================================== - electronPtRequirement = '(Electrons.pt > 24.5*GeV)' - electronQualityRequirement = '(Electrons.DFCommonElectronsLHTight)' - requirement_el = '(' + electronQualityRequirement + \ - '&&' + electronPtRequirement + ')' - - acc.setPrivateTools( CompFactory.DerivationFramework.EGTransverseMassTool( - name = 'EGAM5_enuTransverseMassTool', - ObjectRequirements = requirement_el, - METmin = 25*GeV, - StoreGateEntryName = 'EGAM5_ENuTransverseMass', - ObjectMassHypothesis = 0.511*MeV, - ObjectContainerName = 'Electrons', - METContainerName = 'MET_Core_AntiKt4EMPFlow' - ) ) + electronPtRequirement = "(Electrons.pt > 24.5*GeV)" + electronQualityRequirement = "(Electrons.DFCommonElectronsLHTight)" + requirement_el = ( + "(" + electronQualityRequirement + "&&" + electronPtRequirement + ")" + ) + + acc.setPrivateTools( + CompFactory.DerivationFramework.EGTransverseMassTool( + name="EGAM5_enuTransverseMassTool", + ObjectRequirements=requirement_el, + METmin=25 * GeV, + StoreGateEntryName="EGAM5_ENuTransverseMass", + ObjectMassHypothesis=0.511 * MeV, + ObjectContainerName="Electrons", + METContainerName="MET_Core_AntiKt4EMPFlow", + ) + ) return acc - -def EGAM5KernelCfg(ConfigFlags, name='EGAM5Kernel', **kwargs): - '''Configure the derivation framework driving algorithm (kernel) - for EGAM5''' +def EGAM5KernelCfg(ConfigFlags, name="EGAM5Kernel", **kwargs): + """Configure the derivation framework driving algorithm (kernel) + for EGAM5""" acc = ComponentAccumulator() - # Common augmentations - from DerivationFrameworkPhys.PhysCommonConfig import ( - PhysCommonAugmentationsCfg ) - acc.merge( PhysCommonAugmentationsCfg( - ConfigFlags, - TriggerListsHelper = kwargs['TriggerListsHelper'] ) ) - + from DerivationFrameworkPhys.PhysCommonConfig import PhysCommonAugmentationsCfg + + acc.merge( + PhysCommonAugmentationsCfg( + ConfigFlags, TriggerListsHelper=kwargs["TriggerListsHelper"] + ) + ) # EGAM5 augmentations augmentationTools = [] - - #==================================================================== + # ==================================================================== # enu transverse mass - #==================================================================== + # ==================================================================== EGAM5enuTransverseMassTool = acc.popToolsAndMerge( - EGAM5enuTransverseMassToolCfg(ConfigFlags) ) + EGAM5enuTransverseMassToolCfg(ConfigFlags) + ) acc.addPublicTool(EGAM5enuTransverseMassTool) augmentationTools.append(EGAM5enuTransverseMassTool) - #==================================================================== + # ==================================================================== # Max Cell energy and time - #==================================================================== + # ==================================================================== from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - MaxCellDecoratorCfg ) + MaxCellDecoratorCfg, + ) + MaxCellDecorator = acc.popToolsAndMerge(MaxCellDecoratorCfg(ConfigFlags)) acc.addPublicTool(MaxCellDecorator) augmentationTools.append(MaxCellDecorator) - + # ==================================================================== # Gain and cluster energies per layer decoration tool # ==================================================================== from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - GainDecoratorCfg, ClusterEnergyPerLayerDecoratorCfg ) + GainDecoratorCfg, + ClusterEnergyPerLayerDecoratorCfg, + ) + EGAM5_GainDecoratorTool = acc.popToolsAndMerge( - GainDecoratorCfg(ConfigFlags, name = 'EGAM5_GainDecoratorTool' )) + GainDecoratorCfg(ConfigFlags, name="EGAM5_GainDecoratorTool") + ) acc.addPublicTool(EGAM5_GainDecoratorTool) augmentationTools.append(EGAM5_GainDecoratorTool) - cluster_sizes = (3,7), (5,5), (7,11) + cluster_sizes = (3, 7), (5, 5), (7, 11) for neta, nphi in cluster_sizes: - cename = 'EGAM5_ClusterEnergyPerLayerDecorator_%sx%s' % (neta, nphi) + cename = "EGAM5_ClusterEnergyPerLayerDecorator_%sx%s" % (neta, nphi) EGAM5_ClusterEnergyPerLayerDecorator = acc.popToolsAndMerge( ClusterEnergyPerLayerDecoratorCfg( - ConfigFlags, - neta = neta, - nphi=nphi, - name=cename )) + ConfigFlags, neta=neta, nphi=nphi, name=cename + ) + ) acc.addPublicTool(EGAM5_ClusterEnergyPerLayerDecorator) augmentationTools.append(EGAM5_ClusterEnergyPerLayerDecorator) - # thinning tools thinningTools = [] - streamName = kwargs['StreamName'] + streamName = kwargs["StreamName"] # Track thinning if ConfigFlags.Derivation.Egamma.doTrackThinning: - from DerivationFrameworkInDet.InDetToolsConfig import ( - TrackParticleThinningCfg, MuonTrackParticleThinningCfg, - TauTrackParticleThinningCfg ) + TrackParticleThinningCfg, + MuonTrackParticleThinningCfg, + TauTrackParticleThinningCfg, + ) TrackThinningKeepElectronTracks = True TrackThinningKeepPhotonTracks = True @@ -193,123 +205,139 @@ def EGAM5KernelCfg(ConfigFlags, name='EGAM5Kernel', **kwargs): TrackThinningKeepPVTracks = True # Tracks associated with Electrons - if (TrackThinningKeepElectronTracks): - EGAM5ElectronTPThinningTool = \ + if TrackThinningKeepElectronTracks: + EGAM5ElectronTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM5ElectronTPThinningTool', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM5ElectronTPThinningTool", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM5ElectronTPThinningTool) thinningTools.append(EGAM5ElectronTPThinningTool) # Tracks associated with Electrons (all tracks, large cone, for track # isolation studies of the selected electrons) - if (TrackThinningKeepAllElectronTracks): - EGAM5ElectronTPThinningTool2 = \ + if TrackThinningKeepAllElectronTracks: + EGAM5ElectronTPThinningTool2 = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM5ElectronTPThinningTool2', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 4*GeV', - BestMatchOnly = False, - ConeSize = 0.6) + name="EGAM5ElectronTPThinningTool2", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 4*GeV", + BestMatchOnly=False, + ConeSize=0.6, + ) + ) acc.addPublicTool(EGAM5ElectronTPThinningTool2) thinningTools.append(EGAM5ElectronTPThinningTool2) # Tracks associated with Photons - if (TrackThinningKeepPhotonTracks): - EGAM5PhotonTPThinningTool = \ + if TrackThinningKeepPhotonTracks: + EGAM5PhotonTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM5PhotonTPThinningTool', - StreamName = streamName, - SGKey = 'Photons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - GSFConversionVerticesKey = 'GSFConversionVertices', - SelectionString = 'Photons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM5PhotonTPThinningTool", + StreamName=streamName, + SGKey="Photons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + GSFConversionVerticesKey="GSFConversionVertices", + SelectionString="Photons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM5PhotonTPThinningTool) thinningTools.append(EGAM5PhotonTPThinningTool) # Tracks associated with Jets - if (TrackThinningKeepJetTracks): - EGAM5JetTPThinningTool = \ + if TrackThinningKeepJetTracks: + EGAM5JetTPThinningTool = ( CompFactory.DerivationFramework.JetTrackParticleThinning( - name = 'EGAM5JetTPThinningTool', - StreamName = streamName, - JetKey = 'AntiKt4EMPFlowJets', - InDetTrackParticlesKey = 'InDetTrackParticles') + name="EGAM5JetTPThinningTool", + StreamName=streamName, + JetKey="AntiKt4EMPFlowJets", + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) acc.addPublicTool(EGAM5JetTPThinningTool) thinningTools.append(EGAM5JetTPThinningTool) # Tracks associated with Muons - if (TrackThinningKeepMuonTracks): - EGAM5MuonTPThinningTool = \ - acc.getPrimaryAndMerge(MuonTrackParticleThinningCfg( + if TrackThinningKeepMuonTracks: + EGAM5MuonTPThinningTool = acc.getPrimaryAndMerge( + MuonTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM5MuonTPThinningTool', - StreamName = streamName, - MuonKey = 'Muons', - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM5MuonTPThinningTool", + StreamName=streamName, + MuonKey="Muons", + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM5MuonTPThinningTool) # Tracks associated with Taus - if (TrackThinningKeepTauTracks): - EGAM5TauTPThinningTool = \ - acc.getPrimaryAndMerge(TauTrackParticleThinningCfg( + if TrackThinningKeepTauTracks: + EGAM5TauTPThinningTool = acc.getPrimaryAndMerge( + TauTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM5TauTPThinningTool', - StreamName = streamName, - TauKey = 'TauJets', - ConeSize = 0.6, - InDetTrackParticlesKey = 'InDetTrackParticles', - DoTauTracksThinning = True, - TauTracksKey = 'TauTracks') ) + name="EGAM5TauTPThinningTool", + StreamName=streamName, + TauKey="TauJets", + ConeSize=0.6, + InDetTrackParticlesKey="InDetTrackParticles", + DoTauTracksThinning=True, + TauTracksKey="TauTracks", + ) + ) thinningTools.append(EGAM5TauTPThinningTool) # Tracks from primary vertex - thinning_expression = ' && '.join([ - '(InDetTrackParticles.DFCommonTightPrimary)', - '(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta) < 3.0*mm)', - '(InDetTrackParticles.pt > 10*GeV)']) - if (TrackThinningKeepPVTracks): - EGAM5TPThinningTool = \ - acc.getPrimaryAndMerge(TrackParticleThinningCfg( + thinning_expression = " && ".join( + [ + "(InDetTrackParticles.DFCommonTightPrimary)", + "(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3*mm)", + "(InDetTrackParticles.pt>10*GeV)", + ] + ) + if TrackThinningKeepPVTracks: + EGAM5TPThinningTool = acc.getPrimaryAndMerge( + TrackParticleThinningCfg( ConfigFlags, - name = 'EGAM5TPThinningTool', - StreamName = streamName, - SelectionString = thinning_expression, - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM5TPThinningTool", + StreamName=streamName, + SelectionString=thinning_expression, + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM5TPThinningTool) - # skimming skimmingTool = acc.getPrimaryAndMerge(EGAM5SkimmingToolCfg(ConfigFlags)) - # setup the kernel - acc.addEventAlgo(CompFactory.DerivationFramework.DerivationKernel(name, - SkimmingTools = [skimmingTool], - AugmentationTools = augmentationTools, - ThinningTools = thinningTools) ) + acc.addEventAlgo( + CompFactory.DerivationFramework.DerivationKernel( + name, + SkimmingTools=[skimmingTool], + AugmentationTools=augmentationTools, + ThinningTools=thinningTools, + ) + ) return acc - def EGAM5Cfg(ConfigFlags): - acc = ComponentAccumulator() - # Get the lists of triggers needed for trigger matching. # This is needed at this scope (for the slimming) and further down # in the config chain for actually configuring the matching, so we create @@ -318,136 +346,146 @@ def EGAM5Cfg(ConfigFlags): # multiple times in a train. # DODO: restrict it to relevant triggers from DerivationFrameworkPhys.TriggerListsHelper import TriggerListsHelper + EGAM5TriggerListsHelper = TriggerListsHelper(ConfigFlags) - #EGAM5TriggerListsHelper.Run3TriggerNames = EGAM5TriggerListsHelper.Run3TriggerNamesNoTau - #EGAM5TriggerListsHelper.Run3TriggerNamesTau = [] - #EGAM5TriggerListsHelper.Run2TriggerNamesTau = [] # configure skimming/thinning/augmentation tools - acc.merge(EGAM5KernelCfg(ConfigFlags, - name = 'EGAM5Kernel', - StreamName = 'StreamDAOD_EGAM5', - TriggerListsHelper = EGAM5TriggerListsHelper)) - + acc.merge( + EGAM5KernelCfg( + ConfigFlags, + name="EGAM5Kernel", + StreamName="StreamDAOD_EGAM5", + TriggerListsHelper=EGAM5TriggerListsHelper, + ) + ) # configure slimming from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper - EGAM5SlimmingHelper = SlimmingHelper( - 'EGAM5SlimmingHelper', - NamesAndTypes = ConfigFlags.Input.TypedCollections, - ConfigFlags = ConfigFlags ) + EGAM5SlimmingHelper = SlimmingHelper( + "EGAM5SlimmingHelper", + NamesAndTypes=ConfigFlags.Input.TypedCollections, + ConfigFlags=ConfigFlags, + ) # ------------------------------------------ # containers for which we save all variables # ------------------------------------------- # baseline - EGAM5SlimmingHelper.AllVariables =[ - 'Electrons', - 'GSFTrackParticles', - 'egammaClusters' ] + EGAM5SlimmingHelper.AllVariables = [ + "Electrons", + "GSFTrackParticles", + "egammaClusters", + ] # for trigger studies we also add: MenuType = None if ConfigFlags.Trigger.EDMVersion == 2: - MenuType = 'Run2' + MenuType = "Run2" elif ConfigFlags.Trigger.EDMVersion == 3: - MenuType = 'Run3' + MenuType = "Run3" else: - MenuType = '' + MenuType = "" EGAM5SlimmingHelper.AllVariables += ExtraContainersTrigger[MenuType] EGAM5SlimmingHelper.AllVariables += ExtraContainersElectronTrigger[MenuType] if not ConfigFlags.Input.isMC: EGAM5SlimmingHelper.AllVariables += ExtraContainersTriggerDataOnly[MenuType] - + # and on MC we also add: if ConfigFlags.Input.isMC: EGAM5SlimmingHelper.AllVariables += [ - 'TruthEvents', - 'TruthParticles', - 'TruthVertices', - 'egammaTruthParticles' + "TruthEvents", + "TruthParticles", + "TruthVertices", + "egammaTruthParticles", ] - - # ------------------------------------------- # containers that we slim # ------------------------------------------- # first add variables from smart-slimming # adding only also those for which we add all variables since - # the XXXCPContent.py files also bring in some extra variables + # the XXXCPContent.py files also bring in some extra variables # for other collections - EGAM5SlimmingHelper.SmartCollections = ['Electrons', - 'Photons', - 'Muons', - 'TauJets', - 'InDetTrackParticles', - 'PrimaryVertices', - 'AntiKt4EMPFlowJets', - 'MET_Baseline_AntiKt4EMPFlow', - 'BTagging_AntiKt4EMPFlow' - ] - # muons, tau, MET, b-tagging could be switched off if not needed + EGAM5SlimmingHelper.SmartCollections = [ + "Electrons", + "Photons", + "Muons", + "TauJets", + "InDetTrackParticles", + "PrimaryVertices", + "AntiKt4EMPFlowJets", + "MET_Baseline_AntiKt4EMPFlow", + "BTagging_AntiKt4EMPFlow", + ] + # muons, tau, MET, b-tagging could be switched off if not needed # and use too much space if ConfigFlags.Input.isMC: - EGAM5SlimmingHelper.SmartCollections += ['AntiKt4TruthJets', - 'AntiKt4TruthDressedWZJets'] + EGAM5SlimmingHelper.SmartCollections += [ + "AntiKt4TruthJets", + "AntiKt4TruthDressedWZJets", + ] # then add extra variables: # muons EGAM5SlimmingHelper.ExtraVariables += [ - 'Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40' ] + "Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40" + ] # conversion vertices EGAM5SlimmingHelper.ExtraVariables += [ - 'GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo', - 'GSFConversionVertices.trackParticleLinks' ] + "GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo", + "GSFConversionVertices.trackParticleLinks", + ] # primary vertices - EGAM5SlimmingHelper.ExtraVariables += [ - 'PrimaryVertices.x.y.sumPt2' ] + EGAM5SlimmingHelper.ExtraVariables += ["PrimaryVertices.x.y.sumPt2"] # photons: detailed shower shape variables EGAM5SlimmingHelper.ExtraVariables += PhotonsCPDetailedContent # photons and electrons: gain and cluster energy per layer from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - getGainDecorations, getClusterEnergyPerLayerDecorations ) - gainDecorations = getGainDecorations(acc, 'EGAM5Kernel') - print('EGAM5 gain decorations: ', gainDecorations) + getGainDecorations, + getClusterEnergyPerLayerDecorations, + ) + + gainDecorations = getGainDecorations(acc, "EGAM5Kernel") + print("EGAM5 gain decorations: ", gainDecorations) EGAM5SlimmingHelper.ExtraVariables.extend(gainDecorations) - clusterEnergyDecorations = getClusterEnergyPerLayerDecorations( - acc, 'EGAM5Kernel' ) - print('EGAM5 cluster energy decorations: ', clusterEnergyDecorations) + clusterEnergyDecorations = getClusterEnergyPerLayerDecorations(acc, "EGAM5Kernel") + print("EGAM5 cluster energy decorations: ", clusterEnergyDecorations) EGAM5SlimmingHelper.ExtraVariables.extend(clusterEnergyDecorations) # energy density - EGAM5SlimmingHelper.ExtraVariables += [ - 'TopoClusterIsoCentralEventShape.Density', - 'TopoClusterIsoForwardEventShape.Density', - 'NeutralParticleFlowIsoCentralEventShape.Density', - 'NeutralParticleFlowIsoForwardEventShape.Density'] + EGAM5SlimmingHelper.ExtraVariables += [ + "TopoClusterIsoCentralEventShape.Density", + "TopoClusterIsoForwardEventShape.Density", + "NeutralParticleFlowIsoCentralEventShape.Density", + "NeutralParticleFlowIsoForwardEventShape.Density", + ] # truth if ConfigFlags.Input.isMC: EGAM5SlimmingHelper.ExtraVariables += [ - 'MuonTruthParticles.e.px.py.pz.status.pdgId.truthOrigin.truthType' ] + "MuonTruthParticles.e.px.py.pz.status.pdgId.truthOrigin.truthType" + ] EGAM5SlimmingHelper.ExtraVariables += [ - 'Photons.truthOrigin.truthType.truthParticleLink' ] + "Photons.truthOrigin.truthType.truthParticleLink" + ] # Add event info if ConfigFlags.Derivation.Egamma.doEventInfoSlimming: - EGAM5SlimmingHelper.SmartCollections.append('EventInfo') + EGAM5SlimmingHelper.SmartCollections.append("EventInfo") else: - EGAM5SlimmingHelper.AllVariables += ['EventInfo'] - + EGAM5SlimmingHelper.AllVariables += ["EventInfo"] + # Add egamma trigger objects EGAM5SlimmingHelper.IncludeEGammaTriggerContent = True @@ -455,29 +493,41 @@ def EGAM5Cfg(ConfigFlags): # Run 2 if ConfigFlags.Trigger.EDMVersion == 2: from DerivationFrameworkPhys.TriggerMatchingCommonConfig import ( - AddRun2TriggerMatchingToSlimmingHelper ) + AddRun2TriggerMatchingToSlimmingHelper, + ) + AddRun2TriggerMatchingToSlimmingHelper( - SlimmingHelper = EGAM5SlimmingHelper, - OutputContainerPrefix = 'TrigMatch_', - TriggerList = EGAM5TriggerListsHelper.Run2TriggerNamesNoTau) + SlimmingHelper=EGAM5SlimmingHelper, + OutputContainerPrefix="TrigMatch_", + TriggerList=EGAM5TriggerListsHelper.Run2TriggerNamesNoTau, + ) # Run 3 if ConfigFlags.Trigger.EDMVersion == 3: from TrigNavSlimmingMT.TrigNavSlimmingMTConfig import ( - AddRun3TrigNavSlimmingCollectionsToSlimmingHelper ) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper, + ) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper(EGAM5SlimmingHelper) - EGAM5ItemList = EGAM5SlimmingHelper.GetItemList() - acc.merge(OutputStreamCfg(ConfigFlags, - 'DAOD_EGAM5', - ItemList = EGAM5ItemList, - AcceptAlgs = ['EGAM5Kernel'])) - acc.merge(SetupMetaDataForStreamCfg(ConfigFlags, 'DAOD_EGAM5', - AcceptAlgs=['EGAM5Kernel'], - createMetadata=[ - MetadataCategory.CutFlowMetaData, - MetadataCategory.TruthMetaData, - ])) + acc.merge( + OutputStreamCfg( + ConfigFlags, + "DAOD_EGAM5", + ItemList=EGAM5ItemList, + AcceptAlgs=["EGAM5Kernel"], + ) + ) + acc.merge( + SetupMetaDataForStreamCfg( + ConfigFlags, + "DAOD_EGAM5", + AcceptAlgs=["EGAM5Kernel"], + createMetadata=[ + MetadataCategory.CutFlowMetaData, + MetadataCategory.TruthMetaData, + ], + ) + ) return acc - diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM7.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM7.py index 569489e51a69..06e589e4b42d 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM7.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM7.py @@ -1,145 +1,150 @@ # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration -#!/usr/bin/env python -#==================================================================== +# ==================================================================== # EGAM7.py # This defines DAOD_EGAM7, a skimmed DAOD format for Run 3. # Keep events passing OR of electron triggers, or inclusive # electron selection, to retain fake electron candidates # Cell collection is saved but thinned (keep only cells associated with # egammaClusters) -# It requires the flag EGAM7 in Derivation_tf.py -#==================================================================== +# It requires the flag EGAM7 in Derivation_tf.py +# ==================================================================== from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory from AthenaConfiguration.Enums import MetadataCategory from DerivationFrameworkEGamma.PhotonsCPDetailedContent import ( - PhotonsCPDetailedContent ) + PhotonsCPDetailedContent, +) from DerivationFrameworkEGamma.TriggerContent import ( - BkgElectronTriggers, ExtraContainersTrigger, - ExtraContainersElectronTrigger, ExtraContainersTriggerDataOnly ) + BkgElectronTriggers, + ExtraContainersTrigger, + ExtraContainersElectronTrigger, + ExtraContainersTriggerDataOnly, +) thinCells = True + def EGAM7SkimmingToolCfg(flags): - '''Configure the EGAM7 skimming tool''' + """Configure the EGAM7 skimming tool""" acc = ComponentAccumulator() # off-line based selection - expression = 'count(Electrons.pt > 4.5*GeV) >= 1' - print('EGAM7 offline skimming expression: ', expression) - EGAM7_OfflineSkimmingTool = \ - CompFactory.DerivationFramework.xAODStringSkimmingTool( - name = 'EGAM7_OfflineSkimmingTool', - expression = expression) + expression = "count(Electrons.pt > 4.5*GeV) >= 1" + print("EGAM7 offline skimming expression: ", expression) + EGAM7_OfflineSkimmingTool = CompFactory.DerivationFramework.xAODStringSkimmingTool( + name="EGAM7_OfflineSkimmingTool", expression=expression + ) # trigger-based selection MenuType = None if flags.Trigger.EDMVersion == 2: - MenuType = 'Run2' + MenuType = "Run2" elif flags.Trigger.EDMVersion == 3: - MenuType = 'Run3' + MenuType = "Run3" else: - MenuType = '' + MenuType = "" triggers = BkgElectronTriggers[MenuType] - print('EGAM7 trigger skimming list (OR): ', triggers) - - EGAM7_TriggerSkimmingTool = \ - CompFactory.DerivationFramework.TriggerSkimmingTool( - name = 'EGAM7_TriggerSkimmingTool', - TriggerListOR = triggers) + print("EGAM7 trigger skimming list (OR): ", triggers) + + EGAM7_TriggerSkimmingTool = CompFactory.DerivationFramework.TriggerSkimmingTool( + name="EGAM7_TriggerSkimmingTool", TriggerListOR=triggers + ) # do the AND of trigger-based and offline-based selection - print('EGAM7 skimming is logical AND of previous selections') + print("EGAM7 skimming is logical AND of previous selections") EGAM7_SkimmingTool = CompFactory.DerivationFramework.FilterCombinationAND( - name = 'EGAM7_SkimmingTool', - FilterList=[EGAM7_OfflineSkimmingTool, EGAM7_TriggerSkimmingTool]) + name="EGAM7_SkimmingTool", + FilterList=[EGAM7_OfflineSkimmingTool, EGAM7_TriggerSkimmingTool], + ) acc.addPublicTool(EGAM7_OfflineSkimmingTool) - acc.addPublicTool(EGAM7_TriggerSkimmingTool) - acc.addPublicTool(EGAM7_SkimmingTool, primary = True) - + acc.addPublicTool(EGAM7_TriggerSkimmingTool) + acc.addPublicTool(EGAM7_SkimmingTool, primary=True) + return acc -def EGAM7KernelCfg(ConfigFlags, name='EGAM7Kernel', **kwargs): - '''Configure the derivation framework driving algorithm (kernel) - for EGAM7''' +def EGAM7KernelCfg(ConfigFlags, name="EGAM7Kernel", **kwargs): + """Configure the derivation framework driving algorithm (kernel) + for EGAM7""" acc = ComponentAccumulator() - # Schedule extra jets collections from JetRecConfig.StandardSmallRJets import AntiKt4PV0Track from JetRecConfig.JetRecConfig import JetRecCfg from JetRecConfig.JetConfigFlags import jetInternalFlags + jetList = [AntiKt4PV0Track] jetInternalFlags.isRecoJob = True - for jd in jetList: acc.merge(JetRecCfg(ConfigFlags,jd)) + for jd in jetList: + acc.merge(JetRecCfg(ConfigFlags, jd)) # Common augmentations - from DerivationFrameworkPhys.PhysCommonConfig import ( - PhysCommonAugmentationsCfg ) - acc.merge( PhysCommonAugmentationsCfg( - ConfigFlags, - TriggerListsHelper = kwargs['TriggerListsHelper'] ) ) - + from DerivationFrameworkPhys.PhysCommonConfig import PhysCommonAugmentationsCfg + + acc.merge( + PhysCommonAugmentationsCfg( + ConfigFlags, TriggerListsHelper=kwargs["TriggerListsHelper"] + ) + ) # EGAM7 augmentations augmentationTools = [] - #==================================================================== + # ==================================================================== # Max Cell energy and time - #==================================================================== + # ==================================================================== from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - MaxCellDecoratorCfg ) + MaxCellDecoratorCfg, + ) + MaxCellDecorator = acc.popToolsAndMerge(MaxCellDecoratorCfg(ConfigFlags)) acc.addPublicTool(MaxCellDecorator) - augmentationTools.append(MaxCellDecorator) - + augmentationTools.append(MaxCellDecorator) + # ==================================================================== # Gain and cluster energies per layer decoration tool # ==================================================================== from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - GainDecoratorCfg, ClusterEnergyPerLayerDecoratorCfg ) + GainDecoratorCfg, + ClusterEnergyPerLayerDecoratorCfg, + ) + EGAM7_GainDecoratorTool = acc.popToolsAndMerge( - GainDecoratorCfg(ConfigFlags, name = 'EGAM7_GainDecoratorTool' )) + GainDecoratorCfg(ConfigFlags, name="EGAM7_GainDecoratorTool") + ) acc.addPublicTool(EGAM7_GainDecoratorTool) augmentationTools.append(EGAM7_GainDecoratorTool) - # might need some modification when cell-level reweighting is implemented (see share/EGAM7.py) - cluster_sizes = (3,7), (5,5), (7,11) + # might need some modification if cell-level reweighting is implemented + # (see share/EGAM7.py) + cluster_sizes = (3, 7), (5, 5), (7, 11) for neta, nphi in cluster_sizes: - cename = 'EGAM7_ClusterEnergyPerLayerDecorator_%sx%s' % (neta, nphi) + cename = "EGAM7_ClusterEnergyPerLayerDecorator_%sx%s" % (neta, nphi) EGAM7_ClusterEnergyPerLayerDecorator = acc.popToolsAndMerge( ClusterEnergyPerLayerDecoratorCfg( - ConfigFlags, - neta = neta, - nphi=nphi, - name=cename )) + ConfigFlags, neta=neta, nphi=nphi, name=cename + ) + ) acc.addPublicTool(EGAM7_ClusterEnergyPerLayerDecorator) augmentationTools.append(EGAM7_ClusterEnergyPerLayerDecorator) - # thinning tools thinningTools = [] - print('WARNING, Thinning of trigger navigation has to be properly implemented in R22') - #from DerivationFrameworkCore.ThinningHelper import ThinningHelper - #EGAM7ThinningHelper = ThinningHelper( 'EGAM7ThinningHelper' ) - #EGAM7ThinningHelper.TriggerChains = '(^(?!.*_[0-9]*(mu|j|xe|tau|ht|xs|te))(?!HLT_[eg].*_[0-9]*[eg][0-9].*)(?!HLT_eb.*)(?!.*larpeb.*)(?!HLT_.*_AFP_.*)(HLT_[eg].*))|HLT_e.*_Jpsiee.*' - #EGAM7ThinningHelper.AppendToStream( EGAM7Stream, ExtraContainersTrigger ) - - streamName = kwargs['StreamName'] + streamName = kwargs["StreamName"] # Track thinning if ConfigFlags.Derivation.Egamma.doTrackThinning: - from DerivationFrameworkInDet.InDetToolsConfig import ( - TrackParticleThinningCfg, MuonTrackParticleThinningCfg, - TauTrackParticleThinningCfg ) + TrackParticleThinningCfg, + MuonTrackParticleThinningCfg, + TauTrackParticleThinningCfg, + ) TrackThinningKeepElectronTracks = True TrackThinningKeepPhotonTracks = True @@ -150,165 +155,203 @@ def EGAM7KernelCfg(ConfigFlags, name='EGAM7Kernel', **kwargs): TrackThinningKeepPVTracks = False # Tracks associated with Electrons - if (TrackThinningKeepElectronTracks): - EGAM7ElectronTPThinningTool = \ + if TrackThinningKeepElectronTracks: + EGAM7ElectronTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM7ElectronTPThinningTool', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM7ElectronTPThinningTool", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM7ElectronTPThinningTool) thinningTools.append(EGAM7ElectronTPThinningTool) # Tracks associated with Electrons (all tracks, large cone, for track # isolation studies of the selected electrons) - if (TrackThinningKeepAllElectronTracks): - EGAM7ElectronTPThinningTool2 = CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM7ElectronTPThinningTool2', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 4*GeV', - BestMatchOnly = False, - ConeSize = 0.6) + if TrackThinningKeepAllElectronTracks: + EGAM7ElectronTPThinningTool2 = ( + CompFactory.DerivationFramework.EgammaTrackParticleThinning( + name="EGAM7ElectronTPThinningTool2", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 4*GeV", + BestMatchOnly=False, + ConeSize=0.6, + ) + ) acc.addPublicTool(EGAM7ElectronTPThinningTool2) thinningTools.append(EGAM7ElectronTPThinningTool2) # Tracks associated with Photons - if (TrackThinningKeepPhotonTracks): - EGAM7PhotonTPThinningTool = \ + if TrackThinningKeepPhotonTracks: + EGAM7PhotonTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM7PhotonTPThinningTool', - StreamName = streamName, - SGKey = 'Photons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - GSFConversionVerticesKey = 'GSFConversionVertices', - SelectionString = 'Photons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM7PhotonTPThinningTool", + StreamName=streamName, + SGKey="Photons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + GSFConversionVerticesKey="GSFConversionVertices", + SelectionString="Photons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM7PhotonTPThinningTool) thinningTools.append(EGAM7PhotonTPThinningTool) # Tracks associated with Jets - if (TrackThinningKeepJetTracks): - EGAM7JetTPThinningTool = \ + if TrackThinningKeepJetTracks: + EGAM7JetTPThinningTool = ( CompFactory.DerivationFramework.JetTrackParticleThinning( - name = 'EGAM7JetTPThinningTool', - StreamName = streamName, - JetKey = 'AntiKt4EMPFlowJets', - InDetTrackParticlesKey = 'InDetTrackParticles') + name="EGAM7JetTPThinningTool", + StreamName=streamName, + JetKey="AntiKt4EMPFlowJets", + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) acc.addPublicTool(EGAM7JetTPThinningTool) thinningTools.append(EGAM7JetTPThinningTool) # Tracks associated with Muons - if (TrackThinningKeepMuonTracks): + if TrackThinningKeepMuonTracks: EGAM7MuonTPThinningTool = acc.getPrimaryAndMerge( MuonTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM7MuonTPThinningTool', - StreamName = streamName, - MuonKey = 'Muons', - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM7MuonTPThinningTool", + StreamName=streamName, + MuonKey="Muons", + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM7MuonTPThinningTool) # Tracks associated with Taus - if (TrackThinningKeepTauTracks): - EGAM7TauTPThinningTool = \ - acc.getPrimaryAndMerge(TauTrackParticleThinningCfg( + if TrackThinningKeepTauTracks: + EGAM7TauTPThinningTool = acc.getPrimaryAndMerge( + TauTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM7TauTPThinningTool', - StreamName = streamName, - TauKey = 'TauJets', - ConeSize = 0.6, - InDetTrackParticlesKey = 'InDetTrackParticles', - DoTauTracksThinning = True, - TauTracksKey = 'TauTracks') ) + name="EGAM7TauTPThinningTool", + StreamName=streamName, + TauKey="TauJets", + ConeSize=0.6, + InDetTrackParticlesKey="InDetTrackParticles", + DoTauTracksThinning=True, + TauTracksKey="TauTracks", + ) + ) thinningTools.append(EGAM7TauTPThinningTool) # Tracks from primary vertex - thinning_expression = ' && '.join([ - '(InDetTrackParticles.DFCommonTightPrimary)', - '(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta) < 3.0*mm)', - '(InDetTrackParticles.pt > 10*GeV)']) - if (TrackThinningKeepPVTracks): + thinning_expression = " && ".join( + [ + "(InDetTrackParticles.DFCommonTightPrimary)", + "(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3*mm)", + "(InDetTrackParticles.pt>10*GeV)", + ] + ) + if TrackThinningKeepPVTracks: EGAM7TPThinningTool = acc.getPrimaryAndMerge( TrackParticleThinningCfg( ConfigFlags, - name = 'EGAM7TPThinningTool', - StreamName = streamName, - SelectionString = thinning_expression, - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM7TPThinningTool", + StreamName=streamName, + SelectionString=thinning_expression, + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM7TPThinningTool) # truth thinning if ConfigFlags.Input.isMC: # W, Z and Higgs - truth_cond_WZH = ' && '.join(['(abs(TruthParticles.pdgId) >= 23)', - '(abs(TruthParticles.pdgId) <= 25)']) + truth_cond_WZH = " && ".join( + ["(abs(TruthParticles.pdgId) >= 23)", "(abs(TruthParticles.pdgId) <= 25)"] + ) # Leptons - truth_cond_lep = ' && '.join(['(abs(TruthParticles.pdgId) >= 11)', - '(abs(TruthParticles.pdgId) <= 16)']) + truth_cond_lep = " && ".join( + ["(abs(TruthParticles.pdgId) >= 11)", "(abs(TruthParticles.pdgId) <= 16)"] + ) # Top quark - truth_cond_top = '(abs(TruthParticles.pdgId) == 6)' + truth_cond_top = "(abs(TruthParticles.pdgId) == 6)" # Photon - truth_cond_gam = ' && '.join(['(abs(TruthParticles.pdgId) == 22)', - '(TruthParticles.pt > 1*GeV)']) + truth_cond_gam = " && ".join( + ["(abs(TruthParticles.pdgId) == 22)", "(TruthParticles.pt > 1*GeV)"] + ) # stable particles - truth_cond_finalState = ' && '.join(['(TruthParticles.status == 1)', - '(TruthParticles.barcode<200000)']) - truth_expression = '( ' + truth_cond_WZH + ' ) || ' + \ - '( ' + truth_cond_lep + ' ) || ' + \ - '( ' + truth_cond_top + ' ) || ' + \ - '( ' + truth_cond_gam + ' ) || ' + \ - '( ' + truth_cond_finalState + ' )' - print('EGAM7 truth thinning expression: ', truth_expression) - - EGAM7TruthThinningTool = \ - CompFactory.DerivationFramework.GenericTruthThinning( - name = 'EGAM7TruthThinningTool', - StreamName = streamName, - ParticleSelectionString = truth_expression, - PreserveDescendants = False, - PreserveGeneratorDescendants = True, - PreserveAncestors = True) + truth_cond_finalState = " && ".join( + ["(TruthParticles.status == 1)", "(TruthParticles.barcode<200000)"] + ) + truth_expression = ( + "( " + + truth_cond_WZH + + " ) || " + + "( " + + truth_cond_lep + + " ) || " + + "( " + + truth_cond_top + + " ) || " + + "( " + + truth_cond_gam + + " ) || " + + "( " + + truth_cond_finalState + + " )" + ) + print("EGAM7 truth thinning expression: ", truth_expression) + + EGAM7TruthThinningTool = CompFactory.DerivationFramework.GenericTruthThinning( + name="EGAM7TruthThinningTool", + StreamName=streamName, + ParticleSelectionString=truth_expression, + PreserveDescendants=False, + PreserveGeneratorDescendants=True, + PreserveAncestors=True, + ) acc.addPublicTool(EGAM7TruthThinningTool) thinningTools.append(EGAM7TruthThinningTool) # Keep only calo cells associated with the egammaClusters collection if thinCells: - from DerivationFrameworkCalo.CaloCellDFGetterConfig import ( - thinCaloCellsForDFCfg ) - acc.merge(thinCaloCellsForDFCfg (ConfigFlags, - inputClusterKeys=['egammaClusters'], - streamName = 'StreamDAOD_EGAM7', - inputCellKey = 'AllCalo', - outputCellKey = 'DFEGAMCellContainer')) + from DerivationFrameworkCalo.CaloCellDFGetterConfig import thinCaloCellsForDFCfg + + acc.merge( + thinCaloCellsForDFCfg( + ConfigFlags, + inputClusterKeys=["egammaClusters"], + streamName="StreamDAOD_EGAM7", + inputCellKey="AllCalo", + outputCellKey="DFEGAMCellContainer", + ) + ) # skimming skimmingTool = acc.getPrimaryAndMerge(EGAM7SkimmingToolCfg(ConfigFlags)) - # setup the kernel - acc.addEventAlgo(CompFactory.DerivationFramework.DerivationKernel(name, - SkimmingTools = [skimmingTool], - AugmentationTools = augmentationTools, - ThinningTools = thinningTools) ) + acc.addEventAlgo( + CompFactory.DerivationFramework.DerivationKernel( + name, + SkimmingTools=[skimmingTool], + AugmentationTools=augmentationTools, + ThinningTools=thinningTools, + ) + ) return acc - def EGAM7Cfg(ConfigFlags): - acc = ComponentAccumulator() - # Get the lists of triggers needed for trigger matching. # This is needed at this scope (for the slimming) and further down # in the config chain for actually configuring the matching, so we create @@ -317,137 +360,151 @@ def EGAM7Cfg(ConfigFlags): # multiple times in a train. # DODO: restrict it to relevant triggers from DerivationFrameworkPhys.TriggerListsHelper import TriggerListsHelper + EGAM7TriggerListsHelper = TriggerListsHelper(ConfigFlags) # configure skimming/thinning/augmentation tools - acc.merge(EGAM7KernelCfg(ConfigFlags, - name = 'EGAM7Kernel', - StreamName = 'StreamDAOD_EGAM7', - TriggerListsHelper = EGAM7TriggerListsHelper)) - + acc.merge( + EGAM7KernelCfg( + ConfigFlags, + name="EGAM7Kernel", + StreamName="StreamDAOD_EGAM7", + TriggerListsHelper=EGAM7TriggerListsHelper, + ) + ) # configure slimming from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper - EGAM7SlimmingHelper = SlimmingHelper( - 'EGAM7SlimmingHelper', - NamesAndTypes = ConfigFlags.Input.TypedCollections, - ConfigFlags = ConfigFlags ) + EGAM7SlimmingHelper = SlimmingHelper( + "EGAM7SlimmingHelper", + NamesAndTypes=ConfigFlags.Input.TypedCollections, + ConfigFlags=ConfigFlags, + ) # ------------------------------------------ # containers for which we save all variables # ------------------------------------------- # baseline - EGAM7SlimmingHelper.AllVariables =[ - 'Electrons', - 'GSFTrackParticles', - 'egammaClusters' ] + EGAM7SlimmingHelper.AllVariables = [ + "Electrons", + "GSFTrackParticles", + "egammaClusters", + ] # for trigger studies we also add: MenuType = None if ConfigFlags.Trigger.EDMVersion == 2: - MenuType = 'Run2' + MenuType = "Run2" elif ConfigFlags.Trigger.EDMVersion == 3: - MenuType = 'Run3' + MenuType = "Run3" else: - MenuType = '' + MenuType = "" EGAM7SlimmingHelper.AllVariables += ExtraContainersTrigger[MenuType] EGAM7SlimmingHelper.AllVariables += ExtraContainersElectronTrigger[MenuType] if not ConfigFlags.Input.isMC: EGAM7SlimmingHelper.AllVariables += ExtraContainersTriggerDataOnly[MenuType] - + # and on MC we also add: if ConfigFlags.Input.isMC: EGAM7SlimmingHelper.AllVariables += [ - 'TruthEvents', - 'TruthParticles', - 'TruthVertices', - 'egammaTruthParticles' + "TruthEvents", + "TruthParticles", + "TruthVertices", + "egammaTruthParticles", ] - - # ------------------------------------------- # containers that we slim # ------------------------------------------- # first add variables from smart-slimming # adding only also those for which we add all variables since - # the XXXCPContent.py files also bring in some extra variables + # the XXXCPContent.py files also bring in some extra variables # for other collections # muons, tau, MET, b-tagging could be switched off if not needed # and use too much space - EGAM7SlimmingHelper.SmartCollections = ['Electrons', - 'Photons', - 'Muons', - 'TauJets', - 'InDetTrackParticles', - 'PrimaryVertices', - 'AntiKt4EMPFlowJets', - 'MET_Baseline_AntiKt4EMPFlow', - 'BTagging_AntiKt4EMPFlow' - ] + EGAM7SlimmingHelper.SmartCollections = [ + "Electrons", + "Photons", + "Muons", + "TauJets", + "InDetTrackParticles", + "PrimaryVertices", + "AntiKt4EMPFlowJets", + "MET_Baseline_AntiKt4EMPFlow", + "BTagging_AntiKt4EMPFlow", + ] if ConfigFlags.Input.isMC: - EGAM7SlimmingHelper.SmartCollections += ['AntiKt4TruthJets', - 'AntiKt4TruthDressedWZJets'] + EGAM7SlimmingHelper.SmartCollections += [ + "AntiKt4TruthJets", + "AntiKt4TruthDressedWZJets", + ] # then add extra variables: # muons EGAM7SlimmingHelper.ExtraVariables += [ - 'Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40' ] + "Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40" + ] # conversion vertices EGAM7SlimmingHelper.ExtraVariables += [ - 'GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo', - 'GSFConversionVertices.trackParticleLinks' ] + "GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo", + "GSFConversionVertices.trackParticleLinks", + ] # primary vertices - EGAM7SlimmingHelper.ExtraVariables += [ - 'PrimaryVertices.x.y.sumPt2' ] + EGAM7SlimmingHelper.ExtraVariables += ["PrimaryVertices.x.y.sumPt2"] # track jets EGAM7SlimmingHelper.ExtraVariables += [ - 'AntiKt4PV0TrackJets.pt.eta.phi.e.m.btaggingLink.constituentLinks' ] + "AntiKt4PV0TrackJets.pt.eta.phi.e.m.btaggingLink.constituentLinks" + ] # photons: detailed shower shape variables EGAM7SlimmingHelper.ExtraVariables += PhotonsCPDetailedContent # photons: gain and cluster energy per layer from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - getGainDecorations, getClusterEnergyPerLayerDecorations ) - gainDecorations = getGainDecorations(acc, 'EGAM7Kernel') - print('EGAM7 gain decorations: ', gainDecorations) + getGainDecorations, + getClusterEnergyPerLayerDecorations, + ) + + gainDecorations = getGainDecorations(acc, "EGAM7Kernel") + print("EGAM7 gain decorations: ", gainDecorations) EGAM7SlimmingHelper.ExtraVariables.extend(gainDecorations) - clusterEnergyDecorations = getClusterEnergyPerLayerDecorations( - acc, 'EGAM7Kernel' ) - print('EGAM7 cluster energy decorations: ', clusterEnergyDecorations) + clusterEnergyDecorations = getClusterEnergyPerLayerDecorations(acc, "EGAM7Kernel") + print("EGAM7 cluster energy decorations: ", clusterEnergyDecorations) EGAM7SlimmingHelper.ExtraVariables.extend(clusterEnergyDecorations) # energy density - EGAM7SlimmingHelper.ExtraVariables += [ - 'TopoClusterIsoCentralEventShape.Density', - 'TopoClusterIsoForwardEventShape.Density', - 'NeutralParticleFlowIsoCentralEventShape.Density', - 'NeutralParticleFlowIsoForwardEventShape.Density'] + EGAM7SlimmingHelper.ExtraVariables += [ + "TopoClusterIsoCentralEventShape.Density", + "TopoClusterIsoForwardEventShape.Density", + "NeutralParticleFlowIsoCentralEventShape.Density", + "NeutralParticleFlowIsoForwardEventShape.Density", + ] # truth if ConfigFlags.Input.isMC: EGAM7SlimmingHelper.ExtraVariables += [ - 'MuonTruthParticles.e.px.py.pz.status.pdgId.truthOrigin.truthType' ] + "MuonTruthParticles.e.px.py.pz.status.pdgId.truthOrigin.truthType" + ] EGAM7SlimmingHelper.ExtraVariables += [ - 'Photons.truthOrigin.truthType.truthParticleLink' ] + "Photons.truthOrigin.truthType.truthParticleLink" + ] # Add event info if ConfigFlags.Derivation.Egamma.doEventInfoSlimming: - EGAM7SlimmingHelper.SmartCollections.append('EventInfo') + EGAM7SlimmingHelper.SmartCollections.append("EventInfo") else: - EGAM7SlimmingHelper.AllVariables += ['EventInfo'] - + EGAM7SlimmingHelper.AllVariables += ["EventInfo"] + # Add egamma trigger objects EGAM7SlimmingHelper.IncludeEGammaTriggerContent = True @@ -455,37 +512,53 @@ def EGAM7Cfg(ConfigFlags): # Run 2 if ConfigFlags.Trigger.EDMVersion == 2: from DerivationFrameworkPhys.TriggerMatchingCommonConfig import ( - AddRun2TriggerMatchingToSlimmingHelper ) + AddRun2TriggerMatchingToSlimmingHelper, + ) + AddRun2TriggerMatchingToSlimmingHelper( - SlimmingHelper = EGAM7SlimmingHelper, - OutputContainerPrefix = 'TrigMatch_', - TriggerList = EGAM7TriggerListsHelper.Run2TriggerNamesNoTau) + SlimmingHelper=EGAM7SlimmingHelper, + OutputContainerPrefix="TrigMatch_", + TriggerList=EGAM7TriggerListsHelper.Run2TriggerNamesNoTau, + ) # Run 3 if ConfigFlags.Trigger.EDMVersion == 3: from TrigNavSlimmingMT.TrigNavSlimmingMTConfig import ( - AddRun3TrigNavSlimmingCollectionsToSlimmingHelper ) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper, + ) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper(EGAM7SlimmingHelper) # Add CellContainer and cluster->cell links if thinCells: EGAM7SlimmingHelper.StaticContent = [ - 'CaloCellContainer#DFEGAMCellContainer', - 'CaloClusterCellLinkContainer#egammaClusters_links'] + "CaloCellContainer#DFEGAMCellContainer", + "CaloClusterCellLinkContainer#egammaClusters_links", + ] else: EGAM7SlimmingHelper.StaticContent = [ - 'CaloCellContainer#AllCalo', - 'CaloClusterCellLinkContainer#egammaClusters_links'] + "CaloCellContainer#AllCalo", + "CaloClusterCellLinkContainer#egammaClusters_links", + ] EGAM7ItemList = EGAM7SlimmingHelper.GetItemList() - acc.merge(OutputStreamCfg(ConfigFlags, - 'DAOD_EGAM7', - ItemList = EGAM7ItemList, - AcceptAlgs = ['EGAM7Kernel'])) - acc.merge(SetupMetaDataForStreamCfg(ConfigFlags, 'DAOD_EGAM7', - AcceptAlgs=['EGAM7Kernel'], - createMetadata=[ - MetadataCategory.CutFlowMetaData, - MetadataCategory.TruthMetaData, - ])) - + acc.merge( + OutputStreamCfg( + ConfigFlags, + "DAOD_EGAM7", + ItemList=EGAM7ItemList, + AcceptAlgs=["EGAM7Kernel"], + ) + ) + acc.merge( + SetupMetaDataForStreamCfg( + ConfigFlags, + "DAOD_EGAM7", + AcceptAlgs=["EGAM7Kernel"], + createMetadata=[ + MetadataCategory.CutFlowMetaData, + MetadataCategory.TruthMetaData, + ], + ) + ) + return acc diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM8.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM8.py index a91a88c2a388..0b76b05624b1 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM8.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM8.py @@ -1,12 +1,11 @@ # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration -#!/usr/bin/env python -#==================================================================== +# ==================================================================== # EGAM8.py # This defines DAOD_EGAM8, a skimmed DAOD format for Run 3. # Z->ee reduction for forward e tag-and-probe (one central e, one fwd e) # Z->emu reduction for bkg studies (one mu, one fwd e) -# It requires the flag EGAM8 in Derivation_tf.py -#==================================================================== +# It requires the flag EGAM8 in Derivation_tf.py +# ==================================================================== from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory @@ -15,29 +14,36 @@ from AthenaConfiguration.Enums import MetadataCategory from AthenaCommon.SystemOfUnits import MeV from DerivationFrameworkEGamma.PhotonsCPDetailedContent import ( - PhotonsCPDetailedContent ) + PhotonsCPDetailedContent, +) def EGAM8SkimmingToolCfg(flags): - '''Configure the EGAM8 skimming tool''' + """Configure the EGAM8 skimming tool""" acc = ComponentAccumulator() - expression = ' || '.join(['(count(EGAM8_DiElectronMass >50.0*GeV) >=1)', - '(count(EGAM8_MuonElectronMass >50.0*GeV) >=1)']) - print('EGAM8 skimming expression: ', expression) + expression = " || ".join( + [ + "(count(EGAM8_DiElectronMass >50.0*GeV) >=1)", + "(count(EGAM8_MuonElectronMass >50.0*GeV) >=1)", + ] + ) + print("EGAM8 skimming expression: ", expression) + + acc.setPrivateTools( + CompFactory.DerivationFramework.xAODStringSkimmingTool( + name="EGAM8SkimmingTool", expression=expression + ) + ) - acc.setPrivateTools( CompFactory.DerivationFramework.xAODStringSkimmingTool( - name = 'EGAM8SkimmingTool', - expression = expression) ) - - return(acc) + return acc def EGAM8ZeeMassToolCfg(flags): - '''Configure the EGAM8 ee invariant mass augmentation tool''' + """Configure the EGAM8 ee invariant mass augmentation tool""" acc = ComponentAccumulator() - #==================================================================== + # ==================================================================== # di-electron invariant mass for events passing the Z->ee # selection based on single e trigger, for reco (central) and ID # SF(central+fwd) @@ -46,33 +52,37 @@ def EGAM8ZeeMassToolCfg(flags): # 1 forward e, pT>20 GeV # OS+SS # mee>50 GeV (cut applied in skimming step later) - #==================================================================== - - requirement_tag = ' && '.join(['(Electrons.DFCommonElectronsLHMedium)', - '(Electrons.pt > 24.5*GeV)']) - requirement_probe = 'ForwardElectrons.pt > 19.5*GeV' - - acc.setPrivateTools( CompFactory.DerivationFramework.EGInvariantMassTool( - name = 'EGAM8_ZEEMassTool', - Object1Requirements = requirement_tag, - Object2Requirements = requirement_probe, - StoreGateEntryName = 'EGAM8_DiElectronMass', - Mass1Hypothesis = 0.511*MeV, - Mass2Hypothesis = 0.511*MeV, - Container1Name = 'Electrons', - Container2Name = 'ForwardElectrons', - CheckCharge = False, - DoTransverseMass = False, - MinDeltaR=0.0) ) + # ==================================================================== + + requirement_tag = " && ".join( + ["(Electrons.DFCommonElectronsLHMedium)", "(Electrons.pt > 24.5*GeV)"] + ) + requirement_probe = "ForwardElectrons.pt > 19.5*GeV" + + acc.setPrivateTools( + CompFactory.DerivationFramework.EGInvariantMassTool( + name="EGAM8_ZEEMassTool", + Object1Requirements=requirement_tag, + Object2Requirements=requirement_probe, + StoreGateEntryName="EGAM8_DiElectronMass", + Mass1Hypothesis=0.511 * MeV, + Mass2Hypothesis=0.511 * MeV, + Container1Name="Electrons", + Container2Name="ForwardElectrons", + CheckCharge=False, + DoTransverseMass=False, + MinDeltaR=0.0, + ) + ) return acc def EGAM8ZmueMassToolCfg(flags): - '''Configure the EGAM8 mue invariant mass augmentation tool''' + """Configure the EGAM8 mue invariant mass augmentation tool""" acc = ComponentAccumulator() - - #==================================================================== + + # ==================================================================== # mue invariant mass for events passing the Z->mue selection based # on single muon trigger, for ID SF(central+fwd) background studies # @@ -80,50 +90,57 @@ def EGAM8ZmueMassToolCfg(flags): # 1 forward e, pT>20 GeV # OS+SS # m(mue)>50 GeV (cut applied in skimming step later) - #==================================================================== - - requirement_muon = ' && '.join(['Muons.pt>24.5*GeV', - 'abs(Muons.eta)<2.7', - 'Muons.DFCommonMuonPassPreselection']) - requirement_electron = 'ForwardElectrons.pt > 19.5*GeV' - - acc.setPrivateTools( CompFactory.DerivationFramework.EGInvariantMassTool( - name = 'EGAM8_ZMuEMassTool', - Object1Requirements = requirement_muon, - Object2Requirements = requirement_electron, - StoreGateEntryName = 'EGAM8_MuonElectronMass', - Mass1Hypothesis = 105*MeV, - Mass2Hypothesis = 0.511*MeV, - Container1Name = 'Muons', - Container2Name = 'ForwardElectrons', - CheckCharge = False, - DoTransverseMass = False, - MinDeltaR = 0.0) ) + # ==================================================================== + + requirement_muon = " && ".join( + [ + "Muons.pt>24.5*GeV", + "abs(Muons.eta)<2.7", + "Muons.DFCommonMuonPassPreselection", + ] + ) + requirement_electron = "ForwardElectrons.pt > 19.5*GeV" + + acc.setPrivateTools( + CompFactory.DerivationFramework.EGInvariantMassTool( + name="EGAM8_ZMuEMassTool", + Object1Requirements=requirement_muon, + Object2Requirements=requirement_electron, + StoreGateEntryName="EGAM8_MuonElectronMass", + Mass1Hypothesis=105 * MeV, + Mass2Hypothesis=0.511 * MeV, + Container1Name="Muons", + Container2Name="ForwardElectrons", + CheckCharge=False, + DoTransverseMass=False, + MinDeltaR=0.0, + ) + ) return acc # Main algorithm config -def EGAM8KernelCfg(ConfigFlags, name='EGAM8Kernel', **kwargs): - '''Configure the derivation framework driving algorithm (kernel) - for EGAM8''' +def EGAM8KernelCfg(ConfigFlags, name="EGAM8Kernel", **kwargs): + """Configure the derivation framework driving algorithm (kernel) + for EGAM8""" acc = ComponentAccumulator() - # Common augmentations - from DerivationFrameworkPhys.PhysCommonConfig import ( - PhysCommonAugmentationsCfg ) - acc.merge( PhysCommonAugmentationsCfg( - ConfigFlags, - TriggerListsHelper = kwargs['TriggerListsHelper'] ) ) - + from DerivationFrameworkPhys.PhysCommonConfig import PhysCommonAugmentationsCfg + + acc.merge( + PhysCommonAugmentationsCfg( + ConfigFlags, TriggerListsHelper=kwargs["TriggerListsHelper"] + ) + ) # EGAM8 augmentations augmentationTools = [] - #==================================================================== + # ==================================================================== # ee and mue invariant masses - #==================================================================== + # ==================================================================== EGAM8ZeeMassTool = acc.popToolsAndMerge(EGAM8ZeeMassToolCfg(ConfigFlags)) acc.addPublicTool(EGAM8ZeeMassTool) augmentationTools.append(EGAM8ZeeMassTool) @@ -132,47 +149,51 @@ def EGAM8KernelCfg(ConfigFlags, name='EGAM8Kernel', **kwargs): acc.addPublicTool(EGAM8ZmueMassTool) augmentationTools.append(EGAM8ZmueMassTool) - #==================================================================== + # ==================================================================== # Max Cell energy and time - #==================================================================== + # ==================================================================== from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - MaxCellDecoratorCfg ) + MaxCellDecoratorCfg, + ) + MaxCellDecorator = acc.popToolsAndMerge(MaxCellDecoratorCfg(ConfigFlags)) acc.addPublicTool(MaxCellDecorator) - augmentationTools.append(MaxCellDecorator) + augmentationTools.append(MaxCellDecorator) # ==================================================================== # Gain and cluster energies per layer decoration tool # ==================================================================== - from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - GainDecoratorCfg, ClusterEnergyPerLayerDecoratorCfg ) + from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( + GainDecoratorCfg, + ClusterEnergyPerLayerDecoratorCfg, + ) + GainDecoratorTool = acc.popToolsAndMerge(GainDecoratorCfg(ConfigFlags)) acc.addPublicTool(GainDecoratorTool) augmentationTools.append(GainDecoratorTool) - cluster_sizes = (3,7), (5,5), (7,11) + cluster_sizes = (3, 7), (5, 5), (7, 11) for neta, nphi in cluster_sizes: - cename = 'ClusterEnergyPerLayerDecorator_%sx%s' % (neta, nphi) + cename = "ClusterEnergyPerLayerDecorator_%sx%s" % (neta, nphi) ClusterEnergyPerLayerDecorator = acc.popToolsAndMerge( ClusterEnergyPerLayerDecoratorCfg( - ConfigFlags, - neta = neta, - nphi=nphi, - name=cename )) + ConfigFlags, neta=neta, nphi=nphi, name=cename + ) + ) acc.addPublicTool(ClusterEnergyPerLayerDecorator) augmentationTools.append(ClusterEnergyPerLayerDecorator) - # thinning tools thinningTools = [] - streamName = kwargs['StreamName'] - + streamName = kwargs["StreamName"] + # Track thinning if ConfigFlags.Derivation.Egamma.doTrackThinning: - - from DerivationFrameworkInDet.InDetToolsConfig import ( - TrackParticleThinningCfg, MuonTrackParticleThinningCfg, - TauTrackParticleThinningCfg ) + from DerivationFrameworkInDet.InDetToolsConfig import ( + TrackParticleThinningCfg, + MuonTrackParticleThinningCfg, + TauTrackParticleThinningCfg, + ) TrackThinningKeepElectronTracks = True TrackThinningKeepPhotonTracks = True @@ -183,183 +204,221 @@ def EGAM8KernelCfg(ConfigFlags, name='EGAM8Kernel', **kwargs): TrackThinningKeepPVTracks = False # Tracks associated with Electrons - if (TrackThinningKeepElectronTracks): - EGAM8ElectronTPThinningTool = \ + if TrackThinningKeepElectronTracks: + EGAM8ElectronTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM8ElectronTPThinningTool', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM8ElectronTPThinningTool", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM8ElectronTPThinningTool) thinningTools.append(EGAM8ElectronTPThinningTool) # Tracks associated with Electrons (all tracks, large cone, for track # isolation studies of the selected electrons) - if (TrackThinningKeepAllElectronTracks): - EGAM8ElectronTPThinningTool2 = \ + if TrackThinningKeepAllElectronTracks: + EGAM8ElectronTPThinningTool2 = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM8ElectronTPThinningTool2', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 4*GeV', - BestMatchOnly = False, - ConeSize = 0.6) + name="EGAM8ElectronTPThinningTool2", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 4*GeV", + BestMatchOnly=False, + ConeSize=0.6, + ) + ) acc.addPublicTool(EGAM8ElectronTPThinningTool2) thinningTools.append(EGAM8ElectronTPThinningTool2) - + # Tracks associated with Photons - if (TrackThinningKeepPhotonTracks): - EGAM8PhotonTPThinningTool = \ + if TrackThinningKeepPhotonTracks: + EGAM8PhotonTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM8PhotonTPThinningTool', - StreamName = streamName, - SGKey = 'Photons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - GSFConversionVerticesKey = 'GSFConversionVertices', - SelectionString = 'Photons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM8PhotonTPThinningTool", + StreamName=streamName, + SGKey="Photons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + GSFConversionVerticesKey="GSFConversionVertices", + SelectionString="Photons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM8PhotonTPThinningTool) thinningTools.append(EGAM8PhotonTPThinningTool) # Tracks associated with Jets - if (TrackThinningKeepJetTracks): - EGAM8JetTPThinningTool = \ + if TrackThinningKeepJetTracks: + EGAM8JetTPThinningTool = ( CompFactory.DerivationFramework.JetTrackParticleThinning( - name = 'EGAM8JetTPThinningTool', - StreamName = streamName, - JetKey = 'AntiKt4EMPFlowJets', - InDetTrackParticlesKey = 'InDetTrackParticles') + name="EGAM8JetTPThinningTool", + StreamName=streamName, + JetKey="AntiKt4EMPFlowJets", + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) acc.addPublicTool(EGAM8JetTPThinningTool) thinningTools.append(EGAM8JetTPThinningTool) # Tracks associated with Muons - if (TrackThinningKeepMuonTracks): - EGAM8MuonTPThinningTool = \ - acc.getPrimaryAndMerge(MuonTrackParticleThinningCfg( + if TrackThinningKeepMuonTracks: + EGAM8MuonTPThinningTool = acc.getPrimaryAndMerge( + MuonTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM8MuonTPThinningTool', - StreamName = streamName, - MuonKey = 'Muons', - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM8MuonTPThinningTool", + StreamName=streamName, + MuonKey="Muons", + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM8MuonTPThinningTool) # Tracks associated with Taus - if (TrackThinningKeepTauTracks): - EGAM8TauTPThinningTool = \ - acc.getPrimaryAndMerge(TauTrackParticleThinningCfg( + if TrackThinningKeepTauTracks: + EGAM8TauTPThinningTool = acc.getPrimaryAndMerge( + TauTrackParticleThinningCfg( ConfigFlags, - name = 'EGAM8TauTPThinningTool', - StreamName = streamName, - TauKey = 'TauJets', - ConeSize = 0.6, - InDetTrackParticlesKey = 'InDetTrackParticles', - DoTauTracksThinning = True, - TauTracksKey = 'TauTracks') ) + name="EGAM8TauTPThinningTool", + StreamName=streamName, + TauKey="TauJets", + ConeSize=0.6, + InDetTrackParticlesKey="InDetTrackParticles", + DoTauTracksThinning=True, + TauTracksKey="TauTracks", + ) + ) thinningTools.append(EGAM8TauTPThinningTool) # Tracks from primary vertex - thinning_expression = ' && '.join([ - '(InDetTrackParticles.DFCommonTightPrimary)', - '(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta) < 3.0*mm)', - '(InDetTrackParticles.pt > 10*GeV)']) - if (TrackThinningKeepPVTracks): - EGAM8TPThinningTool = \ - acc.getPrimaryAndMerge(TrackParticleThinningCfg( + thinning_expression = " && ".join( + [ + "(InDetTrackParticles.DFCommonTightPrimary)", + "(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3.0*mm)", + "(InDetTrackParticles.pt>10*GeV)", + ] + ) + if TrackThinningKeepPVTracks: + EGAM8TPThinningTool = acc.getPrimaryAndMerge( + TrackParticleThinningCfg( ConfigFlags, - name = 'EGAM8TPThinningTool', - StreamName = streamName, - SelectionString = thinning_expression, - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM8TPThinningTool", + StreamName=streamName, + SelectionString=thinning_expression, + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM8TPThinningTool) - # truth thinning if ConfigFlags.Input.isMC: # W, Z and Higgs - truth_cond_WZH = ' && '.join(['(abs(TruthParticles.pdgId) >= 23)', - '(abs(TruthParticles.pdgId) <= 25)']) + truth_cond_WZH = " && ".join( + ["(abs(TruthParticles.pdgId) >= 23)", "(abs(TruthParticles.pdgId) <= 25)"] + ) # Leptons - truth_cond_lep = ' && '.join(['(abs(TruthParticles.pdgId) >= 11)', - '(abs(TruthParticles.pdgId) <= 16)']) + truth_cond_lep = " && ".join( + ["(abs(TruthParticles.pdgId) >= 11)", "(abs(TruthParticles.pdgId) <= 16)"] + ) # Top quark - truth_cond_top = '(abs(TruthParticles.pdgId) == 6)' + truth_cond_top = "(abs(TruthParticles.pdgId) == 6)" # Photon - truth_cond_gam = ' && '.join(['(abs(TruthParticles.pdgId) == 22)', - '(TruthParticles.pt > 1*GeV)']) + truth_cond_gam = " && ".join( + ["(abs(TruthParticles.pdgId) == 22)", "(TruthParticles.pt > 1*GeV)"] + ) # stable particles - truth_cond_finalState = ' && '.join(['(TruthParticles.status == 1)', - '(TruthParticles.barcode<200000)']) - truth_expression = '( ' + truth_cond_WZH + ' ) || ' + \ - '( ' + truth_cond_lep + ' ) || ' + \ - '( ' + truth_cond_top + ' ) || ' + \ - '( ' + truth_cond_gam + ' ) || ' + \ - '( ' + truth_cond_finalState + ' )' - print('EGAM8 truth thinning expression: ', truth_expression) - - EGAM8TruthThinningTool = \ - CompFactory.DerivationFramework.GenericTruthThinning( - name = 'EGAM8TruthThinningTool', - StreamName = streamName, - ParticleSelectionString = truth_expression, - PreserveDescendants = False, - PreserveGeneratorDescendants = True, - PreserveAncestors = True) + truth_cond_finalState = " && ".join( + ["(TruthParticles.status == 1)", "(TruthParticles.barcode<200000)"] + ) + truth_expression = ( + "( " + + truth_cond_WZH + + " ) || " + + "( " + + truth_cond_lep + + " ) || " + + "( " + + truth_cond_top + + " ) || " + + "( " + + truth_cond_gam + + " ) || " + + "( " + + truth_cond_finalState + + " )" + ) + print("EGAM8 truth thinning expression: ", truth_expression) + + EGAM8TruthThinningTool = CompFactory.DerivationFramework.GenericTruthThinning( + name="EGAM8TruthThinningTool", + StreamName=streamName, + ParticleSelectionString=truth_expression, + PreserveDescendants=False, + PreserveGeneratorDescendants=True, + PreserveAncestors=True, + ) acc.addPublicTool(EGAM8TruthThinningTool) thinningTools.append(EGAM8TruthThinningTool) - # skimming skimmingTool = acc.popToolsAndMerge(EGAM8SkimmingToolCfg(ConfigFlags)) acc.addPublicTool(skimmingTool) - # setup the kernel - acc.addEventAlgo(CompFactory.DerivationFramework.DerivationKernel(name, - SkimmingTools = [skimmingTool], - AugmentationTools = augmentationTools, - ThinningTools = thinningTools) ) + acc.addEventAlgo( + CompFactory.DerivationFramework.DerivationKernel( + name, + SkimmingTools=[skimmingTool], + AugmentationTools=augmentationTools, + ThinningTools=thinningTools, + ) + ) return acc def EGAM8Cfg(ConfigFlags): - acc = ComponentAccumulator() - # Get the lists of triggers needed for trigger matching. # This is needed at this scope (for the slimming) and further down # in the config chain for actually configuring the matching, so we create # it here and pass it down # TODO: this should ideally be called higher up to avoid it being run # multiple times in a train - + from DerivationFrameworkPhys.TriggerListsHelper import TriggerListsHelper + EGAM8TriggerListsHelper = TriggerListsHelper(ConfigFlags) # configure skimming/thinning/augmentation tools - acc.merge(EGAM8KernelCfg(ConfigFlags, - name = 'EGAM8Kernel', - StreamName = 'StreamDAOD_EGAM8', - TriggerListsHelper = EGAM8TriggerListsHelper)) - + acc.merge( + EGAM8KernelCfg( + ConfigFlags, + name="EGAM8Kernel", + StreamName="StreamDAOD_EGAM8", + TriggerListsHelper=EGAM8TriggerListsHelper, + ) + ) # configure slimming from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper + EGAM8SlimmingHelper = SlimmingHelper( - 'EGAM8SlimmingHelper', - NamesAndTypes = ConfigFlags.Input.TypedCollections, - ConfigFlags = ConfigFlags ) + "EGAM8SlimmingHelper", + NamesAndTypes=ConfigFlags.Input.TypedCollections, + ConfigFlags=ConfigFlags, + ) # ------------------------------------------ # containers for which we save all variables @@ -367,100 +426,110 @@ def EGAM8Cfg(ConfigFlags): # baseline EGAM8SlimmingHelper.AllVariables = [ - 'Electrons', - 'ForwardElectrons', - 'GSFTrackParticles', - 'egammaClusters', - 'ForwardElectronClusters' ] - + "Electrons", + "ForwardElectrons", + "GSFTrackParticles", + "egammaClusters", + "ForwardElectronClusters", + ] + # for trigger studies we also add: # EGAM8SlimmingHelper.AllVariables += [ ] - + # and on MC we also add: if ConfigFlags.Input.isMC: - EGAM8SlimmingHelper.AllVariables +=[ - 'TruthEvents', - 'TruthParticles', - 'TruthVertices', - 'egammaTruthParticles' + EGAM8SlimmingHelper.AllVariables += [ + "TruthEvents", + "TruthParticles", + "TruthVertices", + "egammaTruthParticles", ] - # ------------------------------------------- # containers that we slim # ------------------------------------------- - # first add variables from smart-slimming + # first add variables from smart-slimming # adding only also those for which we add all variables since - # the XXXCPContent.py files also bring in some extra variables + # the XXXCPContent.py files also bring in some extra variables # for other collections - EGAM8SlimmingHelper.SmartCollections = ['Electrons', - 'Photons', - 'Muons', - 'TauJets', - 'PrimaryVertices', - 'InDetTrackParticles', - 'AntiKt4EMPFlowJets', - 'BTagging_AntiKt4EMPFlow', - 'MET_Baseline_AntiKt4EMPFlow', - ] + EGAM8SlimmingHelper.SmartCollections = [ + "Electrons", + "Photons", + "Muons", + "TauJets", + "PrimaryVertices", + "InDetTrackParticles", + "AntiKt4EMPFlowJets", + "BTagging_AntiKt4EMPFlow", + "MET_Baseline_AntiKt4EMPFlow", + ] if ConfigFlags.Input.isMC: - EGAM8SlimmingHelper.SmartCollections += ['AntiKt4TruthJets', - 'AntiKt4TruthDressedWZJets'] + EGAM8SlimmingHelper.SmartCollections += [ + "AntiKt4TruthJets", + "AntiKt4TruthDressedWZJets", + ] # then add extra variables: # muons EGAM8SlimmingHelper.ExtraVariables += [ - 'Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40' ] + "Muons.ptcone20.ptcone30.ptcone40.etcone20.etcone30.etcone40" + ] # conversion vertices EGAM8SlimmingHelper.ExtraVariables += [ - 'GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo', - 'GSFConversionVertices.trackParticleLinks' ] + "GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo", + "GSFConversionVertices.trackParticleLinks", + ] # primary vertices - EGAM8SlimmingHelper.ExtraVariables += [ - 'PrimaryVertices.x.y.sumPt2' ] + EGAM8SlimmingHelper.ExtraVariables += ["PrimaryVertices.x.y.sumPt2"] # track jets EGAM8SlimmingHelper.ExtraVariables += [ - 'AntiKt4PV0TrackJets.pt.eta.phi.e.m.btaggingLink.constituentLinks' ] + "AntiKt4PV0TrackJets.pt.eta.phi.e.m.btaggingLink.constituentLinks" + ] # energy density - EGAM8SlimmingHelper.ExtraVariables += [ - 'TopoClusterIsoCentralEventShape.Density', - 'TopoClusterIsoForwardEventShape.Density', - 'NeutralParticleFlowIsoCentralEventShape.Density', - 'NeutralParticleFlowIsoForwardEventShape.Density'] + EGAM8SlimmingHelper.ExtraVariables += [ + "TopoClusterIsoCentralEventShape.Density", + "TopoClusterIsoForwardEventShape.Density", + "NeutralParticleFlowIsoCentralEventShape.Density", + "NeutralParticleFlowIsoForwardEventShape.Density", + ] # photons: detailed shower shape variables EGAM8SlimmingHelper.ExtraVariables += PhotonsCPDetailedContent # photons: gain and cluster energy per layer from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - getGainDecorations, getClusterEnergyPerLayerDecorations ) - gainDecorations = getGainDecorations(acc, 'EGAM8Kernel') - print('EGAM8 gain decorations: ', gainDecorations) + getGainDecorations, + getClusterEnergyPerLayerDecorations, + ) + + gainDecorations = getGainDecorations(acc, "EGAM8Kernel") + print("EGAM8 gain decorations: ", gainDecorations) EGAM8SlimmingHelper.ExtraVariables.extend(gainDecorations) - clusterEnergyDecorations = getClusterEnergyPerLayerDecorations( - acc, 'EGAM8Kernel' ) - print('EGAM8 cluster energy decorations: ', clusterEnergyDecorations) + clusterEnergyDecorations = getClusterEnergyPerLayerDecorations(acc, "EGAM8Kernel") + print("EGAM8 cluster energy decorations: ", clusterEnergyDecorations) EGAM8SlimmingHelper.ExtraVariables.extend(clusterEnergyDecorations) # truth if ConfigFlags.Input.isMC: EGAM8SlimmingHelper.ExtraVariables += [ - 'MuonTruthParticles.e.px.py.pz.status.pdgId.truthOrigin.truthType' ] + "MuonTruthParticles.e.px.py.pz.status.pdgId.truthOrigin.truthType" + ] EGAM8SlimmingHelper.ExtraVariables += [ - 'Photons.truthOrigin.truthType.truthParticleLink' ] + "Photons.truthOrigin.truthType.truthParticleLink" + ] # Add event info if ConfigFlags.Derivation.Egamma.doEventInfoSlimming: - EGAM8SlimmingHelper.SmartCollections.append('EventInfo') + EGAM8SlimmingHelper.SmartCollections.append("EventInfo") else: - EGAM8SlimmingHelper.AllVariables += ['EventInfo'] + EGAM8SlimmingHelper.AllVariables += ["EventInfo"] # Add egamma trigger objects EGAM8SlimmingHelper.IncludeEGammaTriggerContent = True @@ -470,40 +539,58 @@ def EGAM8Cfg(ConfigFlags): # Run 2 if ConfigFlags.Trigger.EDMVersion == 2: from DerivationFrameworkPhys.TriggerMatchingCommonConfig import ( - AddRun2TriggerMatchingToSlimmingHelper ) + AddRun2TriggerMatchingToSlimmingHelper, + ) + AddRun2TriggerMatchingToSlimmingHelper( - SlimmingHelper = EGAM8SlimmingHelper, - OutputContainerPrefix = 'TrigMatch_', - TriggerList = EGAM8TriggerListsHelper.Run2TriggerNamesNoTau) + SlimmingHelper=EGAM8SlimmingHelper, + OutputContainerPrefix="TrigMatch_", + TriggerList=EGAM8TriggerListsHelper.Run2TriggerNamesNoTau, + ) # Run 3 if ConfigFlags.Trigger.EDMVersion == 3: from TrigNavSlimmingMT.TrigNavSlimmingMTConfig import ( - AddRun3TrigNavSlimmingCollectionsToSlimmingHelper ) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper, + ) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper(EGAM8SlimmingHelper) # Run 2 is added here temporarily to allow testing/comparison/debugging from DerivationFrameworkPhys.TriggerMatchingCommonConfig import ( - AddRun2TriggerMatchingToSlimmingHelper ) + AddRun2TriggerMatchingToSlimmingHelper, + ) + AddRun2TriggerMatchingToSlimmingHelper( - SlimmingHelper = EGAM8SlimmingHelper, - OutputContainerPrefix = 'TrigMatch_', - TriggerList = EGAM8TriggerListsHelper.Run3TriggerNamesNoTau) + SlimmingHelper=EGAM8SlimmingHelper, + OutputContainerPrefix="TrigMatch_", + TriggerList=EGAM8TriggerListsHelper.Run3TriggerNamesNoTau, + ) # Add full CellContainer EGAM8SlimmingHelper.StaticContent = [ - 'CaloCellContainer#AllCalo', - 'CaloClusterCellLinkContainer#egammaClusters_links', - 'CaloClusterCellLinkContainer#ForwardElectronClusters_links'] - + "CaloCellContainer#AllCalo", + "CaloClusterCellLinkContainer#egammaClusters_links", + "CaloClusterCellLinkContainer#ForwardElectronClusters_links", + ] + EGAM8ItemList = EGAM8SlimmingHelper.GetItemList() - acc.merge(OutputStreamCfg(ConfigFlags, - 'DAOD_EGAM8', - ItemList = EGAM8ItemList, - AcceptAlgs = ['EGAM8Kernel'])) - acc.merge(SetupMetaDataForStreamCfg(ConfigFlags, 'DAOD_EGAM8', - AcceptAlgs=['EGAM8Kernel'], - createMetadata=[ - MetadataCategory.CutFlowMetaData, - MetadataCategory.TruthMetaData, - ])) + acc.merge( + OutputStreamCfg( + ConfigFlags, + "DAOD_EGAM8", + ItemList=EGAM8ItemList, + AcceptAlgs=["EGAM8Kernel"], + ) + ) + acc.merge( + SetupMetaDataForStreamCfg( + ConfigFlags, + "DAOD_EGAM8", + AcceptAlgs=["EGAM8Kernel"], + createMetadata=[ + MetadataCategory.CutFlowMetaData, + MetadataCategory.TruthMetaData, + ], + ) + ) return acc diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM9.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM9.py index 0f7bee819138..a90ff2034252 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM9.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGAM9.py @@ -1,26 +1,31 @@ # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration -#!/usr/bin/env python -#==================================================================== +# ==================================================================== # EGAM9.py # This defines DAOD_EGAM9, a skimmed DAOD format for Run 3. -# keep events passing or of photon triggers used for boostrap efficiency +# keep events passing or of photon triggers used for boostrap efficiency # measurement of photon triggers -# It requires the flag EGAM9 in Derivation_tf.py -#==================================================================== +# It requires the flag EGAM9 in Derivation_tf.py +# ==================================================================== from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory from AthenaConfiguration.Enums import MetadataCategory from DerivationFrameworkEGamma.PhotonsCPDetailedContent import ( - PhotonsCPDetailedContent ) + PhotonsCPDetailedContent, +) from DerivationFrameworkEGamma.ElectronsCPDetailedContent import ( - ElectronsCPDetailedContent, GSFTracksCPDetailedContent ) + ElectronsCPDetailedContent, + GSFTracksCPDetailedContent, +) from DerivationFrameworkEGamma.TriggerContent import ( - BootstrapPhotonTriggers, noalgTriggers, - ExtraContainersTrigger, ExtraContainersPhotonTrigger, - ExtraContainersTriggerDataOnly ) + BootstrapPhotonTriggers, + noalgTriggers, + ExtraContainersTrigger, + ExtraContainersPhotonTrigger, + ExtraContainersTriggerDataOnly, +) # additional settings for this derivation @@ -31,234 +36,270 @@ saveJets = False def EGAM9SkimmingToolCfg(flags): - '''Configure the EGAM9 skimming tool''' + """Configure the EGAM9 skimming tool""" acc = ComponentAccumulator() # criteria for off-line based selection - photon_selection = '(count(Photons.pt > 9.5*GeV && ' + \ - 'Photons.DFCommonPhotonsIsEMLoose) > 0)' - electron_selection = '(count(Electrons.pt > 9.5*GeV && ' + \ - 'Electrons.DFCommonElectronsLHMedium) > 0)' - expression = photon_selection + ' || ' + electron_selection + photon_selection = ( + "(count(Photons.pt > 9.5*GeV && " + "Photons.DFCommonPhotonsIsEMLoose) > 0)" + ) + electron_selection = ( + "(count(Electrons.pt > 9.5*GeV && " + + "Electrons.DFCommonElectronsLHMedium) > 0)" + ) + expression = photon_selection + " || " + electron_selection if applyTriggerSelection: # trigger-based selection MenuType = None if flags.Trigger.EDMVersion == 2: - MenuType = 'Run2' + MenuType = "Run2" elif flags.Trigger.EDMVersion == 3: - MenuType = 'Run3' + MenuType = "Run3" else: - MenuType = '' + MenuType = "" triggers = BootstrapPhotonTriggers[MenuType] triggers += noalgTriggers[MenuType] - print('EGAM9 trigger skimming list (OR): ', triggers) - EGAM9_TriggerSkimmingTool = \ - CompFactory.DerivationFramework.TriggerSkimmingTool( - name = 'EGAM9_TriggerSkimmingTool', - TriggerListOR = triggers) + print("EGAM9 trigger skimming list (OR): ", triggers) + EGAM9_TriggerSkimmingTool = CompFactory.DerivationFramework.TriggerSkimmingTool( + name="EGAM9_TriggerSkimmingTool", TriggerListOR=triggers + ) # off-line based selection - print('EGAM9 offline skimming expression: ', expression) - EGAM9_OfflineSkimmingTool = \ + print("EGAM9 offline skimming expression: ", expression) + EGAM9_OfflineSkimmingTool = ( CompFactory.DerivationFramework.xAODStringSkimmingTool( - name = 'EGAM9_OfflineSkimmingTool', - expression = expression) + name="EGAM9_OfflineSkimmingTool", expression=expression + ) + ) # do the AND of trigger-based and offline-based selection - print('EGAM9 skimming is logical AND of previous selections') - EGAM9_SkimmingTool = \ - CompFactory.DerivationFramework.FilterCombinationAND( - name = 'EGAM9_SkimmingTool', - FilterList=[EGAM9_OfflineSkimmingTool, - EGAM9_TriggerSkimmingTool]) + print("EGAM9 skimming is logical AND of previous selections") + EGAM9_SkimmingTool = CompFactory.DerivationFramework.FilterCombinationAND( + name="EGAM9_SkimmingTool", + FilterList=[EGAM9_OfflineSkimmingTool, EGAM9_TriggerSkimmingTool], + ) acc.addPublicTool(EGAM9_OfflineSkimmingTool) acc.addPublicTool(EGAM9_TriggerSkimmingTool) - acc.addPublicTool(EGAM9_SkimmingTool, primary = True) + acc.addPublicTool(EGAM9_SkimmingTool, primary=True) else: # off-line based selection - print('EGAM9 skimming expression: ', expression) - EGAM9_SkimmingTool = \ - CompFactory.DerivationFramework.xAODStringSkimmingTool( - name = 'EGAM9_SkimmingTool', - expression = expression) - acc.addPublicTool(EGAM9_SkimmingTool, primary = True) - + print("EGAM9 skimming expression: ", expression) + EGAM9_SkimmingTool = CompFactory.DerivationFramework.xAODStringSkimmingTool( + name="EGAM9_SkimmingTool", expression=expression + ) + acc.addPublicTool(EGAM9_SkimmingTool, primary=True) + return acc -def EGAM9KernelCfg(ConfigFlags, name='EGAM9Kernel', **kwargs): - '''Configure the derivation framework driving algorithm (kernel) - for EGAM9''' +def EGAM9KernelCfg(ConfigFlags, name="EGAM9Kernel", **kwargs): + """Configure the derivation framework driving algorithm (kernel) + for EGAM9""" acc = ComponentAccumulator() - # Common augmentations - from DerivationFrameworkPhys.PhysCommonConfig import ( - PhysCommonAugmentationsCfg ) - acc.merge( PhysCommonAugmentationsCfg( - ConfigFlags, - TriggerListsHelper = kwargs['TriggerListsHelper'] ) ) - + from DerivationFrameworkPhys.PhysCommonConfig import PhysCommonAugmentationsCfg + + acc.merge( + PhysCommonAugmentationsCfg( + ConfigFlags, TriggerListsHelper=kwargs["TriggerListsHelper"] + ) + ) # EGAM9 augmentations augmentationTools = [] - #==================================================================== + # ==================================================================== # Max Cell energy and time - #==================================================================== + # ==================================================================== from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - MaxCellDecoratorCfg ) + MaxCellDecoratorCfg, + ) + MaxCellDecorator = acc.popToolsAndMerge(MaxCellDecoratorCfg(ConfigFlags)) acc.addPublicTool(MaxCellDecorator) - augmentationTools.append(MaxCellDecorator) - + augmentationTools.append(MaxCellDecorator) + # ==================================================================== # Gain and cluster energies per layer decoration tool # ==================================================================== from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - GainDecoratorCfg, ClusterEnergyPerLayerDecoratorCfg ) + GainDecoratorCfg, + ClusterEnergyPerLayerDecoratorCfg, + ) + EGAM9_GainDecoratorTool = acc.popToolsAndMerge( - GainDecoratorCfg(ConfigFlags, name = 'EGAM9_GainDecoratorTool' )) + GainDecoratorCfg(ConfigFlags, name="EGAM9_GainDecoratorTool") + ) acc.addPublicTool(EGAM9_GainDecoratorTool) augmentationTools.append(EGAM9_GainDecoratorTool) - # might need some modification when cell-level reweighting is implemented (see share/EGAM9.py) - cluster_sizes = (3,7), (5,5), (7,11) + # might need some modification if cell-level reweighting is implemented + # (see share/EGAM9.py) + cluster_sizes = (3, 7), (5, 5), (7, 11) for neta, nphi in cluster_sizes: - cename = 'EGAM9_ClusterEnergyPerLayerDecorator_%sx%s' % (neta, nphi) + cename = "EGAM9_ClusterEnergyPerLayerDecorator_%sx%s" % (neta, nphi) EGAM9_ClusterEnergyPerLayerDecorator = acc.popToolsAndMerge( ClusterEnergyPerLayerDecoratorCfg( - ConfigFlags, - neta = neta, - nphi=nphi, - name=cename )) + ConfigFlags, neta=neta, nphi=nphi, name=cename + ) + ) acc.addPublicTool(EGAM9_ClusterEnergyPerLayerDecorator) augmentationTools.append(EGAM9_ClusterEnergyPerLayerDecorator) - # thinning tools thinningTools = [] - streamName = kwargs['StreamName'] + streamName = kwargs["StreamName"] # Track thinning if ConfigFlags.Derivation.Egamma.doTrackThinning: - TrackThinningKeepElectronTracks = False TrackThinningKeepPhotonTracks = True TrackThinningKeepPVTracks = False # Tracks associated with Electrons - if (TrackThinningKeepElectronTracks): - EGAM9ElectronTPThinningTool = \ + if TrackThinningKeepElectronTracks: + EGAM9ElectronTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM9ElectronTPThinningTool', - StreamName = streamName, - SGKey = 'Electrons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - SelectionString = 'Electrons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM9ElectronTPThinningTool", + StreamName=streamName, + SGKey="Electrons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + SelectionString="Electrons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM9ElectronTPThinningTool) thinningTools.append(EGAM9ElectronTPThinningTool) # Tracks associated with Photons - if (TrackThinningKeepPhotonTracks): - EGAM9PhotonTPThinningTool = \ + if TrackThinningKeepPhotonTracks: + EGAM9PhotonTPThinningTool = ( CompFactory.DerivationFramework.EgammaTrackParticleThinning( - name = 'EGAM9PhotonTPThinningTool', - StreamName = streamName, - SGKey = 'Photons', - GSFTrackParticlesKey = 'GSFTrackParticles', - InDetTrackParticlesKey = 'InDetTrackParticles', - GSFConversionVerticesKey = 'GSFConversionVertices', - SelectionString = 'Photons.pt > 0*GeV', - BestMatchOnly = True, - ConeSize = 0.3) + name="EGAM9PhotonTPThinningTool", + StreamName=streamName, + SGKey="Photons", + GSFTrackParticlesKey="GSFTrackParticles", + InDetTrackParticlesKey="InDetTrackParticles", + GSFConversionVerticesKey="GSFConversionVertices", + SelectionString="Photons.pt > 0*GeV", + BestMatchOnly=True, + ConeSize=0.3, + ) + ) acc.addPublicTool(EGAM9PhotonTPThinningTool) thinningTools.append(EGAM9PhotonTPThinningTool) # Tracks from primary vertex - if (TrackThinningKeepPVTracks) : + thinning_expression = " && ".join( + [ + "(InDetTrackParticles.DFCommonTightPrimary)", + "(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3*mm)", + "(InDetTrackParticles.pt > 10*GeV)", + ] + ) + if TrackThinningKeepPVTracks: from DerivationFrameworkInDet.InDetToolsConfig import ( - TrackParticleThinningCfg ) - thinning_expression = ' && '.join([ - '(InDetTrackParticles.DFCommonTightPrimary)', - '(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta) < 3.0*mm)', - '(InDetTrackParticles.pt > 10*GeV)']) + TrackParticleThinningCfg, + ) + EGAM9TPThinningTool = acc.getPrimaryAndMerge( TrackParticleThinningCfg( ConfigFlags, - name = 'EGAM9TPThinningTool', - StreamName = streamName, - SelectionString = thinning_expression, - InDetTrackParticlesKey = 'InDetTrackParticles') ) + name="EGAM9TPThinningTool", + StreamName=streamName, + SelectionString=thinning_expression, + InDetTrackParticlesKey="InDetTrackParticles", + ) + ) thinningTools.append(EGAM9TPThinningTool) # truth thinning if ConfigFlags.Input.isMC: # W, Z and Higgs - truth_cond_WZH = ' && '.join(['(abs(TruthParticles.pdgId) >= 23)', - '(abs(TruthParticles.pdgId) <= 25)']) + truth_cond_WZH = " && ".join( + ["(abs(TruthParticles.pdgId) >= 23)", "(abs(TruthParticles.pdgId) <= 25)"] + ) # Leptons - truth_cond_lep = ' && '.join(['(abs(TruthParticles.pdgId) >= 11)', - '(abs(TruthParticles.pdgId) <= 16)']) + truth_cond_lep = " && ".join( + ["(abs(TruthParticles.pdgId) >= 11)", "(abs(TruthParticles.pdgId) <= 16)"] + ) # Top quark - truth_cond_top = '(abs(TruthParticles.pdgId) == 6)' + truth_cond_top = "(abs(TruthParticles.pdgId) == 6)" # Photon - truth_cond_gam = ' && '.join(['(abs(TruthParticles.pdgId) == 22)', - '(TruthParticles.pt > 1*GeV)']) + truth_cond_gam = " && ".join( + ["(abs(TruthParticles.pdgId) == 22)", "(TruthParticles.pt > 1*GeV)"] + ) # stable particles - truth_cond_finalState = ' && '.join(['(TruthParticles.status == 1)', - '(TruthParticles.barcode<200000)']) - truth_expression = '( ' + truth_cond_WZH + ' ) || ' + \ - '( ' + truth_cond_lep + ' ) || ' + \ - '( ' + truth_cond_top + ' ) || ' + \ - '( ' + truth_cond_gam + ' ) || ' + \ - '( ' + truth_cond_finalState + ' )' - print('EGAM9 truth thinning expression: ', truth_expression) - - EGAM9TruthThinningTool = \ - CompFactory.DerivationFramework.GenericTruthThinning( - name = 'EGAM9TruthThinningTool', - StreamName = streamName, - ParticleSelectionString = truth_expression, - PreserveDescendants = False, - PreserveGeneratorDescendants = True, - PreserveAncestors = True) + truth_cond_finalState = " && ".join( + ["(TruthParticles.status == 1)", "(TruthParticles.barcode<200000)"] + ) + truth_expression = ( + "( " + + truth_cond_WZH + + " ) || " + + "( " + + truth_cond_lep + + " ) || " + + "( " + + truth_cond_top + + " ) || " + + "( " + + truth_cond_gam + + " ) || " + + "( " + + truth_cond_finalState + + " )" + ) + print("EGAM9 truth thinning expression: ", truth_expression) + + EGAM9TruthThinningTool = CompFactory.DerivationFramework.GenericTruthThinning( + name="EGAM9TruthThinningTool", + StreamName=streamName, + ParticleSelectionString=truth_expression, + PreserveDescendants=False, + PreserveGeneratorDescendants=True, + PreserveAncestors=True, + ) acc.addPublicTool(EGAM9TruthThinningTool) thinningTools.append(EGAM9TruthThinningTool) # Keep only calo cells associated with the egammaClusters collection if thinCells: - from DerivationFrameworkCalo.CaloCellDFGetterConfig import ( - thinCaloCellsForDFCfg ) - acc.merge(thinCaloCellsForDFCfg (ConfigFlags, - inputClusterKeys=['egammaClusters'], - streamName = 'StreamDAOD_EGAM9', - inputCellKey = 'AllCalo', - outputCellKey = 'DFEGAMCellContainer')) + from DerivationFrameworkCalo.CaloCellDFGetterConfig import thinCaloCellsForDFCfg + + acc.merge( + thinCaloCellsForDFCfg( + ConfigFlags, + inputClusterKeys=["egammaClusters"], + streamName="StreamDAOD_EGAM9", + inputCellKey="AllCalo", + outputCellKey="DFEGAMCellContainer", + ) + ) # skimming skimmingTool = acc.getPrimaryAndMerge(EGAM9SkimmingToolCfg(ConfigFlags)) - # setup the kernel - acc.addEventAlgo(CompFactory.DerivationFramework.DerivationKernel(name, - SkimmingTools = [skimmingTool], - AugmentationTools = augmentationTools, - ThinningTools = thinningTools) ) + acc.addEventAlgo( + CompFactory.DerivationFramework.DerivationKernel( + name, + SkimmingTools=[skimmingTool], + AugmentationTools=augmentationTools, + ThinningTools=thinningTools, + ) + ) return acc - def EGAM9Cfg(ConfigFlags): - acc = ComponentAccumulator() - # Get the lists of triggers needed for trigger matching. # This is needed at this scope (for the slimming) and further down # in the config chain for actually configuring the matching, so we create @@ -267,44 +308,50 @@ def EGAM9Cfg(ConfigFlags): # multiple times in a train. # TODO: restrict it to relevant triggers from DerivationFrameworkPhys.TriggerListsHelper import TriggerListsHelper + EGAM9TriggerListsHelper = TriggerListsHelper(ConfigFlags) # configure skimming/thinning/augmentation tools - acc.merge(EGAM9KernelCfg(ConfigFlags, - name = 'EGAM9Kernel', - StreamName = 'StreamDAOD_EGAM9', - TriggerListsHelper = EGAM9TriggerListsHelper)) - + acc.merge( + EGAM9KernelCfg( + ConfigFlags, + name="EGAM9Kernel", + StreamName="StreamDAOD_EGAM9", + TriggerListsHelper=EGAM9TriggerListsHelper, + ) + ) # configure slimming from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg from DerivationFrameworkCore.SlimmingHelper import SlimmingHelper - EGAM9SlimmingHelper = SlimmingHelper( - 'EGAM9SlimmingHelper', - NamesAndTypes = ConfigFlags.Input.TypedCollections, - ConfigFlags = ConfigFlags) + EGAM9SlimmingHelper = SlimmingHelper( + "EGAM9SlimmingHelper", + NamesAndTypes=ConfigFlags.Input.TypedCollections, + ConfigFlags=ConfigFlags, + ) # ------------------------------------------ # containers for which we save all variables # ------------------------------------------- # baseline - EGAM9SlimmingHelper.AllVariables =[ - 'Electrons', - 'Photons', - 'GSFTrackParticles', - 'egammaClusters' ] + EGAM9SlimmingHelper.AllVariables = [ + "Electrons", + "Photons", + "GSFTrackParticles", + "egammaClusters", + ] - # for trigger studies we also add: + # for trigger studies we also add: MenuType = None if ConfigFlags.Trigger.EDMVersion == 2: - MenuType = 'Run2' + MenuType = "Run2" elif ConfigFlags.Trigger.EDMVersion == 3: - MenuType = 'Run3' + MenuType = "Run3" else: - MenuType = '' + MenuType = "" EGAM9SlimmingHelper.AllVariables += ExtraContainersTrigger[MenuType] EGAM9SlimmingHelper.AllVariables += ExtraContainersPhotonTrigger[MenuType] if not ConfigFlags.Input.isMC: @@ -313,88 +360,92 @@ def EGAM9Cfg(ConfigFlags): # and on MC we also add: if ConfigFlags.Input.isMC: EGAM9SlimmingHelper.AllVariables += [ - 'TruthEvents', - 'TruthParticles', - 'TruthVertices', - 'egammaTruthParticles' + "TruthEvents", + "TruthParticles", + "TruthVertices", + "egammaTruthParticles", ] - - # ------------------------------------------- # containers that we slim # ------------------------------------------- # first add variables from smart-slimming # adding only also those for which we add all variables since - # the XXXCPContent.py files also bring in some extra variables + # the XXXCPContent.py files also bring in some extra variables # for other collections - EGAM9SlimmingHelper.SmartCollections = ['Electrons', - 'Photons', - 'InDetTrackParticles', - 'PrimaryVertices', + EGAM9SlimmingHelper.SmartCollections = [ + "Electrons", + "Photons", + "InDetTrackParticles", + "PrimaryVertices", ] if saveJets: - EGAM9SlimmingHelper.SmartCollections += ['AntiKt4EMPFlowJets'] + EGAM9SlimmingHelper.SmartCollections += ["AntiKt4EMPFlowJets"] if ConfigFlags.Input.isMC: - EGAM9SlimmingHelper.SmartCollections += ['AntiKt4TruthJets', - 'AntiKt4TruthDressedWZJets'] + EGAM9SlimmingHelper.SmartCollections += [ + "AntiKt4TruthJets", + "AntiKt4TruthDressedWZJets", + ] # then add extra variables: # photons - EGAM9SlimmingHelper.ExtraVariables += [ - 'Photons.DFCommonLoosePrime5' ] + EGAM9SlimmingHelper.ExtraVariables += ["Photons.DFCommonLoosePrime5"] # conversion vertices EGAM9SlimmingHelper.ExtraVariables += [ - 'GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo', - 'GSFConversionVertices.trackParticleLinks' ] + "GSFConversionVertices.x.y.z.px.py.pz.pt1.pt2.etaAtCalo.phiAtCalo", + "GSFConversionVertices.trackParticleLinks", + ] # primary vertices - EGAM9SlimmingHelper.ExtraVariables += [ - 'PrimaryVertices.x.y.sumPt2' ] + EGAM9SlimmingHelper.ExtraVariables += ["PrimaryVertices.x.y.sumPt2"] # track jets if saveJets: EGAM9SlimmingHelper.ExtraVariables += [ - 'AntiKt4PV0TrackJets.pt.eta.phi.e.m.btaggingLink.constituentLinks' ] - + "AntiKt4PV0TrackJets.pt.eta.phi.e.m.btaggingLink.constituentLinks" + ] # photons and electrons: detailed shower shape variables and track variables EGAM9SlimmingHelper.ExtraVariables += PhotonsCPDetailedContent EGAM9SlimmingHelper.ExtraVariables += ElectronsCPDetailedContent EGAM9SlimmingHelper.ExtraVariables += GSFTracksCPDetailedContent - + # photons: gain and cluster energy per layer from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import ( - getGainDecorations, getClusterEnergyPerLayerDecorations ) - gainDecorations = getGainDecorations(acc, 'EGAM9Kernel') - print('EGAM9 gain decorations: ', gainDecorations) + getGainDecorations, + getClusterEnergyPerLayerDecorations, + ) + + gainDecorations = getGainDecorations(acc, "EGAM9Kernel") + print("EGAM9 gain decorations: ", gainDecorations) EGAM9SlimmingHelper.ExtraVariables.extend(gainDecorations) - clusterEnergyDecorations = getClusterEnergyPerLayerDecorations( - acc, 'EGAM9Kernel' ) - print('EGAM9 cluster energy decorations: ', clusterEnergyDecorations) + clusterEnergyDecorations = getClusterEnergyPerLayerDecorations(acc, "EGAM9Kernel") + print("EGAM9 cluster energy decorations: ", clusterEnergyDecorations) EGAM9SlimmingHelper.ExtraVariables.extend(clusterEnergyDecorations) # energy density - EGAM9SlimmingHelper.ExtraVariables += [ - 'TopoClusterIsoCentralEventShape.Density', - 'TopoClusterIsoForwardEventShape.Density', - 'NeutralParticleFlowIsoCentralEventShape.Density', - 'NeutralParticleFlowIsoForwardEventShape.Density'] + EGAM9SlimmingHelper.ExtraVariables += [ + "TopoClusterIsoCentralEventShape.Density", + "TopoClusterIsoForwardEventShape.Density", + "NeutralParticleFlowIsoCentralEventShape.Density", + "NeutralParticleFlowIsoForwardEventShape.Density", + ] # truth if ConfigFlags.Input.isMC: EGAM9SlimmingHelper.ExtraVariables += [ - 'Photons.truthOrigin.truthType.truthParticleLink' ] + "Photons.truthOrigin.truthType.truthParticleLink" + ] # Add event info if ConfigFlags.Derivation.Egamma.doEventInfoSlimming: - EGAM9SlimmingHelper.SmartCollections.append('EventInfo') + EGAM9SlimmingHelper.SmartCollections.append("EventInfo") else: - EGAM9SlimmingHelper.AllVariables += ['EventInfo'] - + EGAM9SlimmingHelper.AllVariables += ["EventInfo"] + # Add egamma trigger objects EGAM9SlimmingHelper.IncludeEGammaTriggerContent = True @@ -402,46 +453,64 @@ def EGAM9Cfg(ConfigFlags): # Run 2 if ConfigFlags.Trigger.EDMVersion == 2: from DerivationFrameworkPhys.TriggerMatchingCommonConfig import ( - AddRun2TriggerMatchingToSlimmingHelper ) + AddRun2TriggerMatchingToSlimmingHelper, + ) + AddRun2TriggerMatchingToSlimmingHelper( - SlimmingHelper = EGAM9SlimmingHelper, - OutputContainerPrefix = 'TrigMatch_', - TriggerList = EGAM9TriggerListsHelper.Run2TriggerNamesNoTau) + SlimmingHelper=EGAM9SlimmingHelper, + OutputContainerPrefix="TrigMatch_", + TriggerList=EGAM9TriggerListsHelper.Run2TriggerNamesNoTau, + ) # Run 3 if ConfigFlags.Trigger.EDMVersion == 3: from TrigNavSlimmingMT.TrigNavSlimmingMTConfig import ( - AddRun3TrigNavSlimmingCollectionsToSlimmingHelper ) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper, + ) + AddRun3TrigNavSlimmingCollectionsToSlimmingHelper(EGAM9SlimmingHelper) # Run 2 is added here temporarily to allow testing/comparison/debugging from DerivationFrameworkPhys.TriggerMatchingCommonConfig import ( - AddRun2TriggerMatchingToSlimmingHelper ) + AddRun2TriggerMatchingToSlimmingHelper, + ) + AddRun2TriggerMatchingToSlimmingHelper( - SlimmingHelper = EGAM9SlimmingHelper, - OutputContainerPrefix = 'TrigMatch_', - TriggerList = EGAM9TriggerListsHelper.Run3TriggerNamesNoTau) + SlimmingHelper=EGAM9SlimmingHelper, + OutputContainerPrefix="TrigMatch_", + TriggerList=EGAM9TriggerListsHelper.Run3TriggerNamesNoTau, + ) # Add CellContainer and cluster->cell links if keepCells: if thinCells: EGAM9SlimmingHelper.StaticContent = [ - 'CaloCellContainer#DFEGAMCellContainer', - 'CaloClusterCellLinkContainer#egammaClusters_links'] + "CaloCellContainer#DFEGAMCellContainer", + "CaloClusterCellLinkContainer#egammaClusters_links", + ] else: EGAM9SlimmingHelper.StaticContent = [ - 'CaloCellContainer#AllCalo', - 'CaloClusterCellLinkContainer#egammaClusters_links'] + "CaloCellContainer#AllCalo", + "CaloClusterCellLinkContainer#egammaClusters_links", + ] EGAM9ItemList = EGAM9SlimmingHelper.GetItemList() - acc.merge(OutputStreamCfg(ConfigFlags, - 'DAOD_EGAM9', - ItemList = EGAM9ItemList, - AcceptAlgs = ['EGAM9Kernel'])) - acc.merge(SetupMetaDataForStreamCfg(ConfigFlags, 'DAOD_EGAM9', - AcceptAlgs=['EGAM9Kernel'], - createMetadata=[ - MetadataCategory.CutFlowMetaData, - MetadataCategory.TruthMetaData, - ])) + acc.merge( + OutputStreamCfg( + ConfigFlags, + "DAOD_EGAM9", + ItemList=EGAM9ItemList, + AcceptAlgs=["EGAM9Kernel"], + ) + ) + acc.merge( + SetupMetaDataForStreamCfg( + ConfigFlags, + "DAOD_EGAM9", + AcceptAlgs=["EGAM9Kernel"], + createMetadata=[ + MetadataCategory.CutFlowMetaData, + MetadataCategory.TruthMetaData, + ], + ) + ) return acc - diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaCommonConfig.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaCommonConfig.py index 19b78ac9e9a8..3e69704d29df 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaCommonConfig.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaCommonConfig.py @@ -3,33 +3,35 @@ # ******************************************************************** # EGammaCommonConfig.py # Configures all tools needed for e-gamma object selection and sets -# up the kernel algorithms so the results can be accessed/written to -# the DAODs. +# up the kernel algorithms so the results can be accessed/written to +# the DAODs. # Component accumulator version. # ******************************************************************** from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory + def EGammaCommonCfg(ConfigFlags): """Main config method for e-gamma decorations""" acc = ComponentAccumulator() - includeFwdElectrons = 'ForwardElectrons' in ConfigFlags.Input.Collections - + includeFwdElectrons = "ForwardElectrons" in ConfigFlags.Input.Collections # ==================================================================== # PHOTON ETA (=ETA2), ET (=E/COSH(ETA2)) # ==================================================================== from DerivationFrameworkEGamma.EGammaToolsConfig import PhotonsDirectionToolCfg - - DFCommonPhotonsDirection = acc.getPrimaryAndMerge(PhotonsDirectionToolCfg( - ConfigFlags, - name="DFCommonPhotonsDirection", - EtaSGEntry="DFCommonPhotons_eta", - PhiSGEntry="DFCommonPhotons_phi", - EtSGEntry="DFCommonPhotons_et") + + DFCommonPhotonsDirection = acc.getPrimaryAndMerge( + PhotonsDirectionToolCfg( + ConfigFlags, + name="DFCommonPhotonsDirection", + EtaSGEntry="DFCommonPhotons_eta", + PhiSGEntry="DFCommonPhotons_phi", + EtSGEntry="DFCommonPhotons_et", + ) ) # ==================================================================== @@ -38,13 +40,13 @@ def EGammaCommonCfg(ConfigFlags): # ==================================================================== # TODO: following lines my not be needed depending on how we get the sim flavour - #from PyUtils import AthFile + # from PyUtils import AthFile # info from the ConfigFlags # opens the first file from the InputCollections list - #af = AthFile.fopen(ConfigFlags.Input) + # af = AthFile.fopen(ConfigFlags.Input) # this is a dict of dicts, take a look at what's available! # Below are some examples: - #af.fileinfos + # af.fileinfos isMC = ConfigFlags.Input.isMC isFullSim = False @@ -56,11 +58,20 @@ def EGammaCommonCfg(ConfigFlags): print("EGammaCommon: isFullSim = ", isFullSim) if isFullSim: - from EGammaVariableCorrection.EGammaVariableCorrectionConfig import ElectronPhotonVariableCorrectionToolCfg - EGVariableCorrectionTool = acc.popToolsAndMerge(ElectronPhotonVariableCorrectionToolCfg( - ConfigFlags, - name='EGVariableCorrectionTool', - ConfigFile='EGammaVariableCorrection/TUNE23/ElPhVariableNominalCorrection.conf')) + from EGammaVariableCorrection.EGammaVariableCorrectionConfig import ( + ElectronPhotonVariableCorrectionToolCfg, + ) + + configFile = ( + "EGammaVariableCorrection/TUNE23/ElPhVariableNominalCorrection.conf" + ) + EGVariableCorrectionTool = acc.popToolsAndMerge( + ElectronPhotonVariableCorrectionToolCfg( + ConfigFlags, + name="EGVariableCorrectionTool", + ConfigFile=configFile, + ) + ) acc.addPublicTool(EGVariableCorrectionTool) # ==================================================================== @@ -70,125 +81,166 @@ def EGammaCommonCfg(ConfigFlags): # ==================================================================== from ROOT import LikeEnum - from ElectronPhotonSelectorTools.AsgElectronLikelihoodToolsConfig import AsgElectronLikelihoodToolCfg + from ElectronPhotonSelectorTools.AsgElectronLikelihoodToolsConfig import ( + AsgElectronLikelihoodToolCfg, + ) from ElectronPhotonSelectorTools.ElectronLikelihoodToolMapping import electronLHmenu lhMenu = electronLHmenu.offlineMC21 from AthenaConfiguration.Enums import LHCPeriod + if ConfigFlags.GeoModel.Run is LHCPeriod.Run2: lhMenu = electronLHmenu.offlineMC20 # Very Loose - ElectronLHSelectorVeryLoose = acc.popToolsAndMerge(AsgElectronLikelihoodToolCfg( - ConfigFlags, - name="ElectronLHSelectorVeryLoose", - quality = LikeEnum.VeryLoose, - menu=lhMenu) + ElectronLHSelectorVeryLoose = acc.popToolsAndMerge( + AsgElectronLikelihoodToolCfg( + ConfigFlags, + name="ElectronLHSelectorVeryLoose", + quality=LikeEnum.VeryLoose, + menu=lhMenu, + ) ) ElectronLHSelectorVeryLoose.primaryVertexContainer = "PrimaryVertices" acc.addPublicTool(ElectronLHSelectorVeryLoose) # Loose - ElectronLHSelectorLoose = acc.popToolsAndMerge(AsgElectronLikelihoodToolCfg( - ConfigFlags, - name="ElectronLHSelectorLoose", - quality=LikeEnum.Loose, - menu=lhMenu) + ElectronLHSelectorLoose = acc.popToolsAndMerge( + AsgElectronLikelihoodToolCfg( + ConfigFlags, + name="ElectronLHSelectorLoose", + quality=LikeEnum.Loose, + menu=lhMenu, + ) ) ElectronLHSelectorLoose.primaryVertexContainer = "PrimaryVertices" acc.addPublicTool(ElectronLHSelectorLoose) # LooseBL - ElectronLHSelectorLooseBL = acc.popToolsAndMerge(AsgElectronLikelihoodToolCfg( - ConfigFlags, - name="ElectronLHSelectorLooseBL", - quality=LikeEnum.LooseBL, - menu=lhMenu) + ElectronLHSelectorLooseBL = acc.popToolsAndMerge( + AsgElectronLikelihoodToolCfg( + ConfigFlags, + name="ElectronLHSelectorLooseBL", + quality=LikeEnum.LooseBL, + menu=lhMenu, + ) ) ElectronLHSelectorLooseBL.primaryVertexContainer = "PrimaryVertices" acc.addPublicTool(ElectronLHSelectorLooseBL) # Medium - ElectronLHSelectorMedium = acc.popToolsAndMerge(AsgElectronLikelihoodToolCfg( - ConfigFlags, - name="ElectronLHSelectorMedium", - quality=LikeEnum.Medium, - menu=lhMenu) + ElectronLHSelectorMedium = acc.popToolsAndMerge( + AsgElectronLikelihoodToolCfg( + ConfigFlags, + name="ElectronLHSelectorMedium", + quality=LikeEnum.Medium, + menu=lhMenu, + ) ) ElectronLHSelectorMedium.primaryVertexContainer = "PrimaryVertices" acc.addPublicTool(ElectronLHSelectorMedium) # Tight - ElectronLHSelectorTight = acc.popToolsAndMerge(AsgElectronLikelihoodToolCfg( - ConfigFlags, - name="ElectronLHSelectorTight", - quality=LikeEnum.Tight, - menu=lhMenu) + ElectronLHSelectorTight = acc.popToolsAndMerge( + AsgElectronLikelihoodToolCfg( + ConfigFlags, + name="ElectronLHSelectorTight", + quality=LikeEnum.Tight, + menu=lhMenu, + ) ) ElectronLHSelectorTight.primaryVertexContainer = "PrimaryVertices" acc.addPublicTool(ElectronLHSelectorTight) - # ==================================================================== # ELECTRON DNN SELECTORS # ==================================================================== - from ElectronPhotonSelectorTools.AsgElectronSelectorToolConfig import AsgElectronSelectorToolCfg + from ElectronPhotonSelectorTools.AsgElectronSelectorToolConfig import ( + AsgElectronSelectorToolCfg, + ) + # Loose - ElectronDNNSelectorLoose = acc.popToolsAndMerge(AsgElectronSelectorToolCfg( - ConfigFlags, - name="ElectronDNNSelectorLoose", - WorkingPoint="LooseDNNElectron")) + ElectronDNNSelectorLoose = acc.popToolsAndMerge( + AsgElectronSelectorToolCfg( + ConfigFlags, + name="ElectronDNNSelectorLoose", + WorkingPoint="LooseDNNElectron", + ) + ) acc.addPublicTool(ElectronDNNSelectorLoose) # Medium - ElectronDNNSelectorMedium = acc.popToolsAndMerge(AsgElectronSelectorToolCfg( - ConfigFlags, - name="ElectronDNNSelectorMedium", - WorkingPoint="MediumDNNElectron")) + ElectronDNNSelectorMedium = acc.popToolsAndMerge( + AsgElectronSelectorToolCfg( + ConfigFlags, + name="ElectronDNNSelectorMedium", + WorkingPoint="MediumDNNElectron", + ) + ) acc.addPublicTool(ElectronDNNSelectorMedium) # Tight - ElectronDNNSelectorTight = acc.popToolsAndMerge(AsgElectronSelectorToolCfg( - ConfigFlags, - name="ElectronDNNSelectorTight", - WorkingPoint="TightDNNElectron")) + ElectronDNNSelectorTight = acc.popToolsAndMerge( + AsgElectronSelectorToolCfg( + ConfigFlags, + name="ElectronDNNSelectorTight", + WorkingPoint="TightDNNElectron", + ) + ) acc.addPublicTool(ElectronDNNSelectorTight) # ==================================================================== # ELECTRON CHARGE SELECTION # ==================================================================== if ConfigFlags.Derivation.Egamma.addECIDS: - from ElectronPhotonSelectorTools.AsgElectronChargeIDSelectorToolConfig import AsgElectronChargeIDSelectorToolCfg - ElectronChargeIDSelector = acc.popToolsAndMerge(AsgElectronChargeIDSelectorToolCfg( - ConfigFlags, - name="ElectronChargeIDSelectorLoose")) + from ElectronPhotonSelectorTools.AsgElectronChargeIDSelectorToolConfig import ( + AsgElectronChargeIDSelectorToolCfg, + ) + + ElectronChargeIDSelector = acc.popToolsAndMerge( + AsgElectronChargeIDSelectorToolCfg( + ConfigFlags, name="ElectronChargeIDSelectorLoose" + ) + ) ElectronChargeIDSelector.primaryVertexContainer = "PrimaryVertices" - ElectronChargeIDSelector.TrainingFile = "ElectronPhotonSelectorTools/ChargeID/ECIDS_20180731rel21Summer2018.root" + ElectronChargeIDSelector.TrainingFile = ( + "ElectronPhotonSelectorTools/ChargeID/ECIDS_20180731rel21Summer2018.root" + ) acc.addPublicTool(ElectronChargeIDSelector) # ==================================================================== # FWD ELECTRON LH SELECTORS # ==================================================================== if includeFwdElectrons: + from ElectronPhotonSelectorTools.AsgForwardElectronLikelihoodToolConfig import ( + AsgForwardElectronLikelihoodToolCfg, + ) - from ElectronPhotonSelectorTools.AsgForwardElectronLikelihoodToolConfig import AsgForwardElectronLikelihoodToolCfg - - ForwardElectronLHSelectorLoose = acc.popToolsAndMerge(AsgForwardElectronLikelihoodToolCfg( - ConfigFlags, - name="ForwardElectronLHSelectorLoose", - WorkingPoint="LooseLHForwardElectron")) + ForwardElectronLHSelectorLoose = acc.popToolsAndMerge( + AsgForwardElectronLikelihoodToolCfg( + ConfigFlags, + name="ForwardElectronLHSelectorLoose", + WorkingPoint="LooseLHForwardElectron", + ) + ) acc.addPublicTool(ForwardElectronLHSelectorLoose) - ForwardElectronLHSelectorMedium = acc.popToolsAndMerge(AsgForwardElectronLikelihoodToolCfg( - ConfigFlags, - name="ForwardElectronLHSelectorMedium", - WorkingPoint="MediumLHForwardElectron")) + ForwardElectronLHSelectorMedium = acc.popToolsAndMerge( + AsgForwardElectronLikelihoodToolCfg( + ConfigFlags, + name="ForwardElectronLHSelectorMedium", + WorkingPoint="MediumLHForwardElectron", + ) + ) acc.addPublicTool(ForwardElectronLHSelectorMedium) - ForwardElectronLHSelectorTight = acc.popToolsAndMerge(AsgForwardElectronLikelihoodToolCfg( - ConfigFlags, - name="ForwardElectronLHSelectorTight", - WorkingPoint="TightLHForwardElectron")) + ForwardElectronLHSelectorTight = acc.popToolsAndMerge( + AsgForwardElectronLikelihoodToolCfg( + ConfigFlags, + name="ForwardElectronLHSelectorTight", + WorkingPoint="TightLHForwardElectron", + ) + ) acc.addPublicTool(ForwardElectronLHSelectorTight) # ==================================================================== @@ -196,30 +248,37 @@ def EGammaCommonCfg(ConfigFlags): # ==================================================================== from ROOT import egammaPID - from ElectronPhotonSelectorTools.AsgPhotonIsEMSelectorsConfig import AsgPhotonIsEMSelectorCfg + from ElectronPhotonSelectorTools.AsgPhotonIsEMSelectorsConfig import ( + AsgPhotonIsEMSelectorCfg, + ) from ElectronPhotonSelectorTools.PhotonIsEMSelectorMapping import photonPIDmenu # Loose - PhotonIsEMSelectorLoose = acc.popToolsAndMerge(AsgPhotonIsEMSelectorCfg( - ConfigFlags, - name="PhotonIsEMSelectorLoose", - quality=egammaPID.PhotonIDLoose)) + PhotonIsEMSelectorLoose = acc.popToolsAndMerge( + AsgPhotonIsEMSelectorCfg( + ConfigFlags, name="PhotonIsEMSelectorLoose", quality=egammaPID.PhotonIDLoose + ) + ) acc.addPublicTool(PhotonIsEMSelectorLoose) # Tight (default == pt-dependent) - PhotonIsEMSelectorTight = acc.popToolsAndMerge(AsgPhotonIsEMSelectorCfg( - ConfigFlags, - name="PhotonIsEMSelectorTight", - quality=egammaPID.PhotonIDTight)) + PhotonIsEMSelectorTight = acc.popToolsAndMerge( + AsgPhotonIsEMSelectorCfg( + ConfigFlags, name="PhotonIsEMSelectorTight", quality=egammaPID.PhotonIDTight + ) + ) acc.addPublicTool(PhotonIsEMSelectorTight) # Tight (pt-inclusive) # To be removed when pt-dependent menu above is supported with scale factors - PhotonIsEMSelectorTightPtIncl = acc.popToolsAndMerge(AsgPhotonIsEMSelectorCfg( - ConfigFlags, - name="PhotonIsEMSelectorTightPtIncl", - quality=egammaPID.PhotonIDTight, - menu=photonPIDmenu.menuPtInclJan2018)) + PhotonIsEMSelectorTightPtIncl = acc.popToolsAndMerge( + AsgPhotonIsEMSelectorCfg( + ConfigFlags, + name="PhotonIsEMSelectorTightPtIncl", + quality=egammaPID.PhotonIDTight, + menu=photonPIDmenu.menuPtInclJan2018, + ) + ) acc.addPublicTool(PhotonIsEMSelectorTightPtIncl) # ==================================================================== @@ -228,154 +287,197 @@ def EGammaCommonCfg(ConfigFlags): from egammaCaloTools.egammaCaloToolsConfig import CaloFillRectangularClusterCfg - EGAMCOM_caloFillRect55 = acc.popToolsAndMerge(CaloFillRectangularClusterCfg( - ConfigFlags, - name="EGAMCOMCaloFillRectangularCluster55", - cells_name="AllCalo", - eta_size=5, - phi_size=5, - fill_cluster=True)) + EGAMCOM_caloFillRect55 = acc.popToolsAndMerge( + CaloFillRectangularClusterCfg( + ConfigFlags, + name="EGAMCOMCaloFillRectangularCluster55", + cells_name="AllCalo", + eta_size=5, + phi_size=5, + fill_cluster=True, + ) + ) acc.addPublicTool(EGAMCOM_caloFillRect55) - EGAMCOM_caloFillRect35 = acc.popToolsAndMerge(CaloFillRectangularClusterCfg( - ConfigFlags, - name="EGAMCOMCaloFillRectangularCluster35", - cells_name="AllCalo", - eta_size=3, - phi_size=5, - fill_cluster=True)) + EGAMCOM_caloFillRect35 = acc.popToolsAndMerge( + CaloFillRectangularClusterCfg( + ConfigFlags, + name="EGAMCOMCaloFillRectangularCluster35", + cells_name="AllCalo", + eta_size=3, + phi_size=5, + fill_cluster=True, + ) + ) acc.addPublicTool(EGAMCOM_caloFillRect35) - EGAMCOM_caloFillRect37 = acc.popToolsAndMerge(CaloFillRectangularClusterCfg( - ConfigFlags, - name="EGAMCOMCaloFillRectangularCluster37", - cells_name="AllCalo", - eta_size=3, - phi_size=7, - fill_cluster=True)) + EGAMCOM_caloFillRect37 = acc.popToolsAndMerge( + CaloFillRectangularClusterCfg( + ConfigFlags, + name="EGAMCOMCaloFillRectangularCluster37", + cells_name="AllCalo", + eta_size=3, + phi_size=7, + fill_cluster=True, + ) + ) acc.addPublicTool(EGAMCOM_caloFillRect37) - EGAMCOM_caloFillRect711 = acc.popToolsAndMerge(CaloFillRectangularClusterCfg( - ConfigFlags, - name="EGAMCOMCaloFillRectangularCluster711", - cells_name="AllCalo", - eta_size=7, - phi_size=11, - fill_cluster=True)) + EGAMCOM_caloFillRect711 = acc.popToolsAndMerge( + CaloFillRectangularClusterCfg( + ConfigFlags, + name="EGAMCOMCaloFillRectangularCluster711", + cells_name="AllCalo", + eta_size=7, + phi_size=11, + fill_cluster=True, + ) + ) acc.addPublicTool(EGAMCOM_caloFillRect711) # ==================================================================== # AUGMENTATION TOOLS # ==================================================================== from DerivationFrameworkEGamma.EGammaToolsConfig import EGSelectionToolWrapperCfg - from DerivationFrameworkEGamma.EGammaToolsConfig import EGElectronLikelihoodToolWrapperCfg + from DerivationFrameworkEGamma.EGammaToolsConfig import ( + EGElectronLikelihoodToolWrapperCfg, + ) # decorate electrons with the output of LH very loose - ElectronPassLHVeryLoose = acc.getPrimaryAndMerge(EGElectronLikelihoodToolWrapperCfg( - ConfigFlags, - name="ElectronPassLHVeryLoose", - EGammaElectronLikelihoodTool=ElectronLHSelectorVeryLoose, - EGammaFudgeMCTool="", - CutType="", - StoreGateEntryName="DFCommonElectronsLHVeryLoose", - ContainerName="Electrons", - StoreTResult=False)) + ElectronPassLHVeryLoose = acc.getPrimaryAndMerge( + EGElectronLikelihoodToolWrapperCfg( + ConfigFlags, + name="ElectronPassLHVeryLoose", + EGammaElectronLikelihoodTool=ElectronLHSelectorVeryLoose, + EGammaFudgeMCTool="", + CutType="", + StoreGateEntryName="DFCommonElectronsLHVeryLoose", + ContainerName="Electrons", + StoreTResult=False, + ) + ) # decorate electrons with the output of LH loose - ElectronPassLHLoose = acc.getPrimaryAndMerge(EGElectronLikelihoodToolWrapperCfg( - ConfigFlags, - name="ElectronPassLHLoose", - EGammaElectronLikelihoodTool=ElectronLHSelectorLoose, - EGammaFudgeMCTool="", - CutType="", - StoreGateEntryName="DFCommonElectronsLHLoose", - ContainerName="Electrons", - StoreTResult=False)) + ElectronPassLHLoose = acc.getPrimaryAndMerge( + EGElectronLikelihoodToolWrapperCfg( + ConfigFlags, + name="ElectronPassLHLoose", + EGammaElectronLikelihoodTool=ElectronLHSelectorLoose, + EGammaFudgeMCTool="", + CutType="", + StoreGateEntryName="DFCommonElectronsLHLoose", + ContainerName="Electrons", + StoreTResult=False, + ) + ) # decorate electrons with the output of LH loose+BL - ElectronPassLHLooseBL = acc.getPrimaryAndMerge(EGElectronLikelihoodToolWrapperCfg( - ConfigFlags, - name="ElectronPassLHLooseBL", - EGammaElectronLikelihoodTool=ElectronLHSelectorLooseBL, - EGammaFudgeMCTool="", - CutType="", - StoreGateEntryName="DFCommonElectronsLHLooseBL", - ContainerName="Electrons", - StoreTResult=False)) + ElectronPassLHLooseBL = acc.getPrimaryAndMerge( + EGElectronLikelihoodToolWrapperCfg( + ConfigFlags, + name="ElectronPassLHLooseBL", + EGammaElectronLikelihoodTool=ElectronLHSelectorLooseBL, + EGammaFudgeMCTool="", + CutType="", + StoreGateEntryName="DFCommonElectronsLHLooseBL", + ContainerName="Electrons", + StoreTResult=False, + ) + ) # decorate electrons with the output of LH medium - ElectronPassLHMedium = acc.getPrimaryAndMerge(EGElectronLikelihoodToolWrapperCfg( - ConfigFlags, - name="ElectronPassLHMedium", - EGammaElectronLikelihoodTool=ElectronLHSelectorMedium, - EGammaFudgeMCTool="", - CutType="", - StoreGateEntryName="DFCommonElectronsLHMedium", - ContainerName="Electrons", - StoreTResult=False)) + ElectronPassLHMedium = acc.getPrimaryAndMerge( + EGElectronLikelihoodToolWrapperCfg( + ConfigFlags, + name="ElectronPassLHMedium", + EGammaElectronLikelihoodTool=ElectronLHSelectorMedium, + EGammaFudgeMCTool="", + CutType="", + StoreGateEntryName="DFCommonElectronsLHMedium", + ContainerName="Electrons", + StoreTResult=False, + ) + ) # decorate electrons with the output of LH tight - ElectronPassLHTight = acc.getPrimaryAndMerge(EGElectronLikelihoodToolWrapperCfg( - ConfigFlags, - name="ElectronPassLHTight", - EGammaElectronLikelihoodTool=ElectronLHSelectorTight, - EGammaFudgeMCTool="", - CutType="", - StoreGateEntryName="DFCommonElectronsLHTight", - ContainerName="Electrons", - StoreTResult=False)) + ElectronPassLHTight = acc.getPrimaryAndMerge( + EGElectronLikelihoodToolWrapperCfg( + ConfigFlags, + name="ElectronPassLHTight", + EGammaElectronLikelihoodTool=ElectronLHSelectorTight, + EGammaFudgeMCTool="", + CutType="", + StoreGateEntryName="DFCommonElectronsLHTight", + ContainerName="Electrons", + StoreTResult=False, + ) + ) # decorate electrons with the output of DNN Loose - ElectronPassDNNLoose = acc.getPrimaryAndMerge(EGElectronLikelihoodToolWrapperCfg( - ConfigFlags, - name = "ElectronPassDNNLoose", - EGammaElectronLikelihoodTool = ElectronDNNSelectorLoose, - EGammaFudgeMCTool = "", - CutType = "", - StoreGateEntryName = "DFCommonElectronsDNNLoose", - ContainerName = "Electrons", - StoreTResult = False, - StoreGateEntryMultipleNames=["DFCommonElectronsDNN_pel", - "DFCommonElectronsDNN_pcf", - "DFCommonElectronsDNN_ppc", - "DFCommonElectronsDNN_phf", - "DFCommonElectronsDNN_ple", - "DFCommonElectronsDNN_plh"], - StoreMultipleOutputs = True)) + ElectronPassDNNLoose = acc.getPrimaryAndMerge( + EGElectronLikelihoodToolWrapperCfg( + ConfigFlags, + name="ElectronPassDNNLoose", + EGammaElectronLikelihoodTool=ElectronDNNSelectorLoose, + EGammaFudgeMCTool="", + CutType="", + StoreGateEntryName="DFCommonElectronsDNNLoose", + ContainerName="Electrons", + StoreTResult=False, + StoreGateEntryMultipleNames=[ + "DFCommonElectronsDNN_pel", + "DFCommonElectronsDNN_pcf", + "DFCommonElectronsDNN_ppc", + "DFCommonElectronsDNN_phf", + "DFCommonElectronsDNN_ple", + "DFCommonElectronsDNN_plh", + ], + StoreMultipleOutputs=True, + ) + ) # decorate electrons with the output of DNN Medium - ElectronPassDNNMedium = acc.getPrimaryAndMerge(EGElectronLikelihoodToolWrapperCfg( - ConfigFlags, - name = "ElectronPassDNNMedium", - EGammaElectronLikelihoodTool = ElectronDNNSelectorMedium, - EGammaFudgeMCTool = "", - CutType = "", - StoreGateEntryName = "DFCommonElectronsDNNMedium", - ContainerName = "Electrons", - StoreTResult = False)) + ElectronPassDNNMedium = acc.getPrimaryAndMerge( + EGElectronLikelihoodToolWrapperCfg( + ConfigFlags, + name="ElectronPassDNNMedium", + EGammaElectronLikelihoodTool=ElectronDNNSelectorMedium, + EGammaFudgeMCTool="", + CutType="", + StoreGateEntryName="DFCommonElectronsDNNMedium", + ContainerName="Electrons", + StoreTResult=False, + ) + ) # decorate electrons with the output of DNN Tight - ElectronPassDNNTight = acc.getPrimaryAndMerge(EGElectronLikelihoodToolWrapperCfg( - ConfigFlags, - name = "ElectronPassDNNTight", - EGammaElectronLikelihoodTool = ElectronDNNSelectorTight, - EGammaFudgeMCTool = "", - CutType = "", - StoreGateEntryName = "DFCommonElectronsDNNTight", - ContainerName = "Electrons", - StoreTResult = False)) - - # decorate electrons with the output of ECIDS - if ConfigFlags.Derivation.Egamma.addECIDS: - ElectronPassECIDS = acc.getPrimaryAndMerge(EGElectronLikelihoodToolWrapperCfg( + ElectronPassDNNTight = acc.getPrimaryAndMerge( + EGElectronLikelihoodToolWrapperCfg( ConfigFlags, - name="ElectronPassECIDS", - EGammaElectronLikelihoodTool=ElectronChargeIDSelector, + name="ElectronPassDNNTight", + EGammaElectronLikelihoodTool=ElectronDNNSelectorTight, EGammaFudgeMCTool="", CutType="", - StoreGateEntryName="DFCommonElectronsECIDS", + StoreGateEntryName="DFCommonElectronsDNNTight", ContainerName="Electrons", - StoreTResult=True)) + StoreTResult=False, + ) + ) + + # decorate electrons with the output of ECIDS + if ConfigFlags.Derivation.Egamma.addECIDS: + ElectronPassECIDS = acc.getPrimaryAndMerge( + EGElectronLikelihoodToolWrapperCfg( + ConfigFlags, + name="ElectronPassECIDS", + EGammaElectronLikelihoodTool=ElectronChargeIDSelector, + EGammaFudgeMCTool="", + CutType="", + StoreGateEntryName="DFCommonElectronsECIDS", + ContainerName="Electrons", + StoreTResult=True, + ) + ) if includeFwdElectrons: # decorate forward electrons with the output of LH loose @@ -387,7 +489,9 @@ def EGammaCommonCfg(ConfigFlags): EGammaFudgeMCTool="", CutType="", StoreGateEntryName="DFCommonForwardElectronsLHLoose", - ContainerName="ForwardElectrons")) + ContainerName="ForwardElectrons", + ) + ) # decorate forward electrons with the output of LH medium ForwardElectronPassLHMedium = acc.getPrimaryAndMerge( @@ -398,7 +502,9 @@ def EGammaCommonCfg(ConfigFlags): EGammaFudgeMCTool="", CutType="", StoreGateEntryName="DFCommonForwardElectronsLHMedium", - ContainerName="ForwardElectrons")) + ContainerName="ForwardElectrons", + ) + ) # decorate forward electrons with the output of LH tight ForwardElectronPassLHTight = acc.getPrimaryAndMerge( @@ -409,236 +515,307 @@ def EGammaCommonCfg(ConfigFlags): EGammaFudgeMCTool="", CutType="", StoreGateEntryName="DFCommonForwardElectronsLHTight", - ContainerName="ForwardElectrons")) + ContainerName="ForwardElectrons", + ) + ) # decorate photons with the output of IsEM loose # on MC, fudge the shower shapes before computing the ID (but the # original shower shapes are not overridden) if isFullSim: - PhotonPassIsEMLoose = acc.getPrimaryAndMerge(EGSelectionToolWrapperCfg( - ConfigFlags, - name="PhotonPassIsEMLoose", - EGammaSelectionTool=PhotonIsEMSelectorLoose, - EGammaFudgeMCTool=EGVariableCorrectionTool, - CutType="", - StoreGateEntryName="DFCommonPhotonsIsEMLoose", - ContainerName="Photons")) + PhotonPassIsEMLoose = acc.getPrimaryAndMerge( + EGSelectionToolWrapperCfg( + ConfigFlags, + name="PhotonPassIsEMLoose", + EGammaSelectionTool=PhotonIsEMSelectorLoose, + EGammaFudgeMCTool=EGVariableCorrectionTool, + CutType="", + StoreGateEntryName="DFCommonPhotonsIsEMLoose", + ContainerName="Photons", + ) + ) else: - PhotonPassIsEMLoose = acc.getPrimaryAndMerge(EGSelectionToolWrapperCfg( - ConfigFlags, - name="PhotonPassIsEMLoose", - EGammaSelectionTool=PhotonIsEMSelectorLoose, - EGammaFudgeMCTool=None, - CutType="", - StoreGateEntryName="DFCommonPhotonsIsEMLoose", - ContainerName="Photons")) + PhotonPassIsEMLoose = acc.getPrimaryAndMerge( + EGSelectionToolWrapperCfg( + ConfigFlags, + name="PhotonPassIsEMLoose", + EGammaSelectionTool=PhotonIsEMSelectorLoose, + EGammaFudgeMCTool=None, + CutType="", + StoreGateEntryName="DFCommonPhotonsIsEMLoose", + ContainerName="Photons", + ) + ) # decorate photons with the output of IsEM tight # on full-sim MC, fudge the shower shapes before computing the ID # (but the original shower shapes are not overridden) if isFullSim: - PhotonPassIsEMTight = acc.getPrimaryAndMerge(EGSelectionToolWrapperCfg( - ConfigFlags, - name="PhotonPassIsEMTight", - EGammaSelectionTool=PhotonIsEMSelectorTight, - EGammaFudgeMCTool=EGVariableCorrectionTool, - CutType="", - StoreGateEntryName="DFCommonPhotonsIsEMTight", - ContainerName="Photons")) + PhotonPassIsEMTight = acc.getPrimaryAndMerge( + EGSelectionToolWrapperCfg( + ConfigFlags, + name="PhotonPassIsEMTight", + EGammaSelectionTool=PhotonIsEMSelectorTight, + EGammaFudgeMCTool=EGVariableCorrectionTool, + CutType="", + StoreGateEntryName="DFCommonPhotonsIsEMTight", + ContainerName="Photons", + ) + ) else: - PhotonPassIsEMTight = acc.getPrimaryAndMerge(EGSelectionToolWrapperCfg( - ConfigFlags, - name="PhotonPassIsEMTight", - EGammaSelectionTool=PhotonIsEMSelectorTight, - EGammaFudgeMCTool=None, - CutType="", - StoreGateEntryName="DFCommonPhotonsIsEMTight", - ContainerName="Photons")) + PhotonPassIsEMTight = acc.getPrimaryAndMerge( + EGSelectionToolWrapperCfg( + ConfigFlags, + name="PhotonPassIsEMTight", + EGammaSelectionTool=PhotonIsEMSelectorTight, + EGammaFudgeMCTool=None, + CutType="", + StoreGateEntryName="DFCommonPhotonsIsEMTight", + ContainerName="Photons", + ) + ) # decorate photons with the output of IsEM tight pt-inclusive menu # Can be removed once pt-dependent cuts are fully supported. # On full-sim MC, fudge the shower shapes before computing the ID # (but the original shower shapes are not overridden) - PhotonPassIsEMTightPtIncl = acc.getPrimaryAndMerge(EGSelectionToolWrapperCfg( - ConfigFlags, - name="PhotonPassIsEMTightPtIncl", - EGammaSelectionTool=PhotonIsEMSelectorTightPtIncl, - EGammaFudgeMCTool=( - EGVariableCorrectionTool if isFullSim else None), - CutType="", - StoreGateEntryName="DFCommonPhotonsIsEMTightPtIncl", - ContainerName="Photons")) + PhotonPassIsEMTightPtIncl = acc.getPrimaryAndMerge( + EGSelectionToolWrapperCfg( + ConfigFlags, + name="PhotonPassIsEMTightPtIncl", + EGammaSelectionTool=PhotonIsEMSelectorTightPtIncl, + EGammaFudgeMCTool=(EGVariableCorrectionTool if isFullSim else None), + CutType="", + StoreGateEntryName="DFCommonPhotonsIsEMTightPtIncl", + ContainerName="Photons", + ) + ) # decorate photons with the photon cleaning flags # on MC, fudge the shower shapes before computing the flags from DerivationFrameworkEGamma.EGammaToolsConfig import EGPhotonCleaningWrapperCfg + if isFullSim: - PhotonPassCleaning = acc.getPrimaryAndMerge(EGPhotonCleaningWrapperCfg( - ConfigFlags, - name="PhotonPassCleaning", - EGammaFudgeMCTool=EGVariableCorrectionTool, - StoreGateEntryName="DFCommonPhotonsCleaning", - ContainerName="Photons")) + PhotonPassCleaning = acc.getPrimaryAndMerge( + EGPhotonCleaningWrapperCfg( + ConfigFlags, + name="PhotonPassCleaning", + EGammaFudgeMCTool=EGVariableCorrectionTool, + StoreGateEntryName="DFCommonPhotonsCleaning", + ContainerName="Photons", + ) + ) else: - PhotonPassCleaning = acc.getPrimaryAndMerge(EGPhotonCleaningWrapperCfg( - ConfigFlags, - name="PhotonPassCleaning", - EGammaFudgeMCTool=None, - StoreGateEntryName="DFCommonPhotonsCleaning", - ContainerName="Photons")) + PhotonPassCleaning = acc.getPrimaryAndMerge( + EGPhotonCleaningWrapperCfg( + ConfigFlags, + name="PhotonPassCleaning", + EGammaFudgeMCTool=None, + StoreGateEntryName="DFCommonPhotonsCleaning", + ContainerName="Photons", + ) + ) # decorate central electrons and photons with a flag to tell if the # candidates are affected by the crack bug in mc16a and data 2015+2016 from DerivationFrameworkEGamma.EGammaToolsConfig import EGCrackVetoCleaningToolCfg - PhotonPassCrackVeto = acc.getPrimaryAndMerge(EGCrackVetoCleaningToolCfg( - ConfigFlags, - name="PhotonPassCrackVeto", - StoreGateEntryName="DFCommonCrackVetoCleaning", - ContainerName="Photons")) - ElectronPassCrackVeto = acc.getPrimaryAndMerge(EGCrackVetoCleaningToolCfg( - ConfigFlags, - name="ElectronPassCrackVeto", - StoreGateEntryName="DFCommonCrackVetoCleaning", - ContainerName="Electrons")) + + PhotonPassCrackVeto = acc.getPrimaryAndMerge( + EGCrackVetoCleaningToolCfg( + ConfigFlags, + name="PhotonPassCrackVeto", + StoreGateEntryName="DFCommonCrackVetoCleaning", + ContainerName="Photons", + ) + ) + ElectronPassCrackVeto = acc.getPrimaryAndMerge( + EGCrackVetoCleaningToolCfg( + ConfigFlags, + name="ElectronPassCrackVeto", + StoreGateEntryName="DFCommonCrackVetoCleaning", + ContainerName="Electrons", + ) + ) # decorate some electrons with an additional ambiguity flag # against internal and early material conversion from DerivationFrameworkEGamma.EGammaToolsConfig import EGElectronAmbiguityToolCfg - ElectronAmbiguity = acc.getPrimaryAndMerge(EGElectronAmbiguityToolCfg( - ConfigFlags, - name="ElectronAdditionnalAmbiguity", - isMC=ConfigFlags.Input.isMC)) + + ElectronAmbiguity = acc.getPrimaryAndMerge( + EGElectronAmbiguityToolCfg( + ConfigFlags, + name="ElectronAdditionnalAmbiguity", + isMC=ConfigFlags.Input.isMC, + ) + ) # list of all the decorators so far - EGAugmentationTools = [DFCommonPhotonsDirection, - ElectronPassLHVeryLoose, - ElectronPassLHLoose, - ElectronPassLHLooseBL, - ElectronPassLHMedium, - ElectronPassLHTight, - ElectronPassDNNLoose, - ElectronPassDNNMedium, - ElectronPassDNNTight, - PhotonPassIsEMLoose, - PhotonPassIsEMTight, - PhotonPassIsEMTightPtIncl, - PhotonPassCleaning, - PhotonPassCrackVeto, - ElectronPassCrackVeto, - ElectronAmbiguity] + EGAugmentationTools = [ + DFCommonPhotonsDirection, + ElectronPassLHVeryLoose, + ElectronPassLHLoose, + ElectronPassLHLooseBL, + ElectronPassLHMedium, + ElectronPassLHTight, + ElectronPassDNNLoose, + ElectronPassDNNMedium, + ElectronPassDNNTight, + PhotonPassIsEMLoose, + PhotonPassIsEMTight, + PhotonPassIsEMTightPtIncl, + PhotonPassCleaning, + PhotonPassCrackVeto, + ElectronPassCrackVeto, + ElectronAmbiguity, + ] if ConfigFlags.Derivation.Egamma.addECIDS: EGAugmentationTools.extend([ElectronPassECIDS]) if includeFwdElectrons: - EGAugmentationTools.extend([ - ForwardElectronPassLHLoose, - ForwardElectronPassLHMedium, - ForwardElectronPassLHTight, - ]) - + EGAugmentationTools.extend( + [ + ForwardElectronPassLHLoose, + ForwardElectronPassLHMedium, + ForwardElectronPassLHTight, + ] + ) # ================================================== # Truth Related tools if ConfigFlags.Input.isMC: - # Decorate Electron with bkg electron type/origin from MCTruthClassifier.MCTruthClassifierConfig import MCTruthClassifierCfg - BkgElectronMCTruthClassifier = acc.popToolsAndMerge(MCTruthClassifierCfg( - ConfigFlags, - name="BkgElectronMCTruthClassifier", - ParticleCaloExtensionTool = "")) + + BkgElectronMCTruthClassifier = acc.popToolsAndMerge( + MCTruthClassifierCfg( + ConfigFlags, + name="BkgElectronMCTruthClassifier", + ParticleCaloExtensionTool="", + ) + ) acc.addPublicTool(BkgElectronMCTruthClassifier) - from DerivationFrameworkEGamma.EGammaToolsConfig import BkgElectronClassificationCfg - BkgElectronClassificationTool = acc.getPrimaryAndMerge(BkgElectronClassificationCfg( - ConfigFlags, - name="BkgElectronClassificationTool", - MCTruthClassifierTool=BkgElectronMCTruthClassifier)) + from DerivationFrameworkEGamma.EGammaToolsConfig import ( + BkgElectronClassificationCfg, + ) + + BkgElectronClassificationTool = acc.getPrimaryAndMerge( + BkgElectronClassificationCfg( + ConfigFlags, + name="BkgElectronClassificationTool", + MCTruthClassifierTool=BkgElectronMCTruthClassifier, + ) + ) EGAugmentationTools.append(BkgElectronClassificationTool) # Decorate egammaTruthParticles with truth-particle-level etcone20,30,40 - from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import TruthIsolationToolCfg - TruthEgetIsolationTool = acc.getPrimaryAndMerge(TruthIsolationToolCfg( - ConfigFlags, - name="TruthEgetIsolationTool", - isoParticlesKey="egammaTruthParticles", - allParticlesKey="TruthParticles", - particleIDsToCalculate=[-11, 11, 22], - IsolationConeSizes=[0.2, 0.3, 0.4], - excludeIDsFromCone=[-16, -14, -13, -12, 12, 13, 14, 16], - IsolationVarNamePrefix='etcone', - ChargedParticlesOnly=False)) + from DerivationFrameworkMCTruth.TruthDerivationToolsConfig import ( + TruthIsolationToolCfg, + ) + + TruthEgetIsolationTool = acc.getPrimaryAndMerge( + TruthIsolationToolCfg( + ConfigFlags, + name="TruthEgetIsolationTool", + isoParticlesKey="egammaTruthParticles", + allParticlesKey="TruthParticles", + particleIDsToCalculate=[-11, 11, 22], + IsolationConeSizes=[0.2, 0.3, 0.4], + excludeIDsFromCone=[-16, -14, -13, -12, 12, 13, 14, 16], + IsolationVarNamePrefix="etcone", + ChargedParticlesOnly=False, + ) + ) EGAugmentationTools.append(TruthEgetIsolationTool) # Decorate egammaTruthParticles with truth-particle-level ptcone20,30,40 - TruthEgptIsolationTool = acc.getPrimaryAndMerge(TruthIsolationToolCfg( - ConfigFlags, - name="TruthEgptIsolationTool", - isoParticlesKey="egammaTruthParticles", - allParticlesKey="TruthParticles", - particleIDsToCalculate=[-11, 11, 22], - IsolationConeSizes=[0.2, 0.3, 0.4], - IsolationVarNamePrefix='ptcone', - ChargedParticlesOnly=True)) + TruthEgptIsolationTool = acc.getPrimaryAndMerge( + TruthIsolationToolCfg( + ConfigFlags, + name="TruthEgptIsolationTool", + isoParticlesKey="egammaTruthParticles", + allParticlesKey="TruthParticles", + particleIDsToCalculate=[-11, 11, 22], + IsolationConeSizes=[0.2, 0.3, 0.4], + IsolationVarNamePrefix="ptcone", + ChargedParticlesOnly=True, + ) + ) EGAugmentationTools.append(TruthEgptIsolationTool) # Compute the truth-particle-level energy density in the central eta region from EventShapeTools.EventDensityConfig import configEventDensityTool - from JetRecConfig.JetRecConfig import getInputAlgs,getConstitPJGAlg,reOrderAlgs + from JetRecConfig.JetRecConfig import ( + getInputAlgs, + getConstitPJGAlg, + reOrderAlgs, + ) from JetRecConfig.StandardJetConstits import stdConstitDic as cst # Schedule PseudoJetTruth constit_algs = getInputAlgs(cst.Truth, flags=ConfigFlags) - constit_algs, ca = reOrderAlgs( [a for a in constit_algs if a is not None]) + constit_algs, ca = reOrderAlgs([a for a in constit_algs if a is not None]) acc.merge(ca) for a in constit_algs: acc.addEventAlgo(a) constitPJAlg = getConstitPJGAlg(cst.Truth, suffix=None) acc.addEventAlgo(constitPJAlg) - tc = configEventDensityTool("EDTruthCentralTool", cst.Truth, - 0.5, - AbsRapidityMin=0.0, - AbsRapidityMax=1.5, - OutputContainer="TruthIsoCentralEventShape", - OutputLevel=3 - ) + tc = configEventDensityTool( + "EDTruthCentralTool", + cst.Truth, + 0.5, + AbsRapidityMin=0.0, + AbsRapidityMax=1.5, + OutputContainer="TruthIsoCentralEventShape", + OutputLevel=3, + ) acc.addPublicTool(tc) # Compute the truth-particle-level energy density in the forward eta region - tf = configEventDensityTool("EDTruthForwardTool", cst.Truth, - 0.5, - AbsRapidityMin=1.5, - AbsRapidityMax=3.0, - OutputContainer="TruthIsoForwardEventShape", - OutputLevel=3, - ) + tf = configEventDensityTool( + "EDTruthForwardTool", + cst.Truth, + 0.5, + AbsRapidityMin=1.5, + AbsRapidityMax=3.0, + OutputContainer="TruthIsoForwardEventShape", + OutputLevel=3, + ) acc.addPublicTool(tf) - acc.addEventAlgo(CompFactory.EventDensityAthAlg("EDTruthCentralAlg", EventDensityTool=tc)) - acc.addEventAlgo(CompFactory.EventDensityAthAlg("EDTruthForwardAlg", EventDensityTool=tf)) + acc.addEventAlgo( + CompFactory.EventDensityAthAlg("EDTruthCentralAlg", EventDensityTool=tc) + ) + acc.addEventAlgo( + CompFactory.EventDensityAthAlg("EDTruthForwardAlg", EventDensityTool=tf) + ) # ======================================= # CREATE THE DERIVATION KERNEL ALGORITHM # ======================================= - acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation( - "EGammaCommonKernel", - AugmentationTools=EGAugmentationTools - )) + acc.addEventAlgo( + CompFactory.DerivationFramework.CommonAugmentation( + "EGammaCommonKernel", AugmentationTools=EGAugmentationTools + ) + ) # ======================================= # ADD TOOLS : custom electron, photon and muon track isolation # ======================================= from IsolationAlgs.DerivationTrackIsoConfig import DerivationTrackIsoCfg - acc.merge(DerivationTrackIsoCfg(ConfigFlags, object_types = ('Electrons', 'Muons'))) - hasFlowObject = ('JetETMissChargedParticleFlowObjects' in ConfigFlags.Input.Collections and - 'JetETMissNeutralParticleFlowObjects' in ConfigFlags.Input.Collections) + acc.merge(DerivationTrackIsoCfg(ConfigFlags, object_types=("Electrons", "Muons"))) + + hasFlowObject = ( + "JetETMissChargedParticleFlowObjects" in ConfigFlags.Input.Collections + and "JetETMissNeutralParticleFlowObjects" in ConfigFlags.Input.Collections + ) if hasFlowObject: from IsolationAlgs.IsolationSteeringDerivConfig import IsolationSteeringDerivCfg + acc.merge(IsolationSteeringDerivCfg(ConfigFlags)) return acc - diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaDFConfigFlags.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaDFConfigFlags.py index 734f37b3bb1d..d857de1a9779 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaDFConfigFlags.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaDFConfigFlags.py @@ -4,14 +4,14 @@ from AthenaConfiguration.AthConfigFlags import AthConfigFlags + def createEGammaDFConfigFlags(): egdcf = AthConfigFlags() - egdcf.addFlag('Derivation.Egamma.doTrackThinning', True) - egdcf.addFlag('Derivation.Egamma.doEventInfoSlimming', False) - egdcf.addFlag('Derivation.Egamma.addTriggerMatching', False) + egdcf.addFlag("Derivation.Egamma.doTrackThinning", True) + egdcf.addFlag("Derivation.Egamma.doEventInfoSlimming", False) + egdcf.addFlag("Derivation.Egamma.addTriggerMatching", False) # ECIDS currently not supported in R22 # For the moment just turn off, remove from code when # final decision is taken on whether to revive it or not - egdcf.addFlag('Derivation.Egamma.addECIDS', False) + egdcf.addFlag("Derivation.Egamma.addECIDS", False) return egdcf - diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaIsoConfig.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaIsoConfig.py index 647287cdb85d..18c6e6e23adf 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaIsoConfig.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaIsoConfig.py @@ -2,7 +2,7 @@ # ComponentAccumulator version of EGammaIso.py -#listOfScheduledAlgs = [ 'JetAlgorithm/jetalg_ConstitModCorrectPFOCHS_EMPFlow', +# listOfScheduledAlgs = [ 'JetAlgorithm/jetalg_ConstitModCorrectPFOCHS_EMPFlow', # 'PseudoJetAlgorithm/PseudoJetAlgForIsoNFlow', # 'EventDensityAthAlg/CentralDensityForNFlowIsoAlg', # 'EventDensityAthAlg/ForwardDensityForNFlowIsoAlg', @@ -16,27 +16,41 @@ from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from IsolationAlgs.IsolationSteeringDerivConfig import IsolationSteeringDerivCfg -def makeEGammaCommonIsoCfg(ConfigFlags): +def makeEGammaCommonIsoCfg(ConfigFlags): acc = ComponentAccumulator() - addIsoVar = '' + addIsoVar = "" densityList = [] densityDict = {} - for inT in ['CSSK']: - acc.merge(IsolationSteeringDerivCfg(ConfigFlags, inType = 'EMPFlow'+inT)) + for inT in ["CSSK"]: + acc.merge(IsolationSteeringDerivCfg(ConfigFlags, inType="EMPFlow" + inT)) - for eta in ['Central','Forward']: + for eta in ["Central", "Forward"]: # I do not understand why this is needed - densityDict.update({ - "NeutralParticle"+inT+"FlowIso"+eta+"EventShape":"xAOD::EventShape", - "NeutralParticle"+inT+"FlowIso"+eta+"EventShapeAux":"xAOD::EventShapeAuxInfo"}) - densityList += ["NeutralParticle"+inT+"FlowIso"+eta+"EventShape.Density"] - - suff = '' if len(inT) == 0 else '_'+inT - addIsoVar += \ - f".neflowisol20{suff}.neflowisol30{suff}.neflowisol40{suff}" + \ - f".neflowisolcoreConeEnergyCorrection{suff}" + \ - f".neflowisolcoreConeSCEnergyCorrection{suff}" - - return addIsoVar,densityList,densityDict,acc + densityDict.update( + { + "NeutralParticle" + + inT + + "FlowIso" + + eta + + "EventShape": "xAOD::EventShape", + "NeutralParticle" + + inT + + "FlowIso" + + eta + + "EventShapeAux": "xAOD::EventShapeAuxInfo", + } + ) + densityList += [ + "NeutralParticle" + inT + "FlowIso" + eta + "EventShape.Density" + ] + + suff = "" if len(inT) == 0 else "_" + inT + addIsoVar += ( + f".neflowisol20{suff}.neflowisol30{suff}.neflowisol40{suff}" + + f".neflowisolcoreConeEnergyCorrection{suff}" + + f".neflowisolcoreConeSCEnergyCorrection{suff}" + ) + + return addIsoVar, densityList, densityDict, acc diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaLRTConfig.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaLRTConfig.py index c9c2247e818a..fb4df295c07a 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaLRTConfig.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaLRTConfig.py @@ -3,7 +3,7 @@ # ******************************************************************** # EGammaLRTConfig.py # Configures all tools needed for LRT e-gamma object selection and sets -# up the kernel algorithms so the results can be accessed/written to +# up the kernel algorithms so the results can be accessed/written to # the DAODs. Copied and modified from EGammaCommonConfig.py. # Component accumulator version. # ******************************************************************** @@ -11,6 +11,7 @@ from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory + def EGammaLRTCfg(ConfigFlags): """Main config method for LRT e-gamma decorations""" @@ -21,112 +22,152 @@ def EGammaLRTCfg(ConfigFlags): # see Reconstruction/egamma/egammaTools/python/EMPIDBuilderBase.py # on how to configure the selectors # ==================================================================== - # Setting conf file not supported. These are currently setup in the + # Setting conf file not supported. These are currently setup in the # LLP1.py config TODO: implement common ID in egamma tools - # ==================================================================== # ELECTRON CHARGE SELECTION # ==================================================================== if not hasattr(acc, "ElectronChargeIDSelectorLoose"): if ConfigFlags.Derivation.Egamma.addECIDS: - from ElectronPhotonSelectorTools.AsgElectronChargeIDSelectorToolConfig import AsgElectronChargeIDSelectorToolCfg - ElectronChargeIDSelector = acc.popToolsAndMerge(AsgElectronChargeIDSelectorToolCfg( - ConfigFlags, - name="ElectronChargeIDSelectorLoose")) + from ElectronPhotonSelectorTools.AsgElectronChargeIDSelectorToolConfig import ( + AsgElectronChargeIDSelectorToolCfg, + ) + + ElectronChargeIDSelector = acc.popToolsAndMerge( + AsgElectronChargeIDSelectorToolCfg( + ConfigFlags, name="ElectronChargeIDSelectorLoose" + ) + ) ElectronChargeIDSelector.primaryVertexContainer = "PrimaryVertices" - ElectronChargeIDSelector.TrainingFile = "ElectronPhotonSelectorTools/ChargeID/ECIDS_20180731rel21Summer2018.root" + ElectronChargeIDSelector.TrainingFile = ( + "ElectronPhotonSelectorTools/ChargeID/" + + "ECIDS_20180731rel21Summer2018.root" + ) acc.addPublicTool(ElectronChargeIDSelector) # ==================================================================== # AUGMENTATION TOOLS # ==================================================================== - from DerivationFrameworkEGamma.EGammaToolsConfig import EGElectronLikelihoodToolWrapperCfg + from DerivationFrameworkEGamma.EGammaToolsConfig import ( + EGElectronLikelihoodToolWrapperCfg, + ) # decorate electrons with the output of LH very loose # TODO same as above, update with central ID # decorate electrons with the output of ECIDS if ConfigFlags.Derivation.Egamma.addECIDS: - LRTElectronPassECIDS = acc.getPrimaryAndMerge(EGElectronLikelihoodToolWrapperCfg( - ConfigFlags, - name="LRTElectronPassECIDS", - EGammaElectronLikelihoodTool=ElectronChargeIDSelector, - EGammaFudgeMCTool="", - CutType="", - StoreGateEntryName="DFCommonElectronsECIDS", - ContainerName="LRTElectrons", - StoreTResult=True)) + LRTElectronPassECIDS = acc.getPrimaryAndMerge( + EGElectronLikelihoodToolWrapperCfg( + ConfigFlags, + name="LRTElectronPassECIDS", + EGammaElectronLikelihoodTool=ElectronChargeIDSelector, + EGammaFudgeMCTool="", + CutType="", + StoreGateEntryName="DFCommonElectronsECIDS", + ContainerName="LRTElectrons", + StoreTResult=True, + ) + ) # decorate central electrons and photons with a flag to tell the the # candidates are affected by the crack bug in mc16a and data 2015+2016 from DerivationFrameworkEGamma.EGammaToolsConfig import EGCrackVetoCleaningToolCfg - LRTElectronPassCrackVeto = acc.getPrimaryAndMerge(EGCrackVetoCleaningToolCfg( - ConfigFlags, - name="LRTElectronPassCrackVeto", - StoreGateEntryName="DFCommonCrackVetoCleaning", - ContainerName="LRTElectrons")) + + LRTElectronPassCrackVeto = acc.getPrimaryAndMerge( + EGCrackVetoCleaningToolCfg( + ConfigFlags, + name="LRTElectronPassCrackVeto", + StoreGateEntryName="DFCommonCrackVetoCleaning", + ContainerName="LRTElectrons", + ) + ) # decorate some electrons with an additional ambiguity flag # against internal and early material conversion from DerivationFrameworkEGamma.EGammaToolsConfig import EGElectronAmbiguityToolCfg - LRTElectronAmbiguity = acc.getPrimaryAndMerge(EGElectronAmbiguityToolCfg( - ConfigFlags, - name="LRTElectronAdditionnalAmbiguity", - idCut="DFCommonElectronsLHLooseNoPix", - ContainerName="LRTElectrons", - isMC=ConfigFlags.Input.isMC)) + + LRTElectronAmbiguity = acc.getPrimaryAndMerge( + EGElectronAmbiguityToolCfg( + ConfigFlags, + name="LRTElectronAdditionnalAmbiguity", + idCut="DFCommonElectronsLHLooseNoPix", + ContainerName="LRTElectrons", + isMC=ConfigFlags.Input.isMC, + ) + ) # list of all the decorators so far - LRTEGAugmentationTools = [LRTElectronPassCrackVeto, - LRTElectronAmbiguity] + LRTEGAugmentationTools = [LRTElectronPassCrackVeto, LRTElectronAmbiguity] if ConfigFlags.Derivation.Egamma.addECIDS: LRTEGAugmentationTools.extend([LRTElectronPassECIDS]) # ================================================== # Truth Related tools if ConfigFlags.Input.isMC: - # Decorate Electron with bkg electron type/origin from MCTruthClassifier.MCTruthClassifierConfig import MCTruthClassifierCfg - BkgElectronMCTruthClassifier = acc.popToolsAndMerge(MCTruthClassifierCfg( - ConfigFlags, - name="BkgElectronMCTruthClassifier", - ParticleCaloExtensionTool = "")) + + BkgElectronMCTruthClassifier = acc.popToolsAndMerge( + MCTruthClassifierCfg( + ConfigFlags, + name="BkgElectronMCTruthClassifier", + ParticleCaloExtensionTool="", + ) + ) acc.addPublicTool(BkgElectronMCTruthClassifier) - from DerivationFrameworkEGamma.EGammaToolsConfig import BkgElectronClassificationCfg - BkgLRTElectronClassificationTool = acc.getPrimaryAndMerge(BkgElectronClassificationCfg( - ConfigFlags, - name="BkgLRTElectronClassificationTool", - MCTruthClassifierTool=BkgElectronMCTruthClassifier, - ElectronContainerName="LRTElectrons")) + from DerivationFrameworkEGamma.EGammaToolsConfig import ( + BkgElectronClassificationCfg, + ) + + BkgLRTElectronClassificationTool = acc.getPrimaryAndMerge( + BkgElectronClassificationCfg( + ConfigFlags, + name="BkgLRTElectronClassificationTool", + MCTruthClassifierTool=BkgElectronMCTruthClassifier, + ElectronContainerName="LRTElectrons", + ) + ) LRTEGAugmentationTools.append(BkgLRTElectronClassificationTool) # ======================================= # CREATE THE DERIVATION KERNEL ALGORITHM # ======================================= - acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation( - "EGammaLRTKernel", - AugmentationTools=LRTEGAugmentationTools - )) + acc.addEventAlgo( + CompFactory.DerivationFramework.CommonAugmentation( + "EGammaLRTKernel", AugmentationTools=LRTEGAugmentationTools + ) + ) # ======================================= # ADD TOOLS : custom electron, photon and muon track isolation # ======================================= from IsolationAlgs.DerivationTrackIsoConfig import DerivationTrackIsoCfg - acc.merge(DerivationTrackIsoCfg(ConfigFlags, object_types = ('Electrons', 'Muons'), postfix="LRT")) + + acc.merge( + DerivationTrackIsoCfg( + ConfigFlags, object_types=("Electrons", "Muons"), postfix="LRT" + ) + ) if not hasattr(acc, "LRTElectronCaloIsolationBuilder"): - from IsolationAlgs.IsolationSteeringDerivConfig import LRTElectronIsolationSteeringDerivCfg + from IsolationAlgs.IsolationSteeringDerivConfig import ( + LRTElectronIsolationSteeringDerivCfg, + ) + acc.merge(LRTElectronIsolationSteeringDerivCfg(ConfigFlags)) from IsolationAlgs.IsolationBuilderConfig import egIsolationCfg - acc.merge(egIsolationCfg(ConfigFlags, - name="electronIsolationLRT", - ElectronCollectionContainerName = "LRTElectrons" - )) - return acc + acc.merge( + egIsolationCfg( + ConfigFlags, + name="electronIsolationLRT", + ElectronCollectionContainerName="LRTElectrons", + ) + ) + return acc diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaToolsConfig.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaToolsConfig.py index 35d57520306c..b10f1c40967a 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaToolsConfig.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/EGammaToolsConfig.py @@ -1,81 +1,85 @@ # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration -#============================================================================== +# ============================================================================== # Provides configs for the tools used for e-gamma decorations used in DAOD # building -#============================================================================== +# ============================================================================== from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory + # PhotonsDirectionTool def PhotonsDirectionToolCfg(ConfigFlags, name, **kwargs): """Configure the PhotonsDirectionTool""" acc = ComponentAccumulator() PhotonsDirectionTool = CompFactory.DerivationFramework.PhotonsDirectionTool - acc.addPublicTool(PhotonsDirectionTool(name, **kwargs), - primary = True) + acc.addPublicTool(PhotonsDirectionTool(name, **kwargs), primary=True) return acc + # E-gamma selection tool wrapper def EGSelectionToolWrapperCfg(ConfigFlags, name, **kwargs): """Configure the E-gamma selection tool wrapper""" acc = ComponentAccumulator() EGSelectionToolWrapper = CompFactory.DerivationFramework.EGSelectionToolWrapper - acc.addPublicTool(EGSelectionToolWrapper(name, **kwargs), - primary = True) + acc.addPublicTool(EGSelectionToolWrapper(name, **kwargs), primary=True) return acc + # Electron likelihood tool wrapper def EGElectronLikelihoodToolWrapperCfg(ConfigFlags, name, **kwargs): """Configure the electron likelihood tool wrapper""" acc = ComponentAccumulator() - EGElectronLikelihoodToolWrapper = CompFactory.DerivationFramework.EGElectronLikelihoodToolWrapper - acc.addPublicTool(EGElectronLikelihoodToolWrapper(name, **kwargs), - primary = True) + EGElectronLikelihoodToolWrapper = ( + CompFactory.DerivationFramework.EGElectronLikelihoodToolWrapper + ) + acc.addPublicTool(EGElectronLikelihoodToolWrapper(name, **kwargs), primary=True) return acc + # Photon cleaning tool wrapper def EGPhotonCleaningWrapperCfg(ConfigFlags, name, **kwargs): """Configure the photon cleaning tool wrapper""" acc = ComponentAccumulator() EGPhotonCleaningWrapper = CompFactory.DerivationFramework.EGPhotonCleaningWrapper - acc.addPublicTool(EGPhotonCleaningWrapper(name, **kwargs), - primary = True) + acc.addPublicTool(EGPhotonCleaningWrapper(name, **kwargs), primary=True) return acc + # Crack veto cleaning tool def EGCrackVetoCleaningToolCfg(ConfigFlags, name, **kwargs): """Configure the crack veto cleaning tool""" acc = ComponentAccumulator() EGCrackVetoCleaningTool = CompFactory.DerivationFramework.EGCrackVetoCleaningTool - acc.addPublicTool(EGCrackVetoCleaningTool(name, **kwargs), - primary = True) + acc.addPublicTool(EGCrackVetoCleaningTool(name, **kwargs), primary=True) return acc + # Electron ambiguity tool def EGElectronAmbiguityToolCfg(ConfigFlags, name, **kwargs): """Configure the electron ambiguity tool""" acc = ComponentAccumulator() EGElectronAmbiguityTool = CompFactory.DerivationFramework.EGElectronAmbiguityTool - acc.addPublicTool(EGElectronAmbiguityTool(name, **kwargs), - primary = True) + acc.addPublicTool(EGElectronAmbiguityTool(name, **kwargs), primary=True) return acc + # Background electron classification tool def BkgElectronClassificationCfg(ConfigFlags, name, **kwargs): - """Configure the background electron classification tool""" + """Configure the background electron classification tool""" acc = ComponentAccumulator() - BkgElectronClassification = CompFactory.DerivationFramework.BkgElectronClassification - acc.addPublicTool(BkgElectronClassification(name, **kwargs), - primary = True) + BkgElectronClassification = ( + CompFactory.DerivationFramework.BkgElectronClassification + ) + acc.addPublicTool(BkgElectronClassification(name, **kwargs), primary=True) return acc + # Standard + LRT electron collection merger def ElectronMergerCfg(ConfigFlags, name, **kwargs): """Configure the track particle merger tool""" acc = ComponentAccumulator() ElectronMerger = CompFactory.DerivationFramework.ElectronMergerTool - acc.addPublicTool(ElectronMerger(name, **kwargs), - primary = True) + acc.addPublicTool(ElectronMerger(name, **kwargs), primary=True) return acc diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/ElectronsCPDetailedContent.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/ElectronsCPDetailedContent.py index 2be87a61b4c3..aca6ef121d90 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/ElectronsCPDetailedContent.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/ElectronsCPDetailedContent.py @@ -1,11 +1,51 @@ -# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + +ExtraElectronShowerShapes = [ + ".".join( + [ + "Electrons", + "Rhad.Rhad1.e277.Reta.Rphi.weta2.f1.Eratio.DeltaE.weta1.fracs1", + "wtots1.f3.f3core.deltaEta1.deltaPhi1.deltaPhi2", + "deltaPhiRescaled2.deltaPhiFromLastMeasurement", + ] + ) +] + +ExtraElectronTruthInfo = [ + ".".join( + [ + "Electrons", + "lastEgMotherTruthType.lastEgMotherTruthOrigin", + "lastEgMotherTruthParticleLink.lastEgMotherPdgId", + ] + ) +] + -ExtraElectronShowerShapes = ["Electrons.Rhad.Rhad1.e277.Reta.Rphi.weta2.f1.Eratio.DeltaE.weta1.fracs1.wtots1.f3.f3core.deltaEta1.deltaPhi1.deltaPhi2.deltaPhiRescaled2.deltaPhiFromLastMeasurement"] -ExtraElectronTruthInfo = ["Electrons.lastEgMotherTruthType.lastEgMotherTruthOrigin.lastEgMotherTruthParticleLink.lastEgMotherPdgId"] ElectronsCPDetailedContent = ExtraElectronShowerShapes + ExtraElectronTruthInfo -ExtraElectronGSFVar = ["GSFTrackParticles.parameterX.parameterPX.parameterPY.parameterPZ.parameterPosition.numberOfTRTHits.numberOfTRTOutliers.numberOfTRTHighThresholdHits.numberOfTRTHighThresholdOutliers.numberOfTRTXenonHits.eProbabilityComb.eProbabilityHT.eProbabilityNN"] -GSFTracksCPDetailedContent = ExtraElectronGSFVar +ExtraElectronGSFVar = [ + ".".join( + [ + "GSFTrackParticles", + "parameterX.parameterPX.parameterPY.parameterPZ.parameterPosition", + "numberOfTRTHits.numberOfTRTOutliers", + "numberOfTRTHighThresholdHits.numberOfTRTHighThresholdOutliers", + "numberOfTRTXenonHits", + "eProbabilityComb.eProbabilityHT.eProbabilityNN", + ] + ) +] -ElectronsAddAmbiguityContent = ["Electrons.DFCommonSimpleConvRadius.DFCommonSimpleConvPhi.DFCommonSimpleMee.DFCommonSimpleMeeAtVtx.DFCommonSimpleSeparation.DFCommonProdTrueRadius.DFCommonProdTruePhi.DFCommonProdTrueZ"] +GSFTracksCPDetailedContent = ExtraElectronGSFVar +ElectronsAddAmbiguityContent = [ + ".".join( + [ + "Electrons", + "DFCommonSimpleConvRadius.DFCommonSimpleConvPhi.DFCommonSimpleMee", + "DFCommonSimpleMeeAtVtx.DFCommonSimpleSeparation", + "DFCommonProdTrueRadius.DFCommonProdTruePhi.DFCommonProdTrueZ", + ] + ) +] diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/PhotonsCPDetailedContent.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/PhotonsCPDetailedContent.py index 75d148c8bd5a..26ad009d220a 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/PhotonsCPDetailedContent.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/python/PhotonsCPDetailedContent.py @@ -1,3 +1,11 @@ -# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration -PhotonsCPDetailedContent = ["Photons.Rhad.Rhad1.e277.Reta.Rphi.weta2.f1.weta1.fracs1.wtots1.Eratio.DeltaE.f3"] +PhotonsCPDetailedContent = [ + ".".join( + [ + "Photons", + "Rhad.Rhad1.e277.Reta.Rphi.weta2.f1.weta1.fracs1.wtots1", + "Eratio.DeltaE.f3", + ] + ) +] diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/src/EGCrackVetoCleaningTool.cxx b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/src/EGCrackVetoCleaningTool.cxx index 2e8ee2e1fe2d..b25aa783e4f2 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/src/EGCrackVetoCleaningTool.cxx +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkEGamma/src/EGCrackVetoCleaningTool.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration */ /////////////////////////////////////////////////////////////////// @@ -52,7 +52,7 @@ EGCrackVetoCleaningTool::addBranches() const bool maybeBug = clu->hasSampling(CaloSampling::EMB2) && clu->hasSampling(CaloSampling::EME2); const std::vector<const xAOD::CaloCluster*> assocC = - xAOD::EgammaHelpers::getAssociatedTopoClusters(clu); + xAOD::EgammaHelpers::getAssociatedTopoClusters(clu); double dRsatMax = -1.; if (assocC.size() > 1) { for (const xAOD::CaloCluster* sclu : assocC) { -- GitLab