80 G4bool& recalculatedEndPoint,
86 G4bool found_approximate_intersection =
false;
87 G4bool there_is_no_intersection =
false;
89 G4FieldTrack CurrentA_PointVelocity = CurveStartPointVelocity;
90 G4FieldTrack CurrentB_PointVelocity = CurveEndPointVelocity;
92 G4bool validNormalAtE =
false;
95 G4FieldTrack ApproxIntersecPointV(CurveEndPointVelocity);
97 G4bool last_AF_intersection =
false;
98 G4bool final_section =
true;
100 recalculatedEndPoint =
false;
102 G4bool restoredFullEndpoint =
false;
104 G4int substep_no = 0;
108 const G4int max_substeps = 100000000;
109 const G4int warn_substeps = 1000;
120 if( (TrialPoint - StartPosition).mag() < tolerance * CLHEP::mm )
122 G4Exception(
"G4SimpleLocator::EstimateIntersectionPoint()",
124 "Intersection point F is exactly at start point A." );
138 CurrentB_PointVelocity,
147 G4Exception(
"G4SimpleLocator::EstimateIntersectionPoint()",
149 "Intermediate F point is past end B point!" );
158 G4ThreeVector ChordEF_Vector = CurrentF_Point - CurrentE_Point;
161 G4double MomDir_dot_Norm = NewMomentumDir.
dot( NormalAtEntry ) ;
168 NewMomentumDir, NormalAtEntry, validNormalAtE );
173 G4bool adequate_angle = ( MomDir_dot_Norm >= 0.0 )
174 || (! validNormalAtE );
179 found_approximate_intersection =
true;
183 IntersectedOrRecalculatedFT = ApproxIntersecPointV;
184 IntersectedOrRecalculatedFT.
SetPosition( CurrentE_Point );
193 CurrentE_Point, CurrentF_Point, MomentumDir,
194 last_AF_intersection, IP, NewSafety,
197 if ( goodCorrection )
199 IntersectedOrRecalculatedFT = ApproxIntersecPointV;
222 G4bool usedNavigatorAF =
false;
231 last_AF_intersection = Intersects_AF;
240 CurrentB_PointVelocity = ApproxIntersecPointV;
241 CurrentE_Point = PointG;
251 validNormalAtE = validNormalLast;
256 final_section =
false;
261 G4cout <<
"G4PiF::LI> Investigating intermediate point"
263 <<
" on way to full s="
278 G4bool usedNavigatorFB =
false;
287 PointH, &usedNavigatorFB );
302 CurrentA_PointVelocity = ApproxIntersecPointV;
303 CurrentE_Point = PointH;
313 validNormalAtE = validNormalLast;
327 there_is_no_intersection =
true;
333 CurrentA_PointVelocity = CurrentB_PointVelocity;
334 CurrentB_PointVelocity = CurveEndPointVelocity;
335 restoredFullEndpoint =
true;
357 CurrentB_PointVelocity,
361 CurrentB_PointVelocity = newEndPointFT;
365 recalculatedEndPoint =
true;
366 IntersectedOrRecalculatedFT = newEndPointFT;
370 if( curveDist < 0.0 )
373 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
374 -1.0, NewSafety, substep_no );
375 std::ostringstream message;
376 message <<
"Error in advancing propagation." <<
G4endl
377 <<
" Point A (start) is " << CurrentA_PointVelocity
379 <<
" Point B (end) is " << CurrentB_PointVelocity
381 <<
" Curve distance is " << curveDist <<
G4endl
383 <<
"The final curve point is not further along"
384 <<
" than the original!" <<
G4endl;
386 if( recalculatedEndPoint )
388 message <<
"Recalculation of EndPoint was called with fEpsStep= "
391 message.precision(20);
392 message <<
" Point A (Curve start) is " << CurveStartPointVelocity
394 <<
" Point B (Curve end) is " << CurveEndPointVelocity
396 <<
" Point A (Current start) is " << CurrentA_PointVelocity
398 <<
" Point B (Current end) is " << CurrentB_PointVelocity
400 <<
" Point E (Trial Point) is " << CurrentE_Point
402 <<
" Point F (Intersection) is " << ApproxIntersecPointV
404 <<
" LocateIntersection parameters are : Substep no= "
407 G4Exception(
"G4SimpleLocator::EstimateIntersectionPoint()",
411 if ( restoredFullEndpoint )
413 final_section = restoredFullEndpoint;
414 restoredFullEndpoint =
false;
419#ifdef G4DEBUG_LOCATE_INTERSECTION
420 G4int trigger_substepno_print= warn_substeps - 20;
422 if( substep_no >= trigger_substepno_print )
424 G4cout <<
"Difficulty in converging in "
425 <<
"G4SimpleLocator::EstimateIntersectionPoint():"
427 <<
" Substep no = " << substep_no <<
G4endl;
428 if( substep_no == trigger_substepno_print )
430 printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
433 G4cout <<
" State of point A: ";
434 printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
435 -1.0, NewSafety, substep_no-1, 0);
436 G4cout <<
" State of point B: ";
437 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
438 -1.0, NewSafety, substep_no);
443 }
while ( ( ! found_approximate_intersection )
444 && ( ! there_is_no_intersection )
445 && ( substep_no <= max_substeps) );
447 if( substep_no > max_no_seen )
449 max_no_seen = substep_no;
450#ifdef G4DEBUG_LOCATE_INTERSECTION
451 if( max_no_seen > warn_substeps )
453 trigger_substepno_print = max_no_seen-20;
458 if( ( substep_no >= max_substeps)
459 && !there_is_no_intersection
460 && !found_approximate_intersection )
462 G4cout <<
"ERROR - G4SimpleLocator::EstimateIntersectionPoint()" <<
G4endl
463 <<
" Start and Endpoint of Requested Step:" <<
G4endl;
464 printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
467 <<
" Start and end-point of current Sub-Step:" <<
G4endl;
468 printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
469 -1.0, NewSafety, substep_no-1);
470 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
471 -1.0, NewSafety, substep_no);
473 std::ostringstream message;
474 message <<
"Convergence is requiring too many substeps: "
476 <<
" Abandoning effort to intersect." <<
G4endl
477 <<
" Found intersection = "
478 << found_approximate_intersection <<
G4endl
479 <<
" Intersection exists = "
480 << !there_is_no_intersection <<
G4endl;
481 message.precision(10);
484 message <<
" Undertaken only length: " << done_len
485 <<
" out of " << full_len <<
" required." <<
G4endl
486 <<
" Remaining length = " << full_len-done_len;
488 G4Exception(
"G4SimpleLocator::EstimateIntersectionPoint()",
491 else if( substep_no >= warn_substeps )
493 std::ostringstream message;
494 message.precision(10);
496 message <<
"Many substeps while trying to locate intersection." <<
G4endl
497 <<
" Undertaken length: "
499 <<
" - Needed: " << substep_no <<
" substeps." <<
G4endl
500 <<
" Warning level = " << warn_substeps
501 <<
" and maximum substeps = " << max_substeps;
502 G4Exception(
"G4SimpleLocator::EstimateIntersectionPoint()",
505 return !there_is_no_intersection;