Finding the distance to next volume

Hi everyone,
I am trying to do something that seems really simple. When at a boundary (I check that with some G4bool isOnBoundary = (pStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary);), I would like to know what is the distance in straight line to the next boundary.
I tried using ComputeStep with a slightly modified position but Geant4 is not liking it, and I also cannot get the result that way (probably related).
Does anyone have any idea how to do that ?

I was suggested to propagate my particle to the end of my volume, but I do not see how to do that without having my particle to interact in the volume.

If you want to do this with G4Navigator, you should create your own instance local to your class. Do not use the main tracking Navigator; it caches the most recent position information, for speed. When you interfere with that caching, everything gets confused (as you’ve seen).

Create a G4Navigator instance, register the world volume into it, and then you can ask it questions like “which volume is at this point?” or “where’s the next boundary from this point in that direction?” See G4Navigator.hh for specific functions and function arguments.

Thank you, I will try to do that.

For whoever might be interested, here is how I did it.

     fNavigator = new G4Navigator();//create a Navigator
     const G4Step* pStep = &aStep;
     G4ThreeVector theGlobalPoint = pStep->GetPostStepPoint()->GetPosition();//or whatever gives you your position
     const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();
     G4ThreeVector OldMomentum = aParticle->GetMomentumDirection();//or whatever gives you the direction of the particle
     G4int hNavId = G4ParallelWorldProcess::GetHypNavigatorID();
     std::vector<G4Navigator*>::iterator iNav =
          G4TransportationManager::GetTransportationManager()->
                                   GetActiveNavigatorsIterator();
     fNavigator->SetWorldVolume((iNav[hNavId])->GetWorldVolume());//or any other way to set the World volume as the Navigator volume 
     double currentMinimumStep = 100.;//or any number big enough
     double newSafety;
     G4VPhysicalVolume* thePhysVolume =
        fNavigator->LocateGlobalPointAndSetup(theGlobalPoint);
     double preStepLength = fNavigator->ComputeStep( theGlobalPoint, 
                                                         OldMomentum,
                                                         currentMinimumStep, 
                                                         newSafety) ;

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.