From b0710f7d4e38f0df160e43c20a00b62d1fd6f6fd Mon Sep 17 00:00:00 2001
From: John Chapman <John.Chapman@cern.ch>
Date: Wed, 15 May 2024 15:40:06 +0200
Subject: [PATCH] Use new ISFTruthIncident methods in clients

---
 .../src/FastCaloSimV2Tool.cxx                 |  4 +++
 .../src/HadIntProcessorParametric.cxx         |  4 +++
 .../src/McMaterialEffectsUpdator.cxx          | 25 +++++++++++++++++++
 .../src/PhotonConversionTool.cxx              |  8 ++++++
 .../src/G4ParticleDecayHelper.cxx             | 13 ++++++----
 5 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimV2Tool.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimV2Tool.cxx
index ebe953d79fa7..f4f5746ff823 100644
--- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimV2Tool.cxx
+++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimV2Tool.cxx
@@ -226,6 +226,10 @@ StatusCode ISF::FastCaloSimV2Tool::simulate(ISF::ISFParticle& isfp, ISFParticleC
                                      ISF::fKillsPrimary);
 
         m_truthRecordSvc->registerTruthIncident( truth, true );
+        // At this point we need to update the properties of the
+        // ISFParticles produced in the interaction
+        truth.updateParentAfterIncidentProperties();
+        truth.updateChildParticleProperties();
 
         for (auto *secondary : *someSecondaries) {
           if (secondary->getTruthBinding()) {
diff --git a/Simulation/ISF/ISF_Fatras/ISF_FatrasTools/src/HadIntProcessorParametric.cxx b/Simulation/ISF/ISF_Fatras/ISF_FatrasTools/src/HadIntProcessorParametric.cxx
index 1f93510737a2..f36edd9da0f6 100644
--- a/Simulation/ISF/ISF_Fatras/ISF_FatrasTools/src/HadIntProcessorParametric.cxx
+++ b/Simulation/ISF/ISF_Fatras/ISF_FatrasTools/src/HadIntProcessorParametric.cxx
@@ -645,6 +645,10 @@ ISF::ISFParticleVector iFatras::HadIntProcessorParametric::getHadState(const ISF
 			       parent->nextGeoID(),
 			       ISF::fKillsPrimary );
   m_truthRecordSvc->registerTruthIncident( truth);
+  // At this point we need to update the properties of the
+  // ISFParticles produced in the interaction
+  truth.updateParentAfterIncidentProperties();
+  truth.updateChildParticleProperties();
 
   // save info for validation
   if (m_validationMode && m_validationTool) {
diff --git a/Simulation/ISF/ISF_Fatras/ISF_FatrasTools/src/McMaterialEffectsUpdator.cxx b/Simulation/ISF/ISF_Fatras/ISF_FatrasTools/src/McMaterialEffectsUpdator.cxx
index 25ff6551ef67..977edf45c694 100644
--- a/Simulation/ISF/ISF_Fatras/ISF_FatrasTools/src/McMaterialEffectsUpdator.cxx
+++ b/Simulation/ISF/ISF_Fatras/ISF_FatrasTools/src/McMaterialEffectsUpdator.cxx
@@ -1316,6 +1316,11 @@ void iFatras::McMaterialEffectsUpdator::recordBremPhoton(double time,
                                  parent->nextGeoID(),
                                  ISF::fPrimarySurvives );
     m_truthRecordSvc->registerTruthIncident( truth);
+    // At this point we need to update the properties of the
+    // ISFParticles produced in the interaction
+    truth.updateParentAfterIncidentProperties();
+    truth.updateChildParticleProperties();
+
     //Making sure we get some correct truth info from parent if needed before pushing into the particle broker
     if (!bremPhoton->getTruthBinding()) {
 	bremPhoton->setTruthBinding(new ISF::TruthBinding(*parent->getTruthBinding()));
@@ -1449,6 +1454,10 @@ void iFatras::McMaterialEffectsUpdator::recordBremPhotonLay(const ISF::ISFPartic
                                  parent->nextGeoID(),
                                  ISF::fPrimarySurvives );
     m_truthRecordSvc->registerTruthIncident( truth);
+    // At this point we need to update the properties of the
+    // ISFParticles produced in the interaction
+    truth.updateParentAfterIncidentProperties();
+    truth.updateChildParticleProperties();
 
     //Making sure we get some correct truth info from parent if needed before pushing into the particle broker
     if (!bremPhoton->getTruthBinding()) {
@@ -1576,6 +1585,10 @@ iFatras::McMaterialEffectsUpdator::interact(double time,
                                  parent->nextGeoID(),  // inherits from the parent
                                  ISF::fKillsPrimary );
     m_truthRecordSvc->registerTruthIncident( truth);
+    // At this point we need to update the properties of the
+    // ISFParticles produced in the interaction
+    truth.updateParentAfterIncidentProperties();
+    truth.updateChildParticleProperties();
 
     // save info for validation
     if (m_validationMode && m_validationTool) {
@@ -1644,6 +1657,10 @@ iFatras::McMaterialEffectsUpdator::interact(double time,
                                  parent->nextGeoID(),  // inherits from the parent
                                  ISF::fPrimarySurvives );
     m_truthRecordSvc->registerTruthIncident( truth);
+    // At this point we need to update the properties of the
+    // ISFParticles produced in the interaction
+    truth.updateParentAfterIncidentProperties();
+    truth.updateChildParticleProperties();
 
     // push child particles onto stack
     m_particleBroker->push( children[0], parent);
@@ -1765,6 +1782,10 @@ ISF::ISFParticleVector  iFatras::McMaterialEffectsUpdator::interactLay(const ISF
                                  parent->nextGeoID(),  // inherits from the parent
                                  ISF::fPrimarySurvives );
     m_truthRecordSvc->registerTruthIncident( truth);
+    // At this point we need to update the properties of the
+    // ISFParticles produced in the interaction
+    truth.updateParentAfterIncidentProperties();
+    truth.updateChildParticleProperties();
 
     // save info for validation
     if (m_validationMode && m_validationTool) {
@@ -1845,6 +1866,10 @@ ISF::ISFParticleVector  iFatras::McMaterialEffectsUpdator::interactLay(const ISF
                                  parent->nextGeoID(),  // inherits from the parent
                                  ISF::fKillsPrimary );
     m_truthRecordSvc->registerTruthIncident( truth);
+    // At this point we need to update the properties of the
+    // ISFParticles produced in the interaction
+    truth.updateParentAfterIncidentProperties();
+    truth.updateChildParticleProperties();
 
     // save info for validation
     if (m_validationMode && m_validationTool) {
diff --git a/Simulation/ISF/ISF_Fatras/ISF_FatrasTools/src/PhotonConversionTool.cxx b/Simulation/ISF/ISF_Fatras/ISF_FatrasTools/src/PhotonConversionTool.cxx
index 528ad9ca6215..8ef54b10de9c 100755
--- a/Simulation/ISF/ISF_Fatras/ISF_FatrasTools/src/PhotonConversionTool.cxx
+++ b/Simulation/ISF/ISF_Fatras/ISF_FatrasTools/src/PhotonConversionTool.cxx
@@ -307,6 +307,10 @@ void iFatras::PhotonConversionTool::recordChilds(double time,
                                  parent->nextGeoID(),
                                  ISF::fKillsPrimary );
     m_truthRecordSvc->registerTruthIncident( truth);
+    // At this point we need to update the properties of the
+    // ISFParticles produced in the interaction
+    truth.updateParentAfterIncidentProperties();
+    truth.updateChildParticleProperties();
 
     // save info for validation
     if (m_validationMode && m_validationTool) {
@@ -388,6 +392,10 @@ ISF::ISFParticleVector iFatras::PhotonConversionTool::getChilds(const ISF::ISFPa
                                  parent->nextGeoID(),
                                  ISF::fKillsPrimary );
     m_truthRecordSvc->registerTruthIncident( truth);
+    // At this point we need to update the properties of the
+    // ISFParticles produced in the interaction
+    truth.updateParentAfterIncidentProperties();
+    truth.updateChildParticleProperties();
 
     //Make sure the conversion products get a chance to have correct truth info before pushing into the particle broker
     // FIXME Check this doesn't cause problems later in the TruthSvc
diff --git a/Simulation/ISF/ISF_Fatras/ISF_FatrasToolsG4/src/G4ParticleDecayHelper.cxx b/Simulation/ISF/ISF_Fatras/ISF_FatrasToolsG4/src/G4ParticleDecayHelper.cxx
index ca606257cab8..9ac2371e96f0 100644
--- a/Simulation/ISF/ISF_Fatras/ISF_FatrasToolsG4/src/G4ParticleDecayHelper.cxx
+++ b/Simulation/ISF/ISF_Fatras/ISF_FatrasToolsG4/src/G4ParticleDecayHelper.cxx
@@ -248,12 +248,15 @@ void iFatras::G4ParticleDecayHelper::handleDecayParticles(const ISF::ISFParticle
 
       // register TruthIncident
       ISF::ISFTruthIncident truth( const_cast<ISF::ISFParticle&>(particle),
-				   decayProducts,
-				   process,
-				   particle.nextGeoID(),  // inherits from the parent
-				   ISF::fKillsPrimary );
+                                   decayProducts,
+                                   process,
+                                   particle.nextGeoID(),  // inherits from the parent
+                                   ISF::fKillsPrimary );
       m_truthRecordSvc->registerTruthIncident( truth);
-      
+      // At this point we need to update the properties of the
+      // ISFParticles produced in the interaction
+      truth.updateParentAfterIncidentProperties();
+      truth.updateChildParticleProperties();
       // save info for validation
       if (m_validationMode && m_validationTool) {
 	Amg::Vector3D* nMom = 0;
-- 
GitLab