From 6ffd160edbe4a727cafba37ac46d12bbe4cf73a5 Mon Sep 17 00:00:00 2001 From: Wouter Deconinck <wdconinc@gmail.com> Date: Thu, 25 Jan 2024 15:52:53 -0600 Subject: [PATCH] feat: add Geant4TestStackAction --- DDG4/include/DDG4/Geant4TestActions.h | 20 ++++++++++++++++++++ DDG4/plugins/Geant4Factories.cpp | 2 +- DDG4/src/Geant4TestActions.cpp | 27 +++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/DDG4/include/DDG4/Geant4TestActions.h b/DDG4/include/DDG4/Geant4TestActions.h index 9320e4abc..06b3e67fe 100644 --- a/DDG4/include/DDG4/Geant4TestActions.h +++ b/DDG4/include/DDG4/Geant4TestActions.h @@ -148,6 +148,26 @@ namespace dd4hep { void operator()(const G4Step*, G4SteppingManager*) override; }; + /// Example stacking action doing nothing, but print + /** + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_SIMULATION + */ + class Geant4TestStackAction: public Geant4StackingAction, public Geant4TestBase { + public: + /// Standard constructor with initializing arguments + Geant4TestStackAction(Geant4Context* c, const std::string& n); + /// Default destructor + virtual ~Geant4TestStackAction(); + /// New-stage callback + virtual void newStage(G4StackManager*) override; + /// Preparation callback + virtual void prepare(G4StackManager*) override; + /// Return TrackClassification with enum G4ClassificationOfNewTrack or NoTrackClassification + virtual TrackClassification classifyNewTrack(G4StackManager*, const G4Track*) override; + }; + /// Example sensitve detector action doing nothing, but print /** * \author M.Frank diff --git a/DDG4/plugins/Geant4Factories.cpp b/DDG4/plugins/Geant4Factories.cpp index a0a95ce7a..19aec6761 100644 --- a/DDG4/plugins/Geant4Factories.cpp +++ b/DDG4/plugins/Geant4Factories.cpp @@ -139,7 +139,7 @@ DECLARE_GEANT4ACTION(Geant4TestRunAction) DECLARE_GEANT4ACTION(Geant4TestEventAction) DECLARE_GEANT4ACTION(Geant4TestStepAction) DECLARE_GEANT4ACTION(Geant4TestTrackAction) -//DECLARE_GEANT4ACTION(Geant4TestStackingAction) +DECLARE_GEANT4ACTION(Geant4TestStackAction) DECLARE_GEANT4ACTION(Geant4TestGeneratorAction) DECLARE_GEANT4SENSITIVE(Geant4TestSensitive) DECLARE_GEANT4SENSITIVE(Geant4TestSensitiveTracker) diff --git a/DDG4/src/Geant4TestActions.cpp b/DDG4/src/Geant4TestActions.cpp index 3a5b1a73c..50c048aef 100644 --- a/DDG4/src/Geant4TestActions.cpp +++ b/DDG4/src/Geant4TestActions.cpp @@ -183,6 +183,33 @@ void Geant4TestStepAction::operator()(const G4Step*, G4SteppingManager*) { PRINT("%s> calling operator()", m_type.c_str()); } +/// Standard constructor with initializing arguments +Geant4TestStackAction::Geant4TestStackAction(Geant4Context* c, const std::string& n) + : Geant4StackingAction(c, n), Geant4TestBase(this, "Geant4TestStackAction") { + InstanceCount::increment(this); +} + +/// Default destructor +Geant4TestStackAction::~Geant4TestStackAction() { + InstanceCount::decrement(this); +} +/// New-stage callback +void Geant4TestStackAction::newStage(G4StackManager*) { + PRINT("%s> calling newStage()", m_type.c_str()); +} +/// Preparation callback +void Geant4TestStackAction::prepare(G4StackManager*) { + PRINT("%s> calling prepare()", m_type.c_str()); +} +/// Return TrackClassification with enum G4ClassificationOfNewTrack or NoTrackClassification +TrackClassification Geant4TestStackAction::classifyNewTrack(G4StackManager*, const G4Track* trk) { + PRINT("%s> calling classifyNewTrack(track=%d, parent=%d, position=(%f,%f,%f) Context: run=%p evt=%p)", + m_type.c_str(), trk->GetTrackID(), + trk->GetParentID(), trk->GetPosition().x(), trk->GetPosition().y(), trk->GetPosition().z(), + &context()->run(), &context()->event()); + return TrackClassification(); +} + /// Standard constructor with initializing arguments Geant4TestSensitive::Geant4TestSensitive(Geant4Context* c, const std::string& n, DetElement det, Detector& description) : Geant4Sensitive(c, n, det, description), Geant4TestBase(this, "Geant4TestSensitive") { -- GitLab