From 0e043cbba61bc90c35b53b977098eac51f9873a1 Mon Sep 17 00:00:00 2001
From: Gabriel Oliveira Correa <gabriel.oliveira.correa@cern.ch>
Date: Tue, 14 Feb 2023 12:15:45 +0100
Subject: [PATCH 1/2] Fix sim/hardware vector check

---
 .../python/L1TopoOnlineMonitoringConfig.py    | 11 +++++---
 .../src/L1TopoOnlineMonitor.cxx               | 26 +++++++++++++------
 .../src/L1TopoOnlineMonitor.h                 |  9 +++++--
 .../python/L1TopoSimulationConfig.py          |  2 +-
 4 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/Trigger/TrigT1/L1Topo/L1TopoOnlineMonitoring/python/L1TopoOnlineMonitoringConfig.py b/Trigger/TrigT1/L1Topo/L1TopoOnlineMonitoring/python/L1TopoOnlineMonitoringConfig.py
index e8e45039f6d1..131502dc6cf1 100644
--- a/Trigger/TrigT1/L1Topo/L1TopoOnlineMonitoring/python/L1TopoOnlineMonitoringConfig.py
+++ b/Trigger/TrigT1/L1Topo/L1TopoOnlineMonitoring/python/L1TopoOnlineMonitoringConfig.py
@@ -80,7 +80,7 @@ def getMultiplicityLabels(flags,topoModule):
     return topo_trigline_labels
 
 
-def getL1TopoPhase1OnlineMonitor(flags, name='L1TopoOnlineMonitor', doSimMon=True, doHwMonCtp=False, doHwMon=False, doComp=False, forceCtp=False, logLevel = None):
+def getL1TopoPhase1OnlineMonitor(flags, name='L1TopoOnlineMonitor', doSimMon=True, doHwMonCtp=False, doHwMon=False, doComp=False, doMultComp=False, forceCtp=False, logLevel = None):
     # Placeholder for phase-1 implementation
     #raise RuntimeError('L1Topo phase-1 online monitoring not yet implemented')
     alg = CompFactory.L1TopoOnlineMonitor("L1TopoMonitoringTool",
@@ -88,15 +88,16 @@ def getL1TopoPhase1OnlineMonitor(flags, name='L1TopoOnlineMonitor', doSimMon=Tru
                                           doSimMon = doSimMon,
                                           doHwMonCTP = doHwMonCtp,
                                           doComp = doComp,
+                                          doMultComp = doMultComp,
                                           forceCTPasHdw=forceCtp)
     if logLevel : alg.OutputLevel=logLevel
     alg.MonTool = GenericMonitoringTool(flags, 'MonTool')
     alg.MonTool.HistPath = name
-    configureHistograms(alg, flags, doHwMonCtp, doHwMon, doComp)
+    configureHistograms(alg, flags, doHwMonCtp, doHwMon, doComp, doMultComp)
 
     return alg
 
-def configureHistograms(alg, flags, doHwMonCtp, doHwMon, doComp):
+def configureHistograms(alg, flags, doHwMonCtp, doHwMon, doComp, doMultComp):
 
     label_topo_all = []
     for cable in range(2):
@@ -164,6 +165,8 @@ def configureHistograms(alg, flags, doHwMonCtp, doHwMon, doComp):
                                     title='L1Topo events with hardware accept and simulation fail',
                                     xbins=128, xlabels=label_topo_all,
                                     xmin=0, xmax=128)
+
+    if doMultComp:                             
         ylabels = ['#frac{HdwNotSim}{Hdw}','#frac{SimNotHdw}{Sim}','#frac{HdwAndSim}{HdwOrSim}','#frac{Hdw}{Sim}']
         for topo in [(0,'2a'),(1,'2b'),(2,'3a'),(3,'3b')]:
             name = f'Phase1TopoTrigger_{topo[0]},Phase1TopoMissMatch_{topo[0]};Ph1Topo{topo[1]}'
@@ -197,7 +200,7 @@ def configureHistograms(alg, flags, doHwMonCtp, doHwMon, doComp):
                                         ymin=0, ymax=len(fpga_indexes))
         
 
-    mon_failure_labels = ['doHwMon', 'doSimMon', 'doHwMonCTP', 'doComp']
+    mon_failure_labels = ['doHwMon', 'doSimMon', 'doHwMonCTP', 'doComp', 'doMultComp']
     alg.MonTool.defineHistogram('MonitoringFailures', path='EXPERT', type='TH1F',
                                 title='Counts of mon functions returning failure;;Entries',
                                 xlabels=mon_failure_labels, xbins=len(mon_failure_labels),
diff --git a/Trigger/TrigT1/L1Topo/L1TopoOnlineMonitoring/src/L1TopoOnlineMonitor.cxx b/Trigger/TrigT1/L1Topo/L1TopoOnlineMonitoring/src/L1TopoOnlineMonitor.cxx
index 9d6d90fffb13..fdae669a972f 100644
--- a/Trigger/TrigT1/L1Topo/L1TopoOnlineMonitoring/src/L1TopoOnlineMonitor.cxx
+++ b/Trigger/TrigT1/L1Topo/L1TopoOnlineMonitoring/src/L1TopoOnlineMonitor.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
 */
 
 // Local includes
@@ -92,7 +92,7 @@ StatusCode L1TopoOnlineMonitor::start() {
 StatusCode L1TopoOnlineMonitor::fillHistograms( const EventContext& ctx ) const {
   
   DecisionBits decisionBits{};
-  enum class MonFunction : uint8_t {doSimMon=0, doHwMonCTP, doHwMon, doComp, doSummary};
+  enum class MonFunction : uint8_t {doSimMon=0, doHwMonCTP, doHwMon, doComp, doMultComp};
   std::vector<uint8_t> failedMonFunctions;
   std::vector<std::vector<unsigned>> multWeightsSim;
   std::vector<std::vector<unsigned>> multWeightsHdw;
@@ -123,13 +123,21 @@ StatusCode L1TopoOnlineMonitor::fillHistograms( const EventContext& ctx ) const
   }
 
   if (m_doComp) {
-    StatusCode sc = doComp(decisionBits,multWeightsSim,multWeightsHdw);
+    StatusCode sc = doComp(decisionBits);
     ATH_MSG_DEBUG("Executed doComp: " << (sc.isFailure() ? "failed" : "ok"));
     if (sc.isFailure()) {
       failedMonFunctions.push_back(static_cast<uint8_t>(MonFunction::doComp));
     }    
   }
-  
+
+  if (m_doMultComp) {
+    StatusCode sc = doMultComp(multWeightsSim,multWeightsHdw);
+    ATH_MSG_DEBUG("Executed doMultComp: " << (sc.isFailure() ? "failed" : "ok"));
+    if (sc.isFailure()) {
+      failedMonFunctions.push_back(static_cast<uint8_t>(MonFunction::doMultComp));
+    }    
+  }
+
   auto monFailedMonFunctions = Monitored::Collection("MonitoringFailures", failedMonFunctions);
   Monitored::Group(m_monTool, monFailedMonFunctions);
 
@@ -412,7 +420,7 @@ StatusCode L1TopoOnlineMonitor::doHwMon( DecisionBits& decisionBits, std::vector
   return StatusCode::SUCCESS;
 }
 
-StatusCode L1TopoOnlineMonitor::doComp( DecisionBits& decisionBits, std::vector<std::vector<unsigned>> &multWeightsSim, std::vector<std::vector<unsigned>> &multWeightsHdw ) const {
+StatusCode L1TopoOnlineMonitor::doComp( DecisionBits& decisionBits ) const {
   if (!decisionBits.triggerBitsSim.has_value()) {
     ATH_MSG_DEBUG("Simulation bits not set. Skipping simulation to hardware comparison");
     return StatusCode::FAILURE;
@@ -489,9 +497,12 @@ StatusCode L1TopoOnlineMonitor::doComp( DecisionBits& decisionBits, std::vector<
       }
     }
   }
+  return StatusCode::SUCCESS;
+}
 
-  if (multWeightsSim.size() == 0 and multWeightsHdw.size() == 0) {
-    ATH_MSG_DEBUG("Multiplicities not set, skipping multiplicities comparisin");
+StatusCode L1TopoOnlineMonitor::doMultComp( std::vector<std::vector<unsigned>> &multWeightsSim, std::vector<std::vector<unsigned>> &multWeightsHdw ) const {
+  if (multWeightsSim.size() == 0 or multWeightsHdw.size() == 0) {
+    ATH_MSG_DEBUG("Multiplicities not set, skipping multiplicities comparison");
     return StatusCode::FAILURE;
   }
 
@@ -503,7 +514,6 @@ StatusCode L1TopoOnlineMonitor::doComp( DecisionBits& decisionBits, std::vector<
       Monitored::Group(m_monTool, monMultSim, monMultHdw);
     }
   }
-
   return StatusCode::SUCCESS;
 }
 
diff --git a/Trigger/TrigT1/L1Topo/L1TopoOnlineMonitoring/src/L1TopoOnlineMonitor.h b/Trigger/TrigT1/L1Topo/L1TopoOnlineMonitoring/src/L1TopoOnlineMonitor.h
index cebf6a13ef7b..130bcefa62fa 100644
--- a/Trigger/TrigT1/L1Topo/L1TopoOnlineMonitoring/src/L1TopoOnlineMonitor.h
+++ b/Trigger/TrigT1/L1Topo/L1TopoOnlineMonitoring/src/L1TopoOnlineMonitor.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef L1TOPOONLINEMONITORING_L1TopoOnlineMonitor_h
@@ -90,6 +90,8 @@ private:
     this, "doHwMon", true, "Enable L1Topo HW readout from RAW"};
   Gaudi::Property<bool> m_doComp {
     this, "doComp", true, "Enable L1Topo HW/Sim comparison"};
+  Gaudi::Property<bool> m_doMultComp {
+    this, "doMultComp", false, "Enable L1Topo Multiplicity HW/Sim comparison"};
   Gaudi::Property<bool> m_forceCTPasHdw {
     this, "forceCTPasHdw", false, "Force to CTP monitoring as primary in Sim/Hdw comparison"};
 
@@ -119,7 +121,10 @@ private:
   StatusCode doHwMon(DecisionBits& decisionBits, std::vector<std::vector<unsigned>> &multWeights, const EventContext& ctx) const;
   
   /// Compare hardware and simulation
-  StatusCode doComp(DecisionBits& decisionBits, std::vector<std::vector<unsigned>> &multWeightsSim, std::vector<std::vector<unsigned>> &multWeightsHdw) const;
+  StatusCode doComp(DecisionBits& decisionBits) const;
+
+  /// Compare hardware and simulation for the multiplicity algorithms
+  StatusCode doMultComp(std::vector<std::vector<unsigned>> &multWeightsSim, std::vector<std::vector<unsigned>> &multWeightsHdw) const;
     
   /// Get CTP ids from menu
   std::vector<unsigned> getCtpIds(const TrigConf::L1Menu& l1menu);
diff --git a/Trigger/TrigT1/L1Topo/L1TopoSimulation/python/L1TopoSimulationConfig.py b/Trigger/TrigT1/L1Topo/L1TopoSimulation/python/L1TopoSimulationConfig.py
index 763d833c8b8b..da5fe5c96c06 100644
--- a/Trigger/TrigT1/L1Topo/L1TopoSimulation/python/L1TopoSimulationConfig.py
+++ b/Trigger/TrigT1/L1Topo/L1TopoSimulation/python/L1TopoSimulationConfig.py
@@ -437,7 +437,7 @@ if __name__ == '__main__':
   # phase1 mon
   from L1TopoOnlineMonitoring import L1TopoOnlineMonitoringConfig as TopoMonConfig
   acc.addEventAlgo(
-      TopoMonConfig.getL1TopoPhase1OnlineMonitor(flags,'L1/L1TopoOffline',True,True,True,True,args.forceCtp,algLogLevel),
+      TopoMonConfig.getL1TopoPhase1OnlineMonitor(flags,'L1/L1TopoOffline',True,True,True,True,True,args.forceCtp,algLogLevel),
       sequenceName="AthAlgSeq"
   )
   # legacy mon
-- 
GitLab


From 0cb8d4e3f72948bc56979de19046435751864bc5 Mon Sep 17 00:00:00 2001
From: Gabriel Oliveira Correa <gabriel.oliveira.correa@cern.ch>
Date: Tue, 14 Feb 2023 15:11:27 +0100
Subject: [PATCH 2/2] Remove comment for L1Topo Legacy Algorithms

---
 .../L1Topo/L1TopoSimulation/python/L1TopoSimulationConfig.py    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Trigger/TrigT1/L1Topo/L1TopoSimulation/python/L1TopoSimulationConfig.py b/Trigger/TrigT1/L1Topo/L1TopoSimulation/python/L1TopoSimulationConfig.py
index da5fe5c96c06..9c4da7bca8e6 100644
--- a/Trigger/TrigT1/L1Topo/L1TopoSimulation/python/L1TopoSimulationConfig.py
+++ b/Trigger/TrigT1/L1Topo/L1TopoSimulation/python/L1TopoSimulationConfig.py
@@ -48,7 +48,7 @@ def L1LegacyTopoSimulationCfg(flags):
                                                     InputDumpFile = "inputdump_legacy.txt",
                                                     EnableInputDump = flags.Trigger.enableL1TopoDump,
                                                     UseBitwise = flags.Trigger.enableL1TopoBWSimulation,
-                                                    #MonHistBaseDir = "L1/L1LegacyTopoAlgorithms"
+                                                    MonHistBaseDir = "L1/L1LegacyTopoAlgorithms"
                                                    )
 
     # No muon inputs to legacy Topo
-- 
GitLab