From c055c996d2b99c4818f9ce412eb4f2f1d72b2af4 Mon Sep 17 00:00:00 2001
From: Matthew Thomas Anthony <matthew.thomas.anthony@cern.ch>
Date: Mon, 26 Oct 2020 10:34:40 +0000
Subject: [PATCH] Add new ART test for the FlowElement configuration

---
 Event/xAOD/xAODPFlow/CMakeLists.txt           |  2 +
 ...ecexreco_art_pflow_fromesd_FlowElements.sh | 17 ++++
 .../share/run_ESDStandardReco_FlowElements.py | 30 +++++++
 .../eflowRec/share/validateFlowElements.py    | 78 +++++++++++++++++++
 4 files changed, 127 insertions(+)
 create mode 100644 Reconstruction/RecExample/RecExRecoTest/test/test_recexreco_art_pflow_fromesd_FlowElements.sh
 create mode 100644 Reconstruction/eflowRec/share/run_ESDStandardReco_FlowElements.py
 create mode 100644 Reconstruction/eflowRec/share/validateFlowElements.py

diff --git a/Event/xAOD/xAODPFlow/CMakeLists.txt b/Event/xAOD/xAODPFlow/CMakeLists.txt
index aad1df5cc88..d5a3754372b 100644
--- a/Event/xAOD/xAODPFlow/CMakeLists.txt
+++ b/Event/xAOD/xAODPFlow/CMakeLists.txt
@@ -25,3 +25,5 @@ atlas_add_dictionary( xAODPFlowDict
    ${_selectionFile}
    LINK_LIBRARIES AthLinks xAODCore xAODPFlow
    EXTRA_FILES Root/dict/*.cxx )
+
+atlas_generate_cliddb( xAODPFlow)
\ No newline at end of file
diff --git a/Reconstruction/RecExample/RecExRecoTest/test/test_recexreco_art_pflow_fromesd_FlowElements.sh b/Reconstruction/RecExample/RecExRecoTest/test/test_recexreco_art_pflow_fromesd_FlowElements.sh
new file mode 100644
index 00000000000..709d6aa8ead
--- /dev/null
+++ b/Reconstruction/RecExample/RecExRecoTest/test/test_recexreco_art_pflow_fromesd_FlowElements.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+#
+# art-description: Athena runs Standard ESD reconstruction including FlowElements, which are not in the default run
+# art-type: grid
+# art-include master/Athena
+# art-athena-mt: 8
+# art-output: AOD.pool.root
+# art-output: log_FE_validation.txt
+
+export ATHENA_CORE_NUMBER=8 # set number of cores used in multithread to 8.
+
+athena.py eflowRec/run_ESDStandardReco_FlowElements.py 
+rc1=$?
+python eflowRec/validateFlowElements.py --f AOD.pool.root &> log_FE_validation.txt
+rc2=$?
+echo "art-result: ${rc1} ESDtoAOD_FE"
+echo "art-result: ${rc2} AOD_readout"
diff --git a/Reconstruction/eflowRec/share/run_ESDStandardReco_FlowElements.py b/Reconstruction/eflowRec/share/run_ESDStandardReco_FlowElements.py
new file mode 100644
index 00000000000..a852100484d
--- /dev/null
+++ b/Reconstruction/eflowRec/share/run_ESDStandardReco_FlowElements.py
@@ -0,0 +1,30 @@
+#This file is to run standard reconstruction + Flow Elements on an ESD file (Primarily the Flow Element configuration)
+
+from AthenaCommon.AthenaCommonFlags import athenaCommonFlags
+athenaCommonFlags.FilesInput=["/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/RecExRecoTest/mc16_13TeV.361022.Pythia8EvtGen_A14NNPDF23LO_jetjet_JZ2W.recon.ESD.e3668_s3170_r10572_homeMade.pool.root"]
+
+doDumpProperties=True
+
+from RecExConfig.RecAlgsFlags import recAlgs
+recAlgs.doEFlow.set_Value_and_Lock(True)
+
+from eflowRec.eflowRecFlags import jobproperties
+jobproperties.eflowRecFlags.useFlowElements.set_Value_and_Lock(True)
+
+from RecExConfig.RecFlags import rec
+rec.doTrigger.set_Value_and_Lock(False)
+
+#change some calo flags
+from CaloRec.CaloRecFlags import jobproperties
+jobproperties.CaloRecFlags.Enabled.set_Value_and_Lock(True)
+jobproperties.CaloRecFlags.doCaloCluster.set_Value_and_Lock(True)
+jobproperties.CaloRecFlags.doEmCluster.set_Value_and_Lock(False)
+jobproperties.CaloRecFlags.doCaloTopoCluster.set_Value_and_Lock(True)
+
+#Turn of TAG
+rec.doWriteTAG.set_Value_and_Lock(False)
+
+athenaCommonFlags.EvtMax=30
+#Run pflow jet finding - this cannot be enabled via reconstruction flags currently! (without enabling other things we don't want)                                                   
+UserAlgs = ["eflowRec/jetAlgs.py"]
+include ("RecExCommon/RecExCommon_topOptions.py")
diff --git a/Reconstruction/eflowRec/share/validateFlowElements.py b/Reconstruction/eflowRec/share/validateFlowElements.py
new file mode 100644
index 00000000000..89c52c0cf6d
--- /dev/null
+++ b/Reconstruction/eflowRec/share/validateFlowElements.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+#python script to read the xAOD file
+import os
+import sys
+import ROOT
+import collections
+from pprint import pprint
+import argparse
+def ReadMyxAOD(evt):
+    result=[]
+    for i in range(0,evt.getEntries()):
+        evt.getEntry(i)
+
+
+        
+        acc_chargedFE_muon=ROOT.SG.AuxElement.ConstAccessor(
+            "vector<ElementLink<xAOD::MuonContainer>>"
+        )("FE_MuonLinks") # accessor matches type in the aux branch
+        acc_neutralFE_muon=ROOT.SG.AuxElement.ConstAccessor(
+            "vector<ElementLink<xAOD::MuonContainer>>"
+        )("FE_MuonLinks") # accessor matches type in the aux branch
+
+        chargedFEcont=evt.retrieve("xAOD::FlowElementContainer","JetETMissChargedFlowElements")
+        nchargedFE=chargedFEcont.size()
+        try:
+            for cfe in chargedFEcont:
+                cfe_pt=cfe.p4().Pt()
+                print("Charged Flow Element Pt(): {}".format(cfe_pt))
+                if (acc_chargedFE_muon.isAvailable(cfe)):
+                    auxcont_cfe=acc_charged_FE_muon(cfe)
+                    for itr in range(0,auxcont_cfe.size()):
+                        auxlink=auxcont_cfe[itr]
+                        if(auxlink.isValid()):
+                            print("Got a link to a muon")
+                else:
+                    print("No auxdata retrieved")
+
+        try:
+            neutralFEcont=evt.retrieve("xAOD::FlowElementContainer","JetETMissNeutralFlowElements")
+            print("\n")
+            nneutralFE=neutralFEcont.size()
+            for nfe in neutralFEcont:
+                nfe_pt=nfe.p4().Pt()
+                print("Neutral Flow Element Pt(): {}".format(cfe_pt))
+                if (acc_neutralFE_muon.isAvailable(cfe)):
+                    auxcont_nfe=acc_neutral_FE_muon(cfe)
+                    for itr in range(0,auxcont_nfe.size()):
+                        auxlink=auxcont_nfe[itr]
+                        if(auxlink.isValid()):
+                            print("Got a link to a muon")
+                else:
+                    print("No auxdata retrieved")
+        except:
+            print("No charged FE container accessible")
+            nneutralFE=0
+        
+        outputdict={"nChargedFE":nchargedFE,"nNeutralFE":nneutralFE}
+        result.append(outputdict)
+    return result
+
+def main():
+    parser=argparse.ArgumentParser("validateFlowElements.py - script to read xAOD and dump a nice histogram of the efraction")
+    parser.add_argument("--f",dest="files",action="store",default="",help='Input file (default = "")')
+    opts=parser.parse_args()
+    if(opts.files==""):
+        print("No file specified")
+        sys.exit(-1)
+
+    evt=ROOT.POOL.TEvent(ROOT.POOL.TEvent.kClassAccess)
+    stat=evt.readFrom(opts.files)
+
+    result=ReadMyxAOD(evt)
+    print("\n Printing output")
+    for item in result:
+        print(item)
+
+if __name__=="__main__":
+    main()
-- 
GitLab