From b576dab9936b66a7cc5cc351e8527f9eb66b23b6 Mon Sep 17 00:00:00 2001
From: Jonathan Burr <jon.burr@cern.ch>
Date: Thu, 19 Nov 2020 14:23:48 +0000
Subject: [PATCH] Add PFSum variants with CS/VS SK subtraction

---
 .../share/ref_RDOtoRDOTrig_v1Dev_build.ref    | 40 +++++++++++++++++++
 .../share/ref_data_v1Dev_build.ref            | 34 ++++++++++++++++
 .../TrigEDMConfig/python/TriggerEDMRun3.py    |  6 +++
 .../HLTMenuConfig/Jet/JetRecoConfiguration.py |  4 ++
 .../python/HLTMenuConfig/MET/ConfigHelpers.py |  2 +-
 .../HLTMenuConfig/MET/METRecoSequences.py     | 38 ++++++++++++++----
 .../python/HLTMenuConfig/Menu/LS2_v1.py       |  5 +++
 .../HLTMenuConfig/Menu/SignatureDicts.py      |  6 ++-
 8 files changed, 124 insertions(+), 11 deletions(-)

diff --git a/Trigger/TrigValidation/TrigAnalysisTest/share/ref_RDOtoRDOTrig_v1Dev_build.ref b/Trigger/TrigValidation/TrigAnalysisTest/share/ref_RDOtoRDOTrig_v1Dev_build.ref
index f7c1ffcee681..158790011bec 100644
--- a/Trigger/TrigValidation/TrigAnalysisTest/share/ref_RDOtoRDOTrig_v1Dev_build.ref
+++ b/Trigger/TrigValidation/TrigAnalysisTest/share/ref_RDOtoRDOTrig_v1Dev_build.ref
@@ -2664,6 +2664,30 @@ HLT_xe110_mht_L1XE50:
     0: 7
   stepFeatures:
     0: 7
+HLT_xe110_pfsum_L1XE50:
+  eventCount: 4
+  stepCounts:
+    0: 10
+    1: 4
+  stepFeatures:
+    0: 10
+    1: 4
+HLT_xe110_pfsum_cssk_L1XE50:
+  eventCount: 3
+  stepCounts:
+    0: 10
+    1: 3
+  stepFeatures:
+    0: 10
+    1: 3
+HLT_xe110_pfsum_vssk_L1XE50:
+  eventCount: 4
+  stepCounts:
+    0: 10
+    1: 4
+  stepFeatures:
+    0: 10
+    1: 4
 HLT_xe110_tc_em_L1XE50:
   eventCount: 5
   stepCounts:
@@ -2734,6 +2758,22 @@ HLT_xe30_pfsum_L1XE10:
   stepFeatures:
     0: 19
     1: 17
+HLT_xe30_pfsum_cssk_L1XE10:
+  eventCount: 16
+  stepCounts:
+    0: 19
+    1: 16
+  stepFeatures:
+    0: 19
+    1: 16
+HLT_xe30_pfsum_vssk_L1XE10:
+  eventCount: 18
+  stepCounts:
+    0: 19
+    1: 18
+  stepFeatures:
+    0: 19
+    1: 18
 HLT_xe30_tcpufit_L1XE10:
   eventCount: 14
   stepCounts:
diff --git a/Trigger/TrigValidation/TriggerTest/share/ref_data_v1Dev_build.ref b/Trigger/TrigValidation/TriggerTest/share/ref_data_v1Dev_build.ref
index bf246be7e291..5dd1ab0a5502 100644
--- a/Trigger/TrigValidation/TriggerTest/share/ref_data_v1Dev_build.ref
+++ b/Trigger/TrigValidation/TriggerTest/share/ref_data_v1Dev_build.ref
@@ -1672,6 +1672,24 @@ HLT_xe110_mht_L1XE50:
     0: 1
   stepFeatures:
     0: 1
+HLT_xe110_pfsum_L1XE50:
+  eventCount: 0
+  stepCounts:
+    0: 20
+  stepFeatures:
+    0: 20
+HLT_xe110_pfsum_cssk_L1XE50:
+  eventCount: 0
+  stepCounts:
+    0: 20
+  stepFeatures:
+    0: 20
+HLT_xe110_pfsum_vssk_L1XE50:
+  eventCount: 0
+  stepCounts:
+    0: 20
+  stepFeatures:
+    0: 20
 HLT_xe110_tc_em_L1XE50:
   eventCount: 0
 HLT_xe110_tcpufit_L1XE50:
@@ -1734,6 +1752,22 @@ HLT_xe30_pfsum_L1XE10:
   stepFeatures:
     0: 20
     1: 6
+HLT_xe30_pfsum_cssk_L1XE10:
+  eventCount: 3
+  stepCounts:
+    0: 20
+    1: 3
+  stepFeatures:
+    0: 20
+    1: 3
+HLT_xe30_pfsum_vssk_L1XE10:
+  eventCount: 2
+  stepCounts:
+    0: 20
+    1: 2
+  stepFeatures:
+    0: 20
+    1: 2
 HLT_xe30_tcpufit_L1XE10:
   eventCount: 6
   stepCounts:
diff --git a/Trigger/TriggerCommon/TrigEDMConfig/python/TriggerEDMRun3.py b/Trigger/TriggerCommon/TrigEDMConfig/python/TriggerEDMRun3.py
index dde06a068553..cc932f86b609 100644
--- a/Trigger/TriggerCommon/TrigEDMConfig/python/TriggerEDMRun3.py
+++ b/Trigger/TriggerCommon/TrigEDMConfig/python/TriggerEDMRun3.py
@@ -391,6 +391,12 @@ TriggerHLTListRun3 = [
     ('xAOD::TrigMissingETContainer#HLT_MET_pfsum',                         'BS ESD AODFULL AODSLIM AODVERYSLIM', 'MET'),
     ('xAOD::TrigMissingETAuxContainer#HLT_MET_pfsumAux.',                  'BS ESD AODFULL AODSLIM AODVERYSLIM', 'MET'),
 
+    ('xAOD::TrigMissingETContainer#HLT_MET_pfsum_cssk',                    'BS ESD AODFULL AODSLIM AODVERYSLIM', 'MET'),
+    ('xAOD::TrigMissingETAuxContainer#HLT_MET_pfsum_csskAux.',             'BS ESD AODFULL AODSLIM AODVERYSLIM', 'MET'),
+
+    ('xAOD::TrigMissingETContainer#HLT_MET_pfsum_vssk',                    'BS ESD AODFULL AODSLIM AODVERYSLIM', 'MET'),
+    ('xAOD::TrigMissingETAuxContainer#HLT_MET_pfsum_vsskAux.',             'BS ESD AODFULL AODSLIM AODVERYSLIM', 'MET'),
+
     ('xAOD::TrigMissingETContainer#HLT_MET_pfopufit',                      'BS ESD AODFULL AODSLIM AODVERYSLIM', 'MET'),
     ('xAOD::TrigMissingETAuxContainer#HLT_MET_pfopufitAux.',               'BS ESD AODFULL AODSLIM AODVERYSLIM', 'MET'),
 
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetRecoConfiguration.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetRecoConfiguration.py
index 1e775defaf45..6c5b54bb1b81 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetRecoConfiguration.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetRecoConfiguration.py
@@ -98,6 +98,8 @@ def defineJetConstit(jetRecoDict,clustersKey=None,pfoPrefix=None):
         constitModWithAlternateTrk("CorrectPFO", trkopt) 
         constitMods = ["CorrectPFO"+trkopt]
         # apply constituent pileup suppression
+        if "vs" in jetRecoDict["dataType"]:
+            constitMods.append("Vor")
         if "cs" in jetRecoDict["dataType"]:
             constitMods.append("CS")
         if "sk" in jetRecoDict["dataType"]:
@@ -119,6 +121,8 @@ def defineJetConstit(jetRecoDict,clustersKey=None,pfoPrefix=None):
             
     if "tc" in jetRecoDict["dataType"]:
         # apply constituent pileup suppression
+        if "vs" in jetRecoDict["dataType"]:
+            constitMods.append("Vor")
         if "cs" in jetRecoDict["dataType"]:
             constitMods.append("CS")
         if "sk" in jetRecoDict["dataType"]:
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/ConfigHelpers.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/ConfigHelpers.py
index a502306913d0..0e6b550921a7 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/ConfigHelpers.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/ConfigHelpers.py
@@ -17,7 +17,7 @@ log = logging.getLogger(__name__)
 
 # The keys from the MET chain dict that directly affect reconstruction
 # The order here is important as it also controls the dict -> string conversion
-recoKeys = ["EFrecoAlg", "calib", "jetDataType", "jetCalib", "addInfo"]
+recoKeys = ["EFrecoAlg", "calib", "jetDataType", "constitmod", "jetCalib", "addInfo"]
 metFSRoIs = [caloFSRoI, trkFSRoI]
 
 def metRecoDictToString(recoDict, skipDefaults=True):
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/METRecoSequences.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/METRecoSequences.py
index 3ba1a92a7675..38837b6787b5 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/METRecoSequences.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/METRecoSequences.py
@@ -45,6 +45,9 @@ def jetRecoDictForMET(**recoDict):
         if jrd["dataType"] == "pf":
             # We only use em calibration for PFOs
             jrd["calib"] = "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"]
     if jrd["jetCalib"] == "default":
         jrd["jetCalib"] = interpretJetCalibDefault(jrd)
     return jrd
@@ -91,6 +94,20 @@ class ClusterInputConfig(AlgInputConfig):
             )
         else:
             raise ValueError(f"Invalid value for cluster calibration: {calib}")
+        sequences = [tcSeq]
+        if recoDict.get("constitmod"):
+            # Force the datatype to topoclusters
+            recoDict = copy.copy(recoDict)
+            recoDict["jetDataType"] = "tc"
+            jetRecoDict = jetRecoDictForMET(**recoDict)
+            constit = aliasToInputDef(
+                defineJetConstit(jetRecoDict, clustersKey=clusterName)
+            )
+            constit_mod_seq = getConstitModAlg(constit)
+            sequences.append(constit_mod_seq)
+            # Update the name to the modified container name
+            clusterName = constit.containername
+
         return [tcSeq], {"Clusters": clusterName}
 
 
@@ -165,13 +182,18 @@ class PFOInputConfig(AlgInputConfig):
             tracktype="ftf",
         )
         # The jet constituent modifier sequence here is to apply the correct weights
-        # and decorate the PV matching decoration
+        # and decorate the PV matching decoration. If we've specified constituent
+        # modifiers those are also applied.
+        recoDict = copy.copy(recoDict)
+        # Force the jet data type to the correct thing
+        recoDict["jetDataType"] = "pf"
         jetRecoDict = jetRecoDictForMET(trkopt="ftf", **recoDict)
-        jetRecoDict["calib"] = "em"
-        jetRecoDict["dataType"] = "pf"
-        constit_mod_seq = getConstitModAlg(
-            aliasToInputDef(defineJetConstit(jetRecoDict, pfoPrefix=pfoPrefix))
-        )
+        constit = aliasToInputDef(defineJetConstit(jetRecoDict, pfoPrefix=pfoPrefix))
+        constit_mod_seq = getConstitModAlg(constit)
+        # Update the PFO prefix
+        pfoPrefix = constit.containername
+        if pfoPrefix.endswith("ParticleFlowObjects"):
+            pfoPrefix = pfoPrefix[:-19]
         allSeqs = [pfSeq]
         if constit_mod_seq:
             allSeqs.append(constit_mod_seq)
@@ -179,8 +201,8 @@ class PFOInputConfig(AlgInputConfig):
             allSeqs,
             {
                 "PFOPrefix": pfoPrefix,
-                "cPFOs": pfoPrefix + "CHSChargedParticleFlowObjects",
-                "nPFOs": pfoPrefix + "CHSNeutralParticleFlowObjects",
+                "cPFOs": pfoPrefix + "ChargedParticleFlowObjects",
+                "nPFOs": pfoPrefix + "NeutralParticleFlowObjects",
             },
         )
 
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1.py
index 5d800a8a7c06..44eaf8792016 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1.py
@@ -199,6 +199,8 @@ def setupMenu():
         ChainProp(name='HLT_xe30_tcpufit_L1XE10', groups=SingleMETGroup),
         ChainProp(name='HLT_xe30_trkmht_L1XE10', groups=SingleMETGroup),
         ChainProp(name='HLT_xe30_pfsum_L1XE10', groups=SingleMETGroup),
+        ChainProp(name='HLT_xe30_pfsum_cssk_L1XE10', groups=SingleMETGroup),
+        ChainProp(name='HLT_xe30_pfsum_vssk_L1XE10', groups=SingleMETGroup),
         ChainProp(name='HLT_xe30_pfopufit_L1XE10', groups=SingleMETGroup),
         ChainProp(name='HLT_xe30_cvfpufit_L1XE10', groups=SingleMETGroup),
         ChainProp(name='HLT_xe30_mhtpufit_em_subjesgscIS_L1XE10', groups=SingleMETGroup),
@@ -210,6 +212,9 @@ def setupMenu():
         ChainProp(name='HLT_xe110_tc_em_L1XE50', groups=SingleMETGroup),
         ChainProp(name='HLT_xe110_mht_L1XE50', groups=SingleMETGroup),
         ChainProp(name='HLT_xe110_tcpufit_L1XE50', groups=SingleMETGroup),
+        ChainProp(name='HLT_xe110_pfsum_L1XE50', groups=SingleMETGroup),
+        ChainProp(name='HLT_xe110_pfsum_cssk_L1XE50', groups=SingleMETGroup),
+        ChainProp(name='HLT_xe110_pfsum_vssk_L1XE50', groups=SingleMETGroup),
         # MultiMET Chain
         ChainProp(name='HLT_xe30_cell_xe30_tcpufit_L1XE10', l1SeedThresholds=['XE10']*2, groups=MultiMETGroup), #must be FS seeded
         # ATR-21934
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/SignatureDicts.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/SignatureDicts.py
index 62a9bebfc901..22cb4f5be5a7 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/SignatureDicts.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/SignatureDicts.py
@@ -317,8 +317,9 @@ METChainParts = {
     'L2muonCorr'     : [],
     'EFmuonCorr'     : [],
     'addInfo'        : ['FStracks'],
-    'sigFolder'     : 'MET',
-    'subSigs'       : ['MET']
+    'sigFolder'      : 'MET',
+    'subSigs'        : ['MET'],
+    'constitmod'     : ['cssk', 'vssk']
 }
 # ---- MetDictionary of default Values ----
 METChainParts_Default = {
@@ -336,6 +337,7 @@ METChainParts_Default = {
     'EFmuonCorr'     : '',
     'addInfo'        : '',
     'jetDataType'    : 'tc',
+    'constitmod'     : '',
     'sigFolder'     : 'MET',
     'subSigs'       : ['MET']
 }
-- 
GitLab