From 02e98ce7226b2be481ea64b76837f53e95c5de18 Mon Sep 17 00:00:00 2001
From: Maximilian Reininghaus <maximilian.reininghaus@kit.edu>
Date: Tue, 9 Apr 2019 13:18:32 -0300
Subject: [PATCH] use WeightedSum in Sibyll GetInteractionLength

---
 Processes/Sibyll/Interaction.cc | 30 ++++++++----------------------
 1 file changed, 8 insertions(+), 22 deletions(-)

diff --git a/Processes/Sibyll/Interaction.cc b/Processes/Sibyll/Interaction.cc
index ed550a012..1fa35e59e 100644
--- a/Processes/Sibyll/Interaction.cc
+++ b/Processes/Sibyll/Interaction.cc
@@ -162,35 +162,21 @@ namespace corsika::process::sibyll {
         ideally as full particle object so that the four momenta
         and the boosts can be defined..
       */
-      auto const* currentNode = vP.GetNode();
-      const auto mediumComposition =
+
+      auto const* currentNode = p.GetNode();
+      const auto& mediumComposition =
           currentNode->GetModelProperties().GetNuclearComposition();
-      // determine average interaction length
-      // weighted sum
-      int i = -1;
-      si::CrossSectionType weightedProdCrossSection = 0_mb;
-      // get weights of components from environment/medium
-      const auto& w = mediumComposition.GetFractions();
-      // loop over components in medium
-      for (auto const targetId : mediumComposition.GetComponents()) {
-        i++;
-        cout << "Interaction: get interaction length for target: " << targetId << endl;
-
-        auto const [productionCrossSection, elaCrossSection] =
-            GetCrossSection(corsikaBeamId, targetId, ECoM);
-        [[maybe_unused]] const auto& dummy_elaCX = elaCrossSection;
 
-        cout << "Interaction: "
-             << " IntLength: sibyll return (mb): " << productionCrossSection / 1_mb
-             << endl;
-        weightedProdCrossSection += w[i] * productionCrossSection;
-      }
+      si::CrossSectionType weightedProdCrossSection = mediumComposition.WeightedSum(
+          [=](particles::Code targetID) -> si::CrossSectionType {
+            return std::get<0>(this->GetCrossSection(corsikaBeamId, targetID, ECoM));
+          });
+
       cout << "Interaction: "
            << "IntLength: weighted CrossSection (mb): " << weightedProdCrossSection / 1_mb
            << endl;
 
       // calculate interaction length in medium
-      //#warning check interaction length units
       GrammageType const int_length = mediumComposition.GetAverageMassNumber() *
                                       units::constants::u / weightedProdCrossSection;
       cout << "Interaction: "
-- 
GitLab