From 90031f7622a176e26e3c7a7e28d0fa4060d7b7de Mon Sep 17 00:00:00 2001
From: Thomas Madlener <thomas.madlener@desy.de>
Date: Fri, 10 Feb 2023 11:56:01 +0100
Subject: [PATCH] Add double values to EventParameters and store event weights

---
 DDG4/hepmc/HepMC3FileReader.cpp     | 23 ++++++++++++++++-------
 DDG4/include/DDG4/EventParameters.h |  3 +++
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/DDG4/hepmc/HepMC3FileReader.cpp b/DDG4/hepmc/HepMC3FileReader.cpp
index 927471453..72d644541 100644
--- a/DDG4/hepmc/HepMC3FileReader.cpp
+++ b/DDG4/hepmc/HepMC3FileReader.cpp
@@ -45,19 +45,28 @@ namespace dd4hep  {
           if(attr.second.size() > 1 or inAttr.first != 0){
             strstr << "_" << inAttr.first;
           }
-          auto attr_as_int = std::dynamic_pointer_cast<HepMC3::IntAttribute>(inAttr.second);
-          auto attr_as_flt = std::dynamic_pointer_cast<HepMC3::FloatAttribute>(inAttr.second);
-          if(attr_as_int) {
-            m_intValues[strstr.str()] = {attr_as_int->value()};
-          } else if(attr_as_flt) {
-            m_fltValues[strstr.str()] = {attr_as_flt->value()};
+          if(auto int_attr = std::dynamic_pointer_cast<HepMC3::IntAttribute>(inAttr.second)) {
+            m_intValues[strstr.str()] = {int_attr->value()};
+          } else if(auto flt_attr = std::dynamic_pointer_cast<HepMC3::FloatAttribute>(inAttr.second)) {
+            m_fltValues[strstr.str()] = {flt_attr->value()};
+          } else if(auto dbl_attr = std::dynamic_pointer_cast<HepMC3::DoubleAttribute>(inAttr.second)) {
+            m_dblValues[strstr.str()] = {dbl_attr->value()};
           } else { // anything else
             m_strValues[strstr.str()] = {inAttr.second->unparsed_string()};
           }
         }
       }
-    }
 
+      if (const auto& weights = genEvent.weights(); !weights.empty()) {
+        m_dblValues["EventWeights"] = weights;
+      }
+      // Not using the GenEven::weight_names here because that checks for
+      // emptyness and throws in that case. We don't care if we get an empty
+      // vector at this point
+      if (genEvent.run_info() && !genEvent.run_info()->weight_names().empty()) {
+        m_strValues["EventWeightNames"] = genEvent.weight_names();
+      }
+    }
 
     /// Base class to read hepmc3 event files
     /**
diff --git a/DDG4/include/DDG4/EventParameters.h b/DDG4/include/DDG4/EventParameters.h
index 4dded17cd..ee1d08649 100644
--- a/DDG4/include/DDG4/EventParameters.h
+++ b/DDG4/include/DDG4/EventParameters.h
@@ -35,6 +35,7 @@ namespace dd4hep  {
       std::map<std::string, std::vector<int>>         m_intValues {};
       std::map<std::string, std::vector<float>>       m_fltValues {};
       std::map<std::string, std::vector<std::string>> m_strValues {};
+      std::map<std::string, std::vector<double>>      m_dblValues {};
 
     public:
       /// Initializing constructor
@@ -61,6 +62,8 @@ namespace dd4hep  {
       auto const& fltParameters() const { return m_fltValues; }
       /// Get the string event parameters
       auto const& strParameters() const { return m_strValues; }
+      /// Get the double event parameters
+      auto const& dblParameters() const { return m_dblValues; }
 
     };
 
-- 
GitLab