Geant4  10.01.p02
G4Scheduler.cc
Go to the documentation of this file.
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 // $Id: G4Scheduler.cc 60494 2012-07-12 14:49:30Z gcosmo $
27 //
28 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
29 //
30 // History:
31 // -----------
32 // 10 Oct 2011 M.Karamitros created
33 //
34 // -------------------------------------------------------------------
35 
36 #include <G4AllITFinder.hh>
37 #include <G4Scheduler.hh>
38 #include <G4SchedulerMessenger.hh>
39 
40 #include "G4SystemOfUnits.hh"
41 #include "G4ITModelProcessor.hh"
42 #include "G4ITStepProcessor.hh"
43 #include "G4IT.hh"
44 #include "G4ITReactionChange.hh"
45 #include "G4ITModelHandler.hh"
46 #include "G4VITStepModel.hh"
47 #include "G4UserTimeStepAction.hh"
48 #include "G4ITTrackingManager.hh"
50 #include "G4TrackingInformation.hh"
51 #include "G4UnitsTable.hh"
52 #include "G4ITStepStatus.hh"
53 #include "G4ITGun.hh"
54 #include "G4StateManager.hh"
55 #include "G4Timer.hh"
56 #include <sstream>
57 
58 //#define DEBUG_MEM 1
59 #define DEBUG_MEM_STEPPING
60 #define DEBUG_MEM_DETAILED_STEPPING
61 //#define DEBUG_MEM_DOIT
62 
63 #ifdef DEBUG_MEM
64 #include "G4MemStat.hh"
65 using namespace G4MemStat;
66 using G4MemStat::MemStat;
67 #endif
68 
69 //COLOR FOR DEBUGING
70 //#define USE_COLOR 1
71 
72 #ifdef USE_COLOR
73 #define RED "\033[0;31m"
74 #define LIGHT_RED "\33[1;31m"
75 #define GREEN "\033[32;40m"
76 #define GREEN_ON_BLUE "\033[1;32;44m"
77 #define RESET_COLOR "\033[0m"
78 #else
79 #define RED ""
80 #define LIGHT_RED ""
81 #define GREEN ""
82 #define GREEN_ON_BLUE ""
83 #define RESET_COLOR ""
84 #endif
85 
86 using namespace std;
87 
89 
91 {
92 public:
93  explicit IosFlagSaver(std::ostream& _ios) :
94  ios(_ios), f(_ios.flags())
95  {
96  }
98  {
99  ios.flags(f);
100  }
101 
102  // IosFlagSaver(const IosFlagSaver &rhs) = delete;
103  // IosFlagSaver& operator= (const IosFlagSaver& rhs) = delete;
104 
105 private:
106  std::ostream& ios;
107  std::ios::fmtflags f;
108 };
109 
110 template<typename T>
111  inline bool IsInf(T value)
112  {
113  return std::numeric_limits<T>::has_infinity
114  && value == std::numeric_limits<T>::infinity();
115  }
116 //_________________________________________________________________________
117 
119 {
120  if (fgScheduler == 0) fgScheduler = new G4Scheduler();
121  return fgScheduler;
122 }
123 //_________________________________________________________________________
124 
126 {
127  if (requestedState == G4State_Quit)
128  {
129  if (fVerbose >= 4)
130  {
131  G4cout << "G4Scheduler received G4State_Quit" << G4endl;
132  }
133  Clear();
134  //DeleteInstance();
135  }
136  return true;
137 }
138 //_________________________________________________________________________
139 
141 {
142  if (fgScheduler)
143  {
144  delete fgScheduler;
145  }
146 }
147 //_________________________________________________________________________
148 
151  fTrackContainer((G4ITTrackHolder&)*G4ITTrackHolder::Instance())
152 {
153  Create();
154 }
155 
157 {
158  fUseDefaultTimeSteps = true;
159  fUserUpperTimeLimit = -1;
160  fpGun = 0;
161  fContinue = true;
162 // fpMainList = 0;
163 // fpWaitingList = 0;
165 
167 
168  fpUserTimeSteps = 0;
169 
170  fTimeStep = DBL_MAX;
174 
175  fZeroTimeCount = 0;
177 
178  fStartTime = 0;
179  fComputeTimeStep = false;
180  fComputeReaction = false;
182  fEndTime = 1 * microsecond;
183  fGlobalTime = -1;
184  fInteractionStep = true;
185  fUsePreDefinedTimeSteps = false;
186 
188 
189  fpStepProcessor = 0;
190  // fpMasterStepProcessor = 0 ;
191 
192  fpModelProcessor = 0;
193  // fpMasterModelProcessor= 0;
194 
195  fNbSteps = 0;
196  fMaxSteps = -1;
197 
198  fRunning = false;
199  fInitialized = false;
200 
202  fpTrackingManager = 0;
203 
204  fNbTracks = -1;
207 
208  fVerbose = 0;
209  fWhyDoYouStop = false;
210  fDefinedMinTimeStep = -1.;
211  fReachedUserTimeLimit = false;
212  fTmpEndTime = -1.;
213  fTmpGlobalTime = -1.;
214 
216 
218 }
219 
220 //_________________________________________________________________________
221 
223 {
224 
225  if (fSteppingMsg) // is used as a flag to know whether the manager was cleared
226  {
227  Clear();
228  }
229  fgScheduler = 0;
230 
231 // if (fVerbose >= 1)
232 // {
233 // G4cout << "G4Scheduler is being deleted. Bye :) !" << G4endl;
234 // }
235 }
236 
238 {
239 // if (fVerbose) G4cout << "*** G4Scheduler is being cleared ***" << G4endl;
240 
241  if(fSteppingMsg)
242  {
243  delete fSteppingMsg;
244  fSteppingMsg = 0;
245  }
246  if(fpStepProcessor)
247  {
248  delete fpStepProcessor;
249  fpStepProcessor = 0;
250  }
251  if(fpModelProcessor)
252  {
253  delete fpModelProcessor;
254  fpModelProcessor = 0;
255  }
256  if(fpModelHandler)
257  {
258  delete fpModelHandler;
259  fpModelHandler = 0;
260  }
261  // if(fpMasterStepProcessor) delete fpMasterStepProcessor ;
262  // if(fpMasterModelProcessor) delete fpMasterModelProcessor ;
263  G4ITTypeManager::Instance() -> ReleaseRessource();
264  ClearList();
266  {
267  delete fpTrackingManager;
268  fpTrackingManager = 0;
269  }
270 
271  /*
272  * DEBUG
273  * assert(G4StateManager::GetStateManager()->
274  * DeregisterDependent(this) == true);
275  */
276 }
277 
278 //_________________________________________________________________________
279 
281 {
282 // if (fNbTracks == 0) return;
283 
285 
286  fNbTracks = -1;
287 
289 }
290 
291 //_________________________________________________________________________
293 {
294  fpModelHandler->RegisterModel(model, time);
295 }
296 
297 //_________________________________________________________________________
298 
300 {
301  if (fpStepProcessor)
302  {
303  delete fpStepProcessor;
304  }
305  if (fpModelProcessor)
306  {
307  delete fpModelProcessor;
308  }
309  // if(fpMasterModelProcessor)
310  // {
311  // delete fpMasterModelProcessor;
312  // }
313 
314  //______________________________________________________________
315 
318 
319  // fpMasterModelProcessor = new G4ITModelProcessor();
320  // fpMasterModelProcessor->SetModelHandler(fpModelHandler);
321  // fpModelProcessor = fpMasterModelProcessor;
322 
323  //______________________________________________________________
324 
327 
329 
330  // fpMasterStepProcessor = new G4ITStepProcessor();
331  // fpMasterStepProcessor->SetTrackingManager(fpTrackingManager);
332  // fpStepProcessor = fpMasterStepProcessor ;
333 
336  //______________________________________________________________
337 
338  fInitialized = true;
339 }
340 //_________________________________________________________________________
341 
343 {
344  fStartTime = 0;
345  fUserUpperTimeLimit = -1;
346  fTimeStep = DBL_MAX;
350  fGlobalTime = -1;
351  fInteractionStep = true;
353  fZeroTimeCount = 0;
354 
355  fNbSteps = 0;
356  fContinue = true;
357  // fReactingTracks.clear();
358  fLeadingTracks.clear();
360 }
361 //_________________________________________________________________________
362 
364 {
365 
366 #ifdef G4VERBOSE
367  if (fVerbose)
368  {
369  G4cout << "*** G4Scheduler starts processing " << G4endl;
370  if(fVerbose > 2)
371  G4cout << "___________________________________________"
372  "___________________________" << G4endl;
373  }
374 #endif
375 
376  if (fInitialized == false) Initialize();
377 
378  // fpTrackingManager->Initialize();
381 
382  // TODO
383  // fpMasterModelProcessor->Initialize();
384  // fpMasterStepProcessor->Initialize();
385 
386  if (fpGun) fpGun->DefineTracks();
387 
389 
390  // ___________________
391  fRunning = true;
392  Reset();
393 
395 
396 #ifdef G4VERBOSE
397  G4bool trackFound = false;
398 #endif
399 
400  //===========================================================================
401  // By default, before the G4Scheduler is launched, the tracks are pushed to
402  // the delayed lists
403  //===========================================================================
404 
406  {
408 #ifdef G4VERBOSE
409  trackFound = true;
410  G4Timer localtimer;
411  if(fVerbose>1)
412  {
413  localtimer.Start();
414  }
415 #endif
417 #ifdef G4VERBOSE
418  if(fVerbose>1)
419  {
420  localtimer.Stop();
421  G4cout << "G4Scheduler: process time= "<< localtimer << G4endl;
422  }
423 #endif
424  }
425 
426 // //---------------------------------
427 // // TODO: This could be removed ?
428 // if(fTrackContainer.MainListsNOTEmpty()
429 // && (fMaxSteps == -1 ? true : fNbSteps < fMaxSteps)
430 // && fGlobalTime < fEndTime
431 // && fContinue == true)
432 //{
433 //#ifdef G4VERBOSE
434 // trackFound = true;
435 //#endif
436 // DoProcess();
437 //}
438 // //---------------------------------
439 
440 #ifdef G4VERBOSE
441  if(fVerbose)
442  {
443  if(trackFound)
444  {
445  G4cout << "*** G4Scheduler ends at time : "
446  << G4BestUnit(fGlobalTime,"Time") << G4endl;
447  G4cout << "___________________________________" << G4endl;
448  }
449  else
450  {
451  G4cout << "*** G4Scheduler did not start because no "
452  "track was found to be processed"<< G4endl;
453  G4cout << "___________________________________" << G4endl;
454  }
455  }
456 #endif
457 
458  fRunning = false;
459 
461 
462  // ___________________
463  EndTracking();
464  ClearList();
465 
466  Reset();
467 
469 }
470 //_________________________________________________________________________
471 
473 {
474 // if(fTrackContainer.WaitingListsNOTEmpty())
475 // {
476 // G4ExceptionDescription exceptionDescription;
477 // exceptionDescription
478 // << "There is a waiting track list (fpWaitingList != 0).";
479 // exceptionDescription
480 // << " When G4Scheduler::SynchronizeTracks() is called, ";
481 // exceptionDescription
482 // << "no more tracks should remain in the fpWaitingList.";
483 // G4Exception("G4Scheduler::SynchronizeTracks", "ITScheduler002",
484 // FatalErrorInArgument, exceptionDescription);
485 // }
486 
487  // Backup main list and time feature
488  // Reminder : the main list here, should
489  // have the biggest global time
490  // fTrackContainer.MoveMainToWaitingList();
491  // TODO: not yet supported
492 
495 
497  G4double tmpGlobalTime = fGlobalTime;
498  while(fTrackContainer.MergeNextTimeToMainList(tmpGlobalTime))
499  {
500 // assert(tmpGlobalTime == fGlobalTime);
502  DoProcess();
503  }
504 }
505 //_________________________________________________________________________
506 
508 // We split it from the Process() method to avoid repeating code in SynchronizeTracks
509 {
511 
512 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
513  MemStat mem_first, mem_second, mem_diff;
514 #endif
515 
516 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
517  mem_first = MemoryUsage();
518 #endif
519 
520  while (fGlobalTime < fEndTime
522  && (fMaxSteps == -1 ? true : fNbSteps < fMaxSteps)
523  && fContinue == true)
524  {
525 // G4cout << "Mainlist size : " << fTrackContainer.GetMainList()->size()
526 // << G4endl;
527 
528  Stepping();
529 
530 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
531  mem_second = MemoryUsage();
532  mem_diff = mem_second-mem_first;
533  G4cout << "\t || MEM || After step " << fNbSteps << ", diff is : "
534  << mem_diff << G4endl;
535 #endif
536  }
537 
538 #ifdef G4VERBOSE
539  if (fWhyDoYouStop)
540  {
541  G4cout << "G4Scheduler has reached a stage: it might be"
542  " a transition or the end"
543  << G4endl;
544 
545  G4bool normalStop = false;
546 
547  if(fGlobalTime >= fEndTime)
548  {
549  G4cout << "== G4Scheduler: I stop because I reached the final time : "
550  << G4BestUnit(fEndTime,"Time") << " =="<< G4endl;
551  normalStop = true;
552  }
553  if(fTrackContainer.MainListsNOTEmpty() == false) // is empty
554  {
555  G4cout << "G4Scheduler: I stop because the current main list of tracks"
556  "is empty"
557  << G4endl;
558  normalStop = true;
559  }
560  if(fMaxSteps == -1 ? false : fNbSteps >= fMaxSteps)
561  {
562  G4cout << "G4Scheduler: I stop because I reached the maximum allowed "
563  "number of steps=" << fMaxSteps
564  << G4endl;
565  normalStop = true;
566  }
567  if(fContinue && normalStop == false)
568  {
569  G4cout << "G4Scheduler: It might be that I stop because "
570  "I have been told so. You may check "
571  "member fContinue and usage of the method G4Scheduler::Stop()."
572  << G4endl;
573  }
574  }
575 #endif
576 
577 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
578  mem_second = MemoryUsage();
579  mem_diff = mem_second-mem_first;
580  G4cout << "\t || MEM || After stepping, diff is : " << mem_diff << G4endl;
581 #endif
582 
583 #ifdef G4VERBOSE
584  if (fVerbose > 2) G4cout
585  << "*** G4Scheduler has finished processing a track list at time : "
586  << G4BestUnit(fGlobalTime, "Time") << G4endl;
587 #endif
588 }
589 //_________________________________________________________________________
590 
592 {
593  IosFlagSaver iosfs(G4cout);
594  fTimeStep = DBL_MAX;
595 
598 
599  fInteractionStep = false;
600  fReachedUserTimeLimit = false;
601 
603 
604  // Start of step
605 #ifdef G4VERBOSE
606  if (fVerbose > 2)
607  {
608 #ifdef USE_COLOR
609  G4cout << LIGHT_RED;
610 #endif
611  G4cout << "*** Start Of Step N°" << fNbSteps + 1 << " ***" << G4endl;
612  G4cout << "Current Global time : " << G4BestUnit(fGlobalTime, "Time")
613  <<G4endl;
614 #ifdef USE_COLOR
615  G4cout << RESET_COLOR;
616 #endif
617  }
618 #endif
619 
620 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
621  MemStat mem_first, mem_second, mem_diff;
622 #endif
623 
624 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
625  mem_first = MemoryUsage();
626 #endif
627 
629 
631  {
632  if (fpUserTimeSteps == 0) // Extra checking, is it necessary ?
633  {
634  G4ExceptionDescription exceptionDescription;
635  exceptionDescription
636  << "You are asking to use user defined steps but you did not give any.";
637  G4Exception("G4Scheduler::FindUserPreDefinedTimeStep",
638  "ITScheduler004", FatalErrorInArgument,
639  exceptionDescription);
640  return; // makes coverity happy
641  }
642 #ifdef G4VERBOSE
643  if (fVerbose > 2)
644  {
645 #ifdef USE_COLOR
646  G4cout << LIGHT_RED;
647 #endif
648  G4cout << "*** At time : " << G4BestUnit(fGlobalTime, "Time")
649  << " the chosen user time step is : "
650  << G4BestUnit(fDefinedMinTimeStep, "Time") << " ***" << G4endl;
651 #ifdef USE_COLOR
652  G4cout << RESET_COLOR;
653 #endif
654  }
655 #endif
656  }
657 
658  if (fComputeTimeStep)
659  {
660  CalculateMinTimeStep(); // => at least N (N = nb of tracks) loops
661  }
662  else if(fUseDefaultTimeSteps)
663  {
665  }
666 
667 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
668  mem_second = MemoryUsage();
669  mem_diff = mem_second-mem_first;
670  G4cout << "|| MEM || After computing TS, diff is : " << mem_diff << G4endl;
671 #endif
672 
673 #ifdef G4VERBOSE
674  if (fVerbose > 2)
675  {
676 #ifdef USE_COLOR
677  G4cout << LIGHT_RED;
678 #endif
679  G4cout << "*** Time stepper returned : " << G4BestUnit(fTSTimeStep, "Time")
680  << " ***" << G4endl;
681 #ifdef USE_COLOR
682  G4cout << RESET_COLOR;
683 #endif
684  }
685 #endif
686 
687 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
688  mem_first = MemoryUsage();
689 #endif
690 
691  // Call IL even if fTSTimeStep == 0
692  // if fILTimeStep == 0 give the priority to DoIt processes
693  ComputeInteractionLength(); // => at least N loops
694  // All process returns the physical step of interaction
695  // using the approximation : E = cste along the step
696  // Only the transportation calculates the corresponding
697  // time step
698 
699 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
700  mem_second = MemoryUsage();
701  mem_diff = mem_second-mem_first;
702  G4cout << "|| MEM || After IL, diff is : " << mem_diff << G4endl;
703 #endif
704 
705 #ifdef G4VERBOSE
706  if (fVerbose > 2)
707  {
708 #ifdef USE_COLOR
709  G4cout << LIGHT_RED;
710 #endif
711  G4cout << "*** The minimum time returned by the processes is : "
712  << G4BestUnit(fILTimeStep, "Time") << " ***" << G4endl;
713 #ifdef USE_COLOR
714  G4cout << RESET_COLOR;
715 #endif
716  }
717 #endif
718 
719 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
720  mem_first = MemoryUsage();
721 #endif
722 
723  if (fILTimeStep <= fTSTimeStep)
724  // Give the priority to the IL
725  {
726  fInteractionStep = true;
727 // fReactingTracks.clear(); // Give the priority to the IL
731  }
732  else
733  {
734  fInteractionStep = false;
738  }
739 
741  // This check is done at very time step
742  {
744  fITStepStatus = eInteractionWithMedium; // ie: transportation
745  fInteractionStep = true;
746 // fReactingTracks.clear();
749  }
750 
751  if (fTimeStep == 0) // < fTimeTolerance)
752  {
753  fZeroTimeCount++;
755  {
756  G4ExceptionDescription exceptionDescription;
757 
758  exceptionDescription << "Too many zero time steps were detected. ";
759  exceptionDescription << "The simulation is probably stuck. ";
760  exceptionDescription
761  << "The maximum number of zero time steps is currently : "
763  exceptionDescription << ".";
764 
765  G4Exception("G4Scheduler::Stepping", "ITSchedulerNullTimeSteps",
766  FatalErrorInArgument, exceptionDescription);
767  }
768  }
769  else
770  {
771  fZeroTimeCount = 0;
772  }
773 
775  ((fTimeStep <= fDefinedMinTimeStep) || ((fTimeStep > fDefinedMinTimeStep)
777  true : false;
778 
780  // TODO: pre/post
781 
782 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
783  mem_second = MemoryUsage();
784  mem_diff = mem_second-mem_first;
785  G4cout << "|| MEM || After LeadingTracks and UserPreTimeStepAction: "
786  << mem_diff << G4endl;
787 #endif
788 
789 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
790  mem_first = MemoryUsage();
791 #endif
792 
793  // if fTSTimeStep > 0 => needs to call the transportation process
794  // if fILTimeStep < fTSTimeStep => call DoIt processes
795  // if fILTimeStep == fTSTimeStep => give the priority to the DoIt processes
796  if (fTSTimeStep > 0 || fILTimeStep <= fTSTimeStep)
797  {
798  // G4cout << "Will call DoIT" << G4endl;
799  DoIt();
800 
802  KillTracks();
803  }
804  // else
805  // {
806  // G4cout << "fTSTimeStep : " << fTSTimeStep << G4endl;
807  // G4cout << "fILTimeStep : " << fILTimeStep << G4endl;
808  // }
809 
810 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
811  mem_second = MemoryUsage();
812  mem_diff = mem_second-mem_first;
813  G4cout << "|| MEM || After DoIT, diff is : " << mem_diff << G4endl;
814 #endif
815 
817 
818 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
819  mem_first = MemoryUsage();
820 #endif
821 
823 
825 
827 
828  fNbSteps++;
829 
831  {
833  }
834 
836 
837 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
838  mem_second = MemoryUsage();
839  mem_diff = mem_second-mem_first;
840  G4cout << "|| MEM || After computing reactions + UserPostTimeStepAction, "
841  "diff is : " << mem_diff << G4endl;
842 #endif
843 
844  // End of step
845 #ifdef G4VERBOSE
846  if (fVerbose >= 2)
847  {
848 #ifdef USE_COLOR
849  G4cout << LIGHT_RED;
850 #endif
851 
852  G4String interactionType;
853  GetCollisionType(interactionType);
854 
855  std::stringstream finalOutput;
856 
857  finalOutput << "*** End of step N°" << fNbSteps
858  << "\t T_i= " << G4BestUnit(fGlobalTime-fTimeStep, "Time")
859  << "\t dt= " << G4BestUnit(fTimeStep, "Time")
860  << "\t T_f= " << G4BestUnit(fGlobalTime, "Time")
861  << "\t " << interactionType
862  << G4endl;
863 
864  if(fVerbose>2)
865  {
867  {
868  finalOutput << "It has also reached the user time limit" << G4endl;
869  }
870  finalOutput << "_______________________________________________________________"
871  "_______"<< G4endl;
872  }
873 
874  G4cout << finalOutput.str();
875 
876 #ifdef USE_COLOR
877  G4cout << RESET_COLOR;
878 #endif
879  }
880 #endif
881 
882 }
883 //_________________________________________________________________________
884 
886 {
887  if (fpUserTimeSteps == 0) return fDefaultMinTimeStep;
889  return fDefinedMinTimeStep;
890 
891  map<double, double>::const_iterator it_fpUserTimeSteps_i = fpUserTimeSteps
892  ->upper_bound(fGlobalTime);
893  map<double, double>::const_iterator it_fpUserTimeSteps_low = fpUserTimeSteps
894  ->lower_bound(fGlobalTime);
895 
896  // DEBUG
897  // G4cout << "fGlobalTime : " << G4BestUnit(fGlobalTime,"Time")
898  // << G4endl;
899  // G4cout << "fpUserTimeSteps_i : "
900  // <<"<"<<G4BestUnit(it_fpUserTimeSteps->first,"Time")
901  // <<", "<< G4BestUnit(it_fpUserTimeSteps->second,"Time")<<">"
902  // << "\t fpUserTimeSteps_low : "
903  // <<"<"<<G4BestUnit(fpUserTimeSteps_low->first,"Time")<<", "*
904  // << G4BestUnit(fpUserTimeSteps_low->second,"Time")<<">"
905  // << G4endl;
906 
907  if (it_fpUserTimeSteps_i == fpUserTimeSteps->end())
908  {
909  it_fpUserTimeSteps_i--;
911  }
912  else if (fabs(fGlobalTime - it_fpUserTimeSteps_low->first) < fTimeTolerance)
913  {
914  // Case : fGlobalTime = X picosecond
915  // and fpUserTimeSteps_low->first = X picosecond
916  // but the precision is not good enough
917  it_fpUserTimeSteps_i = it_fpUserTimeSteps_low;
918  map<double, double>::const_iterator tmp_it = it_fpUserTimeSteps_low;
919  tmp_it++;
920  if (tmp_it == fpUserTimeSteps->end())
921  {
923  }
924  else
925  {
926  fUserUpperTimeLimit = tmp_it->second;
927  }
928  }
929  else if (it_fpUserTimeSteps_i == it_fpUserTimeSteps_low)
930  {
931  // "Normal" cases
932  fUserUpperTimeLimit = it_fpUserTimeSteps_i->second;
933  it_fpUserTimeSteps_i--;
934  }
935  else
936  {
937  fUserUpperTimeLimit = it_fpUserTimeSteps_i->second;
938  it_fpUserTimeSteps_i = it_fpUserTimeSteps_low;
939  }
940 
941  return it_fpUserTimeSteps_i->second;
942 }
943 
944 //_________________________________________________________________________
945 
947 {
948 
949  if (fpUserTimeSteps == 0)
950  {
951  G4ExceptionDescription exceptionDescription;
952  exceptionDescription
953  << "You are asking to use user defined steps but you did not give any.";
954  G4Exception("G4Scheduler::FindUserPreDefinedTimeStep",
955  "ITScheduler004", FatalErrorInArgument, exceptionDescription);
956  return; // makes coverity happy
957  }
958  map<double, double>::iterator fpUserTimeSteps_i =
959  fpUserTimeSteps->upper_bound(fGlobalTime);
960  map<double, double>::iterator fpUserTimeSteps_low = fpUserTimeSteps
961  ->lower_bound(fGlobalTime);
962 
963  // DEBUG
964  // G4cout << "fGlobalTime : " << G4BestUnit(fGlobalTime,"Time") << G4endl;
965  // G4cout << "fpUserTimeSteps_i : "
966  // <<"<"<<G4BestUnit(fpUserTimeSteps_i->first,"Time")<<", "
967  // << G4BestUnit(fpUserTimeSteps_i->second,"Time")<<">"
968  // << "\t fpUserTimeSteps_low : "
969  // <<"<"<<G4BestUnit(fpUserTimeSteps_low->first,"Time")<<", "
970  // << G4BestUnit(fpUserTimeSteps_low->second,"Time")<<">"
971  // << G4endl;
972 
973  if (fpUserTimeSteps_i == fpUserTimeSteps->end())
974  {
975  fpUserTimeSteps_i--;
976  }
977  else if (fabs(fGlobalTime - fpUserTimeSteps_low->first) < fTimeTolerance)
978  {
979  // Case : fGlobalTime = X picosecond
980  // and fpUserTimeSteps_low->first = X picosecond
981  // but the precision is not good enough
982  fpUserTimeSteps_i = fpUserTimeSteps_low;
983  }
984  else if (fpUserTimeSteps_i == fpUserTimeSteps_low)
985  {
986  // "Normal" cases
987  fpUserTimeSteps_i--;
988  }
989  else
990  {
991  fpUserTimeSteps_i = fpUserTimeSteps_low;
992  }
993 
994  fDefinedMinTimeStep = fpUserTimeSteps_i->second;
995 }
996 //_________________________________________________________________________
997 
999 {
1000 
1001  if (fpModelProcessor == 0)
1002  // if(fpMasterModelProcessor == 0)
1003  {
1004  G4ExceptionDescription exceptionDescription;
1005  exceptionDescription
1006  << "There is no G4ITModelProcessor to hande IT reaction. ";
1007  exceptionDescription
1008  << "You probably did not initialize the G4Scheduler. ";
1009  exceptionDescription
1010  << "Just do G4Scheduler::Instance()->Initialize(); ";
1011  exceptionDescription << " but only after initializing the run manager.";
1012  G4Exception("G4Scheduler::CalculateMinStep", "ITScheduler005",
1013  FatalErrorInArgument, exceptionDescription);
1014  return; // makes coverity happy
1015  }
1016 
1017 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
1018  MemStat mem_first, mem_second, mem_diff;
1019 #endif
1020 
1021 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
1022  mem_first = MemoryUsage();
1023 #endif
1024 
1026  // TODO
1027  // fpMasterModelProcessor -> InitializeStepper(fGlobalTime, fDefinedMinTimeStep) ;
1028 
1029 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
1030  mem_second = MemoryUsage();
1031  mem_diff = mem_second-mem_first;
1032  G4cout << "\t || MEM || G4Scheduler::CalculateMinTimeStep || After "
1033  "computing fpModelProcessor -> InitializeStepper, diff is : "
1034  << mem_diff
1035  << G4endl;
1036 #endif
1037 
1038 // G4TrackList::iterator fpMainList_i = fpMainList->begin();
1039 
1041  G4TrackManyList::iterator it = mainList->begin();
1042  G4TrackManyList::iterator end = mainList->end();
1043 
1044  for (; it != end; it++)
1045  {
1046  G4Track * track = *it;
1047 
1048  if (track == 0)
1049  {
1050  G4ExceptionDescription exceptionDescription;
1051  exceptionDescription << "No track found.";
1052  G4Exception("G4Scheduler::CalculateMinStep", "ITScheduler006",
1053  FatalErrorInArgument, exceptionDescription);
1054  return; // makes coverity happy
1055  }
1056 
1057 #ifdef DEBUG
1058  G4cout << "*_* " << GetIT(track)->GetName()
1059  << " ID: " << track->GetTrackID()
1060  << " at time : " << track->GetGlobalTime()
1061  << G4endl;
1062 #endif
1063 
1064  G4TrackStatus trackStatus = track->GetTrackStatus();
1065  if (trackStatus == fStopAndKill || trackStatus == fStopButAlive)
1066  {
1067  continue;
1068  }
1069 
1070  // This Extract... was thought for MT mode at the track level
1071  //ExtractTimeStepperData(fpModelProcessor) ;
1072 
1074 
1075  // if MT mode at track level, this command should be displaced
1077  }
1078 
1079 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
1080  mem_second = MemoryUsage();
1081  mem_diff = mem_second-mem_first;
1082  G4cout << "\t || MEM || G4Scheduler::CalculateMinTimeStep || "
1083  "After looping on tracks, diff is : " << mem_diff << G4endl;
1084 #endif
1085 }
1086 //_________________________________________________________________________
1087 
1089 {
1090  G4Track* track = (G4Track*) MP->GetTrack();
1091  if (track == 0)
1092  {
1093  MP->CleanProcessor();
1094  return;
1095  }
1096 
1097  const std::vector<std::vector<G4VITStepModel*> >* model =
1098  MP->GetCurrentModel();
1099 
1100  for (unsigned i = 0; i < model->size(); i++)
1101  {
1102  for (unsigned j = 0; j < (*model)[i].size(); j++)
1103  {
1104  G4VITStepModel* mod = (*model)[i][j];
1105 
1106  if (mod == 0)
1107  {
1108  continue;
1109  }
1110 
1111  G4VITTimeStepComputer* stepper(mod->GetTimeStepper());
1112 
1113  G4double sampledMinTimeStep(stepper->GetSampledMinTimeStep());
1114  G4TrackVectorHandle reactants(stepper->GetReactants());
1115 
1116  if (sampledMinTimeStep < fTSTimeStep)
1117  {
1118  /*
1119  // DEBUG SPECIAL CASE
1120  if(!reactants)
1121  {
1122  G4ExceptionDescription exceptionDescription ;
1123  exceptionDescription << "No reactants were found by the time stepper.";
1124  G4Exception("G4Scheduler::ExtractTimeStepperData","ITScheduler007",
1125  FatalErrorInArgument,exceptionDescription);
1126  continue ;
1127  }
1128  */
1129 
1130  fTSTimeStep = sampledMinTimeStep;
1131  //fReactingTracks.clear();
1133  if (bool(reactants))
1134  {
1135  // G4cout << "*** (1) G4Scheduler::ExtractTimeStepperData insert
1136  // reactants for " << GetIT(track)->GetName() << G4endl;
1137  // G4cout << "bool(reactants) = " << bool(reactants) << G4endl;
1138  // G4cout << reactants->size() << G4endl;
1139  // G4cout << GetIT(reactants->operator[](0))->GetName() << G4endl;
1140 
1141  // fReactingTracks.insert(make_pair(track, reactants));
1142  fReactionSet.AddReactions(fTSTimeStep, track, reactants);
1143  stepper->ResetReactants();
1144  }
1145  }
1146  else if (fTSTimeStep == sampledMinTimeStep)
1147  {
1148  /*
1149  // DEBUG SPECIAL CASE
1150  if(!reactants)
1151  {
1152  G4ExceptionDescription exceptionDescription ;
1153  exceptionDescription << "No reactants were found by the time stepper.";
1154  G4Exception("G4Scheduler::ExtractTimeStepperData","ITScheduler008",
1155  FatalErrorInArgument,exceptionDescription);
1156  continue ;
1157  }
1158  */
1159  if (bool(reactants))
1160  {
1161  // G4cout << "*** (2) G4Scheduler::ExtractTimeStepperData insert
1162  // reactants for " << GetIT(track)->GetName() << G4endl;
1163  // G4cout << "bool(reactants) = " << bool(reactants) << G4endl;
1164  // G4cout << "trackA : " << GetIT(track)->GetName()
1165  // << " ("<< track->GetTrackID() << ")" << G4endl;
1166  // G4cout << reactants->size() << G4endl;
1167  // G4cout << GetIT(reactants->operator[](0))->GetName() << G4endl;
1168 
1169  // fReactingTracks.insert(make_pair(track, reactants));
1170  fReactionSet.AddReactions(fTSTimeStep, track, reactants);
1171  stepper->ResetReactants();
1172  }
1173  }
1174  else
1175  {
1176  if (bool(reactants))
1177  {
1178  stepper->ResetReactants();
1179  }
1180  }
1181  }
1182  }
1183 
1184  MP->CleanProcessor();
1185 }
1186 //_________________________________________________________________________
1187 
1189 {
1191  G4TrackManyList::iterator it = mainList ->begin();
1192  G4TrackManyList::iterator end = mainList ->end();
1193 
1195 
1196  for (; it != end; it++)
1197  {
1198  G4Track * track = *it;
1199 
1200 #ifdef DEBUG
1201  G4cout << "*CIL* " << GetIT(track)->GetName()
1202  << " ID: " << track->GetTrackID()
1203  << " at time : " << track->GetGlobalTime()
1204  << G4endl;
1205 #endif
1206 
1208 
1210  }
1211 }
1212 //_________________________________________________________________________
1213 
1215 {
1216  G4Track* track = SP->GetTrack();
1217  if (!track)
1218  {
1219  SP->CleanProcessor();
1220  return;
1221  }
1222  if (track->GetTrackStatus() == fStopAndKill)
1223  {
1224  fTrackContainer.GetMainList()->pop(track);
1225  EndTracking(track);
1226  //return;
1227  }
1228 
1229  if (IsInf(SP->GetInteractionTime()))
1230  {
1231  // G4cout << "!!!!!!!!!!!! IS INF " << track->GetTrackID() << G4endl;
1232  SP->CleanProcessor();
1233  return;
1234  }
1235  else if (SP->GetInteractionTime() < fILTimeStep - DBL_EPSILON)
1236  {
1237  // G4cout << "!!!!!!!!!!!! TEMPS DIFFERENTS "
1238  // << track->GetTrackID() << G4endl;
1239 
1241 
1242  fILTimeStep = SP -> GetInteractionTime();
1243 
1244 // G4cout << "Will set leading step to true for time :"
1245 // << SP -> GetInteractionTime() << " against fTimeStep : "
1246 // << G4BestUnit(fILTimeStep, "Time") << " the trackID is : " << track->GetTrackID()
1247 // << G4endl;
1248 
1249  GetIT(track)->GetTrackingInfo()->SetLeadingStep(true);
1250  fLeadingTracks.push_back(track);
1251  }
1252  else if(fabs(fILTimeStep - SP -> GetInteractionTime()) < DBL_EPSILON )
1253  {
1254 
1255  // G4cout << "!!!!!!!!!!!! MEME TEMPS " << track->GetTrackID() << G4endl;
1256  // G4cout << "Will set leading step to true for time :"
1257  // << SP -> GetInteractionTime() << " against fTimeStep : "
1258  // << fTimeStep << " the trackID is : " << track->GetTrackID()<< G4endl;
1259  GetIT(track)->GetTrackingInfo()->SetLeadingStep(true);
1260  fLeadingTracks.push_back(track);
1261  }
1262  // else
1263  // {
1264  // G4cout << "!!!! Bigger time : " << "currentTime : "<<fILTimeStep
1265  // << " proposedTime : " << SP -> GetInteractionTime() << G4endl;
1266  // }
1267 
1268  SP->CleanProcessor();
1269 }
1270 //_________________________________________________________________________
1271 
1273 
1274 // Call the process having the min step length or just propagate the track on the given time step
1275 
1276 // If the track is "leading the step" (ie one of its process has been selected
1277 // as the one having the minimum time step over all tracks and processes),
1278 // it will undergo its selected processes. Otherwise, it will just propagate the track
1279 // on the given time step.
1280 
1281 {
1282 
1283 #ifdef G4VERBOSE
1284  if (fVerbose > 3)
1285  {
1286 #ifdef USE_COLOR
1287  G4cout << LIGHT_RED;
1288 #endif
1289  G4cout << "*** G4Scheduler::DoIt ***" << G4endl;
1290  G4cout << setw(18) << left << "#Name"
1291  << setw(15) << "trackID"
1292  << setw(35) << "Position"
1293  << setw(25) << "Pre step volume"
1294  << setw(25) << "Post step volume"
1295  << setw(22) << "Process"
1296  << G4endl;
1297 #ifdef USE_COLOR
1298  G4cout << RESET_COLOR;
1299 #endif
1300  }
1301 #endif
1302 
1304  G4TrackManyList::iterator it = mainList->end();
1305  it--;
1306  size_t initialSize = mainList->size();
1307 
1308 // G4cout << "initialSize = " << initialSize << G4endl;
1309 
1310  for(size_t i = 0 ; i < initialSize ; i++)
1311  {
1312 
1313 // G4cout << "i = " << i << G4endl;
1314 
1315  G4Track* track = *it;
1316  if (!track)
1317  {
1318  G4ExceptionDescription exceptionDescription;
1319  exceptionDescription << "No track was pop back the main track list.";
1320  G4Exception("G4Scheduler::DoIt", "ITScheduler009",
1321  FatalErrorInArgument, exceptionDescription);
1322  }
1323 
1324 #ifdef DEBUG
1325 #ifdef USE_COLOR
1326  G4cout << LIGHT_RED;
1327 #endif
1328  G4cout << "*DoIt* " << GetIT(track)->GetName()
1329  << " ID: " << track->GetTrackID()
1330  << " at time : " << track->GetGlobalTime()
1331  << G4endl;
1332 #ifdef USE_COLOR
1333  G4cout << RESET_COLOR;
1334 #endif
1335 #endif
1336 // G4TrackManyList::iterator next_it (it);
1337 // next_it--;
1338 // it = next_it;
1339 
1340  it--;
1341 
1342 #ifdef G4VERBOSE
1343  // PRE STEP VERBOSE
1345  if(fVerbose > 3)
1346  {
1347  G4String volumeName;
1348 
1349  G4TouchableHandle nextTouchable = track->GetNextTouchableHandle();
1350  G4VPhysicalVolume* volume (0);
1351 
1352  if(nextTouchable
1353  && (volume = nextTouchable->GetVolume()))
1354  {
1355  volumeName = volume->GetName();
1356 
1357  if(volume->IsParameterised() || volume->IsReplicated())
1358  {
1359  volumeName+=" ";
1360  volumeName+=nextTouchable->GetReplicaNumber();
1361  }
1362  }
1363  else
1364  {
1365  volumeName = "OutOfWorld";
1366  }
1367 
1368  G4cout << setw(18) << left << GetIT(track)->GetName()
1369  << setw(15) << track->GetTrackID()
1370  << std::setprecision(3)
1371  << setw(35) << G4String(G4BestUnit(track->GetPosition(), "Length"))
1372  << setw(25) << volumeName
1373  << setw(25) << "---"
1374  << G4endl;
1375  }
1376 #endif
1377 
1378 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DOIT)
1379  MemStat mem_first, mem_second, mem_diff;
1380 #endif
1381 
1382 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DOIT)
1383  mem_first = MemoryUsage();
1384 #endif
1385 
1386  // G4cout << " G4Scheduler::DoIt -- fTimeStep="
1387 // << fTimeStep << G4endl;
1389 
1390 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DOIT)
1391  MemStat mem_intermediaire = MemoryUsage();
1392  mem_diff = mem_intermediaire-mem_first;
1393  G4cout << "\t\t >> || MEM || In DoIT with track "
1394  << track->GetTrackID() << ", diff is : " << mem_diff << G4endl;
1395 #endif
1396 
1398 
1399 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DOIT)
1400  mem_second = MemoryUsage();
1401  mem_diff = mem_second-mem_first;
1402  G4cout << "\t >> || MEM || In DoIT with track "
1403  << track->GetTrackID()
1404  << ", diff is : " << mem_diff << G4endl;
1405 #endif
1406 
1407 #ifdef G4VERBOSE
1408  // POST STEP VERBOSE
1410  if(fVerbose > 3)
1411  {
1412  G4cout << setw(18) << left << GetIT(track)->GetName()
1413  << setw(15) << track->GetTrackID()
1414  << std::setprecision(3)
1415  << setw(35) << G4String(G4BestUnit(track->GetPosition(), "Length" ))
1416  << setw(25) << "---";
1417 
1418  G4TouchableHandle nextTouchable = track->GetNextTouchableHandle();
1419  G4VPhysicalVolume* volume (0);
1420 
1421  if(nextTouchable
1422  && (volume = nextTouchable->GetVolume()))
1423  {
1424  G4String volumeName = volume->GetName();
1425 
1426  if(volume->IsParameterised() || volume->IsReplicated())
1427  {
1428  volumeName+=" ";
1429  volumeName+=nextTouchable->GetReplicaNumber();
1430  }
1431 
1432  G4cout << setw(25) << volumeName;
1433  }
1434  else
1435  {
1436  G4cout << setw(25) << "OutOfWorld";
1437  }
1439  {
1440  G4cout << setw(22)
1442  ->GetProcessName();
1443  }
1444  else
1445  {
1446  G4cout << "---";
1447  }
1448  G4cout << G4endl;
1449 
1450  if(fVerbose > 4)
1451  {
1452  const G4TrackVector* secondaries = 0;
1453  if((secondaries = track->GetStep()->GetSecondary()))
1454  {
1455  if(secondaries->empty() == false)
1456  {
1457  G4cout << "\t\t ---->";
1458  for(size_t j = 0; j < secondaries->size(); j++)
1459  {
1460  G4cout << GetIT((*secondaries)[j])->GetName()
1461  << "("<<(*secondaries)[j]->GetTrackID() << ")"<< " ";
1462  }
1463  G4cout << G4endl;
1464  }
1465  }
1466  }
1467  }
1468 #endif
1469  }
1470 }
1471 //_________________________________________________________________________
1472 
1474 {
1475 
1476  G4Track* track = SP->GetTrack();
1477  if (!track)
1478  {
1479  SP->CleanProcessor();
1480  return;
1481  }
1482 
1483  G4TrackStatus status = track->GetTrackStatus();
1484 
1485  switch (status)
1486  {
1487  case fAlive:
1488  case fStopButAlive:
1489  case fSuspend:
1490  case fPostponeToNextEvent:
1491  default:
1492  PushSecondaries(SP);
1493  break;
1494 
1495  case fStopAndKill:
1497  PushSecondaries(SP);
1498  G4TrackList::Pop(track);
1499  EndTracking(track);
1500  break;
1501 
1504  G4TrackVector* secondaries = SP->GetSecondaries();
1505  if (secondaries)
1506  {
1507  for (size_t i = 0; i < secondaries->size(); i++)
1508  {
1509  delete (*secondaries)[i];
1510  }
1511  secondaries->clear();
1512  }
1513  G4TrackList::Pop(track);
1514  EndTracking(track);
1515  break;
1516  }
1517  SP->CleanProcessor();
1518 }
1519 //_________________________________________________________________________
1520 
1522 {
1523  G4TrackVector* secondaries = SP->GetSecondaries();
1524  if (!secondaries || secondaries->empty())
1525  {
1526  // DEBUG
1527  // G4cout << "NO SECONDARIES !!! " << G4endl;
1528  return;
1529  }
1530 
1531  // DEBUG
1532  // G4cout << "There are secondaries : "<< secondaries -> size() << G4endl ;
1533 
1534  G4TrackVector::iterator secondaries_i = secondaries->begin();
1535 
1536  for (; secondaries_i != secondaries->end(); secondaries_i++)
1537  {
1538  G4Track* secondary = *secondaries_i;
1539  fTrackContainer._PushTrack(secondary);
1540  }
1541 }
1542 
1543 //_________________________________________________________________________
1544 
1546 {
1547 // if (fReactingTracks.empty())
1548  if (fReactionSet.Empty())
1549  {
1550  return;
1551  }
1552 
1554  // if(fInteractionStep == false)
1555  {
1557  fTimeStep,
1559  // TODO
1560  // A ne faire uniquement si le temps choisis est celui calculé par le time stepper
1561  // Sinon utiliser quelque chose comme : fModelProcessor->FindReaction(&fMainList);
1562 
1563  std::vector<G4ITReactionChange*> * reactionInfo_v = fpModelProcessor
1564  ->GetReactionInfo();
1565  std::vector<G4ITReactionChange*>::iterator reactionInfo_i = reactionInfo_v
1566  ->begin();
1567 
1568  for (; reactionInfo_i != reactionInfo_v->end(); reactionInfo_i++)
1569  {
1570  G4ITReactionChange* changes = (*reactionInfo_i);
1571  G4Track* trackA = const_cast<G4Track*>(changes->GetTrackA());
1572  G4Track* trackB = const_cast<G4Track*>(changes->GetTrackB());
1573 
1574  if (trackA == 0 || trackB == 0 || trackA->GetTrackStatus() == fStopAndKill
1575  || trackB->GetTrackStatus() == fStopAndKill) continue;
1576 
1577  G4int nbSecondaries = changes->GetNumberOfSecondaries();
1578 
1580  {
1581  const vector<G4Track*>* productsVector = changes->GetfSecondary();
1582  fpUserTimeStepAction->UserReactionAction(*trackA, *trackB,
1583  *productsVector);
1584  }
1585 
1586 #ifdef G4VERBOSE
1587  if (fVerbose)
1588  {
1589  G4cout << "At time : " << setw(7) << G4BestUnit(fGlobalTime, "Time")
1590  << " Reaction : " << GetIT(trackA)->GetName() << " ("
1591  << trackA->GetTrackID() << ") + " << GetIT(trackB)->GetName()
1592  << " (" << trackB->GetTrackID() << ") -> ";
1593  }
1594 #endif
1595 
1596  if (nbSecondaries > 0)
1597  {
1598  for (int i = 0; i < nbSecondaries; i++)
1599  {
1600 #ifdef G4VERBOSE
1601  if (fVerbose && i != 0) G4cout << " + ";
1602 #endif
1603 
1604  G4Track* secondary = changes->GetSecondary(i);
1605  fTrackContainer._PushTrack(secondary);
1606  GetIT(secondary)->SetParentID(trackA->GetTrackID(),
1607  trackB->GetTrackID());
1608 
1609  if (secondary->GetGlobalTime() - fGlobalTime > fTimeTolerance)
1610  {
1611  G4ExceptionDescription exceptionDescription;
1612  exceptionDescription
1613  << "The time of the secondary should not be bigger than the"
1614  " current global time."
1615  << " This may cause synchronization problem. If the process you"
1616  " are using required "
1617  << "such feature please contact the developpers."
1618  << G4endl
1619  << "The global time in the step manager : "
1620  << G4BestUnit(fGlobalTime,"Time")
1621  << G4endl
1622  << "The global time of the track : "
1623  << G4BestUnit(secondary->GetGlobalTime(),"Time")
1624  << G4endl;
1625 
1626  G4Exception("G4Scheduler::ComputeInteractionBetweenTracks",
1627  "ITScheduler010", FatalErrorInArgument,
1628  exceptionDescription);
1629  }
1630 
1631 #ifdef G4VERBOSE
1632  if (fVerbose) G4cout << GetIT(secondary)->GetName() << " ("
1633  << secondary->GetTrackID() << ")";
1634 #endif
1635  }
1636  }
1637  else
1638  {
1639 #ifdef G4VERBOSE
1640  if (fVerbose) G4cout << "No product";
1641 #endif
1642  }
1643 #ifdef G4VERBOSE
1644  if (fVerbose) G4cout << G4endl;
1645 #endif
1646  if (trackA->GetTrackID() == 0 || trackB->GetTrackID() == 0)
1647  {
1648  G4Track* track = 0;
1649  if (trackA->GetTrackID() == 0) track = trackA;
1650  else track = trackB;
1651 
1652  G4ExceptionDescription exceptionDescription;
1653  exceptionDescription
1654  << "The problem was found for the reaction between tracks :"
1655  << trackA->GetParticleDefinition()->GetParticleName() << " ("
1656  << trackA->GetTrackID() << ") & "
1657  << trackB->GetParticleDefinition()->GetParticleName() << " ("
1658  << trackB->GetTrackID() << "). \n";
1659 
1660  if (track->GetStep() == 0)
1661  {
1662  exceptionDescription << "Also no step was found"
1663  << " ie track->GetStep() == 0 \n";
1664  }
1665 
1666  exceptionDescription << "Parent ID of trackA : "
1667  << trackA->GetParentID() << "\n";
1668  exceptionDescription << "Parent ID of trackB : "
1669  << trackB->GetParentID() << "\n";
1670 
1671  exceptionDescription
1672  << "The ID of one of the reaction track was not setup.";
1673  G4Exception("G4Scheduler::ComputeInteractionBetweenTracks",
1674  "ITScheduler011", FatalErrorInArgument,
1675  exceptionDescription);
1676  }
1677 
1678  if (changes->WereParentsKilled())
1679  {
1680  // DEBUG
1681  // G4cout << "Erasing tracks : "
1682  // << "trackA at time : " << G4BestUnit(trackA->GetGlobalTime() , "Time")
1683  // << "\t trackB at time : "<< G4BestUnit(trackB->GetGlobalTime(), "Time")
1684  // << "\t GlobalTime : " << G4BestUnit(fGlobalTime, "Time")
1685  // << G4endl;
1686 
1687  trackA->SetTrackStatus(fStopAndKill);
1688  trackB->SetTrackStatus(fStopAndKill);
1689 
1690  G4TrackList::Pop(trackA);
1691  G4TrackList::Pop(trackB);
1692  EndTracking(trackA);
1693  EndTracking(trackB);
1694  }
1695 
1696  delete changes;
1697  }
1698 
1699  reactionInfo_v->clear(); // never null because point to a non-pointer member of ModelProcessor
1700  }
1701  // DEBUG
1702  //else
1703  //{
1704  // G4cout << "fInteractionStep == true" << G4endl ;
1705  //}
1706 
1707 // fReactingTracks.clear();
1709 }
1710 
1711 //_________________________________________________________________________
1712 
1714 {
1715  if (fNbTracks == 0) fNbTracks = -1;
1716  track->SetTrackID(fNbTracks);
1717  fNbTracks--;
1718 }
1719 
1720 //_________________________________________________________________________
1721 
1723 {
1724  if (fRunning)
1725  {
1726  G4ExceptionDescription exceptionDescription;
1727  exceptionDescription
1728  << "G4Scheduler::PushTrack : You are trying to push tracks while the "
1729  "ITScheduler is running";
1730  G4Exception("G4Scheduler::PushTrack", "ITScheduler012",
1731  FatalErrorInArgument, exceptionDescription);
1732  }
1733  fTrackContainer._PushTrack(track);
1734 }
1735 //_________________________________________________________________________
1736 
1738 {
1740 }
1741 //_________________________________________________________________________
1742 
1744 {
1745  if (fLeadingTracks.empty() == false)
1746  {
1747  std::vector<G4Track*>::iterator fLeadingTracks_i = fLeadingTracks.begin();
1748 
1749  while (fLeadingTracks_i != fLeadingTracks.end())
1750  {
1751  G4Track* track = *fLeadingTracks_i;
1752  if (track)
1753  {
1754  G4IT* ITrack = GetIT(*fLeadingTracks_i);
1755  if (ITrack)
1756  {
1757  GetIT(*fLeadingTracks_i)->GetTrackingInfo()->SetLeadingStep(false);
1758  }
1759  }
1760 
1761  fLeadingTracks_i++;
1762  continue;
1763  }
1764 
1765  fLeadingTracks.clear();
1766  }
1767 }
1768 
1769 //_________________________________________________________________________
1770 
1771 void G4Scheduler::EndTracking(G4Track* trackToBeKilled)
1772 {
1773 // fReactionSet.RemoveReactionSet(trackToBeKilled);
1774  fpTrackingManager->EndTracking(trackToBeKilled);
1775  fTrackContainer.PushToKill(trackToBeKilled);
1776 }
1777 //_________________________________________________________________________
1778 
1780 {
1781  if (fRunning)
1782  {
1783  G4ExceptionDescription exceptionDescription;
1784  exceptionDescription
1785  << "End tracking is called while G4Scheduler is still running."
1786  << G4endl;
1787 
1788  G4Exception("G4Scheduler::EndTracking", "ITScheduler017",
1789  FatalErrorInArgument, exceptionDescription);
1790  }
1791 
1793 
1795  {
1797  G4TrackManyList::iterator it = mainList->begin();
1798  G4TrackManyList::iterator end = mainList->end();
1799  for (; it != end; it++)
1800  {
1802  }
1803  }
1804 
1805  if (fTrackContainer.SecondaryListsNOTEmpty()) // should be empty
1806  {
1808  G4TrackManyList::iterator it = secondaries->begin();
1809  G4TrackManyList::iterator end = secondaries->end();
1810 
1811  for (; it != end; it++)
1812  {
1814  }
1815  }
1816 }
1817 
1818 //_________________________________________________________________________
1820 {
1821  fpTrackingInteractivity = interactivity;
1824 }
1825 
1826 //_________________________________________________________________________
1828 {
1829  fInitialized = false;
1830  Initialize();
1831 }
1832 
1833 //_________________________________________________________________________
1836 fTrackContainer((G4ITTrackHolder&)*G4ITTrackHolder::Instance())
1837 
1838 {
1839  Create();
1840 }
1841 
1842 //_________________________________________________________________________
1844 {
1845  if (this != &right)
1846  {
1847  Create();
1848  }
1849  return *this;
1850 }
1851 
1853 {
1854  return fTrackContainer.GetNTracks();
1855 }
1856 //_________________________________________________________________________
1857 
1859 {
1860  switch(fITStepStatus)
1861  {
1863  interactionType = "eInteractionWithMedium";
1864  break;
1866  interactionType = "eCollisionBetweenTracks";
1867  break;
1868  default:
1869  interactionType = "eCollisionBetweenTracks";
1870  break;
1871  }
1872 }
1873 
G4ITModelHandler holds for two IT types the corresponding model manager.
void RegisterModel(G4VITStepModel *aModel, const G4double globalTime)
G4bool fUseDefaultTimeSteps
Definition: G4Scheduler.hh:278
void Process()
Definition: G4Scheduler.cc:363
void SetTrackStatus(const G4TrackStatus aTrackStatus)
std::map< double, double > * fpUserTimeSteps
Definition: G4Scheduler.hh:244
Its role is the same as G4StepManager :
G4int GetParentID() const
bool fInteractionStep
Definition: G4Scheduler.hh:261
virtual void DefineTracks()
Definition: G4ITGun.hh:56
void MergeSecondariesWithMainList()
virtual size_t GetNTracks()
Similar to G4ParticleChange, but deal with two tracks rather than one.
void FindUserPreDefinedTimeStep()
Definition: G4Scheduler.cc:946
const G4Track * GetTrackA()
The G4ITModelProcessor will call the two processes defined in G4VITModel.
void EndTracking()
virtual G4bool Notify(G4ApplicationState requestedState)
Definition: G4Scheduler.cc:125
G4TrackManyList * GetSecondariesList()
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
void SetTrackingManager(G4ITTrackingManager *trackMan)
void SetParentID(int, int)
Definition: G4IT.hh:250
virtual G4bool IsReplicated() const =0
void PushSecondaries(G4ITStepProcessor *)
bool fReachedUserTimeLimit
Definition: G4Scheduler.hh:249
bool fComputeTimeStep
Definition: G4Scheduler.hh:236
void RemoveReactionSet(G4Track *track)
virtual void UserReactionAction(const G4Track &, const G4Track &, const std::vector< G4Track * > &)
Inform about a reaction.
G4shared_ptr< std::vector< G4Track * > > G4TrackVectorHandle
Definition: G4ITReaction.hh:18
double fTSTimeStep
Definition: G4Scheduler.hh:251
double fTmpEndTime
Definition: G4Scheduler.hh:229
void Clear(Node *)
Define what to do before stepping and after stepping.
const G4ThreeVector & GetPosition() const
G4TrackStatus GetTrackStatus() const
virtual ~G4Scheduler()
Definition: G4Scheduler.cc:222
void CalculateTimeStep(const G4Track *, const G4double)
void AddReactions(double time, G4Track *trackA, G4TrackVectorHandle reactants)
G4int GetNumberOfSecondaries() const
static void Pop(G4Track *)
void SynchronizeTracks()
Definition: G4Scheduler.cc:472
double fPreviousTimeStep
Definition: G4Scheduler.hh:231
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
virtual const G4String & GetName() const =0
void SetPreviousStepTime(G4double)
G4ITStepStatus fITStepStatus
Definition: G4Scheduler.hh:221
#define G4ThreadLocal
Definition: tls.hh:89
bool IsInf(T value)
Definition: G4Scheduler.cc:111
int fMaxNZeroTimeStepsAllowed
Definition: G4Scheduler.hh:233
const G4Step * GetStep() const
void ComputeTrackReaction()
int G4int
Definition: G4Types.hh:78
double fILTimeStep
Definition: G4Scheduler.hh:253
static G4Scheduler * Instance()
Definition: G4Scheduler.cc:118
MemStat MemoryUsage()
Definition: G4MemStat.cc:55
iterator pop(OBJECT *)
virtual void PushTrack(G4Track *)
const G4String & GetParticleName() const
void KillTracks()
static G4ITTypeManager * Instance()
Definition: G4ITType.cc:58
static G4ThreadLocal G4Scheduler * fgScheduler
Definition: G4Scheduler.hh:211
void DefinePhysicalStepLength(G4Track *)
G4ITGun * fpGun
Definition: G4Scheduler.hh:276
static const double microsecond
Definition: G4SIunits.hh:141
virtual void EndTracking(G4Track *)
void FindReaction(G4ITReactionSet *reactionSet, const double currentStepTime, const double previousStepTime, const bool reachedUserStepTimeLimit)
bool fUsePreDefinedTimeSteps
Definition: G4Scheduler.hh:242
G4IT * GetIT(const G4Track *track)
Definition: G4IT.cc:49
virtual void UserPostTimeStepAction()
bool fInitialized
Definition: G4Scheduler.hh:214
G4GLOB_DLL std::ostream G4cout
double fUserUpperTimeLimit
Definition: G4Scheduler.hh:246
static void DeleteInstance()
const G4String & GetName() const
#define RESET_COLOR
Definition: G4Scheduler.cc:83
void Clear()
Definition: G4Scheduler.cc:237
virtual void UserPreTimeStepAction()
In this method, the user can use : G4Scheduler::Instance()->GetGlobalTime(), to know the current simu...
void _PushTrack(G4Track *track)
bool G4bool
Definition: G4Types.hh:79
G4ITStepManager enables to synchronize in time the step of tracks.
Definition: G4Scheduler.hh:88
G4ITTrackingManager * fpTrackingManager
Definition: G4Scheduler.hh:272
const std::vector< std::vector< G4VITStepModel * > > * GetCurrentModel()
void ExtractILData(G4ITStepProcessor *)
double GetLimitingTimeStep() const
Definition: G4Scheduler.cc:885
void ForceReinitialization()
void ExtractDoItData(G4ITStepProcessor *)
void ClearList()
Definition: G4Scheduler.cc:280
void AddTrackID(G4Track *)
double fEndTime
Definition: G4Scheduler.hh:228
bool MergeNextTimeToMainList(double &time)
G4ITModelProcessor * fpModelProcessor
Definition: G4Scheduler.hh:268
const G4TouchableHandle & GetNextTouchableHandle() const
const G4ParticleDefinition * GetParticleDefinition() const
G4TrackVector * GetSecondaries()
#define DBL_EPSILON
Definition: templates.hh:87
bool SecondaryListsNOTEmpty()
G4SchedulerMessenger * fSteppingMsg
Definition: G4Scheduler.hh:209
double fTimeTolerance
Definition: G4Scheduler.hh:224
void PushToKill(G4Track *track)
void Create()
Definition: G4Scheduler.cc:156
G4Track * GetSecondary(G4int) const
G4int GetTrackID() const
static void DeleteInstance()
DeleteInstance should be used instead of the destructor.
Definition: G4Scheduler.cc:140
G4double GetGlobalTime() const
const G4Track * GetTrack() const
void ReserveRessource()
Definition: G4ITType.cc:77
G4ITModelHandler * fpModelHandler
Definition: G4Scheduler.hh:270
IosFlagSaver(std::ostream &_ios)
Definition: G4Scheduler.cc:93
virtual size_t GetNTracks()
const G4String & GetProcessName() const
Definition: G4VProcess.hh:408
G4VITTimeStepComputer * GetTimeStepper()
G4ITStepProcessor * fpStepProcessor
Definition: G4Scheduler.hh:267
double fTimeStep
Definition: G4Scheduler.hh:239
const G4Track * GetTrackB()
std::vector< G4ITReactionChange * > * GetReactionInfo()
std::vector< G4Track * > fLeadingTracks
Definition: G4Scheduler.hh:259
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual G4bool IsParameterised() const =0
virtual void Initialize()
G4TrackingInformation * GetTrackingInfo()
Definition: G4IT.hh:152
double fStartTime
Definition: G4Scheduler.hh:227
const G4VProcess * GetProcessDefinedStep() const
G4ITTrackingInteractivity * fpTrackingInteractivity
Definition: G4Scheduler.hh:274
bool fWhyDoYouStop
Definition: G4Scheduler.hh:213
G4UserTimeStepAction * fpUserTimeStepAction
Definition: G4Scheduler.hh:273
std::vector< G4Track * > G4TrackVector
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
Definition: G4VTouchable.cc:44
void CalculateMinTimeStep()
Definition: G4Scheduler.cc:998
void Stepping(G4Track *, const double &)
void Stop()
G4StepPoint * GetPostStepPoint() const
void CleanAllReaction()
double fDefinedMinTimeStep
Definition: G4Scheduler.hh:247
G4bool fContinue
Definition: G4Scheduler.hh:277
size_t size() const
virtual G4int GetReplicaNumber(G4int depth=0) const
Definition: G4VTouchable.cc:58
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4ITReactionSet fReactionSet
Definition: G4Scheduler.hh:258
void InitializeStepper(const G4double &currentGlobalTime, const G4double &userMinTime)
void Reset()
Definition: G4Scheduler.cc:342
G4bool WereParentsKilled() const
G4Scheduler & operator=(const G4Scheduler &)
virtual void RegisterModel(G4VITStepModel *, double)
Definition: G4Scheduler.cc:292
#define G4endl
Definition: G4ios.hh:61
double fDefaultMinTimeStep
Definition: G4Scheduler.hh:243
void SetModelHandler(G4ITModelHandler *)
double fGlobalTime
Definition: G4Scheduler.hh:225
static const double picosecond
Definition: G4SIunits.hh:142
void Start()
G4TrackList * GetMainList(Key)
std::ostream & ios
Definition: G4Scheduler.cc:106
double G4double
Definition: G4Types.hh:76
std::vector< G4Track * > * GetfSecondary()
void DoProcess()
Definition: G4Scheduler.cc:507
void SetInteractivity(G4ITTrackingInteractivity *)
void GetCollisionType(G4String &interactionType)
int fZeroTimeCount
Definition: G4Scheduler.hh:232
Before stepping all tracks G4Scheduler calls all the G4VITModel which may contain a G4VITTimeStepper ...
#define DBL_MAX
Definition: templates.hh:83
void ComputeInteractionLength()
G4TrackStatus
{ Class description:
bool GetTimeStepComputerFlag()
std::ios::fmtflags f
Definition: G4Scheduler.cc:107
bool fComputeReaction
Definition: G4Scheduler.hh:237
void Initialize()
Definition: G4Scheduler.cc:299
void Stepping()
Definition: G4Scheduler.cc:591
G4ITTrackHolder & fTrackContainer
Definition: G4Scheduler.hh:265
G4ApplicationState
void SetInteractivity(G4ITTrackingInteractivity *)
void SetTrackID(const G4int aValue)
double fTmpGlobalTime
Definition: G4Scheduler.hh:226
void ExtractTimeStepperData(G4ITModelProcessor *)
const G4TrackVector * GetSecondary() const
void ResetLeadingTracks()
#define LIGHT_RED
Definition: G4Scheduler.cc:80
virtual void StartProcessing()
void CleanProcessor()
Restaure original state of the modelProcessor.