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 "Framework/Logger.h"
24#include "SimCore/Event/SimParticle.h"
25#include "SimCore/Factory.h"
26#include "SimCore/UserEventInformation.h"
27
28// Forward Declarations
29class G4Event;
30class G4Run;
31class G4Step;
32class G4Track;
33
34namespace simcore {
35
37enum TYPE { RUN = 1, EVENT, TRACKING, STEPPING, STACKING, NONE };
38
44 public:
50 UserAction(const std::string& name,
52
54 using Factory =
56 const std::string&, framework::config::Parameters&>;
57
59 virtual ~UserAction() = default;
60
68 virtual void BeginOfEventAction(const G4Event*){};
69
77 virtual void EndOfEventAction(const G4Event*){};
78
86 virtual void BeginOfRunAction(const G4Run*){};
87
95 virtual void EndOfRunAction(const G4Run*){};
96
104 virtual void PreUserTrackingAction(const G4Track*){};
105
113 virtual void PostUserTrackingAction(const G4Track*){};
114
122 virtual void stepping(const G4Step*){};
123
132 virtual G4ClassificationOfNewTrack ClassifyNewTrack(
133 const G4Track*, const G4ClassificationOfNewTrack& cl) {
134 return cl;
135 };
136
142 virtual void NewStage(){};
143
149 virtual void PrepareNewEvent(){};
150
156 virtual std::vector<TYPE> getTypes() = 0;
157
158 protected:
170
178 const std::map<int, ldmx::SimParticle>& getCurrentParticleMap() const;
179
180 protected:
182 std::string name_{""};
183
186
188 mutable ::framework::logging::logger theLog_;
189
190}; // UserAction
191
192} // namespace simcore
193
194#define DECLARE_ACTION(NS, CLASS) \
195 namespace { \
196 auto v##CLASS = ::simcore::UserAction::Factory::get().declare<NS::CLASS>(); \
197 }
198
199#endif // SIMCORE_USERACTION_H
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
Factory to dynamically create objects derived from a specific prototype class.
Definition Factory.h:197
Interface that defines a user action.
Definition UserAction.h:43
virtual void stepping(const G4Step *)
Method called after each simulation step.
Definition UserAction.h:122
virtual void PrepareNewEvent()
Method called at the beginning of a new event.
Definition UserAction.h:149
virtual void BeginOfEventAction(const G4Event *)
Method called at the beginning of every event.
Definition UserAction.h:68
virtual void EndOfRunAction(const G4Run *)
Method called at the end of a run.
Definition UserAction.h:95
virtual ~UserAction()=default
Destructor.
UserAction(const std::string &name, framework::config::Parameters &parameters)
Constructor.
virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *, const G4ClassificationOfNewTrack &cl)
Method called when a track is updated.
Definition UserAction.h:132
virtual void PreUserTrackingAction(const G4Track *)
Method called before the UserTrackingAction.
Definition UserAction.h:104
virtual void BeginOfRunAction(const G4Run *)
Method called at the beginning of a run.
Definition UserAction.h:86
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:77
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:142
mutable::framework::logging::logger theLog_
the logging channel user actions can use ldmx_log with
Definition UserAction.h:188
virtual void PostUserTrackingAction(const G4Track *)
Method called after the UserTrackingAction.
Definition UserAction.h:113
std::string name_
Name of the UserAction.
Definition UserAction.h:182
framework::config::Parameters parameters_
The set of parameters used to configure this class.
Definition UserAction.h:185
Encapsulates user defined information associated with a Geant4 event.