Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4ITStepProcessor.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//
27// Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
28//
29// History:
30// -----------
31// 10 Oct 2011 M.Karamitros created
32//
33// -------------------------------------------------------------------
34
35#include "G4ITStepProcessor.hh"
36#include "G4UImanager.hh"
37#include "G4ForceCondition.hh"
38#include "G4GPILSelection.hh"
41#include "G4ParticleTable.hh"
44#include "G4IT.hh"
45#include "G4ITNavigator.hh" // Include from 'geometry'
46
47#include "G4VITProcess.hh"
48#include "G4VProcess.hh"
49#include "G4ITTransportation.hh"
50
51#include "G4ITTrackHolder.hh"
52
56
58
59#include <iomanip> // Include from 'system'
60#include <vector> // Include from 'system'
61
62using namespace std;
63
64static const std::size_t SizeOfSelectedDoItVector = 100;
65
66template<typename T>
67 inline bool IsInf(T value)
68 {
69 return std::numeric_limits<T>::has_infinity
70 && value == std::numeric_limits<T>::infinity();
71 }
72
73//______________________________________________________________________________
74
76{
77 fpVerbose = 0;
78 // fpUserSteppingAction = 0 ;
79 fStoreTrajectory = 0;
80 fpTrackingManager = 0;
81 fpNavigator = 0;
82 kCarTolerance = -1.;
83 fInitialized = false;
84 fPreviousTimeStep = DBL_MAX;
85 fILTimeStep = DBL_MAX;
86 fpTrackContainer = 0;
87
90}
91
92//______________________________________________________________________________
93
94//G4ITStepProcessor::
97 fSelectedAtRestDoItVector(G4VITProcess::GetMaxProcessIndex(), 0),
98 fSelectedPostStepDoItVector(G4VITProcess::GetMaxProcessIndex(), 0)
99{
100 fPhysicalStep = -1.;
101 fPreviousStepSize = -1.;
102
103 fSafety = -1.;
104 fProposedSafety = -1.;
105 fEndpointSafety = -1;
106
108
110}
111
112//______________________________________________________________________________
113
114//G4ITStepProcessor::
117 fSelectedAtRestDoItVector(right.fSelectedAtRestDoItVector),
118 fSelectedPostStepDoItVector(right.fSelectedPostStepDoItVector)
119{
122
123 fSafety = right.fSafety;
126
127 fStepStatus = right.fStepStatus;
128
130}
131
132//______________________________________________________________________________
133
134//G4ITStepProcessor::
136//G4ITStepProcessor::
138{
139 if(this == &right) return *this;
140
145
148
149 fSafety = right.fSafety;
152
153 fStepStatus = right.fStepStatus;
154
156 return *this;
157}
158
159//______________________________________________________________________________
160
161//G4ITStepProcessor::
163{
164 ;
165}
166
167//______________________________________________________________________________
168
170{
171 std::map<const G4ParticleDefinition*, ProcessGeneralInfo*>::iterator it;
172
173 for(it = fProcessGeneralInfoMap.begin(); it != fProcessGeneralInfoMap.end();
174 it++)
175 {
176 if(it->second)
177 {
178 delete it->second;
179 it->second = 0;
180 }
181 }
182
183 fProcessGeneralInfoMap.clear();
184}
185
186//______________________________________________________________________________
187
189{
190 fInitialized = false;
192 Initialize();
193}
194
195//______________________________________________________________________________
196
198{
200 if(fInitialized) return;
201 // ActiveOnlyITProcess();
202
204 ->GetNavigatorForTracking());
205
206 fPhysIntLength = DBL_MAX;
207 kCarTolerance = 0.5
209
210 if(fpVerbose == 0)
211 {
212 G4ITTrackingInteractivity* interactivity = fpTrackingManager->GetInteractivity();
213
214 if(interactivity)
215 {
216 fpVerbose = interactivity->GetSteppingVerbose();
217 fpVerbose->SetStepProcessor(this);
218 }
219 }
220
221 fpTrackContainer = G4ITTrackHolder::Instance();
222
223 fInitialized = true;
224}
225//______________________________________________________________________________
226
228{
229 if(fpStep)
230 {
231 fpStep->DeleteSecondaryVector();
232 delete fpStep;
233 }
234
235 if(fpSecondary) delete fpSecondary;
237 //G4ITTransportationManager::DeleteInstance();
238
239 // if(fpUserSteppingAction) delete fpUserSteppingAction;
240}
241//______________________________________________________________________________
242// should not be used
244{
245 fpVerbose = rhs.fpVerbose;
246 fStoreTrajectory = rhs.fStoreTrajectory;
247
248 // fpUserSteppingAction = 0 ;
249 fpTrackingManager = 0;
250 fpNavigator = 0;
251 fInitialized = false;
252
253 kCarTolerance = rhs.kCarTolerance;
254 fInitialized = false;
255 fPreviousTimeStep = DBL_MAX;
256
259 fpTrackContainer = 0;
260 fILTimeStep = DBL_MAX;
261}
262
263//______________________________________________________________________________
264
266{
267 fLeadingTracks.Reset();
268}
269
270//______________________________________________________________________________
271
273{
274 fLeadingTracks.PrepareLeadingTracks();
275}
276
277//______________________________________________________________________________
278
280{
281 if(this == &rhs) return *this; // handle self assignment
282 //assignment operator
283 return *this;
284}
285
286//______________________________________________________________________________
287
289{
290 // Method not used for the time being
291#ifdef debug
292 G4cout<<"G4ITStepProcessor::CloneProcesses: is called"<<G4endl;
293#endif
294
297 ->GetIterator();
298
299 theParticleIterator->reset();
300 // TODO : Ne faire la boucle que sur les IT **** !!!
301 while((*theParticleIterator)())
302 {
303 G4ParticleDefinition* particle = theParticleIterator->value();
304 G4ProcessManager* pm = particle->GetProcessManager();
305
306 if(!pm)
307 {
308 G4cerr << "ERROR - G4ITStepProcessor::GetProcessNumber()" << G4endl<< " ProcessManager is NULL for particle = "
309 << particle->GetParticleName() << ", PDG_code = "
310 << particle->GetPDGEncoding() << G4endl;
311 G4Exception("G4ITStepProcessor::GetProcessNumber()", "ITStepProcessor0001",
312 FatalException, "Process Manager is not found.");
313 return;
314 }
315
317 }
318}
319
320//______________________________________________________________________________
321
323{
324 // Method not used for the time being
325 G4ProcessVector* processVector = processManager->GetProcessList();
326
327 G4VITProcess* itProcess = 0;
328 for(G4int i = 0; i < (G4int)processVector->size(); ++i)
329 {
330 G4VProcess* base_process = (*processVector)[i];
331 itProcess = dynamic_cast<G4VITProcess*>(base_process);
332
333 if(!itProcess)
334 {
335 processManager->SetProcessActivation(base_process, false);
336 }
337 }
338}
339
340//______________________________________________________________________________
341
344{
345
346#ifdef debug
347 G4cout<<"G4ITStepProcessor::GetProcessNumber: is called track"<<G4endl;
348#endif
349 if(!pm)
350 {
351 G4cerr << "ERROR - G4SteppingManager::GetProcessNumber()" << G4endl<< " ProcessManager is NULL for particle = "
352 << particle->GetParticleName() << ", PDG_code = "
353 << particle->GetPDGEncoding() << G4endl;
354 G4Exception("G4SteppingManager::GetProcessNumber()", "ITStepProcessor0002",
355 FatalException, "Process Manager is not found.");
356 return;
357 }
358
359 std::map<const G4ParticleDefinition*, ProcessGeneralInfo*>::iterator it =
360 fProcessGeneralInfoMap.find(particle);
361 if(it != fProcessGeneralInfoMap.end())
362 {
363 G4Exception("G4SteppingManager::SetupGeneralProcessInfo()",
364 "ITStepProcessor0003",
365 FatalException, "Process info already registered.");
366 return;
367 }
368
369 // here used as temporary
370 fpProcessInfo = new ProcessGeneralInfo();
371
372 // AtRestDoits
373 fpProcessInfo->MAXofAtRestLoops = pm->GetAtRestProcessVector()->entries();
375 fpProcessInfo->fpAtRestGetPhysIntVector =
377#ifdef debug
378 G4cout << "G4ITStepProcessor::GetProcessNumber: #ofAtRest="
379 << fpProcessInfo->MAXofAtRestLoops << G4endl;
380#endif
381
382 // AlongStepDoits
383 fpProcessInfo->MAXofAlongStepLoops =
385 fpProcessInfo->fpAlongStepDoItVector =
387 fpProcessInfo->fpAlongStepGetPhysIntVector =
389#ifdef debug
390 G4cout << "G4ITStepProcessor::GetProcessNumber:#ofAlongStp="
391 << fpProcessInfo->MAXofAlongStepLoops << G4endl;
392#endif
393
394 // PostStepDoits
395 fpProcessInfo->MAXofPostStepLoops =
398 fpProcessInfo->fpPostStepGetPhysIntVector =
400#ifdef debug
401 G4cout << "G4ITStepProcessor::GetProcessNumber: #ofPostStep="
402 << fpProcessInfo->MAXofPostStepLoops << G4endl;
403#endif
404
405 if (SizeOfSelectedDoItVector<fpProcessInfo->MAXofAtRestLoops ||
406 SizeOfSelectedDoItVector<fpProcessInfo->MAXofAlongStepLoops ||
407 SizeOfSelectedDoItVector<fpProcessInfo->MAXofPostStepLoops )
408 {
409 G4cerr << "ERROR - G4ITStepProcessor::GetProcessNumber()" << G4endl
410 << " SizeOfSelectedDoItVector= " << SizeOfSelectedDoItVector
411 << " ; is smaller then one of MAXofAtRestLoops= "
412 << fpProcessInfo->MAXofAtRestLoops << G4endl
413 << " or MAXofAlongStepLoops= " << fpProcessInfo->MAXofAlongStepLoops
414 << " or MAXofPostStepLoops= " << fpProcessInfo->MAXofPostStepLoops << G4endl;
415 G4Exception("G4ITStepProcessor::GetProcessNumber()",
416 "ITStepProcessor0004", FatalException,
417 "The array size is smaller than the actual No of processes.");
418 }
419
420 if(!fpProcessInfo->fpAtRestDoItVector &&
421 !fpProcessInfo->fpAlongStepDoItVector &&
422 !fpProcessInfo->fpPostStepDoItVector)
423 {
424 G4ExceptionDescription exceptionDescription;
425 exceptionDescription << "No DoIt process found ";
426 G4Exception("G4ITStepProcessor::DoStepping","ITStepProcessor0005",
427 FatalErrorInArgument,exceptionDescription);
428 return;
429 }
430
431 if(fpProcessInfo->fpAlongStepGetPhysIntVector
432 && fpProcessInfo->MAXofAlongStepLoops>0)
433 {
434 fpProcessInfo->fpTransportation = dynamic_cast<G4ITTransportation*>
435 ((*fpProcessInfo->fpAlongStepGetPhysIntVector)
436 [G4int(fpProcessInfo->MAXofAlongStepLoops-1)]);
437
438 if(fpProcessInfo->fpTransportation == 0)
439 {
440 G4ExceptionDescription exceptionDescription;
441 exceptionDescription << "No transportation process found ";
442 G4Exception("G4ITStepProcessor::SetupGeneralProcessInfo",
443 "ITStepProcessor0006",
444 FatalErrorInArgument,exceptionDescription);
445 }
446 }
447 fProcessGeneralInfoMap[particle] = fpProcessInfo;
448 // fpProcessInfo = 0;
449}
450
451//______________________________________________________________________________
452
454{
455 fpTrack = track;
456 if(fpTrack)
457 {
458 fpITrack = GetIT(fpTrack);
459 fpStep = const_cast<G4Step*>(fpTrack->GetStep());
460
461 if(fpITrack)
462 {
463 fpTrackingInfo = fpITrack->GetTrackingInfo();
464 }
465 else
466 {
467 fpTrackingInfo = 0;
468 G4cerr << "Track ID : " << fpTrack->GetTrackID() << G4endl;
469
471 errMsg << "No IT pointer was attached to the track you try to process.";
472 G4Exception("G4ITStepProcessor::SetTrack",
473 "ITStepProcessor0007",
475 errMsg);
476 }
477 }
478 else
479 {
480 fpITrack = 0;
481 fpStep = 0;
482 }
483}
484//______________________________________________________________________________
485
487{
488 G4ParticleDefinition* particle = fpTrack->GetDefinition();
489 std::map<const G4ParticleDefinition*, ProcessGeneralInfo*>::iterator it =
490 fProcessGeneralInfoMap.find(particle);
491
492 if(it == fProcessGeneralInfoMap.end())
493 {
495 fpTrack->GetDefinition()->GetProcessManager());
496 if(fpProcessInfo == 0)
497 {
498 G4ExceptionDescription exceptionDescription("...");
499 G4Exception("G4ITStepProcessor::GetProcessNumber",
500 "ITStepProcessor0008",
502 exceptionDescription);
503 return;
504 }
505 }
506 else
507 {
508 fpProcessInfo = it->second;
509 }
510}
511
512//______________________________________________________________________________
513
515{
516 fpSecondary = fpStep->GetfSecondary();
517 fpPreStepPoint = fpStep->GetPreStepPoint();
518 fpPostStepPoint = fpStep->GetPostStepPoint();
519
520 fpState = (G4ITStepProcessorState*) fpITrack->GetTrackingInfo()
522
525}
526
527//______________________________________________________________________________
528
530{
531 // Reset the secondary particles
532 fN2ndariesAtRestDoIt = 0;
533 fN2ndariesAlongStepDoIt = 0;
534 fN2ndariesPostStepDoIt = 0;
535}
536
537//______________________________________________________________________________
538
540{
541 // Select the rest process which has the shortest time before
542 // it is invoked. In rest processes, GPIL()
543 // returns the time before a process occurs.
544 G4double lifeTime(DBL_MAX), shortestLifeTime (DBL_MAX);
545
546 fAtRestDoItProcTriggered = 0;
547 shortestLifeTime = DBL_MAX;
548
549 unsigned int NofInactiveProc=0;
550
551 for( G4int ri=0; ri < (G4int)fpProcessInfo->MAXofAtRestLoops; ++ri )
552 {
553 fpCurrentProcess = dynamic_cast<G4VITProcess*>((*fpProcessInfo->fpAtRestGetPhysIntVector)[ri]);
554 if (fpCurrentProcess== 0)
555 {
556 (fpState->fSelectedAtRestDoItVector)[ri] = InActivated;
557 NofInactiveProc++;
558 continue;
559 } // NULL means the process is inactivated by a user on fly.
560
561 fCondition=NotForced;
562 fpCurrentProcess->SetProcessState(
563 fpTrackingInfo->GetProcessState(fpCurrentProcess->GetProcessID()));
564
565 lifeTime = fpCurrentProcess->AtRestGPIL( *fpTrack, &fCondition );
566 fpCurrentProcess->ResetProcessState();
567
568 if(fCondition==Forced)
569 {
570 (fpState->fSelectedAtRestDoItVector)[ri] = Forced;
571 }
572 else
573 {
574 (fpState->fSelectedAtRestDoItVector)[ri] = InActivated;
575 if(lifeTime < shortestLifeTime )
576 {
577 shortestLifeTime = lifeTime;
578 fAtRestDoItProcTriggered = G4int(ri);
579 }
580 }
581 }
582
583 (fpState->fSelectedAtRestDoItVector)[fAtRestDoItProcTriggered] = NotForced;
584
585// G4cout << " --> Selected at rest process : "
586// << (*fpProcessInfo->fpAtRestGetPhysIntVector)[fAtRestDoItProcTriggered]
587// ->GetProcessName()
588// << G4endl;
589
590 fTimeStep = shortestLifeTime;
591
592 // at least one process is necessary to destroy the particle
593 // exit with warning
594 if(NofInactiveProc==fpProcessInfo->MAXofAtRestLoops)
595 {
596 G4cerr << "ERROR - G4ITStepProcessor::InvokeAtRestDoItProcs()" << G4endl
597 << " No AtRestDoIt process is active!" << G4endl;
598 }
599}
600
601//_________________________________________________________________________
603{
604 G4TrackManyList* mainList = fpTrackContainer->GetMainList();
605 G4TrackManyList::iterator it = mainList ->begin();
606 G4TrackManyList::iterator end = mainList ->end();
607
608 SetPreviousStepTime(previousTimeStep);
609
610 fILTimeStep = DBL_MAX;
611
612 for (; it != end; )
613 {
614 G4Track * track = *it;
615
616#ifdef DEBUG
617 G4cout << "*CIL* " << GetIT(track)->GetName()
618 << " ID: " << track->GetTrackID()
619 << " at time : " << track->GetGlobalTime()
620 << G4endl;
621#endif
622
623 ++it;
625
627 }
628
629 return fILTimeStep;
630}
631
632//_________________________________________________________________________
633
635{
636 assert(fpTrack != 0);
637 if (fpTrack == 0)
638 {
640 return;
641 }
642
643 // assert(fpTrack->GetTrackStatus() != fStopAndKill);
644
645 if (fpTrack->GetTrackStatus() == fStopAndKill)
646 {
647// trackContainer->GetMainList()->pop(fpTrack);
648 fpTrackingManager->EndTracking(fpTrack);
650 return;
651 }
652
653 if (IsInf(fTimeStep))
654 {
655 // G4cout << "!!!!!!!!!!!! IS INF " << track->GetTrackID() << G4endl;
657 return;
658 }
659 else if (fTimeStep < fILTimeStep - DBL_EPSILON)
660 {
661 // G4cout << "!!!!!!!!!!!! TEMPS DIFFERENTS "
662 // << track->GetTrackID() << G4endl;
663
664 fLeadingTracks.Reset();
665
666 fILTimeStep = GetInteractionTime();
667
668// G4cout << "Will set leading step to true for time :"
669// << SP -> GetInteractionTime() << " against fTimeStep : "
670// << G4BestUnit(fILTimeStep, "Time") << " the trackID is : " << track->GetTrackID()
671// << G4endl;
672
673// GetIT(fpTrack)->GetTrackingInfo()->SetLeadingStep(true);
674 fLeadingTracks.Push(fpTrack);
675 }
676 else if(fabs(fILTimeStep - fTimeStep) < DBL_EPSILON )
677 {
678
679 // G4cout << "!!!!!!!!!!!! MEME TEMPS " << track->GetTrackID() << G4endl;
680 // G4cout << "Will set leading step to true for time :"
681 // << SP -> GetInteractionTime() << " against fTimeStep : "
682 // << fTimeStep << " the trackID is : " << track->GetTrackID()<< G4endl;
683// GetIT(fpTrack)->GetTrackingInfo()->SetLeadingStep(true);
684 fLeadingTracks.Push(fpTrack);
685 }
686 // else
687 // {
688 // G4cout << "!!!! Bigger time : " << "currentTime : "<<fILTimeStep
689 // << " proposedTime : " << SP -> GetInteractionTime() << G4endl;
690 // }
691
693}
694
695//___________________________________________________________________________
696
698{
699 SetTrack(track);
701}
702
703//______________________________________________________________________________
704
706{
707 // DEBUG
708 // G4cout << "SetInitialStep for : " << fpITrack-> GetName() << G4endl;
709 //________________________________________________________
710 // Initialize geometry
711
712 if(!fpTrack->GetTouchableHandle())
713 {
714 //==========================================================================
715 // Create navigator state and Locate particle in geometry
716 //==========================================================================
717 /*
718 fpNavigator->NewNavigatorStateAndLocate(fpTrack->GetPosition(),
719 fpTrack->GetMomentumDirection());
720
721 fpITrack->GetTrackingInfo()->
722 SetNavigatorState(fpNavigator->GetNavigatorState());
723 */
724 fpNavigator->NewNavigatorState();
725 fpITrack->GetTrackingInfo()->SetNavigatorState(fpNavigator
726 ->GetNavigatorState());
727
728 G4ThreeVector direction = fpTrack->GetMomentumDirection();
729 fpNavigator->LocateGlobalPointAndSetup(fpTrack->GetPosition(),
730 &direction,
731 false,
732 false); // was false, false
733
734 fpState->fTouchableHandle = fpNavigator->CreateTouchableHistory();
735
736 fpTrack->SetTouchableHandle(fpState->fTouchableHandle);
737 fpTrack->SetNextTouchableHandle(fpState->fTouchableHandle);
738 }
739 else
740 {
741 fpState->fTouchableHandle = fpTrack->GetTouchableHandle();
742 fpTrack->SetNextTouchableHandle(fpState->fTouchableHandle);
743
744 //==========================================================================
745 // Create OR set navigator state
746 //==========================================================================
747
748 if(fpITrack->GetTrackingInfo()->GetNavigatorState())
749 {
750 fpNavigator->SetNavigatorState(fpITrack->GetTrackingInfo()
752 fpITrack->GetTrackingInfo()->SetNavigatorState(fpNavigator
753 ->GetNavigatorState());
754 }
755 else
756 {
757 fpNavigator->NewNavigatorState(*((G4TouchableHistory*) fpState
758 ->fTouchableHandle()));
759 fpITrack->GetTrackingInfo()->SetNavigatorState(fpNavigator
760 ->GetNavigatorState());
761 }
762
763 G4VPhysicalVolume* oldTopVolume =
764 fpTrack->GetTouchableHandle()->GetVolume();
765
766 //==========================================================================
767 // Locate particle in geometry
768 //==========================================================================
769
770// G4VPhysicalVolume* newTopVolume =
771// fpNavigator->LocateGlobalPointAndSetup(
772// fpTrack->GetPosition(),
773// &fpTrack->GetMomentumDirection(),
774// true, false);
775
776 G4VPhysicalVolume* newTopVolume =
777 fpNavigator->ResetHierarchyAndLocate(fpTrack->GetPosition(),
778 fpTrack->GetMomentumDirection(),
779 *((G4TouchableHistory*) fpTrack
780 ->GetTouchableHandle()()));
781
782 if(newTopVolume != oldTopVolume || oldTopVolume->GetRegularStructureId()
783 == 1)
784 {
785 fpState->fTouchableHandle = fpNavigator->CreateTouchableHistory();
786 fpTrack->SetTouchableHandle(fpState->fTouchableHandle);
787 fpTrack->SetNextTouchableHandle(fpState->fTouchableHandle);
788 }
789 }
790
791 fpCurrentVolume = fpState->fTouchableHandle->GetVolume();
792
793 //________________________________________________________
794 // If the primary track has 'Suspend' or 'PostponeToNextEvent' state,
795 // set the track state to 'Alive'.
796 if((fpTrack->GetTrackStatus() == fSuspend) || (fpTrack->GetTrackStatus()
798 {
799 fpTrack->SetTrackStatus(fAlive);
800 }
801
802 //HoangTRAN: it's better to check the status here
803 if(fpTrack->GetTrackStatus() == fStopAndKill) return;
804
805 // If the primary track has 'zero' kinetic energy, set the track
806 // state to 'StopButAlive'.
807 if(fpTrack->GetKineticEnergy() <= 0.0)
808 {
810 }
811 //________________________________________________________
812 // Set vertex information of G4Track at here
813 if(fpTrack->GetCurrentStepNumber() == 0)
814 {
815 fpTrack->SetVertexPosition(fpTrack->GetPosition());
817 fpTrack->SetVertexKineticEnergy(fpTrack->GetKineticEnergy());
819 }
820 //________________________________________________________
821 // If track is already outside the world boundary, kill it
822 if(fpCurrentVolume == 0)
823 {
824 // If the track is a primary, stop processing
825 if(fpTrack->GetParentID() == 0)
826 {
827 G4cerr << "ERROR - G4ITStepProcessor::SetInitialStep()" << G4endl<< " Primary particle starting at - "
828 << fpTrack->GetPosition()
829 << " - is outside of the world volume." << G4endl;
830 G4Exception("G4ITStepProcessor::SetInitialStep()", "ITStepProcessor0011",
831 FatalException, "Primary vertex outside of the world!");
832 }
833
834 fpTrack->SetTrackStatus( fStopAndKill );
835 G4cout << "WARNING - G4ITStepProcessor::SetInitialStep()" << G4endl
836 << " Initial track position is outside world! - "
837 << fpTrack->GetPosition() << G4endl;
838 }
839 else
840 {
841 // Initial set up for attribues of 'Step'
842 fpStep->InitializeStep( fpTrack );
843 }
844
845 fpState->fStepStatus = fUndefined;
846}
847//______________________________________________________________________________
848
850{
851
852 if(!fpStep)
853 {
854 // Create new Step and give it to the track
855 fpStep = new G4Step();
856 fpTrack->SetStep(fpStep);
857 fpSecondary = fpStep->NewSecondaryVector();
858
859 // Create new state and set it in the trackingInfo
860 fpState = new G4ITStepProcessorState();
862
863 SetupMembers();
865
866 fpTrackingManager->StartTracking(fpTrack);
867 }
868 else
869 {
870 SetupMembers();
871
872 fpState->fPreviousStepSize = fpTrack->GetStepLength();
873 /***
874 // Send G4Step information to Hit/Dig if the volume is sensitive
875 fpCurrentVolume = fpStep->GetPreStepPoint()->GetPhysicalVolume();
876 StepControlFlag = fpStep->GetControlFlag();
877 if( fpCurrentVolume != 0 && StepControlFlag != AvoidHitInvocation)
878 {
879 fpSensitive = fpStep->GetPreStepPoint()->
880 GetSensitiveDetector();
881
882 // if( fSensitive != 0 ) {
883 // fSensitive->Hit(fStep);
884 // }
885 }
886 ***/
887 // Store last PostStepPoint to PreStepPoint, and swap current and next
888 // volume information of G4Track. Reset total energy deposit in one Step.
889 fpStep->CopyPostToPreStepPoint();
890 fpStep->ResetTotalEnergyDeposit();
891
892 //JA Set the volume before it is used (in DefineStepLength() for User Limit)
893 fpCurrentVolume = fpStep->GetPreStepPoint()->GetPhysicalVolume();
894 /*
895 G4cout << G4endl;
896 G4cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << G4endl;
897 G4cout << "PreStepPoint Volume : "
898 << fpCurrentVolume->GetName() << G4endl;
899 G4cout << "Track Touchable : "
900 << fpTrack->GetTouchableHandle()->GetVolume()->GetName() << G4endl;
901 G4cout << "Track NextTouchable : "
902 << fpTrack->GetNextTouchableHandle()->GetVolume()->GetName()
903 << G4endl;
904 */
905 // Reset the step's auxiliary points vector pointer
907
908 // Switch next touchable in track to current one
909 fpTrack->SetTouchableHandle(fpTrack->GetNextTouchableHandle());
910 fpState->fTouchableHandle = fpTrack->GetTouchableHandle();
911 fpTrack->SetNextTouchableHandle(fpState->fTouchableHandle);
912
913 //! ADDED BACK
914 /*
915 G4VPhysicalVolume* oldTopVolume =
916 fpTrack->GetTouchableHandle()->GetVolume();
917 fpNavigator->SetNavigatorState(
918 fpITrack->GetTrackingInfo()->GetNavigatorState());
919
920 G4VPhysicalVolume* newTopVolume = fpNavigator->ResetHierarchyAndLocate(
921 fpTrack->GetPosition(), fpTrack->GetMomentumDirection(),
922 *((G4TouchableHistory*) fpTrack->GetTouchableHandle()()));
923
924 // G4VPhysicalVolume* newTopVolume=
925 // fpNavigator->LocateGlobalPointAndSetup(fpTrack->GetPosition(),
926 // &fpTrack->GetMomentumDirection(),
927 // true, false);
928
929 // G4cout << "New Top Volume : " << newTopVolume->GetName() << G4endl;
930
931 if (newTopVolume != oldTopVolume || oldTopVolume->GetRegularStructureId()
932 == 1)
933 {
934 fpState->fTouchableHandle = fpNavigator->CreateTouchableHistory();
935 fpTrack->SetTouchableHandle(fpState->fTouchableHandle);
936 fpTrack->SetNextTouchableHandle(fpState->fTouchableHandle);
937 }
938
939 */
940 //! ADDED BACK
941 //==========================================================================
942 // Only reset navigator state + reset volume hierarchy (internal)
943 // No need to relocate
944 //==========================================================================
945 fpNavigator->SetNavigatorState(fpITrack->GetTrackingInfo()
947 }
948}
949
950//______________________________________________________________________________
951
952// ------------------------------------------------------------------------
953// Compute Interaction Length
954// ------------------------------------------------------------------------
956{
957
959
960#ifdef G4VERBOSE
961 // !!!!! Verbose
962 if(fpVerbose) fpVerbose->DPSLStarted();
963#endif
964
965 G4TrackStatus trackStatus = fpTrack->GetTrackStatus();
966
967 if(trackStatus == fStopAndKill)
968 {
969 return;
970 }
971
972 if(trackStatus == fStopButAlive)
973 {
974 fpITrack->GetTrackingInfo()->SetNavigatorState(fpNavigator
975 ->GetNavigatorState());
976 fpNavigator->ResetNavigatorState();
977 return GetAtRestIL();
978 }
979
980 // Find minimum Step length and corresponding time
981 // demanded by active disc./cont. processes
982
983 // ReSet the counter etc.
984 fpState->fPhysicalStep = DBL_MAX; // Initialize by a huge number
985 fPhysIntLength = DBL_MAX; // Initialize by a huge number
986
987 G4double proposedTimeStep = DBL_MAX;
988 G4VProcess* processWithPostStepGivenByTimeStep(0);
989
990 // GPIL for PostStep
991 fPostStepDoItProcTriggered = fpProcessInfo->MAXofPostStepLoops;
992 fPostStepAtTimeDoItProcTriggered = fpProcessInfo->MAXofPostStepLoops;
993
994 // G4cout << "fpProcessInfo->MAXofPostStepLoops : "
995 // << fpProcessInfo->MAXofPostStepLoops
996 // << " mol : " << fpITrack -> GetName()
997 // << " id : " << fpTrack->GetTrackID()
998 // << G4endl;
999
1000 for(std::size_t np = 0; np < fpProcessInfo->MAXofPostStepLoops; ++np)
1001 {
1002 fpCurrentProcess = dynamic_cast<G4VITProcess*>((*fpProcessInfo
1004 if(fpCurrentProcess == 0)
1005 {
1007 continue;
1008 } // NULL means the process is inactivated by a user on fly.
1009
1010 fCondition = NotForced;
1011 fpCurrentProcess->SetProcessState(fpTrackingInfo->GetProcessState(fpCurrentProcess
1012 ->GetProcessID()));
1013
1014 // G4cout << "Is going to call : "
1015 // << fpCurrentProcess -> GetProcessName()
1016 // << G4endl;
1017 fPhysIntLength = fpCurrentProcess->PostStepGPIL(*fpTrack,
1018 fpState->fPreviousStepSize,
1019 &fCondition);
1020
1021#ifdef G4VERBOSE
1022 // !!!!! Verbose
1023 if(fpVerbose) fpVerbose->DPSLPostStep();
1024#endif
1025
1026 fpCurrentProcess->ResetProcessState();
1027 //fpCurrentProcess->SetProcessState(0);
1028
1029 switch(fCondition)
1030 {
1031 case ExclusivelyForced: // Will need special treatment
1034 fpStep->GetPostStepPoint()->SetProcessDefinedStep(fpCurrentProcess);
1035 break;
1036
1037 case Conditionally:
1038 // (fpState->fSelectedPostStepDoItVector)[np] = Conditionally;
1039 G4Exception("G4ITStepProcessor::DefinePhysicalStepLength()",
1040 "ITStepProcessor0008",
1042 "This feature is no more supported");
1043 break;
1044
1045 case Forced:
1046 (fpState->fSelectedPostStepDoItVector)[np] = Forced;
1047 break;
1048
1049 case StronglyForced:
1051 break;
1052
1053 default:
1055 break;
1056 }
1057
1058 if(fCondition == ExclusivelyForced)
1059 {
1060 for(std::size_t nrest = np + 1; nrest < fpProcessInfo->MAXofPostStepLoops;
1061 ++nrest)
1062 {
1063 (fpState->fSelectedPostStepDoItVector)[nrest] = InActivated;
1064 }
1065 return; // Please note the 'return' at here !!!
1066 }
1067 else
1068 {
1069 if(fPhysIntLength < fpState->fPhysicalStep)
1070 {
1071 // To avoid checking whether the process is actually
1072 // proposing a time step, the returned time steps are
1073 // negative (just for tagging)
1074 if(fpCurrentProcess->ProposesTimeStep())
1075 {
1076 fPhysIntLength *= -1;
1077 if(fPhysIntLength < proposedTimeStep)
1078 {
1079 proposedTimeStep = fPhysIntLength;
1080 fPostStepAtTimeDoItProcTriggered = np;
1081 processWithPostStepGivenByTimeStep = fpCurrentProcess;
1082 }
1083 }
1084 else
1085 {
1086 fpState->fPhysicalStep = fPhysIntLength;
1087 fpState->fStepStatus = fPostStepDoItProc;
1088 fPostStepDoItProcTriggered = G4int(np);
1089 fpStep->GetPostStepPoint()->SetProcessDefinedStep(fpCurrentProcess);
1090 }
1091 }
1092 }
1093 }
1094
1095 // GPIL for AlongStep
1096 fpState->fProposedSafety = DBL_MAX;
1097 G4double safetyProposedToAndByProcess = fpState->fProposedSafety;
1098
1099 for(std::size_t kp = 0; kp < fpProcessInfo->MAXofAlongStepLoops; ++kp)
1100 {
1101 fpCurrentProcess = dynamic_cast<G4VITProcess*>((*fpProcessInfo
1103 if(fpCurrentProcess == 0) continue;
1104 // NULL means the process is inactivated by a user on fly.
1105
1106 fpCurrentProcess->SetProcessState(
1107 fpTrackingInfo->GetProcessState(fpCurrentProcess->GetProcessID()));
1108 fPhysIntLength =
1109 fpCurrentProcess->AlongStepGPIL(*fpTrack,
1110 fpState->fPreviousStepSize,
1111 fpState->fPhysicalStep,
1112 safetyProposedToAndByProcess,
1113 &fGPILSelection);
1114
1115#ifdef G4VERBOSE
1116 // !!!!! Verbose
1117 if(fpVerbose) fpVerbose->DPSLAlongStep();
1118#endif
1119
1120 if(fPhysIntLength < fpState->fPhysicalStep)
1121 {
1122 fpState->fPhysicalStep = fPhysIntLength;
1123 // Should save PS and TS in IT
1124
1125 // Check if the process wants to be the GPIL winner. For example,
1126 // multi-scattering proposes Step limit, but won't be the winner.
1127 if(fGPILSelection == CandidateForSelection)
1128 {
1130 fpStep->GetPostStepPoint()->SetProcessDefinedStep(fpCurrentProcess);
1131 }
1132
1133 // Transportation is assumed to be the last process in the vector
1134 if(kp == fpProcessInfo->MAXofAlongStepLoops - 1)
1135 {
1136 fpTransportation = dynamic_cast<G4ITTransportation*>(fpCurrentProcess);
1137
1138 if(!fpTransportation)
1139 {
1140 G4ExceptionDescription exceptionDescription;
1141 exceptionDescription << "No transportation process found ";
1142 G4Exception("G4ITStepProcessor::DoDefinePhysicalStepLength",
1143 "ITStepProcessor0009",
1145 exceptionDescription);
1146 }
1147
1148 fTimeStep = fpTransportation->GetInteractionTimeLeft();
1149
1150 if(fpTrack->GetNextVolume() != 0) fpState->fStepStatus = fGeomBoundary;
1151 else fpState->fStepStatus = fWorldBoundary;
1152 }
1153 }
1154 else
1155 {
1156 if(kp == fpProcessInfo->MAXofAlongStepLoops - 1)
1157 {
1158 fpTransportation = dynamic_cast<G4ITTransportation*>(fpCurrentProcess);
1159
1160 if(!fpTransportation)
1161 {
1162 G4ExceptionDescription exceptionDescription;
1163 exceptionDescription << "No transportation process found ";
1164 G4Exception("G4ITStepProcessor::DoDefinePhysicalStepLength",
1165 "ITStepProcessor0010",
1167 exceptionDescription);
1168 }
1169
1170 fTimeStep = fpTransportation->GetInteractionTimeLeft();
1171 }
1172 }
1173
1174 // Handle PostStep processes sending back time steps rather than space length
1175 if(proposedTimeStep < fTimeStep)
1176 {
1177 if(fPostStepAtTimeDoItProcTriggered < fpProcessInfo->MAXofPostStepLoops)
1178 {
1179 if((fpState->fSelectedPostStepDoItVector)[fPostStepAtTimeDoItProcTriggered] == InActivated)
1180 {
1181 (fpState->fSelectedPostStepDoItVector)[fPostStepAtTimeDoItProcTriggered] =
1182 NotForced;
1183 // (fpState->fSelectedPostStepDoItVector)[fPostStepDoItProcTriggered] = InActivated;
1184
1185 fpState->fStepStatus = fPostStepDoItProc;
1186 fpStep->GetPostStepPoint()->SetProcessDefinedStep(processWithPostStepGivenByTimeStep);
1187
1188 fTimeStep = proposedTimeStep;
1189
1190 fpTransportation->ComputeStep(*fpTrack,
1191 *fpStep,
1192 fTimeStep,
1193 fpState->fPhysicalStep);
1194 }
1195 }
1196 }
1197 else
1198 {
1199 if(fPostStepDoItProcTriggered < fpProcessInfo->MAXofPostStepLoops)
1200 {
1201 if((fpState->fSelectedPostStepDoItVector)[fPostStepDoItProcTriggered] == InActivated)
1202 {
1203 (fpState->fSelectedPostStepDoItVector)[fPostStepDoItProcTriggered] =
1204 NotForced;
1205 }
1206 }
1207 }
1208
1209// fpCurrentProcess->SetProcessState(0);
1210 fpCurrentProcess->ResetProcessState();
1211
1212 // Make sure to check the safety, even if Step is not limited
1213 // by this process. J. Apostolakis, June 20, 1998
1214 //
1215 if(safetyProposedToAndByProcess < fpState->fProposedSafety)
1216 // proposedSafety keeps the smallest value:
1217 fpState->fProposedSafety = safetyProposedToAndByProcess;
1218 else
1219 // safetyProposedToAndByProcess always proposes a valid safety:
1220 safetyProposedToAndByProcess = fpState->fProposedSafety;
1221
1222 }
1223
1224 fpITrack->GetTrackingInfo()->SetNavigatorState(fpNavigator->GetNavigatorState());
1225 fpNavigator->ResetNavigatorState();
1226}
1227
1228//______________________________________________________________________________
@ FatalException
@ FatalErrorInArgument
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
@ InActivated
@ StronglyForced
@ NotForced
@ Conditionally
@ ExclusivelyForced
@ Forced
@ CandidateForSelection
bool IsInf(T value)
G4IT * GetIT(const G4Track *track)
Definition: G4IT.cc:48
@ typeGPIL
@ typeDoIt
@ fGeomBoundary
Definition: G4StepStatus.hh:43
@ fWorldBoundary
Definition: G4StepStatus.hh:41
@ fUndefined
Definition: G4StepStatus.hh:55
@ fPostStepDoItProc
Definition: G4StepStatus.hh:49
@ fAlongStepDoItProc
Definition: G4StepStatus.hh:47
@ fExclusivelyForcedProc
Definition: G4StepStatus.hh:53
G4TrackStatus
@ fSuspend
@ fAlive
@ fStopAndKill
@ fStopButAlive
@ fPostponeToNextEvent
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
#define theParticleIterator
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4double GetSurfaceTolerance() const
static G4GeometryTolerance * GetInstance()
void Push(G4Track *)
G4TouchableHandle fTouchableHandle
G4SelectedPostStepDoItVector fSelectedPostStepDoItVector
G4SelectedAtRestDoItVector fSelectedAtRestDoItVector
G4ITStepProcessorState & operator=(const G4ITStepProcessorState &)
void SetNavigator(G4ITNavigator *value)
void SetTrack(G4Track *)
G4ITStepProcessor & operator=(const G4ITStepProcessor &other)
G4double ComputeInteractionLength(double previousTimeStep)
void SetPreviousStepTime(G4double)
void DefinePhysicalStepLength(G4Track *)
void SetupGeneralProcessInfo(G4ParticleDefinition *, G4ProcessManager *)
virtual void Initialize()
G4TrackList * GetMainList(Key)
static G4ITTrackHolder * Instance()
G4VITSteppingVerbose * GetSteppingVerbose()
G4ITTrackingInteractivity * GetInteractivity()
void StartTracking(G4Track *)
void EndTracking(G4Track *)
static G4ITTransportationManager * GetTransportationManager()
virtual void ComputeStep(const G4Track &, const G4Step &, const double timeStep, double &spaceStep)
G4TrackingInformation * GetTrackingInfo()
Definition: G4IT.hh:143
virtual const G4String & GetName() const =0
G4ProcessManager * GetProcessManager() const
const G4String & GetParticleName() const
G4PTblDicIterator * GetIterator() const
static G4ParticleTable * GetParticleTable()
G4VProcess * SetProcessActivation(G4VProcess *aProcess, G4bool fActive)
G4ProcessVector * GetAlongStepProcessVector(G4ProcessVectorTypeIndex typ=typeGPIL) const
G4ProcessVector * GetProcessList() const
G4ProcessVector * GetPostStepProcessVector(G4ProcessVectorTypeIndex typ=typeGPIL) const
G4ProcessVector * GetAtRestProcessVector(G4ProcessVectorTypeIndex typ=typeGPIL) const
std::size_t size() const
std::size_t entries() const
void SetProcessDefinedStep(const G4VProcess *aValue)
G4VPhysicalVolume * GetPhysicalVolume() const
Definition: G4Step.hh:62
void DeleteSecondaryVector()
void SetPointerToVectorOfAuxiliaryPoints(std::vector< G4ThreeVector > *vec)
void InitializeStep(G4Track *aValue)
void ResetTotalEnergyDeposit()
G4TrackVector * GetfSecondary()
void CopyPostToPreStepPoint()
G4StepPoint * GetPreStepPoint() const
G4TrackVector * NewSecondaryVector()
G4StepPoint * GetPostStepPoint() const
G4TrackStatus GetTrackStatus() const
void SetTrackStatus(const G4TrackStatus aTrackStatus)
G4int GetTrackID() const
void SetStep(const G4Step *aValue)
G4VPhysicalVolume * GetVolume() const
void SetVertexPosition(const G4ThreeVector &aValue)
const G4TouchableHandle & GetNextTouchableHandle() const
void SetVertexMomentumDirection(const G4ThreeVector &aValue)
G4VPhysicalVolume * GetNextVolume() const
void SetNextTouchableHandle(const G4TouchableHandle &apValue)
const G4ThreeVector & GetPosition() const
void SetTouchableHandle(const G4TouchableHandle &apValue)
G4double GetGlobalTime() const
G4int GetCurrentStepNumber() const
G4ParticleDefinition * GetDefinition() const
const G4TouchableHandle & GetTouchableHandle() const
const G4ThreeVector & GetMomentumDirection() const
G4double GetKineticEnergy() const
G4double GetStepLength() const
void SetVertexKineticEnergy(const G4double aValue)
G4int GetParentID() const
void SetLogicalVolumeAtVertex(const G4LogicalVolume *)
const G4Step * GetStep() const
G4shared_ptr< G4ProcessState_Lock > GetProcessState(size_t index)
void SetStepProcessorState(G4ITStepProcessorState_Lock *)
void SetNavigatorState(G4ITNavigatorState_Lock *)
G4ITStepProcessorState_Lock * GetStepProcessorState()
G4ITNavigatorState_Lock * GetNavigatorState() const
G4bool ProposesTimeStep() const
size_t GetProcessID() const
void ResetProcessState()
void SetProcessState(G4shared_ptr< G4ProcessState_Lock > aProcInfo)
G4double GetInteractionTimeLeft()
virtual void DPSLAlongStep()=0
virtual void DPSLStarted()=0
void SetStepProcessor(const G4ITStepProcessor *stepProcessor)
virtual void DPSLPostStep()=0
G4LogicalVolume * GetLogicalVolume() const
virtual G4int GetRegularStructureId() const =0
G4double PostStepGPIL(const G4Track &track, G4double previousStepSize, G4ForceCondition *condition)
Definition: G4VProcess.hh:483
G4double AtRestGPIL(const G4Track &track, G4ForceCondition *condition)
Definition: G4VProcess.hh:476
G4double AlongStepGPIL(const G4Track &track, G4double previousStepSize, G4double currentMinimumStep, G4double &proposedSafety, G4GPILSelection *selection)
Definition: G4VProcess.hh:465
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
Definition: G4VTouchable.cc:34
G4ProcessVector * fpPostStepDoItVector
G4ProcessVector * fpPostStepGetPhysIntVector
std::size_t MAXofAlongStepLoops
std::size_t MAXofAtRestLoops
G4ProcessVector * fpAlongStepGetPhysIntVector
G4ProcessVector * fpAlongStepDoItVector
G4ProcessVector * fpAtRestGetPhysIntVector
G4ITTransportation * fpTransportation
std::size_t MAXofPostStepLoops
G4ProcessVector * fpAtRestDoItVector
#define DBL_EPSILON
Definition: templates.hh:66
#define DBL_MAX
Definition: templates.hh:62