00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include "G4SteppingManager.hh"
00045 #include "G4SteppingVerbose.hh"
00046 #include "G4UImanager.hh"
00047 #include "G4ForceCondition.hh"
00048 #include "G4GPILSelection.hh"
00049 #include "G4SteppingControl.hh"
00050 #include "G4TransportationManager.hh"
00051 #include "G4UserLimits.hh"
00052 #include "G4VSensitiveDetector.hh"
00053 #include "G4GeometryTolerance.hh"
00054
00056 G4SteppingManager::G4SteppingManager()
00058 : fUserSteppingAction(0), verboseLevel(0)
00059 {
00060
00061
00062 fStep = new G4Step();
00063 fSecondary = fStep->NewSecondaryVector();
00064 fPreStepPoint = fStep->GetPreStepPoint();
00065 fPostStepPoint = fStep->GetPostStepPoint();
00066 #ifdef G4VERBOSE
00067 if(G4VSteppingVerbose::GetInstance()==0) {
00068 fVerbose = new G4SteppingVerbose();
00069 G4VSteppingVerbose::SetInstance(fVerbose);
00070 fVerbose -> SetManager(this);
00071 KillVerbose = true;
00072 }
00073 else {
00074 fVerbose = G4VSteppingVerbose::GetInstance();
00075 fVerbose -> SetManager(this);
00076 KillVerbose = false;
00077 }
00078 #endif
00079 SetNavigator(G4TransportationManager::GetTransportationManager()
00080 ->GetNavigatorForTracking());
00081
00082 fSelectedAtRestDoItVector
00083 = new G4SelectedAtRestDoItVector(SizeOfSelectedDoItVector,0);
00084 fSelectedAlongStepDoItVector
00085 = new G4SelectedAlongStepDoItVector(SizeOfSelectedDoItVector,0);
00086 fSelectedPostStepDoItVector
00087 = new G4SelectedPostStepDoItVector(SizeOfSelectedDoItVector,0);
00088
00089 SetNavigator(G4TransportationManager::GetTransportationManager()
00090 ->GetNavigatorForTracking());
00091
00092 physIntLength = DBL_MAX;
00093 kCarTolerance = 0.5*G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
00094 }
00095
00097 G4SteppingManager::~G4SteppingManager()
00099 {
00100
00101
00102 fStep->DeleteSecondaryVector();
00104 delete fStep;
00105 delete fSelectedAtRestDoItVector;
00106 delete fSelectedAlongStepDoItVector;
00107 delete fSelectedPostStepDoItVector;
00108 if (fUserSteppingAction) delete fUserSteppingAction;
00109 #ifdef G4VERBOSE
00110 if(KillVerbose) delete fVerbose;
00111 #endif
00112 }
00113
00114
00116 G4StepStatus G4SteppingManager::Stepping()
00118 {
00119
00120
00121
00122
00123 #ifdef G4VERBOSE
00124
00125 if(verboseLevel>0) fVerbose->NewStep();
00126 else
00127 if(verboseLevel==-1) {
00128 G4VSteppingVerbose::SetSilent(1);
00129 }
00130 else
00131 G4VSteppingVerbose::SetSilent(0);
00132 #endif
00133
00134
00135
00136 fStep->CopyPostToPreStepPoint();
00137 fStep->ResetTotalEnergyDeposit();
00138
00139
00140 fTrack->SetTouchableHandle(fTrack->GetNextTouchableHandle());
00141
00142
00143 fN2ndariesAtRestDoIt = 0;
00144 fN2ndariesAlongStepDoIt = 0;
00145 fN2ndariesPostStepDoIt = 0;
00146
00147
00148 fCurrentVolume = fStep->GetPreStepPoint()->GetPhysicalVolume();
00149
00150
00151 fStep->SetPointerToVectorOfAuxiliaryPoints(0);
00152
00153
00154
00155
00156
00157 if( fTrack->GetTrackStatus() == fStopButAlive ){
00158 if( MAXofAtRestLoops>0 ){
00159 InvokeAtRestDoItProcs();
00160 fStepStatus = fAtRestDoItProc;
00161 fStep->GetPostStepPoint()->SetStepStatus( fStepStatus );
00162
00163 #ifdef G4VERBOSE
00164
00165 if(verboseLevel>0) fVerbose->AtRestDoItInvoked();
00166 #endif
00167
00168 }
00169
00170 fTrack->SetTrackStatus( fStopAndKill );
00171 }
00172
00173
00174
00175
00176
00177
00178 else{
00179
00180 DefinePhysicalStepLength();
00181
00182
00183 fStep->SetStepLength( PhysicalStep );
00184 fTrack->SetStepLength( PhysicalStep );
00185 G4double GeomStepLength = PhysicalStep;
00186
00187
00188 fStep->GetPostStepPoint()->SetStepStatus( fStepStatus );
00189
00190
00191 InvokeAlongStepDoItProcs();
00192
00193
00194 fStep->UpdateTrack();
00195
00196
00197 endpointSafOrigin= fPostStepPoint->GetPosition();
00198
00199 endpointSafety= std::max( proposedSafety - GeomStepLength, kCarTolerance);
00200
00201 fStep->GetPostStepPoint()->SetSafety( endpointSafety );
00202
00203 #ifdef G4VERBOSE
00204
00205 if(verboseLevel>0) fVerbose->AlongStepDoItAllDone();
00206 #endif
00207
00208
00209 InvokePostStepDoItProcs();
00210
00211 #ifdef G4VERBOSE
00212
00213 if(verboseLevel>0) fVerbose->PostStepDoItAllDone();
00214 #endif
00215 }
00216
00217
00218
00219
00220
00221
00222 fTrack->AddTrackLength(fStep->GetStepLength());
00223 fPreviousStepSize = fStep->GetStepLength();
00224 fStep->SetTrack(fTrack);
00225 #ifdef G4VERBOSE
00226
00227
00228 if(verboseLevel>0) fVerbose->StepInfo();
00229 #endif
00230
00231 fCurrentVolume = fStep->GetPreStepPoint()->GetPhysicalVolume();
00232 StepControlFlag = fStep->GetControlFlag();
00233 if( fCurrentVolume != 0 && StepControlFlag != AvoidHitInvocation) {
00234 fSensitive = fStep->GetPreStepPoint()->
00235 GetSensitiveDetector();
00236 if( fSensitive != 0 ) {
00237 fSensitive->Hit(fStep);
00238 }
00239 }
00240
00241
00242 if( fUserSteppingAction != 0 ) {
00243 fUserSteppingAction->UserSteppingAction(fStep);
00244 }
00245 G4UserSteppingAction* regionalAction
00246 = fStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetRegion()
00247 ->GetRegionalSteppingAction();
00248 if( regionalAction ) regionalAction->UserSteppingAction(fStep);
00249
00250
00251 return fStepStatus;
00252
00253 }
00254
00256 void G4SteppingManager::SetInitialStep(G4Track* valueTrack)
00258 {
00259
00260
00261 PreStepPointIsGeom = false;
00262 FirstStep = true;
00263 fParticleChange = 0;
00264 fPreviousStepSize = 0.;
00265 fStepStatus = fUndefined;
00266
00267 fTrack = valueTrack;
00268 Mass = fTrack->GetDynamicParticle()->GetMass();
00269
00270 PhysicalStep = 0.;
00271 GeometricalStep = 0.;
00272 CorrectedStep = 0.;
00273 PreStepPointIsGeom = false;
00274 FirstStep = false;
00275 fStepStatus = fUndefined;
00276
00277 TempInitVelocity = 0.;
00278 TempVelocity = 0.;
00279 sumEnergyChange = 0.;
00280
00281
00282
00283
00284 if( (fTrack->GetTrackStatus()==fSuspend) ||
00285 (fTrack->GetTrackStatus()==fPostponeToNextEvent) ){
00286 fTrack->SetTrackStatus(fAlive);
00287 }
00288
00289
00290
00291 if(fTrack->GetKineticEnergy() <= 0.0){
00292 fTrack->SetTrackStatus( fStopButAlive );
00293 }
00294
00295
00296
00297
00298
00299 if ( ! fTrack->GetTouchableHandle() ) {
00300 G4ThreeVector direction= fTrack->GetMomentumDirection();
00301 fNavigator->LocateGlobalPointAndSetup( fTrack->GetPosition(),
00302 &direction, false, false );
00303 fTouchableHandle = fNavigator->CreateTouchableHistory();
00304
00305 fTrack->SetTouchableHandle( fTouchableHandle );
00306 fTrack->SetNextTouchableHandle( fTouchableHandle );
00307 }else{
00308 fTrack->SetNextTouchableHandle( fTouchableHandle = fTrack->GetTouchableHandle() );
00309 G4VPhysicalVolume* oldTopVolume= fTrack->GetTouchableHandle()->GetVolume();
00310 G4VPhysicalVolume* newTopVolume=
00311 fNavigator->ResetHierarchyAndLocate( fTrack->GetPosition(),
00312 fTrack->GetMomentumDirection(),
00313 *((G4TouchableHistory*)fTrack->GetTouchableHandle()()) );
00314
00315 if(newTopVolume != oldTopVolume || oldTopVolume->GetRegularStructureId() == 1 ) {
00316 fTouchableHandle = fNavigator->CreateTouchableHistory();
00317 fTrack->SetTouchableHandle( fTouchableHandle );
00318 fTrack->SetNextTouchableHandle( fTouchableHandle );
00319 }
00320 }
00321
00322 if ( fTrack->GetCurrentStepNumber() == 0 ) {
00323 fTrack->SetVertexPosition( fTrack->GetPosition() );
00324 fTrack->SetVertexMomentumDirection( fTrack->GetMomentumDirection() );
00325 fTrack->SetVertexKineticEnergy( fTrack->GetKineticEnergy() );
00326 fTrack->SetLogicalVolumeAtVertex( fTrack->GetVolume()->GetLogicalVolume() );
00327 }
00328
00329 fCurrentVolume = fTouchableHandle->GetVolume();
00330
00331
00332 if( fCurrentVolume==0 ){
00333
00334 if(fTrack->GetParentID()==0)
00335 {
00336 G4cerr << "ERROR - G4SteppingManager::SetInitialStep()" << G4endl
00337 << " Primary particle starting at - "
00338 << fTrack->GetPosition()
00339 << " - is outside of the world volume." << G4endl;
00340 G4Exception("G4SteppingManager::SetInitialStep()", "Tracking0010",
00341 FatalException, "Primary vertex outside of the world!");
00342 }
00343
00344 fTrack->SetTrackStatus( fStopAndKill );
00345 G4cout << "WARNING - G4SteppingManager::SetInitialStep()" << G4endl
00346 << " Initial track position is outside world! - "
00347 << fTrack->GetPosition() << G4endl;
00348 }
00349 else {
00350
00351 fStep->InitializeStep( fTrack );
00352 }
00353 #ifdef G4VERBOSE
00354
00355 if(verboseLevel>0) fVerbose->TrackingStarted();
00356 #endif
00357 }
00358