From b7c4506be9e02c58fca03f8997d4b2881a4eb224 Mon Sep 17 00:00:00 2001
From: Markus Frank <markus.frank@cern.ch>
Date: Tue, 11 Nov 2014 18:15:22 +0000
Subject: [PATCH] Fix compile warnings. Implement new G4 sensitive detector for
 trackers accumulating hits.

---
 DDCore/src/ConditionsInterna.cpp            |  15 +-
 DDCore/src/Printout.cpp                     |   6 +-
 DDCore/src/ToStream.cpp                     |   2 +-
 DDCore/src/XML/DocumentHandler.cpp          |   3 +-
 DDCore/src/plugins/Geant4XML.cpp            |   6 +-
 DDG4/examples/CLICSidSimu.py                |   2 +-
 DDG4/include/DDG4/Geant4SensDetAction.h     |  10 +-
 DDG4/include/DDG4/Geant4SensDetAction.inl   |  10 ++
 DDG4/include/DDG4/Geant4SensitiveDetector.h |   8 +-
 DDG4/include/DDG4/Geant4TrackInformation.h  |   6 +-
 DDG4/include/DDG4/Geant4UIMessenger.h       |   2 +-
 DDG4/include/DDG4/IoStreams.h               |   3 +-
 DDG4/plugins/Geant4SDActions.cpp            | 156 +++++++++++++-------
 DDG4/python/DDG4.py                         |  12 +-
 DDG4/src/Geant4Converter.cpp                |   2 +
 DDG4/src/Geant4Exec.cpp                     |  21 ++-
 DDG4/src/Geant4InputAction.cpp              |   2 +-
 DDG4/src/Geant4SensDetAction.cpp            |   4 +-
 18 files changed, 185 insertions(+), 85 deletions(-)

diff --git a/DDCore/src/ConditionsInterna.cpp b/DDCore/src/ConditionsInterna.cpp
index 89df3fb71..77e44c992 100644
--- a/DDCore/src/ConditionsInterna.cpp
+++ b/DDCore/src/ConditionsInterna.cpp
@@ -50,7 +50,7 @@ std::string IOV::str()  {
 }
 
 /// Standard initializing constructor
-BlockData::BlockData() : Block(), destruct(0), type(0)   {
+BlockData::BlockData() : Block(), destruct(0), copy(0), type(0)   {
 }
 
 /// Standard Destructor
@@ -65,9 +65,18 @@ BlockData::~BlockData()   {
 
 /// Move the data content: 'from' will be reset to NULL
 void BlockData::move(BlockData& from)   {
-  ::memcpy(this,&from,sizeof(BlockData));
-  ::memset(&from,0,sizeof(BlockData));
+  pointer = from.pointer;
+  grammar = from.grammar;
+  ::memcpy(data,from.data,sizeof(data));
+  destruct = from.destruct;
+  copy = from.copy;
+  type = from.type;
+  ::memset(from.data,0,sizeof(data));
   from.type = PLAIN_DATA;
+  from.destruct = 0;
+  from.copy = 0;
+  from.pointer = 0;
+  from.grammar = 0;
 }
 
 /// Set data value
diff --git a/DDCore/src/Printout.cpp b/DDCore/src/Printout.cpp
index 7716cf0de..dbd3bbb87 100644
--- a/DDCore/src/Printout.cpp
+++ b/DDCore/src/Printout.cpp
@@ -67,7 +67,7 @@ int DD4hep::printout(PrintLevel severity, const std::string& src, const char* fm
 int DD4hep::printout(PrintLevel severity, const char* src, const std::string& fmt, ...) {
   if (severity >= print_lvl) {
     va_list args;
-    va_start(args, fmt);
+    va_start(args, &fmt);
     printout(severity, src, fmt.c_str(), args);
     va_end(args);
   }
@@ -83,7 +83,7 @@ int DD4hep::printout(PrintLevel severity, const char* src, const std::string& fm
 int DD4hep::printout(PrintLevel severity, const std::string& src, const std::string& fmt, ...) {
   if (severity >= print_lvl) {
     va_list args;
-    va_start(args, fmt);
+    va_start(args, &fmt);
     printout(severity, src.c_str(), fmt.c_str(), args);
     va_end(args);
   }
@@ -144,7 +144,7 @@ int DD4hep::printout(PrintLevel severity, const std::string& src, const std::str
  */
 std::string DD4hep::format(const std::string& src, const std::string& fmt, ...) {
   va_list args;
-  va_start(args, fmt);
+  va_start(args, &fmt);
   std::string str = format(src, fmt, args);
   va_end(args);
   return str;
diff --git a/DDCore/src/ToStream.cpp b/DDCore/src/ToStream.cpp
index d6c31b30a..99dbdfd3f 100644
--- a/DDCore/src/ToStream.cpp
+++ b/DDCore/src/ToStream.cpp
@@ -24,7 +24,7 @@ namespace {
 using namespace std;
 //==============================================================================
 namespace DD4hep {  namespace Parsers {
-    template <typename T> T evaluate_string(const string& value)   {
+    template <typename T> T evaluate_string(const string& /* value */)   {
       throw "Bad undefined call";
     }
 
diff --git a/DDCore/src/XML/DocumentHandler.cpp b/DDCore/src/XML/DocumentHandler.cpp
index 8247b56ff..28af8311e 100644
--- a/DDCore/src/XML/DocumentHandler.cpp
+++ b/DDCore/src/XML/DocumentHandler.cpp
@@ -53,7 +53,7 @@ namespace DD4hep {
         parser->setDoSchema(true);
         return parser;
       }
-
+#if 0  // warning: unused function 'parse_document' [-Wunused-function]
       /// Helper function to parse a DOM document using an instance of the XercesC pareser
       Document parse_document(const void* bytes, size_t length, xercesc::ErrorHandler* err_handler) {
         auto_ptr<XercesDOMParser> parser(make_parser(err_handler));
@@ -65,6 +65,7 @@ namespace DD4hep {
         doc->setStrictErrorChecking(true);
         return (XmlDocument*) doc;
       }
+#endif
     }
 
     /// XML-DOM ERror handler class for the XercesC document parser.
diff --git a/DDCore/src/plugins/Geant4XML.cpp b/DDCore/src/plugins/Geant4XML.cpp
index 65346156f..bb6083f75 100644
--- a/DDCore/src/plugins/Geant4XML.cpp
+++ b/DDCore/src/plugins/Geant4XML.cpp
@@ -12,9 +12,9 @@
 namespace DD4hep {
   struct Geant4;
   namespace Geometry {
-    struct GdmlFile;
-    struct Property;
-    struct SensitiveDetector;
+    class GdmlFile;
+    class Property;
+    class SensitiveDetector;
   }
 }
 using namespace DD4hep;
diff --git a/DDG4/examples/CLICSidSimu.py b/DDG4/examples/CLICSidSimu.py
index 8244bec6b..4557ddea3 100644
--- a/DDG4/examples/CLICSidSimu.py
+++ b/DDG4/examples/CLICSidSimu.py
@@ -22,7 +22,7 @@ def run():
   kernel.loadXML("file:"+example_dir+"/DDG4_field.xml")
   DDG4.importConstants(lcdd)
 
-  simple = DDG4.Simple(kernel)
+  simple = DDG4.Simple(kernel,tracker='Geant4TrackerCombineAction')
   simple.printDetectors()
   # Configure UI
   simple.setupCshUI()
diff --git a/DDG4/include/DDG4/Geant4SensDetAction.h b/DDG4/include/DDG4/Geant4SensDetAction.h
index c440b5dee..829896e53 100644
--- a/DDG4/include/DDG4/Geant4SensDetAction.h
+++ b/DDG4/include/DDG4/Geant4SensDetAction.h
@@ -443,9 +443,13 @@ namespace DD4hep {
      *  \ingroup DD4HEP_SIMULATION
      */
     template <typename T> class Geant4SensitiveAction : public Geant4Sensitive  {
+    public:
+      typedef T UserData;
     protected:
       /// Collection identifier
-      size_t m_collectionID;
+      size_t   m_collectionID;
+      /// User data block
+      UserData m_userData;
     public:
       /// Standard , initializing constructor
       Geant4SensitiveAction(Geant4Context* context, 
@@ -454,6 +458,10 @@ namespace DD4hep {
 			    Geometry::LCDD& lcdd);
       /// Default destructor
       virtual ~Geant4SensitiveAction();
+      /// Initialization overload for specialization
+      void initialize();
+      /// Finalization overload for specialization
+      void finalize();
       /// Define collections created by this sensitivie action object
       virtual void defineCollections() {}
       /// G4VSensitiveDetector interface: Method invoked at the begining of each event. 
diff --git a/DDG4/include/DDG4/Geant4SensDetAction.inl b/DDG4/include/DDG4/Geant4SensDetAction.inl
index cd63b2f0b..e56a8aeeb 100644
--- a/DDG4/include/DDG4/Geant4SensDetAction.inl
+++ b/DDG4/include/DDG4/Geant4SensDetAction.inl
@@ -24,15 +24,25 @@ namespace DD4hep {
 						    Geometry::LCDD& lcdd)
       : Geant4Sensitive(context,name,det,lcdd), m_collectionID(0)
     {
+      initialize();
       defineCollections();
       InstanceCount::increment(this);
     }
 
     /// Default destructor
     template <typename T> Geant4SensitiveAction<T>::~Geant4SensitiveAction()  {
+      finalize();
       InstanceCount::decrement(this);
     }
 
+    /// Initialization overload for specialization
+    template <typename T> void Geant4SensitiveAction<T>::initialize()    {
+    }
+
+    /// Finalization overload for specialization
+    template <typename T> void Geant4SensitiveAction<T>::finalize()    {
+    }
+
     /// G4VSensitiveDetector interface: Method invoked at the begining of each event. 
     template <typename T> void Geant4SensitiveAction<T>::begin(G4HCofThisEvent* hce)  {
       Geant4Sensitive::begin(hce);
diff --git a/DDG4/include/DDG4/Geant4SensitiveDetector.h b/DDG4/include/DDG4/Geant4SensitiveDetector.h
index ec32ace3e..dc475ae91 100644
--- a/DDG4/include/DDG4/Geant4SensitiveDetector.h
+++ b/DDG4/include/DDG4/Geant4SensitiveDetector.h
@@ -39,14 +39,14 @@ namespace DD4hep {
      * @author  M.Frank
      * @version 1.0
      */
-    struct Geant4SensitiveDetector : public G4VSensitiveDetector  {
-      public:      
+    class Geant4SensitiveDetector : public G4VSensitiveDetector  {
+    public:      
       typedef Geometry::SensitiveDetector  SensitiveDetector;
       typedef G4THitsCollection<Geant4Hit> HitCollection;
       typedef Geant4Hit::Contribution      HitContribution;
       typedef Geant4StepHandler            StepHandler;
 
-      protected:
+    protected:
 
       /// Reference to the detector description object
       LCDD&             m_lcdd;
@@ -66,7 +66,7 @@ namespace DD4hep {
       /// Dump Step information (careful: very verbose)
       void dumpStep(G4Step* step,G4TouchableHistory* history);
 
-      public:
+    public:
 
       /// Constructor. The sensitive detector element is identified by the detector name
       Geant4SensitiveDetector(const std::string& name, LCDD& lcdd);
diff --git a/DDG4/include/DDG4/Geant4TrackInformation.h b/DDG4/include/DDG4/Geant4TrackInformation.h
index 215ef66dc..c3324b146 100644
--- a/DDG4/include/DDG4/Geant4TrackInformation.h
+++ b/DDG4/include/DDG4/Geant4TrackInformation.h
@@ -24,11 +24,15 @@ namespace DD4hep {
      * @author  M.Frank
      * @version 1.0
      */
-    struct Geant4TrackInformation : public G4VUserTrackInformation {
+    class Geant4TrackInformation : public G4VUserTrackInformation {
+    public:
       enum {
         STORE = 1 << 0, LAST = 1 << 31
       };
+    protected:
       int m_flags;
+
+    public:
       /// Default constructor
       Geant4TrackInformation();
       /// Standard destructor
diff --git a/DDG4/include/DDG4/Geant4UIMessenger.h b/DDG4/include/DDG4/Geant4UIMessenger.h
index 8f9b234f9..cdb67d57e 100644
--- a/DDG4/include/DDG4/Geant4UIMessenger.h
+++ b/DDG4/include/DDG4/Geant4UIMessenger.h
@@ -56,7 +56,7 @@ namespace DD4hep {
       template <typename Q, typename R, typename T>
       void addCall(const std::string& name, const std::string& description, Q* p, R (T::*f)()) {
         CallbackSequence::checkTypes(typeid(Q), typeid(T), dynamic_cast<T*>(p));
-        addCall(Callback(p).make(f));
+        addCall(name, description, Callback(p).make(f));
       }
       /// Export all properties to the Geant4 UI
       void exportProperties(PropertyManager& mgr);
diff --git a/DDG4/include/DDG4/IoStreams.h b/DDG4/include/DDG4/IoStreams.h
index 7d3e243e3..c5bd612d3 100644
--- a/DDG4/include/DDG4/IoStreams.h
+++ b/DDG4/include/DDG4/IoStreams.h
@@ -102,7 +102,8 @@ namespace DD4hep {
    *  \ingroup DD4HEP
    *  \see http://www.boost.org/libs/iostreams for further documentation.
    */
-  template <typename T=int> struct dd4hep_file_source : private dd4hep_file<T> {
+  template <typename T=int> class dd4hep_file_source : private dd4hep_file<T> {
+  public:
     typedef dd4hep_file<T> descriptor;
     struct category : boost::iostreams::input_seekable, 
 		      boost::iostreams::device_tag,
diff --git a/DDG4/plugins/Geant4SDActions.cpp b/DDG4/plugins/Geant4SDActions.cpp
index 8322f81d4..e58e0aa66 100644
--- a/DDG4/plugins/Geant4SDActions.cpp
+++ b/DDG4/plugins/Geant4SDActions.cpp
@@ -15,6 +15,7 @@ using namespace std;
 
 #include "DDG4/Geant4TouchableHandler.h"
 #include "DDG4/Geant4StepHandler.h"
+#include "DDG4/Geant4EventAction.h"
 #include "DDG4/Geant4VolumeManager.h"
 #include "DDG4/Geant4Mapping.h"
 #include "G4OpticalPhoton.hh"
@@ -171,102 +172,152 @@ namespace DD4hep {
     }
     typedef Geant4SensitiveAction<Geant4OpticalCalorimeter>  Geant4OpticalCalorimeterAction;
 
-#if 0
     /// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     ///               Geant4SensitiveAction<TrackerCombine>
     /// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     struct TrackerCombine {
-      Geant4TrackerHit  pre;
-      Geant4TrackerHit  post;
+      typedef Geant4Tracker::Hit Hit;
+      typedef Geant4HitCollection HitCollection;
+      Hit  pre;
+      Hit  post;
+      Geant4Sensitive*  sensitive;
       G4Track*          track;
       double            e_cut;
       int               current;
-      TrackerCombine() : pre(), post(), track(0), e_cut(0.0), current(-1)  {
+      int               combined;
+      
+      TrackerCombine() : pre(), post(), sensitive(0), track(0), e_cut(0.0), current(-1), combined(0)  {
       }
+
       void start(G4Step* step, G4StepPoint* point)   {
 	pre.storePoint(step,point);
 	current = pre.truth.trackID;
 	track = step->GetTrack();
+	sensitive->mark(track);
 	post = pre;
+	combined = 0;
       }
+
       void update(G4Step* step) {
 	post.storePoint(step,step->GetPostStepPoint());
 	pre.truth.deposit += post.truth.deposit;
+	++combined;
       }
-      void clear()   {
-	pre.truth.clear();
+
+      void clear()  {
+	post.clear();
+	pre.clear();
 	current = -1;
+	combined = 0;
 	track = 0;
       }
-      Geant4TrackerHit* extractHit(Geant4SensitiveDetector::HitCollection* c)   {
+
+      bool mustSaveTrack(const G4Track* tr)  const   {
+	return track && current != tr->GetTrackID();
+      }
+
+      Hit* extractHit(HitCollection* collection)   {
 	if ( current == -1 || !track ) {
 	  return 0;
 	}
-	else if ( pre.truth.deposit <= e_cut && !Geant4Hit::isGeantino(track) ) {
-	  clear();
-	  return 0;
-	}
 	Position pos = 0.5 * (pre.position + post.position);
 	Momentum mom = 0.5 * (pre.momentum + post.momentum);
 	double path_len = (post.position - pre.position).R();
-	Geant4TrackerHit* hit = new Geant4TrackerHit(pre.truth.trackID,
-						     pre.truth.pdgID,
-						     pre.truth.deposit,
-						     pre.truth.time);
+	Hit* hit = new Hit(pre.truth.trackID,
+			   pre.truth.pdgID,
+			   pre.truth.deposit,
+			   pre.truth.time);
 	hit->position = pos;
 	hit->momentum = mom;
 	hit->length = path_len;
+	collection->add(hit);
+	sensitive->printM2("+++ TrackID:%6d [%s] CREATE hit combination with %2d deposit(s):"
+			   " %e MeV  Pos:%8.2f %8.2f %8.2f",
+			   pre.truth.trackID,sensitive->c_name(),combined,pre.truth.deposit/MeV,
+			   pos.X()/mm,pos.Y()/mm,pos.Z()/mm);
 	clear();
-	c->insert(hit);
-	mark(h.track);
 	return hit;
       }
-    };
 
-    /// Method invoked at the begining of each event. 
-    template <> void Geant4SensitiveAction<TrackerCombine>::Initialize(G4HCofThisEvent* HCE) {
-      userData.e_cut = m_sensitive.energyCutoff();
-      this->Geant4SensitiveDetector::Initialize(HCE);
-    }
 
-    /// Method for generating hit(s) using the information of G4Step object.
-    template <> void Geant4SensitiveAction<TrackerCombine>::clear() {
-      userData.clear();
-      this->Geant4SensitiveDetector::clear();
-    }
+      /// Method for generating hit(s) using the information of G4Step object.
+      G4bool process(G4Step* step, G4TouchableHistory* ) {
+	Geant4StepHandler h(step);
+	void *prePV = h.volume(h.pre), *postPV = h.volume(h.post);
 
-    /// Method for generating hit(s) using the information of G4Step object.
-    template <> G4bool Geant4SensitiveAction<TrackerCombine>::ProcessHits(G4Step* step,G4TouchableHistory* ) {
-      StepHandler h(step);
-      bool return_code = false;
+	Geant4HitCollection* coll = sensitive->collection(0);
+	/// If we are handling a new track, then store the content of the previous one.
+	if ( mustSaveTrack(h.track) )  {
+	  extractHit(coll);
+	}
+	/// There must be something in.
+	if ( h.deposit()/keV <= 0 )  {
+	  return false;
+	}
+	/// We can now start collecting the deposits of the next hit.
+	if ( 0 == track )  {
+	  start(step, h.pre);
+	}
 
-      if ( !userData.track || userData.current != h.track->GetTrackID() ) {
-	return_code = userData.extractHit(collection(0)) != 0;
-	userData.start(step, h.pre);
-      }
+	// ....update .....
+        update(step);
 
-      // ....update .....
-      userData.update(step);
-
-      void *prePV = h.volume(h.pre), *postPV = h.volume(h.post);
-      if ( prePV != postPV ) {
-	void* postSD = h.sd(h.post);
-	return_code = userData.extractHit(collection(0)) != 0;
-	if ( 0 != postSD )   {
-	  void* preSD = h.sd(h.pre);
-	  if ( preSD == postSD ) {
-	    userData.start(step,h.post);
+	if ( prePV != postPV ) {
+	  void* postSD = h.sd(h.post);
+	  extractHit(coll);
+	  if ( 0 != postSD )   {
+	    void* preSD = h.sd(h.pre);
+	    if ( preSD == postSD ) {
+	      start(step,h.post);
+	    }
 	  }
 	}
+	else if ( track->GetTrackStatus() == fStopAndKill ) {
+	  extractHit(coll);
+	}
+	return true;
       }
-      else if ( userData.track->GetTrackStatus() == fStopAndKill ) {
-	return_code = userData.extractHit(collection(0)) != 0;
+
+      /// Post-event action callback
+      void endEvent(const G4Event* /* event */)   {
+	// We need to add the possibly last added hit to the collection here.
+	// otherwise the last hit would be assigned to the next event and the 
+	// MC truth would be screwed.
+	//
+	// Alternatively the 'update' method would become rather CPU consuming,
+	// beacuse the extract action would have to be recalculated over and over.
+	if ( track )   {
+	  Geant4HitCollection* coll = sensitive->collection(0);
+	  extractHit(coll);
+	}
       }
-      return return_code;
+
+    };
+
+    /// Initialization overload for specialization
+    template <> void Geant4SensitiveAction<TrackerCombine>::initialize() {
+      eventAction().callAtEnd(&m_userData,&TrackerCombine::endEvent);
+      m_userData.e_cut = m_sensitive.energyCutoff();
+      m_userData.sensitive = this;
+    }
+
+    /// Define collections created by this sensitivie action object
+    template <> void Geant4SensitiveAction<TrackerCombine>::defineCollections() {
+      m_collectionID = defineCollection<Geant4Tracker::Hit>(m_sensitive.readout().name());
+    }
+
+    /// Method for generating hit(s) using the information of G4Step object.
+    template <> void Geant4SensitiveAction<TrackerCombine>::clear(G4HCofThisEvent*) {
+      m_userData.clear();
+    }
+
+    /// Method for generating hit(s) using the information of G4Step object.
+    template <> G4bool 
+    Geant4SensitiveAction<TrackerCombine>::process(G4Step* step, G4TouchableHistory* history) {
+      return m_userData.process(step, history);
     }
-    typedef Geant4SensitiveAction<TrackerCombine>  Geant4TrackerCombine;
-#endif
 
+    typedef Geant4SensitiveAction<TrackerCombine>  Geant4TrackerCombineAction;
 
     typedef Geant4TrackerAction Geant4SimpleTrackerAction;
     typedef Geant4CalorimeterAction Geant4SimpleCalorimeterAction;
@@ -278,6 +329,7 @@ using namespace DD4hep::Simulation;
 
 #include "DDG4/Factories.h"
 DECLARE_GEANT4SENSITIVE(Geant4TrackerAction)
+DECLARE_GEANT4SENSITIVE(Geant4TrackerCombineAction)
 DECLARE_GEANT4SENSITIVE(Geant4CalorimeterAction)
 DECLARE_GEANT4SENSITIVE(Geant4OpticalCalorimeterAction)
 
diff --git a/DDG4/python/DDG4.py b/DDG4/python/DDG4.py
index 7a331166d..2d4160096 100644
--- a/DDG4/python/DDG4.py
+++ b/DDG4/python/DDG4.py
@@ -225,20 +225,25 @@ I am sick of typing the same over and over again.
 
 """
 class Simple:
-  def __init__(self, kernel,calo='Geant4SimpleCalorimeterAction',tracker='Geant4SimpleTrackerAction'):
+  def __init__(self, kernel,calo='Geant4CalorimeterAction',tracker='Geant4SimpleTrackerAction'):
     kernel.UI = "UI"
     kernel.printProperties()
     self.kernel = kernel
     self.calo = calo
     self.tracker = tracker
+    self.sensitive_types = {}
+    self.sensitive_types['tracker'] = self.tracker
+    self.sensitive_types['calorimeter'] = self.calo
   def printDetectors(self):
     lcdd = self.kernel.lcdd()
     print '+++  List of sensitive detectors:'
-    for i in lcdd.detectors(): 
+    for i in lcdd.detectors():
       o = DetElement(i.second)
       sd = lcdd.sensitiveDetector(o.name())
       if sd.isValid():
-        print '+++  %-32s type:%s'%(o.name(), sd.type(), )
+        typ = sd.type()
+        sdtyp = self.sensitive_types[typ]
+        print '+++  %-32s type:%-12s  --> Sensitive type: %s'%(o.name(), typ, sdtyp,)
 
   def setupDetector(self,name,sensitive_type):
     seq = SensitiveSequence(self.kernel,'Geant4SensDetActionSequence/'+name)
@@ -291,6 +296,7 @@ class Simple:
     evt_root.enableUI()
     self.kernel.eventAction().add(evt_root)
     return evt_root
+
   def setupLCIOOutput(self,name,output):
     evt_lcio = EventAction(self.kernel,'Geant4Output2LCIO/'+name)
     evt_lcio.Control = True
diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp
index b4a1c8d7a..d7ce891a5 100644
--- a/DDG4/src/Geant4Converter.cpp
+++ b/DDG4/src/Geant4Converter.cpp
@@ -223,6 +223,7 @@ namespace {
     }
   };
 
+#if 0  // warning: unused function 'handleName' [-Wunused-function]
   void handleName(const TGeoNode* n) {
     TGeoVolume* v = n->GetVolume();
     TGeoMedium* m = v->GetMedium();
@@ -231,6 +232,7 @@ namespace {
     printout(DEBUG, "G4", "TGeoNode:'%s' Vol:'%s' Shape:'%s' Medium:'%s'", n->GetName(), v->GetName(), s->GetName(),
         m->GetName());
   }
+  #endif 
 
   class G4UserRegionInformation : public G4VUserRegionInformation {
   public:
diff --git a/DDG4/src/Geant4Exec.cpp b/DDG4/src/Geant4Exec.cpp
index 60bc26658..c6d3321af 100644
--- a/DDG4/src/Geant4Exec.cpp
+++ b/DDG4/src/Geant4Exec.cpp
@@ -51,7 +51,8 @@ namespace DD4hep {
     }
 
     /// Sequence handler implementing common actions to all sequences.
-    template <typename T> struct SequenceHdl {
+    template <typename T> class SequenceHdl {
+    public:
       typedef SequenceHdl<T> Base;
       T* m_sequence;
       Geant4Context* m_activeContext;
@@ -117,7 +118,8 @@ namespace DD4hep {
      * @author  M.Frank
      * @version 1.0
      */
-    struct Geant4UserRunAction : public G4UserRunAction, public SequenceHdl<Geant4RunActionSequence> {
+    class Geant4UserRunAction : public G4UserRunAction, public SequenceHdl<Geant4RunActionSequence> {
+    public:
       Geant4UserEventAction* eventAction;
       /// Standard constructor
       Geant4UserRunAction(Geant4Context* context, Geant4RunActionSequence* seq)
@@ -138,7 +140,8 @@ namespace DD4hep {
      * @author  M.Frank
      * @version 1.0
      */
-    struct Geant4UserEventAction : public G4UserEventAction, public SequenceHdl<Geant4EventActionSequence> {
+    class Geant4UserEventAction : public G4UserEventAction, public SequenceHdl<Geant4EventActionSequence> {
+    public:
       Geant4UserRunAction* runAction;
       /// Standard constructor
       Geant4UserEventAction(Geant4Context* context, Geant4EventActionSequence* seq)
@@ -159,7 +162,8 @@ namespace DD4hep {
      * @author  M.Frank
      * @version 1.0
      */
-    struct Geant4UserTrackingAction : public G4UserTrackingAction, public SequenceHdl<Geant4TrackingActionSequence> {
+    class Geant4UserTrackingAction : public G4UserTrackingAction, public SequenceHdl<Geant4TrackingActionSequence> {
+    public:
       /// Standard constructor
       Geant4UserTrackingAction(Geant4Context* context, Geant4TrackingActionSequence* seq)
 	: Base(context, seq) {
@@ -187,7 +191,8 @@ namespace DD4hep {
      * @author  M.Frank
      * @version 1.0
      */
-    struct Geant4UserStackingAction : public G4UserStackingAction, public SequenceHdl<Geant4StackingActionSequence> {
+    class Geant4UserStackingAction : public G4UserStackingAction, public SequenceHdl<Geant4StackingActionSequence> {
+    public:
       /// Standard constructor
       Geant4UserStackingAction(Geant4Context* context, Geant4StackingActionSequence* seq)
 	: Base(context, seq) {
@@ -215,7 +220,8 @@ namespace DD4hep {
      * @author  M.Frank
      * @version 1.0
      */
-    struct Geant4UserGeneratorAction : public G4VUserPrimaryGeneratorAction, public SequenceHdl<Geant4GeneratorActionSequence> {
+    class Geant4UserGeneratorAction : public G4VUserPrimaryGeneratorAction, public SequenceHdl<Geant4GeneratorActionSequence> {
+    public:
       /// Standard constructor
       Geant4UserGeneratorAction(Geant4Context* context, Geant4GeneratorActionSequence* seq)
 	: G4VUserPrimaryGeneratorAction(), Base(context, seq) {
@@ -237,7 +243,8 @@ namespace DD4hep {
      * @author  M.Frank
      * @version 1.0
      */
-    struct Geant4UserSteppingAction : public G4UserSteppingAction, public SequenceHdl<Geant4SteppingActionSequence> {
+    class Geant4UserSteppingAction : public G4UserSteppingAction, public SequenceHdl<Geant4SteppingActionSequence> {
+    public:
       /// Standard constructor
       Geant4UserSteppingAction(Geant4Context* context, Geant4SteppingActionSequence* seq)
 	: Base(context, seq) {
diff --git a/DDG4/src/Geant4InputAction.cpp b/DDG4/src/Geant4InputAction.cpp
index b649d35f2..f4f059fe4 100644
--- a/DDG4/src/Geant4InputAction.cpp
+++ b/DDG4/src/Geant4InputAction.cpp
@@ -102,7 +102,7 @@ int Geant4InputAction::readParticles(int evt_number, std::vector<Particle*>& par
     try  {
       m_reader = PluginService::Create<Geant4EventReader*>(tn.first,tn.second);
       if ( 0 == m_reader )   {
-	PluginDebug dbg();
+	PluginDebug dbg;
 	m_reader = PluginService::Create<Geant4EventReader*>(tn.first,tn.second);
 	abortRun(issue(evid)+"Error creating reader plugin.",
 		 "Failed to create file reader of type %s. Cannot open dataset %s",
diff --git a/DDG4/src/Geant4SensDetAction.cpp b/DDG4/src/Geant4SensDetAction.cpp
index 9ebcd47ff..2221f04a1 100644
--- a/DDG4/src/Geant4SensDetAction.cpp
+++ b/DDG4/src/Geant4SensDetAction.cpp
@@ -348,11 +348,11 @@ void Geant4SensDetActionSequence::end(G4HCofThisEvent* hce) {
   m_end(hce);
   m_actors(&Geant4Sensitive::end, hce);
   m_actors(ContextUpdate());
-  m_hce = 0;
+  // G4HCofThisEvent must be availible until end-event. m_hce = 0;
 }
 
 /// G4VSensitiveDetector interface: Method invoked if the event was aborted.
-/** Hits collections created but not beibg set to G4HCofThisEvent
+/** Hits collections created but not being set to G4HCofThisEvent
  *  at the event should be deleted.
  *  Collection(s) which have already set to G4HCofThisEvent
  *  will be deleted automatically.
-- 
GitLab