Skip to content

Commit

Permalink
add early tracking exit in G4HepEmTrackingManager
Browse files Browse the repository at this point in the history
  • Loading branch information
SeverinDiederichs committed Dec 15, 2024
1 parent 962bc5a commit 59dcd65
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
cmake_minimum_required(VERSION 3.17...3.18 FATAL_ERROR)
project(G4HepEm VERSION 0.1.0)

#----------------------------------------------------------------------------
# Option for enabling early exit
option(G4HepEm_EARLY_TRACKING_EXIT "Enable user-defined early tracking exit" OFF)
if(G4HepEm_EARLY_TRACKING_EXIT)
message(STATUS "User-defined early tracking exit is enabled")
endif()

# Local and Core Modules
include(GNUInstallDirs)
include(CheckLanguage)
Expand All @@ -30,6 +37,10 @@ function(g4hepem_add_library _name)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>)
target_link_libraries(${_name} PUBLIC ${_g4hepem_LINK})

if(G4HepEm_EARLY_TRACKING_EXIT)
target_compile_definitions(${_name} PUBLIC G4HepEm_EARLY_TRACKING_EXIT)
endif()
endif()

# Build static library, if enabled.
Expand All @@ -46,6 +57,10 @@ function(g4hepem_add_library _name)
target_link_libraries(${_name}-static PUBLIC ${_lib}-static)
endforeach()

if(G4HepEm_EARLY_TRACKING_EXIT)
target_compile_definitions(${_name}-static PUBLIC G4HepEm_EARLY_TRACKING_EXIT)
endif()

# If only the static library, add alias targets for convenience.
if(NOT BUILD_SHARED_LIBS)
add_library(${_name} ALIAS ${_name}-static)
Expand Down
33 changes: 23 additions & 10 deletions G4HepEm/G4HepEm/include/G4HepEmTrackingManager.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef G4HepEmTrackingManager_h
#define G4HepEmTrackingManager_h 1

#include "G4EventManager.hh"
#include "G4VTrackingManager.hh"

#include "globals.hh"

class G4HepEmRunManager;
Expand All @@ -22,13 +24,13 @@ class G4HepEmWoodcockHelper;
class G4HepEmTrackingManager : public G4VTrackingManager {
public:
G4HepEmTrackingManager();
~G4HepEmTrackingManager();
virtual ~G4HepEmTrackingManager();

void BuildPhysicsTable(const G4ParticleDefinition &) override;

void PreparePhysicsTable(const G4ParticleDefinition &) override;

void HandOverOneTrack(G4Track *aTrack) override;
virtual void HandOverOneTrack(G4Track *aTrack) override;

void SetMultipleSteps(G4bool val) {
fMultipleSteps = val;
Expand All @@ -47,11 +49,15 @@ public:
fWDTRegionNames.push_back(regionName);
}

protected:
bool TrackElectron(G4Track *aTrack);
bool TrackGamma(G4Track *aTrack);

private:
void TrackElectron(G4Track *aTrack);
void TrackGamma(G4Track *aTrack);
// Pointers to the fast simulation manager processes of the 3 particles if any
// [0] e-; [1] e+; [2] gamma; nullptr: no fast sim manager process attached
G4VProcess *fFastSimProcess[3];

private:
// Stacks secondaries created by HepEm physics (if any) and returns with the
// energy deposit while stacking due to applying secondary production cuts
double StackSecondaries(G4HepEmTLData* aTLData, G4Track* aG4PrimaryTrack,
Expand All @@ -77,6 +83,18 @@ private:
// no harm outside Athena.
void InitXTRRelated();

#ifdef G4HepEm_EARLY_TRACKING_EXIT
// Virtual function to check early tracking exit. This function allows user
// implementations to intercept the G4HepEm tracking loop based on
// user-defined conditions, e.g., when entering a GPU region To be implemented
// in derived classes by users, base implementation does nothing and returns
// false
virtual bool CheckEarlyTrackingExit(G4Track *track, G4EventManager *evtMgr,
G4UserTrackingAction *userTrackingAction,
G4TrackVector &secondaries) const {
return false;
}
#endif

G4HepEmRunManager *fRunManager;
G4HepEmRandomEngine *fRandomEngine;
Expand All @@ -103,11 +121,6 @@ private:
G4VProcess* fENucProcess;
G4VProcess* fPNucProcess;


// Pointers to the fast simulation manager processes of the 3 particles if any
// [0] e-; [1] e+; [2] gamma; nullptr: no fast sim manager process attached
G4VProcess* fFastSimProcess[3];

// ATLAS XTR RELATED:
// Fields to store ptrs to the ATLAS XTR (transition radiation) process and
// detector region that contain the tradiator volumes
Expand Down
19 changes: 17 additions & 2 deletions G4HepEm/G4HepEm/src/G4HepEmTrackingManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void G4HepEmTrackingManager::PreparePhysicsTable(

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void G4HepEmTrackingManager::TrackElectron(G4Track *aTrack) {
bool G4HepEmTrackingManager::TrackElectron(G4Track *aTrack) {
TrackingManagerHelper::ChargedNavigation navigation;

// Prepare for calling the user action.
Expand Down Expand Up @@ -307,6 +307,13 @@ void G4HepEmTrackingManager::TrackElectron(G4Track *aTrack) {

while(aTrack->GetTrackStatus() == fAlive)
{
#ifdef G4HepEm_EARLY_TRACKING_EXIT
// check for user-defined early exit
if (CheckEarlyTrackingExit(aTrack, evtMgr, userTrackingAction, secondaries)) {
return false;
}
#endif

// Beginning of this step: Prepare data structures.
aTrack->IncrementCurrentStepNumber();

Expand Down Expand Up @@ -734,11 +741,12 @@ void G4HepEmTrackingManager::TrackElectron(G4Track *aTrack) {
}

evtMgr->StackTracks(&secondaries);
return true;
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void G4HepEmTrackingManager::TrackGamma(G4Track *aTrack) {
bool G4HepEmTrackingManager::TrackGamma(G4Track *aTrack) {
TrackingManagerHelper::NeutralNavigation navigation;

// Prepare for calling the user action.
Expand Down Expand Up @@ -848,6 +856,12 @@ void G4HepEmTrackingManager::TrackGamma(G4Track *aTrack) {
// === StartTracking ===

while (aTrack->GetTrackStatus() == fAlive) {
#ifdef G4HepEm_EARLY_TRACKING_EXIT
// check for user-defined early exit
if (CheckEarlyTrackingExit(aTrack, evtMgr, userTrackingAction, secondaries)) {
return false;
}
#endif

// Beginning of this step: Prepare data structures.
aTrack->IncrementCurrentStepNumber();
Expand Down Expand Up @@ -1144,6 +1158,7 @@ void G4HepEmTrackingManager::TrackGamma(G4Track *aTrack) {
}

evtMgr->StackTracks(&secondaries);
return true;
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Expand Down

0 comments on commit 59dcd65

Please sign in to comment.