From 6519a4a31273d99b1da31721d230dd667c2bc522 Mon Sep 17 00:00:00 2001
From: ralfulrich <ralf.ulrich@kit.edu>
Date: Tue, 12 Oct 2021 09:38:56 +0200
Subject: [PATCH] adapt also examples

---
 examples/cascade_example.cpp |  6 +++---
 examples/corsika.cpp         | 12 +++++++-----
 examples/hybrid_MC.cpp       | 11 +++--------
 examples/mars.cpp            | 10 ++--------
 examples/vertical_EAS.cpp    | 29 ++++++++---------------------
 5 files changed, 23 insertions(+), 45 deletions(-)

diff --git a/examples/cascade_example.cpp b/examples/cascade_example.cpp
index 2b9c38759..f7693fc40 100644
--- a/examples/cascade_example.cpp
+++ b/examples/cascade_example.cpp
@@ -94,10 +94,10 @@ int main() {
   // setup particle stack, and add primary particle
   setup::Stack stack;
   stack.clear();
-  const Code beamCode = Code::Nucleus;
   const int nuclA = 4;
   const int nuclZ = int(nuclA / 2.15 + 0.7);
-  const HEPMassType mass = get_nucleus_mass(nuclA, nuclZ);
+  const Code beamCode = get_nucleus_code(nuclA, nuclZ);
+  const HEPMassType mass = get_nucleus_mass(beamCode);
   const HEPEnergyType E0 = nuclA * 1_TeV;
   double theta = 0.;
   double phi = 0.;
@@ -125,7 +125,7 @@ int main() {
     cout << "input particle: " << beamCode << endl;
     cout << "input angles: theta=" << theta << " phi=" << phi << endl;
     cout << "input momentum: " << plab.getComponents() / 1_GeV << endl;
-    stack.addParticle(std::make_tuple(beamCode, plab, injectionPos, 0_ns, nuclA, nuclZ));
+    stack.addParticle(std::make_tuple(beamCode, plab, injectionPos, 0_ns));
   }
 
   // setup processes, decays and interactions
diff --git a/examples/corsika.cpp b/examples/corsika.cpp
index f7fc083e8..8166b9e11 100644
--- a/examples/corsika.cpp
+++ b/examples/corsika.cpp
@@ -230,18 +230,20 @@ int main(int argc, char** argv) {
 
   // parse the primary ID as a PDG or A/Z code
   Code beamCode;
-  HEPEnergyType mass;
 
   // check if we want to use a PDG code instead
   if (app.count("--pdg") > 0) {
     beamCode = convert_from_PDG(PDGCode(app["--pdg"]->as<int>()));
-    mass = get_mass(beamCode);
   } else {
     // check manually for proton and neutrons
-    if ((A == 0) && (Z == 1)) beamCode = Code::Proton;
-    if ((A == 1) && (Z == 1)) beamCode = Code::Neutron;
-    mass = get_nucleus_mass(A, Z);
+    if ((A == 0) && (Z == 1))
+      beamCode = Code::Proton;
+    else if ((A == 1) && (Z == 1))
+      beamCode = Code::Neutron;
+    else
+      beamCode = get_nucleus_code(A, Z);
   }
+  HEPEnergyType mass = get_mass(beamCode);
 
   // particle energy
   HEPEnergyType const E0 = 1_GeV * app["--energy"]->as<float>();
diff --git a/examples/hybrid_MC.cpp b/examples/hybrid_MC.cpp
index 3619b99bb..da892f8d4 100644
--- a/examples/hybrid_MC.cpp
+++ b/examples/hybrid_MC.cpp
@@ -157,10 +157,10 @@ int main(int argc, char** argv) {
   // setup particle stack, and add primary particle
   setup::Stack stack;
   stack.clear();
-  const Code beamCode = Code::Nucleus;
   unsigned short const A = std::stoi(std::string(argv[1]));
   unsigned short Z = std::stoi(std::string(argv[2]));
-  auto const mass = get_nucleus_mass(A, Z);
+  const Code beamCode = get_nucleus_code(A, Z);
+  auto const mass = get_mass(beamCode);
   const HEPEnergyType E0 = 1_GeV * std::stof(std::string(argv[3]));
   double theta = 0.;
   auto const thetaRad = theta / 180. * M_PI;
@@ -192,12 +192,7 @@ int main(int argc, char** argv) {
 
   std::cout << "point of injection: " << injectionPos.getCoordinates() << std::endl;
 
-  if (A != 1) {
-    stack.addParticle(std::make_tuple(beamCode, plab, injectionPos, 0_ns, A, Z));
-
-  } else {
-    stack.addParticle(std::make_tuple(Code::Proton, plab, injectionPos, 0_ns));
-  }
+  stack.addParticle(std::make_tuple(Code::Proton, plab, injectionPos, 0_ns));
 
   std::cout << "shower axis length: " << (showerCore - injectionPos).getNorm() * 1.02
             << std::endl;
diff --git a/examples/mars.cpp b/examples/mars.cpp
index 2d0d7ce5b..b4c4b381c 100644
--- a/examples/mars.cpp
+++ b/examples/mars.cpp
@@ -259,18 +259,16 @@ int main(int argc, char** argv) {
 
   // parse the primary ID as a PDG or A/Z code
   Code beamCode;
-  HEPEnergyType mass;
 
   // check if we want to use a PDG code instead
   if (app.count("--pdg") > 0) {
     beamCode = convert_from_PDG(PDGCode(app["--pdg"]->as<int>()));
-    mass = get_mass(beamCode);
   } else {
     // check manually for proton and neutrons
     if ((A == 0) && (Z == 1)) beamCode = Code::Proton;
     if ((A == 1) && (Z == 1)) beamCode = Code::Neutron;
-    mass = get_nucleus_mass(A, Z);
   }
+  HEPEnergyType const mass = get_mass(beamCode);
 
   // particle energy
   HEPEnergyType const E0 = 1_GeV * app["--energy"]->as<float>();
@@ -419,11 +417,7 @@ int main(int argc, char** argv) {
     stack.clear();
 
     // add the desired particle to the stack
-    if (A > 1) {
-      stack.addParticle(std::make_tuple(beamCode, plab, injectionPos, 0_ns, A, Z));
-    } else {
-      stack.addParticle(std::make_tuple(beamCode, plab, injectionPos, 0_ns));
-    }
+    stack.addParticle(std::make_tuple(beamCode, plab, injectionPos, 0_ns));
 
     // run the shower
     EAS.run();
diff --git a/examples/vertical_EAS.cpp b/examples/vertical_EAS.cpp
index 4b10e0436..638752840 100644
--- a/examples/vertical_EAS.cpp
+++ b/examples/vertical_EAS.cpp
@@ -144,17 +144,20 @@ int main(int argc, char** argv) {
   // pre-setup particle stack
   unsigned short const A = std::stoi(std::string(argv[1]));
   Code beamCode;
-  HEPEnergyType mass;
   unsigned short Z = 0;
   if (A > 0) {
-    beamCode = Code::Nucleus;
     Z = std::stoi(std::string(argv[2]));
-    mass = get_nucleus_mass(A, Z);
+    if (A == 1 && Z == 0)
+      beamCode = Code::Neutron;
+    else if (A == 1 && Z == 1)
+      beamCode = Code::Proton;
+    else
+      beamCode = get_nucleus_code(A, Z);
   } else {
     int pdg = std::stoi(std::string(argv[2]));
     beamCode = convert_from_PDG(PDGCode(pdg));
-    mass = get_mass(beamCode);
   }
+  HEPEnergyType mass = get_mass(beamCode);
   HEPEnergyType const E0 = 1_GeV * std::stof(std::string(argv[3]));
   double theta = 0.;
   double phi = 180.;
@@ -261,23 +264,7 @@ int main(int argc, char** argv) {
   setup::Stack stack;
   stack.clear();
 
-  if (A > 1) {
-    stack.addParticle(std::make_tuple(beamCode, plab, injectionPos, 0_ns, A, Z));
-
-  } else {
-    if (A == 1) {
-      if (Z == 1) {
-        stack.addParticle(std::make_tuple(Code::Proton, plab, injectionPos, 0_ns));
-      } else if (Z == 0) {
-        stack.addParticle(std::make_tuple(Code::Neutron, plab, injectionPos, 0_ns));
-      } else {
-        std::cerr << "illegal parameters" << std::endl;
-        return EXIT_FAILURE;
-      }
-    } else {
-      stack.addParticle(std::make_tuple(beamCode, plab, injectionPos, 0_ns));
-    }
-  }
+  stack.addParticle(std::make_tuple(beamCode, plab, injectionPos, 0_ns));
 
   BetheBlochPDG emContinuous(showerAxis);
 
-- 
GitLab