From fa194cf8e4ae2cc7c7831040896ea82a4cc75a71 Mon Sep 17 00:00:00 2001
From: ralfulrich <ralf.ulrich@kit.edu>
Date: Wed, 1 Sep 2021 09:19:17 +0200
Subject: [PATCH] added explicit conex init method. This allows to run multiple
 showers, and re-init

---
 corsika/detail/modules/conex/CONEXhybrid.inl | 10 ++++++----
 corsika/modules/conex/Random.hpp             | 13 +++++++++++++
 tests/modules/testCONEX.cpp                  |  3 ++-
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/corsika/detail/modules/conex/CONEXhybrid.inl b/corsika/detail/modules/conex/CONEXhybrid.inl
index 1e84975f4..95b47ace8 100644
--- a/corsika/detail/modules/conex/CONEXhybrid.inl
+++ b/corsika/detail/modules/conex/CONEXhybrid.inl
@@ -80,7 +80,9 @@ namespace corsika {
     CORSIKA_LOG_DEBUG("showerCore (C8): {}",
                       showerCore_.getCoordinates(center.getCoordinateSystem()));
 
-    int randomSeeds[3] = {1234, 0, 0}; // will be overwritten later??
+    int randomSeeds[3] = {1234, 0,
+                          0}; // SEEDS ARE NOT USED. All random numbers are obtained from
+                              // the CORSIKA 8 stream "conex" and "epos"!
     int heModel = eSibyll23;
 
     int nShower = 1; // large to avoid final stats.
@@ -118,13 +120,13 @@ namespace corsika {
         theta, phi);
 
     int ipart = static_cast<int>(primaryPDG_);
-    auto rng = RNGManager<>::getInstance().getRandomStream("conex");
 
     double dimpact = 0.; // valid only if shower core is fixed on the observation plane;
                          // for skimming showers an offset is needed like in CONEX
 
-    std::array<int, 3> ioseed{static_cast<int>(rng()), static_cast<int>(rng()),
-                              static_cast<int>(rng())};
+    // SEEDS ARE NOT USED. All random numbers are obtained from
+    // the CORSIKA 8 stream "conex" and "epos"!
+    std::array<int, 3> ioseed{1,1,1};
 
     double xminp = injectionHeight_ / 1_m;
 
diff --git a/corsika/modules/conex/Random.hpp b/corsika/modules/conex/Random.hpp
index a638a3308..9532eace8 100644
--- a/corsika/modules/conex/Random.hpp
+++ b/corsika/modules/conex/Random.hpp
@@ -17,6 +17,19 @@
  * This file is an integral part of the epos interface. It must be
  * linked to the executable linked to epos exactly once
  *
+ * Note, that the fortran random numbe interface functions are all
+ * defined in the epos corsika 8 interface:
+ *
+ * ranfst, ranfgt, rmmaqd, ranfini, ranfcv, rmmard, rangen, drangen
+ *
+ * All of them use the epos_random_interface registered as "epos" stream.
+ *
+ * Thus, the fortran part of CONEX will use the "epos" CORSIKA 8 random stream,
+ * only the CONEX c++ part will use the "conex" random stream.
+ *
+ * Since EPOS and CONEX use the same fortran symbols for access to
+ * random numbers this can only be changed by renaming inside the
+ * fortran part.
  */
 
 namespace conex {
diff --git a/tests/modules/testCONEX.cpp b/tests/modules/testCONEX.cpp
index f86dd7b2d..5a943cd01 100644
--- a/tests/modules/testCONEX.cpp
+++ b/tests/modules/testCONEX.cpp
@@ -101,7 +101,8 @@ TEST_CASE("CONEXSourceCut") {
   [[maybe_unused]] corsika::sibyll::NuclearInteraction sibyllNuc(sibyll, env);
 
   CONEXhybrid conex(center, showerAxis, t, injectionHeight, E0, get_PDG(Code::Proton));
-
+  conex.init();
+  
   HEPEnergyType const Eem{1_PeV};
   auto const momentum = showerAxis.getDirection() * Eem;
 
-- 
GitLab