Problem 265

Summary: Segment violations from tracks starting outside of the world boundary
Product: Geant4 Reporter: gas
Component: trackingAssignee: Takashi.Sasaki
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.1   
Hardware: PC   
OS: Linux   

Description gas 2001-06-15 17:30:45 CEST
Tracks starting outside of the world boundary cause segment
violations, due to a misplaced check at the end of
G4SteppingManager::SetInitialStep().  This bug report is about code in
SetInitialStep() that tries and fails to deal with the situation
gracefully.  SetInitialStep() currently does the following actions in
the following order:

 1) Sets fCurrentVolume in G4SteppingManager.

 2) Calls fStep->InitializeStep( fTrack )

 3) "If track is already outside the world boundary, kill it"

Unfortunately, if the track is already outside the world boundary, the
NULL physical volume pointer causes a segment violation in
G4Step::InitializeStep() in step (2), so step (3) is currently
useless.  To be effective, the order of steps 2 and 3 should be
swapped.

N.B. we do recognize that tracks should never start outside the world
boundary.  We see only a few of these cases per 100,000 events.  It
probably indicates a rare bug in some geometry code.  This problem was
never seen before we added BooleanSolids to our geometry, but we have
not been able to prove that is the problem.  Anyway, this bug report
is about the "If track is already outside the world boundary, kill it"
code which does not serve its intended purpose.

The following patch has proved effective for us:

*** G4SteppingManager.cc~	Wed Feb  7 23:48:39 2001
--- G4SteppingManager.cc	Fri Jun 15 13:31:11 2001
***************
*** 274,288 ****
  // Initial set up for attributes of 'G4SteppingManager'
     fCurrentVolume = pTouchableFree->GetVolume();

  // Initial set up for attribues of 'Step'
!    fStep->InitializeStep( fTrack );
  #ifdef G4VERBOSE
                           // !!!!! Verbose
             if(verboseLevel>0) fVerbose->TrackingStarted();
  #endif
- // If track is already outside the world boundary, kill it
-    if( fTrack->GetVolume()==0 ){
-        fTrack->SetTrackStatus( fStopAndKill );
-    }
  }

--- 274,293 ----
  // Initial set up for attributes of 'G4SteppingManager'
     fCurrentVolume = pTouchableFree->GetVolume();

+ // If track is already outside the world boundary, kill it
+    if( fCurrentVolume==0 ){
+        fTrack->SetTrackStatus( fStopAndKill );
+        G4cerr << "G4SteppingManager::SetInitialStep(): warning: "
+               << "initial track position is outside world! "
+               << fTrack->GetPosition() << G4endl;
+    }
+    else {
  // Initial set up for attribues of 'Step'
!        fStep->InitializeStep( fTrack );
!    }
  #ifdef G4VERBOSE
                           // !!!!! Verbose
             if(verboseLevel>0) fVerbose->TrackingStarted();
  #endif
  }
Comment 1 Makoto.Asai 2001-06-20 12:09:59 CEST
This is the matter of G4SteppingManager in tracking category.
Comment 2 Takashi.Sasaki 2001-09-10 01:09:59 CEST
done