From e1bde56acc58251a501e7bf20cbe8b0cd2e9c5b0 Mon Sep 17 00:00:00 2001
From: Frank Gaede <frank.gaede@desy.de>
Date: Thu, 4 Apr 2013 18:05:55 +0000
Subject: [PATCH]  - extended hits with cellID    filled from CopyNO  - added
 edeposited to TrackerHit  - reduced some debug printout    (#define DEBUG 0)

---
 DDG4/include/DDG4/Geant4Hits.h       |  5 +++++
 DDG4/src/Geant4SensitiveDetector.cpp | 19 +++++++++++++++----
 DDG4/src/Geant4TrackerSD.cpp         | 11 ++++++++++-
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/DDG4/include/DDG4/Geant4Hits.h b/DDG4/include/DDG4/Geant4Hits.h
index 71f90ee92..1e4ac4956 100644
--- a/DDG4/include/DDG4/Geant4Hits.h
+++ b/DDG4/include/DDG4/Geant4Hits.h
@@ -76,6 +76,9 @@ namespace DD4hep {
     class Geant4Hit : public G4VHit {
     public:
 
+      // cellID
+      unsigned long     cellID ;
+      
       struct MonteCarloContrib {
 	/// Geant 4 Track identifier
 	int    trackID;
@@ -131,6 +134,8 @@ namespace DD4hep {
       /// Monte Carlo / Geant4 information 
       Contribution       truth;
 
+      double      energyDeposit;
+               
     public:
       /// Default constructor
       Geant4TrackerHit();
diff --git a/DDG4/src/Geant4SensitiveDetector.cpp b/DDG4/src/Geant4SensitiveDetector.cpp
index ad05214d5..5a47199f8 100644
--- a/DDG4/src/Geant4SensitiveDetector.cpp
+++ b/DDG4/src/Geant4SensitiveDetector.cpp
@@ -18,6 +18,8 @@
 
 #include "TGeoNode.h"
 
+#define DEBUG 0
+
 
 // C/C++ include files
 #include <iostream>
@@ -94,7 +96,9 @@ G4bool Geant4SensitiveDetector::ProcessHits(G4Step* step,G4TouchableHistory* his
   double ene_cut = m_sensitive.energyCutoff();
   if ( step->GetTotalEnergyDeposit() > ene_cut ) {
     if ( !Geant4Hit::isGeantino(step->GetTrack()) )   {
+#if DEBUG
       dumpStep(step, hist);
+#endif
       return buildHits(step,hist);
     }
   }
@@ -131,22 +135,29 @@ void Geant4SensitiveDetector::dumpStep(G4Step* st, G4TouchableHistory* /* histor
   Position pos1 = step.prePos();
   Position pos2 = step.postPos();
   Momentum mom = step.postMom();
+
+#if DEBUG
   ::printf("  Track:%08ld Pos:(%8f %8f %8f) -> (%f %f %f)  Mom:%7.0f %7.0f %7.0f \n",
-	   long(step.track), pos1.X(), pos1.Y(), pos1.Z(), pos2.X(), pos2.Y(), pos2.Z(), mom.X(), mom.Y(), mom.Z());
+   	   long(step.track), pos1.X(), pos1.Y(), pos1.Z(), pos2.X(), pos2.Y(), pos2.Z(), mom.X(), mom.Y(), mom.Z());
   ::printf("                pre-Vol: %s  Status:%s\n",
-	   step.preVolume()->GetName().c_str(), step.preStepStatus());
+   	   step.preVolume()->GetName().c_str(), step.preStepStatus());
   ::printf("                post-Vol:%s  Status:%s\n",
-	   step.postVolume()->GetName().c_str(), step.postStepStatus());
+   	   step.postVolume()->GetName().c_str(), step.postStepStatus());
+#endif
+  
   const G4VPhysicalVolume* pv = step.volume(step.post);
-
+  
   typedef Geant4Converter::PlacementMap Places;
   const Places& places = cnv.data().g4Placements;
+#if DEBUG
   for(Places::const_iterator i=places.begin(); i!=places.end();++i) {
     const G4PVPlacement* pl = (*i).second;
     const G4VPhysicalVolume* qv = pl;
+    
     if ( qv == pv ) {
       const TGeoNode* tpv = (*i).first;
       printf("           Found TGeoNode:%s!\n",tpv->GetName());
     }
   }
+#endif
 }
diff --git a/DDG4/src/Geant4TrackerSD.cpp b/DDG4/src/Geant4TrackerSD.cpp
index dde03a433..2a919bf6e 100644
--- a/DDG4/src/Geant4TrackerSD.cpp
+++ b/DDG4/src/Geant4TrackerSD.cpp
@@ -20,7 +20,7 @@ namespace DD4hep {  namespace Simulation {
   /// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   struct Tracker {};
   /// Method for generating hit(s) using the information of G4Step object.
-  template <> bool Geant4GenericSD<Tracker>::buildHits(G4Step* step,G4TouchableHistory* ) {
+  template <> bool Geant4GenericSD<Tracker>::buildHits(G4Step* step,G4TouchableHistory* hist) {
     StepHandler h(step);
     Position prePos    = h.prePos();
     Position postPos   = h.postPos();
@@ -31,11 +31,20 @@ namespace DD4hep {  namespace Simulation {
       double new_len = mean_length(h.preMom(),h.postMom())/hit_len;
       direction *= new_len/hit_len;
     }
+
+    //    G4cout << "----------- Geant4GenericSD<Tracker>::buildHits : position : " << prePos << G4endl ;
+
     Geant4TrackerHit* hit = 
       new Geant4TrackerHit(h.track->GetTrackID(),
 			   h.track->GetDefinition()->GetPDGEncoding(),
 			   step->GetTotalEnergyDeposit(),
 			   h.track->GetGlobalTime());
+
+    
+    HitContribution contrib = Geant4Hit::extractContribution(step);
+    hit->cellID  = ( hist ? hist->GetVolume()->GetCopyNo() : 0 ) ; 
+    hit->energyDeposit =  contrib.deposit ;
+
     hit->position = position;
     hit->momentum = direction;
     hit->length   = hit_len;
-- 
GitLab