I have a simulation of a water tank. The interior surface of the tank is a diffuse reflector, and in the roof are three photomultiplier tubes. The tank is part of an experiment detecting cosmic rays (primarily muons passing through the tank producing Cerenkov photons). For test purposes I have a particle gun that fires optical photons into the tank (with specified energy, position, direction and polarisation). Such photons typically bounce around the tank many times before being absorbed or detected by a PMT. I found that for the first step (from the start point to the first wall), the speed of the photon is correct (c/1.33 - using 1.33 as the refractive index of the water), but after that step the speed becomes c/1.165, and likewise when the photon moves into the casing of the PMT (refractive index 1.49) is moves with speed c/1.245 - the effective refractive index appears to be 1+(x/2) instead of 1+x for all steps apart from the first. This was deduced by using the time for a step as PostStepPoint->GetGlobalTime()-PreStepPoint->GetGlobalTime() and the distance moved during the step as Step->GetStepLength(). Using verbose output from the tracking information gives the same picture - the overall track length and the track time don't match for the expected velocity of the photon. Source code (about 2000 lines in total) is available if required.
Linux tar file has been added which contains a short version of the program which also shows the bug. Just under 600 lines of code in total. Sample output is also included, showing the problem.
I believe I have traced the problem to a calculation in: G4VParticleChange* G4Transportation::AlongStepDoIt In it the time is updated with the following logic: G4double finalVelocity = track.GetVelocity() ; G4double initialVelocity = stepData.GetPreStepPoint()->GetVelocity() ; G4double stepLength = track.GetStepLength() ; if (finalVelocity > 0.0) { G4double meanInverseVelocity ; // deltaTime = stepLength/finalVelocity ; meanInverseVelocity = 0.5 * ( 1.0 / initialVelocity + 1.0 / finalVelocity ) ; deltaTime = stepLength * meanInverseVelocity ; } The problem is that the velocity of the PreStepPoint at a boundary is the velocity in optical medium #1 while the velocity of the PostStepPoint is that of medium #2 upon refraction. Similarly, upon reflection, the PreStepPoint velocity is that of medium #2 (remember there is a 'null' step - zero length step - upon reflection and then the PreStepPoint of the next step points to medium #2), while the PostStepPoint is back in medium #1. The optical photon, of course, moves with the velocity of medium #2 upon refraction and the velocity of medium #1 upon reflection and not their mean! The fix requires special logic for the optical photon, just like in G4Track::GetVelocity(), such that only the PostStepPoint velocity is used to update the time-of-flight. Thank you for being diligent. Peter Gumplinger
For optical photons we now use the velocity to use the one for the relevant medium - not the average of initial and final values. This change was included in Geant4 5.2 patch 1 (27 August 2003) Thanks again for your report. Best regards, John Apostolakis