LDMX Software
UserAction.h
Go to the documentation of this file.
1
6#ifndef SIMCORE_USERACTION_H
7#define SIMCORE_USERACTION_H
8
9/*~~~~~~~~~~~~~~~~*/
10/* C++ StdLib */
11/*~~~~~~~~~~~~~~~~*/
12#include <map>
13#include <string>
14#include <vector>
15
16/*~~~~~~~~~~~~*/
17/* Geant4 */
18/*~~~~~~~~~~~~*/
19#include "G4EventManager.hh"
20#include "G4UserStackingAction.hh"
21
22/*~~~~~~~~~~~~~~~*/
23/* Framework */
24/*~~~~~~~~~~~~~~~*/
25#include "Framework/Configure/Parameters.h"
26#include "Framework/Factory.h"
27#include "Framework/Logger.h"
28#include "SimCore/Event/SimParticle.h"
29#include "SimCore/G4User/UserEventInformation.h"
30
31// Forward Declarations
32class G4Event;
33class G4Run;
34class G4Step;
35class G4Track;
36
37namespace simcore {
38
40enum TYPE { RUN = 1, EVENT, TRACKING, STEPPING, STACKING, NONE };
41
47 public:
53 UserAction(const std::string& name,
55
57 DECLARE_FACTORY(UserAction, std::shared_ptr<UserAction>, const std::string&,
59
61 virtual ~UserAction() = default;
62
70 virtual void beginOfEventAction(const G4Event*) {};
71
79 virtual void endOfEventAction(const G4Event*) {};
80
88 virtual void beginOfRunAction(const G4Run*) {};
89
97 virtual void endOfRunAction(const G4Run*) {};
98
106 virtual void preUserTrackingAction(const G4Track*) {};
107
115 virtual void postUserTrackingAction(const G4Track*) {};
116
124 virtual void stepping(const G4Step*) {};
125
134 virtual G4ClassificationOfNewTrack classifyNewTrack(
135 const G4Track*, const G4ClassificationOfNewTrack& cl) {
136 return cl;
137 };
138
144 virtual void newStage() {};
145
151 virtual void prepareNewEvent() {};
152
158 virtual std::vector<TYPE> getTypes() = 0;
159
160 protected:
172
180 const std::map<int, ldmx::SimParticle>& getCurrentParticleMap() const;
181
190 void abortEvent(const std::string& reason) const;
191
192 protected:
194 std::string name_{""};
195
198
200 mutable ::framework::logging::logger the_log_;
201
202}; // UserAction
203
204} // namespace simcore
205
215#define DECLARE_ACTION(CLASS) FACTORY_REGISTRATION(simcore::UserAction, CLASS)
216
217#endif // SIMCORE_USERACTION_H
Header holding Factory class and supporting macros.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:26
Interface that defines a user action.
Definition UserAction.h:46
virtual void stepping(const G4Step *)
Method called after each simulation step.
Definition UserAction.h:124
virtual void beginOfEventAction(const G4Event *)
Method called at the beginning of every event.
Definition UserAction.h:70
virtual G4ClassificationOfNewTrack classifyNewTrack(const G4Track *, const G4ClassificationOfNewTrack &cl)
Method called when a track is updated.
Definition UserAction.h:134
mutable::framework::logging::logger the_log_
the logging channel user actions can use ldmx_log with
Definition UserAction.h:200
virtual void preUserTrackingAction(const G4Track *)
Method called before the UserTrackingAction.
Definition UserAction.h:106
virtual ~UserAction()=default
Destructor.
DECLARE_FACTORY(UserAction, std::shared_ptr< UserAction >, const std::string &, framework::config::Parameters &)
factory for user actions
UserAction(const std::string &name, framework::config::Parameters &parameters)
Constructor.
const std::map< int, ldmx::SimParticle > & getCurrentParticleMap() const
Get the current particle map.
virtual std::vector< TYPE > getTypes()=0
UserEventInformation * getEventInfo() const
Get a handle to the event information.
virtual void prepareNewEvent()
Method called at the beginning of a new event.
Definition UserAction.h:151
virtual void endOfEventAction(const G4Event *)
Method called at the end of every event.
Definition UserAction.h:79
virtual void newStage()
Method called at the beginning of a new stage.
Definition UserAction.h:144
virtual void endOfRunAction(const G4Run *)
Method called at the end of a run.
Definition UserAction.h:97
std::string name_
Name of the UserAction.
Definition UserAction.h:194
framework::config::Parameters parameters_
The set of parameters used to configure this class.
Definition UserAction.h:197
void abortEvent(const std::string &reason) const
Helper to abort an event with a message.
virtual void beginOfRunAction(const G4Run *)
Method called at the beginning of a run.
Definition UserAction.h:88
virtual void postUserTrackingAction(const G4Track *)
Method called after the UserTrackingAction.
Definition UserAction.h:115
Encapsulates user defined information associated with a Geant4 event.
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...
TYPE
Enum for each of the user action types.
Definition UserAction.h:40