This repository was archived by the owner on May 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserAction.h
More file actions
196 lines (167 loc) · 4.4 KB
/
Copy pathUserAction.h
File metadata and controls
196 lines (167 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#ifndef SIMCORE_USERACTION_H
#define SIMCORE_USERACTION_H
/*~~~~~~~~~~~~~~~~*/
/* C++ StdLib */
/*~~~~~~~~~~~~~~~~*/
#include <iostream>
#include <map>
#include <string>
#include <vector>
/*~~~~~~~~~~~~*/
/* Geant4 */
/*~~~~~~~~~~~~*/
#include "G4EventManager.hh"
#include "G4UserStackingAction.hh"
/*~~~~~~~~~~~~~~~*/
/* Framework */
/*~~~~~~~~~~~~~~~*/
#include "Framework/Configure/Parameters.h"
#include "SimCore/UserEventInformation.h"
#include "SimCore/Event/SimParticle.h"
#include "SimCore/Factory.h"
// Forward Declarations
class G4Event;
class G4Run;
class G4Step;
class G4Track;
namespace simcore {
/// Enum for each of the user action types.
enum TYPE { RUN = 1, EVENT, TRACKING, STEPPING, STACKING, NONE };
/**
* @class UserAction
* @brief Interface that defines a user action.
*/
class UserAction {
public:
/**
* Constructor.
*
* @param name Name given the to class instance.
*/
UserAction(const std::string& name,
framework::config::Parameters& parameters);
/// factory for user actions
using Factory = ::simcore::Factory<UserAction,
std::shared_ptr<UserAction>,
const std::string&,
framework::config::Parameters&>;
/// Destructor
virtual ~UserAction();
/**
* Method called at the beginning of every event.
*
* TYPE::EVENT
*
* @param event Geant4 event object.
*/
virtual void BeginOfEventAction(const G4Event*){};
/**
* Method called at the end of every event.
*
* TYPE::EVENT
*
* @param event Geant4 event object.
*/
virtual void EndOfEventAction(const G4Event*){};
/**
* Method called at the beginning of a run.
*
* TYPE::RUN
*
* @param run Current Geant4 run object.
*/
virtual void BeginOfRunAction(const G4Run*){};
/**
* Method called at the end of a run.
*
* TYPE::RUN
*
* @param run Current Geant4 run object.
*/
virtual void EndOfRunAction(const G4Run*){};
/**
* Method called before the UserTrackingAction.
*
* TYPE::TRACKING
*
* @param track current Geant4 track
*/
virtual void PreUserTrackingAction(const G4Track*){};
/**
* Method called after the UserTrackingAction.
*
* TYPE::TRACKING
*
* @param track current Geant4 track
*/
virtual void PostUserTrackingAction(const G4Track*){};
/**
* Method called after each simulation step.
*
* TYPE::STEPPING
*
* @param current Geant4 step
*/
virtual void stepping(const G4Step*){};
/**
* Method called when a track is updated
*
* TYPE::STEPPING
*
* @param current Geant4 track
* @param current tracks' classification
*/
virtual G4ClassificationOfNewTrack ClassifyNewTrack(
const G4Track*, const G4ClassificationOfNewTrack& cl) {
return cl;
};
/**
* Method called at the beginning of a new stage
*
* TYPE::STACKING
*/
virtual void NewStage(){};
/**
* Method called at the beginning of a new event
*
* TYPE::STACKING
*/
virtual void PrepareNewEvent(){};
/**
* @return The user action types
*
* Must be defined by any UserActions so that we know what functions to call.
*/
virtual std::vector<TYPE> getTypes() = 0;
protected:
/**
* Get a handle to the event information
*
* This is static just to point out that it doesn't
* depend on any of the member variables of this class.
* It is just a helper function for shortening any
* code that interacts with our event information.
*
* @returns pointer to the current event information
*/
UserEventInformation* getEventInfo() const;
/**
* Get the current particle map
*
* @note The current particle map will only have the particles
* already fully processed and chosen to be saved. The ancestry
* of the particles will not have been traced yet.
*/
const std::map<int,ldmx::SimParticle>& getCurrentParticleMap() const;
protected:
/// Name of the UserAction
std::string name_{""};
/// The set of parameters used to configure this class
framework::config::Parameters parameters_;
}; // UserAction
} // namespace simcore
#define DECLARE_ACTION(NS, CLASS) \
namespace { \
auto v##CLASS = ::simcore::UserAction::Factory::get().declare<NS::CLASS>(); \
}
#endif // SIMCORE_USERACTION_H