Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Event.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4Event
27//
28// Class description:
29//
30// This is the class which represents an event. A G4Event is constructed and
31// deleted by G4RunManager (or its derived class). When a G4Event object is
32// passed to G4EventManager, G4Event must have one or more primary verteces
33// and primary particle(s) associated to the verteces as an input of
34// simulating an event.
35// G4Event has trajectories, hits collections, and/or digi collections.
36
37// Author: M.Asai, SLAC
38// Adding sub-event : M.Asai, JLAB
39// --------------------------------------------------------------------
40#ifndef G4Event_hh
41#define G4Event_hh 1
42
43#include <set>
44#include <map>
45
46#include "globals.hh"
47#include "evtdefs.hh"
48#include "G4Allocator.hh"
49#include "G4PrimaryVertex.hh"
50#include "G4HCofThisEvent.hh"
51#include "G4DCofThisEvent.hh"
54#include "G4Profiler.hh"
55
57class G4SubEvent;
58
59class G4Event
60{
61 public:
63
64 public:
65 G4Event() = default;
66 explicit G4Event(G4int evID);
67 ~G4Event();
68
69 G4Event(const G4Event &) = delete;
70 G4Event& operator=(const G4Event &) = delete;
71
72 inline void *operator new(std::size_t);
73 inline void operator delete(void* anEvent);
74
75 G4bool operator==(const G4Event& right) const;
76 G4bool operator!=(const G4Event& right) const;
77
78 void Print() const;
79 // Print the event ID (starts with zero and increments by one) to G4cout.
80 void Draw() const;
81 // Invoke Draw() methods of all stored trajectories, hits, and digits.
82 // For hits and digits, Draw() methods of the concrete classes must be
83 // implemented. Otherwise nothing will be drawn.
84
85 inline void SetEventID(G4int i)
86 { eventID = i; }
88 { HC = value; }
90 { DC = value; }
92 { trajectoryContainer = value; }
93 inline void SetEventAborted()
94 { eventAborted = true; }
96 {
97 randomNumberStatus = new G4String(st);
98 validRandomNumberStatus = true;
99 }
101 {
102 randomNumberStatusForProcessing = new G4String(st);
103 validRandomNumberStatusForProcessing = true;
104 }
105 inline void KeepTheEvent(G4bool vl=true)
106 { keepTheEvent = vl; }
107 inline G4bool ToBeKept() const
108 { return keepTheEvent || GetNumberOfRemainingSubEvents()>0; }
109 inline void KeepForPostProcessing() const
110 { ++grips; }
111 inline void PostProcessingFinished() const
112 {
113 --grips;
114 if (grips<0)
115 {
116 G4Exception("G4Event::Release()", "EVENT91001", FatalException,
117 "Number of grips is negative. This cannot be correct.");
118 }
119 }
120 inline G4int GetNumberOfGrips() const
121 { return grips; }
122
123 inline G4int GetEventID() const
124 { return eventID; }
125
126 inline void AddPrimaryVertex(G4PrimaryVertex* aPrimaryVertex)
127 {
128 // This method sets a new primary vertex. This method must be invoked
129 // exclusively by G4VPrimaryGenerator concrete class.
130
131 if( thePrimaryVertex == nullptr )
132 { thePrimaryVertex = aPrimaryVertex; }
133 else
134 { thePrimaryVertex->SetNext( aPrimaryVertex ); }
135 ++numberOfPrimaryVertex;
136 }
137
139 { return numberOfPrimaryVertex; }
140 // Returns number of primary verteces the G4Event object has.
141
143 {
144 if( i == 0 )
145 { return thePrimaryVertex; }
146 if( i > 0 && i < numberOfPrimaryVertex )
147 {
148 G4PrimaryVertex* primaryVertex = thePrimaryVertex;
149 for( G4int j=0; j<i; ++j )
150 {
151 if( primaryVertex == nullptr ) return nullptr;
152 primaryVertex = primaryVertex->GetNext();
153 }
154 return primaryVertex;
155 }
156
157 return nullptr;
158 }
159 // Returns i-th primary vertex of the event.
160
162 { return HC; }
164 { return DC; }
166 { return trajectoryContainer; }
167 // These three methods return the pointers to the G4HCofThisEvent
168 // (hits collections of this event), G4DCofThisEvent (digi collections
169 // of this event), and G4TrajectoryContainer (trajectory coonainer),
170 // respectively.
171
172 inline G4bool IsAborted() const { return eventAborted; }
173 // Return a boolean which indicates the event has been aborted and thus
174 // it should not be used for analysis.
175
177 { userInfo = anInfo; }
179 { return userInfo; }
180 // Set and Get method of G4VUserEventInformation
181
182 inline const G4String& GetRandomNumberStatus() const
183 {
184 if(!validRandomNumberStatus)
185 { G4Exception(
186 "G4Event::GetRandomNumberStatus","Event0701",JustWarning,
187 "Random number status is not available for this event."); }
188 return *randomNumberStatus;
189 }
191 {
192 if(!validRandomNumberStatusForProcessing)
193 { G4Exception(
194 "G4Event::GetRandomNumberStatusForProcessing","Event0702",
196 "Random number status is not available for this event."); }
197 return *randomNumberStatusForProcessing;
198 }
199
200 private:
201
202 // event ID
203 G4int eventID = 0;
204
205 // PrimaryVertex
206 G4PrimaryVertex* thePrimaryVertex = nullptr;
207 G4int numberOfPrimaryVertex = 0;
208
209 // HitsCollection
210 G4HCofThisEvent* HC = nullptr;
211
212 // DigiCollection
213 G4DCofThisEvent* DC = nullptr;
214
215 // TrajectoryContainer
216 G4TrajectoryContainer* trajectoryContainer = nullptr;
217
218 // Boolean flag which shall be set to true if the event is aborted and
219 // thus the containing information is not to be used.
220 G4bool eventAborted = false;
221
222 // UserEventInformation (optional)
223 G4VUserEventInformation* userInfo = nullptr;
224
225 // Initial random number engine status before primary particle generation
226 G4String* randomNumberStatus = nullptr;
227 G4bool validRandomNumberStatus = false;
228
229 // Initial random number engine status before event processing
230 G4String* randomNumberStatusForProcessing = nullptr;
231 G4bool validRandomNumberStatusForProcessing = false;
232
233 // Flag to keep the event until the end of run
234 G4bool keepTheEvent = false;
235 mutable G4int grips = 0;
236
237 //========================= for sub-event parallelism
238 // following methods should be used only within the master thread
239
240 public:
242 // This method is to be invoked from G4RunManager.
243 // SpawnSubEvent() is internally invoked.
245 // This method is to be invoked from G4RunManager once a sub-event is
246 // fully processed by a worker thread.
247
249 // This method is used by G4EventManager to store all the remeining sub-event
250 // object at the end of processing the event.
251
253 // Registering sub-event when it is sent to a worker thread.
255 // Number of sub-events that have been sent to worker threads but not yet
256 // completed.
257 {
258 auto tot = (G4int)fSubEvtVector.size();
259 for(auto& sem : fSubEvtStackMap)
260 { tot += (G4int)sem.second->size(); }
261 return tot;
262 }
263
264 void MergeSubEventResults(const G4Event* se);
265
266 private:
267 std::map<G4int,std::set<G4SubEvent*>*> fSubEvtStackMap;
268 std::set<G4SubEvent*> fSubEvtVector;
269
270 // motherEvent pointer is non-null for an event created in the worker
271 // thread of sub-event parallelism.
272 // This object and all the contained objects must be deleted by the
273 // responsible worker thread.
274 private:
275 G4Event* motherEvent = nullptr;
276 G4int subEventType = -1;
277
278 public:
280 {
281 motherEvent = me;
282 subEventType = ty;
283 }
285 { return motherEvent; }
287 { return subEventType; }
288};
289
291
292inline void* G4Event::operator new(std::size_t)
293{
294 if (anEventAllocator() == nullptr)
295 {
297 }
298 return (void*)anEventAllocator()->MallocSingle();
299}
300
301inline void G4Event::operator delete(void* anEvent)
302{
303 anEventAllocator()->FreeSingle((G4Event*)anEvent);
304}
305
306#endif
G4EVENT_DLL G4Allocator< G4Event > *& anEventAllocator()
Definition G4Event.cc:38
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4int StoreSubEvent(G4int, G4SubEvent *)
Definition G4Event.cc:158
G4bool IsAborted() const
Definition G4Event.hh:172
G4bool ToBeKept() const
Definition G4Event.hh:107
G4int GetSubEventType() const
Definition G4Event.hh:286
G4int GetNumberOfPrimaryVertex() const
Definition G4Event.hh:138
void Print() const
Definition G4Event.cc:120
~G4Event()
Definition G4Event.cc:49
const G4String & GetRandomNumberStatus() const
Definition G4Event.hh:182
G4int GetNumberOfGrips() const
Definition G4Event.hh:120
void PostProcessingFinished() const
Definition G4Event.hh:111
G4TrajectoryContainer * GetTrajectoryContainer() const
Definition G4Event.hh:165
void SetRandomNumberStatus(G4String &st)
Definition G4Event.hh:95
void KeepTheEvent(G4bool vl=true)
Definition G4Event.hh:105
G4HCofThisEvent * GetHCofThisEvent() const
Definition G4Event.hh:161
void MergeSubEventResults(const G4Event *se)
Definition G4Event.cc:204
void SetRandomNumberStatusForProcessing(G4String &st)
Definition G4Event.hh:100
void SetDCofThisEvent(G4DCofThisEvent *value)
Definition G4Event.hh:89
G4PrimaryVertex * GetPrimaryVertex(G4int i=0) const
Definition G4Event.hh:142
G4Event()=default
void FlagAsSubEvent(G4Event *me, G4int ty)
Definition G4Event.hh:279
G4Event(const G4Event &)=delete
const G4String & GetRandomNumberStatusForProcessing() const
Definition G4Event.hh:190
G4bool operator!=(const G4Event &right) const
Definition G4Event.cc:115
G4DCofThisEvent * GetDCofThisEvent() const
Definition G4Event.hh:163
void SetHCofThisEvent(G4HCofThisEvent *value)
Definition G4Event.hh:87
void SetEventAborted()
Definition G4Event.hh:93
G4int GetEventID() const
Definition G4Event.hh:123
void SetUserInformation(G4VUserEventInformation *anInfo)
Definition G4Event.hh:176
G4SubEvent * PopSubEvent(G4int)
Definition G4Event.cc:173
void AddPrimaryVertex(G4PrimaryVertex *aPrimaryVertex)
Definition G4Event.hh:126
void SetEventID(G4int i)
Definition G4Event.hh:85
G4Event * GetMotherEvent() const
Definition G4Event.hh:284
G4bool operator==(const G4Event &right) const
Definition G4Event.cc:110
void KeepForPostProcessing() const
Definition G4Event.hh:109
G4VUserEventInformation * GetUserInformation() const
Definition G4Event.hh:178
G4Event & operator=(const G4Event &)=delete
G4int TerminateSubEvent(G4SubEvent *)
Definition G4Event.cc:219
G4int SpawnSubEvent(G4SubEvent *)
Definition G4Event.cc:189
void SetTrajectoryContainer(G4TrajectoryContainer *value)
Definition G4Event.hh:91
G4int GetNumberOfRemainingSubEvents() const
Definition G4Event.hh:254
void Draw() const
Definition G4Event.cc:125
void SetNext(G4PrimaryVertex *nv)
G4PrimaryVertex * GetNext() const
#define G4EVENT_DLL
Definition evtdefs.hh:45