From 780d0fedf8f35f1f09a68b722d89df3826999d02 Mon Sep 17 00:00:00 2001
From: Gianantonio Pezzullo <g.pezzullo@yale.edu>
Date: Mon, 5 Apr 2021 06:00:40 +0000
Subject: [PATCH] Fixed the way the ComboHypoTool module takes the legs + added
 comboHypo 03dRAB to the Tau+X chains ATR-22652

---
 .../src/TrigComboHypoTool.cxx                 | 35 ++++++++++++++-----
 .../src/TrigComboHypoTool.h                   |  4 +--
 .../share/ref_RDOtoRDOTrig_v1Dev_build.ref    |  6 ++--
 .../share/ref_data_v1Dev_build.ref            |  6 ++--
 .../Combined/GenerateCombinedChainDefs.py     |  8 ++---
 .../HLTMenuConfig/Menu/GenerateMenuMT.py      | 31 ++++++++--------
 .../python/HLTMenuConfig/Menu/LS2_v1.py       |  6 ++--
 7 files changed, 58 insertions(+), 38 deletions(-)

diff --git a/Trigger/TrigHypothesis/TrigHypoCommonTools/src/TrigComboHypoTool.cxx b/Trigger/TrigHypothesis/TrigHypoCommonTools/src/TrigComboHypoTool.cxx
index f2fc907f9707..7f9fdf2e9806 100644
--- a/Trigger/TrigHypothesis/TrigHypoCommonTools/src/TrigComboHypoTool.cxx
+++ b/Trigger/TrigHypothesis/TrigHypoCommonTools/src/TrigComboHypoTool.cxx
@@ -31,12 +31,12 @@ StatusCode TrigComboHypoTool::initialize()
     ATH_MSG_DEBUG("m_monTool name: " << m_monTool);
   }
 
-  if (m_legA<0){
-    ATH_MSG_ERROR("Index for legA not set! legA = "<<m_legA);
+  if (m_legA==""){
+    ATH_MSG_ERROR("LegA not set!");
     return StatusCode::FAILURE;
   }
-  if (m_legB<0){
-    ATH_MSG_ERROR("Index for legB not set! legB = "<<m_legB);
+  if (m_legB==""){
+    ATH_MSG_ERROR("LegB not set!");
     return StatusCode::FAILURE;
   }
   if ((!m_useMin) && (!m_useMax)){
@@ -62,13 +62,32 @@ bool TrigComboHypoTool::executeAlg(std::vector<LegDecision> &combination) const
     ATH_MSG_ERROR("Number of legs found is less than 2! N_legs = " << combination.size() );
     return false;
   }
+  int           legA_index(-1), legB_index(-1);
+
+  ATH_MSG_DEBUG("Legs available = "<< combination);
+  for (int i=0; i<nCombs; ++i){
+    auto combId = HLT::Identifier(combination[i].first);
+    if (!TrigCompositeUtils::isLegId(combId))
+      continue;
+    std::string   legName = combId.name().substr(0,6);
+    if (legName == m_legA){
+      legA_index = i;
+    }else  if (legName == m_legB){
+      legB_index = i;
+    }
+    ATH_MSG_DEBUG("\t Leg: "<< legName <<", full name:"<<combId.name());
+  }
 
-  if ( (m_legA >= nCombs) || (m_legB >= nCombs)){
-    ATH_MSG_ERROR("One or both leg indexes are out of range: n_combinations =  " << combination.size() <<", legA = "<<m_legA<<", legB = "<< m_legB );
+  if ( legA_index<0){
+    ATH_MSG_ERROR("legA = "<< m_legA << " NOT FOUND!");
+    return false;
+  }
+  if ( legB_index<0){
+    ATH_MSG_ERROR("legB = "<< m_legB << " NOT FOUND!");
     return false;
   }
 
-  auto EL= combination[m_legA].second;    
+  auto EL= combination[legA_index].second;    
   auto legA_pLink = TrigCompositeUtils::findLink<xAOD::IParticleContainer>( *EL, featureString() ).link;
   if (!legA_pLink.isValid()){
     ATH_MSG_ERROR("link for "<<m_legA<<" not valid");
@@ -76,7 +95,7 @@ bool TrigComboHypoTool::executeAlg(std::vector<LegDecision> &combination) const
   }
   ATH_MSG_DEBUG("link for legA: "<<m_legA<<" is valid");
 
-  EL = combination[m_legB].second;
+  EL = combination[legB_index].second;
   auto legB_pLink = TrigCompositeUtils::findLink<xAOD::IParticleContainer>( *EL, featureString() ).link;
   if (!legB_pLink.isValid()){
     ATH_MSG_ERROR("link for "<<m_legB<<" not valid");
diff --git a/Trigger/TrigHypothesis/TrigHypoCommonTools/src/TrigComboHypoTool.h b/Trigger/TrigHypothesis/TrigHypoCommonTools/src/TrigComboHypoTool.h
index 937ca54f9c66..00fc97f50214 100644
--- a/Trigger/TrigHypothesis/TrigHypoCommonTools/src/TrigComboHypoTool.h
+++ b/Trigger/TrigHypothesis/TrigHypoCommonTools/src/TrigComboHypoTool.h
@@ -50,8 +50,8 @@ class TrigComboHypoTool:  public ComboHypoToolBase {
   Gaudi::Property< bool >      m_useMax    {this, "UseMax"   , false, "Apply max_cut"     };
 
   //legs
-  Gaudi::Property<int>         m_legA      {this, "LegA"     ,    -1, "First Leg"};
-  Gaudi::Property<int>         m_legB      {this, "LegB"     ,    -1, "Second Leg"};
+  Gaudi::Property<std::string> m_legA      {this, "LegA"     ,    "", "First Leg"};
+  Gaudi::Property<std::string> m_legB      {this, "LegB"     ,    "", "Second Leg"};
 
   // cuts
   Gaudi::Property<float> m_varMin {this,"LowerCut", -9999., "Lower cut for legs pair"};
diff --git a/Trigger/TrigValidation/TrigAnalysisTest/share/ref_RDOtoRDOTrig_v1Dev_build.ref b/Trigger/TrigValidation/TrigAnalysisTest/share/ref_RDOtoRDOTrig_v1Dev_build.ref
index 4867a23e0987..d94f967e6268 100644
--- a/Trigger/TrigValidation/TrigAnalysisTest/share/ref_RDOtoRDOTrig_v1Dev_build.ref
+++ b/Trigger/TrigValidation/TrigAnalysisTest/share/ref_RDOtoRDOTrig_v1Dev_build.ref
@@ -992,7 +992,7 @@ HLT_e17_lhmedium_ivarloose_tau25_mediumRNN_tracktwoMVA_03dRAB_L1EM15VHI_2TAU12IM
     7: 6
     8: 6
     9: 2
-HLT_e17_lhmedium_tau25_mediumRNN_tracktwoMVA_xe50_cell_L1EM15VHI_2TAU12IM_XE35:
+HLT_e17_lhmedium_tau25_mediumRNN_tracktwoMVA_xe50_cell_03dRAB_L1EM15VHI_2TAU12IM_XE35:
   eventCount: 1
   stepCounts:
     0: 3
@@ -3227,7 +3227,7 @@ HLT_mu14_ivarloose_tau35_mediumRNN_tracktwoMVA_03dRAB_L1MU10_TAU20IM:
     7: 7
     8: 7
     9: 1
-HLT_mu14_tau25_mediumRNN_tracktwoMVA_xe50_cell_L1MU10_TAU12IM_XE35:
+HLT_mu14_tau25_mediumRNN_tracktwoMVA_xe50_cell_03dRAB_L1MU10_TAU12IM_XE35:
   eventCount: 0
   stepCounts:
     0: 4
@@ -4484,7 +4484,7 @@ HLT_tau35_tightRNN_tracktwoMVA_L1TAU12IM:
     2: 20
     3: 20
     4: 4
-HLT_tau60_mediumRNN_tracktwoMVA_tau25_mediumRNN_tracktwoMVA_xe50_cell_L1TAU40_2TAU12IM_XE40:
+HLT_tau60_mediumRNN_tracktwoMVA_tau25_mediumRNN_tracktwoMVA_xe50_cell_03dRAB_L1TAU40_2TAU12IM_XE40:
   eventCount: 0
   stepCounts:
     0: 3
diff --git a/Trigger/TrigValidation/TriggerTest/share/ref_data_v1Dev_build.ref b/Trigger/TrigValidation/TriggerTest/share/ref_data_v1Dev_build.ref
index 3982d2553a51..378ed913f788 100644
--- a/Trigger/TrigValidation/TriggerTest/share/ref_data_v1Dev_build.ref
+++ b/Trigger/TrigValidation/TriggerTest/share/ref_data_v1Dev_build.ref
@@ -603,7 +603,7 @@ HLT_e17_lhloose_mu14_L1EM15VH_MU10:
   eventCount: 0
 HLT_e17_lhmedium_ivarloose_tau25_mediumRNN_tracktwoMVA_03dRAB_L1EM15VHI_2TAU12IM_4J12:
   eventCount: 0
-HLT_e17_lhmedium_tau25_mediumRNN_tracktwoMVA_xe50_cell_L1EM15VHI_2TAU12IM_XE35:
+HLT_e17_lhmedium_tau25_mediumRNN_tracktwoMVA_xe50_cell_03dRAB_L1EM15VHI_2TAU12IM_XE35:
   eventCount: 0
 HLT_e17_lhvloose_L1EM15VH:
   eventCount: 0
@@ -1863,7 +1863,7 @@ HLT_mu14_ivarloose_tau35_mediumRNN_tracktwoMVA_03dRAB_L1MU10_TAU20IM:
   eventCount: 0
   stepFeatures:
     0: 1
-HLT_mu14_tau25_mediumRNN_tracktwoMVA_xe50_cell_L1MU10_TAU12IM_XE35:
+HLT_mu14_tau25_mediumRNN_tracktwoMVA_xe50_cell_03dRAB_L1MU10_TAU12IM_XE35:
   eventCount: 0
   stepFeatures:
     0: 1
@@ -2912,7 +2912,7 @@ HLT_tau35_tightRNN_tracktwoMVA_L1TAU12IM:
     2: 3
     3: 3
     4: 1
-HLT_tau60_mediumRNN_tracktwoMVA_tau25_mediumRNN_tracktwoMVA_xe50_cell_L1TAU40_2TAU12IM_XE40:
+HLT_tau60_mediumRNN_tracktwoMVA_tau25_mediumRNN_tracktwoMVA_xe50_cell_03dRAB_L1TAU40_2TAU12IM_XE40:
   eventCount: 0
   stepFeatures:
     0: 4
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Combined/GenerateCombinedChainDefs.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Combined/GenerateCombinedChainDefs.py
index baad1fd2a9c6..5478f3260299 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Combined/GenerateCombinedChainDefs.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Combined/GenerateCombinedChainDefs.py
@@ -125,8 +125,8 @@ def TrigComboHypoToolFromDict(chainDict):
     monTool.Histograms = [defineHistogram(obs_to_use[0]+'OfProcessed', type='TH1F', path='EXPERT', title=obs_to_use[0]+" in accepted combinations [MeV]", xbins=allowed_obs[obs_to_use[0]]['hist_nbins'], xmin=allowed_obs[obs_to_use[0]]['hist_min'], xmax=allowed_obs[obs_to_use[0]]['hist_max'])]
     tool= TrigComboHypoTool(name)
     tool.Variable    = obs_to_use[0]
-    tool.LegA        = legA
-    tool.LegB        = legB
+    tool.LegA        = "leg{:03d}".format(legA)
+    tool.LegB        = "leg{:03d}".format(legB)
     if len(l_min)==1:
         tool.UseMin    = True
         tool.LowerCut  = cut_min
@@ -141,8 +141,8 @@ def TrigComboHypoToolFromDict(chainDict):
     log.debug("[TrigComboHypoToolFromDict] legA = %d", legA)
     log.debug("[TrigComboHypoToolFromDict] legB = %d", legB)
     if len(l_min)==1:
-        log.debug("[TrigComboHypoToolFromDict] min  = %d", cut_min)
+        log.debug("[TrigComboHypoToolFromDict] min  = %10.3f", cut_min)
     if len(l_max)==1:
-        log.debug("[TrigComboHypoToolFromDict] max  = %d", cut_max)
+        log.debug("[TrigComboHypoToolFromDict] max  = %10.3f", cut_max)
 
     return tool
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/GenerateMenuMT.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/GenerateMenuMT.py
index 96f7c0bf0181..c68420ba00d1 100755
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/GenerateMenuMT.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/GenerateMenuMT.py
@@ -465,25 +465,26 @@ class GenerateMenuMT(object, metaclass=Singleton):
             log.error('[__generateChainConfigs] No Chain Configuration found for %s',chainName)
             raise Exception("[__generateChainConfigs] chain generation failed, exiting.")
 
-        elif len(listOfChainConfigs)>1:
+        else:
+            if len(listOfChainConfigs)>1:
                 log.debug("Merging strategy from dictionary: %s", mainChainDict["mergingStrategy"])
                 theChainConfig = mergeChainDefs(listOfChainConfigs, mainChainDict)
-
-                if len(mainChainDict['extraComboHypos']) > 0:
-                    try:
-                        functionToCall ='GenerateCombinedChainDefs.addTopoInfo(theChainConfig,mainChainDict,listOfChainConfigs,lengthOfChainConfigs)' 
-                        log.debug("Trying to add extra ComboHypoTool for %s",mainChainDict['extraComboHypos'])
-                        theChainConfig = eval(functionToCall)
-                    except RuntimeError:
-                        log.error('[__generateChainConfigs] Problems creating ChainDef for chain %s ', chainName)
-                        log.error('[__generateChainConfigs] I am in the extraComboHypos section, for %s ', mainChainDict['extraComboHypos'])
-                        log.exception('[__generateChainConfigs] Full chain dictionary is\n %s ', mainChainDict)
-                        raise Exception('[__generateChainConfigs] Stopping menu generation. Please investigate the exception shown above.')
+            else:
+                theChainConfig = listOfChainConfigs[0]
+            
+            if len(mainChainDict['extraComboHypos']) > 0:
+                try:
+                    functionToCall ='GenerateCombinedChainDefs.addTopoInfo(theChainConfig,mainChainDict,listOfChainConfigs,lengthOfChainConfigs)' 
+                    log.debug("Trying to add extra ComboHypoTool for %s",mainChainDict['extraComboHypos'])
+                    theChainConfig = eval(functionToCall)
+                except RuntimeError:
+                    log.error('[__generateChainConfigs] Problems creating ChainDef for chain %s ', chainName)
+                    log.error('[__generateChainConfigs] I am in the extraComboHypos section, for %s ', mainChainDict['extraComboHypos'])
+                    log.exception('[__generateChainConfigs] Full chain dictionary is\n %s ', mainChainDict)
+                    raise Exception('[__generateChainConfigs] Stopping menu generation. Please investigate the exception shown above.')
                         
 
-        else:
-            theChainConfig = listOfChainConfigs[0]
-
+        
         # Configure event building strategy
         eventBuildType = mainChainDict['eventBuildType']
         if eventBuildType:
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1.py
index 5f2245145cbd..a7362fa385ac 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/LS2_v1.py
@@ -661,9 +661,9 @@ def setupMenu():
 
 
         #ATR-22108: combined tau+X chains: TODO: add dRtt, need T&P-like merging
-        ChainProp(name='HLT_tau60_mediumRNN_tracktwoMVA_tau25_mediumRNN_tracktwoMVA_xe50_cell_L1TAU40_2TAU12IM_XE40', l1SeedThresholds=['TAU40','TAU12IM','XE40'], stream=[PhysicsStream], groups=PrimaryLegGroup+TauMETGroup),  # ATR-22966
-        ChainProp(name='HLT_e17_lhmedium_tau25_mediumRNN_tracktwoMVA_xe50_cell_L1EM15VHI_2TAU12IM_XE35', l1SeedThresholds=['EM15VHI','TAU12IM','XE35'], stream=[PhysicsStream], groups=PrimaryLegGroup+TauMETGroup),
-        ChainProp(name='HLT_mu14_tau25_mediumRNN_tracktwoMVA_xe50_cell_L1MU10_TAU12IM_XE35', l1SeedThresholds=['MU10','TAU12IM','XE35'], stream=[PhysicsStream], groups=PrimaryLegGroup+TauMETGroup),
+        ChainProp(name='HLT_tau60_mediumRNN_tracktwoMVA_tau25_mediumRNN_tracktwoMVA_xe50_cell_03dRAB_L1TAU40_2TAU12IM_XE40', l1SeedThresholds=['TAU40','TAU12IM','XE40'], stream=[PhysicsStream], groups=PrimaryLegGroup+TauMETGroup),  # ATR-22966
+        ChainProp(name='HLT_e17_lhmedium_tau25_mediumRNN_tracktwoMVA_xe50_cell_03dRAB_L1EM15VHI_2TAU12IM_XE35', l1SeedThresholds=['EM15VHI','TAU12IM','XE35'], stream=[PhysicsStream], groups=PrimaryLegGroup+TauMETGroup),
+        ChainProp(name='HLT_mu14_tau25_mediumRNN_tracktwoMVA_xe50_cell_03dRAB_L1MU10_TAU12IM_XE35', l1SeedThresholds=['MU10','TAU12IM','XE35'], stream=[PhysicsStream], groups=PrimaryLegGroup+TauMETGroup),
         ChainProp(name='HLT_e17_lhmedium_ivarloose_tau25_mediumRNN_tracktwoMVA_03dRAB_L1EM15VHI_2TAU12IM_4J12', l1SeedThresholds=['EM15VHI','TAU12IM'], stream=[PhysicsStream], groups=PrimaryLegGroup+EgammaTauGroup),
 
         ChainProp(name='HLT_mu20_ivarloose_tau20_mediumRNN_tracktwoMVA_03dRAB_L1MU20', l1SeedThresholds=['MU20','TAU8'], stream=[PhysicsStream], groups=PrimaryLegGroup+MuonTauGroup),
-- 
GitLab