diff --git a/Control/AthToolSupport/AsgTools/AsgTools/AsgTool.h b/Control/AthToolSupport/AsgTools/AsgTools/AsgTool.h
index 276cbecf545648da6abd976cf8965be95a355a1a..28731384fb84bbabf0d2a500615b01acf9afcaf3 100644
--- a/Control/AthToolSupport/AsgTools/AsgTools/AsgTool.h
+++ b/Control/AthToolSupport/AsgTools/AsgTools/AsgTool.h
@@ -7,6 +7,7 @@
 #include "AsgTools/AsgToolsConf.h"
 #include "AsgTools/IAsgTool.h"
 #include "AsgTools/MsgLevel.h"
+#include "AsgTools/MessageCheck.h"
 
 // Environment specific include(s):
 #ifdef ASGTOOL_STANDALONE
diff --git a/Control/AthToolSupport/AsgTools/AsgTools/AsgToolsDict.h b/Control/AthToolSupport/AsgTools/AsgTools/AsgToolsDict.h
index 084af7dd12faa600025dab06db19ac029b1ea0a4..89687ac0c7432ae531726a8f9c1a8d5ae9460abb 100644
--- a/Control/AthToolSupport/AsgTools/AsgTools/AsgToolsDict.h
+++ b/Control/AthToolSupport/AsgTools/AsgTools/AsgToolsDict.h
@@ -18,6 +18,8 @@
 // setProperty(...) function(s) come(s) from the AlgTool base class, with all
 // the necessary dictionaries declared in GaudiKernel.
 #ifdef ASGTOOL_STANDALONE
+// In athena, we get this from GAUDI
+#include "AsgTools/StatusCode.h"
 
 // Helper macro for declaring the setProperty functions to the dictionary:
 #define SETPROPERTY_INSTAN( TYPE )                                            \
diff --git a/Control/AthToolSupport/AsgTools/AsgTools/selection.xml b/Control/AthToolSupport/AsgTools/AsgTools/selection.xml
index ce865064a416e1bf2658e6dd8719df1bcf123374..7609ec8e7cb70c043a482198c0511a0d66b62ffe 100644
--- a/Control/AthToolSupport/AsgTools/AsgTools/selection.xml
+++ b/Control/AthToolSupport/AsgTools/AsgTools/selection.xml
@@ -9,5 +9,5 @@
 
    <!-- Helper types: -->
    <class name="asg::ToolStore" />
-   
+
 </lcgdict>
diff --git a/Control/AthToolSupport/AsgTools/AsgTools/selection_StandAlone.xml b/Control/AthToolSupport/AsgTools/AsgTools/selection_StandAlone.xml
new file mode 100644
index 0000000000000000000000000000000000000000..2007c70863d7e1b6f4ede43231ef6d811f5ddee2
--- /dev/null
+++ b/Control/AthToolSupport/AsgTools/AsgTools/selection_StandAlone.xml
@@ -0,0 +1,6 @@
+<lcgdict>
+
+   <!-- Primitive types: -->
+   <class name="StatusCode" />
+
+</lcgdict>
diff --git a/Control/AthToolSupport/AsgTools/CMakeLists.txt b/Control/AthToolSupport/AsgTools/CMakeLists.txt
index 4a546a76b5efbe0674dfcb07bb0d65207889b3c5..da369e11e9baaea96598034067724ae297d12d3f 100644
--- a/Control/AthToolSupport/AsgTools/CMakeLists.txt
+++ b/Control/AthToolSupport/AsgTools/CMakeLists.txt
@@ -48,8 +48,15 @@ atlas_add_library( AsgTools
    LINK_LIBRARIES ${libs}
    PRIVATE_LINK_LIBRARIES ${Boost_LIBRARIES} ${ROOT_LIBRARIES} )
 
+# Select which xml files to use for dictionary generation
+if( XAOD_STANDALONE )
+   set( selection AsgTools/selection.xml AsgTools/selection_StandAlone.xml )
+else()
+   set( selection AsgTools/selection.xml )
+endif()
+
 atlas_add_dictionary( AsgToolsDict
-   AsgTools/AsgToolsDict.h AsgTools/selection.xml
+   AsgTools/AsgToolsDict.h ${selection}
    LINK_LIBRARIES AsgTools )
 
 # Silence some warnings that are generated by the code on MacOS X:
diff --git a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithmsDict.h b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithmsDict.h
index 66ae37f0ee6f640494fe3cbf953e297f3cebef16..2b3cbbe994908aaff39a39f546fed442719eecd2 100644
--- a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithmsDict.h
+++ b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithmsDict.h
@@ -9,6 +9,7 @@
 #define ASG_ANALYSIS_ALGORITHMS__ASG_ANALYSIS_ALGORITHMS_DICT_H
 
 #include <AsgAnalysisAlgorithms/AsgPtEtaSelectionTool.h>
+#include <AsgAnalysisAlgorithms/AsgFlagSelectionTool.h>
 #include <AsgAnalysisAlgorithms/AsgSelectionAlg.h>
 #include <AsgAnalysisAlgorithms/AsgViewFromSelectionAlg.h>
 #include <AsgAnalysisAlgorithms/AsgxAODNTupleMakerAlg.h>
diff --git a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgFlagSelectionTool.h b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgFlagSelectionTool.h
new file mode 100644
index 0000000000000000000000000000000000000000..2c4cb378df711628634b18919cd946c60eb5cd57
--- /dev/null
+++ b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgFlagSelectionTool.h
@@ -0,0 +1,88 @@
+/*
+ Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+ */
+
+/// @author Teng Jian Khoo
+
+
+
+#ifndef ASG_ANALYSIS_ALGORITHMS__ASG_FLAG_SELECTION_TOOL_H
+#define ASG_ANALYSIS_ALGORITHMS__ASG_FLAG_SELECTION_TOOL_H
+
+#include <AsgTools/AsgTool.h>
+#include <PATCore/IAsgSelectionTool.h>
+#include <xAODBase/IParticle.h>
+#include <string>
+#include <vector>
+
+namespace CP
+{
+    /// \brief an \ref IAsgSelectionTool that cuts on char decorations
+    ///
+    /// For ROOT I/O reasons, chars are commonly used to store boolean
+    /// properties, such as flags indicating whether particular criteria
+    /// have been passed. This tool provides a conversion of a list
+    /// of such decorations, interpreted as bools, into the SelectionType
+    /// encoding of TAccept, for use in AnaAlgSequence.
+    ///
+    /// A list of flags may be provided to the tool, and the output will
+    /// simply concatenate them into the TAccept. Each selection criterion
+    /// must be passed (no OR behaviour), but the flag logic may be
+    /// inverted, such that flags may be encoded as "passX" or !"failX".
+
+    class AsgFlagSelectionTool final
+    : public asg::AsgTool, virtual public IAsgSelectionTool
+  {
+    //
+    // public interface
+    //
+
+    // Create a proper constructor for Athena
+    ASG_TOOL_CLASS( AsgFlagSelectionTool, IAsgSelectionTool )
+
+
+    /// \brief standard constructor
+    /// \par Guarantee
+    ///   strong
+    /// \par Failures
+    ///   out of memory II
+  public:
+    AsgFlagSelectionTool (const std::string& name);
+
+
+
+
+    //
+    // inherited interface
+    //
+
+    virtual StatusCode initialize () override;
+
+    virtual const Root::TAccept& getTAccept( ) const override;
+
+    virtual const Root::TAccept& accept( const xAOD::IParticle* /*part*/ ) const override;
+
+
+
+    //
+    // private interface
+    //
+
+    /// tool properties
+    /// \{
+
+    std::vector<std::string> m_selFlags;
+    std::vector<bool> m_invertFlags;
+    std::vector<SG::AuxElement::ConstAccessor<char> > m_acc_selFlags;
+
+    /// \}
+
+
+    /// \brief the \ref TAccept we are using
+  private:
+    mutable Root::TAccept m_accept;
+  };
+}
+
+#endif
+
diff --git a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgViewFromSelectionAlg.h b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgViewFromSelectionAlg.h
index 9f5a1c07a41ace1792f8b7a5234c1cb024cd8318..fb02baa133a405159ccd4c691021c15127261f48 100644
--- a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgViewFromSelectionAlg.h
+++ b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgViewFromSelectionAlg.h
@@ -63,7 +63,7 @@ namespace CP
 
     /// the list of accessors and cut ignore list
   private:
-    std::vector<std::pair<std::unique_ptr<const SG::AuxElement::Accessor<SelectionType> >,SelectionType> > m_accessors;
+    std::vector<std::pair<std::unique_ptr<const SG::AuxElement::ConstAccessor<SelectionType> >,SelectionType> > m_accessors;
 
     /// \brief the templated version of execute for a single systematic
   private:
diff --git a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/selection.xml b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/selection.xml
index 9e42f576277d1dd5b3c3bb8fe26bb4ba8200f9cf..4e0c736ef820960c402a04ad850070c3972f851c 100644
--- a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/selection.xml
+++ b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/selection.xml
@@ -1,6 +1,7 @@
 <lcgdict>
 
    <class name="CP::AsgPtEtaSelectionTool" />
+   <class name="CP::AsgFlagSelectionTool" />
    <class name="CP::AsgSelectionAlg" />
    <class name="CP::AsgViewSelectionAlg" />
    <class name="CP::AsgxAODNTupleMakerAlg" />
diff --git a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/Root/AsgFlagSelectionTool.cxx b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/Root/AsgFlagSelectionTool.cxx
new file mode 100644
index 0000000000000000000000000000000000000000..ec25213ae991ab8db2df9472fe71db50dffef733
--- /dev/null
+++ b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/Root/AsgFlagSelectionTool.cxx
@@ -0,0 +1,86 @@
+/*
+ Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+ */
+
+/// @author Teng Jian Khoo
+
+
+
+//
+// includes
+//
+
+#include <AsgAnalysisAlgorithms/AsgFlagSelectionTool.h>
+
+#include <cmath>
+
+//
+// method implementations
+//
+
+namespace CP
+{
+    AsgFlagSelectionTool ::
+    AsgFlagSelectionTool (const std::string& name)
+    : AsgTool (name)
+    {
+      declareProperty ("selectionFlags", m_selFlags, "list of flags to use as selection criteria");
+      declareProperty ("invertFlags",    m_invertFlags, "toggles for inverting the selection (index-parallel to selectionFlags)");
+    }
+
+
+
+    StatusCode AsgFlagSelectionTool ::
+    initialize ()
+    {
+      if(m_invertFlags.size()!=m_selFlags.size() && !m_invertFlags.empty()) {
+          ATH_MSG_ERROR("Property invertFlags has different size to selectionFlags. Please check your configuration");
+          return StatusCode::FAILURE;
+      }
+      // Could also warn if there are fewer values, but we don't have to force users to set where irrelevant.
+      // Maybe warn unless the size is 0, in which case assume all default?
+
+      for(size_t index=0; index<m_selFlags.size(); ++index) {
+          const std::string& thisflag = m_selFlags[index];
+          if (thisflag.empty()) {
+              ATH_MSG_ERROR("Empty string passed as selection flag!");
+              return StatusCode::FAILURE;
+          } else {
+              // Extend m_invertFlags until the size matches m_selectionFlags
+              // Only done in the case that m_invert was empty
+              if(m_invertFlags.size()<index+1) {m_invertFlags.push_back(false);}
+              std::string doInvertStr = m_invertFlags[index] ? "!" : "";
+              m_accept.addCut (doInvertStr + thisflag, doInvertStr + thisflag);
+              m_acc_selFlags.push_back(SG::AuxElement::ConstAccessor<char>(thisflag));
+          }
+      }
+
+      return StatusCode::SUCCESS;
+    }
+
+
+
+    const Root::TAccept& AsgFlagSelectionTool ::
+    getTAccept () const
+    {
+      return m_accept;
+    }
+
+
+
+    const Root::TAccept& AsgFlagSelectionTool ::
+    accept (const xAOD::IParticle *particle) const
+    {
+      m_accept.clear();
+      for(std::size_t cutIndex=0; cutIndex<m_accept.getNCuts(); ++cutIndex) {
+          // Test against the opposite of the invert value
+          bool testval = !m_invertFlags[cutIndex];
+          ATH_MSG_VERBOSE("Now testing flag \"" << m_selFlags[cutIndex] << "\" requiring value " << testval);
+          m_accept.setCutResult (cutIndex, bool(m_acc_selFlags[cutIndex](*particle))==testval);
+      }
+      ATH_MSG_VERBOSE("  Result: " << m_accept);
+
+      return m_accept;
+    }
+}
+
diff --git a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/Root/AsgViewFromSelectionAlg.cxx b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/Root/AsgViewFromSelectionAlg.cxx
index 72f6d3cbf8af481cb8c7e662a5917c82a2110499..046c6ab9051d02007a4f768b5fc24f365112efda 100644
--- a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/Root/AsgViewFromSelectionAlg.cxx
+++ b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/Root/AsgViewFromSelectionAlg.cxx
@@ -108,7 +108,7 @@ namespace CP
       SelectionType ignore = 0;
       if (iter < m_ignore.size())
         ignore = m_ignore[iter];
-      auto accessor = std::make_unique<SG::AuxElement::Accessor<SelectionType> > (m_selection[iter]);
+      auto accessor = std::make_unique<SG::AuxElement::ConstAccessor<SelectionType> > (m_selection[iter]);
       m_accessors.push_back (std::make_pair (std::move (accessor), ignore));
     }
 
diff --git a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/python/PileupAnalysisSequence.py b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/python/PileupAnalysisSequence.py
index 917ba08ac92df2d49f04a0ac7f01add0f98ac730..d8cdbbf18af8a913d2a5541ad9ae8378ed412016 100644
--- a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/python/PileupAnalysisSequence.py
+++ b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/python/PileupAnalysisSequence.py
@@ -4,7 +4,7 @@
 from AnaAlgorithm.AnaAlgSequence import AnaAlgSequence
 from AnaAlgorithm.DualUseConfig import createAlgorithm, addPrivateTool
 
-def makePileupAnalysisSequence( dataType ):
+def makePileupAnalysisSequence( dataType, userPileupConfigs=[], userLumicalcFiles=[] ):
     """Create a PRW analysis algorithm sequence
 
     Keyword arguments:
@@ -18,8 +18,8 @@ def makePileupAnalysisSequence( dataType ):
     seq = AnaAlgSequence( "PileupAnalysisSequence" )
 
     muMcFiles = ["dev/PileupReweighting/mc15ab_defaults.NotRecommended.prw.root",
-                 "dev/PileupReweighting/mc15c_v2_defaults.NotRecommended.prw.root"]
-    muDataFiles = ["dev/SUSYTools/ilumicalc_histograms_None_276262-284154.root"]
+                 "dev/PileupReweighting/mc15c_v2_defaults.NotRecommended.prw.root"] + userPileupConfigs
+    muDataFiles = ["dev/SUSYTools/ilumicalc_histograms_None_276262-284154.root"] + userLumicalcFiles
 
     # Set up the only algorithm of the sequence:
     alg = createAlgorithm( 'CP::PileupReweightingAlg', 'PileupReweightingAlg' )
diff --git a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/src/components/AsgAnalysisAlgorithms_entries.cxx b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/src/components/AsgAnalysisAlgorithms_entries.cxx
index 9972a0552f7eda454de7b68156a4e81c54254b83..2280fc57b1ca2e5e7418417700479190343ea4e9 100644
--- a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/src/components/AsgAnalysisAlgorithms_entries.cxx
+++ b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/src/components/AsgAnalysisAlgorithms_entries.cxx
@@ -8,6 +8,7 @@
 #include <GaudiKernel/DeclareFactoryEntries.h>
 
 #include <AsgAnalysisAlgorithms/AsgPtEtaSelectionTool.h>
+#include <AsgAnalysisAlgorithms/AsgFlagSelectionTool.h>
 #include <AsgAnalysisAlgorithms/AsgSelectionAlg.h>
 #include <AsgAnalysisAlgorithms/AsgViewFromSelectionAlg.h>
 #include <AsgAnalysisAlgorithms/AsgxAODNTupleMakerAlg.h>
@@ -18,6 +19,7 @@
 #include <AsgAnalysisAlgorithms/SysListLoaderAlg.h>
 
 DECLARE_NAMESPACE_TOOL_FACTORY (CP, AsgPtEtaSelectionTool)
+DECLARE_NAMESPACE_TOOL_FACTORY (CP, AsgFlagSelectionTool)
 DECLARE_NAMESPACE_ALGORITHM_FACTORY (CP, AsgSelectionAlg)
 DECLARE_NAMESPACE_ALGORITHM_FACTORY (CP, AsgViewFromSelectionAlg)
 DECLARE_NAMESPACE_ALGORITHM_FACTORY (CP, AsgxAODNTupleMakerAlg)
@@ -29,6 +31,7 @@ DECLARE_NAMESPACE_ALGORITHM_FACTORY (CP, SysListLoaderAlg)
 
 DECLARE_FACTORY_ENTRIES(AsgAnalysisAlgorithms) {
   DECLARE_NAMESPACE_ALGTOOL (CP, AsgPtEtaSelectionTool)
+  DECLARE_NAMESPACE_ALGTOOL (CP, AsgFlagSelectionTool)
   DECLARE_NAMESPACE_ALGORITHM (CP, AsgSelectionAlg)
   DECLARE_NAMESPACE_ALGORITHM (CP, AsgViewFromSelectionAlg)
   DECLARE_NAMESPACE_ALGORITHM (CP, AsgxAODNTupleMakerAlg)
diff --git a/PhysicsAnalysis/Algorithms/EgammaAnalysisAlgorithms/python/ElectronAnalysisSequence.py b/PhysicsAnalysis/Algorithms/EgammaAnalysisAlgorithms/python/ElectronAnalysisSequence.py
index 0d92ffec3adacaf119b515bee1431106811daf62..318663e9e1d551cfb5e25bf05a13d3eddf7920b6 100644
--- a/PhysicsAnalysis/Algorithms/EgammaAnalysisAlgorithms/python/ElectronAnalysisSequence.py
+++ b/PhysicsAnalysis/Algorithms/EgammaAnalysisAlgorithms/python/ElectronAnalysisSequence.py
@@ -6,13 +6,17 @@ from AnaAlgorithm.DualUseConfig import createAlgorithm, addPrivateTool
 
 def makeElectronAnalysisSequence( dataType,
                                   isolationWP = 'GradientLoose',
-                                  likelihoodWP = 'LooseLHElectron' ):
+                                  likelihoodWP = 'LooseLHElectron',
+                                  recomputeLikelihood = False,
+                                  prefilterLikelihood = False ):
     """Create an electron analysis algorithm sequence
 
-    Keywrod arguments:
+    Keyword arguments:
       dataType -- The data type to run on ("data", "mc" or "afii")
       isolationWP -- The isolation selection working point to use
       likelihoodWP -- The likelihood selection working point to use
+      recomputeLikelihood -- Whether to rerun the LH. If not, use derivation flags
+      prefilterLikelihood -- Creates intermediate selection on LH, in case of cluster thinning etc
     """
 
     if not dataType in ["data", "mc", "afii"] :
@@ -21,6 +25,36 @@ def makeElectronAnalysisSequence( dataType,
     # Create the analysis algorithm sequence object:
     seq = AnaAlgSequence( "ElectronAnalysisSequence" )
 
+    # Set up the likelihood ID selection algorithm
+    # It is safe to do this before calibration, as the cluster E is used
+    alg = createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlg' )
+    alg.selectionDecoration = 'selectLikelihood'
+    lhNcuts = 1
+    if recomputeLikelihood:
+        # Rerun the likelihood ID
+        addPrivateTool( alg, 'selectionTool', 'AsgElectronLikelihoodTool' )
+        alg.selectionTool.primaryVertexContainer = 'PrimaryVertices'
+        alg.selectionTool.WorkingPoint = likelihoodWP
+        lhNcuts = 7
+    else:
+        # Select from Derivation Framework flags
+        addPrivateTool( alg, 'selectionTool', 'CP::AsgFlagSelectionTool' )
+        dfFlag = "DFCommonElectronsLH" + likelihoodWP.split('LH')[0]
+        alg.selectionTool.selectionFlags = [dfFlag]
+        lhNcuts = 1
+    seq.append( alg, inputPropName = 'particles',
+    outputPropName = 'particlesOut' )
+
+    # Only run subsequent processing on the objects passing LH cut
+    # This is needed e.g. for top derivations that thin the clusters
+    # from the electrons failing Loose(LH)
+    # Basically invalidates the first cutflow step
+    if prefilterLikelihood:
+        alg = createAlgorithm( 'CP::AsgViewFromSelectionAlg',
+        'ElectronLHViewFromSelectionAlg' )
+        alg.selection = [ 'selectLikelihood' ]
+        seq.append( alg, inputPropName = 'input', outputPropName = 'output' )
+
     # Set up the calibration and smearing algorithm:
     alg = createAlgorithm( 'CP::EgammaCalibrationAndSmearingAlg',
                            'ElectronCalibrationAndSmearingAlg' )
@@ -48,15 +82,6 @@ def makeElectronAnalysisSequence( dataType,
         pass
     seq.append( alg, inputPropName = 'egammas', outputPropName = 'egammasOut' )
 
-    # Set up the likelihood ID selection algorithm:
-    alg = createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlg' )
-    addPrivateTool( alg, 'selectionTool', 'AsgElectronLikelihoodTool' )
-    alg.selectionTool.primaryVertexContainer = 'PrimaryVertices'
-    alg.selectionTool.WorkingPoint = likelihoodWP
-    alg.selectionDecoration = 'selectLikelihood'
-    seq.append( alg, inputPropName = 'particles',
-                outputPropName = 'particlesOut' )
-
     # Set up the isolation selection algorithm:
     alg = createAlgorithm( 'CP::EgammaIsolationSelectionAlg',
                            'ElectronIsolationSelectionAlg' )
diff --git a/PhysicsAnalysis/Algorithms/EgammaAnalysisAlgorithms/python/PhotonAnalysisSequence.py b/PhysicsAnalysis/Algorithms/EgammaAnalysisAlgorithms/python/PhotonAnalysisSequence.py
index f0f4c4ff8a8b665b8db8975f734479661c9891b4..54252ce34b4ea6b7101f335a7cf971ef01473277 100644
--- a/PhysicsAnalysis/Algorithms/EgammaAnalysisAlgorithms/python/PhotonAnalysisSequence.py
+++ b/PhysicsAnalysis/Algorithms/EgammaAnalysisAlgorithms/python/PhotonAnalysisSequence.py
@@ -4,12 +4,18 @@
 from AnaAlgorithm.AnaAlgSequence import AnaAlgSequence
 from AnaAlgorithm.DualUseConfig import createAlgorithm, addPrivateTool
 
-def makePhotonAnalysisSequence( dataType, quality = 0 ):
+from ROOT import egammaPID
+
+def makePhotonAnalysisSequence( dataType, quality = egammaPID.PhotonTight,
+                                recomputeIsEM = False,
+                                prefilterIsEM = False):
     """Create a photon analysis algorithm sequence
 
     Keywrod arguments:
       dataType -- The data type to run on ("data", "mc" or "afii")
       quality -- The photon quality to require during the selection
+      recomputeLikelihood -- Whether to rerun the cut-based selection. If not, use derivation flags
+      prefilterLikelihood -- Creates intermediate selection on IsEM, in case of cluster thinning etc
     """
 
     if not dataType in ["data", "mc", "afii"] :
@@ -18,6 +24,35 @@ def makePhotonAnalysisSequence( dataType, quality = 0 ):
     # Create the analysis algorithm sequence object:
     seq = AnaAlgSequence( "PhotonAnalysisSequence" )
 
+    # Set up the photon selection algorithm:
+    alg = createAlgorithm( 'CP::AsgSelectionAlg', 'PhotonIsEMSelectorAlg' )
+    alg.selectionDecoration = 'selectEM'
+    if recomputeIsEM:
+        # Rerun the cut-based ID
+        addPrivateTool( alg, 'selectionTool', 'AsgPhotonIsEMSelector' )
+        alg.selectionTool.isEMMask = quality
+        alg.selectionTool.ConfigFile = \
+        'ElectronPhotonSelectorTools/offline/20180116/PhotonIsEMTightSelectorCutDefs.conf'
+    else:
+        # Select from Derivation Framework flags
+        addPrivateTool( alg, 'selectionTool', 'CP::AsgFlagSelectionTool' )
+        WPnames = {egammaPID.PhotonLoose:"Loose",
+            egammaPID.PhotonTight:"Tight"}
+        dfFlag = "DFCommonPhotonsIsEM" + WPnames[quality]
+        alg.selectionTool.selectionFlags = [dfFlag]
+    seq.append( alg, inputPropName = 'particles',
+    outputPropName = 'particlesOut' )
+
+    # Only run subsequent processing on the objects passing LH cut
+    # This is needed e.g. for top derivations that thin the clusters
+    # from the electrons failing Loose(LH)
+    # Basically invalidates the first cutflow step
+    if prefilterIsEM:
+        alg = createAlgorithm( 'CP::AsgViewFromSelectionAlg',
+        'PhotonLHViewFromSelectionAlg' )
+        alg.selection = [ 'selectIsEM' ]
+        seq.append( alg, inputPropName = 'input', outputPropName = 'output' )
+
     # Set up the calibration ans smearing algorithm:
     alg = createAlgorithm( 'CP::EgammaCalibrationAndSmearingAlg',
                            'PhotonCalibrationAndSmearingAlg' )
@@ -55,16 +90,6 @@ def makePhotonAnalysisSequence( dataType, quality = 0 ):
         pass
     seq.append( alg, inputPropName = 'egammas', outputPropName = 'egammasOut' )
 
-    # Set up the photon selection algorithm:
-    alg = createAlgorithm( 'CP::AsgSelectionAlg', 'PhotonIsEMSelectorAlg' )
-    addPrivateTool( alg, 'selectionTool', 'AsgPhotonIsEMSelector' )
-    alg.selectionTool.isEMMask = quality
-    alg.selectionTool.ConfigFile = \
-        'ElectronPhotonSelectorTools/offline/mc15_20150712/PhotonIsEMTightSelectorCutDefs.conf'
-    alg.selectionDecoration = 'selectEM'
-    seq.append( alg, inputPropName = 'particles',
-                outputPropName = 'particlesOut' )
-
     # Set up the photon efficiency correction algorithm:
     alg = createAlgorithm( 'CP::PhotonEfficiencyCorrectionAlg',
                            'PhotonEfficiencyCorrectionAlg' )
diff --git a/PhysicsAnalysis/Algorithms/EgammaAnalysisAlgorithms/share/EgammaAnalysisAlgorithmsTest_eljob.py b/PhysicsAnalysis/Algorithms/EgammaAnalysisAlgorithms/share/EgammaAnalysisAlgorithmsTest_eljob.py
index 7fec3f349dbb8671bc8ab85286f4d39df1daea67..5a18c6c65df123e067b956860f02867a5fb771c3 100755
--- a/PhysicsAnalysis/Algorithms/EgammaAnalysisAlgorithms/share/EgammaAnalysisAlgorithmsTest_eljob.py
+++ b/PhysicsAnalysis/Algorithms/EgammaAnalysisAlgorithms/share/EgammaAnalysisAlgorithmsTest_eljob.py
@@ -76,7 +76,7 @@ for alg in pileupSequence:
 # Include, and then set up the electron analysis sequence:
 from EgammaAnalysisAlgorithms.ElectronAnalysisSequence import \
     makeElectronAnalysisSequence
-electronSequence = makeElectronAnalysisSequence( dataType )
+electronSequence = makeElectronAnalysisSequence( dataType, recomputeLikelihood=True )
 electronSequence.configure( inputName = 'Electrons',
                             outputName = 'AnalysisElectrons' )
 print( electronSequence ) # For debugging
@@ -89,7 +89,7 @@ for alg in electronSequence:
 # Include, and then set up the photon analysis sequence:
 from EgammaAnalysisAlgorithms.PhotonAnalysisSequence import \
     makePhotonAnalysisSequence
-photonSequence = makePhotonAnalysisSequence( dataType )
+photonSequence = makePhotonAnalysisSequence( dataType, recomputeIsEM=True )
 photonSequence.configure( inputName = 'Photons',
                           outputName = 'AnalysisPhotons' )
 print( photonSequence ) # For debugging
diff --git a/PhysicsAnalysis/Algorithms/EgammaAnalysisAlgorithms/share/EgammaAnalysisAlgorithmsTest_jobOptions.py b/PhysicsAnalysis/Algorithms/EgammaAnalysisAlgorithms/share/EgammaAnalysisAlgorithmsTest_jobOptions.py
index fb3c73acb73c64ff50b8c6f13061d79a67752537..be36bca9707a10e51d4ef52a07274afdfd94685c 100644
--- a/PhysicsAnalysis/Algorithms/EgammaAnalysisAlgorithms/share/EgammaAnalysisAlgorithmsTest_jobOptions.py
+++ b/PhysicsAnalysis/Algorithms/EgammaAnalysisAlgorithms/share/EgammaAnalysisAlgorithmsTest_jobOptions.py
@@ -36,7 +36,7 @@ algSeq += pileupSequence
 # Include, and then set up the electron analysis sequence:
 from EgammaAnalysisAlgorithms.ElectronAnalysisSequence import \
     makeElectronAnalysisSequence
-electronSequence = makeElectronAnalysisSequence( dataType )
+electronSequence = makeElectronAnalysisSequence( dataType, recomputeLikelihood=True )
 electronSequence.configure( inputName = 'Electrons',
                             outputName = 'AnalysisElectrons' )
 print( electronSequence ) # For debugging
@@ -47,7 +47,7 @@ algSeq += electronSequence
 # Include, and then set up the photon analysis sequence:
 from EgammaAnalysisAlgorithms.PhotonAnalysisSequence import \
     makePhotonAnalysisSequence
-photonSequence = makePhotonAnalysisSequence( dataType )
+photonSequence = makePhotonAnalysisSequence( dataType, recomputeIsEM=True )
 photonSequence.configure( inputName = 'Photons',
                           outputName = 'AnalysisPhotons' )
 print( photonSequence ) # For debugging
diff --git a/PhysicsAnalysis/D3PDTools/AnaAlgorithm/AnaAlgorithm/AnaAlgorithm.h b/PhysicsAnalysis/D3PDTools/AnaAlgorithm/AnaAlgorithm/AnaAlgorithm.h
index 44e5b4b22c27ee0006506a37ecd5aaa10203d6e8..009ecdbd76ee435914aa2c9ece814a9dee91b531 100644
--- a/PhysicsAnalysis/D3PDTools/AnaAlgorithm/AnaAlgorithm/AnaAlgorithm.h
+++ b/PhysicsAnalysis/D3PDTools/AnaAlgorithm/AnaAlgorithm/AnaAlgorithm.h
@@ -20,6 +20,7 @@
 #include <vector>
 #else
 #include <AthenaBaseComps/AthHistogramAlgorithm.h>
+#include <AsgTools/MessageCheck.h>
 #endif
 
 class TH1;