49 fUseNormalCorrection(false),
51 fiNavigator(theNavigator),
54 fiDeltaIntersection(-1.0),
83 std::ostringstream os;
110 if( ((stepNo == 0) && (verboseLevel <3)) || (verboseLevel >= 3) )
112 oldprc = os.precision(4);
113 os << std::setw( 6) <<
" "
114 << std::setw( 25) <<
" Current Position and Direction" <<
" "
116 os << std::setw( 5) <<
"Step#"
117 << std::setw(10) <<
" s " <<
" "
118 << std::setw(10) <<
"X(mm)" <<
" "
119 << std::setw(10) <<
"Y(mm)" <<
" "
120 << std::setw(10) <<
"Z(mm)" <<
" "
121 << std::setw( 7) <<
" N_x " <<
" "
122 << std::setw( 7) <<
" N_y " <<
" "
123 << std::setw( 7) <<
" N_z " <<
" " ;
124 os << std::setw( 7) <<
" Delta|N|" <<
" "
125 << std::setw( 9) <<
"StepLen" <<
" "
126 << std::setw(12) <<
"StartSafety" <<
" "
127 << std::setw( 9) <<
"PhsStep" <<
" ";
129 os.precision(oldprc);
131 if((stepNo == 0) && (verboseLevel <=3))
135 printStatus( StartFT, StartFT, -1.0, safety, -1, os, verboseLevel);
137 if( verboseLevel <= 3 )
141 os << std::setw( 4) << stepNo <<
" ";
145 os << std::setw( 5) <<
"Start" ;
147 oldprc = os.precision(8);
149 os << std::setw(10) << CurrentPosition.
x() <<
" "
150 << std::setw(10) << CurrentPosition.
y() <<
" "
151 << std::setw(10) << CurrentPosition.
z() <<
" ";
153 os << std::setw( 7) << CurrentUnitVelocity.
x() <<
" "
154 << std::setw( 7) << CurrentUnitVelocity.
y() <<
" "
155 << std::setw( 7) << CurrentUnitVelocity.
z() <<
" ";
160 os << std::setw( 9) << step_len <<
" ";
161 os << std::setw(12) << safety <<
" ";
162 if( requestStep != -1.0 )
164 os << std::setw( 9) << requestStep <<
" ";
168 os << std::setw( 9) <<
"Init/NotKnown" <<
" ";
171 os.precision(oldprc);
177 os <<
"Step taken was " << step_len
178 <<
" out of PhysicalStep= " << requestStep <<
G4endl;
179 os <<
"Final safety is: " << safety <<
G4endl;
180 os <<
"Chord length = " << (CurrentPosition-StartPosition).mag()
203 const G4int no_trials=20;
211 G4double advanceLength= endCurveLen - currentCurveLen ;
222 while( !goodAdvance && (++itrial < no_trials) );
226 retEndPoint = newEndPoint;
230 retEndPoint = EstimatedEndStateB;
236 const G4String MethodName(
"G4VIntersectionLocator::ReEstimateEndpoint()");
239 G4int latest_good_trials = 0;
244 G4cout << MethodName <<
" called - goodAdv= " << goodAdvance
245 <<
" trials = " << itrial
246 <<
" previous good= " << latest_good_trials
249 latest_good_trials = 0;
253 latest_good_trials++;
264 G4cout << MethodName <<
"> AccurateAdvance failed " ;
265 G4cout <<
" in " << itrial <<
" integration trials/steps. " <<
G4endl;
266 G4cout <<
" It went only " << lengthDone <<
" instead of " << curveDist
267 <<
" -- a difference of " << curveDist - lengthDone <<
G4endl;
268 G4cout <<
" ReEstimateEndpoint> Reset endPoint to original value!"
274 static G4int noInaccuracyWarnings = 0;
275 G4int maxNoWarnings = 10;
276 if ( (noInaccuracyWarnings < maxNoWarnings )
281 std::ostringstream message;
282 message.precision(12);
283 message <<
" Integration inaccuracy requires"
284 <<
" an adjustment in the step's endpoint." <<
G4endl
285 <<
" Two mid-points are further apart than their"
286 <<
" curve length difference" <<
G4endl
287 <<
" Dist = " << linearDist
288 <<
" curve length = " << curveDist <<
G4endl;
289 message <<
" Correction applied is " << move.
mag() << G4endl
290 <<
" Old Estimated B position= "
292 <<
" Recalculated Position= "
294 <<
" Change ( new - old ) = " << move;
295 G4Exception(
"G4VIntersectionLocator::ReEstimateEndpoint()",
306 sumCorrectionsSq += (EstimatedEndStateB.
GetPosition() -
334 G4bool recalculated=
false;
342 && (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 )
410 if( (pLogical != 0) && ( (pSolid=pLogical->
GetSolid()) !=0 ) )
424 G4cerr <<
"PROBLEM in G4VIntersectionLocator::GetLocalSurfaceNormal."
426 G4cerr <<
" Normal is not unit - mag=" << Normal.mag() <<
G4endl;
427 G4cerr <<
" at trial local point " << CurrentE_Point <<
G4endl;
454 G4bool goodAdjust=
false, Intersects_FP=
false, validNormal=
false;
459 if(!validNormal) {
return false; }
470 <<
"G4VIntersectionLocator::AdjustementOfFoundIntersection()"
472 <<
" No intersection. Parallels lines!" <<
G4endl;
475 lambda =- Normal.
dot(CurrentF_Point-CurrentE_Point)/n_d_m;
479 NewPoint = CurrentF_Point+lambda*MomentumDir;
483 dist = std::abs(lambda);
495 fPreviousSafety, fPreviousSftOrigin,
496 stepLengthFP, Point_G );
503 Intersects_FP =
IntersectChord( CurrentF_Point, NewPoint, NewSafety,
504 fPreviousSafety, fPreviousSftOrigin,
505 stepLengthFP, Point_G );
510 IntersectionPoint = Point_G;
527 G4ThreeVector NormalAtEntryLast, NormalAtEntryGlobal, diffNormals;
533 NormalAtEntryLast = GetLastSurfaceNormal( CurrentInt_Point, validNormalLast );
543 std::ostringstream message;
544 message <<
"PROBLEM: Normal is not unit - magnitude = "
546 message <<
" at trial intersection point " << CurrentInt_Point <<
G4endl;
547 message <<
" Obtained from Get *Last* Surface Normal.";
548 G4Exception(
"G4VIntersectionLocator::GetSurfaceNormal()",
553 if( validNormalLast )
555 NormalAtEntry=NormalAtEntryLast;
557 validNormal = validNormalLast;
559 return NormalAtEntry;
571 GetLocalSurfaceNormal( CurrentE_Point, validNormal );
578 if( validNormal && ( std::fabs(globalNormal.
mag2() - 1.0) >
perThousand ) )
580 std::ostringstream message;
581 message <<
"**************************************************************"
583 message <<
" Bad Normal in G4VIntersectionLocator::GetGlobalSurfaceNormal "
585 message <<
" * Constituents: " <<
G4endl;
586 message <<
" Local Normal= " << localNormal <<
G4endl;
587 message <<
" Transform: " << G4endl
590 <<
" Net Rotation = " << localToGlobal.
NetRotation()
592 message <<
" * Result: " <<
G4endl;
593 message <<
" Global Normal= " << localNormal <<
G4endl;
594 message <<
"**************************************************************"
596 G4Exception(
"G4VIntersectionLocator::GetGlobalSurfaceNormal()",
610 G4bool& normalIsValid)
const
615 normalIsValid= validNorm;
632 G4double MomDir_dot_Norm = NewMomentumDir.
dot( NormalAtEntry ) ;
634 MomDir_dot_ABchord= (1.0 / ABchord_length) * NewMomentumDir.
dot( ChordAB_v );
636 std::ostringstream outStream;
638 << std::setw(6) <<
" Step# "
639 << std::setw(17) <<
" |ChordEF|(mag)" <<
" "
640 << std::setw(18) <<
" uMomentum.Normal" <<
" "
641 << std::setw(18) <<
" uMomentum.ABdir " <<
" "
642 << std::setw(16) <<
" AB-dist " <<
" "
643 <<
" Chord Vector (EF) "
645 outStream.precision(7);
647 <<
" " << std::setw(5) << step_no
648 <<
" " << std::setw(18) << ChordEF_v.
mag()
649 <<
" " << std::setw(18) << MomDir_dot_Norm
650 <<
" " << std::setw(18) << MomDir_dot_ABchord
651 <<
" " << std::setw(12) << ABchord_length
655 <<
" MomentumDir= " <<
" " << NewMomentumDir
656 <<
" Normal at Entry E= " << NormalAtEntry
657 <<
" AB chord = " << ChordAB_v
659 G4cout << outStream.str();
663 G4cerr <<
" PROBLEM in G4VIntersectionLocator::ReportTrialStep " << G4endl
664 <<
" Normal is not unit - mag=" << NormalAtEntry.
mag()
665 <<
" ValidNormalAtE = " << validNormal
688 MethodName(
"G4VIntersectionLocator::LocateGlobalPointWithinVolumeAndCheck()");
709 G4cerr <<
" ERROR in " << MethodName <<
" Position located "
710 << ( inMother ==
kSurface ?
" on Surface " :
" outside " )
711 <<
"expected volume" <<
G4endl;
713 G4cerr <<
" Safety (from Outside) = " << safetyFromOut <<
G4endl;
721 if( (nextPhysical != motherPhys)
722 || (nextPhysical->
GetCopyNo() != motherCopyNo )
725 G4cerr <<
" ERROR in " << MethodName
726 <<
" Position located outside expected volume" <<
G4endl;
752 G4cerr <<
" ERROR occured in Intersection Locator" <<
G4endl;
753 G4cerr <<
" Code Location info: " << CodeLocationInfo <<
G4endl;
754 if( CheckMode > 1 ) {
783 G4int verboseLevel= 5;
786 -1.0, NewSafety, substep_no, msg, verboseLevel );
787 msg <<
"Error in advancing propagation." <<
G4endl
788 <<
" Point A (start) is " << A_PtVel <<
G4endl
789 <<
" Point B (end) is " << B_PtVel <<
G4endl
790 <<
" Curve distance is " << curveDist <<
G4endl
792 <<
"The final curve point is not further along"
793 <<
" than the original!" <<
G4endl;
794 msg <<
" Value of fEpsStep= " << epsStep <<
G4endl;
796 G4int oldprc = msg.precision(20);
797 msg <<
" Point A (Curve start) is " << StartPointVel << G4endl
798 <<
" Point B (Curve end) is " << EndPointVel << G4endl
799 <<
" Point A (Current start) is " << A_PtVel << G4endl
800 <<
" Point B (Current end) is " << B_PtVel << G4endl
801 <<
" Point S (Sub start) is " << SubStart_PtVel
802 <<
" Point E (Trial Point) is " << E_Point << G4endl
803 <<
" Point F (Intersection) is " << ApproxIntersecPointV
805 <<
" LocateIntersection parameters are : " << G4endl
806 <<
" Substep no (total) = " << substep_no << G4endl
807 <<
" Substep (depth= " << depth << substep_no_p;
808 msg.precision(oldprc);
825 oss <<
"ReportProgress: Current status of intersection search: " <<
G4endl;
826 if( depth > 0 ) oss <<
" Depth= " << depth;
827 oss <<
" Substep no = " << substep_no <<
G4endl;
828 G4int verboseLevel = 5;
833 printStatus( StartPointVel, EndPointVel, -1.0, -1.0, -1,
835 oss <<
" * Start and end-point of requested Step:" <<
G4endl;
836 oss <<
" ** State of point A: ";
837 printStatus( A_PtVel, A_PtVel, -1.0, safetyPrev, substep_no-1,
839 oss <<
" ** State of point B: ";
840 printStatus( A_PtVel, B_PtVel, -1.0, safetyLast, substep_no,
853 unsigned long int numCalls )
864 if( (TrialPoint - StartPosition).mag2() < tolerance*tolerance)
869 G4cout <<
"Intersection F == start A in " << MethodName;
872 G4cout <<
" Start-Trial: " << TrialPoint - StartPosition;
873 G4cout <<
" Start-last: " << StartPosition - lastStart;
875 if( (StartPosition - lastStart).mag() < tolerance )
880 G4cout <<
" { Unmoved: " <<
" still#= " << numStill
881 <<
" total # = " << numUnmoved <<
" } - ";
887 G4cout <<
" Occured: " << ++occurredOnTop;
888 G4cout <<
" out of total calls= " << numCalls;
890 lastStart = StartPosition;
G4FieldTrack ReEstimateEndpoint(const G4FieldTrack &CurrentStateA, const G4FieldTrack &EstimtdEndStateB, G4double linearDistSq, G4double curveDist)
G4double GetCurveLength() const
CLHEP::Hep3Vector G4ThreeVector
G4VPhysicalVolume * GetVolume(G4int depth=0) const
double dot(const Hep3Vector &) const
G4ThreeVector GetGlobalSurfaceNormal(const G4ThreeVector &CurrentE_Point, G4bool &validNormal)
G4bool IsCheckModeActive() const
G4ThreeVector GetSurfaceNormal(const G4ThreeVector &CurrentInt_Point, G4bool &validNormal)
virtual G4TouchableHistoryHandle CreateTouchableHistoryHandle() const
G4bool IntersectChord(const G4ThreeVector &StartPointA, const G4ThreeVector &EndPointB, G4double &NewSafety, G4double &PreviousSafety, G4ThreeVector &PreviousSftOrigin, G4double &LinearStepLength, G4ThreeVector &IntersectionPoint, G4bool *calledNavigator=0)
G4double GetSurfaceTolerance() const
const G4ThreeVector & GetMomentumDir() const
G4VSolid * GetSolid() const
G4Navigator * fiNavigator
const G4AffineTransform GetLocalToGlobalTransform() const
void printStatus(const G4FieldTrack &startFT, const G4FieldTrack ¤tFT, G4double requestStep, G4double safety, G4int stepNum)
static constexpr double perThousand
void SetCheckMode(G4bool value)
G4double GetEpsilonStepFor()
void ReportImmediateHit(const char *MethodName, const G4ThreeVector &StartPosition, const G4ThreeVector &TrialPoint, double tolerance, unsigned long int numCalls)
G4ThreeVector GetPosition() const
G4GLOB_DLL std::ostream G4cout
virtual EInside Inside(const G4ThreeVector &p) const =0
virtual ~G4VIntersectionLocator()
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const =0
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)
void ReportTrialStep(G4int step_no, const G4ThreeVector &ChordAB_v, const G4ThreeVector &ChordEF_v, const G4ThreeVector &NewMomentumDir, const G4ThreeVector &NormalAtEntry, G4bool validNormal)
void LocateGlobalPointWithinVolumeCheckAndReport(const G4ThreeVector &pos, const G4String &CodeLocationInfo, G4int CheckMode)
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
G4Navigator * GetNavigatorFor()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4bool LocateGlobalPointWithinVolumeAndCheck(const G4ThreeVector &pos)
G4TouchableHistory * CreateTouchableHistory() const
G4LogicalVolume * GetLogicalVolume() const
#define fPreviousSftOrigin
virtual G4ThreeVector GetGlobalExitNormal(const G4ThreeVector &point, G4bool *valid)
G4Navigator * fHelpingNavigator
G4VIntersectionLocator(G4Navigator *theNavigator)
virtual G4int GetCopyNo() const =0
void SetWorldVolume(G4VPhysicalVolume *pWorld)
const G4AffineTransform & GetGlobalToLocalTransform() const
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=0, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
G4bool CheckAndReEstimateEndpoint(const G4FieldTrack &CurrentStartA, const G4FieldTrack &EstimatedEndB, G4FieldTrack &RevisedEndPoint, G4int &errorCode)
const G4AffineTransform & GetTopTransform() const
static constexpr double perThousand
void CheckMode(G4bool mode)
const G4NavigationHistory * GetHistory() const
G4VSolid * GetSolid(G4int depth=0) const
G4ThreeVector GetMomentum() const
G4TouchableHistory * fpTouchable
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const =0
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)
G4MagInt_Driver * GetIntegrationDriver()
G4ChordFinder * GetChordFinderFor()
G4bool AccurateAdvance(G4FieldTrack &y_current, G4double hstep, G4double eps, G4double hinitial=0.0)
static G4GeometryTolerance * GetInstance()
virtual void LocateGlobalPointWithinVolume(const G4ThreeVector &position)
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)
G4GLOB_DLL std::ostream G4cerr