From 39bb81db3558bc88ffff5093891098208ea746a7 Mon Sep 17 00:00:00 2001
From: Goetz Gaycken <goetz.gaycken@cern.ch>
Date: Sun, 18 Feb 2018 17:36:57 +0100
Subject: [PATCH] Moved common definitions to common job options file.

Also use helper methods to create standard jets, and removed FlavTagInit
calls.


Former-commit-id: 228aaa4cdeee38e366befe980f8b835e0abe31a8
---
 .../python/HIGG2D4ExtraContent.py             |  26 +-
 .../python/HIGG5Common.py                     | 228 ++++++++++++++++++
 .../python/HIGG5D1ExtraContent.py             |  39 +--
 .../python/HIGG5D2ExtraContent.py             |  33 +--
 .../python/HIGG5D3ExtraContent.py             |  31 +--
 .../DerivationFrameworkHiggs/share/HIGG2D4.py | 134 ++--------
 .../DerivationFrameworkHiggs/share/HIGG5D1.py | 145 ++---------
 .../DerivationFrameworkHiggs/share/HIGG5D2.py | 212 +++-------------
 .../DerivationFrameworkHiggs/share/HIGG5D3.py |  97 +-------
 9 files changed, 353 insertions(+), 592 deletions(-)
 create mode 100644 PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG5Common.py

diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG2D4ExtraContent.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG2D4ExtraContent.py
index d8c2bcdb556..b28442857b0 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG2D4ExtraContent.py
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG2D4ExtraContent.py
@@ -2,27 +2,17 @@
 
 #Content included in addition to the Smart Slimming Content
 
-HIGG2D4ExtraContent=[
-    "egammaClusters.rawE.phi_sampl.calM",
+import HIGG5Common
+ExtraContent=HIGG5Common.getHIGG5Common()
+ExtraContent+=[
     "GSFTrackParticles.expectNextToInnermostPixelLayerHit.numberOfNextToInnermostPixelLayerHits.numberOfNextToInnermostPixelLayerOutliers",
     "Muons.quality.etcone20.etcone30.etcone40",
     "ExtrapolatedMuonTrackParticles.numberOfTRTHits.numberOfTRTOutliers",
-    "AntiKt4EMTopoJets.JetEMScaleMomentum_pt.JetEMScaleMomentum_eta.JetEMScaleMomentum_phi.JetEMScaleMomentum_m.GhostTrackCount.TrackWidthPt500.DetectorEta",
-    "AntiKt4EMTopoJets.DFCommonJets_Calib_pt.DFCommonJets_Calib_eta.DFCommonJets_Calib_phi.DFCommonJets_Calib_m",
-    "AntiKt4LCTopoJets.TrackWidthPt500.TrackCount.GhostTrackCount",
-    "TauJets.IsTruthMatched.truthJetLink.truthParticleLink.ptDetectorAxis.etaDetectorAxis.phiDetectorAxis.mDetectorAxis",
-    "BTagging_AntiKt4EMTopo.MV2cl100_discriminant",
-    "BTagging_AntiKtVR30Rmax4Rmin02Track.MV2c10_discriminant.MV2c10mu_discriminant.MV2c10rnn_discriminant.MV2cl100_discriminant.DL1_pu.DL1_pc.DL1_pb.DL1mu_pu.DL1mu_pc.DL1mu_pb.DL1rnn_pu.DL1rnn_pc.DL1rnn_pb"]
+    "BTagging_AntiKtVR30Rmax4Rmin02Track.MV2c10_discriminant.MV2c10mu_discriminant.MV2c10rnn_discriminant.MV2cl100_discriminant.DL1_pu.DL1_pc.DL1_pb.DL1mu_pu.DL1mu_pc.DL1mu_pb.DL1rnn_pu.DL1rnn_pc.DL1rnn_pb"
+]
 
-HIGG2D4ExtraContentTruth=[]
+ExtraContentTruth=HIGG5Common.getHIGG5CommonTruth()
 
-HIGG2D4ExtraContainers=[
-    "CaloCalTopoClusters",
-    "TauChargedParticleFlowObjects",
-    "AntiKtVR30Rmax4Rmin02TrackJets"]
+ExtraContainers=[]
 
-HIGG2D4ExtraContainersTruth=[
-    "TruthEvents",
-    "TruthParticles",
-    "TruthVertices",
-    "MuonTruthParticles"]
+ExtraContainersTruth=[]
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG5Common.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG5Common.py
new file mode 100644
index 00000000000..48c93009290
--- /dev/null
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG5Common.py
@@ -0,0 +1,228 @@
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+
+# commont content for Hbb DAODs
+# will impact content of HIGG5D1, HIGG5D2, HIGG5D3, HIGG2D4
+
+def getHIGG5Common() :
+    return [
+        "egammaClusters.rawE.phi_sampl.calM",
+        "Muons.clusterLink.EnergyLoss.energyLossType",
+        "TauJets.IsTruthMatched.truthJetLink.truthParticleLink.ptDetectorAxis.etaDetectorAxis.phiDetectorAxis.mDetectorAxis",
+        ("AntiKt4EMTopoJets.TrackWidthPt500.GhostTrackCount.Jvt.JvtJvfcorr.JvtRpt"
+           ".JetEMScaleMomentum_pt.JetEMScaleMomentum_eta.JetEMScaleMomentum_phi.JetEMScaleMomentum_m.DetectorEta"
+           ".DFCommonJets_Calib_pt.DFCommonJets_Calib_eta.DFCommonJets_Calib_phi.DFCommonJets_Calib_m"),
+        ("AntiKtVR30Rmax4Rmin02TrackJets.-JetConstitScaleMomentum_pt.-JetConstitScaleMomentum_eta.-JetConstitScaleMomentum_phi.-JetConstitScaleMomentum_m"
+            ".-constituentLinks.-constituentWeight.-ConstituentScale"),
+        "AntiKt10LCTopoJets.GhostVR30Rmax4Rmin02TrackJet",
+        "BTagging_AntiKtVR30Rmax4Rmin02Track.MV2c10_discriminant",
+        "BTagging_AntiKt4EMTopo.MV2cl100_discriminant",
+        "CaloCalTopoClusters.CENTER_MAG.calE.calEta.calM.calPhi.calPt.e_sampl.etaCalo.eta_sampl.phiCalo.phi_sampl.rawE.rawEta.rawM.rawPhi",
+        "TauChargedParticleFlowObjects.bdtPi0Score.e.eta.m.phi.pt.rapidity"
+        ]
+
+def getHIGG5CommonTruth() :
+    return [
+        "AntiKt4EMTopoJets.ConeTruthLabelID",
+        "TruthEvents.PDFID1.PDFID2.PDGID1.PDGID2.Q.X1.X2.XF1.XF2.weights.crossSection.crossSectionError.truthParticleLinks",
+        "TruthVertices.barcode.x.y.z.t.id.incomingParticleLinks.outgoingParticleLinks",
+         # "TruthParticles.px.py.pz.e.m.decayVtxLink.prodVtxLink.barcode.pdgId.status.TopHadronOriginFlag.classifierParticleOrigin.classifierParticleType.classifierParticleOutCome.dressedPhoton.polarizationTheta.polarizationPhi",
+        ("TruthParticles.px.py.pz.e.m.decayVtxLink.prodVtxLink.barcode.pdgId.status.TopHadronOriginFlag"
+            ".classifierParticleOrigin.classifierParticleType.classifierParticleOutCome"
+            ".dressedPhoton.polarizationPhi.polarizationTheta"
+            ".truthOrigin.truthParticleLink.truthType"),
+        "MuonTruthParticles.barcode.decayVtxLink.e.m.pdgId.prodVtxLink.px.py.pz.recoMuonLink.status.truthOrigin.truthParticleLink.truthType"
+        ]
+
+def filterContentList(pattern, content_list) :
+    result=[]
+    import re
+    pat=re.compile(pattern)
+    for elm in content_list :
+        head=elm.split('.',2)[0]
+        if pat.match(head) :
+            result.append(elm)
+    return result
+
+# --- common thinning tools
+def getTruthThinningTool(tool_prefix, thinning_helper) :
+    from DerivationFrameworkCore.DerivationFrameworkMaster import DerivationFrameworkIsMonteCarlo
+    if not DerivationFrameworkIsMonteCarlo :
+        return None
+    # MC truth thinning (not for data)
+    truth_cond_WZH    = "((abs(TruthParticles.pdgId) >= 23) && (abs(TruthParticles.pdgId) <= 25))" # W, Z and Higgs
+    truth_cond_Lepton = "((abs(TruthParticles.pdgId) >= 11) && (abs(TruthParticles.pdgId) <= 16))" # Leptons
+    truth_cond_Quark  = "((abs(TruthParticles.pdgId) ==  6) || (abs(TruthParticles.pdgId) ==  5))" # Top quark and Bottom quark
+    truth_cond_Photon = "((abs(TruthParticles.pdgId) == 22) && (TruthParticles.pt > 1*GeV))"       # Photon
+    truth_expression = '('+truth_cond_WZH+' || '+truth_cond_Lepton +' || '+truth_cond_Quark +' || '+truth_cond_Photon+')'
+    from DerivationFrameworkMCTruth.DerivationFrameworkMCTruthConf import DerivationFramework__GenericTruthThinning
+    MCThinningTool = DerivationFramework__GenericTruthThinning(
+        name                         = tool_prefix + "MCThinningTool",
+        ThinningService              = thinning_helper.ThinningSvc(),
+        ParticleSelectionString      = truth_expression,
+        PreserveDescendants          = False,
+        PreserveGeneratorDescendants = True,
+        PreserveAncestors            = True)
+    from AthenaCommon.AppMgr import ToolSvc
+    ToolSvc += MCThinningTool
+    return MCThinningTool
+
+def getInDetTrackParticleThinning(tool_prefix, thinning_helper, **kwargs) :
+    kwargs.setdefault('name',                   tool_prefix + 'TPThinningTool')
+    kwargs.setdefault('ThinningService',        thinning_helper.ThinningSvc())
+    kwargs.setdefault('SelectionString',        '( abs(InDetTrackParticles.d0) < 2 ) && ( abs(DFCommonInDetTrackZ0AtPV*sin(InDetTrackParticles.theta)) < 3 )')
+    kwargs.setdefault('InDetTrackParticlesKey', 'InDetTrackParticles')
+
+    from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__TrackParticleThinning
+    thinning_tool = DerivationFramework__TrackParticleThinning( name = kwargs.pop('name'), **kwargs)
+
+    from AthenaCommon.AppMgr import ToolSvc
+    ToolSvc += thinning_tool
+    return thinning_tool
+
+def getMuonTrackParticleThinning(tool_prefix, thinning_helper) :
+    from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__MuonTrackParticleThinning
+    thinning_tool = DerivationFramework__MuonTrackParticleThinning(name                   = tool_prefix + "MuonTPThinningTool",
+                                                                   ThinningService        = thinning_helper.ThinningSvc(),
+                                                                   MuonKey                = "Muons",
+                                                                   InDetTrackParticlesKey = "InDetTrackParticles")
+    from AthenaCommon.AppMgr import ToolSvc
+    ToolSvc += thinning_tool
+    return thinning_tool
+
+def getEgammaTrackParticleThinning(tool_prefix, thinning_helper, **kwargs) :
+    from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__EgammaTrackParticleThinning
+    kwargs.setdefault( 'name',                  tool_prefix + "ElectronTPThinningTool")
+    kwargs.setdefault( 'ThinningService',       thinning_helper.ThinningSvc())
+    kwargs.setdefault( 'SGKey',                 'Electrons')
+    kwargs.setdefault( 'InDetTrackParticlesKey','InDetTrackParticles')
+    kwargs.setdefault( 'BestMatchOnly',         True)
+
+    thinning_tool =  DerivationFramework__EgammaTrackParticleThinning(name  = kwargs.pop('name'),
+                                                                  **kwargs)
+    from AthenaCommon.AppMgr import ToolSvc
+    ToolSvc+= thinning_tool
+    return thinning_tool
+
+def getElectronTrackParticleThinning(tool_prefix, thinning_helper, **kwargs) :
+    kwargs.setdefault( 'name',                  tool_prefix + "ElectronTPThinningTool")
+    kwargs.setdefault( 'SGKey','Electrons')
+    return getEgammaTrackParticleThinning(tool_prefix, thinning_helper,**kwargs)
+
+
+def getPhotonTrackParticleThinning(tool_prefix, thinning_helper, **kwargs) :
+    kwargs.setdefault( 'name', tool_prefix + "PhotonTPThinningTool")
+    kwargs.setdefault( 'SGKey','Photons')
+    return getEgammaTrackParticleThinning(tool_prefix, thinning_helper,**kwargs)
+
+def getJetTrackParticleThinning(tool_prefix, thinning_helper, **kwargs) :
+    from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__JetTrackParticleThinning
+    kwargs.setdefault( 'name',                  tool_prefix + "JetTPThinningTool")
+    kwargs.setdefault( 'ThinningService',       thinning_helper.ThinningSvc())
+    kwargs.setdefault( 'JetKey',                'AntiKt4EMTopoJets')
+    kwargs.setdefault( 'InDetTrackParticlesKey','InDetTrackParticles')
+
+    thinning_tool = DerivationFramework__JetTrackParticleThinning(name  = kwargs.pop('name'),
+                                                                  **kwargs)
+    from AthenaCommon.AppMgr import ToolSvc
+    ToolSvc+= thinning_tool
+    return thinning_tool
+
+def getAntiKt4EMTopoTrackParticleThinning(tool_prefix, thinning_helper, **kwargs) :
+    kwargs.setdefault( 'name',tool_prefix + 'AntiKt4EMTopoJetTPThinningTool')
+    kwargs.setdefault( 'JetKey','AntiKt4EMTopoJets')
+    return getJetTrackParticleThinning(tool_prefix, thinning_helper, **kwargs)
+
+def getAntiKt10LCTopoTrackParticleThinning(tool_prefix, thinning_helper, **kwargs) :
+    kwargs.setdefault( 'name', tool_prefix + 'AntiKt10LCTopoJetTPThinningTool')
+    kwargs.setdefault( 'JetKey',         'AntiKt10LCTopoJets')
+    kwargs.setdefault( 'SelectionString','(AntiKt10LCTopoJets.pt > 100*GeV && abs(AntiKt10LCTopoJets.eta)<2.6)')
+    kwargs.setdefault( 'ApplyAnd',       True)
+    return getJetTrackParticleThinning(tool_prefix, thinning_helper, **kwargs)
+
+def getTCCTrackParticleThinning(tool_prefix, thinning_helper) :
+    # Tracks and CaloClusters associated with TCCs
+    from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__TCCTrackParticleThinning
+    thinning_tool = DerivationFramework__TCCTrackParticleThinning(name                         = tool_prefix + "TCCTPThinningTool",
+                                                                  ThinningService              = thinning_helper.ThinningSvc(),
+                                                                  JetKey                       = "AntiKt10TrackCaloClusterJets",
+                                                                  TCCKey                       = "TrackCaloClustersCombinedAndNeutral",
+                                                                  InDetTrackParticlesKey       = "InDetTrackParticles",
+                                                                  CaloCalTopoClustersKey       = "CaloCalTopoClusters",
+                                                                  ThinOriginCorrectedClusters  = True,
+                                                                  SelectionString              = "AntiKt10TrackCaloClusterJets.pt>100*GeV && abs(AntiKt10TrackCaloClusterJets.eta)<2.6",
+                                                                  OriginCaloCalTopoClustersKey = "LCOriginTopoClusters")
+    from AthenaCommon.AppMgr import ToolSvc
+    ToolSvc+= thinning_tool
+    return thinning_tool
+
+
+def getTauTrackParticleThinning(tool_prefix, thinning_helper) :
+    # Tracks associated with taus
+    from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__TauTrackParticleThinning
+    thinning_tool = DerivationFramework__TauTrackParticleThinning(name                   = tool_prefix + "TauTPThinningTool",
+                                                                  ThinningService        = thinning_helper.ThinningSvc(),
+                                                                  TauKey                 = "TauJets",
+                                                                  ConeSize               = 0.6,
+                                                                  InDetTrackParticlesKey = "InDetTrackParticles")
+    from AthenaCommon.AppMgr import ToolSvc
+    ToolSvc+= thinning_tool
+    return thinning_tool
+
+
+def getTauCaloClusterThinning(tool_prefix, thinning_helper) :
+    # calo cluster thinning
+    from DerivationFrameworkCalo.DerivationFrameworkCaloConf import DerivationFramework__CaloClusterThinning
+    thinning_tool = DerivationFramework__CaloClusterThinning(name                  = tool_prefix + "TauCCThinningTool",
+                                                             ThinningService       = thinning_helper.ThinningSvc(),
+                                                             SGKey                 = "TauJets",
+                                                            TopoClCollectionSGKey = "CaloCalTopoClusters")
+    from AthenaCommon.AppMgr import ToolSvc
+    ToolSvc+= thinning_tool
+    return thinning_tool
+
+def getJetCaloClusterThinning(tool_prefix, thinning_helper, **kwargs) :
+    if 'SGKey' not in kwargs :
+        raise Exception('getJetCaloClusterThinning called without providing the keyword argument SGKey')
+
+    from DerivationFrameworkCalo.DerivationFrameworkCaloConf import DerivationFramework__JetCaloClusterThinning
+    kwargs.setdefault('name',                 tool_prefix + 'FatjetCCThinningTool')
+    kwargs.setdefault('ThinningService',      thinning_helper.ThinningSvc())
+    kwargs.setdefault('TopoClCollectionSGKey','CaloCalTopoClusters')
+    kwargs.setdefault('ApplyAnd',             True)
+    thinning_tool = DerivationFramework__JetCaloClusterThinning(name                  = kwargs.pop('name'), **kwargs)
+
+    from AthenaCommon.AppMgr import ToolSvc
+    ToolSvc+= thinning_tool
+    return thinning_tool
+
+def getAntiKt10LCTopoCaloClusterThinning(tool_prefix, thinning_helper, **kwargs) :
+    kwargs.setdefault('name',                 tool_prefix + 'AntiKt10LCTopoCaloClusterThinningTool')
+    kwargs.setdefault('SGKey',                'AntiKt10LCTopoJets')
+    kwargs.setdefault('SelectionString',      '(AntiKt10LCTopoJets.pt > 100*GeV && abs(AntiKt10LCTopoJets.eta)<2.6)')
+    return getJetCaloClusterThinning(tool_prefix, thinning_helper, **kwargs)
+
+def getAntiKt10LCTopoTrimmedPtFrac5SmallR20Thinning(tool_prefix, thinning_helper) :
+    from DerivationFrameworkTools.DerivationFrameworkToolsConf import DerivationFramework__GenericObjectThinning
+    thinning_tool = DerivationFramework__GenericObjectThinning( name             = tool_prefix + "LargeRJetThinningTool",
+                                                                ThinningService  = thinning_helper.ThinningSvc(),
+                                                                ContainerName    = "AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets",
+                                                                SelectionString  = "(AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets.pt > 100*GeV && abs(AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets.eta)<2.6)",
+                                                                ApplyAnd         = False)
+    from AthenaCommon.AppMgr import ToolSvc
+    ToolSvc+= thinning_tool
+    return thinning_tool
+
+def getAntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20Thinning(tool_prefix, thinning_helper) :
+    from DerivationFrameworkTools.DerivationFrameworkToolsConf import DerivationFramework__GenericObjectThinning
+    thinning_tool =DerivationFramework__GenericObjectThinning( name             = tool_prefix + "TCCJetThinningTool",
+                                                               ThinningService  = thinning_helper.ThinningSvc(),
+                                                               ContainerName    = "AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20Jets",
+                                                               SelectionString  = "(AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20Jets.pt > 100*GeV && abs(AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20Jets.eta)<2.6)",
+                                                               ApplyAnd         = False)
+    from AthenaCommon.AppMgr import ToolSvc
+    ToolSvc+= thinning_tool
+    return thinning_tool
+
+def addTrimmedTruthWZJets(sequence, output_group) :
+    from DerivationFrameworkJetEtMiss.JetCommon import addTrimmedJets
+    addTrimmedJets("AntiKt", 1.0, "TruthWZ", rclus=0.2, ptfrac=0.05, mods="groomed", includePreTools=False, algseq=sequence,outputGroup=output_group)
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG5D1ExtraContent.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG5D1ExtraContent.py
index b32f30dd4a5..73bfe12ccd6 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG5D1ExtraContent.py
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG5D1ExtraContent.py
@@ -2,38 +2,13 @@
 
 #Content included in addition to the Smart Slimming Content
 
-ExtraContent=[
-    "egammaClusters.rawE.phi_sampl.calM",
-    "Muons.clusterLink.EnergyLoss.energyLossType",
-    "AntiKt4EMTopoJets.TrackWidthPt500.GhostTrackCount.Jvt.JvtJvfcorr.JvtRpt",
-    "AntiKt4EMTopoJets.JetEMScaleMomentum_pt.JetEMScaleMomentum_eta.JetEMScaleMomentum_phi.JetEMScaleMomentum_m.DetectorEta",
-    "AntiKt4EMTopoJets.DFCommonJets_Calib_pt.DFCommonJets_Calib_eta.DFCommonJets_Calib_phi.DFCommonJets_Calib_m",
-    "Photons.f3core",
-    "TauJets.IsTruthMatched.truthJetLink.truthParticleLink.ptDetectorAxis.etaDetectorAxis.phiDetectorAxis.mDetectorAxis",
-    "BTagging_AntiKt4EMTopo.MV2cl100_discriminant",
-    "BTagging_AntiKtVR30Rmax4Rmin02Track.MV2c10_discriminant",
-    "AntiKtVR30Rmax4Rmin02TrackJets.-JetConstitScaleMomentum_pt.-JetConstitScaleMomentum_eta.-JetConstitScaleMomentum_phi.-JetConstitScaleMomentum_m.-constituentLinks.-constituentWeight.-ConstituentScale",
-    "AntiKt10LCTopoJets.GhostVR30Rmax4Rmin02TrackJet",
-     #  "AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20JetsAux.pt.eta.phi.m.constituentLinks.JetConstitScaleMomentum_pt.JetConstitScaleMomentum_eta.JetConstitScaleMomentum_phi.JetConstitScaleMomentum_m.Parent.GhostTrackCount.GhostMuonSegmentCount.DetectorEta.ECF1.ECF2.ECF3.Tau1_wta.Tau2_wta.Tau3_wta"
-    "AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20JetsAux.pt.eta.phi.m.constituentLinks.JetConstitScaleMomentum_pt.JetConstitScaleMomentum_eta.JetConstitScaleMomentum_phi.JetConstitScaleMomentum_m.Angularity.Aplanarity.DetectorEta.ECF1.ECF2.ECF3.FoxWolfram0.FoxWolfram2.GhostMuonSegmentCount.GhostTrackCount.KtDR.Parent.PlanarFlow.Qw.Split12.Split23.Tau1_wta.Tau2_wta.Tau3_wta.ZCut12",
-#     "AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20JetsAux.Angularity.Aplanarity.DetectorEta.ECF1.ECF2.ECF3.FoxWolfram0.FoxWolfram2.GhostMuonSegmentCount.GhostTrackCount.JetConstitScaleMomentum_eta.JetConstitScaleMomentum_m.JetConstitScaleMomentum_phi.JetConstitScaleMomentum_pt.KtDR.Parent.PlanarFlow.Qw.Split12.Split23.Tau1_wta.Tau2_wta.Tau3_wta.ZCut12.constituentLinks.eta.m.phi.pt"
-
-      "CaloCalTopoClusters.CENTER_MAG.calE.calEta.calM.calPhi.calPt.e_sampl.etaCalo.eta_sampl.phiCalo.phi_sampl.rawE.rawEta.rawM.rawPhi"
-    ]
-#    "BTagging_AntiKt2Track.DL1_pc.DL1_pb.DL1_pu.DL1mu_pu.DL1mu_pc.DL1mu_pb.DL1rnn_pu.DL1rnn_pb.DL1rnn_pc.MV2cl100_discriminant.MV2c100_discriminant.MV2c10mu_discriminant.MV2c10_discriminant.MV2c10rnn_discriminant",
-
-ExtraContentTruth=[
-    "AntiKt4EMTopoJets.ConeTruthLabelID"
+import HIGG5Common
+ExtraContent=HIGG5Common.getHIGG5Common()
+ExtraContent+=[
+    "Photons.f3core"
     ]
 
-ExtraContainers=[
-#     "MuonSegments",
-#    "CaloCalTopoClusters",
-    "TauChargedParticleFlowObjects"
-    ]
+ExtraContentTruth=HIGG5Common.getHIGG5CommonTruth()
 
-ExtraContainersTruth=[
-    "TruthEvents",
-    "TruthParticles",
-    "TruthVertices",
-    "MuonTruthParticles"]
+ExtraContainers=[]
+ExtraContainersTruth=[]
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG5D2ExtraContent.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG5D2ExtraContent.py
index f6354262f1e..4df7f2e2021 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG5D2ExtraContent.py
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG5D2ExtraContent.py
@@ -2,32 +2,15 @@
 
 #Content included in addition to the Smart Slimming Content
 
-ExtraContent=[
-    "egammaClusters.rawE.phi_sampl.calM",
-    "Muons.clusterLink.EnergyLoss.energyLossType",
-    "AntiKt4EMTopoJets.TrackWidthPt500.GhostTrackCount.Jvt.JvtJvfcorr.JvtRpt",
-    "AntiKt4EMTopoJets.JetEMScaleMomentum_pt.JetEMScaleMomentum_eta.JetEMScaleMomentum_phi.JetEMScaleMomentum_m.DetectorEta",
-    "AntiKt4EMTopoJets.DFCommonJets_Calib_pt.DFCommonJets_Calib_eta.DFCommonJets_Calib_phi.DFCommonJets_Calib_m",
-    "Photons.f3core",
-    "TauJets.IsTruthMatched.truthJetLink.truthParticleLink.ptDetectorAxis.etaDetectorAxis.phiDetectorAxis.mDetectorAxis",
-    "BTagging_AntiKt4EMTopo.MV2cl100_discriminant",
-    "BTagging_AntiKtVR30Rmax4Rmin02Track.MV2c10_discriminant",
-    "AntiKtVR30Rmax4Rmin02TrackJets.-JetConstitScaleMomentum_pt.-JetConstitScaleMomentum_eta.-JetConstitScaleMomentum_phi.-JetConstitScaleMomentum_m.-constituentLinks.-constituentWeight.-ConstituentScale",
-    "AntiKt10LCTopoJets.GhostVR30Rmax4Rmin02TrackJet"
+import HIGG5Common
+ExtraContent=HIGG5Common.getHIGG5Common()
+ExtraContent+=[
+   "AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20Jets.pt.eta.phi.m.constituentLinks.JetConstitScaleMomentum_pt.JetConstitScaleMomentum_eta.JetConstitScaleMomentum_phi.JetConstitScaleMomentum_m.Angularity.Aplanarity.DetectorEta.ECF1.ECF2.ECF3.FoxWolfram0.FoxWolfram2.GhostMuonSegmentCount.GhostTrackCount.KtDR.Parent.PlanarFlow.Qw.Split12.Split23.Tau1_wta.Tau2_wta.Tau3_wta.ZCut12",
+    "Photons.f3core"
    ]
 
-ExtraContentTruth=[
-    "AntiKt4EMTopoJets.ConeTruthLabelID"
-    ]
+ExtraContentTruth=HIGG5Common.getHIGG5CommonTruth()
 
-ExtraContainers=[
-    "MuonSegments",
-    "CaloCalTopoClusters",
-    "TauChargedParticleFlowObjects"
-    ]
+ExtraContainers=[]
 
-ExtraContainersTruth=[
-    "TruthEvents",
-    "TruthParticles",
-    "TruthVertices",
-    "MuonTruthParticles"]
+ExtraContainersTruth=[]
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG5D3ExtraContent.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG5D3ExtraContent.py
index 287e37bdb5d..739d2268c60 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG5D3ExtraContent.py
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/python/HIGG5D3ExtraContent.py
@@ -2,30 +2,15 @@
 
 #Content included in addition to the Smart Slimming Content
 
-ExtraContent=[
-    "Muons.clusterLink.EnergyLoss.energyLossType",
-    "AntiKt4EMTopoJets.TrackWidthPt500.GhostTrackCount.Jvt.JvtJvfcorr.JvtRpt",
-    "AntiKt4EMTopoJets.JetEMScaleMomentum_pt.JetEMScaleMomentum_eta.JetEMScaleMomentum_phi.JetEMScaleMomentum_m.DetectorEta",
-    "AntiKt4EMTopoJets.DFCommonJets_Calib_pt.DFCommonJets_Calib_eta.DFCommonJets_Calib_phi.DFCommonJets_Calib_m",
-    "Photons.f3core",
-    "BTagging_AntiKt4EMTopo.MV2cl100_discriminant"]
+import HIGG5Common
+ExtraContent=HIGG5Common.filterContentList('Muons|AntiKt4EMTopoJets|Photons|BTagging_AntiKt4EMTopo',
+                                                  HIGG5Common.getHIGG5Common() )
+ExtraContent+=[
+    "Photons.f3core"
+    ]
 
-ExtraContentTruth=[
-    "AntiKt4EMTopoJets.ConeTruthLabelID"]
+ExtraContentTruth=HIGG5Common.getHIGG5CommonTruth()
 
 ExtraContainers=[]
-    #"BTagging_AntiKt10LCTopo",
-    #"xTrigDecision", # for xAOD::TrigDecision_v1
-    #"xTrigDecisionAux", # for xAOD::TrigDecisionAuxInfo_v1
-    #"TrigDecision", # for TrigDec::TrigDecision
-    #"HLT_TrigEFBjetContainer_EFBjetFex", # for TrigEFBjetContainer
-    #"HLT_TrigL2BjetContainer_L2BjetFex", # for TrigL2BjetContainer
-    #"HLT_JetCollection_TrigJetRec",
-    #"MuonSegments"]
 
-
-ExtraContainersTruth=[
-    "TruthEvents",
-    "TruthParticles",
-    "TruthVertices",
-    "MuonTruthParticles"]
+ExtraContainersTruth=[]
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG2D4.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG2D4.py
index a02b0d1f393..091a46cd3f6 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG2D4.py
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG2D4.py
@@ -43,106 +43,19 @@ HIGG2D4ThinningHelper = ThinningHelper("HIGG2D4ThinningHelper")
 HIGG2D4ThinningHelper.TriggerChains = 'HLT_e.*|HLT_2e.*|HLT_mu.*|HLT_2mu.*|HLT_xe.*|HLT_j.*|HLT_b.*' 
 HIGG2D4ThinningHelper.AppendToStream(HIGG2D4Stream) 
 
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__JetTrackParticleThinning
-HIGG2D4JetTPThinningTool2 = DerivationFramework__JetTrackParticleThinning(name                   = "HIGG2D4JetTPThinningTool2",
-                                                                          ThinningService        = HIGG2D4ThinningHelper.ThinningSvc(),
-                                                                          JetKey                 = "AntiKt4EMTopoJets",
-                                                                          InDetTrackParticlesKey = "InDetTrackParticles")
-ToolSvc += HIGG2D4JetTPThinningTool2
-thinningTools.append(HIGG2D4JetTPThinningTool2)
-
-# Tracks associated with Muons
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__MuonTrackParticleThinning
-HIGG2D4MuonTPThinningTool = DerivationFramework__MuonTrackParticleThinning(name                   = "HIGG2D4MuonTPThinningTool",
-                                                                           ThinningService        = HIGG2D4ThinningHelper.ThinningSvc(),
-                                                                           MuonKey                = "Muons",
-                                                                           InDetTrackParticlesKey = "InDetTrackParticles")
-ToolSvc += HIGG2D4MuonTPThinningTool
-thinningTools.append(HIGG2D4MuonTPThinningTool)
-
-# Tracks associated with Electrons
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__EgammaTrackParticleThinning
-HIGG2D4ElectronTPThinningTool = DerivationFramework__EgammaTrackParticleThinning(name                   = "HIGG2D4ElectronTPThinningTool",
-                                                                                 ThinningService        = HIGG2D4ThinningHelper.ThinningSvc(),
-                                                                                 SGKey                  = "Electrons",
-                                                                                 InDetTrackParticlesKey = "InDetTrackParticles",
-                                                                                 BestMatchOnly          = False)
-ToolSvc += HIGG2D4ElectronTPThinningTool
-thinningTools.append(HIGG2D4ElectronTPThinningTool)
-
-# Tracks associated with Photons
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__EgammaTrackParticleThinning
-HIGG2D4PhotonTPThinningTool = DerivationFramework__EgammaTrackParticleThinning(       name                    = "HIGG2D4PhotonTPThinningTool",
-                                                                                      ThinningService         = HIGG2D4ThinningHelper.ThinningSvc(),
-                                                                                      SGKey                   = "Photons",
-                                                                                      InDetTrackParticlesKey  = "InDetTrackParticles",
-                                                                                      BestMatchOnly           = True)
-ToolSvc += HIGG2D4PhotonTPThinningTool
-thinningTools.append(HIGG2D4PhotonTPThinningTool)
-
-# Tracks associated with taus
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__TauTrackParticleThinning
-HIGG2D4TauTPThinningTool = DerivationFramework__TauTrackParticleThinning(name                   = "HIGG2D4TauTPThinningTool",
-                                                                         ThinningService        = HIGG2D4ThinningHelper.ThinningSvc(),
-                                                                         TauKey                 = "TauJets",
-                                                                         ConeSize               = 0.6,
-                                                                         InDetTrackParticlesKey = "InDetTrackParticles")
-ToolSvc += HIGG2D4TauTPThinningTool
-thinningTools.append(HIGG2D4TauTPThinningTool)
-
-
-# calo cluster thinning
-from DerivationFrameworkCalo.DerivationFrameworkCaloConf import DerivationFramework__CaloClusterThinning
-HIGG2D4TauCCThinningTool = DerivationFramework__CaloClusterThinning(name                  = "HIGG2D4TauCCThinningTool",
-                                                                    ThinningService       = HIGG2D4ThinningHelper.ThinningSvc(),
-                                                                    SGKey                 = "TauJets",
-                                                                    TopoClCollectionSGKey = "CaloCalTopoClusters")
-ToolSvc += HIGG2D4TauCCThinningTool
-thinningTools.append(HIGG2D4TauCCThinningTool)
 
+import DerivationFrameworkHiggs.HIGG5Common as HIGG5Common
+thinningTools.append( HIGG5Common.getAntiKt4EMTopoTrackParticleThinning('HIGG2D4',HIGG2D4ThinningHelper) )
+thinningTools.append( HIGG5Common.getMuonTrackParticleThinning(         'HIGG2D4',HIGG2D4ThinningHelper) )
+thinningTools.append( HIGG5Common.getElectronTrackParticleThinning(     'HIGG2D4',HIGG2D4ThinningHelper,   BestMatchOnly=False) )
+thinningTools.append( HIGG5Common.getPhotonTrackParticleThinning(       'HIGG2D4',HIGG2D4ThinningHelper) )
+thinningTools.append( HIGG5Common.getTauTrackParticleThinning(          'HIGG2D4',HIGG2D4ThinningHelper) )
+thinningTools.append( HIGG5Common.getTauCaloClusterThinning(            'HIGG2D4',HIGG2D4ThinningHelper) )
 
 # Truth particles
-useGenericTruthThinning = True
-if useGenericTruthThinning:
-    truth_cond_WZH    = "((abs(TruthParticles.pdgId) >= 23) && (abs(TruthParticles.pdgId) <= 25))" # W, Z and Higgs
-    truth_cond_Lepton = "((abs(TruthParticles.pdgId) >= 11) && (abs(TruthParticles.pdgId) <= 16))" # Leptons
-    truth_cond_Quark  = "((abs(TruthParticles.pdgId) ==  6) || (abs(TruthParticles.pdgId) ==  5))" # Top or Bottom quark
-    truth_cond_Photon = "((abs(TruthParticles.pdgId) == 22) && (TruthParticles.pt > 1*GeV))"       # Photon
-
-    truth_expression = '('+truth_cond_WZH+' || '+truth_cond_Lepton +' || '+truth_cond_Quark +' || '+truth_cond_Photon+')'
-
-    from DerivationFrameworkMCTruth.DerivationFrameworkMCTruthConf import DerivationFramework__GenericTruthThinning
-    HIGG2D4TruthThinningTool = DerivationFramework__GenericTruthThinning(name                         = "HIGG2D4TruthThinningTool", 
-                                                                         ThinningService              = HIGG2D4ThinningHelper.ThinningSvc(),
-                                                                         ParticleSelectionString      = truth_expression,
-                                                                         PreserveDescendants          = False,
-                                                                         PreserveGeneratorDescendants = True,
-                                                                         PreserveAncestors            = True)
-else:
-    from DerivationFrameworkMCTruth.DerivationFrameworkMCTruthConf import DerivationFramework__MenuTruthThinning
-    HIGG2D4TruthThinningTool = DerivationFramework__MenuTruthThinning(name                         = "HIGG2D4TruthThinningTool",
-                                                                      ThinningService              = "HIGG2D4ThinningSvc",
-                                                                      WritePartons                 = False,
-                                                                      WriteHadrons                 = False,
-                                                                      WriteBHadrons                = True,
-                                                                      WriteGeant                   = False,
-                                                                      GeantPhotonPtThresh          = -1.0,
-                                                                      WriteTauHad                  = True,
-                                                                      PartonPtThresh               = -1.0,
-                                                                      WriteBSM                     = True,
-                                                                      WriteBosons                  = True,
-                                                                      WriteBSMProducts             = True,
-                                                                      WriteBosonProducts           = True,
-                                                                      WriteTopAndDecays            = True,
-                                                                      WriteEverything              = False,
-                                                                      WriteAllLeptons              = True,
-                                                                      WriteStatus3                 = False,
-                                                                      PreserveGeneratorDescendants = True,
-                                                                      WriteFirstN                  = -1)
-
 if DerivationFrameworkIsMonteCarlo:
-    ToolSvc += HIGG2D4TruthThinningTool
-    thinningTools.append(HIGG2D4TruthThinningTool)
+    thinningTools.append(HIGG5Common.getTruthThinningTool('HIGG2D4', HIGG2D4ThinningHelper))
+
 print "HIGG2D4.py thinningTools", thinningTools
 
 #====================================================================
@@ -310,24 +223,25 @@ higg2d4Seq += CfgMgr.DerivationFramework__DerivationKernel(
 if not "HIGG2D4Jets" in OutputJets:
     OutputJets["HIGG2D4Jets"] = []
 
-    reducedJetList = ["AntiKt2PV0TrackJets", "AntiKt4PV0TrackJets", "AntiKt10LCTopoJets"]
-    replaceAODReducedJets(reducedJetList, higg2d4Seq, "HIGG2D4Jets")
+    addAntiKt2PV0TrackJets(higg2d4Seq, 'HIGG2D4Jets')
+    addAntiKt4PV0TrackJets(higg2d4Seq, "HIGG2D4Jets")
+    addDefaultTrimmedJets(higg2d4Seq,"HIGG2D4");
 
-#====================================================================
-# Special jets
-#====================================================================
     if jetFlags.useTruth:
-          addTrimmedJets("AntiKt", 1.0, "TruthWZ", rclus=0.2, ptfrac=0.05, mods="groomed", includePreTools=False, algseq=higg2d4Seq,outputGroup="HIGG2D4Jets")
+      addAntiKt4TruthJets(higg2d4Seq, "HIGG2D4Jets")
+      addAntiKt4TruthWZJets(higg2d4Seq, "HIGG2D4Jets")
 
-    addDefaultTrimmedJets(higg2d4Seq,"HIGG2D4");
+      HIGG5Common.addTrimmedTruthWZJets(higg2d4Seq,'HIGG2D4Jets')
+      # reducedJetList = ["AntiKt2PV0TrackJets", "AntiKt4PV0TrackJets", "AntiKt10LCTopoJets"]
+      # replaceAODReducedJets(reducedJetList, higg2d4Seq, "HIGG2D4Jets")
 
 #====================================================================
 # Create variable-R trackjets and dress AntiKt10LCTopo with ghost VR-trkjet 
 #====================================================================
 
-addVRJets(higg2d4Seq, "AntiKtVR30Rmax4Rmin02Track", "GhostVR30Rmax4Rmin02TrackJet", 
-          VRJetAlg="AntiKt", VRJetRadius=0.4, VRJetInputs="pv0track", 
-          ghostArea = 0 , ptmin = 2000, ptminFilter = 7000, 
+addVRJets(higg2d4Seq, "AntiKtVR30Rmax4Rmin02Track", "GhostVR30Rmax4Rmin02TrackJet",
+          VRJetAlg="AntiKt", VRJetRadius=0.4, VRJetInputs="pv0track",
+          ghostArea = 0 , ptmin = 2000, ptminFilter = 7000,
           variableRMinRadius = 0.02, variableRMassScale = 30000, calibOpt = "none")
 
 #===================================================================
@@ -386,11 +300,11 @@ HIGG2D4SlimmingHelper.SmartCollections = ["Electrons",
                                           "InDetTrackParticles",
                                           "PrimaryVertices"]
 
-HIGG2D4SlimmingHelper.ExtraVariables = HIGG2D4ExtraContent
-HIGG2D4SlimmingHelper.AllVariables = HIGG2D4ExtraContainers
+HIGG2D4SlimmingHelper.ExtraVariables = ExtraContent
+HIGG2D4SlimmingHelper.AllVariables = ExtraContainers
 if DerivationFrameworkIsMonteCarlo:
-    HIGG2D4SlimmingHelper.ExtraVariables += HIGG2D4ExtraContentTruth
-    HIGG2D4SlimmingHelper.AllVariables += HIGG2D4ExtraContainersTruth
+    HIGG2D4SlimmingHelper.ExtraVariables += ExtraContentTruth
+    HIGG2D4SlimmingHelper.AllVariables += ExtraContainersTruth
 HIGG2D4SlimmingHelper.ExtraVariables += JetTagConfig.GetExtraPromptVariablesForDxAOD()
 
 # Add the jet containers to the stream
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG5D1.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG5D1.py
index f76014a000f..1eb6f5ea5c0 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG5D1.py
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG5D1.py
@@ -42,109 +42,27 @@ from DerivationFrameworkCore.ThinningHelper import ThinningHelper
 HIGG5D1ThinningHelper = ThinningHelper("HIGG5D1ThinningHelper") 
 #trigger navigation content
 HIGG5D1ThinningHelper.TriggerChains = 'HLT_xe.*|HLT_j.*|HLT_g.*' 
-HIGG5D1ThinningHelper.AppendToStream(HIGG5D1Stream) 
+HIGG5D1ThinningHelper.AppendToStream(HIGG5D1Stream)
 
+import DerivationFrameworkHiggs.HIGG5Common as HIGG5Common
+thinningTools.append( HIGG5Common.getAntiKt4EMTopoTrackParticleThinning('HIGG5D1',HIGG5D1ThinningHelper) )
+thinningTools.append( HIGG5Common.getMuonTrackParticleThinning(         'HIGG5D1',HIGG5D1ThinningHelper) )
+thinningTools.append( HIGG5Common.getElectronTrackParticleThinning(     'HIGG5D1',HIGG5D1ThinningHelper) )
+thinningTools.append( HIGG5Common.getPhotonTrackParticleThinning(       'HIGG5D1',HIGG5D1ThinningHelper) )
+thinningTools.append( HIGG5Common.getTauTrackParticleThinning(          'HIGG5D1',HIGG5D1ThinningHelper) )
+thinningTools.append( HIGG5Common.getTauCaloClusterThinning(            'HIGG5D1',HIGG5D1ThinningHelper) )
 
 # MC truth thinning (not for data)
-truth_cond_WZH    = "((abs(TruthParticles.pdgId) >= 23) && (abs(TruthParticles.pdgId) <= 25))" # W, Z and Higgs
-truth_cond_Lepton = "((abs(TruthParticles.pdgId) >= 11) && (abs(TruthParticles.pdgId) <= 16))" # Leptons
-truth_cond_Quark  = "((abs(TruthParticles.pdgId) ==  6) || (abs(TruthParticles.pdgId) ==  5))" # Top quark and Bottom quark
-truth_cond_Photon = "((abs(TruthParticles.pdgId) == 22) && (TruthParticles.pt > 1*GeV))"       # Photon
-truth_expression = '('+truth_cond_WZH+' || '+truth_cond_Lepton +' || '+truth_cond_Quark +' || '+truth_cond_Photon+')'
-from DerivationFrameworkMCTruth.DerivationFrameworkMCTruthConf import DerivationFramework__GenericTruthThinning
-HIGG5D1MCThinningTool = DerivationFramework__GenericTruthThinning(
-    name                         = "HIGG5D1MCThinningTool", 
-    ThinningService              = HIGG5D1ThinningHelper.ThinningSvc(),
-    ParticleSelectionString      = truth_expression,
-    PreserveDescendants          = False,
-    PreserveGeneratorDescendants = True,
-    PreserveAncestors            = True)
-
 if DerivationFrameworkIsMonteCarlo :
-    ToolSvc += HIGG5D1MCThinningTool
-    thinningTools.append(HIGG5D1MCThinningTool)
-
-# MET/Jet tracks
-# thinning_expression = "(InDetTrackParticles.pt > 0.5*GeV) && (InDetTrackParticles.numberOfPixelHits > 0) && (InDetTrackParticles.numberOfSCTHits > 5) && (abs(DFCommonInDetTrackZ0AtPV) < 1.5)"
-# from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__TrackParticleThinning
-# HIGG5D1TPThinningTool = DerivationFramework__TrackParticleThinning( name                = "HIGG5D1TPThinningTool",
-#                                                                 ThinningService         = "HIGG5D1ThinningSvc",
-#                                                                 SelectionString         = thinning_expression,
-#                                                                 InDetTrackParticlesKey  = "InDetTrackParticles",
-#                                                                 ApplyAnd                = True)
-# ToolSvc += HIGG5D1TPThinningTool
-# thinningTools.append(HIGG5D1TPThinningTool)
-
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__JetTrackParticleThinning
-HIGG5D1JetTPThinningTool = DerivationFramework__JetTrackParticleThinning( name          = "HIGG5D1JetTPThinningTool",
-                                                                ThinningService         = HIGG5D1ThinningHelper.ThinningSvc(),
-                                                                JetKey                  = "AntiKt4EMTopoJets",
-                                                                InDetTrackParticlesKey  = "InDetTrackParticles")
-ToolSvc += HIGG5D1JetTPThinningTool
-thinningTools.append(HIGG5D1JetTPThinningTool)
-
-# Tracks associated with Muons
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__MuonTrackParticleThinning
-HIGG5D1MuonTPThinningTool = DerivationFramework__MuonTrackParticleThinning(name                    = "HIGG5D1MuonTPThinningTool",
-                                                                            ThinningService         = HIGG5D1ThinningHelper.ThinningSvc(),
-                                                                            MuonKey                 = "Muons",
-                                                                            InDetTrackParticlesKey  = "InDetTrackParticles")
-ToolSvc += HIGG5D1MuonTPThinningTool
-thinningTools.append(HIGG5D1MuonTPThinningTool)
-
-# Tracks associated with Electrons
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__EgammaTrackParticleThinning
-HIGG5D1ElectronTPThinningTool = DerivationFramework__EgammaTrackParticleThinning(       name                    = "HIGG5D1ElectronTPThinningTool",
-                                                                                        ThinningService         = HIGG5D1ThinningHelper.ThinningSvc(),
-                                                                                        SGKey                   = "Electrons",
-                                                                                        InDetTrackParticlesKey  = "InDetTrackParticles",
-                                                                                        BestMatchOnly           = True)
-ToolSvc += HIGG5D1ElectronTPThinningTool
-thinningTools.append(HIGG5D1ElectronTPThinningTool)
-
-# Tracks associated with Photons
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__EgammaTrackParticleThinning
-HIGG5D1PhotonTPThinningTool = DerivationFramework__EgammaTrackParticleThinning(       name                    = "HIGG5D1PhotonTPThinningTool",
-                                                                                      ThinningService         = HIGG5D1ThinningHelper.ThinningSvc(),
-                                                                                      SGKey                   = "Photons",
-                                                                                      InDetTrackParticlesKey  = "InDetTrackParticles",
-                                                                                      BestMatchOnly           = True)
-ToolSvc += HIGG5D1PhotonTPThinningTool
-thinningTools.append(HIGG5D1PhotonTPThinningTool)
-
-# Tracks associated with taus
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__TauTrackParticleThinning
-HIGG5D1TauTPThinningTool = DerivationFramework__TauTrackParticleThinning( name                  = "HIGG5D1TauTPThinningTool",
-                                                                          ThinningService         = HIGG5D1ThinningHelper.ThinningSvc(),
-                                                                          TauKey                  = "TauJets",
-                                                                          ConeSize                = 0.6,
-                                                                          InDetTrackParticlesKey  = "InDetTrackParticles")
-ToolSvc += HIGG5D1TauTPThinningTool
-thinningTools.append(HIGG5D1TauTPThinningTool)
-
-
-# calo cluster thinning
-from DerivationFrameworkCalo.DerivationFrameworkCaloConf import DerivationFramework__CaloClusterThinning
-HIGG5D1TauCCThinningTool = DerivationFramework__CaloClusterThinning(name                  = "HIGG5D1TauCCThinningTool",
-                                                                    ThinningService       = HIGG5D1ThinningHelper.ThinningSvc(),
-                                                                    SGKey                 = "TauJets",
-                                                                    TopoClCollectionSGKey = "CaloCalTopoClusters")
-ToolSvc += HIGG5D1TauCCThinningTool
-thinningTools.append(HIGG5D1TauCCThinningTool)
-
+    thinningTools.append(HIGG5Common.getTruthThinningTool('HIGG5D1', HIGG5D1ThinningHelper))
 
 #====================================================================
 # jet selection 
 #====================================================================
-#jetSel = '(( count( (AntiKt4EMTopoJets.pt > 0.0*GeV) && (abs(AntiKt4EMTopoJets.eta) < 2.6) ) ) > 1)'
 jetSel = '(( count( (AntiKt4EMTopoJets.DFCommonJets_Calib_pt > 15.*GeV) && (abs(AntiKt4EMTopoJets.DFCommonJets_Calib_eta) < 2.6) ) ) > 0)'
 jetSel += '|| (( count( (AntiKt4EMTopoJets.pt > 100.0*GeV) && (abs(AntiKt4EMTopoJets.eta) < 2.6) ) ) > 0)'
 jetSel += '|| (( count( (AntiKt10LCTopoJets.pt > 100.0*GeV) && (abs(AntiKt10LCTopoJets.eta) < 2.6) ) ) > 0)'
-# jetSel += '|| (( count( (CamKt12LCTopoJets.pt > 100.0*GeV) && (abs(CamKt12LCTopoJets.eta) < 2.6) ) ) > 0)'
 jetSel += '|| (( count( (AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets.pt > 100.0*GeV) && (abs(AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets.eta) < 2.6) ) ) > 0)'
-# jetSel += '|| (( count( (AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets.DFCommonJets_Calib_pt > 100.0*GeV) && (abs(AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets.DFCommonJets_Calib_eta) < 2.6) ) ) > 0)'
-# jetSel += '|| (( count( (CamKt10LCTopoPrunedR50Z15Jets.pt > 100.0*GeV) && (abs(CamKt10LCTopoPrunedR50Z15Jets.eta) < 2.6) ) ) > 0)'
-# jetSel += '|| (( count( (CamKt12LCTopoBDRSFilteredMU100Y15Jets.pt > 100.0*GeV) && (abs(CamKt12LCTopoBDRSFilteredMU100Y15Jets.eta) < 2.6) ) ) > 0)'
 
 #====================================================================
 # Trigger selection
@@ -258,7 +176,7 @@ higg5d1Seq = CfgMgr.AthSequencer("HIGG5D1Sequence")
 
 
 #=======================================
-# CREATE THE DERIVATION KERNEL ALGORITHM   
+# CREATE THE DERIVATION KERNEL ALGORITHM
 #=======================================
 from DerivationFrameworkCore.DerivationFrameworkCoreConf import DerivationFramework__DerivationKernel
 
@@ -275,32 +193,16 @@ if not "HIGG5D1Jets" in OutputJets:
     OutputJets["HIGG5D1Jets"] = []
 
     #AntiKt2PV0TrackJets
-    addStandardJets("AntiKt", 0.2, "PV0Track", 2000, mods="track_ungroomed", algseq=higg5d1Seq, outputGroup="HIGG5D1Jets")
-    OutputJets["HIGG5D1Jets"].append("AntiKt2PV0TrackJets")
-    #AntiKt4PV0TrackJets
-    addStandardJets("AntiKt", 0.4, "PV0Track", 2000, mods="track_ungroomed", algseq=higg5d1Seq, outputGroup="HIGG5D1Jets")
-    OutputJets["HIGG5D1Jets"].append("AntiKt4PV0TrackJets")
-    #AntiKt10LCTopoJets
-    # addStandardJets("AntiKt", 1.0, "LCTopo", mods="lctopo_ungroomed", ptmin=40000, ptminFilter=50000, calibOpt="none", algseq=higg5d1Seq, outputGroup="HIGG5D1Jets")
-    # OutputJets["HIGG5D1Jets"].append("AntiKt10LCTopoJets")
-
-#====================================================================
-# Special jets
-#====================================================================
-# if not "HIGG5D1Jets" in OutputJets:
-    # OutputJets["HIGG5D1Jets"] = ["AntiKt2PV0TrackJets","AntiKt10LCTopoJets","CamKt12LCTopoJets"]
+    addAntiKt2PV0TrackJets(higg5d1Seq, 'HIGG5D1Jets')
+    addAntiKt4PV0TrackJets(higg5d1Seq, "HIGG5D1Jets")
+    addDefaultTrimmedJets(higg5d1Seq,"HIGG5D1");
 
     if jetFlags.useTruth:
-      #AntiKt4TruthJets
-      addStandardJets("AntiKt", 0.4, "Truth", 5000, mods="truth_ungroomed", algseq=higg5d1Seq, outputGroup="HIGG5D1Jets")
-      OutputJets["HIGG5D1Jets"].append("AntiKt4TruthJets")
-      #AntiKt4TruthWZJets
-      addStandardJets("AntiKt", 0.4, "TruthWZ", 5000, mods="truth_ungroomed", algseq=higg5d1Seq, outputGroup="HIGG5D1Jets")
-      OutputJets["HIGG5D1Jets"].append("AntiKt4TruthWZJets")
+      addAntiKt4TruthJets(higg5d1Seq, "HIGG5D1Jets")
+      addAntiKt4TruthWZJets(higg5d1Seq, "HIGG5D1Jets")
 
-      addTrimmedJets("AntiKt", 1.0, "TruthWZ", rclus=0.2, ptfrac=0.05, includePreTools=False, algseq=higg5d1Seq,outputGroup="HIGG5D1Jets")
+      HIGG5Common.addTrimmedTruthWZJets(higg5d1Seq,'HIGG5D1Jets')
 
-    addDefaultTrimmedJets(higg5d1Seq,"HIGG5D1");
 
 #====================================================================
 # Create variable-R trackjets and dress AntiKt10LCTopo with ghost VR-trkjet 
@@ -319,15 +221,10 @@ from BTagging.BTaggingFlags import BTaggingFlags
 # alias for VR
 BTaggingFlags.CalibrationChannelAliases += ["AntiKtVR30Rmax4Rmin02Track->AntiKtVR30Rmax4Rmin02Track,AntiKt4EMTopo"]
 
-from DerivationFrameworkFlavourTag.FlavourTagCommon import FlavorTagInit
-# must re-tag AntiKt4LCTopoJets and AntiKt4PV0TrackJets to make JetFitterNN work with corresponding VR jets (nikola: why?)
-# also, re-tag R=0.2 track jets
-FlavorTagInit( JetCollections = ["AntiKt4PV0TrackJets", "AntiKtVR30Rmax4Rmin02TrackJets", "AntiKt2PV0TrackJets"], Sequencer = higg5d1Seq )
-
 # Jet calibration should come after fat jets
-applyJetCalibration_xAODColl(jetalg="AntiKt4EMTopo", sequence=higg5d1Seq)
-# applyJetCalibration_CustomColl(jetalg="AntiKt10LCTopoTrimmedPtFrac5SmallR20", sequence=higg5d1Seq)
-# applyJetCalibration_OTFJets("AntiKt10LCTopoTrimmedPtFrac5SmallR20",sequence=higg5d1Seq)
+# applyJetCalibration_xAODColl(jetalg="AntiKt4EMTopo", sequence=higg5d1Seq)
+# # applyJetCalibration_CustomColl(jetalg="AntiKt10LCTopoTrimmedPtFrac5SmallR20", sequence=higg5d1Seq)
+# # applyJetCalibration_OTFJets("AntiKt10LCTopoTrimmedPtFrac5SmallR20",sequence=higg5d1Seq)
 
 
 
@@ -422,8 +319,8 @@ addMETOutputs(HIGG5D1SlimmingHelper,[],["Track","AntiKt10LCTopoTrimmedPtFrac5Sma
 # HIGG5D1SlimmingHelper.IncludeMuonTriggerContent = True
 HIGG5D1SlimmingHelper.IncludeEGammaTriggerContent = True
 # HIGG5D1SlimmingHelper.IncludeBJetTriggerContent = True
-#HIGG5D1SlimmingHelper.IncludeBPhysTriggerContent = True
-#HIGG5D1SlimmingHelper.IncludeJetTauEtMissTriggerContent = True
+# HIGG5D1SlimmingHelper.IncludeBPhysTriggerContent = True
+# HIGG5D1SlimmingHelper.IncludeJetTauEtMissTriggerContent = True
 HIGG5D1SlimmingHelper.IncludeEtMissTriggerContent = True
 HIGG5D1SlimmingHelper.IncludeJetTriggerContent = True
 
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG5D2.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG5D2.py
index 2d18c700f8e..20d92139eed 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG5D2.py
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG5D2.py
@@ -39,150 +39,28 @@ thinningTools=[]
 
 # Establish the thinning helper (which will set up the services behind the scenes) 
 from DerivationFrameworkCore.ThinningHelper import ThinningHelper 
-HIGG5D2ThinningHelper = ThinningHelper("HIGG5D2ThinningHelper") 
+HIGG5D2ThinningHelper = ThinningHelper("HIGG5D2ThinningHelper")
 #trigger navigation content
 HIGG5D2ThinningHelper.TriggerChains = 'HLT_e.*|HLT_mu.*|HLT_xe.*|HLT_j.*' 
 HIGG5D2ThinningHelper.AppendToStream(HIGG5D2Stream) 
 
+import DerivationFrameworkHiggs.HIGG5Common as HIGG5Common
+thinningTools.append( HIGG5Common.getAntiKt4EMTopoTrackParticleThinning('HIGG5D2',HIGG5D2ThinningHelper, SelectionString = "AntiKt4EMTopoJets.pt > 100000*GeV", ApplyAnd = True) )
+thinningTools.append( HIGG5Common.getAntiKt10LCTopoTrackParticleThinning('HIGG5D2',HIGG5D2ThinningHelper))
+thinningTools.append( HIGG5Common.getMuonTrackParticleThinning(         'HIGG5D2',HIGG5D2ThinningHelper) )
+thinningTools.append( HIGG5Common.getElectronTrackParticleThinning(     'HIGG5D2',HIGG5D2ThinningHelper) )
+thinningTools.append( HIGG5Common.getPhotonTrackParticleThinning(       'HIGG5D2',HIGG5D2ThinningHelper) )
+thinningTools.append( HIGG5Common.getTauTrackParticleThinning(          'HIGG5D2',HIGG5D2ThinningHelper) )
+thinningTools.append( HIGG5Common.getTauCaloClusterThinning(            'HIGG5D2',HIGG5D2ThinningHelper) )
+thinningTools.append( HIGG5Common.getAntiKt10LCTopoCaloClusterThinning( 'HIGG5D2',HIGG5D2ThinningHelper) )
+thinningTools.append( HIGG5Common.getTCCTrackParticleThinning(          'HIGG5D2',HIGG5D2ThinningHelper) )
 
-# MC truth thinning (not for data)
-truth_cond_WZH    = "((abs(TruthParticles.pdgId) >= 23) && (abs(TruthParticles.pdgId) <= 25))" # W, Z and Higgs
-truth_cond_Lepton = "((abs(TruthParticles.pdgId) >= 11) && (abs(TruthParticles.pdgId) <= 16))" # Leptons
-truth_cond_Quark  = "((abs(TruthParticles.pdgId) ==  6) || (abs(TruthParticles.pdgId) ==  5))" # Top quark and Bottom quark
-truth_cond_Photon = "((abs(TruthParticles.pdgId) == 22) && (TruthParticles.pt > 1*GeV))"       # Photon
-truth_expression = '('+truth_cond_WZH+' || '+truth_cond_Lepton +' || '+truth_cond_Quark +' || '+truth_cond_Photon+')'
-from DerivationFrameworkMCTruth.DerivationFrameworkMCTruthConf import DerivationFramework__GenericTruthThinning
-HIGG5D2MCThinningTool = DerivationFramework__GenericTruthThinning(
-    name                         = "HIGG5D2MCThinningTool", 
-    ThinningService              = HIGG5D2ThinningHelper.ThinningSvc(),
-    ParticleSelectionString      = truth_expression,
-    PreserveDescendants          = False,
-    PreserveGeneratorDescendants = True,
-    PreserveAncestors            = True)
+thinningTools.append( HIGG5Common.getAntiKt10LCTopoTrimmedPtFrac5SmallR20Thinning('HIGG5D2',HIGG5D2ThinningHelper) )
+thinningTools.append( HIGG5Common.getAntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20Thinning('HIGG5D2',HIGG5D2ThinningHelper) )
 
+# MC truth thinning (not for data)
 if DerivationFrameworkIsMonteCarlo :
-    ToolSvc += HIGG5D2MCThinningTool
-    thinningTools.append(HIGG5D2MCThinningTool)
-
-# MET/Jet tracks
-# thinning_expression = "(InDetTrackParticles.pt > 0.5*GeV) && (InDetTrackParticles.numberOfPixelHits > 0) && (InDetTrackParticles.numberOfSCTHits > 5) && (abs(DFCommonInDetTrackZ0AtPV) < 1.5)"
-# from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__TrackParticleThinning
-# HIGG5D2TPThinningTool = DerivationFramework__TrackParticleThinning( name                = "HIGG5D2TPThinningTool",
-#                                                                 ThinningService         = HIGG5D2ThinningHelper.ThinningSvc(),
-#                                                                 SelectionString         = thinning_expression,
-#                                                                 InDetTrackParticlesKey  = "InDetTrackParticles",
-#                                                                 ApplyAnd                = True)
-# ToolSvc += HIGG5D2TPThinningTool
-# thinningTools.append(HIGG5D2TPThinningTool)
-
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__JetTrackParticleThinning
-HIGG5D2JetTPThinningTool = DerivationFramework__JetTrackParticleThinning( name          = "HIGG5D2JetTPThinningTool",
-                                                                          ThinningService         = HIGG5D2ThinningHelper.ThinningSvc(),
-                                                                          JetKey                  = "AntiKt4EMTopoJets",
-                                                                          InDetTrackParticlesKey  = "InDetTrackParticles",
-                                                                          SelectionString = "AntiKt4EMTopoJets.pt > 100000*GeV",
-                                                                          ApplyAnd        = True)
-ToolSvc += HIGG5D2JetTPThinningTool
-thinningTools.append(HIGG5D2JetTPThinningTool)
-
-HIGG5D2FatjetTPThinningTool = DerivationFramework__JetTrackParticleThinning( name          = "HIGG5D2FatjetTPThinningTool",
-                                                                             ThinningService         = HIGG5D2ThinningHelper.ThinningSvc(),
-                                                                             JetKey                  = "AntiKt10LCTopoJets",
-                                                                             InDetTrackParticlesKey  = "InDetTrackParticles",
-                                                                             SelectionString  = "(AntiKt10LCTopoJets.pt > 100*GeV && abs(AntiKt10LCTopoJets.eta)<2.6)",
-                                                                             ApplyAnd        = True)
-ToolSvc += HIGG5D2FatjetTPThinningTool
-thinningTools.append(HIGG5D2FatjetTPThinningTool)
-from DerivationFrameworkCalo.DerivationFrameworkCaloConf import DerivationFramework__JetCaloClusterThinning
-HIGG5D2FatjetCCThinningTool = DerivationFramework__JetCaloClusterThinning(name                  = "HIGG5D2FatjetCCThinningTool",
-                                                                          ThinningService       = HIGG5D2ThinningHelper.ThinningSvc(),
-                                                                          SGKey                 = "AntiKt10LCTopoJets",     
-                                                                          TopoClCollectionSGKey = "CaloCalTopoClusters",
-                                                                          SelectionString  = "(AntiKt10LCTopoJets.pt > 100*GeV && abs(AntiKt10LCTopoJets.eta)<2.6)",
-                                                                          ApplyAnd        = True)
-ToolSvc += HIGG5D2FatjetCCThinningTool
-thinningTools.append(HIGG5D2FatjetCCThinningTool)
-
-# Tracks associated with Muons
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__MuonTrackParticleThinning
-HIGG5D2MuonTPThinningTool = DerivationFramework__MuonTrackParticleThinning(name                    = "HIGG5D2MuonTPThinningTool",
-                                                                            ThinningService         = HIGG5D2ThinningHelper.ThinningSvc(),
-                                                                            MuonKey                 = "Muons",
-                                                                            InDetTrackParticlesKey  = "InDetTrackParticles")
-ToolSvc += HIGG5D2MuonTPThinningTool
-thinningTools.append(HIGG5D2MuonTPThinningTool)
-
-# Tracks associated with Electrons
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__EgammaTrackParticleThinning
-HIGG5D2ElectronTPThinningTool = DerivationFramework__EgammaTrackParticleThinning(       name                    = "HIGG5D2ElectronTPThinningTool",
-                                                                                        ThinningService         = HIGG5D2ThinningHelper.ThinningSvc(),
-                                                                                        SGKey                   = "Electrons",
-                                                                                        InDetTrackParticlesKey  = "InDetTrackParticles",
-                                                                                        BestMatchOnly           = True)
-ToolSvc += HIGG5D2ElectronTPThinningTool
-thinningTools.append(HIGG5D2ElectronTPThinningTool)
-
-# Tracks associated with Photons
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__EgammaTrackParticleThinning
-HIGG5D2PhotonTPThinningTool = DerivationFramework__EgammaTrackParticleThinning(       name                    = "HIGG5D2PhotonTPThinningTool",
-                                                                                      ThinningService         = HIGG5D2ThinningHelper.ThinningSvc(),
-                                                                                      SGKey                   = "Photons",
-                                                                                      InDetTrackParticlesKey  = "InDetTrackParticles",
-                                                                                      BestMatchOnly           = True)
-ToolSvc += HIGG5D2PhotonTPThinningTool
-thinningTools.append(HIGG5D2PhotonTPThinningTool)
-
-# Tracks associated with taus
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__TauTrackParticleThinning
-HIGG5D2TauTPThinningTool = DerivationFramework__TauTrackParticleThinning( name                  = "HIGG5D2TauTPThinningTool",
-                                                                          ThinningService         = HIGG5D2ThinningHelper.ThinningSvc(),
-                                                                          TauKey                  = "TauJets",
-                                                                          ConeSize                = 0.6,
-                                                                          InDetTrackParticlesKey  = "InDetTrackParticles")
-ToolSvc += HIGG5D2TauTPThinningTool
-thinningTools.append(HIGG5D2TauTPThinningTool)
-
-
-# calo cluster thinning
-from DerivationFrameworkCalo.DerivationFrameworkCaloConf import DerivationFramework__CaloClusterThinning
-HIGG5D2TauCCThinningTool = DerivationFramework__CaloClusterThinning(name                  = "HIGG5D2TauCCThinningTool",
-                                                                    ThinningService       = HIGG5D2ThinningHelper.ThinningSvc(),
-                                                                    SGKey                 = "TauJets",
-                                                                    TopoClCollectionSGKey = "CaloCalTopoClusters")
-ToolSvc += HIGG5D2TauCCThinningTool
-thinningTools.append(HIGG5D2TauCCThinningTool)
-
-# Tracks and CaloClusters associated with TCCs
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__TCCTrackParticleThinning
-HIGG5D2TCCTPThinningTool = DerivationFramework__TCCTrackParticleThinning(name                         = "HIGG5D2TCCTPThinningTool",
-                                                                         ThinningService              = HIGG5D2ThinningHelper.ThinningSvc(),
-                                                                         JetKey                       = "AntiKt10TrackCaloClusterJets",
-                                                                         TCCKey                       = "TrackCaloClustersCombinedAndNeutral",
-                                                                         InDetTrackParticlesKey       = "InDetTrackParticles",
-                                                                         CaloCalTopoClustersKey       = "CaloCalTopoClusters",
-                                                                         ThinOriginCorrectedClusters  = True,
-                                                                         SelectionString              = "AntiKt10TrackCaloClusterJets.pt>100*GeV && abs(AntiKt10TrackCaloClusterJets.eta)<2.6",
-                                                                         OriginCaloCalTopoClustersKey = "LCOriginTopoClusters")
-ToolSvc += HIGG5D2TCCTPThinningTool
-thinningTools.append(HIGG5D2TCCTPThinningTool)
-
-#Large-R jet thinning
-from DerivationFrameworkTools.DerivationFrameworkToolsConf import DerivationFramework__GenericObjectThinning
-HIGG5D2LargeRJetThinningTool = DerivationFramework__GenericObjectThinning( name             = "HIGG5D2LargeRJetThinningTool",
-                                                                           ThinningService  = HIGG5D2ThinningHelper.ThinningSvc(),
-                                                                           ContainerName    = "AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets",
-                                                                           SelectionString  = "(AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets.pt > 100*GeV && abs(AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets.eta)<2.6)",
-                                                                           ApplyAnd         = False)
-ToolSvc += HIGG5D2LargeRJetThinningTool
-thinningTools.append(HIGG5D2LargeRJetThinningTool)
-HIGG5D2TCCJetThinningTool = DerivationFramework__GenericObjectThinning( name             = "HIGG5D2TCCJetThinningTool",
-                                                                        ThinningService  = HIGG5D2ThinningHelper.ThinningSvc(),
-                                                                        ContainerName    = "AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20Jets",
-                                                                        SelectionString  = "(AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20Jets.pt > 100*GeV && abs(AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20Jets.eta)<2.6)",
-                                                                        ApplyAnd         = False)
-ToolSvc += HIGG5D2TCCJetThinningTool
-thinningTools.append(HIGG5D2TCCJetThinningTool)
-
+    thinningTools.append(HIGG5Common.getTruthThinningTool('HIGG5D2', HIGG5D2ThinningHelper))
 
 #========================================================================
 # lepton selection (keep isolation failed leptons for QCD-MJ estimation)
@@ -192,17 +70,12 @@ lepSel = '( count( (Muons.pt > 20.0*GeV) && (abs(Muons.eta) < 2.6) && (Muons.DFC
 #====================================================================
 # jet selection 
 #====================================================================
-#jetSel = '(( count( (AntiKt4EMTopoJets.pt > 0.0*GeV) && (abs(AntiKt4EMTopoJets.eta) < 2.6) ) ) > 1)'
 jetSel = '(( count( (AntiKt4EMTopoJets.DFCommonJets_Calib_pt > 15.*GeV) && (abs(AntiKt4EMTopoJets.DFCommonJets_Calib_eta) < 2.6) ) ) > 0)'
 jetSel += '|| (( count( (AntiKt4EMTopoJets.pt > 100.0*GeV) && (abs(AntiKt4EMTopoJets.eta) < 2.6) ) ) > 0)'
 jetSel += '|| (( count( (AntiKt10LCTopoJets.pt > 100.0*GeV) && (abs(AntiKt10LCTopoJets.eta) < 2.6) ) ) > 0)'
-# jetSel += '|| (( count( (CamKt12LCTopoJets.pt > 100.0*GeV) && (abs(CamKt12LCTopoJets.eta) < 2.6) ) ) > 0)'
 jetSel += '|| (( count( (AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets.pt > 100.0*GeV) && (abs(AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets.eta) < 2.6) ) ) > 0)'
 jetSel += '|| (( count( (AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20Jets.pt > 100.0*GeV) && (abs(AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20Jets.eta) < 2.6) ) ) > 0)'
-# jetSel += '|| (( count( (AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets.DFCommonJets_Calib_pt > 100.0*GeV) && (abs(AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets.DFCommonJets_Calib_eta) < 2.6) ) ) > 0)'
-# jetSel += '|| (( count( (CamKt10LCTopoPrunedR50Z15Jets.pt > 100.0*GeV) && (abs(CamKt10LCTopoPrunedR50Z15Jets.eta) < 2.6) ) ) > 0)'
-# jetSel += '|| (( count( (CamKt12LCTopoBDRSFilteredMU100Y15Jets.pt > 100.0*GeV) && (abs(CamKt12LCTopoBDRSFilteredMU100Y15Jets.eta) < 2.6) ) ) > 0)'
-#jetSel = '(( count( (AntiKt4EMTopoJets.pt > 0.0*GeV) && (abs(AntiKt4EMTopoJets.eta) < 2.6) ) ) > 1) || (( count( (AntiKt4EMTopoJets.pt > 100.0*GeV) && (abs(AntiKt4EMTopoJets.eta) < 2.6) ) ) > 0) || (( count( (AntiKt10LCTopoJets.pt > 100.0*GeV) && (abs(AntiKt10LCTopoJets.eta) < 2.6) ) ) > 0) || (( count( (CamKt12LCTopoJets.pt > 100.0*GeV) && (abs(CamKt12LCTopoJets.eta) < 2.6) ) ) > 0)'
+
 
 #====================================================================
 # Trigger selection
@@ -391,41 +264,29 @@ higg5d2Seq += CfgMgr.DerivationFramework__DerivationKernel(
 if not "HIGG5D2Jets" in OutputJets:
     OutputJets["HIGG5D2Jets"] = []
 
-    reducedJetList = ["AntiKt2PV0TrackJets",
-                      "AntiKt4PV0TrackJets"]
+    #AntiKt2PV0TrackJets
+    addAntiKt2PV0TrackJets(higg5d2Seq, 'HIGG5D2Jets')
+    addAntiKt4PV0TrackJets(higg5d2Seq, "HIGG5D2Jets")
 
-    replaceAODReducedJets(reducedJetList,higg5d2Seq,"HIGG5D2Jets")
-
-#====================================================================
-# Special jets
-#====================================================================
-# if not "HIGG5D2Jets" in OutputJets:
-    # OutputJets["HIGG5D2Jets"] = ["AntiKt2PV0TrackJets","AntiKt10LCTopoJets","CamKt12LCTopoJets"]
+    addDefaultTrimmedJets(higg5d2Seq,"HIGG5D2");
 
     if jetFlags.useTruth:
-      #AntiKt4TruthJets
-      addStandardJets("AntiKt", 0.4, "Truth", 5000, mods="truth_ungroomed", algseq=higg5d2Seq, outputGroup="HIGG5D2Jets")
-      OutputJets["HIGG5D2Jets"].append("AntiKt4TruthJets")
-      #AntiKt4TruthWZJets
-      addStandardJets("AntiKt", 0.4, "TruthWZ", 5000, mods="truth_ungroomed", algseq=higg5d2Seq, outputGroup="HIGG5D2Jets")
-      OutputJets["HIGG5D2Jets"].append("AntiKt4TruthWZJets")
-
-      addTrimmedJets("AntiKt", 1.0, "TruthWZ", rclus=0.2, ptfrac=0.05, includePreTools=False, algseq=higg5d2Seq,outputGroup="HIGG5D2Jets")
+      addAntiKt4TruthJets(higg5d2Seq, "HIGG5D2Jets")
+      addAntiKt4TruthWZJets(higg5d2Seq, "HIGG5D2Jets")
 
-    addDefaultTrimmedJets(higg5d2Seq,"HIGG5D2");
+      HIGG5Common.addTrimmedTruthWZJets(higg5d2Seq,'HIGG5D2Jets') 
 
+    #=======================================
+    # TCC JETS
+    #=======================================
+    from DerivationFrameworkJetEtMiss.TCCReconstruction import runTCCReconstruction
+    # Set up geometry and BField
+    import AthenaCommon.AtlasUnixStandardJob
 
-#=======================================
-# TCC JETS
-#=======================================
-from DerivationFrameworkJetEtMiss.TCCReconstruction import runTCCReconstruction
-# Set up geometry and BField
-import AthenaCommon.AtlasUnixStandardJob
-include("RecExCond/AllDet_detDescr.py")
-runTCCReconstruction(higg5d2Seq, ToolSvc, "LCOriginTopoClusters", "InDetTrackParticles")
-from DerivationFrameworkJetEtMiss.ExtendedJetCommon import addTCCTrimmedJets
-addTCCTrimmedJets(higg5d2Seq, "HIGG5D2")
-OutputJets["HIGG5D2Jets"].append("AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20Jets")
+    include("RecExCond/AllDet_detDescr.py")
+    runTCCReconstruction(higg5d2Seq, ToolSvc, "LCOriginTopoClusters", "InDetTrackParticles")
+    from DerivationFrameworkJetEtMiss.ExtendedJetCommon import addTCCTrimmedJets
+    addTCCTrimmedJets(higg5d2Seq, "HIGG5D2")
 
 #====================================================================
 # Create variable-R trackjets and dress AntiKt10LCTopo with ghost VR-trkjet 
@@ -444,11 +305,10 @@ from BTagging.BTaggingFlags import BTaggingFlags
 # alias for VR
 BTaggingFlags.CalibrationChannelAliases += ["AntiKtVR30Rmax4Rmin02Track->AntiKtVR30Rmax4Rmin02Track,AntiKt4EMTopo"]
 
-
 # Jet calibration should come after fat jets
-applyJetCalibration_xAODColl(jetalg="AntiKt4EMTopo", sequence=higg5d2Seq)
-# applyJetCalibration_CustomColl(jetalg="AntiKt10LCTopoTrimmedPtFrac5SmallR20", sequence=higg5d2Seq)
-# applyJetCalibration_OTFJets("AntiKt10LCTopoTrimmedPtFrac5SmallR20",sequence=higg5d2Seq)
+# applyJetCalibration_xAODColl(jetalg="AntiKt4EMTopo", sequence=higg5d2Seq)
+# # applyJetCalibration_CustomColl(jetalg="AntiKt10LCTopoTrimmedPtFrac5SmallR20", sequence=higg5d2Seq)
+# # applyJetCalibration_OTFJets("AntiKt10LCTopoTrimmedPtFrac5SmallR20",sequence=higg5d2Seq)
 
 
 
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG5D3.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG5D3.py
index d1d218ae315..712df390092 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG5D3.py
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkHiggs/share/HIGG5D3.py
@@ -44,73 +44,15 @@ HIGG5D3ThinningHelper.TriggerChains = 'HLT_g.*|HLT_2g.*|HLT_mu.*|HLT_j.*|HLT_b.*
 HIGG5D3ThinningHelper.AppendToStream(HIGG5D3Stream) 
 
 
-# # MC truth thinning (not for data)
-# truth_cond_WZH    = "((abs(TruthParticles.pdgId) >= 23) && (abs(TruthParticles.pdgId) <= 25))" # W, Z and Higgs
-# truth_cond_Lepton = "((abs(TruthParticles.pdgId) >= 11) && (abs(TruthParticles.pdgId) <= 16))" # Leptons
-# truth_cond_Quark  = "((abs(TruthParticles.pdgId) ==  6) || (abs(TruthParticles.pdgId) ==  5))" # Top quark and Bottom quark
-# truth_cond_Photon = "((abs(TruthParticles.pdgId) == 22) && (TruthParticles.pt > 1*GeV))"       # Photon
-# truth_expression = '('+truth_cond_WZH+' || '+truth_cond_Lepton +' || '+truth_cond_Quark +' || '+truth_cond_Photon+')'
-# from DerivationFrameworkMCTruth.DerivationFrameworkMCTruthConf import DerivationFramework__GenericTruthThinning
-# HIGG5D3MCThinningTool = DerivationFramework__GenericTruthThinning(
-#     name                    = "HIGG5D3MCThinningTool", 
-#     ThinningService         = HIGG5D3ThinningHelper.ThinningSvc(),
-#     ParticleSelectionString = truth_expression,
-#     PreserveDescendants     = False,
-#     PreserveGeneratorDescendants = True,
-#     PreserveAncestors       = True)
-# if DerivationFrameworkIsMonteCarlo :
-#     ToolSvc += HIGG5D3MCThinningTool
-#     thinningTools.append(HIGG5D3MCThinningTool)
-
-
-# MET/Jet tracks
-thinning_expression = "( abs(InDetTrackParticles.d0) < 2 ) && ( abs(DFCommonInDetTrackZ0AtPV*sin(InDetTrackParticles.theta)) < 3 )"
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__TrackParticleThinning
-HIGG5D3TPThinningTool = DerivationFramework__TrackParticleThinning( name                = "HIGG5D3TPThinningTool",
-                                                                  ThinningService         = HIGG5D3ThinningHelper.ThinningSvc(),
-                                                                  SelectionString         = thinning_expression,
-                                                                  InDetTrackParticlesKey  = "InDetTrackParticles")
-ToolSvc += HIGG5D3TPThinningTool
-thinningTools.append(HIGG5D3TPThinningTool)
-
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__JetTrackParticleThinning
-HIGG5D3JetTPThinningTool = DerivationFramework__JetTrackParticleThinning( name          = "HIGG5D3JetTPThinningTool",
-                                                                ThinningService         = HIGG5D3ThinningHelper.ThinningSvc(),
-                                                                JetKey                  = "AntiKt4EMTopoJets",
-                                                                InDetTrackParticlesKey  = "InDetTrackParticles",
-                                                                #SelectionString         = "AntiKt4EMTopoJets.pt > 20*GeV",
-                                                                ApplyAnd                = True)
-ToolSvc += HIGG5D3JetTPThinningTool
-thinningTools.append(HIGG5D3JetTPThinningTool)
-
-# Tracks associated with Muons
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__MuonTrackParticleThinning
-HIGG5D3MuonTPThinningTool = DerivationFramework__MuonTrackParticleThinning(name                    = "HIGG5D3MuonTPThinningTool",
-                                                                            ThinningService         = HIGG5D3ThinningHelper.ThinningSvc(),
-                                                                            MuonKey                 = "Muons",
-                                                                            InDetTrackParticlesKey  = "InDetTrackParticles")
-ToolSvc += HIGG5D3MuonTPThinningTool
-thinningTools.append(HIGG5D3MuonTPThinningTool)
-
-# Tracks associated with Electrons
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__EgammaTrackParticleThinning
-HIGG5D3ElectronTPThinningTool = DerivationFramework__EgammaTrackParticleThinning(       name                    = "HIGG5D3ElectronTPThinningTool",
-                                                                                        ThinningService         = HIGG5D3ThinningHelper.ThinningSvc(),
-                                                                                        SGKey                   = "Electrons",
-                                                                                        InDetTrackParticlesKey  = "InDetTrackParticles",
-                                                                                        BestMatchOnly           = True)
-ToolSvc += HIGG5D3ElectronTPThinningTool
-thinningTools.append(HIGG5D3ElectronTPThinningTool)
-
-# Tracks associated with Photons
-from DerivationFrameworkInDet.DerivationFrameworkInDetConf import DerivationFramework__EgammaTrackParticleThinning
-HIGG5D3PhotonTPThinningTool = DerivationFramework__EgammaTrackParticleThinning(       name                    = "HIGG5D3PhotonTPThinningTool",
-                                                                                      ThinningService         = HIGG5D3ThinningHelper.ThinningSvc(),
-                                                                                      SGKey                   = "Photons",
-                                                                                      InDetTrackParticlesKey  = "InDetTrackParticles",
-                                                                                      BestMatchOnly           = True)
-ToolSvc += HIGG5D3PhotonTPThinningTool
-thinningTools.append(HIGG5D3PhotonTPThinningTool)
+import DerivationFrameworkHiggs.HIGG5Common as HIGG5Common
+thinningTools.append( HIGG5Common.getInDetTrackParticleThinning(        'HIGG5D3',HIGG5D3ThinningHelper) )
+
+thinningTools.append( HIGG5Common.getAntiKt4EMTopoTrackParticleThinning('HIGG5D3',HIGG5D3ThinningHelper,   ApplyAnd=True) )
+thinningTools.append( HIGG5Common.getMuonTrackParticleThinning(         'HIGG5D3',HIGG5D3ThinningHelper) )
+thinningTools.append( HIGG5Common.getElectronTrackParticleThinning(     'HIGG5D3',HIGG5D3ThinningHelper) )
+thinningTools.append( HIGG5Common.getPhotonTrackParticleThinning(       'HIGG5D3',HIGG5D3ThinningHelper) )
+
+
 
 #====================================================================
 # Skimming Tool
@@ -311,21 +253,11 @@ higg5d3Seq += CfgMgr.DerivationFramework__DerivationKernel(
 if not "HIGG5D3Jets" in OutputJets:
     OutputJets["HIGG5D3Jets"] = []
 
-    #AntiKt2PV0TrackJets
-    addStandardJets("AntiKt", 0.2, "PV0Track", 2000, mods="track_ungroomed", algseq=higg5d3Seq, outputGroup="HIGG5D3Jets")
-    OutputJets["HIGG5D3Jets"].append("AntiKt2PV0TrackJets")
-    #AntiKt4PV0TrackJets
-    addStandardJets("AntiKt", 0.4, "PV0Track", 2000, mods="track_ungroomed", algseq=higg5d3Seq, outputGroup="HIGG5D3Jets")
-    OutputJets["HIGG5D3Jets"].append("AntiKt4PV0TrackJets")
+    addAntiKt2PV0TrackJets(higg5d3Seq, 'HIGG5D3Jets')
+    addAntiKt4PV0TrackJets(higg5d3Seq, "HIGG5D3Jets")
 
-#====================================================================
-# Special jets
-#====================================================================
-# if not "HIGG5D3Jets" in OutputJets:
     if jetFlags.useTruth:
-      #AntiKt4TruthJets
-      addStandardJets("AntiKt", 0.4, "Truth", 5000, mods="truth_ungroomed", algseq=higg5d3Seq, outputGroup="HIGG5D3Jets")
-      OutputJets["HIGG5D3Jets"].append("AntiKt4TruthJets")
+      addAntiKt4TruthJets(higg5d3Seq, "HIGG5D3Jets")
 
 higg5d3Seq += CfgMgr.DerivationFramework__DerivationKernel(
     "HIGG5D3Kernel",
@@ -336,12 +268,9 @@ higg5d3Seq += CfgMgr.DerivationFramework__DerivationKernel(
 #===================================================================
 # Run b-tagging
 #===================================================================
-from BTagging.BTaggingFlags import BTaggingFlags
-from DerivationFrameworkFlavourTag.FlavourTagCommon import FlavorTagInit
-FlavorTagInit( JetCollections = ["AntiKt4PV0TrackJets", "AntiKt2PV0TrackJets"], Sequencer = higg5d3Seq )
 
 # Jet calibration should come after fat jets
-applyJetCalibration_xAODColl(jetalg="AntiKt4EMTopo", sequence=higg5d3Seq)
+# applyJetCalibration_xAODColl(jetalg="AntiKt4EMTopo", sequence=higg5d3Seq)
 
 #====================================================================
 # Add non-prompt lepton tagging
-- 
GitLab