81 G4bool& recalculatedEndPoint,
87 G4bool found_approximate_intersection =
false;
88 G4bool there_is_no_intersection =
false;
90 G4FieldTrack CurrentA_PointVelocity = CurveStartPointVelocity;
91 G4FieldTrack CurrentB_PointVelocity = CurveEndPointVelocity;
93 G4bool validNormalAtE =
false;
96 G4FieldTrack ApproxIntersecPointV(CurveEndPointVelocity);
98 G4bool last_AF_intersection =
false;
99 G4bool final_section =
true;
101 recalculatedEndPoint =
false;
103 G4bool restoredFullEndpoint =
false;
105 G4int substep_no = 0;
109 const G4int max_substeps = 100000000;
110 const G4int warn_substeps = 1000;
121 if( (TrialPoint - StartPosition).mag() < tolerance * CLHEP::mm )
123 G4Exception(
"G4SimpleLocator::EstimateIntersectionPoint()",
125 "Intersection point F is exactly at start point A." );
139 CurrentB_PointVelocity,
148 G4Exception(
"G4SimpleLocator::EstimateIntersectionPoint()",
150 "Intermediate F point is past end B point!" );
159 G4ThreeVector ChordEF_Vector = CurrentF_Point - CurrentE_Point;
162 G4double MomDir_dot_Norm = NewMomentumDir.
dot( NormalAtEntry ) ;
169 NewMomentumDir, NormalAtEntry, validNormalAtE );
174 G4bool adequate_angle = ( MomDir_dot_Norm >= 0.0 )
175 || (! validNormalAtE );
180 found_approximate_intersection =
true;
184 IntersectedOrRecalculatedFT = ApproxIntersecPointV;
185 IntersectedOrRecalculatedFT.
SetPosition( CurrentE_Point );
194 CurrentE_Point, CurrentF_Point, MomentumDir,
195 last_AF_intersection, IP, NewSafety,
198 if ( goodCorrection )
200 IntersectedOrRecalculatedFT = ApproxIntersecPointV;
223 G4bool usedNavigatorAF =
false;
232 last_AF_intersection = Intersects_AF;
241 CurrentB_PointVelocity = ApproxIntersecPointV;
242 CurrentE_Point = PointG;
252 validNormalAtE = validNormalLast;
257 final_section =
false;
262 G4cout <<
"G4PiF::LI> Investigating intermediate point"
264 <<
" on way to full s="
279 G4bool usedNavigatorFB =
false;
288 PointH, &usedNavigatorFB );
303 CurrentA_PointVelocity = ApproxIntersecPointV;
304 CurrentE_Point = PointH;
314 validNormalAtE = validNormalLast;
328 there_is_no_intersection =
true;
334 CurrentA_PointVelocity = CurrentB_PointVelocity;
335 CurrentB_PointVelocity = CurveEndPointVelocity;
336 restoredFullEndpoint =
true;
358 CurrentB_PointVelocity,
362 CurrentB_PointVelocity = newEndPointFT;
366 recalculatedEndPoint =
true;
367 IntersectedOrRecalculatedFT = newEndPointFT;
371 if( curveDist < 0.0 )
374 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
375 -1.0, NewSafety, substep_no );
376 std::ostringstream message;
377 message <<
"Error in advancing propagation." <<
G4endl
378 <<
" Point A (start) is " << CurrentA_PointVelocity
380 <<
" Point B (end) is " << CurrentB_PointVelocity
382 <<
" Curve distance is " << curveDist <<
G4endl
384 <<
"The final curve point is not further along"
385 <<
" than the original!" <<
G4endl;
387 if( recalculatedEndPoint )
389 message <<
"Recalculation of EndPoint was called with fEpsStep= "
392 message.precision(20);
393 message <<
" Point A (Curve start) is " << CurveStartPointVelocity
395 <<
" Point B (Curve end) is " << CurveEndPointVelocity
397 <<
" Point A (Current start) is " << CurrentA_PointVelocity
399 <<
" Point B (Current end) is " << CurrentB_PointVelocity
401 <<
" Point E (Trial Point) is " << CurrentE_Point
403 <<
" Point F (Intersection) is " << ApproxIntersecPointV
405 <<
" LocateIntersection parameters are : Substep no= "
408 G4Exception(
"G4SimpleLocator::EstimateIntersectionPoint()",
412 if ( restoredFullEndpoint )
414 final_section = restoredFullEndpoint;
415 restoredFullEndpoint =
false;
420#ifdef G4DEBUG_LOCATE_INTERSECTION
421 G4int trigger_substepno_print= warn_substeps - 20;
423 if( substep_no >= trigger_substepno_print )
425 G4cout <<
"Difficulty in converging in "
426 <<
"G4SimpleLocator::EstimateIntersectionPoint():"
428 <<
" Substep no = " << substep_no <<
G4endl;
429 if( substep_no == trigger_substepno_print )
431 printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
434 G4cout <<
" State of point A: ";
435 printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
436 -1.0, NewSafety, substep_no-1, 0);
437 G4cout <<
" State of point B: ";
438 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
439 -1.0, NewSafety, substep_no);
444 }
while ( ( ! found_approximate_intersection )
445 && ( ! there_is_no_intersection )
446 && ( substep_no <= max_substeps) );
448 if( substep_no > max_no_seen )
450 max_no_seen = substep_no;
451#ifdef G4DEBUG_LOCATE_INTERSECTION
452 if( max_no_seen > warn_substeps )
454 trigger_substepno_print = max_no_seen-20;
459 if( ( substep_no >= max_substeps)
460 && !there_is_no_intersection
461 && !found_approximate_intersection )
463 G4cout <<
"ERROR - G4SimpleLocator::EstimateIntersectionPoint()" <<
G4endl
464 <<
" Start and Endpoint of Requested Step:" <<
G4endl;
465 printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
468 <<
" Start and end-point of current Sub-Step:" <<
G4endl;
469 printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
470 -1.0, NewSafety, substep_no-1);
471 printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
472 -1.0, NewSafety, substep_no);
474 std::ostringstream message;
475 message <<
"Convergence is requiring too many substeps: "
477 <<
" Abandoning effort to intersect." <<
G4endl
478 <<
" Found intersection = "
479 << found_approximate_intersection <<
G4endl
480 <<
" Intersection exists = "
481 << !there_is_no_intersection <<
G4endl;
482 message.precision(10);
485 message <<
" Undertaken only length: " << done_len
486 <<
" out of " << full_len <<
" required." <<
G4endl
487 <<
" Remaining length = " << full_len-done_len;
489 G4Exception(
"G4SimpleLocator::EstimateIntersectionPoint()",
492 else if( substep_no >= warn_substeps )
494 std::ostringstream message;
495 message.precision(10);
497 message <<
"Many substeps while trying to locate intersection." <<
G4endl
498 <<
" Undertaken length: "
500 <<
" - Needed: " << substep_no <<
" substeps." <<
G4endl
501 <<
" Warning level = " << warn_substeps
502 <<
" and maximum substeps = " << max_substeps;
503 G4Exception(
"G4SimpleLocator::EstimateIntersectionPoint()",
506 return !there_is_no_intersection;