Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4StackManager.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: G4StackManager.cc 109173 2018-04-03 06:51:03Z gcosmo $
28 //
29 //
30 // Last Modification : 09/Dec/96 M.Asai
31 //
32 
33 #include "G4StackManager.hh"
34 #include "G4StackingMessenger.hh"
35 #include "G4VTrajectory.hh"
36 #include "evmandefs.hh"
37 #include "G4ios.hh"
38 
40 :userStackingAction(0),verboseLevel(0),numberOfAdditionalWaitingStacks(0)
41 {
43 #ifdef G4_USESMARTSTACK
45  // G4cout<<"+++ G4StackManager uses G4SmartTrackStack. +++"<<G4endl;
46 #else
47  urgentStack = new G4TrackStack(5000);
48 // G4cout<<"+++ G4StackManager uses ordinary G4TrackStack. +++"<<G4endl;
49 #endif
50  waitingStack = new G4TrackStack(1000);
51  postponeStack = new G4TrackStack(1000);
52 }
53 
55 {
57 
58 #ifdef G4VERBOSE
59  if(verboseLevel>0)
60  {
61  G4cout << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << G4endl;
62  G4cout << " Maximum number of tracks in the urgent stack : " << urgentStack->GetMaxNTrack() << G4endl;
63  G4cout << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << G4endl;
64  }
65 #endif
66  delete urgentStack;
67  delete waitingStack;
68  delete postponeStack;
69  delete theMessenger;
71  for(int i=0;i<numberOfAdditionalWaitingStacks;i++) {
72  delete additionalWaitingStacks[i];
73  }
74  }
75 }
76 
77 const G4StackManager & G4StackManager::operator=
78 (const G4StackManager &) { return *this; }
80 const{ return false; }
82 const{ return true; }
83 
84 #include "G4ParticleDefinition.hh"
85 #include "G4VProcess.hh"
86 
87 //Needed for temporal service
88 #include "G4ParticleTable.hh"
89 #include "G4ProcessManager.hh"
90 #include "G4ProcessVector.hh"
91 
93 {
94  const G4ParticleDefinition* pd = newTrack->GetParticleDefinition();
95  if(pd->GetParticleDefinitionID() < 0)
96  {
98  ED << "A track without proper process manager is pushed into the track stack.\n"
99  << " Particle name : " << pd->GetParticleName() << " -- ";
100  if(newTrack->GetParentID()<0)
101  { ED << "created by a primary particle generator."; }
102  else
103  {
104  const G4VProcess* vp = newTrack->GetCreatorProcess();
105  if(vp)
106  { ED << "created by " << vp->GetProcessName() << "."; }
107  else
108  { ED << "creaded by unknown process."; }
109  }
110  G4Exception("G4StackManager::PushOneTrack","Event10051",
111  FatalException,ED);
112  delete newTrack;
113  return GetNUrgentTrack();
114  }
115 
116  G4ClassificationOfNewTrack classification = DefaultClassification( newTrack );
117  if(userStackingAction)
118  { classification = userStackingAction->ClassifyNewTrack( newTrack ); }
119 
120  if(classification==fKill) // delete newTrack without stacking
121  {
122 #ifdef G4VERBOSE
123  if( verboseLevel > 1 )
124  {
125  G4cout << " ---> G4Track " << newTrack << " (trackID "
126  << newTrack->GetTrackID() << ", parentID "
127  << newTrack->GetParentID() << ") is not to be stored." << G4endl;
128  }
129 #endif
130  delete newTrack;
131  delete newTrajectory;
132  }
133  else
134  {
135  G4StackedTrack newStackedTrack( newTrack, newTrajectory );
136  switch (classification)
137  {
138  case fUrgent:
139  urgentStack->PushToStack( newStackedTrack );
140  break;
141  case fWaiting:
142  waitingStack->PushToStack( newStackedTrack );
143  break;
144  case fPostpone:
145  postponeStack->PushToStack( newStackedTrack );
146  break;
147  default:
148  G4int i = classification - 10;
151  ED << "invalid classification " << classification << G4endl;
152  G4Exception("G4StackManager::PushOneTrack","Event0051",
153  FatalException,ED);
154  } else {
155  additionalWaitingStacks[i-1]->PushToStack( newStackedTrack );
156  }
157  break;
158  }
159  }
160 
161  return GetNUrgentTrack();
162 }
163 
164 
166 {
167 #ifdef G4VERBOSE
168  if( verboseLevel > 1 )
169  {
170  G4cout << "### pop requested out of "
171  << GetNUrgentTrack() << " stacked tracks." << G4endl;
172  }
173 #endif
174 
175  while( GetNUrgentTrack() == 0 )
176  {
177 #ifdef G4VERBOSE
178  if( verboseLevel > 1 ) G4cout << "### " << GetNWaitingTrack()
179  << " waiting tracks are re-classified to" << G4endl;
180 #endif
183  for(int i=0;i<numberOfAdditionalWaitingStacks;i++) {
184  if(i==0) {
185  additionalWaitingStacks[0]->TransferTo(waitingStack);
186  } else {
188  }
189  }
190  }
192 #ifdef G4VERBOSE
193  if( verboseLevel > 1 ) G4cout << " " << GetNUrgentTrack()
194  << " urgent tracks and " << GetNWaitingTrack()
195  << " waiting tracks." << G4endl;
196 #endif
197  if( ( GetNUrgentTrack()==0 ) && ( GetNWaitingTrack()==0 ) ) return 0;
198  }
199 
200  G4StackedTrack selectedStackedTrack = urgentStack->PopFromStack();
201  G4Track * selectedTrack = selectedStackedTrack.GetTrack();
202  *newTrajectory = selectedStackedTrack.GetTrajectory();
203 
204 #ifdef G4VERBOSE
205  if( verboseLevel > 2 )
206  {
207  G4cout << "Selected G4StackedTrack : " << &selectedStackedTrack
208  << " with G4Track " << selectedStackedTrack.GetTrack()
209  << " (trackID " << selectedStackedTrack.GetTrack()->GetTrackID()
210  << ", parentID " << selectedStackedTrack.GetTrack()->GetParentID()
211  << ")" << G4endl;
212  }
213 #endif
214 
215  return selectedTrack;
216 }
217 
219 {
220  G4StackedTrack aStackedTrack;
221  G4TrackStack tmpStack;
222 
223  if( !userStackingAction ) return;
224  if( GetNUrgentTrack() == 0 ) return;
225 
226  urgentStack->TransferTo(&tmpStack);
227  while( tmpStack.GetNTrack() > 0 )
228  {
229  aStackedTrack=tmpStack.PopFromStack();
230  G4ClassificationOfNewTrack classification =
231  userStackingAction->ClassifyNewTrack( aStackedTrack.GetTrack() );
232  switch (classification)
233  {
234  case fKill:
235  delete aStackedTrack.GetTrack();
236  delete aStackedTrack.GetTrajectory();
237  break;
238  case fUrgent:
239  urgentStack->PushToStack( aStackedTrack );
240  break;
241  case fWaiting:
242  waitingStack->PushToStack( aStackedTrack );
243  break;
244  case fPostpone:
245  postponeStack->PushToStack( aStackedTrack );
246  break;
247  default:
248  G4int i = classification - 10;
251  ED << "invalid classification " << classification << G4endl;
252  G4Exception("G4StackManager::ReClassify","Event0052",
253  FatalException,ED);
254  } else {
255  additionalWaitingStacks[i-1]->PushToStack( aStackedTrack );
256  }
257  break;
258  }
259  }
260 }
261 
263 {
265 
266  urgentStack->clearAndDestroy(); // Set the urgentStack in a defined state. Not doing it would affect reproducibility.
267 
268  G4int n_passedFromPrevious = 0;
269 
270  if( GetNPostponedTrack() > 0 )
271  {
272 #ifdef G4VERBOSE
273  if( verboseLevel > 1 )
274  {
276  << " postponed tracked are now shifted to the stack." << G4endl;
277  }
278 #endif
279 
280  G4StackedTrack aStackedTrack;
281  G4TrackStack tmpStack;
282 
283  postponeStack->TransferTo(&tmpStack);
284 
285  while( tmpStack.GetNTrack() > 0 )
286  {
287  aStackedTrack=tmpStack.PopFromStack();
288  G4Track* aTrack = aStackedTrack.GetTrack();
289  aTrack->SetParentID(-1);
290  G4ClassificationOfNewTrack classification;
292  { classification = userStackingAction->ClassifyNewTrack( aTrack ); }
293  else
294  { classification = DefaultClassification( aTrack ); }
295 
296  if(classification==fKill)
297  {
298  delete aTrack;
299  delete aStackedTrack.GetTrajectory();
300  }
301  else
302  {
303  aTrack->SetTrackID(-(++n_passedFromPrevious));
304  switch (classification)
305  {
306  case fUrgent:
307  urgentStack->PushToStack( aStackedTrack );
308  break;
309  case fWaiting:
310  waitingStack->PushToStack( aStackedTrack );
311  break;
312  case fPostpone:
313  postponeStack->PushToStack( aStackedTrack );
314  break;
315  default:
316  G4int i = classification - 10;
319  ED << "invalid classification " << classification << G4endl;
320  G4Exception("G4StackManager::PrepareNewEvent","Event0053",
321  FatalException,ED);
322  } else {
323  additionalWaitingStacks[i-1]->PushToStack( aStackedTrack );
324  }
325  break;
326  }
327  }
328  }
329  }
330 
331  return n_passedFromPrevious;
332 }
333 
335 {
337  {
338  for(int i=numberOfAdditionalWaitingStacks;i<iAdd;i++)
339  {
340  G4TrackStack* newStack = new G4TrackStack;
341  additionalWaitingStacks.push_back(newStack);
342  }
344  }
345  else if (iAdd < numberOfAdditionalWaitingStacks)
346  {
347  for(int i=numberOfAdditionalWaitingStacks;i>iAdd;i--)
348  {
349  delete additionalWaitingStacks[i];
350  }
351  }
352 }
353 
355 {
356  if(origin==destination) return;
357  if(origin==fKill) return;
358  G4TrackStack* originStack = 0;
359  switch(origin)
360  {
361  case fUrgent:
362  originStack = 0;
363  break;
364  case fWaiting:
365  originStack = waitingStack;
366  break;
367  case fPostpone:
368  originStack = postponeStack;
369  break;
370  default:
371  int i = origin - 10;
373  break;
374  }
375 
376  if(destination==fKill)
377  {
378  if(originStack)
379  { originStack->clearAndDestroy(); }
380  else
382  }
383  else
384  {
385  G4TrackStack* targetStack = 0;
386  switch(destination)
387  {
388  case fUrgent:
389  targetStack = 0;
390  break;
391  case fWaiting:
392  targetStack = waitingStack;
393  break;
394  case fPostpone:
395  targetStack = postponeStack;
396  break;
397  default:
398  int i = destination - 10;
400  break;
401  }
402  if(originStack)
403  {
404  if(targetStack)
405  { originStack->TransferTo(targetStack); }
406  else
407  { originStack->TransferTo(urgentStack); }
408  }
409  else
410  { urgentStack->TransferTo(targetStack); }
411  }
412  return;
413 }
414 
416 {
417  if(origin==destination) return;
418  if(origin==fKill) return;
419  G4TrackStack* originStack = 0;
420  switch(origin)
421  {
422  case fUrgent:
423  originStack = 0;
424  break;
425  case fWaiting:
426  originStack = waitingStack;
427  break;
428  case fPostpone:
429  originStack = postponeStack;
430  break;
431  default:
432  int i = origin - 10;
434  break;
435  }
436 
437  G4StackedTrack aStackedTrack;
438  if(destination==fKill)
439  {
440  if( originStack && originStack->GetNTrack() ) {
441  aStackedTrack = originStack->PopFromStack();
442  delete aStackedTrack.GetTrack();
443  delete aStackedTrack.GetTrajectory();
444  }
445  else if (urgentStack->GetNTrack() ) {
446  aStackedTrack = urgentStack->PopFromStack();
447  delete aStackedTrack.GetTrack();
448  delete aStackedTrack.GetTrajectory();
449  }
450  }
451  else
452  {
453  G4TrackStack* targetStack = 0;
454  switch(destination)
455  {
456  case fUrgent:
457  targetStack = 0;
458  break;
459  case fWaiting:
460  targetStack = waitingStack;
461  break;
462  case fPostpone:
463  targetStack = postponeStack;
464  break;
465  default:
466  int i = destination - 10;
468  break;
469  }
470  if(originStack && originStack->GetNTrack()) {
471  aStackedTrack = originStack->PopFromStack();
472  if(targetStack) { targetStack->PushToStack(aStackedTrack); }
473  else { urgentStack->PushToStack(aStackedTrack); }
474  }
475  else if(urgentStack->GetNTrack()) {
476  aStackedTrack = urgentStack->PopFromStack();
477  if(targetStack) { targetStack->PushToStack(aStackedTrack); }
478  else { urgentStack->PushToStack(aStackedTrack); }
479  }
480  }
481  return;
482 }
483 
485 {
488  for(int i=1;i<=numberOfAdditionalWaitingStacks;i++) {ClearWaitingStack(i);}
489 }
490 
492 {
494 }
495 
497 {
498  if(i==0) {
500  } else {
501  if(i<=numberOfAdditionalWaitingStacks) additionalWaitingStacks[i-1]->clearAndDestroy();
502  }
503 }
504 
506 {
508 }
509 
511 {
513  for(int i=1;i<=numberOfAdditionalWaitingStacks;i++) {n += additionalWaitingStacks[i-1]->GetNTrack();}
514  return n;
515 }
516 
518 {
519  return urgentStack->GetNTrack();
520 }
521 
523 {
524  if(i==0) { return waitingStack->GetNTrack(); }
525  else {
526  if(i<=numberOfAdditionalWaitingStacks) { return additionalWaitingStacks[i-1]->GetNTrack();}
527  }
528  return 0;
529 }
530 
532 {
533  return postponeStack->GetNTrack();
534 }
535 
537 {
539 }
540 
542 {
545 }
546 
548 {
549  G4ClassificationOfNewTrack classification = fUrgent;
550  if( aTrack->GetTrackStatus() == fPostponeToNextEvent )
551  { classification = fPostpone; }
552  return classification;
553 }
554 
555 
556 
557 
G4int numberOfAdditionalWaitingStacks
void SetStackManager(G4StackManager *value)
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
G4Track * PopNextTrack(G4VTrajectory **newTrajectory)
void ClearPostponeStack()
std::vector< G4TrackStack * > additionalWaitingStacks
void SetTrackID(const G4int aValue)
void SetUserStackingAction(G4UserStackingAction *value)
void ClearWaitingStack(int i=0)
#define G4endl
Definition: G4ios.hh:61
const G4String & GetParticleName() const
G4int GetTrackID() const
G4TrackStack * waitingStack
void PushToStack(const G4StackedTrack &aStackedTrack)
Definition: G4TrackStack.hh:62
G4int GetNWaitingTrack(int i=0) const
G4int operator==(const G4StackManager &right) const
void SetNumberOfAdditionalWaitingStacks(G4int iAdd)
const G4ParticleDefinition * GetParticleDefinition() const
G4int PrepareNewEvent()
G4int GetNTrack() const
Definition: G4TrackStack.hh:74
G4int GetParticleDefinitionID() const
G4int GetMaxNTrack() const
Definition: G4TrackStack.hh:75
const XML_Char int const XML_Char * value
Definition: expat.h:331
G4int GetNPostponedTrack() const
virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *aTrack)
G4ClassificationOfNewTrack DefaultClassification(G4Track *aTrack)
G4StackingMessenger * theMessenger
G4TrackStack * urgentStack
const G4String & GetProcessName() const
Definition: G4VProcess.hh:411
G4StackedTrack PopFromStack()
Definition: G4TrackStack.hh:63
void clearAndDestroy()
Definition: G4TrackStack.cc:40
G4TrackStack * postponeStack
void TransferOneStackedTrack(G4ClassificationOfNewTrack origin, G4ClassificationOfNewTrack destination)
void SetVerboseLevel(G4int const value)
G4int GetNUrgentTrack() const
G4UserStackingAction * userStackingAction
G4int GetNTotalTrack() const
virtual void PrepareNewEvent()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
G4int operator!=(const G4StackManager &right) const
void TransferTo(G4TrackStack *aStack)
Definition: G4TrackStack.cc:49
int G4int
Definition: G4Types.hh:78
G4int PushOneTrack(G4Track *newTrack, G4VTrajectory *newTrajectory=0)
void SetParentID(const G4int aValue)
const G4VProcess * GetCreatorProcess() const
G4GLOB_DLL std::ostream G4cout
void TransferStackedTracks(G4ClassificationOfNewTrack origin, G4ClassificationOfNewTrack destination)
Char_t n[5]
G4TrackStatus GetTrackStatus() const
G4VTrajectory * GetTrajectory() const
G4Track * GetTrack() const
G4int GetParentID() const