49#include <unordered_set>
55 return fpEventManager;
60 if(fpEventManager !=
nullptr)
63 "G4EventManager::G4EventManager() has already been made.");
73 fpEventManager =
this;
79 delete trackContainer;
83 delete userEventAction;
84 fpEventManager =
nullptr;
87void G4EventManager::DoProcessing(
G4Event* anEvent)
89 abortRequested =
false;
94 "IllegalState -- Geometry not closed: cannot process an event.");
97 currentEvent = anEvent;
99 if(storetRandomNumberStatusToG4Event > 1)
101 std::ostringstream oss;
103 randomNumberStatusToG4Event = oss.str();
118 if ( verboseLevel > 0 )
120 G4cout <<
"=====================================" <<
G4endl;
121 G4cout <<
" G4EventManager::ProcessOneEvent() " <<
G4endl;
122 G4cout <<
"=====================================" <<
G4endl;
128#ifdef G4_STORE_TRAJECTORY
129 trajectoryContainer =
nullptr;
133 if(sdManager !=
nullptr)
138#if defined(GEANT4_USE_TIMEMORY)
143 if ( verboseLevel > 1 )
146 <<
" vertices passed from G4Event." <<
G4endl;
156 if ( verboseLevel > 0 )
159 <<
"are passed from G4EventTransformer." <<
G4endl;
160 G4cout <<
"!!!!!!! Now start processing an event !!!!!!!" <<
G4endl;
164 std::unordered_set<G4VTrackingManager *> trackingManagersToFlush;
169 while( (track=trackContainer->
PopNextTrack(&previousTrajectory)) !=
nullptr )
175 if (particleTrackingManager !=
nullptr)
178 if ( verboseLevel > 1 )
182 <<
") is handed over to custom TrackingManager." <<
G4endl;
192 trackingManagersToFlush.insert(particleTrackingManager);
196 if ( verboseLevel > 1 )
200 <<
") is passed to G4TrackingManager." <<
G4endl;
210 if ( verboseLevel > 0 )
214 <<
") is processed with stopping code " << istop <<
G4endl;
219#ifdef G4_STORE_TRAJECTORY
222 if(previousTrajectory !=
nullptr)
226 aTrajectory = previousTrajectory;
230 if(trajectoryContainer ==
nullptr)
235 trajectoryContainer->
insert(aTrajectory);
260 "Illegal trackstatus returned from G4TrackingManager."\
261 " Continue with simulation.");
264 if( secondaries !=
nullptr )
266 for(
auto & secondarie : *secondaries)
267 {
delete secondarie; }
268 secondaries->clear();
281 trackingManagersToFlush.clear();
291 if ( verboseLevel > 0 )
293 G4cout <<
"NULL returned from G4StackManager." <<
G4endl;
294 G4cout <<
"Terminate current event processing." <<
G4endl;
298 if(sdManager !=
nullptr)
303#if defined(GEANT4_USE_TIMEMORY)
304 eventProfiler.reset();
307 if(userEventAction !=
nullptr)
313 currentEvent =
nullptr;
314 abortRequested =
false;
320 if( trackVector !=
nullptr )
322 if( trackVector->empty() )
return;
323 for(
auto newTrack : *trackVector )
328 newTrack->SetTrackID( trackIDCounter );
329 if(newTrack->GetDynamicParticle()->GetPrimaryParticle() !=
nullptr)
333 pp->SetTrackID(trackIDCounter);
336 newTrack->SetOriginTouchableHandle(newTrack->GetTouchableHandle());
339 if ( verboseLevel > 1 )
341 G4cout <<
"A new track " << newTrack
342 <<
" (trackID " << newTrack->GetTrackID()
343 <<
", parentID " << newTrack->GetParentID()
344 <<
") is passed to G4StackManager." <<
G4endl;
348 trackVector->clear();
354 userEventAction = userAction;
355 if(userEventAction !=
nullptr)
363 userStackingAction = userAction;
369 userTrackingAction = userAction;
375 userSteppingAction = userAction;
382 DoProcessing(anEvent);
389 if (randStat ==
nullptr) randStat =
new G4String;
392 if(anEvent ==
nullptr)
397 if (storetRandomNumberStatusToG4Event==1
398 || storetRandomNumberStatusToG4Event==3)
400 std::ostringstream oss;
402 (*randStat) = oss.str();
406 DoProcessing(anEvent);
407 if(tempEvent) {
delete anEvent; }
417 "G4VUserEventInformation cannot be set because of absence "\
438 if(currentEvent !=
nullptr) { currentEvent->
KeepTheEvent(); }
443 abortRequested =
true;
444 trackContainer->
clear();
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
@ 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)
void ProcessOneEvent(G4Event *anEvent)
G4VUserEventInformation * GetUserInformation()
G4int GetNumberOfPrimaryVertex() const
void SetRandomNumberStatus(G4String &st)
void KeepTheEvent(G4bool vl=true)
G4HCofThisEvent * GetHCofThisEvent() const
void SetRandomNumberStatusForProcessing(G4String &st)
void SetHCofThisEvent(G4HCofThisEvent *value)
void SetUserInformation(G4VUserEventInformation *anInfo)
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
G4Track * PopNextTrack(G4VTrajectory **newTrajectory)
G4int PushOneTrack(G4Track *newTrack, G4VTrajectory *newTrajectory=nullptr)
void SetUserStackingAction(G4UserStackingAction *value)
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
G4bool SetNewState(const G4ApplicationState &requestedState)
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 BeginOfEventAction(const G4Event *anEvent)
virtual void EndOfEventAction(const G4Event *anEvent)
virtual void HandOverOneTrack(G4Track *aTrack)=0
virtual void MergeTrajectory(G4VTrajectory *secondTrajectory)=0