From 11ce41c85cab78c3d4cecfcf46df658ba1c76bc2 Mon Sep 17 00:00:00 2001
From: Mark Hodgkinson <m.hodgkinson@sheffield.ac.uk>
Date: Tue, 25 Jul 2017 14:05:41 +0100
Subject: [PATCH] Add two job options files in share which allow us to run
 calorimeter and particle flow reconstruciton on ESD files. This is heavily
 based on CaloHiveExOpts.py Update eflowRec_entries.cxx to be aware of new
 PFClusterSelector algorithm.

Former-commit-id: 0af91d9baac3d0f102d56eae56def888925a6558
---
 .../eflowRec/share/PFlowHiveDeps.py           |  26 ++
 .../eflowRec/share/PFlowHiveExOpts.py         | 224 ++++++++++++++++++
 .../src/components/eflowRec_entries.cxx       |   3 +
 3 files changed, 253 insertions(+)
 create mode 100644 Reconstruction/eflowRec/share/PFlowHiveDeps.py
 create mode 100644 Reconstruction/eflowRec/share/PFlowHiveExOpts.py

diff --git a/Reconstruction/eflowRec/share/PFlowHiveDeps.py b/Reconstruction/eflowRec/share/PFlowHiveDeps.py
new file mode 100644
index 00000000000..fde5bf74487
--- /dev/null
+++ b/Reconstruction/eflowRec/share/PFlowHiveDeps.py
@@ -0,0 +1,26 @@
+#
+#  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+#
+
+#
+## Based on CaloHiveDeps.py: Algorithm Data Dependencies for CaloBottoUp.py
+## With small adjustments to make it work on ESD files
+
+xAODMaker__EventInfoCnvAlg.ExtraInputs =  [('EventInfo','McEventInfo')]
+xAODMaker__EventInfoCnvAlg.ExtraOutputs = [('xAOD::EventAuxInfo','EventInfoAux.'),
+                                           ('xAOD::EventInfo','EventInfo') ]
+
+topSequence.CaloTopoCluster.ExtraInputs =  [('CaloCalibrationHitContainer','LArCalibrationHitActive'),
+                                            ('CaloCalibrationHitContainer','LArCalibrationHitDeadMaterial'),
+                                            ('CaloCalibrationHitContainer','LArCalibrationHitInactive'),
+                                            ('CaloCellContainer','AllCalo')]
+topSequence.CaloTopoCluster.ExtraOutputs = [('xAOD::CaloClusterContainer','CaloCalTopoClusters'),
+                                            ('xAOD::CaloClusterAuxContainer','CaloCalTopoClustersAux.'),
+                                            ('xAOD::CaloClusterContainer','CaloTopoCluster'),
+                                            ('xAOD::CaloClusterAuxContainer','CaloTopoClusterAux.'),
+                                            ('CaloClusterCellLinkContainer','CaloTopoCluster_links'),
+                                            ('CaloClusterCellLinkContainer','CaloCalTopoClusters_links')]
+
+
+StreamESD.ExtraInputs = [('CaloCellContainer','AllCalo'),
+                         ('xAOD::CaloClusterContainer','CaloTopoCluster')]
diff --git a/Reconstruction/eflowRec/share/PFlowHiveExOpts.py b/Reconstruction/eflowRec/share/PFlowHiveExOpts.py
new file mode 100644
index 00000000000..65c7f7e19e5
--- /dev/null
+++ b/Reconstruction/eflowRec/share/PFlowHiveExOpts.py
@@ -0,0 +1,224 @@
+#
+#  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+#
+# Runs calorimeter clustering reconstruction - this part is taken from CaloHiveExOpts.py
+# Additional configuration runs particle flow MT algorithms and sets up items needed for track to calorimeter extrapolation
+
+from AthenaCommon.AlgSequence import AlgSequence
+topSequence = AlgSequence()
+
+import MagFieldServices.SetupField
+
+from AthenaCommon.GlobalFlags import globalflags
+globalflags.DetGeo = 'atlas'
+from AthenaCommon.DetFlags import DetFlags
+DetFlags.detdescr.all_setOff()
+DetFlags.detdescr.Muon_setOn()
+if hasattr(DetFlags,'BField_on'): DetFlags.BField_setOn()
+from TrkDetDescrSvc.AtlasTrackingGeometrySvc import AtlasTrackingGeometrySvc
+AtlasTrackingGeometrySvc  = svcMgr.AtlasTrackingGeometrySvc
+include('RecExCond/AllDet_detDescr.py')
+
+#---------------------------------------------------------------------------------#
+# MT-specific code
+# Get number of processes and threads
+from AthenaCommon.ConcurrencyFlags import jobproperties as jp
+nThreads = jp.ConcurrencyFlags.NumThreads()
+nProc = jp.ConcurrencyFlags.NumProcs()
+
+if nThreads >=1 :
+   from AthenaCommon.AlgScheduler import AlgScheduler
+   AlgScheduler.OutputLevel( INFO )
+   AlgScheduler.ShowControlFlow( True )
+   AlgScheduler.ShowDataDependencies( True )
+   AlgScheduler.setDataLoaderAlg( 'SGInputLoader' )
+
+   # Support for the MT-MP hybrid mode
+   if (nProc > 0) :
+
+      from AthenaCommon.Logging import log as msg
+      if (theApp.EvtMax == -1) : 
+         msg.fatal('EvtMax must be >0 for hybrid configuration')
+         sys.exit(AthenaCommon.ExitCodes.CONFIGURATION_ERROR)
+
+         if ( theApp.EvtMax % nProc != 0 ) :
+            msg.warning('EvtMax[%s] is not divisible by nProcs[%s]: MP Workers will not process all requested events',theApp.EvtMax,nProc)
+
+         chunkSize = int (theApp.EvtMax / nProc)
+
+         from AthenaMP.AthenaMPFlags import jobproperties as jps 
+         jps.AthenaMPFlags.ChunkSize= chunkSize
+         
+         msg.info('AthenaMP workers will process %s events each',chunkSize)
+
+   ## force loading of data. make sure this alg is at the front of the
+   ## AlgSequence
+   #
+   from SGComps.SGCompsConf import SGInputLoader
+   topSequence+=SGInputLoader(OutputLevel=DEBUG, ShowEventDump=False)
+
+# MT-specific code
+#---------------------------------------------------------------------------------#
+
+theApp.EvtMax = 5
+
+from xAODEventInfoCnv.xAODEventInfoCreator import xAODMaker__EventInfoCnvAlg
+topSequence+=xAODMaker__EventInfoCnvAlg()
+
+#---------------------------------------------------------------------------------#
+# NEW Conditions access infrastructure
+#
+from IOVSvc.IOVSvcConf import CondInputLoader
+topSequence += CondInputLoader( "CondInputLoader", OutputLevel=DEBUG,  )
+
+import StoreGate.StoreGateConf as StoreGateConf
+svcMgr += StoreGateConf.StoreGateSvc("ConditionStore")
+
+from IOVSvc.IOVSvcConf import CondSvc
+svcMgr += CondSvc()
+# NEW Conditions access infrastructure
+#---------------------------------------------------------------------------------#
+
+# Make sure PerfMon is off
+include( "PerfMonGPerfTools/DisablePerfMon_jobOFragment.py" )
+
+# Input file
+dataFile="/eos/atlas/atlascerngroupdisk/phys-rig/MC15Samples/ESD/mc15_13TeV.361022.Pythia8EvtGen_A14NNPDF23LO_jetjet_JZ2W.recon.ESD.e3668_s2832_r7968/ESD.08355655._001904.pool.root.1"
+
+from AthenaCommon.AthenaCommonFlags  import athenaCommonFlags
+athenaCommonFlags.FilesInput=[dataFile,dataFile]
+
+# AutoConfiguration
+from RecExConfig.RecFlags import rec
+rec.AutoConfiguration = ['everything']
+import RecExConfig.AutoConfiguration as auto
+auto.ConfigureFromListOfKeys(rec.AutoConfiguration())
+
+from RecExConfig.ObjKeyStore import objKeyStore, CfgKeyStore
+from RecExConfig.InputFilePeeker import inputFileSummary
+objKeyStore.addManyTypesInputFile(inputFileSummary['eventdata_itemsList'])
+
+#---------------------------------------------------------------------------------#
+# Detector Description
+from AtlasGeoModel import SetGeometryVersion
+from AtlasGeoModel import GeoModelInit
+
+from LArGeoAlgsNV.LArGeoAlgsNVConf import LArDetectorToolNV
+from TileGeoModel.TileGeoModelConf import TileDetectorTool
+
+ServiceMgr.GeoModelSvc.DetectorTools += [ LArDetectorToolNV(ApplyAlignments = True, GeometryConfig = "RECO"),
+                                          TileDetectorTool(GeometryConfig = "RECO")
+                                          ]
+
+
+from CaloDetMgrDetDescrCnv import CaloDetMgrDDCnv
+
+include( "TileConditions/TileConditions_jobOptions.py" )
+
+include( "CaloConditions/LArTTCellMap_ATLAS_jobOptions.py")
+include( "CaloConditions/CaloTTIdMap_ATLAS_jobOptions.py")
+
+include( "LArConditionsCommon/LArConditionsCommon_MC_jobOptions.py" )
+include( "LArConditionsCommon/LArIdMap_MC_jobOptions.py" )
+from LArConditionsCommon import LArAlignable
+ServiceMgr.DetDescrCnvSvc.DecodeIdDict = True
+# Detector Description
+#---------------------------------------------------------------------------------#
+
+import AthenaPoolCnvSvc.ReadAthenaPool  #Maybe better to break up to get rid of MetaData stuff
+
+svcMgr.EventSelector.InputCollections = athenaCommonFlags.FilesInput()
+
+from GaudiAlg.GaudiAlgConf import EventCounter
+topSequence+=EventCounter(Frequency=2)
+
+from LArROD.LArRODFlags import larRODFlags
+larRODFlags.readDigits=False
+
+from CaloRec.CaloRecFlags import jobproperties
+jobproperties.CaloRecFlags.clusterCellGetterName = 'CaloRec.CaloCellGetter.CaloCellGetter'
+
+from CaloRec.CaloCellFlags import jobproperties
+jobproperties.CaloCellFlags.doLArDeadOTXCorr=False
+
+include( "CaloRec/CaloTopoCluster_jobOptions.py" )
+
+#PFlow
+
+from eflowRec.eflowRecConf import PFLeptonSelector
+PFLeptonSelector=PFLeptonSelector("PFLeptonSelector")
+topSequence += PFLeptonSelector
+
+from eflowRec.eflowRecConf import PFTrackSelector
+PFTrackSelector=PFTrackSelector("PFTrackSelector")
+
+from eflowRec.eflowRecConf import eflowTrackCaloDummyExtensionTool
+TrackCaloExtensionTool=eflowTrackCaloDummyExtensionTool()
+
+PFTrackSelector.trackExtrapolatorTool = TrackCaloExtensionTool
+
+from InDetTrackSelectionTool.InDetTrackSelectionToolConf import InDet__InDetTrackSelectionTool
+TrackSelectionTool = InDet__InDetTrackSelectionTool()
+
+from AthenaCommon.AppMgr import ToolSvc
+ToolSvc += TrackSelectionTool
+
+TrackSelectionTool.CutLevel = "TightPrimary"
+TrackSelectionTool.minPt = 500.0 
+
+PFTrackSelector.trackSelectionTool = TrackSelectionTool
+
+topSequence += PFTrackSelector
+
+from eflowRec.eflowRecConf import PFClusterSelector
+PFClusterSelector=PFClusterSelector("PFClusterSelector")
+
+topSequence += PFClusterSelector
+
+import AthenaPoolCnvSvc.WriteAthenaPool
+logRecoOutputItemList_jobOptions = logging.getLogger( 'py:RecoOutputItemList_jobOptions' )
+from OutputStreamAthenaPool.OutputStreamAthenaPool import  createOutputStream
+
+StreamESD=createOutputStream("StreamESD","myESD.pool.root",True)
+include ("CaloRecEx/CaloRecOutputItemList_jobOptions.py")
+StreamESD.ItemList+=CaloESDList
+
+print StreamESD.ItemList
+
+#---------------------------------------------------------------------------------#
+# MT-specific code
+if nThreads >=1 :
+   include ( "CaloHiveDeps.py" )
+
+print "==========================================================================================\n"
+
+#
+## set which Algorithms can be cloned
+#
+# names of algs are:
+#  SGInputLoader
+#  xAODMaker::EventInfoCnvAlg
+#  EventCounter
+#  CaloCellMaker
+#  CmbTowerBldr
+#  CaloClusterMakerSWCmb
+#  CaloTopoCluster
+#  StreamESD
+
+#  set algCardinality = 1 to disable cloning for all Algs
+algCardinality = nThreads
+
+if (algCardinality > 1):   
+   for alg in topSequence:      
+      name = alg.name()
+      if name in ["CaloCellMaker","StreamESD"] :
+         # suppress INFO message about Alg unclonability
+         alg.Cardinality = 1
+      else:
+         alg.Cardinality = algCardinality
+
+#Change input and output container names
+topSequence.CaloTopoCluster.ClustersOutputName="CaloCalTopoClusterV2"
+topSequence.PFClusterSelector.calClustersName="CaloCalTopoClusterV2"
+           
+
diff --git a/Reconstruction/eflowRec/src/components/eflowRec_entries.cxx b/Reconstruction/eflowRec/src/components/eflowRec_entries.cxx
index 04b1cda55eb..bba1efacb4a 100644
--- a/Reconstruction/eflowRec/src/components/eflowRec_entries.cxx
+++ b/Reconstruction/eflowRec/src/components/eflowRec_entries.cxx
@@ -17,6 +17,7 @@
 #include "eflowRec/eflowVertexInformationSetter.h"
 #include "eflowRec/PFLeptonSelector.h"
 #include "eflowRec/PFTrackSelector.h"
+#include "eflowRec/PFClusterSelector.h"
 #include "GaudiKernel/DeclareFactoryEntries.h"
 
 DECLARE_ALGORITHM_FACTORY( eflowBuilder )
@@ -26,6 +27,7 @@ DECLARE_ALGORITHM_FACTORY( eflowObjectBuilder )
 DECLARE_ALGORITHM_FACTORY( eflowOverlapRemoval )
 DECLARE_ALGORITHM_FACTORY( eflowVertexInformationSetter )
 DECLARE_ALGORITHM_FACTORY( PFLeptonSelector )
+DECLARE_ALGORITHM_FACTORY( PFClusterSelector )
 DECLARE_ALGORITHM_FACTORY( PFTrackSelector )
 DECLARE_TOOL_FACTORY( eflowRecoverSplitShowersTool )
 DECLARE_TOOL_FACTORY( eflowCellLevelSubtractionTool )
@@ -47,6 +49,7 @@ DECLARE_FACTORY_ENTRIES(eflowRec) {
     DECLARE_ALGORITHM (eflowOverlapRemoval )
     DECLARE_ALGORITHM ( eflowVertexInformationSetter )
     DECLARE_ALGORITHM( PFLeptonSelector )
+    DECLARE_ALGORITHM( PFClusterSelector )
     DECLARE_ALGORITHM( PFTrackSelector )
     DECLARE_TOOL ( eflowRecoverSplitShowersTool )
     DECLARE_TOOL ( eflowCellLevelSubtractionTool )
-- 
GitLab