diff --git a/PhysicsAnalysis/Algorithms/KLFitterAnalysisAlgorithms/CMakeLists.txt b/PhysicsAnalysis/Algorithms/KLFitterAnalysisAlgorithms/CMakeLists.txt
index 8dde3d13496448389f796f9f89d2ab83f394320a..805c3acad46754da0d2acd27bd5ade7d4c1770d8 100644
--- a/PhysicsAnalysis/Algorithms/KLFitterAnalysisAlgorithms/CMakeLists.txt
+++ b/PhysicsAnalysis/Algorithms/KLFitterAnalysisAlgorithms/CMakeLists.txt
@@ -10,28 +10,49 @@ if(XAOD_ANALYSIS)
   # source from https://www.github.com/KLFitter/KLFitter
   find_package(KLFitter)
 
-  find_package( ROOT COMPONENTS Core )
-
-  # Generate a CINT dictionary source file:
-  atlas_add_root_dictionary(KLFitterAnalysisAlgorithmsLib _cintDictSource
-    ROOT_HEADERS Root/LinkDef.h
-    EXTERNAL_PACKAGES ROOT )
-
-  atlas_add_library( KLFitterAnalysisAlgorithmsLib
-    KLFitterAnalysisAlgorithms/*.h Root/*.cxx ${_cintDictSource}
-    PUBLIC_HEADERS KLFitterAnalysisAlgorithms
-    INCLUDE_DIRS ${KLFITTER_INCLUDE_DIRS}
-    PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
-    LINK_LIBRARIES ${KLFITTER_LIBRARIES}
-    AnaAlgorithmLib FourMomUtils SystematicsHandlesLib SelectionHelpersLib xAODJet xAODMuon xAODTau xAODEgamma xAODMissingET
-    FTagAnalysisInterfacesLib PathResolver
-    PRIVATE_LINK_LIBRARIES ${ROOT_LIBRARIES} PATInterfaces xAODCore xAODMetaData )
-
-  atlas_add_dictionary( KLFitterAnalysisAlgorithmsDict
-    KLFitterAnalysisAlgorithms/KLFitterAnalysisAlgorithmsDict.h
-    KLFitterAnalysisAlgorithms/selection.xml
-    LINK_LIBRARIES KLFitterAnalysisAlgorithmsLib
-    EXTRA_FILES Root/dict/*.cxx )
+  find_package( ROOT COMPONENTS Core Physics)
+
+  if(XAOD_STANDALONE)
+    # Generate a CINT dictionary source file:
+    atlas_add_root_dictionary(KLFitterAnalysisAlgorithmsLib _cintDictSource
+      ROOT_HEADERS Root/LinkDef.h
+      EXTERNAL_PACKAGES ROOT )
+
+    atlas_add_library( KLFitterAnalysisAlgorithmsLib
+      KLFitterAnalysisAlgorithms/*.h Root/*.cxx ${_cintDictSource}
+      INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${KLFITTER_INCLUDE_DIRS}
+      PUBLIC_HEADERS KLFitterAnalysisAlgorithms
+      PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
+      LINK_LIBRARIES ${ROOT_LIBRARIES} ${KLFITTER_LIBRARIES}
+      AnaAlgorithmLib FourMomUtils SystematicsHandlesLib SelectionHelpersLib xAODJet xAODMuon xAODTau xAODEgamma xAODMissingET xAODCore
+      FTagAnalysisInterfacesLib PathResolver AthContainers )
+  else()
+    atlas_add_library( KLFitterAnalysisAlgorithmsLib
+      KLFitterAnalysisAlgorithms/*.h Root/*.cxx
+      INCLUDE_DIRS ${KLFITTER_INCLUDE_DIRS}
+      PUBLIC_HEADERS KLFitterAnalysisAlgorithms
+      LINK_LIBRARIES ${KLFITTER_LIBRARIES}
+      AnaAlgorithmLib FourMomUtils SystematicsHandlesLib SelectionHelpersLib xAODJet xAODMuon xAODTau xAODEgamma xAODMissingET xAODCore
+      FTagAnalysisInterfacesLib PathResolver )
+  endif()
+
+  if(XAOD_STANDALONE)
+    atlas_add_dictionary( KLFitterAnalysisAlgorithmsDict
+      KLFitterAnalysisAlgorithms/KLFitterAnalysisAlgorithmsDict.h
+      KLFitterAnalysisAlgorithms/selection.xml
+      LINK_LIBRARIES KLFitterAnalysisAlgorithmsLib
+      EXTRA_FILES Root/dict/*.cxx )
+  else()
+    atlas_add_component(
+      KLFitterAnalysisAlgorithms src/components/*.cxx
+      LINK_LIBRARIES KLFitterAnalysisAlgorithmsLib
+    )
+    atlas_add_dictionary( KLFitterAnalysisAlgorithmsDict
+      KLFitterAnalysisAlgorithms/KLFitterAnalysisAlgorithmsDict.h
+      KLFitterAnalysisAlgorithms/selection_ath.xml
+      LINK_LIBRARIES KLFitterAnalysisAlgorithmsLib
+      EXTRA_FILES Root/dict/*.cxx )
+  endif()
 
   atlas_install_python_modules( python/*.py )
 
diff --git a/PhysicsAnalysis/Algorithms/KLFitterAnalysisAlgorithms/KLFitterAnalysisAlgorithms/KLFitterAnalysisAlgorithmsDict.h b/PhysicsAnalysis/Algorithms/KLFitterAnalysisAlgorithms/KLFitterAnalysisAlgorithms/KLFitterAnalysisAlgorithmsDict.h
index e218b495b0e75a5be50d04588f1e23472434d9ed..839aafed9ffeaf67a6df725c228a2fdb43ecd229 100644
--- a/PhysicsAnalysis/Algorithms/KLFitterAnalysisAlgorithms/KLFitterAnalysisAlgorithms/KLFitterAnalysisAlgorithmsDict.h
+++ b/PhysicsAnalysis/Algorithms/KLFitterAnalysisAlgorithms/KLFitterAnalysisAlgorithms/KLFitterAnalysisAlgorithmsDict.h
@@ -8,11 +8,11 @@
 #ifndef KLFITTERANALYSIS_ALGORITHMS_DICT_H
 #define KLFITTERANALYSIS_ALGORITHMS_DICT_H
 
+#include "KLFitterAnalysisAlgorithms/RunKLFitterAlg.h"
 #include "KLFitterAnalysisAlgorithms/KLFitterFinalizeOutputAlg.h"
 #include "KLFitterAnalysisAlgorithms/KLFitterResult.h"
 #include "KLFitterAnalysisAlgorithms/KLFitterResultAuxContainer.h"
 #include "KLFitterAnalysisAlgorithms/KLFitterResultContainer.h"
-#include "KLFitterAnalysisAlgorithms/RunKLFitterAlg.h"
 
 // EDM include(s).
 #include "xAODCore/tools/DictHelpers.h"
diff --git a/PhysicsAnalysis/Algorithms/KLFitterAnalysisAlgorithms/src/components/KLFitterReconstructionAlgorithms_entries.cxx b/PhysicsAnalysis/Algorithms/KLFitterAnalysisAlgorithms/src/components/KLFitterReconstructionAlgorithms_entries.cxx
index efef964517540e14564ef7b2eee423a87cc33ac7..121bbd54ca45d984d9418c12cc0b889937f708c2 100644
--- a/PhysicsAnalysis/Algorithms/KLFitterAnalysisAlgorithms/src/components/KLFitterReconstructionAlgorithms_entries.cxx
+++ b/PhysicsAnalysis/Algorithms/KLFitterAnalysisAlgorithms/src/components/KLFitterReconstructionAlgorithms_entries.cxx
@@ -8,5 +8,5 @@
 #include <KLFitterAnalysisAlgorithms/RunKLFitterAlg.h>
 #include <KLFitterAnalysisAlgorithms/KLFitterFinalizeOutputAlg.h>
 
-DECLARE_COMPONENT (EventReco::KLFitterFinalizeOutputAlg)
 DECLARE_COMPONENT (EventReco::RunKLFitterAlg)
+DECLARE_COMPONENT (EventReco::KLFitterFinalizeOutputAlg)