From f0bcb05ea763e3f31c72f74c0dde665808ddebe7 Mon Sep 17 00:00:00 2001
From: Moritz Kiehn <msmk@cern.ch>
Date: Fri, 10 Mar 2017 13:03:58 +0100
Subject: [PATCH] Surfaces/BoundaryCheck: store covariance by value

---
 Core/include/ACTS/Surfaces/BoundaryCheck.hpp  | 33 +++++++----------
 Core/include/ACTS/Surfaces/CylinderBounds.hpp | 12 +++----
 Core/include/ACTS/Surfaces/DiamondBounds.hpp  | 22 ++++++------
 .../ACTS/Surfaces/DiscTrapezoidalBounds.hpp   | 10 +++---
 Core/include/ACTS/Surfaces/LineBounds.hpp     | 12 +++----
 Core/include/ACTS/Surfaces/RadialBounds.hpp   | 10 +++---
 .../include/ACTS/Surfaces/RectangleBounds.hpp | 22 ++++++------
 .../include/ACTS/Surfaces/TrapezoidBounds.hpp | 20 +++++------
 Core/include/ACTS/Surfaces/TriangleBounds.hpp | 16 ++++-----
 Core/src/Surfaces/BoundaryCheck.cpp           | 35 ++-----------------
 Tests/Surfaces/BoundaryCheckTests.cpp         | 16 ++-------
 11 files changed, 77 insertions(+), 131 deletions(-)

diff --git a/Core/include/ACTS/Surfaces/BoundaryCheck.hpp b/Core/include/ACTS/Surfaces/BoundaryCheck.hpp
index 0fae84c44..5a4b7527f 100644
--- a/Core/include/ACTS/Surfaces/BoundaryCheck.hpp
+++ b/Core/include/ACTS/Surfaces/BoundaryCheck.hpp
@@ -14,7 +14,7 @@
 #define ACTS_SURFACES_BOUNDARYCHECK_H 1
 
 #include <cmath>
-#include <memory>
+#include <limits>
 #include <vector>
 #include "ACTS/Utilities/Definitions.hpp"
 #include "ACTS/Utilities/ParameterDefinitions.hpp"
@@ -62,13 +62,13 @@ public:
     chi2corr = 1   ///< relative (chi2 based) with full correlations
   };
 
-  bool   checkLoc0;      ///< check local 1 coordinate
-  bool   checkLoc1;      ///< check local 2 coordinate
-  double toleranceLoc0;  ///< absolute tolerance in local 1 coordinate
-  double toleranceLoc1;  ///< absolute tolerance in local 2 coordinate
-  double nSigmas;        ///< allowed sigmas for chi2 boundary check
-  std::unique_ptr<ActsSymMatrixD<2>> lCovariance;  ///< local covariance matrix
-  BoundaryCheckType bcType;  ///< the type how we check the boundary
+  bool   checkLoc0;               ///< check local 1 coordinate
+  bool   checkLoc1;               ///< check local 2 coordinate
+  double toleranceLoc0;           ///< absolute tolerance in local 1 coordinate
+  double toleranceLoc1;           ///< absolute tolerance in local 2 coordinate
+  double nSigmas;                 ///< allowed sigmas for chi2 boundary check
+  ActsSymMatrixD<2> lCovariance;  ///< local covariance matrix
+  BoundaryCheckType bcType;       ///< the type how we check the boundary
 
   /// Constructor for single boolean behavious
   BoundaryCheck(bool sCheck);
@@ -90,17 +90,6 @@ public:
                 bool                     chkL0 = true,
                 bool                     chkL1 = true);
 
-  /// Copy Constructor
-  ///
-  /// @param bCheck is the source class
-  BoundaryCheck(const BoundaryCheck& bCheck);
-
-  /// Assignment operator
-  ///
-  /// @param bCheck is the source class
-  BoundaryCheck&
-  operator=(const BoundaryCheck& bCheck);
-
   /// Overwriting of the
   /// Conversion operator to bool
   operator bool() const { return (checkLoc0 || checkLoc1); }
@@ -125,8 +114,10 @@ public:
 inline std::vector<Vector2D>
 BoundaryCheck::EllipseToPoly(int resolution) const
 {
-  const double h = lCovariance ? nSigmas * sqrt((*lCovariance)(1, 1)) : 0.;
-  const double w = lCovariance ? nSigmas * sqrt((*lCovariance)(0, 0)) : 0.;
+  const double h
+      = (bcType == chi2corr) ? nSigmas * sqrt(lCovariance(1, 1)) : 0.;
+  const double w
+      = (bcType == chi2corr) ? nSigmas * sqrt(lCovariance(0, 0)) : 0.;
 
   // first add the four vertices
   std::vector<Vector2D> v((1 + resolution) * 4);
diff --git a/Core/include/ACTS/Surfaces/CylinderBounds.hpp b/Core/include/ACTS/Surfaces/CylinderBounds.hpp
index 98edbc3dc..761b4be04 100644
--- a/Core/include/ACTS/Surfaces/CylinderBounds.hpp
+++ b/Core/include/ACTS/Surfaces/CylinderBounds.hpp
@@ -213,16 +213,16 @@ CylinderBounds::inside(const Vector2D& lpos, const BoundaryCheck& bcheck) const
         lpos, bcheck.toleranceLoc0, bcheck.toleranceLoc1);
 
   float theta
-      = ((*bcheck.lCovariance)(1, 0) != 0
-         && ((*bcheck.lCovariance)(1, 1) - (*bcheck.lCovariance)(0, 0)) != 0)
+      = (bcheck.lCovariance(1, 0) != 0
+         && (bcheck.lCovariance(1, 1) - bcheck.lCovariance(0, 0)) != 0)
       ? .5 * std::atan(
-                 2 * (*bcheck.lCovariance)(1, 0)
-                 / ((*bcheck.lCovariance)(1, 1) - (*bcheck.lCovariance)(0, 0)))
+                 2 * bcheck.lCovariance(1, 0)
+                 / (bcheck.lCovariance(1, 1) - bcheck.lCovariance(0, 0)))
       : 0.;
   double sinTheta = std::sin(theta);
   double cosTheta = std::cos(theta);
-  double dphi     = sinTheta * sinTheta * (*bcheck.lCovariance)(0, 0);
-  double dz       = cosTheta * cosTheta * (*bcheck.lCovariance)(0, 1);
+  double dphi     = sinTheta * sinTheta * bcheck.lCovariance(0, 0);
+  double dz       = cosTheta * cosTheta * bcheck.lCovariance(0, 1);
   double max_ell  = dphi > dz ? dphi : dz;
   double limit    = bcheck.nSigmas * sqrt(max_ell);
   return insideLocZ(lpos[Acts::eLOC_Z], limit);
diff --git a/Core/include/ACTS/Surfaces/DiamondBounds.hpp b/Core/include/ACTS/Surfaces/DiamondBounds.hpp
index c4feed579..ac6ade05f 100644
--- a/Core/include/ACTS/Surfaces/DiamondBounds.hpp
+++ b/Core/include/ACTS/Surfaces/DiamondBounds.hpp
@@ -239,9 +239,9 @@ DiamondBounds::inside(const Vector2D& lpos, const BoundaryCheck& bcheck) const
         lpos, bcheck.toleranceLoc0, bcheck.toleranceLoc1);
 
   // a fast FALSE
-  double max_ell = (*bcheck.lCovariance)(0, 0) > (*bcheck.lCovariance)(1, 1)
-      ? (*bcheck.lCovariance)(0, 0)
-      : (*bcheck.lCovariance)(1, 1);
+  double max_ell = bcheck.lCovariance(0, 0) > bcheck.lCovariance(1, 1)
+      ? bcheck.lCovariance(0, 0)
+      : bcheck.lCovariance(1, 1);
   double limit = bcheck.nSigmas * sqrt(max_ell);
   if (lpos[Acts::eLOC_Y]
       < -2 * m_valueStore.at(DiamondBounds::bv_halfY1) - limit)
@@ -254,9 +254,9 @@ DiamondBounds::inside(const Vector2D& lpos, const BoundaryCheck& bcheck) const
   if (fabsX > (m_valueStore.at(DiamondBounds::bv_medHalfX) + limit))
     return false;
   // a fast TRUE
-  double min_ell = (*bcheck.lCovariance)(0, 0) < (*bcheck.lCovariance)(1, 1)
-      ? (*bcheck.lCovariance)(0, 0)
-      : (*bcheck.lCovariance)(1, 1);
+  double min_ell = bcheck.lCovariance(0, 0) < bcheck.lCovariance(1, 1)
+      ? bcheck.lCovariance(0, 0)
+      : bcheck.lCovariance(1, 1);
   limit = bcheck.nSigmas * sqrt(min_ell);
   if (fabsX < (fmin(m_valueStore.at(DiamondBounds::bv_minHalfX),
                     m_valueStore.at(DiamondBounds::bv_maxHalfX))
@@ -272,12 +272,10 @@ DiamondBounds::inside(const Vector2D& lpos, const BoundaryCheck& bcheck) const
   // compute KDOP and axes for surface polygon
   std::vector<KDOP>     elementKDOP(5);
   std::vector<Vector2D> elementP(6);
-  float                 theta
-      = ((*bcheck.lCovariance)(1, 0) != 0
-         && ((*bcheck.lCovariance)(1, 1) - (*bcheck.lCovariance)(0, 0)) != 0)
-      ? .5 * std::atan(
-                 2 * (*bcheck.lCovariance)(1, 0)
-                 / ((*bcheck.lCovariance)(1, 1) - (*bcheck.lCovariance)(0, 0)))
+  float                 theta = (bcheck.lCovariance(1, 0) != 0
+                 && (bcheck.lCovariance(1, 1) - bcheck.lCovariance(0, 0)) != 0)
+      ? .5 * std::atan(2 * bcheck.lCovariance(1, 0)
+                       / (bcheck.lCovariance(1, 1) - bcheck.lCovariance(0, 0)))
       : 0.;
   auto rotMatrix = Eigen::Rotation2D<double>(theta).toRotationMatrix();
   ActsMatrixD<2, 2> normal;
diff --git a/Core/include/ACTS/Surfaces/DiscTrapezoidalBounds.hpp b/Core/include/ACTS/Surfaces/DiscTrapezoidalBounds.hpp
index 3ab109b1f..ea8290066 100644
--- a/Core/include/ACTS/Surfaces/DiscTrapezoidalBounds.hpp
+++ b/Core/include/ACTS/Surfaces/DiscTrapezoidalBounds.hpp
@@ -226,12 +226,12 @@ DiscTrapezoidalBounds::inside(const Vector2D&      lpos,
   // a fast FALSE
   double sinPhi = std::sin(lpos[1]);
   double cosPhi = std::cos(lpos[1]);
-  double dx     = bcheck.nSigmas * sqrt((*bcheck.lCovariance)(0, 0));
+  double dx     = bcheck.nSigmas * sqrt(bcheck.lCovariance(0, 0));
   double dy     = bcheck.nSigmas
-      * sqrt(sinPhi * sinPhi * (*bcheck.lCovariance)(0, 0)
+      * sqrt(sinPhi * sinPhi * bcheck.lCovariance(0, 0)
              + lpos(0, 0) * lpos(0, 0) * cosPhi * cosPhi
-                 * (*bcheck.lCovariance)(1, 1)
-             + 2 * cosPhi * sinPhi * lpos(0, 0) * (*bcheck.lCovariance)(0, 1));
+                 * bcheck.lCovariance(1, 1)
+             + 2 * cosPhi * sinPhi * lpos(0, 0) * bcheck.lCovariance(0, 1));
   double max_ell = dx > dy ? dx : dy;
   if (lpos(0, 0)
       > (m_valueStore.at(DiscTrapezoidalBounds::bv_rMax)
@@ -390,7 +390,7 @@ DiscTrapezoidalBounds::inside(const Vector2D&      lpos,
   ActsMatrixD<2, 2> covRotMatrix;
   covRotMatrix << cosPhi, -lpos(0, 0) * sinPhi, sinPhi, lpos(0, 0) * cosPhi;
   ActsMatrixD<2, 2> lCovarianceCar
-      = covRotMatrix * (*bcheck.lCovariance) * covRotMatrix.transpose();
+      = covRotMatrix * bcheck.lCovariance * covRotMatrix.transpose();
   Vector2D lposCar(covRotMatrix(1, 1), -covRotMatrix(0, 1));
 
   // ellipse is always at (0,0), surface is moved to ellipse position and then
diff --git a/Core/include/ACTS/Surfaces/LineBounds.hpp b/Core/include/ACTS/Surfaces/LineBounds.hpp
index 94c240a55..3c34bad30 100644
--- a/Core/include/ACTS/Surfaces/LineBounds.hpp
+++ b/Core/include/ACTS/Surfaces/LineBounds.hpp
@@ -161,16 +161,16 @@ LineBounds::inside(const Vector2D& lpos, const BoundaryCheck& bcheck) const
     return LineBounds::inside(lpos, bcheck.toleranceLoc0, bcheck.toleranceLoc1);
   // ellipsoid check
   float theta
-      = ((*bcheck.lCovariance)(1, 0) != 0
-         && ((*bcheck.lCovariance)(1, 1) - (*bcheck.lCovariance)(0, 0)) != 0)
+      = (bcheck.lCovariance(1, 0) != 0
+         && (bcheck.lCovariance(1, 1) - bcheck.lCovariance(0, 0)) != 0)
       ? .5 * std::atan(
-                 2 * (*bcheck.lCovariance)(1, 0)
-                 / ((*bcheck.lCovariance)(1, 1) - (*bcheck.lCovariance)(0, 0)))
+                 2 * bcheck.lCovariance(1, 0)
+                 / (bcheck.lCovariance(1, 1) - bcheck.lCovariance(0, 0)))
       : 0.;
   double sinTheta = std::sin(theta);
   double cosTheta = std::cos(theta);
-  double dphi     = sinTheta * sinTheta * (*bcheck.lCovariance)(0, 0);
-  double dz       = cosTheta * cosTheta * (*bcheck.lCovariance)(0, 1);
+  double dphi     = sinTheta * sinTheta * bcheck.lCovariance(0, 0);
+  double dz       = cosTheta * cosTheta * bcheck.lCovariance(0, 1);
   double max_ell  = dphi > dz ? dphi : dz;
   double limit    = bcheck.nSigmas * sqrt(max_ell);
   return insideLocZ(lpos[Acts::eLOC_Z], limit);
diff --git a/Core/include/ACTS/Surfaces/RadialBounds.hpp b/Core/include/ACTS/Surfaces/RadialBounds.hpp
index e7cd421de..75b4fc891 100644
--- a/Core/include/ACTS/Surfaces/RadialBounds.hpp
+++ b/Core/include/ACTS/Surfaces/RadialBounds.hpp
@@ -191,12 +191,12 @@ RadialBounds::inside(const Vector2D& lpos, const BoundaryCheck& bcheck) const
   // a fast FALSE
   double sinPhi = std::sin(lpos[1]);
   double cosPhi = std::cos(lpos[1]);
-  double dx     = bcheck.nSigmas * sqrt((*bcheck.lCovariance)(0, 0));
+  double dx     = bcheck.nSigmas * sqrt(bcheck.lCovariance(0, 0));
   double dy     = bcheck.nSigmas
-      * sqrt(sinPhi * sinPhi * (*bcheck.lCovariance)(0, 0)
+      * sqrt(sinPhi * sinPhi * bcheck.lCovariance(0, 0)
              + lpos(0, 0) * lpos(0, 0) * cosPhi * cosPhi
-                 * (*bcheck.lCovariance)(1, 1)
-             + 2 * cosPhi * sinPhi * lpos(0, 0) * (*bcheck.lCovariance)(0, 1));
+                 * bcheck.lCovariance(1, 1)
+             + 2 * cosPhi * sinPhi * lpos(0, 0) * bcheck.lCovariance(0, 1));
   double max_ell = dx > dy ? dx : dy;
   if (lpos(0, 0) > (m_valueStore[RadialBounds::bv_rMax] + max_ell))
     return false;
@@ -346,7 +346,7 @@ RadialBounds::inside(const Vector2D& lpos, const BoundaryCheck& bcheck) const
   ActsMatrixD<2, 2> covRotMatrix;
   covRotMatrix << cosPhi, -lpos(0, 0) * sinPhi, sinPhi, lpos(0, 0) * cosPhi;
   ActsMatrixD<2, 2> lCovarianceCar
-      = covRotMatrix * (*bcheck.lCovariance) * covRotMatrix.transpose();
+      = covRotMatrix * bcheck.lCovariance * covRotMatrix.transpose();
   Vector2D lposCar(covRotMatrix(1, 1), -covRotMatrix(0, 1));
 
   // ellipse is always at (0,0), surface is moved to ellipse position and then
diff --git a/Core/include/ACTS/Surfaces/RectangleBounds.hpp b/Core/include/ACTS/Surfaces/RectangleBounds.hpp
index f0fa736bc..5a5fe73d1 100644
--- a/Core/include/ACTS/Surfaces/RectangleBounds.hpp
+++ b/Core/include/ACTS/Surfaces/RectangleBounds.hpp
@@ -156,27 +156,25 @@ RectangleBounds::inside(const Vector2D& lpos, const BoundaryCheck& bcheck) const
         && RectangleBounds::insideLoc1(lpos, bcheck.toleranceLoc1);
 
   // a fast FALSE
-  double max_ell = (*bcheck.lCovariance)(0, 0) > (*bcheck.lCovariance)(1, 1)
-      ? (*bcheck.lCovariance)(0, 0)
-      : (*bcheck.lCovariance)(1, 1);
+  double max_ell = bcheck.lCovariance(0, 0) > bcheck.lCovariance(1, 1)
+      ? bcheck.lCovariance(0, 0)
+      : bcheck.lCovariance(1, 1);
   double limit = bcheck.nSigmas * sqrt(max_ell);
   if (!RectangleBounds::inside(lpos, limit, limit)) return false;
   // a fast TRUE
-  double min_ell = (*bcheck.lCovariance)(0, 0) < (*bcheck.lCovariance)(1, 1)
-      ? (*bcheck.lCovariance)(0, 0)
-      : (*bcheck.lCovariance)(1, 1);
+  double min_ell = bcheck.lCovariance(0, 0) < bcheck.lCovariance(1, 1)
+      ? bcheck.lCovariance(0, 0)
+      : bcheck.lCovariance(1, 1);
   limit = bcheck.nSigmas * sqrt(min_ell);
   if (RectangleBounds::inside(lpos, limit, limit)) return true;
 
   // compute KDOP and axes for surface polygon
   std::vector<KDOP>     elementKDOP(4);
   std::vector<Vector2D> elementP(4);
-  float                 theta
-      = ((*bcheck.lCovariance)(1, 0) != 0
-         && ((*bcheck.lCovariance)(1, 1) - (*bcheck.lCovariance)(0, 0)) != 0)
-      ? .5
-          * std::atan(2 * (*bcheck.lCovariance)(1, 0)
-                            / ((*bcheck.lCovariance)(1, 1) - (*bcheck.lCovariance)(0, 0)))
+  float                 theta = (bcheck.lCovariance(1, 0) != 0
+                 && (bcheck.lCovariance(1, 1) - bcheck.lCovariance(0, 0)) != 0)
+      ? .5 * std::atan(2 * bcheck.lCovariance(1, 0)
+                       / (bcheck.lCovariance(1, 1) - bcheck.lCovariance(0, 0)))
       : 0.;
   auto rotMatrix = Eigen::Rotation2D<double>(theta).toRotationMatrix();
   // ellipse is always at (0,0), surface is moved to ellipse position and then
diff --git a/Core/include/ACTS/Surfaces/TrapezoidBounds.hpp b/Core/include/ACTS/Surfaces/TrapezoidBounds.hpp
index 773fffd34..ff087d09d 100644
--- a/Core/include/ACTS/Surfaces/TrapezoidBounds.hpp
+++ b/Core/include/ACTS/Surfaces/TrapezoidBounds.hpp
@@ -300,9 +300,9 @@ TrapezoidBounds::inside(const Vector2D& lpos, const BoundaryCheck& bcheck) const
 
   // a fast FALSE
   double fabsY   = std::abs(lpos[Acts::eLOC_Y]);
-  double max_ell = (*bcheck.lCovariance)(0, 0) > (*bcheck.lCovariance)(1, 1)
-      ? (*bcheck.lCovariance)(0, 0)
-      : (*bcheck.lCovariance)(1, 1);
+  double max_ell = bcheck.lCovariance(0, 0) > bcheck.lCovariance(1, 1)
+      ? bcheck.lCovariance(0, 0)
+      : bcheck.lCovariance(1, 1);
   double limit = bcheck.nSigmas * sqrt(max_ell);
   if (fabsY > (m_valueStore.at(TrapezoidBounds::bv_halfY) + limit))
     return false;
@@ -311,9 +311,9 @@ TrapezoidBounds::inside(const Vector2D& lpos, const BoundaryCheck& bcheck) const
   if (fabsX > (m_valueStore.at(TrapezoidBounds::bv_maxHalfX) + limit))
     return false;
   // a fast TRUE
-  double min_ell = (*bcheck.lCovariance)(0, 0) < (*bcheck.lCovariance)(1, 1)
-      ? (*bcheck.lCovariance)(0, 0)
-      : (*bcheck.lCovariance)(1, 1);
+  double min_ell = bcheck.lCovariance(0, 0) < bcheck.lCovariance(1, 1)
+      ? bcheck.lCovariance(0, 0)
+      : bcheck.lCovariance(1, 1);
   limit = bcheck.nSigmas * sqrt(min_ell);
   if (fabsX < (m_valueStore.at(TrapezoidBounds::bv_minHalfX) + limit)
       && fabsY < (m_valueStore.at(TrapezoidBounds::bv_halfY) + limit))
@@ -323,11 +323,11 @@ TrapezoidBounds::inside(const Vector2D& lpos, const BoundaryCheck& bcheck) const
   std::vector<KDOP>     elementKDOP(3);
   std::vector<Vector2D> elementP(4);
   float                 theta
-      = ((*bcheck.lCovariance)(1, 0) != 0
-         && ((*bcheck.lCovariance)(1, 1) - (*bcheck.lCovariance)(0, 0)) != 0)
+      = (bcheck.lCovariance(1, 0) != 0
+         && (bcheck.lCovariance(1, 1) - bcheck.lCovariance(0, 0)) != 0)
       ? .5 * std::atan(
-                 2 * (*bcheck.lCovariance)(1, 0)
-                 / ((*bcheck.lCovariance)(1, 1) - (*bcheck.lCovariance)(0, 0)))
+                 2 * bcheck.lCovariance(1, 0)
+                 / (bcheck.lCovariance(1, 1) - bcheck.lCovariance(0, 0)))
       : 0.;
   auto rotMatrix = Eigen::Rotation2D<double>(theta).toRotationMatrix();
   ActsMatrixD<2, 2> normal;
diff --git a/Core/include/ACTS/Surfaces/TriangleBounds.hpp b/Core/include/ACTS/Surfaces/TriangleBounds.hpp
index 2d7a571e4..7aa19da0a 100644
--- a/Core/include/ACTS/Surfaces/TriangleBounds.hpp
+++ b/Core/include/ACTS/Surfaces/TriangleBounds.hpp
@@ -201,9 +201,9 @@ TriangleBounds::inside(const Vector2D& lpos, const BoundaryCheck& bcheck) const
         lpos, bcheck.toleranceLoc0, bcheck.toleranceLoc1);
 
   /// @todo check for quick limit test
-  /// double max_ell = (*bcheck.lCovariance)(0, 0) > (*bcheck.lCovariance)(1, 1)
-  ///    ? (*bcheck.lCovariance)(0, 0)
-  ///    : (*bcheck.lCovariance)(1, 1);
+  /// double max_ell = bcheck.lCovariance(0, 0) > bcheck.lCovariance(1, 1)
+  ///    ? bcheck.lCovariance(0, 0)
+  ///    : bcheck.lCovariance(1, 1);
   /// a fast FALSE
   /// double fabsR = sqrt(lpos[Acts::eLOC_X] * lpos[Acts::eLOC_X]
   ///                    + lpos[Acts::eLOC_Y] * lpos[Acts::eLOC_Y]);
@@ -213,12 +213,10 @@ TriangleBounds::inside(const Vector2D& lpos, const BoundaryCheck& bcheck) const
   // compute KDOP and axes for surface polygon
   std::vector<KDOP>     elementKDOP(3);
   std::vector<Vector2D> elementP(3);
-  double                theta
-      = ((*bcheck.lCovariance)(1, 0) != 0
-         && ((*bcheck.lCovariance)(1, 1) - (*bcheck.lCovariance)(0, 0)) != 0)
-      ? .5
-          * std::atan(2 * (*bcheck.lCovariance)(1, 0)
-                            / ((*bcheck.lCovariance)(1, 1) - (*bcheck.lCovariance)(0, 0)))
+  double                theta = (bcheck.lCovariance(1, 0) != 0
+                  && (bcheck.lCovariance(1, 1) - bcheck.lCovariance(0, 0)) != 0)
+      ? .5 * std::atan(2 * bcheck.lCovariance(1, 0)
+                       / (bcheck.lCovariance(1, 1) - bcheck.lCovariance(0, 0)))
       : 0.;
   auto rotMatrix = Eigen::Rotation2D<double>(theta).toRotationMatrix();
   ActsMatrixD<2, 2> normal;
diff --git a/Core/src/Surfaces/BoundaryCheck.cpp b/Core/src/Surfaces/BoundaryCheck.cpp
index e6773d231..7e7a8a881 100644
--- a/Core/src/Surfaces/BoundaryCheck.cpp
+++ b/Core/src/Surfaces/BoundaryCheck.cpp
@@ -18,7 +18,7 @@ Acts::BoundaryCheck::BoundaryCheck(bool sCheck)
   , toleranceLoc0(0.)
   , toleranceLoc1(0.)
   , nSigmas(-1)
-  , lCovariance(nullptr)
+  , lCovariance(ActsSymMatrixD<2>::Identity())
   , bcType(absolute)
 {
 }
@@ -32,7 +32,7 @@ Acts::BoundaryCheck::BoundaryCheck(bool   chkL0,
   , toleranceLoc0(tloc0)
   , toleranceLoc1(tloc1)
   , nSigmas(-1)
-  , lCovariance(nullptr)
+  , lCovariance(ActsSymMatrixD<2>::Identity())
   , bcType(absolute)
 {
 }
@@ -46,36 +46,7 @@ Acts::BoundaryCheck::BoundaryCheck(const ActsSymMatrixD<2>& lCov,
   , toleranceLoc0(0.)
   , toleranceLoc1(0.)
   , nSigmas(nsig)
-  , lCovariance(std::make_unique<ActsSymMatrixD<2>>(lCov))
+  , lCovariance(lCov)
   , bcType(chi2corr)
 {
 }
-
-Acts::BoundaryCheck::BoundaryCheck(const BoundaryCheck& bCheck)
-  : checkLoc0(bCheck.checkLoc0)
-  , checkLoc1(bCheck.checkLoc1)
-  , toleranceLoc0(bCheck.toleranceLoc0)
-  , toleranceLoc1(bCheck.toleranceLoc1)
-  , nSigmas(bCheck.nSigmas)
-  , lCovariance(nullptr)
-  , bcType(bCheck.bcType)
-{
-  lCovariance = bCheck.lCovariance
-      ? std::make_unique<ActsSymMatrixD<2>>(*bCheck.lCovariance)
-      : nullptr;
-}
-
-Acts::BoundaryCheck&
-Acts::BoundaryCheck::operator=(const BoundaryCheck& bCheck)
-{
-  if (this != &bCheck) {
-    checkLoc0     = bCheck.checkLoc0;
-    checkLoc1     = bCheck.checkLoc1;
-    toleranceLoc0 = bCheck.toleranceLoc0;
-    toleranceLoc1 = bCheck.toleranceLoc1;
-    nSigmas       = bCheck.nSigmas;
-    lCovariance   = nullptr;
-    bcType        = bCheck.bcType;
-  }
-  return (*this);
-}
diff --git a/Tests/Surfaces/BoundaryCheckTests.cpp b/Tests/Surfaces/BoundaryCheckTests.cpp
index c063180b6..076206ed8 100644
--- a/Tests/Surfaces/BoundaryCheckTests.cpp
+++ b/Tests/Surfaces/BoundaryCheckTests.cpp
@@ -62,8 +62,8 @@ namespace Test {
     BoundaryCheck boundaryCheckWithCovariance{cov, nSigma, true, true};
     BOOST_TEST(boundaryCheckWithCovariance.checkLoc1 == true);
     BoundaryCheck copyConstructedBoundaryCheck(boundaryCheckWithCovariance);
-    const auto& originalCovariance = *(boundaryCheckWithCovariance.lCovariance);
-    const auto& copiedCovariance = *(copyConstructedBoundaryCheck.lCovariance);
+    auto originalCovariance = boundaryCheckWithCovariance.lCovariance;
+    auto copiedCovariance = copyConstructedBoundaryCheck.lCovariance;
     BOOST_TEST(originalCovariance == copiedCovariance);
     // corner cases (NaN, inf, in tolerance and covariance) are not tested.
   }
@@ -157,7 +157,6 @@ namespace Test {
   }
 
   /// Unit test for assignment
-  BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(BoundaryCheckAssignment, 1);
   BOOST_AUTO_TEST_CASE(BoundaryCheckAssignment)
   {
     //
@@ -172,16 +171,7 @@ namespace Test {
     BOOST_TEST(assigned.toleranceLoc0 == original.toleranceLoc0);
     BOOST_TEST(assigned.toleranceLoc1 == original.toleranceLoc1);
     BOOST_TEST(assigned.nSigmas == original.nSigmas);
-    BOOST_TEST((bool(original.lCovariance)),
-               "Original object pointer to covariance should not be null");
-    // the following will fail
-    BOOST_TEST((bool(assigned.lCovariance)),
-               "Assigned object pointer to covariance should not be null");
-    if (original.lCovariance and assigned.lCovariance) {
-      auto& originalCovariance{*(original.lCovariance)};
-      auto& assignedCovariance{*(assigned.lCovariance)};
-      BOOST_TEST(originalCovariance == assignedCovariance);
-    }
+    BOOST_TEST(assigned.lCovariance == original.lCovariance);
   }
   BOOST_AUTO_TEST_SUITE_END();
 }  // end of namespace Test
-- 
GitLab