Skip to content

Commit

Permalink
refactor: embed SEvt into G4App (#37)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
plexoos and github-actions[bot] authored Oct 3, 2024
1 parent ef2794d commit 83daebc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
ignore: |
include/argparse
thread-comments: true
format-review: true
tidy-checks: '-*'

- name: Fail fast?!
Expand Down
35 changes: 27 additions & 8 deletions src/simg4ox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@

using namespace std;

SEvt *sev = nullptr;

struct DetectorConstruction : G4VUserDetectorConstruction
{

Expand All @@ -71,6 +69,11 @@ struct DetectorConstruction : G4VUserDetectorConstruction

struct PrimaryGenerator : G4VUserPrimaryGeneratorAction
{
SEvt *sev;

PrimaryGenerator(SEvt *sev) : sev(sev)
{
}

void GeneratePrimaries(G4Event *event) override
{
Expand Down Expand Up @@ -110,6 +113,11 @@ struct PrimaryGenerator : G4VUserPrimaryGeneratorAction

struct EventAction : G4UserEventAction
{
SEvt *sev;

EventAction(SEvt *sev) : sev(sev)
{
}

void BeginOfEventAction(const G4Event *event) override
{
Expand Down Expand Up @@ -142,6 +150,11 @@ void get_label(spho &ulabel, const G4Track *track)

struct SteppingAction : G4UserSteppingAction
{
SEvt *sev;

SteppingAction(SEvt *sev) : sev(sev)
{
}

void UserSteppingAction(const G4Step *step)
{
Expand Down Expand Up @@ -195,6 +208,11 @@ struct SteppingAction : G4UserSteppingAction
struct TrackingAction : G4UserTrackingAction
{
const G4Track *transient_fSuspend_track = nullptr;
SEvt *sev;

TrackingAction(SEvt *sev) : sev(sev)
{
}

void PreUserTrackingAction_Optical_FabricateLabel(const G4Track *track)
{
Expand Down Expand Up @@ -270,16 +288,20 @@ struct TrackingAction : G4UserTrackingAction
struct G4App
{
G4App(filesystem::path gdml_file)
: det_cons_(new DetectorConstruction(gdml_file)), prim_gen_(new PrimaryGenerator),
stepping_(new SteppingAction), tracking_(new TrackingAction), event_act_(new EventAction)
: sev(SEvt::HighLevelCreate(SEvt::ECPU)), det_cons_(new DetectorConstruction(gdml_file)),
prim_gen_(new PrimaryGenerator(sev)), event_act_(new EventAction(sev)), stepping_(new SteppingAction(sev)),
tracking_(new TrackingAction(sev))
{
}

// Create "global" event
SEvt *sev;

G4VUserDetectorConstruction *det_cons_;
G4VUserPrimaryGeneratorAction *prim_gen_;
EventAction *event_act_;
SteppingAction *stepping_;
TrackingAction *tracking_;
EventAction *event_act_;
};

int main(int argc, char **argv)
Expand Down Expand Up @@ -317,9 +339,6 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}

// Create global event
sev = SEvt::HighLevelCreate(SEvt::ECPU);

// Configure Geant4
// The physics list must be instantiated before other user actions
G4VModularPhysicsList *physics = new FTFP_BERT;
Expand Down

0 comments on commit 83daebc

Please sign in to comment.