From 57d6f7df8278c7cccd8e5f6a1043854ddbf1b09e Mon Sep 17 00:00:00 2001
From: "guofangyi@ihep.ac.cn" <guofangyi@ihep.ac.cn>
Date: Mon, 6 May 2024 02:45:05 +0000
Subject: [PATCH] Resolve "MCParticle in simulation"

---
 Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp b/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp
index 0c687f82..12628068 100644
--- a/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp
+++ b/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp
@@ -81,6 +81,14 @@ Edm4hepWriterAnaElemTool::BeginOfEventAction(const G4Event* anEvent) {
         newparticle.setMomentumAtEndpoint(mcGenParticle.getMomentumAtEndpoint());
         newparticle.setSpin           (mcGenParticle.getSpin());
         newparticle.setColorFlow      (mcGenParticle.getColorFlow());
+
+        // Add parent-daughter relation
+        for(auto imc = 0; imc<mcGenParticle.parents_size(); imc++){
+            newparticle.addToParents(mcGenParticle.getParents(imc));
+        }
+        for(auto imc = 0; imc<mcGenParticle.daughters_size(); imc++){
+            newparticle.addToDaughters(mcGenParticle.getDaughters(imc));
+        }
     }
     
     msg() << "mcCol size (original) : " << mcCol->size() << endmsg;
-- 
GitLab