37 #include <CLHEP/Units/SystemOfUnits.h>
46 : fId(id), fVerbose(0), fMinTriggerDistance(
DBL_MAX ), fReportSoftWarnings( false )
69 G4cout <<
"*************** " << fType <<
" *****************" <<
G4endl
71 << std::setw(15) <<
"Safety/mm" <<
" "
72 << std::setw(15) <<
"Distance/mm" <<
" "
73 << std::setw(52) <<
"Position (local coordinates)"
76 << std::setw(15) << motherSafety /
millimeter <<
" "
77 << std::setw(15) <<
"N/C" <<
" " << localPoint <<
" - "
81 if ( motherSafety < 0.0 )
83 std::ostringstream message;
84 message <<
"Negative Safety In Voxel Navigation !" <<
G4endl
85 <<
" Current solid " << motherSolid->
GetName()
87 <<
" for the current (local) point " << localPoint;
88 message <<
" Solid info: " << *motherSolid <<
G4endl;
93 std::ostringstream message;
94 message <<
"Point is outside Current Volume - " <<
G4endl
96 <<
" is outside current volume '" << motherPhysical->
GetName()
99 message <<
" Estimated isotropic distance to solid (distToIn)= "
100 << estDistToSolid <<
G4endl;
101 if( estDistToSolid > 100.0 * motherSolid->
GetTolerance() )
103 message <<
" Solid info: " << *motherSolid <<
G4endl;
105 "Point is far outside Current Volume !" );
110 "Point is a little outside Current Volume.");
118 static const G4int precVerf= 16;
120 G4cout <<
" - Information on mother / key daughters ..." <<
G4endl;
121 G4cout <<
" Type " << std::setw(12) <<
"Solid-Name" <<
" "
122 << std::setw(3*(6+precVerf)) <<
" local point" <<
" "
123 << std::setw(4+precVerf) <<
"solid-Safety" <<
" "
124 << std::setw(4+precVerf) <<
"solid-Step" <<
" "
125 << std::setw(17) <<
"distance Method "
126 << std::setw(3*(6+precVerf)) <<
" local direction" <<
" "
128 G4cout <<
" Mother " << std::setw(12) << motherSolid->
GetName() <<
" "
129 << std::setw(4+precVerf) << localPoint <<
" "
130 << std::setw(4+precVerf) << motherSafety <<
" "
132 G4cout.precision(oldprec);
154 intersectionPoint= samplePoint + sampleStep * sampleDirection;
158 G4String solidResponse =
"-kInside-";
160 { solidResponse =
"-kOutside-"; }
162 { solidResponse =
"-kSurface-"; }
166 G4cout <<
" Invoked Inside() for solid: "
168 <<
". Solid replied: " << solidResponse <<
G4endl
169 <<
" For point p: " << intersectionPoint
170 <<
", considered as 'intersection' point." <<
G4endl;
173 G4double safetyIn= -1, safetyOut= -1;
174 G4double newDistIn= -1, newDistOut= -1;
189 std::ostringstream message;
190 message.precision(16);
191 message <<
"Conflicting response from Solid." <<
G4endl
192 <<
" Inaccurate solid DistanceToIn"
194 <<
" Solid gave DistanceToIn = "
195 << sampleStep <<
" yet returns " << solidResponse
196 <<
" for this point !" <<
G4endl
197 <<
" Original Point = " << samplePoint <<
G4endl
198 <<
" Original Direction = " << sampleDirection <<
G4endl
199 <<
" Intersection Point = " << intersectionPoint <<
G4endl
200 <<
" Safety values: " <<
G4endl;
203 message <<
" DistanceToIn(p) = " << safetyIn;
207 message <<
" DistanceToOut(p) = " << safetyOut;
210 message <<
" Solid Parameters: " << *sampleSolid;
218 if(
std::max( newDistIn, newDistOut ) <=
221 std::ostringstream message;
222 message <<
"Zero from both Solid DistanceIn and Out(p,v)." <<
G4endl
223 <<
" Identified point for which the solid "
225 <<
" has MAJOR problem: " <<
G4endl
226 <<
" --> Both DistanceToIn(p,v) and DistanceToOut(p,v) "
227 <<
"return Zero, an equivalent value or negative value."
229 <<
" Solid: " << sampleSolid <<
G4endl
230 <<
" Point p= " << intersectionPoint <<
G4endl
231 <<
" Direction v= " << sampleDirection <<
G4endl
232 <<
" DistanceToIn(p,v) = " << newDistIn <<
G4endl
233 <<
" DistanceToOut(p,v,..) = " << newDistOut <<
G4endl
234 <<
" Safety values: " <<
G4endl
235 <<
" DistanceToIn(p) = " << safetyIn <<
G4endl
236 <<
" DistanceToOut(p) = " << safetyOut;
245 static const G4int precVerf= 20;
248 << std::setw(12) << sampleSolid->
GetName() <<
" "
249 << std::setw(4+precVerf) << samplePoint <<
" "
250 << std::setw(4+precVerf) << sampleSafety <<
" "
251 << std::setw(4+precVerf) << sampleStep <<
" "
252 << std::setw(16) <<
"distanceToIn" <<
" "
253 << std::setw(4+precVerf) << localDirection <<
" "
255 G4cout.precision(oldprec);
278 G4bool SuspiciousDaughterDist = ( sampleStep >= motherStep )
285 msg <<
" WARNING - Called with 'infinite' step. " <<
G4endl;
286 msg <<
" Checks have no meaning if daughter step is infinite." <<
G4endl;
289 msg <<
" sampleStep < kInfinity " << (sampleStep<
kInfinity) << G4endl;
291 msg <<
" Returning immediately.";
292 G4Exception(
"G4NavigationLogger::CheckDaughterEntryPoint()",
306 G4ThreeVector localExitMotherPos= localPoint+motherStep*localDirection;
312 G4ThreeVector localEntryInDaughter = localPoint+sampleStep*localDirection;
313 EInside insideMother= motherSolid->
Inside( localEntryInDaughter );
315 G4String solidResponse =
"-kInside-";
316 if (insideMother ==
kOutside) { solidResponse =
"-kOutside-"; }
317 else if (insideMother ==
kSurface) { solidResponse =
"-kSurface-"; }
319 G4double distToReEntry = distExitToReEntry + motherStep;
320 G4ThreeVector localReEntryPoint = localPoint+distToReEntry*localDirection;
323 G4bool DaughterEntryIsOutside = SuspiciousDaughterDist
324 && ( (sampleStep < distToReEntry) || (insideMother ==
kOutside ) );
325 G4bool EntryIsMotherExit = std::fabs(sampleStep-motherStep) < kCarTolerance;
328 G4ThreeVector sampleEntryPoint= samplePoint+sampleStep*sampleDirection;
331 G4double sampleExitDist = sampleStep+sampleCrossingDist;
332 G4ThreeVector sampleExitPoint= samplePoint+sampleExitDist*sampleDirection;
334 G4bool TransitProblem = ( (sampleStep < motherStep)
335 && (sampleExitDist > motherStep + kCarTolerance) )
336 || ( EntryIsMotherExit && (sampleCrossingDist > kCarTolerance) );
338 if( DaughterEntryIsOutside
340 || (SuspiciousDaughterDist && (
fVerbose > 3) ) )
345 if( DaughterEntryIsOutside )
347 msg <<
"WARNING> Intersection distance to Daughter volume is further"
348 <<
" than the distance to boundary." <<
G4endl
349 <<
" It appears that part of the daughter volume is *outside*"
350 <<
" this mother. " <<
G4endl;
351 msg <<
" One of the following checks signaled a problem:" << G4endl
352 <<
" -sampleStep (dist to daugh) < mother-exit dist + distance "
353 <<
"to ReEntry point for mother " << G4endl
354 <<
" -position of daughter intersection is outside mother volume."
357 else if( TransitProblem )
359 G4double protrusion = sampleExitDist - motherStep;
361 msg <<
"WARNING> Daughter volume extends beyond mother boundary. "
363 if ( ( sampleStep < motherStep )
364 && (sampleExitDist > motherStep + kCarTolerance ) )
367 msg <<
" Crossing distance in the daughter causes is to extend"
368 <<
" beyond the mother exit. " <<
G4endl;
369 msg <<
" Length protruding = " << protrusion <<
G4endl;
371 if( EntryIsMotherExit )
374 msg <<
" Intersection distance to Daughter is within "
375 <<
" tolerance of the distance" <<
G4endl;
376 msg <<
" to the mother boundary * and * " <<
G4endl;
377 msg <<
" the crossing distance in the daughter is > tolerance."
383 msg <<
"NearMiss> Intersection to Daughter volume is in extension past the"
384 <<
" current exit point of the mother volume." <<
G4endl;
385 msg <<
" This is not an error - just an unusual occurence,"
386 <<
" possible in the case of concave volume. " <<
G4endl;
388 msg <<
"---- Information about intersection with daughter, mother: "
390 msg <<
" sampleStep (daughter) = " << sampleStep << G4endl
391 <<
" motherStep = " << motherStep << G4endl
392 <<
" distToRentry(mother) = " << distToReEntry << G4endl
393 <<
" Inside(entry pnt daug): " << solidResponse << G4endl
394 <<
" dist across daughter = " << sampleCrossingDist <<
G4endl;
395 msg <<
" Mother Name (Solid) : " << motherSolid->
GetName() << G4endl
396 <<
" In local (mother) coordinates: " << G4endl
397 <<
" Starting Point = " << localPoint << G4endl
398 <<
" Direction = " << localDirection << G4endl
399 <<
" Exit Point (mother)= " << localExitMotherPos << G4endl
400 <<
" Entry Point (daughter)= " << localPoint+sampleStep*localDirection
404 msg <<
" ReEntry Point (mother)= " << localReEntryPoint <<
G4endl;
408 msg <<
" No ReEntry - track does not encounter mother volume again! "
411 msg <<
" Daughter Name (Solid): " << sampleSolid->
GetName() << G4endl
412 <<
" In daughter coordinates: " << G4endl
413 <<
" Starting Point = " << samplePoint << G4endl
414 <<
" Direction = " << sampleDirection << G4endl
415 <<
" Entry Point (daughter)= " << sampleEntryPoint
417 msg <<
" Description of mother solid: " << G4endl
418 << *motherSolid << G4endl
419 <<
" Description of daughter solid: " << G4endl
420 << *sampleSolid <<
G4endl;
423 if( DaughterEntryIsOutside || TransitProblem )
430 <<
" -- Checked distance of Entry to daughter vs exit of mother"
452 << std::setw(15) << motherSafety <<
" "
453 << std::setw(15) << motherStep <<
" " << localPoint <<
" - "
457 if( ( motherStep < 0.0 ) || ( motherStep >=
kInfinity) )
462 std::ostringstream message;
463 message <<
"Current point is outside the current solid !" <<
G4endl
464 <<
" Problem in Navigation" <<
G4endl
465 <<
" Point (local coordinates): "
467 <<
" Local Direction: " << localDirection <<
G4endl
468 <<
" Solid: " << motherSolid->
GetName();
471 G4cout.precision(oldPrOut);
472 G4cerr.precision(oldPrErr);
476 static const G4int precVerf= 20;
478 G4cout <<
" Mother " << std::setw(12) << motherSolid->
GetName() <<
" "
479 << std::setw(4+precVerf) << localPoint <<
" "
480 << std::setw(4+precVerf) << motherSafety <<
" "
481 << std::setw(4+precVerf) << motherStep <<
" "
482 << std::setw(16) <<
"distanceToOut" <<
" "
483 << std::setw(4+precVerf) << localDirection <<
" "
485 G4cout.precision(oldprec);
502 banner = isMotherVolume;
506 G4String volumeType = isMotherVolume ?
" Mother " :
"Daughter";
509 G4cout <<
"************** " <<
fId <<
"::ComputeSafety() ****************"
512 << std::setw(15) <<
"Safety/mm" <<
" "
513 << std::setw(52) <<
"Position (local coordinates)"
517 << std::setw(15) << safety <<
" " << point <<
" - "
537 << std::setw(15) << sampleSafety <<
" ";
540 G4cout << std::setw(15) << sampleStep <<
" ";
544 G4cout << std::setw(15) <<
"Not-Available" <<
" ";
546 G4cout << samplePoint <<
" - "
550 G4cout <<
" dir= " << sampleDirection;
553 G4cout.precision(oldPrec);
568 const char* msg )
const
570 G4double normMag2 = unitNormal.mag2();
575 G4double normMag= std::sqrt(normMag2);
577 message.precision(10);
578 message <<
"============================================================"
580 message <<
" WARNING> Normal is not a unit vector. "
581 <<
" - but |normal| = " << normMag
582 <<
" - and |normal|^2 = " << normMag2 << G4endl
583 <<
" which differ from 1.0 by: " << G4endl
584 <<
" |normal|-1 = " << normMag - 1.0
585 <<
" and |normal|^2 - 1 = " << normMag2 - 1.0 << G4endl
586 <<
" n = " << unitNormal <<
G4endl;
587 message <<
" Info string: " << msg <<
G4endl;
588 message <<
"============================================================"
591 message.precision(16);
593 message <<
" Information on call to DistanceToOut: " <<
G4endl;
594 message <<
" Position = " << localPoint << G4endl
595 <<
" Direction = " << localDirection <<
G4endl;
596 message <<
" Obtained> distance = " << step <<
G4endl;
597 message <<
" > Exit position = " << localPoint+step*localDirection
599 message <<
" Parameters of solid: " <<
G4endl;
601 message <<
"============================================================";
618 const char* msg )
const
620 G4double normMag2 = rotatedNormal.mag2();
625 G4double normMag= std::sqrt(normMag2);
627 message.precision(10);
628 message <<
"============================================================"
630 message <<
" WARNING> Rotated n(ormal) is not a unit vector. " << G4endl
631 <<
" |normal| = " << normMag
632 <<
" and |normal|^2 = " << normMag2 << G4endl
633 <<
" Diff from 1.0: " << G4endl
634 <<
" |normal|-1 = " << normMag - 1.0
635 <<
" and |normal|^2 - 1 = " << normMag2 - 1.0 <<
G4endl;
636 message <<
" Rotated n = (" << rotatedNormal.x() <<
"," << rotatedNormal.y() <<
","
637 << rotatedNormal.z() <<
")" <<
G4endl;
638 message <<
" Original n = (" << originalNormal.x() <<
"," << originalNormal.y() <<
","
639 << originalNormal.z() <<
")" <<
G4endl;
640 message <<
" Info string: " << msg <<
G4endl;
641 message <<
"============================================================"
644 message.precision(16);
646 message <<
" Information on RotationMatrix : " <<
G4endl;
647 message <<
" Original: " <<
G4endl;
648 message << rotationM <<
G4endl;
649 message <<
" Inverse (used in transformation): " <<
G4endl;
650 message << rotationM.inverse() <<
G4endl;
651 message <<
"============================================================";
682 "Erroneous call to ReportOutsideMother: no Solid is available");
703 if( safetyToOut > kCarTolerance
704 && ( distToOut < 0.0 || distToOut >=
kInfinity ) )
709 msg1 <<
" Dangerous inconsistency in response of solid." <<
G4endl
712 msg1 <<
" Mother volume gives safety > 0 despite being called for *Outside* point "
714 <<
" Location = " << localPoint <<
G4endl
715 <<
" Direction= " << localDirection <<
G4endl
716 <<
" - Safety (Isotropic d) = " << safetyToOut <<
G4endl
717 <<
" - Intersection Distance= " << distToOut <<
G4endl
725 if( std::fabs(distToOut) < kCarTolerance && std::fabs(distToInPos) < kCarTolerance )
735 if( std::fabs(distToOut) < kCarTolerance )
742 msg <<
" Warning> DistanceToOut(p,v): Distance from surface is not rounded to zero" <<
G4endl;
753 msg <<
"============================================================" <<
G4endl;
754 msg <<
" WARNING> Current Point appears to be Outside mother volume !! " <<
G4endl;
755 msg <<
" Response of DistanceToOut was negative or kInfinity when called in "
763 if( triggerDist <= 0.0 ) {
765 triggerDist =
std::max ( 1.0e+6 * kCarTolerance,
770 ? ( safetyToIn > triggerDist )
771 : ( safetyToOut > triggerDist );
779 G4Exception( fMethod,
"GeomNav0003", exceptionType, msg);
792 G4String fMethod =
fId +
"::ComputeStep() / output from G4NavigatorLogger::ReportVolumeAndIntersection";
799 os <<
" ERROR> Solid is not available. Logical Volume = " << logicalVol << std::endl;
818 const G4double epsilonDist = 1000.0 * kCarTolerance;
819 const G4ThreeVector PointPlusDir = localPoint + epsilonDist * localDirection;
820 const G4ThreeVector PointMinusDir = localPoint - epsilonDist * localDirection;
821 const G4ThreeVector PointPlusNorm = localPoint + epsilonDist * exitNormal;
822 const G4ThreeVector PointMinusNorm = localPoint - epsilonDist * exitNormal;
830 os <<
" Current physical volume = " << physical->
GetName() <<
G4endl;
831 os <<
" Position (loc) = " << localPoint <<
G4endl
832 <<
" Direction (dir) = " << localDirection <<
G4endl;
833 os <<
" For confirmation:" <<
G4endl;
834 os <<
" Response of DistanceToOut (loc, +dir)= " << distToOut <<
G4endl;
835 os <<
" Response of DistanceToOut (loc, -dir)= " << distToOutNeg <<
G4endl;
837 os <<
" Inside responds = " << inSolid <<
" , ie: ";
839 os <<
" Outside -- a problem, as observed in " << fMethod <<
G4endl;
841 os <<
" Surface -- unexpected / inconsistent response ! " <<
G4endl;
843 os <<
" Inside -- unexpected / inconsistent response ! " <<
G4endl;
845 os <<
" Obtain safety(ToIn) = " << safetyToIn <<
G4endl;
846 os <<
" Obtain safety(ToOut) = " << safetyToOut <<
G4endl;
847 os <<
" Response of DistanceToIn (loc, +dir)= " << distToInPos <<
G4endl;
848 os <<
" Response of DistanceToIn (loc, -dir)= " << distToInNeg <<
G4endl;
850 os <<
" Exit Normal at loc = " << exitNormal <<
G4endl;
851 os <<
" Dir . Normal = " << exitNormal.dot( localDirection );
854 os <<
" Checking points moved from position by distance/dir. Solid responses: " << G4endl
860 os <<
" Parameters of solid: " <<
G4endl;
862 os <<
"============================================================";
void AlongComputeStepLog(const G4VSolid *sampleSolid, const G4ThreeVector &samplePoint, const G4ThreeVector &sampleDirection, const G4ThreeVector &localDirection, G4double sampleSafety, G4double sampleStep) const
void PrintDaughterLog(const G4VSolid *sampleSolid, const G4ThreeVector &samplePoint, G4double sampleSafety, G4bool onlySafety, const G4ThreeVector &sampleDirection, G4double sampleStep) const
static const G4double kInfinity
std::ostringstream G4ExceptionDescription
CLHEP::Hep3Vector G4ThreeVector
CLHEP::HepRotation G4RotationMatrix
G4double GetTolerance() const
virtual G4GeometryType GetEntityType() const =0
G4NavigationLogger(const G4String &id)
void ReportOutsideMother(const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, const G4VPhysicalVolume *motherPV, G4double tDist=30.0 *CLHEP::cm) const
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
virtual EInside Inside(const G4ThreeVector &p) const =0
void ReportVolumeAndIntersection(std::ostream &ostrm, const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, const G4VPhysicalVolume *physical) const
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const =0
G4bool CheckAndReportBadNormal(const G4ThreeVector &unitNormal, const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, G4double step, const G4VSolid *solid, const char *msg) const
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
const G4String EInsideNames[3]
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4bool fReportSoftWarnings
static const double perMillion
G4LogicalVolume * GetLogicalVolume() const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
void ComputeSafetyLog(const G4VSolid *solid, const G4ThreeVector &point, G4double safety, G4bool isMotherVolume, G4int banner=-1) const
void PreComputeStepLog(const G4VPhysicalVolume *motherPhysical, G4double motherSafety, const G4ThreeVector &localPoint) const
static const double millimeter
void PostComputeStepLog(const G4VSolid *motherSolid, const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, G4double motherStep, G4double motherSafety) const
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
G4double fMinTriggerDistance
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const =0
static G4GeometryTolerance * GetInstance()
G4VSolid * GetSolid() const
G4GLOB_DLL std::ostream G4cerr