From 115d355d970a0331d217624cf5b038b7d9763d08 Mon Sep 17 00:00:00 2001 From: lintao <lintao51@gmail.com> Date: Wed, 16 Dec 2020 21:38:08 +0800 Subject: [PATCH] WIP: associate the tracker hit and the primary particle. --- Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp b/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp index 954664bf..b5b2ae7f 100644 --- a/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp +++ b/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp @@ -193,6 +193,17 @@ Edm4hepWriterAnaElemTool::EndOfEventAction(const G4Event* anEvent) { trk_hit->momentum.z()/CLHEP::GeV}; edm_trk_hit.setMomentum(edm4hep::Vector3f(mom)); + // get the truth or contribution + auto& truth = trk_hit->truth; + int trackID = truth.trackID; + + int pritrkid = m_track2primary[trackID]; + if (pritrkid <= 0) { + error() << "Failed to find the primary track for trackID #" << trackID << endmsg; + pritrkid = 1; + } + + edm_trk_hit.setMCParticle(mcCol->at(pritrkid-1)); } dd4hep::sim::Geant4CalorimeterHit* cal_hit = dynamic_cast<dd4hep::sim::Geant4CalorimeterHit*>(h); -- GitLab