37using CLHEP::millimeter;
56 G4String fType = fId +
"::ComputeStep()";
58 if ( fVerbose == 1 || fVerbose > 4 )
60 G4cout <<
"*************** " << fType <<
" *****************" <<
G4endl
62 << std::setw(15) <<
"Safety/mm" <<
" "
63 << std::setw(15) <<
"Distance/mm" <<
" "
64 << std::setw(52) <<
"Position (local coordinates)"
67 << std::setw(15) << motherSafety / millimeter <<
" "
68 << std::setw(15) <<
"N/C" <<
" " << localPoint <<
" - "
72 if ( motherSafety < 0.0 )
74 std::ostringstream message;
75 message <<
"Negative Safety In Voxel Navigation !" <<
G4endl
76 <<
" Current solid " << motherSolid->
GetName()
77 <<
" gave negative safety: " << motherSafety / millimeter <<
G4endl
78 <<
" for the current (local) point " << localPoint;
79 message <<
" Solid info: " << *motherSolid <<
G4endl;
84 std::ostringstream message;
85 message <<
"Point is outside Current Volume - " <<
G4endl
86 <<
" Point " << localPoint / millimeter
87 <<
" is outside current volume '" << motherPhysical->
GetName()
90 message <<
" Estimated isotropic distance to solid (distToIn)= "
91 << estDistToSolid <<
G4endl;
92 if( estDistToSolid > 100.0 * motherSolid->
GetTolerance() )
94 message <<
" Solid info: " << *motherSolid <<
G4endl;
96 "Point is far outside Current Volume !" );
101 "Point is a little outside Current Volume.");
109 static const G4int precVerf = 16;
111 G4cout <<
" - Information on mother / key daughters ..." <<
G4endl;
112 G4cout <<
" Type " << std::setw(12) <<
"Solid-Name" <<
" "
113 << std::setw(3*(6+precVerf)) <<
" local point" <<
" "
114 << std::setw(4+precVerf) <<
"solid-Safety" <<
" "
115 << std::setw(4+precVerf) <<
"solid-Step" <<
" "
116 << std::setw(17) <<
"distance Method "
117 << std::setw(3*(6+precVerf)) <<
" local direction" <<
" "
119 G4cout <<
" Mother " << std::setw(12) << motherSolid->
GetName() <<
" "
120 << std::setw(4+precVerf) << localPoint <<
" "
121 << std::setw(4+precVerf) << motherSafety <<
" "
123 G4cout.precision(oldprec);
142 if ( sampleStep < kInfinity )
145 intersectionPoint = samplePoint + sampleStep * sampleDirection;
146 EInside insideIntPt = sampleSolid->
Inside(intersectionPoint);
147 G4String fType = fId +
"::ComputeStep()";
149 G4String solidResponse =
"-kInside-";
151 { solidResponse =
"-kOutside-"; }
153 { solidResponse =
"-kSurface-"; }
155 if ( fVerbose == 1 || fVerbose > 4 )
157 G4cout <<
" Invoked Inside() for solid: "
159 <<
". Solid replied: " << solidResponse <<
G4endl
160 <<
" For point p: " << intersectionPoint
161 <<
", considered as 'intersection' point." <<
G4endl;
164 G4double safetyIn = -1, safetyOut = -1;
165 G4double newDistIn = -1, newDistOut = -1;
168 safetyIn = sampleSolid->
DistanceToIn(intersectionPoint);
169 newDistIn = sampleSolid->
DistanceToIn(intersectionPoint,
180 std::ostringstream message;
181 message.precision(16);
182 message <<
"Conflicting response from Solid." <<
G4endl
183 <<
" Inaccurate solid DistanceToIn"
185 <<
" Solid gave DistanceToIn = "
186 << sampleStep <<
" yet returns " << solidResponse
187 <<
" for this point !" <<
G4endl
188 <<
" Original Point = " << samplePoint <<
G4endl
189 <<
" Original Direction = " << sampleDirection <<
G4endl
190 <<
" Intersection Point = " << intersectionPoint <<
G4endl
191 <<
" Safety values: " <<
G4endl;
194 message <<
" DistanceToIn(p) = " << safetyIn;
198 message <<
" DistanceToOut(p) = " << safetyOut;
201 message <<
" Solid Parameters: " << *sampleSolid;
209 if( std::max( newDistIn, newDistOut ) <=
212 std::ostringstream message;
213 message <<
"Zero from both Solid DistanceIn and Out(p,v)." <<
G4endl
214 <<
" Identified point for which the solid "
216 <<
" has MAJOR problem: " <<
G4endl
217 <<
" --> Both DistanceToIn(p,v) and DistanceToOut(p,v) "
218 <<
"return Zero, an equivalent value or negative value."
220 <<
" Solid: " << sampleSolid <<
G4endl
221 <<
" Point p= " << intersectionPoint <<
G4endl
222 <<
" Direction v= " << sampleDirection <<
G4endl
223 <<
" DistanceToIn(p,v) = " << newDistIn <<
G4endl
224 <<
" DistanceToOut(p,v,..) = " << newDistOut <<
G4endl
225 <<
" Safety values: " <<
G4endl
226 <<
" DistanceToIn(p) = " << safetyIn <<
G4endl
227 <<
" DistanceToOut(p) = " << safetyOut;
236 static const G4int precVerf= 20;
239 << std::setw(12) << sampleSolid->
GetName() <<
" "
240 << std::setw(4+precVerf) << samplePoint <<
" "
241 << std::setw(4+precVerf) << sampleSafety <<
" "
242 << std::setw(4+precVerf) << sampleStep <<
" "
243 << std::setw(16) <<
"distanceToIn" <<
" "
244 << std::setw(4+precVerf) << localDirection <<
" "
246 G4cout.precision(oldprec);
269 G4bool SuspiciousDaughterDist = ( sampleStep >= motherStep )
270 && ( sampleStep < kInfinity );
272 if( sampleStep >= kInfinity )
276 msg <<
" WARNING - Called with 'infinite' step. " <<
G4endl;
277 msg <<
" Checks have no meaning if daughter step is infinite." <<
G4endl;
278 msg <<
" kInfinity = " << kInfinity / millimeter <<
G4endl;
279 msg <<
" sampleStep = " << sampleStep / millimeter <<
G4endl;
280 msg <<
" sampleStep < kInfinity " << (sampleStep<kInfinity) <<
G4endl;
281 msg <<
" kInfinity - sampleStep " << (kInfinity-sampleStep) / millimeter <<
G4endl;
282 msg <<
" Returning immediately.";
283 G4Exception(
"G4NavigationLogger::CheckDaughterEntryPoint()",
297 G4ThreeVector localExitMotherPos = localPoint+motherStep*localDirection;
303 G4ThreeVector localEntryInDaughter = localPoint+sampleStep*localDirection;
304 EInside insideMother = motherSolid->
Inside( localEntryInDaughter );
306 G4String solidResponse =
"-kInside-";
307 if (insideMother ==
kOutside) { solidResponse =
"-kOutside-"; }
308 else if (insideMother ==
kSurface) { solidResponse =
"-kSurface-"; }
310 G4double distToReEntry = distExitToReEntry + motherStep;
311 G4ThreeVector localReEntryPoint = localPoint+distToReEntry*localDirection;
315 G4bool DaughterEntryIsOutside = SuspiciousDaughterDist
316 && ( (sampleStep * (1.0+eps) < distToReEntry) || (insideMother ==
kOutside ) );
320 G4ThreeVector sampleEntryPoint = samplePoint+sampleStep*sampleDirection;
323 G4double sampleExitDist = sampleStep+sampleCrossingDist;
324 G4ThreeVector sampleExitPoint = samplePoint+sampleExitDist*sampleDirection;
326 G4bool TransitProblem = ( (sampleStep < motherStep)
328 || ( EntryIsMotherExit && (sampleCrossingDist >
kCarTolerance) );
330 if( DaughterEntryIsOutside
332 || (SuspiciousDaughterDist && (fVerbose > 3) ) )
337 if( DaughterEntryIsOutside )
339 msg <<
"WARNING> Intersection distance to Daughter volume is further"
340 <<
" than the distance to boundary." <<
G4endl
341 <<
" It appears that part of the daughter volume is *outside*"
342 <<
" this mother. " <<
G4endl;
343 msg <<
" One of the following checks signaled a problem:" <<
G4endl
344 <<
" -sampleStep (dist to daugh) < mother-exit dist + distance "
345 <<
"to ReEntry point for mother " <<
G4endl
346 <<
" -position of daughter intersection is outside mother volume."
349 else if( TransitProblem )
351 G4double protrusion = sampleExitDist - motherStep;
353 msg <<
"WARNING> Daughter volume extends beyond mother boundary. "
355 if ( ( sampleStep < motherStep )
359 msg <<
" Crossing distance in the daughter causes is to extend"
360 <<
" beyond the mother exit. " <<
G4endl;
361 msg <<
" Length protruding = " << protrusion <<
G4endl;
363 if( EntryIsMotherExit )
366 msg <<
" Intersection distance to Daughter is within "
367 <<
" tolerance of the distance" <<
G4endl;
368 msg <<
" to the mother boundary * and * " <<
G4endl;
369 msg <<
" the crossing distance in the daughter is > tolerance."
375 msg <<
"NearMiss> Intersection to Daughter volume is in extension past the"
376 <<
" current exit point of the mother volume." <<
G4endl;
377 msg <<
" This is not an error - just an unusual occurrence,"
378 <<
" possible in the case of concave volume. " <<
G4endl;
380 msg <<
"---- Information about intersection with daughter, mother: "
382 msg <<
" sampleStep (daughter) = " << sampleStep <<
G4endl
383 <<
" motherStep = " << motherStep <<
G4endl
384 <<
" distToRentry(mother) = " << distToReEntry <<
G4endl
385 <<
" Inside(entry pnt daug): " << solidResponse <<
G4endl
386 <<
" dist across daughter = " << sampleCrossingDist <<
G4endl;
387 msg <<
" Mother Name (Solid) : " << motherSolid->
GetName() <<
G4endl
388 <<
" In local (mother) coordinates: " <<
G4endl
389 <<
" Starting Point = " << localPoint <<
G4endl
390 <<
" Direction = " << localDirection <<
G4endl
391 <<
" Exit Point (mother)= " << localExitMotherPos <<
G4endl
392 <<
" Entry Point (daughter)= " << localPoint+sampleStep*localDirection
394 if( distToReEntry < kInfinity )
396 msg <<
" ReEntry Point (mother)= " << localReEntryPoint <<
G4endl;
400 msg <<
" No ReEntry - track does not encounter mother volume again! "
403 msg <<
" Daughter Name (Solid): " << sampleSolid->
GetName() <<
G4endl
404 <<
" In daughter coordinates: " <<
G4endl
405 <<
" Starting Point = " << samplePoint <<
G4endl
406 <<
" Direction = " << sampleDirection <<
G4endl
407 <<
" Entry Point (daughter)= " << sampleEntryPoint
409 msg <<
" Description of mother solid: " <<
G4endl
411 <<
" Description of daughter solid: " <<
G4endl
412 << *sampleSolid <<
G4endl;
413 G4String fType = fId +
"::ComputeStep()";
415 if( DaughterEntryIsOutside || TransitProblem )
422 <<
" -- Checked distance of Entry to daughter vs exit of mother"
441 if ( fVerbose == 1 || fVerbose > 4 )
444 << std::setw(15) << motherSafety <<
" "
445 << std::setw(15) << motherStep <<
" " << localPoint <<
" - "
449 if( ( motherStep < 0.0 ) || ( motherStep >= kInfinity) )
451 G4String fType = fId +
"::ComputeStep()";
454 std::ostringstream message;
455 message <<
"Current point is outside the current solid !" <<
G4endl
456 <<
" Problem in Navigation" <<
G4endl
457 <<
" Point (local coordinates): "
459 <<
" Local Direction: " << localDirection <<
G4endl
460 <<
" Solid: " << motherSolid->
GetName();
463 G4cout.precision(oldPrOut);
464 G4cerr.precision(oldPrErr);
468 static const G4int precVerf = 20;
470 G4cout <<
" Mother " << std::setw(12) << motherSolid->
GetName() <<
" "
471 << std::setw(4+precVerf) << localPoint <<
" "
472 << std::setw(4+precVerf) << motherSafety <<
" "
473 << std::setw(4+precVerf) << motherStep <<
" "
474 << std::setw(16) <<
"distanceToOut" <<
" "
475 << std::setw(4+precVerf) << localDirection <<
" "
477 G4cout.precision(oldprec);
494 banner =
static_cast<G4int>(isMotherVolume);
498 G4String volumeType = isMotherVolume ?
" Mother " :
"Daughter";
501 G4cout <<
"************** " << fId <<
"::ComputeSafety() ****************"
504 << std::setw(15) <<
"Safety/mm" <<
" "
505 << std::setw(52) <<
"Position (local coordinates)"
509 << std::setw(15) << safety <<
" " << point <<
" - "
529 << std::setw(15) << sampleSafety <<
" ";
532 G4cout << std::setw(15) << sampleStep <<
" ";
536 G4cout << std::setw(15) <<
"Not-Available" <<
" ";
538 G4cout << samplePoint <<
" - "
542 G4cout <<
" dir= " << sampleDirection;
545 G4cout.precision(oldPrec);
560 const char* msg )
const
563 G4bool badLength = ( std::fabs ( normMag2 - 1.0 ) > CLHEP::perMillion );
567 G4double normMag = std::sqrt(normMag2);
569 message.precision(10);
570 message <<
"============================================================"
572 message <<
" WARNING> Normal is not a unit vector. "
573 <<
" - but |normal| = " << normMag
574 <<
" - and |normal|^2 = " << normMag2 <<
G4endl
575 <<
" which differ from 1.0 by: " <<
G4endl
576 <<
" |normal|-1 = " << normMag - 1.0
577 <<
" and |normal|^2 - 1 = " << normMag2 - 1.0 <<
G4endl
578 <<
" n = " << unitNormal <<
G4endl;
579 message <<
" Info string: " << msg <<
G4endl;
580 message <<
"============================================================"
583 message.precision(16);
585 message <<
" Information on call to DistanceToOut: " <<
G4endl;
586 message <<
" Position = " << localPoint <<
G4endl
587 <<
" Direction = " << localDirection <<
G4endl;
588 message <<
" Obtained> distance = " << step <<
G4endl;
589 message <<
" > Exit position = " << localPoint+step*localDirection
591 message <<
" Parameters of solid: " <<
G4endl;
593 message <<
"============================================================";
595 G4String fMethod = fId +
"::ComputeStep()";
610 const char* msg )
const
613 G4bool badLength = ( std::fabs ( normMag2 - 1.0 ) > CLHEP::perMillion );
617 G4double normMag = std::sqrt(normMag2);
619 message.precision(10);
620 message <<
"============================================================"
622 message <<
" WARNING> Rotated n(ormal) is not a unit vector. " <<
G4endl
623 <<
" |normal| = " << normMag
624 <<
" and |normal|^2 = " << normMag2 <<
G4endl
625 <<
" Diff from 1.0: " <<
G4endl
626 <<
" |normal|-1 = " << normMag - 1.0
627 <<
" and |normal|^2 - 1 = " << normMag2 - 1.0 <<
G4endl;
628 message <<
" Rotated n = (" << rotatedNormal.
x() <<
"," << rotatedNormal.
y() <<
","
629 << rotatedNormal.
z() <<
")" <<
G4endl;
630 message <<
" Original n = (" << originalNormal.
x() <<
"," << originalNormal.
y() <<
","
631 << originalNormal.
z() <<
")" <<
G4endl;
632 message <<
" Info string: " << msg <<
G4endl;
633 message <<
"============================================================"
636 message.precision(16);
638 message <<
" Information on RotationMatrix : " <<
G4endl;
639 message <<
" Original: " <<
G4endl;
640 message << rotationM <<
G4endl;
641 message <<
" Inverse (used in transformation): " <<
G4endl;
643 message <<
"============================================================";
645 G4String fMethod = fId +
"::ComputeStep()";
666 const G4VSolid* solid = logicalVol !=
nullptr
669 G4String fMethod = fId +
"::ComputeStep()";
671 if( solid ==
nullptr )
674 "Erroneous call to ReportOutsideMother: no Solid is available");
693 && ( distToOut < 0.0 || distToOut >= kInfinity ) )
698 msg1 <<
" Dangerous inconsistency in response of solid." <<
G4endl
701 msg1 <<
" Mother volume gives safety > 0 despite being called for *Outside* point "
703 <<
" Location = " << localPoint <<
G4endl
704 <<
" Direction= " << localDirection <<
G4endl
705 <<
" - Safety (Isotropic d) = " << safetyToOut <<
G4endl
706 <<
" - Intersection Distance= " << distToOut <<
G4endl
727 if( fReportSoftWarnings )
729 msg <<
" Warning> DistanceToOut(p,v): "
730 <<
"Distance from surface is not rounded to zero" <<
G4endl;
742 msg <<
"============================================================"
744 msg <<
" WARNING> Current Point appears to be Outside mother volume !! "
746 msg <<
" Response of DistanceToOut was negative or kInfinity"
747 <<
" when called in " << fMethod <<
G4endl;
754 if( triggerDist <= 0.0 )
757 fMinTriggerDistance );
761 ? ( safetyToIn > triggerDist )
762 : ( safetyToOut > triggerDist );
770 G4Exception( fMethod,
"GeomNav0003", exceptionType, msg);
784 G4String fMethod = fId +
"::ComputeStep()";
787 const G4VSolid* solid = logicalVol !=
nullptr
789 if( solid ==
nullptr )
791 os <<
" ERROR> Solid is not available. Logical Volume = "
792 << logicalVol << std::endl;
812 const G4ThreeVector PointPlusDir = localPoint + epsilonDist * localDirection;
813 const G4ThreeVector PointMinusDir = localPoint - epsilonDist * localDirection;
814 const G4ThreeVector PointPlusNorm = localPoint + epsilonDist * exitNormal;
815 const G4ThreeVector PointMinusNorm = localPoint - epsilonDist * exitNormal;
823 os <<
" Current physical volume = " << physical->
GetName() <<
G4endl;
824 os <<
" Position (loc) = " << localPoint <<
G4endl
825 <<
" Direction (dir) = " << localDirection <<
G4endl;
826 os <<
" For confirmation:" <<
G4endl;
827 os <<
" Response of DistanceToOut (loc, +dir)= " << distToOut <<
G4endl;
828 os <<
" Response of DistanceToOut (loc, -dir)= " << distToOutNeg <<
G4endl;
830 os <<
" Inside responds = " << inSolid <<
" , ie: ";
833 os <<
" Outside -- a problem, as observed in " << fMethod <<
G4endl;
837 os <<
" Surface -- unexpected / inconsistent response ! " <<
G4endl;
841 os <<
" Inside -- unexpected / inconsistent response ! " <<
G4endl;
843 os <<
" Obtain safety(ToIn) = " << safetyToIn <<
G4endl;
844 os <<
" Obtain safety(ToOut) = " << safetyToOut <<
G4endl;
845 os <<
" Response of DistanceToIn (loc, +dir)= " << distToInPos <<
G4endl;
846 os <<
" Response of DistanceToIn (loc, -dir)= " << distToInNeg <<
G4endl;
848 os <<
" Exit Normal at loc = " << exitNormal <<
G4endl;
849 os <<
" Dir . Normal = " << exitNormal.
dot( localDirection );
852 os <<
" Checking points moved from position by distance/direction." <<
G4endl
853 <<
" Solid responses: " <<
G4endl
854 <<
" +eps in direction : "
856 <<
" +eps in Normal : "
858 <<
" -eps in direction : "
860 <<
" -eps in Normal : "
863 os <<
" Parameters of solid: " <<
G4endl;
865 os <<
"============================================================";
const G4double kCarTolerance
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
double dot(const Hep3Vector &) const
HepRotation inverse() const
static G4GeometryTolerance * GetInstance()
G4VSolid * GetSolid() const
void PreComputeStepLog(const G4VPhysicalVolume *motherPhysical, G4double motherSafety, const G4ThreeVector &localPoint) const
G4NavigationLogger(const G4String &id)
void CheckDaughterEntryPoint(const G4VSolid *sampleSolid, const G4ThreeVector &samplePoint, const G4ThreeVector &sampleDirection, const G4VSolid *motherSolid, const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, G4double motherStep, G4double sampleStep) const
void PrintDaughterLog(const G4VSolid *sampleSolid, const G4ThreeVector &samplePoint, G4double sampleSafety, G4bool onlySafety, const G4ThreeVector &sampleDirection, G4double sampleStep) const
G4bool CheckAndReportBadNormal(const G4ThreeVector &unitNormal, const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, G4double step, const G4VSolid *solid, const char *msg) const
void ComputeSafetyLog(const G4VSolid *solid, const G4ThreeVector &point, G4double safety, G4bool isMotherVolume, G4int banner=-1) const
void ReportVolumeAndIntersection(std::ostream &ostrm, const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, const G4VPhysicalVolume *physical) const
void PostComputeStepLog(const G4VSolid *motherSolid, const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, G4double motherStep, G4double motherSafety) const
void ReportOutsideMother(const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, const G4VPhysicalVolume *motherPV, G4double tDist=30.0 *CLHEP::cm) const
void AlongComputeStepLog(const G4VSolid *sampleSolid, const G4ThreeVector &samplePoint, const G4ThreeVector &sampleDirection, const G4ThreeVector &localDirection, G4double sampleSafety, G4double sampleStep) const
G4LogicalVolume * GetLogicalVolume() const
const G4String & GetName() const
G4double GetTolerance() const
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
virtual G4GeometryType GetEntityType() const =0
const G4String EInsideNames[3]