From 4906acf460ebd5e246a35dc2e334bb4f67207138 Mon Sep 17 00:00:00 2001 From: Dan Guest <daniel.hay.guest@cern.ch> Date: Mon, 17 Feb 2025 18:56:01 +0000 Subject: [PATCH] Merge of !77747 and !77764 to work around reference file updates Apply 1 suggestion(s) to 1 file(s) Co-authored-by: Dan Guest <daniel.hay.guest@cern.ch> --- .../python/BTaggingContent.py | 11 ++++ .../python/FtagDerivationConfig.py | 31 ++-------- ...OCSSKSoftDropBeta100Zcut10JetsCPContent.py | 1 + .../DerivationFrameworkPhys/python/PHYS.py | 7 --- .../Root/DataPrepUtilities.cxx | 4 +- .../python/FlavorTagNNConfig.py | 3 +- .../JetTagAlgs/BTagging/python/BTagConfig.py | 15 ++++- .../BTagging/python/JetBTagginglessConfig.py | 56 ++++++++++++------- .../BTagging/python/TrackLeptonConfig.py | 28 ++++++++++ .../python/BTaggingConfigFlags.py | 27 +++++++++ Tools/WorkflowTestRunner/python/References.py | 12 ++-- 11 files changed, 132 insertions(+), 63 deletions(-) create mode 100644 PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/TrackLeptonConfig.py diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkFlavourTag/python/BTaggingContent.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkFlavourTag/python/BTaggingContent.py index 478f9419b8d..ea1fe03481b 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkFlavourTag/python/BTaggingContent.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkFlavourTag/python/BTaggingContent.py @@ -191,6 +191,17 @@ def BTaggingXbbContent(jetcol, ConfigFlags = None): def BTagginglessContent(jetcol, ConfigFlags=None): BTaggingRun3AuxVar = _getVars("GN2v01", extra_flavours=['tau']) + + for gn3_dev in ['GN3V00', 'GN3PflowV00', 'GN3MuonsV00']: + BTaggingRun3AuxVar += _getVars(gn3_dev, extra_flavours=['tau',], flip_modes=['SimpleFlip']) + + BTaggingRun3AuxVar += _getVars( + "GN3PflowMuonsV00", + extra_flavours=['tau', 'ud', 'g', 's', 'quark'], + flip_modes=['SimpleFlip'] + ) + BTaggingRun3AuxVar += ['GN3PflowMuonsV00_ptFromTruthDressedWZJet'] + isRun4 = _isRun4(ConfigFlags) aux = BTaggingRun3AuxVar if not isRun4 else [] btagcontent = _getVariableList(jetcol, aux) diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkFlavourTag/python/FtagDerivationConfig.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkFlavourTag/python/FtagDerivationConfig.py index b8e2bb08187..bda3e80ac2a 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkFlavourTag/python/FtagDerivationConfig.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkFlavourTag/python/FtagDerivationConfig.py @@ -6,11 +6,9 @@ from AthenaConfiguration.ComponentFactory import CompFactory from BTagging.BTagConfig import BTagAlgsCfg, GetTaggerTrainingMap from BTagging.JetBTagginglessConfig import JetBTagginglessAlgCfg from BTagging.BTagTrackAugmenterAlgConfig import BTagTrackAugmenterAlgCfg +from BTagging.TrackLeptonConfig import TrackLeptonDecorationCfg from JetTagCalibration.JetTagCalibConfig import JetTagCalibCfg -from ElectronPhotonSelectorTools.AsgElectronLikelihoodToolsConfig import AsgElectronLikelihoodToolCfg -from ElectronPhotonSelectorTools.LikelihoodEnums import LikeEnum -from MuonSelectorTools.MuonSelectorToolsConfig import MuonSelectionToolCfg from AthenaConfiguration.Enums import LHCPeriod import ParticleJetTools.ParentDecoratorConfig as pdc @@ -59,7 +57,7 @@ def FtagJetCollectionsCfg(cfgFlags, jet_cols, pv_cols=None, # decorate tracks with detailed truth info and reco lepton info acc.merge(trackTruthDecorator(cfgFlags)) - acc.merge(trackLeptonDecorator(cfgFlags)) + acc.merge(TrackLeptonDecorationCfg(cfgFlags)) # Treat large-R jets as a special case largeRJetCollection = 'AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets' @@ -120,7 +118,10 @@ def BTagLargeRDecoration(cfgFlags, jet_col): for nnFile in nnFiles: # ugly string parsing to get the tagger name tagger_name = nnFile.split('/')[-3] - + # separate calse for JetCalibTools models + if nnFile.split('/')[0] == "JetCalibTools": + # not technically a tagger, but works in this code + tagger_name = nnFile.split('_')[-2] acc.addEventAlgo( CompFactory.FlavorTagDiscriminants.JetTagDecoratorAlg( f'{jet_col}{tagger_name}JetTagAlg', @@ -172,26 +173,6 @@ def tagSingleJetCollection(cfgFlags, jet_col, pv_col, return acc -def trackLeptonDecorator(cfgFlags) -> ComponentAccumulator: - """Decorate tracks with information about reconstructed leptons""" - acc = ComponentAccumulator() - - electronID_tool = acc.popToolsAndMerge( - AsgElectronLikelihoodToolCfg(cfgFlags, name="ftagElectronID", quality=LikeEnum.VeryLoose) - ) - muonID_tool = acc.popToolsAndMerge( # loose quality selection - MuonSelectionToolCfg(cfgFlags, name="ftagMuonID", MuQuality=2, MaxEta=2.5) - ) - acc.addEventAlgo(CompFactory.FlavorTagDiscriminants.TrackLeptonDecoratorAlg( - 'TrackLeptonDecoratorAlg', - trackContainer=_getTrackCollection(cfgFlags), - electronSelectionTool=electronID_tool, - muonSelectionTool=muonID_tool, - )) - - return acc - - def trackTruthDecorator(cfgFlags) -> ComponentAccumulator: """Decorate tracks with detailed truth information.""" acc = ComponentAccumulator() diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkJetEtMiss/python/AntiKt10UFOCSSKSoftDropBeta100Zcut10JetsCPContent.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkJetEtMiss/python/AntiKt10UFOCSSKSoftDropBeta100Zcut10JetsCPContent.py index 6d4dbf83d14..65802bd13c8 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkJetEtMiss/python/AntiKt10UFOCSSKSoftDropBeta100Zcut10JetsCPContent.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkJetEtMiss/python/AntiKt10UFOCSSKSoftDropBeta100Zcut10JetsCPContent.py @@ -9,6 +9,7 @@ AntiKt10UFOCSSKSoftDropBeta100Zcut10JetsCPContent = [ "AntiKt10UFOCSSKSoftDropBeta100Zcut10JetsAux.Parent.DetectorEta.DetectorY", "AntiKt10UFOCSSKSoftDropBeta100Zcut10JetsAux.GhostCHadronsFinalCount.GhostBHadronsFinalCount", "AntiKt10UFOCSSKSoftDropBeta100Zcut10JetsAux.R10TruthLabel_R21Precision.R10TruthLabel_R21Precision_2022v1.R10TruthLabel_R22v1", +"AntiKt10UFOCSSKSoftDropBeta100Zcut10JetsAux.bJR10v00_mass.bJR10v00_pt.bJR10v00Ext_mass.bJR10v00Ext_pt.bJR10v01_mass.bJR10v01_pt", "AntiKt10UFOCSSKJets", "AntiKt10UFOCSSKJetsAux.NumTrkPt500.GhostAntiKtVR30Rmax4Rmin02PV0TrackJets.PartonTruthLabelID", "AntiKt10TruthSoftDropBeta100Zcut10Jets", diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/python/PHYS.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/python/PHYS.py index c1d3638d161..0e20912b0fe 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/python/PHYS.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/python/PHYS.py @@ -147,13 +147,6 @@ def PHYSCoreCfg(flags, name_tag='PHYS', StreamName='StreamDAOD_PHYS', TriggerLis for score in ["phbb", "phcc", "ptop", "pqcd"]: extraList.append(f"{tagger}_{score}") PHYSSlimmingHelper.ExtraVariables += ["AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets." + ".".join(extraList)] - - # Large-Radius jet regression extra content - extraListReg = [] - modelName = "bJR10v00" - for score in ["mass", "pt"]: - extraListReg.append(f"{modelName}_{score}") - PHYSSlimmingHelper.ExtraVariables += ["AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets." + ".".join(extraListReg)] # Truth extra content if flags.Input.isMC: diff --git a/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/Root/DataPrepUtilities.cxx b/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/Root/DataPrepUtilities.cxx index 3d5acb194e1..a7d91540a8f 100644 --- a/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/Root/DataPrepUtilities.cxx +++ b/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/Root/DataPrepUtilities.cxx @@ -209,8 +209,8 @@ namespace FlavorTagDiscriminants { } StringRegexes flip_converters { - {"(GN1[^_]*|GN2[^_]*)"_r, "$1" + flip_name}, - {"(GN1[^_]*|GN2[^_]*)_(.*)"_r, "$1" + flip_name + "_$2"}, + {"(GN1[^_]*|GN2[^_]*|GN3[^_]*)"_r, "$1" + flip_name}, + {"(GN1[^_]*|GN2[^_]*|GN3[^_]*)_(.*)"_r, "$1" + flip_name + "_$2"}, {"(IP[23]D)_(.*)"_r, "$1Neg_$2"}, {"(rnnip|(?:dips|DIPS)[^_]*)_(.*)"_r, "$1flip_$2"}, {"(JetFitter|SV1|JetFitterSecondaryVertex)_(.*)"_r, "$1Flip_$2"}, diff --git a/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/python/FlavorTagNNConfig.py b/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/python/FlavorTagNNConfig.py index 325ae400b70..7118371026c 100644 --- a/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/python/FlavorTagNNConfig.py +++ b/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/python/FlavorTagNNConfig.py @@ -225,6 +225,7 @@ def MultifoldGNNCfg( useBTaggingObject=None, tag_requirements=set(), defaultOutputValues={}, + foldHashName='jetFoldRankHash', ): common = commonpath(nnFilePaths) nn_name = '_'.join(PurePath(common).with_suffix('').parts) @@ -280,7 +281,7 @@ def MultifoldGNNCfg( constituentContainer=TrackCollection, decorator=FTD.MultifoldGNNTool( name=f'{algname}_tool', - foldHashName='jetFoldHash', + foldHashName=foldHashName, nnFiles=nnFilePaths, flipTagConfig=FlipConfig, variableRemapping=remapping, diff --git a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTagConfig.py b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTagConfig.py index 073908ad9bb..32590846785 100644 --- a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTagConfig.py +++ b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTagConfig.py @@ -57,7 +57,9 @@ def GetTaggerTrainingMap(inputFlags, jet_col): "BTagging/20230413/gn2xwithmassv00/antikt10ufo/network.onnx", "BTagging/20230705/gn2xv01/antikt10ufo/network.onnx", "BTagging/20240925/GN2Xv02/antikt10ufo/network.onnx", - "JetCalibTools/CalibArea-00-04-83/CalibrationFactors/MC20_bbJES_ak10csskufo_Sep24_calibFactors.onnx", # GN2X-based regression model + "JetCalibTools/CalibArea-00-04-83/CalibrationFactors/MC20_bbJES_ak10csskufo_Sep24_calibFactors.onnx", # bJR10v00 + "JetCalibTools/CalibArea-00-04-83/CalibrationFactors/bbJESJMS_calibFactors_R22_MC20_CSSKUFO_bJR10v00Ext_20250212.onnx", # bJR10v00Ext + "JetCalibTools/CalibArea-00-04-83/CalibrationFactors/bbJESJMS_calibFactors_R22_MC20MC23_CSSKUFO_bJR10v01_20250212.onnx" # bJR10v01 ], "HLT_AntiKt4EMPFlowJets_subresjesgscIS_ftf_TLA": [ "BTagging/20220314/dipsLoose/antikt4empflow/network.json", # input to DL1dv01 @@ -384,11 +386,15 @@ def BTagAlgsCfg( # multifold models, at the moment this is only supported via inputFlags for networks in inputFlags.BTagging.NNs.get(jetcol, []): - assert len(networks['folds']) > 1 + assert isinstance(networks['folds'], list) dirnames = [Path(path).parent for path in networks['folds']] assert len(set(dirnames)) == 1, 'Different folds should be located in the same dir' dirname = str(dirnames[0]) + # skip ghost association: not suppoted on the BTagging object + if not networks.get('cone_association'): + continue + args = dict( flags=inputFlags, BTaggingCollection=BTagCollection, @@ -397,6 +403,9 @@ def BTagAlgsCfg( remapping=networks.get('remapping', {}), JetCollection=jetcol, ) + if foldHashName := networks.get('hash'): + args['foldHashName'] = foldHashName + # disable GN2v01 if there are 0 tracks if '/GN2v01/' in dirname: @@ -430,7 +439,7 @@ def _get_flip_config(nn_path): return ['FLIP_SIGN'] if 'rnnip' in nn_path or 'dips' in nn_path: return ['NEGATIVE_IP_ONLY'] - if 'gn1' in nn_path or 'gn2' in nn_path: + if 'gn1' in nn_path or 'gn2' in nn_path or 'gn3' in nn_path: return ['SIMPLE_FLIP'] else: return [] diff --git a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/JetBTagginglessConfig.py b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/JetBTagginglessConfig.py index a4949c654a1..3032199ed47 100644 --- a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/JetBTagginglessConfig.py +++ b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/JetBTagginglessConfig.py @@ -7,16 +7,19 @@ from AthenaConfiguration.ComponentFactory import CompFactory from BTagging.JetParticleAssociationAlgConfig import JetParticleAssociationAlgCfg from BTagging.BTagTrackAugmenterAlgConfig import BTagTrackAugmenterAlgCfg +from BTagging.BTagConfig import _get_flip_config +from BTagging.TrackLeptonConfig import TrackLeptonDecorationCfg from FlavorTagDiscriminants.FlavorTagNNConfig import MultifoldGNNCfg from pathlib import Path + def JetBTagginglessAlgCfg( - cfgFlags, - JetCollection, - pv_col='PrimaryVertices', - trackAugmenterPrefix=None, - fast=False): + cfgFlags, + JetCollection, + pv_col='PrimaryVertices', + trackAugmenterPrefix=None, + fast=False): """ Run flavour tagging on jet collection in derivations. @@ -44,33 +47,48 @@ def JetBTagginglessAlgCfg( prefix=trackAugmenterPrefix, )) - acc.merge(JetParticleAssociationAlgCfg( - cfgFlags, - JetCollection, - trackCollection, - JetTrackAssociator, - )) - for networks in cfgFlags.BTagging.NNs.get(JetCollection, []): - assert len(networks['folds']) > 1 + assert isinstance(networks['folds'], list) dirnames = [Path(path).parent for path in networks['folds']] assert len(set(dirnames)) == 1, 'Different folds should be located in the same dir' dirname = str(dirnames[0]) + if 'Muon' in dirname: + acc.merge(TrackLeptonDecorationCfg(cfgFlags)) + args = dict( - flags=cfgFlags, - JetCollection=JetCollection, - TrackCollection=trackCollection, - nnFilePaths=networks['folds'], - remapping=networks.get('remapping', {}), + flags=cfgFlags, + JetCollection=JetCollection, + TrackCollection=trackCollection, + nnFilePaths=networks['folds'], + remapping=networks.get('remapping', {}), ) + if foldHashName := networks.get('hash'): + args['foldHashName'] = foldHashName + + if networks.get('cone_association'): + acc.merge(JetParticleAssociationAlgCfg( + cfgFlags, + JetCollection, + trackCollection, + JetTrackAssociator, + )) + else: + args['remapping'].setdefault( + 'BTagTrackToJetAssociator', 'GhostTrack') + if '/GN2v01/' in dirname: args['tag_requirements'] = {'nonzeroTracks'} acc.merge(MultifoldGNNCfg(**args)) - return acc + # add flip taggers + if cfgFlags.BTagging.RunFlipTaggers and networks.get('flip', True): + for flip_config in _get_flip_config(dirname): + acc.merge(MultifoldGNNCfg(**args, FlipConfig=flip_config)) + + return acc def _fastCfg(flags, pv, tc, pfx): diff --git a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/TrackLeptonConfig.py b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/TrackLeptonConfig.py new file mode 100644 index 00000000000..7917f19fc2f --- /dev/null +++ b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/TrackLeptonConfig.py @@ -0,0 +1,28 @@ +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + +from ElectronPhotonSelectorTools.AsgElectronLikelihoodToolsConfig import AsgElectronLikelihoodToolCfg +from MuonSelectorTools.MuonSelectorToolsConfig import MuonSelectionToolCfg +from ElectronPhotonSelectorTools.LikelihoodEnums import LikeEnum + +from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator +from AthenaConfiguration.ComponentFactory import CompFactory + + +def TrackLeptonDecorationCfg(cfgFlags) -> ComponentAccumulator: + """Decorate tracks with information about reconstructed leptons""" + acc = ComponentAccumulator() + + electronID_tool = acc.popToolsAndMerge( + AsgElectronLikelihoodToolCfg(cfgFlags, name="ftagElectronID", quality=LikeEnum.VeryLoose) + ) + muonID_tool = acc.popToolsAndMerge( # loose quality selection + MuonSelectionToolCfg(cfgFlags, name="ftagMuonID", MuQuality=2, MaxEta=2.5) + ) + acc.addEventAlgo(CompFactory.FlavorTagDiscriminants.TrackLeptonDecoratorAlg( + 'TrackLeptonDecoratorAlg', + trackContainer="InDetTrackParticles", + electronSelectionTool=electronID_tool, + muonSelectionTool=muonID_tool, + )) + + return acc diff --git a/PhysicsAnalysis/JetTagging/JetTagConfig/python/BTaggingConfigFlags.py b/PhysicsAnalysis/JetTagging/JetTagConfig/python/BTaggingConfigFlags.py index 4614976012b..667c604e508 100644 --- a/PhysicsAnalysis/JetTagging/JetTagConfig/python/BTaggingConfigFlags.py +++ b/PhysicsAnalysis/JetTagging/JetTagConfig/python/BTaggingConfigFlags.py @@ -76,19 +76,45 @@ def runFlipTag(flags): return isRun3Derivation(flags) def getNNs(flags): + ''' + Gets the paths of models to run via MultiFoldTagger. + ''' # dummy for now caldir = 'BTagging/20231205/GN2v01/antikt4empflow' pf_nns = [f'{caldir}/network_fold{n}.onnx' for n in range(4)] + + # We can save our results to the jet container, rather than the b-tagging container + # but this functionality is not yet setup for non multi-fold taggers. The easiest (/hackiest) + # solution is to pass all the GN3 paths below as seperate single-fold-multi-fold-taggers + # But this *should* be cleaned up at some point + # Note also, reco tests failing due to leptonID missing, so for now don't run taggers unless derivation + # https://gitlab.cern.ch/atlas/athena/-/merge_requests/77764#note_9063625 + gn3_paths = [ + "BTagging/20250213/GN3V00/antikt4empflow/network.onnx", # Only tracks + "BTagging/20250213/GN3PflowV00/antikt4empflow/network.onnx", # Tracks+PFlow + "BTagging/20250213/GN3MuonsV00/antikt4empflow/network.onnx", # Tracks+Muons + "BTagging/20250213/GN3PflowMuonsV00/antikt4empflow/network.onnx", # Tracks+Muons+PFlow + ] if isRun3Derivation(flags) else [ + "BTagging/20250213/GN3V00/antikt4empflow/network.onnx", # Only tracks + "BTagging/20250213/GN3PflowV00/antikt4empflow/network.onnx", # Tracks+PFlow + ] + return { 'AntiKt4EMPFlowJets': [ { 'folds': pf_nns, + 'hash': 'jetFoldHash', + 'cone_association': True, }, + *[{'folds' : [nn_path]} for nn_path in gn3_paths] ], 'AntiKt4EMPFlowCustomVtxJets': [ { 'folds': pf_nns, + 'hash': 'jetFoldHash', + 'cone_association': True }, + *[{'folds' : [nn_path]} for nn_path in gn3_paths] ] } @@ -151,5 +177,6 @@ def createBTaggingConfigFlags(): # - folds: list of NNs to run # - remapping (optional): any variable remapping btagcf.addFlag("BTagging.NNs", getNNs) + return btagcf diff --git a/Tools/WorkflowTestRunner/python/References.py b/Tools/WorkflowTestRunner/python/References.py index 50f2f45c7ed..1233d28c6d1 100644 --- a/Tools/WorkflowTestRunner/python/References.py +++ b/Tools/WorkflowTestRunner/python/References.py @@ -30,16 +30,16 @@ references_map = { "q452": "v32", "q454": "v47", # Derivations - "data_PHYS_Run2": "v42", + "data_PHYS_Run2": "v43", "data_PHYSLITE_Run2": "v24", - "data_PHYS_Run3": "v42", + "data_PHYS_Run3": "v43", "data_PHYSLITE_Run3": "v25", - "mc_PHYS_Run2": "v54", + "mc_PHYS_Run2": "v55", "mc_PHYSLITE_Run2": "v28", - "mc_PHYS_Run3": "v57", + "mc_PHYS_Run3": "v58", "mc_PHYSLITE_Run3": "v31", - "af3_PHYS_Run2": "v4", + "af3_PHYS_Run2": "v5", "af3_PHYSLITE_Run2": "v5", - "af3_PHYS_Run3": "v38", + "af3_PHYS_Run3": "v39", "af3_PHYSLITE_Run3": "v32", } -- GitLab