55#include <unordered_set>
61 return fpEventManager;
66 if(fpEventManager !=
nullptr)
69 "G4EventManager::G4EventManager() has already been made.");
79 fpEventManager =
this;
85 delete trackContainer;
89 delete userEventAction;
90 fpEventManager =
nullptr;
93void G4EventManager::DoProcessing(
G4Event* anEvent)
95 abortRequested =
false;
100 "IllegalState -- Geometry not closed: cannot process an event.");
103 currentEvent = anEvent;
105 if(storetRandomNumberStatusToG4Event > 1)
107 std::ostringstream oss;
109 randomNumberStatusToG4Event = oss.str();
124 if ( verboseLevel > 0 )
126 G4cout <<
"=====================================" <<
G4endl;
127 G4cout <<
" G4EventManager::ProcessOneEvent() " <<
G4endl;
128 G4cout <<
"=====================================" <<
G4endl;
134#ifdef G4_STORE_TRAJECTORY
135 trajectoryContainer =
nullptr;
139 if(sdManager !=
nullptr)
144#if defined(GEANT4_USE_TIMEMORY)
149 if ( verboseLevel > 1 )
152 <<
" vertices passed from G4Event." <<
G4endl;
162 if ( verboseLevel > 0 )
165 <<
"are passed from G4EventTransformer." <<
G4endl;
166 G4cout <<
"!!!!!!! Now start processing an event !!!!!!!" <<
G4endl;
170 std::unordered_set<G4VTrackingManager *> trackingManagersToFlush;
175 while( (track=trackContainer->
PopNextTrack(&previousTrajectory)) !=
nullptr )
181 if (particleTrackingManager !=
nullptr)
184 if ( verboseLevel > 1 )
188 <<
") is handed over to custom TrackingManager." <<
G4endl;
198 trackingManagersToFlush.insert(particleTrackingManager);
202 if ( verboseLevel > 1 )
206 <<
") is passed to G4TrackingManager." <<
G4endl;
216 if ( verboseLevel > 0 )
220 <<
") is processed with stopping code " << istop <<
G4endl;
225#ifdef G4_STORE_TRAJECTORY
228 if(previousTrajectory !=
nullptr)
232 aTrajectory = previousTrajectory;
237 if(trajectoryContainer ==
nullptr)
242 trajectoryContainer->
insert(aTrajectory);
268 "Illegal track status returned from G4TrackingManager."\
269 " Continue with simulation.");
273 if( secondaries !=
nullptr )
275 for(
auto & secondarie : *secondaries)
276 {
delete secondarie; }
277 secondaries->clear();
290 trackingManagersToFlush.clear();
300 if ( verboseLevel > 0 )
302 G4cout <<
"NULL returned from G4StackManager." <<
G4endl;
303 G4cout <<
"Terminate current event processing." <<
G4endl;
307 if(sdManager !=
nullptr)
312#if defined(GEANT4_USE_TIMEMORY)
313 eventProfiler.reset();
320 if(!subEventPara && (userEventAction !=
nullptr))
330 if ( verboseLevel > 2 )
332 G4cout<<
"## End of processing an event --- "
333 <<nses<<
" sub-event types registered."<<
G4endl;
336 for(std::size_t i=0;i<nses;i++)
344 currentEvent =
nullptr;
345 abortRequested =
false;
351 if(currentEvent==
nullptr)
return nullptr;
365 ev->TerminateSubEvent(
const_cast<G4SubEvent*
>(se));
367 if ( verboseLevel > 1 )
369 G4cout <<
"A sub-event of type " << seType
370 <<
" is merged to the event " << ev->GetEventID() <<
G4endl;
371 if(ev->GetNumberOfRemainingSubEvents()>0)
373 G4cout <<
" ---- This event still has " << ev->GetNumberOfRemainingSubEvents()
374 <<
" sub-events to be processed." <<
G4endl;
377 {
G4cout <<
" ---- This event has no more sub-event remaining." <<
G4endl; }
385 if( trackVector !=
nullptr )
387 if( trackVector->empty() )
return;
388 for(
auto newTrack : *trackVector )
393 newTrack->SetTrackID( trackIDCounter );
394 if(newTrack->GetDynamicParticle()->GetPrimaryParticle() !=
nullptr)
398 pp->SetTrackID(trackIDCounter);
401 newTrack->SetOriginTouchableHandle(newTrack->GetTouchableHandle());
404 if ( verboseLevel > 1 )
406 G4cout <<
"A new track " << newTrack
407 <<
" (trackID " << newTrack->GetTrackID()
408 <<
", parentID " << newTrack->GetParentID()
409 <<
") is passed to G4StackManager." <<
G4endl;
413 trackVector->clear();
419 userEventAction = userAction;
420 if(userEventAction !=
nullptr)
428 userStackingAction = userAction;
434 userTrackingAction = userAction;
440 userSteppingAction = userAction;
447 DoProcessing(anEvent);
454 if (randStat ==
nullptr) randStat =
new G4String;
457 if(anEvent ==
nullptr)
462 if (storetRandomNumberStatusToG4Event==1
463 || storetRandomNumberStatusToG4Event==3)
465 std::ostringstream oss;
467 (*randStat) = oss.str();
471 DoProcessing(anEvent);
472 if(tempEvent) {
delete anEvent; }
482 "G4VUserEventInformation cannot be set because of absence "\
503 if(currentEvent !=
nullptr) { currentEvent->
KeepTheEvent(); }
508 abortRequested =
true;
509 trackContainer->
clear();
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
#define G4MUTEX_INITIALIZER
@ fKillTrackAndSecondaries
std::vector< G4Track * > G4TrackVector
G4GLOB_DLL std::ostream G4cout
static std::ostream & saveFullState(std::ostream &os)
void SetUserAction(G4UserEventAction *userAction)
void SetUserInformation(G4VUserEventInformation *anInfo)
void KeepTheCurrentEvent()
G4ProfilerConfig< G4ProfileType::Event > ProfilerConfig
static G4EventManager * GetEventManager()
void StackTracks(G4TrackVector *trackVector, G4bool IDhasAlreadySet=false)
G4SubEvent * PopSubEvent(G4int ty)
void ProcessOneEvent(G4Event *anEvent)
G4VUserEventInformation * GetUserInformation()
void TerminateSubEvent(const G4SubEvent *se, const G4Event *evt)
G4int GetNumberOfPrimaryVertex() const
void SetRandomNumberStatus(G4String &st)
void KeepTheEvent(G4bool vl=true)
G4HCofThisEvent * GetHCofThisEvent() const
void MergeSubEventResults(const G4Event *se)
void SetRandomNumberStatusForProcessing(G4String &st)
void SetHCofThisEvent(G4HCofThisEvent *value)
void SetUserInformation(G4VUserEventInformation *anInfo)
G4SubEvent * PopSubEvent(G4int)
G4VUserEventInformation * GetUserInformation() const
void SetTrajectoryContainer(G4TrajectoryContainer *value)
static G4GlobalFastSimulationManager * GetGlobalFastSimulationManager()
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=nullptr, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
G4VTrackingManager * GetTrackingManager() const
void TerminateCurrentEvent(G4HCofThisEvent *HCE)
G4HCofThisEvent * PrepareNewEvent()
static G4SDManager * GetSDMpointerIfExist()
G4int GetNTotalTrack() const
G4int GetNUrgentTrack() const
G4int GetSubEventType(std::size_t i)
G4Track * PopNextTrack(G4VTrajectory **newTrajectory)
G4int PrepareNewEvent(G4Event *currentEvent)
std::size_t GetNSubEventTypes()
G4int PushOneTrack(G4Track *newTrack, G4VTrajectory *newTrajectory=nullptr)
void SetUserStackingAction(G4UserStackingAction *value)
void ReleaseSubEvent(G4int ty)
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
G4bool SetNewState(const G4ApplicationState &requestedState)
G4int GetSubEventType() const
G4Event * GetEvent() const
G4TrackStatus GetTrackStatus() const
const G4ParticleDefinition * GetParticleDefinition() const
G4int GetParentID() const
void SetUserAction(G4UserTrackingAction *apAction)
G4TrackVector * GimmeSecondaries() const
void ProcessOneTrack(G4Track *apValueG4Track)
G4VTrajectory * GimmeTrajectory() const
G4bool insert(G4VTrajectory *p)
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const
virtual void SetEventManager(G4EventManager *value)
virtual void MergeSubEvent(G4Event *masterEvent, const G4Event *subEvent)
virtual void BeginOfEventAction(const G4Event *anEvent)
virtual void EndOfEventAction(const G4Event *anEvent)
virtual void HandOverOneTrack(G4Track *aTrack)=0
virtual void MergeTrajectory(G4VTrajectory *secondTrajectory)=0