Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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// --------------------------------------------------------------------
39#ifndef G4Event_hh
40#define G4Event_hh 1
41
42#include "globals.hh"
43#include "evtdefs.hh"
44#include "G4Allocator.hh"
45#include "G4PrimaryVertex.hh"
46#include "G4HCofThisEvent.hh"
47#include "G4DCofThisEvent.hh"
50#include "G4Profiler.hh"
51
53
54class G4Event
55{
56 public:
58
59 public:
60 G4Event() = default;
61 explicit G4Event(G4int evID);
62 ~G4Event();
63
64 G4Event(const G4Event &) = delete;
65 G4Event& operator=(const G4Event &) = delete;
66
67 inline void *operator new(std::size_t);
68 inline void operator delete(void* anEvent);
69
70 G4bool operator==(const G4Event& right) const;
71 G4bool operator!=(const G4Event& right) const;
72
73 void Print() const;
74 // Print the event ID (starts with zero and increments by one) to G4cout.
75 void Draw() const;
76 // Invoke Draw() methods of all stored trajectories, hits, and digits.
77 // For hits and digits, Draw() methods of the concrete classes must be
78 // implemented. Otherwise nothing will be drawn.
79
80 inline void SetEventID(G4int i)
81 { eventID = i; }
83 { HC = value; }
85 { DC = value; }
87 { trajectoryContainer = value; }
88 inline void SetEventAborted()
89 { eventAborted = true; }
91 {
92 randomNumberStatus = new G4String(st);
93 validRandomNumberStatus = true;
94 }
96 {
97 randomNumberStatusForProcessing = new G4String(st);
98 validRandomNumberStatusForProcessing = true;
99 }
100 inline void KeepTheEvent(G4bool vl=true)
101 { keepTheEvent = vl; }
102 inline G4bool ToBeKept() const
103 { return keepTheEvent; }
104 inline void KeepForPostProcessing() const
105 { ++grips; }
106 inline void PostProcessingFinished() const
107 {
108 --grips;
109 if (grips<0)
110 {
111 G4Exception("G4Event::Release()", "EVENT91001", FatalException,
112 "Number of grips is negative. This cannot be correct.");
113 }
114 }
115 inline G4int GetNumberOfGrips() const
116 { return grips; }
117
118 inline G4int GetEventID() const
119 { return eventID; }
120
121 inline void AddPrimaryVertex(G4PrimaryVertex* aPrimaryVertex)
122 {
123 // This method sets a new primary vertex. This method must be invoked
124 // exclusively by G4VPrimaryGenerator concrete class.
125
126 if( thePrimaryVertex == nullptr )
127 { thePrimaryVertex = aPrimaryVertex; }
128 else
129 { thePrimaryVertex->SetNext( aPrimaryVertex ); }
130 ++numberOfPrimaryVertex;
131 }
132
134 { return numberOfPrimaryVertex; }
135 // Returns number of primary verteces the G4Event object has.
136
138 {
139 if( i == 0 )
140 { return thePrimaryVertex; }
141 if( i > 0 && i < numberOfPrimaryVertex )
142 {
143 G4PrimaryVertex* primaryVertex = thePrimaryVertex;
144 for( G4int j=0; j<i; ++j )
145 {
146 if( primaryVertex == nullptr ) return nullptr;
147 primaryVertex = primaryVertex->GetNext();
148 }
149 return primaryVertex;
150 }
151
152 return nullptr;
153 }
154 // Returns i-th primary vertex of the event.
155
157 { return HC; }
159 { return DC; }
161 { return trajectoryContainer; }
162 // These three methods return the pointers to the G4HCofThisEvent
163 // (hits collections of this event), G4DCofThisEvent (digi collections
164 // of this event), and G4TrajectoryContainer (trajectory coonainer),
165 // respectively.
166
167 inline G4bool IsAborted() const { return eventAborted; }
168 // Return a boolean which indicates the event has been aborted and thus
169 // it should not be used for analysis.
170
172 { userInfo = anInfo; }
174 { return userInfo; }
175 // Set and Get method of G4VUserEventInformation
176
177 inline const G4String& GetRandomNumberStatus() const
178 {
179 if(!validRandomNumberStatus)
180 { G4Exception(
181 "G4Event::GetRandomNumberStatus","Event0701",JustWarning,
182 "Random number status is not available for this event."); }
183 return *randomNumberStatus;
184 }
186 {
187 if(!validRandomNumberStatusForProcessing)
188 { G4Exception(
189 "G4Event::GetRandomNumberStatusForProcessing","Event0702",
191 "Random number status is not available for this event."); }
192 return *randomNumberStatusForProcessing;
193 }
194
195 private:
196
197 // event ID
198 G4int eventID = 0;
199
200 // PrimaryVertex
201 G4PrimaryVertex* thePrimaryVertex = nullptr;
202 G4int numberOfPrimaryVertex = 0;
203
204 // HitsCollection
205 G4HCofThisEvent* HC = nullptr;
206
207 // DigiCollection
208 G4DCofThisEvent* DC = nullptr;
209
210 // TrajectoryContainer
211 G4TrajectoryContainer* trajectoryContainer = nullptr;
212
213 // Boolean flag which shall be set to true if the event is aborted and
214 // thus the containing information is not to be used.
215 G4bool eventAborted = false;
216
217 // UserEventInformation (optional)
218 G4VUserEventInformation* userInfo = nullptr;
219
220 // Initial random number engine status before primary particle generation
221 G4String* randomNumberStatus = nullptr;
222 G4bool validRandomNumberStatus = false;
223
224 // Initial random number engine status before event processing
225 G4String* randomNumberStatusForProcessing = nullptr;
226 G4bool validRandomNumberStatusForProcessing = false;
227
228 // Flag to keep the event until the end of run
229 G4bool keepTheEvent = false;
230 mutable G4int grips = 0;
231};
232
234
235inline void* G4Event::operator new(std::size_t)
236{
237 if (anEventAllocator() == nullptr)
238 {
240 }
241 return (void*)anEventAllocator()->MallocSingle();
242}
243
244inline void G4Event::operator delete(void* anEvent)
245{
246 anEventAllocator()->FreeSingle((G4Event*)anEvent);
247}
248
249#endif
G4EVENT_DLL G4Allocator< G4Event > *& anEventAllocator()
Definition: G4Event.cc:37
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4bool IsAborted() const
Definition: G4Event.hh:167
G4bool ToBeKept() const
Definition: G4Event.hh:102
G4int GetNumberOfPrimaryVertex() const
Definition: G4Event.hh:133
void Print() const
Definition: G4Event.cc:81
~G4Event()
Definition: G4Event.cc:48
const G4String & GetRandomNumberStatus() const
Definition: G4Event.hh:177
G4int GetNumberOfGrips() const
Definition: G4Event.hh:115
void PostProcessingFinished() const
Definition: G4Event.hh:106
G4TrajectoryContainer * GetTrajectoryContainer() const
Definition: G4Event.hh:160
void SetRandomNumberStatus(G4String &st)
Definition: G4Event.hh:90
void KeepTheEvent(G4bool vl=true)
Definition: G4Event.hh:100
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:156
void SetRandomNumberStatusForProcessing(G4String &st)
Definition: G4Event.hh:95
void SetDCofThisEvent(G4DCofThisEvent *value)
Definition: G4Event.hh:84
G4PrimaryVertex * GetPrimaryVertex(G4int i=0) const
Definition: G4Event.hh:137
G4Event()=default
G4Event(const G4Event &)=delete
const G4String & GetRandomNumberStatusForProcessing() const
Definition: G4Event.hh:185
G4bool operator!=(const G4Event &right) const
Definition: G4Event.cc:76
G4DCofThisEvent * GetDCofThisEvent() const
Definition: G4Event.hh:158
void SetHCofThisEvent(G4HCofThisEvent *value)
Definition: G4Event.hh:82
void SetEventAborted()
Definition: G4Event.hh:88
G4int GetEventID() const
Definition: G4Event.hh:118
void SetUserInformation(G4VUserEventInformation *anInfo)
Definition: G4Event.hh:171
void AddPrimaryVertex(G4PrimaryVertex *aPrimaryVertex)
Definition: G4Event.hh:121
void SetEventID(G4int i)
Definition: G4Event.hh:80
G4bool operator==(const G4Event &right) const
Definition: G4Event.cc:71
void KeepForPostProcessing() const
Definition: G4Event.hh:104
G4VUserEventInformation * GetUserInformation() const
Definition: G4Event.hh:173
G4Event & operator=(const G4Event &)=delete
void SetTrajectoryContainer(G4TrajectoryContainer *value)
Definition: G4Event.hh:86
void Draw() const
Definition: G4Event.cc:86
void SetNext(G4PrimaryVertex *nv)
G4PrimaryVertex * GetNext() const
#define G4EVENT_DLL
Definition: evtdefs.hh:45