37using CLHEP::millimeter;
61 G4String fType = fId +
"::ComputeStep()";
63 if ( fVerbose == 1 || fVerbose > 4 )
65 G4cout <<
"*************** " << fType <<
" *****************" <<
G4endl
67 << std::setw(15) <<
"Safety/mm" <<
" "
68 << std::setw(15) <<
"Distance/mm" <<
" "
69 << std::setw(52) <<
"Position (local coordinates)"
72 << std::setw(15) << motherSafety / millimeter <<
" "
73 << std::setw(15) <<
"N/C" <<
" " << localPoint <<
" - "
77 if ( motherSafety < 0.0 )
79 std::ostringstream message;
80 message <<
"Negative Safety In Voxel Navigation !" <<
G4endl
81 <<
" Current solid " << motherSolid->
GetName()
82 <<
" gave negative safety: " << motherSafety / millimeter <<
G4endl
83 <<
" for the current (local) point " << localPoint;
84 message <<
" Solid info: " << *motherSolid <<
G4endl;
89 std::ostringstream message;
90 message <<
"Point is outside Current Volume - " <<
G4endl
91 <<
" Point " << localPoint / millimeter
92 <<
" is outside current volume '" << motherPhysical->
GetName()
95 message <<
" Estimated isotropic distance to solid (distToIn)= "
96 << estDistToSolid <<
G4endl;
97 if( estDistToSolid > 100.0 * motherSolid->
GetTolerance() )
99 message <<
" Solid info: " << *motherSolid <<
G4endl;
101 "Point is far outside Current Volume !" );
106 "Point is a little outside Current Volume.");
114 static const G4int precVerf = 16;
116 G4cout <<
" - Information on mother / key daughters ..." <<
G4endl;
117 G4cout <<
" Type " << std::setw(12) <<
"Solid-Name" <<
" "
118 << std::setw(3*(6+precVerf)) <<
" local point" <<
" "
119 << std::setw(4+precVerf) <<
"solid-Safety" <<
" "
120 << std::setw(4+precVerf) <<
"solid-Step" <<
" "
121 << std::setw(17) <<
"distance Method "
122 << std::setw(3*(6+precVerf)) <<
" local direction" <<
" "
124 G4cout <<
" Mother " << std::setw(12) << motherSolid->
GetName() <<
" "
125 << std::setw(4+precVerf) << localPoint <<
" "
126 << std::setw(4+precVerf) << motherSafety <<
" "
128 G4cout.precision(oldprec);
147 if ( sampleStep < kInfinity )
150 intersectionPoint = samplePoint + sampleStep * sampleDirection;
151 EInside insideIntPt = sampleSolid->
Inside(intersectionPoint);
152 G4String fType = fId +
"::ComputeStep()";
154 G4String solidResponse =
"-kInside-";
156 { solidResponse =
"-kOutside-"; }
158 { solidResponse =
"-kSurface-"; }
160 if ( fVerbose == 1 || fVerbose > 4 )
162 G4cout <<
" Invoked Inside() for solid: "
164 <<
". Solid replied: " << solidResponse <<
G4endl
165 <<
" For point p: " << intersectionPoint
166 <<
", considered as 'intersection' point." <<
G4endl;
169 G4double safetyIn = -1, safetyOut = -1;
170 G4double newDistIn = -1, newDistOut = -1;
173 safetyIn = sampleSolid->
DistanceToIn(intersectionPoint);
174 newDistIn = sampleSolid->
DistanceToIn(intersectionPoint,
185 std::ostringstream message;
186 message.precision(16);
187 message <<
"Conflicting response from Solid." <<
G4endl
188 <<
" Inaccurate solid DistanceToIn"
190 <<
" Solid gave DistanceToIn = "
191 << sampleStep <<
" yet returns " << solidResponse
192 <<
" for this point !" <<
G4endl
193 <<
" Original Point = " << samplePoint <<
G4endl
194 <<
" Original Direction = " << sampleDirection <<
G4endl
195 <<
" Intersection Point = " << intersectionPoint <<
G4endl
196 <<
" Safety values: " <<
G4endl;
199 message <<
" DistanceToIn(p) = " << safetyIn;
203 message <<
" DistanceToOut(p) = " << safetyOut;
206 message <<
" Solid Parameters: " << *sampleSolid;
214 if( std::max( newDistIn, newDistOut ) <=
217 std::ostringstream message;
218 message <<
"Zero from both Solid DistanceIn and Out(p,v)." <<
G4endl
219 <<
" Identified point for which the solid "
221 <<
" has MAJOR problem: " <<
G4endl
222 <<
" --> Both DistanceToIn(p,v) and DistanceToOut(p,v) "
223 <<
"return Zero, an equivalent value or negative value."
225 <<
" Solid: " << sampleSolid <<
G4endl
226 <<
" Point p= " << intersectionPoint <<
G4endl
227 <<
" Direction v= " << sampleDirection <<
G4endl
228 <<
" DistanceToIn(p,v) = " << newDistIn <<
G4endl
229 <<
" DistanceToOut(p,v,..) = " << newDistOut <<
G4endl
230 <<
" Safety values: " <<
G4endl
231 <<
" DistanceToIn(p) = " << safetyIn <<
G4endl
232 <<
" DistanceToOut(p) = " << safetyOut;
241 static const G4int precVerf= 20;
244 << std::setw(12) << sampleSolid->
GetName() <<
" "
245 << std::setw(4+precVerf) << samplePoint <<
" "
246 << std::setw(4+precVerf) << sampleSafety <<
" "
247 << std::setw(4+precVerf) << sampleStep <<
" "
248 << std::setw(16) <<
"distanceToIn" <<
" "
249 << std::setw(4+precVerf) << localDirection <<
" "
251 G4cout.precision(oldprec);
274 G4bool SuspiciousDaughterDist = ( sampleStep >= motherStep )
275 && ( sampleStep < kInfinity );
277 if( sampleStep >= kInfinity )
281 msg <<
" WARNING - Called with 'infinite' step. " <<
G4endl;
282 msg <<
" Checks have no meaning if daughter step is infinite." <<
G4endl;
283 msg <<
" kInfinity = " << kInfinity / millimeter <<
G4endl;
284 msg <<
" sampleStep = " << sampleStep / millimeter <<
G4endl;
285 msg <<
" sampleStep < kInfinity " << (sampleStep<kInfinity) <<
G4endl;
286 msg <<
" kInfinity - sampleStep " << (kInfinity-sampleStep) / millimeter <<
G4endl;
287 msg <<
" Returning immediately.";
288 G4Exception(
"G4NavigationLogger::CheckDaughterEntryPoint()",
302 G4ThreeVector localExitMotherPos = localPoint+motherStep*localDirection;
308 G4ThreeVector localEntryInDaughter = localPoint+sampleStep*localDirection;
309 EInside insideMother = motherSolid->
Inside( localEntryInDaughter );
311 G4String solidResponse =
"-kInside-";
312 if (insideMother ==
kOutside) { solidResponse =
"-kOutside-"; }
313 else if (insideMother ==
kSurface) { solidResponse =
"-kSurface-"; }
315 G4double distToReEntry = distExitToReEntry + motherStep;
316 G4ThreeVector localReEntryPoint = localPoint+distToReEntry*localDirection;
320 G4bool DaughterEntryIsOutside = SuspiciousDaughterDist
321 && ( (sampleStep * (1.0+eps) < distToReEntry) || (insideMother ==
kOutside ) );
325 G4ThreeVector sampleEntryPoint = samplePoint+sampleStep*sampleDirection;
328 G4double sampleExitDist = sampleStep+sampleCrossingDist;
329 G4ThreeVector sampleExitPoint = samplePoint+sampleExitDist*sampleDirection;
331 G4bool TransitProblem = ( (sampleStep < motherStep)
333 || ( EntryIsMotherExit && (sampleCrossingDist >
kCarTolerance) );
335 if( DaughterEntryIsOutside
337 || (SuspiciousDaughterDist && (fVerbose > 3) ) )
342 if( DaughterEntryIsOutside )
344 msg <<
"WARNING> Intersection distance to Daughter volume is further"
345 <<
" than the distance to boundary." <<
G4endl
346 <<
" It appears that part of the daughter volume is *outside*"
347 <<
" this mother. " <<
G4endl;
348 msg <<
" One of the following checks signaled a problem:" <<
G4endl
349 <<
" -sampleStep (dist to daugh) < mother-exit dist + distance "
350 <<
"to ReEntry point for mother " <<
G4endl
351 <<
" -position of daughter intersection is outside mother volume."
354 else if( TransitProblem )
356 G4double protrusion = sampleExitDist - motherStep;
358 msg <<
"WARNING> Daughter volume extends beyond mother boundary. "
360 if ( ( sampleStep < motherStep )
364 msg <<
" Crossing distance in the daughter causes is to extend"
365 <<
" beyond the mother exit. " <<
G4endl;
366 msg <<
" Length protruding = " << protrusion <<
G4endl;
368 if( EntryIsMotherExit )
371 msg <<
" Intersection distance to Daughter is within "
372 <<
" tolerance of the distance" <<
G4endl;
373 msg <<
" to the mother boundary * and * " <<
G4endl;
374 msg <<
" the crossing distance in the daughter is > tolerance."
380 msg <<
"NearMiss> Intersection to Daughter volume is in extension past the"
381 <<
" current exit point of the mother volume." <<
G4endl;
382 msg <<
" This is not an error - just an unusual occurrence,"
383 <<
" possible in the case of concave volume. " <<
G4endl;
385 msg <<
"---- Information about intersection with daughter, mother: "
387 msg <<
" sampleStep (daughter) = " << sampleStep <<
G4endl
388 <<
" motherStep = " << motherStep <<
G4endl
389 <<
" distToRentry(mother) = " << distToReEntry <<
G4endl
390 <<
" Inside(entry pnt daug): " << solidResponse <<
G4endl
391 <<
" dist across daughter = " << sampleCrossingDist <<
G4endl;
392 msg <<
" Mother Name (Solid) : " << motherSolid->
GetName() <<
G4endl
393 <<
" In local (mother) coordinates: " <<
G4endl
394 <<
" Starting Point = " << localPoint <<
G4endl
395 <<
" Direction = " << localDirection <<
G4endl
396 <<
" Exit Point (mother)= " << localExitMotherPos <<
G4endl
397 <<
" Entry Point (daughter)= " << localPoint+sampleStep*localDirection
399 if( distToReEntry < kInfinity )
401 msg <<
" ReEntry Point (mother)= " << localReEntryPoint <<
G4endl;
405 msg <<
" No ReEntry - track does not encounter mother volume again! "
408 msg <<
" Daughter Name (Solid): " << sampleSolid->
GetName() <<
G4endl
409 <<
" In daughter coordinates: " <<
G4endl
410 <<
" Starting Point = " << samplePoint <<
G4endl
411 <<
" Direction = " << sampleDirection <<
G4endl
412 <<
" Entry Point (daughter)= " << sampleEntryPoint
414 msg <<
" Description of mother solid: " <<
G4endl
416 <<
" Description of daughter solid: " <<
G4endl
417 << *sampleSolid <<
G4endl;
418 G4String fType = fId +
"::ComputeStep()";
420 if( DaughterEntryIsOutside || TransitProblem )
427 <<
" -- Checked distance of Entry to daughter vs exit of mother"
446 if ( fVerbose == 1 || fVerbose > 4 )
449 << std::setw(15) << motherSafety <<
" "
450 << std::setw(15) << motherStep <<
" " << localPoint <<
" - "
454 if( ( motherStep < 0.0 ) || ( motherStep >= kInfinity) )
456 G4String fType = fId +
"::ComputeStep()";
459 std::ostringstream message;
460 message <<
"Current point is outside the current solid !" <<
G4endl
461 <<
" Problem in Navigation" <<
G4endl
462 <<
" Point (local coordinates): "
464 <<
" Local Direction: " << localDirection <<
G4endl
465 <<
" Solid: " << motherSolid->
GetName();
468 G4cout.precision(oldPrOut);
469 G4cerr.precision(oldPrErr);
473 static const G4int precVerf = 20;
475 G4cout <<
" Mother " << std::setw(12) << motherSolid->
GetName() <<
" "
476 << std::setw(4+precVerf) << localPoint <<
" "
477 << std::setw(4+precVerf) << motherSafety <<
" "
478 << std::setw(4+precVerf) << motherStep <<
" "
479 << std::setw(16) <<
"distanceToOut" <<
" "
480 << std::setw(4+precVerf) << localDirection <<
" "
482 G4cout.precision(oldprec);
499 banner =
static_cast<G4int>(isMotherVolume);
503 G4String volumeType = isMotherVolume ?
" Mother " :
"Daughter";
506 G4cout <<
"************** " << fId <<
"::ComputeSafety() ****************"
509 << std::setw(15) <<
"Safety/mm" <<
" "
510 << std::setw(52) <<
"Position (local coordinates)"
514 << std::setw(15) << safety <<
" " << point <<
" - "
534 << std::setw(15) << sampleSafety <<
" ";
537 G4cout << std::setw(15) << sampleStep <<
" ";
541 G4cout << std::setw(15) <<
"Not-Available" <<
" ";
543 G4cout << samplePoint <<
" - "
547 G4cout <<
" dir= " << sampleDirection;
550 G4cout.precision(oldPrec);
565 const char* msg )
const
568 G4bool badLength = ( std::fabs ( normMag2 - 1.0 ) > CLHEP::perMillion );
572 G4double normMag = std::sqrt(normMag2);
574 message.precision(10);
575 message <<
"============================================================"
577 message <<
" WARNING> Normal is not a unit vector. "
578 <<
" - but |normal| = " << normMag
579 <<
" - and |normal|^2 = " << normMag2 <<
G4endl
580 <<
" which differ from 1.0 by: " <<
G4endl
581 <<
" |normal|-1 = " << normMag - 1.0
582 <<
" and |normal|^2 - 1 = " << normMag2 - 1.0 <<
G4endl
583 <<
" n = " << unitNormal <<
G4endl;
584 message <<
" Info string: " << msg <<
G4endl;
585 message <<
"============================================================"
588 message.precision(16);
590 message <<
" Information on call to DistanceToOut: " <<
G4endl;
591 message <<
" Position = " << localPoint <<
G4endl
592 <<
" Direction = " << localDirection <<
G4endl;
593 message <<
" Obtained> distance = " << step <<
G4endl;
594 message <<
" > Exit position = " << localPoint+step*localDirection
596 message <<
" Parameters of solid: " <<
G4endl;
598 message <<
"============================================================";
600 G4String fMethod = fId +
"::ComputeStep()";
615 const char* msg )
const
618 G4bool badLength = ( std::fabs ( normMag2 - 1.0 ) > CLHEP::perMillion );
622 G4double normMag = std::sqrt(normMag2);
624 message.precision(10);
625 message <<
"============================================================"
627 message <<
" WARNING> Rotated n(ormal) is not a unit vector. " <<
G4endl
628 <<
" |normal| = " << normMag
629 <<
" and |normal|^2 = " << normMag2 <<
G4endl
630 <<
" Diff from 1.0: " <<
G4endl
631 <<
" |normal|-1 = " << normMag - 1.0
632 <<
" and |normal|^2 - 1 = " << normMag2 - 1.0 <<
G4endl;
633 message <<
" Rotated n = (" << rotatedNormal.
x() <<
"," << rotatedNormal.
y() <<
","
634 << rotatedNormal.
z() <<
")" <<
G4endl;
635 message <<
" Original n = (" << originalNormal.
x() <<
"," << originalNormal.
y() <<
","
636 << originalNormal.
z() <<
")" <<
G4endl;
637 message <<
" Info string: " << msg <<
G4endl;
638 message <<
"============================================================"
641 message.precision(16);
643 message <<
" Information on RotationMatrix : " <<
G4endl;
644 message <<
" Original: " <<
G4endl;
645 message << rotationM <<
G4endl;
646 message <<
" Inverse (used in transformation): " <<
G4endl;
648 message <<
"============================================================";
650 G4String fMethod = fId +
"::ComputeStep()";
671 const G4VSolid* solid = logicalVol !=
nullptr
674 G4String fMethod = fId +
"::ComputeStep()";
676 if( solid ==
nullptr )
679 "Erroneous call to ReportOutsideMother: no Solid is available");
698 && ( distToOut < 0.0 || distToOut >= kInfinity ) )
703 msg1 <<
" Dangerous inconsistency in response of solid." <<
G4endl
706 msg1 <<
" Mother volume gives safety > 0 despite being called for *Outside* point "
708 <<
" Location = " << localPoint <<
G4endl
709 <<
" Direction= " << localDirection <<
G4endl
710 <<
" - Safety (Isotropic d) = " << safetyToOut <<
G4endl
711 <<
" - Intersection Distance= " << distToOut <<
G4endl
725 if( fReportSoftWarnings )
727 msg <<
" Warning> DistanceToOut(p,v): "
728 <<
"Distance from surface is not rounded to zero" <<
G4endl;
740 msg <<
"============================================================"
742 msg <<
" WARNING> Current Point appears to be Outside mother volume !! "
744 msg <<
" Response of DistanceToOut was negative or kInfinity"
745 <<
" when called in " << fMethod <<
G4endl;
752 if( triggerDist <= 0.0 )
755 fMinTriggerDistance );
759 ? ( safetyToIn > triggerDist )
760 : ( safetyToOut > triggerDist );
768 G4Exception( fMethod,
"GeomNav0003", exceptionType, msg);
781 G4String fMethod = fId +
"::ComputeStep()";
784 const G4VSolid* solid = logicalVol !=
nullptr
786 if( solid ==
nullptr )
788 os <<
" ERROR> Solid is not available. Logical Volume = "
789 << logicalVol << std::endl;
809 const G4ThreeVector PointPlusDir = localPoint + epsilonDist * localDirection;
810 const G4ThreeVector PointMinusDir = localPoint - epsilonDist * localDirection;
811 const G4ThreeVector PointPlusNorm = localPoint + epsilonDist * exitNormal;
812 const G4ThreeVector PointMinusNorm = localPoint - epsilonDist * exitNormal;
820 os <<
" Current physical volume = " << physical->
GetName() <<
G4endl;
821 os <<
" Position (loc) = " << localPoint <<
G4endl
822 <<
" Direction (dir) = " << localDirection <<
G4endl;
823 os <<
" For confirmation:" <<
G4endl;
824 os <<
" Response of DistanceToOut (loc, +dir)= " << distToOut <<
G4endl;
825 os <<
" Response of DistanceToOut (loc, -dir)= " << distToOutNeg <<
G4endl;
827 os <<
" Inside responds = " << inSolid <<
" , ie: ";
830 os <<
" Outside -- a problem, as observed in " << fMethod <<
G4endl;
834 os <<
" Surface -- unexpected / inconsistent response ! " <<
G4endl;
838 os <<
" Inside -- unexpected / inconsistent response ! " <<
G4endl;
840 os <<
" Obtain safety(ToIn) = " << safetyToIn <<
G4endl;
841 os <<
" Obtain safety(ToOut) = " << safetyToOut <<
G4endl;
842 os <<
" Response of DistanceToIn (loc, +dir)= " << distToInPos <<
G4endl;
843 os <<
" Response of DistanceToIn (loc, -dir)= " << distToInNeg <<
G4endl;
845 os <<
" Exit Normal at loc = " << exitNormal <<
G4endl;
846 os <<
" Dir . Normal = " << exitNormal.
dot( localDirection );
849 os <<
" Checking points moved from position by distance/direction." <<
G4endl
850 <<
" Solid responses: " <<
G4endl
851 <<
" +eps in direction : "
853 <<
" +eps in Normal : "
855 <<
" -eps in direction : "
857 <<
" -eps in Normal : "
860 os <<
" Parameters of solid: " <<
G4endl;
862 os <<
"============================================================";
const G4double kCarTolerance
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
CLHEP::HepRotation G4RotationMatrix
CLHEP::Hep3Vector G4ThreeVector
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
double dot(const Hep3Vector &) const
HepRotation inverse() const
static G4GeometryTolerance * GetInstance()
G4LogicalVolume represents a leaf node or unpositioned subtree in the geometry hierarchy....
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
G4VPhysicalVolume is an abstract base class for the representation of a positioned volume....
G4LogicalVolume * GetLogicalVolume() const
const G4String & GetName() const
G4VSolid is an abstract base class for solids, physical shapes that can be tracked through....
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]