From 835a0d5df9d4a44e666449c1daf417c296f10081 Mon Sep 17 00:00:00 2001
From: Shaojun Lu <shaojun.lu@desy.de>
Date: Mon, 1 Jun 2015 13:14:34 +0000
Subject: [PATCH]   Overload function 'Geant4HitData::extractContribution' with
 'bool ApplyBirksLaw' for extracting the MC contribution for a given hit from
 the step information with BirksLaw effect option.

---
 DDG4/include/DDG4/Geant4Data.h |  2 ++
 DDG4/src/Geant4Data.cpp        | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/DDG4/include/DDG4/Geant4Data.h b/DDG4/include/DDG4/Geant4Data.h
index 7047181c6..5cf3c0ade 100644
--- a/DDG4/include/DDG4/Geant4Data.h
+++ b/DDG4/include/DDG4/Geant4Data.h
@@ -179,6 +179,8 @@ namespace DD4hep {
       virtual ~Geant4HitData();
       /// Extract the MC contribution for a given hit from the step information
       static Contribution extractContribution(const G4Step* step);
+      /// Extract the MC contribution for a given hit from the step information with BirksLaw option
+      static Contribution extractContribution(const G4Step* step, bool ApplyBirksLaw);
     };
 
     /// Helper class to define structures used by the generic DDG4 tracker sensitive detector
diff --git a/DDG4/src/Geant4Data.cpp b/DDG4/src/Geant4Data.cpp
index 408c64fd0..0232f5b89 100644
--- a/DDG4/src/Geant4Data.cpp
+++ b/DDG4/src/Geant4Data.cpp
@@ -70,6 +70,18 @@ Geant4HitData::Contribution Geant4HitData::extractContribution(const G4Step* ste
   Contribution contrib(h.trkID(),h.trkPdgID(),deposit,h.trkTime(),pos);
   return contrib;
 }
+/// Extract the MC contribution for a given hit from the step information with BirksLaw effect option
+Geant4HitData::Contribution Geant4HitData::extractContribution(const G4Step* step, bool ApplyBirksLaw) {
+  Geant4StepHandler h(step);
+  if ( ApplyBirksLaw == true ) h.doApplyBirksLaw();
+  double deposit =
+    (h.trackDef() == G4OpticalPhoton::OpticalPhotonDefinition()) ? h.trkEnergy() : h.totalEnergy();
+  const G4ThreeVector& pre  = h.prePosG4();
+  const G4ThreeVector& post = h.postPosG4();
+  float pos[] = {float((pre.x()+post.x())/2.0),float((pre.y()+post.y())/2.0),float((pre.z()+post.z())/2.0) };
+  Contribution contrib(h.trkID(),h.trkPdgID(),deposit,h.trkTime(),pos);
+  return contrib;
+}
 
 /// Default constructor
 Geant4Tracker::Hit::Hit()
-- 
GitLab