From 9bf20a53d39b8de92b8fc548392f6e60300bdd48 Mon Sep 17 00:00:00 2001
From: ralfulrich <ralf.ulrich@kit.edu>
Date: Mon, 9 Nov 2020 18:04:57 +0100
Subject: [PATCH] added central tracking testing

---
 Processes/Tracking/CMakeLists.txt             | 10 ++++
 .../testTracking.cc}                          | 42 +++++++++++---
 .../TrackingLeapFrogCurved/CMakeLists.txt     |  9 +--
 .../TrackingLeapFrogStraight/CMakeLists.txt   | 11 +---
 .../testTrackingBFieldStack.h                 | 58 -------------------
 Processes/TrackingLine/CMakeLists.txt         |  9 +--
 Processes/TrackingLine/testTrackingLine.cc    | 35 -----------
 7 files changed, 49 insertions(+), 125 deletions(-)
 rename Processes/{TrackingLeapFrogStraight/testTrackingLeapFrogStraight.cc => Tracking/testTracking.cc} (77%)
 delete mode 100644 Processes/TrackingLeapFrogStraight/testTrackingBFieldStack.h
 delete mode 100644 Processes/TrackingLine/testTrackingLine.cc

diff --git a/Processes/Tracking/CMakeLists.txt b/Processes/Tracking/CMakeLists.txt
index d0aebb6d3..088b37a41 100644
--- a/Processes/Tracking/CMakeLists.txt
+++ b/Processes/Tracking/CMakeLists.txt
@@ -32,3 +32,13 @@ target_include_directories (
 
 install (FILES ${MODEL_HEADERS} DESTINATION include/${MODEL_NAMESPACE})
 
+# #-- -- -- -- -- -- -- -- -- --
+# #code unit testing
+CORSIKA_ADD_TEST (testTracking)
+target_link_libraries (
+   testTracking
+   ProcessTrackingLine
+   ProcessTrackingLeapFrogStraight
+   ProcessTrackingLeapFrogCurved
+   CORSIKAtesting
+)
diff --git a/Processes/TrackingLeapFrogStraight/testTrackingLeapFrogStraight.cc b/Processes/Tracking/testTracking.cc
similarity index 77%
rename from Processes/TrackingLeapFrogStraight/testTrackingLeapFrogStraight.cc
rename to Processes/Tracking/testTracking.cc
index e75cbf741..fffe1ba2a 100644
--- a/Processes/TrackingLeapFrogStraight/testTrackingLeapFrogStraight.cc
+++ b/Processes/Tracking/testTracking.cc
@@ -6,7 +6,9 @@
  * the license.
  */
 
-#include <corsika/process/tracking_bfield/Tracking.h>
+#include <corsika/process/tracking_leapfrog_curved/Tracking.h>
+#include <corsika/process/tracking_leapfrog_straight/Tracking.h>
+#include <corsika/process/tracking_line/Tracking.h>
 
 #include <corsika/particles/ParticleProperties.h>
 
@@ -28,19 +30,45 @@ using namespace corsika::units;
 using namespace corsika::geometry;
 using namespace corsika::units::si;
 
+typedef corsika::geometry::Vector<corsika::units::si::magnetic_flux_density_d>
+    MagneticFieldVector;
+
 template <typename T>
 int sgn(T val) {
   return (T(0) < val) - (val < T(0));
 }
 
-TEST_CASE("TrackingBField") {
+/*
+  This is the unified and commond unit test for Tracking:
+
+  - tracking_leapfrog_curved::Tracking
+  - tracking_leapfrog_straight::Tracking
+  - tracking_line::Tracking
+
+ */
+
+TEMPLATE_TEST_CASE("TrackingLeapfrog_Curved", "tracking",
+                   tracking_leapfrog_curved::Tracking,
+                   tracking_leapfrog_straight::Tracking, tracking_line::Tracking) {
 
   logging::SetLevel(logging::level::trace);
 
   const HEPEnergyType P0 = 10_GeV;
 
   auto PID = GENERATE(as<Code>{}, Code::MuPlus, Code::MuPlus, Code::Gamma);
-  auto Bfield = GENERATE(as<MagneticFluxType>{}, 0_T, 50_uT, -50_uT);
+  // for algorithms that know magnetic deflections choose: +-50uT, 0uT
+  // otherwise just 0uT
+  auto Bfield = GENERATE(filter(
+      []([[maybe_unused]] MagneticFluxType v) {
+        if constexpr (std::is_same_v<TestType, tracking_line::Tracking>)
+          return v == 0_uT;
+	else 
+	  return true;
+      },
+      values<MagneticFluxType>({50_uT, 0_uT, -50_uT})));
+  // particle --> (world) --> | --> (target)
+  // true: start inside "world" volume
+  // false: start inside "target" volume
   auto outer = GENERATE(as<bool>{}, true, false);
 
   SECTION(fmt::format("Tracking PID={}, Bfield={} uT, from outside={}", PID,
@@ -57,7 +85,7 @@ TEST_CASE("TrackingBField") {
     if (chargeNumber != 0 and Bfield != 0_T) {
       deflect = -sgn(chargeNumber) * sgn(Bfield / 1_T); // direction of deflection
       LengthType const gyroradius =
-	P0 * 1_V / (constants::c * abs(chargeNumber) * abs(Bfield) * 1_eV);
+          P0 * 1_V / (constants::c * abs(chargeNumber) * abs(Bfield) * 1_eV);
       radius = gyroradius;
     }
 
@@ -65,8 +93,7 @@ TEST_CASE("TrackingBField") {
     { [[maybe_unused]] const auto& env_dummy = env; }
     auto const& cs = *csPtr;
 
-    tracking_leapfrog_straight::Tracking tracking;
-    using tracking_leapfrog_straight::MagneticFieldVector;
+    TestType tracking;
     Point const center(cs, {0_m, 0_m, 0_m});
     auto target = setup::Environment::CreateNode<geometry::Sphere>(center, radius);
 
@@ -122,6 +149,7 @@ TEST_CASE("TrackingBField") {
                 deflect, particle.GetMomentum().GetComponents(),
                 particle.GetPosition().GetCoordinates(), pointCheck.GetCoordinates());
 
-    CHECK((particle.GetPosition() - pointCheck).norm() / radius == Approx(0).margin(1e-3));
+    CHECK((particle.GetPosition() - pointCheck).norm() / radius ==
+          Approx(0).margin(1e-3));
   }
 }
diff --git a/Processes/TrackingLeapFrogCurved/CMakeLists.txt b/Processes/TrackingLeapFrogCurved/CMakeLists.txt
index 141929f27..8b3794d69 100644
--- a/Processes/TrackingLeapFrogCurved/CMakeLists.txt
+++ b/Processes/TrackingLeapFrogCurved/CMakeLists.txt
@@ -34,11 +34,4 @@ target_include_directories (
 
 install (FILES ${MODEL_HEADERS} DESTINATION include/${MODEL_NAMESPACE})
 
-# #-- -- -- -- -- -- -- -- -- --
-# #code unit testing
-CORSIKA_ADD_TEST (testTrackingLeapFrogCurved)
-target_link_libraries (
-   testTrackingLeapFrogCurved
-   ProcessTrackingLeapFrogCurved
-   CORSIKAtesting
-)
+# Note: all Tracking Algorithms are tested in testTracking
diff --git a/Processes/TrackingLeapFrogStraight/CMakeLists.txt b/Processes/TrackingLeapFrogStraight/CMakeLists.txt
index afd5d99c7..fba534550 100644
--- a/Processes/TrackingLeapFrogStraight/CMakeLists.txt
+++ b/Processes/TrackingLeapFrogStraight/CMakeLists.txt
@@ -5,7 +5,7 @@ set (
 
 set (
   MODEL_NAMESPACE
-  corsika/process/tracking_leapfrag_straight
+  corsika/process/tracking_leapfrog_straight
   )
 
 add_library (ProcessTrackingLeapFrogStraight INTERFACE)
@@ -33,11 +33,4 @@ target_include_directories (
 
 install (FILES ${MODEL_HEADERS} DESTINATION include/${MODEL_NAMESPACE})
 
-# #-- -- -- -- -- -- -- -- -- --
-# #code unit testing
-CORSIKA_ADD_TEST (testTrackingLeapFrogStraight)
-target_link_libraries (
-   testTrackingLeapFrogStraight
-   ProcessTrackingLeapFrogStraight
-   CORSIKAtesting
-)
+# Note: all Tracking Algorithms are tested in testTracking
diff --git a/Processes/TrackingLeapFrogStraight/testTrackingBFieldStack.h b/Processes/TrackingLeapFrogStraight/testTrackingBFieldStack.h
deleted file mode 100644
index 98d7ce3fe..000000000
--- a/Processes/TrackingLeapFrogStraight/testTrackingBFieldStack.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
- *
- * This software is distributed under the terms of the GNU General Public
- * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
- * the license.
- */
-
-#pragma once
-
-#include <corsika/environment/Environment.h>
-
-#include <corsika/geometry/Point.h>
-#include <corsika/geometry/Vector.h>
-
-#include <corsika/particles/ParticleProperties.h>
-
-#include <corsika/stack/CombinedStack.h>
-#include <corsika/stack/node/GeometryNodeStackExtension.h>
-#include <corsika/stack/nuclear_extension/NuclearStackExtension.h>
-
-#include <corsika/units/PhysicalUnits.h>
-
-class TestMagneticField {
-  using MagneticFieldVector =
-      corsika::geometry::Vector<corsika::units::si::magnetic_flux_density_d>;
-
-  TestMagneticField() = delete;
-  
-public:
-  TestMagneticField(const corsika::units::si::MagneticFluxType& field)
-    : Bz_(field) {}
-
-  void SetMagneticField(const corsika::units::si::MagneticFluxType& field) { Bz_ = field; }
-  MagneticFieldVector GetMagneticField(corsika::geometry::Point const& p) const {
-    using namespace corsika::units::si;
-    return MagneticFieldVector(p.GetCoordinateSystem(), 0_T, 0_T, Bz_);
-  }
-
-private:
-  corsika::units::si::MagneticFluxType Bz_;
-};
-
-using TestEnvironmentType = corsika::environment::Environment<TestMagneticField>;
-
-template <typename T>
-using SetupGeometryDataInterface =
-    corsika::stack::node::GeometryDataInterface<T, TestEnvironmentType>;
-
-// combine particle data stack with geometry information for tracking
-template <typename StackIter>
-using StackWithGeometryInterface = corsika::stack::CombinedParticleInterface<
-    corsika::stack::nuclear_extension::ParticleDataStack::MPIType,
-    SetupGeometryDataInterface, StackIter>;
-
-using TestTrackingBFieldStack = corsika::stack::CombinedStack<
-    typename corsika::stack::nuclear_extension::ParticleDataStack::StackImpl,
-    corsika::stack::node::GeometryData<TestEnvironmentType>, StackWithGeometryInterface>;
diff --git a/Processes/TrackingLine/CMakeLists.txt b/Processes/TrackingLine/CMakeLists.txt
index a5376eac1..75dcaec7e 100644
--- a/Processes/TrackingLine/CMakeLists.txt
+++ b/Processes/TrackingLine/CMakeLists.txt
@@ -34,11 +34,4 @@ target_include_directories (
 
 install (FILES ${MODEL_HEADERS} DESTINATION include/${MODEL_NAMESPACE})
 
-# #-- -- -- -- -- -- -- -- -- --
-# #code unit testing
-CORSIKA_ADD_TEST (testTrackingLine)
-target_link_libraries (
-   testTrackingLine
-   ProcessTrackingLine
-   CORSIKAtesting
-)
+# Note: all Tracking Algorithms are tested in testTracking
diff --git a/Processes/TrackingLine/testTrackingLine.cc b/Processes/TrackingLine/testTrackingLine.cc
deleted file mode 100644
index df6524185..000000000
--- a/Processes/TrackingLine/testTrackingLine.cc
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
- *
- * This software is distributed under the terms of the GNU General Public
- * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
- * the license.
- */
-
-#include <corsika/process/tracking_line/Tracking.h>
-#include <testTrackingLineStack.h> // test-build, and include file is obtained from CMAKE_CURRENT_SOURCE_DIR
-
-#include <corsika/environment/Environment.h>
-#include <corsika/particles/ParticleProperties.h>
-
-#include <corsika/geometry/Point.h>
-#include <corsika/geometry/Sphere.h>
-#include <corsika/geometry/Vector.h>
-#include <corsika/geometry/Intersections.hpp>
-
-#include <corsika/setup/SetupTrajectory.h>
-using corsika::setup::Trajectory;
-
-#include <catch2/catch.hpp>
-
-using namespace corsika;
-using namespace corsika::process;
-using namespace corsika::units;
-using namespace corsika::geometry;
-
-#include <iostream>
-using namespace std;
-using namespace corsika::units::si;
-
-TEST_CASE("TrackingLine") {
-}
-- 
GitLab