62 fCurrentModel.assign(
G4ITType::size(), std::vector<G4VITStepModel*>());
68 fUserMinTimeStep = -1.;
70 fpTrackingManager = 0;
74 fComputeTimeStep =
false;
75 fComputeReaction =
false;
82 fCurrentModel.clear();
83 fReactionInfo.clear();
95 fUserMinTimeStep = -1.;
97 fpTrackingManager = 0;
100 fComputeTimeStep =
false;
101 fComputeReaction =
false;
106 fpModelHandler->RegisterModel(model, time);
112 if(
this == &rhs)
return *
this;
119 fpModelHandler->Initialize();
123 fComputeTimeStep =
false;
124 fComputeReaction =
false;
125 if(fpModelHandler->GetTimeStepComputerFlag()) fComputeTimeStep =
true;
126 if(fpModelHandler->GetReactionProcessFlag()) fComputeReaction =
true;
135 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING) 136 MemStat mem_first, mem_second, mem_diff;
139 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING) 145 InitializeStepper(currentGlobalTime, definedMinTimeStep);
149 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING) 151 mem_diff = mem_second-mem_first;
152 G4cout <<
"\t || MEM || G4Scheduler::CalculateMinTimeStep || After " 153 "computing fpModelProcessor -> InitializeStepper, diff is : " 164 for (; it != end; ++it)
166 G4Track *
track = *it;
171 exceptionDescription <<
"No track found.";
172 G4Exception(
"G4Scheduler::CalculateMinStep",
"ITScheduler006",
179 <<
" ID: " << track->GetTrackID()
180 <<
" at time : " << track->GetGlobalTime()
184 G4TrackStatus trackStatus = track->GetTrackStatus();
185 if (trackStatus == fStopAndKill || trackStatus == fStopButAlive)
193 CalculateTimeStep(track, definedMinTimeStep);
196 ExtractTimeStepperData();
199 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING) 201 mem_diff = mem_second-mem_first;
202 G4cout <<
"\t || MEM || G4Scheduler::CalculateMinTimeStep || " 203 "After looping on tracks, diff is : " << mem_diff <<
G4endl;
218 const std::vector<std::vector<G4VITStepModel*> >* model = GetCurrentModel();
220 for(
unsigned i = 0; i < model->size(); ++i)
222 for(
unsigned j = 0; j < (*model)[i].size(); ++j)
233 G4double sampledMinTimeStep(stepper->GetSampledMinTimeStep());
236 if(sampledMinTimeStep < fTSTimeStep)
250 fTSTimeStep = sampledMinTimeStep;
253 fReactionSet->CleanAllReaction();
263 fReactionSet->AddReactions(fTSTimeStep,
264 const_cast<G4Track*>(fpTrack),
269 else if(fTSTimeStep == sampledMinTimeStep)
294 fReactionSet->AddReactions(fTSTimeStep,
295 const_cast<G4Track*>(fpTrack),
297 stepper->ResetReactants();
304 stepper->ResetReactants();
319 if(fpModelHandler == 0)
323 <<
"No G4ITModelHandler was passed to the modelProcessor.";
324 G4Exception(
"G4ITModelProcessor::InitializeStepper",
325 "ITModelProcessor002",
327 exceptionDescription);
329 const std::vector<std::vector<G4ITModelManager*> >* modelManager =
330 fpModelHandler->GetAllModelManager();
332 if(modelManager == 0)
336 <<
"No G4ITModelManager was register to G4ITModelHandler.";
337 G4Exception(
"G4ITModelProcessor::InitializeStepper",
338 "ITModelProcessor003",
340 exceptionDescription);
343 int nbModels1 = modelManager->size();
354 for(
int i = 0; i < nbModels1; i++)
356 nbModels2 = (*modelManager)[i].size();
358 for(
int j = 0; j <= i; j++)
360 modman = (*modelManager)[i][j];
362 if(modman == 0)
continue;
364 model = modman->
GetModel(currentGlobalTime);
367 #if defined (DEBUG_MEM) 368 MemStat mem_first, mem_second, mem_diff;
371 #if defined (DEBUG_MEM) 378 #if defined (DEBUG_MEM) 380 mem_diff = mem_second-mem_first;
381 G4cout <<
"\t || MEM || G4ITModelProcessor::InitializeStepper || After computing stepper -> Prepare(), diff is : " << mem_diff <<
G4endl;
383 fCurrentModel[i][j] = model;
387 if(nbModels1 == 1 && nbModels2 == 1)
389 fpModelManager = modman;
405 exceptionDescription <<
"No track was passed to the method (track == 0).";
407 "ITModelProcessor004",
409 exceptionDescription);
412 fUserMinTimeStep = userMinTimeStep;
422 fpModel->GetTimeStepper()->CalculateStep(*fpTrack, fUserMinTimeStep);
426 std::vector<G4VITStepModel*>& model = fCurrentModel[
GetIT(fpTrack)
429 for(
int i = 0; i < (int) model.size(); i++)
431 if(model[i] == 0)
continue;
432 model[i]->GetTimeStepper()->CalculateStep(*fpTrack, fUserMinTimeStep);
443 G4bool reachedUserTimeLimit,
453 if(fReactionSet->Empty())
462 FindReaction(fReactionSet,
465 reachedUserTimeLimit);
470 std::vector<G4ITReactionChange*> * reactionInfo_v = GetReactionInfo();
471 std::vector<G4ITReactionChange*>::iterator reactionInfo_i = reactionInfo_v
474 for(; reactionInfo_i != reactionInfo_v->end(); ++reactionInfo_i)
477 G4Track* trackA =
const_cast<G4Track*
>(changes->
GetTrackA());
478 G4Track* trackB =
const_cast<G4Track*
>(changes->
GetTrackB());
480 if(trackA == 0 || trackB == 0 || trackA->GetTrackStatus() == fStopAndKill
481 || trackB->GetTrackStatus() == fStopAndKill)
continue;
484 const vector<G4Track*>* productsVector = changes->
GetfSecondary();
486 if(fpUserTimeStepAction)
498 << trackA->GetTrackID() <<
") + " <<
GetIT(trackB)->
GetName() <<
" (" 499 << trackB->GetTrackID() <<
") -> ";
503 if(nbSecondaries > 0)
505 for(
int i = 0; i < nbSecondaries; ++i)
508 if(fVerbose && i != 0)
G4cout <<
" + ";
511 G4Track* secondary = (*productsVector)[i];
512 fpTrackContainer->_PushTrack(secondary);
514 trackB->GetTrackID());
516 if(secondary->GetGlobalTime() - fGlobalTime > fTimeTolerance)
519 exceptionDescription <<
"The time of the secondary should not be bigger than the" 520 " current global time." 521 <<
" This may cause synchronization problem. If the process you" 522 " are using required " 523 <<
"such feature please contact the developpers." <<
G4endl<<
"The global time in the step manager : " 526 <<
"The global time of the track : " 527 <<
G4BestUnit(secondary->GetGlobalTime(),
"Time")
530 G4Exception(
"G4Scheduler::ComputeInteractionBetweenTracks",
533 exceptionDescription);
539 << secondary->GetTrackID() <<
")";
546 if(fVerbose)
G4cout <<
"No product";
552 if(trackA->GetTrackID() == 0 || trackB->GetTrackID() == 0)
555 if(trackA->GetTrackID() == 0) track = trackA;
560 <<
"The problem was found for the reaction between tracks :" 561 << trackA->GetParticleDefinition()->GetParticleName() <<
" (" 562 << trackA->GetTrackID() <<
") & " 563 << trackB->GetParticleDefinition()->GetParticleName() <<
" (" 564 << trackB->GetTrackID() <<
"). \n";
566 if(track->GetStep() == 0)
568 exceptionDescription <<
"Also no step was found" 569 <<
" ie track->GetStep() == 0 \n";
572 exceptionDescription <<
"Parent ID of trackA : " 573 << trackA->GetParentID() <<
"\n";
574 exceptionDescription <<
"Parent ID of trackB : " 575 << trackB->GetParentID() <<
"\n";
578 <<
"The ID of one of the reaction track was not setup.";
579 G4Exception(
"G4Scheduler::ComputeInteractionBetweenTracks",
582 exceptionDescription);
594 trackA->SetTrackStatus(fStopAndKill);
595 trackB->SetTrackStatus(fStopAndKill);
599 fpTrackingManager->EndTracking(trackA);
600 fpTrackingManager->EndTracking(trackB);
606 reactionInfo_v->clear();
615 fReactionSet->CleanAllReaction();
617 fpTrackContainer->MergeSecondariesWithMainList();
618 fpTrackContainer->KillTracks();
623 const double currentStepTime,
624 const double previousStepTime,
625 const bool reachedUserStepTimeLimit)
630 if(reactionSet == 0)
return;
631 if(fpModelHandler->GetAllModelManager()->empty())
return;
635 std::map<G4Track*, G4ITReactionPerTrackPtr, compTrackPerID>::iterator tracks_i =
636 reactionPerTrackMap.begin();
643 for(tracks_i = reactionPerTrackMap.begin();
644 tracks_i != reactionPerTrackMap.end();
645 tracks_i = reactionPerTrackMap.begin())
648 G4Track* trackA = tracks_i->first;
649 if(trackA->GetTrackStatus() == fStopAndKill)
661 const std::vector<G4VITStepModel*> model = fCurrentModel[ITypeA];
668 assert(reactionList.begin() != reactionList.end());
670 for(G4ITReactionList::iterator it = reactionList.begin();
671 it != reactionList.end(); it = reactionList.begin())
674 trackB = reaction->GetReactant(trackA);
675 if(trackB->GetTrackStatus() == fStopAndKill)
685 <<
"The IT reaction process sent back a reaction between trackA and trackB. ";
686 exceptionDescription <<
"The problem is trackA == trackB";
688 "ITModelProcessor005",
690 exceptionDescription);
696 if(ITypeB != ITypeBtmp)
700 if(model[ITypeB]) process = model[ITypeB]->GetReactionProcess();
709 reachedUserStepTimeLimit))
716 fReactionInfo.push_back(changes);
virtual G4bool TestReactibility(const G4Track &, const G4Track &, const double, const double, bool)=0
const G4Track * GetTrackA()
std::ostringstream G4ExceptionDescription
void SetParentID(int, int)
G4shared_ptr< std::vector< G4Track * > > G4TrackVectorHandle
void CalculateTimeStep(const G4Track *, const G4double)
G4shared_ptr< G4ITReaction > G4ITReactionPtr
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
virtual const G4String & GetName() const =0
virtual void ResetReactants()
G4int GetNumberOfSecondaries() const
std::map< G4Track *, G4ITReactionPerTrackPtr, compTrackPerID > G4ITReactionPerTrackMap
G4ITReactionPerTrackMap & GetReactionMap()
static void SetTimes(const G4double &, const G4double &)
G4double CalculateMinTimeStep(G4double currentGlobalTime, G4double definedMinTimeStep)
static G4ITReactionSet * Instance()
void SelectThisReaction(G4ITReactionPtr reaction)
void FindReaction(G4ITReactionSet *reactionSet, const double currentStepTime, const double previousStepTime, const bool reachedUserStepTimeLimit)
G4IT * GetIT(const G4Track *track)
std::list< G4ITReactionPtr > G4ITReactionList
G4GLOB_DLL std::ostream G4cout
G4bool WereParentsKilled() const
virtual void UserReactionAction(const G4Track &, const G4Track &, const std::vector< G4Track *> *)
virtual ~G4ITModelProcessor()
G4VITTimeStepComputer * GetTimeStepper()
const G4Track * GetTrackB()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4ITModelProcessor & operator=(const G4ITModelProcessor &other)
G4shared_ptr< G4ITReactionPerTrack > G4ITReactionPerTrackPtr
void RegisterModel(double time, G4VITStepModel *)
virtual const G4ITType GetITType() const =0
void ComputeTrackReaction(G4ITStepStatus fITStepStatus, G4double fGlobalTime, G4double currentTimeStep, G4double previousTimeStep, G4bool reachedUserTimeLimit, G4double fTimeTolerance, G4UserTimeStepAction *fpUserTimeStepAction, G4int fVerbose)
void InitializeStepper(G4double currentGlobalTime, G4double userMinTime)
static G4ITTrackHolder * Instance()
G4VITStepModel * GetModel(const G4double globalTime)
std::vector< G4Track * > * GetfSecondary()
virtual G4ITReactionChange * MakeReaction(const G4Track &, const G4Track &)=0
void ExtractTimeStepperData()