47 : fiNavigator(theNavigator)
82 std::ostringstream os;
109 if( ((stepNo == 0) && (verboseLevel <3)) || (verboseLevel >= 3) )
111 oldprc = os.precision(4);
112 os << std::setw( 6) <<
" "
113 << std::setw( 25) <<
" Current Position and Direction" <<
" "
115 os << std::setw( 5) <<
"Step#"
116 << std::setw(10) <<
" s " <<
" "
117 << std::setw(10) <<
"X(mm)" <<
" "
118 << std::setw(10) <<
"Y(mm)" <<
" "
119 << std::setw(10) <<
"Z(mm)" <<
" "
120 << std::setw( 7) <<
" N_x " <<
" "
121 << std::setw( 7) <<
" N_y " <<
" "
122 << std::setw( 7) <<
" N_z " <<
" " ;
123 os << std::setw( 7) <<
" Delta|N|" <<
" "
124 << std::setw( 9) <<
"StepLen" <<
" "
125 << std::setw(12) <<
"StartSafety" <<
" "
126 << std::setw( 9) <<
"PhsStep" <<
" ";
128 os.precision(oldprc);
130 if((stepNo == 0) && (verboseLevel <=3))
134 printStatus( StartFT, StartFT, -1.0, safety, -1, os, verboseLevel);
136 if( verboseLevel <= 3 )
140 os << std::setw( 4) << stepNo <<
" ";
144 os << std::setw( 5) <<
"Start" ;
146 oldprc = os.precision(8);
148 os << std::setw(10) << CurrentPosition.
x() <<
" "
149 << std::setw(10) << CurrentPosition.
y() <<
" "
150 << std::setw(10) << CurrentPosition.
z() <<
" ";
152 os << std::setw( 7) << CurrentUnitVelocity.
x() <<
" "
153 << std::setw( 7) << CurrentUnitVelocity.
y() <<
" "
154 << std::setw( 7) << CurrentUnitVelocity.
z() <<
" ";
159 os << std::setw( 9) << step_len <<
" ";
160 os << std::setw(12) << safety <<
" ";
161 if( requestStep != -1.0 )
163 os << std::setw( 9) << requestStep <<
" ";
167 os << std::setw( 9) <<
"Init/NotKnown" <<
" ";
170 os.precision(oldprc);
176 os <<
"Step taken was " << step_len
177 <<
" out of PhysicalStep= " << requestStep <<
G4endl;
178 os <<
"Final safety is: " << safety <<
G4endl;
179 os <<
"Chord length = " << (CurrentPosition-StartPosition).mag()
205 const G4int no_trials = 20;
213 G4double advanceLength = endCurveLen - currentCurveLen ;
220 goodAdvance = integrDriver->AccurateAdvance(newEndPoint, advanceLength,
224 while( !goodAdvance && (++itrial < no_trials) );
228 retEndPoint = newEndPoint;
232 retEndPoint = EstimatedEndStateB;
238 const G4String MethodName(
"G4VIntersectionLocator::ReEstimateEndpoint()");
241 G4int latest_good_trials = 0;
246 G4cout << MethodName <<
" called - goodAdv= " << goodAdvance
247 <<
" trials = " << itrial
248 <<
" previous good= " << latest_good_trials
251 latest_good_trials = 0;
255 ++latest_good_trials;
266 G4cout << MethodName <<
"> AccurateAdvance failed " ;
267 G4cout <<
" in " << itrial <<
" integration trials/steps. " <<
G4endl;
268 G4cout <<
" It went only " << lengthDone <<
" instead of " << curveDist
269 <<
" -- a difference of " << curveDist - lengthDone <<
G4endl;
270 G4cout <<
" ReEstimateEndpoint> Reset endPoint to original value!"
276 static G4int noInaccuracyWarnings = 0;
277 G4int maxNoWarnings = 10;
278 if ( (noInaccuracyWarnings < maxNoWarnings )
283 std::ostringstream message;
284 message.precision(12);
285 message <<
" Integration inaccuracy requires"
286 <<
" an adjustment in the step's endpoint." <<
G4endl
287 <<
" Two mid-points are further apart than their"
288 <<
" curve length difference" <<
G4endl
289 <<
" Dist = " << linearDist
290 <<
" curve length = " << curveDist <<
G4endl;
291 message <<
" Correction applied is " << move.
mag() <<
G4endl
292 <<
" Old Estimated B position= "
294 <<
" Recalculated Position= "
296 <<
" Change ( new - old ) = " << move;
297 G4Exception(
"G4VIntersectionLocator::ReEstimateEndpoint()",
338 G4bool recalculated =
false;
346 && (curveDist*curveDist *(1.0+2.0*
fiEpsilonStep ) < linDistSq ) )
362 newEndPointFT = CurrentStartA;
366 G4Exception(
"G4MultiLevelLocator::EstimateIntersectionPoint()",
368 "A & B are at equal distance in 2nd half. A & B will coincide." );
374 if( curveDist < 0.0 )
407 if( located !=
nullptr)
412 if( (pLogical !=
nullptr) && ( (pSolid=pLogical->
GetSolid()) !=
nullptr ) )
421 if( std::fabs(Normal.mag2() - 1.0 ) > CLHEP::perThousand)
423 G4cerr <<
"PROBLEM in G4VIntersectionLocator::GetLocalSurfaceNormal."
425 G4cerr <<
" Normal is not unit - mag=" << Normal.mag() <<
G4endl;
426 G4cerr <<
" at trial local point " << CurrentE_Point <<
G4endl;
453 G4bool goodAdjust =
false, Intersects_FP =
false, validNormal =
false;
458 if(!validNormal) {
return false; }
468 G4Exception(
"G4VIntersectionLocator::AdjustmentOfFoundIntersection()",
470 "No intersection. Parallels lines!");
473 lambda =- Normal.
dot(CurrentF_Point-CurrentE_Point)/n_d_m;
477 NewPoint = CurrentF_Point+lambda*MomentumDir;
481 dist = std::abs(lambda);
494 stepLengthFP, Point_G );
501 Intersects_FP =
IntersectChord( CurrentF_Point, NewPoint, NewSafety,
503 stepLengthFP, Point_G );
508 IntersectionPoint = Point_G;
525 G4ThreeVector NormalAtEntryLast, NormalAtEntryGlobal, diffNormals;
531 NormalAtEntryLast = GetLastSurfaceNormal( CurrentInt_Point, validNormalLast );
539 && ( std::fabs(NormalAtEntryLast.
mag2() - 1.0) > perThousand ) )
541 std::ostringstream message;
542 message <<
"PROBLEM: Normal is not unit - magnitude = "
544 message <<
" at trial intersection point " << CurrentInt_Point <<
G4endl;
545 message <<
" Obtained from Get *Last* Surface Normal.";
546 G4Exception(
"G4VIntersectionLocator::GetSurfaceNormal()",
551 if( validNormalLast )
553 NormalAtEntry = NormalAtEntryLast;
555 validNormal = validNormalLast;
557 return NormalAtEntry;
568 G4ThreeVector localNormal = GetLocalSurfaceNormal(CurrentE_Point,validNormal);
574 if( validNormal && ( std::fabs(globalNormal.
mag2() - 1.0) > perThousand ) )
576 std::ostringstream message;
577 message <<
"**************************************************************"
579 message <<
" Bad Normal in G4VIntersectionLocator::GetGlobalSurfaceNormal "
581 message <<
" * Constituents: " <<
G4endl;
582 message <<
" Local Normal= " << localNormal <<
G4endl;
583 message <<
" Transform: " <<
G4endl
586 <<
" Net Rotation = " << localToGlobal.
NetRotation()
588 message <<
" * Result: " <<
G4endl;
589 message <<
" Global Normal= " << localNormal <<
G4endl;
590 message <<
"**************************************************************";
591 G4Exception(
"G4VIntersectionLocator::GetGlobalSurfaceNormal()",
605 G4bool& normalIsValid)
const
610 normalIsValid = validNorm;
627 G4double MomDir_dot_Norm = NewMomentumDir.
dot( NormalAtEntry );
629 MomDir_dot_ABchord = (1.0 / ABchord_length) * NewMomentumDir.
dot( ChordAB_v );
631 std::ostringstream outStream;
632 outStream << std::setw(6) <<
" Step# "
633 << std::setw(17) <<
" |ChordEF|(mag)" <<
" "
634 << std::setw(18) <<
" uMomentum.Normal" <<
" "
635 << std::setw(18) <<
" uMomentum.ABdir " <<
" "
636 << std::setw(16) <<
" AB-dist " <<
" "
637 <<
" Chord Vector (EF) "
639 outStream.precision(7);
640 outStream <<
" " << std::setw(5) << step_no
641 <<
" " << std::setw(18) << ChordEF_v.
mag()
642 <<
" " << std::setw(18) << MomDir_dot_Norm
643 <<
" " << std::setw(18) << MomDir_dot_ABchord
644 <<
" " << std::setw(12) << ABchord_length
647 outStream <<
" MomentumDir= " <<
" " << NewMomentumDir
648 <<
" Normal at Entry E= " << NormalAtEntry
649 <<
" AB chord = " << ChordAB_v
651 G4cout << outStream.str();
653 if( ( std::fabs(NormalAtEntry.
mag2() - 1.0) > perThousand ) )
655 std::ostringstream message;
656 message <<
"Normal is not unit - mag= " << NormalAtEntry.
mag() <<
G4endl
657 <<
" ValidNormalAtE = " << validNormal;
658 G4Exception(
"G4VIntersectionLocator::ReportTrialStep()",
681 MethodName(
"G4VIntersectionLocator::LocateGlobalPointWithinVolumeAndCheck()");
701 std::ostringstream message;
702 message <<
"Position located "
703 << ( inMother ==
kSurface ?
" on Surface " :
" outside " )
704 <<
"expected volume" <<
G4endl
705 <<
" Safety (from Outside) = "
707 G4Exception(
"G4VIntersectionLocator::LocateGlobalPointWithinVolumeAndCheck()",
716 if( (nextPhysical != motherPhys)
717 || (nextPhysical->
GetCopyNo() != motherCopyNo )
720 G4Exception(
"G4VIntersectionLocator::LocateGlobalPointWithinVolumeAndCheck()",
722 "Position located outside expected volume.");
748 std::ostringstream message;
749 message <<
"Failed point location." <<
G4endl
750 <<
" Code Location info: " << CodeLocationInfo;
751 G4Exception(
"G4VIntersectionLocator::LocateGlobalPointWithinVolumeCheckAndReport()",
778 G4int verboseLevel= 5;
781 -1.0, NewSafety, substep_no, msg, verboseLevel );
782 msg <<
"Error in advancing propagation." <<
G4endl
783 <<
" The final curve point is NOT further along"
784 <<
" than the original!" <<
G4endl
785 <<
" Going *backwards* from len(A) = " << A_PtVel.
GetCurveLength()
787 <<
" Curve distance is " << curveDist / CLHEP::millimeter <<
" mm "
789 <<
" Point A' (start) is " << A_PtVel <<
G4endl
790 <<
" Point B' (end) is " << B_PtVel <<
G4endl;
793 G4long oldprc = msg.precision(20);
794 msg <<
" In full precision, the position, momentum, E_kin, length, rest mass "
795 <<
" ... are: " <<
G4endl;
796 msg <<
" Point A[0] (Curve start) is " << StartPointVel <<
G4endl
797 <<
" Point S (Sub start) is " << SubStart_PtVel
798 <<
" Point A' (Current start) is " << A_PtVel <<
G4endl
799 <<
" Point E (Trial Point) is " << E_Point <<
G4endl
800 <<
" Point F (Intersection) is " << ApproxIntersecPointV <<
G4endl
801 <<
" Point B' (Current end) is " << B_PtVel <<
G4endl
802 <<
" Point B[0] (Curve end) is " << EndPointVel <<
G4endl
804 <<
" LocateIntersection parameters are : " <<
G4endl
805 <<
" Substep no (total) = " << substep_no <<
G4endl
806 <<
" Substep no = " << substep_no_p <<
" at depth= " << depth;
807 msg.precision(oldprc);
824 oss <<
"ReportProgress: Current status of intersection search: " <<
G4endl;
825 if( depth > 0 ) { oss <<
" Depth= " << depth; }
826 oss <<
" Substep no = " << substep_no <<
G4endl;
827 G4int verboseLevel = 5;
830 printStatus( StartPointVel, EndPointVel, -1.0, -1.0, -1,
832 oss <<
" * Start and end-point of requested Step:" <<
G4endl;
833 oss <<
" ** State of point A: ";
834 printStatus( A_PtVel, A_PtVel, -1.0, safetyPrev, substep_no-1,
836 oss <<
" ** State of point B: ";
837 printStatus( A_PtVel, B_PtVel, -1.0, safetyLast, substep_no,
850 unsigned long int numCalls )
854 if( ptrLast ==
nullptr )
861 if( (TrialPoint - StartPosition).mag2() < tolerance*tolerance)
866 G4cout <<
"Intersection F == start A in " << MethodName;
868 G4cout <<
" Start-Trial: " << TrialPoint - StartPosition;
869 G4cout <<
" Start-last: " << StartPosition - lastStart;
871 if( (StartPosition - lastStart).mag() < tolerance )
876 G4cout <<
" { Unmoved: " <<
" still#= " << numStill
877 <<
" total # = " << numUnmoved <<
" } - ";
883 G4cout <<
" Occurred: " << ++occurredOnTop;
884 G4cout <<
" out of total calls= " << numCalls;
886 lastStart = StartPosition;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
#define fPreviousSftOrigin
CLHEP::Hep3Vector G4ThreeVector
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
double dot(const Hep3Vector &) const
G4VIntegrationDriver * GetIntegrationDriver()
const G4ThreeVector & GetMomentumDir() const
G4double GetCurveLength() const
G4ThreeVector GetPosition() const
G4ThreeVector GetMomentum() const
G4double GetSurfaceTolerance() const
static G4GeometryTolerance * GetInstance()
G4VSolid * GetSolid() const
const G4AffineTransform & GetTopTransform() const
G4TouchableHistory * CreateTouchableHistory() const
G4VExternalNavigation * GetExternalNavigation() const
void CheckMode(G4bool mode)
virtual void LocateGlobalPointWithinVolume(const G4ThreeVector &position)
virtual G4ThreeVector GetGlobalExitNormal(const G4ThreeVector &point, G4bool *valid)
const G4AffineTransform GetLocalToGlobalTransform() const
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=nullptr, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
G4Navigator * Clone() const
void SetWorldVolume(G4VPhysicalVolume *pWorld)
G4bool IsCheckModeActive() const
virtual G4TouchableHandle CreateTouchableHistoryHandle() const
const G4AffineTransform & GetGlobalToLocalTransform() const
virtual G4VSolid * GetSolid(G4int depth=0) const
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
virtual const G4NavigationHistory * GetHistory() const
G4ThreeVector GetGlobalSurfaceNormal(const G4ThreeVector &CurrentE_Point, G4bool &validNormal)
void SetCheckMode(G4bool value)
G4Navigator * fiNavigator
G4Navigator * fHelpingNavigator
G4Navigator * GetNavigatorFor()
G4ChordFinder * GetChordFinderFor()
G4VIntersectionLocator(G4Navigator *theNavigator)
G4TouchableHistory * fpTouchable
virtual ~G4VIntersectionLocator()
G4ThreeVector GetSurfaceNormal(const G4ThreeVector &CurrentInt_Point, G4bool &validNormal)
void LocateGlobalPointWithinVolumeCheckAndReport(const G4ThreeVector &pos, const G4String &CodeLocationInfo, G4int CheckMode)
void ReportTrialStep(G4int step_no, const G4ThreeVector &ChordAB_v, const G4ThreeVector &ChordEF_v, const G4ThreeVector &NewMomentumDir, const G4ThreeVector &NormalAtEntry, G4bool validNormal)
G4bool IntersectChord(const G4ThreeVector &StartPointA, const G4ThreeVector &EndPointB, G4double &NewSafety, G4double &PreviousSafety, G4ThreeVector &PreviousSftOrigin, G4double &LinearStepLength, G4ThreeVector &IntersectionPoint, G4bool *calledNavigator=nullptr)
G4bool CheckAndReEstimateEndpoint(const G4FieldTrack &CurrentStartA, const G4FieldTrack &EstimatedEndB, G4FieldTrack &RevisedEndPoint, G4int &errorCode)
void ReportProgress(std::ostream &oss, const G4FieldTrack &StartPointVel, const G4FieldTrack &EndPointVel, G4int substep_no, const G4FieldTrack &A_PtVel, const G4FieldTrack &B_PtVel, G4double safetyLast, G4int depth=-1)
G4double GetEpsilonStepFor()
void ReportImmediateHit(const char *MethodName, const G4ThreeVector &StartPosition, const G4ThreeVector &TrialPoint, G4double tolerance, unsigned long int numCalls)
G4FieldTrack ReEstimateEndpoint(const G4FieldTrack &CurrentStateA, const G4FieldTrack &EstimtdEndStateB, G4double linearDistSq, G4double curveDist)
G4bool LocateGlobalPointWithinVolumeAndCheck(const G4ThreeVector &pos)
void printStatus(const G4FieldTrack &startFT, const G4FieldTrack ¤tFT, G4double requestStep, G4double safety, G4int stepNum)
G4bool AdjustmentOfFoundIntersection(const G4ThreeVector &A, const G4ThreeVector &CurrentE_Point, const G4ThreeVector &CurrentF_Point, const G4ThreeVector &MomentumDir, const G4bool IntersectAF, G4ThreeVector &IntersectionPoint, G4double &NewSafety, G4double &fPrevSafety, G4ThreeVector &fPrevSftOrigin)
void ReportReversedPoints(std::ostringstream &ossMsg, const G4FieldTrack &StartPointVel, const G4FieldTrack &EndPointVel, G4double NewSafety, G4double epsStep, const G4FieldTrack &CurrentA_PointVelocity, const G4FieldTrack &CurrentB_PointVelocity, const G4FieldTrack &SubStart_PointVelocity, const G4ThreeVector &CurrentE_Point, const G4FieldTrack &ApproxIntersecPointV, G4int sbstp_no, G4int sbstp_no_p, G4int depth)
G4LogicalVolume * GetLogicalVolume() const
virtual G4int GetCopyNo() const =0
virtual EInside Inside(const G4ThreeVector &p) const =0
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const =0
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const =0
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0