From 9c2be65457df26a85d1b7c16b851fe8af3af28c7 Mon Sep 17 00:00:00 2001
From: Maximilian Reininghaus <maximilian.reininghaus@kit.edu>
Date: Fri, 2 Oct 2020 16:39:49 +0200
Subject: [PATCH] add event type flag, set in Cascade

---
 Framework/Cascade/Cascade.h               |  9 +++++--
 Stack/History/CMakeLists.txt              |  1 +
 Stack/History/Event.hpp                   | 30 ++++++++++++++---------
 Stack/History/EventType.hpp               | 13 ++++++++++
 Stack/History/HistoryObservationPlane.hpp | 29 +++++++++++-----------
 5 files changed, 54 insertions(+), 28 deletions(-)
 create mode 100644 Stack/History/EventType.hpp

diff --git a/Framework/Cascade/Cascade.h b/Framework/Cascade/Cascade.h
index 8d2bd1743..986526333 100644
--- a/Framework/Cascade/Cascade.h
+++ b/Framework/Cascade/Cascade.h
@@ -16,6 +16,7 @@
 #include <corsika/random/UniformRealDistribution.h>
 #include <corsika/stack/SecondaryView.h>
 #include <corsika/units/PhysicalUnits.h>
+#include <corsika/history/EventType.hpp>
 
 #include <corsika/logging/Logging.h>
 
@@ -325,8 +326,10 @@ namespace corsika::cascade {
           actual_decay_time);
       const auto sample_process = uniDist(fRNG);
       units::si::InverseTimeType inv_decay_count = units::si::InverseTimeType::zero();
-      return fProcessSequence.SelectDecay(particle, view, sample_process,
+      auto const returnCode = fProcessSequence.SelectDecay(particle, view, sample_process,
                                           inv_decay_count);
+      view.GetProjectile().GetEvent()->set_type(history::EventType::Decay);
+      return returnCode;
     }
 
     auto interaction(Particle& particle, TStackView& view) {
@@ -339,8 +342,10 @@ namespace corsika::cascade {
           current_inv_length);
       const auto sample_process = uniDist(fRNG);
       auto inv_lambda_count = units::si::InverseGrammageType::zero();
-      return fProcessSequence.SelectInteraction(particle, view, sample_process,
+      auto const returnCode = fProcessSequence.SelectInteraction(particle, view, sample_process,
                                                 inv_lambda_count);
+            view.GetProjectile().GetEvent()->set_type(history::EventType::Interaction);
+      return returnCode;
     }
 
     // but this here temporarily. Should go into dedicated file later:
diff --git a/Stack/History/CMakeLists.txt b/Stack/History/CMakeLists.txt
index a1df0e255..6fd9e24a8 100644
--- a/Stack/History/CMakeLists.txt
+++ b/Stack/History/CMakeLists.txt
@@ -1,5 +1,6 @@
 set (
   HISTORY_HEADERS
+  EventType.hpp
   Event.hpp
   HistorySecondaryProducer.hpp
   HistoryObservationPlane.hpp
diff --git a/Stack/History/Event.hpp b/Stack/History/Event.hpp
index eb91de759..c569a577f 100644
--- a/Stack/History/Event.hpp
+++ b/Stack/History/Event.hpp
@@ -8,9 +8,11 @@
 
 #pragma once
 
+#include <corsika/logging/Logging.h>
 #include <corsika/particles/ParticleProperties.h>
 #include <corsika/stack/history/SecondaryParticle.hpp>
 #include <corsika/logging/Logging.h>
+#include <corsika/history/EventType.hpp>
 
 #include <iostream>
 #include <memory>
@@ -21,15 +23,16 @@ namespace corsika::history {
 
   class Event;
   using EventPtr = std::shared_ptr<history::Event>;
-  
+
   class Event {
 
-    size_t projectileIndex_ = 0; //!< index of projectile on stack
+    size_t projectile_index_ = 0; //!< index of projectile on stack
     std::vector<SecondaryParticle> secondaries_;
     EventPtr parent_event_;
 
-    std::optional<corsika::particles::Code>
-        targetCode_; 
+    EventType type_ = EventType::Uninitialized;
+
+    std::optional<corsika::particles::Code> targetCode_;
 
   public:
     Event() = default;
@@ -38,10 +41,10 @@ namespace corsika::history {
 
     bool hasParentEvent() const { return bool(parent_event_); }
     EventPtr& parentEvent() { return parent_event_; }
-    const EventPtr& parentEvent() const { return parent_event_; }
-    
-    void setProjectileIndex(size_t i) { projectileIndex_ = i; }
-    size_t projectileIndex() const { return projectileIndex_; }
+    EventPtr const& parentEvent() const { return parent_event_; }
+
+    void setProjectileIndex(size_t i) { projectile_index_ = i; }
+    size_t projectileIndex() const { return projectile_index_; }
 
     template <typename TStackIterator>
     TStackIterator projectile(TStackIterator begin) {
@@ -49,7 +52,7 @@ namespace corsika::history {
       // MR: This is dangerous. You can pass any iterator though it must
       // be stack.begin() to yield the correct projectile
 
-      return begin + projectileIndex_;
+      return begin + projectile_index_;
     }
 
     size_t addSecondary(units::si::HEPEnergyType energy,
@@ -59,13 +62,18 @@ namespace corsika::history {
       return secondaries_.size() - 1;
     }
 
-    std::vector<SecondaryParticle>& secondaries() { return secondaries_; }
+    std::vector<SecondaryParticle> const& secondaries() const { return secondaries_; }
 
     void setTargetCode(const particles::Code t) { targetCode_ = t; }
 
     std::string as_string() const {
-      return fmt::format("hasParent={}, projIndex={}, Nsec={}", hasParentEvent(), projectileIndex_, secondaries_.size());
+      return fmt::format("hasParent={}, projIndex={}, Nsec={}", hasParentEvent(),
+                         projectile_index_, secondaries_.size());
     }
+
+    EventType eventType() const { return type_; }
+
+    void setEventType(EventType t) { type_ = t; }
   };
 
 } // namespace corsika::history
diff --git a/Stack/History/EventType.hpp b/Stack/History/EventType.hpp
new file mode 100644
index 000000000..4781d5c64
--- /dev/null
+++ b/Stack/History/EventType.hpp
@@ -0,0 +1,13 @@
+/*
+ * (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
+ *
+ * This software is distributed under the terms of the GNU General Public
+ * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
+ * the license.
+ */
+
+#pragma once
+
+namespace corsika::history {
+  enum class EventType { Uninitialized, Interaction, Decay };
+}
diff --git a/Stack/History/HistoryObservationPlane.hpp b/Stack/History/HistoryObservationPlane.hpp
index 019d5e1ee..ef1aa0373 100644
--- a/Stack/History/HistoryObservationPlane.hpp
+++ b/Stack/History/HistoryObservationPlane.hpp
@@ -21,21 +21,20 @@
 namespace corsika::history {
   namespace detail {
     inline auto hist_factory() {
-      /*auto h = boost::histogram::make_histogram(
-          boost::histogram::axis::regular<double, boost::histogram::axis::transform::log>{
-              130, 1e8, 1e21, "muon energy/eV"},
-          boost::histogram::axis::integer<int, boost::histogram::use_default,
-                                          boost::histogram::axis::option::growth_t>{
-              0, 10, "hadronic generation"},
-          boost::histogram::axis::regular<double, boost::histogram::axis::transform::log>{
-              130, 1e8, 1e21, "hadronic energy/eV"},
-          boost::histogram::axis::category<int, boost::histogram::use_default,
-                                           boost::histogram::axis::option::growth_t>{});*/
-
-      auto h = boost::histogram::make_histogram(
-          boost::histogram::axis::integer<int, boost::histogram::use_default,
-                                          boost::histogram::axis::option::growth_t>{
-              0, 10, "hadronic generation"});
+      namespace bh = boost::histogram;
+      namespace bha = bh::axis;
+      auto h = bh::make_histogram(
+          bha::regular<double, bha::transform::log>{130, 1e8, 1e21, "muon energy/eV"},
+          bha::integer<int, bh::use_default, bha::option::growth_t>{
+              0, 10, "hadronic interaction generation"},
+          bha::regular<double, bha::transform::log>{130, 1e8, 1e21, "hadronic energy/eV"},
+          bha::category<int, bh::use_default, bha::option::growth_t>{});
+      /*
+            auto h = bh::make_histogram(
+                bha::integer<int, bh::use_default,
+                                                bha::option::growth_t>{
+                    0, 10, "hadronic generation"});
+      */
       return h;
     }
   } // namespace detail
-- 
GitLab