From 35f9a2a9a5a505d6e90a12c657889a1a41ceb874 Mon Sep 17 00:00:00 2001 From: Frank Gaede <frank-dieter.gaede@cern.ch> Date: Thu, 9 Nov 2017 19:20:38 +0100 Subject: [PATCH] add Geant4::HitData::MonteCarloContrib::length --- DDG4/include/DDG4/Geant4Data.h | 19 +++++++++++-------- DDG4/lcio/LCIOConversions.cpp | 2 +- DDG4/src/Geant4Data.cpp | 8 +++++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/DDG4/include/DDG4/Geant4Data.h b/DDG4/include/DDG4/Geant4Data.h index fee3ff60b..89cd369cf 100644 --- a/DDG4/include/DDG4/Geant4Data.h +++ b/DDG4/include/DDG4/Geant4Data.h @@ -146,6 +146,8 @@ namespace dd4hep { double deposit; /// Timestamp when this energy was deposited double time; + /// Length of this step + double length = 0.0; /// Proper position of the hit contribution float x,y,z; @@ -154,24 +156,24 @@ namespace dd4hep { : trackID(-1), pdgID(-1), deposit(0.0), time(0.0), x(0), y(0), z(0) { } /// Initializing constructor - MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp) - : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp), x(0), y(0), z(0) { + MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp, double len) + : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp), length(len), x(0), y(0), z(0) { } /// Initializing constructor - MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp, float* pos) - : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp), + MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp, double len, float* pos) + : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp), length(len), x(pos[0]), y(pos[1]), z(pos[2]) { } /// Initializing constructor - MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp, double* pos) - : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp), + MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp, double len, double* pos) + : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp), length(len), x(pos[0]), y(pos[1]), z(pos[2]) { } /// Copy constructor MonteCarloContrib(const MonteCarloContrib& c) - : trackID(c.trackID), pdgID(c.pdgID), deposit(c.deposit), time(c.time), + : trackID(c.trackID), pdgID(c.pdgID), deposit(c.deposit), time(c.time), length(c.length), x(c.x), y(c.y), z(c.z) { } /// Assignment operator @@ -181,6 +183,7 @@ namespace dd4hep { pdgID = c.pdgID; deposit = c.deposit; time = c.time; + length = c.length; x = c.x; y = c.y; z = c.z; @@ -190,7 +193,7 @@ namespace dd4hep { /// Clear data content void clear() { x = y = z = 0.0; - time = deposit = 0.0; + time = deposit = length = 0.0; pdgID = trackID = -1; } }; diff --git a/DDG4/lcio/LCIOConversions.cpp b/DDG4/lcio/LCIOConversions.cpp index 1a27b3d11..1a8830494 100644 --- a/DDG4/lcio/LCIOConversions.cpp +++ b/DDG4/lcio/LCIOConversions.cpp @@ -203,7 +203,7 @@ namespace dd4hep { EVENT::MCParticle* lc_mcp = (EVENT::MCParticle*)lc_parts->getElementAt(trackID); if ( hit_creation_mode == Geant4Sensitive::DETAILED_MODE ) { float contrib_pos[] = {float(c.x/mm), float(c.y/mm), float(c.z/mm)}; - lc_hit->addMCParticleContribution(lc_mcp, c.deposit/GeV, c.time/ns, c.pdgID, contrib_pos); + lc_hit->addMCParticleContribution(lc_mcp, c.deposit/GeV, c.time/ns, c.length/mm, c.pdgID, contrib_pos); } else { lc_hit->addMCParticleContribution(lc_mcp, c.deposit/GeV, c.time/ns); diff --git a/DDG4/src/Geant4Data.cpp b/DDG4/src/Geant4Data.cpp index a6ab612ba..e481fbba5 100644 --- a/DDG4/src/Geant4Data.cpp +++ b/DDG4/src/Geant4Data.cpp @@ -70,8 +70,9 @@ Geant4HitData::Contribution Geant4HitData::extractContribution(const G4Step* ste (h.trackDef() == G4OpticalPhoton::OpticalPhotonDefinition()) ? h.trkEnergy() : h.totalEnergy(); const G4ThreeVector& pre = h.prePosG4(); const G4ThreeVector& post = h.postPosG4(); + double length = (post-pre).mag() ; 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); + Contribution contrib(h.trkID(),h.trkPdgID(),deposit,h.trkTime(),length,pos); return contrib; } /// Extract the MC contribution for a given hit from the step information with BirksLaw effect option @@ -82,8 +83,9 @@ Geant4HitData::Contribution Geant4HitData::extractContribution(const G4Step* ste (h.trackDef() == G4OpticalPhoton::OpticalPhotonDefinition()) ? h.trkEnergy() : h.totalEnergy(); const G4ThreeVector& pre = h.prePosG4(); const G4ThreeVector& post = h.postPosG4(); + double length = (post-pre).mag() ; 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); + Contribution contrib(h.trkID(),h.trkPdgID(),deposit,h.trkTime(),length,pos); return contrib; } @@ -95,7 +97,7 @@ Geant4Tracker::Hit::Hit() /// Standard initializing constructor Geant4Tracker::Hit::Hit(int track_id, int pdg_id, double deposit, double time_stamp) -: Geant4HitData(), position(), momentum(), length(0.0), truth(track_id, pdg_id, deposit, time_stamp), energyDeposit(deposit) { + : Geant4HitData(), position(), momentum(), length(0.0), truth(track_id, pdg_id, deposit, time_stamp, 0.), energyDeposit(deposit) { InstanceCount::increment(this); } -- GitLab