From 352204c993284de49837182e33245d5dca8bc155 Mon Sep 17 00:00:00 2001
From: Maximilian Reininghaus <maximilian.reininghaus@kit.edu>
Date: Fri, 18 Jan 2019 15:42:04 +0100
Subject: [PATCH] GetAvgMassNumber() moved to NuclearComposition

---
 Environment/NuclearComposition.h | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/Environment/NuclearComposition.h b/Environment/NuclearComposition.h
index 3bc1101a4..a96abd402 100644
--- a/Environment/NuclearComposition.h
+++ b/Environment/NuclearComposition.h
@@ -13,9 +13,9 @@
 #define _include_NuclearComposition_h
 
 #include <corsika/particles/ParticleProperties.h>
+#include <cassert>
 #include <numeric>
 #include <stdexcept>
-#include <cassert>
 #include <vector>
 
 namespace corsika::environment {
@@ -24,12 +24,19 @@ namespace corsika::environment {
     std::vector<corsika::particles::Code> const
         fComponents; //!< particle codes of consitutents
 
+    double const fAvgMassNumber;
+
   public:
     NuclearComposition(std::vector<corsika::particles::Code> pComponents,
                        std::vector<float> pFractions)
         : fNumberFractions(pFractions)
-        , fComponents(pComponents) {
-            
+        , fComponents(pComponents)
+        , fAvgMassNumber(std::inner_product(
+              pComponents.cbegin(), pComponents.cend(), pFractions.cbegin(), 0.,
+              [](double x, double y) { return x + y; },
+              [](auto const& compID, auto const& fraction) {
+                return corsika::particles::GetNucleusA(compID) * fraction;
+              })) {
       assert(pComponents.size() == pFractions.size());
       auto const sumFractions =
           std::accumulate(pFractions.cbegin(), pFractions.cend(), 0.f);
@@ -43,6 +50,7 @@ namespace corsika::environment {
 
     auto const& GetFractions() const { return fNumberFractions; }
     auto const& GetComponents() const { return fComponents; }
+    auto const GetAverageMassNumber() const { return fAvgMassNumber; }
   };
 
 } // namespace corsika::environment
-- 
GitLab