diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/HnlSkimmingTool.h b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/HnlSkimmingTool.h
index 51ecff18e88c5f58b752fb18727853bb0911285b..9455cc32a63dd681b04f2dffb3267f25cbdf84ed 100644
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/HnlSkimmingTool.h
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/HnlSkimmingTool.h
@@ -24,7 +24,7 @@ namespace DerivationFramework {
   public: 
     /** Constructor with parameters */
     HnlSkimmingTool( const std::string& t, const std::string& n, const IInterface* p );
-   
+
     /** Destructor */
     ~HnlSkimmingTool();
    
@@ -34,7 +34,7 @@ namespace DerivationFramework {
  
     /** Check that the current event passes this filter */
     virtual bool eventPassesFilter() const;
-
+ 		bool IsGood(const xAOD::Muon& mu) const;
   private:
     ToolHandle< Trig::TrigDecisionTool > m_trigDecisionTool;
     std::vector< std::string > m_triggers;
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/DVFlags.py b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/DVFlags.py
index 6ef13644a4c3d0cd21755e98da65edc3d51cebca..2e0e3fe2b500d6f17b92b459148ab0f07a1494e2 100644
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/DVFlags.py
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/DVFlags.py
@@ -100,9 +100,9 @@ class DV_METFilterFlags(JobProperty):
 		          "HLT_xe90_tc_lcw_L1XE50","HLT_xe100_tc_lcw_L1XE50","HLT_xe120_tc_lcw_L1XE50",
 		          "HLT_xe90_tc_lcw_L1XE55","HLT_xe100_tc_lcw_L1XE55","HLT_xe120_tc_lcw_L1XE55",
 		          "HLT_xe90_tc_lcw_L1XE60","HLT_xe100_tc_lcw_L1XE60","HLT_xe120_tc_lcw_L1XE60",
-		          "HLT_xe90_mht_L1XE50","HLT_xe100_mht_L1XE50","HLT_xe120_mht_L1XE50",
-		          "HLT_xe90_mht_L1XE55","HLT_xe100_mht_L1XE55","HLT_xe120_mht_L1XE55",
-		          "HLT_xe90_mht_L1XE60","HLT_xe100_mht_L1XE60","HLT_xe120_mht_L1XE60",
+		          "HLT_xe90_mht_L1XE50","HLT_xe100_mht_L1XE50","HLT_xe110_mht_LXE50","HLT_xe120_mht_L1XE50",
+		          "HLT_xe90_mht_L1XE55","HLT_xe100_mht_L1XE55","HLT_xe110_mht_LXE55","HLT_xe120_mht_L1XE55",
+		          "HLT_xe90_mht_L1XE60","HLT_xe100_mht_L1XE60","HLT_xe110_mht_LXE60","HLT_xe120_mht_L1XE60",
 		          "HLT_xe90_topoclPS_L1XE50","HLT_xe100_topoclPS_L1XE50","HLT_xe120_topoclPS_L1XE50",
 		          "HLT_xe90_topoclPS_L1XE55","HLT_xe100_topoclPS_L1XE55","HLT_xe120_topoclPS_L1XE55",
 		          "HLT_xe90_topoclPS_L1XE60","HLT_xe100_topoclPS_L1XE60","HLT_xe120_topoclPS_L1XE60",
@@ -142,16 +142,16 @@ class DV_MeffFilterFlags(JobProperty):
     cutMEToverMeffMax=0.7   ## 
     cutJetPtMin=40.0*Units.GeV
     cutJetEtaMax=2.5
-    cutMETMin=100.0*Units.GeV
+    cutMETMin=150.0*Units.GeV
     triggers=["HLT_xe90_L1XE50","HLT_xe100_L1XE50","HLT_xe120_L1XE50",
 		          "HLT_xe90_L1XE55","HLT_xe100_L1XE55","HLT_xe120_L1XE55",
 		          "HLT_xe90_L1XE60","HLT_xe100_L1XE60","HLT_xe120_L1XE60",
 		          "HLT_xe90_tc_lcw_L1XE50","HLT_xe100_tc_lcw_L1XE50","HLT_xe120_tc_lcw_L1XE50",
 		          "HLT_xe90_tc_lcw_L1XE55","HLT_xe100_tc_lcw_L1XE55","HLT_xe120_tc_lcw_L1XE55",
 		          "HLT_xe90_tc_lcw_L1XE60","HLT_xe100_tc_lcw_L1XE60","HLT_xe120_tc_lcw_L1XE60",
-		          "HLT_xe90_mht_L1XE50","HLT_xe100_mht_L1XE50","HLT_xe120_mht_L1XE50",
-		          "HLT_xe90_mht_L1XE55","HLT_xe100_mht_L1XE55","HLT_xe120_mht_L1XE55",
-		          "HLT_xe90_mht_L1XE60","HLT_xe100_mht_L1XE60","HLT_xe120_mht_L1XE60",
+		          "HLT_xe90_mht_L1XE50","HLT_xe100_mht_L1XE50","HLT_xe110_mht_L1XE50","HLT_xe120_mht_L1XE50",
+		          "HLT_xe90_mht_L1XE55","HLT_xe100_mht_L1XE55","HLT_xe110_mht_L1XE51","HLT_xe120_mht_L1XE55",
+		          "HLT_xe90_mht_L1XE60","HLT_xe100_mht_L1XE60","HLT_xe110_mht_L1XE60","HLT_xe120_mht_L1XE60",
 		          "HLT_xe90_topoclPS_L1XE50","HLT_xe100_topoclPS_L1XE50","HLT_xe120_topoclPS_L1XE50",
 		          "HLT_xe90_topoclPS_L1XE55","HLT_xe100_topoclPS_L1XE55","HLT_xe120_topoclPS_L1XE55",
 		          "HLT_xe90_topoclPS_L1XE60","HLT_xe100_topoclPS_L1XE60","HLT_xe120_topoclPS_L1XE60",
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/KinkedTrackFlags.py b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/KinkedTrackFlags.py
index dd3b42a3c18ca68cb6bed5f54f2fd250bb34b698..37d3c5c966023709215b52168229278d3ce3cb22 100644
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/KinkedTrackFlags.py
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/python/KinkedTrackFlags.py
@@ -1,118 +1,253 @@
 # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
 
-##=============================================================================
-## Name:        KinkedTrackFlags.py
-## Authors:     Shimpei Yamamoto
-## Email:       shimpei.yamamoto@cern.ch
-## Created:     Febrary 2011
-##
-## Description: Here, all necessary job flags for the RPV/LL ESD-based DPD
-##              are defined.
-##
-##=============================================================================
-
-__doc__ = """job flags for the RPV/LL KinkedTrack DESD"""
-__version__ = "0.0.1"
-
-from AthenaCommon.JobProperties import JobProperty, JobPropertyContainer
-from AthenaCommon.JobProperties import jobproperties
-
-import AthenaCommon.SystemOfUnits as Units
-
-primRPVLLDESDM=jobproperties.PrimaryDPDFlags_RPVLLStream
-
-class KinkedTrack_containerFlags(JobProperty):
-    statusOn = True
-    jetCollectionName = "AntiKt4LCTopoJets"
-    electronCollectionName = "Electrons"
-    muonCollectionName = "Muons"
-    METCollectionName = "MET_Reference_AntiKt4LCTopo"
-    METTermName = "FinalTrk" # or "FinalClus" ??
-    egClusterCollectionName = "egammaClusters"
-    msTrackCollectionName = "MuonSpectrometerTrackParticles"
-    pass
-primRPVLLDESDM.add_JobProperty(KinkedTrack_containerFlags)
-
-class KinkedTrack_singleJetMetFilterFlags(JobProperty):
-    statusOn = True
-    allowedTypes = ['bool']
-    StoredValue  = True
-    triggerNames = [
-        "HLT_j80_xe80_dphi10_L1J40_DPHI-J20s2XE50",
-        "HLT_j80_xe80_dphi10_L1J40_DPHI-J20XE50",
-        "HLT_j100_xe80_dphi10_L1J40_DPHI-J20s2XE50",
-        "HLT_j100_xe80_dphi10_L1J40_DPHI-J20XE50",
-        "HLT_j80_xe80",
-        "HLT_j100_xe80"
-        ]
-    cutsEtMin = [120.0*Units.GeV, 60.0*Units.GeV]
-    cutEtaMax = 3.2
-    doLeptonVeto = True
-    electronIDKey = "Tight"
-    muonIDKey = "Medium"
-    leptonPtMax = 20.0*Units.GeV
-    leptonEtaMax = 2.5
-    cutMetMin = -1  # no cut
-    jetMetDphiMin = 1.0
-    pass
-primRPVLLDESDM.add_JobProperty(KinkedTrack_singleJetMetFilterFlags)
-
-class KinkedTrack_ZeeFilterFlags(JobProperty):
-    statusOn = True
-    allowedTypes = ['bool']
-    StoredValue  = True
-    triggerNames = [
-        #"HLT_e24_medium_iloose",
-        #"HLT_e24_tight_iloose",
-        #"HLT_e26_tight_iloose",
-        #"HLT_e28_tight_iloose",
-        "HLT_e24_medium_iloose_L1EM18VH",
-        "HLT_e24_lhmedium_iloose_L1EM18VH",
-        "HLT_e24_medium_iloose_L1EM20VH",
-        "HLT_e24_lhmedium_iloose_L1EM20VH",
-        "HLT_e24_tight_iloose_L1EM20VH",
-        "HLT_e24_lhtight_iloose_L1EM20VH",
-        "HLT_e26_tight_iloose",
-        "HLT_e26_lhtight_iloose"
-        ]
-    doTriggerMatch = False
-    electronPtMin = 40*Units.GeV
-    electronEtaMax = 2.5
-    electronIDKeys = ["Tight"]
-    clusterEtMin = 15*Units.GeV
-    clusterEtaMax = 2.5
-    diElectronMassLow = (91.1876-40)*Units.GeV
-    diElectronMassHigh = (91.1876+40)*Units.GeV
-    deltaPhiMax = 1.5
-    preScaleClusterEtMax = 60.0*Units.GeV
-    preScale = 5
-    pass
-primRPVLLDESDM.add_JobProperty(KinkedTrack_ZeeFilterFlags)
-
-class KinkedTrack_ZmumuFilterFlags(JobProperty):
-    statusOn = True
-    allowedTypes = ['bool']
-    StoredValue  = True
-    triggerNames = [
-        "HLT_mu20_iloose",
-        "HLT_mu20_iloose_L1MU15",
-        "HLT_mu24_iloose",
-        "HLT_mu24_iloose_L1MU15",
-        "HLT_mu24_imedium",
-        "HLT_mu26_imedium"
-        ]
-    doTriggerMatch = False
-    muonPtMin = 40*Units.GeV
-    muonEtaMax = 2.5
-    muonIDKeys = ["Medium"]
-    trackPtMin = 15*Units.GeV
-    trackEtaMax = 2.5
-    diMuonMassLow = (91.1876-40)*Units.GeV
-    diMuonMassHigh = (91.1876+40)*Units.GeV
-    deltaPhiMax = 1.5
-    preScaleTrackPtMax = 60.0*Units.GeV
-    preScale = 5
-    pass
-primRPVLLDESDM.add_JobProperty(KinkedTrack_ZmumuFilterFlags)
-
-
+##=============================================================================
+## Name:        KinkedTrackFlags.py
+## Authors:     Shimpei Yamamoto
+## Email:       shimpei.yamamoto@cern.ch
+## Created:     Febrary 2011
+##
+## Description: Here, all necessary job flags for the RPV/LL ESD-based DPD
+##              are defined.
+##
+##=============================================================================
+
+__doc__ = """job flags for the RPV/LL KinkedTrack DESD"""
+__version__ = "0.0.1"
+
+from AthenaCommon.JobProperties import JobProperty, JobPropertyContainer
+from AthenaCommon.JobProperties import jobproperties
+
+import AthenaCommon.SystemOfUnits as Units
+
+primRPVLLDESDM=jobproperties.PrimaryDPDFlags_RPVLLStream
+
+class KinkedTrack_containerFlags(JobProperty):
+    statusOn = True
+    jetCollectionName = "AntiKt4EMTopoJets"
+    electronCollectionName = "Electrons"
+    muonCollectionName = "Muons"
+    METCollectionName = "MET_Reference_AntiKt4EMTopo"
+    METTermName = "FinalTrk" # or "FinalClus" ??
+    egClusterCollectionName = "egammaClusters"
+    msTrackCollectionName = "MuonSpectrometerTrackParticles"
+    pass
+primRPVLLDESDM.add_JobProperty(KinkedTrack_containerFlags)
+
+class KinkedTrack_singleJetMetFilterFlags(JobProperty):
+    statusOn = True
+    allowedTypes = ['bool']
+    StoredValue  = True
+    triggerNames = [
+        'HLT_xe80_L1XE50',
+        'HLT_xe80_tc_lcw_L1XE50',
+        'HLT_xe80_tc_em_L1XE50',
+        'HLT_xe80_mht_L1XE50',
+        'HLT_xe80_pueta_L1XE50',
+        'HLT_xe80_pufit_L1XE50',
+        'HLT_xe80_wEFMu_L1XE50',
+        'HLT_xe80_tc_lcw_wEFMu_L1XE50',
+        'HLT_xe80_tc_em_wEFMu_L1XE50',
+        'HLT_xe80_mht_wEFMu_L1XE50',
+        'HLT_xe80_pueta_wEFMu_L1XE50',
+        'HLT_xe80_pufit_wEFMu_L1XE50',
+        'HLT_xe80',
+        'HLT_xe80_tc_lcw',
+        'HLT_xe80_tc_em',
+        'HLT_xe80_mht',
+        'HLT_xe80_pueta',
+        'HLT_xe80_pufit',
+        'HLT_xe80_wEFMu',
+        'HLT_xe80_tc_lcw_wEFMu',
+        'HLT_xe80_tc_em_wEFMu',
+        'HLT_xe80_mht_wEFMu',
+        'HLT_xe80_pueta_wEFMu',
+        'HLT_xe80_pufit_wEFMu',
+        'HLT_xe80_L1XE70',
+        'HLT_xe80_tc_lcw_L1XE70',
+        'HLT_xe80_tc_em_L1XE70',
+        'HLT_xe80_mht_L1XE70',
+        'HLT_xe80_pueta_L1XE70',
+        'HLT_xe80_pufit_L1XE70',
+        'HLT_xe80_wEFMu_L1XE70',
+        'HLT_xe80_tc_lcw_wEFMu_L1XE70',
+        'HLT_xe80_tc_em_wEFMu_L1XE70',
+        'HLT_xe80_mht_wEFMu_L1XE70',
+        'HLT_xe80_pueta_wEFMu_L1XE70',
+        'HLT_xe80_pufit_wEFMu_L1XE70',
+        'HLT_xe90_L1XE50',
+        'HLT_xe90_tc_lcw_L1XE50',
+        'HLT_xe90_mht_L1XE50',
+        'HLT_xe90_tc_em_L1XE50',
+        'HLT_xe90_wEFMu_L1XE50',
+        'HLT_xe90_tc_lcw_wEFMu_L1XE50',
+        'HLT_xe90_mht_wEFMu_L1XE50',
+        'HLT_xe90_tc_em_wEFMu_L1XE50',
+        'HLT_xe90_pueta_L1XE50',
+        'HLT_xe90_L1XE60',
+        'HLT_xe90_mht',
+        'HLT_xe90_mht_L1XE60',
+        'HLT_xe90_mht_wEFMu',
+        'HLT_xe90_pueta',
+        'HLT_xe90_pueta_L1XE60',
+        'HLT_xe90_pueta_wEFMu',
+        'HLT_xe90_pufit',
+        'HLT_xe90_pufit_L1XE60',
+        'HLT_xe90_pufit_wEFMu',
+        'HLT_xe90_tc_em',
+        'HLT_xe90_tc_em_wEFMu',
+        'HLT_xe90_tc_lcw',
+        'HLT_xe90_tc_lcw_L1XE60',
+        'HLT_xe90_tc_lcw_wEFMu',
+        'HLT_xe90_wEFMu',
+        'HLT_xe100',
+        'HLT_xe100_L1XE60',
+        'HLT_xe100_mht_L1XE60',
+        'HLT_xe100_tc_lcw_L1XE60',
+        'HLT_xe100_L1XE50',
+        'HLT_xe100_L1XE80',
+        'HLT_xe100_tc_lcw',
+        'HLT_xe100_tc_lcw_L1XE50',
+        'HLT_xe100_tc_lcw_L1XE80',
+        'HLT_xe100_tc_em',
+        'HLT_xe100_tc_em_L1XE50',
+        'HLT_xe100_tc_em_L1XE80',
+        'HLT_xe100_mht',
+        'HLT_xe100_mht_L1XE50',
+        'HLT_xe100_mht_L1XE80',
+        'HLT_xe100_pueta',
+        'HLT_xe100_pueta_L1XE80',
+        'HLT_xe100_pufit',
+        'HLT_xe100_pufit_L1XE80',
+        'HLT_xe100_wEFMu',
+        'HLT_xe100_wEFMu_L1XE50',
+        'HLT_xe100_wEFMu_L1XE80',
+        'HLT_xe100_tc_lcw_wEFMu',
+        'HLT_xe100_tc_lcw_wEFMu_L1XE50',
+        'HLT_xe100_tc_lcw_wEFMu_L1XE80',
+        'HLT_xe100_tc_em_wEFMu',
+        'HLT_xe100_tc_em_wEFMu_L1XE50',
+        'HLT_xe100_tc_em_wEFMu_L1XE80',
+        'HLT_xe100_mht_wEFMu',
+        'HLT_xe100_mht_wEFMu_L1XE50',
+        'HLT_xe100_mht_wEFMu_L1XE80',
+        'HLT_xe100_pueta_wEFMu',
+        'HLT_xe100_pueta_wEFMu_L1XE80',
+        'HLT_xe100_pufit_wEFMu',
+        'HLT_xe100_pufit_wEFMu_L1XE80',
+        'HLT_xe110_pueta_L1XE60',
+        'HLT_xe110_pufit_L1XE60',
+        'HLT_xe110_L1XE60',
+        'HLT_xe110_mht_L1XE60',
+        'HLT_xe110_tc_lcw_L1XE60',
+        'HLT_xe120',
+        'HLT_xe120_mht',
+        'HLT_xe120_pueta',
+        'HLT_xe120_pufit',
+        'HLT_xe120_tc_em',
+        'HLT_xe120_tc_lcw',
+        'HLT_xe120_wEFMu',
+        'HLT_xe120_mht_wEFMu',
+        'HLT_xe120_pueta_wEFMu',
+        'HLT_xe120_pufit_wEFMu',
+        'HLT_xe120_tc_em_wEFMu',
+        'HLT_xe120_tc_lcw_wEFMu'
+        ]
+    cutsEtMin = [80.0*Units.GeV, 40.0*Units.GeV]
+    cutEtaMax = 3.2
+    doLeptonVeto = True
+    electronIDKey = "Tight"
+    muonIDKey = "Medium"
+    leptonPtMax = 20.0*Units.GeV
+    leptonEtaMax = 2.5
+    cutMetMin = 60.0*Units.GeV  # no cut
+    jetMetDphiMin = 1.0
+    pass
+primRPVLLDESDM.add_JobProperty(KinkedTrack_singleJetMetFilterFlags)
+
+class KinkedTrack_ZeeFilterFlags(JobProperty):
+    statusOn = True
+    allowedTypes = ['bool']
+    StoredValue  = True
+    triggerNames = [
+        ## 0.3e34
+        'HLT_e24_lhmedium_iloose_L1EM18VH',
+        'HLT_e24_lhmedium_ivarloose_L1EM18VH',
+        'HLT_e24_lhmedium_nod0_iloose_L1EM18VH',
+        'HLT_e24_lhmedium_nod0_ivarloose_L1EM18VH',
+        ## 0.5e34
+        'HLT_e24_lhmedium_L1EM20VH',
+        'HLT_e24_lhmedium_nod0_L1EM20VH',
+        'HLT_e24_lhmedium_iloose',
+        'HLT_e24_lhmedium_ivarloose',
+        'HLT_e24_lhmedium_nod0_iloose',
+        'HLT_e24_lhmedium_nod0_ivarloose',
+        'HLT_e24_lhmedium_iloose_L1EM20VH',
+        'HLT_e24_lhmedium_ivarloose_L1EM20VH',
+        'HLT_e24_lhmedium_nod0_iloose_L1EM20VH',
+        'HLT_e24_lhmedium_nod0_ivarloose_L1EM20VH',
+        ## runs up to 1e34 :
+        'HLT_e24_lhtight_iloose',
+        'HLT_e24_lhtight_nod0_iloose',
+        'HLT_e24_lhtight_ivarloose',
+        'HLT_e24_lhtight_nod0_ivarloose',
+        ##  runs up to 2e34 :
+        'HLT_e26_lhtight_smooth_iloose',
+        'HLT_e26_lhtight_smooth_ivarloose',
+        'HLT_e26_lhtight_iloose',
+        'HLT_e26_lhtight_ivarloose',
+        'HLT_e26_lhtight_nod0_iloose',
+        'HLT_e26_lhtight_nod0_ivarloose',
+        'HLT_e28_lhtight_smooth_iloose',
+        'HLT_e28_lhtight_smooth_ivarloose',
+        'HLT_e28_lhtight_iloose',
+        'HLT_e28_lhtight_ivarloose',
+        'HLT_e28_lhtight_nod0_iloose',
+        'HLT_e28_lhtight_nod0_ivarloose',
+        ]
+    doTriggerMatch = False
+    electronPtMin = 40*Units.GeV
+    electronEtaMax = 2.5
+    electronIDKeys = ["Tight"]
+    clusterEtMin = 15*Units.GeV
+    clusterEtaMax = 2.5
+    diElectronMassLow = (91.1876-40)*Units.GeV
+    diElectronMassHigh = (91.1876+40)*Units.GeV
+    deltaPhiMax = 1.5
+    preScaleClusterEtMax = 60.0*Units.GeV
+    preScale = 5
+    pass
+primRPVLLDESDM.add_JobProperty(KinkedTrack_ZeeFilterFlags)
+
+class KinkedTrack_ZmumuFilterFlags(JobProperty):
+    statusOn = True
+    allowedTypes = ['bool']
+    StoredValue  = True
+    triggerNames = [
+        ## 0.5e34
+        'HLT_mu20_iloose_L1MU15',
+        'HLT_mu20_ivarloose_L1MU15',
+        ## 1.0e34
+        'HLT_mu24_iloose_L1MU15',
+        'HLT_mu24_ivarloose_L1MU15',
+        ## 1.5e34
+        'HLT_mu24_imedium',
+        'HLT_mu24_ivarmedium',
+        ## 2e34
+        'HLT_mu26_imedium',
+        'HLT_mu26_ivarmedium',
+        ]
+    doTriggerMatch = False
+    muonPtMin = 40*Units.GeV
+    muonEtaMax = 2.5
+    muonIDKeys = ["Medium"]
+    trackPtMin = 15*Units.GeV
+    trackEtaMax = 2.5
+    diMuonMassLow = (91.1876-40)*Units.GeV
+    diMuonMassHigh = (91.1876+40)*Units.GeV
+    deltaPhiMax = 1.5
+    preScaleTrackPtMax = 60.0*Units.GeV
+    preScale = 5
+    pass
+primRPVLLDESDM.add_JobProperty(KinkedTrack_ZmumuFilterFlags)
+
+
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/run/compileRPVLLRates.py b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/run/compileRPVLLRates.py
new file mode 100644
index 0000000000000000000000000000000000000000..ccf303c62da4b65297a752678ecc33ab48850b5f
--- /dev/null
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/run/compileRPVLLRates.py
@@ -0,0 +1,191 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+#the input log file should have the output of:
+#python readFiles.py [output file name] [InputFolderWithLogFiles]
+#easiest to do if you're in the run folder.
+# do "eosmount eosDir; cd eosDir/atlas/atlastier0/tzero/prod/data16_13TeV/physics_Main/00303304/"
+# then run the python command from that folder, with the input folder name in this case being data16_13TeV.00303304.physics_Main.daq.RAW.f716.recon.task.LOG/
+
+#for shorter runs, you can also use a grep command:
+#grep -E "RAWtoESD.*RPVLL.*Events|BSESOutputSvcStreamDRAW_RPVLL.*events" 00300784/data16_13TeV.00300784.physics_Main.daq.RAW.f708.recon.task.LOG/* > ~/rpvllLog_00300784.out &
+#the folder with log files is on eos: eos/eosatlas/atlastier0/tzero/prod/physics_Main/ 
+#if grep complains about the long argument, just cd into the folder with the log files. The command does take quite a while to run.
+#The log files only stay around for a few weeks, or the folder is empty and only LOGARC remain. the logs can likely be recovered from the LOGARC files, if necessary
+
+#43 lines should be recovered from each file!
+
+#run file with python compileRPVLLRates.py rpvllLog_00303304.out 303304 lbTimes_00303304.out
+#where the rpvllLog is the output from your grep command, next entry is the run number (plot label), and the next is a list of lb and seconds/lb (can be copied from runquery)
+
+import sys
+import ROOT
+from ROOT import gROOT, TCanvas, TH1F, THStack
+import math
+
+#Make sure you have the atlas style files accessible!
+from AtlasStyle import SetAtlasStyle 
+SetAtlasStyle() 
+
+def end_lb(lumiBlock, lbEventList = [], rateHists = [], totalRateHist = 0):
+	events_in_lb = lbEventList[0]
+	events_passed_lb = lbEventList[42]
+	lbFilters = [0] * 20	
+	for i in range(0,21):
+	   if i < 7: 
+		lbFilters[i] = lbEventList[2*i+1]
+	   elif i > 7: lbFilters[i-1] = lbEventList[2*i+1]
+	for i,lb in enumerate(lbFilters):
+		rateHists[i].Fill(lumiBlock, float(lb) )
+	totalRateHist.Fill(lumiBlock, float(events_passed_lb) )
+	return
+
+mypath = sys.argv[1]
+runNumber = sys.argv[2]
+lb_rates = sys.argv[3]
+
+List = open(mypath).readlines()
+c1 = TCanvas( 'c1', 'yay canvas', 1000, 600 )
+
+#the filter names could change run-to-run, with filter updates. If so, need to update the number of items in the list
+#and the hardcoded numbers 43 (2*number of filters + 1 line for the total accepted into RPVLL) , 21 (number of filters), 42 (2*number of filters)
+filterNames = ['DiLep_SiElectronFilterKernel','DiLep_SiPhotonXFilterKernel','DiLep_SiMuonFilterKernel','DiLep_DiElectronFilterKernel','DiLep_DiPhotonFilterKernel',
+'DiLep_DiElPhFilterKernel','DiLep_DiLoElPhFilterKernel','DVAugmentationKernel','DVMuonFilterKernel','DV_PhotonFilterKernel',
+'DV_PhotonPlusTLJetFilterKernel','DV_MultiJetFilterKernel','DV_METFilterKernel','DV_MeffFilterKernel','KinkedTrackJetFilterKernel',
+'KinkedTrackZeeFilterKernel','KinkedTrackZmumuFilterKernel','HnlFilterKernel','HV_MuvtxFilterKernel','HV_JetMETFilterKernel','HV_CalRatioFilterKernel']
+
+#just a list of filter names minus the augmentation kernel, which is just every event in the run (we don't want to plot that!)
+filterNames_mAug = ['DiLep_SiElectronFilterKernel','DiLep_SiPhotonXFilterKernel','DiLep_SiMuonFilterKernel','DiLep_DiElectronFilterKernel','DiLep_DiPhotonFilterKernel',
+'DiLep_DiElPhFilterKernel','DiLep_DiLoElPhFilterKernel','DVMuonFilterKernel','DV_PhotonFilterKernel',
+'DV_PhotonPlusTLJetFilterKernel','DV_MultiJetFilterKernel','DV_METFilterKernel','DV_MeffFilterKernel','KinkedTrackJetFilterKernel',
+'KinkedTrackZeeFilterKernel','KinkedTrackZmumuFilterKernel','HnlFilterKernel','HV_MuvtxFilterKernel','HV_JetMETFilterKernel','HV_CalRatioFilterKernel']
+
+eventList = [0] * 43
+lbEventList = [0] * 43 
+
+rateHists = []
+for i in range(0,20):
+  rateHists.append(TH1F("ratePerLB_filter"+str(i),"ratePerLB_filter;lb;rate",2500,0,2500))
+  rateHists[i].Sumw2()
+totalRateHist = TH1F("ratePerLB_full","ratePerLB_full;lb;rate",2500,0,2500)
+totalRateHist.Sumw2()
+
+lbTimeHist = TH1F("lbTimeHist","lbTimeHist",2500,0,2500)
+lbList = open(lb_rates).readlines()
+for lineNo,line in enumerate(lbList):
+	lbTimeHist.Fill(float(line.split()[0]), float(line.split()[1]))
+	lbTimeHist.SetBinError(lbTimeHist.FindBin(float(line.split()[0])),0)
+
+current_lb = 0
+first_lb = 0
+last_lb = 2500
+
+for lineNo,line in enumerate(List):
+    if lineNo%43 == 0:
+    	for lb in line.split("._"):
+	    if "lb" in lb:
+	    	if int(lb[2:]) != current_lb:
+			if current_lb != 0: end_lb(current_lb, lbEventList, rateHists, totalRateHist)
+			lbEventList = [0] * 43
+			current_lb = int(lb[2:])
+		if first_lb == 0:
+			first_lb = current_lb
+    if(lineNo < len(List) - 43):
+        if(line.split()[0][:-10] == List[lineNo+43].split()[0][:-10]):
+		continue
+    [int(s) for s in line.split() if s.isdigit()]
+    eventList[lineNo%43] += int(s)
+    lbEventList[lineNo%43] += int(s)
+
+#print eventList
+end_lb(current_lb, lbEventList, rateHists, totalRateHist)
+last_lb = current_lb
+
+TotalEvents = eventList[0]
+TotalRPVLLPass = eventList[42]
+print 'Out of ',TotalEvents,' events, ',TotalRPVLLPass,' events passed RPVLL filters. Efficiency: ',float(TotalRPVLLPass)/float(TotalEvents)*100.,'%.'
+
+TotalFracList = [0]*21
+RPVLLFracList = [0]*21
+filterEvents = [0]*21
+closureTest = 0
+
+for filterNo in range(0,21):	
+	closureTest += eventList[filterNo*2+1]
+	TotalFracList[filterNo] = float(eventList[filterNo*2+1])/float(TotalEvents)
+	RPVLLFracList[filterNo] = float(eventList[filterNo*2+1])/float(TotalRPVLLPass)
+	filterEvents[filterNo] = eventList[filterNo*2+1]
+	print filterNames[filterNo],' (rel, total): (',RPVLLFracList[filterNo],', ',TotalFracList[filterNo],')'
+	
+#subtracting away the results of the DVAugmentationKernel, which isn't a filter.
+#the first number should always be greater than the second - because of overlaps.
+print 'Total number of events passing filters / total number passing RPVLL: ',closureTest-eventList[15],'/',TotalRPVLLPass,'. Rate: ',float(closureTest-eventList[15])/float(TotalRPVLLPass)*100.,'%.'
+
+#printout for easy copy-paste into google spreasheet:
+for n in filterNames:
+	print n,
+print ''
+for n in filterEvents:
+	print n,
+
+totalRateHist.SetMarkerStyle(22)
+totalRateHist.SetMarkerSize(1.2)
+if (last_lb - first_lb) > 600:
+	totalRateHist.SetMarkerSize(0.6)
+totalRateHist.SetMarkerColor(ROOT.kBlack)
+totalRateHist.SetLineColor(ROOT.kBlack)
+totalRateHist.Divide(lbTimeHist)
+for bin in range(1,totalRateHist.GetNbinsX() + 1):
+	totalRateHist.SetBinError( bin, 0 ) #the rate is what it is, there are no appreciable errors on it
+hs = THStack("hs","Stacked 1D histograms");
+
+colors = [
+#Seven for DiLep
+ROOT.kBlue+3, ROOT.kBlue +1, ROOT.kBlue- 4, ROOT.kBlue-2, ROOT.kBlue - 7,ROOT.kBlue - 5, ROOT.kBlue -9, 
+#Six for DV
+ROOT.kRed+3, ROOT.kRed +1, ROOT.kRed-2, ROOT.kRed - 4, ROOT.kRed -6,ROOT.kRed -9,
+#Three for kinked track
+ROOT.kCyan+2, ROOT.kTeal - 8, ROOT.kCyan -6, 
+#HNL
+ROOT.kOrange+8, 
+#Three for HV
+ROOT.kViolet +8, ROOT.kViolet+3,  ROOT.kViolet -9,
+#Extra
+ROOT.kGreen+3, ROOT.kGreen +1, ROOT.kGreen-1, ROOT.kGreen - 2, ROOT.kGreen -6 ]
+
+c1.SetRightMargin(0.25)
+c1.SetLeftMargin(0.1)
+leg = ROOT.TLegend(0.76,.15,.97,.96)
+leg.SetFillColor(0)
+leg.SetFillStyle(0)
+leg.SetBorderSize(0)
+leg.SetTextSize(0.02)
+leg.AddEntry(totalRateHist, "Overall RPVLL rate","lp")
+
+for i,hist in enumerate(rateHists):
+	hist.SetFillColor(colors[i])
+	hist.SetLineColor(colors[i])
+	hist.Divide(lbTimeHist)
+	hs.Add(hist)
+	leg.AddEntry(hist, filterNames_mAug[i], "f")	
+
+hs.Draw("HIST")
+hs.GetXaxis().SetTitle("lumi block")
+hs.GetYaxis().SetTitle("rate [Hz]")
+hs.GetYaxis().SetTitleOffset(0.8)
+totalRateHist.Draw("pSAME")
+
+hs.GetXaxis().SetRangeUser(first_lb - 20, last_lb + 20)
+hs.GetYaxis().SetRangeUser(0,100)
+leg.Draw()
+latex2 = ROOT.TLatex(0.55,0.86,"Run "+runNumber)
+latex2.SetNDC();
+latex2.SetTextSize(0.05);
+latex2.SetTextAlign(13); 
+latex2.Draw()
+latex = ROOT.TLatex(0.52,0.915,"#font[72]{ATLAS }#font[42]{Internal}")
+latex.SetNDC();
+latex.SetTextSize(0.05);
+latex.SetTextAlign(13); 
+latex.Draw()
+c1.Update()
+c1.Print("run_"+runNumber+"_rate.pdf")
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/run/readFiles.py b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/run/readFiles.py
new file mode 100644
index 0000000000000000000000000000000000000000..141a2da0bf48f3587c6ca34b95c8e8484cebfc14
--- /dev/null
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/run/readFiles.py
@@ -0,0 +1,33 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+#file to parse log files for rate compilation. Instructions are in compileRPVLLRates.py
+
+from os import listdir
+from os.path import isfile, join
+import re
+import sys
+
+text_file = open(sys.argv[1], "w")
+mypath = sys.argv[2]
+onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
+
+print 'About to loop through files!'
+for f in onlyfiles:
+  badName = False
+  #sometimes ls files from mounted eos gives funny results. This should fix that!
+  #double check that any files that had "sys" in the name are not duplicates of files without - in some runs, they all are! there should only be a handful.
+  #if they're all duplicates, can just skip files with 'sys' in f instead.
+  if 'sys' in f:
+    badName = True
+    openFile = open(mypath+'.'.join(f.split('.')[3:16]))
+  else:
+    openFile = open(mypath+f)
+  print f
+  for line in openFile:
+    #this line will need to be changed for "RAWtoALL"
+    if re.match('RAWtoESD.*RPVLL.*Events',line) or re.match('RAWtoESD.*BSESOutputSvcStreamDRAW_RPVLL.*events',line):
+      if badName: 
+	text_file.write('.'.join(f.split('.')[3:16]) + ':' + line)
+      else: 	
+	text_file.write(f + ':' + line)
+text_file.close()
diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/HnlSkimmingTool.cxx b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/HnlSkimmingTool.cxx
index decab84511c81591b02a0581fe1c5971cbc86d21..ff1758fd9526b7f2f2adb970752b52a4795e9cf1 100644
--- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/HnlSkimmingTool.cxx
+++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/HnlSkimmingTool.cxx
@@ -77,6 +77,21 @@ StatusCode DerivationFramework::HnlSkimmingTool::finalize()
 }
 
 // The filter itself
+//Add of the chi2 cut
+bool DerivationFramework::HnlSkimmingTool::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.;
+}
+/////////////////////End of add of the chi2 cut
 bool DerivationFramework::HnlSkimmingTool::eventPassesFilter() const
 {
   bool acceptEvent(false);
@@ -146,17 +161,21 @@ bool DerivationFramework::HnlSkimmingTool::eventPassesFilter() const
     }
     bool passD0cut = true;
     int type = (*mu_itr2)->muonType();
-    if(type==0){ //d0 cut is for combined muons only
-      passD0cut = false;
-      if(fabs((*mu_itr2)->primaryTrackParticle()->d0())>m_mu2d0Min) passD0cut = true;
-    }
-    if((*mu_itr2)->pt()>m_mu2PtMin && fabs((*mu_itr2)->eta())<m_mu2AbsEtaMax && passTypeCut && isIso && passD0cut){
-      muon2passed = true;
-      break;
+    const xAOD::Muon *mu = (*mu_itr2);
+    if(IsGood(*mu)){
+      if(type==0){ //d0 cut is for combined muons only
+	passD0cut = false;
+	if(fabs((*mu_itr2)->primaryTrackParticle()->d0())>m_mu2d0Min) passD0cut = true;
+      }
+      if((*mu_itr2)->pt()>m_mu2PtMin && fabs((*mu_itr2)->eta())<m_mu2AbsEtaMax && passTypeCut && isIso && passD0cut){
+	muon2passed = true;
+	break;
+      }
     }
   }
   
   if(muon2passed) acceptEvent = true;
   
   return acceptEvent; 
-}  
+}
+