Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4EventManager.cc
이 파일의 문서화 페이지로 가기
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 //
27 // $Id: G4EventManager.cc 104522 2017-06-02 07:19:30Z gcosmo $
28 //
29 //
30 //
31 
32 #include "G4EventManager.hh"
33 #include "G4ios.hh"
34 #include "G4EvManMessenger.hh"
35 #include "G4Event.hh"
36 #include "G4UserEventAction.hh"
37 #include "G4UserStackingAction.hh"
38 #include "G4SDManager.hh"
39 #include "G4StateManager.hh"
40 #include "G4ApplicationState.hh"
42 #include "G4Navigator.hh"
43 #include "Randomize.hh"
44 
47 { return fpEventManager; }
48 
50 :currentEvent(nullptr),trajectoryContainer(nullptr),
51  trackIDCounter(0),
52  verboseLevel(0),tracking(false),abortRequested(false),
53  storetRandomNumberStatusToG4Event(false)
54 {
55  if(fpEventManager)
56  {
57  G4Exception("G4EventManager::G4EventManager","Event0001",FatalException,
58  "G4EventManager::G4EventManager() has already been made.");
59  }
60  else
61  {
65  theMessenger = new G4EvManMessenger(this);
68  fpEventManager = this;
69  userEventAction = nullptr;
70  userStackingAction = nullptr;
71  userTrackingAction = nullptr;
72  userSteppingAction = nullptr;
73  }
74 }
75 
76 /* private -> never called
77 G4EventManager::G4EventManager(const G4EventManager&) {;}
78 G4EventManager& G4EventManager::operator=(const G4EventManager&)
79 { return *this; }
80 */
81 
83 {
84  delete trackContainer;
85  delete transformer;
86  delete trackManager;
87  delete theMessenger;
88  delete userEventAction;
89  fpEventManager = 0;
90 }
91 
92 /*
93 const G4EventManager & G4EventManager::operator=(const G4EventManager &right)
94 { }
95 G4int G4EventManager::operator==(const G4EventManager &right) const { }
96 G4int G4EventManager::operator!=(const G4EventManager &right) const { }
97 */
98 
100 {
101  abortRequested = false;
103  if(currentState!=G4State_GeomClosed)
104  {
105  G4Exception("G4EventManager::ProcessOneEvent",
106  "Event0002", JustWarning,
107  "IllegalApplicationState -- Geometry is not closed : cannot process an event.");
108  return;
109  }
110  currentEvent = anEvent;
113  {
114  std::ostringstream oss;
116  randomNumberStatusToG4Event = oss.str();
118  }
119 
120  // Reseting Navigator has been moved to G4EventManager, so that resetting
121  // is now done for every event.
122  G4ThreeVector center(0,0,0);
123  G4Navigator* navigator =
125  navigator->LocateGlobalPointAndSetup(center,0,false);
126 
127  G4Track * track = nullptr;
128  G4TrackStatus istop = fAlive;
129 
130 #ifdef G4VERBOSE
131  if ( verboseLevel > 0 )
132  {
133  G4cout << "=====================================" << G4endl;
134  G4cout << " G4EventManager::ProcessOneEvent() " << G4endl;
135  G4cout << "=====================================" << G4endl;
136  }
137 #endif
138 
140 
141 #ifdef G4_STORE_TRAJECTORY
142  trajectoryContainer = nullptr;
143 #endif
144 
146  if(sdManager)
148 
150 
151 #ifdef G4VERBOSE
152  if ( verboseLevel > 1 )
153  {
155  << " vertices passed from G4Event." << G4endl;
156  }
157 #endif
158 
159  if(!abortRequested)
161 
162 #ifdef G4VERBOSE
163  if ( verboseLevel > 0 )
164  {
165  G4cout << trackContainer->GetNTotalTrack() << " primaries "
166  << "are passed from G4EventTransformer." << G4endl;
167  G4cout << "!!!!!!! Now start processing an event !!!!!!!" << G4endl;
168  }
169 #endif
170 
171  G4VTrajectory* previousTrajectory;
172  while( ( track = trackContainer->PopNextTrack(&previousTrajectory) ) != 0 ) // Loop checking 12.28.2015 M.Asai
173  {
174 
175 #ifdef G4VERBOSE
176  if ( verboseLevel > 1 )
177  {
178  G4cout << "Track " << track << " (trackID " << track->GetTrackID()
179  << ", parentID " << track->GetParentID()
180  << ") is passed to G4TrackingManager." << G4endl;
181  }
182 #endif
183 
184  tracking = true;
185  trackManager->ProcessOneTrack( track );
186  istop = track->GetTrackStatus();
187  tracking = false;
188 
189 #ifdef G4VERBOSE
190  if ( verboseLevel > 0 )
191  {
192  G4cout << "Track (trackID " << track->GetTrackID()
193  << ", parentID " << track->GetParentID()
194  << ") is processed with stopping code " << istop << G4endl;
195  }
196 #endif
197 
198  G4VTrajectory * aTrajectory = nullptr;
199 #ifdef G4_STORE_TRAJECTORY
200  aTrajectory = trackManager->GimmeTrajectory();
201 
202  if(previousTrajectory)
203  {
204  previousTrajectory->MergeTrajectory(aTrajectory);
205  delete aTrajectory;
206  aTrajectory = previousTrajectory;
207  }
208  if(aTrajectory&&(istop!=fStopButAlive)&&(istop!=fSuspend))
209  {
213  trajectoryContainer->insert(aTrajectory);
214  }
215 #endif
216 
217  G4TrackVector * secondaries = trackManager->GimmeSecondaries();
218  switch (istop)
219  {
220  case fStopButAlive:
221  case fSuspend:
222  trackContainer->PushOneTrack( track, aTrajectory );
223  StackTracks( secondaries );
224  break;
225 
227  trackContainer->PushOneTrack( track );
228  StackTracks( secondaries );
229  break;
230 
231  case fStopAndKill:
232  StackTracks( secondaries );
233  delete track;
234  break;
235 
236  case fAlive:
237  G4Exception("G4EventManager::DoProcessing","Event004",JustWarning,
238  "Illegal trackstatus returned from G4TrackingManager. Continue with"\
239  "simulation.");
240  break;
242  //if( secondaries ) secondaries->clearAndDestroy();
243  if( secondaries )
244  {
245  for(size_t i=0;i<secondaries->size();i++)
246  { delete (*secondaries)[i]; }
247  secondaries->clear();
248  }
249  delete track;
250  break;
251  }
252  }
253 
254 #ifdef G4VERBOSE
255  if ( verboseLevel > 0 )
256  {
257  G4cout << "NULL returned from G4StackManager." << G4endl;
258  G4cout << "Terminate current event processing." << G4endl;
259  }
260 #endif
261 
262  if(sdManager)
264 
266 
268  currentEvent = nullptr;
269  abortRequested = false;
270 }
271 
272 void G4EventManager::StackTracks(G4TrackVector *trackVector,G4bool IDhasAlreadySet)
273 {
274  if( trackVector )
275  {
276  //size_t n_passedTrack = trackVector->size();
277  //if( n_passedTrack == 0 ) return;
278  //for( size_t i = 0; i < n_passedTrack; i++ )
279  //{
280  // newTrack = (*trackVector)[ i ];
281  if( trackVector->size() == 0 ) return;
282  for( auto newTrack : *trackVector )
283  {
284  trackIDCounter++;
285  if(!IDhasAlreadySet)
286  {
287  newTrack->SetTrackID( trackIDCounter );
288  if(newTrack->GetDynamicParticle()->GetPrimaryParticle())
289  {
291  = (G4PrimaryParticle*)(newTrack->GetDynamicParticle()->GetPrimaryParticle());
293  }
294  }
295  newTrack->SetOriginTouchableHandle(newTrack->GetTouchableHandle());
296  trackContainer->PushOneTrack( newTrack );
297 #ifdef G4VERBOSE
298  if ( verboseLevel > 1 )
299  {
300  G4cout << "A new track " << newTrack
301  << " (trackID " << newTrack->GetTrackID()
302  << ", parentID " << newTrack->GetParentID()
303  << ") is passed to G4StackManager." << G4endl;
304  }
305 #endif
306  }
307  trackVector->clear();
308  }
309 }
310 
312 {
313  userEventAction = userAction;
315 }
316 
318 {
319  userStackingAction = userAction;
321 }
322 
324 {
325  userTrackingAction = userAction;
326  trackManager->SetUserAction(userAction);
327 }
328 
330 {
331  userSteppingAction = userAction;
332  trackManager->SetUserAction(userAction);
333 }
334 
336 {
337  trackIDCounter = 0;
338  DoProcessing(anEvent);
339 }
340 
342 {
343  static G4ThreadLocal G4String *randStat = 0;
344  if (!randStat) randStat = new G4String;
345  trackIDCounter = 0;
346  G4bool tempEvent = false;
347  if(!anEvent)
348  {
349  anEvent = new G4Event();
350  tempEvent = true;
351  }
353  {
354  std::ostringstream oss;
356  anEvent->SetRandomNumberStatus(*randStat=oss.str());
357  }
358  StackTracks(trackVector,false);
359  DoProcessing(anEvent);
360  if(tempEvent)
361  { delete anEvent; }
362 }
363 
365 {
367  if(currentState!=G4State_EventProc || currentEvent==0)
368  {
369  G4Exception("G4EventManager::SetUserInformation",
370  "Event0003", JustWarning,
371  "G4VUserEventInformation cannot be set because of ansense of G4Event.");
372  return;
373  }
374 
376 }
377 
379 {
381  if(currentState!=G4State_EventProc || currentEvent==0)
382  { return 0; }
383 
385 }
386 
389 
391 {
392  abortRequested = true;
395 }
396 
void SetUserAction(G4UserTrackingAction *apAction)
G4TrajectoryContainer * trajectoryContainer
void SetHCofThisEvent(G4HCofThisEvent *value)
Definition: G4Event.hh:117
G4bool SetNewState(G4ApplicationState requestedState)
static std::ostream & saveFullState(std::ostream &os)
Definition: Random.cc:285
G4Track * PopNextTrack(G4VTrajectory **newTrajectory)
void SetUserInformation(G4VUserEventInformation *anInfo)
Definition: G4Event.hh:198
G4PrimaryTransformer * transformer
void SetUserStackingAction(G4UserStackingAction *value)
void StackTracks(G4TrackVector *trackVector, G4bool IDhasAlreadySet=false)
G4UserSteppingAction * userSteppingAction
void ProcessOneEvent(G4Event *anEvent)
#define G4endl
Definition: G4ios.hh:61
G4int GetTrackID() const
void AbortCurrentEvent()
G4Navigator * GetNavigatorForTracking() const
G4StateManager * stateManager
G4HCofThisEvent * PrepareNewEvent()
Definition: G4SDManager.cc:109
G4String randomNumberStatusToG4Event
G4int storetRandomNumberStatusToG4Event
#define G4ThreadLocal
Definition: tls.hh:69
void SetTrajectoryContainer(G4TrajectoryContainer *value)
Definition: G4Event.hh:121
G4int PrepareNewEvent()
void SetUserAction(G4UserEventAction *userAction)
void SetTrackID(G4int id)
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:185
G4TrackVector * GimmeSecondaries() const
virtual void BeginOfEventAction(const G4Event *anEvent)
G4UserEventAction * userEventAction
bool G4bool
Definition: G4Types.hh:79
void SetRandomNumberStatus(G4String &st)
Definition: G4Event.hh:125
virtual void SetEventManager(G4EventManager *value)
G4EvManMessenger * theMessenger
static G4SDManager * GetSDMpointerIfExist()
Definition: G4SDManager.cc:49
G4VUserEventInformation * GetUserInformation()
G4TrackingManager * trackManager
static G4EventManager * GetEventManager()
void KeepTheCurrentEvent()
G4UserStackingAction * userStackingAction
void TerminateCurrentEvent(G4HCofThisEvent *HCE)
Definition: G4SDManager.cc:116
G4int GetNTotalTrack() const
void SetUserInformation(G4VUserEventInformation *anInfo)
static G4TransportationManager * GetTransportationManager()
G4Event * currentEvent
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
G4int PushOneTrack(G4Track *newTrack, G4VTrajectory *newTrajectory=0)
G4ApplicationState GetCurrentState() const
void SetRandomNumberStatusForProcessing(G4String &st)
Definition: G4Event.hh:130
G4StackManager * trackContainer
virtual void MergeTrajectory(G4VTrajectory *secondTrajectory)=0
std::vector< G4Track * > G4TrackVector
G4int GetNumberOfPrimaryVertex() const
Definition: G4Event.hh:164
void KeepTheEvent(G4bool vl=true)
Definition: G4Event.hh:135
G4bool insert(G4VTrajectory *p)
static G4ThreadLocal G4EventManager * fpEventManager
G4GLOB_DLL std::ostream G4cout
G4ApplicationState
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=0, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
Definition: G4Navigator.cc:131
void DoProcessing(G4Event *anEvent)
G4VTrajectory * GimmeTrajectory() const
G4SDManager * sdManager
G4TrackStatus GetTrackStatus() const
G4TrackVector * GimmePrimaries(G4Event *anEvent, G4int trackIDCounter=0)
G4VUserEventInformation * GetUserInformation() const
Definition: G4Event.hh:199
G4UserTrackingAction * userTrackingAction
void ProcessOneTrack(G4Track *apValueG4Track)
virtual void EndOfEventAction(const G4Event *anEvent)
G4TrackStatus
static G4StateManager * GetStateManager()
G4int GetParentID() const