From 4fb0cca7b51b035d45347dac9640d5a318696649 Mon Sep 17 00:00:00 2001
From: Jonathan Bossio <jonathan.bossio@cern.ch>
Date: Mon, 7 Dec 2020 09:55:51 +0100
Subject: [PATCH] Small redesign of jet chain dict keys

dataType -> constitType and constitMod
calib    -> clusterCalib
---
 .../Jet/JetChainConfiguration.py              |  9 +--
 .../HLTMenuConfig/Jet/JetMenuSequences.py     |  2 +-
 .../HLTMenuConfig/Jet/JetRecoConfiguration.py | 65 +++++++++----------
 .../HLTMenuConfig/Jet/JetRecoSequences.py     |  4 +-
 .../HLTMenuConfig/MET/METRecoSequences.py     |  8 +--
 .../python/HLTMenuConfig/Menu/LS2_v1.py       | 18 ++---
 .../HLTMenuConfig/Menu/SignatureDicts.py      | 15 +++--
 7 files changed, 60 insertions(+), 61 deletions(-)

diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetChainConfiguration.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetChainConfiguration.py
index cda41f8bb654..1240e95e80e1 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetChainConfiguration.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetChainConfiguration.py
@@ -114,11 +114,11 @@ class JetChainConfiguration(ChainConfigurationBase):
         return jetCollectionName, ChainStep(stepName, [jetSeq], multiplicity=[1], chainDicts=[self.dict])
 
     def getJetCaloRecoChainStep(self):
-        stepName = "CaloRecoPTStep_jet_"+self.recoDict["calib"]
+        stepName = "CaloRecoPTStep_jet_"+self.recoDict["clusterCalib"]
         from AthenaConfiguration.AllConfigFlags import ConfigFlags
         from TriggerMenuMT.HLTMenuConfig.Jet.JetMenuSequences import jetCaloRecoMenuSequence
         jetSeq, clustersKey = RecoFragmentsPool.retrieve( jetCaloRecoMenuSequence,
-                                                          ConfigFlags, clusterCalib=self.recoDict["calib"] )
+                                                          ConfigFlags, clusterCalib=self.recoDict["clusterCalib"] )
 
         return str(clustersKey), ChainStep(stepName, [jetSeq], multiplicity=[1], chainDicts=[self.dict])
 
@@ -126,8 +126,9 @@ class JetChainConfiguration(ChainConfigurationBase):
         # Define a fixed preselection dictionary for prototyping -- we may expand the options
         preselRecoDict = {
             'recoAlg':'a4',
-            'dataType':'tc',
-            'calib':'em',
+            'constitType':'tc',
+            'clusterCalib':'em',
+            'constitMod':'',
             'jetCalib':'subjesIS',
             'trkopt':'notrk',
             'trkpresel': 'nopresel'
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetMenuSequences.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetMenuSequences.py
index 2215c5846f49..4f7793f1efe9 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetMenuSequences.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetMenuSequences.py
@@ -37,7 +37,7 @@ def jetCaloRecoSequences( configFlags, RoIs, **jetRecoDict ):
     # Get the topocluster reconstruction sequence
     from .JetRecoSequences import jetClusterSequence, jetRecoSequence
     topoClusterSequence, clustersKey = RecoFragmentsPool.retrieve(
-        jetClusterSequence, configFlags, RoIs=RoIs, clusterCalib=jetRecoDict["calib"])
+        jetClusterSequence, configFlags, RoIs=RoIs, clusterCalib=jetRecoDict["clusterCalib"])
 
     # Get the jet reconstruction sequence including the jet definition and output collection
     jetRecoSeq, jetsOut, jetDef  = RecoFragmentsPool.retrieve(
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetRecoConfiguration.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetRecoConfiguration.py
index 1f91b6668fff..394ce03e0829 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetRecoConfiguration.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetRecoConfiguration.py
@@ -15,12 +15,12 @@ from AthenaCommon.Logging import logging
 log = logging.getLogger("TriggerMenuMT.HLTMenuConfig.Jet.JetRecoConfiguration")
 
 def interpretJetCalibDefault(recoDict):
-    if recoDict['dataType'].endswith('tc'):
+    if recoDict['constitType'] == 'tc':
         return 'subresjesgscIS' if recoDict['trkopt'] == 'ftf' else 'subjesIS'
-    elif recoDict['dataType'].endswith('pf'):
+    elif recoDict['constitType'] == 'pf':
       return 'subresjesgscIS'
 
-recoKeys = ['recoAlg','dataType','calib','jetCalib','trkopt','trkpresel']
+recoKeys = ['recoAlg','constitType','clusterCalib','constitMod','jetCalib','trkopt','trkpresel']
 
 # Extract the jet reco dict from the chainDict
 def extractRecoDict(chainParts):
@@ -46,7 +46,7 @@ def extractRecoDict(chainParts):
 
 # Translate the reco dict to a string for suffixing etc
 def jetRecoDictToString(jetRecoDict):
-    strtemp = "{recoAlg}_{dataType}_{calib}_{jetCalib}"
+    strtemp = "{recoAlg}_{constitMod}_{constitType}_{clusterCalib}_{jetCalib}"
     if jetRecoDict["trkopt"] != "notrk":
         strtemp += "_{trkopt}_{trkpresel}"
     return strtemp.format(**jetRecoDict)
@@ -57,25 +57,20 @@ def jetRecoDictFromString(jet_def_string):
     # Translate the definition string into an approximation
     # of the "recoParts" in the jet chainParts.
     jetRecoDict = {}
-    # Insert values from string
-    # Python names are more descriptive. May want to sync
-    # these names with the SignatureDict, needs coordination with
-    # menu group when they start to implement this
-    trkopt = "notrk"
-    trkpresel = "nopresel"
-    if "_ftf" in jet_def_string:
-        jetalg, inputtype, clusterscale, jetcalib, trkopt = jet_def_string.split('_')
-    else:
-        jetalg, inputtype, clusterscale, jetcalib = jet_def_string.split('_')
-
-    jetRecoDict = {
-        "recoAlg":   jetalg,
-        "dataType":  inputtype,
-        "calib":     clusterscale,
-        "jetCalib":  jetcalib,
-        "trkopt" :   trkopt,
-        "trkpresel": trkpresel
-    }
+    from TriggerMenuMT.HLTMenuConfig.Menu.SignatureDicts import JetChainParts,JetChainParts_Default
+    for key in recoKeys:
+        keyFound = False
+        for part in jet_def_string.split('_'):
+            if part in JetChainParts[key]:
+                jetRecoDict[key] = part
+                keyFound         = True
+        if not keyFound:
+            jetRecoDict[key] = JetChainParts_Default[key]
+
+    # set proper jetCalib key in default case
+    if jetRecoDict['jetCalib'] == "default":
+        jetRecoDict['jetCalib'] = interpretJetCalibDefault(jetRecoDict)
+
     return jetRecoDict
 
 # Define the jet constituents to be interpreted by JetRecConfig
@@ -88,7 +83,7 @@ def defineJetConstit(jetRecoDict,clustersKey=None,pfoPrefix=None):
     # type, mods and the input container name
 
     
-    if "pf" in jetRecoDict["dataType"]:
+    if jetRecoDict["constitType"] == "pf":
         if pfoPrefix is None:
             raise RuntimeError("JetRecoConfiguration: Cannot define PF jets without pfo prefix!")
 
@@ -98,11 +93,11 @@ def defineJetConstit(jetRecoDict,clustersKey=None,pfoPrefix=None):
         constitModWithAlternateTrk("CorrectPFO", trkopt) 
         constitMods = ["CorrectPFO"+trkopt]
         # apply constituent pileup suppression
-        if "vs" in jetRecoDict["dataType"]:
+        if "vs" in jetRecoDict["constitMod"]:
             constitMods.append("Vor")
-        if "cs" in jetRecoDict["dataType"]:
+        if "cs" in jetRecoDict["constitMod"]:
             constitMods.append("CS")
-        if "sk" in jetRecoDict["dataType"]:
+        if "sk" in jetRecoDict["constitMod"]:
             constitMods.append("SK")
         # Generate a new JetConstitModifier with track proterties setup according to trkopt
         constitModWithAlternateTrk("CHS", trkopt) # 
@@ -119,20 +114,20 @@ def defineJetConstit(jetRecoDict,clustersKey=None,pfoPrefix=None):
             jetConstit = JetConstitSeq( "HLT_EMPFlow"+modstring, xAODType.ParticleFlow, constitMods, inputname=inputPFO, outputname=pfoPrefix+modstring+"ParticleFlowObjects",label='EMPFlow'+(modstring if modstring!='CHS' else '') )
 
             
-    if "tc" in jetRecoDict["dataType"]:
+    if jetRecoDict["constitType"] == "tc":
         # apply constituent pileup suppression
-        if "vs" in jetRecoDict["dataType"]:
+        if "vs" in jetRecoDict["constitMod"]:
             constitMods.append("Vor")
-        if "cs" in jetRecoDict["dataType"]:
+        if "cs" in jetRecoDict["constitMod"]:
             constitMods.append("CS")
-        if "sk" in jetRecoDict["dataType"]:
+        if "sk" in jetRecoDict["constitMod"]:
             constitMods.append("SK")
         # build a modifier identifier :
         modstring = ''.join(constitMods)
         # prepend the cluster calib state :
-        if jetRecoDict["calib"] == "em":
+        if jetRecoDict["clusterCalib"] == "em":
             constitMods = ["EM"] + constitMods
-        elif jetRecoDict["calib"] == "lcw":
+        elif jetRecoDict["clusterCalib"] == "lcw":
             constitMods = ["LC"] + constitMods
 
         jetConstit = JetConstitSeq( "HLT_"+constitMods[0]+"Topo",xAODType.CaloCluster, constitMods, inputname=clustersKey, outputname=clustersKey+modstring,label=constitMods[0]+'Topo'+modstring)
@@ -221,7 +216,7 @@ def defineCalibMods(jetRecoDict,dataSource,rhoKey="auto"):
         if jetRecoDict["trkopt"]=="notrk" and "subres" in jetRecoDict["jetCalib"]:
             raise ValueError("Pileup residual calibration requested but no track source provided!")
 
-        if jetRecoDict["dataType"].endswith("tc"):
+        if jetRecoDict["constitType"] == "tc":
             calibContext,calibSeq = {
                 ("a4","subjes"):   ("TrigRun2","JetArea_EtaJES_GSC"), # Calo GSC only
                 ("a4","subjesIS"): ("TrigRun2","JetArea_EtaJES_GSC"), # Calo GSC only
@@ -237,7 +232,7 @@ def defineCalibMods(jetRecoDict,dataSource,rhoKey="auto"):
                 gscDepth = "trackWIDTH"
                 pvname = "HLT_IDVertex_FS"
 
-        elif jetRecoDict["dataType"].endswith("pf"):
+        elif jetRecoDict["constitType"] == "pf":
             gscDepth = "auto"
             if 'sd' in jetRecoDict["recoAlg"]:
                 calibContext = "TrigSoftDrop"
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetRecoSequences.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetRecoSequences.py
index 97d40f5a0de1..b4827bf5f760 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetRecoSequences.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetRecoSequences.py
@@ -80,7 +80,7 @@ def standardJetBuildSequence( configFlags, dataSource, clustersKey, **jetRecoDic
     trkcolls = getTrkColls(jetRecoDict) if jetRecoDict["trkopt"]!="notrk" else {}
 
     # Add particle flow reconstruction if needed
-    if "pf" in jetRecoDict["dataType"]:
+    if jetRecoDict["constitType"] == "pf":
         if not trkcolls:
             raise RuntimeError("PFlow jet chain requested with no tracking option!")
         from eflowRec.PFHLTSequence import PFHLTSequence
@@ -95,8 +95,8 @@ def standardJetBuildSequence( configFlags, dataSource, clustersKey, **jetRecoDic
     # chosen jet collection
     jetsFullName = jetDef.fullname()
     jetsOut = recordable(jetsFullName)
-    doConstitMods = jetRecoDict["dataType"] in ["sktc","cssktc", "pf", "csskpf"]
     JetRecConfig.instantiateAliases(jetDef)
+    doConstitMods = jetRecoDict["constitMod"]+jetRecoDict["constitType"] in ["sktc","cssktc", "pf", "csskpf"]
     if doConstitMods:
         # Get online monitoring jet rec tool
         from JetRecTools import OnlineMon                                                  
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/METRecoSequences.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/METRecoSequences.py
index 38837b6787b5..30c6109c6519 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/METRecoSequences.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/METRecoSequences.py
@@ -41,13 +41,13 @@ def jetRecoDictForMET(**recoDict):
     jrd = {k: recoDict.get(k, JetChainParts_Default[k]) for k in jetRecoKeys}
     if "jetDataType" in recoDict:
         # Allow for the renaming dataType -> jetDataType
-        jrd["dataType"] = recoDict["jetDataType"]
-        if jrd["dataType"] == "pf":
+        jrd["constitType"] = recoDict["jetDataType"]
+        if jrd["constitType"] == "pf":
             # We only use em calibration for PFOs
-            jrd["calib"] = "em"
+            jrd["clusterCalib"] = "em"
     # For various reasons, we can store the constituent modifiers separately
     # to the data type, so we have to add that back in
-    jrd["dataType"] = recoDict.get("constitmod", "") + jrd["dataType"]
+    jrd["constitMod"] = recoDict.get("constitmod", "")
     if jrd["jetCalib"] == "default":
         jrd["jetCalib"] = interpretJetCalibDefault(jrd)
     return jrd
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1.py
index e3c862c83029..34909e5f003a 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1.py
@@ -244,10 +244,10 @@ def setupMenu():
         ChainProp(name='HLT_j85_pf_ftf_L1J20', groups=SingleJetGroup),
 
         ChainProp(name='HLT_j45_nojcalib_L1J20', groups=SingleJetGroup),
-        ChainProp(name='HLT_j45_sktc_nojcalib_L1J20', groups=SingleJetGroup),
-        ChainProp(name='HLT_j45_cssktc_nojcalib_L1J20', groups=SingleJetGroup),
+        ChainProp(name='HLT_j45_sk_nojcalib_L1J20', groups=SingleJetGroup),
+        ChainProp(name='HLT_j45_cssk_nojcalib_L1J20', groups=SingleJetGroup),
         ChainProp(name='HLT_j45_pf_nojcalib_ftf_L1J20', groups=SingleJetGroup),
-        ChainProp(name='HLT_j45_csskpf_nojcalib_ftf_L1J20', groups=SingleJetGroup),
+        ChainProp(name='HLT_j45_cssk_pf_nojcalib_ftf_L1J20', groups=SingleJetGroup),
 
         ChainProp(name='HLT_j260_320eta490_L1J20', groups=['Online',SingleJetGroup]),
 
@@ -258,12 +258,12 @@ def setupMenu():
         ChainProp(name='HLT_2j330_a10t_lcw_nojcalib_35smcINF_L1J100', groups=SingleJetGroup),
         ChainProp(name='HLT_j460_a10sd_lcw_nojcalib_L1J100', groups=SingleJetGroup),
         ChainProp(name='HLT_j460_a10sd_pf_nojcalib_ftf_L1J100', groups=SingleJetGroup),
-        ChainProp(name='HLT_j460_a10sd_csskpf_nojcalib_ftf_L1J100', groups=SingleJetGroup),
-        ChainProp(name='HLT_j460_a10sd_csskpf_nojcalib_ftf_35smcINF_L1J100', groups=SingleJetGroup),
-        ChainProp(name='HLT_2j330_a10sd_csskpf_nojcalib_ftf_35smcINF_L1J100', groups=SingleJetGroup),
-        ChainProp(name='HLT_j460_a10sd_csskpf_jes_ftf_L1J100', groups=SingleJetGroup),
-        ChainProp(name='HLT_j460_a10sd_csskpf_jes_ftf_35smcINF_L1J100', groups=SingleJetGroup),
-        ChainProp(name='HLT_2j330_a10sd_csskpf_jes_ftf_35smcINF_L1J100', groups=SingleJetGroup),
+        ChainProp(name='HLT_j460_a10sd_cssk_pf_nojcalib_ftf_L1J100', groups=SingleJetGroup),
+        ChainProp(name='HLT_j460_a10sd_cssk_pf_nojcalib_ftf_35smcINF_L1J100', groups=SingleJetGroup),
+        ChainProp(name='HLT_2j330_a10sd_cssk_pf_nojcalib_ftf_35smcINF_L1J100', groups=SingleJetGroup),
+        ChainProp(name='HLT_j460_a10sd_cssk_pf_jes_ftf_L1J100', groups=SingleJetGroup),
+        ChainProp(name='HLT_j460_a10sd_cssk_pf_jes_ftf_35smcINF_L1J100', groups=SingleJetGroup),
+        ChainProp(name='HLT_2j330_a10sd_cssk_pf_jes_ftf_35smcINF_L1J100', groups=SingleJetGroup),
 
         ChainProp(name='HLT_j0_vbenfSEP30etSEP34mass35SEP50fbet_L1J20', groups=SingleJetGroup),
 
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/SignatureDicts.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/SignatureDicts.py
index 63d7cd61fb15..bf350ddcc6b2 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/SignatureDicts.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/SignatureDicts.py
@@ -115,10 +115,12 @@ JetChainParts = {
     # Reco information
     'recoAlg'      : # Jet clustering algorithm
       ['a4', 'a10', 'a10r', 'a10t', 'a10sd'],
-    'dataType'     : # Jet input type (rename?)
-      ['tc','pf','sktc','cssktc','csskpf'],
-    'calib'        : # Topocluster calibration (change to constit mods?)
+    'constitType'  : # Jet input type
+      ['tc','pf'], # 'ufo' might be added at some point
+    'clusterCalib' : # Topocluster calibration
       ['em', 'lcw'],
+    'constitMod'   : # Constituent modifiers
+      ['sk', 'cssk'],
     'jetCalib'     : # Jet calibration
       ['jes', 'subjes', 'subjesIS', 'subjesgscIS', 'subresjesgscIS', 'nojcalib'],
     'scan'         : # No longer used?
@@ -179,8 +181,9 @@ JetChainParts_Default = {
     'subSigs'       : ['Jet'],
     #
     'recoAlg'       :'a4',
-    'dataType'      :'tc',
-    'calib'         :'em',
+    'constitType'   :'tc',
+    'clusterCalib'  :'em',
+    'constitMod'    :'',
     'jetCalib'      :'default',
     'scan'          :'FS',
     'trkopt'        : 'notrk',
@@ -336,7 +339,7 @@ METChainParts = {
     'jetCalib'       : JetChainParts['jetCalib'],
     'L2recoAlg'      : [],
     'EFrecoAlg'      : ['cell', 'tc', 'tcpufit', 'mht', 'trkmht', 'pfsum', 'cvfpufit', 'pfopufit', 'mhtpufit'],
-    'jetDataType'    : JetChainParts['dataType'],
+    'jetDataType'    : JetChainParts['constitType'],
     'L2muonCorr'     : [],
     'EFmuonCorr'     : [],
     'addInfo'        : ['FStracks'],
-- 
GitLab