From f68ad6d6c7228805cf4848766ffe883bfd08e7dc Mon Sep 17 00:00:00 2001
From: Bill Balunas <bill.balunas@cern.ch>
Date: Fri, 29 Jan 2021 13:24:27 +0100
Subject: [PATCH] Restore function to schedule CHS FlowElements

---
 .../python/ExtendedJetCommon.py               | 27 ++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkJetEtMiss/python/ExtendedJetCommon.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkJetEtMiss/python/ExtendedJetCommon.py
index 8d4942a7a588..854a1b3fac8f 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkJetEtMiss/python/ExtendedJetCommon.py
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkJetEtMiss/python/ExtendedJetCommon.py
@@ -126,7 +126,7 @@ def addAntiKt10TruthWZJets(sequence,outputlist):
         addStandardJets("AntiKt", 1.0, "TruthWZ", ptmin=40000, mods="truth_ungroomed_larger", algseq=sequence, outputGroup=outputlist)
 
 def addAntiKt4EMPFlowJetsFE(sequence, outputlist):
-    addCHSPFlowObjectsFE()   # noqa: F821 (FIXME, does not exist)
+    addCHSPFlowObjectsFE()
     addStandardJets("AntiKt", 0.4, "EMPFlowFE", ptmin=10000, ptminFilter=15000, mods="pflow_ungroomed", algseq=sequence, outputGroup=outputlist)
 
 ##################################################################  
@@ -857,7 +857,32 @@ def addCHSPFlowObjects():
             job.jetalg.Tools.append(jtm.jetconstitCHSPFlow)
             extjetlog.info("Added CHS PFlow sequence to \'jetalg\'")
             extjetlog.info(job.jetalg.Tools)
+
 ##################################################################
+# Same as above, but using xAOD::FlowElement instead of xAOD::PFO
+##################################################################   
+def addCHSPFlowObjectsFE():
+    # Only act if the collection does not already exist
+    from RecExConfig.AutoConfiguration import IsInInputFile
+    if not IsInInputFile("xAOD::FlowElementContainer","CHSFlowElements"):
+        # Check that an alg doing this has not already been inserted
+        from AthenaCommon.AlgSequence import AlgSequence
+        job = AlgSequence()
+        from JetRec.JetRecStandard import jtm
+        if not hasattr(job,"jetalgCHSPFlowFE") and not hasattr(jtm,"jetconstitCHSPFlowFE"):
+            from JetRec.JetRecConf import JetToolRunner
+            jtm += JetToolRunner("jetconstitCHSPFlowFE",
+                                 EventShapeTools=[],
+                                 Tools=[jtm.JetConstitSeq_PFlowCHS_FE])
+            # Add this tool runner to the JetAlgorithm instance "jetalg"
+            # which runs all preparatory tools
+            # This was added by JetCommon
+            job.jetalg.Tools.append(jtm.jetconstitCHSPFlowFE)
+            extjetlog.info("Added CHS PFlow (FlowElement) sequence to \'jetalg\'")
+            extjetlog.info(job.jetalg.Tools)
+
+##################################################################
+
 applyJetCalibration_xAODColl("AntiKt4EMTopo")
 updateJVT_xAODColl("AntiKt4EMTopo")
 applyJetCalibration_xAODColl("AntiKt4EMPFlow")
-- 
GitLab