LDMX Software
UserAction.h
1
2#ifndef SIMCORE_USERACTION_H
3#define SIMCORE_USERACTION_H
4
5/*~~~~~~~~~~~~~~~~*/
6/* C++ StdLib */
7/*~~~~~~~~~~~~~~~~*/
8#include <iostream>
9#include <map>
10#include <string>
11#include <vector>
12
13/*~~~~~~~~~~~~*/
14/* Geant4 */
15/*~~~~~~~~~~~~*/
16#include "G4EventManager.hh"
17#include "G4UserStackingAction.hh"
18
19/*~~~~~~~~~~~~~~~*/
20/* Framework */
21/*~~~~~~~~~~~~~~~*/
22#include "Framework/Configure/Parameters.h"
23#include "SimCore/Event/SimParticle.h"
24#include "SimCore/Factory.h"
25#include "SimCore/UserEventInformation.h"
26
27// Forward Declarations
28class G4Event;
29class G4Run;
30class G4Step;
31class G4Track;
32
33namespace simcore {
34
36enum TYPE { RUN = 1, EVENT, TRACKING, STEPPING, STACKING, NONE };
37
43 public:
49 UserAction(const std::string& name,
51
53 using Factory =
55 const std::string&, framework::config::Parameters&>;
56
58 virtual ~UserAction() = default;
59
67 virtual void BeginOfEventAction(const G4Event*){};
68
76 virtual void EndOfEventAction(const G4Event*){};
77
85 virtual void BeginOfRunAction(const G4Run*){};
86
94 virtual void EndOfRunAction(const G4Run*){};
95
103 virtual void PreUserTrackingAction(const G4Track*){};
104
112 virtual void PostUserTrackingAction(const G4Track*){};
113
121 virtual void stepping(const G4Step*){};
122
131 virtual G4ClassificationOfNewTrack ClassifyNewTrack(
132 const G4Track*, const G4ClassificationOfNewTrack& cl) {
133 return cl;
134 };
135
141 virtual void NewStage(){};
142
148 virtual void PrepareNewEvent(){};
149
155 virtual std::vector<TYPE> getTypes() = 0;
156
157 protected:
169
177 const std::map<int, ldmx::SimParticle>& getCurrentParticleMap() const;
178
179 protected:
181 std::string name_{""};
182
185
186}; // UserAction
187
188} // namespace simcore
189
190#define DECLARE_ACTION(NS, CLASS) \
191 namespace { \
192 auto v##CLASS = ::simcore::UserAction::Factory::get().declare<NS::CLASS>(); \
193 }
194
195#endif // SIMCORE_USERACTION_H
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
Factory to dynamically create objects derived from a specific prototype class.
Definition Factory.h:197
Interface that defines a user action.
Definition UserAction.h:42
virtual void stepping(const G4Step *)
Method called after each simulation step.
Definition UserAction.h:121
virtual void PrepareNewEvent()
Method called at the beginning of a new event.
Definition UserAction.h:148
virtual void BeginOfEventAction(const G4Event *)
Method called at the beginning of every event.
Definition UserAction.h:67
virtual void EndOfRunAction(const G4Run *)
Method called at the end of a run.
Definition UserAction.h:94
virtual ~UserAction()=default
Destructor.
virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *, const G4ClassificationOfNewTrack &cl)
Method called when a track is updated.
Definition UserAction.h:131
virtual void PreUserTrackingAction(const G4Track *)
Method called before the UserTrackingAction.
Definition UserAction.h:103
virtual void BeginOfRunAction(const G4Run *)
Method called at the beginning of a run.
Definition UserAction.h:85
const std::map< int, ldmx::SimParticle > & getCurrentParticleMap() const
Get the current particle map.
virtual void EndOfEventAction(const G4Event *)
Method called at the end of every event.
Definition UserAction.h:76
virtual std::vector< TYPE > getTypes()=0
UserEventInformation * getEventInfo() const
Get a handle to the event information.
virtual void NewStage()
Method called at the beginning of a new stage.
Definition UserAction.h:141
virtual void PostUserTrackingAction(const G4Track *)
Method called after the UserTrackingAction.
Definition UserAction.h:112
std::string name_
Name of the UserAction.
Definition UserAction.h:181
framework::config::Parameters parameters_
The set of parameters used to configure this class.
Definition UserAction.h:184
Encapsulates user defined information associated with a Geant4 event.