From 5c911754731fc2af874ebaabaea75e257a382594 Mon Sep 17 00:00:00 2001
From: Remy Prechelt <prechelt@hawaii.edu>
Date: Fri, 21 May 2021 10:31:17 -1000
Subject: [PATCH] Add z-coordinate to ParticleWriter.

---
 corsika/detail/modules/ObservationPlane.inl      |  4 ++--
 .../modules/writers/ParticleWriterParquet.inl    | 16 ++++++++++++----
 corsika/modules/writers/ParticleWriterOff.hpp    |  4 ++--
 .../modules/writers/ParticleWriterParquet.hpp    |  7 ++++---
 tests/output/testWriterObservationPlane.cpp      |  2 +-
 5 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/corsika/detail/modules/ObservationPlane.inl b/corsika/detail/modules/ObservationPlane.inl
index 2f0bdab98..4a9efbca6 100644
--- a/corsika/detail/modules/ObservationPlane.inl
+++ b/corsika/detail/modules/ObservationPlane.inl
@@ -55,11 +55,11 @@ namespace corsika {
     if (pid == Code::Nucleus) {
       // add our particles to the output file stream
       output_.write(particle.getNuclearA(), particle.getNuclearZ(), energy,
-                    displacement.dot(xAxis_), displacement.dot(yAxis_), weight);
+                    displacement.dot(xAxis_), displacement.dot(yAxis_), 0_m, weight);
     } else {
       // add our particles to the output file stream
       output_.write(particle.getPID(), energy, displacement.dot(xAxis_),
-                    displacement.dot(yAxis_), weight);
+                    displacement.dot(yAxis_), 0_m, weight);
     }
 
     CORSIKA_LOG_TRACE("Particle detected absorbed={}", deleteOnHit_);
diff --git a/corsika/detail/modules/writers/ParticleWriterParquet.inl b/corsika/detail/modules/writers/ParticleWriterParquet.inl
index d89db474f..5fdd9ba51 100644
--- a/corsika/detail/modules/writers/ParticleWriterParquet.inl
+++ b/corsika/detail/modules/writers/ParticleWriterParquet.inl
@@ -15,7 +15,7 @@ namespace corsika {
   inline ParticleWriterParquet::ParticleWriterParquet()
       : output_()
       , showerId_(0)
-      , energyGround_(0_eV) {}
+      , totalEnergy_(0_eV) {}
 
   inline void ParticleWriterParquet::startOfLibrary(
       boost::filesystem::path const& directory) {
@@ -35,6 +35,10 @@ namespace corsika {
                      parquet::ConvertedType::NONE);
     output_.addField("y", parquet::Repetition::REQUIRED, parquet::Type::FLOAT,
                      parquet::ConvertedType::NONE);
+    output_.addField("z", parquet::Repetition::REQUIRED, parquet::Type::FLOAT,
+                     parquet::ConvertedType::NONE);
+    output_.addField("z", parquet::Repetition::REQUIRED, parquet::Type::FLOAT,
+                     parquet::ConvertedType::NONE);
     output_.addField("weight", parquet::Repetition::REQUIRED, parquet::Type::FLOAT,
                      parquet::ConvertedType::NONE);
 
@@ -42,7 +46,7 @@ namespace corsika {
     output_.buildStreamer();
 
     showerId_ = 0;
-    energyGround_ = 0_eV;
+    totalEnergy_ = 0_eV;
     countHadrons_ = 0;
     countOthers_ = 0;
     countEM_ = 0;
@@ -59,15 +63,17 @@ namespace corsika {
 
   inline void ParticleWriterParquet::write(Code const& pid, HEPEnergyType const& energy,
                                            LengthType const& x, LengthType const& y,
+                                           LengthType const& z,
                                            double const weight) {
 
     // write the next row - we must write `shower_` first.
     *(output_.getWriter()) << showerId_ << static_cast<int>(get_PDG(pid))
                            << static_cast<float>(energy / 1_GeV)
                            << static_cast<float>(x / 1_m) << static_cast<float>(y / 1_m)
+                           << static_cast<float>(z / 1_m)
                            << static_cast<float>(weight) << parquet::EndRow;
 
-    energyGround_ += energy;
+    totalEnergy_ += energy;
 
     if (is_hadron(pid)) {
       ++countHadrons_;
@@ -83,13 +89,15 @@ namespace corsika {
   inline void ParticleWriterParquet::write(unsigned int const A, unsigned int const Z,
                                            HEPEnergyType const& energy,
                                            LengthType const& x, LengthType const& y,
+                                           LengthType const& z,
                                            double const weight) {
     // write the next row - we must write `shower_` first.
     *(output_.getWriter()) << showerId_ << static_cast<int>(get_PDG(A, Z))
                            << static_cast<float>(energy / 1_GeV)
                            << static_cast<float>(x / 1_m) << static_cast<float>(y / 1_m)
+                           << static_cast<float>(z / 1_m)
                            << static_cast<float>(weight) << parquet::EndRow;
-    energyGround_ += energy;
+    totalEnergy_ += energy;
 
     ++countHadrons_;
   }
diff --git a/corsika/modules/writers/ParticleWriterOff.hpp b/corsika/modules/writers/ParticleWriterOff.hpp
index 6f036a74b..27a6ab763 100644
--- a/corsika/modules/writers/ParticleWriterOff.hpp
+++ b/corsika/modules/writers/ParticleWriterOff.hpp
@@ -27,12 +27,12 @@ namespace corsika {
     void endOfLibrary() final override {}
 
     // for pdg particles
-    void write(Code const&, HEPEnergyType const&, LengthType const&, LengthType const&,
+    void write(Code const&, HEPEnergyType const&, LengthType const&, LengthType const&, LengthType const&,
                double const) {}
 
     // for nuclei
     void write(unsigned int const, unsigned int const, HEPEnergyType const&,
-               LengthType const&, LengthType const&, double const) {}
+               LengthType const&, LengthType const&, LengthType const&, double const) {}
 
   }; // class ParticleWriterOff
 
diff --git a/corsika/modules/writers/ParticleWriterParquet.hpp b/corsika/modules/writers/ParticleWriterParquet.hpp
index dd5bd1c94..05b49cce8 100644
--- a/corsika/modules/writers/ParticleWriterParquet.hpp
+++ b/corsika/modules/writers/ParticleWriterParquet.hpp
@@ -51,6 +51,7 @@ namespace corsika {
      */
     void write(Code const& pid, units::si::HEPEnergyType const& energy,
                units::si::LengthType const& x, units::si::LengthType const& y,
+               units::si::LengthType const& z,
                const double weight);
 
     /**
@@ -58,7 +59,7 @@ namespace corsika {
      */
     void write(unsigned int const A, unsigned int const Z,
                units::si::HEPEnergyType const& energy, units::si::LengthType const& x,
-               units::si::LengthType const& y, const double weight);
+               units::si::LengthType const& y, units::si::LengthType const& z, const double weight);
 
     /**
      * Return collected library-level summary for output.
@@ -68,7 +69,7 @@ namespace corsika {
     /**
      * If plane is absorbing particles: return the total energy absorbed.
      */
-    HEPEnergyType getEnergyGround() const { return energyGround_; }
+    HEPEnergyType getTotalEnergy() const { return totalEnergy_; }
 
   private:
     ParquetStreamer output_; ///< The primary output file.
@@ -79,7 +80,7 @@ namespace corsika {
     double countEM_ = 0;      ///< count EM particles hitting plane.
     double countOthers_ = 0;  ///< count othe types of particles hitting plane
 
-    HEPEnergyType energyGround_; ///< energy absorbed in ground.
+    HEPEnergyType totalEnergy_; ///< energy absorbed in ground.
 
   }; // class ParticleWriterParquet
 
diff --git a/tests/output/testWriterObservationPlane.cpp b/tests/output/testWriterObservationPlane.cpp
index 71fefabaa..8ac8787a8 100644
--- a/tests/output/testWriterObservationPlane.cpp
+++ b/tests/output/testWriterObservationPlane.cpp
@@ -21,7 +21,7 @@ struct TestWriterPlane : public ParticleWriterParquet {
 
   YAML::Node getConfig() const { return YAML::Node(); }
 
-  void checkWrite() { ParticleWriterParquet::write(Code::Unknown, 1_eV, 2_m, 3_m, 1.0); }
+  void checkWrite() { ParticleWriterParquet::write(Code::Unknown, 1_eV, 2_m, 3_m, 0_m, 1.0); }
 };
 
 TEST_CASE("ObservationPlaneWriterParquet") {
-- 
GitLab