From f87d10d9ac8fbd3327bd25a391a6261eb48a6ced Mon Sep 17 00:00:00 2001
From: Atlas-Software Librarian <Atlas-Software.Librarian@cern.ch>
Date: Fri, 8 Apr 2016 15:53:58 +0200
Subject: [PATCH] 'CMakeLists.txt' (MuonPerformanceAlgs-00-00-15)

    * Fix to Zmumu Muon Probe config
    * Tagging MuonPerformanceAlgs-00-00-15

2015-06-23 Max Goblirsch <goblirsc@CERN.CH>
    * Updated muon SF treatment for Zmumu Reco efficiencies
    * Added match DR systematic to the JPsi Reco efficiency
    * Updated top level directory names for the Trig/Iso analyses
    * Probe eta cut removed for the Trig/Iso analyses
    * Fixed efficiency plot flag for the Zmumu Trig/Iso analyses
    * Tagging MuonPerformanceAlgs-00-00-14

2015-06-22 Max Goblirsch <goblirsc@CERN.CH>
    * Created common alg for Trigger and iso (with common tree) in JPsiTPMuonAnalysis.py and ZmumuTPMuonAnalysis.py
    * Updated tag trigger lists according to TagProbe mailing list discussion
    * Added truth probe running for isolation and trigger
    * Added ID efficiencies with MS probes for reco JPsi

2015-06-21 Max Goblirsch <goblirsc@CERN.CH>
...
(Long ChangeLog diff - truncated)
---
 .../MuonPerformanceAlgs/CMakeLists.txt        |  33 +
 .../MuonPerformanceAlgs/cmt/requirements      |   1 +
 .../python/CommonMuonTPConfig.py              | 451 ++++++++++
 .../python/JPsiTPIsolAnalysis.py              |  59 ++
 .../python/JPsiTPMuonAnalysis.py              | 339 +++++++
 .../python/JPsiTPRecoAnalysis.py              | 342 +++++++
 .../python/JPsiTPTrigAnalysis.py              | 134 +++
 .../python/MuonTPAnalysis.py                  |  99 ++
 .../python/ZmumuTPIsolAnalysis.py             |  57 ++
 .../python/ZmumuTPMuonAnalysis.py             | 343 +++++++
 .../python/ZmumuTPRecoAnalysis.py             | 658 ++++++++++++++
 .../python/ZmumuTPTrigAnalysis.py             | 130 +++
 .../MuonPerformanceAlgs/scripts/Submit.sh     |  84 ++
 .../scripts/makeTarBalls.sh                   |  16 +
 .../share/MuonTP_topOptions.py                | 129 +--
 .../share/ZmumuTPAnalysis.py                  | 851 ------------------
 .../share/ZmumuTPIsolationAnalysis.py         | 241 -----
 .../share/ZmumuTPTrigAnalysis.py              | 337 -------
 .../share/Zmumu_19.0.2.1.py                   |  10 -
 .../MuonPerformanceAlgs/share/Zmumu_19.2.0.py | 200 ----
 .../MuonPerformanceAlgs/src/MuonTPAlg.cxx     |   7 +-
 .../MuonPerformanceAlgs/src/MuonTPAlg.h       |   1 +
 22 files changed, 2799 insertions(+), 1723 deletions(-)
 create mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/CMakeLists.txt
 create mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/CommonMuonTPConfig.py
 create mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/JPsiTPIsolAnalysis.py
 create mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/JPsiTPMuonAnalysis.py
 create mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/JPsiTPRecoAnalysis.py
 create mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/JPsiTPTrigAnalysis.py
 create mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/MuonTPAnalysis.py
 create mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/ZmumuTPIsolAnalysis.py
 create mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/ZmumuTPMuonAnalysis.py
 create mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/ZmumuTPRecoAnalysis.py
 create mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/ZmumuTPTrigAnalysis.py
 create mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/scripts/Submit.sh
 create mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/scripts/makeTarBalls.sh
 delete mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/ZmumuTPAnalysis.py
 delete mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/ZmumuTPIsolationAnalysis.py
 delete mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/ZmumuTPTrigAnalysis.py
 delete mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/Zmumu_19.0.2.1.py
 delete mode 100644 PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/Zmumu_19.2.0.py

diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/CMakeLists.txt b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/CMakeLists.txt
new file mode 100644
index 00000000000..6da979e2336
--- /dev/null
+++ b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/CMakeLists.txt
@@ -0,0 +1,33 @@
+################################################################################
+# Package: MuonPerformanceAlgs
+################################################################################
+
+# Declare the package name:
+atlas_subdir( MuonPerformanceAlgs )
+
+# Declare the package's dependencies:
+atlas_depends_on_subdirs( PUBLIC
+                          Reconstruction/RecoTools/RecoToolInterfaces
+                          PRIVATE
+                          Control/AthenaBaseComps
+                          Event/xAOD/xAODEventInfo
+                          Event/xAOD/xAODMuon
+                          GaudiKernel
+                          PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceHistUtils
+                          PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonResonanceTools
+                          PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonTPTools )
+
+# External dependencies:
+find_package( ROOT COMPONENTS Core Tree MathCore Hist RIO pthread )
+
+# Component(s) in the package:
+atlas_add_component( MuonPerformanceAlgs
+                     src/*.cxx
+                     src/components/*.cxx
+                     INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
+                     LINK_LIBRARIES ${ROOT_LIBRARIES} RecoToolInterfaces AthenaBaseComps xAODEventInfo xAODMuon GaudiKernel MuonPerformanceHistUtils MuonResonanceToolsLib )
+
+# Install files from the package:
+atlas_install_python_modules( python/*.py )
+atlas_install_joboptions( share/*.py )
+
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/cmt/requirements b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/cmt/requirements
index 30e9e2d6ad4..d738b40d7a6 100644
--- a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/cmt/requirements
+++ b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/cmt/requirements
@@ -21,3 +21,4 @@ public
 library MuonPerformanceAlgs *.cxx -s=components *.cxx
 apply_pattern component_library
 apply_pattern declare_joboptions files="../share/*.py"
+apply_pattern declare_python_modules files="*.py"
\ No newline at end of file
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/CommonMuonTPConfig.py b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/CommonMuonTPConfig.py
new file mode 100644
index 00000000000..19f864b2217
--- /dev/null
+++ b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/CommonMuonTPConfig.py
@@ -0,0 +1,451 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+
+from AthenaCommon.AlgSequence import AlgSequence
+from AthenaCommon.AppMgr import ToolSvc
+
+job = AlgSequence()
+
+from MuonEfficiencyCorrections.MuonEfficiencyCorrectionsConf import CP__MuonEfficiencyScaleFactors
+
+
+# add an instance of the TP Algorithm
+def AddTagProbeAlg(name, ProbeCont, MatchCont):
+
+    from AthenaCommon.AlgSequence import AlgSequence
+    from AthenaCommon.AppMgr import ToolSvc
+    job = AlgSequence()
+    MuonContainerToUse = "Muons"
+    if hasattr(job, "MuonQualityUpdater"):
+        MuonContainerToUse = "UpdatedMuons"
+    from MuonPerformanceAlgs.MuonPerformanceAlgsConf import MuonTPAlg
+    thisAlg = MuonTPAlg(name)
+    thisAlg.TagContainerName   = MuonContainerToUse
+    thisAlg.ProbeContainerName = ProbeCont
+    thisAlg.MatchContainerName = MatchCont
+    job += thisAlg
+    return thisAlg
+
+# add a muon selection tool if there is none yet
+def AddMuonSelectionTool():
+
+    from AthenaCommon.AppMgr import ToolSvc
+    if not hasattr(ToolSvc,"TagProbeMuonSelectionTool"):
+        from MuonSelectorTools.MuonSelectorToolsConf import CP__MuonSelectionTool
+        ToolSvc += CP__MuonSelectionTool("TagProbeMuonSelectionTool")
+        ToolSvc.TagProbeMuonSelectionTool.MaxEta = 99.  # don't cut on eta in this tool
+
+# add a GRL tool if there is none yet
+def AddGoodRunsListSelectionTool(GoodRunsListVec=["/afs/cern.ch/user/a/atlasdqm/grlgen/Atlas_Ready/data15_13TeV.periodAllYear_HEAD_DQDefects-00-01-02_PHYS_StandardGRL_Atlas_Ready.xml"]):
+
+    from AthenaCommon.AppMgr import ToolSvc
+    if not hasattr(ToolSvc,"MCPAnalysisGRLTool"):
+        from AthenaCommon import CfgMgr
+        ToolSvc += CfgMgr.GoodRunsListSelectionTool("MCPAnalysisGRLTool")
+        ToolSvc.MCPAnalysisGRLTool.GoodRunsListVec=GoodRunsListVec
+
+# Add a track isolation updater tool
+def AddIsolationTools():
+    from AthenaCommon.AlgSequence import AlgSequence
+    job = AlgSequence()
+    from AthenaCommon.AppMgr import ToolSvc
+    
+    if not hasattr(ToolSvc, "MyTrackIsoTool"):
+        print "Adding it!!"
+            
+        #try:
+        from IsolationTool.IsolationToolConf import xAOD__TrackIsolationTool
+        ToolSvc += xAOD__TrackIsolationTool("MyTrackIsoTool")
+        # Cuts suggested by Dongliang to reproduce the default muon ptcone
+        ToolSvc.MyTrackIsoTool.TrackSelectionTool.maxZ0SinTheta= 3.
+        ToolSvc.MyTrackIsoTool.TrackSelectionTool.minPt= 1000.
+        #ToolSvc.MyTrackIsoTool.TrackSelectionTool.minNSiHits= 9
+        #ToolSvc.MyTrackIsoTool.TrackSelectionTool.minNPixelHits= 1
+        ToolSvc.MyTrackIsoTool.TrackSelectionTool.CutLevel="Loose"
+        
+        
+        from AthenaCommon.GlobalFlags import globalflags
+        isMC = not globalflags.DataSource()=='data'
+        from IsolationCorrections.IsolationCorrectionsConf import CP__IsolationCorrectionTool
+        IsoCorrectionTool = CP__IsolationCorrectionTool ("NewLeakageCorrTool",IsMC = isMC)
+        ToolSvc += IsoCorrectionTool
+
+        # tool to collect topo clusters in cone
+        from ParticlesInConeTools.ParticlesInConeToolsConf import xAOD__CaloClustersInConeTool
+        ToolSvc += xAOD__CaloClustersInConeTool("MyCaloClustersInConeTool",CaloClusterLocation = "CaloCalTopoClusters")
+
+        from CaloIdentifier import SUBCALO
+
+        from IsolationTool.IsolationToolConf import xAOD__CaloIsolationTool
+        ToolSvc += xAOD__CaloIsolationTool("MyCaloIsoTool")
+        ToolSvc.MyCaloIsoTool.IsoLeakCorrectionTool = ToolSvc.NewLeakageCorrTool
+        ToolSvc.MyCaloIsoTool.ClustersInConeTool = ToolSvc.MyCaloClustersInConeTool
+        ToolSvc.MyCaloIsoTool.EMCaloNums  = [SUBCALO.LAREM]
+        ToolSvc.MyCaloIsoTool.HadCaloNums = [SUBCALO.LARHEC, SUBCALO.TILE]
+        ToolSvc.MyCaloIsoTool.UseEMScale  = True
+        ToolSvc.MyCaloIsoTool.saveOnlyRequestedCorrections = True   
+        
+        #from MuonPerformanceAlgs.MuonPerformanceAlgsConf import TrackIsolationDecorAlg
+
+        #job += TrackIsolationDecorAlg("MyIDTrackDecorator")
+        #job.MyIDTrackDecorator.TrackIsolationTool = ToolSvc.MyTrackIsoTool
+        #job.MyIDTrackDecorator.CaloIsolationTool = ToolSvc.MyCaloIsoTool
+
+        
+        #except AttributeError:
+            #print "This did not work :("
+            #sys.exit(1)
+    
+# Add the trigger decision tool
+def AddTrigDecisionTool():
+    from AthenaCommon import CfgMgr
+    from AthenaCommon.Constants import WARNING
+    from AthenaCommon.AppMgr import ToolSvc
+    if not hasattr(ToolSvc, "TrigDecisionTool"):
+        ToolSvc += CfgMgr.Trig__TrigDecisionTool( "TrigDecisionTool",
+                                            OutputLevel = WARNING,
+                                            TrigDecisionKey = "xTrigDecision" )
+    
+# Add the trigger matching tool
+def AddTrigMatchingTool():
+    from AthenaCommon.AppMgr import ToolSvc
+    if not hasattr(ToolSvc,"TrigMuonMatching"):
+        from TrigMuonMatching.TrigMuonMatchingConf import Trig__TrigMuonMatching
+        trigmatch = Trig__TrigMuonMatching("TrigMuonMatching")
+        ToolSvc += trigmatch
+        #trigmatch.dRmin = 0.1
+        #trigmatch.LVL1dRmin = 0.2
+        trigmatch.TriggerTool = ToolSvc.TrigDecisionTool
+
+        
+# Add instance of the TP plotting tool
+def AddPlottingTool(name, EffiFlag, applySF=False, DoProbeMatchPlots=False, ProduceEfficiencies=False):
+
+    from AthenaCommon.AppMgr import ToolSvc
+    from MuonTPTools.MuonTPToolsConf import DiMuonTPPlotTool
+    thetool = DiMuonTPPlotTool(name)
+    thetool.EfficiencyFlag = EffiFlag
+    thetool.doTrkValidPlots = False
+    thetool.doJPsiKinematicPlots = False
+    thetool.doZmumuKinematicPlots = False
+    thetool.doFineEtaPhiPlots = False
+    thetool.doDetectorRegionPlots = False
+    thetool.DoAsymmErrorGraphs = False
+    thetool.doJPsiDileptonPlots = False
+    thetool.doZmumuDileptonPlots = False
+    thetool.doTrigValidPlots = False
+    thetool.ProduceProbeMatchPlots = DoProbeMatchPlots
+    thetool.ProduceEfficiencies = ProduceEfficiencies
+    thetool.ApplyScaleFactors = applySF
+    ToolSvc+= thetool
+    return thetool
+
+# Add a tree filling tool
+def AddTreeTool (name, EffiFlag,WriteSFInfo=False):
+    from AthenaCommon.AppMgr import ToolSvc
+    from MuonTPTools.MuonTPToolsConf import DiMuonTPTreeTool
+    thetool = DiMuonTPTreeTool(name)
+    thetool.EfficiencyFlag = EffiFlag
+    thetool.MuonSelectionTool = ToolSvc.TagProbeMuonSelectionTool
+    thetool.RecordScaleFactorInfo = WriteSFInfo
+    ToolSvc+= thetool
+    return thetool
+    
+def AddMuonEfficiencyScaleFactors (WorkingPoint="Medium"):
+    from AthenaCommon.AppMgr import ToolSvc
+    from MuonEfficiencyCorrections.MuonEfficiencyCorrectionsConf import CP__MuonEfficiencyScaleFactors
+    if not hasattr(ToolSvc, "EffiScaleFactors_%s"%WorkingPoint):
+        sf = CP__MuonEfficiencyScaleFactors("EffiScaleFactors_%s"%WorkingPoint)
+        sf.WorkingPoint = WorkingPoint
+        ToolSvc += sf
+    return getattr(ToolSvc,  "EffiScaleFactors_%s"%WorkingPoint)
+
+# Add a TP selection tool
+def AddZmumuTPSelectionTool (name, EffiFlag, ProbeType, SameSign=False, AntiIso=False, UseTrigger=True):
+
+    from AthenaCommon.AppMgr import ToolSvc
+    from AthenaCommon.Constants import DEBUG
+    from MuonTPTools.MuonTPToolsConf import DiMuonTPSelectionTool
+    thetool = DiMuonTPSelectionTool(name)
+    thetool.IsNotIncludedInNominal = False
+    
+    # Try to add the isolation updater tools (only works in full athena!)
+    if hasattr(ToolSvc, "MyTrackIsoTool"):
+        thetool.TrackIsolationTool = ToolSvc.MyTrackIsoTool
+        thetool.CaloIsolationTool = ToolSvc.MyCaloIsoTool
+    if hasattr(ToolSvc, "MCPAnalysisGRLTool"):
+        thetool.GRLTool = ToolSvc.MCPAnalysisGRLTool
+    # pt cuts
+    thetool.TagPtCut = 28000.
+    thetool.ProbePtCut = 10000.
+    # Z window
+    thetool.HighMassWindow = 121000.
+    thetool.LowMassWindow = 61000.
+    #thetool.OutputLevel=DEBUG      # this is a bit spammy
+    thetool.ProbeTrackIsoCut = -1.
+    
+    # Tag isolation 
+    thetool.TagTrackIsoCut = 0.2
+    thetool.TagCaloIsoCut = 0.2
+    thetool.TagTrackAntiIsoCut = -1
+    thetool.TagCaloAntiIsoCut = -1
+    
+    # Probe isolation: disabled by default - turned on below 
+    thetool.ProbeTrackIsoCut = -1
+    thetool.ProbeTrackAntiIsoCut = -1
+    thetool.ProbeCaloIsoCut = -1
+    thetool.ProbeCaloAntiIsoCut = -1
+    
+    # Tag IP cuts
+    thetool.TagD0Cut = -1
+    thetool.TagD0SignCut = 3
+    thetool.TagZ0Cut = 10
+    
+    # Probe IP cuts
+    thetool.ProbeD0Cut = -1
+    thetool.ProbeD0SignCut = 3
+    thetool.ProbeZ0Cut = 10
+    
+    thetool.EfficiencyFlag = EffiFlag
+    # tools  
+    thetool.SelectionTool = ToolSvc.TagProbeMuonSelectionTool
+    thetool.TriggerMatchTool = ToolSvc.TrigMuonMatching
+    thetool.TriggerDecisionTool = ToolSvc.TrigDecisionTool
+    # trigger(s)
+    if UseTrigger:
+        thetool.TagTriggerList = ["HLT_mu14","HLT_mu20_iloose_L1MU15","HLT_mu24_iloose_L1MU15","HLT_mu24_imedium","HLT_mu26_imedium"]
+    #thetool.TagTriggerList = []
+
+    if ProbeType == "ID":
+        thetool.UseIDProbes=True
+        thetool.ProbeIDHitCut=True
+        thetool.DeltaPhiCut=2.0
+        thetool.ProbeTrackIsoCut = 0.15    # try runing without probe iso!
+        thetool.ProbeCaloIsoCut = 0.25
+        #thetool.ProbeTrackIsoCut = -1
+        if AntiIso:
+            thetool.ProbeTrackIsoCut = -1
+            thetool.ProbeCaloIsoCut = -1
+            thetool.ProbeTrackAntiIsoCut = 1.2
+            thetool.ProbeCaloAntiIsoCut = 1.2
+            thetool.HighMassWindow = 121000.
+            thetool.LowMassWindow = 61000.
+            thetool.ProbeZ0Cut = -1
+            thetool.ProbeD0SignCut =-1
+            thetool.ProbeD0Cut =-1
+    if ProbeType == "MS":
+        thetool.ProbeIDHitCut=False
+        thetool.UseMSProbes = True
+        thetool.DeltaPhiCut=2.0
+        thetool.ProbeCaloIsoCut = 0.35    # try runing without probe iso!
+        thetool.ProbeD0Cut = -1
+        thetool.ProbeZ0Cut = -1
+        thetool.ProbeD0SignCut =-1
+        if AntiIso:
+            thetool.ProbeCaloIsoCut = -1
+            thetool.ProbeCaloAntiIsoCut = 1.2
+            thetool.HighMassWindow = 121000.
+            thetool.LowMassWindow = 61000.
+            thetool.ProbeZ0Cut = -1
+            thetool.ProbeD0SignCut =-1
+            thetool.ProbeD0Cut =-1
+            #thetool.TagTrackIsoCut = -1
+            #thetool.TagTrackAntiIsoCut = 1.4
+    if ProbeType == "CaloTag":
+        thetool.UseCaloProbes = True
+        thetool.ProbeIDHitCut=True
+        thetool.ProbeTrackIsoCut = 0.15    # try runing without probe iso!
+        #thetool.ProbeCaloIsoCut = 0.25
+        thetool.DeltaPhiCut=2.0
+        if AntiIso:
+            thetool.ProbeTrackIsoCut = -1
+            thetool.ProbeCaloIsoCut = -1
+            thetool.ProbeTrackAntiIsoCut = 1.2
+            thetool.ProbeCaloAntiIsoCut = 1.2
+            thetool.HighMassWindow = 121000.
+            thetool.LowMassWindow = 61000.
+            thetool.ProbeZ0Cut = -1
+            thetool.ProbeD0SignCut =-1
+            thetool.ProbeD0Cut =-1
+    if ProbeType == "Truth":
+        thetool.UseTruthProbes = True
+    if ProbeType == "Loose":
+        thetool.UseLooseProbes = True
+    if ProbeType == "Medium":
+        thetool.UseMediumProbes = True
+    if ProbeType == "Tight":
+        thetool.UseTightProbes = True
+    if ProbeType == "HighPt":
+        thetool.UseHighPtProbes = True
+
+
+    if SameSign:
+        thetool.AcceptOppCharge=False
+        thetool.AcceptSameCharge=True
+
+    ToolSvc += thetool
+    return thetool
+
+# Add a TP selection tool
+def AddJPsiTPSelectionTool (name, EffiFlag, ProbeType, SameSign=False, AntiIso=False, UseTrigger=True):
+
+    from AthenaCommon.AppMgr import ToolSvc
+    from AthenaCommon.Constants import DEBUG
+    from MuonTPTools.MuonTPToolsConf import DiMuonTPSelectionTool
+    thetool = DiMuonTPSelectionTool(name)
+    thetool.IsNotIncludedInNominal = False
+    
+    # Try to add the isolation updater tools (only works in full athena!)
+    if hasattr(ToolSvc, "MyTrackIsoTool"):
+        thetool.TrackIsolationTool = ToolSvc.MyTrackIsoTool
+        thetool.CaloIsolationTool = ToolSvc.MyCaloIsoTool
+    if hasattr(ToolSvc, "MCPAnalysisGRLTool"):
+        thetool.GRLTool = ToolSvc.MCPAnalysisGRLTool
+    # pt cuts
+    thetool.TagPtCut = 4000.
+    thetool.ProbePtCut = 2500.
+    # JPsi mass window
+    thetool.HighMassWindow = 3500.
+    thetool.LowMassWindow = 2700.
+    #thetool.OutputLevel=DEBUG      # this is a bit spammy
+    thetool.ProbeTrackIsoCut = -1.
+    
+    # Tag isolation 
+    thetool.TagTrackIsoCut = -1
+    thetool.TagCaloIsoCut = -1
+    thetool.TagTrackAntiIsoCut = -1
+    thetool.TagCaloAntiIsoCut = -1
+    
+    # Probe isolation: disabled by default - turned on below 
+    thetool.ProbeTrackIsoCut = -1
+    thetool.ProbeTrackAntiIsoCut = -1
+    thetool.ProbeCaloIsoCut = -1
+    thetool.ProbeCaloAntiIsoCut = -1
+    
+    # Tag IP cuts
+    thetool.TagD0Cut = 0.3
+    thetool.TagD0SignCut = 3
+    thetool.TagZ0Cut = 10
+    
+    # Probe IP cuts
+    thetool.ProbeD0Cut = 0.3
+    thetool.ProbeD0SignCut = 3
+    thetool.ProbeZ0Cut = 10
+    
+    thetool.EfficiencyFlag = EffiFlag
+    # tools  
+    thetool.SelectionTool = ToolSvc.TagProbeMuonSelectionTool
+    thetool.TriggerMatchTool = ToolSvc.TrigMuonMatching
+    thetool.TriggerDecisionTool = ToolSvc.TrigDecisionTool
+    # trigger(s)
+    if UseTrigger:
+        thetool.TagTriggerList = ["HLT_noalg_L1MU4",
+                                  "HLT_noalg_L1MU6",
+                                  "HLT_mu4",
+                                  "HLT_mu6"]
+        if ProbeType == "ID" or ProbeType == "CaloTag" or ProbeType == "Loose" or ProbeType == "Medium" or ProbeType == "Tight":
+            thetool.TagTriggerList += [
+                                  "HLT_mu4_bJpsi_Trkloose",
+                                  "HLT_mu6_bJpsi_Trkloose",
+                                  "HLT_mu10_bJpsi_Trkloose",
+                                  "HLT_mu18_bJpsi_Trkloose",]
+        if ProbeType == "MS":
+            thetool.TagTriggerList = ["HLT_mu4_mu4_idperf_bJpsimumu_noid"]
+        if ProbeType == "Loose" or ProbeType == "Medium" or ProbeType == "Tight":
+            thetool.TagTriggerList += [
+                                  "HLT_mu20_2mu0noL1_JpsimumuFS",
+                                  "HLT_mu18_2mu0noL1_JpsimumuFS",
+                                  "HLT_mu20_2mu4_JpsimumuL2",
+                                  "HLT_mu18_2mu4_JpsimumuL2"]
+            
+    thetool.DeltaPhiCut=0.2
+    thetool.DeltaEtaCut=0.2
+
+    if ProbeType == "ID":
+        thetool.UseIDProbes=True
+        thetool.ProbeIDHitCut=True
+    if ProbeType == "MS":
+        thetool.ProbeIDHitCut=False
+        thetool.UseMSProbes = True
+    if ProbeType == "CaloTag":
+        thetool.UseCaloProbes = True
+        thetool.ProbeIDHitCut=True
+    if ProbeType == "Truth":
+        thetool.UseTruthProbes = True
+    if ProbeType == "TruthMatchedMuons":
+        thetool.UseTruthMatchedProbes = True
+    if ProbeType == "Loose":
+        thetool.UseLooseProbes = True
+    if ProbeType == "Medium":
+        thetool.UseMediumProbes = True
+    if ProbeType == "Tight":
+        thetool.UseTightProbes = True
+    if ProbeType == "HighPt":
+        thetool.UseHighPtProbes = True
+
+    ToolSvc += thetool
+    return thetool
+
+
+# Add a reco efficiency tool
+def AddMuonRecoTPEfficiencyTool (name, EffiFlag):
+    from AthenaCommon.AppMgr import ToolSvc
+    from MuonTPTools.MuonTPToolsConf import MuonRecoTPEfficiencyTool
+    thetool = MuonRecoTPEfficiencyTool(name)
+    thetool.MuonAuthor = 21
+    thetool.MatchToAnyMS = False
+    thetool.MatchToCB = False
+    thetool.MatchToLoose = False
+    thetool.MatchToMedium = False
+    thetool.MatchToTight = False
+    thetool.MatchToID = False
+    thetool.MatchToCaloTag = False
+    thetool.MatchToHighPt = False
+    thetool.MatchPtCut = 2000.0         # speed up the loop a bit
+    thetool.EfficiencyFlag = EffiFlag
+    thetool.SelectionTool = ToolSvc.TagProbeMuonSelectionTool
+    thetool.TriggerMatchTool = ToolSvc.TrigMuonMatching
+    ToolSvc += thetool
+    return thetool
+
+
+# Add a trigger efficiency tool
+def AddTriggerTPEfficiencyTool (name, EffiFlag):
+    from AthenaCommon.AppMgr import ToolSvc
+    from MuonTPTools.MuonTPToolsConf import MuonTrigTPEfficiencyTool
+    thetool = MuonTrigTPEfficiencyTool(name)
+    thetool.MuonAuthor       = 21
+    thetool.MatchPtCut       = 5000.0         # speed up the loop a bit
+    thetool.EfficiencyFlag   = EffiFlag
+    thetool.SelectionTool    = ToolSvc.TagProbeMuonSelectionTool
+    thetool.TriggerMatchTool = ToolSvc.TrigMuonMatching
+    ToolSvc += thetool
+    return thetool
+
+
+# Add an iso efficiency tool
+def AddIsolTPEfficiencyTool (name, EffiFlag):
+    from AthenaCommon.AppMgr import ToolSvc
+    from MuonTPTools.MuonTPToolsConf import MuonIsolTPEfficiencyTool
+    thetool = MuonIsolTPEfficiencyTool(name)
+    thetool.MuonAuthor       = 21
+    thetool.MatchPtCut       = 5000.0         # speed up the loop a bit
+    thetool.EfficiencyFlag   = EffiFlag
+    thetool.SelectionTool    = ToolSvc.TagProbeMuonSelectionTool
+    thetool.TriggerMatchTool = ToolSvc.TrigMuonMatching
+    ToolSvc += thetool
+    return thetool
+
+# Add an instance of the 'main' TP tool
+def AddMuonTPTool (name, EffiFlag):
+
+    from AthenaCommon.Constants import DEBUG
+    from AthenaCommon.AppMgr import ToolSvc
+    from MuonTPTools.MuonTPToolsConf import MuonTPTool
+    thetool = MuonTPTool(name)
+    thetool.EfficiencyFlag = EffiFlag
+    #thetool.OutputLevel = DEBUG
+    thetool.DumpInefficientEvents = False
+    ToolSvc += thetool
+    return thetool
+
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/JPsiTPIsolAnalysis.py b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/JPsiTPIsolAnalysis.py
new file mode 100644
index 00000000000..d57cd20ce22
--- /dev/null
+++ b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/JPsiTPIsolAnalysis.py
@@ -0,0 +1,59 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+from MuonPerformanceAlgs import CommonMuonTPConfig 
+  
+def AddIsolPlots(name_suffix,
+                 doEtaSlices=True, 
+                 doClosure=False,
+                 DoProbeMatchPlots=True,
+                 ProduceEfficiencies=False):
+    
+    PlotTools = []
+    # add plotting tools in slices
+    if doEtaSlices:
+        Slices = {
+                   "All" : (0.0,10.0),
+                   "noCrack" : (0.1,10.0),
+                   "Crack" : (0.0,0.1),
+                   "Barrel" : (0.1,1.1),
+                   "Transition" : (1.1, 1.3),
+                   "Endcap" : (1.3,2.0),
+                   "CSC" : (2.0,2.7)
+                   }
+
+        for etaslice, interval in Slices.iteritems():
+            PlotTool = CommonMuonTPConfig.AddPlottingTool(name="JPsiTPIsoPlottingTool_%s_%s"%(name_suffix,etaslice),EffiFlag=name_suffix+"_"+etaslice,applySF = False,DoProbeMatchPlots=DoProbeMatchPlots,ProduceEfficiencies=ProduceEfficiencies)
+            PlotTool.ProbeAbsEtaMin = interval[0]
+            PlotTool.ProbeAbsEtaMax = interval[1]
+            PlotTools.append(PlotTool)
+            if doClosure:
+                PlotToolCL = CommonMuonTPConfig.AddPlottingTool(name="JPsiTPIsoPlottingToolClosure_%s_%s"%(name_suffix,etaslice),EffiFlag=name_suffix+"_"+etaslice+"_Closure",applySF = True,DoProbeMatchPlots=DoProbeMatchPlots,ProduceEfficiencies=ProduceEfficiencies)
+                PlotToolCL.ProbeAbsEtaMin = interval[0]
+                PlotToolCL.ProbeAbsEtaMax = interval[1]
+                PlotTools.append(PlotToolCL)
+                
+    else:
+        PlotTools = [CommonMuonTPConfig.AddPlottingTool(name="JPsiTPIsoPlottingTool_%s_All"%name_suffix,EffiFlag=name_suffix+"_All",applySF = False,DoProbeMatchPlots=DoProbeMatchPlots,ProduceEfficiencies=ProduceEfficiencies)]
+        if doClosure:
+            PlotTools.append(CommonMuonTPConfig.AddPlottingTool(name="JPsiTPIsoPlottingToolClosure_%s_All"%name_suffix,EffiFlag=name_suffix+"_All_Closure",applySF = True,DoProbeMatchPlots=DoProbeMatchPlots,ProduceEfficiencies=ProduceEfficiencies))
+    # config the plot tools for Zmm isolation
+    for thetool in PlotTools:
+        thetool.doJPsiKinematicPlots = True
+        thetool.doFineEtaPhiPlots = True
+        thetool.DoAsymmErrorGraphs = True
+        thetool.doJPsiDileptonPlots = True
+        
+    return PlotTools
+    
+def AddIsolMatchTools(name_suffix):
+    #MATCH_DR = 0.05
+    #MatchingTools = []
+    #thistool = CommonMuonTPConfig.AddIsolTPEfficiencyTool(name="ZmumuTPIsoEfficiencyTool_%s_CB"%name_suffix,EffiFlag="Isolation")
+    #thistool.ApplyScaleFactors = False
+    #thistool.MaximumDrCut = MATCH_DR
+    #MatchingTools += [thistool]
+    #return MatchingTools
+    return []
+     
+     
+     
\ No newline at end of file
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/JPsiTPMuonAnalysis.py b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/JPsiTPMuonAnalysis.py
new file mode 100644
index 00000000000..c29d391a09b
--- /dev/null
+++ b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/JPsiTPMuonAnalysis.py
@@ -0,0 +1,339 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+from MuonPerformanceAlgs import CommonMuonTPConfig, JPsiTPTrigAnalysis, JPsiTPIsolAnalysis
+
+def AddConfiguredMuonTPAlg(name_suffix  = "MuonProbe_JPsi",
+                            MatchContainer = "Muons",
+                            doIso = True,
+                            doTrig = True,
+                            doTrigEtaSlices    = True, 
+                            doIsolEtaSlices    = False, 
+                            doIsolPlots      = False,
+                            doTriggerPlots      = True,
+                            writeNtuple    = False,
+                            doClosure      = False,
+                            doDRSys    = False,
+                            doDPhiTPSys    = False,
+                            doProbeCharSys = False,
+                            doVeryLooseProbes = False,
+                            doLooseProbes   = False,
+                            doMediumProbes  = False,
+                            doTightProbes   = False,
+                            doHighPtProbes   = False,
+                            doTruthProbes   = False,
+                            DoProbeMatchPlots=True,
+                            ProduceEfficiencies=False,
+                            doL1 = False,
+                            doL2 = False, doEF = False,
+                            doHLT = False
+                ):
+    
+    from AthenaCommon.AlgSequence import AlgSequence
+    from AthenaCommon.AppMgr import ToolSvc
+    job = AlgSequence()
+
+    MuonContainerToUse = "Muons"
+    if hasattr(job, "MuonQualityUpdater"):
+        MuonContainerToUse = "UpdatedMuons"
+
+    ProbeContainer = MuonContainerToUse
+    theAlg = CommonMuonTPConfig.AddTagProbeAlg(name="JPsiTPMuonAlg_%s"%name_suffix, ProbeCont=ProbeContainer, MatchCont=MatchContainer)
+    theAlg.TopLevelFolderName = "JPsiTPMuon"
+
+    SelectionTools = []
+    
+    if doLooseProbes:
+        SelecToolsOC_LooseProbes = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_LooseProbes_%s"%name_suffix,EffiFlag="%s_OC_LooseProbes"%name_suffix, ProbeType="Loose")
+        SelecToolsOC_LooseProbes.UseLooseProbes = True
+        SelectionTools.append(SelecToolsOC_LooseProbes)
+        
+        SelecToolsSC_LooseProbes = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_SC_LooseProbes_%s"%name_suffix,EffiFlag="%s_SC_LooseProbes"%name_suffix, ProbeType="Loose", SameSign=True)
+        SelecToolsSC_LooseProbes.UseLooseProbes = True
+        SelectionTools.append(SelecToolsSC_LooseProbes)
+
+        
+        if doDPhiTPSys:
+            SelecToolsOC_LooseProbesDPhiCut = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_LooseProbesDPhiCut_%s"%name_suffix,EffiFlag="%s_OC_LooseProbesDPhiCut"%name_suffix, ProbeType="Loose")
+            SelecToolsOC_LooseProbesDPhiCut.DeltaPhiCut  = 3.04
+            SelecToolsOC_LooseProbesDPhiCut.IsNominal = False
+            SelectionTools.append(SelecToolsOC_LooseProbesDPhiCut)
+            
+            SelecToolsSC_LooseProbesDPhiCut = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_SC_LooseProbesDPhiCut_%s"%name_suffix,EffiFlag="%s_SC_LooseProbesDPhiCut"%name_suffix, ProbeType="Loose", SameSign=True)
+            SelecToolsSC_LooseProbesDPhiCut.DeltaPhiCut  = 3.04
+            SelecToolsSC_LooseProbesDPhiCut.IsNominal = False
+            SelectionTools.append(SelecToolsSC_LooseProbesDPhiCut)
+
+        if doProbeCharSys:
+            SelecToolsOC_LooseProbesPos = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_LooseProbesPos_%s"%name_suffix,EffiFlag="%s_OC_LooseProbesPos"%name_suffix, ProbeType="Loose")
+            SelecToolsOC_LooseProbesPos.doProbeChargeSys = True
+            SelecToolsOC_LooseProbesPos.ProbeCharge = "positive"
+            SelecToolsOC_LooseProbesPos.IsNominal = False
+            SelectionTools.append(SelecToolsOC_LooseProbesPos)
+
+            SelecToolsOC_LooseProbesNeg = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_LooseProbesNeg_%s"%name_suffix,EffiFlag="%s_OC_LooseProbesNeg"%name_suffix, ProbeType="Loose")
+            SelecToolsOC_LooseProbesNeg.doProbeChargeSys = True
+            SelecToolsOC_LooseProbesNeg.IsNominal = False
+            SelecToolsOC_LooseProbesNeg.ProbeCharge = "negative"
+            SelectionTools.append(SelecToolsOC_LooseProbesNeg)
+            
+            
+            SelecToolsSC_LooseProbesPos = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_SC_LooseProbesPos_%s"%name_suffix,EffiFlag="%s_SC_LooseProbesPos"%name_suffix, ProbeType="Loose", SameSign=True)
+            SelecToolsSC_LooseProbesPos.doProbeChargeSys = True
+            SelecToolsSC_LooseProbesPos.ProbeCharge = "positive"
+            SelecToolsSC_LooseProbesPos.IsNominal = False
+            SelectionTools.append(SelecToolsSC_LooseProbesPos)
+
+            SelecToolsSC_LooseProbesNeg = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_SC_LooseProbesNeg_%s"%name_suffix,EffiFlag="%s_SC_LooseProbesNeg"%name_suffix, ProbeType="Loose", SameSign=True)
+            SelecToolsSC_LooseProbesNeg.doProbeChargeSys = True
+            SelecToolsSC_LooseProbesNeg.IsNominal = False
+            SelecToolsSC_LooseProbesNeg.ProbeCharge = "negative"
+            SelectionTools.append(SelecToolsSC_LooseProbesNeg)
+
+    
+    if doMediumProbes:
+        SelecToolsOC_MediumProbes = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_MediumProbes_%s"%name_suffix,EffiFlag="%s_OC_MediumProbes"%name_suffix, ProbeType="Medium")
+        SelecToolsOC_MediumProbes.UseMediumProbes = True
+        SelectionTools.append(SelecToolsOC_MediumProbes)
+        
+        SelecToolsSC_MediumProbes = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_SC_MediumProbes_%s"%name_suffix,EffiFlag="%s_SC_MediumProbes"%name_suffix, ProbeType="Medium", SameSign=True)
+        SelecToolsSC_MediumProbes.UseMediumProbes = True
+        SelectionTools.append(SelecToolsSC_MediumProbes)
+
+        
+        if doDPhiTPSys:
+            SelecToolsOC_MediumProbesDPhiCut = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_MediumProbesDPhiCut_%s"%name_suffix,EffiFlag="%s_OC_MediumProbesDPhiCut"%name_suffix, ProbeType="Medium")
+            SelecToolsOC_MediumProbesDPhiCut.DeltaPhiCut  = 3.04
+            SelecToolsOC_MediumProbesDPhiCut.IsNominal = False
+            SelectionTools.append(SelecToolsOC_MediumProbesDPhiCut)
+            
+            SelecToolsSC_MediumProbesDPhiCut = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_SC_MediumProbesDPhiCut_%s"%name_suffix,EffiFlag="%s_SC_MediumProbesDPhiCut"%name_suffix, ProbeType="Medium", SameSign=True)
+            SelecToolsSC_MediumProbesDPhiCut.DeltaPhiCut  = 3.04
+            SelecToolsSC_MediumProbesDPhiCut.IsNominal = False
+            SelectionTools.append(SelecToolsSC_MediumProbesDPhiCut)
+
+        if doProbeCharSys:
+            SelecToolsOC_MediumProbesPos = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_MediumProbesPos_%s"%name_suffix,EffiFlag="%s_OC_MediumProbesPos"%name_suffix, ProbeType="Medium")
+            SelecToolsOC_MediumProbesPos.doProbeChargeSys = True
+            SelecToolsOC_MediumProbesPos.ProbeCharge = "positive"
+            SelecToolsOC_MediumProbesPos.IsNominal = False
+            SelectionTools.append(SelecToolsOC_MediumProbesPos)
+
+            SelecToolsOC_MediumProbesNeg = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_MediumProbesNeg_%s"%name_suffix,EffiFlag="%s_OC_MediumProbesNeg"%name_suffix, ProbeType="Medium")
+            SelecToolsOC_MediumProbesNeg.doProbeChargeSys = True
+            SelecToolsOC_MediumProbesNeg.IsNominal = False
+            SelecToolsOC_MediumProbesNeg.ProbeCharge = "negative"
+            SelectionTools.append(SelecToolsOC_MediumProbesNeg)
+            
+            
+            SelecToolsSC_MediumProbesPos = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_SC_MediumProbesPos_%s"%name_suffix,EffiFlag="%s_SC_MediumProbesPos"%name_suffix, ProbeType="Medium", SameSign=True)
+            SelecToolsSC_MediumProbesPos.doProbeChargeSys = True
+            SelecToolsSC_MediumProbesPos.ProbeCharge = "positive"
+            SelecToolsSC_MediumProbesPos.IsNominal = False
+            SelectionTools.append(SelecToolsSC_MediumProbesPos)
+
+            SelecToolsSC_MediumProbesNeg = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_SC_MediumProbesNeg_%s"%name_suffix,EffiFlag="%s_SC_MediumProbesNeg"%name_suffix, ProbeType="Medium", SameSign=True)
+            SelecToolsSC_MediumProbesNeg.doProbeChargeSys = True
+            SelecToolsSC_MediumProbesNeg.IsNominal = False
+            SelecToolsSC_MediumProbesNeg.ProbeCharge = "negative"
+            SelectionTools.append(SelecToolsSC_MediumProbesNeg)
+
+    if doTightProbes:
+        SelecToolsOC_TightProbes = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_TightProbes_%s"%name_suffix,EffiFlag="%s_OC_TightProbes"%name_suffix, ProbeType="Tight")
+        SelecToolsOC_TightProbes.UseTightProbes = True
+        SelectionTools.append(SelecToolsOC_TightProbes)
+        
+        SelecToolsSC_TightProbes = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_SC_TightProbes_%s"%name_suffix,EffiFlag="%s_SC_TightProbes"%name_suffix, ProbeType="Tight", SameSign=True)
+        SelecToolsSC_TightProbes.UseTightProbes = True
+        SelectionTools.append(SelecToolsSC_TightProbes)
+
+        
+        if doDPhiTPSys:
+            SelecToolsOC_TightProbesDPhiCut = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_TightProbesDPhiCut_%s"%name_suffix,EffiFlag="%s_OC_TightProbesDPhiCut"%name_suffix, ProbeType="Tight")
+            SelecToolsOC_TightProbesDPhiCut.DeltaPhiCut  = 3.04
+            SelecToolsOC_TightProbesDPhiCut.IsNominal = False
+            SelectionTools.append(SelecToolsOC_TightProbesDPhiCut)
+            
+            SelecToolsSC_TightProbesDPhiCut = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_SC_TightProbesDPhiCut_%s"%name_suffix,EffiFlag="%s_SC_TightProbesDPhiCut"%name_suffix, ProbeType="Tight", SameSign=True)
+            SelecToolsSC_TightProbesDPhiCut.DeltaPhiCut  = 3.04
+            SelecToolsSC_TightProbesDPhiCut.IsNominal = False
+            SelectionTools.append(SelecToolsSC_TightProbesDPhiCut)
+
+        if doProbeCharSys:
+            SelecToolsOC_TightProbesPos = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_TightProbesPos_%s"%name_suffix,EffiFlag="%s_OC_TightProbesPos"%name_suffix, ProbeType="Tight")
+            SelecToolsOC_TightProbesPos.doProbeChargeSys = True
+            SelecToolsOC_TightProbesPos.ProbeCharge = "positive"
+            SelecToolsOC_TightProbesPos.IsNominal = False
+            SelectionTools.append(SelecToolsOC_TightProbesPos)
+
+            SelecToolsOC_TightProbesNeg = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_TightProbesNeg_%s"%name_suffix,EffiFlag="%s_OC_TightProbesNeg"%name_suffix, ProbeType="Tight")
+            SelecToolsOC_TightProbesNeg.doProbeChargeSys = True
+            SelecToolsOC_TightProbesNeg.IsNominal = False
+            SelecToolsOC_TightProbesNeg.ProbeCharge = "negative"
+            SelectionTools.append(SelecToolsOC_TightProbesNeg)
+            
+            
+            SelecToolsSC_TightProbesPos = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_SC_TightProbesPos_%s"%name_suffix,EffiFlag="%s_SC_TightProbesPos"%name_suffix, ProbeType="Tight", SameSign=True)
+            SelecToolsSC_TightProbesPos.doProbeChargeSys = True
+            SelecToolsSC_TightProbesPos.ProbeCharge = "positive"
+            SelecToolsSC_TightProbesPos.IsNominal = False
+            SelectionTools.append(SelecToolsSC_TightProbesPos)
+
+            SelecToolsSC_TightProbesNeg = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_SC_TightProbesNeg_%s"%name_suffix,EffiFlag="%s_SC_TightProbesNeg"%name_suffix, ProbeType="Tight", SameSign=True)
+            SelecToolsSC_TightProbesNeg.doProbeChargeSys = True
+            SelecToolsSC_TightProbesNeg.IsNominal = False
+            SelecToolsSC_TightProbesNeg.ProbeCharge = "negative"
+            SelectionTools.append(SelecToolsSC_TightProbesNeg)
+
+
+    if doHighPtProbes:
+        SelecToolsOC_HighPtProbes = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_HighPtProbes_%s"%name_suffix,EffiFlag="%s_OC_HighPtProbes"%name_suffix, ProbeType="HighPt")
+        SelecToolsOC_HighPtProbes.UseHighPtProbes = True
+        SelectionTools.append(SelecToolsOC_HighPtProbes)
+        
+        SelecToolsSC_HighPtProbes = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_SC_HighPtProbes_%s"%name_suffix,EffiFlag="%s_SC_HighPtProbes"%name_suffix, ProbeType="HighPt", SameSign=True)
+        SelecToolsSC_HighPtProbes.UseHighPtProbes = True
+        SelectionTools.append(SelecToolsSC_HighPtProbes)
+
+        
+        if doDPhiTPSys:
+            SelecToolsOC_HighPtProbesDPhiCut = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_HighPtProbesDPhiCut_%s"%name_suffix,EffiFlag="%s_OC_HighPtProbesDPhiCut"%name_suffix, ProbeType="HighPt")
+            SelecToolsOC_HighPtProbesDPhiCut.DeltaPhiCut  = 3.04
+            SelecToolsOC_HighPtProbesDPhiCut.IsNominal = False
+            SelectionTools.append(SelecToolsOC_HighPtProbesDPhiCut)
+            
+            SelecToolsSC_HighPtProbesDPhiCut = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_SC_HighPtProbesDPhiCut_%s"%name_suffix,EffiFlag="%s_SC_HighPtProbesDPhiCut"%name_suffix, ProbeType="HighPt", SameSign=True)
+            SelecToolsSC_HighPtProbesDPhiCut.DeltaPhiCut  = 3.04
+            SelecToolsSC_HighPtProbesDPhiCut.IsNominal = False
+            SelectionTools.append(SelecToolsSC_HighPtProbesDPhiCut)
+
+        if doProbeCharSys:
+            SelecToolsOC_HighPtProbesPos = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_HighPtProbesPos_%s"%name_suffix,EffiFlag="%s_OC_HighPtProbesPos"%name_suffix, ProbeType="HighPt")
+            SelecToolsOC_HighPtProbesPos.doProbeChargeSys = True
+            SelecToolsOC_HighPtProbesPos.ProbeCharge = "positive"
+            SelecToolsOC_HighPtProbesPos.IsNominal = False
+            SelectionTools.append(SelecToolsOC_HighPtProbesPos)
+
+            SelecToolsOC_HighPtProbesNeg = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_HighPtProbesNeg_%s"%name_suffix,EffiFlag="%s_OC_HighPtProbesNeg"%name_suffix, ProbeType="HighPt")
+            SelecToolsOC_HighPtProbesNeg.doProbeChargeSys = True
+            SelecToolsOC_HighPtProbesNeg.IsNominal = False
+            SelecToolsOC_HighPtProbesNeg.ProbeCharge = "negative"
+            SelectionTools.append(SelecToolsOC_HighPtProbesNeg)
+            
+            
+            SelecToolsSC_HighPtProbesPos = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_SC_HighPtProbesPos_%s"%name_suffix,EffiFlag="%s_SC_HighPtProbesPos"%name_suffix, ProbeType="HighPt", SameSign=True)
+            SelecToolsSC_HighPtProbesPos.doProbeChargeSys = True
+            SelecToolsSC_HighPtProbesPos.ProbeCharge = "positive"
+            SelecToolsSC_HighPtProbesPos.IsNominal = False
+            SelectionTools.append(SelecToolsSC_HighPtProbesPos)
+
+            SelecToolsSC_HighPtProbesNeg = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_SC_HighPtProbesNeg_%s"%name_suffix,EffiFlag="%s_SC_HighPtProbesNeg"%name_suffix, ProbeType="HighPt", SameSign=True)
+            SelecToolsSC_HighPtProbesNeg.doProbeChargeSys = True
+            SelecToolsSC_HighPtProbesNeg.IsNominal = False
+            SelecToolsSC_HighPtProbesNeg.ProbeCharge = "negative"
+            SelectionTools.append(SelecToolsSC_HighPtProbesNeg)
+
+    from AthenaCommon.GlobalFlags import globalflags
+    if doTruthProbes and not globalflags.DataSource()=='data':
+        SelecToolsOC_TruthProbes = CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_TruthProbes_%s"%name_suffix,EffiFlag="%s_TruthProbes"%name_suffix, ProbeType="TruthMatchedMuons")
+        SelectionTools.append(SelecToolsOC_TruthProbes)
+        
+
+    for thetool in SelectionTools:
+        thetool.ProbeTrackIsoCut = -1
+        thetool.ProbeTrackAntiIsoCut = -1
+        thetool.ProbeCaloIsoCut = -1
+        thetool.ProbeCaloAntiIsoCut = -1
+        # also accept high eta muons
+        thetool.ProbeEtaCut = 4.5  
+        
+    PlotTools = []
+    
+    # first the trigger plots 
+    if doTrig and doTriggerPlots:
+        PlotTools += JPsiTPTrigAnalysis.AddTrigPlots(name_suffix=name_suffix,doEtaSlices=doTrigEtaSlices,
+                                        doClosure=doClosure,
+                                        DoProbeMatchPlots=DoProbeMatchPlots,
+                                        ProduceEfficiencies=ProduceEfficiencies)
+    # then the isolation plots
+    if doIso and doIsolPlots:
+        PlotTools += JPsiTPIsolAnalysis.AddIsolPlots(name_suffix=name_suffix,doEtaSlices=doIsolEtaSlices,
+                                        doClosure=doClosure,
+                                        DoProbeMatchPlots=DoProbeMatchPlots,
+                                        ProduceEfficiencies=ProduceEfficiencies)
+        
+    
+    MatchingTools = []
+    if doTrig:
+        MatchingTools += JPsiTPTrigAnalysis.AddTrigMatchTools(name_suffix=name_suffix,doL1 = doL1, doL2=doL2, doEF=doEF,doHLT=doHLT,doDRSys=doDRSys)
+    if doIso:
+        MatchingTools += JPsiTPIsolAnalysis.AddIsolMatchTools(name_suffix)
+    
+    
+    ntuples = []
+    if writeNtuple:
+        ntuples.append(CommonMuonTPConfig.AddTreeTool(name="JPsiTPMuonTreeTool_%s"%name_suffix, EffiFlag="Trees",WriteSFInfo=doClosure))
+    
+    for ntuple in ntuples:
+        if doIso:
+            ntuple.AddExtendedIsolation = True
+        
+    # create the TP tool itself
+    TheTPTool = CommonMuonTPConfig.AddMuonTPTool(name = "MuonProbeTPTool_%s"%name_suffix,EffiFlag=name_suffix)
+    TheTPTool.MuonTPSelectionTools  = SelectionTools
+    TheTPTool.PlottingTools         = PlotTools
+    TheTPTool.MuonTPEfficiencyTools = MatchingTools
+    TheTPTool.TreeTools             = ntuples
+    theAlg.MuonTPTools += [TheTPTool]
+    
+    
+    
+def AddJPsiTPMuonAnalysis(doIso = True,
+                           doTrig = True,
+                           doTrigEtaSlices    = True, 
+                           doIsolEtaSlices    = False, 
+                           doIsolPlots      = False,
+                           doTriggerPlots      = True,
+                           writeNtuple=False, doClosure=False, 
+                           doDRSys=False, doDPhiTPSys=True, 
+                           doProbeCharSys=True, 
+                           doLooseProbes=False, doMediumProbes=False, 
+                           doTightProbes=False, doTruthProbes=False,
+                           doHighPtProbes=False,
+                           doL1=False, doL2=False, doEF=False, 
+                           doHLT=False, DoProbeMatchPlots=True, 
+                           ProduceEfficiencies=False):
+    
+    from AthenaCommon.AlgSequence import AlgSequence
+    from AthenaCommon.AppMgr import ToolSvc
+    job = AlgSequence()
+
+
+    MuonContainerToUse = "Muons"
+    if hasattr(job, "MuonQualityUpdater"):
+        MuonContainerToUse = "UpdatedMuons"
+        
+    ##########################################################################################
+    # Add the Zmm TP algorithm for muon probes
+    AddConfiguredMuonTPAlg( name_suffix  = "MuonProbe_JPsi",
+                            MatchContainer = "Muons",
+                            doIso=doIso,
+                            doTrig=doTrig,
+                            doTrigEtaSlices    = doTrigEtaSlices, 
+                            doIsolEtaSlices    = doIsolEtaSlices, 
+                            doIsolPlots      = doIsolPlots,
+                            doTriggerPlots      = doTriggerPlots,
+                            writeNtuple    = writeNtuple,
+                            doClosure      = doClosure,
+                            doDRSys      = doDRSys,
+                            doDPhiTPSys    = doDPhiTPSys,
+                            doProbeCharSys = doProbeCharSys,
+                            doLooseProbes   = doLooseProbes,
+                            doMediumProbes  = doMediumProbes,
+                            doTightProbes   = doTightProbes,
+                            doHighPtProbes   = doHighPtProbes,
+                            doTruthProbes   = doTruthProbes,
+                            doL1 = doL1, doL2=doL2, 
+                            doEF=doEF,doHLT=doHLT,
+                            DoProbeMatchPlots=DoProbeMatchPlots,
+                            ProduceEfficiencies=ProduceEfficiencies
+                )
\ No newline at end of file
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/JPsiTPRecoAnalysis.py b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/JPsiTPRecoAnalysis.py
new file mode 100644
index 00000000000..e202b6780df
--- /dev/null
+++ b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/JPsiTPRecoAnalysis.py
@@ -0,0 +1,342 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+from MuonPerformanceAlgs import CommonMuonTPConfig 
+
+def AddConfiguredJPsiTPAlg(name_suffix="myProbes",
+                           ProbeKind = "CaloTag", # options: "CaloTag","MS", "Truth", "ID"
+                           MatchContainer="Muons",
+                           doID=False,
+                           doCB=True,
+                           doLoose=True,
+                           doMedium=True,
+                           doTight=True,
+                           doHighPt=True,
+                           doStandalone=False,
+                           doCaloTag=False,
+                           doIndividualAuthors=False,
+                           writeNtuple=False,
+                           useTrigger=True,
+                           doDRSys = False,
+                           doClosure=False,
+                           DoProbeMatchPlots=True,
+                           ProduceEfficiencies=False):
+
+    from AthenaCommon.AlgSequence import AlgSequence
+    from AthenaCommon.AppMgr import ToolSvc
+    job = AlgSequence()
+
+    MuonContainerToUse = "Muons"
+    #if hasattr(job, "MuonQualityUpdater"):
+        #MuonContainerToUse = "UpdatedMuons"
+
+    ProbeContainer=MuonContainerToUse
+
+    if ProbeKind == "MSTrackPart":
+        ProbeContainer = "ExtrapolatedMuonTrackParticles"
+        ProbeKind = "MS"
+        
+    if ProbeKind == "ID":
+        ProbeContainer = "InDetTrackParticles"
+
+    if ProbeKind == "Truth":
+        ProbeContainer = "MuonTruthParticles"
+
+    theAlg = CommonMuonTPConfig.AddTagProbeAlg(name="JPsiTPAlg_%s"%name_suffix,
+                           ProbeCont=ProbeContainer,
+                           MatchCont=MatchContainer)
+    theAlg.TopLevelFolderName = "JPsiTPReco"
+
+    #AddMuonSelectionTool()
+
+
+    # add a plotting tool
+    #PlotTool = AddPlottingTool(name="JPsiTPPlottingTool_%s"%name_suffix,EffiFlag=name_suffix)
+
+    # add J/Psi TP selection tools
+    SelectionTools = []
+    SelectionTools += [CommonMuonTPConfig.AddJPsiTPSelectionTool(name="JPsiTPSelectionTool_OC_%s"%name_suffix,EffiFlag="%s_OC"%name_suffix, ProbeType = ProbeKind, UseTrigger = useTrigger)]
+
+
+    PlotTools = []
+    # add plotting tools in slices
+    PlotTools = [CommonMuonTPConfig.AddPlottingTool(name="JPsiTPPlottingTool_%s_All"%name_suffix,EffiFlag=name_suffix+"_All",applySF = False,DoProbeMatchPlots=DoProbeMatchPlots,ProduceEfficiencies=ProduceEfficiencies)]
+    for thetool in PlotTools:
+        thetool.doJPsiKinematicPlots = True
+        thetool.doJPsiDileptonPlots = True
+
+    # add any desired matching tools
+
+    MATCH_DR = 0.05
+    
+    MatchingTools = []
+
+    if doID:
+        thistoolID = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_ID"%name_suffix,EffiFlag="IDTracks")
+        thistoolID.MatchToID = True
+        thistoolID.ApplyScaleFactors = False
+        thistoolID.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolID]
+        
+        if doDRSys:
+            thistoolID_dRdown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_ID_dRdown"%name_suffix,EffiFlag="IDTracks_dRDown")
+            thistoolID_dRdown.MatchToID = True
+            thistoolID_dRdown.ApplyScaleFactors = False
+            thistoolID_dRdown.IsNominal=False
+            thistoolID_dRdown.MaximumDrCut = 0.5 *MATCH_DR
+            MatchingTools += [thistoolID_dRdown]
+            
+            thistoolID_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_ID_dRUp"%name_suffix,EffiFlag="IDTracks_dRUp")
+            thistoolID_dRUp.MatchToID = True
+            thistoolID_dRUp.ApplyScaleFactors = False
+            thistoolID_dRUp.IsNominal=False
+            thistoolID_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolID_dRUp]
+        
+    if doLoose:
+        thistoolLoose = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_Loose"%name_suffix,EffiFlag="LooseMuons")
+        thistoolLoose.MatchToLoose = True
+        thistoolLoose.ApplyScaleFactors = False
+        thistoolLoose.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolLoose]
+        
+        if doDRSys:
+            thistoolLoose_dRdown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_Loose_dRdown"%name_suffix,EffiFlag="LooseMuons_dRDown")
+            thistoolLoose_dRdown.MatchToLoose = True
+            thistoolLoose_dRdown.ApplyScaleFactors = False
+            thistoolLoose_dRdown.IsNominal=False
+            thistoolLoose_dRdown.MaximumDrCut = 0.5 *MATCH_DR
+            MatchingTools += [thistoolLoose_dRdown]
+            
+            thistoolLoose_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_Loose_dRUp"%name_suffix,EffiFlag="LooseMuons_dRUp")
+            thistoolLoose_dRUp.MatchToLoose = True
+            thistoolLoose_dRUp.ApplyScaleFactors = False
+            thistoolLoose_dRUp.IsNominal=False
+            thistoolLoose_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolLoose_dRUp]
+            
+        # also run a version without CaloTag
+        thistoolLoose_noCaloTag = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_Loose_noCaloTag"%name_suffix,EffiFlag="LooseMuons_noCaloTag")
+        thistoolLoose_noCaloTag.MatchToLoose_noCaloTag = True
+        thistoolLoose_noCaloTag.ApplyScaleFactors = False
+        thistoolLoose_noCaloTag.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolLoose_noCaloTag]
+        
+        if doDRSys:
+            thistoolLoose_noCaloTag_dRdown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_Loose_noCaloTag_dRdown"%name_suffix,EffiFlag="LooseMuons_noCaloTag_dRDown")
+            thistoolLoose_noCaloTag_dRdown.MatchToLoose_noCaloTag = True
+            thistoolLoose_noCaloTag_dRdown.ApplyScaleFactors = False
+            thistoolLoose_noCaloTag_dRdown.IsNominal=False
+            thistoolLoose_noCaloTag_dRdown.MaximumDrCut = 0.5 *MATCH_DR
+            MatchingTools += [thistoolLoose_noCaloTag_dRdown]
+            
+            thistoolLoose_noCaloTag_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_Loose_noCaloTag_dRUp"%name_suffix,EffiFlag="LooseMuons_noCaloTag_dRUp")
+            thistoolLoose_noCaloTag_dRUp.MatchToLoose_noCaloTag = True
+            thistoolLoose_noCaloTag_dRUp.ApplyScaleFactors = False
+            thistoolLoose_noCaloTag_dRUp.IsNominal=False
+            thistoolLoose_noCaloTag_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolLoose_noCaloTag_dRUp]
+        
+    if doMedium:
+        thistoolMed = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_Medium"%name_suffix,EffiFlag="MediumMuons")
+        thistoolMed.MatchToMedium = True
+        thistoolMed.ApplyScaleFactors = False
+        thistoolMed.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolMed]
+        
+        if doDRSys:
+            thistoolMedium_dRdown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_Medium_dRdown"%name_suffix,EffiFlag="MediumMuons_dRDown")
+            thistoolMedium_dRdown.MatchToMedium = True
+            thistoolMedium_dRdown.IsNominal=False
+            thistoolMedium_dRdown.ApplyScaleFactors = False
+            thistoolMedium_dRdown.MaximumDrCut = 0.5 *MATCH_DR
+            MatchingTools += [thistoolMedium_dRdown]
+            
+            thistoolMedium_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_Medium_dRUp"%name_suffix,EffiFlag="MediumMuons_dRUp")
+            thistoolMedium_dRUp.MatchToMedium = True
+            thistoolMedium_dRUp.IsNominal=False
+            thistoolMedium_dRUp.ApplyScaleFactors = False
+            thistoolMedium_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolMedium_dRUp]
+        
+    if doTight:
+        thistoolTight = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_Tight"%name_suffix,EffiFlag="TightMuons")
+        thistoolTight.MatchToTight = True
+        thistoolTight.ApplyScaleFactors = False
+        thistoolTight.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolTight]
+        
+        if doDRSys:
+            thistoolTight_dRdown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_Tight_dRdown"%name_suffix,EffiFlag="TightMuons_dRDown")
+            thistoolTight_dRdown.MatchToTight = True
+            thistoolTight_dRdown.ApplyScaleFactors = False
+            thistoolTight_dRdown.IsNominal=False
+            thistoolTight_dRdown.MaximumDrCut = 0.5 *MATCH_DR
+            MatchingTools += [thistoolTight_dRdown]
+            
+            thistoolTight_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_Tight_dRUp"%name_suffix,EffiFlag="TightMuons_dRUp")
+            thistoolTight_dRUp.MatchToTight = True
+            thistoolTight_dRUp.IsNominal=False
+            thistoolTight_dRUp.ApplyScaleFactors = False
+            thistoolTight_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolTight_dRUp]
+
+    if doHighPt:
+        thistoolHighPt = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_HighPt"%name_suffix,
+                                                                       EffiFlag="HighPtMuons")
+        thistoolHighPt.MatchToHighPt = True
+        thistoolHighPt.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Tight")  # UPDATE when SF available for high pt
+        thistoolHighPt.ApplyScaleFactors=doClosure
+        thistoolHighPt.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolHighPt]
+        if doDRSys:
+            thistoolHighPt_dRDown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_HighPt_dRDown"%name_suffix,
+                                                                                  EffiFlag="HighPtMuons_dRDown")
+            thistoolHighPt_dRDown.MatchToHighPt = True
+            thistoolHighPt_dRDown.IsNominal=False
+            thistoolHighPt_dRDown.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("HighPt")  # UPDATE when SF available for high pt
+            #thistoolHighPt_dRDown.ApplyScaleFactors = True
+            thistoolHighPt_dRDown.MaximumDrCut = 0.5 * MATCH_DR
+            MatchingTools += [thistoolHighPt_dRDown]
+            
+            thistoolHighPt_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="JPsiTPEfficiencyTool_%s_HighPt_dRUp"%name_suffix,
+                                                                                EffiFlag="HighPtMuons_dRUp")
+            thistoolHighPt_dRUp.MatchToHighPt = True
+            thistoolHighPt_dRUp.IsNominal=False
+            thistoolHighPt_dRUp.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Tight")  # UPDATE when SF available for high pt
+            #thistoolHighPt_dRUp.ApplyScaleFactors = True
+            thistoolHighPt_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolHighPt_dRUp]
+            
+    ntuples = []
+    if writeNtuple:
+        ntuples.append(CommonMuonTPConfig.AddTreeTool(name="JPsiTPTreeTool_%s"%name_suffix, EffiFlag="Trees",WriteSFInfo=doClosure))
+
+    # create the TP tool itself
+    TheTPTool = CommonMuonTPConfig.AddMuonTPTool(name = "JPsiTPTool_%s"%name_suffix,EffiFlag=name_suffix)
+    TheTPTool.MuonTPSelectionTools = SelectionTools
+    TheTPTool.PlottingTools = PlotTools
+    TheTPTool.MuonTPEfficiencyTools = MatchingTools
+    TheTPTool.TreeTools = ntuples
+    theAlg.MuonTPTools += [TheTPTool]
+
+
+def AddJPsiTPRecoAnalysis(writeNtuple=False, 
+                          doClosure=False, 
+                          doDRSys = False, 
+                          doValid=False,
+                          DoProbeMatchPlots=True,
+                          ProduceEfficiencies=False):
+
+
+    from AthenaCommon.AlgSequence import AlgSequence
+    from AthenaCommon.AppMgr import ToolSvc
+    job = AlgSequence()
+
+    MuonContainerToUse = "Muons"
+    #if hasattr(job, "MuonQualityUpdater"):
+        #MuonContainerToUse = "UpdatedMuons"
+
+
+    ##########################################################################################
+    # Add the JPsi TP algorithm using ID tracks as probes and matching to muons
+    AddConfiguredJPsiTPAlg(name_suffix = "IDProbes_JPsi",
+                           ProbeKind = "ID",
+                           MatchContainer = MuonContainerToUse,
+                           doID = False,
+                           doCB = False, 
+                           doLoose = True,
+                           doMedium = True,
+                           doTight = True,
+                           doHighPt=True,
+                           doClosure=doClosure,
+                           doDRSys=doDRSys,
+                           doStandalone = False,
+                           doCaloTag = False,
+                           doIndividualAuthors = doValid,
+                           writeNtuple = writeNtuple,
+                           DoProbeMatchPlots=DoProbeMatchPlots,
+                           ProduceEfficiencies=ProduceEfficiencies)
+    ##########################################################################################
+    # Add the JPsi TP algorithm using MS tracks as probes and matching to ID tracks
+    AddConfiguredJPsiTPAlg(name_suffix = "MSProbes_ID_JPsi",
+                           ProbeKind = "MS",
+                           MatchContainer = "InDetTrackParticles",
+                           doID = True,
+                           doCB = False, 
+                           doLoose = False,
+                           doMedium = False,
+                           doDRSys=doDRSys,
+                           doTight = False,
+                           doHighPt=False,
+                           doClosure=doClosure,
+                           doStandalone = False,
+                           doCaloTag = False,
+                           doIndividualAuthors = doValid,
+                           writeNtuple = writeNtuple,
+                           DoProbeMatchPlots=DoProbeMatchPlots,
+                           ProduceEfficiencies=ProduceEfficiencies)
+
+
+    #########################################################################################
+    #Add the JPsi TP algorithm using CaloTag muons as probes and matching to muons
+    AddConfiguredJPsiTPAlg(name_suffix = "CaloProbes_JPsi",
+                           ProbeKind = "CaloTag",
+                           MatchContainer = MuonContainerToUse,
+                           doID = False,
+                           doCB = False, 
+                           doLoose = True,
+                           doMedium = True,
+                           doDRSys=doDRSys,
+                           doClosure=doClosure,
+                           doTight = True,
+                           doHighPt=True,
+                           doStandalone = False,
+                           doCaloTag = False,
+                           doIndividualAuthors = doValid,
+                           writeNtuple = writeNtuple,
+                           DoProbeMatchPlots=DoProbeMatchPlots,
+                           ProduceEfficiencies=ProduceEfficiencies)
+
+
+    ##########################################################################################
+    # Add the JPsi TP algorithm using Truth probes for Muons
+    AddConfiguredJPsiTPAlg(name_suffix = "TruthProbes_Muon_JPsi",
+                           ProbeKind = "Truth",
+                           MatchContainer = MuonContainerToUse,
+                           doID = False,
+                           doCB = False, 
+                           doLoose = True,
+                           doMedium = True,
+                           doDRSys=False,
+                           doClosure=doClosure,
+                           doTight = True,
+                           doHighPt=True,
+                           doStandalone = False,
+                           doCaloTag = False,
+                           doIndividualAuthors = doValid,
+                           writeNtuple = writeNtuple,
+                           useTrigger = False,
+                           DoProbeMatchPlots=DoProbeMatchPlots,
+                           ProduceEfficiencies=ProduceEfficiencies)
+
+
+    ##########################################################################################
+    # Add the JPsi TP algorithm using Truth probes for ID tracks
+    AddConfiguredJPsiTPAlg(name_suffix = "TruthProbes_ID_JPsi",
+                           ProbeKind = "Truth",
+                           MatchContainer = "InDetTrackParticles",
+                           doID = True,
+                           doCB = False, 
+                           doLoose = False,
+                           doMedium = False,
+                           doTight = False,
+                           doHighPt=False,
+                           doDRSys=False,
+                           doClosure=doClosure,
+                           doStandalone = False,
+                           doCaloTag = False,
+                           doIndividualAuthors = doValid,
+                           writeNtuple = writeNtuple,
+                           useTrigger = False,
+                           DoProbeMatchPlots=DoProbeMatchPlots,
+                           ProduceEfficiencies=ProduceEfficiencies)
\ No newline at end of file
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/JPsiTPTrigAnalysis.py b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/JPsiTPTrigAnalysis.py
new file mode 100644
index 00000000000..3cd00eef826
--- /dev/null
+++ b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/JPsiTPTrigAnalysis.py
@@ -0,0 +1,134 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+from MuonPerformanceAlgs import CommonMuonTPConfig
+
+def AddTrigPlots(name_suffix,
+                 doEtaSlices=True, 
+                 doClosure=False,
+                 DoProbeMatchPlots=True,
+                 ProduceEfficiencies=False):
+    PlotTools = []
+    # add plotting tools in slices
+    if doEtaSlices:
+        Slices = {
+                   "Barrel"     : (0.0,1.05),
+                   "Endcap"     : (1.05,2.5)
+                   }
+
+        for etaslice, interval in Slices.iteritems():
+            PlotTool = CommonMuonTPConfig.AddPlottingTool(name="TriggerTPPlottingTool_%s_%s"%(name_suffix,etaslice),
+                                                          EffiFlag=name_suffix+"_"+etaslice,
+                                                          applySF = False,
+                                                          DoProbeMatchPlots=DoProbeMatchPlots,
+                                                          ProduceEfficiencies=ProduceEfficiencies)
+            PlotTool.ProbeAbsEtaMin = interval[0]
+            PlotTool.ProbeAbsEtaMax = interval[1]
+            PlotTools.append(PlotTool)
+            if doClosure:
+                PlotToolCL = CommonMuonTPConfig.AddPlottingTool(name="TriggerTPPlottingTool_Closure_%s_%s"%(name_suffix,etaslice),
+                                                                EffiFlag=name_suffix+"_"+etaslice+"_Closure",
+                                                                applySF = True,
+                                                                DoProbeMatchPlots=DoProbeMatchPlots,
+                                                                ProduceEfficiencies=ProduceEfficiencies)
+                PlotToolCL.ProbeAbsEtaMin = interval[0]
+                PlotToolCL.ProbeAbsEtaMax = interval[1]
+                PlotTools.append(PlotToolCL)
+            pass
+                
+    else:
+        PlotTools = [CommonMuonTPConfig.AddPlottingTool(name="TriggerTPPlottingTool_%s_All"%name_suffix,
+                                                        EffiFlag=name_suffix+"_All",
+                                                        applySF = False,
+                                                        DoProbeMatchPlots=DoProbeMatchPlots,
+                                                        ProduceEfficiencies=ProduceEfficiencies)]
+        if doClosure:
+            PlotTools.append(CommonMuonTPConfig.AddPlottingTool(name="TriggerTPPlottingTool_Closure_%s_All"%name_suffix,
+                                                                EffiFlag=name_suffix+"_All_Closure",
+                                                                applySF = True,
+                                                                DoProbeMatchPlots=DoProbeMatchPlots,
+                                                                ProduceEfficiencies=ProduceEfficiencies))
+        pass
+    
+    # configure the plot tools
+    for thetool in PlotTools:
+        thetool.DoAsymmErrorGraphs    = True
+        thetool.doTrigValidPlots    = True
+    return PlotTools
+
+def GetTriggerList():
+    TriggerList_HLT = [
+                "HLT_noalg_L1MU10",
+                "HLT_mu4",
+                "HLT_mu6",
+                "HLT_mu10",
+                "HLT_mu14",
+                "HLT_mu18",
+                "HLT_mu20_msonly_mu6noL1_msonly_nscan05 ",
+                "HLT_mu20_2mu0noL1_JpsimumuFS",
+                "HLT_mu18_2mu0noL1_JpsimumuFS",
+                "HLT_mu20_2mu4_JpsimumuL2",
+                "HLT_mu18_2mu4_JpsimumuL2",
+                "HLT_AllTriggers", # this is needed, if you want to have combined (inclusive) efficiency of all HLT triggers
+                    ]
+    TriggerList_L1 = [
+                "L1_MU10",
+                "L1_MU15",
+                "L1_AllTriggers", # this is needed, if you want to have combined (inclusive) efficiency of all L1 triggers 
+                ]
+    TriggerList_L2 = [
+                       "L2_MU20" # a dummy name
+                        ]
+    TriggerList_EF = [  "EF_MU30" # a dummy name
+                                ]
+    return {
+        "L1": TriggerList_L1,
+        "L2": TriggerList_L2,
+        "EF": TriggerList_EF,
+        "HLT":TriggerList_HLT
+    }
+     
+
+def AddTrigMatchTools(name_suffix,doL1 = True, doL2=False, doEF=False,doHLT=True,doDRSys=True):
+    TrigList = GetTriggerList()
+    TriggerList_L1  = []
+    TriggerList_L2  = []
+    TriggerList_EF  = []
+    TriggerList_HLT = []
+    
+    if doHLT:
+        TriggerList_HLT = TrigList["HLT"]
+    if doL1:
+        TriggerList_L1 = TrigList["L1"]
+    if doL2:
+        TriggerList_L2 = TrigList["L2"]
+    if doEF:
+        TriggerList_EF = TrigList["EF"]
+
+    MatchingTools = []
+
+    MATCH_DR = 0.05
+    for Trigitem in TriggerList_L1 + TriggerList_L2 + TriggerList_EF + TriggerList_HLT:
+        thistool = CommonMuonTPConfig.AddTriggerTPEfficiencyTool(name="TriggerTPEfficiencyTool_%s_%s"%(name_suffix,Trigitem),EffiFlag=Trigitem)
+        thistool.TrigItem = Trigitem 
+        # Delta R: 0.1 for L2/EF/HLT, 0.2 for L1 - taken from TrigMuonMatching
+        MATCH_DR = 0.1
+        if "L1" in Trigitem:
+            MATCH_DR = 0.2
+        thistool.MaximumDrCut = MATCH_DR
+        MatchingTools.append(thistool)
+        if doDRSys:
+            thistool_dRup = CommonMuonTPConfig.AddTriggerTPEfficiencyTool(name="TriggerTPEfficiencyTool_DrUp_%s_%s"%(name_suffix,Trigitem),EffiFlag="%s_dRUp"%Trigitem)
+            thistool_dRup.TrigItem = Trigitem
+            thistool_dRup.IsNominal = False
+            thistool_dRup.MaximumDrCut = MATCH_DR+0.05
+            MatchingTools.append(thistool_dRup)
+
+            thistool_dRDown = CommonMuonTPConfig.AddTriggerTPEfficiencyTool(name="TriggerTPEfficiencyTool_DrDown_%s_%s"%(name_suffix,Trigitem),EffiFlag="%s_dRDown"%Trigitem)
+            thistool_dRDown.TrigItem = Trigitem
+            thistool_dRDown.IsNominal = False
+            thistool_dRDown.MaximumDrCut =  MATCH_DR-0.05
+            MatchingTools.append(thistool_dRDown)
+
+        
+    return MatchingTools
+    
\ No newline at end of file
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/MuonTPAnalysis.py b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/MuonTPAnalysis.py
new file mode 100644
index 00000000000..cd16437c85e
--- /dev/null
+++ b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/MuonTPAnalysis.py
@@ -0,0 +1,99 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+#
+# Massimiliano Bellomo
+# June 2015
+#
+# Example job option fragment for running tag-and-probe tools in Athena from xAOD in Reco_tf
+#
+
+def MuonTPConfig(outputFilename, doPlots = False, doEff = False):
+    # outputFilename: name of the output file
+    # doPlots: steers creation of probe/match histograms
+    # doEff: steers additional creation of efficiency histograms if doPlots is true
+
+    from AthenaCommon.AppMgr import ServiceMgr
+    from AthenaCommon.AlgSequence import AlgSequence
+    from MuonPerformanceAlgs import ZmumuTPRecoAnalysis
+    from MuonPerformanceAlgs import ZmumuTPMuonAnalysis
+    from MuonPerformanceAlgs import JPsiTPRecoAnalysis
+    from MuonPerformanceAlgs import JPsiTPMuonAnalysis
+    from MuonPerformanceAlgs import CommonMuonTPConfig
+
+    # Full job is a list of algorithms
+    job = AlgSequence()
+
+    ############## Zmumu T&P Configuration ########################
+    do_Zmumu_RecoEff_TagProbe      = True # this is for Z->mumu, reco eff. You can add your own analysis in a similar way.
+    do_Zmumu_IsolationEff_TagProbe = True # this is for Z->mumu, isolation eff. You can add your own analysis in a similar way.
+    do_Zmumu_TriggerEff_TagProbe   = True # this is for Z->mumu, Trigger eff.
+
+    ############## JPsi T&P Configuration ########################
+    do_JPsi_RecoEff_TagProbe       = True
+    do_JPsi_IsolationEff_TagProbe  = True
+    do_JPsi_TriggerEff_TagProbe    = True
+
+ 
+    GRL_to_use  = []
+    #GRL_to_use  = ["/afs/cern.ch/user/a/atlasdqm/grlgen/All_Good/data15_13TeV.periodA_DetStatus-v62-pro18_DQDefects-00-01-02_PHYS_StandardGRL_All_Good.xml"]
+
+    CommonMuonTPConfig.AddTrigDecisionTool()
+    CommonMuonTPConfig.AddTrigMatchingTool()
+    CommonMuonTPConfig.AddMuonSelectionTool()
+    CommonMuonTPConfig.AddGoodRunsListSelectionTool(GRL_to_use)
+    
+    ##### Reco eff analysis options
+    if do_Zmumu_RecoEff_TagProbe:
+        ZmumuTPRecoAnalysis.AddZmumuTPRecoAnalysis(doEtaSlices=False,
+                                                   writeNtuple=True,
+                                                   doClosure=False,
+                                                   doDRSys=True,
+                                                   doValid=False,
+                                                   DoProbeMatchPlots = doPlots,
+                                                   ProduceEfficiencies=doPlots and doEff)    
+    if do_JPsi_RecoEff_TagProbe:
+        JPsiTPRecoAnalysis.AddJPsiTPRecoAnalysis(writeNtuple=True,
+                                                 doValid=False,
+                                                 doDRSys=True,
+                                                 DoProbeMatchPlots = doPlots,
+                                                 ProduceEfficiencies=doPlots and doEff) 
+        
+    if do_Zmumu_TriggerEff_TagProbe or do_Zmumu_IsolationEff_TagProbe:
+        ZmumuTPMuonAnalysis.AddZmumuTPMuonAnalysis( doIso = do_Zmumu_IsolationEff_TagProbe,
+                                doTrig = do_Zmumu_TriggerEff_TagProbe,
+                                doTrigEtaSlices    = True, 
+                                doIsolEtaSlices    = False, 
+                                doIsolPlots      = False,
+                                doTriggerPlots      = True,
+                                writeNtuple=True, doClosure=False, 
+                                doDRSys=True, doDPhiTPSys=True, 
+                                doProbeCharSys=True, 
+                                doLooseProbes=True, doMediumProbes=True, 
+                                doTightProbes=True, doTruthProbes=True,
+                                doHighPtProbes=True,
+                                doL1=True, doL2=False, doEF=False, 
+                                doHLT=True, DoProbeMatchPlots=False, 
+                                ProduceEfficiencies=doPlots and doEff)
+        
+    if do_JPsi_TriggerEff_TagProbe or do_JPsi_IsolationEff_TagProbe:
+        JPsiTPMuonAnalysis.AddJPsiTPMuonAnalysis( doIso = do_JPsi_IsolationEff_TagProbe,
+                                doTrig = do_JPsi_TriggerEff_TagProbe,
+                                doTrigEtaSlices    = True, 
+                                doIsolEtaSlices    = False, 
+                                doIsolPlots      = False,
+                                doTriggerPlots      = True,
+                                writeNtuple=True, doClosure=False, 
+                                doDRSys=True, doDPhiTPSys=True, 
+                                doProbeCharSys=True, 
+                                doLooseProbes=True, doMediumProbes=True, 
+                                doTightProbes=True, doTruthProbes=True, 
+                                doHighPtProbes=True,
+                                doL1=True, doL2=False, doEF=False, 
+                                doHLT=True, DoProbeMatchPlots=False, 
+                                ProduceEfficiencies=doPlots and doEff)
+                
+    # Add HistSvc
+    from GaudiSvc.GaudiSvcConf import THistSvc
+    ServiceMgr += THistSvc()
+    ServiceMgr.THistSvc.Output += ["MUONTP DATAFILE='{}' OPT='RECREATE'".format(outputFilename)]
+
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/ZmumuTPIsolAnalysis.py b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/ZmumuTPIsolAnalysis.py
new file mode 100644
index 00000000000..92901c9c408
--- /dev/null
+++ b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/ZmumuTPIsolAnalysis.py
@@ -0,0 +1,57 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+from MuonPerformanceAlgs import CommonMuonTPConfig 
+  
+def AddIsolPlots(name_suffix,
+                 doEtaSlices=True, 
+                 doClosure=False,
+                 DoProbeMatchPlots=True,
+                 ProduceEfficiencies=False):
+    
+    PlotTools = []
+    # add plotting tools in slices
+    if doEtaSlices:
+        Slices = {
+                   "All" : (0.0,10.0),
+                   "noCrack" : (0.1,10.0),
+                   "Crack" : (0.0,0.1),
+                   "Barrel" : (0.1,1.1),
+                   "Transition" : (1.1, 1.3),
+                   "Endcap" : (1.3,2.0),
+                   "CSC" : (2.0,2.7)
+                   }
+
+        for etaslice, interval in Slices.iteritems():
+            PlotTool = CommonMuonTPConfig.AddPlottingTool(name="ZmumuTPIsoPlottingTool_%s_%s"%(name_suffix,etaslice),EffiFlag=name_suffix+"_"+etaslice,applySF = False,DoProbeMatchPlots=DoProbeMatchPlots,ProduceEfficiencies=ProduceEfficiencies)
+            PlotTool.ProbeAbsEtaMin = interval[0]
+            PlotTool.ProbeAbsEtaMax = interval[1]
+            PlotTools.append(PlotTool)
+            if doClosure:
+                PlotToolCL = CommonMuonTPConfig.AddPlottingTool(name="ZmumuTPIsoPlottingToolClosure_%s_%s"%(name_suffix,etaslice),EffiFlag=name_suffix+"_"+etaslice+"_Closure",applySF = True,DoProbeMatchPlots=DoProbeMatchPlots,ProduceEfficiencies=ProduceEfficiencies)
+                PlotToolCL.ProbeAbsEtaMin = interval[0]
+                PlotToolCL.ProbeAbsEtaMax = interval[1]
+                PlotTools.append(PlotToolCL)
+                
+    else:
+        PlotTools = [CommonMuonTPConfig.AddPlottingTool(name="ZmumuTPIsoPlottingTool_%s_All"%name_suffix,EffiFlag=name_suffix+"_All",applySF = False,DoProbeMatchPlots=DoProbeMatchPlots,ProduceEfficiencies=ProduceEfficiencies)]
+        if doClosure:
+            PlotTools.append(CommonMuonTPConfig.AddPlottingTool(name="ZmumuTPIsoPlottingToolClosure_%s_All"%name_suffix,EffiFlag=name_suffix+"_All_Closure",applySF = True,DoProbeMatchPlots=DoProbeMatchPlots,ProduceEfficiencies=ProduceEfficiencies))
+    # config the plot tools for Zmm isolation
+    for thetool in PlotTools:
+        thetool.doZmumuKinematicPlots = True
+        thetool.doFineEtaPhiPlots = True
+        thetool.DoAsymmErrorGraphs = True
+        thetool.doZmumuDileptonPlots = True
+        
+    return PlotTools
+    
+def AddIsolMatchTools(name_suffix):
+    #MATCH_DR = 0.05
+    #MatchingTools = []
+    #thistool = CommonMuonTPConfig.AddIsolTPEfficiencyTool(name="ZmumuTPIsoEfficiencyTool_%s_CB"%name_suffix,EffiFlag="Isolation")
+    #thistool.ApplyScaleFactors = False
+    #thistool.MaximumDrCut = MATCH_DR
+    #MatchingTools += [thistool]
+    #return MatchingTools
+    return []
+     
\ No newline at end of file
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/ZmumuTPMuonAnalysis.py b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/ZmumuTPMuonAnalysis.py
new file mode 100644
index 00000000000..8be883d1a81
--- /dev/null
+++ b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/ZmumuTPMuonAnalysis.py
@@ -0,0 +1,343 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+from MuonPerformanceAlgs import CommonMuonTPConfig, ZmumuTPTrigAnalysis, ZmumuTPIsolAnalysis
+
+def AddConfiguredMuonTPAlg(name_suffix  = "MuonProbe",
+                            MatchContainer = "Muons",
+                            doIso = True,
+                            doTrig = True,
+                            doTrigEtaSlices    = True, 
+                            doIsolEtaSlices    = False, 
+                            doIsolPlots      = False,
+                            doTriggerPlots      = True,
+                            writeNtuple    = False,
+                            doClosure      = False,
+                            doDRSys    = False,
+                            doDPhiTPSys    = False,
+                            doProbeCharSys = False,
+                            doVeryLooseProbes = False,
+                            doLooseProbes   = False,
+                            doMediumProbes  = False,
+                            doTightProbes   = False,
+                            doHighPtProbes   = False,
+                            doTruthProbes   = False,
+                            DoProbeMatchPlots=True,
+                            ProduceEfficiencies=False,
+                            doL1 = False,
+                            doL2 = False, doEF = False,
+                            doHLT = False
+                ):
+    
+    from AthenaCommon.AlgSequence import AlgSequence
+    from AthenaCommon.AppMgr import ToolSvc
+    job = AlgSequence()
+
+    MuonContainerToUse = "Muons"
+    if hasattr(job, "MuonQualityUpdater"):
+        MuonContainerToUse = "UpdatedMuons"
+
+    ProbeContainer = MuonContainerToUse
+    theAlg = CommonMuonTPConfig.AddTagProbeAlg(name="ZmumuMuProbeAlg_%s"%name_suffix, ProbeCont=ProbeContainer, MatchCont=MatchContainer)
+    theAlg.TopLevelFolderName = "ZmumuTPMuon"
+
+    SelectionTools = []
+    
+    if doLooseProbes:
+        SelecToolsOC_LooseProbes = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_LooseProbes_%s"%name_suffix,EffiFlag="%s_OC_LooseProbes"%name_suffix, ProbeType="Loose")
+        SelecToolsOC_LooseProbes.UseLooseProbes = True
+        SelectionTools.append(SelecToolsOC_LooseProbes)
+        
+        SelecToolsSC_LooseProbes = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_LooseProbes_%s"%name_suffix,EffiFlag="%s_SC_LooseProbes"%name_suffix, ProbeType="Loose", SameSign=True)
+        SelecToolsSC_LooseProbes.UseLooseProbes = True
+        SelectionTools.append(SelecToolsSC_LooseProbes)
+
+        
+        if doDPhiTPSys:
+            SelecToolsOC_LooseProbesDPhiCut = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_LooseProbesDPhiCut_%s"%name_suffix,EffiFlag="%s_OC_LooseProbesDPhiCut"%name_suffix, ProbeType="Loose")
+            SelecToolsOC_LooseProbesDPhiCut.DeltaPhiCut  = 3.04
+            SelecToolsOC_LooseProbesDPhiCut.IsNominal = False
+            SelectionTools.append(SelecToolsOC_LooseProbesDPhiCut)
+            
+            SelecToolsSC_LooseProbesDPhiCut = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_LooseProbesDPhiCut_%s"%name_suffix,EffiFlag="%s_SC_LooseProbesDPhiCut"%name_suffix, ProbeType="Loose", SameSign=True)
+            SelecToolsSC_LooseProbesDPhiCut.DeltaPhiCut  = 3.04
+            SelecToolsSC_LooseProbesDPhiCut.IsNominal = False
+            SelectionTools.append(SelecToolsSC_LooseProbesDPhiCut)
+
+        if doProbeCharSys:
+            SelecToolsOC_LooseProbesPos = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_LooseProbesPos_%s"%name_suffix,EffiFlag="%s_OC_LooseProbesPos"%name_suffix, ProbeType="Loose")
+            SelecToolsOC_LooseProbesPos.doProbeChargeSys = True
+            SelecToolsOC_LooseProbesPos.ProbeCharge = "positive"
+            SelecToolsOC_LooseProbesPos.IsNominal = False
+            SelectionTools.append(SelecToolsOC_LooseProbesPos)
+
+            SelecToolsOC_LooseProbesNeg = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_LooseProbesNeg_%s"%name_suffix,EffiFlag="%s_OC_LooseProbesNeg"%name_suffix, ProbeType="Loose")
+            SelecToolsOC_LooseProbesNeg.doProbeChargeSys = True
+            SelecToolsOC_LooseProbesNeg.IsNominal = False
+            SelecToolsOC_LooseProbesNeg.ProbeCharge = "negative"
+            SelectionTools.append(SelecToolsOC_LooseProbesNeg)
+            
+            
+            SelecToolsSC_LooseProbesPos = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_LooseProbesPos_%s"%name_suffix,EffiFlag="%s_SC_LooseProbesPos"%name_suffix, ProbeType="Loose", SameSign=True)
+            SelecToolsSC_LooseProbesPos.doProbeChargeSys = True
+            SelecToolsSC_LooseProbesPos.ProbeCharge = "positive"
+            SelecToolsSC_LooseProbesPos.IsNominal = False
+            SelectionTools.append(SelecToolsSC_LooseProbesPos)
+
+            SelecToolsSC_LooseProbesNeg = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_LooseProbesNeg_%s"%name_suffix,EffiFlag="%s_SC_LooseProbesNeg"%name_suffix, ProbeType="Loose", SameSign=True)
+            SelecToolsSC_LooseProbesNeg.doProbeChargeSys = True
+            SelecToolsSC_LooseProbesNeg.IsNominal = False
+            SelecToolsSC_LooseProbesNeg.ProbeCharge = "negative"
+            SelectionTools.append(SelecToolsSC_LooseProbesNeg)
+
+    
+    if doMediumProbes:
+        SelecToolsOC_MediumProbes = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_MediumProbes_%s"%name_suffix,EffiFlag="%s_OC_MediumProbes"%name_suffix, ProbeType="Medium")
+        SelecToolsOC_MediumProbes.UseMediumProbes = True
+        SelectionTools.append(SelecToolsOC_MediumProbes)
+        
+        SelecToolsSC_MediumProbes = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_MediumProbes_%s"%name_suffix,EffiFlag="%s_SC_MediumProbes"%name_suffix, ProbeType="Medium", SameSign=True)
+        SelecToolsSC_MediumProbes.UseMediumProbes = True
+        SelectionTools.append(SelecToolsSC_MediumProbes)
+
+        
+        if doDPhiTPSys:
+            SelecToolsOC_MediumProbesDPhiCut = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_MediumProbesDPhiCut_%s"%name_suffix,EffiFlag="%s_OC_MediumProbesDPhiCut"%name_suffix, ProbeType="Medium")
+            SelecToolsOC_MediumProbesDPhiCut.DeltaPhiCut  = 3.04
+            SelecToolsOC_MediumProbesDPhiCut.IsNominal = False
+            SelectionTools.append(SelecToolsOC_MediumProbesDPhiCut)
+            
+            SelecToolsSC_MediumProbesDPhiCut = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_MediumProbesDPhiCut_%s"%name_suffix,EffiFlag="%s_SC_MediumProbesDPhiCut"%name_suffix, ProbeType="Medium", SameSign=True)
+            SelecToolsSC_MediumProbesDPhiCut.DeltaPhiCut  = 3.04
+            SelecToolsSC_MediumProbesDPhiCut.IsNominal = False
+            SelectionTools.append(SelecToolsSC_MediumProbesDPhiCut)
+
+        if doProbeCharSys:
+            SelecToolsOC_MediumProbesPos = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_MediumProbesPos_%s"%name_suffix,EffiFlag="%s_OC_MediumProbesPos"%name_suffix, ProbeType="Medium")
+            SelecToolsOC_MediumProbesPos.doProbeChargeSys = True
+            SelecToolsOC_MediumProbesPos.ProbeCharge = "positive"
+            SelecToolsOC_MediumProbesPos.IsNominal = False
+            SelectionTools.append(SelecToolsOC_MediumProbesPos)
+
+            SelecToolsOC_MediumProbesNeg = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_MediumProbesNeg_%s"%name_suffix,EffiFlag="%s_OC_MediumProbesNeg"%name_suffix, ProbeType="Medium")
+            SelecToolsOC_MediumProbesNeg.doProbeChargeSys = True
+            SelecToolsOC_MediumProbesNeg.IsNominal = False
+            SelecToolsOC_MediumProbesNeg.ProbeCharge = "negative"
+            SelectionTools.append(SelecToolsOC_MediumProbesNeg)
+            
+            
+            SelecToolsSC_MediumProbesPos = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_MediumProbesPos_%s"%name_suffix,EffiFlag="%s_SC_MediumProbesPos"%name_suffix, ProbeType="Medium", SameSign=True)
+            SelecToolsSC_MediumProbesPos.doProbeChargeSys = True
+            SelecToolsSC_MediumProbesPos.ProbeCharge = "positive"
+            SelecToolsSC_MediumProbesPos.IsNominal = False
+            SelectionTools.append(SelecToolsSC_MediumProbesPos)
+
+            SelecToolsSC_MediumProbesNeg = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_MediumProbesNeg_%s"%name_suffix,EffiFlag="%s_SC_MediumProbesNeg"%name_suffix, ProbeType="Medium", SameSign=True)
+            SelecToolsSC_MediumProbesNeg.doProbeChargeSys = True
+            SelecToolsSC_MediumProbesNeg.IsNominal = False
+            SelecToolsSC_MediumProbesNeg.ProbeCharge = "negative"
+            SelectionTools.append(SelecToolsSC_MediumProbesNeg)
+
+    if doTightProbes:
+        SelecToolsOC_TightProbes = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_TightProbes_%s"%name_suffix,EffiFlag="%s_OC_TightProbes"%name_suffix, ProbeType="Tight")
+        SelecToolsOC_TightProbes.UseTightProbes = True
+        SelectionTools.append(SelecToolsOC_TightProbes)
+        
+        SelecToolsSC_TightProbes = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_TightProbes_%s"%name_suffix,EffiFlag="%s_SC_TightProbes"%name_suffix, ProbeType="Tight", SameSign=True)
+        SelecToolsSC_TightProbes.UseTightProbes = True
+        SelectionTools.append(SelecToolsSC_TightProbes)
+
+        
+        if doDPhiTPSys:
+            SelecToolsOC_TightProbesDPhiCut = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_TightProbesDPhiCut_%s"%name_suffix,EffiFlag="%s_OC_TightProbesDPhiCut"%name_suffix, ProbeType="Tight")
+            SelecToolsOC_TightProbesDPhiCut.DeltaPhiCut  = 3.04
+            SelecToolsOC_TightProbesDPhiCut.IsNominal = False
+            SelectionTools.append(SelecToolsOC_TightProbesDPhiCut)
+            
+            SelecToolsSC_TightProbesDPhiCut = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_TightProbesDPhiCut_%s"%name_suffix,EffiFlag="%s_SC_TightProbesDPhiCut"%name_suffix, ProbeType="Tight", SameSign=True)
+            SelecToolsSC_TightProbesDPhiCut.DeltaPhiCut  = 3.04
+            SelecToolsSC_TightProbesDPhiCut.IsNominal = False
+            SelectionTools.append(SelecToolsSC_TightProbesDPhiCut)
+
+        if doProbeCharSys:
+            SelecToolsOC_TightProbesPos = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_TightProbesPos_%s"%name_suffix,EffiFlag="%s_OC_TightProbesPos"%name_suffix, ProbeType="Tight")
+            SelecToolsOC_TightProbesPos.doProbeChargeSys = True
+            SelecToolsOC_TightProbesPos.ProbeCharge = "positive"
+            SelecToolsOC_TightProbesPos.IsNominal = False
+            SelectionTools.append(SelecToolsOC_TightProbesPos)
+
+            SelecToolsOC_TightProbesNeg = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_TightProbesNeg_%s"%name_suffix,EffiFlag="%s_OC_TightProbesNeg"%name_suffix, ProbeType="Tight")
+            SelecToolsOC_TightProbesNeg.doProbeChargeSys = True
+            SelecToolsOC_TightProbesNeg.IsNominal = False
+            SelecToolsOC_TightProbesNeg.ProbeCharge = "negative"
+            SelectionTools.append(SelecToolsOC_TightProbesNeg)
+            
+            
+            SelecToolsSC_TightProbesPos = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_TightProbesPos_%s"%name_suffix,EffiFlag="%s_SC_TightProbesPos"%name_suffix, ProbeType="Tight", SameSign=True)
+            SelecToolsSC_TightProbesPos.doProbeChargeSys = True
+            SelecToolsSC_TightProbesPos.ProbeCharge = "positive"
+            SelecToolsSC_TightProbesPos.IsNominal = False
+            SelectionTools.append(SelecToolsSC_TightProbesPos)
+
+            SelecToolsSC_TightProbesNeg = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_TightProbesNeg_%s"%name_suffix,EffiFlag="%s_SC_TightProbesNeg"%name_suffix, ProbeType="Tight", SameSign=True)
+            SelecToolsSC_TightProbesNeg.doProbeChargeSys = True
+            SelecToolsSC_TightProbesNeg.IsNominal = False
+            SelecToolsSC_TightProbesNeg.ProbeCharge = "negative"
+            SelectionTools.append(SelecToolsSC_TightProbesNeg)
+
+
+    if doHighPtProbes:
+        SelecToolsOC_HighPtProbes = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_HighPtProbes_%s"%name_suffix,EffiFlag="%s_OC_HighPtProbes"%name_suffix, ProbeType="HighPt")
+        SelecToolsOC_HighPtProbes.UseHighPtProbes = True
+        SelectionTools.append(SelecToolsOC_HighPtProbes)
+        
+        SelecToolsSC_HighPtProbes = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_HighPtProbes_%s"%name_suffix,EffiFlag="%s_SC_HighPtProbes"%name_suffix, ProbeType="HighPt", SameSign=True)
+        SelecToolsSC_HighPtProbes.UseHighPtProbes = True
+        SelectionTools.append(SelecToolsSC_HighPtProbes)
+
+        
+        if doDPhiTPSys:
+            SelecToolsOC_HighPtProbesDPhiCut = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_HighPtProbesDPhiCut_%s"%name_suffix,EffiFlag="%s_OC_HighPtProbesDPhiCut"%name_suffix, ProbeType="HighPt")
+            SelecToolsOC_HighPtProbesDPhiCut.DeltaPhiCut  = 3.04
+            SelecToolsOC_HighPtProbesDPhiCut.IsNominal = False
+            SelectionTools.append(SelecToolsOC_HighPtProbesDPhiCut)
+            
+            SelecToolsSC_HighPtProbesDPhiCut = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_HighPtProbesDPhiCut_%s"%name_suffix,EffiFlag="%s_SC_HighPtProbesDPhiCut"%name_suffix, ProbeType="HighPt", SameSign=True)
+            SelecToolsSC_HighPtProbesDPhiCut.DeltaPhiCut  = 3.04
+            SelecToolsSC_HighPtProbesDPhiCut.IsNominal = False
+            SelectionTools.append(SelecToolsSC_HighPtProbesDPhiCut)
+
+        if doProbeCharSys:
+            SelecToolsOC_HighPtProbesPos = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_HighPtProbesPos_%s"%name_suffix,EffiFlag="%s_OC_HighPtProbesPos"%name_suffix, ProbeType="HighPt")
+            SelecToolsOC_HighPtProbesPos.doProbeChargeSys = True
+            SelecToolsOC_HighPtProbesPos.ProbeCharge = "positive"
+            SelecToolsOC_HighPtProbesPos.IsNominal = False
+            SelectionTools.append(SelecToolsOC_HighPtProbesPos)
+
+            SelecToolsOC_HighPtProbesNeg = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_HighPtProbesNeg_%s"%name_suffix,EffiFlag="%s_OC_HighPtProbesNeg"%name_suffix, ProbeType="HighPt")
+            SelecToolsOC_HighPtProbesNeg.doProbeChargeSys = True
+            SelecToolsOC_HighPtProbesNeg.IsNominal = False
+            SelecToolsOC_HighPtProbesNeg.ProbeCharge = "negative"
+            SelectionTools.append(SelecToolsOC_HighPtProbesNeg)
+            
+            
+            SelecToolsSC_HighPtProbesPos = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_HighPtProbesPos_%s"%name_suffix,EffiFlag="%s_SC_HighPtProbesPos"%name_suffix, ProbeType="HighPt", SameSign=True)
+            SelecToolsSC_HighPtProbesPos.doProbeChargeSys = True
+            SelecToolsSC_HighPtProbesPos.ProbeCharge = "positive"
+            SelecToolsSC_HighPtProbesPos.IsNominal = False
+            SelectionTools.append(SelecToolsSC_HighPtProbesPos)
+
+            SelecToolsSC_HighPtProbesNeg = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_HighPtProbesNeg_%s"%name_suffix,EffiFlag="%s_SC_HighPtProbesNeg"%name_suffix, ProbeType="HighPt", SameSign=True)
+            SelecToolsSC_HighPtProbesNeg.doProbeChargeSys = True
+            SelecToolsSC_HighPtProbesNeg.IsNominal = False
+            SelecToolsSC_HighPtProbesNeg.ProbeCharge = "negative"
+            SelectionTools.append(SelecToolsSC_HighPtProbesNeg)
+            
+            
+    from AthenaCommon.GlobalFlags import globalflags
+    if doTruthProbes and not globalflags.DataSource()=='data':
+        SelecToolsOC_TruthProbes = CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_TruthProbes_%s"%name_suffix,EffiFlag="%s_TruthProbes"%name_suffix, ProbeType="TruthMatchedMuons")
+        SelectionTools.append(SelecToolsOC_TruthProbes)
+        
+        
+    for thetool in SelectionTools:
+        thetool.ProbeTrackIsoCut = -1
+        thetool.ProbeTrackAntiIsoCut = -1
+        thetool.ProbeCaloIsoCut = -1
+        thetool.ProbeCaloAntiIsoCut = -1
+        # also accept high eta muons
+        thetool.ProbeEtaCut = 4.5   
+        
+    PlotTools = []
+    
+    # first the trigger plots 
+    if doTrig and doTriggerPlots:
+        PlotTools += ZmumuTPTrigAnalysis.AddTrigPlots(name_suffix=name_suffix,
+                                        doEtaSlices=doTrigEtaSlices,
+                                        doClosure=doClosure,
+                                        DoProbeMatchPlots=DoProbeMatchPlots,
+                                        ProduceEfficiencies=ProduceEfficiencies)
+    # then the isolation plots
+    if doIso and doIsolPlots:
+        PlotTools += ZmumuTPIsolAnalysis.AddIsolPlots(name_suffix=name_suffix,
+                                        doEtaSlices=doIsolEtaSlices,
+                                        doClosure=doClosure,
+                                        DoProbeMatchPlots=DoProbeMatchPlots,
+                                        ProduceEfficiencies=ProduceEfficiencies)
+        
+    
+    MatchingTools = []
+    if doTrig:
+        MatchingTools += ZmumuTPTrigAnalysis.AddTrigMatchTools(name_suffix=name_suffix,doL1 = doL1, doL2=doL2, doEF=doEF,doHLT=doHLT,doDRSys=doDRSys)
+    if doIso:
+        MatchingTools += ZmumuTPIsolAnalysis.AddIsolMatchTools(name_suffix=name_suffix)
+    
+    
+    ntuples = []
+    if writeNtuple:
+        ntuples.append(CommonMuonTPConfig.AddTreeTool(name="ZmumuTPMuonTreeTool_%s"%name_suffix, EffiFlag="Trees",WriteSFInfo=doClosure))
+    
+    for ntuple in ntuples:
+        if doIso:
+            ntuple.AddExtendedIsolation = True
+        
+    # create the TP tool itself
+    TheTPTool = CommonMuonTPConfig.AddMuonTPTool(name = "MuonProbeTPTool_%s"%name_suffix,EffiFlag=name_suffix)
+    TheTPTool.MuonTPSelectionTools  = SelectionTools
+    TheTPTool.PlottingTools         = PlotTools
+    TheTPTool.MuonTPEfficiencyTools = MatchingTools
+    TheTPTool.TreeTools             = ntuples
+    theAlg.MuonTPTools += [TheTPTool]
+    
+    
+    
+def AddZmumuTPMuonAnalysis(doIso = True,
+                           doTrig = True,
+                           doTrigEtaSlices    = True, 
+                           doIsolEtaSlices    = False, 
+                           doIsolPlots      = False,
+                           doTriggerPlots      = True,
+                           writeNtuple=False, doClosure=False, 
+                           doDRSys=False, doDPhiTPSys=True, 
+                           doProbeCharSys=True, 
+                           doLooseProbes=False, doMediumProbes=False, 
+                           doTightProbes=False,  
+                           doTruthProbes=False,
+                           doHighPtProbes=False,
+                           doL1=False, doL2=False, doEF=False, 
+                           doHLT=False, DoProbeMatchPlots=True, 
+                           ProduceEfficiencies=False):
+    
+    from AthenaCommon.AlgSequence import AlgSequence
+    from AthenaCommon.AppMgr import ToolSvc
+    job = AlgSequence()
+
+
+    MuonContainerToUse = "Muons"
+    if hasattr(job, "MuonQualityUpdater"):
+        MuonContainerToUse = "UpdatedMuons"
+        
+    ##########################################################################################
+    # Add the Zmm TP algorithm for muon probes
+    AddConfiguredMuonTPAlg(name_suffix  = "MuonProbe",
+                            MatchContainer = "Muons",
+                            doIso=doIso,
+                            doTrig=doTrig,
+                            doTrigEtaSlices    = doTrigEtaSlices, 
+                            doIsolEtaSlices    = doIsolEtaSlices, 
+                            doIsolPlots      = doIsolPlots,
+                            doTriggerPlots      = doTriggerPlots,
+                            writeNtuple    = writeNtuple,
+                            doClosure      = doClosure,
+                            doDRSys      = doDRSys,
+                            doDPhiTPSys    = doDPhiTPSys,
+                            doProbeCharSys = doProbeCharSys,
+                            doLooseProbes   = doLooseProbes,
+                            doMediumProbes  = doMediumProbes,
+                            doTightProbes   = doTightProbes,
+                            doHighPtProbes   = doHighPtProbes,
+                            doTruthProbes=doTruthProbes,
+                            doL1 = doL1, doL2=doL2, 
+                            doEF=doEF,doHLT=doHLT,
+                            DoProbeMatchPlots=DoProbeMatchPlots,
+                            ProduceEfficiencies=ProduceEfficiencies
+                )
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/ZmumuTPRecoAnalysis.py b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/ZmumuTPRecoAnalysis.py
new file mode 100644
index 00000000000..98ae931a772
--- /dev/null
+++ b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/ZmumuTPRecoAnalysis.py
@@ -0,0 +1,658 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+
+from MuonPerformanceAlgs import CommonMuonTPConfig 
+################################################################
+# Add a version of the Z TP algorithm and all associated tools
+################################################################
+def AddConfiguredZmumuTPAlg(name_suffix="myProbes",
+                            ProbeKind = "CaloTag", # options: "CaloTag","MS", "Truth", "ID"
+                            MatchContainer="Muons",
+                            doID=False,
+                            doCB = True, doLoose=True,
+                            doMedium=True,doTight=True,
+                            doHighPt=True,
+                            doStandalone=False, doCaloTag=False,
+                            doIndividualAuthors=False,
+                            doEtaSlices=False, writeNtuple=False,
+                            doClosure = False, doDRSys = False,
+                            DoProbeMatchPlots=True,
+                            ProduceEfficiencies=False):
+
+
+    from AthenaCommon.AlgSequence import AlgSequence
+    from AthenaCommon.AppMgr import ToolSvc
+    job = AlgSequence()
+
+    MuonContainerToUse = "Muons"
+    #if hasattr(job, "MuonQualityUpdater"):
+        #MuonContainerToUse = "UpdatedMuons"
+
+    ProbeContainer=MuonContainerToUse
+
+    if ProbeKind == "MSTrackPart":
+        ProbeContainer = "ExtrapolatedMuonTrackParticles"
+        ProbeKind = "MS"
+        
+    if ProbeKind == "ID":
+        ProbeContainer = "InDetTrackParticles"
+    if ProbeKind == "Truth":
+        ProbeContainer = "MuonTruthParticles"
+
+    theAlg = CommonMuonTPConfig.AddTagProbeAlg(name="ZmumuTPAlg_%s"%name_suffix,
+                           ProbeCont=ProbeContainer,
+                           MatchCont=MatchContainer)
+    theAlg.TopLevelFolderName = "ZmumuTPReco"
+
+    #AddMuonSelectionTool()
+
+
+    # add a plotting tool
+    #PlotTool = AddPlottingTool(name="ZmumuTPPlottingTool_%s"%name_suffix,EffiFlag=name_suffix)
+
+    # add four TP selection tools (iso and antiiso OC and SC)
+    SelectionTools = []
+    SelectionTools += [CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_%s"%name_suffix,
+                                                                  EffiFlag="%s_OC"%name_suffix, 
+                                                                  ProbeType = ProbeKind)]
+    SelectionTools += [CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_%s"%name_suffix,
+                                                                  EffiFlag="%s_SC"%name_suffix, 
+                                                                  ProbeType = ProbeKind, 
+                                                                  SameSign=True)]
+    SelectionTools += [CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OCAntiIso_%s"%name_suffix,
+                                                                  EffiFlag="%s_OCAntiIso"%name_suffix, 
+                                                                  ProbeType = ProbeKind, 
+                                                                  AntiIso=True)]
+    SelectionTools += [CommonMuonTPConfig.AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SCAntiIso_%s"%name_suffix,
+                                                                  EffiFlag="%s_SCAntiIso"%name_suffix, 
+                                                                  ProbeType = ProbeKind, 
+                                                                  SameSign=True, 
+                                                                  AntiIso=True)]
+
+    PlotTools = []
+    # add plotting tools in slices
+    if doEtaSlices:
+        Slices = {
+                   "All" : (0.0,10.0),
+                   "noCrack" : (0.1,10.0),
+                   "Crack" : (0.0,0.1),
+                   "Barrel" : (0.1,1.1),
+                   "Transition" : (1.1, 1.3),
+                   "Endcap" : (1.3,2.0),
+                   "CSC" : (2.0,2.7)
+                   }
+
+        for etaslice, interval in Slices.iteritems():
+            PlotTool = CommonMuonTPConfig.AddPlottingTool(name="ZmumuTPPlottingTool_%s_%s"%(name_suffix,etaslice),
+                                                          EffiFlag=name_suffix+"_"+etaslice,
+                                                          applySF = False,
+                                                          DoProbeMatchPlots=DoProbeMatchPlots,
+                                                          ProduceEfficiencies=ProduceEfficiencies)
+            PlotTool.ProbeAbsEtaMin = interval[0]
+            PlotTool.ProbeAbsEtaMax = interval[1]
+            PlotTools.append(PlotTool)
+            if doClosure:
+                PlotToolCL = CommonMuonTPConfig.AddPlottingTool(name="ZmumuTPPlottingToolClosure_%s_%s"%(name_suffix,etaslice),
+                                                                EffiFlag=name_suffix+"_"+etaslice+"_Closure",
+                                                                applySF = True,
+                                                                DoProbeMatchPlots=DoProbeMatchPlots,
+                                                                ProduceEfficiencies=ProduceEfficiencies)
+                PlotToolCL.ProbeAbsEtaMin = interval[0]
+                PlotToolCL.ProbeAbsEtaMax = interval[1]
+                PlotTools.append(PlotToolCL)
+                
+    else:
+        PlotTools = [CommonMuonTPConfig.AddPlottingTool(name="ZmumuTPPlottingTool_%s_All"%name_suffix,
+                                                        EffiFlag=name_suffix+"_All",
+                                                        applySF = False,
+                                                        DoProbeMatchPlots=DoProbeMatchPlots,
+                                                        ProduceEfficiencies=ProduceEfficiencies)]
+        if doClosure:
+            PlotTools.append(CommonMuonTPConfig.AddPlottingTool(name="ZmumuTPPlottingToolClosure_%s_All"%name_suffix,
+                                                                EffiFlag=name_suffix+"_All_Closure",
+                                                                applySF = True,
+                                                                DoProbeMatchPlots=DoProbeMatchPlots,
+                                                                ProduceEfficiencies=ProduceEfficiencies))
+        
+    # Config the plot tools
+    for thetool in PlotTools:
+        thetool.doZmumuKinematicPlots = False
+        thetool.doFineEtaPhiPlots = True
+        thetool.doDetectorRegionPlots = True
+    
+    # add any desired matching tools
+    MATCH_DR = 0.05
+
+    
+    MatchingTools = []
+    if doCB:
+        thistoolCB = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_CB"%name_suffix,
+                                                                    EffiFlag="CombinedMuons")
+        thistoolCB.MatchToCB = True
+        thistoolCB.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Medium")
+        thistoolCB.ApplyScaleFactors=doClosure
+        thistoolCB.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolCB]
+        if doDRSys:
+            thistoolCB_dRDown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_CB_dRDown"%name_suffix,
+                                                                               EffiFlag="CombinedMuons_dRDown")
+            thistoolCB_dRDown.IsNominal=False                            
+            thistoolCB_dRDown.MatchToCB = True
+            thistoolCB_dRDown.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Medium")
+            #thistoolCB_dRDown.ApplyScaleFactors = True
+            thistoolCB_dRDown.MaximumDrCut = 0.5 * MATCH_DR
+            MatchingTools += [thistoolCB_dRDown]
+            
+            thistoolCB_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_CB_dRUp"%name_suffix,
+                                                                             EffiFlag="CombinedMuons_dRUp")
+            thistoolCB_dRUp.MatchToCB = True
+            thistoolCB_dRUp.IsNominal=False
+            thistoolCB_dRUp.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Medium")
+            #thistoolCB_dRUp.ApplyScaleFactors = True
+            thistoolCB_dRUp.MaximumDrCut = 2. * MATCH_DR
+            MatchingTools += [thistoolCB_dRUp]
+
+    if doLoose:
+        thistoolLoose = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Loose"%name_suffix,
+                                                                       EffiFlag="LooseMuons")
+        thistoolLoose.MatchToLoose = True
+        thistoolLoose.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Loose")
+        thistoolLoose.ApplyScaleFactors=doClosure
+        #thistoolLoose.ApplyScaleFactors = True
+        thistoolLoose.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolLoose]
+        if doDRSys:
+            thistoolLoose_dRDown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Loose_dRDown"%name_suffix,
+                                                                                  EffiFlag="LooseMuons_dRDown")
+            thistoolLoose_dRDown.MatchToLoose = True
+            thistoolLoose_dRDown.IsNominal=False
+            thistoolLoose_dRDown.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Loose")
+            #thistoolLoose_dRDown.ApplyScaleFactors = True
+            thistoolLoose_dRDown.MaximumDrCut = 0.5 * MATCH_DR
+            MatchingTools += [thistoolLoose_dRDown]
+            
+            thistoolLoose_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Loose_dRUp"%name_suffix,
+                                                                                EffiFlag="LooseMuons_dRUp")
+            thistoolLoose_dRUp.MatchToLoose = True
+            thistoolLoose_dRUp.IsNominal=False
+            thistoolLoose_dRUp.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Loose")
+            #thistoolLoose_dRUp.ApplyScaleFactors = True
+            thistoolLoose_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolLoose_dRUp]
+            
+        # also run a version without CaloTag
+        thistoolLoose_noCaloTag = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Loose_noCaloTag"%name_suffix,
+                                                                                 EffiFlag="LooseMuons_noCaloTag")
+        thistoolLoose_noCaloTag.MatchToLoose_noCaloTag = True
+        thistoolLoose_noCaloTag.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Loose")
+        thistoolLoose_noCaloTag.ApplyScaleFactors=doClosure
+        #thistoolLoose_noCaloTag.ApplyScaleFactors = True
+        thistoolLoose_noCaloTag.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolLoose_noCaloTag]
+        if doDRSys:
+            thistoolLoose_noCaloTag_dRDown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Loose_noCaloTag_dRDown"%name_suffix,
+                                                                                            EffiFlag="LooseMuons_noCaloTag_dRDown")
+            thistoolLoose_noCaloTag_dRDown.MatchToLoose_noCaloTag = True
+            thistoolLoose_noCaloTag_dRDown.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Loose")
+            #thistoolLoose_noCaloTag_dRDown.ApplyScaleFactors = True
+            thistoolLoose_noCaloTag_dRDown.IsNominal=False
+            thistoolLoose_noCaloTag_dRDown.MaximumDrCut = 0.5 * MATCH_DR
+            MatchingTools += [thistoolLoose_noCaloTag_dRDown]
+            
+            thistoolLoose_noCaloTag_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Loose_noCaloTag_dRUp"%name_suffix,
+                                                                                          EffiFlag="LooseMuons_noCaloTag_dRUp")
+            thistoolLoose_noCaloTag_dRUp.MatchToLoose_noCaloTag = True
+            thistoolLoose_noCaloTag_dRUp.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Loose")
+            #thistoolLoose_noCaloTag_dRUp.ApplyScaleFactors = True
+            thistoolLoose_noCaloTag_dRUp.IsNominal=False
+            thistoolLoose_noCaloTag_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolLoose_noCaloTag_dRUp]
+        
+    if doMedium:
+        thistoolMed = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Medium"%name_suffix,
+                                                                     EffiFlag="MediumMuons")
+        thistoolMed.MatchToMedium = True
+        thistoolMed.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Medium")
+        thistoolMed.ApplyScaleFactors=doClosure
+        thistoolMed.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolMed]
+        if doDRSys:
+            thistoolMed_dRDown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Medium_dRDown"%name_suffix,
+                                                                                EffiFlag="MediumMuons_dRDown")
+            thistoolMed_dRDown.MatchToMedium = True
+            thistoolMed_dRDown.IsNominal=False
+            thistoolMed_dRDown.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Medium")
+            #thistoolMed_dRDown.ApplyScaleFactors = True
+            thistoolMed_dRDown.MaximumDrCut = 0.5 * MATCH_DR
+            MatchingTools += [thistoolMed_dRDown]
+
+            thistoolMed_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Medium_dRUp"%name_suffix,
+                                                                              EffiFlag="MediumMuons_dRUp")
+            thistoolMed_dRUp.MatchToMedium = True
+            thistoolMed_dRUp.IsNominal=False
+            thistoolMed_dRUp.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Medium")
+            #thistoolMed_dRUp.ApplyScaleFactors = True
+            thistoolMed_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolMed_dRUp]
+            
+        thistoolMed_PtrMatch = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_PtrMatch_%s_Medium"%name_suffix,
+                                                                              EffiFlag="MediumMuons_PtrMatching")
+        thistoolMed_PtrMatch.MatchToMedium = True
+        thistoolMed_PtrMatch.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Medium")
+        thistoolMed_PtrMatch.ApplyScaleFactors=doClosure
+        #thistoolMed_PtrMatch.ApplyScaleFactors = True
+        thistoolMed_PtrMatch.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolMed_PtrMatch]
+
+        
+    if doTight:
+        thistoolTight = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Tight"%name_suffix,
+                                                                       EffiFlag="TightMuons")
+        thistoolTight.MatchToTight = True
+        thistoolTight.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Tight")
+        thistoolTight.ApplyScaleFactors=doClosure
+        #thistoolTight.ApplyScaleFactors = True
+        thistoolTight.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolTight]
+        if doDRSys:
+            thistoolTight_dRDown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Tight_dRDown"%name_suffix,
+                                                                                  EffiFlag="TightMuons_dRDown")
+            thistoolTight_dRDown.MatchToTight = True
+            thistoolTight_dRDown.IsNominal=False
+            thistoolTight_dRDown.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Tight")
+            #thistoolTight_dRDown.ApplyScaleFactors = True
+            thistoolTight_dRDown.MaximumDrCut = 0.5 * MATCH_DR
+            MatchingTools += [thistoolTight_dRDown]
+            
+            thistoolTight_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Tight_dRUp"%name_suffix,
+                                                                                EffiFlag="TightMuons_dRUp")
+            thistoolTight_dRUp.MatchToTight = True
+            thistoolTight_dRUp.IsNominal=False
+            thistoolTight_dRUp.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Tight")
+            #thistoolTight_dRUp.ApplyScaleFactors = True
+            thistoolTight_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolTight_dRUp]
+
+        
+    if doHighPt:
+        thistoolHighPt = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_HighPt"%name_suffix,
+                                                                       EffiFlag="HighPtMuons")
+        thistoolHighPt.MatchToHighPt = True
+        thistoolHighPt.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Tight")  # UPDATE when SF available for high pt
+        thistoolHighPt.ApplyScaleFactors=doClosure
+        #thistoolHighPt.ApplyScaleFactors = True
+        thistoolHighPt.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolHighPt]
+        if doDRSys:
+            thistoolHighPt_dRDown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_HighPt_dRDown"%name_suffix,
+                                                                                  EffiFlag="HighPtMuons_dRDown")
+            thistoolHighPt_dRDown.MatchToHighPt = True
+            thistoolHighPt_dRDown.IsNominal=False
+            thistoolHighPt_dRDown.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("HighPt")  # UPDATE when SF available for high pt
+            #thistoolHighPt_dRDown.ApplyScaleFactors = True
+            thistoolHighPt_dRDown.MaximumDrCut = 0.5 * MATCH_DR
+            MatchingTools += [thistoolHighPt_dRDown]
+            
+            thistoolHighPt_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_HighPt_dRUp"%name_suffix,
+                                                                                EffiFlag="HighPtMuons_dRUp")
+            thistoolHighPt_dRUp.MatchToHighPt = True
+            thistoolHighPt_dRUp.IsNominal=False
+            thistoolHighPt_dRUp.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Tight")  # UPDATE when SF available for high pt
+            #thistoolHighPt_dRUp.ApplyScaleFactors = True
+            thistoolHighPt_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolHighPt_dRUp]
+            
+
+    if doStandalone:
+        thistoolSA = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_SA"%name_suffix,
+                                                                    EffiFlag="StandaloneMuons")
+        thistoolSA.MatchToAnyMS = True
+        thistoolSA.IDhitCut = False
+        thistoolSA.ApplyScaleFactors = doClosure
+        thistoolSA.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolSA]
+        if doDRSys:
+            thistoolSA_dRDown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_SA_dRDown"%name_suffix,
+                                                                               EffiFlag="StandaloneMuons_dRDown")
+            thistoolSA_dRDown.MatchToAnyMS = True
+            thistoolSA_dRDown.IDhitCut = False
+            thistoolSA_dRDown.IsNominal=False
+            thistoolSA_dRDown.ApplyScaleFactors = doClosure
+            thistoolSA_dRDown.MaximumDrCut = 0.5 * MATCH_DR
+            MatchingTools += [thistoolSA_dRDown]
+
+            thistoolSA_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_SA_dRUp"%name_suffix,
+                                                                             EffiFlag="StandaloneMuons_dRUp")
+            thistoolSA_dRUp.MatchToAnyMS = True
+            thistoolSA_dRUp.IDhitCut = False
+            thistoolSA_dRUp.IsNominal=False
+            thistoolSA_dRUp.ApplyScaleFactors = doClosure
+            thistoolSA_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolSA_dRUp]
+
+    if doCaloTag:
+        thistoolCT = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_CT"%name_suffix,
+                                                                    EffiFlag="CaloTaggedMuons")
+        thistoolCT.MatchToCaloTag = True
+        thistoolCT.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Loose")
+        thistoolCT.ApplyScaleFactors=doClosure
+        #thistoolCT.ApplyScaleFactors = True
+        thistoolCT.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolCT]
+        if doDRSys:
+            thistoolCT_dRDown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_CT_dRDown"%name_suffix,
+                                                                               EffiFlag="CaloTaggedMuons_dRDown")
+            thistoolCT_dRDown.MatchToCaloTag = True
+            thistoolCT_dRDown.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Loose")
+            #thistoolCT_dRDown.ApplyScaleFactors = True
+            thistoolCT_dRDown.IsNominal=False
+            thistoolCT_dRDown.MaximumDrCut = 0.5 * MATCH_DR
+            MatchingTools += [thistoolCT_dRDown]
+
+            thistoolCT_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_CT_dRUp"%name_suffix,
+                                                                             EffiFlag="CaloTaggedMuons_dRUp")
+            thistoolCT_dRUp.MatchToCaloTag = True
+            thistoolCT_dRUp.ScaleFactorTool = CommonMuonTPConfig.AddMuonEfficiencyScaleFactors("Loose")
+            #thistoolCT_dRUp.ApplyScaleFactors = True
+            thistoolCT_dRUp.IsNominal=False
+            thistoolCT_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolCT_dRUp]
+
+    if doID:
+        thistoolID = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_ID"%name_suffix,
+                                                                    EffiFlag="IDTracks")
+        thistoolID.MatchToID = True
+        thistoolID.ApplyScaleFactors = doClosure
+        thistoolID.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolID]
+        if doDRSys:
+            thistoolID_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_ID_dRUp"%name_suffix,
+                                                                             EffiFlag="IDTracks_dRUp")
+            thistoolID_dRUp.MatchToID = True
+            thistoolID_dRUp.ApplyScaleFactors = doClosure
+            thistoolID_dRUp.MaximumDrCut = 2 * MATCH_DR
+            thistoolID_dRUp.IsNominal=False
+            MatchingTools += [thistoolID_dRUp]
+
+            thistoolID_dRDown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_ID_dRDown"%name_suffix,
+                                                                               EffiFlag="IDTracks_dRDown")
+            thistoolID_dRDown.MatchToID = True
+            thistoolID_dRDown.ApplyScaleFactors = doClosure
+            thistoolID_dRDown.MaximumDrCut = 0.5 * MATCH_DR
+            thistoolID_dRDown.IsNominal=False
+            MatchingTools += [thistoolID_dRDown]
+
+        #thistoolID_noMCPcuts = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_ID_noMCP"%name_suffix,EffiFlag="IDTracks_noMCP")
+        #thistoolID_noMCPcuts.MatchToID = True
+        #thistoolID_noMCPcuts.IDhitCut = False
+        #thistoolID_noMCPcuts.ApplyScaleFactors = doClosure
+        #thistoolID_noMCPcuts.MaximumDrCut = MATCH_DR
+        #MatchingTools += [thistoolID_noMCPcuts]
+        #if doDRSys:
+            #thistoolID_noMCPcuts_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_ID_noMCP_dRUp"%name_suffix,EffiFlag="IDTracks_noMCP_dRUp")
+            #thistoolID_noMCPcuts_dRUp.MatchToID = True
+            #thistoolID_noMCPcuts_dRUp.ApplyScaleFactors = doClosure
+            #thistoolID_noMCPcuts_dRUp.MaximumDrCut = 2 * MATCH_DR
+            #MatchingTools += [thistoolID_noMCPcuts_dRUp]
+
+            #thistoolID_noMCPcuts_dRDown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_ID_noMCP_dRDown"%name_suffix,EffiFlag="IDTracks_noMCP_dRDown")
+            #thistoolID_noMCPcuts_dRDown.MatchToID = True
+            #thistoolID_noMCPcuts_dRDown.ApplyScaleFactors = doClosure
+            #thistoolID_noMCPcuts_dRDown.MaximumDrCut = 0.5 * MATCH_DR
+            #MatchingTools += [thistoolID_noMCPcuts_dRDown]
+            
+
+
+    if doIndividualAuthors:
+        thistoolMuidCB = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidCB"%name_suffix,
+                                                                        EffiFlag="MuidCB")
+        thistoolMuidCB.MatchToMuidCB = True
+        thistoolMuidCB.ApplyScaleFactors = doClosure
+        thistoolMuidCB.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolMuidCB]
+        if doDRSys:
+            thistoolMuidCB_dRDown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidCB_dRDown"%name_suffix,
+                                                                                   EffiFlag="MuidCB_dRDown")
+            thistoolMuidCB_dRDown.MatchToMuidCB = True
+            thistoolMuidCB_dRDown.ApplyScaleFactors = doClosure
+            thistoolMuidCB_dRDown.MaximumDrCut = 0.5 * MATCH_DR
+            thistoolMuidCB_dRDown.IsNominal=False
+            MatchingTools += [thistoolMuidCB_dRDown]
+
+            thistoolMuidCB_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidCB_dRUp"%name_suffix,
+                                                                                 EffiFlag="MuidCB_dRUp")
+            thistoolMuidCB_dRUp.MatchToMuidCB = True
+            thistoolMuidCB_dRUp.ApplyScaleFactors = doClosure
+            thistoolMuidCB_dRUp.MaximumDrCut = 2 * MATCH_DR
+            thistoolMuidCB_dRUp.IsNominal=False
+            MatchingTools += [thistoolMuidCB_dRUp]
+
+        thistoolSTACO = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_STACO"%name_suffix,
+                                                                       EffiFlag="STACO")
+        thistoolSTACO.MatchToSTACO = True
+        thistoolSTACO.ApplyScaleFactors = doClosure
+        thistoolSTACO.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolSTACO]
+        if doDRSys:
+            thistoolSTACO_dRDown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_STACO_dRDown"%name_suffix,
+                                                                                  EffiFlag="STACO_dRDown")
+            thistoolSTACO_dRDown.MatchToSTACO = True
+            thistoolSTACO_dRDown.ApplyScaleFactors = doClosure
+            thistoolSTACO_dRDown.IsNominal=False
+            thistoolSTACO_dRDown.MaximumDrCut = 0.5 * MATCH_DR
+            MatchingTools += [thistoolSTACO_dRDown]
+
+            thistoolSTACO_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_STACO_dRUp"%name_suffix,
+                                                                                EffiFlag="STACO_dRUp")
+            thistoolSTACO_dRUp.MatchToSTACO = True
+            thistoolSTACO_dRUp.ApplyScaleFactors = doClosure
+            thistoolSTACO_dRUp.IsNominal=False
+            thistoolSTACO_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolSTACO_dRUp]
+
+        thistoolMuTag = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuTag"%name_suffix,
+                                                                       EffiFlag="MuTag")
+        thistoolMuTag.MatchToMuTag = True
+        thistoolMuTag.ApplyScaleFactors = doClosure
+        thistoolMuTag.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolMuTag]
+        if doDRSys:
+            thistoolMuTag_dRDown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuTag_dRDown"%name_suffix,
+                                                                                  EffiFlag="MuTag_dRDown")
+            thistoolMuTag_dRDown.MatchToMuTag = True
+            thistoolMuTag_dRDown.ApplyScaleFactors = doClosure
+            thistoolMuTag_dRDown.IsNominal=False
+            thistoolMuTag_dRDown.MaximumDrCut = 0.5 * MATCH_DR
+            MatchingTools += [thistoolMuTag_dRDown]
+
+            thistoolMuTag_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuTag_dRUp"%name_suffix,
+                                                                                EffiFlag="MuTag_dRUp")
+            thistoolMuTag_dRUp.MatchToMuTag = True
+            thistoolMuTag_dRUp.ApplyScaleFactors = doClosure
+            thistoolMuTag_dRUp.IsNominal=False
+            thistoolMuTag_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolMuTag_dRUp]
+
+        thistoolMuTagIMO = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuTagIMO"%name_suffix,
+                                                                          EffiFlag="MuTagIMO")
+        thistoolMuTagIMO.MatchToMuTagIMO = True
+        thistoolMuTagIMO.ApplyScaleFactors = doClosure
+        thistoolMuTagIMO.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolMuTagIMO]
+        if doDRSys:
+            thistoolMuTagIMO_dRDown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuTagIMO_dRDown"%name_suffix,
+                                                                                     EffiFlag="MuTagIMO_dRDown")
+            thistoolMuTagIMO_dRDown.MatchToMuTagIMO = True
+            thistoolMuTagIMO_dRDown.ApplyScaleFactors = doClosure
+            thistoolMuTagIMO_dRDown.IsNominal=False
+            thistoolMuTagIMO_dRDown.MaximumDrCut = 0.5 * MATCH_DR
+            MatchingTools += [thistoolMuTagIMO_dRDown]
+
+            thistoolMuTagIMO_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuTagIMO_dRUp"%name_suffix,
+                                                                                   EffiFlag="MuTagIMO_dRUp")
+            thistoolMuTagIMO_dRUp.MatchToMuTagIMO = True
+            thistoolMuTagIMO_dRUp.ApplyScaleFactors = doClosure
+            thistoolMuTagIMO_dRUp.IsNominal=False
+            thistoolMuTagIMO_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolMuTagIMO_dRUp]
+
+        thistoolMuidSA = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidSA"%name_suffix,
+                                                                        EffiFlag="MuidSA")
+        thistoolMuidSA.MatchToMuidSA = True
+        thistoolMuidSA.ApplyScaleFactors = doClosure
+        thistoolMuidSA.IDhitCut = False
+        thistoolMuidSA.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolMuidSA]
+        if doDRSys:
+            thistoolMuidSA_dRDown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidSA_dRDown"%name_suffix,
+                                                                                   EffiFlag="MuidSA_dRDown")
+            thistoolMuidSA_dRDown.MatchToMuidSA = True
+            thistoolMuidSA_dRDown.ApplyScaleFactors = doClosure
+            thistoolMuidSA_dRDown.IsNominal=False
+            thistoolMuidSA_dRDown.MaximumDrCut = 0.5 * MATCH_DR
+            MatchingTools += [thistoolMuidSA_dRDown]
+
+            thistoolMuidSA_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidSA_dRUp"%name_suffix,
+                                                                                 EffiFlag="MuidSA_dRUp")
+            thistoolMuidSA_dRUp.MatchToMuidSA = True
+            thistoolMuidSA_dRUp.ApplyScaleFactors = doClosure
+            thistoolMuidSA_dRUp.IsNominal=False
+            thistoolMuidSA_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolMuidSA_dRUp]
+
+        thistoolMuGirl = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidGirl"%name_suffix,
+                                                                        EffiFlag="MuGirl")
+        thistoolMuGirl.MatchToMuGirl = True
+        thistoolMuGirl.ApplyScaleFactors = doClosure
+        thistoolMuGirl.MaximumDrCut = MATCH_DR
+        MatchingTools += [thistoolMuGirl]
+        if doDRSys:
+            thistoolMuGirl_dRDown = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidGirl_dRDown"%name_suffix,
+                                                                                   EffiFlag="MuGirl_dRDown")
+            thistoolMuGirl_dRDown.MatchToMuGirl = True
+            thistoolMuGirl_dRDown.ApplyScaleFactors = doClosure
+            thistoolMuGirl_dRDown.IsNominal=False
+            thistoolMuGirl_dRDown.MaximumDrCut = 0.5 * MATCH_DR
+            MatchingTools += [thistoolMuGirl_dRDown]
+
+            thistoolMuGirl_dRUp = CommonMuonTPConfig.AddMuonRecoTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidGirl_dRUp"%name_suffix,
+                                                                                 EffiFlag="MuGirl_dRUp")
+            thistoolMuGirl_dRUp.MatchToMuGirl = True
+            thistoolMuGirl_dRUp.IsNominal=False
+            thistoolMuGirl_dRUp.ApplyScaleFactors = doClosure
+            thistoolMuGirl_dRUp.MaximumDrCut = 2 * MATCH_DR
+            MatchingTools += [thistoolMuGirl_dRUp]
+            
+    ntuples = []
+    if writeNtuple:
+        ntuples.append(CommonMuonTPConfig.AddTreeTool(name="ZmumuTPTreeTool_%s"%name_suffix, 
+                                                      EffiFlag="Trees",WriteSFInfo=doClosure))
+
+    # create the TP tool itself
+    TheTPTool = CommonMuonTPConfig.AddMuonTPTool(name = "ZmumuTPTool_%s"%name_suffix,
+                                                 EffiFlag=name_suffix)
+    TheTPTool.MuonTPSelectionTools = SelectionTools
+    TheTPTool.PlottingTools = PlotTools
+    TheTPTool.MuonTPEfficiencyTools = MatchingTools
+    TheTPTool.TreeTools = ntuples
+    theAlg.MuonTPTools += [TheTPTool]
+
+
+def AddZmumuTPRecoAnalysis(doEtaSlices=False,writeNtuple=False,doClosure=False,doDRSys=False, doValid=False,DoProbeMatchPlots=True,ProduceEfficiencies=False):
+
+
+    from AthenaCommon.AlgSequence import AlgSequence
+    from AthenaCommon.AppMgr import ToolSvc
+    job = AlgSequence()
+
+    MuonContainerToUse = "Muons"
+    #if hasattr(job, "MuonQualityUpdater"):
+        #MuonContainerToUse = "UpdatedMuons"
+
+
+    ###########################################################################################
+    ## Add the Zmm TP algorithm using ID tracks as probes and matching to muons
+    #AddConfiguredZmumuTPAlg(name_suffix = "IDProbes",
+                            #ProbeKind = "ID",
+                            #MatchContainer = MuonContainerToUse,
+                            #doID = False, doCB = True, doLoose=True, doMedium = True,
+                            #doTight=True, doStandalone = False, doCaloTag = True, doIndividualAuthors = doValid,
+                            #doEtaSlices=doEtaSlices, writeNtuple = writeNtuple,doClosure=doClosure, doDRSys = doDRSys)
+
+
+    #########################################################################################
+    #Add the Zmm TP algorithm using CaloTag muons as probes and matching to muons
+    AddConfiguredZmumuTPAlg(name_suffix = "CaloProbes",
+                            ProbeKind = "CaloTag",
+                            MatchContainer = MuonContainerToUse,
+                            doID = False, doCB = True, doLoose=True, doMedium = True,
+                            doTight=True, doHighPt=True,
+                            doStandalone = False, doCaloTag = False, doIndividualAuthors = doValid,
+                            doEtaSlices=doEtaSlices, writeNtuple = writeNtuple,doClosure=doClosure, doDRSys = doDRSys,
+                            DoProbeMatchPlots=DoProbeMatchPlots,
+                            ProduceEfficiencies=ProduceEfficiencies)
+
+
+    ##########################################################################################
+    # Add the Zmm TP algorithm using MS muons as probes and matching to ID tracks
+   # AddConfiguredZmumuTPAlg(name_suffix = "MSTrackPartProbes_ID",
+   #                         ProbeKind = "MSTrackPart",
+   #                         MatchContainer = "InDetTrackParticles",
+   #                         doID = True, doCB = False, doLoose=False, doMedium = False,
+   #                         doTight=False, doHighPt=True,
+   #                         doStandalone = False, doCaloTag = False,
+   #                         doEtaSlices=doEtaSlices, writeNtuple = writeNtuple,doClosure=doClosure, doDRSys = doDRSys)
+
+
+    ##########################################################################################
+    # Add the Zmm TP algorithm using MS muons as probes and matching to ID tracks
+    AddConfiguredZmumuTPAlg(name_suffix = "MSProbes_ID",
+                            ProbeKind = "MS",
+                            MatchContainer = "InDetTrackParticles",
+                            doID = True, doCB = False, doLoose=False, doMedium = False,
+                            doTight=False, doHighPt=False,
+                            doStandalone = False, doCaloTag = False, doIndividualAuthors = False,
+                            doEtaSlices=doEtaSlices, writeNtuple = writeNtuple,doClosure=doClosure, doDRSys = doDRSys,
+                            DoProbeMatchPlots=DoProbeMatchPlots,
+                            ProduceEfficiencies=ProduceEfficiencies)
+
+
+    ##########################################################################################
+    # Add the Zmm TP algorithm using MS muons as probes and matching to CaloTag muons
+    AddConfiguredZmumuTPAlg(name_suffix = "MSProbes_Muon",
+                            ProbeKind = "MS",
+                            MatchContainer = MuonContainerToUse,
+                            doID = False, doCB = False, doLoose=False, doMedium = False,
+                            doTight=False, doHighPt=False,
+                            doStandalone = False, doCaloTag = True, doIndividualAuthors = False,
+                            doEtaSlices=doEtaSlices, writeNtuple = writeNtuple,doClosure=doClosure, doDRSys = doDRSys,
+                            DoProbeMatchPlots=DoProbeMatchPlots,
+                            ProduceEfficiencies=ProduceEfficiencies)
+    
+    
+    # Only add truth probes if we are running on MC!
+    from AthenaCommon.GlobalFlags import globalflags
+    if not globalflags.DataSource()=='data':
+        ##########################################################################################
+        # Add the Zmm TP algorithm using Truth probes for Muons
+        AddConfiguredZmumuTPAlg(name_suffix = "TruthProbes_Muon",
+                                ProbeKind = "Truth",
+                                MatchContainer = MuonContainerToUse,
+                                doID = False, doCB = True, doLoose=True, doMedium = True,
+                                doTight=True, doHighPt=True,
+                                doStandalone = False, doCaloTag = True, doIndividualAuthors = doValid,
+                                doEtaSlices=doEtaSlices, writeNtuple = writeNtuple,doClosure=False, doDRSys = False,
+                                DoProbeMatchPlots=DoProbeMatchPlots,
+                                ProduceEfficiencies=ProduceEfficiencies)
+
+        ##########################################################################################
+        # Add the Zmm TP algorithm using Truth probes for Tracks
+        AddConfiguredZmumuTPAlg(name_suffix = "TruthProbes_ID",
+                                ProbeKind = "Truth",
+                                MatchContainer = "InDetTrackParticles",
+                                doID = True, doCB = False, doLoose=False, doMedium = False,
+                                doTight=False, doHighPt=False,
+                                doStandalone = False, doCaloTag = False, doIndividualAuthors = False,
+                                doEtaSlices=doEtaSlices, writeNtuple = writeNtuple,doClosure=False, doDRSys = False,
+                                DoProbeMatchPlots=DoProbeMatchPlots,
+                                ProduceEfficiencies=ProduceEfficiencies)
\ No newline at end of file
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/ZmumuTPTrigAnalysis.py b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/ZmumuTPTrigAnalysis.py
new file mode 100644
index 00000000000..192c2b0f26e
--- /dev/null
+++ b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/python/ZmumuTPTrigAnalysis.py
@@ -0,0 +1,130 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+from MuonPerformanceAlgs import CommonMuonTPConfig
+
+def AddTrigPlots(name_suffix,doEtaSlices=True, 
+                 doClosure=False,
+                 DoProbeMatchPlots=True,
+                 ProduceEfficiencies=False):
+    PlotTools = []
+    # add plotting tools in slices
+    if doEtaSlices:
+        Slices = {
+                   "Barrel"     : (0.0,1.05),
+                   "Endcap"     : (1.05,2.5)
+                   }
+
+        for etaslice, interval in Slices.iteritems():
+            PlotTool = CommonMuonTPConfig.AddPlottingTool(name="TriggerTPPlottingTool_%s_%s"%(name_suffix,etaslice),
+                                                          EffiFlag=name_suffix+"_"+etaslice,
+                                                          applySF = False,
+                                                          DoProbeMatchPlots=DoProbeMatchPlots,
+                                                          ProduceEfficiencies=ProduceEfficiencies)
+            PlotTool.ProbeAbsEtaMin = interval[0]
+            PlotTool.ProbeAbsEtaMax = interval[1]
+            PlotTools.append(PlotTool)
+            if doClosure:
+                PlotToolCL = CommonMuonTPConfig.AddPlottingTool(name="TriggerTPPlottingTool_Closure_%s_%s"%(name_suffix,etaslice),
+                                                                EffiFlag=name_suffix+"_"+etaslice+"_Closure",
+                                                                applySF = True,
+                                                                DoProbeMatchPlots=DoProbeMatchPlots,
+                                                                ProduceEfficiencies=ProduceEfficiencies)
+                PlotToolCL.ProbeAbsEtaMin = interval[0]
+                PlotToolCL.ProbeAbsEtaMax = interval[1]
+                PlotTools.append(PlotToolCL)
+            pass
+                
+    else:
+        PlotTools = [CommonMuonTPConfig.AddPlottingTool(name="TriggerTPPlottingTool_%s_All"%name_suffix,
+                                                        EffiFlag=name_suffix+"_All",
+                                                        applySF = False,
+                                                        DoProbeMatchPlots=DoProbeMatchPlots,
+                                                        ProduceEfficiencies=ProduceEfficiencies)]
+        if doClosure:
+            PlotTools.append(CommonMuonTPConfig.AddPlottingTool(name="TriggerTPPlottingTool_Closure_%s_All"%name_suffix,
+                                                                EffiFlag=name_suffix+"_All_Closure",
+                                                                applySF = True,
+                                                                DoProbeMatchPlots=DoProbeMatchPlots,
+                                                                ProduceEfficiencies=ProduceEfficiencies))
+        pass
+    
+    # configure the plot tools
+    for thetool in PlotTools:
+        thetool.DoAsymmErrorGraphs    = True
+        thetool.doTrigValidPlots    = True
+    return PlotTools
+
+def GetTriggerList():
+    TriggerList_HLT = [
+                "HLT_mu14",
+                "HLT_mu20_iloose_L1MU15",
+                "HLT_mu24_iloose_L1MU15",
+                "HLT_mu24_imedium",
+                "HLT_mu26_imedium",
+                "HLT_mu50",
+                "HLT_mu40",
+                "HLT_AllTriggers", # this is needed, if you want to have combined (inclusive) efficiency of all HLT triggers
+                    ]
+    TriggerList_L1 = [
+                "L1_MU10",
+                "L1_MU15",
+                "L1_MU20",
+                "L1_AllTriggers", # this is needed, if you want to have combined (inclusive) efficiency of all L1 triggers 
+                ]
+    TriggerList_L2 = [
+                       "L2_MU20" # a dummy name
+                        ]
+    TriggerList_EF = [  "EF_MU30" # a dummy name
+                                ]
+    return {
+        "L1": TriggerList_L1,
+        "L2": TriggerList_L2,
+        "EF": TriggerList_EF,
+        "HLT":TriggerList_HLT
+    }
+     
+
+def AddTrigMatchTools(name_suffix,doL1 = True, doL2=False, doEF=False,doHLT=True,doDRSys=True):
+    TrigList = GetTriggerList()
+    TriggerList_L1  = []
+    TriggerList_L2  = []
+    TriggerList_EF  = []
+    TriggerList_HLT = []
+    
+    if doHLT:
+        TriggerList_HLT = TrigList["HLT"]
+    if doL1:
+        TriggerList_L1 = TrigList["L1"]
+    if doL2:
+        TriggerList_L2 = TrigList["L2"]
+    if doEF:
+        TriggerList_EF = TrigList["EF"]
+
+    MatchingTools = []
+
+    MATCH_DR = 0.05
+    for Trigitem in TriggerList_L1 + TriggerList_L2 + TriggerList_EF + TriggerList_HLT:
+        thistool = CommonMuonTPConfig.AddTriggerTPEfficiencyTool(name="TriggerTPEfficiencyTool_%s_%s"%(name_suffix,Trigitem),EffiFlag=Trigitem)
+        thistool.TrigItem = Trigitem
+        # Delta R: 0.1 for L2/EF/HLT, 0.2 for L1 - taken from TrigMuonMatching
+        MATCH_DR = 0.1
+        if "L1" in Trigitem:
+            MATCH_DR = 0.2
+        thistool.MaximumDrCut = MATCH_DR
+        MatchingTools.append(thistool)
+        if doDRSys:
+            thistool_dRup = CommonMuonTPConfig.AddTriggerTPEfficiencyTool(name="TriggerTPEfficiencyTool_DrUp_%s_%s"%(name_suffix,Trigitem),EffiFlag="%s_dRUp"%Trigitem)
+            thistool_dRup.TrigItem = Trigitem
+            thistool_dRup.IsNominal = False
+            thistool_dRup.MaximumDrCut = MATCH_DR+0.05
+            MatchingTools.append(thistool_dRup)
+
+            thistool_dRDown = CommonMuonTPConfig.AddTriggerTPEfficiencyTool(name="TriggerTPEfficiencyTool_DrDown_%s_%s"%(name_suffix,Trigitem),EffiFlag="%s_dRDown"%Trigitem)
+            thistool_dRDown.TrigItem = Trigitem
+            thistool_dRDown.IsNominal = False
+            thistool_dRDown.MaximumDrCut =  MATCH_DR-0.05
+            MatchingTools.append(thistool_dRDown)
+
+        
+    return MatchingTools
+    
\ No newline at end of file
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/scripts/Submit.sh b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/scripts/Submit.sh
new file mode 100644
index 00000000000..13161f6c03b
--- /dev/null
+++ b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/scripts/Submit.sh
@@ -0,0 +1,84 @@
+
+#!/bin/bash
+
+#///////////////////////////////////////////////////////////////
+# Tag-and-probe grid submit script.
+# Use: First generate tarballs using a dummy xAOD file via
+# source makeTarBalls.sh <dummy xAOD>
+# then submit jobs via source Submit.sh <Dataset or txt file containing many datasets>
+# Parameters:
+# SUFFIX will be appended to the end of the output DS. Default: TP_<Date>_v1
+#///////////////////////////////////////////////////////////////
+
+# configure the name of the output dataset:
+SUFFIX="TP_"
+DATE=`date +%Y%m%d`
+SUFFIX+=$DATE
+SUFFIX+="_v1"                  # change version name
+
+if  [ "niko" = $USER ]; then
+        NAME="nkoehler"
+else NAME=$USER
+fi
+my_prun_nickname=$NAME		# enter cern username
+
+if [ -e $1 ]
+then list=$1
+else list="dummy.txt";echo $1 > $list
+fi
+
+while read sample
+  do
+  # ds=$sample
+  # Remove whitespace.. either line should do
+  #  (the first removes leading whitespace, the second removes trailing whitespace)
+  # ds="${sample#"${sample%%[![:space:]]*}"}"
+  ds="${sample%"${sample##*[![:space:]]}"}"
+
+  if [[ "${ds}" == "" ]]
+      then
+      continue
+  fi
+
+  # Ignore lines starting with a hash
+  if [[ ${ds:0:1} == "#" ]]
+      then
+      continue
+  fi
+  echo submitting $sample...
+  # 
+  # Here, we clean up the DS name a bit to stay within the 13X character limit
+  # Feel free to extend! 
+  #
+  dsorig=$ds
+  dsorig=${ds/.merge.AOD/}
+  dsorig=${dsorig/user.dzhang./}
+  dsorig=${dsorig/_EXT0/}
+  dsorig=${dsorig/group.perf-muons:group.perf-muons./}
+  dsorig=${dsorig/data15_comm:data15_comm./}
+  dsorig=${dsorig/data15_13TeV:data15_13TeV./}
+  dsorig=${dsorig/mc15_13TeV:mc15_13TeV./}
+  dsorig=${dsorig/_hdamp172p5/}
+  dsorig=${dsorig/EvtGen_P2012/}
+  dsorig=${dsorig/group.det-muon:group.det-muon./}
+  dsorig=${dsorig/group.det-muon./}
+  dsorig=${dsorig//s????_/}
+  dsorig=${dsorig%\/}
+  outname="user.$my_prun_nickname.$dsorig.$SUFFIX"
+  # Submit using pathena.
+  pathena MuonPerformanceAlgs/MuonTP_topOptions.py \
+      --inDS $ds \
+      --outDS $outname \
+      --express \
+      --mergeOutput \
+      --useShortLivedReplicas \
+      --site=AUTO \
+      --inTarBall=otb.tar\
+      --inRunConfig=runconf.datatp
+  echo "output DS is " $outname/
+done < "$list"
+      #--nFilesPerJob=1 \
+      #--noSubmit \
+
+
+   #   --excludedSite=ANALY_IN2P3-CC_SL6,ANALY_IN2P3-CC \
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/scripts/makeTarBalls.sh b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/scripts/makeTarBalls.sh
new file mode 100644
index 00000000000..6c72c3359d1
--- /dev/null
+++ b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/scripts/makeTarBalls.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+# generate tarballs for the main submit script
+if  [ "niko" = $USER ]; then
+	NAME="nkoehler"
+else NAME=$USER
+fi
+
+pathena -c "FNAME='$1'" MuonPerformanceAlgs/MuonTP_topOptions.py \
+      --dbRelease=LATEST \
+      --outDS='user.'$NAME'.dummy.1' \
+      --outTarBall=otb.tar\
+      --outRunConfig=runconf.datatp \
+      --mergeOutput \
+      --nGBPerJob=MAX \
+      --noSubmit
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/MuonTP_topOptions.py b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/MuonTP_topOptions.py
index 6ccb6d79ff5..0ea41d5c1b8 100644
--- a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/MuonTP_topOptions.py
+++ b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/MuonTP_topOptions.py
@@ -8,29 +8,62 @@
 
 
 #Specify input file.
-if not "pandaJob" in globals() and not  "FNAME" in globals():
-    include ('MuonPerformanceAlgs/Zmumu_19.0.2.1.py')
-else:
+
+#InputAODList = []
+#if not "pandaJob" in globals() and not  "FNAME" in globals():
+
+
+
+from AthenaCommon.AppMgr import ServiceMgr
+import AthenaPoolCnvSvc.ReadAthenaPool
+from AthenaCommon.AthenaCommonFlags import athenaCommonFlags as acf
+
+
+if 'FILELIST' in globals():
+        #FILELIST="filelist.txt"
+    print "running with local file list %s"%FILELIST
+
+    import os
+
+    if os.path.isfile(FILELIST):
+      with open(FILELIST,'r') as input:
+          InputAODList=[bla for bla in input.read().split("\n") if bla != ""and not '#' in bla ]
+          acf.FilesInput = InputAODList
+          ServiceMgr.EventSelector.InputCollections = InputAODList
+
+elif 'FNAME' in globals():
+    print "running with manually specified input file %s"%FNAME
     InputAODList=[FNAME]
+    acf.FilesInput = InputAODList
+    ServiceMgr.EventSelector.InputCollections = InputAODList
+    
+#else:
+    #print "Neither FNAME nor FILELIST specified - if we are not on the grid, this might go wrong..."
+
+#if not "pandaJob" in globals() and not  "FNAME" in globals():
+    #if not 'FILELIST' in globals():
+        #FILELIST="filelist.txt"
+    #print "running with file list %s"%FILELIST
 
+    #with open(FILELIST,'r') as input:
+        #InputAODList=[bla for bla in input.read().split("\n") if bla != ""and not '#' in bla ]
 
-#include ('PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/Sample_Valid3_147407_e3099_s2578_r6588.py')
+#else:
+    #InputAODList=[FNAME]
 
 
 #--------------------------------------------------------------
 # Input stream
 #--------------------------------------------------------------
 
-from AthenaCommon.AppMgr import ServiceMgr
-import AthenaPoolCnvSvc.ReadAthenaPool
-ServiceMgr.EventSelector.InputCollections = InputAODList
 
 print ServiceMgr.EventSelector.InputCollections
+if len(ServiceMgr.EventSelector.InputCollections) == 0:
+    print "Empty input collection - are you running locally without FNAME or FILELIST set? This may go horribly wrong..."
+    
+    
 
 
-from AthenaCommon.AthenaCommonFlags import athenaCommonFlags as acf
-acf.FilesInput = InputAODList
-
 #--------------------------------------------------------------
 # Reduce the event loop spam a bit
 #--------------------------------------------------------------
@@ -72,75 +105,9 @@ include ("MuonPerformanceAlgs/RecExCommon_for_TP.py")
 # Allow messge service more than default 500 lines.
 ServiceMgr.MessageSvc.infoLimit = 20000
 
-# Full job is a list of algorithms
-from AthenaCommon.AlgSequence import AlgSequence
-job = AlgSequence()
-
-
-include ('MuonPerformanceAlgs/ZmumuTPAnalysis.py')
-include ('MuonPerformanceAlgs/ZmumuTPIsolationAnalysis.py')
-include ('MuonPerformanceAlgs/ZmumuTPTrigAnalysis.py')
-
-# now we can add the TP analysis/es itself/themselves :)
-
-############## Zmumu T&P Configuration ########################
-do_Zmumu_RecoEff_TagProbe      = True # this is for Z->mumu, reco eff. You can add your own analysis in a similar way.
-do_Zmumu_IsolationEff_TagProbe = True # this is for Z->mumu, isolation eff. You can add your own analysis in a similar way.
-do_Zmumu_Trigger_TagProbe      = True  # this is for Z->mumu, Trigger eff.
-
-##### General analysis options
-writeNtuple = True                     # Write an ntuple on top of the histos - for detailed studies, but increases output file size
-doEtaSlices = False
-doClosure   = False
-doDRSys     = False
-doValid     = False
-
-
-# Add utilities (tool, upstream algorithms) we need
-AddIsolationTools()
-AddTrigDecisionTool()
-AddTrigMatchingTool()
-AddMuonSelectionTool()
-
-
-##### Reco eff analysis options
-if do_Zmumu_RecoEff_TagProbe:
-	writeNtuple = True                    
-	doEtaSlices = False
-	doClosure   = False
-	doDRSys     = True
-	doValid     = True
-	AddZmumuTPAnalysis(doEtaSlices,writeNtuple,doClosure,doDRSys,doValid)      
-###############################################################
-
-
-##### Isolation eff analysis options
-if do_Zmumu_IsolationEff_TagProbe: 
-    doEtaSlices = False
-    doClosure   = False
-    doDRSys     = True
-    doValid     = True
-    AddZmumuTPIsolationAnalysis(doEtaSlices,writeNtuple,doClosure,doDRSys)
-    pass
-###############################################################
-
-
-##### Trigger analysis options
-if do_Zmumu_Trigger_TagProbe:
-        doTriggerL1  = True
-        doTriggerL2  = False
-        doTriggerEF  = False
-        doTriggerHLT = True
-        doEtaSlices  = True
-        doDRSys      = False
-        AddTriggerTPAnalysis(doEtaSlices,writeNtuple,doClosure,doDRSys,doL1=doTriggerL1,doL2=doTriggerL2,doEF=doTriggerEF,doHLT=doTriggerHLT)
-###############################################################
-
-print ToolSvc
-print job
-print ServiceMgr
-# Add HistSvc
-from GaudiSvc.GaudiSvcConf import THistSvc
-ServiceMgr += THistSvc()
-ServiceMgr.THistSvc.Output += ["MUONTP DATAFILE='muontp.root' OPT='RECREATE'"]
+# Configure Muon TP tools
+from MuonPerformanceAlgs import MuonTPAnalysis
+MuonTPAnalysis.MuonTPConfig('muontp.root',doPlots=True,doEff=True)
+
+
 
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/ZmumuTPAnalysis.py b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/ZmumuTPAnalysis.py
deleted file mode 100644
index 29ce3300b5f..00000000000
--- a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/ZmumuTPAnalysis.py
+++ /dev/null
@@ -1,851 +0,0 @@
-
-from AthenaCommon.AlgSequence import AlgSequence
-from AthenaCommon.AppMgr import ToolSvc
-
-job = AlgSequence()
-
-from MuonEfficiencyCorrections.MuonEfficiencyCorrectionsConf import CP__MuonEfficiencyScaleFactors
-
-
-# add an instance of the TP Algorithm
-def AddZmumuTPAlg(name, ProbeCont, MatchCont):
-
-    from AthenaCommon.AlgSequence import AlgSequence
-    from AthenaCommon.AppMgr import ToolSvc
-    job = AlgSequence()
-    MuonContainerToUse = "Muons"
-    if hasattr(job, "MuonQualityUpdater"):
-        MuonContainerToUse = "UpdatedMuons"
-    from MuonPerformanceAlgs.MuonPerformanceAlgsConf import MuonTPAlg
-    thisAlg = MuonTPAlg(name)
-    thisAlg.TagContainerName   = MuonContainerToUse
-    thisAlg.ProbeContainerName = ProbeCont
-    thisAlg.MatchContainerName = MatchCont
-    job += thisAlg
-    return thisAlg
-
-# add a muon selection tool if there is none yet
-def AddMuonSelectionTool():
-
-    from AthenaCommon.AppMgr import ToolSvc
-    if not hasattr(ToolSvc,"TagProbeMuonSelectionTool"):
-        from MuonSelectorTools.MuonSelectorToolsConf import CP__MuonSelectionTool
-        ToolSvc += CP__MuonSelectionTool("TagProbeMuonSelectionTool")
-        ToolSvc.TagProbeMuonSelectionTool.MaxEta = 99.  # don't cut on eta in this tool
-
-
-# Add a track isolation updater tool
-def AddIsolationTools():
-    from AthenaCommon.AlgSequence import AlgSequence
-    job = AlgSequence()
-    from AthenaCommon.AppMgr import ToolSvc
-    
-    if not hasattr(ToolSvc, "MyTrackIsoTool"):
-        print "Adding it!!"
-            
-        #try:
-        from IsolationTool.IsolationToolConf import xAOD__TrackIsolationTool
-        ToolSvc += xAOD__TrackIsolationTool("MyTrackIsoTool")
-        # Cuts suggested by Dongliang to reproduce the default muon ptcone
-        ToolSvc.MyTrackIsoTool.TrackSelectionTool.maxZ0SinTheta= 3.
-        ToolSvc.MyTrackIsoTool.TrackSelectionTool.minPt= 1000.
-        #ToolSvc.MyTrackIsoTool.TrackSelectionTool.minNSiHits= 9
-        #ToolSvc.MyTrackIsoTool.TrackSelectionTool.minNPixelHits= 1
-        ToolSvc.MyTrackIsoTool.TrackSelectionTool.CutLevel="Loose"
-        
-        
-        from AthenaCommon.GlobalFlags import globalflags
-        isMC = not globalflags.DataSource()=='data'
-        from IsolationCorrections.IsolationCorrectionsConf import CP__IsolationCorrectionTool
-        IsoCorrectionTool = CP__IsolationCorrectionTool ("NewLeakageCorrTool",IsMC = isMC)
-        ToolSvc += IsoCorrectionTool
-
-        # tool to collect topo clusters in cone
-        from ParticlesInConeTools.ParticlesInConeToolsConf import xAOD__CaloClustersInConeTool
-        ToolSvc += xAOD__CaloClustersInConeTool("MyCaloClustersInConeTool",CaloClusterLocation = "CaloCalTopoClusters")
-
-        from CaloIdentifier import SUBCALO
-
-        from IsolationTool.IsolationToolConf import xAOD__CaloIsolationTool
-        ToolSvc += xAOD__CaloIsolationTool("MyCaloIsoTool")
-        ToolSvc.MyCaloIsoTool.IsoLeakCorrectionTool = ToolSvc.NewLeakageCorrTool
-        ToolSvc.MyCaloIsoTool.ClustersInConeTool = ToolSvc.MyCaloClustersInConeTool
-        ToolSvc.MyCaloIsoTool.EMCaloNums  = [SUBCALO.LAREM]
-        ToolSvc.MyCaloIsoTool.HadCaloNums = [SUBCALO.LARHEC, SUBCALO.TILE]
-        ToolSvc.MyCaloIsoTool.UseEMScale  = True
-        ToolSvc.MyCaloIsoTool.saveOnlyRequestedCorrections = True   
-        
-        from MuonPerformanceAlgs.MuonPerformanceAlgsConf import TrackIsolationDecorAlg
-
-        job += TrackIsolationDecorAlg("MyIDTrackDecorator")
-        job.MyIDTrackDecorator.TrackIsolationTool = ToolSvc.MyTrackIsoTool
-        job.MyIDTrackDecorator.CaloIsolationTool = ToolSvc.MyCaloIsoTool
-
-        
-        #except AttributeError:
-            #print "This did not work :("
-            #sys.exit(1)
-    
-# Add the trigger decision tool
-def AddTrigDecisionTool():
-    from AthenaCommon.AppMgr import ToolSvc
-    if not hasattr(ToolSvc, "TrigDecisionTool"):
-        ToolSvc += CfgMgr.Trig__TrigDecisionTool( "TrigDecisionTool",
-                                            OutputLevel = WARNING,
-                                            TrigDecisionKey = "xTrigDecision" )
-    
-# Add the trigger matching tool
-def AddTrigMatchingTool():
-    from AthenaCommon.AppMgr import ToolSvc
-    if not hasattr(ToolSvc,"TrigMuonMatching"):
-        from TrigMuonMatching.TrigMuonMatchingConf import Trig__TrigMuonMatching
-        trigmatch = Trig__TrigMuonMatching("TrigMuonMatching")
-        ToolSvc += trigmatch
-        #trigmatch.dRmin = 0.1
-        #trigmatch.LVL1dRmin = 0.2
-        trigmatch.TriggerTool = ToolSvc.TrigDecisionTool
-
-        
-# Add instance of the TP plotting tool
-def AddZmumuTPPlotTool(name, EffiFlag, applySF=False):
-
-    from AthenaCommon.AppMgr import ToolSvc
-    from MuonTPTools.MuonTPToolsConf import ZmumuMuonTPPlotTool
-    thetool = ZmumuMuonTPPlotTool(name)
-    thetool.EfficiencyFlag = EffiFlag
-    thetool.doTrkValidPlots = False
-    thetool.doBasicKinematicPlots = False
-    thetool.doFineEtaPhiPlots = True
-    thetool.doDetectorRegionPlots = True
-    thetool.DoAsymmErrorGraphs = False
-    thetool.doDileptonPlots = False
-    thetool.ApplyScaleFactors = applySF
-    ToolSvc+= thetool
-    return thetool
-
-# Add a tree filling tool
-def AddZmumuTPTreeTool (name, EffiFlag):
-    from AthenaCommon.AppMgr import ToolSvc
-    from MuonTPTools.MuonTPToolsConf import ZmumuMuonTPTreeTool
-    thetool = ZmumuMuonTPTreeTool(name)
-    thetool.EfficiencyFlag = EffiFlag
-    ToolSvc+= thetool
-    return thetool
-    
-
-# Add a TP selection tool
-def AddZmumuTPSelectionTool (name, EffiFlag, ProbeType, SameSign=False, AntiIso=False):
-
-    from AthenaCommon.AppMgr import ToolSvc
-    from MuonTPTools.MuonTPToolsConf import ZmumuMuonTPSelectionTool
-    thetool = ZmumuMuonTPSelectionTool(name)
-    
-    # Try to add the isolation updater tools (only works in full athena!)
-    if hasattr(ToolSvc, "MyTrackIsoTool"):
-        thetool.TrackIsolationTool = ToolSvc.MyTrackIsoTool
-        thetool.CaloIsolationTool = ToolSvc.MyCaloIsoTool
-    
-    # pt cuts
-    thetool.TagPtCut = 25000.
-    thetool.ProbePtCut = 10000.
-    # Z window
-    thetool.HighMassWindow = 101000.
-    thetool.LowMassWindow = 81000.
-    #thetool.OutputLevel=DEBUG      # this is a bit spammy
-    thetool.ProbeTrackIsoCut = -1.
-    
-    # Tag isolation 
-    thetool.TagTrackIsoCut = 0.2
-    thetool.TagCaloIsoCut = 0.2
-    thetool.TagTrackAntiIsoCut = -1
-    thetool.TagCaloAntiIsoCut = -1
-    
-    # Probe isolation: disabled by default - turned on below 
-    thetool.ProbeTrackIsoCut = -1
-    thetool.ProbeTrackAntiIsoCut = -1
-    thetool.ProbeCaloIsoCut = -1
-    thetool.ProbeCaloAntiIsoCut = -1
-    
-    # Tag IP cuts
-    thetool.TagD0Cut = -1
-    thetool.TagD0SignCut = 3
-    thetool.TagZ0Cut = 10
-    
-    # Probe IP cuts
-    thetool.ProbeD0Cut = -1
-    thetool.ProbeD0SignCut = 3
-    thetool.ProbeZ0Cut = 10
-    
-    thetool.EfficiencyFlag = EffiFlag
-    # tools  
-    thetool.SelectionTool = ToolSvc.TagProbeMuonSelectionTool
-    thetool.TriggerMatchTool = ToolSvc.TrigMuonMatching
-    thetool.TriggerDecisionTool = ToolSvc.TrigDecisionTool
-    # trigger(s)
-    thetool.TagTriggerList = ["HLT_mu26_imedium"]
-
-    if ProbeType == "ID":
-        thetool.UseIDProbes=True
-        thetool.ProbeIDHitCut=True
-        thetool.DeltaPhiCut=2.0
-        thetool.ProbeTrackIsoCut = 0.15    # try runing without probe iso!
-        thetool.ProbeCaloIsoCut = 0.25
-        #thetool.ProbeTrackIsoCut = -1
-        if AntiIso:
-            thetool.ProbeTrackIsoCut = -1
-            thetool.ProbeCaloIsoCut = -1
-            thetool.ProbeTrackAntiIsoCut = 1.2
-            thetool.ProbeCaloAntiIsoCut = 1.2
-            thetool.HighMassWindow = 121000.
-            thetool.LowMassWindow = 61000.
-            thetool.ProbeZ0Cut = -1
-            thetool.ProbeD0SignCut =-1
-            thetool.ProbeD0Cut =-1
-    if ProbeType == "MS":
-        thetool.ProbeIDHitCut=False
-        thetool.UseMSProbes = True
-        thetool.DeltaPhiCut=2.0
-        thetool.ProbeCaloIsoCut = 0.35    # try runing without probe iso!
-        thetool.ProbeD0Cut = -1
-        thetool.ProbeZ0Cut = -1
-        thetool.ProbeD0SignCut =-1
-        if AntiIso:
-            thetool.ProbeCaloIsoCut = -1
-            thetool.ProbeCaloAntiIsoCut = 1.2
-            thetool.HighMassWindow = 121000.
-            thetool.LowMassWindow = 61000.
-            thetool.ProbeZ0Cut = -1
-            thetool.ProbeD0SignCut =-1
-            thetool.ProbeD0Cut =-1
-            #thetool.TagTrackIsoCut = -1
-            #thetool.TagTrackAntiIsoCut = 1.4
-    if ProbeType == "CaloTag":
-        thetool.UseCaloProbes = True
-        thetool.ProbeIDHitCut=True
-        thetool.ProbeTrackIsoCut = 0.15    # try runing without probe iso!
-        #thetool.ProbeCaloIsoCut = 0.25
-        thetool.DeltaPhiCut=2.0
-        if AntiIso:
-            thetool.ProbeTrackIsoCut = -1
-            thetool.ProbeCaloIsoCut = -1
-            thetool.ProbeTrackAntiIsoCut = 1.2
-            thetool.ProbeCaloAntiIsoCut = 1.2
-            thetool.HighMassWindow = 121000.
-            thetool.LowMassWindow = 61000.
-            thetool.ProbeZ0Cut = -1
-            thetool.ProbeD0SignCut =-1
-            thetool.ProbeD0Cut =-1
-    if ProbeType == "Truth":
-        thetool.UseTruthProbes = True
-
-
-    if SameSign:
-        thetool.AcceptOppCharge=False
-        thetool.AcceptSameCharge=True
-
-    ToolSvc += thetool
-    return thetool
-
-# Add an efficiency tool
-def AddZmumuTPEfficiencyTool (name, EffiFlag):
-    from AthenaCommon.AppMgr import ToolSvc
-    from MuonTPTools.MuonTPToolsConf import MuonRecoTPEfficiencyTool
-    thetool = MuonRecoTPEfficiencyTool(name)
-    thetool.MuonAuthor = 21
-    thetool.MatchToAnyMS = False
-    thetool.MatchToCB = False
-    thetool.MatchToLoose = False
-    thetool.MatchToMedium = False
-    thetool.MatchToTight = False
-    thetool.MatchToID = False
-    thetool.MatchToCaloTag = False
-    thetool.MatchPtCut = 5000.0         # speed up the loop a bit
-    thetool.EfficiencyFlag = EffiFlag
-    thetool.SelectionTool = ToolSvc.TagProbeMuonSelectionTool
-    thetool.TriggerMatchTool = ToolSvc.TrigMuonMatching
-    ToolSvc += thetool
-    return thetool
-
-# Add an instance of the 'main' TP tool
-def AddZmumuTPTool (name, EffiFlag):
-
-    from AthenaCommon.AppMgr import ToolSvc
-    from MuonTPTools.MuonTPToolsConf import MuonTPTool
-    thetool = MuonTPTool(name)
-    thetool.EfficiencyFlag = EffiFlag
-    #thetool.OutputLevel = DEBUG
-    thetool.DumpInefficientEvents = True
-    ToolSvc += thetool
-    return thetool
-
-################################################################
-# Add a version of the Z TP algorithm and all associated tools
-################################################################
-def AddConfiguredZmumuTPAlg(name_suffix="myProbes",
-                            ProbeKind = "CaloTag", # options: "CaloTag","MS", "Truth", "ID"
-                            MatchContainer="Muons",
-                            doID=False,
-                            doCB = True, doLoose=True,
-                            doMedium=True,doTight=True,
-                            doStandalone=False, doCaloTag=False,
-                            doIndividualAuthors=False,
-                            doEtaSlices=False, writeNtuple=False,
-                            doClosure = False, doDRSys = False):
-
-
-    from AthenaCommon.AlgSequence import AlgSequence
-    from AthenaCommon.AppMgr import ToolSvc
-    job = AlgSequence()
-
-    MuonContainerToUse = "Muons"
-    #if hasattr(job, "MuonQualityUpdater"):
-        #MuonContainerToUse = "UpdatedMuons"
-
-    ProbeContainer=MuonContainerToUse
-
-    if ProbeKind == "MSTrackPart":
-        ProbeContainer = "ExtrapolatedMuonTrackParticles"
-        ProbeKind = "MS"
-        
-    if ProbeKind == "ID":
-        ProbeContainer = "InDetTrackParticles"
-    if ProbeKind == "Truth":
-        ProbeContainer = "MuonTruthParticles"
-
-    theAlg = AddZmumuTPAlg(name="ZmumuTPAlg_%s"%name_suffix,
-                           ProbeCont=ProbeContainer,
-                           MatchCont=MatchContainer)
-
-    AddMuonSelectionTool()
-
-
-    # add a plotting tool
-    #PlotTool = AddZmumuTPPlotTool(name="ZmumuTPPlottingTool_%s"%name_suffix,EffiFlag=name_suffix)
-
-    # add four TP selection tools (iso and antiiso OC and SC)
-    SelectionTools = []
-    SelectionTools += [AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OC_%s"%name_suffix,EffiFlag="%s_OC"%name_suffix, ProbeType = ProbeKind)]
-    SelectionTools += [AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SC_%s"%name_suffix,EffiFlag="%s_SC"%name_suffix, ProbeType = ProbeKind, SameSign=True)]
-    SelectionTools += [AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_OCAntiIso_%s"%name_suffix,EffiFlag="%s_OCAntiIso"%name_suffix, ProbeType = ProbeKind, AntiIso=True)]
-    SelectionTools += [AddZmumuTPSelectionTool(name="ZmumuTPSelectionTool_SCAntiIso_%s"%name_suffix,EffiFlag="%s_SCAntiIso"%name_suffix, ProbeType = ProbeKind, SameSign=True, AntiIso=True)]
-
-
-    PlotTools = []
-    # add plotting tools in slices
-    if doEtaSlices:
-        Slices = {
-                   "All" : (0.0,10.0),
-                   "noCrack" : (0.1,10.0),
-                   "Crack" : (0.0,0.1),
-                   "Barrel" : (0.1,1.1),
-                   "Transition" : (1.1, 1.3),
-                   "Endcap" : (1.3,2.0),
-                   "CSC" : (2.0,2.7)
-                   }
-
-        for etaslice, interval in Slices.iteritems():
-            PlotTool = AddZmumuTPPlotTool(name="ZmumuTPPlottingTool_%s_%s"%(name_suffix,etaslice),EffiFlag=name_suffix+"_"+etaslice,applySF = False)
-            PlotTool.ProbeAbsEtaMin = interval[0]
-            PlotTool.ProbeAbsEtaMax = interval[1]
-            PlotTools.append(PlotTool)
-            if doClosure:
-                PlotToolCL = AddZmumuTPPlotTool(name="ZmumuTPPlottingToolClosure_%s_%s"%(name_suffix,etaslice),EffiFlag=name_suffix+"_"+etaslice+"_Closure",applySF = True)
-                PlotToolCL.ProbeAbsEtaMin = interval[0]
-                PlotToolCL.ProbeAbsEtaMax = interval[1]
-                PlotTools.append(PlotToolCL)
-                
-    else:
-        PlotTools = [AddZmumuTPPlotTool(name="ZmumuTPPlottingTool_%s_All"%name_suffix,EffiFlag=name_suffix+"_All",applySF = False)]
-        if doClosure:
-            PlotTools.append(AddZmumuTPPlotTool(name="ZmumuTPPlottingToolClosure_%s_All"%name_suffix,EffiFlag=name_suffix+"_All_Closure",applySF = True))
-        
-
-    # add any desired matching tools
-
-    MATCH_DR = 0.05
-
-    
-    MatchingTools = []
-    if doCB:
-        thistoolCB = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_CB"%name_suffix,EffiFlag="CombinedMuons")
-        thistoolCB.MatchToCB = True
-        if not hasattr(ToolSvc, "EffiScaleFactors_CBMuons"):
-            ToolSvc+= CP__MuonEfficiencyScaleFactors("EffiScaleFactors_CBMuons")
-            ToolSvc.EffiScaleFactors_CBMuons.WorkingPoint = "CB"
-            ToolSvc.EffiScaleFactors_CBMuons.DataPeriod = "2012"
-        thistoolCB.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-        thistoolCB.ApplyScaleFactors = True
-        thistoolCB.MaximumDrCut = MATCH_DR
-        MatchingTools += [thistoolCB]
-        if doDRSys:
-            thistoolCB_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_CB_dRDown"%name_suffix,EffiFlag="CombinedMuons_dRDown")
-            thistoolCB_dRDown.MatchToCB = True
-            thistoolCB_dRDown.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-            thistoolCB_dRDown.ApplyScaleFactors = True
-            thistoolCB_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            MatchingTools += [thistoolCB_dRDown]
-            
-            thistoolCB_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_CB_dRUp"%name_suffix,EffiFlag="CombinedMuons_dRUp")
-            thistoolCB_dRUp.MatchToCB = True
-            thistoolCB_dRUp.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-            thistoolCB_dRUp.ApplyScaleFactors = True
-            thistoolCB_dRUp.MaximumDrCut = 2. * MATCH_DR
-            MatchingTools += [thistoolCB_dRUp]
-
-    if doLoose:
-        thistoolLoose = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Loose"%name_suffix,EffiFlag="LooseMuons")
-        thistoolLoose.MatchToLoose = True
-        if not hasattr(ToolSvc, "EffiScaleFactors_CBMuons"):
-            ToolSvc+= CP__MuonEfficiencyScaleFactors("EffiScaleFactors_CBMuons")
-            ToolSvc.EffiScaleFactors_CBMuons.WorkingPoint = "CB"
-            ToolSvc.EffiScaleFactors_CBMuons.DataPeriod = "2012"
-        thistoolLoose.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-        thistoolLoose.ApplyScaleFactors = True
-        thistoolLoose.MaximumDrCut = MATCH_DR
-        MatchingTools += [thistoolLoose]
-        if doDRSys:
-            thistoolLoose_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Loose_dRDown"%name_suffix,EffiFlag="LooseMuons_dRDown")
-            thistoolLoose_dRDown.MatchToLoose = True
-            thistoolLoose_dRDown.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-            thistoolLoose_dRDown.ApplyScaleFactors = True
-            thistoolLoose_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            MatchingTools += [thistoolLoose_dRDown]
-            
-            thistoolLoose_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Loose_dRUp"%name_suffix,EffiFlag="LooseMuons_dRUp")
-            thistoolLoose_dRUp.MatchToLoose = True
-            thistoolLoose_dRUp.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-            thistoolLoose_dRUp.ApplyScaleFactors = True
-            thistoolLoose_dRUp.MaximumDrCut = 2 * MATCH_DR
-            MatchingTools += [thistoolLoose_dRUp]
-            
-        # also run a version without CaloTag
-        thistoolLoose_noCaloTag = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Loose_noCaloTag"%name_suffix,EffiFlag="LooseMuons_noCaloTag")
-        thistoolLoose_noCaloTag.MatchToLoose_noCaloTag = True
-        if not hasattr(ToolSvc, "EffiScaleFactors_CBMuons"):
-            ToolSvc+= CP__MuonEfficiencyScaleFactors("EffiScaleFactors_CBMuons")
-            ToolSvc.EffiScaleFactors_CBMuons.WorkingPoint = "CB"
-            ToolSvc.EffiScaleFactors_CBMuons.DataPeriod = "2012"
-        thistoolLoose_noCaloTag.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-        thistoolLoose_noCaloTag.ApplyScaleFactors = True
-        thistoolLoose_noCaloTag.MaximumDrCut = MATCH_DR
-        MatchingTools += [thistoolLoose_noCaloTag]
-        if doDRSys:
-            thistoolLoose_noCaloTag_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Loose_noCaloTag_dRDown"%name_suffix,EffiFlag="LooseMuons_noCaloTag_dRDown")
-            thistoolLoose_noCaloTag_dRDown.MatchToLoose_noCaloTag = True
-            thistoolLoose_noCaloTag_dRDown.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-            thistoolLoose_noCaloTag_dRDown.ApplyScaleFactors = True
-            thistoolLoose_noCaloTag_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            MatchingTools += [thistoolLoose_noCaloTag_dRDown]
-            
-            thistoolLoose_noCaloTag_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Loose_noCaloTag_dRUp"%name_suffix,EffiFlag="LooseMuons_noCaloTag_dRUp")
-            thistoolLoose_noCaloTag_dRUp.MatchToLoose_noCaloTag = True
-            thistoolLoose_noCaloTag_dRUp.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-            thistoolLoose_noCaloTag_dRUp.ApplyScaleFactors = True
-            thistoolLoose_noCaloTag_dRUp.MaximumDrCut = 2 * MATCH_DR
-            MatchingTools += [thistoolLoose_noCaloTag_dRUp]
-        
-    if doMedium:
-        thistoolMed = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Medium"%name_suffix,EffiFlag="MediumMuons")
-        thistoolMed.MatchToMedium = True
-        if not hasattr(ToolSvc, "EffiScaleFactors_CBMuons"):
-            ToolSvc+= CP__MuonEfficiencyScaleFactors("EffiScaleFactors_CBMuons")
-            ToolSvc.EffiScaleFactors_CBMuons.WorkingPoint = "CB"
-            ToolSvc.EffiScaleFactors_CBMuons.DataPeriod = "2012"
-        thistoolMed.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-        thistoolMed.ApplyScaleFactors = True
-        thistoolMed.MaximumDrCut = MATCH_DR
-        MatchingTools += [thistoolMed]
-        if doDRSys:
-            thistoolMed_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Medium_dRDown"%name_suffix,EffiFlag="MediumMuons_dRDown")
-            thistoolMed_dRDown.MatchToMedium = True
-            thistoolMed_dRDown.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-            thistoolMed_dRDown.ApplyScaleFactors = True
-            thistoolMed_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            MatchingTools += [thistoolMed_dRDown]
-
-            thistoolMed_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Medium_dRUp"%name_suffix,EffiFlag="MediumMuons_dRUp")
-            thistoolMed_dRUp.MatchToMedium = True
-            thistoolMed_dRUp.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-            thistoolMed_dRUp.ApplyScaleFactors = True
-            thistoolMed_dRUp.MaximumDrCut = 0.010
-            MatchingTools += [thistoolMed_dRUp]
-
-        
-    if doTight:
-        thistoolTight = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Tight"%name_suffix,EffiFlag="TightMuons")
-        thistoolTight.MatchToTight = True
-        if not hasattr(ToolSvc, "EffiScaleFactors_CBMuons"):
-            ToolSvc+= CP__MuonEfficiencyScaleFactors("EffiScaleFactors_CBMuons")
-            ToolSvc.EffiScaleFactors_CBMuons.WorkingPoint = "CB"
-            ToolSvc.EffiScaleFactors_CBMuons.DataPeriod = "2012"
-        thistoolTight.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-        thistoolTight.ApplyScaleFactors = True
-        thistoolTight.MaximumDrCut = MATCH_DR
-        MatchingTools += [thistoolTight]
-        if doDRSys:
-            thistoolTight_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Tight_dRDown"%name_suffix,EffiFlag="TightMuons_dRDown")
-            thistoolTight_dRDown.MatchToTight = True
-            thistoolTight_dRDown.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-            thistoolTight_dRDown.ApplyScaleFactors = True
-            thistoolTight_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            MatchingTools += [thistoolTight_dRDown]
-            
-            thistoolTight_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_Tight_dRUp"%name_suffix,EffiFlag="TightMuons_dRUp")
-            thistoolTight_dRUp.MatchToTight = True
-            thistoolTight_dRUp.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-            thistoolTight_dRUp.ApplyScaleFactors = True
-            thistoolTight_dRUp.MaximumDrCut = 0.010
-            MatchingTools += [thistoolTight_dRUp]
-            
-
-    if doStandalone:
-        thistoolSA = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_SA"%name_suffix,EffiFlag="StandaloneMuons")
-        thistoolSA.MatchToAnyMS = True
-        thistoolSA.IDhitCut = False
-        thistoolSA.ApplyScaleFactors = False
-        thistoolSA.MaximumDrCut = MATCH_DR
-        MatchingTools += [thistoolSA]
-        if doDRSys:
-            thistoolSA_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_SA_dRDown"%name_suffix,EffiFlag="StandaloneMuons_dRDown")
-            thistoolSA_dRDown.MatchToAnyMS = True
-            thistoolSA_dRDown.IDhitCut = False
-            thistoolSA_dRDown.ApplyScaleFactors = False
-            thistoolSA_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            MatchingTools += [thistoolSA_dRDown]
-
-            thistoolSA_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_SA_dRUp"%name_suffix,EffiFlag="StandaloneMuons_dRUp")
-            thistoolSA_dRUp.MatchToAnyMS = True
-            thistoolSA_dRUp.IDhitCut = False
-            thistoolSA_dRUp.ApplyScaleFactors = False
-            thistoolSA_dRUp.MaximumDrCut = 2 * MATCH_DR
-            MatchingTools += [thistoolSA_dRUp]
-
-    if doCaloTag:
-        thistoolCT = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_CT"%name_suffix,EffiFlag="CaloTaggedMuons")
-        thistoolCT.MatchToCaloTag = True
-        if not hasattr(ToolSvc, "EffiScaleFactors_CBMuons"):
-            ToolSvc+= CP__MuonEfficiencyScaleFactors("EffiScaleFactors_CBMuons")
-            ToolSvc.EffiScaleFactors_CBMuons.WorkingPoint = "CB"
-            ToolSvc.EffiScaleFactors_CBMuons.DataPeriod = "2012"
-        thistoolCT.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-        thistoolCT.ApplyScaleFactors = True
-        thistoolCT.MaximumDrCut = MATCH_DR
-        MatchingTools += [thistoolCT]
-        if doDRSys:
-            thistoolCT_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_CT_dRDown"%name_suffix,EffiFlag="CaloTaggedMuons_dRDown")
-            thistoolCT_dRDown.MatchToCaloTag = True
-            thistoolCT_dRDown.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-            thistoolCT_dRDown.ApplyScaleFactors = True
-            thistoolCT_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            MatchingTools += [thistoolCT_dRDown]
-
-            thistoolCT_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_CT_dRUp"%name_suffix,EffiFlag="CaloTaggedMuons_dRUp")
-            thistoolCT_dRUp.MatchToCaloTag = True
-            thistoolCT_dRUp.ScaleFactorTool = ToolSvc.EffiScaleFactors_CBMuons
-            thistoolCT_dRUp.ApplyScaleFactors = True
-            thistoolCT_dRUp.MaximumDrCut = 2 * MATCH_DR
-            MatchingTools += [thistoolCT_dRUp]
-
-    if doID:
-        thistoolID = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_ID"%name_suffix,EffiFlag="IDTracks")
-        thistoolID.MatchToID = True
-        thistoolID.ApplyScaleFactors = False
-        thistoolID.MaximumDrCut = MATCH_DR
-        MatchingTools += [thistoolID]
-        if doDRSys:
-            thistoolID_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_ID_dRUp"%name_suffix,EffiFlag="IDTracks_dRUp")
-            thistoolID_dRUp.MatchToID = True
-            thistoolID_dRUp.ApplyScaleFactors = False
-            thistoolID_dRUp.MaximumDrCut = 2 * MATCH_DR
-            MatchingTools += [thistoolID_dRUp]
-
-            thistoolID_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_ID_dRDown"%name_suffix,EffiFlag="IDTracks_dRDown")
-            thistoolID_dRDown.MatchToID = True
-            thistoolID_dRDown.ApplyScaleFactors = False
-            thistoolID_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            MatchingTools += [thistoolID_dRDown]
-
-        thistoolID_noMCPcuts = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_ID_noMCP"%name_suffix,EffiFlag="IDTracks_noMCP")
-        thistoolID_noMCPcuts.MatchToID = True
-        thistoolID_noMCPcuts.IDhitCut = False
-        thistoolID_noMCPcuts.ApplyScaleFactors = False
-        thistoolID_noMCPcuts.MaximumDrCut = MATCH_DR
-        MatchingTools += [thistoolID_noMCPcuts]
-        if doDRSys:
-            thistoolID_noMCPcuts_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_ID_noMCP_dRUp"%name_suffix,EffiFlag="IDTracks_noMCP_dRUp")
-            thistoolID_noMCPcuts_dRUp.MatchToID = True
-            thistoolID_noMCPcuts_dRUp.ApplyScaleFactors = False
-            thistoolID_noMCPcuts_dRUp.MaximumDrCut = 2 * MATCH_DR
-            MatchingTools += [thistoolID_noMCPcuts_dRUp]
-
-            thistoolID_noMCPcuts_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_ID_noMCP_dRDown"%name_suffix,EffiFlag="IDTracks_noMCP_dRDown")
-            thistoolID_noMCPcuts_dRDown.MatchToID = True
-            thistoolID_noMCPcuts_dRDown.ApplyScaleFactors = False
-            thistoolID_noMCPcuts_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            MatchingTools += [thistoolID_noMCPcuts_dRDown]
-            
-
-
-    if doIndividualAuthors:
-        thistoolMuidCB = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidCB"%name_suffix,EffiFlag="MuidCB")
-        thistoolMuidCB.MatchToMuidCB = True
-        thistoolMuidCB.ApplyScaleFactors = False
-        thistoolMuidCB.MaximumDrCut = MATCH_DR
-        MatchingTools += [thistoolMuidCB]
-        if doDRSys:
-            thistoolMuidCB_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidCB_dRDown"%name_suffix,EffiFlag="MuidCB_dRDown")
-            thistoolMuidCB_dRDown.MatchToMuidCB = True
-            thistoolMuidCB_dRDown.ApplyScaleFactors = False
-            thistoolMuidCB_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            MatchingTools += [thistoolMuidCB_dRDown]
-
-            thistoolMuidCB_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidCB_dRUp"%name_suffix,EffiFlag="MuidCB_dRUp")
-            thistoolMuidCB_dRUp.MatchToMuidCB = True
-            thistoolMuidCB_dRUp.ApplyScaleFactors = False
-            thistoolMuidCB_dRUp.MaximumDrCut = 2 * MATCH_DR
-            MatchingTools += [thistoolMuidCB_dRUp]
-
-        thistoolSTACO = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_STACO"%name_suffix,EffiFlag="STACO")
-        thistoolSTACO.MatchToSTACO = True
-        thistoolSTACO.ApplyScaleFactors = False
-        thistoolSTACO.MaximumDrCut = MATCH_DR
-        MatchingTools += [thistoolSTACO]
-        if doDRSys:
-            thistoolSTACO_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_STACO_dRDown"%name_suffix,EffiFlag="STACO_dRDown")
-            thistoolSTACO_dRDown.MatchToSTACO = True
-            thistoolSTACO_dRDown.ApplyScaleFactors = False
-            thistoolSTACO_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            MatchingTools += [thistoolSTACO_dRDown]
-
-            thistoolSTACO_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_STACO_dRUp"%name_suffix,EffiFlag="STACO_dRUp")
-            thistoolSTACO_dRUp.MatchToSTACO = True
-            thistoolSTACO_dRUp.ApplyScaleFactors = False
-            thistoolSTACO_dRUp.MaximumDrCut = 2 * MATCH_DR
-            MatchingTools += [thistoolSTACO_dRUp]
-
-        thistoolMuTag = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuTag"%name_suffix,EffiFlag="MuTag")
-        thistoolMuTag.MatchToMuTag = True
-        thistoolMuTag.ApplyScaleFactors = False
-        thistoolMuTag.MaximumDrCut = MATCH_DR
-        MatchingTools += [thistoolMuTag]
-        if doDRSys:
-            thistoolMuTag_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuTag_dRDown"%name_suffix,EffiFlag="MuTag_dRDown")
-            thistoolMuTag_dRDown.MatchToMuTag = True
-            thistoolMuTag_dRDown.ApplyScaleFactors = False
-            thistoolMuTag_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            MatchingTools += [thistoolMuTag_dRDown]
-
-            thistoolMuTag_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuTag_dRUp"%name_suffix,EffiFlag="MuTag_dRUp")
-            thistoolMuTag_dRUp.MatchToMuTag = True
-            thistoolMuTag_dRUp.ApplyScaleFactors = False
-            thistoolMuTag_dRUp.MaximumDrCut = 2 * MATCH_DR
-            MatchingTools += [thistoolMuTag_dRUp]
-
-        thistoolMuTagIMO = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuTagIMO"%name_suffix,EffiFlag="MuTagIMO")
-        thistoolMuTagIMO.MatchToMuTagIMO = True
-        thistoolMuTagIMO.ApplyScaleFactors = False
-        thistoolMuTagIMO.MaximumDrCut = MATCH_DR
-        MatchingTools += [thistoolMuTagIMO]
-        if doDRSys:
-            thistoolMuTagIMO_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuTagIMO_dRDown"%name_suffix,EffiFlag="MuTagIMO_dRDown")
-            thistoolMuTagIMO_dRDown.MatchToMuTagIMO = True
-            thistoolMuTagIMO_dRDown.ApplyScaleFactors = False
-            thistoolMuTagIMO_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            MatchingTools += [thistoolMuTagIMO_dRDown]
-
-            thistoolMuTagIMO_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuTagIMO_dRUp"%name_suffix,EffiFlag="MuTagIMO_dRUp")
-            thistoolMuTagIMO_dRUp.MatchToMuTagIMO = True
-            thistoolMuTagIMO_dRUp.ApplyScaleFactors = False
-            thistoolMuTagIMO_dRUp.MaximumDrCut = 2 * MATCH_DR
-            MatchingTools += [thistoolMuTagIMO_dRUp]
-
-        thistoolMuidSA = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidSA"%name_suffix,EffiFlag="MuidSA")
-        thistoolMuidSA.MatchToMuidSA = True
-        thistoolMuidSA.ApplyScaleFactors = False
-        thistoolMuidSA.IDhitCut = False
-        thistoolMuidSA.MaximumDrCut = MATCH_DR
-        MatchingTools += [thistoolMuidSA]
-        if doDRSys:
-            thistoolMuidSA_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidSA_dRDown"%name_suffix,EffiFlag="MuidSA_dRDown")
-            thistoolMuidSA_dRDown.MatchToMuidSA = True
-            thistoolMuidSA_dRDown.ApplyScaleFactors = False
-            thistoolMuidSA_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            MatchingTools += [thistoolMuidSA_dRDown]
-
-            thistoolMuidSA_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidSA_dRUp"%name_suffix,EffiFlag="MuidSA_dRUp")
-            thistoolMuidSA_dRUp.MatchToMuidSA = True
-            thistoolMuidSA_dRUp.ApplyScaleFactors = False
-            thistoolMuidSA_dRUp.MaximumDrCut = 2 * MATCH_DR
-            MatchingTools += [thistoolMuidSA_dRUp]
-
-        thistoolMuGirl = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidGirl"%name_suffix,EffiFlag="MuGirl")
-        thistoolMuGirl.MatchToMuGirl = True
-        thistoolMuGirl.ApplyScaleFactors = False
-        thistoolMuGirl.MaximumDrCut = MATCH_DR
-        MatchingTools += [thistoolMuGirl]
-        if doDRSys:
-            thistoolMuGirl_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidGirl_dRDown"%name_suffix,EffiFlag="MuGirl_dRDown")
-            thistoolMuGirl_dRDown.MatchToMuGirl = True
-            thistoolMuGirl_dRDown.ApplyScaleFactors = False
-            thistoolMuGirl_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            MatchingTools += [thistoolMuGirl_dRDown]
-
-            thistoolMuGirl_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidGirl_dRUp"%name_suffix,EffiFlag="MuGirl_dRUp")
-            thistoolMuGirl_dRUp.MatchToMuGirl = True
-            thistoolMuGirl_dRUp.ApplyScaleFactors = False
-            thistoolMuGirl_dRUp.MaximumDrCut = 2 * MATCH_DR
-            MatchingTools += [thistoolMuGirl_dRUp]
-
-        #thistoolMuGirlLowBeta = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidGirlLowBeta"%name_suffix,EffiFlag="MuGirlLowBeta")
-        #thistoolMuGirlLowBeta.MatchToMuGirlLowBeta = True
-        #thistoolMuGirlLowBeta.ApplyScaleFactors = False
-        #thistoolMuGirlLowBeta.MaximumDrCut = MATCH_DR
-        #MatchingTools += [thistoolMuGirlLowBeta]
-        #if doDRSys:
-            #thistoolMuGirlLowBeta_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidGirlLowBeta_dRDown"%name_suffix,EffiFlag="MuGirlLowBeta_dRDown")
-            #thistoolMuGirlLowBeta_dRDown.MatchToMuGirlLowBeta = True
-            #thistoolMuGirlLowBeta_dRDown.ApplyScaleFactors = False
-            #thistoolMuGirlLowBeta_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            #MatchingTools += [thistoolMuGirlLowBeta_dRDown]
-
-            #thistoolMuGirlLowBeta_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_MuidGirlLowBeta_dRUp"%name_suffix,EffiFlag="MuGirlLowBeta_dRUp")
-            #thistoolMuGirlLowBeta_dRUp.MatchToMuGirlLowBeta = True
-            #thistoolMuGirlLowBeta_dRUp.ApplyScaleFactors = False
-            #thistoolMuGirlLowBeta_dRUp.MaximumDrCut = 2 * MATCH_DR
-            #MatchingTools += [thistoolMuGirlLowBeta_dRUp]
-
-        #thistoolCaloLikelihood = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_CaloLR"%name_suffix,EffiFlag="CaloLikelihood")
-        #thistoolCaloLikelihood.MatchToCaloLikelihood = True
-        #thistoolCaloLikelihood.ApplyScaleFactors = False
-        #thistoolCaloLikelihood.MaximumDrCut = MATCH_DR
-        #MatchingTools += [thistoolCaloLikelihood]
-        #if doDRSys:
-            #thistoolCaloLikelihood_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_CaloLR_dRDown"%name_suffix,EffiFlag="CaloLikelihood_dRDown")
-            #thistoolCaloLikelihood_dRDown.MatchToCaloLikelihood = True
-            #thistoolCaloLikelihood_dRDown.ApplyScaleFactors = False
-            #thistoolCaloLikelihood_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            #MatchingTools += [thistoolCaloLikelihood_dRDown]
-
-            #thistoolCaloLikelihood_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_CaloLR_dRUp"%name_suffix,EffiFlag="CaloLikelihood_dRUp")
-            #thistoolCaloLikelihood_dRUp.MatchToCaloLikelihood = True
-            #thistoolCaloLikelihood_dRUp.ApplyScaleFactors = False
-            #thistoolCaloLikelihood_dRUp.MaximumDrCut = 2 * MATCH_DR
-            #MatchingTools += [thistoolCaloLikelihood_dRUp]
-
-        #thistoolExtrapolateToIP = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_ExtrapIP"%name_suffix,EffiFlag="ExtrapolateToIP")
-        #thistoolExtrapolateToIP.MatchToExtrapolateToIP = True
-        #thistoolExtrapolateToIP.ApplyScaleFactors = False
-        #thistoolExtrapolateToIP.IDhitCut = False
-        #thistoolExtrapolateToIP.MaximumDrCut = MATCH_DR
-        #MatchingTools += [thistoolExtrapolateToIP]
-        #if doDRSys:
-            #thistoolExtrapolateToIP_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_ExtrapIP_dRDown"%name_suffix,EffiFlag="ExtrapolateToIP_dRDown")
-            #thistoolExtrapolateToIP_dRDown.MatchToExtrapolateToIP = True
-            #thistoolExtrapolateToIP_dRDown.ApplyScaleFactors = False
-            #thistoolExtrapolateToIP_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            #MatchingTools += [thistoolExtrapolateToIP_dRDown]
-
-            #thistoolExtrapolateToIP_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPEfficiencyTool_%s_ExtrapIP_dRUp"%name_suffix,EffiFlag="ExtrapolateToIP_dRUp")
-            #thistoolExtrapolateToIP_dRUp.MatchToExtrapolateToIP = True
-            #thistoolExtrapolateToIP_dRUp.ApplyScaleFactors = False
-            #thistoolExtrapolateToIP_dRUp.MaximumDrCut = 2 * MATCH_DR
-            #MatchingTools += [thistoolExtrapolateToIP_dRUp]
-            
-            
-    ntuples = []
-    if writeNtuple:
-        ntuples.append(AddZmumuTPTreeTool(name="ZmumuTPTreeTool_%s"%name_suffix, EffiFlag="Trees"))
-
-    # create the TP tool itself
-    TheTPTool = AddZmumuTPTool(name = "ZmumuTPTool_%s"%name_suffix,EffiFlag=name_suffix)
-    TheTPTool.MuonTPSelectionTools = SelectionTools
-    TheTPTool.PlottingTools = PlotTools
-    TheTPTool.MuonTPEfficiencyTools = MatchingTools
-    TheTPTool.TreeTools = ntuples
-    theAlg.MuonTPTools += [TheTPTool]
-
-
-def AddZmumuTPAnalysis(doEtaSlices=False,writeNtuple=False,doClosure=False,doDRSys=False, doValid=False):
-
-
-    from AthenaCommon.AlgSequence import AlgSequence
-    from AthenaCommon.AppMgr import ToolSvc
-    job = AlgSequence()
-
-    MuonContainerToUse = "Muons"
-    #if hasattr(job, "MuonQualityUpdater"):
-        #MuonContainerToUse = "UpdatedMuons"
-
-
-    ##########################################################################################
-    # Add the Zmm TP algorithm using ID tracks as probes and matching to muons
-    AddConfiguredZmumuTPAlg(name_suffix = "IDProbes",
-                            ProbeKind = "ID",
-                            MatchContainer = MuonContainerToUse,
-                            doID = False, doCB = True, doLoose=True, doMedium = True,
-                            doTight=False, doStandalone = False, doCaloTag = True, doIndividualAuthors = doValid,
-                            doEtaSlices=doEtaSlices, writeNtuple = writeNtuple,doClosure=doClosure, doDRSys = doDRSys)
-
-
-    #########################################################################################
-    #Add the Zmm TP algorithm using CaloTag muons as probes and matching to muons
-    AddConfiguredZmumuTPAlg(name_suffix = "CaloProbes",
-                            ProbeKind = "CaloTag",
-                            MatchContainer = MuonContainerToUse,
-                            doID = False, doCB = True, doLoose=True, doMedium = True,
-                            doTight=False,
-                            doStandalone = False, doCaloTag = False, doIndividualAuthors = doValid,
-                            doEtaSlices=doEtaSlices, writeNtuple = writeNtuple,doClosure=doClosure, doDRSys = doDRSys)
-
-
-    ##########################################################################################
-    # Add the Zmm TP algorithm using MS muons as probes and matching to ID tracks
-   # AddConfiguredZmumuTPAlg(name_suffix = "MSTrackPartProbes_ID",
-   #                         ProbeKind = "MSTrackPart",
-   #                         MatchContainer = "InDetTrackParticles",
-   #                         doID = True, doCB = False, doLoose=False, doMedium = False,
-   #                         doTight=False,
-   #                         doStandalone = False, doCaloTag = False,
-   #                         doEtaSlices=doEtaSlices, writeNtuple = writeNtuple,doClosure=doClosure, doDRSys = doDRSys)
-
-
-    ##########################################################################################
-    # Add the Zmm TP algorithm using MS muons as probes and matching to ID tracks
-    AddConfiguredZmumuTPAlg(name_suffix = "MSProbes_ID",
-                            ProbeKind = "MS",
-                            MatchContainer = "InDetTrackParticles",
-                            doID = True, doCB = False, doLoose=False, doMedium = False,
-                            doTight=False,
-                            doStandalone = False, doCaloTag = False, doIndividualAuthors = False,
-                            doEtaSlices=doEtaSlices, writeNtuple = writeNtuple,doClosure=doClosure, doDRSys = doDRSys)
-
-
-    ##########################################################################################
-    # Add the Zmm TP algorithm using MS muons as probes and matching to CaloTag muons
-    AddConfiguredZmumuTPAlg(name_suffix = "MSProbes_Muon",
-                            ProbeKind = "MS",
-                            MatchContainer = MuonContainerToUse,
-                            doID = False, doCB = False, doLoose=False, doMedium = False,
-                            doTight=False,
-                            doStandalone = False, doCaloTag = True, doIndividualAuthors = False,
-                            doEtaSlices=doEtaSlices, writeNtuple = writeNtuple,doClosure=doClosure, doDRSys = doDRSys)
-
-    ##########################################################################################
-    # Add the Zmm TP algorithm using Truth probes for Muons
-    AddConfiguredZmumuTPAlg(name_suffix = "TruthProbes_Muon",
-                            ProbeKind = "Truth",
-                            MatchContainer = MuonContainerToUse,
-                            doID = False, doCB = True, doLoose=True, doMedium = True,
-                            doTight=False,
-                            doStandalone = False, doCaloTag = True, doIndividualAuthors = doValid,
-                            doEtaSlices=doEtaSlices, writeNtuple = writeNtuple,doClosure=doClosure, doDRSys = doDRSys)
-
-    ##########################################################################################
-    # Add the Zmm TP algorithm using Truth probes for Tracks
-    AddConfiguredZmumuTPAlg(name_suffix = "TruthProbes_ID",
-                            ProbeKind = "Truth",
-                            MatchContainer = "InDetTrackParticles",
-                            doID = True, doCB = False, doLoose=False, doMedium = False,
-                            doTight=False,
-                            doStandalone = False, doCaloTag = False, doIndividualAuthors = False,
-                            doEtaSlices=doEtaSlices, writeNtuple = writeNtuple,doClosure=doClosure, doDRSys = doDRSys)
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/ZmumuTPIsolationAnalysis.py b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/ZmumuTPIsolationAnalysis.py
deleted file mode 100644
index 76d907b8be1..00000000000
--- a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/ZmumuTPIsolationAnalysis.py
+++ /dev/null
@@ -1,241 +0,0 @@
-
-
-# Add instance of the TP plotting tool
-def AddZmumuTPIsolationPlotTool(name, EffiFlag, applySF=False):
-
-    from AthenaCommon.AppMgr import ToolSvc
-    from MuonTPTools.MuonTPToolsConf import ZmumuMuonTPPlotTool
-    thetool = ZmumuMuonTPPlotTool(name)
-    thetool.EfficiencyFlag = EffiFlag
-    thetool.doTrkValidPlots = False
-    thetool.doBasicKinematicPlots = True
-    thetool.doFineEtaPhiPlots = True
-    thetool.DoAsymmErrorGraphs = True
-    thetool.doDileptonPlots = True
-    thetool.ApplyScaleFactors = applySF
-    ToolSvc+= thetool
-    return thetool
-
-# Add a tree filling tool
-def AddZmumuTPIsolationTreeTool (name, EffiFlag):
-    from AthenaCommon.AppMgr import ToolSvc
-    from MuonTPTools.MuonTPToolsConf import ZmumuMuonTPIsolationTreeTool
-    thetool = ZmumuMuonTPIsolationTreeTool(name)
-    thetool.EfficiencyFlag = EffiFlag
-    ToolSvc+= thetool
-    return thetool
-    
-
-# Add a TP selection tool
-def AddZmumuTPIsolationSelectionTool (name, EffiFlag, ProbeType, SameSign=False, AntiIso=False):
-
-    from AthenaCommon.AppMgr import ToolSvc
-    from MuonTPTools.MuonTPToolsConf import ZmumuMuonTPSelectionTool
-    thetool = ZmumuMuonTPSelectionTool(name)
-    
-    if hasattr(ToolSvc, "MyTrackIsoTool"):
-        thetool.TrackIsolationTool = ToolSvc.MyTrackIsoTool
-        thetool.CaloIsolationTool = ToolSvc.MyCaloIsoTool
-        
-    # pt cuts
-    thetool.TagPtCut = 25000.
-    thetool.ProbePtCut = 10000.
-    # Z window
-    thetool.HighMassWindow = 101000.
-    thetool.LowMassWindow = 81000.
-    #thetool.OutputLevel=DEBUG      # this is a bit spammy
-    thetool.ProbeTrackIsoCut = -1.
-    
-    # Tag isolation 
-    thetool.TagTrackIsoCut = 0.2
-    thetool.TagCaloIsoCut = 0.2
-    thetool.TagTrackAntiIsoCut = -1
-    thetool.TagCaloAntiIsoCut = -1
-    
-    # Probe isolation: disabled for isolation studies
-    thetool.ProbeTrackIsoCut = -1
-    thetool.ProbeTrackAntiIsoCut = -1
-    thetool.ProbeCaloIsoCut = -1
-    thetool.ProbeCaloAntiIsoCut = -1
-    
-    # Tag IP cuts
-    thetool.TagD0Cut = -1
-    thetool.TagD0SignCut = 3
-    thetool.TagZ0Cut = 10
-    
-    # Probe IP cuts
-    thetool.ProbeD0Cut = -1
-    thetool.ProbeD0SignCut = 3
-    thetool.ProbeZ0Cut = 10
-    
-    thetool.EfficiencyFlag = EffiFlag
-    # tools  
-    thetool.SelectionTool = ToolSvc.TagProbeMuonSelectionTool
-    thetool.TriggerMatchTool = ToolSvc.TrigMuonMatching
-    thetool.TriggerDecisionTool = ToolSvc.TrigDecisionTool
-    # trigger(s)
-    thetool.TagTriggerList = ["HLT_mu26_imedium"]
-    
-    # Tag IP cuts
-    thetool.TagD0Cut = -1
-    thetool.TagD0SignCut = 3
-    thetool.TagZ0Cut = 10
-    
-    # Probe IP cuts
-    thetool.ProbeD0Cut = -1
-    thetool.ProbeD0SignCut = 3
-    thetool.ProbeZ0Cut = 10
-    
-    thetool.EfficiencyFlag = EffiFlag
-    # tools  
-    thetool.SelectionTool = ToolSvc.TagProbeMuonSelectionTool
-    thetool.TriggerMatchTool = ToolSvc.TrigMuonMatching
-    thetool.TriggerDecisionTool = ToolSvc.TrigDecisionTool
-    # trigger(s)
-    thetool.TagTriggerList = ["HLT_mu26_imedium"]
-
-    if ProbeType == "Truth":
-        thetool.UseTruthProbes = True
-    if ProbeType == "CB":
-        thetool.UseCBProbes = True
-
-    if SameSign:
-        thetool.AcceptOppCharge=False
-        thetool.AcceptSameCharge=True
-
-    ToolSvc += thetool
-    return thetool
-
-
-    
-################################################################
-# Add a version of the Z TP algorithm and all associated tools
-################################################################
-def AddConfiguredZmumuTPIsolationAlg(name_suffix="myProbes",
-                            ProbeKind = "CB", # options: "CaloTag","MS", "Truth", "ID"
-                            MatchContainer="Muons",
-                            doEtaSlices=False, writeNtuple=False,
-                            doClosure = False, doDRSys = False):
-
-
-    from AthenaCommon.AlgSequence import AlgSequence
-    from AthenaCommon.AppMgr import ToolSvc
-    job = AlgSequence()
-
-    MuonContainerToUse = "Muons"
-
-    ProbeContainer=MuonContainerToUse
-
-    theAlg = AddZmumuTPAlg(name="ZmumuTPIsolationAlg_%s"%name_suffix,
-                           ProbeCont=ProbeContainer,
-                           MatchCont=MatchContainer)
-
-    AddMuonSelectionTool()
-
-    # add two TP selection tools ( OC and SC)
-    SelectionTools = []
-    SelectionTools += [AddZmumuTPIsolationSelectionTool(name="ZmumuTPIsolationSelectionTool_OC_%s"%name_suffix,EffiFlag="Isolation", ProbeType = ProbeKind)]
-    SelectionTools += [AddZmumuTPIsolationSelectionTool(name="ZmumuTPIsolationSelectionTool_SC_%s"%name_suffix,EffiFlag="Isolation_SC", ProbeType = ProbeKind, SameSign=True)]
-
-
-    PlotTools = []
-    # add plotting tools in slices
-    if doEtaSlices:
-        Slices = {
-                   "All" : (0.0,10.0),
-                   "noCrack" : (0.1,10.0),
-                   "Crack" : (0.0,0.1),
-                   "Barrel" : (0.1,1.1),
-                   "Transition" : (1.1, 1.3),
-                   "Endcap" : (1.3,2.0),
-                   "CSC" : (2.0,2.7)
-                   }
-
-        for etaslice, interval in Slices.iteritems():
-            PlotTool = AddZmumuTPIsolationPlotToo(name="ZmumuTPIsoPlottingTool_%s_%s"%(name_suffix,etaslice),EffiFlag=name_suffix+"_"+etaslice,applySF = False)
-            PlotTool.ProbeAbsEtaMin = interval[0]
-            PlotTool.ProbeAbsEtaMax = interval[1]
-            PlotTools.append(PlotTool)
-            if doClosure:
-                PlotToolCL = AddZmumuTPIsolationPlotTool(name="ZmumuTPIsoPlottingToolClosure_%s_%s"%(name_suffix,etaslice),EffiFlag=name_suffix+"_"+etaslice+"_Closure",applySF = True)
-                PlotToolCL.ProbeAbsEtaMin = interval[0]
-                PlotToolCL.ProbeAbsEtaMax = interval[1]
-                PlotTools.append(PlotToolCL)
-                
-    else:
-        PlotTools = [AddZmumuTPIsolationPlotTool(name="ZmumuTPIsoPlottingTool_%s_All"%name_suffix,EffiFlag=name_suffix+"_All",applySF = False)]
-        if doClosure:
-            PlotTools.append(AddZmumuTPIsolationPlotTool(name="ZmumuTPIsoPlottingToolClosure_%s_All"%name_suffix,EffiFlag=name_suffix+"_All_Closure",applySF = True))
-        
-
-    # add any desired matching tools
-
-    MATCH_DR = 0.05
-
-    
-    MatchingTools = []
-    thistool = AddZmumuTPEfficiencyTool(name="ZmumuTPIsoEfficiencyTool_%s_CB"%name_suffix,EffiFlag="Isolation")
-    if ProbeKind == "CB":
-        thistool.MatchToCB = True
-    if ProbeKind == "Loose":
-        thistool.MatchToLoose = True
-    if ProbeKind == "Medium":
-        thistool.MatchToMedium = True
-    thistool.ApplyScaleFactors = False
-    thistool.MaximumDrCut = MATCH_DR
-    MatchingTools += [thistool]
-    if doDRSys:
-        thistool_dRDown = AddZmumuTPEfficiencyTool(name="ZmumuTPIsoEfficiencyTool_%s_CB_dRDown"%name_suffix,EffiFlag="Isolation_dRDown")
-        if ProbeKind == "CB":
-            thistool_dRDown.MatchToCB = True
-        if ProbeKind == "Loose":
-            thistool_dRDown.MatchToLoose = True
-        if ProbeKind == "Medium":
-            thistool_dRDown.MatchToMedium = True
-        thistool_dRDown.ApplyScaleFactors = False
-        thistool_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-        MatchingTools += [thistool_dRDown]
-        
-        thistool_dRUp = AddZmumuTPEfficiencyTool(name="ZmumuTPIsoEfficiencyTool_%s_CB_dRUp"%name_suffix,EffiFlag="Isolation_dRUp")
-        if ProbeKind == "CB":
-            thistool_dRUp.MatchToCB = True
-        if ProbeKind == "Loose":
-            thistool_dRUp.MatchToLoose = True
-        if ProbeKind == "Medium":
-            thistool_dRUp.MatchToMedium = True
-        thistool_dRUp.ApplyScaleFactors = False
-        thistool_dRUp.MaximumDrCut = 2. * MATCH_DR
-        MatchingTools += [thistool_dRUp]
-
-    
-
-    ntuples = []
-    if writeNtuple:
-        ntuples.append(AddZmumuTPIsolationTreeTool(name="ZmumuTPIsoTreeTool_%s"%name_suffix, EffiFlag="Trees"))
-
-    # create the TP tool itself
-    TheTPTool = AddZmumuTPTool(name = "ZmumuTPTool_%s"%name_suffix,EffiFlag=name_suffix)
-    TheTPTool.MuonTPSelectionTools = SelectionTools
-    TheTPTool.PlottingTools = PlotTools
-    TheTPTool.MuonTPEfficiencyTools = MatchingTools
-    TheTPTool.TreeTools = ntuples
-    theAlg.MuonTPTools += [TheTPTool]
-
-
-def AddZmumuTPIsolationAnalysis(doEtaSlices=False,writeNtuple=False,doClosure=False,doDRSys=False):
-
-
-    from AthenaCommon.AlgSequence import AlgSequence
-    from AthenaCommon.AppMgr import ToolSvc
-    job = AlgSequence()
-
-    MuonContainerToUse = "Muons"
-    #if hasattr(job, "MuonQualityUpdater"):
-        #MuonContainerToUse = "UpdatedMuons"
-
-    ##########################################################################################
-    # Add the Zmm TP algorithm using Combined muons as probes and matching to ID tracks
-    AddConfiguredZmumuTPIsolationAlg(name_suffix = "CBProbes",
-                            ProbeKind = "CB",
-                            MatchContainer = MuonContainerToUse,
-                            doEtaSlices=doEtaSlices, writeNtuple = writeNtuple,doClosure=doClosure, doDRSys = doDRSys)
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/ZmumuTPTrigAnalysis.py b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/ZmumuTPTrigAnalysis.py
deleted file mode 100644
index 0a9f3b98685..00000000000
--- a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/ZmumuTPTrigAnalysis.py
+++ /dev/null
@@ -1,337 +0,0 @@
-
-from AthenaCommon.AlgSequence import AlgSequence
-from AthenaCommon.AppMgr import ToolSvc
-
-job = AlgSequence()
-
-from MuonEfficiencyCorrections.MuonEfficiencyCorrectionsConf import CP__MuonEfficiencyScaleFactors
-
-# ============================================================
-# Add instance of the TP plotting tool
-def AddTriggerTPPlotTool(name, EffiFlag, applySF=False):
-    from AthenaCommon.AppMgr import ToolSvc
-    from MuonTPTools.MuonTPToolsConf import  MuonTrigTPPlotTool
-    thetool = MuonTrigTPPlotTool(name)
-    thetool.EfficiencyFlag        = EffiFlag
-    thetool.doTrkValidPlots       = False
-    thetool.doBasicKinematicPlots = True
-    thetool.ApplyScaleFactors     = applySF
-    thetool.DoAsymmErrorGraphs    = True
-    ToolSvc+= thetool
-    return thetool
-
-# ============================================================
-# Add a tree filling tool
-def AddTriggerTPTreeTool (name, EffiFlag):
-    from AthenaCommon.AppMgr import ToolSvc
-    from MuonTPTools.MuonTPToolsConf import MuonTrigTPTreeTool
-    thetool = MuonTrigTPTreeTool(name)
-    thetool.EfficiencyFlag = EffiFlag
-    ToolSvc+= thetool
-    return thetool
-
-# ============================================================
-def AddTriggerTPSelectionTool (name, EffiFlag, SameSign=False, AntiIso=False):
-    from AthenaCommon.AppMgr import ToolSvc
-    from MuonTPTools.MuonTPToolsConf import ZmumuMuonTPSelectionTool
-    thetool = ZmumuMuonTPSelectionTool(name)
-    
-    if hasattr(ToolSvc, "MyTrackIsoTool"):
-        thetool.TrackIsolationTool = ToolSvc.MyTrackIsoTool
-        thetool.CaloIsolationTool = ToolSvc.MyCaloIsoTool
-        
-    # pt cuts
-    thetool.TagPtCut       = 25000.
-    thetool.ProbePtCut     =  5000.
-    # Z window 
-    thetool.HighMassWindow = 101000.
-    thetool.LowMassWindow  = 81000.
-    #thetool.OutputLevel   = DEBUG      # this is a bit spammy
-    thetool.ProbeTrackIsoCut = -1.
-    
-    # Tag isolation 
-    thetool.TagTrackIsoCut     = 0.2
-    thetool.TagCaloIsoCut      = 0.2
-    thetool.TagTrackAntiIsoCut = -1
-    thetool.TagCaloAntiIsoCut  = -1
-    
-    # Probe isolation: disabled by default - turned on below 
-    thetool.ProbeTrackIsoCut     = -1
-    thetool.ProbeTrackAntiIsoCut = -1
-    thetool.ProbeCaloIsoCut      = -1
-    thetool.ProbeCaloAntiIsoCut  = -1
-    
-    # Tag IP cuts
-    thetool.TagD0Cut       = -1
-    thetool.TagD0SignCut   = 3
-    thetool.TagZ0Cut       = 10
-    
-    # Probe IP cuts
-    thetool.ProbeD0Cut     = -1
-    thetool.ProbeD0SignCut = 3
-    thetool.ProbeZ0Cut     = 10
-    
-    thetool.EfficiencyFlag = EffiFlag
-    # tools  
-    thetool.SelectionTool = ToolSvc.TagProbeMuonSelectionTool
-    thetool.TriggerMatchTool = ToolSvc.TrigMuonMatching
-    thetool.TriggerDecisionTool = ToolSvc.TrigDecisionTool
-    # trigger(s)
-    thetool.TagTriggerList = [
-        "HLT_mu26_imedium"
-        ]
-
-    thetool.UseCBProbes      = True
-    thetool.ProbeIDHitCut    = True
-    thetool.ProbeTrackIsoCut = 0.35
-    thetool.ProbeCaloIsoCut  = -1
-    thetool.DeltaPhiCut      = 2.0
-    if AntiIso:
-        thetool.ProbeTrackIsoCut = -1
-        thetool.ProbeCaloIsoCut = -1
-        thetool.ProbeTrackAntiIsoCut = 1.2
-        thetool.ProbeCaloAntiIsoCut = 1.2
-        thetool.HighMassWindow = 121000.
-        thetool.LowMassWindow = 61000.
-        thetool.ProbeZ0Cut = -1
-        thetool.ProbeD0SignCut =-1
-        thetool.ProbeD0Cut =-1
-        
-    if SameSign:
-        thetool.AcceptOppCharge=False
-        thetool.AcceptSameCharge=True
-
-    ToolSvc += thetool
-    return thetool
-
-# ============================================================
-# Add an efficiency tool
-def AddTriggerTPEfficiencyTool (name, EffiFlag):
-    from AthenaCommon.AppMgr import ToolSvc
-    from MuonTPTools.MuonTPToolsConf import MuonTrigTPEfficiencyTool
-    thetool = MuonTrigTPEfficiencyTool(name)
-    thetool.MuonAuthor       = 21
-    thetool.MatchPtCut       = 5000.0         # speed up the loop a bit
-    thetool.EfficiencyFlag   = EffiFlag
-    thetool.SelectionTool    = ToolSvc.TagProbeMuonSelectionTool
-    thetool.TriggerMatchTool = ToolSvc.TrigMuonMatching
-    ToolSvc += thetool
-    return thetool
-
-
-# ============================================================
-################################################################
-# Add a version of the Z TP algorithm and all associated tools
-################################################################
-def AddConfiguredTriggerTPAlg(name_suffix="Trigger",
-                            MatchContainer="Muons",
-                            TriggerList_L1 = [], TriggerList_L2 = [], TriggerList_EF = [], TriggerList_HLT=[],
-                            doEtaSlices = True, 
-                            writeNtuple = False,
-                            doClosure   = False,
-                            doDRSys     = False
-			    ):
-    from AthenaCommon.AlgSequence import AlgSequence
-    from AthenaCommon.AppMgr import ToolSvc
-    job = AlgSequence()
-
-    MuonContainerToUse = "Muons"
-    if hasattr(job, "MuonQualityUpdater"):
-        MuonContainerToUse = "UpdatedMuons"
-
-    ProbeContainer = MuonContainerToUse
-    theAlg = AddZmumuTPAlg(name="ZmumuTPAlg_%s"%name_suffix,
-                           ProbeCont=ProbeContainer,
-                           MatchCont=MatchContainer)
-
-    AddMuonSelectionTool()
-
-    # add two TP selection tools (OC and SC)
-    SelectionTools = []
-    SelectionTools += [AddTriggerTPSelectionTool(name="ZmumuTPSelectionTool_Trigger_OC_%s"%name_suffix,EffiFlag="%s_OC"%name_suffix)]
-    SelectionTools += [AddTriggerTPSelectionTool(name="ZmumuTPSelectionTool_Trigger_SC_%s"%name_suffix,EffiFlag="%s_SC"%name_suffix, SameSign=True)]
-
-
-    PlotTools = []
-    # add plotting tools in slices
-    if doEtaSlices:
-        Slices = {
-                   "All"        : (0.0,10.0),
-                   "noCrack"    : (0.1,10.0),
-                   "Crack"      : (0.0,0.1),
-                   "Barrel"     : (0.1,1.1),
-                   "Transition" : (1.1, 1.3),
-                   "Endcap"     : (1.3,2.0),
-                   "CSC"        : (2.0,2.7)
-                   }
-
-        for etaslice, interval in Slices.iteritems():
-            PlotTool = AddTriggerTPPlotTool(name="TriggerTPPlottingTool_%s_%s"%(name_suffix,etaslice),EffiFlag=name_suffix+"_"+etaslice,applySF = False)
-            PlotTool.ProbeAbsEtaMin = interval[0]
-            PlotTool.ProbeAbsEtaMax = interval[1]
-            PlotTools.append(PlotTool)
-            if doClosure:
-                PlotToolCL = AddTriggerTPPlotTool(name="TriggerTPPlottingTool_Closure_%s_%s"%(name_suffix,etaslice),EffiFlag=name_suffix+"_"+etaslice+"_Closure",applySF = True)
-                PlotToolCL.ProbeAbsEtaMin = interval[0]
-                PlotToolCL.ProbeAbsEtaMax = interval[1]
-                PlotTools.append(PlotToolCL)
-                
-    else:
-        PlotTools = [AddTriggerTPPlotTool(name="TriggerTPPlottingTool_%s_All"%name_suffix,EffiFlag=name_suffix+"_All",applySF = False)]
-        if doClosure:
-            PlotTools.append(AddTriggerTPPlotTool(name="TriggerTPPlottingTool_Closure_%s_All"%name_suffix,EffiFlag=name_suffix+"_All_Closure",applySF = True))
-        
-
-    # add any desired matching tools
-
-    MATCH_DR = 0.05
-
-    MatchingTools = []
-
-    for Trigitem in TriggerList_L1 + TriggerList_HLT:
-        thistool = AddTriggerTPEfficiencyTool(name="TriggerTPEfficiencyTool_%s_%s"%(name_suffix,Trigitem),EffiFlag=Trigitem)
-        thistool.TrigItem = Trigitem
-        thistool.MaximumDrCut = MATCH_DR
-        MatchingTools.append(thistool)
-        if doDRSys:
-            thistool_dRup = AddTriggerTPEfficiencyTool(name="TriggerTPEfficiencyTool_DrUp_%s_%s"%(name_suffix,Trigitem),EffiFlag="%s_dRUp"%Trigitem)
-            thistool_dRup.TrigItem = Trigitem
-            thistool_dRup.MaximumDrCut = 2.0 * MATCH_DR
-            MatchingTools.append(thistool_dRup)
-
-            thistool_dRDown = AddTriggerTPEfficiencyTool(name="TriggerTPEfficiencyTool_DrDown_%s_%s"%(name_suffix,Trigitem),EffiFlag="%s_dRDown"%Trigitem)
-            thistool_dRDown.TrigItem = Trigitem
-            thistool_dRDown.MaximumDrCut = 0.5 * MATCH_DR
-            MatchingTools.append(thistool_dRDown)
-
-           
-
-    ntuples = []
-    if writeNtuple:
-        ntuples.append(AddTriggerTPTreeTool(name="TriggerTPTreeTool_%s"%name_suffix, EffiFlag="Trees"))
-
-    # create the TP tool itself
-    TheTPTool = AddZmumuTPTool(name = "TriggerTPTool_%s"%name_suffix,EffiFlag=name_suffix)
-    TheTPTool.MuonTPSelectionTools  = SelectionTools
-    TheTPTool.PlottingTools         = PlotTools
-    TheTPTool.MuonTPEfficiencyTools = MatchingTools
-    TheTPTool.TreeTools             = ntuples
-    theAlg.MuonTPTools += [TheTPTool]
-
-
-def AddTriggerTPAnalysis(doEtaSlices=True,writeNtuple=False,doClosure=False,doDRSys=False,doL1=False,doL2=False,doEF=False,doHLT=False):
-    from AthenaCommon.AlgSequence import AlgSequence
-    from AthenaCommon.AppMgr import ToolSvc
-    job = AlgSequence()
-
-
-    MuonContainerToUse = "Muons"
-    if hasattr(job, "MuonQualityUpdater"):
-        MuonContainerToUse = "UpdatedMuons"
-    TriggerList_L1  = []
-    TriggerList_L2  = []
-    TriggerList_EF  = []
-    TriggerList_HLT = []
-    
-    if doHLT:
-        TriggerList_HLT = [
-                 #        Multi-Muon Triggers
-#                "HLT_2mu4",
-#                "HLT_2mu6",
-#                "HLT_2mu10",
-#                "HLT_2mu14",
-#                "HLT_3mu6",
-#                "HLT_3mu6_msonly",
-#                "HLT_mu11_2mu4noL1_nscan03_L1MU10_2MU6",
-#                "HLT_mu11_2mu4noL1_nscan03_L1MU11_2MU6",
-#                "HLT_mu14_iloose_mu14",
-#                "HLT_mu18_2mu0noL1_JpsimumuFS",
-#                "HLT_mu18_2mu4_JpsimumuL2",
-#                "HLT_mu18_2mu4noL1",
-#                "HLT_mu18_mu8noL1",
-#                "HLT_mu20_2mu0noL1_JpsimumuFS",
-#                "HLT_mu20_2mu4_JpsimumuL2",
-#                "HLT_mu20_2mu4noL1",
-#                "HLT_mu20_iloose_2mu4noL1",
-#                "HLT_mu20_iloose_mu8noL1",
-#                "HLT_mu20_imedium_mu8noL1",
-#                "HLT_mu20_msonly_mu6noL1_msonly_nscan05",
-#                "HLT_mu20_mu8noL1",
-#                "HLT_mu22_2mu4noL1",
-#                "HLT_mu22_mu8noL1",
-#                "HLT_mu24_2mu4noL1",
-#                "HLT_mu24_mu8noL1",
-    		 #        Single-Muon
-                "HLT_mu0_perf",
-                #"HLT_mu0noL1_fsperf",
-                "HLT_mu4",
-                "HLT_mu4_msonly",
-                "HLT_mu4_r1extr",
-                "HLT_mu6",
-                "HLT_mu6_msonly",
-                "HLT_mu10",
-                "HLT_mu10_msonly",
-                "HLT_mu10_r1extr",
-                "HLT_mu14",
-                "HLT_mu18",
-                "HLT_mu20",
-                "HLT_mu20_L1MU15",
-                "HLT_mu20_iloose_L1MU15",
-                "HLT_mu20_msonly",
-                "HLT_mu20_r1extr",
-                "HLT_mu22",
-                "HLT_mu24",
-                "HLT_mu24_L1MU15",
-                "HLT_mu24_iloose_L1MU15",
-                "HLT_mu24_imedium",
-                "HLT_mu26",
-                "HLT_mu26_imedium",
-                "HLT_mu50",
-                "HLT_mu60_0eta105_msonly",
-
-                "HLT_AllTriggers", # this is needed, if you want to have combined (inclusive) efficiency of all HLT triggers
-                    ]
-    if doL1:
-        TriggerList_L1 = [
-                "L1_MU4",
-                "L1_MU6",
-                "L1_MU10",
-                "L1_MU15",
-                "L1_MU20",
-#                "L1_2MU4",
-#                "L1_2MU6",
-#                "L1_2MU10",
-#                "L1_3MU4",
-#                "L1_3MU6",
-#                "L1_MU6_2MU4",
-#                "L1_MU10_2MU6",
-#                "L1_MU11_2MU6",
-
-                "L1_AllTriggers", # this is needed, if you want to have combined (inclusive) efficiency of all L1 triggers
-                               ]
-
-    # PLEASE NOTE !!! L2 & EF are so far only placeholders
-    if doL2:
-        TriggerList_L2 = [
-                            "L2_MU20" # a dummy name
-                                ]
-    if doEF:
-        TriggerList_EF = [
-                            "EF_MU30" # a dummy name
-                                ]
-
-
-    ##########################################################################################
-    # Add the Zmm TP algorithm using MS muons as probes and matching to CaloTag muons
-    AddConfiguredTriggerTPAlg(
-                            name_suffix     = "MuonTrigValid",
-                            MatchContainer  = "Muons",
-                            TriggerList_L1  = TriggerList_L1,
-                            TriggerList_L2  = TriggerList_L2,
-                            TriggerList_EF  = TriggerList_EF,
-                            TriggerList_HLT = TriggerList_HLT,
-                            doEtaSlices     = doEtaSlices,
-                            writeNtuple     = writeNtuple,
-                            doClosure       = doClosure,
-                            doDRSys         = doDRSys 
-			    )
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/Zmumu_19.0.2.1.py b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/Zmumu_19.0.2.1.py
deleted file mode 100644
index f4326dbf870..00000000000
--- a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/Zmumu_19.0.2.1.py
+++ /dev/null
@@ -1,10 +0,0 @@
-if not 'FILELIST' in globals():
-	FILELIST="filelist.txt"
-	
-print "running with file list %s"%FILELIST				
-
-with open(FILELIST,'r') as input:
-    InputAODList=[bla for bla in input.read().split("\n") if bla != ""and not '#' in bla ]
-    #print InputAODList
-
-
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/Zmumu_19.2.0.py b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/Zmumu_19.2.0.py
deleted file mode 100644
index a4cc40dd082..00000000000
--- a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/share/Zmumu_19.2.0.py
+++ /dev/null
@@ -1,200 +0,0 @@
-InputAODList = ['root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/99/b4/AOD.01600180._000193.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/27/6d/AOD.01600180._000144.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/fd/cb/AOD.01600180._000101.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/5c/d5/AOD.01600180._000104.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/c8/11/AOD.01600180._000158.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/ec/40/AOD.01600180._000176.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/05/4b/AOD.01600180._000140.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/72/a1/AOD.01600180._000044.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/5c/f4/AOD.01600180._000195.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/7f/a4/AOD.01600180._000168.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/58/15/AOD.01600180._000093.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/fd/41/AOD.01600180._000053.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/50/72/AOD.01600180._000127.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/ff/0c/AOD.01600180._000031.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/c5/eb/AOD.01600180._000069.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/c1/47/AOD.01600180._000087.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/de/8a/AOD.01600180._000174.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/f0/7e/AOD.01600180._000150.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/ff/4b/AOD.01600180._000157.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/3a/5f/AOD.01600180._000021.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/89/99/AOD.01600180._000062.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/a6/24/AOD.01600180._000043.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/9b/40/AOD.01600180._000149.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/31/73/AOD.01600180._000050.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/37/c5/AOD.01600180._000012.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/d6/2d/AOD.01600180._000037.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/7b/04/AOD.01600180._000009.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/b4/21/AOD.01600180._000032.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/89/8d/AOD.01600180._000137.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/a6/25/AOD.01600180._000163.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/ae/7a/AOD.01600180._000102.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/94/d0/AOD.01600180._000191.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/71/77/AOD.01600180._000008.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/2c/2a/AOD.01600180._000155.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/8e/a0/AOD.01600180._000039.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/88/7d/AOD.01600180._000065.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/40/67/AOD.01600180._000040.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/ce/4b/AOD.01600180._000001.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/8c/b9/AOD.01600180._000067.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/4b/c9/AOD.01600180._000196.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/27/32/AOD.01600180._000025.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/04/97/AOD.01600180._000115.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/43/86/AOD.01600180._000003.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/92/fa/AOD.01600180._000199.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/19/ea/AOD.01600180._000048.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/63/10/AOD.01600180._000116.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/c5/ee/AOD.01600180._000121.pool.root.2',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/75/45/AOD.01600180._000088.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/8a/d6/AOD.01600180._000173.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/a0/9e/AOD.01600180._000147.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/80/5a/AOD.01600180._000034.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/26/6b/AOD.01600180._000041.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/35/5c/AOD.01600180._000166.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/c4/d8/AOD.01600180._000108.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/87/82/AOD.01600180._000143.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/7e/88/AOD.01600180._000073.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/d1/9f/AOD.01600180._000002.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/38/0d/AOD.01600180._000135.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/d2/ee/AOD.01600180._000094.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/bc/a7/AOD.01600180._000181.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/4b/1b/AOD.01600180._000092.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/f6/af/AOD.01600180._000170.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/9f/4a/AOD.01600180._000125.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/06/3d/AOD.01600180._000006.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/57/9b/AOD.01600180._000004.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/68/58/AOD.01600180._000141.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/60/95/AOD.01600180._000024.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/75/c8/AOD.01600180._000064.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/45/30/AOD.01600180._000023.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/9c/2e/AOD.01600180._000018.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/2d/35/AOD.01600180._000156.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/6f/fe/AOD.01600180._000074.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/fa/62/AOD.01600180._000175.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/48/2b/AOD.01600180._000161.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/58/37/AOD.01600180._000026.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/3b/02/AOD.01600180._000122.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/c6/23/AOD.01600180._000005.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/61/aa/AOD.01600180._000010.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/4a/13/AOD.01600180._000178.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/64/a4/AOD.01600180._000011.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/4f/e2/AOD.01600180._000145.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/9d/42/AOD.01600180._000080.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/99/a7/AOD.01600180._000046.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/4a/a8/AOD.01600180._000072.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/c3/58/AOD.01600180._000084.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/01/08/AOD.01600180._000098.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/9b/27/AOD.01600180._000123.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/40/67/AOD.01600180._000076.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/dc/3e/AOD.01600180._000038.pool.root.5',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/be/4a/AOD.01600180._000188.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/ce/c5/AOD.01600180._000020.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/ee/c2/AOD.01600180._000189.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/05/51/AOD.01600180._000113.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/75/9f/AOD.01600180._000117.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/2b/c6/AOD.01600180._000184.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/42/4d/AOD.01600180._000036.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/37/47/AOD.01600180._000019.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/23/d6/AOD.01600180._000152.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/09/f3/AOD.01600180._000015.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/7a/b8/AOD.01600180._000109.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/03/82/AOD.01600180._000103.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/5d/24/AOD.01600180._000089.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/59/69/AOD.01600180._000047.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/47/ce/AOD.01600180._000165.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/74/5a/AOD.01600180._000035.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/67/83/AOD.01600180._000061.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/1a/05/AOD.01600180._000096.pool.root.2',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/8f/66/AOD.01600180._000194.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/85/43/AOD.01600180._000111.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/ff/ef/AOD.01600180._000085.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/36/91/AOD.01600180._000110.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/13/e3/AOD.01600180._000118.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/f6/16/AOD.01600180._000114.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/31/48/AOD.01600180._000132.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/a9/34/AOD.01600180._000107.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/21/00/AOD.01600180._000056.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/82/84/AOD.01600180._000185.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/a5/34/AOD.01600180._000033.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/bf/8d/AOD.01600180._000124.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/42/55/AOD.01600180._000017.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/e0/59/AOD.01600180._000052.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/02/68/AOD.01600180._000192.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/8e/40/AOD.01600180._000054.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/40/2f/AOD.01600180._000095.pool.root.2',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/75/75/AOD.01600180._000164.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/fd/ec/AOD.01600180._000055.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/69/8c/AOD.01600180._000081.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/a7/28/AOD.01600180._000146.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/8a/c4/AOD.01600180._000057.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/73/97/AOD.01600180._000128.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/d9/05/AOD.01600180._000049.pool.root.5',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/31/94/AOD.01600180._000138.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/85/43/AOD.01600180._000097.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/b9/22/AOD.01600180._000071.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/e7/e5/AOD.01600180._000066.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/4d/52/AOD.01600180._000082.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/f3/e3/AOD.01600180._000171.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/da/a4/AOD.01600180._000077.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/b6/d8/AOD.01600180._000169.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/4f/22/AOD.01600180._000013.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/7a/46/AOD.01600180._000051.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/97/3d/AOD.01600180._000079.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/fa/7f/AOD.01600180._000106.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/dc/78/AOD.01600180._000014.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/4f/bf/AOD.01600180._000059.pool.root.5',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/6c/8d/AOD.01600180._000133.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/52/c9/AOD.01600180._000030.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/1c/ba/AOD.01600180._000154.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/1b/99/AOD.01600180._000042.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/9f/a4/AOD.01600180._000099.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/95/f6/AOD.01600180._000105.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/c9/ff/AOD.01600180._000029.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/06/68/AOD.01600180._000063.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/da/65/AOD.01600180._000112.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/27/fa/AOD.01600180._000180.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/3c/22/AOD.01600180._000151.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/ee/19/AOD.01600180._000119.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/62/14/AOD.01600180._000129.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/8f/22/AOD.01600180._000153.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/c0/1c/AOD.01600180._000028.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/f5/69/AOD.01600180._000190.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/48/50/AOD.01600180._000022.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/4c/b9/AOD.01600180._000078.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/1d/9e/AOD.01600180._000177.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/f3/48/AOD.01600180._000120.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/28/ff/AOD.01600180._000070.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/82/d3/AOD.01600180._000200.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/49/54/AOD.01600180._000183.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/75/f9/AOD.01600180._000148.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/4c/d1/AOD.01600180._000197.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/36/43/AOD.01600180._000058.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/2f/8f/AOD.01600180._000060.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/2f/c8/AOD.01600180._000186.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/ab/9f/AOD.01600180._000134.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/4d/c8/AOD.01600180._000172.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/ca/b0/AOD.01600180._000160.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/43/1d/AOD.01600180._000075.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/37/db/AOD.01600180._000162.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/e1/e0/AOD.01600180._000045.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/2d/37/AOD.01600180._000016.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/2e/5c/AOD.01600180._000159.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/9f/21/AOD.01600180._000086.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/c9/cc/AOD.01600180._000167.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/8c/d7/AOD.01600180._000131.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/f8/2f/AOD.01600180._000130.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/31/55/AOD.01600180._000027.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/af/07/AOD.01600180._000083.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/01/4c/AOD.01600180._000136.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/5b/e9/AOD.01600180._000007.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/c1/54/AOD.01600180._000198.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/07/d8/AOD.01600180._000068.pool.root.5',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/ee/2e/AOD.01600180._000179.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/da/4c/AOD.01600180._000090.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/e6/12/AOD.01600180._000187.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/05/e7/AOD.01600180._000126.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/59/74/AOD.01600180._000182.pool.root.4',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/98/17/AOD.01600180._000139.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/14/cf/AOD.01600180._000100.pool.root.3',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/35/d2/AOD.01600180._000091.pool.root.1',
-                'root://eosatlas//eos/atlas/atlasdatadisk/rucio/valid1/c9/07/AOD.01600180._000142.pool.root.1']
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/src/MuonTPAlg.cxx b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/src/MuonTPAlg.cxx
index ad98ee07249..3dff9b23f26 100644
--- a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/src/MuonTPAlg.cxx
+++ b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/src/MuonTPAlg.cxx
@@ -25,6 +25,7 @@ MuonTPAlg::MuonTPAlg(const std::string& name, ISvcLocator* pSvcLocator ) :
   declareProperty("TagContainerName",   m_tagContainerName   = "Muons");
   declareProperty("ProbeContainerName", m_probeContainerName = "InDetTrackParticles");
   declareProperty("MatchContainerName", m_matchContainerName = "Muons");
+  declareProperty("TopLevelFolderName", m_topLevelOutputFolderName = "UndefinedTagAndProbe");
 }
 
 //**********************************************************************
@@ -45,21 +46,21 @@ StatusCode MuonTPAlg::initialize() {
     for(auto hd : histData) {
       
       std::string histPath = hd.second+"/"+hd.first->GetName();
-      m_histSvc->regHist("/MUONTP/"+histPath, hd.first).ignore(); //or check the statuscode
+      m_histSvc->regHist("/MUONTP/"+m_topLevelOutputFolderName+"/"+histPath, hd.first).ignore(); //or check the statuscode
     }
 
     std::vector<std::pair <TTree*, std::string> > treeData = tool->retrieveBookedTrees();
     for(auto hd : treeData) {
 
       std::string treePath = hd.second+"/"+hd.first->GetName();
-      m_histSvc->regTree("/MUONTP/"+treePath, hd.first).ignore(); //or check the statuscode
+      m_histSvc->regTree("/MUONTP/"+m_topLevelOutputFolderName+"/"+treePath, hd.first).ignore(); //or check the statuscode
       ATH_MSG_DEBUG(std::string(" registered tree ")+"/MUONTP/"+treePath);
     }
     std::vector<std::pair <TGraph*, std::string> > graphData = tool->retrieveBookedGraphs();
     for(auto hd : graphData) {
 
       std::string graphPath = hd.second+"/"+hd.first->GetName();
-      m_histSvc->regGraph("/MUONTP/"+graphPath, hd.first).ignore(); //or check the statuscode
+      m_histSvc->regGraph("/MUONTP/"+m_topLevelOutputFolderName+"/"+graphPath, hd.first).ignore(); //or check the statuscode
       ATH_MSG_DEBUG(std::string(" registered graph ")+"/MUONTP/"+graphPath);
     }
   }
diff --git a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/src/MuonTPAlg.h b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/src/MuonTPAlg.h
index 09fd2fd6909..ac6903d8c30 100644
--- a/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/src/MuonTPAlg.h
+++ b/PhysicsAnalysis/MuonID/MuonPerformanceAnalysis/MuonPerformanceAlgs/src/MuonTPAlg.h
@@ -38,6 +38,7 @@ private:
   std::string m_tagContainerName;
   std::string m_probeContainerName;
   std::string m_matchContainerName;
+  std::string m_topLevelOutputFolderName;
 
   /// Athena configured tools
   ServiceHandle<ITHistSvc> m_histSvc;
-- 
GitLab