From 554d025520c7c8c9084193a70fe9054823f3686c Mon Sep 17 00:00:00 2001
From: Bertrand Martin <martindl@cern.ch>
Date: Tue, 23 Jun 2020 18:01:40 +0200
Subject: [PATCH] DAOD_PHYS: add low-pt di-tau reconstruction

Hello,

This MR enables the on-the-fly reconstruction of low-pt di-taus in DAOD_PHYS.
A small change was made in the DiTauRec tool scheduling, to avoid a "spurious JetAlgorithm addition" to AlgSequence, which could cause some conflicts when scheduling ditau reconstruction on-the-fly, depending when the DAOD_PHYS AthSequencer is added to DerivationFrameworkJob.
Other small changes: the import of `DerivationFramework__CommonAugmentation` and `DerivationFramework__DerivationKernel` was commented out, it did not seem mandatory, please let me know if that is wrong.
Also, the `DerivationFramework__DerivationKernel` was added to `DerivationFrameworkJob` instead of `SeqPHYS`, in case that was intended, I am happy to put this back.

Besides, TauCommon has been better structured, so that functions can be imported and more specific actions can be made, such as decorate only the desired tau ID WP, instead of all 4 WPs.

What is not functional yet is the thinning of low-pt ditaus. No matter what I tried, I end up with `ERROR MultipleProxyLoader: unable to find valid proxy loader for DiTauJetsLowPt.nSubjets`.
Not sure why, the ditau EDM is defined in xAODTau, and that was working in 21.2. To be followed up.

Cheers,
Bertrand
---
 .../DerivationFrameworkPhys/share/PHYS.py     |  24 +-
 .../python/TauCommon.py                       | 223 ++++++++++--------
 .../python/TauJetsCPContent.py                |   2 +-
 .../DiTauRec/python/DiTauAlgorithmsHolder.py  |  21 +-
 .../DiTauRec/python/DiTauBuilder.py           |   3 +-
 5 files changed, 143 insertions(+), 130 deletions(-)

diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYS.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYS.py
index 6aa324cd328..dd6f9e1d0c9 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYS.py
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYS.py
@@ -46,7 +46,7 @@ if (DerivationFrameworkIsMonteCarlo):
                                                                   ParticleSelectionString = "(abs(TruthParticles.pdgId) == 4)",
                                                                   Do_Compress             = True)
    ToolSvc += PHYSTruthCharmTool
-   from DerivationFrameworkCore.DerivationFrameworkCoreConf import DerivationFramework__CommonAugmentation
+   #from DerivationFrameworkCore.DerivationFrameworkCoreConf import DerivationFramework__CommonAugmentation
    SeqPHYS += CfgMgr.DerivationFramework__CommonAugmentation("PHYSTruthCharmKernel",AugmentationTools=[PHYSTruthCharmTool])
    # Add HF particles
    addHFAndDownstreamParticles(SeqPHYS)
@@ -189,22 +189,20 @@ addQGTaggerTool(jetalg="AntiKt4EMPFlow",sequence=SeqPHYS,algname="QGTaggerToolPF
 #====================================================================
 # Add our sequence to the top sequence
 #====================================================================
-# Ideally, this should come at the end of the job, but the tau additions
-# below make it such that we need it here
+# Ideally, this should come at the end of the job
 DerivationFrameworkJob += SeqPHYS
 
 #====================================================================
 # Tau   
 #====================================================================
-'''
-# Schedule low-pt di-tau reconstruction (needs AntiKt2PV0TrackJets)
+# Add low-pt di-tau reconstruction
 from DerivationFrameworkTau.TauCommon import addDiTauLowPt
-addDiTauLowPt()
-
+addDiTauLowPt(Seq=SeqPHYS)
+'''
 # Low-pt di-tau thinning
 from DerivationFrameworkTools.DerivationFrameworkToolsConf import DerivationFramework__GenericObjectThinning
 PHYSDiTauLowPtThinningTool = DerivationFramework__GenericObjectThinning(name            = "PHYSDiTauLowPtThinningTool",
-                                                                        ThinningService = PHYSThinningHelper.ThinningSvc(),
+                                                                        StreamName      = PHYSStream.Name,
                                                                         ContainerName   = "DiTauJetsLowPt",
                                                                         SelectionString = "DiTauJetsLowPt.nSubjets > 1")
 ToolSvc += PHYSDiTauLowPtThinningTool
@@ -212,7 +210,7 @@ thinningTools.append(PHYSDiTauLowPtThinningTool)
 
 # ID tracks associated with low-pt ditau
 PHYSDiTauLowPtTPThinningTool = DerivationFramework__DiTauTrackParticleThinning(name                    = "PHYSDiTauLowPtTPThinningTool",
-                                                                               ThinningService         = PHYSThinningHelper.ThinningSvc(),
+                                                                               StreamName              = PHYSStream.Name,
                                                                                DiTauKey                = "DiTauJetsLowPt",
                                                                                InDetTrackParticlesKey  = "InDetTrackParticles",
                                                                                SelectionString         = "DiTauJetsLowPt.nSubjets > 1")
@@ -223,9 +221,9 @@ thinningTools.append(PHYSDiTauLowPtTPThinningTool)
 # CREATE THE DERIVATION KERNEL ALGORITHM   
 #====================================================================
 # Add the kernel for thinning (requires the objects be defined)
-from DerivationFrameworkCore.DerivationFrameworkCoreConf import DerivationFramework__DerivationKernel
-DerivationFrameworkJob += CfgMgr.DerivationFramework__DerivationKernel("PHYSKernel",
-                                                                       ThinningTools = thinningTools)
+#from DerivationFrameworkCore.DerivationFrameworkCoreConf import DerivationFramework__DerivationKernel
+SeqPHYS += CfgMgr.DerivationFramework__DerivationKernel("PHYSKernel",
+                                                        ThinningTools = thinningTools)
 
 
 #====================================================================
@@ -273,7 +271,7 @@ PHYSSlimmingHelper.SmartCollections = ["Electrons",
                                        #"MET_Baseline_AntiKt4EMPFlow",
                                        "TauJets",
                                        "DiTauJets",
-                                       #"DiTauJetsLowPt",
+                                       "DiTauJetsLowPt",
                                        "AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets",
                                        #"AntiKtVR30Rmax4Rmin02TrackJets_BTagging201903",
                                        #"BTagging_AntiKtVR30Rmax4Rmin02Track_201903"
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkTau/python/TauCommon.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkTau/python/TauCommon.py
index d8e46c00e87..2b09c165218 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkTau/python/TauCommon.py
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkTau/python/TauCommon.py
@@ -7,147 +7,165 @@
 #********************************************************************
 
 from __future__ import print_function
-
-from DerivationFrameworkCore.DerivationFrameworkMaster import DerivationFrameworkJob
-from AthenaCommon.AppMgr import ToolSvc
 from AthenaCommon import CfgMgr 
 
-#====================================================================
-# MAKE TAU ENUMS AVAILABLE
-#====================================================================
-#from ROOT import xAOD__TauJetParameters__IsTauFlag
+# will likely be replaced with generic tau decorator tool
+#from tauRec.TauRecAODBuilder import TauRecAODProcessor_FTau
+#TauRecAODProcessor_FTau()
 
 #====================================================================
 # AUGMENTATION TOOLS
 #====================================================================
-from DerivationFrameworkTools.DerivationFrameworkToolsConf import DerivationFramework__AsgSelectionToolWrapper
-from TauAnalysisTools.TauAnalysisToolsConf import TauAnalysisTools__TauSelectionTool
+def AddTauAugmentation(Seq=None, doVeryLoose=None, doLoose=None, doMedium=None, doTight=None):
 
-#from tauRec.TauRecAODBuilder import TauRecAODProcessor_FTau
-#TauRecAODProcessor_FTau()
-
-DFCommonTauWrapperTools = []
-
-# VeryLoose
-DFCommonTausSelectorVeryLoose = TauAnalysisTools__TauSelectionTool(name="DFCommonTausSelectorVeryLoose")
-DFCommonTausSelectorVeryLoose.JetIDWP = 19
-DFCommonTausSelectorVeryLoose.SelectionCuts = 1<<6
-DFCommonTausSelectorVeryLoose.ConfigPath = ''
-#TauAnalysisTools::CutJetIDWP should be used but issue with the dictionnary
-ToolSvc += DFCommonTausSelectorVeryLoose
-DFCommonTausVeryLooseWrapper = DerivationFramework__AsgSelectionToolWrapper( name = "DFCommonTausVeryLooseWrapper",
-                                                                             AsgSelectionTool = DFCommonTausSelectorVeryLoose,
-                                                                             StoreGateEntryName   = "DFCommonTausVeryLoose",
-                                                                             ContainerName        = "TauJets")
-ToolSvc += DFCommonTausVeryLooseWrapper
-print (DFCommonTausVeryLooseWrapper)
-DFCommonTauWrapperTools.append(DFCommonTausVeryLooseWrapper)
-
-# Loose
-DFCommonTausSelectorLoose = TauAnalysisTools__TauSelectionTool(name="DFCommonTausSelectorLoose")
-DFCommonTausSelectorLoose.JetIDWP = 20
-DFCommonTausSelectorLoose.SelectionCuts = 1<<6
-DFCommonTausSelectorLoose.ConfigPath = ''
-#TauAnalysisTools::CutJetIDWP should be used but issue with the dictionnary
-ToolSvc += DFCommonTausSelectorLoose
-DFCommonTausLooseWrapper = DerivationFramework__AsgSelectionToolWrapper( name = "DFCommonTausLooseWrapper",
-                                                                         AsgSelectionTool = DFCommonTausSelectorLoose,
-                                                                         StoreGateEntryName   = "DFCommonTausLoose",
-                                                                         ContainerName        = "TauJets")
-ToolSvc += DFCommonTausLooseWrapper
-print (DFCommonTausLooseWrapper)
-DFCommonTauWrapperTools.append(DFCommonTausLooseWrapper)
-
-# Medium
-DFCommonTausSelectorMedium = TauAnalysisTools__TauSelectionTool(name="DFCommonTausSelectorMedium")
-DFCommonTausSelectorMedium.JetIDWP = 21
-DFCommonTausSelectorMedium.SelectionCuts = 1<<6
-DFCommonTausSelectorMedium.ConfigPath = ''
-ToolSvc += DFCommonTausSelectorMedium
-DFCommonTausMediumWrapper = DerivationFramework__AsgSelectionToolWrapper( name = "DFCommonTausMediumWrapper",
-                                                                          AsgSelectionTool = DFCommonTausSelectorMedium,
-                                                                          StoreGateEntryName   = "DFCommonTausMedium",
-                                                                          ContainerName        = "TauJets")
-ToolSvc += DFCommonTausMediumWrapper
-print (DFCommonTausMediumWrapper)
-DFCommonTauWrapperTools.append(DFCommonTausMediumWrapper)
-
-# Tight
-DFCommonTausSelectorTight = TauAnalysisTools__TauSelectionTool(name="DFCommonTausSelectorTight")
-DFCommonTausSelectorTight.JetIDWP = 22
-DFCommonTausSelectorTight.SelectionCuts = 1<<6
-DFCommonTausSelectorTight.ConfigPath = ''
-ToolSvc += DFCommonTausSelectorTight
-DFCommonTausTightWrapper = DerivationFramework__AsgSelectionToolWrapper( name = "DFCommonTausTightWrapper",
-                                                                         AsgSelectionTool = DFCommonTausSelectorTight,
-                                                                         StoreGateEntryName   = "DFCommonTausTight",
-                                                                         ContainerName        = "TauJets" )
-ToolSvc += DFCommonTausTightWrapper
-print (DFCommonTausTightWrapper)
-DFCommonTauWrapperTools.append(DFCommonTausTightWrapper)
-
-
-#=======================================
-# CREATE THE DERIVATION KERNEL ALGORITHM
-#=======================================
+    if not Seq or hasattr(Seq,"TauAugmentationKernel"+Seq.name()):
+        print("Tau augmentation will not be scheduled")
+        return
 
-DerivationFrameworkJob += CfgMgr.DerivationFramework__CommonAugmentation( "TauCommonKernel",
-                                                                          AugmentationTools = DFCommonTauWrapperTools )
+    from AthenaCommon.AppMgr import ToolSvc
+    from DerivationFrameworkTools.DerivationFrameworkToolsConf import DerivationFramework__AsgSelectionToolWrapper
+    from TauAnalysisTools.TauAnalysisToolsConf import TauAnalysisTools__TauSelectionTool
+    import PyUtils.RootUtils as ru
+    ROOT = ru.import_root()
+    import cppyy
+    cppyy.loadDictionary('TauAnalysisTools')
+
+    TauAugmentationTools = []
+
+    if doVeryLoose:
+        if not hasattr(ToolSvc,"TauVeryLooseWrapper"):
+            TauSelectorVeryLoose = TauAnalysisTools__TauSelectionTool(name="TauSelectorVeryLoose")
+            TauSelectorVeryLoose.JetIDWP = ROOT.TauAnalysisTools.e_JETID.JETIDRNNVERYLOOSE
+            TauSelectorVeryLoose.SelectionCuts = ROOT.TauAnalysisTools.SelectionCuts.CutJetIDWP
+            TauSelectorVeryLoose.ConfigPath = ''
+            ToolSvc += TauSelectorVeryLoose
+
+            TauVeryLooseWrapper = DerivationFramework__AsgSelectionToolWrapper(name               = "TauVeryLooseWrapper",
+                                                                               AsgSelectionTool   = TauSelectorVeryLoose,
+                                                                               StoreGateEntryName = "DFTauVeryLoose",
+                                                                               ContainerName      = "TauJets")
+            ToolSvc += TauVeryLooseWrapper
+        else:
+            TauVeryLooseWrapper = getattr(ToolSvc,"TauVeryLooseWrapper")
+
+        print (TauVeryLooseWrapper)
+        TauAugmentationTools.append(TauVeryLooseWrapper)
+    
+    if doLoose:
+        if not hasattr(ToolSvc,"TauLooseWrapper"):
+            TauSelectorLoose = TauAnalysisTools__TauSelectionTool(name="TauSelectorLoose")
+            TauSelectorLoose.JetIDWP = ROOT.TauAnalysisTools.e_JETID.JETIDRNNLOOSE
+            TauSelectorLoose.SelectionCuts = ROOT.TauAnalysisTools.SelectionCuts.CutJetIDWP
+            TauSelectorLoose.ConfigPath = ''
+            ToolSvc += TauSelectorLoose
+
+            TauLooseWrapper = DerivationFramework__AsgSelectionToolWrapper(name               = "TauLooseWrapper",
+                                                                           AsgSelectionTool   = TauSelectorLoose,
+                                                                           StoreGateEntryName = "DFTauLoose",
+                                                                           ContainerName      = "TauJets")
+            ToolSvc += TauLooseWrapper
+        else:
+            TauLooseWrapper = getattr(ToolSvc,"TauLooseWrapper")
+
+        print (TauLooseWrapper)
+        TauAugmentationTools.append(TauLooseWrapper)
+    
+    if doMedium:
+        if not hasattr(ToolSvc,"TauMediumWrapper"):
+            TauSelectorMedium = TauAnalysisTools__TauSelectionTool(name="TauSelectorMedium")
+            TauSelectorMedium.JetIDWP = ROOT.TauAnalysisTools.e_JETID.JETIDRNNMEDIUM
+            TauSelectorMedium.SelectionCuts = ROOT.TauAnalysisTools.SelectionCuts.CutJetIDWP
+            TauSelectorMedium.ConfigPath = ''
+            ToolSvc += TauSelectorMedium
+
+            TauMediumWrapper = DerivationFramework__AsgSelectionToolWrapper(name               = "TauMediumWrapper",
+                                                                            AsgSelectionTool   = TauSelectorMedium,
+                                                                            StoreGateEntryName = "DFTauMedium",
+                                                                            ContainerName      = "TauJets")
+            ToolSvc += TauMediumWrapper
+        else:
+            TauMediumWrapper = getattr(ToolSvc,"TauMediumWrapper")
+
+        print (TauMediumWrapper)
+        TauAugmentationTools.append(TauMediumWrapper)
+    
+    if doTight:
+        if not hasattr(ToolSvc,"TauTightWrapper"):
+            TauSelectorTight = TauAnalysisTools__TauSelectionTool(name="TauSelectorTight")
+            TauSelectorTight.JetIDWP = ROOT.TauAnalysisTools.e_JETID.JETIDRNNTIGHT
+            TauSelectorTight.SelectionCuts = ROOT.TauAnalysisTools.SelectionCuts.CutJetIDWP
+            TauSelectorTight.ConfigPath = ''
+            ToolSvc += TauSelectorTight
+
+            TauTightWrapper = DerivationFramework__AsgSelectionToolWrapper(name               = "TauTightWrapper",
+                                                                           AsgSelectionTool   = TauSelectorTight,
+                                                                           StoreGateEntryName = "DFTauTight",
+                                                                           ContainerName      = "TauJets")
+            ToolSvc += TauTightWrapper
+        else:
+            TauTightWrapper = getattr(ToolSvc,"TauTightWrapper")
+
+        print (TauTightWrapper)
+        TauAugmentationTools.append(TauTightWrapper)
+            
+    if TauAugmentationTools:
+        Seq += CfgMgr.DerivationFramework__DerivationKernel("TauAugmentationKernel"+Seq.name(), AugmentationTools = TauAugmentationTools)
 
 #=================
 # TAU THINNING
 #=================
-def ThinTau(Name=None, ThinningService=None, Seq=None, SelectionString=None):
+def ThinTau(Seq=None, streamName=None, selectionString=None):
 
-    if not Name or not ThinningService or not Seq:
-        print ("Can't schedule tau thinning")
+    if not Seq or not streamName or hasattr(Seq,"TauThinningKernel"+Seq.name()):
+        print ("Tau thinning will not be scheduled")
         return
 
-    if not SelectionString:
-        SelectionString = "(TauJets.pt >= 15.*GeV) && (TauJets.nTracks<4 && TauJets.nTracks>0)"
+    if not selectionString:
+        selectionString = "(TauJets.pt >= 15.*GeV) && (TauJets.nTracks>0 && TauJets.nTracks<4)"
+
+    print ("Adding tau thinning:", selectionString)
 
     from AthenaCommon.AppMgr import ToolSvc
 
     # TauJets thinning
     from DerivationFrameworkTools.DerivationFrameworkToolsConf import DerivationFramework__GenericObjectThinning
-    TauJetsThinningTool = DerivationFramework__GenericObjectThinning(name            = Name+"TauJetsThinningTool",
-                                                                     ThinningService = ThinningService,
+    TauJetsThinningTool = DerivationFramework__GenericObjectThinning(name            = "TauJetsThinningTool"+Seq.name(),
+                                                                     StreamName      = streamName,
                                                                      ContainerName   = "TauJets",
-                                                                     SelectionString = SelectionString)
+                                                                     SelectionString = selectionString)
     ToolSvc += TauJetsThinningTool
     print (TauJetsThinningTool)
 
     # Only keep tau tracks (and associated ID tracks) classified as charged tracks
     from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__TauTrackParticleThinning
-    TauTPThinningTool = DerivationFramework__TauTrackParticleThinning(name                   = Name+"TauTPThinningTool",
-                                                                      ThinningService        = ThinningService,
+    TauTPThinningTool = DerivationFramework__TauTrackParticleThinning(name                   = "TauTPThinningTool"+Seq.name(),
+                                                                      StreamName             = streamName,
                                                                       TauKey                 = "TauJets",
                                                                       InDetTrackParticlesKey = "InDetTrackParticles",
-                                                                      SelectionString        = SelectionString,
-                                                                      ApplyAnd               = False,
+                                                                      SelectionString        = selectionString,
                                                                       DoTauTracksThinning    = True,
                                                                       TauTracksKey           = "TauTracks")
     ToolSvc += TauTPThinningTool
     print (TauTPThinningTool)
 
-    Seq += CfgMgr.DerivationFramework__DerivationKernel(Name+"TauThinningKernel", ThinningTools = [TauJetsThinningTool,TauTPThinningTool])
+    Seq += CfgMgr.DerivationFramework__DerivationKernel("TauThinningKernel"+Seq.name(), ThinningTools = [TauJetsThinningTool,TauTPThinningTool])
 
-'''
 #=======================================
 # Low-pt di-tau reconstruction
 #=======================================
-def addDiTauLowPt():
+def addDiTauLowPt(Seq=None):
 
-    from AthenaCommon.AppMgr import ToolSvc
-    if hasattr(ToolSvc,"DFCommonDiTauLowPtBuilder"):
+    if not Seq or hasattr(Seq,"DiTauLowPtBuilder"+Seq.name()):
+        print("Low-pt ditau reconstruction will not be scheduled")
         return
 
+    print ("Adding low-pt di-tau reconstruction")
+
     from DerivationFrameworkJetEtMiss.ExtendedJetCommon import addCHSPFlowObjects
     addCHSPFlowObjects()
 
     from DerivationFrameworkJetEtMiss.JetCommon import addStandardJets
-    from DerivationFrameworkCore.DerivationFrameworkMaster import DerivationFrameworkJob
-    addStandardJets("AntiKt", 1.0, "EMPFlow", ptmin=40000, ptminFilter=50000, mods="pflow_ungroomed", calibOpt="none", algseq=DerivationFrameworkJob, outputGroup="TauCommon")
+    addStandardJets("AntiKt", 1.0, "EMPFlow", ptmin=40000, ptminFilter=50000, mods="pflow_ungroomed", calibOpt="none", algseq=Seq, outputGroup="TauCommon")
 
     import DiTauRec.DiTauAlgorithmsHolder as DiTauAlgs
     from DiTauRec.DiTauRecConf import DiTauBuilder
@@ -156,17 +174,18 @@ def addDiTauLowPt():
     ditauTools.append(DiTauAlgs.getSeedJetBuilder("AntiKt10EMPFlowJets"))
     ditauTools.append(DiTauAlgs.getElMuFinder())
     ditauTools.append(DiTauAlgs.getSubjetBuilder())
+    Seq += DiTauAlgs.getTVATool()
     ditauTools.append(DiTauAlgs.getVertexFinder())
     ditauTools.append(DiTauAlgs.getDiTauTrackFinder())
     ditauTools.append(DiTauAlgs.getIDVarCalculator(False))
 
+    from AthenaCommon.AppMgr import ToolSvc
     for tool in ditauTools:
         if not hasattr(ToolSvc,tool.name()):
             ToolSvc += tool            
     
-    DiTauLowPtBuilder = DiTauBuilder(name="DFCommonDiTauLowPtBuilder",
+    DiTauLowPtBuilder = DiTauBuilder(name="DiTauLowPtBuilder"+Seq.name(),
                                      DiTauContainer="DiTauJetsLowPt",
-                                     DiTauAuxContainer="DiTauJetsLowPtAux.",
                                      SeedJetName="AntiKt10EMPFlowJets",
                                      minPt=50000,
                                      maxEta=2.5,
@@ -174,8 +193,4 @@ def addDiTauLowPt():
                                      Rsubjet=0.2,
                                      Rcore=0.1,
                                      Tools=ditauTools)
-    ToolSvc += DiTauLowPtBuilder
-    DerivationFrameworkJob += DiTauLowPtBuilder
-
-    print ("Low-pt di-tau building has been scheduled")
-'''
+    Seq += DiTauLowPtBuilder
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkTau/python/TauJetsCPContent.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkTau/python/TauJetsCPContent.py
index 7fc38cbb54c..4892bc607d8 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkTau/python/TauJetsCPContent.py
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkTau/python/TauJetsCPContent.py
@@ -5,7 +5,7 @@ TauJetsCPContent = [
 "InDetTrackParticles",
 "InDetTrackParticlesAux.phi.vertexLink.theta.qOverP.truthParticleLink.truthMatchProbability",
 "TauJets",
-"TauJetsAux.pt.eta.phi.m.tauTrackLinks.jetLink.vertexLink.charge.isTauFlags.BDTJetScore.BDTEleScore.ptFinalCalib.etaFinalCalib.phiFinalCalib.mFinalCalib.electronLink.EleMatchLikelihoodScore.pt_combined.eta_combined.phi_combined.m_combined.BDTJetScoreSigTrans.BDTEleScoreSigTrans.PanTau_DecayMode.RNNJetScore.RNNJetScoreSigTrans.seedJetWidth.seedJetJvt.BDTEleScore_retuned.BDTEleScoreSigTrans_retuned.BDTEleLoose_retuned.BDTEleMedium_retuned.BDTEleTight_retuned.seedTrackWidthPt1000.seedTrackWidthPt500.truthParticleLink.truthJetLink",
+"TauJetsAux.pt.eta.phi.m.tauTrackLinks.jetLink.vertexLink.charge.isTauFlags.BDTJetScore.BDTEleScore.ptFinalCalib.etaFinalCalib.phiFinalCalib.mFinalCalib.electronLink.EleMatchLikelihoodScore.pt_combined.eta_combined.phi_combined.m_combined.BDTJetScoreSigTrans.BDTEleScoreSigTrans.PanTau_DecayMode.RNNJetScore.RNNJetScoreSigTrans.seedJetWidth.seedJetJvt.seedTrackWidthPt1000.seedTrackWidthPt500.truthParticleLink.truthJetLink",
 "TauTracks",
 "TauTracksAux.pt.eta.phi.flagSet.trackLinks",
 "TruthTaus",
diff --git a/Reconstruction/DiTauRec/python/DiTauAlgorithmsHolder.py b/Reconstruction/DiTauRec/python/DiTauAlgorithmsHolder.py
index d85146415b2..914480beeed 100644
--- a/Reconstruction/DiTauRec/python/DiTauAlgorithmsHolder.py
+++ b/Reconstruction/DiTauRec/python/DiTauAlgorithmsHolder.py
@@ -88,11 +88,11 @@ def getElMuFinder():
     return ElMuFinder
 
 
-def setupTJVFTool():
-    from AthenaCommon.AppMgr import ToolSvc
+def getTVATool():
+    _name = sPrefix + 'TVATool'
 
-    from JetRec.JetRecConf import JetAlgorithm
-    jetTrackAlg = JetAlgorithm("JetTrackAlg_forDiTaus")
+    if _name in cached_instances:
+        return cached_instances[_name]
 
     from JetRecTools.JetRecToolsConf import TrackVertexAssociationTool
     TVATool = TrackVertexAssociationTool("TVATool_forDiTaus",
@@ -102,23 +102,24 @@ def setupTJVFTool():
                                          MaxTransverseDistance=2.5,  # in mm
                                          MaxLongitudinalDistance=2  # in mm
                                          )
-
+    from AthenaCommon.AppMgr import ToolSvc
     ToolSvc += TVATool
+
+    from JetRec.JetRecConf import JetAlgorithm
+    jetTrackAlg = JetAlgorithm(name=_name)
     jetTrackAlg.Tools = [TVATool]
 
-    from AthenaCommon.AlgSequence import AlgSequence
-    topSequence = AlgSequence()
-    topSequence += jetTrackAlg
+    cached_instances[_name] = jetTrackAlg
+    return jetTrackAlg
 
 
+# requires getTVATool
 def getVertexFinder():
     _name = sPrefix + 'VertexFinder'
 
     if _name in cached_instances:
         return cached_instances[_name]
 
-    setupTJVFTool()
-
     from DiTauRec.DiTauRecConf import VertexFinder
     VertexFinder = VertexFinder(name=_name,
                                 PrimVtxContainerName="PrimaryVertices",
diff --git a/Reconstruction/DiTauRec/python/DiTauBuilder.py b/Reconstruction/DiTauRec/python/DiTauBuilder.py
index cf154424823..c41f0c7b49c 100644
--- a/Reconstruction/DiTauRec/python/DiTauBuilder.py
+++ b/Reconstruction/DiTauRec/python/DiTauBuilder.py
@@ -52,12 +52,11 @@ class DiTauBuilder(Configured):
         from InDetRecExample.InDetJobProperties import InDetFlags
         from JetRec.JetRecFlags import jetFlags
         if (InDetFlags.doVertexFinding() and jetFlags.useTracks()) or diTauFlags.doVtxFinding:
+            topSequence += DiTauAlgs.getTVATool()
             tools.append(DiTauAlgs.getVertexFinder())
-            pass
         tools.append(DiTauAlgs.getDiTauTrackFinder())
         if diTauFlags.doCellFinding:
             tools.append(DiTauAlgs.getCellFinder(self.write_jet_cells, self.write_subjet_cells))
-            pass
 
         if not diTauFlags.doCellFinding:
             self.use_cells = False
-- 
GitLab