From 73002a4e666153fc08fc907d4878b066df0db7ba Mon Sep 17 00:00:00 2001
From: Susumu Oda <susumu.oda@cern.ch>
Date: Fri, 27 Mar 2020 09:49:31 +0100
Subject: [PATCH 01/12] Define categoryErrorCount_t and
 categoryErrorEtaPhiMap_t classes

---
 .../share/InDetMonitoringSCT.py               |  4 +--
 .../SCT_Monitoring/src/SCTErrMonAlg.cxx       | 13 ++++-----
 .../SCT_Monitoring/src/SCTErrMonAlg.h         | 27 ++++++++++++++++++-
 .../SCT_Monitoring/src/SCTErrMonTool.h        |  4 +--
 4 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/InnerDetector/InDetExample/InDetRecExample/share/InDetMonitoringSCT.py b/InnerDetector/InDetExample/InDetRecExample/share/InDetMonitoringSCT.py
index 152892dd0226..26ae01f97e4f 100755
--- a/InnerDetector/InDetExample/InDetRecExample/share/InDetMonitoringSCT.py
+++ b/InnerDetector/InDetExample/InDetRecExample/share/InDetMonitoringSCT.py
@@ -116,11 +116,11 @@ InDetSCTMonMan = AthenaMonManager("InDetSCTMonManager",
                                   Run                 = DQMonFlags.monManRun(),
                                   LumiBlock           = DQMonFlags.monManLumiBlock(),
                                   AthenaMonTools      = [ InDetSCTHitsTool,
-                                                          InDetSCTErrMonTool
+                                                          # InDetSCTErrMonTool
                                                         ] )
 
 if useNewAlgs:
-  # include("SCT_Monitoring/SCTErrMonAlg_jobOptions.py")
+  include("SCT_Monitoring/SCTErrMonAlg_jobOptions.py")
   include("SCT_Monitoring/SCTHitEffMonAlg_jobOptions.py")
   include("SCT_Monitoring/SCTLorentzMonAlg_jobOptions.py")
   include("SCT_Monitoring/SCTTracksMonAlg_jobOptions.py")
diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
index 66777500eca0..e2f5991b74de 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
@@ -192,17 +192,17 @@ SCTErrMonAlg::fillByteStreamErrors(const EventContext& ctx) const {
     fill("SCTErrMonitor", lumiBlockAcc, nBSErrorsAcc);
   }
 
-  std::array<int, CategoryErrors::N_ERRCATEGORY> tot_mod_bytestreamCate_errs;
-  tot_mod_bytestreamCate_errs.fill(0);
+  categoryErrorCount_t categoryErrorCount;
+  categoryErrorEtaPhiMap_t categoryErrorEtaPhiMap;
   int total_errors{0};
   for (int errType{0}; errType < SCT_ByteStreamErrors::NUM_ERROR_TYPES; ++errType) {
-    total_errors += fillByteStreamErrorsHelper(m_byteStreamErrTool->getErrorSet(errType), errType, tot_mod_bytestreamCate_errs);
+    total_errors += fillByteStreamErrorsHelper(m_byteStreamErrTool->getErrorSet(errType), errType, categoryErrorCount, categoryErrorEtaPhiMap);
   }
   /// Fill /SCT/GENERAL/errors/SCT_LinksWith*VsLbs ///
   for (int errCate{0}; errCate < CategoryErrors::N_ERRCATEGORY; ++errCate) {
     auto lumiBlockAcc{Monitored::Scalar<int>("lumiBlock", pEvent->lumiBlock())};
     auto nCategoryErrorsAcc{Monitored::Scalar<int>("n_"+CategoryErrorsNames[errCate],
-                                                   tot_mod_bytestreamCate_errs[errCate])};
+                                                   categoryErrorCount[errCate])};
     fill("SCTErrMonitor", lumiBlockAcc, nCategoryErrorsAcc);
   }
   
@@ -270,7 +270,8 @@ SCTErrMonAlg::fillByteStreamErrors(const EventContext& ctx) const {
 int
 SCTErrMonAlg::fillByteStreamErrorsHelper(const set<IdentifierHash>& errors,
                                          int err_type,
-                                         std::array<int, CategoryErrors::N_ERRCATEGORY>& tot_mod_bytestreamCate_errs) const {
+                                         categoryErrorCount_t& categoryErrorCount,
+                                         categoryErrorEtaPhiMap_t& categoryErrorEtaPhiMap) const {
 
   //--- Check categories of the BS error
   bool b_category[CategoryErrors::N_ERRCATEGORY];
@@ -373,7 +374,7 @@ SCTErrMonAlg::fillByteStreamErrorsHelper(const set<IdentifierHash>& errors,
   }
 
   for (int errCate{0}; errCate < CategoryErrors::N_ERRCATEGORY; ++errCate) {
-    if (b_category[errCate]) tot_mod_bytestreamCate_errs[errCate]++;
+    if (b_category[errCate]) categoryErrorCount[errCate]++;
   }
 
   if (b_category[CategoryErrors::SUMMARY]) return nerrors;
diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h
index 5677754e3991..97de97bcaae7 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h
@@ -16,6 +16,7 @@
 #include "SCT_ConditionsTools/ISCT_ConfigurationConditionsTool.h"
 #include "SCT_ConditionsTools/ISCT_DCSConditionsTool.h"
 
+#include <array>
 #include <atomic>
 #include <mutex>
 #include <utility>
@@ -34,6 +35,29 @@ class SCTErrMonAlg : public AthMonitorAlgorithm {
   // First pair is eta and second pair is phi.
   // First element of pair is minimum second is maximum.
   typedef std::pair<std::pair<double, double>, std::pair<double, double>> moduleGeo_t;
+  class categoryErrorCount_t : public std::array<int, SCT_Monitoring::CategoryErrors::N_ERRCATEGORY> {
+  public:
+    categoryErrorCount_t() {
+      this->fill(0);
+    };
+  };
+  class categoryErrorEtaPhiMap_t : public std::array<std::array<std::array<std::array<std::array<bool,
+            SCT_Monitoring::N_PHI_BINS>, SCT_Monitoring::N_ETA_BINS>, SCT_Monitoring::N_ENDCAPSx2>,
+                                                                SCT_Monitoring::N_REGIONS>, SCT_Monitoring::CategoryErrors::N_ERRCATEGORY> {
+  public:
+    categoryErrorEtaPhiMap_t() {
+      for (int iCat{0}; iCat<SCT_Monitoring::CategoryErrors::N_ERRCATEGORY; iCat++) {
+        for (int iReg{0}; iReg<SCT_Monitoring::N_REGIONS; iReg++) {
+          for (int iLay{0}; iLay<SCT_Monitoring::N_ENDCAPSx2; iLay++) {
+            for (int iEta{0}; iEta<SCT_Monitoring::N_ETA_BINS; iEta++) {
+              (*this)[iCat][iReg][iLay][iEta].fill(false);
+            }
+          }
+        }
+      }
+    };
+  };
+  // N_PHI_BINS=56 > N_PHI_BINS_EC=52, N_ETA_BINS=13 > N_ETA_BINS_EC=3, N_ENDCAPSx2=18 > N_BARRELSx2=8 defined in SCT_MonitoringNumbers.h
 
   static const unsigned int s_nBinsEta;
   static const double s_rangeEta;
@@ -63,7 +87,8 @@ class SCTErrMonAlg : public AthMonitorAlgorithm {
   /// Used in fillByteStreamErrors()
   int fillByteStreamErrorsHelper(const std::set<IdentifierHash>& errors,
                                  int err_type,
-                                 std::array<int, SCT_Monitoring::CategoryErrors::N_ERRCATEGORY>& tot_mod_bytestreamCate_errs) const;
+                                 categoryErrorCount_t& categoryErrorCount,
+                                 categoryErrorEtaPhiMap_t& categoryErrorEtaPhiMap) const;
   void numByteStreamErrors(const std::set<IdentifierHash>& errors, int& ntot) const;
   bool disabledSCT(std::set<IdentifierHash>& sctHashDisabled) const;
   bool errorSCT(std::set<IdentifierHash>& sctHashBadLinkError,
diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonTool.h b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonTool.h
index 926a7565aa07..a172bc54517c 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonTool.h
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonTool.h
@@ -146,7 +146,7 @@ class SCTErrMonTool : public ManagedMonitorToolBase {
   // Unnecessary but necessary to fill necessary m_ConfNew
   /// Under LB directories
   // total number of errors
-  TH2F_LW* m_pallErrsCate[SCT_ByteStreamErrors::NUM_ERROR_TYPES][SCT_Monitoring::N_REGIONS][SCT_Monitoring::N_ENDCAPSx2]{}; // Filled in fillByteStreamErrorsHelper. Used to fill m_allErrsCate and m_summaryErrsRecent
+  TH2F_LW* m_pallErrsCate[SCT_Monitoring::CategoryErrors::N_ERRCATEGORY][SCT_Monitoring::N_REGIONS][SCT_Monitoring::N_ENDCAPSx2]{}; // Filled in fillByteStreamErrorsHelper. Used to fill m_allErrsCate and m_summaryErrsRecent
   // Default histos to print per lumi block
   TH2F_LW* m_numErrorsPerLumi[SCT_Monitoring::N_REGIONS_INC_GENERAL]{}; // Filled in fillByteStreamErrorsHelper. Used to fill m_rateErrorsPerLumi
   /// Detector coverage
@@ -158,7 +158,7 @@ class SCTErrMonTool : public ManagedMonitorToolBase {
   TProfile_LW* m_ConfNew{}; // Filled in fillCondDBMaps using m_MaskedAllLinks and m_allErrsCate. Noise plots are also used.
   TProfile_LW* m_LinksWithCategorisedErrorsVsLB[SCT_Monitoring::CategoryErrors::N_ERRCATEGORY]{}; // Fillded in fillByteStreamErrors using m_pallErrsCate
   /// Under LB directories
-  TProfile2D_LW* m_allErrsCate[SCT_ByteStreamErrors::NUM_ERROR_TYPES][SCT_Monitoring::N_REGIONS][SCT_Monitoring::N_ENDCAPSx2]{}; // Rate of errors. Filled in fillByteStreamErrors. Used to fill necessary m_ConfNew
+  TProfile2D_LW* m_allErrsCate[SCT_Monitoring::CategoryErrors::N_ERRCATEGORY][SCT_Monitoring::N_REGIONS][SCT_Monitoring::N_ENDCAPSx2]{}; // Rate of errors. Filled in fillByteStreamErrors. Used to fill necessary m_ConfNew
   TProfile2D_LW* m_rateErrorsPerLumi[SCT_Monitoring::N_REGIONS]{}; // Filled in checkRateHists using m_numErrorsPerLumi
   /// Only online
   TProfile_LW* m_ConfOnline[SCT_Monitoring::N_REGIONS_INC_GENERAL]{}; // Filled in fillCondDBMaps using m_MaskedAllLinks and m_allErrsCate
-- 
GitLab


From 9148aed61048d007bf8c1508de7db1ececbdd478 Mon Sep 17 00:00:00 2001
From: Susumu Oda <susumu.oda@cern.ch>
Date: Fri, 27 Mar 2020 10:23:50 +0100
Subject: [PATCH 02/12] Add errorEtaPhiMap_t to check exisisting wafers.

---
 .../SCT_Monitoring/src/SCTErrMonAlg.cxx       | 29 ++++++++++++++++++-
 .../SCT_Monitoring/src/SCTErrMonAlg.h         | 22 +++++++-------
 2 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
index e2f5991b74de..b7f0c6627fd9 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
@@ -42,6 +42,25 @@ StatusCode SCTErrMonAlg::initialize() {
     m_geo[i] = moduleGeo;
   }
 
+  // Fill existing wafers
+  SCT_ID::const_id_iterator waferIterator{m_pSCTHelper->wafer_begin()};
+  SCT_ID::const_id_iterator waferEnd{m_pSCTHelper->wafer_end()};
+  for (; waferIterator not_eq waferEnd; ++waferIterator) {
+    const Identifier waferId{*waferIterator};
+    int layer{m_pSCTHelper->layer_disk(waferId)};
+    int side{m_pSCTHelper->side(waferId)};
+    int barrel_ec{m_pSCTHelper->barrel_ec(waferId)};
+    int ieta{m_pSCTHelper->eta_module(waferId)};
+    int iphi{m_pSCTHelper->phi_module(waferId)};
+    layer = layer * 2 + side;
+    int regionIndex{GENERAL_INDEX};
+    if ((barrel_ec == BARREL) and (layer >= 0) and (layer < N_BARRELSx2)) regionIndex = BARREL_INDEX;
+    else if (barrel_ec == ENDCAP_A) regionIndex = ENDCAP_A_INDEX;
+    else if (barrel_ec == ENDCAP_C) regionIndex = ENDCAP_C_INDEX;
+    else continue;
+    m_errorEtaPhiMap[regionIndex][layer][ieta][iphi] = true; // This wafer exists.
+  }
+
   return AthMonitorAlgorithm::initialize();
 }
 
@@ -326,10 +345,12 @@ SCTErrMonAlg::fillByteStreamErrorsHelper(const set<IdentifierHash>& errors,
     if (not hash.is_valid()) continue;
 
     //--- FIll module information with BS error
-    Identifier fitId{m_pSCTHelper->wafer_id(hash)};
+    const Identifier fitId{m_pSCTHelper->wafer_id(hash)};
     int layer{m_pSCTHelper->layer_disk(fitId)};
     int side{m_pSCTHelper->side(fitId)};
     int barrel_ec{m_pSCTHelper->barrel_ec(fitId)};
+    int ieta{m_pSCTHelper->eta_module(fitId)};
+    int iphi{m_pSCTHelper->phi_module(fitId)};
     layer = layer * 2 + side;
     // barrel_ec = {ENDCAP_C=-2, BARREL=0, ENDCAP_A=2}
     // -> regionIndex = {ENDCAP_C_INDEX=0, BARREL_INDEX=1, ENDCAP_A_INDEX=2, GENERAL_INDEX=3}
@@ -346,6 +367,12 @@ SCTErrMonAlg::fillByteStreamErrorsHelper(const set<IdentifierHash>& errors,
     }
 
     if (m_doPerLumiErrors) numErrorsPerLumi[regionIndex][layer]++;
+
+    for (int errCate{0}; errCate < CategoryErrors::N_ERRCATEGORY; ++errCate) {
+      if (b_category[errCate] and regionIndex!=GENERAL_INDEX) {
+        categoryErrorEtaPhiMap[errCate][regionIndex][layer][ieta][iphi] = true;
+      }
+    }
   }
 
   /// Fill /SCT/GENERAL/errors/Masked Links ///
diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h
index 97de97bcaae7..bb8faa7c980c 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h
@@ -41,29 +41,29 @@ class SCTErrMonAlg : public AthMonitorAlgorithm {
       this->fill(0);
     };
   };
-  class categoryErrorEtaPhiMap_t : public std::array<std::array<std::array<std::array<std::array<bool,
-            SCT_Monitoring::N_PHI_BINS>, SCT_Monitoring::N_ETA_BINS>, SCT_Monitoring::N_ENDCAPSx2>,
-                                                                SCT_Monitoring::N_REGIONS>, SCT_Monitoring::CategoryErrors::N_ERRCATEGORY> {
+  class errorEtaPhiMap_t : public std::array<std::array<std::array<std::array<bool,
+             SCT_Monitoring::N_PHI_BINS>, SCT_Monitoring::N_ETA_BINS>,
+             SCT_Monitoring::N_ENDCAPSx2>, SCT_Monitoring::N_REGIONS> {
+    // N_PHI_BINS=56 > N_PHI_BINS_EC=52, N_ETA_BINS=13 > N_ETA_BINS_EC=3, N_ENDCAPSx2=18 > N_BARRELSx2=8 defined in SCT_MonitoringNumbers.h
   public:
-    categoryErrorEtaPhiMap_t() {
-      for (int iCat{0}; iCat<SCT_Monitoring::CategoryErrors::N_ERRCATEGORY; iCat++) {
-        for (int iReg{0}; iReg<SCT_Monitoring::N_REGIONS; iReg++) {
-          for (int iLay{0}; iLay<SCT_Monitoring::N_ENDCAPSx2; iLay++) {
-            for (int iEta{0}; iEta<SCT_Monitoring::N_ETA_BINS; iEta++) {
-              (*this)[iCat][iReg][iLay][iEta].fill(false);
-            }
+    errorEtaPhiMap_t() {
+      for (int iReg{0}; iReg<SCT_Monitoring::N_REGIONS; iReg++) {
+        for (int iLay{0}; iLay<SCT_Monitoring::N_ENDCAPSx2; iLay++) {
+          for (int iEta{0}; iEta<SCT_Monitoring::N_ETA_BINS; iEta++) {
+            (*this)[iReg][iLay][iEta].fill(false);
           }
         }
       }
     };
   };
-  // N_PHI_BINS=56 > N_PHI_BINS_EC=52, N_ETA_BINS=13 > N_ETA_BINS_EC=3, N_ENDCAPSx2=18 > N_BARRELSx2=8 defined in SCT_MonitoringNumbers.h
+  typedef std::array<errorEtaPhiMap_t, SCT_Monitoring::CategoryErrors::N_ERRCATEGORY> categoryErrorEtaPhiMap_t;
 
   static const unsigned int s_nBinsEta;
   static const double s_rangeEta;
   static const unsigned int s_nBinsPhi;
   static const double s_wafersThreshold;
 
+  errorEtaPhiMap_t m_errorEtaPhiMap{};
   std::vector<moduleGeo_t> m_geo{};
 
   mutable std::atomic_bool m_isFirstConfigurationDetails{true};
-- 
GitLab


From e6e2a4fa3eaf96656320bb9ea21dde84546efbd5 Mon Sep 17 00:00:00 2001
From: Susumu Oda <susumu.oda@cern.ch>
Date: Fri, 27 Mar 2020 15:34:43 +0100
Subject: [PATCH 03/12] Add indices(Vector)_t

---
 .../SCT_Monitoring/src/SCTErrMonAlg.cxx       | 11 ++++----
 .../SCT_Monitoring/src/SCTErrMonAlg.h         | 25 +++++++++++--------
 2 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
index b7f0c6627fd9..ea7a5181de04 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
@@ -43,6 +43,7 @@ StatusCode SCTErrMonAlg::initialize() {
   }
 
   // Fill existing wafers
+  m_indices.reserve(maxHash);
   SCT_ID::const_id_iterator waferIterator{m_pSCTHelper->wafer_begin()};
   SCT_ID::const_id_iterator waferEnd{m_pSCTHelper->wafer_end()};
   for (; waferIterator not_eq waferEnd; ++waferIterator) {
@@ -58,7 +59,7 @@ StatusCode SCTErrMonAlg::initialize() {
     else if (barrel_ec == ENDCAP_A) regionIndex = ENDCAP_A_INDEX;
     else if (barrel_ec == ENDCAP_C) regionIndex = ENDCAP_C_INDEX;
     else continue;
-    m_errorEtaPhiMap[regionIndex][layer][ieta][iphi] = true; // This wafer exists.
+    m_indices.push_back(indices_t{regionIndex, layer, ieta, iphi});
   }
 
   return AthMonitorAlgorithm::initialize();
@@ -212,10 +213,10 @@ SCTErrMonAlg::fillByteStreamErrors(const EventContext& ctx) const {
   }
 
   categoryErrorCount_t categoryErrorCount;
-  categoryErrorEtaPhiMap_t categoryErrorEtaPhiMap;
+  categoryErrorMap_t categoryErrorMap;
   int total_errors{0};
   for (int errType{0}; errType < SCT_ByteStreamErrors::NUM_ERROR_TYPES; ++errType) {
-    total_errors += fillByteStreamErrorsHelper(m_byteStreamErrTool->getErrorSet(errType), errType, categoryErrorCount, categoryErrorEtaPhiMap);
+    total_errors += fillByteStreamErrorsHelper(m_byteStreamErrTool->getErrorSet(errType), errType, categoryErrorCount, categoryErrorMap);
   }
   /// Fill /SCT/GENERAL/errors/SCT_LinksWith*VsLbs ///
   for (int errCate{0}; errCate < CategoryErrors::N_ERRCATEGORY; ++errCate) {
@@ -290,7 +291,7 @@ int
 SCTErrMonAlg::fillByteStreamErrorsHelper(const set<IdentifierHash>& errors,
                                          int err_type,
                                          categoryErrorCount_t& categoryErrorCount,
-                                         categoryErrorEtaPhiMap_t& categoryErrorEtaPhiMap) const {
+                                         categoryErrorMap_t& categoryErrorMap) const {
 
   //--- Check categories of the BS error
   bool b_category[CategoryErrors::N_ERRCATEGORY];
@@ -370,7 +371,7 @@ SCTErrMonAlg::fillByteStreamErrorsHelper(const set<IdentifierHash>& errors,
 
     for (int errCate{0}; errCate < CategoryErrors::N_ERRCATEGORY; ++errCate) {
       if (b_category[errCate] and regionIndex!=GENERAL_INDEX) {
-        categoryErrorEtaPhiMap[errCate][regionIndex][layer][ieta][iphi] = true;
+        categoryErrorMap[errCate][regionIndex][layer][ieta][iphi] = true;
       }
     }
   }
diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h
index bb8faa7c980c..07f575d15ff0 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h
@@ -41,29 +41,32 @@ class SCTErrMonAlg : public AthMonitorAlgorithm {
       this->fill(0);
     };
   };
-  class errorEtaPhiMap_t : public std::array<std::array<std::array<std::array<bool,
-             SCT_Monitoring::N_PHI_BINS>, SCT_Monitoring::N_ETA_BINS>,
-             SCT_Monitoring::N_ENDCAPSx2>, SCT_Monitoring::N_REGIONS> {
+  class categoryErrorMap_t : public std::array<std::array<std::array<std::array<std::array<bool,
+             SCT_Monitoring::N_PHI_BINS>, SCT_Monitoring::N_ETA_BINS>, SCT_Monitoring::N_ENDCAPSx2>,
+             SCT_Monitoring::N_REGIONS>, SCT_Monitoring::N_ERRCATEGORY> {
     // N_PHI_BINS=56 > N_PHI_BINS_EC=52, N_ETA_BINS=13 > N_ETA_BINS_EC=3, N_ENDCAPSx2=18 > N_BARRELSx2=8 defined in SCT_MonitoringNumbers.h
   public:
-    errorEtaPhiMap_t() {
-      for (int iReg{0}; iReg<SCT_Monitoring::N_REGIONS; iReg++) {
-        for (int iLay{0}; iLay<SCT_Monitoring::N_ENDCAPSx2; iLay++) {
-          for (int iEta{0}; iEta<SCT_Monitoring::N_ETA_BINS; iEta++) {
-            (*this)[iReg][iLay][iEta].fill(false);
+    categoryErrorMap_t() {
+      for (int iCat{0}; iCat<SCT_Monitoring::N_ERRCATEGORY; iCat++) {
+        for (int iReg{0}; iReg<SCT_Monitoring::N_REGIONS; iReg++) {
+          for (int iLay{0}; iLay<SCT_Monitoring::N_ENDCAPSx2; iLay++) {
+            for (int iEta{0}; iEta<SCT_Monitoring::N_ETA_BINS; iEta++) {
+              (*this)[iCat][iReg][iLay][iEta].fill(false);
+            }
           }
         }
       }
     };
   };
-  typedef std::array<errorEtaPhiMap_t, SCT_Monitoring::CategoryErrors::N_ERRCATEGORY> categoryErrorEtaPhiMap_t;
+  typedef std::array<int, 4> indices_t; // 4: regionIndex, layer, ieta, iphi
+  typedef std::vector<indices_t> indicesVector_t;
 
   static const unsigned int s_nBinsEta;
   static const double s_rangeEta;
   static const unsigned int s_nBinsPhi;
   static const double s_wafersThreshold;
 
-  errorEtaPhiMap_t m_errorEtaPhiMap{};
+  indicesVector_t m_indices{};
   std::vector<moduleGeo_t> m_geo{};
 
   mutable std::atomic_bool m_isFirstConfigurationDetails{true};
@@ -88,7 +91,7 @@ class SCTErrMonAlg : public AthMonitorAlgorithm {
   int fillByteStreamErrorsHelper(const std::set<IdentifierHash>& errors,
                                  int err_type,
                                  categoryErrorCount_t& categoryErrorCount,
-                                 categoryErrorEtaPhiMap_t& categoryErrorEtaPhiMap) const;
+                                 categoryErrorMap_t& categoryErrorMap) const;
   void numByteStreamErrors(const std::set<IdentifierHash>& errors, int& ntot) const;
   bool disabledSCT(std::set<IdentifierHash>& sctHashDisabled) const;
   bool errorSCT(std::set<IdentifierHash>& sctHashBadLinkError,
-- 
GitLab


From 62e403e08af044c1ca4226fa45b716951d1af5a5 Mon Sep 17 00:00:00 2001
From: Susumu Oda <susumu.oda@cern.ch>
Date: Fri, 27 Mar 2020 15:54:58 +0100
Subject: [PATCH 04/12] Add fill for error category eta-phi maps

---
 .../SCT_Monitoring/src/SCTErrMonAlg.cxx                | 10 ++++++++--
 .../InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h  |  5 +++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
index ea7a5181de04..79e870ecbadf 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
@@ -43,7 +43,7 @@ StatusCode SCTErrMonAlg::initialize() {
   }
 
   // Fill existing wafers
-  m_indices.reserve(maxHash);
+  m_indicesVector.reserve(maxHash);
   SCT_ID::const_id_iterator waferIterator{m_pSCTHelper->wafer_begin()};
   SCT_ID::const_id_iterator waferEnd{m_pSCTHelper->wafer_end()};
   for (; waferIterator not_eq waferEnd; ++waferIterator) {
@@ -59,7 +59,7 @@ StatusCode SCTErrMonAlg::initialize() {
     else if (barrel_ec == ENDCAP_A) regionIndex = ENDCAP_A_INDEX;
     else if (barrel_ec == ENDCAP_C) regionIndex = ENDCAP_C_INDEX;
     else continue;
-    m_indices.push_back(indices_t{regionIndex, layer, ieta, iphi});
+    m_indicesVector.push_back(indices_t{regionIndex, layer, ieta, iphi});
   }
 
   return AthMonitorAlgorithm::initialize();
@@ -224,6 +224,12 @@ SCTErrMonAlg::fillByteStreamErrors(const EventContext& ctx) const {
     auto nCategoryErrorsAcc{Monitored::Scalar<int>("n_"+CategoryErrorsNames[errCate],
                                                    categoryErrorCount[errCate])};
     fill("SCTErrMonitor", lumiBlockAcc, nCategoryErrorsAcc);
+
+    for (const indices_t& indices : m_indicesVector) {
+      auto etaAcc{Monitored::Scalar<int>("eta", indices[ETAINDEX])};
+      auto phiAcc{Monitored::Scalar<int>("phi", indices[PHIINDEX])};
+      fill("SCTErrMonitor", etaAcc, phiAcc);
+    }
   }
   
   if (m_coverageCheck) {
diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h
index 07f575d15ff0..0c87deee3c54 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h
@@ -58,7 +58,8 @@ class SCTErrMonAlg : public AthMonitorAlgorithm {
       }
     };
   };
-  typedef std::array<int, 4> indices_t; // 4: regionIndex, layer, ieta, iphi
+  enum {REGIONINDEX, LAYERINDEX, ETAINDEX, PHIINDEX, NINDICES};
+  typedef std::array<int, NINDICES> indices_t;
   typedef std::vector<indices_t> indicesVector_t;
 
   static const unsigned int s_nBinsEta;
@@ -66,7 +67,7 @@ class SCTErrMonAlg : public AthMonitorAlgorithm {
   static const unsigned int s_nBinsPhi;
   static const double s_wafersThreshold;
 
-  indicesVector_t m_indices{};
+  indicesVector_t m_indicesVector{};
   std::vector<moduleGeo_t> m_geo{};
 
   mutable std::atomic_bool m_isFirstConfigurationDetails{true};
-- 
GitLab


From d29a6ca051687fc63864925df3400367b7a1669b Mon Sep 17 00:00:00 2001
From: Susumu Oda <susumu.oda@cern.ch>
Date: Fri, 27 Mar 2020 16:12:20 +0100
Subject: [PATCH 05/12] Add variable

---
 .../InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx       | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
index 79e870ecbadf..b0b4eb1e1d9d 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
@@ -228,7 +228,9 @@ SCTErrMonAlg::fillByteStreamErrors(const EventContext& ctx) const {
     for (const indices_t& indices : m_indicesVector) {
       auto etaAcc{Monitored::Scalar<int>("eta", indices[ETAINDEX])};
       auto phiAcc{Monitored::Scalar<int>("phi", indices[PHIINDEX])};
-      fill("SCTErrMonitor", etaAcc, phiAcc);
+      auto hasErrorAcc{Monitored::Scalar<bool>("hasError",
+                       categoryErrorMap[errCate][indices[REGIONINDEX]][indices[LAYERINDEX]][indices[ETAINDEX]][indices[PHIINDEX]])};
+      fill("SCTErrMonitor", etaAcc, phiAcc, hasErrorAcc);
     }
   }
   
-- 
GitLab


From 7f7626d0844f18f4ab210f18fdfdfae749824747 Mon Sep 17 00:00:00 2001
From: Susumu Oda <susumu.oda@cern.ch>
Date: Fri, 27 Mar 2020 16:54:28 +0100
Subject: [PATCH 06/12] Update

---
 .../SCT_Monitoring/SCT_MonitoringNumbers.h           |  4 ++--
 .../SCT_Monitoring/src/SCTErrMonAlg.cxx              | 12 ++++++++----
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/SCT_Monitoring/SCT_MonitoringNumbers.h b/InnerDetector/InDetMonitoring/SCT_Monitoring/SCT_Monitoring/SCT_MonitoringNumbers.h
index 11ac1182f3f4..c1ce3e6aa6d7 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/SCT_Monitoring/SCT_MonitoringNumbers.h
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/SCT_Monitoring/SCT_MonitoringNumbers.h
@@ -18,7 +18,7 @@ namespace SCT_Monitoring{
   ///what array indices mean when looping over subsystems
   enum BecIndex {INVALID_INDEX=-1, ENDCAP_C_INDEX=0, BARREL_INDEX=1, ENDCAP_A_INDEX=2, GENERAL_INDEX=3, N_REGIONS=3, N_REGIONS_INC_GENERAL=N_REGIONS+1};
   ///Possible values of the 'BEC' (Barrel or EndCap) value
-  enum Bec{ ENDCAP_C=-2, BARREL=0, ENDCAP_A=2, GENERAL=3, INVALID_SYSTEM=4};
+  enum Bec{ENDCAP_C=-2, BARREL=0, ENDCAP_A=2, GENERAL=3, INVALID_SYSTEM=4};
   ///Array for conversion of an array index to a Bec
   static const std::vector<Bec> index2BecArray={ENDCAP_C, BARREL, ENDCAP_A, GENERAL};
   ///Conversion  bec->index
@@ -27,7 +27,7 @@ namespace SCT_Monitoring{
   }
   ///Conversion index->bec
   inline Bec index2Bec(const unsigned int i) {
-    return (i < 4) ? (index2BecArray[i]) : INVALID_SYSTEM;
+    return i < N_REGIONS_INC_GENERAL ? (index2BecArray[i]) : INVALID_SYSTEM;
   }
   
   ///Numbers to use in histograms
diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
index b0b4eb1e1d9d..9cc23985237f 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
@@ -226,10 +226,14 @@ SCTErrMonAlg::fillByteStreamErrors(const EventContext& ctx) const {
     fill("SCTErrMonitor", lumiBlockAcc, nCategoryErrorsAcc);
 
     for (const indices_t& indices : m_indicesVector) {
-      auto etaAcc{Monitored::Scalar<int>("eta", indices[ETAINDEX])};
-      auto phiAcc{Monitored::Scalar<int>("phi", indices[PHIINDEX])};
-      auto hasErrorAcc{Monitored::Scalar<bool>("hasError",
-                       categoryErrorMap[errCate][indices[REGIONINDEX]][indices[LAYERINDEX]][indices[ETAINDEX]][indices[PHIINDEX]])};
+      const int region{indices[REGIONINDEX]};
+      const int layer{indices[LAYERINDEX]};
+      const int eta{indices[ETAINDEX]};
+      const int phi{indices[PHIINDEX]};
+      auto etaAcc{Monitored::Scalar<int>("eta", eta)};
+      auto phiAcc{Monitored::Scalar<int>("phi", phi)};
+      auto hasErrorAcc{Monitored::Scalar<bool>("hasError_"+CategoryErrorsNames[errCate]+"_"+subDetNameShort[region].Data()+"_"+to_string(layer/2)+"_"+to_string(layer%2),
+                                               categoryErrorMap[errCate][region][layer][eta][phi])};
       fill("SCTErrMonitor", etaAcc, phiAcc, hasErrorAcc);
     }
   }
-- 
GitLab


From 459e310b613c60c13b488838fea05402ba7a0096 Mon Sep 17 00:00:00 2001
From: Susumu Oda <susumu.oda@cern.ch>
Date: Fri, 27 Mar 2020 18:35:21 +0100
Subject: [PATCH 07/12] Update

---
 .../share/SCTErrMonAlg_jobOptions.py               | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py b/InnerDetector/InDetMonitoring/SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py
index e58ca7db2efa..6ab47b9cebab 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py
@@ -104,6 +104,20 @@ for i in range(sctMon.N_ERRCATEGORY):
                                xbins = sctMon.NBINS_LBs,
                                xmin = 0.5,
                                xmax = sctMon.NBINS_LBs+0.5)
+#
+for errCate in range(sctMon.N_ERRCATEGORY):
+    for region in range(sctMon.N_REGIONS):
+        for layer in range(sctMon.N_ENDCAPSx2):
+            myMonGroup.defineHistogram(varname = "eta, phi, hasError_"+sctMon.CategoryErrorsNames[errCrate]+"_"+sctMon.subDetNameShort[region].Data()+"_"+str(layer/2)+"_"+str(layer%2),
+                                       type = "TProfile2D",
+                                       title = ("SCT_NumberOf" + sctMon.CategoryErrorsNames[errCrate]  + sctMon.esubDetNameShort[reg].Data() + "_").Data(), ####
+                                       path = "SCT"+sctMon.subDetNameShort[region].Data()+"/errors/"+sctMon.CategoryErrorsNames[errCrate],
+                                       xbins = sctMon.N_ETA_BINS if region==sctMon.BARREL_INDEX else sctMon.N_ETA_BINS_EC,
+                                       xmin = (sctMon.FIRST_ETA_BIN if region==sctMon.BARREL_INDEX else sctMon.FIRST_ETA_BINS_EC)-0.5,
+                                       xmax = (sctMon.LAST_ETA_BIN if region==sctMon.BARREL_INDEX else sctMon.LAST_ETA_BINS_EC)+0.5,
+                                       ybins = sctMon.N_PHI_BINS if region==sctMon.BARREL_INDEX else sctMon.N_PHI_BINS_EC,
+                                       ymin = (sctMon.FIRST_PHI_BIN if region==sctMon.BARREL_INDEX else sctMon.FIRST_PHI_BINS_EC)-0.5,
+                                       ymax = (sctMon.LAST_PHI_BIN if region==sctMon.BARREL_INDEX else sctMon.LAST_PHI_BINS_EC)+0.5)
 
 # Filled in fillByteStreamErrorsHelper
 myMonGroup.defineHistogram(varname = "maskedLinksBin;Masked Links",
-- 
GitLab


From 8bed2ac5f077fd158b72cb49afbb885ecdf292a1 Mon Sep 17 00:00:00 2001
From: Susumu Oda <susumu.oda@cern.ch>
Date: Sat, 28 Mar 2020 05:17:42 +0100
Subject: [PATCH 08/12] Use lb duration

---
 .../SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py          | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py b/InnerDetector/InDetMonitoring/SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py
index 6ab47b9cebab..bd5963f506c9 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py
@@ -104,7 +104,7 @@ for i in range(sctMon.N_ERRCATEGORY):
                                xbins = sctMon.NBINS_LBs,
                                xmin = 0.5,
                                xmax = sctMon.NBINS_LBs+0.5)
-#
+# Filled in fillByteStreamErrors
 for errCate in range(sctMon.N_ERRCATEGORY):
     for region in range(sctMon.N_REGIONS):
         for layer in range(sctMon.N_ENDCAPSx2):
@@ -117,7 +117,8 @@ for errCate in range(sctMon.N_ERRCATEGORY):
                                        xmax = (sctMon.LAST_ETA_BIN if region==sctMon.BARREL_INDEX else sctMon.LAST_ETA_BINS_EC)+0.5,
                                        ybins = sctMon.N_PHI_BINS if region==sctMon.BARREL_INDEX else sctMon.N_PHI_BINS_EC,
                                        ymin = (sctMon.FIRST_PHI_BIN if region==sctMon.BARREL_INDEX else sctMon.FIRST_PHI_BINS_EC)-0.5,
-                                       ymax = (sctMon.LAST_PHI_BIN if region==sctMon.BARREL_INDEX else sctMon.LAST_PHI_BINS_EC)+0.5)
+                                       ymax = (sctMon.LAST_PHI_BIN if region==sctMon.BARREL_INDEX else sctMon.LAST_PHI_BINS_EC)+0.5,
+                                       duration = "lb")
 
 # Filled in fillByteStreamErrorsHelper
 myMonGroup.defineHistogram(varname = "maskedLinksBin;Masked Links",
-- 
GitLab


From 7f9a5f25c23bc42b4074355d1e518c388a685676 Mon Sep 17 00:00:00 2001
From: Susumu Oda <susumu.oda@cern.ch>
Date: Sat, 28 Mar 2020 05:58:01 +0100
Subject: [PATCH 09/12] Fix bugs

---
 .../share/SCTErrMonAlg_jobOptions.py               | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py b/InnerDetector/InDetMonitoring/SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py
index bd5963f506c9..07757f985070 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py
@@ -108,16 +108,16 @@ for i in range(sctMon.N_ERRCATEGORY):
 for errCate in range(sctMon.N_ERRCATEGORY):
     for region in range(sctMon.N_REGIONS):
         for layer in range(sctMon.N_ENDCAPSx2):
-            myMonGroup.defineHistogram(varname = "eta, phi, hasError_"+sctMon.CategoryErrorsNames[errCrate]+"_"+sctMon.subDetNameShort[region].Data()+"_"+str(layer/2)+"_"+str(layer%2),
+            myMonGroup.defineHistogram(varname = "eta, phi, hasError_"+sctMon.CategoryErrorsNames[errCate]+"_"+sctMon.subDetNameShort[region].Data()+"_"+str(layer/2)+"_"+str(layer%2),
                                        type = "TProfile2D",
-                                       title = ("SCT_NumberOf" + sctMon.CategoryErrorsNames[errCrate]  + sctMon.esubDetNameShort[reg].Data() + "_").Data(), ####
-                                       path = "SCT"+sctMon.subDetNameShort[region].Data()+"/errors/"+sctMon.CategoryErrorsNames[errCrate],
+                                       title = "SCT_NumberOf" + sctMon.CategoryErrorsNames[errCate]  + sctMon.subDetNameShort[region].Data() + "_", ####
+                                       path = "SCT"+sctMon.subDetNameShort[region].Data()+"/errors/"+sctMon.CategoryErrorsNames[errCate],
                                        xbins = sctMon.N_ETA_BINS if region==sctMon.BARREL_INDEX else sctMon.N_ETA_BINS_EC,
-                                       xmin = (sctMon.FIRST_ETA_BIN if region==sctMon.BARREL_INDEX else sctMon.FIRST_ETA_BINS_EC)-0.5,
-                                       xmax = (sctMon.LAST_ETA_BIN if region==sctMon.BARREL_INDEX else sctMon.LAST_ETA_BINS_EC)+0.5,
+                                       xmin = (sctMon.FIRST_ETA_BIN if region==sctMon.BARREL_INDEX else sctMon.FIRST_ETA_BIN_EC)-0.5,
+                                       xmax = (sctMon.LAST_ETA_BIN if region==sctMon.BARREL_INDEX else sctMon.LAST_ETA_BIN_EC)+0.5,
                                        ybins = sctMon.N_PHI_BINS if region==sctMon.BARREL_INDEX else sctMon.N_PHI_BINS_EC,
-                                       ymin = (sctMon.FIRST_PHI_BIN if region==sctMon.BARREL_INDEX else sctMon.FIRST_PHI_BINS_EC)-0.5,
-                                       ymax = (sctMon.LAST_PHI_BIN if region==sctMon.BARREL_INDEX else sctMon.LAST_PHI_BINS_EC)+0.5,
+                                       ymin = (sctMon.FIRST_PHI_BIN if region==sctMon.BARREL_INDEX else sctMon.FIRST_PHI_BIN_EC)-0.5,
+                                       ymax = (sctMon.LAST_PHI_BIN if region==sctMon.BARREL_INDEX else sctMon.LAST_PHI_BIN_EC)+0.5,
                                        duration = "lb")
 
 # Filled in fillByteStreamErrorsHelper
-- 
GitLab


From febd4827f9acb1cf28b0c4b1ce751030532e951f Mon Sep 17 00:00:00 2001
From: Susumu Oda <susumu.oda@cern.ch>
Date: Sat, 28 Mar 2020 07:17:37 +0100
Subject: [PATCH 10/12] Implement more profiles

---
 .../InDetExample/InDetRecExample/share/InDetMonitoringSCT.py | 4 ++--
 .../SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py          | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/InnerDetector/InDetExample/InDetRecExample/share/InDetMonitoringSCT.py b/InnerDetector/InDetExample/InDetRecExample/share/InDetMonitoringSCT.py
index 26ae01f97e4f..152892dd0226 100755
--- a/InnerDetector/InDetExample/InDetRecExample/share/InDetMonitoringSCT.py
+++ b/InnerDetector/InDetExample/InDetRecExample/share/InDetMonitoringSCT.py
@@ -116,11 +116,11 @@ InDetSCTMonMan = AthenaMonManager("InDetSCTMonManager",
                                   Run                 = DQMonFlags.monManRun(),
                                   LumiBlock           = DQMonFlags.monManLumiBlock(),
                                   AthenaMonTools      = [ InDetSCTHitsTool,
-                                                          # InDetSCTErrMonTool
+                                                          InDetSCTErrMonTool
                                                         ] )
 
 if useNewAlgs:
-  include("SCT_Monitoring/SCTErrMonAlg_jobOptions.py")
+  # include("SCT_Monitoring/SCTErrMonAlg_jobOptions.py")
   include("SCT_Monitoring/SCTHitEffMonAlg_jobOptions.py")
   include("SCT_Monitoring/SCTLorentzMonAlg_jobOptions.py")
   include("SCT_Monitoring/SCTTracksMonAlg_jobOptions.py")
diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py b/InnerDetector/InDetMonitoring/SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py
index 07757f985070..a94c1047ce69 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/share/SCTErrMonAlg_jobOptions.py
@@ -104,13 +104,14 @@ for i in range(sctMon.N_ERRCATEGORY):
                                xbins = sctMon.NBINS_LBs,
                                xmin = 0.5,
                                xmax = sctMon.NBINS_LBs+0.5)
+
 # Filled in fillByteStreamErrors
 for errCate in range(sctMon.N_ERRCATEGORY):
     for region in range(sctMon.N_REGIONS):
         for layer in range(sctMon.N_ENDCAPSx2):
-            myMonGroup.defineHistogram(varname = "eta, phi, hasError_"+sctMon.CategoryErrorsNames[errCate]+"_"+sctMon.subDetNameShort[region].Data()+"_"+str(layer/2)+"_"+str(layer%2),
+            myMonGroup.defineHistogram(varname = "eta, phi, hasError_"+sctMon.CategoryErrorsNames[errCate]+"_"+sctMon.subDetNameShort[region].Data()+"_"+str(layer/2)+"_"+str(layer%2)+";SCT_NumberOf"+sctMon.CategoryErrorsNames[errCate]+sctMon.subDetNameShort[region].Data()+"_"+str(layer/2)+"_"+str(layer%2),
                                        type = "TProfile2D",
-                                       title = "SCT_NumberOf" + sctMon.CategoryErrorsNames[errCate]  + sctMon.subDetNameShort[region].Data() + "_", ####
+                                       title = "Num of "+sctMon.CategoryErrorsNames[errCate]+" per "+sctMon.layerName[region].Data()+str(layer/2)+"_"+str(layer%2),
                                        path = "SCT"+sctMon.subDetNameShort[region].Data()+"/errors/"+sctMon.CategoryErrorsNames[errCate],
                                        xbins = sctMon.N_ETA_BINS if region==sctMon.BARREL_INDEX else sctMon.N_ETA_BINS_EC,
                                        xmin = (sctMon.FIRST_ETA_BIN if region==sctMon.BARREL_INDEX else sctMon.FIRST_ETA_BIN_EC)-0.5,
-- 
GitLab


From 7be4e0e3badb1de7342d8812c4beb9d2de52deb6 Mon Sep 17 00:00:00 2001
From: Susumu Oda <susumu.oda@cern.ch>
Date: Mon, 30 Mar 2020 09:50:35 +0200
Subject: [PATCH 11/12] Migrate to SCTErrMonAlg

---
 .../share/InDetMonitoringSCT.py               |  6 +++---
 .../SCT_Monitoring/src/SCTErrMonAlg.cxx       | 16 +++++----------
 .../SCT_Monitoring/src/SCTErrMonAlg.h         | 20 ++++++++++++-------
 3 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/InnerDetector/InDetExample/InDetRecExample/share/InDetMonitoringSCT.py b/InnerDetector/InDetExample/InDetRecExample/share/InDetMonitoringSCT.py
index 152892dd0226..d43351ec1ddb 100755
--- a/InnerDetector/InDetExample/InDetRecExample/share/InDetMonitoringSCT.py
+++ b/InnerDetector/InDetExample/InDetRecExample/share/InDetMonitoringSCT.py
@@ -10,7 +10,7 @@ useNewAlgs = True # Use new AthenaMT friendly DQ algorithms instead of DQ tools
 
 tracksName = (InDetKeys.SCTTracks() if InDetFlags.doTrackSegmentsSCT() else InDetKeys.UnslimmedTracks())
 
-doTriggger = False
+doTriggger = True
 TrigDecisionTool_InDetSCTHitsTool = ""
 if globalflags.DataSource == "data":
   from RecExConfig.RecFlags import rec
@@ -116,16 +116,16 @@ InDetSCTMonMan = AthenaMonManager("InDetSCTMonManager",
                                   Run                 = DQMonFlags.monManRun(),
                                   LumiBlock           = DQMonFlags.monManLumiBlock(),
                                   AthenaMonTools      = [ InDetSCTHitsTool,
-                                                          InDetSCTErrMonTool
                                                         ] )
 
 if useNewAlgs:
-  # include("SCT_Monitoring/SCTErrMonAlg_jobOptions.py")
+  include("SCT_Monitoring/SCTErrMonAlg_jobOptions.py")
   include("SCT_Monitoring/SCTHitEffMonAlg_jobOptions.py")
   include("SCT_Monitoring/SCTLorentzMonAlg_jobOptions.py")
   include("SCT_Monitoring/SCTTracksMonAlg_jobOptions.py")
 
 else:
+  InDetSCTMonMan.AthenaMonTools += [ InDetSCTErrMonTool ]
   InDetSCTMonMan.AthenaMonTools += [ InDetSCTHitEffMonTool ]
   InDetSCTMonMan.AthenaMonTools += [ InDetSCTLorentzMonTool ]
   InDetSCTMonMan.AthenaMonTools += [ InDetSCTTracksMonTool ]
diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
index 9cc23985237f..289386b064b5 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
@@ -167,7 +167,7 @@ SCTErrMonAlg::fillConfigurationDetails(const EventContext& ctx) const {
   auto detailedConfBinAcc{Monitored::Scalar<int>("detailedConfBin")};
   auto nBadAcc{Monitored::Scalar<double>("nBad")};
   for (unsigned int i{0}; i<ConfbinsDetailed; i++) {
-    detailedConfBinAcc = 0;
+    detailedConfBinAcc = i;
     if (i==0) nBadAcc = nBadMods;
     else if (i==1) nBadAcc = nBadLink0;
     else if (i==2) nBadAcc = nBadLink1;
@@ -212,17 +212,16 @@ SCTErrMonAlg::fillByteStreamErrors(const EventContext& ctx) const {
     fill("SCTErrMonitor", lumiBlockAcc, nBSErrorsAcc);
   }
 
-  categoryErrorCount_t categoryErrorCount;
   categoryErrorMap_t categoryErrorMap;
   int total_errors{0};
   for (int errType{0}; errType < SCT_ByteStreamErrors::NUM_ERROR_TYPES; ++errType) {
-    total_errors += fillByteStreamErrorsHelper(m_byteStreamErrTool->getErrorSet(errType), errType, categoryErrorCount, categoryErrorMap);
+    total_errors += fillByteStreamErrorsHelper(m_byteStreamErrTool->getErrorSet(errType), errType, categoryErrorMap);
   }
   /// Fill /SCT/GENERAL/errors/SCT_LinksWith*VsLbs ///
   for (int errCate{0}; errCate < CategoryErrors::N_ERRCATEGORY; ++errCate) {
     auto lumiBlockAcc{Monitored::Scalar<int>("lumiBlock", pEvent->lumiBlock())};
     auto nCategoryErrorsAcc{Monitored::Scalar<int>("n_"+CategoryErrorsNames[errCate],
-                                                   categoryErrorCount[errCate])};
+                                                   categoryErrorMap.count(errCate))};
     fill("SCTErrMonitor", lumiBlockAcc, nCategoryErrorsAcc);
 
     for (const indices_t& indices : m_indicesVector) {
@@ -302,11 +301,10 @@ SCTErrMonAlg::fillByteStreamErrors(const EventContext& ctx) const {
 int
 SCTErrMonAlg::fillByteStreamErrorsHelper(const set<IdentifierHash>& errors,
                                          int err_type,
-                                         categoryErrorCount_t& categoryErrorCount,
                                          categoryErrorMap_t& categoryErrorMap) const {
-
   //--- Check categories of the BS error
-  bool b_category[CategoryErrors::N_ERRCATEGORY];
+  std::array<bool, CategoryErrors::N_ERRCATEGORY> b_category;
+  b_category.fill(false);
 
   b_category[CategoryErrors::MASKEDLINKALL] =
     (err_type == SCT_ByteStreamErrors::MaskedLink) or (err_type == SCT_ByteStreamErrors::MaskedROD);
@@ -413,10 +411,6 @@ SCTErrMonAlg::fillByteStreamErrorsHelper(const set<IdentifierHash>& errors,
     }
   }
 
-  for (int errCate{0}; errCate < CategoryErrors::N_ERRCATEGORY; ++errCate) {
-    if (b_category[errCate]) categoryErrorCount[errCate]++;
-  }
-
   if (b_category[CategoryErrors::SUMMARY]) return nerrors;
   return 0;
 }
diff --git a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h
index 0c87deee3c54..0050bd2f25e9 100644
--- a/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h
+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.h
@@ -35,12 +35,6 @@ class SCTErrMonAlg : public AthMonitorAlgorithm {
   // First pair is eta and second pair is phi.
   // First element of pair is minimum second is maximum.
   typedef std::pair<std::pair<double, double>, std::pair<double, double>> moduleGeo_t;
-  class categoryErrorCount_t : public std::array<int, SCT_Monitoring::CategoryErrors::N_ERRCATEGORY> {
-  public:
-    categoryErrorCount_t() {
-      this->fill(0);
-    };
-  };
   class categoryErrorMap_t : public std::array<std::array<std::array<std::array<std::array<bool,
              SCT_Monitoring::N_PHI_BINS>, SCT_Monitoring::N_ETA_BINS>, SCT_Monitoring::N_ENDCAPSx2>,
              SCT_Monitoring::N_REGIONS>, SCT_Monitoring::N_ERRCATEGORY> {
@@ -57,6 +51,19 @@ class SCTErrMonAlg : public AthMonitorAlgorithm {
         }
       }
     };
+    int count(int errCate) {
+      int cnt{0};
+      for (int iReg{0}; iReg<SCT_Monitoring::N_REGIONS; iReg++) {
+        for (int iLay{0}; iLay<SCT_Monitoring::N_ENDCAPSx2; iLay++) {
+          for (int iEta{0}; iEta<SCT_Monitoring::N_ETA_BINS; iEta++) {
+            for (int iPhi{0}; iPhi<SCT_Monitoring::N_PHI_BINS; iPhi++) {
+              if ((*this)[errCate][iReg][iLay][iEta][iPhi]) cnt++;
+            }
+          }
+        }
+      }
+      return cnt;
+    }
   };
   enum {REGIONINDEX, LAYERINDEX, ETAINDEX, PHIINDEX, NINDICES};
   typedef std::array<int, NINDICES> indices_t;
@@ -91,7 +98,6 @@ class SCTErrMonAlg : public AthMonitorAlgorithm {
   /// Used in fillByteStreamErrors()
   int fillByteStreamErrorsHelper(const std::set<IdentifierHash>& errors,
                                  int err_type,
-                                 categoryErrorCount_t& categoryErrorCount,
                                  categoryErrorMap_t& categoryErrorMap) const;
   void numByteStreamErrors(const std::set<IdentifierHash>& errors, int& ntot) const;
   bool disabledSCT(std::set<IdentifierHash>& sctHashDisabled) const;
-- 
GitLab


From 292646a1c47bec6246266f7ce36e911896d34b0a Mon Sep 17 00:00:00 2001
From: Susumu Oda <susumu.oda@cern.ch>
Date: Tue, 31 Mar 2020 04:52:27 +0200
Subject: [PATCH 12/12] Fix a bug (revert doTrigger flag). Use useNewAlgs flag.

---
 .../share/InDetMonitoringSCT.py               | 38 +++++++++----------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/InnerDetector/InDetExample/InDetRecExample/share/InDetMonitoringSCT.py b/InnerDetector/InDetExample/InDetRecExample/share/InDetMonitoringSCT.py
index d43351ec1ddb..c99037988812 100755
--- a/InnerDetector/InDetExample/InDetRecExample/share/InDetMonitoringSCT.py
+++ b/InnerDetector/InDetExample/InDetRecExample/share/InDetMonitoringSCT.py
@@ -10,7 +10,7 @@ useNewAlgs = True # Use new AthenaMT friendly DQ algorithms instead of DQ tools
 
 tracksName = (InDetKeys.SCTTracks() if InDetFlags.doTrackSegmentsSCT() else InDetKeys.UnslimmedTracks())
 
-doTriggger = True
+doTriggger = False
 TrigDecisionTool_InDetSCTHitsTool = ""
 if globalflags.DataSource == "data":
   from RecExConfig.RecFlags import rec
@@ -27,27 +27,27 @@ InDetSCTHitsTool = SCTHitsNoiseMonTool ( name = "InDetSCTHitsNoiseMonTool",
 if (InDetFlags.doPrintConfigurables()):
   printfunc (InDetSCTHitsTool)
 
-from SCT_Monitoring.SCT_MonitoringConf import SCTErrMonTool
-InDetSCTErrMonTool = SCTErrMonTool ( name             = "InDetSCTErrMonTool",
-                                     OutputLevel      = 4,
-                                     histoPathBase    = "/stat",
-                                     UseDCS           = InDetFlags.useDCS() )
-if InDetFlags.useDCS():
-  from SCT_ConditionsTools.SCT_DCSConditionsToolSetup import SCT_DCSConditionsToolSetup
-  sct_DCSConditionsToolSetup = SCT_DCSConditionsToolSetup()
-  sct_DCSConditionsToolSetup.setup()
-  InDetSCTErrMonTool.SCT_DCSConditionsTool = sct_DCSConditionsToolSetup.getTool()
-else:
-  InDetSCTErrMonTool.SCT_DCSConditionsTool = None
+if not useNewAlgs:
+  from SCT_Monitoring.SCT_MonitoringConf import SCTErrMonTool
+  InDetSCTErrMonTool = SCTErrMonTool ( name             = "InDetSCTErrMonTool",
+                                       OutputLevel      = 4,
+                                       histoPathBase    = "/stat",
+                                       UseDCS           = InDetFlags.useDCS() )
+  if InDetFlags.useDCS():
+    from SCT_ConditionsTools.SCT_DCSConditionsToolSetup import SCT_DCSConditionsToolSetup
+    sct_DCSConditionsToolSetup = SCT_DCSConditionsToolSetup()
+    sct_DCSConditionsToolSetup.setup()
+    InDetSCTErrMonTool.SCT_DCSConditionsTool = sct_DCSConditionsToolSetup.getTool()
+  else:
+    InDetSCTErrMonTool.SCT_DCSConditionsTool = None
 
-if jobproperties.Beam.beamType()=='collisions':
-  from AthenaMonitoring.FilledBunchFilterTool import GetFilledBunchFilterTool
-  InDetSCTErrMonTool.FilterTools += [GetFilledBunchFilterTool()]
+  if jobproperties.Beam.beamType()=='collisions':
+    from AthenaMonitoring.FilledBunchFilterTool import GetFilledBunchFilterTool
+    InDetSCTErrMonTool.FilterTools += [GetFilledBunchFilterTool()]
   
-if (InDetFlags.doPrintConfigurables()):
-  printfunc (InDetSCTErrMonTool)
+  if (InDetFlags.doPrintConfigurables()):
+    printfunc (InDetSCTErrMonTool)
 
-if not useNewAlgs:
   from SCT_Monitoring.SCT_MonitoringConf import SCTTracksMonTool
   InDetSCTTracksMonTool = SCTTracksMonTool ( name             = "InDetSCTTracksMonTool",
                                              OutputLevel      = 4,
-- 
GitLab