From 40eabfb29bb3b318bc808465858438588847127b Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Fri, 18 Nov 2022 18:14:15 +0100
Subject: [PATCH] Undo fix to propagate Geant4Particle charge. Must be done in
 the output stage.

---
 DDG4/hepmc/HepMC3EventReader.cpp         | 4 +---
 DDG4/plugins/Geant4EventReaderHepEvt.cpp | 7 +------
 DDG4/plugins/Geant4EventReaderHepMC.cpp  | 7 +------
 DDG4/src/Geant4Output2ROOT.cpp           | 8 ++++++--
 DDG4/src/Geant4ParticleHandler.cpp       | 2 +-
 5 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/DDG4/hepmc/HepMC3EventReader.cpp b/DDG4/hepmc/HepMC3EventReader.cpp
index dc6f7c897..79e9d2cd1 100644
--- a/DDG4/hepmc/HepMC3EventReader.cpp
+++ b/DDG4/hepmc/HepMC3EventReader.cpp
@@ -97,9 +97,7 @@ HEPMC3EventReader::readParticles(int event_number, Vertices& vertices, Particles
     const int   pdg     = mcp->pid();
     PropertyMask status(p->status);
     p->pdgID        = pdg;
-    // p->charge       = int(mcp->getCharge()*3.0);
-    G4ParticleDefinition* def = G4ParticleTable::GetParticleTable()->FindParticle(p->pdgID);
-    p->charge = int(3.0 * (def ? def->GetPDGCharge() : -1.0)); // Assume e-/pi-
+    p->charge       = 0; // int(mcp->getCharge()*3.0); // FIXME
     p->psx          = mom.get_component(0) * mom_unit;
     p->psy          = mom.get_component(1) * mom_unit;
     p->psz          = mom.get_component(2) * mom_unit;
diff --git a/DDG4/plugins/Geant4EventReaderHepEvt.cpp b/DDG4/plugins/Geant4EventReaderHepEvt.cpp
index c8a773758..f1fc11701 100644
--- a/DDG4/plugins/Geant4EventReaderHepEvt.cpp
+++ b/DDG4/plugins/Geant4EventReaderHepEvt.cpp
@@ -85,10 +85,6 @@ namespace dd4hep {
 #include <CLHEP/Units/SystemOfUnits.h>
 #include <CLHEP/Units/PhysicalConstants.h>
 
-// Geant4 include files
-#include <G4GlobalConfig.hh>
-#include <G4ParticleTable.hh>
-
 // C/C++ include files
 #include <cerrno>
 
@@ -241,8 +237,7 @@ Geant4EventReaderHepEvt::readParticles(int /* event_number */,
     //
     //  PDGID
     p->pdgID = IDHEP;
-    auto* def = G4ParticleTable::GetParticleTable()->FindParticle(p->pdgID);
-    p->charge = int(3.0 * (def ? def->GetPDGCharge() : 1.0)); // Assume e-/pi-
+    p->charge = 0;
     //
     //  Momentum vector
     p->pex = p->psx = PHEP1*CLHEP::GeV;
diff --git a/DDG4/plugins/Geant4EventReaderHepMC.cpp b/DDG4/plugins/Geant4EventReaderHepMC.cpp
index 737ef7acb..83ee40ac7 100644
--- a/DDG4/plugins/Geant4EventReaderHepMC.cpp
+++ b/DDG4/plugins/Geant4EventReaderHepMC.cpp
@@ -21,10 +21,6 @@
 @}
  */
 
-// Geant4 include files
-#include <G4GlobalConfig.hh>
-#include <G4ParticleTable.hh>
-
 // Framework include files
 #include <DDG4/IoStreams.h>
 #include <DDG4/Geant4InputAction.h>
@@ -447,8 +443,7 @@ int HepMC::read_particle(EventStream &info, istringstream& input, Geant4Particle
     cout << "Particle id: " << p->id << endl;
   }
 #endif
-  G4ParticleDefinition* def = G4ParticleTable::GetParticleTable()->FindParticle(p->pdgID);
-  p->charge = int(3.0 * (def ? def->GetPDGCharge() : -1.0)); // Assume e-/pi-
+  p->charge = 0;
   p->psx *= info.mom_unit;
   p->psy *= info.mom_unit;
   p->psz *= info.mom_unit;
diff --git a/DDG4/src/Geant4Output2ROOT.cpp b/DDG4/src/Geant4Output2ROOT.cpp
index 0eb97bcf5..c43e58593 100644
--- a/DDG4/src/Geant4Output2ROOT.cpp
+++ b/DDG4/src/Geant4Output2ROOT.cpp
@@ -22,7 +22,7 @@
 
 // Geant4 include files
 #include <G4HCofThisEvent.hh>
-#include <G4ParticleDefinition.hh>
+#include <G4ParticleTable.hh>
 
 // ROOT include files
 #include <TFile.h>
@@ -151,11 +151,15 @@ void Geant4Output2ROOT::saveEvent(OutputContext<G4Event>& /* ctxt */) {
       typedef Geant4HitWrapper::HitManipulator Manip;
       typedef Geant4ParticleMap::ParticleMap ParticleMap;
       Manip* manipulator = Geant4HitWrapper::manipulator<Geant4Particle>();
+      G4ParticleTable* table = G4ParticleTable::GetParticleTable();
       const ParticleMap& pm = parts->particles();
       vector<void*> particles;
       particles.reserve(pm.size());
       for ( const auto& i : pm )   {
-        particles.emplace_back((ParticleMap::mapped_type*)i.second);
+	auto* p = i.second;
+	G4ParticleDefinition* def = table->FindParticle(p->pdgID);
+	p->charge = int(3.0 * (def ? def->GetPDGCharge() : -1.0)); // Assume e-/pi-
+        particles.emplace_back((ParticleMap::mapped_type*)p);
       }
       fill("MCParticles",manipulator->vec_type,&particles);
     }
diff --git a/DDG4/src/Geant4ParticleHandler.cpp b/DDG4/src/Geant4ParticleHandler.cpp
index 8295a97d5..574cbb4bc 100644
--- a/DDG4/src/Geant4ParticleHandler.cpp
+++ b/DDG4/src/Geant4ParticleHandler.cpp
@@ -234,7 +234,7 @@ void Geant4ParticleHandler::begin(const G4Track* track)   {
     m_currTrack.daughters    = prim_part->daughters;
     m_currTrack.pdgID        = prim_part->pdgID;
     m_currTrack.mass         = prim_part->mass;
-    m_currTrack.charge       = prim_part->charge;
+    m_currTrack.charge       = int(3.0 * h.charge());
   }
   else  {
     m_currTrack.id           = m_globalParticleID;
-- 
GitLab