83 G4bool& recalculatedEndPoint,
89 G4bool found_approximate_intersection =
false;
90 G4bool there_is_no_intersection =
false;
92 G4FieldTrack CurrentA_PointVelocity = CurveStartPointVelocity;
93 G4FieldTrack CurrentB_PointVelocity = CurveEndPointVelocity;
95 G4bool validNormalAtE =
false;
98 G4FieldTrack ApproxIntersecPointV(CurveEndPointVelocity);
100 G4bool last_AF_intersection =
false;
101 G4bool final_section =
true;
103 recalculatedEndPoint =
false;
105 G4bool restoredFullEndpoint =
false;
107 G4int substep_no = 0;
111 const G4int max_substeps = 100000000;
112 const G4int warn_substeps = 1000;
123 if( (TrialPoint - StartPosition).mag() < tolerance *
CLHEP::mm )
125 G4Exception(
"G4SimpleLocator::EstimateIntersectionPoint()",
127 "Intersection point F is exactly at start point A." );
141 CurrentB_PointVelocity,
150 G4Exception(
"G4SimpleLocator::EstimateIntersectionPoint()",
152 "Intermediate F point is past end B point!" );
161 G4ThreeVector ChordEF_Vector = CurrentF_Point - CurrentE_Point;
164 G4double MomDir_dot_Norm = NewMomentumDir.
dot( NormalAtEntry ) ;
171 NewMomentumDir, NormalAtEntry, validNormalAtE );
176 G4bool adequate_angle = ( MomDir_dot_Norm >= 0.0 )
177 || (! validNormalAtE );
182 found_approximate_intersection =
true;
186 IntersectedOrRecalculatedFT = ApproxIntersecPointV;
187 IntersectedOrRecalculatedFT.
SetPosition( CurrentE_Point );
196 CurrentE_Point, CurrentF_Point, MomentumDir,
197 last_AF_intersection, IP, NewSafety,
198 fPreviousSafety, fPreviousSftOrigin );
200 if ( goodCorrection )
202 IntersectedOrRecalculatedFT = ApproxIntersecPointV;
225 G4bool usedNavigatorAF =
false;
234 last_AF_intersection = Intersects_AF;
243 CurrentB_PointVelocity = ApproxIntersecPointV;
244 CurrentE_Point = PointG;
254 validNormalAtE = validNormalLast;
259 final_section =
false;
264 G4cout <<
"G4PiF::LI> Investigating intermediate point"
266 <<
" on way to full s="
281 G4bool usedNavigatorFB =
false;
287 NewSafety,fPreviousSafety,
290 PointH, &usedNavigatorFB );
305 CurrentA_PointVelocity = ApproxIntersecPointV;
306 CurrentE_Point = PointH;
316 validNormalAtE = validNormalLast;
330 there_is_no_intersection =
true;
336 CurrentA_PointVelocity = CurrentB_PointVelocity;
337 CurrentB_PointVelocity = CurveEndPointVelocity;
338 restoredFullEndpoint =
true;
360 CurrentB_PointVelocity,
364 CurrentB_PointVelocity = newEndPointFT;
368 recalculatedEndPoint =
true;
369 IntersectedOrRecalculatedFT = newEndPointFT;
373 if( curveDist < 0.0 )
376 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
377 -1.0, NewSafety, substep_no );
379 message <<
"Error in advancing propagation." <<
G4endl
380 <<
" Point A (start) is " << CurrentA_PointVelocity
382 <<
" Point B (end) is " << CurrentB_PointVelocity
384 <<
" Curve distance is " << curveDist <<
G4endl
386 <<
"The final curve point is not further along"
387 <<
" than the original!" <<
G4endl;
389 if( recalculatedEndPoint )
391 message <<
"Recalculation of EndPoint was called with fEpsStep= "
394 message.precision(20);
395 message <<
" Point A (Curve start) is " << CurveStartPointVelocity
397 <<
" Point B (Curve end) is " << CurveEndPointVelocity
399 <<
" Point A (Current start) is " << CurrentA_PointVelocity
401 <<
" Point B (Current end) is " << CurrentB_PointVelocity
403 <<
" Point E (Trial Point) is " << CurrentE_Point
405 <<
" Point F (Intersection) is " << ApproxIntersecPointV
407 <<
" LocateIntersection parameters are : Substep no= "
410 G4Exception(
"G4SimpleLocator::EstimateIntersectionPoint()",
414 if ( restoredFullEndpoint )
416 final_section = restoredFullEndpoint;
417 restoredFullEndpoint =
false;
422 #ifdef G4DEBUG_LOCATE_INTERSECTION
423 G4int trigger_substepno_print= warn_substeps - 20;
425 if( substep_no >= trigger_substepno_print )
427 G4cout <<
"Difficulty in converging in "
428 <<
"G4SimpleLocator::EstimateIntersectionPoint():"
430 <<
" Substep no = " << substep_no <<
G4endl;
431 if( substep_no == trigger_substepno_print )
433 printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
436 G4cout <<
" State of point A: ";
437 printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
438 -1.0, NewSafety, substep_no-1, 0);
439 G4cout <<
" State of point B: ";
440 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
441 -1.0, NewSafety, substep_no);
446 }
while ( ( ! found_approximate_intersection )
447 && ( ! there_is_no_intersection )
448 && ( substep_no <= max_substeps) );
450 if( substep_no > max_no_seen )
452 max_no_seen = substep_no;
453 #ifdef G4DEBUG_LOCATE_INTERSECTION
454 if( max_no_seen > warn_substeps )
456 trigger_substepno_print = max_no_seen-20;
461 if( ( substep_no >= max_substeps)
462 && !there_is_no_intersection
463 && !found_approximate_intersection )
465 G4cout <<
"ERROR - G4SimpleLocator::EstimateIntersectionPoint()" <<
G4endl
466 <<
" Start and Endpoint of Requested Step:" <<
G4endl;
467 printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
470 <<
" Start and end-point of current Sub-Step:" <<
G4endl;
471 printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
472 -1.0, NewSafety, substep_no-1);
473 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
474 -1.0, NewSafety, substep_no);
477 message <<
"Convergence is requiring too many substeps: "
478 << substep_no << G4endl
479 <<
" Abandoning effort to intersect." << G4endl
480 <<
" Found intersection = "
481 << found_approximate_intersection << G4endl
482 <<
" Intersection exists = "
483 << !there_is_no_intersection <<
G4endl;
484 message.precision(10);
487 message <<
" Undertaken only length: " << done_len
488 <<
" out of " << full_len <<
" required." << G4endl
489 <<
" Remaining length = " << full_len-done_len;
491 G4Exception(
"G4SimpleLocator::EstimateIntersectionPoint()",
494 else if( substep_no >= warn_substeps )
497 message.precision(10);
499 message <<
"Many substeps while trying to locate intersection." <<
G4endl
500 <<
" Undertaken length: "
502 <<
" - Needed: " << substep_no <<
" substeps." <<
G4endl
503 <<
" Warning level = " << warn_substeps
504 <<
" and maximum substeps = " << max_substeps;
505 G4Exception(
"G4SimpleLocator::EstimateIntersectionPoint()",
508 return !there_is_no_intersection;