Modify the momentum and position of particles when they pass through specific volume

I want to change the momentum and position of particles when they pass through specific volume. I did using the following code:

if(track->GetVolume()->GetName() == "scintillator"){

    // Modify the position
    G4ThreeVector newPosition(1*CLHEP::cm, 1*CLHEP::cm, 2*CLHEP::cm);
    track->SetPosition(newPosition);
    // Modify the momentum direction
    G4ThreeVector newMomentumDirection(1, 0, 0);  // Example: Set to x direction
    track->SetMomentumDirection(newMomentumDirection);
    std::cout << "Changed Track" << std::endl;
}

the program running properly but it is giving following warning:

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : GeomNav1002
issued by : G4Navigator::ComputeStep()
Accuracy error or slightly inaccurate position shift.
The Step’s starting point has moved 1920.6 mm
since the last call to a Locate method.
This has resulted in moving 1920.6 mm from the last point at which the safety was calculated
which is more than the computed safety= 0.01 mm at that point.
This difference is 1920.6 mm.
The tolerated accuracy is 1e-06 mm.
This problem can be due to either
- a process that has proposed a displacement larger than the current safety , or
- inaccuracy in the computation of the safety We suggest that you

  • find i) what particle is being tracked, and ii) through what part of your geometry
    for example by re-running this event with
    /tracking/verbose 1
    - check which processes you declare for this particle (and look at non-standard ones)
  • in case, create a detailed logfile of this event using:
    /tracking/verbose 6

*** This is just a warning message. ***

Should I be worried about it? how can I supress this warning?

You should not be doing that outside of a process. You can write a process, add it to your physics list, and change the track kinematics in the process. There is documentation for that in both the Application Developers Guide and the Toolkit Developers Guide.

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