46 : fiNavigator(theNavigator)
81 std::ostringstream os;
108 if( ((stepNo == 0) && (verboseLevel <3)) || (verboseLevel >= 3) )
110 oldprc = os.precision(4);
111 os << std::setw( 6) <<
" "
112 << std::setw( 25) <<
" Current Position and Direction" <<
" "
114 os << std::setw( 5) <<
"Step#"
115 << std::setw(10) <<
" s " <<
" "
116 << std::setw(10) <<
"X(mm)" <<
" "
117 << std::setw(10) <<
"Y(mm)" <<
" "
118 << std::setw(10) <<
"Z(mm)" <<
" "
119 << std::setw( 7) <<
" N_x " <<
" "
120 << std::setw( 7) <<
" N_y " <<
" "
121 << std::setw( 7) <<
" N_z " <<
" " ;
122 os << std::setw( 7) <<
" Delta|N|" <<
" "
123 << std::setw( 9) <<
"StepLen" <<
" "
124 << std::setw(12) <<
"StartSafety" <<
" "
125 << std::setw( 9) <<
"PhsStep" <<
" ";
127 os.precision(oldprc);
129 if((stepNo == 0) && (verboseLevel <=3))
133 printStatus( StartFT, StartFT, -1.0, safety, -1, os, verboseLevel);
135 if( verboseLevel <= 3 )
139 os << std::setw( 4) << stepNo <<
" ";
143 os << std::setw( 5) <<
"Start" ;
145 oldprc = os.precision(8);
147 os << std::setw(10) << CurrentPosition.
x() <<
" "
148 << std::setw(10) << CurrentPosition.
y() <<
" "
149 << std::setw(10) << CurrentPosition.
z() <<
" ";
151 os << std::setw( 7) << CurrentUnitVelocity.
x() <<
" "
152 << std::setw( 7) << CurrentUnitVelocity.
y() <<
" "
153 << std::setw( 7) << CurrentUnitVelocity.
z() <<
" ";
158 os << std::setw( 9) << step_len <<
" ";
159 os << std::setw(12) << safety <<
" ";
160 if( requestStep != -1.0 )
162 os << std::setw( 9) << requestStep <<
" ";
166 os << std::setw( 9) <<
"Init/NotKnown" <<
" ";
169 os.precision(oldprc);
175 os <<
"Step taken was " << step_len
176 <<
" out of PhysicalStep= " << requestStep <<
G4endl;
177 os <<
"Final safety is: " << safety <<
G4endl;
178 os <<
"Chord length = " << (CurrentPosition-StartPosition).mag()
204 const G4int no_trials = 20;
212 G4double advanceLength = endCurveLen - currentCurveLen ;
219 goodAdvance = integrDriver->AccurateAdvance(newEndPoint, advanceLength,
223 while( !goodAdvance && (++itrial < no_trials) );
227 retEndPoint = newEndPoint;
231 retEndPoint = EstimatedEndStateB;
237 const G4String MethodName(
"G4VIntersectionLocator::ReEstimateEndpoint()");
240 G4int latest_good_trials = 0;
245 G4cout << MethodName <<
" called - goodAdv= " << goodAdvance
246 <<
" trials = " << itrial
247 <<
" previous good= " << latest_good_trials
250 latest_good_trials = 0;
254 ++latest_good_trials;
265 G4cout << MethodName <<
"> AccurateAdvance failed " ;
266 G4cout <<
" in " << itrial <<
" integration trials/steps. " <<
G4endl;
267 G4cout <<
" It went only " << lengthDone <<
" instead of " << curveDist
268 <<
" -- a difference of " << curveDist - lengthDone <<
G4endl;
269 G4cout <<
" ReEstimateEndpoint> Reset endPoint to original value!"
275 static G4int noInaccuracyWarnings = 0;
276 G4int maxNoWarnings = 10;
277 if ( (noInaccuracyWarnings < maxNoWarnings )
283 message.precision(12);
284 message <<
" Integration inaccuracy requires"
285 <<
" an adjustment in the step's endpoint." <<
G4endl
286 <<
" Two mid-points are further apart than their"
287 <<
" curve length difference" <<
G4endl
288 <<
" Dist = " << linearDist
289 <<
" curve length = " << curveDist <<
G4endl;
290 message <<
" Correction applied is " << move.
mag() << G4endl
291 <<
" Old Estimated B position= "
293 <<
" Recalculated Position= "
295 <<
" Change ( new - old ) = " << move;
296 G4Exception(
"G4VIntersectionLocator::ReEstimateEndpoint()",
307 sumCorrectionsSq += (EstimatedEndStateB.
GetPosition() -
335 G4bool recalculated =
false;
343 && (curveDist*curveDist *(1.0+2.0*
fiEpsilonStep ) < linDistSq ) )
359 newEndPointFT = CurrentStartA;
363 G4Exception(
"G4MultiLevelLocator::EstimateIntersectionPoint()",
365 "A & B are at equal distance in 2nd half. A & B will coincide." );
371 if( curveDist < 0.0 )
409 if( (pLogical !=
nullptr) && ( (pSolid=pLogical->
GetSolid()) !=
nullptr ) )
420 G4cerr <<
"PROBLEM in G4VIntersectionLocator::GetLocalSurfaceNormal."
423 G4cerr <<
" at trial local point " << CurrentE_Point <<
G4endl;
450 G4bool goodAdjust =
false, Intersects_FP =
false, validNormal =
false;
455 if(!validNormal) {
return false; }
465 G4Exception(
"G4VIntersectionLocator::AdjustmentOfFoundIntersection()",
467 "No intersection. Parallels lines!");
470 lambda =- Normal.
dot(CurrentF_Point-CurrentE_Point)/n_d_m;
474 NewPoint = CurrentF_Point+lambda*MomentumDir;
490 fPreviousSafety, fPreviousSftOrigin,
491 stepLengthFP, Point_G );
498 Intersects_FP =
IntersectChord( CurrentF_Point, NewPoint, NewSafety,
499 fPreviousSafety, fPreviousSftOrigin,
500 stepLengthFP, Point_G );
505 IntersectionPoint = Point_G;
522 G4ThreeVector NormalAtEntryLast, NormalAtEntryGlobal, diffNormals;
539 message <<
"PROBLEM: Normal is not unit - magnitude = "
541 message <<
" at trial intersection point " << CurrentInt_Point <<
G4endl;
542 message <<
" Obtained from Get *Last* Surface Normal.";
543 G4Exception(
"G4VIntersectionLocator::GetSurfaceNormal()",
548 if( validNormalLast )
550 NormalAtEntry = NormalAtEntryLast;
552 validNormal = validNormalLast;
554 return NormalAtEntry;
571 if( validNormal && ( std::fabs(globalNormal.
mag2() - 1.0) >
perThousand ) )
574 message <<
"**************************************************************"
576 message <<
" Bad Normal in G4VIntersectionLocator::GetGlobalSurfaceNormal "
578 message <<
" * Constituents: " <<
G4endl;
579 message <<
" Local Normal= " << localNormal <<
G4endl;
580 message <<
" Transform: " << G4endl
583 <<
" Net Rotation = " << localToGlobal.
NetRotation()
585 message <<
" * Result: " <<
G4endl;
586 message <<
" Global Normal= " << localNormal <<
G4endl;
587 message <<
"**************************************************************";
588 G4Exception(
"G4VIntersectionLocator::GetGlobalSurfaceNormal()",
602 G4bool& normalIsValid)
const
607 normalIsValid = validNorm;
624 G4double MomDir_dot_Norm = NewMomentumDir.
dot( NormalAtEntry );
626 MomDir_dot_ABchord = (1.0 / ABchord_length) * NewMomentumDir.
dot( ChordAB_v );
628 std::ostringstream outStream;
629 outStream << std::setw(6) <<
" Step# "
630 << std::setw(17) <<
" |ChordEF|(mag)" <<
" "
631 << std::setw(18) <<
" uMomentum.Normal" <<
" "
632 << std::setw(18) <<
" uMomentum.ABdir " <<
" "
633 << std::setw(16) <<
" AB-dist " <<
" "
634 <<
" Chord Vector (EF) "
636 outStream.precision(7);
637 outStream <<
" " << std::setw(5) << step_no
638 <<
" " << std::setw(18) << ChordEF_v.
mag()
639 <<
" " << std::setw(18) << MomDir_dot_Norm
640 <<
" " << std::setw(18) << MomDir_dot_ABchord
641 <<
" " << std::setw(12) << ABchord_length
644 outStream <<
" MomentumDir= " <<
" " << NewMomentumDir
645 <<
" Normal at Entry E= " << NormalAtEntry
646 <<
" AB chord = " << ChordAB_v
648 G4cout << outStream.str();
653 message <<
"Normal is not unit - mag= " << NormalAtEntry.
mag() << G4endl
654 <<
" ValidNormalAtE = " << validNormal;
655 G4Exception(
"G4VIntersectionLocator::ReportTrialStep()",
678 MethodName(
"G4VIntersectionLocator::LocateGlobalPointWithinVolumeAndCheck()");
699 message <<
"Position located "
700 << ( inMother ==
kSurface ?
" on Surface " :
" outside " )
701 <<
"expected volume" <<
G4endl
702 <<
" Safety (from Outside) = "
704 G4Exception(
"G4VIntersectionLocator::LocateGlobalPointWithinVolumeAndCheck()",
713 if( (nextPhysical != motherPhys)
714 || (nextPhysical->
GetCopyNo() != motherCopyNo )
717 G4Exception(
"G4VIntersectionLocator::LocateGlobalPointWithinVolumeAndCheck()",
719 "Position located outside expected volume.");
746 message <<
"Failed point location." <<
G4endl
747 <<
" Code Location info: " << CodeLocationInfo;
748 G4Exception(
"G4VIntersectionLocator::LocateGlobalPointWithinVolumeCheckAndReport()",
775 G4int verboseLevel= 5;
778 -1.0, NewSafety, substep_no, msg, verboseLevel );
779 msg <<
"Error in advancing propagation." <<
G4endl
780 <<
" Point A (start) is " << A_PtVel <<
G4endl
781 <<
" Point B (end) is " << B_PtVel <<
G4endl
782 <<
" Curve distance is " << curveDist <<
G4endl
784 <<
"The final curve point is not further along"
785 <<
" than the original!" <<
G4endl;
786 msg <<
" Value of fEpsStep= " << epsStep <<
G4endl;
788 G4int oldprc = msg.precision(20);
789 msg <<
" Point A (Curve start) is " << StartPointVel << G4endl
790 <<
" Point B (Curve end) is " << EndPointVel << G4endl
791 <<
" Point A (Current start) is " << A_PtVel << G4endl
792 <<
" Point B (Current end) is " << B_PtVel << G4endl
793 <<
" Point S (Sub start) is " << SubStart_PtVel
794 <<
" Point E (Trial Point) is " << E_Point << G4endl
795 <<
" Point F (Intersection) is " << ApproxIntersecPointV
797 <<
" LocateIntersection parameters are : " << G4endl
798 <<
" Substep no (total) = " << substep_no << G4endl
799 <<
" Substep (depth= " << depth << substep_no_p;
800 msg.precision(oldprc);
817 oss <<
"ReportProgress: Current status of intersection search: " <<
G4endl;
818 if( depth > 0 ) oss <<
" Depth= " << depth;
819 oss <<
" Substep no = " << substep_no <<
G4endl;
820 G4int verboseLevel = 5;
823 printStatus( StartPointVel, EndPointVel, -1.0, -1.0, -1,
825 oss <<
" * Start and end-point of requested Step:" <<
G4endl;
826 oss <<
" ** State of point A: ";
827 printStatus( A_PtVel, A_PtVel, -1.0, safetyPrev, substep_no-1,
829 oss <<
" ** State of point B: ";
830 printStatus( A_PtVel, B_PtVel, -1.0, safetyLast, substep_no,
843 unsigned long int numCalls )
847 if( ptrLast ==
nullptr )
854 if( (TrialPoint - StartPosition).mag2() < tolerance*tolerance)
859 G4cout <<
"Intersection F == start A in " << MethodName;
861 G4cout <<
" Start-Trial: " << TrialPoint - StartPosition;
862 G4cout <<
" Start-last: " << StartPosition - lastStart;
864 if( (StartPosition - lastStart).mag() < tolerance )
869 G4cout <<
" { Unmoved: " <<
" still#= " << numStill
870 <<
" total # = " << numUnmoved <<
" } - ";
876 G4cout <<
" Occured: " << ++occurredOnTop;
877 G4cout <<
" out of total calls= " << numCalls;
879 lastStart = StartPosition;