From ed16c4a74d6bb5adf2b96f794de27b9f2530dba6 Mon Sep 17 00:00:00 2001
From: ralfulrich <ralf.ulrich@kit.edu>
Date: Tue, 2 Apr 2019 11:32:42 +0200
Subject: [PATCH] style, remove Stack from ProcessInterface

---
 Processes/CMakeLists.txt                      |  2 +-
 Processes/EnergyLoss/EnergyLoss.cc            | 16 ++++-----
 Processes/EnergyLoss/EnergyLoss.h             |  3 +-
 .../HadronicElasticModel.cc                   |  2 +-
 .../HadronicElasticModel.h                    |  4 +--
 Processes/Sibyll/Decay.cc                     | 35 +++++++++----------
 Processes/Sibyll/Decay.h                      |  6 ++--
 Processes/Sibyll/Interaction.cc               |  6 ++--
 Processes/Sibyll/Interaction.h                |  4 +--
 Processes/Sibyll/NuclearInteraction.cc        | 10 +++---
 Processes/Sibyll/NuclearInteraction.h         |  4 +--
 Processes/Sibyll/testSibyll.cc                | 15 ++++----
 Processes/StackInspector/StackInspector.cc    |  4 +--
 Processes/StackInspector/StackInspector.h     |  2 +-
 Processes/TrackWriter/TrackWriter.cc          | 10 +++---
 Processes/TrackWriter/TrackWriter.h           |  4 +--
 16 files changed, 63 insertions(+), 64 deletions(-)

diff --git a/Processes/CMakeLists.txt b/Processes/CMakeLists.txt
index d6162179c..cddec6bd4 100644
--- a/Processes/CMakeLists.txt
+++ b/Processes/CMakeLists.txt
@@ -4,7 +4,7 @@ add_subdirectory (Sibyll)
 if (PYTHIA8_FOUND)
   add_subdirectory (Pythia)
 endif (PYTHIA8_FOUND)
-add_subdirectory (StackInspector)
+# add_subdirectory (StackInspector)
 add_subdirectory (TrackWriter)
 add_subdirectory (TrackingLine)
 add_subdirectory (HadronicElasticModel)
diff --git a/Processes/EnergyLoss/EnergyLoss.cc b/Processes/EnergyLoss/EnergyLoss.cc
index 3cdd84e31..094eec177 100644
--- a/Processes/EnergyLoss/EnergyLoss.cc
+++ b/Processes/EnergyLoss/EnergyLoss.cc
@@ -148,7 +148,7 @@ namespace corsika::process::EnergyLoss {
            (0.5 * log(aux) - beta2 - Cadj / Z - delta / 2 + barkas + bloch) * dX;
   }
 
-  process::EProcessReturn EnergyLoss::DoContinuous(Particle& p, Track& t, Stack&) {
+  process::EProcessReturn EnergyLoss::DoContinuous(Particle& p, Track& t) {
     if (p.GetChargeNumber() == 0) return process::EProcessReturn::eOk;
     GrammageType const dX =
         p.GetNode()->GetModelProperties().IntegratedGrammage(t, t.GetLength());
@@ -178,16 +178,16 @@ namespace corsika::process::EnergyLoss {
     return units::si::meter * std::numeric_limits<double>::infinity();
   }
 
-  void EnergyLoss::MomentumUpdate(corsika::setup::Stack::ParticleType& p,
+  void EnergyLoss::MomentumUpdate(corsika::setup::Stack::ParticleType& vP,
                                   corsika::units::si::HEPEnergyType Enew) {
-    HEPMomentumType Pnew = elab2plab(Enew, p.GetMass());
-    auto pnew = p.GetMomentum();
-    p.SetMomentum(pnew * Pnew / pnew.GetNorm());
+    HEPMomentumType Pnew = elab2plab(Enew, vP.GetMass());
+    auto pnew = vP.GetMomentum();
+    vP.SetMomentum(pnew * Pnew / pnew.GetNorm());
   }
 
 #include <corsika/geometry/CoordinateSystem.h>
 
-  int EnergyLoss::GetXbin(corsika::setup::Stack::ParticleType& p,
+  int EnergyLoss::GetXbin(corsika::setup::Stack::ParticleType& vP,
                           const HEPEnergyType dE) {
 
     using namespace corsika::geometry;
@@ -195,12 +195,12 @@ namespace corsika::process::EnergyLoss {
     CoordinateSystem const& rootCS =
         RootCoordinateSystem::GetInstance().GetRootCoordinateSystem();
     Point pos1(rootCS, 0_m, 0_m, 0_m);
-    Point pos2(rootCS, 0_m, 0_m, p.GetPosition().GetCoordinates()[2]);
+    Point pos2(rootCS, 0_m, 0_m, vP.GetPosition().GetCoordinates()[2]);
     Vector delta = (pos2 - pos1) / 1_s;
     Trajectory t(Line(pos1, delta), 1_s);
 
     GrammageType const grammage =
-        p.GetNode()->GetModelProperties().IntegratedGrammage(t, t.GetLength());
+        vP.GetNode()->GetModelProperties().IntegratedGrammage(t, t.GetLength());
 
     const int bin = grammage / fdX;
 
diff --git a/Processes/EnergyLoss/EnergyLoss.h b/Processes/EnergyLoss/EnergyLoss.h
index 5eb2a6b67..323ef8573 100644
--- a/Processes/EnergyLoss/EnergyLoss.h
+++ b/Processes/EnergyLoss/EnergyLoss.h
@@ -35,8 +35,7 @@ namespace corsika::process::EnergyLoss {
     void Init() {}
 
     corsika::process::EProcessReturn DoContinuous(corsika::setup::Stack::ParticleType&,
-                                                  corsika::setup::Trajectory&,
-                                                  corsika::setup::Stack&);
+                                                  corsika::setup::Trajectory&);
     corsika::units::si::LengthType MaxStepLength(corsika::setup::Stack::ParticleType&,
                                                  corsika::setup::Trajectory&);
 
diff --git a/Processes/HadronicElasticModel/HadronicElasticModel.cc b/Processes/HadronicElasticModel/HadronicElasticModel.cc
index 289968645..33f162e41 100644
--- a/Processes/HadronicElasticModel/HadronicElasticModel.cc
+++ b/Processes/HadronicElasticModel/HadronicElasticModel.cc
@@ -79,7 +79,7 @@ namespace corsika::process::HadronicElasticModel {
   }
 
   template <>
-  process::EProcessReturn HadronicElasticInteraction::DoInteraction(Particle& p, Stack&) {
+  process::EProcessReturn HadronicElasticInteraction::DoInteraction(Particle& p) {
     if (p.GetPID() != particles::Code::Proton) { return process::EProcessReturn::eOk; }
 
     using namespace units::si;
diff --git a/Processes/HadronicElasticModel/HadronicElasticModel.h b/Processes/HadronicElasticModel/HadronicElasticModel.h
index fae8c9724..4180c04c5 100644
--- a/Processes/HadronicElasticModel/HadronicElasticModel.h
+++ b/Processes/HadronicElasticModel/HadronicElasticModel.h
@@ -59,8 +59,8 @@ namespace corsika::process::HadronicElasticModel {
     template <typename Particle, typename Track>
     corsika::units::si::GrammageType GetInteractionLength(Particle const& p, Track&);
 
-    template <typename Particle, typename Stack>
-    corsika::process::EProcessReturn DoInteraction(Particle& p, Stack&);
+    template <typename Particle>
+    corsika::process::EProcessReturn DoInteraction(Particle&);
   };
 
 } // namespace corsika::process::HadronicElasticModel
diff --git a/Processes/Sibyll/Decay.cc b/Processes/Sibyll/Decay.cc
index 3cd009c58..7a865e92f 100644
--- a/Processes/Sibyll/Decay.cc
+++ b/Processes/Sibyll/Decay.cc
@@ -24,7 +24,8 @@ using std::vector;
 
 using namespace corsika;
 using namespace corsika::setup;
-using Particle = Stack::StackIterator; // ParticleType;
+using Projectile = corsika::setup::StackView::ParticleType;
+using Particle = corsika::setup::Stack::ParticleType;
 using Track = Trajectory;
 
 namespace corsika::process::sibyll {
@@ -103,27 +104,27 @@ namespace corsika::process::sibyll {
   }
 
   template <>
-  units::si::TimeType Decay::GetLifetime(Particle const& p) {
+  units::si::TimeType Decay::GetLifetime(Particle const& vP) {
     using namespace units::si;
 
-    HEPEnergyType E = p.GetEnergy();
-    HEPMassType m = p.GetMass();
+    HEPEnergyType E = vP.GetEnergy();
+    HEPMassType m = vP.GetMass();
 
     const double gamma = E / m;
 
-    const TimeType t0 = particles::GetLifetime(p.GetPID());
+    const TimeType t0 = particles::GetLifetime(vP.GetPID());
     auto const lifetime = gamma * t0;
 
     const auto mkin =
-        (E * E - p.GetMomentum().squaredNorm()); // delta_mass(p.GetMomentum(), E, m);
-    cout << "Decay: code: " << p.GetPID() << endl;
+        (E * E - vP.GetMomentum().squaredNorm()); // delta_mass(vP.GetMomentum(), E, m);
+    cout << "Decay: code: " << vP.GetPID() << endl;
     cout << "Decay: MinStep: t0: " << t0 << endl;
     cout << "Decay: MinStep: energy: " << E / 1_GeV << " GeV" << endl;
-    cout << "Decay: momentum: " << p.GetMomentum().GetComponents() / 1_GeV << " GeV"
+    cout << "Decay: momentum: " << vP.GetMomentum().GetComponents() / 1_GeV << " GeV"
          << endl;
     cout << "Decay: momentum: shell mass-kin. inv. mass " << mkin / 1_GeV / 1_GeV << " "
          << m / 1_GeV * m / 1_GeV << endl;
-    auto sib_id = process::sibyll::ConvertToSibyllRaw(p.GetPID());
+    auto sib_id = process::sibyll::ConvertToSibyllRaw(vP.GetPID());
     cout << "Decay: sib mass: " << get_sibyll_mass2(sib_id) << endl;
     cout << "Decay: MinStep: gamma: " << gamma << endl;
     cout << "Decay: MinStep: tau: " << lifetime << endl;
@@ -132,23 +133,23 @@ namespace corsika::process::sibyll {
   }
 
   template <>
-  void Decay::DoDecay(Particle& p, Stack&) {
+  void Decay::DoDecay(Projectile& vP) {
     using geometry::Point;
     using namespace units::si;
 
     fCount++;
     SibStack ss;
     ss.Clear();
-    const particles::Code pCode = p.GetPID();
+    const particles::Code pCode = vP.GetPID();
     // copy particle to sibyll stack
-    ss.AddParticle(process::sibyll::ConvertToSibyllRaw(pCode), p.GetEnergy(),
-                   p.GetMomentum(),
+    ss.AddParticle(process::sibyll::ConvertToSibyllRaw(pCode), vP.GetEnergy(),
+                   vP.GetMomentum(),
                    // setting particle mass with Corsika values, may be inconsistent
                    // with sibyll internal values
                    particles::GetMass(pCode));
     // remember position
-    Point const decayPoint = p.GetPosition();
-    TimeType const t0 = p.GetTime();
+    Point const decayPoint = vP.GetPosition();
+    TimeType const t0 = vP.GetTime();
     // set all particles/hadrons unstable
     // setHadronsUnstable();
     SetUnstable(pCode);
@@ -166,7 +167,7 @@ namespace corsika::process::sibyll {
       // FOR NOW: skip particles that have decayed in Sibyll, move to iterator?
       if (psib.HasDecayed()) continue;
       // add to corsika stack
-      p.AddSecondary(
+      vP.AddSecondary(
           tuple<particles::Code, units::si::HEPEnergyType, corsika::stack::MomentumVector,
                 geometry::Point, units::si::TimeType>{
               process::sibyll::ConvertFromSibyll(psib.GetPID()), psib.GetEnergy(),
@@ -174,8 +175,6 @@ namespace corsika::process::sibyll {
     }
     // empty sibyll stack
     ss.Clear();
-    // remove original particle from corsika stack
-    p.Delete();
   }
 
 } // namespace corsika::process::sibyll
diff --git a/Processes/Sibyll/Decay.h b/Processes/Sibyll/Decay.h
index 7e7a202e7..5dc06bd0c 100644
--- a/Processes/Sibyll/Decay.h
+++ b/Processes/Sibyll/Decay.h
@@ -37,10 +37,10 @@ namespace corsika::process {
       void SetHadronsUnstable();
 
       template <typename Particle>
-      corsika::units::si::TimeType GetLifetime(Particle const& p);
+      corsika::units::si::TimeType GetLifetime(Particle const&);
 
-      template <typename Particle, typename Stack>
-      void DoDecay(Particle& p, Stack&);
+      template <typename Projectile>
+      void DoDecay(Projectile&);
     };
   } // namespace sibyll
 } // namespace corsika::process
diff --git a/Processes/Sibyll/Interaction.cc b/Processes/Sibyll/Interaction.cc
index 645667f81..83348508b 100644
--- a/Processes/Sibyll/Interaction.cc
+++ b/Processes/Sibyll/Interaction.cc
@@ -29,7 +29,8 @@ using std::tuple;
 
 using namespace corsika;
 using namespace corsika::setup;
-using Particle = Stack::StackIterator; // ParticleType;
+using Particle = Stack::StackIterator;       // ParticleType;
+using Projectile = StackView::StackIterator; // ParticleType;
 using Track = Trajectory;
 
 namespace corsika::process::sibyll {
@@ -207,7 +208,7 @@ namespace corsika::process::sibyll {
    */
 
   template <>
-  process::EProcessReturn Interaction::DoInteraction(Particle& p, Stack&) {
+  process::EProcessReturn Interaction::DoInteraction(Projectile& p) {
 
     using namespace units;
     using namespace utl;
@@ -331,7 +332,6 @@ namespace corsika::process::sibyll {
              << " DoInteraction: should have dropped particle.. "
              << "THIS IS AN ERROR" << endl;
         throw std::runtime_error("energy too low for SIBYLL");
-        // p.Delete(); delete later... different process
       } else {
         fCount++;
         // Sibyll does not know about units..
diff --git a/Processes/Sibyll/Interaction.h b/Processes/Sibyll/Interaction.h
index 33fe9001a..4d70a0afb 100644
--- a/Processes/Sibyll/Interaction.h
+++ b/Processes/Sibyll/Interaction.h
@@ -61,8 +61,8 @@ namespace corsika::process::sibyll {
        event is copied (and boosted) into the shower lab frame.
      */
 
-    template <typename Particle, typename Stack>
-    corsika::process::EProcessReturn DoInteraction(Particle&, Stack&);
+    template <typename Particle>
+    corsika::process::EProcessReturn DoInteraction(Particle&);
 
   private:
     corsika::random::RNG& fRNG =
diff --git a/Processes/Sibyll/NuclearInteraction.cc b/Processes/Sibyll/NuclearInteraction.cc
index f12dba923..da85b0f3d 100644
--- a/Processes/Sibyll/NuclearInteraction.cc
+++ b/Processes/Sibyll/NuclearInteraction.cc
@@ -31,7 +31,8 @@ using std::vector;
 
 using namespace corsika;
 using namespace corsika::setup;
-using Particle = Stack::StackIterator; // ParticleType;
+using Particle = Stack::ParticleType;        // StackIterator; // ParticleType;
+using Projectile = StackView::StackIterator; // StackView::ParticleType;
 using Track = Trajectory;
 
 namespace corsika::process::sibyll {
@@ -307,7 +308,7 @@ namespace corsika::process::sibyll {
   }
 
   template <>
-  process::EProcessReturn NuclearInteraction::DoInteraction(Particle& p, Stack& s) {
+  process::EProcessReturn NuclearInteraction::DoInteraction(Projectile& p) {
 
     // this routine superimposes different nucleon-nucleon interactions
     // in a nucleus-nucleus interaction, based the SIBYLL routine SIBNUC
@@ -594,12 +595,9 @@ namespace corsika::process::sibyll {
               PprojNucLab.GetSpaceLikeComponents(), pOrig, tOrig});
       // create inelastic interaction
       cout << "calling HadronicInteraction..." << endl;
-      fHadronicInteraction.DoInteraction(inelasticNucleon, s);
+      fHadronicInteraction.DoInteraction(inelasticNucleon);
     }
 
-    // delete parent particle
-    p.Delete();
-
     cout << "NuclearInteraction: DoInteraction: done" << endl;
 
     return process::EProcessReturn::eOk;
diff --git a/Processes/Sibyll/NuclearInteraction.h b/Processes/Sibyll/NuclearInteraction.h
index 1a6449d2c..520265fbb 100644
--- a/Processes/Sibyll/NuclearInteraction.h
+++ b/Processes/Sibyll/NuclearInteraction.h
@@ -55,8 +55,8 @@ namespace corsika::process::sibyll {
     template <typename Particle, typename Track>
     corsika::units::si::GrammageType GetInteractionLength(Particle& p, Track&);
 
-    template <typename Particle, typename Stack>
-    corsika::process::EProcessReturn DoInteraction(Particle& p, Stack& s);
+    template <typename Projectle>
+    corsika::process::EProcessReturn DoInteraction(Projectle& p);
 
   private:
     corsika::process::sibyll::Interaction& fHadronicInteraction;
diff --git a/Processes/Sibyll/testSibyll.cc b/Processes/Sibyll/testSibyll.cc
index 7a02fa288..ce096994b 100644
--- a/Processes/Sibyll/testSibyll.cc
+++ b/Processes/Sibyll/testSibyll.cc
@@ -119,12 +119,13 @@ TEST_CASE("SibyllInterface", "[processes]") {
                    corsika::stack::MomentumVector, geometry::Point, units::si::TimeType>{
             particles::Code::Proton, E0, plab, pos, 0_ns});
     particle.SetNode(nodePtr);
+    stack::SecondaryView view(particle);
+    auto projectile = view.GetProjectile();
 
     Interaction model;
 
     model.Init();
-    [[maybe_unused]] const process::EProcessReturn ret =
-        model.DoInteraction(particle, stack);
+    [[maybe_unused]] const process::EProcessReturn ret = model.DoInteraction(projectile);
     [[maybe_unused]] const GrammageType length =
         model.GetInteractionLength(particle, track);
   }
@@ -144,13 +145,14 @@ TEST_CASE("SibyllInterface", "[processes]") {
                                      units::si::TimeType, unsigned short, unsigned short>{
             particles::Code::Nucleus, E0, plab, pos, 0_ns, 4, 2});
     particle.SetNode(nodePtr);
+    stack::SecondaryView view(particle);
+    auto projectile = view.GetProjectile();
 
     Interaction hmodel;
     NuclearInteraction model(hmodel);
 
     model.Init();
-    [[maybe_unused]] const process::EProcessReturn ret =
-        model.DoInteraction(particle, stack);
+    [[maybe_unused]] const process::EProcessReturn ret = model.DoInteraction(projectile);
     [[maybe_unused]] const GrammageType length =
         model.GetInteractionLength(particle, track);
   }
@@ -167,6 +169,8 @@ TEST_CASE("SibyllInterface", "[processes]") {
         std::tuple<particles::Code, units::si::HEPEnergyType,
                    corsika::stack::MomentumVector, geometry::Point, units::si::TimeType>{
             particles::Code::Proton, E0, plab, pos, 0_ns});
+    stack::SecondaryView view(particle);
+    auto projectile = view.GetProjectile();
 
     const std::vector<particles::Code> particleList = {
         particles::Code::PiPlus, particles::Code::PiMinus, particles::Code::KPlus,
@@ -175,8 +179,7 @@ TEST_CASE("SibyllInterface", "[processes]") {
     Decay model(particleList);
 
     model.Init();
-    /*[[maybe_unused]] const process::EProcessReturn ret =*/model.DoDecay(particle,
-                                                                          stack);
+    /*[[maybe_unused]] const process::EProcessReturn ret =*/model.DoDecay(projectile);
     [[maybe_unused]] const TimeType time = model.GetLifetime(particle);
   }
 }
diff --git a/Processes/StackInspector/StackInspector.cc b/Processes/StackInspector/StackInspector.cc
index a22742165..eb0c9e11f 100644
--- a/Processes/StackInspector/StackInspector.cc
+++ b/Processes/StackInspector/StackInspector.cc
@@ -37,8 +37,8 @@ template <typename Stack>
 StackInspector<Stack>::~StackInspector() {}
 
 template <typename Stack>
-process::EProcessReturn StackInspector<Stack>::DoContinuous(Particle&, setup::Trajectory&,
-                                                            Stack& s) {
+process::EProcessReturn StackInspector<Stack>::DoContinuous(Particle&,
+                                                            setup::Trajectory&) {
 
   if (!fReport) return process::EProcessReturn::eOk;
   [[maybe_unused]] int i = 0;
diff --git a/Processes/StackInspector/StackInspector.h b/Processes/StackInspector/StackInspector.h
index 9488767d7..c4262c175 100644
--- a/Processes/StackInspector/StackInspector.h
+++ b/Processes/StackInspector/StackInspector.h
@@ -31,7 +31,7 @@ namespace corsika::process {
       ~StackInspector();
 
       void Init();
-      EProcessReturn DoContinuous(Particle&, corsika::setup::Trajectory&, Stack& s);
+      EProcessReturn DoContinuous(Particle&, corsika::setup::Trajectory&);
       corsika::units::si::LengthType MaxStepLength(Particle&,
                                                    corsika::setup::Trajectory&);
 
diff --git a/Processes/TrackWriter/TrackWriter.cc b/Processes/TrackWriter/TrackWriter.cc
index b58a40fbb..5ea8588d9 100644
--- a/Processes/TrackWriter/TrackWriter.cc
+++ b/Processes/TrackWriter/TrackWriter.cc
@@ -33,13 +33,13 @@ namespace corsika::process::TrackWriter {
   }
 
   template <>
-  process::EProcessReturn TrackWriter::DoContinuous(Particle& p, Track& t, Stack&) {
+  process::EProcessReturn TrackWriter::DoContinuous(Particle& vP, Track& vT) {
     using namespace units::si;
-    auto const start = t.GetPosition(0).GetCoordinates();
-    auto const delta = t.GetPosition(1).GetCoordinates() - start;
-    auto const& name = particles::GetName(p.GetPID());
+    auto const start = vT.GetPosition(0).GetCoordinates();
+    auto const delta = vT.GetPosition(1).GetCoordinates() - start;
+    auto const& name = particles::GetName(vP.GetPID());
 
-    fFile << name << "    " << p.GetEnergy() / 1_eV << ' ' << start[0] / 1_m << ' '
+    fFile << name << "    " << vP.GetEnergy() / 1_eV << ' ' << start[0] / 1_m << ' '
           << start[1] / 1_m << ' ' << start[2] / 1_m << "   " << delta[0] / 1_m << ' '
           << delta[1] / 1_m << ' ' << delta[2] / 1_m << '\n';
 
diff --git a/Processes/TrackWriter/TrackWriter.h b/Processes/TrackWriter/TrackWriter.h
index fa2430569..51fd5a157 100644
--- a/Processes/TrackWriter/TrackWriter.h
+++ b/Processes/TrackWriter/TrackWriter.h
@@ -28,8 +28,8 @@ namespace corsika::process::TrackWriter {
 
     void Init();
 
-    template <typename Particle, typename Track, typename Stack>
-    corsika::process::EProcessReturn DoContinuous(Particle& p, Track& t, Stack&);
+    template <typename Particle, typename Track>
+    corsika::process::EProcessReturn DoContinuous(Particle&, Track&);
 
     template <typename Particle, typename Track>
     corsika::units::si::LengthType MaxStepLength(Particle&, Track&);
-- 
GitLab