From 835052494f4fd5b25ea0fa5aebe9e964f36c580b Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Tue, 26 Jun 2018 19:43:12 +0200
Subject: [PATCH] Elaborate a bit more the DDG4_MySensDet example and fix the
 persistency of the Geant4 hits

---
 examples/DDG4_MySensDet/src/MyTrackerHit.cpp | 54 ++++++++++++++++++++
 examples/DDG4_MySensDet/src/MyTrackerHit.h   | 34 ++----------
 2 files changed, 57 insertions(+), 31 deletions(-)
 create mode 100644 examples/DDG4_MySensDet/src/MyTrackerHit.cpp

diff --git a/examples/DDG4_MySensDet/src/MyTrackerHit.cpp b/examples/DDG4_MySensDet/src/MyTrackerHit.cpp
new file mode 100644
index 000000000..8a6385eb7
--- /dev/null
+++ b/examples/DDG4_MySensDet/src/MyTrackerHit.cpp
@@ -0,0 +1,54 @@
+//==========================================================================
+//  AIDA Detector description implementation 
+//--------------------------------------------------------------------------
+// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
+// All rights reserved.
+//
+// For the licensing terms see $DD4hepINSTALL/LICENSE.
+// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
+//
+// Author     : M.Frank
+//
+//==========================================================================
+
+/// Framework include files
+#include "MyTrackerHit.h"
+#include "G4Track.hh"
+
+using namespace SomeExperiment;
+
+/// Assignment operator
+MyTrackerHit& MyTrackerHit::operator=(const MyTrackerHit& c)  {
+  if ( &c != this )  {
+    position = c.position;
+    momentum = c.momentum;
+    length = c.length;
+    truth = c.truth;
+  }
+  return *this;
+}
+
+/// Clear hit content
+MyTrackerHit& MyTrackerHit::clear() {
+  position.SetXYZ(0, 0, 0);
+  momentum.SetXYZ(0, 0, 0);
+  length = 0.0;
+  truth.clear();
+  return *this;
+}
+
+/// Store Geant4 point and step information into tracker hit structure.
+MyTrackerHit& MyTrackerHit::storePoint(const G4Step* step, const G4StepPoint* pnt) {
+  G4Track* trk = step->GetTrack();
+  G4ThreeVector pos = pnt->GetPosition();
+  G4ThreeVector mom = pnt->GetMomentum();
+
+  truth.trackID = trk->GetTrackID();
+  truth.pdgID   = trk->GetDefinition()->GetPDGEncoding();
+  truth.deposit = step->GetTotalEnergyDeposit();
+  truth.time    = trk->GetGlobalTime();
+  position.SetXYZ(pos.x(), pos.y(), pos.z());
+  momentum.SetXYZ(mom.x(), mom.y(), mom.z());
+  length = 0;
+  return *this;
+}
diff --git a/examples/DDG4_MySensDet/src/MyTrackerHit.h b/examples/DDG4_MySensDet/src/MyTrackerHit.h
index 8c0e351e2..a80daa19d 100644
--- a/examples/DDG4_MySensDet/src/MyTrackerHit.h
+++ b/examples/DDG4_MySensDet/src/MyTrackerHit.h
@@ -67,39 +67,11 @@ namespace SomeExperiment {
     /// Default destructor
     virtual ~MyTrackerHit() = default;
     /// Assignment operator
-    MyTrackerHit& operator=(const MyTrackerHit& c)  {
-      if ( &c != this )  {
-        position = c.position;
-        momentum = c.momentum;
-        length = c.length;
-        truth = c.truth;
-      }
-      return *this;
-    }
+    MyTrackerHit& operator=(const MyTrackerHit& c);
     /// Clear hit content
-    MyTrackerHit& clear() {
-      position.SetXYZ(0, 0, 0);
-      momentum.SetXYZ(0, 0, 0);
-      length = 0.0;
-      truth.clear();
-      return *this;
-    }
-
+    MyTrackerHit& clear();
     /// Store Geant4 point and step information into tracker hit structure.
-    MyTrackerHit& storePoint(const G4Step* step, const G4StepPoint* pnt) {
-      G4Track* trk = step->GetTrack();
-      G4ThreeVector pos = pnt->GetPosition();
-      G4ThreeVector mom = pnt->GetMomentum();
-
-      truth.trackID = trk->GetTrackID();
-      truth.pdgID   = trk->GetDefinition()->GetPDGEncoding();
-      truth.deposit = step->GetTotalEnergyDeposit();
-      truth.time    = trk->GetGlobalTime();
-      position.SetXYZ(pos.x(), pos.y(), pos.z());
-      momentum.SetXYZ(mom.x(), mom.y(), mom.z());
-      length = 0;
-      return *this;
-    }
+    MyTrackerHit& storePoint(const G4Step* step, const G4StepPoint* pnt);
   };
 }
 
-- 
GitLab