From 626c711ef73757e836ed1c178dd7ec86856462a5 Mon Sep 17 00:00:00 2001
From: Tomasz Bold <tomasz.bold@gmail.com>
Date: Thu, 5 Nov 2020 17:26:38 +0000
Subject: [PATCH] Added Electron FEX to the newJO HLT test

---
 .../TrigEgammaFastElectronFexMTConfig.py      | 32 +++++++++++++
 .../TrigInDetConfig/python/TrigInDetConfig.py | 17 +------
 .../Electron/generateElectron.py              | 48 ++++++++++++++-----
 .../HLTMenuConfig/Menu/MenuComponents.py      | 16 +++----
 .../python/HLTMenuConfig/Muon/generateMuon.py |  4 +-
 5 files changed, 78 insertions(+), 39 deletions(-)

diff --git a/Trigger/TrigHypothesis/TrigEgammaHypo/python/TrigEgammaFastElectronFexMTConfig.py b/Trigger/TrigHypothesis/TrigEgammaHypo/python/TrigEgammaFastElectronFexMTConfig.py
index 07891a3f43df..2ee0a2d5939c 100644
--- a/Trigger/TrigHypothesis/TrigEgammaHypo/python/TrigEgammaFastElectronFexMTConfig.py
+++ b/Trigger/TrigHypothesis/TrigEgammaHypo/python/TrigEgammaFastElectronFexMTConfig.py
@@ -88,3 +88,35 @@ class EgammaFastElectronFex_HighPt(EgammaFastElectronFex_all):
         self.AcceptAll = False
         self.TrackPt = 2.0 * GeV
 
+def fastElectronFexAlgCfg(flags, name="EgammaFastElectronFex_1", rois="EMRoIs"):
+    from AthenaConfiguration.ComponentFactory import CompFactory
+    from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
+    from TrigEDMConfig.TriggerEDMRun3 import recordable
+    acc = ComponentAccumulator()
+
+    from TrackToCalo.TrackToCaloConfig import ParticleCaloExtensionToolCfg
+    extAcc = ParticleCaloExtensionToolCfg(flags)
+    extTool = acc.popToolsAndMerge(extAcc)
+
+    efex = CompFactory.TrigEgammaFastElectronFexMT("EgammaFastElectronFex_1",
+                                                    AcceptAll=True,
+                                                    TrackPt=1.0 * GeV,
+                                                    TrackPtHighEt=2.0 * GeV,
+                                                    ClusEt=20.0 * GeV,
+                                                    CaloTrackdEtaNoExtrap=0.5,
+                                                    CaloTrackdEtaNoExtrapHighEt=0.1,
+                                                    CaloTrackdETA=0.5,
+                                                    CaloTrackdPHI=0.5,
+                                                    CaloTrackdEoverPLow=0.0,
+                                                    CaloTrackdEoverPHigh=999.0,
+                                                    RCalBarrelFace=1470.0*mm,
+                                                    ZCalEndcapFace=3800.0*mm,
+                                                    ParticleCaloExtensionTool=extTool,
+                                                    ElectronsName=recordable("HLT_FastElectrons"),
+                                                    RoIs=rois,
+                                                    TrackParticlesName="HLT_IDTrack_Electron_FTF",
+                                                    TrigEMClusterName="HLT_FastCaloEMClusters"
+                                                    )
+
+    acc.addEventAlgo(efex)
+    return acc
diff --git a/Trigger/TrigTools/TrigInDetConfig/python/TrigInDetConfig.py b/Trigger/TrigTools/TrigInDetConfig/python/TrigInDetConfig.py
index 01b109eab4a7..623ac4110208 100644
--- a/Trigger/TrigTools/TrigInDetConfig/python/TrigInDetConfig.py
+++ b/Trigger/TrigTools/TrigInDetConfig/python/TrigInDetConfig.py
@@ -367,7 +367,7 @@ def TrigInDetCondCfg( flags ):
   acc.merge( mfsc )
   return acc
 
-def TrigInDetConfig( inflags, roisKey="EMRoIs", signatureName='' ):
+def trigInDetCfg( inflags, roisKey="EMRoIs", signatureName='' ):
 
   # redirect InDet.Tracking flags to point to a specific trigger setting
   flags = inflags.cloneAndReplace("InDet.Tracking", "Trigger.InDetTracking."+signatureName)
@@ -665,19 +665,6 @@ def TrigInDetConfig( inflags, roisKey="EMRoIs", signatureName='' ):
 
   return acc
 
-def indetInViewRecoCfg( flags, viewMakerName, signature='' ):
-  """ TBD if this function should be defined here or moved to the menu are, for sake of symmetry it is kept here now
-  There would certainly be additional algorithms
-  """
-
-  from TriggerMenuMT.HLTMenuConfig.Menu.MenuComponents import InViewReco
-  reco = InViewReco( viewMakerName )
-  algAcc = TrigInDetConfig( flags, roisKey=reco.inputMaker().InViewRoIs, signatureName=signature )
-
-  reco.mergeReco( algAcc )
-  return reco
-
-
 if __name__ == "__main__":
     from AthenaCommon.Configurable import Configurable
     Configurable.configurableRun3Behavior=1
@@ -704,7 +691,7 @@ if __name__ == "__main__":
     from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
     acc.merge(ByteStreamReadCfg(ConfigFlags))
 
-    acc.merge( indetInViewRecoCfg( ConfigFlags, viewMakerName="IMTest", signature="Electron" ) )
+    acc.merge( trigInDetCfg( ConfigFlags, viewMakerName="IMTest", signature="Electron" ) )
     from RegionSelector.RegSelConfig import regSelCfg
     rsc = regSelCfg( ConfigFlags )
     acc.merge( rsc )
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Electron/generateElectron.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Electron/generateElectron.py
index 213ae8b8304f..2816243c42e3 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Electron/generateElectron.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Electron/generateElectron.py
@@ -2,7 +2,7 @@
 
 from TriggerMenuMT.HLTMenuConfig.Electron.ElectronRecoSequences import l2CaloRecoCfg, l2CaloHypoCfg
 from TriggerMenuMT.HLTMenuConfig.Menu.MenuComponents import CAMenuSequence, \
-    ChainStep, Chain, createStepView, EmptyMenuSequence
+    ChainStep, Chain, createStepView, EmptyMenuSequence, InViewReco
 
 from TrigEgammaHypo.TrigEgammaFastCaloHypoTool import TrigEgammaFastCaloHypoToolFromDict
 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
@@ -37,7 +37,7 @@ def generateChains( flags,  chainDict ):
 
     accCalo.addEventAlgo(l2CaloHypo, sequenceName=stepView.getName())
 
-    fastCaloSequence = CAMenuSequence( Sequence    = l2CaloReco.sequence(),
+    fastCaloSequence = CAMenuSequence( Sequence  = l2CaloReco.sequence(),
                                      Maker       = l2CaloReco.inputMaker(),
                                      Hypo        = l2CaloHypo,
                                      HypoToolGen = TrigEgammaFastCaloHypoToolFromDict, 
@@ -55,11 +55,33 @@ def generateChains( flags,  chainDict ):
     accTrk = ComponentAccumulator()
     accTrk.addSequence(stepView)
 
-    # # # fast ID
-    from TrigInDetConfig.TrigInDetConfig import indetInViewRecoCfg
-    fastInDetReco = indetInViewRecoCfg(flags, viewMakerName='ElectronInDet', signature='Electron')
-    accTrk.merge( fastInDetReco, sequenceName=stepReco.getName() )
-    # TODO once tracking fully works remove fake hypos
+    # # # fast ID (need to be customised because require secialised configuration of the views maker - i.e. parent has to be linked)
+    name = "IMFastElectron"
+    evtViewMaker = CompFactory.EventViewCreatorAlgorithm(name,
+                                                          ViewFallThrough = True,
+                                                          RoIsLink        = 'initialRoI',
+                                                          RoITool         = CompFactory.ViewCreatorInitialROITool(),
+                                                          InViewRoIs      = name+'RoIs',
+                                                          Views           = name+'Views',
+                                                          ViewNodeName    = name+"InView",
+                                                          RequireParentView = True)
+    del name
+
+    from TrigInDetConfig.TrigInDetConfig import trigInDetCfg
+    idTracking = trigInDetCfg(flags, roisKey=evtViewMaker.InViewRoIs, signatureName="Electron")
+
+    fastInDetReco = InViewReco("FastElectron", viewMaker=evtViewMaker)
+    fastInDetReco.mergeReco(idTracking)
+    fastInDetReco.addRecoAlgo(CompFactory.AthViews.ViewDataVerifier( name = 'VDVElectronFastCalo',
+                              DataObjects=[('xAOD::TrigEMClusterContainer' , 'StoreGateSvc+HLT_FastCaloEMClusters')]) )
+
+    from TrigEgammaHypo.TrigEgammaFastElectronFexMTConfig import fastElectronFexAlgCfg
+    fastInDetReco.mergeReco(fastElectronFexAlgCfg(flags, rois=evtViewMaker.InViewRoIs))
+
+    accTrk.merge(fastInDetReco, sequenceName=stepReco.getName())
+
+    accVDVCalo = ComponentAccumulator()
+
 
 
     # TODO remove once full tracking is in place
@@ -71,11 +93,11 @@ def generateChains( flags,  chainDict ):
 
     accTrk.addEventAlgo(fakeHypoAlg, sequenceName=stepView.getName())
 
-    fastInDetSequence = CAMenuSequence( Sequence    = fastInDetReco.sequence(),
-                                      Maker       = fastInDetReco.inputMaker(),
-                                      Hypo        = fakeHypoAlg,
-                                      HypoToolGen = makeFakeHypoTool,
-                                      CA = accTrk)
+    fastInDetSequence = CAMenuSequence(Sequence    = fastInDetReco.sequence(),
+                                       Maker       = fastInDetReco.inputMaker(),
+                                       Hypo        = fakeHypoAlg,
+                                       HypoToolGen = makeFakeHypoTool,
+                                       CA = accTrk)
 
     fastInDetStep = ChainStep( name=secondStepName, Sequences=[fastInDetSequence], chainDicts=[chainDict], multiplicity=getChainMultFromDict(chainDict))
 
@@ -89,6 +111,6 @@ def generateChains( flags,  chainDict ):
     
     # # # offline egamma
     emptyStep = ChainStep(name="EmptyElStep", Sequences=[EmptyMenuSequence("EmptyElStep")], chainDicts=[chainDict])
-    chain = Chain( chainDict['chainName'], L1Thresholds=l1Thresholds, ChainSteps=[fastCaloStep, fastInDetStep, emptyStep] )
+    chain = Chain(chainDict['chainName'], L1Thresholds=l1Thresholds, ChainSteps=[fastCaloStep, fastInDetStep, emptyStep])
     
     return chain
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/MenuComponents.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/MenuComponents.py
index f21f12636640..e98f9cce66e9 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/MenuComponents.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/MenuComponents.py
@@ -828,10 +828,7 @@ class InEventReco( ComponentAccumulator ):
         self.mainSeq = seqAND( name )
         self.addSequence( self.mainSeq )
 
-        # Details below to be checked
         self.inputMakerAlg = inputMaker
-
-        # Avoid registering a duplicate
         self.addEventAlgo( self.inputMakerAlg, self.mainSeq.name )
         self.recoSeq = parOR( "InputSeq_"+self.inputMakerAlg.name )
         self.addSequence( self.recoSeq, self.mainSeq.name )
@@ -852,7 +849,7 @@ class InEventReco( ComponentAccumulator ):
 
 
 
-class InViewReco( ComponentAccumulator ):
+class InViewReco(ComponentAccumulator):
     """ Class to handle in-view reco, sets up the View maker if not provided and exposes InputMaker so that more inputs to it can be added in the process of assembling the menu """
     def __init__(self, name, viewMaker=None, roisKey=None):
         super( InViewReco, self ).__init__()
@@ -877,19 +874,20 @@ class InViewReco( ComponentAccumulator ):
         self.viewsSeq = parOR( self.viewMakerAlg.ViewNodeName )
         self.addSequence( self.viewsSeq, self.mainSeq.name )
 
-    def addInputFromFilter(self, filterAlg ):
-        assert len(filterAlg.Output) == 1, "Can only oprate on filter algs with one configured output, use addInput to setup specific inputs"
-        self.addInput( filterAlg.Output[0], "Reco_"+( filterAlg.Output[0].replace("Filtered_", "") ) )
-
     def addInput(self, inKey, outKey ):
         """Adds input (DecisionsContainer) from which the views should be created """
         self.viewMakerAlg.InputMakerInputDecisions += [ inKey ]
         self.viewMakerAlg.InputMakerOutputDecisions = outKey
 
     def mergeReco( self, ca ):
-        """ Merged CA movnig reconstruction algorithms into the right sequence """
+        """ Merge CA movnig reconstruction algorithms into the right sequence """
         return self.merge( ca, sequenceName=self.viewsSeq.getName() )
 
+    def addRecoAlgo( self, algo ):
+        """ Place algorithm in the correct reconstruction sequence """
+        return self.addEventAlgo( algo, sequenceName=self.viewsSeq.getName() )
+
+
     def addHypoAlg(self, alg):
         self.addEventAlgo( alg, self.mainSeq.name )
 
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Muon/generateMuon.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Muon/generateMuon.py
index 35f432cec8d6..c687d6abc0cb 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Muon/generateMuon.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Muon/generateMuon.py
@@ -6,7 +6,7 @@ from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
 from TrigL2MuonSA.TrigL2MuonSAConfig_newJO import l2MuFastAlgCfg, l2MuFastHypoCfg
 from TrigmuComb.TrigmuCombConfig_newJO import l2MuCombRecoCfg, l2MuCombHypoCfg
 from TrigMuonHypoMT.TrigMuonHypoMTConfig import TrigMufastHypoToolFromDict, TrigmuCombHypoToolFromDict, TrigMuonEFMSonlyHypoToolFromDict
-from TrigInDetConfig.TrigInDetConfig import TrigInDetConfig
+from TrigInDetConfig.TrigInDetConfig import trigInDetCfg
 
 from TriggerMenuMT.HLTMenuConfig.Menu.ChainDictTools import splitChainDict
 
@@ -235,7 +235,7 @@ def generateChains( flags, chainDict ):
         recoL2CB.mergeReco( MuCombViewDataVerifier() )
 
         #ID tracking
-        accID = TrigInDetConfig( flags, roisKey=recoL2CB.inputMaker().InViewRoIs, signatureName="Muon" )
+        accID = trigInDetCfg( flags, roisKey=recoL2CB.inputMaker().InViewRoIs, signatureName="Muon" )
         recoL2CB.mergeReco(accID)
 
         accL2CB.merge(recoL2CB, sequenceName = stepL2CBReco.getName())
-- 
GitLab