59 #define DEBUG_MEM_STEPPING
60 #define DEBUG_MEM_DETAILED_STEPPING
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"
82 #define GREEN_ON_BLUE ""
83 #define RESET_COLOR ""
94 ios(_ios), f(_ios.flags())
107 std::ios::fmtflags
f;
113 return std::numeric_limits<T>::has_infinity
114 && value == std::numeric_limits<T>::infinity();
120 if (fgScheduler == 0) fgScheduler =
new G4Scheduler();
131 G4cout <<
"G4Scheduler received G4State_Quit" <<
G4endl;
369 G4cout <<
"*** G4Scheduler starts processing " <<
G4endl;
371 G4cout <<
"___________________________________________"
372 "___________________________" <<
G4endl;
397 G4bool trackFound =
false;
421 G4cout <<
"G4Scheduler: process time= "<< localtimer <<
G4endl;
445 G4cout <<
"*** G4Scheduler ends at time : "
447 G4cout <<
"___________________________________" <<
G4endl;
451 G4cout <<
"*** G4Scheduler did not start because no "
452 "track was found to be processed"<<
G4endl;
453 G4cout <<
"___________________________________" <<
G4endl;
512 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
513 MemStat mem_first, mem_second, mem_diff;
516 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
530 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
532 mem_diff = mem_second-mem_first;
533 G4cout <<
"\t || MEM || After step " <<
fNbSteps <<
", diff is : "
541 G4cout <<
"G4Scheduler has reached a stage: it might be"
542 " a transition or the end"
545 G4bool normalStop =
false;
549 G4cout <<
"== G4Scheduler: I stop because I reached the final time : "
555 G4cout <<
"G4Scheduler: I stop because the current main list of tracks"
562 G4cout <<
"G4Scheduler: I stop because I reached the maximum allowed "
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()."
577 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
579 mem_diff = mem_second-mem_first;
580 G4cout <<
"\t || MEM || After stepping, diff is : " << mem_diff <<
G4endl;
585 <<
"*** G4Scheduler has finished processing a track list at time : "
620 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
621 MemStat mem_first, mem_second, mem_diff;
624 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
636 <<
"You are asking to use user defined steps but you did not give any.";
637 G4Exception(
"G4Scheduler::FindUserPreDefinedTimeStep",
639 exceptionDescription);
649 <<
" the chosen user time step is : "
667 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
669 mem_diff = mem_second-mem_first;
670 G4cout <<
"|| MEM || After computing TS, diff is : " << mem_diff <<
G4endl;
687 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
699 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
701 mem_diff = mem_second-mem_first;
702 G4cout <<
"|| MEM || After IL, diff is : " << mem_diff <<
G4endl;
711 G4cout <<
"*** The minimum time returned by the processes is : "
719 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
758 exceptionDescription <<
"Too many zero time steps were detected. ";
759 exceptionDescription <<
"The simulation is probably stuck. ";
761 <<
"The maximum number of zero time steps is currently : "
763 exceptionDescription <<
".";
765 G4Exception(
"G4Scheduler::Stepping",
"ITSchedulerNullTimeSteps",
782 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
784 mem_diff = mem_second-mem_first;
785 G4cout <<
"|| MEM || After LeadingTracks and UserPreTimeStepAction: "
789 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
810 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
812 mem_diff = mem_second-mem_first;
813 G4cout <<
"|| MEM || After DoIT, diff is : " << mem_diff <<
G4endl;
818 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
837 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
839 mem_diff = mem_second-mem_first;
840 G4cout <<
"|| MEM || After computing reactions + UserPostTimeStepAction, "
841 "diff is : " << mem_diff <<
G4endl;
855 std::stringstream finalOutput;
857 finalOutput <<
"*** End of step N°" <<
fNbSteps
861 <<
"\t " << interactionType
868 finalOutput <<
"It has also reached the user time limit" <<
G4endl;
870 finalOutput <<
"_______________________________________________________________"
874 G4cout << finalOutput.str();
891 map<double, double>::const_iterator it_fpUserTimeSteps_i =
fpUserTimeSteps
893 map<double, double>::const_iterator it_fpUserTimeSteps_low =
fpUserTimeSteps
909 it_fpUserTimeSteps_i--;
917 it_fpUserTimeSteps_i = it_fpUserTimeSteps_low;
918 map<double, double>::const_iterator tmp_it = it_fpUserTimeSteps_low;
929 else if (it_fpUserTimeSteps_i == it_fpUserTimeSteps_low)
933 it_fpUserTimeSteps_i--;
938 it_fpUserTimeSteps_i = it_fpUserTimeSteps_low;
941 return it_fpUserTimeSteps_i->second;
953 <<
"You are asking to use user defined steps but you did not give any.";
954 G4Exception(
"G4Scheduler::FindUserPreDefinedTimeStep",
958 map<double, double>::iterator fpUserTimeSteps_i =
982 fpUserTimeSteps_i = fpUserTimeSteps_low;
984 else if (fpUserTimeSteps_i == fpUserTimeSteps_low)
991 fpUserTimeSteps_i = fpUserTimeSteps_low;
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",
1017 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
1018 MemStat mem_first, mem_second, mem_diff;
1021 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
1029 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
1031 mem_diff = mem_second-mem_first;
1032 G4cout <<
"\t || MEM || G4Scheduler::CalculateMinTimeStep || After "
1033 "computing fpModelProcessor -> InitializeStepper, diff is : "
1044 for (; it != end; it++)
1051 exceptionDescription <<
"No track found.";
1052 G4Exception(
"G4Scheduler::CalculateMinStep",
"ITScheduler006",
1079 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
1081 mem_diff = mem_second-mem_first;
1082 G4cout <<
"\t || MEM || G4Scheduler::CalculateMinTimeStep || "
1083 "After looping on tracks, diff is : " << mem_diff <<
G4endl;
1097 const std::vector<std::vector<G4VITStepModel*> >* model =
1100 for (
unsigned i = 0; i < model->size(); i++)
1102 for (
unsigned j = 0; j < (*model)[i].size(); j++)
1113 G4double sampledMinTimeStep(stepper->GetSampledMinTimeStep());
1133 if (
bool(reactants))
1143 stepper->ResetReactants();
1159 if (
bool(reactants))
1171 stepper->ResetReactants();
1176 if (
bool(reactants))
1178 stepper->ResetReactants();
1196 for (; it != end; it++)
1291 << setw(15) <<
"trackID"
1292 << setw(35) <<
"Position"
1293 << setw(25) <<
"Pre step volume"
1294 << setw(25) <<
"Post step volume"
1295 << setw(22) <<
"Process"
1306 size_t initialSize = mainList->
size();
1310 for(
size_t i = 0 ; i < initialSize ; i++)
1319 exceptionDescription <<
"No track was pop back the main track list.";
1320 G4Exception(
"G4Scheduler::DoIt",
"ITScheduler009",
1353 && (volume = nextTouchable->
GetVolume()))
1355 volumeName = volume->
GetName();
1365 volumeName =
"OutOfWorld";
1370 << std::setprecision(3)
1372 << setw(25) << volumeName
1373 << setw(25) <<
"---"
1378 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DOIT)
1379 MemStat mem_first, mem_second, mem_diff;
1382 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DOIT)
1390 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DOIT)
1392 mem_diff = mem_intermediaire-mem_first;
1393 G4cout <<
"\t\t >> || MEM || In DoIT with track "
1399 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DOIT)
1401 mem_diff = mem_second-mem_first;
1402 G4cout <<
"\t >> || MEM || In DoIT with track "
1404 <<
", diff is : " << mem_diff <<
G4endl;
1414 << std::setprecision(3)
1416 << setw(25) <<
"---";
1422 && (volume = nextTouchable->
GetVolume()))
1432 G4cout << setw(25) << volumeName;
1436 G4cout << setw(25) <<
"OutOfWorld";
1455 if(secondaries->empty() ==
false)
1458 for(
size_t j = 0; j < secondaries->size(); j++)
1461 <<
"("<<(*secondaries)[j]->GetTrackID() <<
")"<<
" ";
1507 for (
size_t i = 0; i < secondaries->size(); i++)
1509 delete (*secondaries)[i];
1511 secondaries->clear();
1524 if (!secondaries || secondaries->empty())
1534 G4TrackVector::iterator secondaries_i = secondaries->begin();
1536 for (; secondaries_i != secondaries->end(); secondaries_i++)
1538 G4Track* secondary = *secondaries_i;
1565 std::vector<G4ITReactionChange*>::iterator reactionInfo_i = reactionInfo_v
1568 for (; reactionInfo_i != reactionInfo_v->end(); reactionInfo_i++)
1581 const vector<G4Track*>* productsVector = changes->
GetfSecondary();
1596 if (nbSecondaries > 0)
1598 for (
int i = 0; i < nbSecondaries; i++)
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."
1619 <<
"The global time in the step manager : "
1622 <<
"The global time of the track : "
1626 G4Exception(
"G4Scheduler::ComputeInteractionBetweenTracks",
1628 exceptionDescription);
1649 if (trackA->
GetTrackID() == 0) track = trackA;
1650 else track = trackB;
1653 exceptionDescription
1654 <<
"The problem was found for the reaction between tracks :"
1662 exceptionDescription <<
"Also no step was found"
1663 <<
" ie track->GetStep() == 0 \n";
1666 exceptionDescription <<
"Parent ID of trackA : "
1668 exceptionDescription <<
"Parent ID of trackB : "
1671 exceptionDescription
1672 <<
"The ID of one of the reaction track was not setup.";
1673 G4Exception(
"G4Scheduler::ComputeInteractionBetweenTracks",
1675 exceptionDescription);
1699 reactionInfo_v->clear();
1727 exceptionDescription
1728 <<
"G4Scheduler::PushTrack : You are trying to push tracks while the "
1729 "ITScheduler is running";
1730 G4Exception(
"G4Scheduler::PushTrack",
"ITScheduler012",
1747 std::vector<G4Track*>::iterator fLeadingTracks_i =
fLeadingTracks.begin();
1751 G4Track* track = *fLeadingTracks_i;
1754 G4IT* ITrack =
GetIT(*fLeadingTracks_i);
1784 exceptionDescription
1785 <<
"End tracking is called while G4Scheduler is still running."
1788 G4Exception(
"G4Scheduler::EndTracking",
"ITScheduler017",
1799 for (; it != end; it++)
1811 for (; it != end; it++)
1863 interactionType =
"eInteractionWithMedium";
1866 interactionType =
"eCollisionBetweenTracks";
1869 interactionType =
"eCollisionBetweenTracks";
G4ITModelHandler holds for two IT types the corresponding model manager.
void RegisterModel(G4VITStepModel *aModel, const G4double globalTime)
G4bool fUseDefaultTimeSteps
void SetTrackStatus(const G4TrackStatus aTrackStatus)
std::map< double, double > * fpUserTimeSteps
Its role is the same as G4StepManager :
G4int GetParentID() const
virtual void DefineTracks()
void MergeSecondariesWithMainList()
virtual size_t GetNTracks()
Similar to G4ParticleChange, but deal with two tracks rather than one.
void FindUserPreDefinedTimeStep()
const G4Track * GetTrackA()
The G4ITModelProcessor will call the two processes defined in G4VITModel.
virtual G4bool Notify(G4ApplicationState requestedState)
G4TrackManyList * GetSecondariesList()
std::ostringstream G4ExceptionDescription
virtual void Initialize()
void SetTrackingManager(G4ITTrackingManager *trackMan)
void SetParentID(int, int)
virtual G4bool IsReplicated() const =0
void PushSecondaries(G4ITStepProcessor *)
bool fReachedUserTimeLimit
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
Define what to do before stepping and after stepping.
const G4ThreeVector & GetPosition() const
G4TrackStatus GetTrackStatus() const
void CalculateTimeStep(const G4Track *, const G4double)
void AddReactions(double time, G4Track *trackA, G4TrackVectorHandle reactants)
G4int GetNumberOfSecondaries() const
static void Pop(G4Track *)
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
virtual const G4String & GetName() const =0
void SetPreviousStepTime(G4double)
G4ITStepStatus fITStepStatus
bool GetReactionProcessFlag()
int fMaxNZeroTimeStepsAllowed
const G4Step * GetStep() const
void ComputeTrackReaction()
static G4Scheduler * Instance()
virtual void PushTrack(G4Track *)
const G4String & GetParticleName() const
static G4ITTypeManager * Instance()
static G4ThreadLocal G4Scheduler * fgScheduler
void DefinePhysicalStepLength(G4Track *)
static const double microsecond
virtual void EndTracking(G4Track *)
void FindReaction(G4ITReactionSet *reactionSet, const double currentStepTime, const double previousStepTime, const bool reachedUserStepTimeLimit)
bool fUsePreDefinedTimeSteps
G4IT * GetIT(const G4Track *track)
virtual void UserPostTimeStepAction()
G4GLOB_DLL std::ostream G4cout
double fUserUpperTimeLimit
static void DeleteInstance()
const G4String & GetName() const
virtual void UserPreTimeStepAction()
In this method, the user can use : G4Scheduler::Instance()->GetGlobalTime(), to know the current simu...
void _PushTrack(G4Track *track)
G4ITStepManager enables to synchronize in time the step of tracks.
G4ITTrackingManager * fpTrackingManager
const std::vector< std::vector< G4VITStepModel * > > * GetCurrentModel()
void ExtractILData(G4ITStepProcessor *)
double GetLimitingTimeStep() const
void ForceReinitialization()
void ExtractDoItData(G4ITStepProcessor *)
void AddTrackID(G4Track *)
bool MergeNextTimeToMainList(double &time)
G4ITModelProcessor * fpModelProcessor
const G4TouchableHandle & GetNextTouchableHandle() const
const G4ParticleDefinition * GetParticleDefinition() const
G4TrackVector * GetSecondaries()
bool SecondaryListsNOTEmpty()
G4SchedulerMessenger * fSteppingMsg
void PushToKill(G4Track *track)
G4Track * GetSecondary(G4int) const
static void DeleteInstance()
DeleteInstance should be used instead of the destructor.
double GetInteractionTime()
G4double GetGlobalTime() const
const G4Track * GetTrack() const
G4ITModelHandler * fpModelHandler
IosFlagSaver(std::ostream &_ios)
virtual size_t GetNTracks()
const G4String & GetProcessName() const
G4VITTimeStepComputer * GetTimeStepper()
G4ITStepProcessor * fpStepProcessor
const G4Track * GetTrackB()
std::vector< G4ITReactionChange * > * GetReactionInfo()
std::vector< G4Track * > fLeadingTracks
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
virtual G4bool IsParameterised() const =0
bool DelayListsNOTEmpty()
virtual void Initialize()
G4TrackingInformation * GetTrackingInfo()
const G4VProcess * GetProcessDefinedStep() const
G4ITTrackingInteractivity * fpTrackingInteractivity
G4UserTimeStepAction * fpUserTimeStepAction
std::vector< G4Track * > G4TrackVector
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
void CalculateMinTimeStep()
void Stepping(G4Track *, const double &)
G4StepPoint * GetPostStepPoint() const
double fDefinedMinTimeStep
virtual G4int GetReplicaNumber(G4int depth=0) const
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4ITReactionSet fReactionSet
void InitializeStepper(const G4double ¤tGlobalTime, const G4double &userMinTime)
G4bool WereParentsKilled() const
G4Scheduler & operator=(const G4Scheduler &)
virtual void RegisterModel(G4VITStepModel *, double)
double fDefaultMinTimeStep
virtual void EndProcessing()
void SetModelHandler(G4ITModelHandler *)
static const double picosecond
G4TrackList * GetMainList(Key)
std::vector< G4Track * > * GetfSecondary()
void SetInteractivity(G4ITTrackingInteractivity *)
void GetCollisionType(G4String &interactionType)
Before stepping all tracks G4Scheduler calls all the G4VITModel which may contain a G4VITTimeStepper ...
void ComputeInteractionLength()
bool GetTimeStepComputerFlag()
G4ITTrackHolder & fTrackContainer
void SetInteractivity(G4ITTrackingInteractivity *)
void SetTrackID(const G4int aValue)
void ExtractTimeStepperData(G4ITModelProcessor *)
const G4TrackVector * GetSecondary() const
void ResetLeadingTracks()
virtual void StartProcessing()
void CleanProcessor()
Restaure original state of the modelProcessor.