From d92bc627fd8d5c3fb71e8a4a6ba4b952967ca001 Mon Sep 17 00:00:00 2001
From: Nikos Karastathis <n.karastathis@kit.edu>
Date: Fri, 18 Mar 2022 16:26:06 +0100
Subject: [PATCH] fix stack in all examples

---
 examples/boundary_example.cpp       |  9 +++++----
 examples/cascade_example.cpp        | 18 +++++++++---------
 examples/cascade_proton_example.cpp | 11 ++++++-----
 examples/corsika.cpp                | 12 +++++++-----
 examples/em_shower.cpp              |  5 +++--
 examples/hybrid_MC.cpp              |  9 +++++----
 examples/mars.cpp                   | 20 +++++++++++---------
 examples/stopping_power.cpp         |  2 +-
 examples/vertical_EAS.cpp           | 12 +++++++-----
 9 files changed, 54 insertions(+), 44 deletions(-)

diff --git a/examples/boundary_example.cpp b/examples/boundary_example.cpp
index 36866057b..4ede91209 100644
--- a/examples/boundary_example.cpp
+++ b/examples/boundary_example.cpp
@@ -89,7 +89,8 @@ int main() {
   RNGManager<>::getInstance().registerRandomStream("cascade");
 
   // setup environment, geometry
-  using EnvType = setup::Environment;
+  using EnvironmentInterface = IMediumPropertyModel<IMagneticFieldModel<IMediumModel>>;
+  using EnvType = Environment<EnvironmentInterface>;
   EnvType env;
   auto& universe = *(env.getUniverse());
 
@@ -98,8 +99,8 @@ int main() {
   // create "world" as infinite sphere filled with protons
   auto world = EnvType::createNode<Sphere>(Point{rootCS, 0_m, 0_m, 0_m}, 100_km);
 
-  using MyHomogeneousModel = MediumPropertyModel<
-      UniformMagneticField<HomogeneousMedium<setup::EnvironmentInterface>>>;
+  using MyHomogeneousModel =
+      MediumPropertyModel<UniformMagneticField<HomogeneousMedium<EnvironmentInterface>>>;
 
   auto const props = world->setModelProperties<MyHomogeneousModel>(
       Medium::AirDry1Atm, Vector(rootCS, 0_T, 0_T, 0_T), 1_kg / (1_m * 1_m * 1_m),
@@ -128,7 +129,7 @@ int main() {
   auto sequence = make_sequence(cut, boundaryCrossing, trackWriter);
 
   // setup particle stack, and add primary particles
-  setup::Stack stack;
+  setup::Stack<EnvType> stack;
   stack.clear();
   const Code beamCode = Code::MuPlus;
   const HEPMassType mass = get_mass(beamCode);
diff --git a/examples/cascade_example.cpp b/examples/cascade_example.cpp
index ce61dd9e7..6d09fe152 100644
--- a/examples/cascade_example.cpp
+++ b/examples/cascade_example.cpp
@@ -68,16 +68,17 @@ int main() {
   RNGManager<>::getInstance().registerRandomStream("cascade");
 
   // setup environment, geometry
-  setup::Environment env;
+  using EnvironmentInterface = IMediumPropertyModel<IMagneticFieldModel<IMediumModel>>;
+  using EnvType = Environment<EnvironmentInterface>;
+  EnvType env;
   auto& universe = *(env.getUniverse());
 
   CoordinateSystemPtr const& rootCS = env.getCoordinateSystem();
 
-  auto world =
-      setup::Environment::createNode<Sphere>(Point{rootCS, 0_m, 0_m, 0_m}, 150_km);
+  auto world = EnvType::createNode<Sphere>(Point{rootCS, 0_m, 0_m, 0_m}, 150_km);
 
-  using MyHomogeneousModel = MediumPropertyModel<
-      UniformMagneticField<HomogeneousMedium<setup::EnvironmentInterface>>>;
+  using MyHomogeneousModel =
+      MediumPropertyModel<UniformMagneticField<HomogeneousMedium<EnvironmentInterface>>>;
 
   // fraction of oxygen
   double const fox = 0.20946;
@@ -86,15 +87,14 @@ int main() {
       1_kg / (1_m * 1_m * 1_m),
       NuclearComposition({Code::Nitrogen, Code::Oxygen}, {1. - fox, fox}));
 
-  auto innerMedium =
-      setup::Environment::createNode<Sphere>(Point{rootCS, 0_m, 0_m, 0_m}, 5000_m);
+  auto innerMedium = EnvType::createNode<Sphere>(Point{rootCS, 0_m, 0_m, 0_m}, 5000_m);
 
   innerMedium->setModelProperties(props);
   world->addChild(std::move(innerMedium));
   universe.addChild(std::move(world));
 
   // setup particle stack, and add primary particle
-  setup::Stack stack;
+  setup::Stack<EnvType> stack;
   stack.clear();
   const int nuclA = 4;
   const int nuclZ = int(nuclA / 2.15 + 0.7);
@@ -132,7 +132,7 @@ int main() {
 
   // setup processes, decays and interactions
   setup::Tracking tracking;
-  StackInspector<setup::Stack> stackInspect(100, true, E0);
+  StackInspector<setup::Stack<EnvType>> stackInspect(100, true, E0);
 
   RNGManager<>::getInstance().registerRandomStream("sibyll");
   RNGManager<>::getInstance().registerRandomStream("pythia");
diff --git a/examples/cascade_proton_example.cpp b/examples/cascade_proton_example.cpp
index 5a7845239..bc30603fb 100644
--- a/examples/cascade_proton_example.cpp
+++ b/examples/cascade_proton_example.cpp
@@ -71,15 +71,16 @@ int main() {
   OutputManager output("cascade_proton_outputs");
 
   // setup environment, geometry
-  using EnvType = setup::Environment;
+  using EnvironmentInterface = IMediumPropertyModel<IMagneticFieldModel<IMediumModel>>;
+  using EnvType = Environment<EnvironmentInterface>;
   EnvType env;
   auto& universe = *(env.getUniverse());
   CoordinateSystemPtr const& rootCS = env.getCoordinateSystem();
 
   auto world = EnvType::createNode<Sphere>(Point{rootCS, 0_m, 0_m, 0_m}, 150_km);
 
-  using MyHomogeneousModel = MediumPropertyModel<
-      UniformMagneticField<HomogeneousMedium<setup::EnvironmentInterface>>>;
+  using MyHomogeneousModel =
+      MediumPropertyModel<UniformMagneticField<HomogeneousMedium<EnvironmentInterface>>>;
 
   world->setModelProperties<MyHomogeneousModel>(
       Medium::AirDry1Atm, MagneticFieldVector(rootCS, 0_T, 0_T, 1_mT),
@@ -88,7 +89,7 @@ int main() {
   universe.addChild(std::move(world));
 
   // setup particle stack, and add primary particle
-  setup::Stack stack;
+  setup::Stack<EnvType> stack;
   stack.clear();
   const Code beamCode = Code::Proton;
   const HEPMassType mass = Proton::mass;
@@ -119,7 +120,7 @@ int main() {
 
   // setup processes, decays and interactions
   setup::Tracking tracking;
-  StackInspector<setup::Stack> stackInspect(1000, true, E0);
+  StackInspector<setup::Stack<EnvType>> stackInspect(1000, true, E0);
 
   RNGManager<>::getInstance().registerRandomStream("sibyll");
   RNGManager<>::getInstance().registerRandomStream("pythia");
diff --git a/examples/corsika.cpp b/examples/corsika.cpp
index 94d885b21..5cc04e646 100644
--- a/examples/corsika.cpp
+++ b/examples/corsika.cpp
@@ -81,7 +81,10 @@
 using namespace corsika;
 using namespace std;
 
-using Particle = setup::Stack::particle_type;
+using EnvironmentInterface = IMediumPropertyModel<IMagneticFieldModel<IMediumModel>>;
+using EnvType = Environment<EnvironmentInterface>;
+
+using Particle = setup::Stack<EnvType>::particle_type;
 
 void registerRandomStreams(int seed) {
   RNGManager<>::getInstance().registerRandomStream("cascade");
@@ -196,14 +199,13 @@ int main(int argc, char** argv) {
   registerRandomStreams(app["--seed"]->as<int>());
 
   /* === START: SETUP ENVIRONMENT AND ROOT COORDINATE SYSTEM === */
-  using EnvType = setup::Environment;
   EnvType env;
   CoordinateSystemPtr const& rootCS = env.getCoordinateSystem();
   Point const center{rootCS, 0_m, 0_m, 0_m};
   GeomagneticModel wmm(center, corsika_data("GeoMag/WMM.COF"));
 
   // build a Linsley US Standard atmosphere into `env`
-  create_5layer_atmosphere<setup::EnvironmentInterface, MyExtraEnv>(
+  create_5layer_atmosphere<EnvironmentInterface, MyExtraEnv>(
       env, AtmosphereId::LinsleyUSStd, center, Medium::AirDry1Atm,
       wmm.getField(2022.5, 10_km, 49, 8.4));
 
@@ -331,7 +333,7 @@ int main(int argc, char** argv) {
 
   corsika::urqmd::UrQMD urqmd;
   InteractionCounter urqmdCounted(urqmd);
-  StackInspector<setup::Stack> stackInspect(10000, false, E0);
+  StackInspector<setup::Stack<EnvType>> stackInspect(10000, false, E0);
 
   // assemble all processes into an ordered process list
   struct EnergySwitch {
@@ -360,7 +362,7 @@ int main(int argc, char** argv) {
 
   // create the cascade object using the default stack and tracking implementation
   setup::Tracking tracking;
-  setup::Stack stack;
+  setup::Stack<EnvType> stack;
   Cascade EAS(env, tracking, sequence, output, stack);
 
   // print our primary parameters all in one place
diff --git a/examples/em_shower.cpp b/examples/em_shower.cpp
index fe67c6477..018666a46 100644
--- a/examples/em_shower.cpp
+++ b/examples/em_shower.cpp
@@ -91,13 +91,14 @@ int main(int argc, char** argv) {
   registerRandomStreams(seed);
 
   // setup environment, geometry
-  using EnvType = setup::Environment;
+  using EnvironmentInterface = IMediumPropertyModel<IMagneticFieldModel<IMediumModel>>;
+  using EnvType = Environment<EnvironmentInterface>;
   EnvType env;
   CoordinateSystemPtr const& rootCS = env.getCoordinateSystem();
   Point const center{rootCS, 0_m, 0_m, 0_m};
 
   // build a Linsley US Standard atmosphere into `env`
-  create_5layer_atmosphere<setup::EnvironmentInterface, MyExtraEnv>(
+  create_5layer_atmosphere<EnvironmentInterface, MyExtraEnv>(
       env, AtmosphereId::LinsleyUSStd, center, Medium::AirDry1Atm,
       MagneticFieldVector{rootCS, 0_T, 50_uT, 0_T});
 
diff --git a/examples/hybrid_MC.cpp b/examples/hybrid_MC.cpp
index 4e6950634..0cb65570b 100644
--- a/examples/hybrid_MC.cpp
+++ b/examples/hybrid_MC.cpp
@@ -173,18 +173,19 @@ int main(int argc, char** argv) {
   registerRandomStreams(seed);
 
   // setup environment, geometry
-  using EnvType = setup::Environment;
+  using EnvironmentInterface = IMediumPropertyModel<IMagneticFieldModel<IMediumModel>>;
+  using EnvType = Environment<EnvironmentInterface>;
   EnvType env;
   CoordinateSystemPtr const& rootCS = env.getCoordinateSystem();
   Point const center{rootCS, 0_m, 0_m, 0_m};
 
   // build a Linsley US Standard atmosphere into `env`
-  create_5layer_atmosphere<setup::EnvironmentInterface, MyExtraEnv>(
+  create_5layer_atmosphere<EnvironmentInterface, MyExtraEnv>(
       env, AtmosphereId::LinsleyUSStd, center, Medium::AirDry1Atm,
       MagneticFieldVector{rootCS, 0_T, 50_uT, 0_T});
 
   // setup particle stack, and add primary particle
-  setup::Stack stack;
+  setup::Stack<EnvType> stack;
   stack.clear();
   unsigned short const A = std::stoi(std::string(argv[1]));
   unsigned short const Z = std::stoi(std::string(argv[2]));
@@ -298,7 +299,7 @@ int main(int argc, char** argv) {
     HEPEnergyType cutE_;
     EnergySwitch(HEPEnergyType cutE)
         : cutE_(cutE) {}
-    bool operator()(const setup::Stack::particle_type& p) const {
+    bool operator()(const setup::Stack<EnvType>::particle_type& p) const {
       return (p.getEnergy() < cutE_);
     }
   };
diff --git a/examples/mars.cpp b/examples/mars.cpp
index 84cf46823..bc7cbd4cf 100644
--- a/examples/mars.cpp
+++ b/examples/mars.cpp
@@ -81,7 +81,10 @@
 using namespace corsika;
 using namespace std;
 
-using Particle = setup::Stack::particle_type;
+using EnvironmentInterface = IMediumPropertyModel<IMagneticFieldModel<IMediumModel>>;
+using EnvType = Environment<EnvironmentInterface>;
+
+using Particle = setup::Stack<EnvType>::particle_type;
 
 typedef decltype(1 * pascal) PressureType;
 typedef decltype(1 * degree_celsius) TemperatureType;
@@ -218,17 +221,16 @@ int main(int argc, char** argv) {
   registerRandomStreams(app["--seed"]->as<int>());
 
   /* === START: SETUP ENVIRONMENT AND ROOT COORDINATE SYSTEM === */
-  using EnvType = setup::Environment;
   EnvType env;
   CoordinateSystemPtr const& rootCS = env.getCoordinateSystem();
   Point const center{rootCS, 0_m, 0_m, 0_m};
   LengthType const radiusMars = 3389.5_km;
   auto builder =
-      make_layered_spherical_atmosphere_builder<setup::EnvironmentInterface, MyExtraEnv>::
-          create(center,
-                 radiusMars,                                   // Mars
-                 Medium::AirDry1Atm,                           // Mars, close enough
-                 MagneticFieldVector{rootCS, 0_T, 0_uT, 0_T}); // Mars
+      make_layered_spherical_atmosphere_builder<EnvironmentInterface, MyExtraEnv>::create(
+          center,
+          radiusMars,                                   // Mars
+          Medium::AirDry1Atm,                           // Mars, close enough
+          MagneticFieldVector{rootCS, 0_T, 0_uT, 0_T}); // Mars
 
   builder.setNuclearComposition(                             // Mars
       {{Code::Nitrogen, Code::Oxygen}, {1. / 3., 2. / 3.}}); // simplified
@@ -364,7 +366,7 @@ int main(int argc, char** argv) {
 
   corsika::urqmd::UrQMD urqmd;
   InteractionCounter urqmdCounted{urqmd};
-  StackInspector<setup::Stack> stackInspect(5000, false, E0);
+  StackInspector<setup::Stack<EnvType>> stackInspect(5000, false, E0);
 
   // assemble all processes into an ordered process list
   struct EnergySwitch {
@@ -395,7 +397,7 @@ int main(int argc, char** argv) {
 
   // create the cascade object using the default stack and tracking implementation
   setup::Tracking tracking;
-  setup::Stack stack;
+  setup::Stack<EnvType> stack;
   Cascade EAS(env, tracking, sequence, output, stack);
 
   // print our primary parameters all in one place
diff --git a/examples/stopping_power.cpp b/examples/stopping_power.cpp
index 8d0641960..4aa5a0f5a 100644
--- a/examples/stopping_power.cpp
+++ b/examples/stopping_power.cpp
@@ -50,7 +50,7 @@ int main() {
 
   BetheBlochPDG eLoss;
 
-  setup::Stack stack;
+  setup::Stack<EnvType> stack;
 
   std::ofstream file("dEdX.dat");
   file << "# beta*gamma, dE/dX / MeV/(g/cm²)" << std::endl;
diff --git a/examples/vertical_EAS.cpp b/examples/vertical_EAS.cpp
index 6173c4603..b5e5f1633 100644
--- a/examples/vertical_EAS.cpp
+++ b/examples/vertical_EAS.cpp
@@ -76,7 +76,10 @@
 using namespace corsika;
 using namespace std;
 
-using Particle = setup::Stack::particle_type;
+using EnvironmentInterface = IMediumPropertyModel<IMagneticFieldModel<IMediumModel>>;
+using EnvType = Environment<EnvironmentInterface>;
+
+using Particle = setup::Stack<EnvType>::particle_type;
 
 void registerRandomStreams(int seed) {
   RNGManager<>::getInstance().registerRandomStream("cascade");
@@ -122,14 +125,13 @@ int main(int argc, char** argv) {
   registerRandomStreams(seed);
 
   // setup environment, geometry
-  using EnvType = setup::Environment;
   EnvType env;
   CoordinateSystemPtr const& rootCS = env.getCoordinateSystem();
   Point const center{rootCS, 0_m, 0_m, 0_m};
   GeomagneticModel wmm(center, corsika_data("GeoMag/WMM.COF"));
 
   // build a Linsley US Standard atmosphere into `env`
-  create_5layer_atmosphere<setup::EnvironmentInterface, MyExtraEnv>(
+  create_5layer_atmosphere<EnvironmentInterface, MyExtraEnv>(
       env, AtmosphereId::LinsleyUSStd, center, Medium::AirDry1Atm,
       wmm.getField(2022.5, 10_km, 49, 8.4));
 
@@ -254,7 +256,7 @@ int main(int argc, char** argv) {
 
   corsika::urqmd::UrQMD urqmd;
   InteractionCounter urqmdCounted{urqmd};
-  StackInspector<setup::Stack> stackInspect(50000, false, E0);
+  StackInspector<setup::Stack<EnvType>> stackInspect(50000, false, E0);
 
   // assemble all processes into an ordered process list
   struct EnergySwitch {
@@ -272,7 +274,7 @@ int main(int argc, char** argv) {
   string const cMSHist_file = "inthist_cms_verticalEAS.npz";
 
   // setup particle stack, and add primary particle
-  setup::Stack stack;
+  setup::Stack<EnvType> stack;
   stack.clear();
 
   stack.addParticle(std::make_tuple(
-- 
GitLab