From e1540e6e29ca7547699938f04c01307c52b400ac Mon Sep 17 00:00:00 2001
From: Atlas-Software Librarian <Atlas-Software.Librarian@cern.ch>
Date: Fri, 8 Apr 2016 15:49:35 +0200
Subject: [PATCH] 'CMakeLists.txt' (LongLivedParticleDPDMaker-00-01-15)

	* Add PhysDPD_HIPs to separate out Highly Ionizing Particle selection into it's own DESD (DESD_HIPs).
	* Also modify HipsFlags.py - trigger selection expression is now there so it can be used by both
	PhysDESDM_Hips.py (old version, for running HIPs selection in DESDM_RPVLL) and the new PhysDPD_HIPs.py.
	* Tag as LongLivedParticleDPDMaker-00-01-15

2016-01-12 Nick Barlow
	* Modify stream name for DRAW_RPVLL to comply with conventions in
	PrimaryDPDMaker
	* Tag as LongLivedParticleDPDMaker-00-01-14

2015-12-03 Nick Barlow
	* Add share/PhysDRAW_RPVLL.py script in case we might want to write out DRAW instead of DESD.

2015-10-11 Christian Ohm
	* Fix of coverity defects 30224, 30925, 30924, 30223, 30225, 30226,
	  30227, 30222, 16941
	* Tag as LongLivedParticleDPDMaker-00-01-12
---
 .../LongLivedParticleDPDMaker/CMakeLists.txt  |  44 +++
 .../LongLivedParticleDPDMaker/DiLepFilters.h  | 101 +++++++
 .../DiLepSkimTools.h                          |  48 ++++
 .../LongLivedParticleDPDMaker/IDiLepFilters.h |  44 +++
 .../RPVLLTestRates.h                          |   1 -
 .../LongLivedParticleDPDMaker/RpvMuonMSTool.h |  53 ----
 .../LongLivedParticleDPDMaker/cmt/version.cmt |   2 +-
 .../python/DiLepFlags.py                      | 158 ----------
 .../python/HVFlags.py                         |   2 +-
 .../python/HipsFlags.py                       |  69 +----
 .../python/PrimaryDPDFlags_RPVLLStream.py     |   3 +-
 .../share/PhysDESDM_DiLep.py                  | 255 +++++-----------
 .../share/PhysDESDM_Hips.py                   |  11 +-
 .../share/PhysDESDM_RPVLL.py                  |   1 +
 .../share/PhysDPD_HIPs.py                     |  63 ++++
 .../share/PhysDRAW_RPVLL.py                   | 116 ++++++++
 .../src/DiLepFilters.cxx                      | 272 ++++++++++++++++++
 .../src/DiLepSkimTools.cxx                    | 124 ++++++++
 .../src/KinkTrkZeeTagTool.cxx                 |   4 +
 .../src/KinkTrkZmumuTagTool.cxx               |   5 +
 .../src/RPVLLTestRates.cxx                    |   8 +-
 .../src/RpvElectronD0Tool.cxx                 |   1 +
 .../src/RpvMuonD0Tool.cxx                     |  34 ++-
 .../src/RpvMuonMSTool.cxx                     |  76 -----
 .../LongLivedParticleDPDMaker_entries.cxx     |   9 +-
 25 files changed, 952 insertions(+), 552 deletions(-)
 create mode 100644 PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/CMakeLists.txt
 create mode 100644 PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/DiLepFilters.h
 create mode 100644 PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/DiLepSkimTools.h
 create mode 100644 PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/IDiLepFilters.h
 delete mode 100644 PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/RpvMuonMSTool.h
 delete mode 100644 PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/DiLepFlags.py
 create mode 100644 PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDPD_HIPs.py
 create mode 100644 PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDRAW_RPVLL.py
 create mode 100644 PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/DiLepFilters.cxx
 create mode 100644 PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/DiLepSkimTools.cxx
 delete mode 100644 PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RpvMuonMSTool.cxx

diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/CMakeLists.txt b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/CMakeLists.txt
new file mode 100644
index 00000000000..d4f0ba0143d
--- /dev/null
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/CMakeLists.txt
@@ -0,0 +1,44 @@
+################################################################################
+# Package: LongLivedParticleDPDMaker
+################################################################################
+
+# Declare the package name:
+atlas_subdir( LongLivedParticleDPDMaker )
+
+# Declare the package's dependencies:
+atlas_depends_on_subdirs( PUBLIC
+                          Control/AthenaBaseComps
+                          Event/xAOD/xAODCaloEvent
+                          Event/xAOD/xAODEgamma
+                          Event/xAOD/xAODMuon
+                          Event/xAOD/xAODTracking
+                          GaudiKernel
+                          PhysicsAnalysis/DerivationFramework/DerivationFrameworkInterfaces
+                          PhysicsAnalysis/MuonID/MuonSelectorTools
+                          Trigger/TrigAnalysis/TrigDecisionTool
+                          Trigger/TrigAnalysis/TrigObjectMatching
+                          PRIVATE
+                          Control/AthenaKernel
+                          Event/EventBookkeeperMetaData
+                          Event/EventInfo
+                          Event/FourMomUtils
+                          Event/xAOD/xAODEventInfo
+                          Event/xAOD/xAODJet
+                          Event/xAOD/xAODMissingET )
+
+# External dependencies:
+find_package( CLHEP )
+find_package( ROOT COMPONENTS Core Tree MathCore Hist RIO pthread )
+
+# Component(s) in the package:
+atlas_add_component( LongLivedParticleDPDMaker
+                     src/*.cxx
+                     src/components/*.cxx
+                     INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS}
+                     LINK_LIBRARIES ${ROOT_LIBRARIES} ${CLHEP_LIBRARIES} AthenaBaseComps xAODCaloEvent xAODEgamma xAODMuon xAODTracking GaudiKernel MuonSelectorToolsLib TrigDecisionToolLib TrigObjectMatchingLib AthenaKernel EventBookkeeperMetaData EventInfo FourMomUtils xAODEventInfo xAODJet xAODMissingET )
+
+# Install files from the package:
+atlas_install_headers( LongLivedParticleDPDMaker )
+atlas_install_python_modules( python/*.py )
+atlas_install_joboptions( share/*.py )
+
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/DiLepFilters.h b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/DiLepFilters.h
new file mode 100644
index 00000000000..b4c2d030f0b
--- /dev/null
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/DiLepFilters.h
@@ -0,0 +1,101 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+/////////////////////////////////////////////////////////////////
+// DiLepFilters.h, (c) ATLAS Detector software
+/////////////////////////////////////////////////////////////////
+// Author: Dominik Krauss (krauss@mpp.mpg.de)
+
+#ifndef DERIVATIONFRAMEWORK_DILEPFILTERS_H
+#define DERIVATIONFRAMEWORK_DILEPFILTERS_H 1
+
+// STL
+#include <cmath>
+#include <string>
+
+// Athena
+#include "AthenaBaseComps/AthAlgTool.h"
+#include "GaudiKernel/ToolHandle.h"
+#include "TrigDecisionTool/TrigDecisionTool.h"
+#include "LongLivedParticleDPDMaker/IDiLepFilters.h"
+#include "xAODEgamma/Electron.h"
+#include "xAODEgamma/Photon.h"
+#include "xAODMuon/Muon.h"
+
+namespace DerivationFramework
+{
+  class DiLepFilters : public AthAlgTool, virtual public IDiLepFilters
+  {
+    public:
+      DiLepFilters(const std::string& t, const std::string& n, const IInterface* p);
+      virtual ~DiLepFilters() = default;
+
+      StatusCode initialize() override;
+
+      // retrieves the trigger information
+      // has to be called in every event before the filters are used
+      // returns true if at least one trigger is passed
+      bool GetTriggers() override;
+
+      // single filter implementations
+      bool PassSiEl(const xAOD::Electron& el) const override;
+      bool PassSiPhX(const xAOD::Photon& ph, const xAOD::Electron& el) const override;
+      bool PassSiPhX(const xAOD::Photon& ph1, const xAOD::Photon& ph2) const override;
+      bool PassSiPhX(const xAOD::Photon& ph, const xAOD::Muon& mu) const override;
+      bool PassSiMu(const xAOD::Muon& mu) const override;
+
+      // di filter implementations
+      bool PassDiEl(const xAOD::Electron& el1, const xAOD::Electron& el2) const override;
+      bool PassDiPh(const xAOD::Photon& ph1, const xAOD::Photon& ph2) const override;
+      bool PassDiElPh(const xAOD::Electron& el, const xAOD::Photon& ph) const override;
+      bool PassDiLoElPh(const xAOD::Electron& el, const xAOD::Photon& ph) const override;
+
+    private:
+      ToolHandle<Trig::TrigDecisionTool> m_tdt;
+
+      // trigger names
+      std::string m_trig_siph;
+      std::string m_trig_diph;
+      std::string m_trig_simu;
+
+      // trigger flags
+      bool m_pass_siph;
+      bool m_pass_diph;
+      bool m_pass_simu;
+
+      // cut values of the filters
+      double m_el_eta;
+      double m_ph_eta;
+      double m_mu_eta;
+      double m_mu_beta;
+
+      double m_el_d0;
+      double m_mu_d0;
+
+      double m_siel_pt;
+      double m_siph_pt;
+      double m_siph_xpt;
+      double m_simu_pt;
+      double m_diel_pt;
+      double m_diph_pt;
+      double m_dielph_pt;
+      double m_diloelph_pt;
+
+      static constexpr double m_GeVtoMeV = 1000.;
+
+      // small helper functions
+      inline bool PassEta(const xAOD::IParticle& part, double eta_cut) const;
+      inline bool Passd0(const xAOD::Electron& el, double d0_cut) const;
+      inline bool Passd0(const xAOD::Muon& mu, double d0_cut) const;
+      inline bool IsLoose(const xAOD::Egamma& eg) const;
+      inline bool SameCluster(const xAOD::Egamma& eg1, const xAOD::Egamma& eg2) const;
+      inline bool IsGood(const xAOD::Muon& mu) const;
+
+      inline bool PassCuts(const xAOD::Electron& el, double pt_cut, bool loose = false) const;
+      inline bool PassCuts(const xAOD::Photon& ph, double pt_cut) const;
+      inline bool PassCuts(const xAOD::Muon& mu, double pt_cut, double eta_cut) const;
+  };
+}
+
+#endif
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/DiLepSkimTools.h b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/DiLepSkimTools.h
new file mode 100644
index 00000000000..594c116c95b
--- /dev/null
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/DiLepSkimTools.h
@@ -0,0 +1,48 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+/////////////////////////////////////////////////////////////////
+// DiLepSkimTools.h, (c) ATLAS Detector software
+/////////////////////////////////////////////////////////////////
+// Author: Dominik Krauss (krauss@mpp.mpg.de)
+
+#ifndef DERIVATIONFRAMEWORK_DILEPSKIMTOOLS_H
+#define DERIVATIONFRAMEWORK_DILEPSKIMTOOLS_H 1
+
+// STL
+#include <string>
+
+// Athena
+#include "AthenaBaseComps/AthAlgTool.h"
+#include "DerivationFrameworkInterfaces/ISkimmingTool.h"
+#include "GaudiKernel/ToolHandle.h"
+#include "LongLivedParticleDPDMaker/DiLepFilters.h"
+#include "xAODEgamma/ElectronContainer.h"
+#include "xAODEgamma/PhotonContainer.h"
+#include "xAODMuon/MuonContainer.h"
+
+namespace DerivationFramework
+{
+  // for each filter a dedicated DiLepSkim instance is needed
+  class DiLepSkim : public AthAlgTool, public ISkimmingTool
+  {
+    public:
+      enum class Filters {None, SiEl, SiPhX, SiMu, DiEl, DiPh, DiElPh, DiLoElPh};
+
+      DiLepSkim(const std::string& t, const std::string& n, const IInterface* p);
+
+      StatusCode initialize() override;
+
+      // checks if an event passes the filter defined by m_filter
+      bool eventPassesFilter() const override;
+
+    private:
+      ToolHandle<DerivationFramework::IDiLepFilters> m_dlf;
+
+      int m_filter_prop;
+      Filters m_filter;
+  };
+}
+
+#endif
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/IDiLepFilters.h b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/IDiLepFilters.h
new file mode 100644
index 00000000000..d4ae08f02c8
--- /dev/null
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/IDiLepFilters.h
@@ -0,0 +1,44 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+/////////////////////////////////////////////////////////////////
+// IDiLepFilters.h, (c) ATLAS Detector software
+/////////////////////////////////////////////////////////////////
+// Author: Dominik Krauss (krauss@mpp.mpg.de)
+
+#ifndef DERIVATIONFRAMEWORK_IDILEPFILTERS_H
+#define DERIVATIONFRAMEWORK_IDILEPFILTERS_H 1
+
+// Athena
+#include "GaudiKernel/IAlgTool.h"
+#include "xAODEgamma/Electron.h"
+#include "xAODEgamma/Photon.h"
+#include "xAODMuon/Muon.h"
+
+// declaration of interface ID
+static const InterfaceID IID_DerivationFramework_IDiLepFilters("DerivationFramework::IDiLepFilters", 1, 0);
+
+namespace DerivationFramework
+{
+  class IDiLepFilters : virtual public IAlgTool
+  {
+    public:
+      static const InterfaceID& interfaceID() { return IID_DerivationFramework_IDiLepFilters; }
+
+      virtual bool GetTriggers() = 0;
+
+      virtual bool PassSiEl(const xAOD::Electron& el) const = 0;
+      virtual bool PassSiPhX(const xAOD::Photon& ph, const xAOD::Electron& el) const = 0;
+      virtual bool PassSiPhX(const xAOD::Photon& ph1, const xAOD::Photon& ph2) const = 0;
+      virtual bool PassSiPhX(const xAOD::Photon& ph, const xAOD::Muon& mu) const = 0;
+      virtual bool PassSiMu(const xAOD::Muon& mu) const = 0;
+
+      virtual bool PassDiEl(const xAOD::Electron& el1, const xAOD::Electron& el2) const = 0;
+      virtual bool PassDiPh(const xAOD::Photon& ph1, const xAOD::Photon& ph2) const = 0;
+      virtual bool PassDiElPh(const xAOD::Electron& el, const xAOD::Photon& ph) const = 0;
+      virtual bool PassDiLoElPh(const xAOD::Electron& el, const xAOD::Photon& ph) const = 0;
+  };
+}
+
+#endif
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/RPVLLTestRates.h b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/RPVLLTestRates.h
index c48668181c8..69a9a8025a4 100755
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/RPVLLTestRates.h
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/RPVLLTestRates.h
@@ -38,7 +38,6 @@ class RPVLLTestRates : public AthAlgorithm  {
  private:
 
    int m_EventCounter;
-   StoreGateSvc * m_MetaDataStore;
    ServiceHandle<ITHistSvc> m_tHistSvc;
 
    std::vector<std::string> m_DecisionLabel;
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/RpvMuonMSTool.h b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/RpvMuonMSTool.h
deleted file mode 100644
index 4c54469ba16..00000000000
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/RpvMuonMSTool.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
-*/
-
-///////////////////////////////////////////////////////////
-// RpvMuonMSTool.h  (c) ATLAS Detector software
-///////////////////////////////////////////////////////////////////
-
-#ifndef DERIVATIONFRAMEWORK_RPVMUONMSTOOL_H
-#define DERIVATIONFRAMEWORK_RPVMUONMSTOOL_H 1
-
-#include<string>
-
-// Gaudi & Athena basics
-#include "AthenaBaseComps/AthAlgTool.h"
-
-// DerivationFramework includes
-#include "DerivationFrameworkInterfaces/IAugmentationTool.h"
-
-namespace DerivationFramework {
-
-  /** @class RpvMuonMSTool
-
-      the code used in this implementation is kindly stolen from:
-      atlasoff:: ISF/ISF_Core/ISF_Tools
-
-      @author Michael Flowerdew -at- cern.ch
-     */
-  class RpvMuonMSTool : public AthAlgTool, public IAugmentationTool {
-   
-  public:
-    /** Constructor with parameters */
-    RpvMuonMSTool( const std::string& t, const std::string& n, const IInterface* p );
-   
-    /** Destructor */
-    ~RpvMuonMSTool();
-   
-    // Athena algtool's Hooks
-    StatusCode  initialize();
-    StatusCode  finalize();
- 
-    /** Check that the current event passes this filter */
-    virtual StatusCode addBranches() const;
-
-  private:
-    std::string m_collName;
-    std::string m_sgPrefix;
-
-  };
-
-}
-
-#endif
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/cmt/version.cmt b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/cmt/version.cmt
index af2f6a6d462..5f0aec91a5d 100644
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/cmt/version.cmt
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/cmt/version.cmt
@@ -1 +1 @@
-LongLivedParticleDPDMaker-r696404
+LongLivedParticleDPDMaker-r717389
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/DiLepFlags.py b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/DiLepFlags.py
deleted file mode 100644
index e7cd6cbc814..00000000000
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/DiLepFlags.py
+++ /dev/null
@@ -1,158 +0,0 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
-
-from AthenaCommon.JobProperties import JobProperty, JobPropertyContainer
-from AthenaCommon.JobProperties import jobproperties
-
-import AthenaCommon.SystemOfUnits as Units
-
-primRPVLLDESDM = jobproperties.PrimaryDPDFlags_RPVLLStream
-
-class DiLep_containerFlags(JobProperty):
-    statusOn               = True
-    photonCollectionName   = 'Photons'
-    electronCollectionName = 'Electrons'
-    muonCollectionName     = 'Muons'
-    pass
-primRPVLLDESDM.add_JobProperty(DiLep_containerFlags)
-
-class DiLep_singlePhotonFilterFlags(JobProperty):
-    statusOn     = True
-    allowedTypes = ['bool']
-    StoredValue  = False    
-    cutEtMin     = 150*Units.GeV
-    cutEtaMax    = 2.5
-    cutd0Min     = None
-    cutIsEM      = 'Loose'
-    trigger      = 'HLT_g140_loose'
-    pass
-primRPVLLDESDM.add_JobProperty(DiLep_singlePhotonFilterFlags)
-
-class DiLep_singlePhotonFilterFlags_addph(JobProperty):
-    statusOn     = True
-    allowedTypes = ['bool']
-    StoredValue  = False    
-    cutEtMin     = 10*Units.GeV
-    cutEtaMax    = 2.5
-    cutd0Min     = None
-    cutIsEM      = 'Loose'
-    trigger      = None
-    pass
-primRPVLLDESDM.add_JobProperty(DiLep_singlePhotonFilterFlags_addph)
-
-class DiLep_singlePhotonFilterFlags_addel(JobProperty):
-    statusOn     = True
-    allowedTypes = ['bool']
-    StoredValue  = False    
-    cutEtMin     = 10*Units.GeV
-    cutEtaMax    = 2.5
-    cutd0Min     = 2.0*Units.mm
-    cutIsEM      = None
-    trigger      = None
-    pass
-primRPVLLDESDM.add_JobProperty(DiLep_singlePhotonFilterFlags_addel)
-
-class DiLep_singlePhotonFilterFlags_addmu(JobProperty):
-    statusOn     = True
-    allowedTypes = ['bool']
-    StoredValue  = False    
-    cutEtMin     = 10*Units.GeV
-    cutEtaMax    = 2.5
-    cutd0Min     = 1.5*Units.mm
-    trigger      = None
-    pass
-primRPVLLDESDM.add_JobProperty(DiLep_singlePhotonFilterFlags_addmu)
-
-class DiLep_singleElectronFilterFlags(JobProperty):
-    statusOn     = True
-    allowedTypes = ['bool']
-    StoredValue  = False    
-    cutEtMin     = 140*Units.GeV
-    cutEtaMax    = 2.5
-    cutd0Min     = 2.0*Units.mm
-    cutIsEM      = None
-    trigger      = 'HLT_g140_loose'
-    pass
-primRPVLLDESDM.add_JobProperty(DiLep_singleElectronFilterFlags)
-
-class DiLep_singleMuonFilterFlags(JobProperty):
-    statusOn     = True
-    allowedTypes = ['bool']
-    StoredValue  = False    
-    cutEtMin     = 60*Units.GeV
-    cutEtaMax    = 1.07
-    cutd0Min     = 1.5*Units.mm
-    trigger      = 'HLT_mu60_0eta105_msonly'
-    pass
-primRPVLLDESDM.add_JobProperty(DiLep_singleMuonFilterFlags)
-
-class DiLep_diPhotonFilterFlags(JobProperty):
-    statusOn     = True
-    allowedTypes = ['bool']
-    StoredValue  = False    
-    cutEtMin     = 50*Units.GeV
-    cutEtaMax    = 2.5
-    cutd0Min     = None
-    cutIsEM      = 'Loose'
-    trigger      = 'HLT_2g50_loose'
-    pass
-primRPVLLDESDM.add_JobProperty(DiLep_diPhotonFilterFlags)
-
-class DiLep_diElectronFilterFlags(JobProperty):
-    statusOn     = True
-    allowedTypes = ['bool']
-    StoredValue  = False    
-    cutEtMin     = 50*Units.GeV
-    cutEtaMax    = 2.5
-    cutd0Min     = 2.0*Units.mm
-    cutIsEM      = None
-    trigger      = 'HLT_2g50_loose'
-    pass
-primRPVLLDESDM.add_JobProperty(DiLep_diElectronFilterFlags)
-
-class DiLep_diEgammaFilterFlags_electron(JobProperty):
-    statusOn     = True
-    allowedTypes = ['bool']
-    StoredValue  = False    
-    cutEtMin     = 50*Units.GeV
-    cutEtaMax    = 2.5
-    cutd0Min     = 2.0*Units.mm
-    cutIsEM      = None
-    trigger      = 'HLT_2g50_loose'
-    pass
-primRPVLLDESDM.add_JobProperty(DiLep_diEgammaFilterFlags_electron)
-
-class DiLep_diEgammaFilterFlags_photon(JobProperty):
-    statusOn     = True
-    allowedTypes = ['bool']
-    StoredValue  = False    
-    cutEtMin     = 50*Units.GeV
-    cutEtaMax    = 2.5
-    cutd0Min     = None
-    cutIsEM      = 'Loose'
-    trigger      = None
-    pass
-primRPVLLDESDM.add_JobProperty(DiLep_diEgammaFilterFlags_photon)
-
-class DiLep_diLooseEgammaFilterFlags_electron(JobProperty):
-    statusOn     = True
-    allowedTypes = ['bool']
-    StoredValue  = False    
-    cutEtMin     = 50*Units.GeV
-    cutEtaMax    = 2.5
-    cutd0Min     = None
-    cutIsEM      = 'Loose'
-    trigger      = 'HLT_2g50_loose'
-    pass
-primRPVLLDESDM.add_JobProperty(DiLep_diLooseEgammaFilterFlags_electron)
-
-class DiLep_diLooseEgammaFilterFlags_photon(JobProperty):
-    statusOn     = True
-    allowedTypes = ['bool']
-    StoredValue  = False    
-    cutEtMin     = 50*Units.GeV
-    cutEtaMax    = 2.5
-    cutd0Min     = None
-    cutIsEM      = 'Loose'
-    trigger      = None
-    pass
-primRPVLLDESDM.add_JobProperty(DiLep_diLooseEgammaFilterFlags_photon)
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/HVFlags.py b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/HVFlags.py
index c30da21f6c2..f0673fe49e6 100644
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/HVFlags.py
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/HVFlags.py
@@ -39,6 +39,6 @@ class HV_jetMETFilterFlags(JobProperty):
   #      "HLT_j80_xe80",
 	"HLT_j100_xe80"
     ]
-    cutMetMin = 100.0*Units.GeV  # MET cut, currently placed on MET_Reference_AntiKt4TopoEM
+    cutMetMin = 120.0*Units.GeV  # MET cut, currently placed on MET_Reference_AntiKt4TopoEM
     pass
 primRPVLLDESDM.add_JobProperty(HV_jetMETFilterFlags)
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/HipsFlags.py b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/HipsFlags.py
index dc54e67dd16..8ac3ce275c4 100644
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/HipsFlags.py
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/HipsFlags.py
@@ -5,70 +5,19 @@ from AthenaCommon.JobProperties import jobproperties
 
 import AthenaCommon.SystemOfUnits as Units
 
-primRPVLLDESDM=jobproperties.PrimaryDPDFlags_RPVLLStream
+class PrimaryDPDFlags_HIPsStream(JobPropertyContainer):
+    """ The PrimaryDPD HIPs flag/job property  container."""
 
-class Hips_triggerFilterFlags(JobProperty):
-    statusOn = True
-    allowedTypes = ['bool']
-    StoredValue  = True
-    TriggerNames = [] # only put trigger names in this list if you want to override the below stream-specific ones
-    EgammaTriggerNames = [
-        #"EF_g20_loose",
-        #"EF_g40_loose",
-        #"EF_g60_loose",
-        #"EF_g80_loose",
-        #"EF_e20_loose",
-        #"EF_e60_loose",
-        #"EF_g40_loose_EFxe40_noMu",
-        #"EF_g40_loose_xe45_medium_noMu",
-        #"EF_g40_loose_xe55_medium_noMu",
-        #"EF_2g20_loose"
-        #"EF_e60_medium1",
-        "EF_g120_loose",
-        "EF_2g40_loose"
-    ]
-    JetTauEtmissTriggerNames = []
-    MuonsTriggerNames = []
-    pass
-primRPVLLDESDM.add_JobProperty(Hips_triggerFilterFlags)
+jobproperties.add_Container(PrimaryDPDFlags_HIPsStream)
 
-class Hips_triggerFilterFlags_hiptrt(JobProperty):
-    statusOn = True
-    allowedTypes = ['bool']
-    StoredValue  = True
-    TriggerNames = [] # only put trigger names in this list if you want to override the below stream-specific ones
-    EgammaTriggerNames = [
-        "EF_g_nocut_hiptrtL2"
-    ]
-    JetTauEtmissTriggerNames = []
-    MuonsTriggerNames = []
-    pass
-primRPVLLDESDM.add_JobProperty(Hips_triggerFilterFlags_hiptrt)
+primHIPsDESD=jobproperties.PrimaryDPDFlags_HIPsStream
 
-class Hips_electronFilterFlags(JobProperty):
-    statusOn = True
-    allowedTypes = ['bool']
-    StoredValue  = True  
-#    cutMinE = 15.0*Units.GeV
-#    cutEtaMax = 2.2
-    cutMinE = 60.0*Units.GeV
-    cutEtaMax = 1.4
-#    passAll = True
-    pass
-primRPVLLDESDM.add_JobProperty(Hips_electronFilterFlags)
 
+primHIPsDESD=jobproperties.PrimaryDPDFlags_HIPsStream
 
-class Hips_hipsFilterFlags(JobProperty):
+class HipsTriggerFilterExpression(JobProperty):
     statusOn = True
-    allowedTypes = ['bool']
-    StoredValue  = True
-    cutMinE = 40.0*Units.GeV
-    cutEtaMax = 2.2
-    cutMaxDeltaPhi = 0.05
-    cutMinTRTHTHits = 20
-    cutMinTRTHTFraction = 0.2
-    cutCaloCluster='CaloCalTopoCluster'
-## FOR TESTING ON R16
-#    cutCaloCluster='EMTopoCluster430'
+    allowedTypes = ['string']
+    StoredValue  = 'HLT_g0_hiptrt_L1EM18VH || HLT_g0_hiptrt_L1EM20VH || HLT_g0_hiptrt_L1EM20VHI || HLT_g0_hiptrt_L1EM22VHI' 
     pass
-primRPVLLDESDM.add_JobProperty(Hips_hipsFilterFlags)
+primHIPsDESD.add_JobProperty(HipsTriggerFilterExpression)
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/PrimaryDPDFlags_RPVLLStream.py b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/PrimaryDPDFlags_RPVLLStream.py
index a28a56953c3..c0934738ae6 100644
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/PrimaryDPDFlags_RPVLLStream.py
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/PrimaryDPDFlags_RPVLLStream.py
@@ -32,7 +32,6 @@ jobproperties.add_Container(PrimaryDPDFlags_RPVLLStream)
 
 primRPVLLDESDM=jobproperties.PrimaryDPDFlags_RPVLLStream
 
-import DiLepFlags
 import DVFlags
 import KinkedTrackFlags
 import StoppedFlags
@@ -92,7 +91,7 @@ primRPVLLDESDM.add_JobProperty(doQuirks)
 class doHips(JobProperty):
     statusOn = True
     allowedTypes = ["bool"]
-    StoredValue = True
+    StoredValue = False
     pass
 primRPVLLDESDM.add_JobProperty(doHips)
 
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDESDM_DiLep.py b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDESDM_DiLep.py
index c806334bfc4..95d5e6145ed 100644
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDESDM_DiLep.py
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDESDM_DiLep.py
@@ -1,172 +1,85 @@
-# ##########################################################################################
-# Electron/photon/muon augmentation
-# Use the derivation framework tools directly
-# ##########################################################################################
-
-# Cache the container names (used throughout)
-photons   = primRPVLLDESDM.DiLep_containerFlags.photonCollectionName
-electrons = primRPVLLDESDM.DiLep_containerFlags.electronCollectionName
-muons     = primRPVLLDESDM.DiLep_containerFlags.muonCollectionName
-
-# Electron d0
-from LongLivedParticleDPDMaker.LongLivedParticleDPDMakerConf import DerivationFramework__RpvElectronD0Tool
-DiLepElectronD0 = DerivationFramework__RpvElectronD0Tool( name           = "DiLepElectronD0",
-                                                          CollectionName = electrons,
-                                                          SGPrefix       = "DiLep" + electrons,
-                                                        )
-ToolSvc += DiLepElectronD0
-
-# Muon d0
-from LongLivedParticleDPDMaker.LongLivedParticleDPDMakerConf import DerivationFramework__RpvMuonD0Tool
-DiLepMuonD0 = DerivationFramework__RpvMuonD0Tool( name           = "DiLepMuonD0",
-                                                  CollectionName = muons,
-                                                  SGPrefix       = "DiLep" + muons,
-                                                )
-ToolSvc += DiLepMuonD0
-
-# Muon IsMS
-from LongLivedParticleDPDMaker.LongLivedParticleDPDMakerConf import DerivationFramework__RpvMuonMSTool
-DiLepMuonMS = DerivationFramework__RpvMuonMSTool( name           = "DiLepMuonMS",
-                                                  CollectionName = muons,
-                                                  SGPrefix       = "DiLep" + muons,
-                                                )
-ToolSvc += DiLepMuonMS
-
-# PROBLEM! Classes I want to use are not available in AtlasProduction
-# For now, I copied the classes to this package
-
-# Photon IsEM
-# from DerivationFrameworkEGamma.DerivationFrameworkEGammaConf import DerivationFramework__EGammaPassSelectionWrapper
-from LongLivedParticleDPDMaker.LongLivedParticleDPDMakerConf import DerivationFramework__RpvEgammaIDTool
-DiLepPhotonSelection = DerivationFramework__RpvEgammaIDTool( name               = "DiLepPhotonSelection",
-                                                             SelectionVariables = ["Loose", "Tight"],
-                                                             CollectionName     = photons,
-                                                             SGPrefix           = "DiLep" + photons,
-                                                           )
-ToolSvc += DiLepPhotonSelection
-
-# Electron IsEM
-DiLepElectronSelection = DerivationFramework__RpvEgammaIDTool( name               = "DiLepElectronSelection",
-                                                               SelectionVariables = ["Loose", "Medium", "Tight"],
-                                                               CollectionName     = electrons,
-                                                               SGPrefix           = "DiLep" + electrons,
-                                                             )
-ToolSvc += DiLepElectronSelection
-
-# Kernel for the augmentation tools
-from DerivationFrameworkCore.DerivationFrameworkCoreConf import DerivationFramework__DerivationKernel
-topSequence += DerivationFramework__DerivationKernel( "RPVLLAugmentationKernel",
-                                                      AugmentationTools = [DiLepElectronD0, DiLepMuonD0, DiLepMuonMS, DiLepPhotonSelection, DiLepElectronSelection],
-                                                    )
-
-# ##########################################################################################
-# Selection algorithms setup
-# ##########################################################################################
-
-def EgammaSelectionString(flags, container, number = 1):
-    """Construct electron and photon selection string based on the flags provided (from DiLepFlags)
-    """
-
-    cutList = []
-    if flags.cutEtMin:  cutList.append('%s.pt > %s'          % (container, flags.cutEtMin))
-    if flags.cutEtaMax: cutList.append('abs(%s.eta) < %s'    % (container, flags.cutEtaMax))
-    if flags.cutd0Min:  cutList.append('abs(DiLep%sD0) > %s' % (container, flags.cutd0Min))
-    if flags.cutIsEM:   cutList.append('DiLep%s%s'           % (container, flags.cutIsEM))
-
-    cutString = 'count(' + ' && '.join(cutList) + ') > %i' % (number-1)
-    if flags.trigger: cutString = flags.trigger + ' && ' + cutString
-
-    print cutString
-    return cutString
-
-def MuonSelectionString(flags, container, number = 1):
-    """Construct muon selection string based on the flags provided (from DiLepFlags)
-    """
-
-    cutList_combined = []
-    if flags.cutEtMin:  cutList_combined.append('%s.pt > %s'          % (container, flags.cutEtMin))
-    if flags.cutEtaMax: cutList_combined.append('abs(%s.eta) < %s'    % (container, flags.cutEtaMax))
-    if flags.cutd0Min:  cutList_combined.append('abs(DiLep%sD0) > %s' % (container, flags.cutd0Min))
-    cutList_combined.append('DiLep%sisCombined == 1' % (container))
-
-    cutList_msonly = []
-    if flags.cutEtMin:  cutList_msonly.append('%s.pt > %s'       % (container, flags.cutEtMin))
-    if flags.cutEtaMax: cutList_msonly.append('abs(%s.eta) < %s' % (container, flags.cutEtaMax))
-    cutList_msonly.append('DiLep%sisCombined == 0' % (container))
-    cutList_msonly.append('DiLep%sisMS == 1'       % (container))
-
-    cutString = 'count((' + ' && '.join(cutList_combined) + ') || (' + ' && '.join(cutList_msonly) + ')) > %i' % (number-1)
-    if flags.trigger: cutString = flags.trigger + ' && ' + cutString
-
-    print cutString
-    return cutString
-
-from DerivationFrameworkTools.DerivationFrameworkToolsConf import DerivationFramework__xAODStringSkimmingTool as skimtool
 from DerivationFrameworkCore.DerivationFrameworkCoreConf import DerivationFramework__DerivationKernel as kernel
+from LongLivedParticleDPDMaker.LongLivedParticleDPDMakerConf import DerivationFramework__DiLepFilters as filters
+from LongLivedParticleDPDMaker.LongLivedParticleDPDMakerConf import DerivationFramework__DiLepSkim as skim
+
+# ##########################################################################################
+# DiLep filter definitions
+# ##########################################################################################
+
+# define cut values of the filters
+ToolSvc += filters( "DiLepFilters",
+                    
+                    SiPhTrigger   = "HLT_g140_loose",
+                    DiPhTrigger   = "HLT_2g50_loose",
+                    SiMuTrigger   = "HLT_mu60_0eta105_msonly",
+                    
+                    ElEtaMax      = 2.5,
+                    PhEtaMax      = 2.5,
+                    MuEtaMax      = 2.5,
+                    MuBaEtaMax    = 1.07,
+                    
+                    ElD0Min       = 2.0,
+                    MuD0Min       = 1.5,
+                    
+                    SiElPtMin     = 140.,
+                    SiPhPtMin     = 150.,
+                    SiPhXPtMin    =  10.,
+                    SiMuPtMin     =  60.,
+                    DiElPtMin     =  50.,
+                    DiPhPtMin     =  50.,
+                    DiElPhPtMin   =  50.,
+                    DiLoElPhPtMin =  50.
+                  )
+
+# ##########################################################################################
+# Single electron skim tool
+# ##########################################################################################
+
+DiLepSiElectronFilterTool = skim("RPVLL_DiLep_SiElectronSkim", Filter = 1)
+ToolSvc     += DiLepSiElectronFilterTool
+topSequence += kernel( "RPVLL_DiLep_SiElectronFilterKernel",
+                       SkimmingTools = [DiLepSiElectronFilterTool],
+                     )
+RPVLLfilterNames.extend(["RPVLL_DiLep_SiElectronFilterKernel"])
 
 # ##########################################################################################
-# Single photon filter - removed 07/10/15 to reduce rate
-# ##########################################################################################
-###
-###DiLepSinglePhotonFilterTool = skimtool( name       = "DiLepSinglePhotonFilterTool",
-###                                        expression = EgammaSelectionString(primRPVLLDESDM.DiLep_singlePhotonFilterFlags, photons, 1),
-###                                      )
-###ToolSvc     += DiLepSinglePhotonFilterTool
-###topSequence += kernel( "RPVLL_DiLep_SinglePhotonFilterKernel",
-###                       SkimmingTools = [DiLepSinglePhotonFilterTool],
-###                     )
-###RPVLLfilterNames.extend(["RPVLL_DiLep_SinglePhotonFilterKernel"])
-
-# ##########################################################################################
-# Single photon + X filter
+# Single photon + X skim tool
 # ##########################################################################################
 
-pString  = EgammaSelectionString(primRPVLLDESDM.DiLep_singlePhotonFilterFlags, photons, 1)
-apString = EgammaSelectionString(primRPVLLDESDM.DiLep_singlePhotonFilterFlags_addph, photons, 2) # 2 is not a bug! (double counting)
-aeString = EgammaSelectionString(primRPVLLDESDM.DiLep_singlePhotonFilterFlags_addel, electrons, 1)
-amString = MuonSelectionString(primRPVLLDESDM.DiLep_singlePhotonFilterFlags_addmu, muons, 1)
-DiLepSinglePhotonXFilterTool = skimtool( name       = "DiLepSinglePhotonXFilterTool",
-                                         expression = pString + ' && (' + apString + ' || ' + aeString + ' || ' + amString + ')',
-                                       )
-ToolSvc     += DiLepSinglePhotonXFilterTool
-topSequence += kernel( "RPVLL_DiLep_SinglePhotonXFilterKernel",
-                       SkimmingTools = [DiLepSinglePhotonXFilterTool],
+DiLepSiPhotonXFilterTool = skim("RPVLL_DiLep_SiPhotonXSkim", Filter = 2)
+ToolSvc     += DiLepSiPhotonXFilterTool
+topSequence += kernel( "RPVLL_DiLep_SiPhotonXFilterKernel",
+                       SkimmingTools = [DiLepSiPhotonXFilterTool],
                      )
-RPVLLfilterNames.extend(["RPVLL_DiLep_SinglePhotonXFilterKernel"])
+RPVLLfilterNames.extend(["RPVLL_DiLep_SiPhotonXFilterKernel"])
 
 # ##########################################################################################
-# Single electron filter
+# Single muon skim tool
 # ##########################################################################################
 
-DiLepSingleElectronFilterTool = skimtool( name       = "DiLepSingleElectronFilterTool",
-                                          expression = EgammaSelectionString(primRPVLLDESDM.DiLep_singleElectronFilterFlags, electrons, 1),
-                                        )
-ToolSvc     += DiLepSingleElectronFilterTool
-topSequence += kernel( "RPVLL_DiLep_SingleElectronFilterKernel",
-                       SkimmingTools = [DiLepSingleElectronFilterTool],
+DiLepSiMuonFilterTool = skim("RPVLL_DiLep_SiMuonSkim", Filter = 3)
+ToolSvc     += DiLepSiMuonFilterTool
+topSequence += kernel( "RPVLL_DiLep_SiMuonFilterKernel",
+                       SkimmingTools = [DiLepSiMuonFilterTool],
                      )
-RPVLLfilterNames.extend(["RPVLL_DiLep_SingleElectronFilterKernel"])
+RPVLLfilterNames.extend(["RPVLL_DiLep_SiMuonFilterKernel"])
 
 # ##########################################################################################
-# Single muon filter
+# Di electron skim tool
 # ##########################################################################################
 
-DiLepSingleMuonFilterTool = skimtool( name       = "DiLepSingleMuonFilterTool",
-                                      expression = MuonSelectionString(primRPVLLDESDM.DiLep_singleMuonFilterFlags, muons, 1),
-                                    )
-ToolSvc     += DiLepSingleMuonFilterTool
-topSequence += kernel( "RPVLL_DiLep_SingleMuonFilterKernel",
-                       SkimmingTools = [DiLepSingleMuonFilterTool],
+DiLepDiElectronFilterTool = skim("RPVLL_DiLep_DiElectronSkim", Filter = 4)
+ToolSvc     += DiLepDiElectronFilterTool
+topSequence += kernel( "RPVLL_DiLep_DiElectronFilterKernel",
+                       SkimmingTools = [DiLepDiElectronFilterTool],
                      )
-RPVLLfilterNames.extend(["RPVLL_DiLep_SingleMuonFilterKernel"])
+RPVLLfilterNames.extend(["RPVLL_DiLep_DiElectronFilterKernel"])
 
 # ##########################################################################################
-# Double photon filter
+# Di photon skim tool
 # ##########################################################################################
 
-DiLepDiPhotonFilterTool = skimtool( name       = "DiLepDiPhotonFilterTool",
-                                    expression = EgammaSelectionString(primRPVLLDESDM.DiLep_diPhotonFilterFlags, photons, 2),
-                                  )
+DiLepDiPhotonFilterTool = skim("RPVLL_DiLep_DiPhotonSkim", Filter = 5)
 ToolSvc     += DiLepDiPhotonFilterTool
 topSequence += kernel( "RPVLL_DiLep_DiPhotonFilterKernel",
                        SkimmingTools = [DiLepDiPhotonFilterTool],
@@ -174,41 +87,19 @@ topSequence += kernel( "RPVLL_DiLep_DiPhotonFilterKernel",
 RPVLLfilterNames.extend(["RPVLL_DiLep_DiPhotonFilterKernel"])
 
 # ##########################################################################################
-# Double electron filter
+# Di electron+photon skim tools
 # ##########################################################################################
 
-DiLepDiElectronFilterTool = skimtool( name       = "DiLepDiElectronFilterTool",
-                                      expression = EgammaSelectionString(primRPVLLDESDM.DiLep_diElectronFilterFlags, electrons, 2),
-                                    )
-ToolSvc     += DiLepDiElectronFilterTool
-topSequence += kernel( "RPVLL_DiLep_DiElectronFilterKernel",
-                       SkimmingTools = [DiLepDiElectronFilterTool],
-                     )
-RPVLLfilterNames.extend(["RPVLL_DiLep_DiElectronFilterKernel"])
-
-# ##########################################################################################
-# Double electron+photon filters
-# ##########################################################################################
-
-eString = EgammaSelectionString(primRPVLLDESDM.DiLep_diEgammaFilterFlags_electron, electrons, 1)
-gString = EgammaSelectionString(primRPVLLDESDM.DiLep_diEgammaFilterFlags_photon, photons, 1)
-DiLepDiEgammaFilterTool = skimtool( name       = "DiLepDiEgammaFilterTool",
-                                    expression = eString + ' && ' + gString,
-                                  )
-ToolSvc     += DiLepDiEgammaFilterTool
-topSequence += kernel( "RPVLL_DiLep_DiEgammaFilterKernel",
-                       SkimmingTools = [DiLepDiEgammaFilterTool],
+DiLepDiElPhFilterTool = skim("RPVLL_DiLep_DiElPhSkim", Filter = 6)
+ToolSvc     += DiLepDiElPhFilterTool
+topSequence += kernel( "RPVLL_DiLep_DiElPhFilterKernel",
+                       SkimmingTools = [DiLepDiElPhFilterTool],
                      )
-RPVLLfilterNames.extend(["RPVLL_DiLep_DiEgammaFilterKernel"])
+RPVLLfilterNames.extend(["RPVLL_DiLep_DiElPhFilterKernel"])
 
-eLString = EgammaSelectionString(primRPVLLDESDM.DiLep_diLooseEgammaFilterFlags_electron, electrons, 1)
-gLString = EgammaSelectionString(primRPVLLDESDM.DiLep_diLooseEgammaFilterFlags_photon, photons, 1)
-DiLepDiLooseEgammaFilterTool = skimtool( name       = "DiLepDiLooseEgammaFilterTool",
-                                         expression = eLString + ' && ' + gLString,
-                                       )
-ToolSvc     += DiLepDiLooseEgammaFilterTool
-topSequence += kernel( "RPVLL_DiLep_DiLooseEgammaFilterKernel",
-                       SkimmingTools = [DiLepDiLooseEgammaFilterTool],
+DiLepDiLoElPhFilterTool = skim("RPVLL_DiLep_DiLoElPhSkim", Filter = 7)
+ToolSvc     += DiLepDiLoElPhFilterTool
+topSequence += kernel( "RPVLL_DiLep_DiLoElPhFilterKernel",
+                       SkimmingTools = [DiLepDiLoElPhFilterTool],
                      )
-RPVLLfilterNames.extend(["RPVLL_DiLep_DiLooseEgammaFilterKernel"])
-
+RPVLLfilterNames.extend(["RPVLL_DiLep_DiLoElPhFilterKernel"])
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDESDM_Hips.py b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDESDM_Hips.py
index dc6c39abcb4..701bf7f4d91 100644
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDESDM_Hips.py
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDESDM_Hips.py
@@ -1,12 +1,21 @@
+
+#############################################################################################
+##### NOTE!! this file is the one called when using the HIPs filter as part of the DESDM_RPVLL.
+#####  This has been superseded by PhysDPD_HIPs.py which makes a standalone DESD_HIPS format.
+##############################################################################################
+
+
 from DerivationFrameworkTools.DerivationFrameworkToolsConf import DerivationFramework__xAODStringSkimmingTool as skimtool
 from DerivationFrameworkCore.DerivationFrameworkCoreConf import DerivationFramework__DerivationKernel as kernel
+from LongLivedParticleDPDMaker.HipsFlags import primHIPsDESD
 
 # ##########################################################################################
 # HIP trigger filter
 # ##########################################################################################
 
 HipTriggerFilterTool = skimtool( name = "HipTriggerFilterTool",
-                                 expression = 'HLT_g0_hiptrt_L1EM18VH || HLT_g0_hiptrt_L1EM20VH || HLT_g0_hiptrt_L1EM20VHI || HLT_g0_hiptrt_L1EM22VHI' )
+                                 expression = primHIPsDESD.HipsTriggerFilterExpression())
+
 
 ToolSvc += HipTriggerFilterTool
 topSequence += kernel( "RPVLL_HipTriggerFilterKernel",
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDESDM_RPVLL.py b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDESDM_RPVLL.py
index 77878b39d85..816499d50a6 100644
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDESDM_RPVLL.py
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDESDM_RPVLL.py
@@ -68,6 +68,7 @@ if primRPVLLDESDM.doStopped():
     pass
 
 ## Highly ionizing particles search (contact: Avishek Chatterjee)
+### Now has it's own stream.
 if primRPVLLDESDM.doHips():
     include("LongLivedParticleDPDMaker/PhysDESDM_Hips.py")
     pass
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDPD_HIPs.py b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDPD_HIPs.py
new file mode 100644
index 00000000000..5dca6fb7f8a
--- /dev/null
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDPD_HIPs.py
@@ -0,0 +1,63 @@
+##-----------------------------------------------------------------------------
+## Name: PhysDPD_HIPs.py
+##
+## Description: Separating out the HIPs filters from the DESDM_RPVLL to their own stream.
+##
+##-----------------------------------------------------------------------------
+
+# ##########################################################################################
+# Imports and initial setup
+# ##########################################################################################
+
+from OutputStreamAthenaPool.MultipleStreamManager import MSMgr
+from PrimaryDPDMaker.PrimaryDPDHelpers import buildFileName
+from PrimaryDPDMaker.PrimaryDPDFlags import primDPD
+
+from LongLivedParticleDPDMaker.HipsFlags import primHIPsDESD
+
+streamName = primDPD.WriteDESD_HIPsStream.StreamName
+fileName   = buildFileName( primDPD.WriteDESD_HIPsStream )
+HIPsStream      = MSMgr.NewPoolStream( streamName,fileName )
+
+
+from DerivationFrameworkTools.DerivationFrameworkToolsConf import DerivationFramework__xAODStringSkimmingTool as skimtool
+from DerivationFrameworkCore.DerivationFrameworkCoreConf import DerivationFramework__DerivationKernel as kernel
+
+HIPsFilterNames = [] # Filters should append their final selection algo names to this list
+filtersToBookkeep = [] # Not sure what this does?
+
+
+HipTriggerFilterTool = skimtool( name = "HipTriggerFilterTool",
+                                 expression = primHIPsDESD.HipsTriggerFilterExpression())
+
+ToolSvc += HipTriggerFilterTool
+
+topSequence += kernel( "HIPsTriggerFilterKernel",
+                       SkimmingTools = [HipTriggerFilterTool] )
+
+HIPsFilterNames.extend(["HIPsTriggerFilterKernel"])
+
+################# OR together all the filters into one, if at least one analysis selection is active
+
+HIPsStream.AcceptAlgs(HIPsFilterNames)
+
+
+
+# ##########################################################################################
+# Output stream definition
+# ##########################################################################################
+
+# Add everything from the input file
+from AthenaCommon.KeyStore import CfgKeyStore,CfgItemList
+theCKS = CfgKeyStore('KeyStore')
+outList = CfgItemList( 'HIPsStream' )
+outList += theCKS['inputFile']
+
+# Remove items here, as needed
+outList.removeAllItems( 'RpcPadContainer#RPCPAD' ) # Avoids crash in 20.1.0.2
+
+# Configure the stream
+HIPsStream.AddItem(outList())
+
+# make sure bookkeeping info is kept for additional filters
+HIPsStream.AddOtherAlgsToBookkeep(filtersToBookkeep)
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDRAW_RPVLL.py b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDRAW_RPVLL.py
new file mode 100644
index 00000000000..42c6ccbdd43
--- /dev/null
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/share/PhysDRAW_RPVLL.py
@@ -0,0 +1,116 @@
+##-----------------------------------------------------------------------------
+## Name: PhysDESDM_RPVLL.py
+##
+## Author: Nick Barlow (Cambridge)
+## Email:  Nicholas.Robert.Barlow@cern.ch
+## Author: Christian Ohm (Stockholm)
+## Email:  Christian.Ohm@cern.ch
+## Author: Mike Flowerdew (Munich MPI)
+## Email:  Michael.Flowerdew@cern.ch
+##
+## Description: This defines the content of the DRAW_RPVLL output stream.
+##
+##-----------------------------------------------------------------------------
+
+# ##########################################################################################
+# Imports and initial setup
+# ##########################################################################################
+
+
+
+from LongLivedParticleDPDMaker.LongLivedDPDFlags import WriteRPVLLStream
+from LongLivedParticleDPDMaker.PrimaryDPDFlags_RPVLLStream import primRPVLLDESDM
+ 
+RPVLL_augmentationKernels = []
+
+RPVLL_filterTools = []
+
+
+RPVLLfilterNames = [] # Filters should append their final selection algo names to this list
+filtersToBookkeep = [] # Not sure what this does?
+
+# ##########################################################################################
+# Filter configuration
+# ##########################################################################################
+
+## For each analysis, include a job options file that defines the filter 
+## for that analysis and adds it to the top filter
+
+# ##########################################################################################
+# First, the filters which are *definitely* planned for Run 2
+
+
+
+## Dilepton search (contact Mike Flowerdew)
+if primRPVLLDESDM.doDiLep():
+    include("LongLivedParticleDPDMaker/PhysDESDM_DiLep.py")
+    pass
+
+## RPV search based on displaced vertex finding in the ID (contact: Nick Barlow)
+if primRPVLLDESDM.doDV():
+    include("LongLivedParticleDPDMaker/PhysDESDM_DV.py")
+    pass
+
+# Kink-based chargino search (contact: Shimpei Yamamoto)
+if primRPVLLDESDM.doKinkedTrack():
+    include("LongLivedParticleDPDMaker/PhysDESDM_KinkedTrack.py")
+    pass
+
+## Stopped R-hadron search (contact: Andy Haas)
+if primRPVLLDESDM.doStopped():
+    include("LongLivedParticleDPDMaker/PhysDESDM_Stopped.py")
+    pass
+
+## Highly ionizing particles search (contact: Avishek Chatterjee)
+if primRPVLLDESDM.doHips():
+    include("LongLivedParticleDPDMaker/PhysDESDM_Hips.py")
+    pass
+
+## Heavy neutral lepton search (contact: Avishek Chatterjee)
+if primRPVLLDESDM.doHnl():
+    include("LongLivedParticleDPDMaker/PhysDESDM_HNL.py")
+    pass
+
+# Exotics displaced hadronic jets =search (contact: Heather Russell)
+if primRPVLLDESDM.doHV():
+    include("LongLivedParticleDPDMaker/PhysDESDM_HV.py")
+    pass
+
+
+### output stream
+
+from OutputStreamAthenaPool.MultipleStreamManager import MSMgr
+
+from PrimaryDPDMaker.PrimaryDPDHelpers import buildFileName
+from PrimaryDPDMaker.PrimaryDPDFlags import primDPD
+
+streamName = primDPD.WriteRAWPhysDPD_RPVLL.StreamName
+fileName   = buildFileName( primDPD.WriteRAWPhysDPD_RPVLL )
+
+if fileName.endswith(".pool.root") :
+    fileName = fileName.rstrip(".pool.root")
+    fileName+=".dat"
+    pass
+if fileName.endswith("root") :
+    fileName = fileName.rstrip(".root")
+    fileName+=".dat"
+    pass
+RPVLL = MSMgr.NewByteStream( streamName, fileName )
+RPVLL.bsOutputSvc.WriteEventlessFiles = primDPD.WriteEventlessFiles()
+
+RPVLL.AddAcceptAlgs(RPVLLfilterNames)
+
+#########################################
+# Add the containers to the output stream
+#########################################
+from PrimaryDPDMaker import PrimaryDPD_OutputDefinitions as dpdOutput
+
+# Take everything from the input
+ExcludeList=[]
+dpdOutput.addAllItemsFromInputExceptExcludeList(streamName,ExcludeList)
+
+
+
+
+
+
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/DiLepFilters.cxx b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/DiLepFilters.cxx
new file mode 100644
index 00000000000..2452b030bb7
--- /dev/null
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/DiLepFilters.cxx
@@ -0,0 +1,272 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+/////////////////////////////////////////////////////////////////
+// DiLepFilters.cxx, (c) ATLAS Detector software
+/////////////////////////////////////////////////////////////////
+// Author: Dominik Krauss (krauss@mpp.mpg.de)
+
+#include "LongLivedParticleDPDMaker/DiLepFilters.h"
+
+DerivationFramework::DiLepFilters::DiLepFilters(const std::string& t, const std::string& n, const IInterface* p)
+                                               : AthAlgTool(t, n, p), m_tdt("Trig::TrigDecisionTool/TrigDecisionTool"),
+                                                 m_trig_siph(""), m_trig_diph(""), m_trig_simu(""),
+                                                 m_pass_siph(false), m_pass_diph(false), m_pass_simu(false),
+                                                 m_el_eta(0.), m_ph_eta(0.), m_mu_eta(0.), m_mu_beta(0.),
+                                                 m_el_d0(0.), m_mu_d0(0.),
+                                                 m_siel_pt(0.), m_siph_pt(0.), m_siph_xpt(0.), m_simu_pt(0.),
+                                                 m_diel_pt(0.), m_diph_pt(0.), m_dielph_pt(0.), m_diloelph_pt(0.)
+{
+  declareInterface<IDiLepFilters>(this);
+
+  declareProperty("TrigDecisionTool", m_tdt);
+
+  declareProperty("SiPhTrigger", m_trig_siph);
+  declareProperty("DiPhTrigger", m_trig_diph);
+  declareProperty("SiMuTrigger", m_trig_simu);
+
+  declareProperty("ElEtaMax", m_el_eta);
+  declareProperty("PhEtaMax", m_ph_eta);
+  declareProperty("MuEtaMax", m_mu_eta);
+  declareProperty("MuBaEtaMax", m_mu_beta);
+
+  declareProperty("ElD0Min", m_el_d0);
+  declareProperty("MuD0Min", m_mu_d0);
+
+  declareProperty("SiElPtMin", m_siel_pt);
+  declareProperty("SiPhPtMin", m_siph_pt);
+  declareProperty("SiPhXPtMin", m_siph_xpt);
+  declareProperty("SiMuPtMin", m_simu_pt);
+  declareProperty("DiElPtMin", m_diel_pt);
+  declareProperty("DiPhPtMin", m_diph_pt);
+  declareProperty("DiElPhPtMin", m_dielph_pt);
+  declareProperty("DiLoElPhPtMin", m_diloelph_pt);
+}
+
+StatusCode DerivationFramework::DiLepFilters::initialize()
+{
+  ATH_MSG_VERBOSE("initialize() ...");
+
+  CHECK(m_tdt.retrieve());
+
+  return StatusCode::SUCCESS;
+}
+
+bool DerivationFramework::DiLepFilters::GetTriggers()
+{
+  m_pass_siph = m_tdt->isPassed(m_trig_siph);
+  m_pass_diph = m_tdt->isPassed(m_trig_diph);
+  m_pass_simu = m_tdt->isPassed(m_trig_simu);
+
+  return m_pass_siph || m_pass_diph || m_pass_simu;
+}
+
+bool DerivationFramework::DiLepFilters::PassSiEl(const xAOD::Electron& el) const
+{
+  if(!m_pass_siph) return false;
+
+  return PassCuts(el, m_siel_pt);
+}
+
+bool DerivationFramework::DiLepFilters::PassSiPhX(const xAOD::Photon& ph, const xAOD::Electron& el) const
+{
+  if(!m_pass_siph) return false;
+
+  if(SameCluster(ph, el)) return false;
+
+  if(!PassCuts(ph, m_siph_pt)) return false;
+  if(!PassCuts(el, m_siph_xpt)) return false;
+
+  return true;
+}
+
+bool DerivationFramework::DiLepFilters::PassSiPhX(const xAOD::Photon& ph1, const xAOD::Photon& ph2) const
+{
+  if(!m_pass_siph) return false;
+
+  if(SameCluster(ph1, ph2)) return false;
+
+  if(PassCuts(ph1, m_siph_pt) && PassCuts(ph2, m_siph_xpt)) return true;
+  if(PassCuts(ph2, m_siph_pt) && PassCuts(ph1, m_siph_xpt)) return true;
+
+  return false;
+}
+
+bool DerivationFramework::DiLepFilters::PassSiPhX(const xAOD::Photon& ph, const xAOD::Muon& mu) const
+{
+  if(!m_pass_siph) return false;
+
+  if(!PassCuts(ph, m_siph_pt)) return false;
+  if(!PassCuts(mu, m_siph_xpt, m_mu_eta)) return false;
+
+  return true;
+}
+
+bool DerivationFramework::DiLepFilters::PassSiMu(const xAOD::Muon& mu) const
+{
+  if(!m_pass_simu) return false;
+
+  return PassCuts(mu, m_simu_pt, m_mu_beta);
+}
+
+bool DerivationFramework::DiLepFilters::PassDiEl(const xAOD::Electron& el1, const xAOD::Electron& el2) const
+{
+  if(!m_pass_diph) return false;
+
+  if(SameCluster(el1, el2)) return false;
+
+  if(!PassCuts(el1, m_diel_pt)) return false;
+  if(!PassCuts(el2, m_diel_pt)) return false;
+
+  return true;
+}
+
+bool DerivationFramework::DiLepFilters::PassDiPh(const xAOD::Photon& ph1, const xAOD::Photon& ph2) const
+{
+  if(!m_pass_diph) return false;
+
+  if(SameCluster(ph1, ph2)) return false;
+
+  if(!PassCuts(ph1, m_diph_pt)) return false;
+  if(!PassCuts(ph2, m_diph_pt)) return false;
+
+  return true;
+}
+
+bool DerivationFramework::DiLepFilters::PassDiElPh(const xAOD::Electron& el, const xAOD::Photon& ph) const
+{
+  if(!m_pass_diph) return false;
+
+  if(SameCluster(el, ph)) return false;
+
+  if(!PassCuts(el, m_dielph_pt)) return false;
+  if(!PassCuts(ph, m_dielph_pt)) return false;
+
+  return true;
+}
+
+bool DerivationFramework::DiLepFilters::PassDiLoElPh(const xAOD::Electron& el, const xAOD::Photon& ph) const
+{
+  if(!m_pass_diph) return false;
+
+  if(SameCluster(el, ph)) return false;
+
+  if(!PassCuts(el, m_diloelph_pt, true)) return false;
+  if(!PassCuts(ph, m_diloelph_pt)) return false;
+
+  return true;
+}
+
+bool DerivationFramework::DiLepFilters::PassEta(const xAOD::IParticle& part, double eta_cut) const
+{
+  return std::fabs(part.eta()) < eta_cut;
+}
+
+bool DerivationFramework::DiLepFilters::Passd0(const xAOD::Electron& el, double d0_cut) const
+{
+  const xAOD::TrackParticle* el_tr = el.trackParticle();
+  if(el_tr == nullptr)
+  {
+    ATH_MSG_WARNING("Could not retrieve electron track!");
+    return false;
+  }
+
+  return std::fabs(el_tr->d0()) > d0_cut;
+}
+
+bool DerivationFramework::DiLepFilters::Passd0(const xAOD::Muon& mu, double d0_cut) const
+{
+  const xAOD::TrackParticle* mu_tr = mu.trackParticle(xAOD::Muon::InnerDetectorTrackParticle);
+  if(mu_tr == nullptr)
+  {
+    ATH_MSG_WARNING("Could not retrieve muon ID track!");
+    return false;
+  }
+
+  return std::fabs(mu_tr->d0()) > d0_cut;
+}
+
+bool DerivationFramework::DiLepFilters::IsLoose(const xAOD::Egamma& eg) const
+{
+  bool isLoose = false;
+  eg.passSelection(isLoose, "Loose");
+  return isLoose;
+}
+
+bool DerivationFramework::DiLepFilters::SameCluster(const xAOD::Egamma& eg1, const xAOD::Egamma& eg2) const
+{
+  const xAOD::CaloCluster* calo1 = eg1.caloCluster();
+  const xAOD::CaloCluster* calo2 = eg2.caloCluster();
+  if(calo1 == nullptr || calo2 == nullptr)
+  {
+    ATH_MSG_WARNING("Could not retrieve CaloCluster!");
+    return false;
+  }
+
+  return calo1->p4().DeltaR(calo2->p4()) < 0.01;
+}
+
+bool DerivationFramework::DiLepFilters::IsGood(const xAOD::Muon& mu) const
+{
+  if(mu.muonType() != xAOD::Muon::Combined) return false;
+
+  float chi2 = 0.;
+  if(!mu.parameter(chi2, xAOD::Muon::msInnerMatchChi2)) return false;
+
+  int dof = 1;
+  if(!mu.parameter(dof, xAOD::Muon::msInnerMatchDOF)) return false;
+  if(dof == 0) dof = 1;
+
+  return (chi2 / static_cast<float>(dof)) < 5.;
+}
+
+bool DerivationFramework::DiLepFilters::PassCuts(const xAOD::Electron& el, double pt_cut, bool loose) const
+{
+  if(el.pt() < pt_cut * m_GeVtoMeV) return false;
+  if(!PassEta(el, m_el_eta)) return false;
+
+  if(loose)
+  {
+    if(!IsLoose(el)) return false;
+  }
+  else
+  {
+    if(!Passd0(el, m_el_d0)) return false;
+  }
+
+  return true;
+}
+
+bool DerivationFramework::DiLepFilters::PassCuts(const xAOD::Photon& ph, double pt_cut) const
+{
+  if(ph.pt() < pt_cut * m_GeVtoMeV) return false;
+  if(!PassEta(ph, m_ph_eta)) return false;
+  if(!IsLoose(ph)) return false;
+
+  return true;
+}
+
+bool DerivationFramework::DiLepFilters::PassCuts(const xAOD::Muon& mu, double pt_cut, double eta_cut) const
+{
+  const xAOD::IParticle* mu_ip = nullptr;
+
+  if(IsGood(mu))
+  {
+    if(!Passd0(mu, m_mu_d0)) return false;
+
+    mu_ip = &mu;
+  }
+  else
+  {
+    const xAOD::TrackParticle* mu_mstr = mu.trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle);
+    if(mu_mstr == nullptr) return false;
+
+    mu_ip = mu_mstr;
+  }
+
+  if(mu_ip->pt() < pt_cut * m_GeVtoMeV) return false;
+  if(!PassEta(*mu_ip, eta_cut)) return false;
+
+  return true;
+}
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/DiLepSkimTools.cxx b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/DiLepSkimTools.cxx
new file mode 100644
index 00000000000..f8dabf30626
--- /dev/null
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/DiLepSkimTools.cxx
@@ -0,0 +1,124 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+/////////////////////////////////////////////////////////////////
+// DiLepSkimTools.cxx, (c) ATLAS Detector software
+/////////////////////////////////////////////////////////////////
+// Author: Dominik Krauss (krauss@mpp.mpg.de)
+
+#include "LongLivedParticleDPDMaker/DiLepSkimTools.h"
+
+DerivationFramework::DiLepSkim::DiLepSkim(const std::string& t, const std::string& n, const IInterface* p)
+                                         : AthAlgTool(t, n, p), m_dlf("DerivationFramework::DiLepFilters/DiLepFilters"),
+                                           m_filter_prop(0), m_filter(Filters::None)
+{
+  declareInterface<DerivationFramework::ISkimmingTool>(this);
+  declareProperty("Filter", m_filter_prop);
+}
+
+StatusCode DerivationFramework::DiLepSkim::initialize()
+{
+  ATH_MSG_VERBOSE("initialize() ...");
+
+  CHECK(m_dlf.retrieve());
+
+  m_filter = static_cast<Filters>(m_filter_prop);
+  if(m_filter == Filters::None)
+  {
+    ATH_MSG_ERROR("No DESD filter specified!");
+    return StatusCode::FAILURE;
+  }
+
+  return StatusCode::SUCCESS;
+}
+
+bool DerivationFramework::DiLepSkim::eventPassesFilter() const
+{
+  // we check the filters only if at least one trigger is passed
+  if(!m_dlf->GetTriggers()) return false;
+
+  // retrieve particle containers
+  const xAOD::ElectronContainer* elc = nullptr;
+  CHECK(evtStore()->retrieve(elc, "Electrons"));
+  const xAOD::MuonContainer* muc = nullptr;
+  CHECK(evtStore()->retrieve(muc, "Muons"));
+  const xAOD::PhotonContainer* phc = nullptr;
+  CHECK(evtStore()->retrieve(phc, "Photons"));
+
+  // loop over containers and check filters
+  if(m_filter == Filters::SiEl)
+  {
+    for(const xAOD::Electron* el: *elc)
+    {
+      if(m_dlf->PassSiEl(*el)) return true;
+    }
+  }
+  else if(m_filter == Filters::SiPhX)
+  {
+    for(auto ph1 = phc->cbegin(); ph1 != phc->cend(); ph1++)
+    {
+      for(const xAOD::Electron* el: *elc)
+      {
+        if(m_dlf->PassSiPhX(**ph1, *el)) return true;
+      }
+      for(auto ph2 = ph1+1; ph2 != phc->cend(); ph2++)
+      {
+        if(m_dlf->PassSiPhX(**ph1, **ph2)) return true;
+      }
+      for(const xAOD::Muon* mu: *muc)
+      {
+        if(m_dlf->PassSiPhX(**ph1, *mu)) return true;
+      }
+    }
+  }
+  else if(m_filter == Filters::SiMu)
+  {
+    for(const xAOD::Muon* mu: *muc)
+    {
+      if(m_dlf->PassSiMu(*mu)) return true;
+    }
+  }
+  else if(m_filter == Filters::DiEl)
+  {
+    for(auto el1 = elc->cbegin(); el1 != elc->cend(); el1++)
+    {
+      for(auto el2 = el1+1; el2 != elc->cend(); el2++)
+      {
+        if(m_dlf->PassDiEl(**el1, **el2)) return true;
+      }
+    }
+  }
+  else if(m_filter == Filters::DiPh)
+  {
+    for(auto ph1 = phc->cbegin(); ph1 != phc->cend(); ph1++)
+    {
+      for(auto ph2 = ph1+1; ph2 != phc->cend(); ph2++)
+      {
+        if(m_dlf->PassDiPh(**ph1, **ph2)) return true;
+      }
+    }
+  }
+  else if(m_filter == Filters::DiElPh)
+  {
+    for(const xAOD::Electron* el: *elc)
+    {
+      for(const xAOD::Photon* ph: *phc)
+      {
+        if(m_dlf->PassDiElPh(*el, *ph)) return true;
+      }
+    }
+  }
+  else if(m_filter == Filters::DiLoElPh)
+  {
+    for(const xAOD::Electron* el: *elc)
+    {
+      for(const xAOD::Photon* ph: *phc)
+      {
+        if(m_dlf->PassDiLoElPh(*el, *ph)) return true;
+      }
+    }
+  }
+
+  return false;
+}
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/KinkTrkZeeTagTool.cxx b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/KinkTrkZeeTagTool.cxx
index a06f5e22374..74fb3f483a9 100644
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/KinkTrkZeeTagTool.cxx
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/KinkTrkZeeTagTool.cxx
@@ -119,6 +119,9 @@ StatusCode DerivationFramework::KinkTrkZeeTagTool::addBranches() const
   std::string sgKey1(m_sgKeyPrefix+"DiEleMass");
   if (evtStore()->contains< float >(sgKey1)) {
     ATH_MSG_ERROR("StoreGate key " << sgKey1 << "already exists.");
+    // avoid mem leak
+    delete probeEleEt;
+    delete diEleMass;
     return StatusCode::FAILURE;
   }
   CHECK(evtStore()->record(diEleMass, sgKey1));
@@ -126,6 +129,7 @@ StatusCode DerivationFramework::KinkTrkZeeTagTool::addBranches() const
   std::string sgKey2(m_sgKeyPrefix+"ProbeEleEt");
   if (evtStore()->contains< float >(sgKey2)) {
     ATH_MSG_ERROR("StoreGate key " << sgKey2 << "already exists.");
+    delete probeEleEt; // avoid mem leak
     return StatusCode::FAILURE;
   }
   CHECK(evtStore()->record(probeEleEt, sgKey2));
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/KinkTrkZmumuTagTool.cxx b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/KinkTrkZmumuTagTool.cxx
index e3836323b8d..988c1c6d970 100644
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/KinkTrkZmumuTagTool.cxx
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/KinkTrkZmumuTagTool.cxx
@@ -124,12 +124,17 @@ StatusCode DerivationFramework::KinkTrkZmumuTagTool::addBranches() const
   // Writing to SG
   if (evtStore()->contains< float >(sgKey1)) {
     ATH_MSG_ERROR("StoreGate key " << sgKey1 << "already exists.");
+    // avoid mem leak
+    delete diMuonTrkMass;
+    delete probeMuPt;
     return StatusCode::FAILURE;
   }
   CHECK(evtStore()->record(diMuonTrkMass, sgKey1));
 
   if (evtStore()->contains< float >(sgKey2)) {
     ATH_MSG_ERROR("StoreGate key " << sgKey2 << "already exists.");
+    // avoid mem leak
+    delete probeMuPt;
     return StatusCode::FAILURE;
   }
   CHECK(evtStore()->record(probeMuPt, sgKey2));
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RPVLLTestRates.cxx b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RPVLLTestRates.cxx
index 4a0161e8d74..609f65c764a 100755
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RPVLLTestRates.cxx
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RPVLLTestRates.cxx
@@ -15,7 +15,11 @@
 
 RPVLLTestRates::RPVLLTestRates(const std::string& name, ISvcLocator* pSvcLocator) :
   AthAlgorithm(name, pSvcLocator),
+  m_EventCounter(0),
   m_tHistSvc("THistSvc",name),
+  m_myTree(0),
+  m_skimPassHist(0),
+  m_twoDskimHist(0),
   m_runNum(0),
   m_lumiBlock(0),
   m_evtNum(0)
@@ -34,11 +38,9 @@ RPVLLTestRates::~RPVLLTestRates() {}
 
 StatusCode RPVLLTestRates::initialize() {
 
-  StatusCode sc = service("StoreGateSvc/InputMetaDataStore", m_MetaDataStore);
-  if(sc.isFailure()) return StatusCode::FAILURE;
   m_EventCounter=0;
 
-  sc = m_tHistSvc.retrieve();
+  StatusCode sc = m_tHistSvc.retrieve();
   if (sc.isFailure()) return StatusCode::FAILURE;
 
   m_myTree= new TTree("myTree","myTree");
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RpvElectronD0Tool.cxx b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RpvElectronD0Tool.cxx
index 005aaee7849..6f0fac01a51 100644
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RpvElectronD0Tool.cxx
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RpvElectronD0Tool.cxx
@@ -73,6 +73,7 @@ StatusCode DerivationFramework::RpvElectronD0Tool::addBranches() const
 
      if (evtStore()->contains<std::vector<float> >(sgKey)) {
        ATH_MSG_ERROR("Tool is attempting to write a StoreGate key " << sgKey << " which already exists. Please use a different key");
+       delete d0vec; // avoid mem leak
        return StatusCode::FAILURE;
      }
      CHECK(evtStore()->record(d0vec, sgKey));       
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RpvMuonD0Tool.cxx b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RpvMuonD0Tool.cxx
index 2e313ace8ba..b3481ecc039 100644
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RpvMuonD0Tool.cxx
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RpvMuonD0Tool.cxx
@@ -62,23 +62,38 @@ StatusCode DerivationFramework::RpvMuonD0Tool::addBranches() const
      for (xAOD::MuonContainer::const_iterator muIt = muons->begin(); muIt!=muons->end(); ++muIt) {
        
        float d0 = 9e99;
+	 
        // Alternative: (*muIt)->trackParticle( xAOD::Muon::InnerDetectorTrackParticle ) ?
        if (*muIt && (*muIt)->primaryTrackParticle()) d0 = (*muIt)->primaryTrackParticle()->d0();
-       else ATH_MSG_WARNING("Problem accessing muon track!");
+       else ATH_MSG_WARNING("Problem accessing muon track!");	 
        
        d0vec->push_back(d0);
-       //// is it a combined muon?
-       if ((*muIt)->muonType()==xAOD::Muon::Combined) isCombinedVec->push_back(1);
-       else isCombinedVec->push_back(0);
+       //// is it a combined muon?  /// NEW - also see if it has a bad chisq for ID trk match - if so, treat it as standalone (i.e. don't apply d0 cut)
+       bool isGoodCombined = false;
        
-
-     }     
-
+       if ((*muIt)->muonType()==xAOD::Muon::Combined) {
+	 float chi2 = 0.;
+	 if (!(*muIt)->parameter(chi2, xAOD::Muon::msInnerMatchChi2)) ATH_MSG_WARNING("Problem accessing muon chisq!");
+	 int dof = 1;
+	 if (!(*muIt)->parameter(dof,xAOD::Muon::msInnerMatchDOF)) ATH_MSG_WARNING("Problem accessing muon DoF!");
+	 if (dof == 0) dof = 1;
+	 if (chi2/float(dof) < 5.)  isGoodCombined = true;  ///  MS <==> ID match - require good chisq
+       }
+       if (isGoodCombined) {
+	   isCombinedVec->push_back(1); 
+       } else {
+	 isCombinedVec->push_back(0);  /// either not combined, or bad chisq.
+       }     
+     }
+     
      // Write decision to SG for access by downstream algs 
      std::string sgKey(m_sgPrefix+"D0");
 
      if (evtStore()->contains<std::vector<float> >(sgKey)) {
        ATH_MSG_ERROR("Tool is attempting to write a StoreGate key " << sgKey << " which already exists. Please use a different key");
+       // avoid mem leak
+       delete d0vec; 
+       delete isCombinedVec;
        return StatusCode::FAILURE;
      }
      CHECK(evtStore()->record(d0vec, sgKey)); 
@@ -87,14 +102,11 @@ StatusCode DerivationFramework::RpvMuonD0Tool::addBranches() const
 
      if (evtStore()->contains<std::vector<int> >(sgKey)) {
        ATH_MSG_ERROR("Tool is attempting to write a StoreGate key " << sgKey << " which already exists. Please use a different key");
+       delete isCombinedVec; // avoid mem leak
        return StatusCode::FAILURE;
      }
      CHECK(evtStore()->record(isCombinedVec, sgKey));       
-
-     
-
      
      return StatusCode::SUCCESS;
-
 }
 
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RpvMuonMSTool.cxx b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RpvMuonMSTool.cxx
deleted file mode 100644
index e0c29a34b5d..00000000000
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RpvMuonMSTool.cxx
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
-*/
-
-///////////////////////////////////////////////////////////////////
-// RpvMuonMSTool.cxx, (c) ATLAS Detector software
-///////////////////////////////////////////////////////////////////
-// Authors: Mike Flowerdew (Michael.Flowerdew@cern.ch), Dominik Krauss (dominik.krauss@cern.ch)
-// Augments a muon with a flag whether it has MS track
-// Writes result to SG for later selection by string parser
-
-#include "LongLivedParticleDPDMaker/RpvMuonMSTool.h"
-#include "xAODMuon/MuonContainer.h"
-#include <vector>
-#include <string>
-
-// Constructor
-DerivationFramework::RpvMuonMSTool::RpvMuonMSTool( const std::string& t,
-						   const std::string& n,
-						   const IInterface* p ) :
-  AthAlgTool(t,n,p),
-  m_collName("Muons"),
-  m_sgPrefix("")
-  {
-    declareInterface<DerivationFramework::IAugmentationTool>(this);
-    declareProperty("CollectionName", m_collName);
-    declareProperty("SGPrefix", m_sgPrefix);
-  }
- 
-// Destructor
-DerivationFramework::RpvMuonMSTool::~RpvMuonMSTool() {
-} 
-
-// Athena initialize and finalize
-StatusCode DerivationFramework::RpvMuonMSTool::initialize()
-{
-     ATH_MSG_VERBOSE("initialize() ...");
-     return StatusCode::SUCCESS;
-}
-StatusCode DerivationFramework::RpvMuonMSTool::finalize()
-{
-     ATH_MSG_VERBOSE("finalize() ...");
-     return StatusCode::SUCCESS;
-}
-
-// Augmentation
-StatusCode DerivationFramework::RpvMuonMSTool::addBranches() const
-{
-     // Retrieve data
-     const xAOD::MuonContainer* muons = evtStore()->retrieve<const xAOD::MuonContainer>(m_collName);
-     if(!muons) {
-	ATH_MSG_ERROR("Couldn't retrieve muon container with key: " << m_collName);
-	return StatusCode::FAILURE;
-     }
-	
-     // Make a vector for the cut results
-     std::vector<int>* isMSVec = new std::vector<int>();
-
-     // Loop over muons, set decisions
-     for (xAOD::MuonContainer::const_iterator muIt = muons->begin(); muIt != muons->end(); ++muIt) {
-       // has it a MS track?
-       if ((*muIt)->trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle) != NULL) isMSVec->push_back(1);
-       else isMSVec->push_back(0);
-     }     
-
-     // Write decision to SG for access by downstream algs 
-     std::string sgKey = m_sgPrefix + "isMS";
-
-     if (evtStore()->contains<std::vector<int> >(sgKey)) {
-       ATH_MSG_ERROR("Tool is attempting to write a StoreGate key " << sgKey << " which already exists. Please use a different key");
-       return StatusCode::FAILURE;
-     }
-     CHECK(evtStore()->record(isMSVec, sgKey));
-     
-     return StatusCode::SUCCESS;
-}
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/components/LongLivedParticleDPDMaker_entries.cxx b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/components/LongLivedParticleDPDMaker_entries.cxx
index 635bb3869c7..7551989bd5d 100644
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/components/LongLivedParticleDPDMaker_entries.cxx
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/components/LongLivedParticleDPDMaker_entries.cxx
@@ -2,8 +2,9 @@
 
 #include "LongLivedParticleDPDMaker/RpvElectronD0Tool.h"
 #include "LongLivedParticleDPDMaker/RpvMuonD0Tool.h"
-#include "LongLivedParticleDPDMaker/RpvMuonMSTool.h"
 #include "LongLivedParticleDPDMaker/RpvEgammaIDTool.h"
+#include "LongLivedParticleDPDMaker/DiLepFilters.h"
+#include "LongLivedParticleDPDMaker/DiLepSkimTools.h"
 #include "LongLivedParticleDPDMaker/HnlSkimmingTool.h"
 #include "LongLivedParticleDPDMaker/DVMissingETFilterTool.h"
 #include "LongLivedParticleDPDMaker/DVTracklessJetFilterTool.h"
@@ -15,8 +16,9 @@
 
 DECLARE_NAMESPACE_TOOL_FACTORY( DerivationFramework, RpvElectronD0Tool )
 DECLARE_NAMESPACE_TOOL_FACTORY( DerivationFramework, RpvMuonD0Tool )
-DECLARE_NAMESPACE_TOOL_FACTORY( DerivationFramework, RpvMuonMSTool )
 DECLARE_NAMESPACE_TOOL_FACTORY( DerivationFramework, RpvEgammaIDTool )
+DECLARE_NAMESPACE_TOOL_FACTORY( DerivationFramework, DiLepFilters )
+DECLARE_NAMESPACE_TOOL_FACTORY( DerivationFramework, DiLepSkim )
 DECLARE_NAMESPACE_TOOL_FACTORY( DerivationFramework, HnlSkimmingTool )
 DECLARE_NAMESPACE_TOOL_FACTORY( DerivationFramework, DVMissingETFilterTool )
 DECLARE_NAMESPACE_TOOL_FACTORY( DerivationFramework, DVMeffFilterTool )
@@ -30,8 +32,9 @@ DECLARE_FACTORY_ENTRIES( LongLivedParticleDPDMaker ) {
 
   DECLARE_NAMESPACE_TOOL( DerivationFramework, RpvElectronD0Tool  );
   DECLARE_NAMESPACE_TOOL( DerivationFramework, RpvMuonD0Tool  );
-  DECLARE_NAMESPACE_TOOL( DerivationFramework, RpvMuonMSTool  );
   DECLARE_NAMESPACE_TOOL( DerivationFramework, RpvEgammaIDTool  );
+  DECLARE_NAMESPACE_TOOL( DerivationFramework, DiLepFilters );
+  DECLARE_NAMESPACE_TOOL( DerivationFramework, DiLepSkim );
   DECLARE_NAMESPACE_TOOL( DerivationFramework, HnlSkimmingTool  );
   DECLARE_NAMESPACE_TOOL( DerivationFramework, DVMissingETFilterTool  );
   DECLARE_NAMESPACE_TOOL( DerivationFramework, DVMeffFilterTool  );
-- 
GitLab