From 5ee93223ff1d233a74e483525bf0b04a3aada2e4 Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Wed, 1 Mar 2023 19:16:52 +0100
Subject: [PATCH] Addendum to PR https://github.com/AIDASoft/DD4hep/pull/1068
---
DDG4/plugins/Geant4SDActions.cpp | 26 +++++++++++++++-----------
DDG4/src/Geant4Data.cpp | 2 ++
2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/DDG4/plugins/Geant4SDActions.cpp b/DDG4/plugins/Geant4SDActions.cpp
index 27ca959bc..9aa13e189 100644
--- a/DDG4/plugins/Geant4SDActions.cpp
+++ b/DDG4/plugins/Geant4SDActions.cpp
@@ -104,7 +104,7 @@ namespace dd4hep {
except("+++ Invalid CELL ID for hit!");
}
print("Hit with deposit:%f Pos:%f %f %f ID=%016X",
- step->GetTotalEnergyDeposit(), pos.X(), pos.Y(), pos.Z(), (void*)hit->cellID);
+ hit->energyDeposit,hit->position.X(),hit->position.Y(),hit->position.Z(),(void*)hit->cellID);
Geant4TouchableHandler handler(step);
print(" Geant4 path:%s",handler.path().c_str());
return true;
@@ -119,7 +119,8 @@ namespace dd4hep {
Geant4FastSimHandler h(spot);
Hit* hit = new Hit(h.trkID(), h.trkPdgID(), h.deposit(), h.track->GetGlobalTime(),
0e0, h.avgPosition(), h.momentum());
- hit->cellID = cellID(h.touchable(), h.avgPositionG4());
+ hit->cellID = cellID(h.touchable(), h.avgPositionG4());
+ hit->truth = Hit::extractContribution(spot);
collection(m_collectionID)->add(hit);
mark(h.track);
if ( 0 == hit->cellID ) {
@@ -127,7 +128,7 @@ namespace dd4hep {
except("+++ Invalid CELL ID for hit!");
}
print("Hit with deposit:%f Pos:%f %f %f ID=%016X",
- h.deposit(),hit->position.X(),hit->position.Y(),hit->position.Z(),(void*)hit->cellID);
+ hit->energyDeposit,hit->position.X(),hit->position.Y(),hit->position.Z(),(void*)hit->cellID);
Geant4TouchableHandler handler(h.touchable());
print(" Geant4 path:%s",handler.path().c_str());
return true;
@@ -169,11 +170,11 @@ namespace dd4hep {
Direction mom = 0.5 * ( h.preMom() + h.postMom() ) ;
double tim = h.track->GetGlobalTime();
double hit_len = direction.R();
+ auto contrib = Hit::extractContribution(step);
- Hit* hit = new Hit(h.trkID(), h.trkPdgID(), h.deposit(), tim, hit_len, pos, mom);
- hit->truth = Hit::extractContribution(step);
- hit->energyDeposit = hit->truth.deposit;
- hit->cellID = cellID(step);
+ Hit* hit = new Hit(h.trkID(), h.trkPdgID(), contrib.deposit, tim, hit_len, pos, mom);
+ hit->truth = contrib;
+ hit->cellID = cellID(step);
if (track->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition()) {
track->SetTrackStatus(fStopAndKill);
}
@@ -184,7 +185,7 @@ namespace dd4hep {
except("+++ Invalid CELL ID for hit!");
}
print("Hit with deposit:%f Pos:%f %f %f ID=%016X",
- step->GetTotalEnergyDeposit(), pos.X(),pos.Y(), pos.Z(), (void*)hit->cellID);
+ hit->energyDeposit,hit->position.X(),hit->position.Y(),hit->position.Z(),(void*)hit->cellID);
Geant4TouchableHandler handler(step);
print(" Geant4 path:%s",handler.path().c_str());
return true;
@@ -197,9 +198,12 @@ namespace dd4hep {
{
typedef Geant4Tracker::Hit Hit;
Geant4FastSimHandler h(spot);
- Hit* hit = new Hit(h.trkID(), h.trkPdgID(), h.deposit(), h.track->GetGlobalTime(),
+ auto contrib = Hit::extractContribution(spot);
+ Hit* hit = new Hit(h.trkID(), h.trkPdgID(), contrib.deposit, h.track->GetGlobalTime(),
0e0, h.avgPosition(), h.momentum());
- hit->cellID = cellID(h.touchable(), h.avgPositionG4());
+ hit->cellID = cellID(h.touchable(), h.avgPositionG4());
+ hit->truth = contrib;
+
collection(m_collectionID)->add(hit);
mark(h.track);
if ( 0 == hit->cellID ) {
@@ -207,7 +211,7 @@ namespace dd4hep {
except("+++ Invalid CELL ID for hit!");
}
print("Hit with deposit:%f Pos:%f %f %f ID=%016X",
- h.deposit(),hit->position.X(),hit->position.Y(),hit->position.Z(),(void*)hit->cellID);
+ hit->energyDeposit,hit->position.X(),hit->position.Y(),hit->position.Z(),(void*)hit->cellID);
Geant4TouchableHandler handler(h.touchable());
print(" Geant4 path:%s",handler.path().c_str());
return true;
diff --git a/DDG4/src/Geant4Data.cpp b/DDG4/src/Geant4Data.cpp
index c9d1456ff..9d3ac7bd4 100644
--- a/DDG4/src/Geant4Data.cpp
+++ b/DDG4/src/Geant4Data.cpp
@@ -132,6 +132,7 @@ void Geant4Tracker::Hit::copyFrom(const Hit& c) {
if ( &c != this ) {
position = c.position;
momentum = c.momentum;
+ deposit = c.deposit;
length = c.length;
truth = c.truth;
}
@@ -141,6 +142,7 @@ void Geant4Tracker::Hit::copyFrom(const Hit& c) {
Geant4Tracker::Hit& Geant4Tracker::Hit::clear() {
position.SetXYZ(0, 0, 0);
momentum.SetXYZ(0, 0, 0);
+ deposit = 0.0;
length = 0.0;
truth.clear();
return *this;
--
GitLab