From 320ee4c46ce9e18300ce0b082940cb2760a1b947 Mon Sep 17 00:00:00 2001
From: R D Schaffer <r.d.schaffer@cern.ch>
Date: Thu, 3 Sep 2020 14:53:50 +0000
Subject: [PATCH] Fixing thresholds for currents to not read in maps for
 online, and returning zero b-field if no map is read

---
 .../MagFieldElements/AtlasFieldCache.icc       |  6 ++----
 .../src/AtlasFieldMapCondAlg.cxx               | 18 +++++++++++++++---
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/MagneticField/MagFieldElements/MagFieldElements/AtlasFieldCache.icc b/MagneticField/MagFieldElements/MagFieldElements/AtlasFieldCache.icc
index 0ea794a5eae8..8f5bd59d0217 100644
--- a/MagneticField/MagFieldElements/MagFieldElements/AtlasFieldCache.icc
+++ b/MagneticField/MagFieldElements/MagFieldElements/AtlasFieldCache.icc
@@ -51,10 +51,8 @@ MagField::AtlasFieldCache::getField(const double* ATH_RESTRICT xyz,
 {
   // Allow for the case of no map for testing
   if (m_fieldMap == nullptr) {
-    // constant ATLAS magnetic field if no map has been set - for testing
-    constexpr double TEST_BFIELD = 1.997;
-    bxyz[0] = bxyz[1] = 0;
-    bxyz[2] = TEST_BFIELD;
+    // return 0 bfield if map is missing
+    bxyz[0] = bxyz[1] = bxyz[2] = 0;
     if (deriv) {
       for (int i = 0; i < 9; i++) {
         deriv[i] = 0.;
diff --git a/MagneticField/MagFieldServices/src/AtlasFieldMapCondAlg.cxx b/MagneticField/MagFieldServices/src/AtlasFieldMapCondAlg.cxx
index 261c22ecf732..c60f448f33e8 100644
--- a/MagneticField/MagFieldServices/src/AtlasFieldMapCondAlg.cxx
+++ b/MagneticField/MagFieldServices/src/AtlasFieldMapCondAlg.cxx
@@ -260,9 +260,21 @@ MagField::AtlasFieldMapCondAlg::updateFieldMap(const EventContext& ctx, Cache& c
         fullMapFilename = m_fullMapFilename;
         soleMapFilename = m_soleMapFilename;
         toroMapFilename = m_toroMapFilename;
-        cache.m_mapSoleCurrent = m_mapSoleCurrent;
-        cache.m_mapToroCurrent = m_mapToroCurrent;
-
+        if (m_mapSoleCurrent < m_soleMinCurrent) {
+            cache.m_mapSoleCurrent = 0;
+            ATH_MSG_INFO("updateFieldMap: requested solenoid current in JobOpt " << m_mapSoleCurrent << " is below allowed minimum " << m_soleMinCurrent << " setting to 0");
+        }
+        else {
+            cache.m_mapSoleCurrent = m_mapSoleCurrent;
+        }
+        if (m_mapToroCurrent < m_toroMinCurrent) {
+            cache.m_mapToroCurrent = 0;
+            ATH_MSG_INFO("updateFieldMap: requested toroid current in JobOpt " << m_mapToroCurrent << " is below allowed minimum " << m_toroMinCurrent << " setting to 0");
+        }
+        else {
+            cache.m_mapToroCurrent = m_mapToroCurrent;
+        }
+        
         // Create a range for the current run
         EventIDBase start, stop;
         start.set_run_number(ctx.eventID().run_number());
-- 
GitLab