From 81108d29fd39bdb24f3cbb9f9f2eb818ba00654b Mon Sep 17 00:00:00 2001
From: Bingxuan Liu <bingxuan.liu@cern.ch>
Date: Thu, 17 Nov 2022 17:33:50 +0100
Subject: [PATCH 1/4] Change checkAbsEta to a bool and remove assert

---
 .../CalibrationDataInterfaceROOT.h            |  2 +-
 .../Root/CalibrationDataInterfaceROOT.cxx     | 30 ++++++++++++++-----
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/CalibrationDataInterface/CalibrationDataInterfaceROOT.h b/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/CalibrationDataInterface/CalibrationDataInterfaceROOT.h
index ce49d8b0f53d..c4db4e56b0eb 100644
--- a/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/CalibrationDataInterface/CalibrationDataInterfaceROOT.h
+++ b/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/CalibrationDataInterface/CalibrationDataInterfaceROOT.h
@@ -461,7 +461,7 @@ namespace Analysis
       double               m_maxAbsEta;
       OutOfBoundsStrategy  m_absEtaStrategy;
       OutOfBoundsStrategy  m_otherStrategy;
-      void                 checkAbsEta(const CalibrationDataVariables& variables, unsigned int index);
+      bool                 checkAbsEta(const CalibrationDataVariables& variables, unsigned int index);
       /** counters for flagging out-of-bound cases */
       std::vector<unsigned int> m_etaCounters;
       std::vector<unsigned int> m_mainCounters;
diff --git a/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/Root/CalibrationDataInterfaceROOT.cxx b/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/Root/CalibrationDataInterfaceROOT.cxx
index 9ab6903080df..f07895999d88 100644
--- a/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/Root/CalibrationDataInterfaceROOT.cxx
+++ b/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/Root/CalibrationDataInterfaceROOT.cxx
@@ -802,7 +802,10 @@ Analysis::CalibrationDataInterfaceROOT::getScaleFactor (const CalibrationDataVar
   }
 
   // perform out-of-bound check of jet eta
-  checkAbsEta(variables, indexSF);
+  if (!checkAbsEta(variables, indexSF)) {
+    cerr << "Jet |eta| is outside of the boundary!" << endl;
+    return Analysis::kError;
+  }
 
   // retrieve the MC/MC scale factor
   double MCMCSF = m_useMCMCSF ? getMCMCScaleFactor(variables, indexSF, indexEff) : 1;
@@ -988,7 +991,11 @@ Analysis::CalibrationDataInterfaceROOT::getMCEfficiency (const CalibrationDataVa
   if (! container) return Analysis::kError;
   
   // perform out-of-bound check of jet eta
-  checkAbsEta(variables, index);
+  if (!checkAbsEta(variables, index)) {
+    cerr << "Jet |eta| is outside of the boundary!" << endl;
+    return Analysis::kError;
+  }
+
 
   // always retrieve the result itself
   double value;
@@ -1546,7 +1553,10 @@ Analysis::CalibrationDataInterfaceROOT::getWeightScaleFactor (const CalibrationD
   checkWeightScaleFactors(indexSF, indexEff);
 
   // perform out-of-bound check of jet eta
-  checkAbsEta(variables, indexSF);
+  if (!checkAbsEta(variables, indexSF)) {
+    cerr << "Jet |eta| is outside of the boundary!" << endl;
+    return Analysis::kError;
+  }
 
   // Always retrieve the result itself 
   double value;
@@ -1900,22 +1910,26 @@ Analysis::CalibrationDataInterfaceROOT::checkWeightScaleFactors(unsigned int ind
 }
 
 //________________________________________________________________________________
-void
+bool
 Analysis::CalibrationDataInterfaceROOT::checkAbsEta(const CalibrationDataVariables& variables,
 						    unsigned int index)
 {
   // Check whether the jet eta value is outside the range of validity, subject to the strategy
   // specified in the configuration file.
-
-  if (m_absEtaStrategy == Ignore) return;
+  bool pass = true;
+  
   switch (m_absEtaStrategy) {
   case GiveUp:
-    assert(!(std::fabs(variables.jetEta) > m_maxAbsEta)); break;
+    if (std::fabs(variables.jetEta) > m_maxAbsEta) {
+      pass = false;  
+    }
   case Flag:
   default:
-    if (std::fabs(variables.jetEta) > m_maxAbsEta)
+    if (std::fabs(variables.jetEta) > m_maxAbsEta) {
       increaseCounter(index, Eta);
+    }
   }
+  return pass;
 }
 
 //________________________________________________________________________________
-- 
GitLab


From 4699df513cfc98fa94052495d469b84382cf4751 Mon Sep 17 00:00:00 2001
From: Bingxuan Liu <bingxuan.liu@cern.ch>
Date: Thu, 17 Nov 2022 18:23:04 +0100
Subject: [PATCH 2/4] Add Ignore flag back

---
 .../Root/CalibrationDataInterfaceROOT.cxx                      | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/Root/CalibrationDataInterfaceROOT.cxx b/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/Root/CalibrationDataInterfaceROOT.cxx
index f07895999d88..981bd61fa173 100644
--- a/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/Root/CalibrationDataInterfaceROOT.cxx
+++ b/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/Root/CalibrationDataInterfaceROOT.cxx
@@ -1917,7 +1917,8 @@ Analysis::CalibrationDataInterfaceROOT::checkAbsEta(const CalibrationDataVariabl
   // Check whether the jet eta value is outside the range of validity, subject to the strategy
   // specified in the configuration file.
   bool pass = true;
-  
+  if (m_absEtaStrategy == Ignore) return pass; 
+ 
   switch (m_absEtaStrategy) {
   case GiveUp:
     if (std::fabs(variables.jetEta) > m_maxAbsEta) {
-- 
GitLab


From 8272bd03ae8788edfdc3a8fad724042676598de8 Mon Sep 17 00:00:00 2001
From: Bingxuan Liu <bingxuan.liu@cern.ch>
Date: Fri, 18 Nov 2022 12:36:46 +0100
Subject: [PATCH 3/4] add [[nodiscard]] and break

---
 .../CalibrationDataInterface/CalibrationDataInterfaceROOT.h     | 2 +-
 .../Root/CalibrationDataInterfaceROOT.cxx                       | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/CalibrationDataInterface/CalibrationDataInterfaceROOT.h b/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/CalibrationDataInterface/CalibrationDataInterfaceROOT.h
index c4db4e56b0eb..9b74937eab33 100644
--- a/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/CalibrationDataInterface/CalibrationDataInterfaceROOT.h
+++ b/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/CalibrationDataInterface/CalibrationDataInterfaceROOT.h
@@ -461,7 +461,7 @@ namespace Analysis
       double               m_maxAbsEta;
       OutOfBoundsStrategy  m_absEtaStrategy;
       OutOfBoundsStrategy  m_otherStrategy;
-      bool                 checkAbsEta(const CalibrationDataVariables& variables, unsigned int index);
+      [[nodiscard]] bool                 checkAbsEta(const CalibrationDataVariables& variables, unsigned int index);
       /** counters for flagging out-of-bound cases */
       std::vector<unsigned int> m_etaCounters;
       std::vector<unsigned int> m_mainCounters;
diff --git a/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/Root/CalibrationDataInterfaceROOT.cxx b/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/Root/CalibrationDataInterfaceROOT.cxx
index 981bd61fa173..67abadebeb2d 100644
--- a/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/Root/CalibrationDataInterfaceROOT.cxx
+++ b/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/Root/CalibrationDataInterfaceROOT.cxx
@@ -1924,6 +1924,7 @@ Analysis::CalibrationDataInterfaceROOT::checkAbsEta(const CalibrationDataVariabl
     if (std::fabs(variables.jetEta) > m_maxAbsEta) {
       pass = false;  
     }
+    break;
   case Flag:
   default:
     if (std::fabs(variables.jetEta) > m_maxAbsEta) {
-- 
GitLab


From 7732ebbb3002fe630839a314fa3e8f967d8fb672 Mon Sep 17 00:00:00 2001
From: Bingxuan Liu <bingxuan.liu@cern.ch>
Date: Mon, 21 Nov 2022 10:33:06 +0100
Subject: [PATCH 4/4] Chenge kError to kRange

---
 .../Root/CalibrationDataInterfaceROOT.cxx                   | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/Root/CalibrationDataInterfaceROOT.cxx b/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/Root/CalibrationDataInterfaceROOT.cxx
index 67abadebeb2d..02336ca7c646 100644
--- a/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/Root/CalibrationDataInterfaceROOT.cxx
+++ b/PhysicsAnalysis/JetTagging/JetTagPerformanceCalibration/CalibrationDataInterface/Root/CalibrationDataInterfaceROOT.cxx
@@ -804,7 +804,7 @@ Analysis::CalibrationDataInterfaceROOT::getScaleFactor (const CalibrationDataVar
   // perform out-of-bound check of jet eta
   if (!checkAbsEta(variables, indexSF)) {
     cerr << "Jet |eta| is outside of the boundary!" << endl;
-    return Analysis::kError;
+    return Analysis::kRange;
   }
 
   // retrieve the MC/MC scale factor
@@ -993,7 +993,7 @@ Analysis::CalibrationDataInterfaceROOT::getMCEfficiency (const CalibrationDataVa
   // perform out-of-bound check of jet eta
   if (!checkAbsEta(variables, index)) {
     cerr << "Jet |eta| is outside of the boundary!" << endl;
-    return Analysis::kError;
+    return Analysis::kRange;
   }
 
 
@@ -1555,7 +1555,7 @@ Analysis::CalibrationDataInterfaceROOT::getWeightScaleFactor (const CalibrationD
   // perform out-of-bound check of jet eta
   if (!checkAbsEta(variables, indexSF)) {
     cerr << "Jet |eta| is outside of the boundary!" << endl;
-    return Analysis::kError;
+    return Analysis::kRange;
   }
 
   // Always retrieve the result itself 
-- 
GitLab