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;
368 G4cout <<
"*** G4Scheduler starts processing " <<
G4endl;
370 G4cout <<
"___________________________________________"
371 "___________________________" <<
G4endl;
396 G4bool trackFound =
false;
420 G4cout <<
"G4Scheduler: process time= "<< localtimer <<
G4endl;
444 G4cout <<
"*** G4Scheduler ends at time : "
446 G4cout <<
"___________________________________" <<
G4endl;
450 G4cout <<
"*** G4Scheduler did not start because no "
451 "track was found to be processed"<<
G4endl;
452 G4cout <<
"___________________________________" <<
G4endl;
511 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
512 MemStat mem_first, mem_second, mem_diff;
515 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
529 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
531 mem_diff = mem_second-mem_first;
532 G4cout <<
"\t || MEM || After step " <<
fNbSteps <<
", diff is : "
540 G4cout <<
"G4Scheduler has reached a stage: it might be"
541 " a transition or the end"
544 G4bool normalStop =
false;
548 G4cout <<
"== G4Scheduler: I stop because I reached the final time : "
554 G4cout <<
"G4Scheduler: I stop because the current main list of tracks"
561 G4cout <<
"G4Scheduler: I stop because I reached the maximum allowed "
568 G4cout <<
"G4Scheduler: It might be that I stop because "
569 "I have been told so. You may check "
570 "member fContinue and usage of the method G4Scheduler::Stop()."
576 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
578 mem_diff = mem_second-mem_first;
579 G4cout <<
"\t || MEM || After stepping, diff is : " << mem_diff <<
G4endl;
584 <<
"*** G4Scheduler has finished processing a track list at time : "
619 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
620 MemStat mem_first, mem_second, mem_diff;
623 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
635 <<
"You are asking to use user defined steps but you did not give any.";
636 G4Exception(
"G4Scheduler::FindUserPreDefinedTimeStep",
638 exceptionDescription);
648 <<
" the chosen user time step is : "
666 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
668 mem_diff = mem_second-mem_first;
669 G4cout <<
"|| MEM || After computing TS, diff is : " << mem_diff <<
G4endl;
686 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
698 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
700 mem_diff = mem_second-mem_first;
701 G4cout <<
"|| MEM || After IL, diff is : " << mem_diff <<
G4endl;
710 G4cout <<
"*** The minimum time returned by the processes is : "
718 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
755 exceptionDescription <<
"Too many zero time steps were detected. ";
756 exceptionDescription <<
"The simulation is probably stuck. ";
758 <<
"The maximum number of zero time steps is currently : "
760 exceptionDescription <<
".";
762 G4Exception(
"G4Scheduler::Stepping",
"ITSchedulerNullTimeSteps",
779 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
781 mem_diff = mem_second-mem_first;
782 G4cout <<
"|| MEM || After LeadingTracks and UserPreTimeStepAction: "
786 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
807 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
809 mem_diff = mem_second-mem_first;
810 G4cout <<
"|| MEM || After DoIT, diff is : " << mem_diff <<
G4endl;
815 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
834 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
836 mem_diff = mem_second-mem_first;
837 G4cout <<
"|| MEM || After computing reactions + UserPostTimeStepAction, "
838 "diff is : " << mem_diff <<
G4endl;
852 std::stringstream finalOutput;
854 finalOutput <<
"*** End of step N°" <<
fNbSteps
858 <<
"\t " << interactionType
865 finalOutput <<
"It has also reached the user time limit" <<
G4endl;
867 finalOutput <<
"_______________________________________________________________"
871 G4cout << finalOutput.str();
888 map<double, double>::const_iterator it_fpUserTimeSteps_i =
fpUserTimeSteps
890 map<double, double>::const_iterator it_fpUserTimeSteps_low =
fpUserTimeSteps
906 it_fpUserTimeSteps_i--;
914 it_fpUserTimeSteps_i = it_fpUserTimeSteps_low;
915 map<double, double>::const_iterator tmp_it = it_fpUserTimeSteps_low;
926 else if (it_fpUserTimeSteps_i == it_fpUserTimeSteps_low)
930 it_fpUserTimeSteps_i--;
935 it_fpUserTimeSteps_i = it_fpUserTimeSteps_low;
938 return it_fpUserTimeSteps_i->second;
950 <<
"You are asking to use user defined steps but you did not give any.";
951 G4Exception(
"G4Scheduler::FindUserPreDefinedTimeStep",
955 map<double, double>::iterator fpUserTimeSteps_i =
979 fpUserTimeSteps_i = fpUserTimeSteps_low;
981 else if (fpUserTimeSteps_i == fpUserTimeSteps_low)
988 fpUserTimeSteps_i = fpUserTimeSteps_low;
1002 exceptionDescription
1003 <<
"There is no G4ITModelProcessor to hande IT reaction. ";
1004 exceptionDescription
1005 <<
"You probably did not initialize the G4Scheduler. ";
1006 exceptionDescription
1007 <<
"Just do G4Scheduler::Instance()->Initialize(); ";
1008 exceptionDescription <<
" but only after initializing the run manager.";
1009 G4Exception(
"G4Scheduler::CalculateMinStep",
"ITScheduler005",
1014 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
1015 MemStat mem_first, mem_second, mem_diff;
1018 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
1026 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
1028 mem_diff = mem_second-mem_first;
1029 G4cout <<
"\t || MEM || G4Scheduler::CalculateMinTimeStep || After "
1030 "computing fpModelProcessor -> InitializeStepper, diff is : "
1041 for (; it != end; it++)
1048 exceptionDescription <<
"No track found.";
1049 G4Exception(
"G4Scheduler::CalculateMinStep",
"ITScheduler006",
1076 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
1078 mem_diff = mem_second-mem_first;
1079 G4cout <<
"\t || MEM || G4Scheduler::CalculateMinTimeStep || "
1080 "After looping on tracks, diff is : " << mem_diff <<
G4endl;
1094 const std::vector<std::vector<G4VITStepModel*> >* model =
1097 for (
unsigned i = 0; i < model->size(); i++)
1099 for (
unsigned j = 0; j < (*model)[i].size(); j++)
1110 G4double sampledMinTimeStep(stepper->GetSampledMinTimeStep());
1129 if (
bool(reactants))
1138 stepper->ResetReactants();
1154 if (
bool(reactants))
1165 stepper->ResetReactants();
1170 if (
bool(reactants))
1172 stepper->ResetReactants();
1190 for (; it != end; it++)
1285 << setw(15) <<
"trackID"
1286 << setw(35) <<
"Position"
1287 << setw(25) <<
"Pre step volume"
1288 << setw(25) <<
"Post step volume"
1289 << setw(22) <<
"Process"
1300 size_t initialSize = mainList->
size();
1304 for(
size_t i = 0 ; i < initialSize ; i++)
1313 exceptionDescription <<
"No track was pop back the main track list.";
1314 G4Exception(
"G4Scheduler::DoIt",
"ITScheduler009",
1347 && (volume = nextTouchable->
GetVolume()))
1349 volumeName = volume->
GetName();
1359 volumeName =
"OutOfWorld";
1364 << std::setprecision(3)
1366 << setw(25) << volumeName
1367 << setw(25) <<
"---"
1372 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DOIT)
1373 MemStat mem_first, mem_second, mem_diff;
1376 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DOIT)
1384 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DOIT)
1386 mem_diff = mem_intermediaire-mem_first;
1387 G4cout <<
"\t\t >> || MEM || In DoIT with track "
1393 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DOIT)
1395 mem_diff = mem_second-mem_first;
1396 G4cout <<
"\t >> || MEM || In DoIT with track "
1398 <<
", diff is : " << mem_diff <<
G4endl;
1408 << std::setprecision(3)
1410 << setw(25) <<
"---";
1416 && (volume = nextTouchable->
GetVolume()))
1426 G4cout << setw(25) << volumeName;
1430 G4cout << setw(25) <<
"OutOfWorld";
1449 if(secondaries->empty() ==
false)
1452 for(
size_t j = 0; j < secondaries->size(); j++)
1455 <<
"("<<(*secondaries)[j]->GetTrackID() <<
")"<<
" ";
1499 for (
size_t i = 0; i < secondaries->size(); i++)
1501 delete (*secondaries)[i];
1503 secondaries->clear();
1516 if (!secondaries || secondaries->empty())
1526 G4TrackVector::iterator secondaries_i = secondaries->begin();
1528 for (; secondaries_i != secondaries->end(); secondaries_i++)
1530 G4Track* secondary = *secondaries_i;
1555 std::vector<G4ITReactionChange*>::iterator reactionInfo_i = reactionInfo_v
1558 for (; reactionInfo_i != reactionInfo_v->end(); reactionInfo_i++)
1571 const vector<G4Track*>* productsVector = changes->
GetfSecondary();
1586 if (nbSecondaries > 0)
1588 for (
int i = 0; i < nbSecondaries; i++)
1602 exceptionDescription
1603 <<
"The time of the secondary should not be bigger than the"
1604 " current global time."
1605 <<
" This may cause synchronization problem. If the process you"
1606 " are using required "
1607 <<
"such feature please contact the developpers."
1609 <<
"The global time in the step manager : "
1612 <<
"The global time of the track : "
1616 G4Exception(
"G4Scheduler::ComputeInteractionBetweenTracks",
1618 exceptionDescription);
1639 if (trackA->
GetTrackID() == 0) track = trackA;
1640 else track = trackB;
1643 exceptionDescription
1644 <<
"The problem was found for the reaction between tracks :"
1652 exceptionDescription <<
"Also no step was found"
1653 <<
" ie track->GetStep() == 0 \n";
1656 exceptionDescription <<
"Parent ID of trackA : "
1658 exceptionDescription <<
"Parent ID of trackB : "
1661 exceptionDescription
1662 <<
"The ID of one of the reaction track was not setup.";
1663 G4Exception(
"G4Scheduler::ComputeInteractionBetweenTracks",
1665 exceptionDescription);
1689 reactionInfo_v->clear();
1716 exceptionDescription
1717 <<
"G4Scheduler::PushTrack : You are trying to push tracks while the "
1718 "ITScheduler is running";
1719 G4Exception(
"G4Scheduler::PushTrack",
"ITScheduler012",
1736 std::vector<G4Track*>::iterator fLeadingTracks_i =
fLeadingTracks.begin();
1740 G4Track* track = *fLeadingTracks_i;
1743 G4IT* ITrack =
GetIT(*fLeadingTracks_i);
1772 exceptionDescription
1773 <<
"End tracking is called while G4Scheduler is still running."
1776 G4Exception(
"G4Scheduler::EndTracking",
"ITScheduler017",
1787 for (; it != end; it++)
1799 for (; it != end; it++)
1851 interactionType =
"eInteractionWithMedium";
1854 interactionType =
"eCollisionBetweenTracks";
1857 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
virtual void UserReactionAction(const G4Track &, const G4Track &, const std::vector< G4Track * > &)
Inform about a reaction.
Define what to do before stepping and after stepping.
const G4ThreeVector & GetPosition() const
G4TrackStatus GetTrackStatus() const
void CalculateTimeStep(const G4Track *, const G4double)
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
CLHEP::shared_ptr< std::vector< G4Track * > > G4TrackVectorHandle
static G4ITTypeManager * Instance()
static G4ThreadLocal G4Scheduler * fgScheduler
void DefinePhysicalStepLength(G4Track *)
static const double microsecond
virtual void EndTracking(G4Track *)
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
void FindReaction(std::map< G4Track *, G4TrackVectorHandle > *, const double currentStepTime, const double previousStepTime, const bool reachedUserStepTimeLimit)
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
void InitializeStepper(const G4double ¤tGlobalTime, const G4double &userMinTime)
G4bool WereParentsKilled() const
G4Scheduler & operator=(const G4Scheduler &)
virtual void RegisterModel(G4VITStepModel *, double)
double fDefaultMinTimeStep
std::map< G4Track *, G4TrackVectorHandle > fReactingTracks
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.