47 fUseNormalCorrection(false),
48 fiNavigator( theNavigator ),
50 fiEpsilonStep( -1.0 ),
51 fiDeltaIntersection( -1.0 ),
81 std::ostringstream os;
82 printStatus( StartFT, CurrentFT, requestStep, safety, stepNo, os);
96 std::ostringstream& os )
107 if( ((stepNo == 0) && (verboseLevel <3)) || (verboseLevel >= 3) )
109 oldprc = os.precision(4);
110 os << std::setw( 6) <<
" "
111 << std::setw( 25) <<
" Current Position and Direction" <<
" "
113 os << std::setw( 5) <<
"Step#"
114 << std::setw(10) <<
" s " <<
" "
115 << std::setw(10) <<
"X(mm)" <<
" "
116 << std::setw(10) <<
"Y(mm)" <<
" "
117 << std::setw(10) <<
"Z(mm)" <<
" "
118 << std::setw( 7) <<
" N_x " <<
" "
119 << std::setw( 7) <<
" N_y " <<
" "
120 << std::setw( 7) <<
" N_z " <<
" " ;
121 os << std::setw( 7) <<
" Delta|N|" <<
" "
122 << std::setw( 9) <<
"StepLen" <<
" "
123 << std::setw(12) <<
"StartSafety" <<
" "
124 << std::setw( 9) <<
"PhsStep" <<
" ";
126 os.precision(oldprc);
128 if((stepNo == 0) && (verboseLevel <=3))
134 if( verboseLevel <= 3 )
138 os << std::setw( 4) << stepNo <<
" ";
142 os << std::setw( 5) <<
"Start" ;
144 oldprc = os.precision(8);
146 os << std::setw(10) << CurrentPosition.x() <<
" "
147 << std::setw(10) << CurrentPosition.y() <<
" "
148 << std::setw(10) << CurrentPosition.z() <<
" ";
150 os << std::setw( 7) << CurrentUnitVelocity.x() <<
" "
151 << std::setw( 7) << CurrentUnitVelocity.y() <<
" "
152 << std::setw( 7) << CurrentUnitVelocity.z() <<
" ";
157 os << std::setw( 9) << step_len <<
" ";
158 os << std::setw(12) << safety <<
" ";
159 if( requestStep != -1.0 )
161 os << std::setw( 9) << requestStep <<
" ";
165 os << std::setw( 9) <<
"Init/NotKnown" <<
" ";
168 os.precision(oldprc);
174 os <<
"Step taken was " << step_len
175 <<
" out of PhysicalStep= " << requestStep <<
G4endl;
176 os <<
"Final safety is: " << safety <<
G4endl;
177 os <<
"Chord length = " << (CurrentPosition-StartPosition).mag()
199 const G4int no_trials= 20;
205 G4double advanceLength= endCurveLen - currentCurveLen ;
216 while( !goodAdvance && (++itrial < no_trials) );
220 retEndPoint= newEndPoint;
224 retEndPoint= EstimatedEndStateB;
230 static const G4String MethodName(
"G4VIntersectionLocator::ReEstimateEndpoint");
233 G4int latest_good_trials=0;
238 G4cout << MethodName <<
" called - goodAdv= " << goodAdvance
239 <<
" trials = " << itrial
240 <<
" previous good= " << latest_good_trials
243 latest_good_trials=0;
247 latest_good_trials++;
258 G4cout << MethodName <<
"> AccurateAdvance failed " ;
259 G4cout <<
" in " << itrial <<
" integration trials/steps. " <<
G4endl;
260 G4cout <<
" It went only " << lengthDone <<
" instead of " << curveDist
261 <<
" -- a difference of " << curveDist - lengthDone <<
G4endl;
262 G4cout <<
" ReEstimateEndpoint> Reset endPoint to original value!"
267 static G4int noInaccuracyWarnings = 0;
268 G4int maxNoWarnings = 10;
269 if ( (noInaccuracyWarnings < maxNoWarnings )
274 std::ostringstream message;
275 message.precision(12);
276 message <<
" Integration inaccuracy requires"
277 <<
" an adjustment in the step's endpoint." <<
G4endl
278 <<
" Two mid-points are further apart than their"
279 <<
" curve length difference" <<
G4endl
280 <<
" Dist = " << std::sqrt(linearDistSq)
281 <<
" curve length = " << curveDist <<
G4endl;
282 message <<
" Correction applied is " << move.mag() << G4endl
283 <<
" Old Estimated B position= "
285 <<
" Recalculated Position= "
287 <<
" Change ( new - old ) = " << move;
288 G4Exception(
"G4VIntersectionLocator::ReEstimateEndpoint()",
299 sumCorrectionsSq += (EstimatedEndStateB.
GetPosition() -
302 linearDistSq -= curveDist;
339 if( (pLogical != 0) && ( (pSolid=pLogical->
GetSolid()) !=0 ) )
353 G4cerr <<
"PROBLEM in G4VIntersectionLocator::GetLocalSurfaceNormal."
355 G4cerr <<
" Normal is not unit - mag=" << Normal.mag() <<
G4endl;
356 G4cerr <<
" at trial local point " << CurrentE_Point <<
G4endl;
384 G4bool goodAdjust=
false, Intersects_FP=
false, validNormal=
false;
389 if(!validNormal) {
return false; }
393 G4double n_d_m = Normal.dot(MomentumDir);
400 <<
"G4VIntersectionLocator::AdjustementOfFoundIntersection()"
402 <<
" No intersection. Parallels lines!" <<
G4endl;
405 lambda =- Normal.dot(CurrentF_Point-CurrentE_Point)/n_d_m;
409 NewPoint = CurrentF_Point+lambda*MomentumDir;
413 dist = std::abs(lambda);
425 fPreviousSafety, fPreviousSftOrigin,
426 stepLengthFP, Point_G );
433 Intersects_FP =
IntersectChord( CurrentF_Point, NewPoint, NewSafety,
434 fPreviousSafety, fPreviousSftOrigin,
435 stepLengthFP, Point_G );
440 IntersectionPoint = Point_G;
453 G4ThreeVector NormalAtEntryLast, NormalAtEntryGlobal, diffNormals;
467 && ( std::fabs(NormalAtEntryLast.mag2() - 1.0) >
perThousand ) )
469 std::ostringstream message;
470 message <<
"PROBLEM: Normal is not unit - magnitude = "
471 << NormalAtEntryLast.mag() <<
G4endl;
472 message <<
" at trial intersection point " << CurrentInt_Point <<
G4endl;
473 message <<
" Obtained from Get *Last* Surface Normal.";
474 G4Exception(
"G4VIntersectionLocator::GetSurfaceNormal()",
479 if( validNormalLast )
481 NormalAtEntry=NormalAtEntryLast;
483 validNormal = validNormalLast;
485 return NormalAtEntry;
500 if( validNormal && ( std::fabs(globalNormal.mag2() - 1.0) >
perThousand ) )
502 std::ostringstream message;
503 message <<
"**************************************************************"
505 message <<
" Bad Normal in G4VIntersectionLocator::GetGlobalSurfaceNormal "
507 message <<
" * Constituents: " <<
G4endl;
508 message <<
" Local Normal= " << localNormal <<
G4endl;
509 message <<
" Transform: " << G4endl
512 <<
" Net Rotation = " << localToGlobal.
NetRotation()
514 message <<
" * Result: " <<
G4endl;
515 message <<
" Global Normal= " << localNormal <<
G4endl;
516 message <<
"**************************************************************"
518 G4Exception(
"G4VIntersectionLocator::GetGlobalSurfaceNormal()",
528 G4bool& normalIsValid)
const
533 normalIsValid= validNorm;
545 G4double ABchord_length = ChordAB_v.mag();
546 G4double MomDir_dot_Norm = NewMomentumDir.dot( NormalAtEntry ) ;
548 MomDir_dot_ABchord= (1.0 / ABchord_length) * NewMomentumDir.dot( ChordAB_v );
550 std::ostringstream outStream;
552 << std::setw(6) <<
" Step# "
553 << std::setw(17) <<
" |ChordEF|(mag)" <<
" "
554 << std::setw(18) <<
" uMomentum.Normal" <<
" "
555 << std::setw(18) <<
" uMomentum.ABdir " <<
" "
556 << std::setw(16) <<
" AB-dist " <<
" "
557 <<
" Chord Vector (EF) "
559 outStream.precision(7);
561 <<
" " << std::setw(5) << step_no
562 <<
" " << std::setw(18) << ChordEF_v.mag()
563 <<
" " << std::setw(18) << MomDir_dot_Norm
564 <<
" " << std::setw(18) << MomDir_dot_ABchord
565 <<
" " << std::setw(12) << ABchord_length
569 <<
" MomentumDir= " <<
" " << NewMomentumDir
570 <<
" Normal at Entry E= " << NormalAtEntry
571 <<
" AB chord = " << ChordAB_v
573 G4cout << outStream.str();
575 if( ( std::fabs(NormalAtEntry.mag2() - 1.0) >
perThousand ) )
577 G4cerr <<
" PROBLEM in G4VIntersectionLocator::ReportTrialStep " << G4endl
578 <<
" Normal is not unit - mag=" << NormalAtEntry.mag()
579 <<
" ValidNormalAtE = " << validNormal
598 const G4String MethodName(
"G4VIntersectionLocator::LocateGlobalPointWithinVolumeAndCheck()");
609 G4VSolid* motherSolid= startTH->GetSolid();
619 G4cerr <<
" ERROR in " << MethodName <<
" Position located "
620 << ( inMother ==
kSurface ?
" on Surface " :
" outside " )
621 <<
"expected volume" <<
G4endl;
623 G4cerr <<
" Safety (from Outside) = " << safetyFromOut <<
G4endl;
631 if( (nextPhysical != motherPhys)
632 || (nextPhysical->
GetCopyNo() != motherCopyNo )
635 G4cerr <<
" ERROR in " << MethodName
636 <<
" Position located outside expected volume" <<
G4endl;
659 G4cerr <<
" ERROR occured in Intersection Locator" <<
G4endl;
660 G4cerr <<
" Code Location info: " << CodeLocationInfo <<
G4endl;
661 if( CheckMode > 1 ) {
G4FieldTrack ReEstimateEndpoint(const G4FieldTrack &CurrentStateA, const G4FieldTrack &EstimtdEndStateB, G4double linearDistSq, G4double curveDist)
G4double GetCurveLength() const
CLHEP::Hep3Vector G4ThreeVector
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
G4ThreeVector GetLastSurfaceNormal(const G4ThreeVector &intersectPoint, G4bool &validNormal) const
G4Navigator * fiNavigator
static const double perThousand
const G4AffineTransform GetLocalToGlobalTransform() const
void SetCheckMode(G4bool value)
G4double GetEpsilonStepFor()
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 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 printStatus(const G4FieldTrack &startFT, const G4FieldTrack ¤tFT, G4double requestStep, G4double safety, G4int step)
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)
G4ThreeVector GetLocalSurfaceNormal(const G4ThreeVector &CurrentE_Point, G4bool &validNormal)
const G4AffineTransform & GetTopTransform() const
void CheckMode(G4bool mode)
const G4NavigationHistory * GetHistory() 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
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)
G4VSolid * GetSolid() const
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