Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Event Class Reference

#include <G4Event.hh>

Public Types

using ProfilerConfig = G4ProfilerConfig<G4ProfileType::Event>
 

Public Member Functions

 G4Event ()=default
 
 G4Event (G4int evID)
 
 ~G4Event ()
 
 G4Event (const G4Event &)=delete
 
G4Eventoperator= (const G4Event &)=delete
 
void * operator new (std::size_t)
 
void operator delete (void *anEvent)
 
G4bool operator== (const G4Event &right) const
 
G4bool operator!= (const G4Event &right) const
 
void Print () const
 
void Draw () const
 
void SetEventID (G4int i)
 
void SetHCofThisEvent (G4HCofThisEvent *value)
 
void SetDCofThisEvent (G4DCofThisEvent *value)
 
void SetTrajectoryContainer (G4TrajectoryContainer *value)
 
void SetEventAborted ()
 
void SetRandomNumberStatus (G4String &st)
 
void SetRandomNumberStatusForProcessing (G4String &st)
 
void KeepTheEvent (G4bool vl=true)
 
G4bool ToBeKept () const
 
void KeepForPostProcessing () const
 
void PostProcessingFinished () const
 
G4int GetNumberOfGrips () const
 
G4int GetEventID () const
 
void AddPrimaryVertex (G4PrimaryVertex *aPrimaryVertex)
 
G4int GetNumberOfPrimaryVertex () const
 
G4PrimaryVertexGetPrimaryVertex (G4int i=0) const
 
G4HCofThisEventGetHCofThisEvent () const
 
G4DCofThisEventGetDCofThisEvent () const
 
G4TrajectoryContainerGetTrajectoryContainer () const
 
G4bool IsAborted () const
 
void SetUserInformation (G4VUserEventInformation *anInfo)
 
G4VUserEventInformationGetUserInformation () const
 
const G4StringGetRandomNumberStatus () const
 
const G4StringGetRandomNumberStatusForProcessing () const
 
G4SubEventPopSubEvent (G4int)
 
G4int TerminateSubEvent (G4SubEvent *)
 
G4int StoreSubEvent (G4int, G4SubEvent *)
 
G4int SpawnSubEvent (G4SubEvent *)
 
G4int GetNumberOfRemainingSubEvents () const
 
void MergeSubEventResults (const G4Event *se)
 
void FlagAsSubEvent (G4Event *me, G4int ty)
 
G4EventGetMotherEvent () const
 
G4int GetSubEventType () const
 

Detailed Description

Definition at line 59 of file G4Event.hh.

Member Typedef Documentation

◆ ProfilerConfig

Constructor & Destructor Documentation

◆ G4Event() [1/3]

G4Event::G4Event ( )
default

◆ G4Event() [2/3]

G4Event::G4Event ( G4int evID)
explicit

Definition at line 44 of file G4Event.cc.

45 : eventID(evID)
46{
47}

◆ ~G4Event()

G4Event::~G4Event ( )

Definition at line 49 of file G4Event.cc.

50{
51 G4PrimaryVertex* nextVertex = thePrimaryVertex;
52 while(nextVertex != nullptr)
53 {
54 G4PrimaryVertex* thisVertex = nextVertex;
55 nextVertex = thisVertex->GetNext();
56 thisVertex->ClearNext();
57 delete thisVertex;
58 }
59 thePrimaryVertex = nullptr;
60 delete HC;
61 delete DC;
62 if(trajectoryContainer != nullptr)
63 {
64 trajectoryContainer->clearAndDestroy();
65 delete trajectoryContainer;
66 }
67 delete userInfo;
68 delete randomNumberStatus;
69 delete randomNumberStatusForProcessing;
70
71 // Following G4Exception are temporally issuing JustWarning to delete
72 // unprocessed tracks in sub-events. Once sub-event mechanism is completely
73 // implemented, G4Exception should cause FatalException.
74
75 G4int remainingSE = 0;
76 for(auto& sem : fSubEvtStackMap)
77 {
78 if((sem.second!=nullptr)&&!(sem.second->empty()))
79 {
80 remainingSE += sem.second->size();
81 for(auto& se : *(sem.second))
82 {
83 se->clearAndDestroy();
84 }
85 sem.second->clear();
86 }
87 }
88 if(remainingSE>0)
89 {
91 ed << "Deleting G4Event (id:" << eventID << ") that still has "
92 << remainingSE << " sub-events un-processed.";
93 G4Exception("G4Event::~G4Event()","SubEvt0001",JustWarning,ed);
94 }
95
96 if(!(fSubEvtVector.empty()))
97 {
99 ed << "Deleting G4Event (id:" << eventID << ") that has "
100 << fSubEvtVector.size() << " sub-events still processing.";
101 G4Exception("G4Event::~G4Event()","SubEvt0001",JustWarning,ed);
102 for(auto& se : fSubEvtVector)
103 {
104 se->clearAndDestroy();
105 delete se;
106 }
107 }
108}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
int G4int
Definition G4Types.hh:85
G4PrimaryVertex * GetNext() const

◆ G4Event() [3/3]

G4Event::G4Event ( const G4Event & )
delete

Member Function Documentation

◆ AddPrimaryVertex()

void G4Event::AddPrimaryVertex ( G4PrimaryVertex * aPrimaryVertex)
inline

Definition at line 126 of file G4Event.hh.

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 }
void SetNext(G4PrimaryVertex *nv)

Referenced by G4AdjointPrimaryGeneratorAction::GeneratePrimaries(), G4RTPrimaryGeneratorAction::GeneratePrimaries(), G4HEPEvtInterface::GeneratePrimaryVertex(), G4ParticleGun::GeneratePrimaryVertex(), G4SingleParticleSource::GeneratePrimaryVertex(), and G4RayShooter::Shoot().

◆ Draw()

void G4Event::Draw ( ) const

Definition at line 125 of file G4Event.cc.

126{
128 if(pVVisManager == nullptr) return;
129
130 if(trajectoryContainer != nullptr)
131 {
132 std::size_t n_traj = trajectoryContainer->entries();
133 for(std::size_t i=0; i<n_traj; ++i)
134 { (*trajectoryContainer)[i]->DrawTrajectory(); }
135 }
136
137 if(HC != nullptr)
138 {
139 std::size_t n_HC = HC->GetCapacity();
140 for(std::size_t j=0; j<n_HC; ++j)
141 {
142 G4VHitsCollection* VHC = HC->GetHC((G4int)j);
143 if(VHC != nullptr) VHC->DrawAllHits();
144 }
145 }
146
147 if(DC != nullptr)
148 {
149 std::size_t n_DC = DC->GetCapacity();
150 for(std::size_t j=0; j<n_DC; ++j)
151 {
152 G4VDigiCollection* VDC = DC->GetDC((G4int)j);
153 if(VDC != nullptr) VDC->DrawAllDigi();
154 }
155 }
156}
G4VDigiCollection * GetDC(G4int i) const
size_t GetCapacity() const
G4VHitsCollection * GetHC(G4int i)
std::size_t entries() const
virtual void DrawAllDigi()
virtual void DrawAllHits()
static G4VVisManager * GetConcreteInstance()

◆ FlagAsSubEvent()

void G4Event::FlagAsSubEvent ( G4Event * me,
G4int ty )
inline

Definition at line 279 of file G4Event.hh.

280 {
281 motherEvent = me;
282 subEventType = ty;
283 }

◆ GetDCofThisEvent()

G4DCofThisEvent * G4Event::GetDCofThisEvent ( ) const
inline

Definition at line 163 of file G4Event.hh.

164 { return DC; }

Referenced by G4DigiManager::GetDigiCollection(), G4DigiManager::SetDigiCollection(), and G4PersistencyManager::Store().

◆ GetEventID()

◆ GetHCofThisEvent()

G4HCofThisEvent * G4Event::GetHCofThisEvent ( ) const
inline

Definition at line 161 of file G4Event.hh.

162 { return HC; }

Referenced by G4DigiManager::GetHitsCollection(), G4PersistencyManager::Store(), and G4RunManager::UpdateScoring().

◆ GetMotherEvent()

G4Event * G4Event::GetMotherEvent ( ) const
inline

Definition at line 284 of file G4Event.hh.

285 { return motherEvent; }

◆ GetNumberOfGrips()

G4int G4Event::GetNumberOfGrips ( ) const
inline

Definition at line 120 of file G4Event.hh.

121 { return grips; }

Referenced by G4RunManager::CleanUpUnnecessaryEvents(), and G4RunManager::StackPreviousEvent().

◆ GetNumberOfPrimaryVertex()

G4int G4Event::GetNumberOfPrimaryVertex ( ) const
inline

Definition at line 138 of file G4Event.hh.

139 { return numberOfPrimaryVertex; }

◆ GetNumberOfRemainingSubEvents()

G4int G4Event::GetNumberOfRemainingSubEvents ( ) const
inline

Definition at line 254 of file G4Event.hh.

257 {
258 auto tot = (G4int)fSubEvtVector.size();
259 for(auto& sem : fSubEvtStackMap)
260 { tot += (G4int)sem.second->size(); }
261 return tot;
262 }

Referenced by ToBeKept().

◆ GetPrimaryVertex()

G4PrimaryVertex * G4Event::GetPrimaryVertex ( G4int i = 0) const
inline

Definition at line 142 of file G4Event.hh.

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 }

Referenced by G4AdjointPrimaryGeneratorAction::GeneratePrimaries(), and G4PrimaryTransformer::GimmePrimaries().

◆ GetRandomNumberStatus()

const G4String & G4Event::GetRandomNumberStatus ( ) const
inline

Definition at line 182 of file G4Event.hh.

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 }

◆ GetRandomNumberStatusForProcessing()

const G4String & G4Event::GetRandomNumberStatusForProcessing ( ) const
inline

Definition at line 190 of file G4Event.hh.

191 {
192 if(!validRandomNumberStatusForProcessing)
193 { G4Exception(
194 "G4Event::GetRandomNumberStatusForProcessing","Event0702",
196 "Random number status is not available for this event."); }
197 return *randomNumberStatusForProcessing;
198 }

◆ GetSubEventType()

G4int G4Event::GetSubEventType ( ) const
inline

Definition at line 286 of file G4Event.hh.

287 { return subEventType; }

◆ GetTrajectoryContainer()

G4TrajectoryContainer * G4Event::GetTrajectoryContainer ( ) const
inline

Definition at line 165 of file G4Event.hh.

166 { return trajectoryContainer; }

Referenced by G4TheRayTracer::GenerateColour(), and G4RTRun::RecordEvent().

◆ GetUserInformation()

G4VUserEventInformation * G4Event::GetUserInformation ( ) const
inline

Definition at line 178 of file G4Event.hh.

179 { return userInfo; }

Referenced by G4EventManager::GetUserInformation().

◆ IsAborted()

G4bool G4Event::IsAborted ( ) const
inline

Definition at line 172 of file G4Event.hh.

172{ return eventAborted; }

◆ KeepForPostProcessing()

void G4Event::KeepForPostProcessing ( ) const
inline

Definition at line 109 of file G4Event.hh.

110 { ++grips; }

◆ KeepTheEvent()

void G4Event::KeepTheEvent ( G4bool vl = true)
inline

Definition at line 105 of file G4Event.hh.

106 { keepTheEvent = vl; }

Referenced by G4EventManager::KeepTheCurrentEvent().

◆ MergeSubEventResults()

void G4Event::MergeSubEventResults ( const G4Event * se)

Definition at line 204 of file G4Event.cc.

205{
206#ifdef G4_STORE_TRAJECTORY
207 if(se->trajectoryContainer!=nullptr && se->trajectoryContainer->size()>0)
208 {
209 if(trajectoryContainer==nullptr) trajectoryContainer = new G4TrajectoryContainer;
210 for(auto& trj : *(se->trajectoryContainer->GetVector()))
211 { trajectoryContainer->push_back(trj); }
212 }
213#endif
214 // Note:
215 // - scores are merged directly to the scoring manager
216 // - hits collections should be merged by the user event action
217}
TrajectoryVector * GetVector() const
void push_back(G4VTrajectory *p)

Referenced by G4EventManager::TerminateSubEvent().

◆ operator delete()

void G4Event::operator delete ( void * anEvent)
inline

Definition at line 301 of file G4Event.hh.

302{
303 anEventAllocator()->FreeSingle((G4Event*)anEvent);
304}
G4EVENT_DLL G4Allocator< G4Event > *& anEventAllocator()
Definition G4Event.cc:38

◆ operator new()

void * G4Event::operator new ( std::size_t )
inline

Definition at line 292 of file G4Event.hh.

293{
294 if (anEventAllocator() == nullptr)
295 {
297 }
298 return (void*)anEventAllocator()->MallocSingle();
299}

◆ operator!=()

G4bool G4Event::operator!= ( const G4Event & right) const

Definition at line 115 of file G4Event.cc.

116{
117 return ( eventID != right.eventID );
118}

◆ operator=()

G4Event & G4Event::operator= ( const G4Event & )
delete

◆ operator==()

G4bool G4Event::operator== ( const G4Event & right) const

Definition at line 110 of file G4Event.cc.

111{
112 return ( eventID == right.eventID );
113}

◆ PopSubEvent()

G4SubEvent * G4Event::PopSubEvent ( G4int ty)

Definition at line 173 of file G4Event.cc.

174{
175 G4SubEvent* se = nullptr;
176 auto ses = fSubEvtStackMap.find(ty);
177 if(ses!=fSubEvtStackMap.end())
178 {
179 auto sev = ses->second;
180 if(!(sev->empty()))
181 {
182 se = sev->extract(sev->begin()).value();
183 SpawnSubEvent(se);
184 }
185 }
186 return se;
187}
G4int SpawnSubEvent(G4SubEvent *)
Definition G4Event.cc:189

Referenced by G4EventManager::PopSubEvent().

◆ PostProcessingFinished()

void G4Event::PostProcessingFinished ( ) const
inline

Definition at line 111 of file G4Event.hh.

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 }
@ FatalException

◆ Print()

void G4Event::Print ( ) const

Definition at line 120 of file G4Event.cc.

121{
122 G4cout << "G4Event " << eventID << G4endl;
123}
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout

◆ SetDCofThisEvent()

void G4Event::SetDCofThisEvent ( G4DCofThisEvent * value)
inline

Definition at line 89 of file G4Event.hh.

90 { DC = value; }

Referenced by G4DigiManager::SetDigiCollection().

◆ SetEventAborted()

void G4Event::SetEventAborted ( )
inline

Definition at line 93 of file G4Event.hh.

94 { eventAborted = true; }

Referenced by G4RunManager::AbortEvent(), and G4RunManager::AbortRun().

◆ SetEventID()

void G4Event::SetEventID ( G4int i)
inline

◆ SetHCofThisEvent()

void G4Event::SetHCofThisEvent ( G4HCofThisEvent * value)
inline

Definition at line 87 of file G4Event.hh.

88 { HC = value; }

◆ SetRandomNumberStatus()

void G4Event::SetRandomNumberStatus ( G4String & st)
inline

Definition at line 95 of file G4Event.hh.

96 {
97 randomNumberStatus = new G4String(st);
98 validRandomNumberStatus = true;
99 }

Referenced by G4EventManager::ProcessOneEvent().

◆ SetRandomNumberStatusForProcessing()

void G4Event::SetRandomNumberStatusForProcessing ( G4String & st)
inline

Definition at line 100 of file G4Event.hh.

101 {
102 randomNumberStatusForProcessing = new G4String(st);
103 validRandomNumberStatusForProcessing = true;
104 }

◆ SetTrajectoryContainer()

void G4Event::SetTrajectoryContainer ( G4TrajectoryContainer * value)
inline

Definition at line 91 of file G4Event.hh.

92 { trajectoryContainer = value; }

◆ SetUserInformation()

void G4Event::SetUserInformation ( G4VUserEventInformation * anInfo)
inline

Definition at line 176 of file G4Event.hh.

177 { userInfo = anInfo; }

Referenced by G4EventManager::SetUserInformation().

◆ SpawnSubEvent()

G4int G4Event::SpawnSubEvent ( G4SubEvent * se)

Definition at line 189 of file G4Event.cc.

190{
191 auto ss = fSubEvtVector.find(se);
192 if(ss!=fSubEvtVector.end())
193 {
195 ed << "Sub-event " << se << " of type " << se->GetSubEventType()
196 << " with " << se->GetNTrack() << " tracks has already spawned.";
197 G4Exception("G4Event::SpawnSubEvent","SubEvent9001",
198 FatalException,ed);
199 }
200 fSubEvtVector.insert(se);
201 return (G4int)fSubEvtVector.size();
202}
G4int GetSubEventType() const
Definition G4SubEvent.hh:61
std::size_t GetNTrack() const
Definition G4SubEvent.hh:62

Referenced by PopSubEvent().

◆ StoreSubEvent()

G4int G4Event::StoreSubEvent ( G4int ty,
G4SubEvent * se )

Definition at line 158 of file G4Event.cc.

159{
160 std::set<G4SubEvent*>* sev = nullptr;
161 auto ses = fSubEvtStackMap.find(ty);
162 if(ses==fSubEvtStackMap.end())
163 {
164 sev = new std::set<G4SubEvent*>;
165 fSubEvtStackMap[ty] = sev;
166 }
167 else
168 { sev = ses->second; }
169 sev->insert(se);
170 return (G4int)sev->size();
171}

Referenced by G4SubEventTrackStack::PushToStack(), and G4SubEventTrackStack::ReleaseSubEvent().

◆ TerminateSubEvent()

G4int G4Event::TerminateSubEvent ( G4SubEvent * se)

Definition at line 219 of file G4Event.cc.

220{
221 auto ss = fSubEvtVector.find(se);
222 if(ss==fSubEvtVector.end())
223 {
225 ed << "Sub-event " << se << " of type " << se->GetSubEventType()
226 << " with " << se->GetNTrack() << " tracks has never been spawned.";
227 G4Exception("G4Event::TerminateSubEvent","SubEvent9002",
228 FatalException,ed);
229 }
230
231 fSubEvtVector.erase(ss);
232
233 ss = fSubEvtVector.find(se);
234 if(ss!=fSubEvtVector.end())
235 {
237 ed << "Sub-event " << se << " of type " << se->GetSubEventType()
238 << " with " << se->GetNTrack() << " appears more than once. PANIC!";
239 G4Exception("G4Event::TerminateSubEvent","SubEvent9003",
240 FatalException,ed);
241 }
242
243 se->clearAndDestroy();
244 delete se;
245 return (G4int)fSubEvtVector.size();
246}
void clearAndDestroy()
Definition G4SubEvent.cc:40

◆ ToBeKept()

G4bool G4Event::ToBeKept ( ) const
inline

Definition at line 107 of file G4Event.hh.

108 { return keepTheEvent || GetNumberOfRemainingSubEvents()>0; }
G4int GetNumberOfRemainingSubEvents() const
Definition G4Event.hh:254

Referenced by G4RunManager::CleanUpPreviousEvents(), G4RunManager::CleanUpUnnecessaryEvents(), and G4RunManager::StackPreviousEvent().


The documentation for this class was generated from the following files: