From 5b1dbeacc5970e28f71727751c1d06e1bf3d67a4 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 | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/Environment/NuclearComposition.h b/Environment/NuclearComposition.h
index 3678b1305..a96abd402 100644
--- a/Environment/NuclearComposition.h
+++ b/Environment/NuclearComposition.h
@@ -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