From b0fc4998596970c81d155102baac1eed293f2690 Mon Sep 17 00:00:00 2001
From: MatousVozak <matous.vozak@cern.ch>
Date: Mon, 24 Aug 2020 21:44:27 +0200
Subject: [PATCH] Switching builder classes to free functions, getters are now
 for fetching tools from RecLoadTools config, adding new slice settings
 (mainly track collections), making recordable as decorator, removing remap
 from FTF and adding it to slice settings

---
 .../python/TrigFastTrackFinder_Config.py      |   6 +-
 .../TrigInDetConfig/python/InDetPT.py         |  19 +-
 .../TrigInDetConfig/python/InDetSetup.py      |  35 +--
 .../TrigInDetConfig/python/InDetTrigCommon.py | 279 +++++++++---------
 .../python/InDetTrigConfigSettings.py         |  78 ++++-
 5 files changed, 234 insertions(+), 183 deletions(-)

diff --git a/Trigger/TrigAlgorithms/TrigFastTrackFinder/python/TrigFastTrackFinder_Config.py b/Trigger/TrigAlgorithms/TrigFastTrackFinder/python/TrigFastTrackFinder_Config.py
index 3ffb496fd77..9ef37087a7e 100755
--- a/Trigger/TrigAlgorithms/TrigFastTrackFinder/python/TrigFastTrackFinder_Config.py
+++ b/Trigger/TrigAlgorithms/TrigFastTrackFinder/python/TrigFastTrackFinder_Config.py
@@ -167,8 +167,10 @@ class TrigFastTrackFinderBase(TrigFastTrackFinder):
     __slots__ = []
     def __init__(self, name, type):
         TrigFastTrackFinder.__init__(self,name)
-        remapped_type = remap[type]
-        assert(remapped_type is not None)
+        #Remapping should be now covered by SliceConfigurationSetting
+        #remapped_type = remap[type]
+        #assert(remapped_type is not None)
+        remapped_type = type
 
         #Global keys/names for collections 
         from TrigInDetConfig.InDetTrigCollectionKeys import TrigPixelKeys, TrigSCTKeys
diff --git a/Trigger/TrigTools/TrigInDetConfig/python/InDetPT.py b/Trigger/TrigTools/TrigInDetConfig/python/InDetPT.py
index ca3c0f158f2..c8980be26e5 100644
--- a/Trigger/TrigTools/TrigInDetConfig/python/InDetPT.py
+++ b/Trigger/TrigTools/TrigInDetConfig/python/InDetPT.py
@@ -57,8 +57,6 @@ def makeInDetPrecisionTracking( whichSignature,
 
   ptAlgs = [] #List containing all the precision tracking algorithms hence every new added alg has to be appended to the list
 
-  print('MAT FTF col: {}'.format(inputFTFtracks) )
-
   #-----------------------------------------------------------------------------
   #                        Naming conventions
 
@@ -79,7 +77,9 @@ def makeInDetPrecisionTracking( whichSignature,
 
   #Load signature configuration (containing cut values, names of collections, etc)
   from .InDetTrigConfigSettings import getInDetTrigConfig     
-  configSetting = getInDetTrigConfig( whichSignature )
+
+  #Remap only temporary until signatures fix their naming
+  configSetting = getInDetTrigConfig( whichSignature, doRemap = False )
 
   #Atm there are mainly two output track collections one from ambiguity solver stage and one from trt,
   #we want to have the output name of the track collection the same whether TRT was run or not,
@@ -101,6 +101,8 @@ def makeInDetPrecisionTracking( whichSignature,
                              ( 'TrackCollection' , 'StoreGateSvc+' + inputFTFtracks )]
   
   from AthenaCommon.AppMgr import ToolSvc
+
+  #TODO: this part will not be needed once builders and getters are implemented also for TRT
   #-----------------------------------------------------------------------------
   #                        Choose track summary tool
   from InDetTrigRecExample.InDetTrigConfigRecLoadTools import InDetTrigTrackSummaryTool
@@ -129,13 +131,13 @@ def makeInDetPrecisionTracking( whichSignature,
 
   #-----------------------------------------------------------------------------
   #                        Ambiguity solving stage
-  from .InDetTrigCommon import TrkAmbiguityScore_builder, TrkAmbiguitySolver_builder, get_full_name
+  from .InDetTrigCommon import ambiguityScoreAlg_builder, ambiguitySolverAlg_builder, get_full_name
   ambSolvingStageAlgs = [
-                           TrkAmbiguityScore_builder( name   = get_full_name(  'TrkAmbiguityScore', configSetting.name() ),
-                                                      config = configSetting ),
+                           ambiguityScoreAlg_builder( name   = get_full_name(  core = 'TrkAmbiguityScore', suffix  = configSetting.name() ),
+                                                   config = configSetting ),
 
-                           TrkAmbiguitySolver_builder( name   = get_full_name( 'TrkAmbiguitySolver', configSetting.name() ),
-                                                       config = configSetting )
+                           ambiguitySolverAlg_builder( name   = get_full_name( core = 'TrkAmbiguitySolver', suffix = configSetting.name() ),
+                                                    config = configSetting )
                         ]
 
   #Loading the alg to the sequence
@@ -145,6 +147,7 @@ def makeInDetPrecisionTracking( whichSignature,
   for alg in ptAlgs:
       print(alg)
 
+  #TODO:implement builders and getters for TRT
   if configSetting.doTRT:
 
             proxySignature = whichSignature
diff --git a/Trigger/TrigTools/TrigInDetConfig/python/InDetSetup.py b/Trigger/TrigTools/TrigInDetConfig/python/InDetSetup.py
index 1019e5f6aeb..c796e0a2bbd 100644
--- a/Trigger/TrigTools/TrigInDetConfig/python/InDetSetup.py
+++ b/Trigger/TrigTools/TrigInDetConfig/python/InDetSetup.py
@@ -305,45 +305,30 @@ def makeInDetAlgs( whichSignature='', separateTrackParticleCreator='', rois = 'E
   if doFTF: 
       #Load signature configuration (containing cut values, names of collections, etc)
       from .InDetTrigConfigSettings import getInDetTrigConfig
-      #from .InDetPT import remapSuffix #This is just temporary
-      #TODO: we should fix signature names without need to remap!
-      #sign = remapSuffix( separateTrackParticleCreator) 
-      sign = separateTrackParticleCreator 
-      #Remove: Hot fix!
-      #if sign == 'Electron':
-      #   sign = 'electron'
-      #print('MAT:',sign)
-      configSetting = getInDetTrigConfig( sign )
+      configSetting = getInDetTrigConfig( whichSignature )
 
       from TrigFastTrackFinder.TrigFastTrackFinder_Config import TrigFastTrackFinderBase
-      theFTF = TrigFastTrackFinderBase("TrigFastTrackFinder_" + whichSignature, whichSignature)
-      theFTF.RoIs = rois
-      theFTF.TracksName = configSetting.FTFtracks() #"TrigFastTrackFinder_Tracks_" + separateTrackParticleCreator
-      
-      #the following doCloneRemoval modification should be set up in the InDetTrigSliceSettings once legacy trigger not needed
-      if whichSignature=="Electron":
-         theFTF.doCloneRemoval = True
+      theFTF = TrigFastTrackFinderBase("TrigFastTrackFinder_" + whichSignature, configSetting.name() )
+      theFTF.RoIs           = rois
+      theFTF.TracksName     = configSetting.trkTracksFTF() #Original: "TrigFastTrackFinder_Tracks_" + separateTrackParticleCreator, will be removed eventually
+      theFTF.doCloneRemoval = configSetting.doCloneRemoval()
 
       viewAlgs.append(theFTF)
 
 
       from TrigInDetConf.TrigInDetPostTools import  InDetTrigParticleCreatorToolFTF
-      from TrigEDMConfig.TriggerEDMRun3 import recordable
       from InDetTrigParticleCreation.InDetTrigParticleCreationConf import InDet__TrigTrackingxAODCnvMT
 
 
 
-      trackCollection = configSetting.FTFtrackCollection() # "HLT_IDTrack_" + separateTrackParticleCreator + "_FTF"
-
-
       theTrackParticleCreatorAlg = InDet__TrigTrackingxAODCnvMT(name = "InDetTrigTrackParticleCreatorAlg" + whichSignature,
-                                                                TrackName = configSetting.FTFtracks(),#"TrigFastTrackFinder_Tracks_" + separateTrackParticleCreator,
+                                                                TrackName = configSetting.trkTracksFTF(),#"TrigFastTrackFinder_Tracks_" + separateTrackParticleCreator,
                                                                 ParticleCreatorTool = InDetTrigParticleCreatorToolFTF)
     
-      if separateTrackParticleCreator == "BeamSpot" : 
-         theTrackParticleCreatorAlg.TrackParticlesName = trackCollection
-      else:
-         theTrackParticleCreatorAlg.TrackParticlesName = recordable( trackCollection )
+      
+      #In general all FTF trackParticle collections are recordable except beamspot to save space
+      theTrackParticleCreatorAlg.TrackParticlesName = configSetting.tracksFTF( doRecord = configSetting.isRecordable() )
+
       viewAlgs.append(theTrackParticleCreatorAlg)
 
 
diff --git a/Trigger/TrigTools/TrigInDetConfig/python/InDetTrigCommon.py b/Trigger/TrigTools/TrigInDetConfig/python/InDetTrigCommon.py
index 307d92f70c6..4e8e5a70d8f 100644
--- a/Trigger/TrigTools/TrigInDetConfig/python/InDetTrigCommon.py
+++ b/Trigger/TrigTools/TrigInDetConfig/python/InDetTrigCommon.py
@@ -17,11 +17,21 @@ def get_name_prefix():
 def get_name_suffix(signature):
    return '_%s'%signature
 
+#Retrieve full name of the algorithm/tool which consist of
+#1] Predefined PREFIX describing the scope where this tool is being used (Inner Detector Trigger) 
+#2] CORE name containing the actual name of the tool 
+#3] SUFFIX which is derived from signature name: _electron, _muonLate, _FS etc
 def get_full_name( core, suffix ):
-   return  '{}{}{}'.format(  get_name_prefix(), core, get_name_suffix(suffix) ),
+   return  '{}{}{}'.format(  get_name_prefix(), core, get_name_suffix(suffix) )
 
-#Temporary function before trk sum tool builder is ready
-def get_track_summary_tool( doTRT ):
+
+#Retrieve name of the score map
+#Map of Tracks and floats (representing score of a given track)
+def get_scoredmap( suffix ):
+   return "ScoredMap{}".format(suffix) 
+
+
+def trackSummaryTool_getter( doTRT ):
    from InDetTrigRecExample.InDetTrigConfigRecLoadTools import InDetTrigTrackSummaryTool  
    from TrigInDetConf.TrigInDetRecCommonTools           import InDetTrigTrackSummaryToolSharedHitsWithTRTPid  
 
@@ -31,9 +41,10 @@ def get_track_summary_tool( doTRT ):
    else:
       return InDetTrigTrackSummaryTool
 
-#TODO 
-#need to implement this in both FTF and PT
-#Better retrieval of summary tool (rather than through a parameter?)? Use the correct one!
+#--------------------------------------------------------------------------------------
+#TODO:
+#1] need to implement this in both FTF and PT
+#2] Convert this tool into builders and getters
 def getTrackParticleCnv( prefix, suffix, outPTTracks, outPTTrackParticles ):
   """ Use the  track collection and convert it to container of xAOD Track Particles  """
   #suffix = '_%s'suff if suff else '' #Suffix should be based on the signature and type of tracking, e.g for cosmics and PT  -> Cosmics_PT ( for FTF or EFID, Cosmics_FTF, Cosmics_EFID )
@@ -114,7 +125,7 @@ def getTrackParticleCnv( prefix, suffix, outPTTracks, outPTTrackParticles ):
 #--------------------------------------------------------------------------------------
 ## Scoring tools
 @makePublicTool
-def get_ambiguity_scoring_tool(name, config):
+def ambiguityScoringTool_builder(name, config):
 
     #NOTE extra scaling for MB on top of standard cuts (taken from Run2) -> Can we not just put it in the setting with 0.95 factor?
     #from InDetTrigRecExample.InDetTrigSliceSettings import InDetTrigSliceSettings
@@ -129,41 +140,60 @@ def get_ambiguity_scoring_tool(name, config):
     from InDetTrigRecExample.InDetTrigConfigRecLoadTools import InDetTrigTRTDriftCircleCut
 
     #NOTE: Run2 config seems to be using offline version of 
-    from InDetTrigRecExample.ConfiguredNewTrackingTrigCuts import EFIDTrackingCuts
-    InDetTrigCutValues = EFIDTrackingCuts
     #https://gitlab.cern.ch/atlas/athena/-/blob/master/InnerDetector/InDetExample/InDetRecExample/python/ConfiguredNewTrackingCuts.py
     #1] Is this really what we want here? 
-    #2] Somehow merge/adapt the settings in InDetTrigConfigSettings.py?
+    #2] TODO: Somehow merge/adapt the settings in InDetTrigConfigSettings.py?
 
-    doTRT = config.doTRT()
-    
-    if config.name() == 'cosmicsN':
+    if config.isSignature('cosmicsN'):
         #Can potentially recreate the isntance of the tool here and in the if config just have a list of parameters needed to be changed for the tool
         from InDetTrigRecExample.InDetTrigConfigRecLoadToolsCosmics import InDetTrigScoringToolCosmics_SiPattern 
         return InDetTrigScoringToolCosmics_SiPattern
     else:
-        from InDetTrackScoringTools.InDetTrackScoringToolsConf import InDet__InDetAmbiScoringTool
-        return InDet__InDetAmbiScoringTool(name                = name,
-                                       Extrapolator        = InDetTrigExtrapolator, 
-                                       DriftCircleCutTool  = InDetTrigTRTDriftCircleCut,
-                                       #to have a steeper turn-n curve
-                                       minPt               = InDetTrigCutValues.minPT(), #config.pTmin(),
-                                       maxRPhiImp          = InDetTrigCutValues.maxPrimaryImpact(),
-                                       maxZImp             = InDetTrigCutValues.maxZImpact(),
-                                       maxEta              = InDetTrigCutValues.maxEta(),
-                                       minSiClusters       = InDetTrigCutValues.minClusters(),
-                                       maxSiHoles          = InDetTrigCutValues.maxHoles(),
-                                       maxPixelHoles       = InDetTrigCutValues.maxPixelHoles(),
-                                       maxSCTHoles         = InDetTrigCutValues.maxSCTHoles(),
-                                       maxDoubleHoles      = InDetTrigCutValues.maxDoubleHoles(),
-                                       usePixel            = InDetTrigCutValues.usePixel(),
-                                       useSCT              = InDetTrigCutValues.useSCT(),
-                                       doEmCaloSeed        = False,
-                                       useTRT_AmbigFcn     = True,
-                                       minTRTonTrk         = 0,
-                                       SummaryTool         = get_track_summary_tool( doTRT ),
-                                      )
 
+        from InDetTrigRecExample.ConfiguredNewTrackingTrigCuts import EFIDTrackingCuts
+        InDetTrigCutValues = EFIDTrackingCuts
+        #Configuration of parameters based on the signature and Flags (following Run2 settings)
+        kwargs = {}
+        #Prepare default parameter settings for the tool
+        kwargs = setDefaults( kwargs,
+                              Extrapolator        = InDetTrigExtrapolator, 
+                              DriftCircleCutTool  = InDetTrigTRTDriftCircleCut,
+                              SummaryTool         = trackSummaryTool_getter( config.doTRT() ),
+                              #to have a steeper turn-n curve
+                              minPt               = config.pTmin(), #TODO: double check values, implement 0.95 for MinBias?  #InDetTrigCutValues.minPT(), #config.pTmin(),
+                              maxRPhiImp          = InDetTrigCutValues.maxPrimaryImpact(),
+                              maxZImp             = InDetTrigCutValues.maxZImpact(),
+                              maxEta              = InDetTrigCutValues.maxEta(),
+                              minSiClusters       = InDetTrigCutValues.minClusters(),
+                              maxSiHoles          = InDetTrigCutValues.maxHoles(),
+                              maxPixelHoles       = InDetTrigCutValues.maxPixelHoles(),
+                              maxSCTHoles         = InDetTrigCutValues.maxSCTHoles(),
+                              maxDoubleHoles      = InDetTrigCutValues.maxDoubleHoles(),
+                              usePixel            = InDetTrigCutValues.usePixel(),
+                              useSCT              = InDetTrigCutValues.useSCT(),
+                              doEmCaloSeed        = False,
+                              useAmbigFcn         = True, 
+                              useTRT_AmbigFcn     = False,
+                              minTRTonTrk         = 0,
+                             )
+
+        #Change some of the parameters in case of beamgas signature
+        if config.isSignature('beamgas'):
+            from InDetTrigRecExample.ConfiguredNewTrackingTrigCuts import EFIDTrackingCutsBeamGas
+            kwargs = setDefaults( kwargs,
+                                  minPt          = EFIDTrackingCutsBeamGas.minPT(),
+                                  maxRPhiImp     = EFIDTrackingCutsBeamGas.maxPrimaryImpact(),
+                                  maxZImp        = EFIDTrackingCutsBeamGas.maxZImpact(),
+                                  minSiClusters  = EFIDTrackingCutsBeamGas.minClusters(),
+                                  maxSiHoles     = EFIDTrackingCutsBeamGas.maxHoles(),
+                                  useSigmaChi2   = True
+                                )
+
+
+        from InDetTrackScoringTools.InDetTrackScoringToolsConf import InDet__InDetAmbiScoringTool
+        return InDet__InDetAmbiScoringTool(name             = name,
+                                           **kwargs
+                                           )
 
 
 
@@ -171,32 +201,29 @@ def get_ambiguity_scoring_tool(name, config):
 
 #--------------------------------------------------------------------------
 #                    Track Ambiguity algs/tools
+def associationTool_getter():
+      #TODO double check this!
+      from InDetRecExample.TrackingCommon import getInDetTrigPRDtoTrackMapToolGangedPixels
+      return getInDetTrigPRDtoTrackMapToolGangedPixels()  
 
-def get_association_tool():
-      return TrackingCommon.getInDetTrigPRDtoTrackMapToolGangedPixels(),  
-      #Which one to use?
-      from InDetTrigRecExample.InDetTrigConfigRecLoadTools import  InDetTrigPrdAssociationTool
-      return  InDetTrigPrdAssociationTool
-
-def get_track_fitter(config):
+def trackFitterTool_getter(config):
       #For now load from RecLoadTools where the config is based on: InDetTrigFlags.trackFitterType()  (gaussian, kalman, globalChi2, ...)
       #There are also variations of cosmic/TRT fitters -> Decision which fitter to return  has to be adapted based on the signature as well
-
-      if config.name() == 'cosmicsN':
+      if config.isSignature('cosmicsN'):
          from InDetTrigRecExample.InDetTrigConfigRecLoadTools import InDetTrigTrackFitterCosmics
          return InDetTrigTrackFitterCosmics
       else:
          from InDetTrigRecExample.InDetTrigConfigRecLoadTools import InDetTrigTrackFitter 
          return  InDetTrigTrackFitter
 
-def get_track_selection_tool(config):
+def trackSelectionTool_getter(config):
       #TODO this might need to be revisited!
 
-      if config.name() == 'beamgas':
+      if config.isSignature('beamgas'):
         from InDetTrigRecExample.InDetTrigConfigRecLoadToolsBeamGas import InDetTrigAmbiTrackSelectionToolBeamGas
         return InDetTrigAmbiTrackSelectionToolBeamGas
 
-      elif config.name() == 'cosmicsN':
+      elif config.isSignature('cosmicsN'):
         from InDetTrigRecExample.InDetTrigConfigRecLoadToolsCosmics import  InDetTrigAmbiTrackSelectionToolCosmicsN
         return InDetTrigAmbiTrackSelectionToolCosmicsN
 
@@ -207,19 +234,21 @@ def get_track_selection_tool(config):
 
 
 
+#--------------------------------------------------------------------------
+#                    Track Ambiguity Solver algs/tools
 
 @makePublicTool
-def get_TrkAmbiguityProcessorTool( name, config):
+def ambiguityProcessorTool_builder( name, config):
 
    #Configuration of parameters based on the signature and Flags (following Run2 settings)
    kwargs = {}
 
    #Add parameters to empty kwargs
-   if config.name() == 'cosmicsN':
+   if config.isSignature('cosmicsN'):
      kwargs = setDefaults( kwargs,
                            SuppressHoleSearch = False,
                            RefitPrds =  False)
-   elif config.name() =='electron' and InDetTrigFlags.doBremRecovery():
+   elif config.isSignature('electron') and InDetTrigFlags.doBremRecovery():
      import AthenaCommon.SystemOfUnits as Units
      kwargs = setDefaults( kwargs,
                            tryBremFit  = True,
@@ -233,123 +262,103 @@ def get_TrkAmbiguityProcessorTool( name, config):
                            MatEffects = 0  )
 
 
+   #-----------------------
+   #Set/Get subtools
+
+   trackFitterTool    = trackFitterTool_getter(config),
+
+   scoringTool        = ambiguityScoringTool_builder( name   = get_full_name( 'AmbiguityScoringTool',config.name()),
+                                                      config = config)
+
+   associationTool    = associationTool_getter()
+
+   trackSummaryTool   = trackSummaryTool_getter( config.doTRT() )
+
+   trackSelectionTool = trackSelectionTool_getter(config)
+
+
    #Return configured tool
    from TrkAmbiguityProcessor.TrkAmbiguityProcessorConf import Trk__SimpleAmbiguityProcessorTool
    return  Trk__SimpleAmbiguityProcessorTool(    name             = name , 
-                                                 Fitter           = get_track_fitter(config),
-                                                 ScoringTool      = get_ambiguity_scoring_tool( get_full_name( 'AmbiguityScoringTool',config.name()), config),
-                                                 AssociationTool  = get_association_tool(),
-                                                 TrackSummaryTool = get_track_summary_tool( config.doTRT() ),
-                                                 SelectionTool    = get_track_selection_tool(config),
-                                                 **kwargs
+                                   **setDefaults(kwargs,
+                                                 Fitter           = trackFitterTool,
+                                                 ScoringTool      = scoringTool,
+                                                 AssociationTool  = associationTool,
+                                                 TrackSummaryTool = trackSummaryTool,
+                                                 SelectionTool    = trackSelectionTool,
+                                                 )
                                              )
 
    
 
 
-
-
 #Need to differentiate between "standard" precision tracking code seeded by FTF and EFID-like/offline pattern recognition seeding configured here:
 #https://gitlab.cern.ch/atlas/athena/blob/master/InnerDetector/InDetExample/InDetRecExample/share/ConfiguredNewTrackingSiPattern.py#L499
-
+      
 
 from TrkAmbiguitySolver.TrkAmbiguitySolverConf import Trk__TrkAmbiguitySolver
-class TrkAmbiguitySolver_builder(Trk__TrkAmbiguitySolver):
-   """ 
-      This algorithm resolves any ambiguities between tracks
-      Requires ambiguity processor tool
-   """
-   def __init__(self, name, config):
+def ambiguitySolverAlg_builder(name, config):
 
-      name = '%s%s%s' %( get_name_prefix(), 'TrkAmbiguitySolver', get_name_suffix( config.name ) )
-      super(Trk__TrkAmbiguitySolver, self ).__init__( name ) 
+      #Get correct name for the ouput TrkTrack collection
+      def getTrackOutput():
+         #If we are also applying TRT then this collection is just intermediate
+         if config.doTRT():
+            return  "%s%sTrkTrack%s" %('HLT_ID', 'AmbSol', get_name_suffix( config.name() ))
+         #Otherwise use final collection name
+         else:
+            return  config.tracksPT()
 
-      #-----------------------
-      #Set alg/tool parameters
-
-      #Set input/output names
-      self.set_track_collections( config.name )
 
       #-----------------------
-      #Set subtools
-
-      self.load_ambi_processor(config.name)
+      #Set/Get subtools
+      ambiguityProcessor = ambiguityProcessorTool_builder( name   = get_full_name( 'AmbiguityProcessor', config.name()),
+                                                           config = config ) 
+
+      return Trk__TrkAmbiguitySolver( name               = name,
+                                      TrackInput         = get_scoredmap( get_name_suffix(config.name() )),
+                                      TrackOutput        = getTrackOutput(),
+                                      AmbiguityProcessor = ambiguityProcessor
+                                    )
       
 
-   #------------------------------------------------------------------
-   # Track collection naming convention 
-   def set_track_collections( self, signature ):
-         self.TrackInput   = self.get_track_input_name(signature)
-         self.TrackOutput  = self.get_track_output_name(signature)
-
-   def get_track_output_name(self,signature):
-      return  "%s%sTrkTrack%s" %('HLT_ID', 'AmbSol', signature)
-
-   def get_track_input_name(self,signature):
-      return  "ScoredMap%s" %(signature)
-
-   #------------------------------------------------------------------
-   # Loading subtools
-   def load_ambi_processor(self, config):
-      self.AmbiguityProcessor = get_TrkAmbiguityProcessorTool( get_full_name( 'AmbiguityProcessor', config.name()), config = config ) 
-      
-
-
 #--------------------------------------------------------------------------
 #                    Track Ambiguity Score algs/tools
 @makePublicTool
-def get_TrkAmbiguityScoreProcessorTool( name, config):
+def ambiguityScoreProcessorTool_builder( name, config):
    #   Tool contains backend functions for calculating score of a provided track 
    #   Score of each track is based on track parameters such as hits in the ID, higher score -> more likely to survive ambiguity resolving between tracks
-      
-      from AthenaCommon.AppMgr import ToolSvc
-      from InDetTrigRecExample.InDetTrigConfigRecLoadTools import  InDetTrigPrdAssociationTool, InDetTrigAmbiTrackSelectionTool
-
-      from TrkAmbiguityProcessor.TrkAmbiguityProcessorConf import Trk__DenseEnvironmentsAmbiguityScoreProcessorTool
-      return  Trk__DenseEnvironmentsAmbiguityScoreProcessorTool(     name               = name,
-                                                                     ScoringTool        = get_ambiguity_scoring_tool( get_full_name( 'AmbiguityScoringTool',config.name() ), config = config),
-                                                                     AssociationTool    = InDetTrigPrdAssociationTool,#TrackingCommon.getInDetTrigPRDtoTrackMapToolGangedPixels(),
-                                                                     SelectionTool      = InDetTrigAmbiTrackSelectionTool ) # #TODO this might need to be revisited!
 
+      #-----------------------
+      #Set/Get subtools
+      scoringTool = ambiguityScoringTool_builder( name   = get_full_name( 'AmbiguityScoringTool',config.name() ),
+                                                  config = config)
 
+      associationTool    = associationTool_getter()
 
+      trackSelectionTool = trackSelectionTool_getter(config)
 
-from TrkAmbiguitySolver.TrkAmbiguitySolverConf import Trk__TrkAmbiguityScore
-class TrkAmbiguityScore_builder(Trk__TrkAmbiguityScore):
-   def __init__(self, name, config):
-      """ 
-         Alg loops over provided tracks and calls subtool(TrkAmbigutyScoreProcessor) to assign scores for each one of them
-      """
-      super().__init__( name  )
-
-      self.signatureSuffix = get_name_suffix(config.name() )
+      from TrkAmbiguityProcessor.TrkAmbiguityProcessorConf import Trk__DenseEnvironmentsAmbiguityScoreProcessorTool
+      return  Trk__DenseEnvironmentsAmbiguityScoreProcessorTool( name               = name,
+                                                                 ScoringTool        = scoringTool,
+                                                                 AssociationTool    = associationTool,
+                                                                 SelectionTool      = trackSelectionTool
+                                                                )  
 
 
-      #-----------------------
-      #Set alg/tool parameters
 
-      #Set input/output names
-      self.set_track_collections( )
+from TrkAmbiguitySolver.TrkAmbiguitySolverConf import Trk__TrkAmbiguityScore
+def ambiguityScoreAlg_builder(name, config):
+      #Alg loops over provided tracks and calls subtool(TrkAmbigutyScoreProcessor) to assign scores for each one of them
 
       #-----------------------
-      #Set subtools
-      self.load_ambi_score_processor( config )
+      #Set/Get subtools
+      ambiguityScoreProcessor = ambiguityScoreProcessorTool_builder( name   = get_full_name( 'AmbiguityScoreProcessorTool', config.name()),
+                                                                     config = config )
+
+      return Trk__TrkAmbiguityScore(   name                    = name,
+                                       TrackInput              = [ config.trkTracksFTF()  ],
+                                       TrackOutput             = get_scoredmap( get_name_suffix( config.name() ) ),
+                                       AmbiguityScoreProcessor = ambiguityScoreProcessor,
+                                    )
       
 
-   #------------------------------------------------------------------
-   # Track collection naming convention 
-   def set_track_collections( self ):
-         self.TrackInput   = [ self.get_track_input_name()  ]
-         self.TrackOutput  =   self.get_track_output_name()
-
-   def get_track_output_name(self):
-      return  "%s%sTrkTrack%s" %('HLT_ID', 'AmbSol', self.signatureSuffix)
-
-   def get_track_input_name(self):
-      return  "ScoredMap%s" %(self.signatureSuffix)
-
-   #------------------------------------------------------------------
-   # Loading subtools
-   def load_ambi_score_processor(self, signatureConfig):
-      from AthenaCommon.AppMgr import ToolSvc
-      self.AmbiguityScoreProcessor = get_TrkAmbiguityScoreProcessorTool( name = get_full_name( 'AmbiguityScoreProcessorTool', signatureConfig.name()), config = signatureConfig )
diff --git a/Trigger/TrigTools/TrigInDetConfig/python/InDetTrigConfigSettings.py b/Trigger/TrigTools/TrigInDetConfig/python/InDetTrigConfigSettings.py
index fa3e18655ba..87e80181ab4 100644
--- a/Trigger/TrigTools/TrigInDetConfig/python/InDetTrigConfigSettings.py
+++ b/Trigger/TrigTools/TrigInDetConfig/python/InDetTrigConfigSettings.py
@@ -20,16 +20,49 @@ __all__    = [ "getInDetTrigConfig", "printDefinedSlices" ]
 
 # this dictionary will get filled after all the classes 
 # are definied 
-_ConfigSettings = {} 
+#_ConfigSettings = {} 
 
-def getInDetTrigConfig( name ) :
-    if name in _ConfigSettings :
-        return _ConfigSettings[name]
+
+#This function is a wrapper around functions that return name of collections
+#It checks whether the collection is specified to be recorded into EDM and if so it marks it to be recordable
+def makeRecordable(getName):
+      def recordCollection(*args, **kwargs):
+
+         #Retrieve record decision
+         record=kwargs.pop("doRecord",False) 
+
+         #Get the name of the collection
+         collectionName = getName(*args, **kwargs)
+
+         from TrigEDMConfig.TriggerEDMRun3 import recordable
+         if record:
+              return recordable( collectionName )
+         else:
+             return collectionName
+
+      return recordCollection
+            
+
+
+def getInDetTrigConfig( name, doRemap = True ) :
+   
+    #Use remapping if needed, eventually we should get rid of this by aligning nomenclature between signatures and ID
+    from TrigFastTrackFinder.TrigFastTrackFinder_Config import remap
+    signature = name
+
+    #doRemap is only temporary parameter as FTF and PT gets different signature naming ...
+    if doRemap: 
+      signature = remap[name]
+    #Crash if signature is not amongst one of the selected ones
+    assert(signature is not None), 'Signature name: {} is not amongst commonly used ones, please contact IDTrig group (hn-atlas-inner-detector-trigger@cern.ch) if you would like to add new one'.format(signature)
+
+    if signature in _ConfigSettings :
+        return _ConfigSettings[signature]
     else : 
         #       don't just return None, and do nothing as this 
         #       will just hide the error until people try to use 
         #       the bad slice configuration
-        raise Exception( "getInDetTrigConfig() called with incorrectnon existent slice: "+name )
+        raise Exception( "getInDetTrigConfig() called with incorrect non existent slice: "+signature )
         return None         
 
 
@@ -65,13 +98,21 @@ class _Settings :
         self._monPtMin            = 1*GeV
         self._roiName             = ""
         self._trackCollection     = ""
-        self._tracks              = "TrigFastTrackFinder_Tracks" # Base Name of the track collection being produced by FTF, full name is appended by signature suffix
+        self._trkTracks           = "TrigFastTrackFinder_Tracks" # Base Name of the track collection being produced by FTF, full name is appended by signature suffix, this is just temporary name and will be replaced by HLT_IDTrkTrack_Signature
 
         self._doTRT               = False
+        self._isRecordable        = True
 
   def name(self) :
    return self._name
 
+  #If signature name provided separate by underscore to be used for nomenclature
+  def suffix(self):
+      return '' if not self._name else '_' + self._name 
+
+  def isSignature(self, signature):
+      return (self._name == signature)
+
   def pTmin(self) :
    return self._pTmin 
 
@@ -123,19 +164,29 @@ class _Settings :
   def trackCollection(self) :
    return self._trackCollection
 
-  #Have separate collections for each?
-  def FTFtrackCollection(self) :
-   return self._trackCollection + '_FTF'
+  #Name of tracks from ambiguity solving stage  
+  @makeRecordable
+  def trkTracksAmbiSol(self, doRecord = False):
+   return '{}{}'.format( self._trkTracks, self.suffix() )
 
-  def PTtrackCollection(self) :
+  @makeRecordable
+  def tracksPT(self, doRecord = True ) :
    return self._trackCollection + '_IDTrig'
 
-  def FTFtracks(self) :
-   return '{}{}'.format( self._tracks, '' if not self._name else '_' + self._name )
+  @makeRecordable
+  def trkTracksFTF(self, doRecord = False):
+   return '{}{}'.format( self._trkTracks, self.suffix() )
+
+  @makeRecordable
+  def tracksFTF(self, doRecord = True) :
+   return self._trackCollection + '_FTF'
 
   def doTRT(self) :
    return self._doTRT
 
+  def isRecordable(self) :
+   return self._isRecordable
+
 
   def printout(self): 
        print( self._name, " :")
@@ -300,7 +351,8 @@ class _Settings_beamSpot( _Settings ) :
         self._roiName         = "HLT_Roi_Beamspot"
         self._trackCollection = "HLT_IDTrack_Beamspot"
 
-        self._doTRT               = False
+        self._doTRT           = False
+        self._isRecordable    = False
 
 
 # minBias
-- 
GitLab