Geant4  10.01.p02
G4NavigationLogger.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4NavigationLogger.cc 90836 2015-06-10 09:31:06Z gcosmo $
28 //
29 //
30 // class G4NavigationLogger Implementation
31 //
32 // Author: G.Cosmo, 2010
33 //
34 // --------------------------------------------------------------------
35 
36 #include <iomanip>
37 #include <CLHEP/Units/SystemOfUnits.h>
38 
39 #include "G4NavigationLogger.hh"
40 #include "G4GeometryTolerance.hh"
41 
42 // const double millimeter = CLHEP::Units::millimeter;
43 using CLHEP::millimeter;
44 
46  : fId(id), fVerbose(0), fMinTriggerDistance( DBL_MAX ), fReportSoftWarnings( false )
47 {
48 }
49 
51 {
52 }
53 
54 // ********************************************************************
55 // PreComputeStepLog
56 // ********************************************************************
57 //
58 void
60  G4double motherSafety,
61  const G4ThreeVector& localPoint) const
62 {
63  G4VSolid* motherSolid = motherPhysical->GetLogicalVolume()->GetSolid();
64  G4String fType = fId + "::ComputeStep()";
65  // const double millimeter = CLHEP::millimeter;
66 
67  if ( fVerbose == 1 || fVerbose > 4 )
68  {
69  G4cout << "*************** " << fType << " *****************" << G4endl
70  << " VolType "
71  << std::setw(15) << "Safety/mm" << " "
72  << std::setw(15) << "Distance/mm" << " "
73  << std::setw(52) << "Position (local coordinates)"
74  << " - Solid" << G4endl;
75  G4cout << " Mother "
76  << std::setw(15) << motherSafety / millimeter << " "
77  << std::setw(15) << "N/C" << " " << localPoint << " - "
78  << motherSolid->GetEntityType() << ": " << motherSolid->GetName()
79  << G4endl;
80  }
81  if ( motherSafety < 0.0 )
82  {
83  std::ostringstream message;
84  message << "Negative Safety In Voxel Navigation !" << G4endl
85  << " Current solid " << motherSolid->GetName()
86  << " gave negative safety: " << motherSafety / millimeter << G4endl
87  << " for the current (local) point " << localPoint;
88  message << " Solid info: " << *motherSolid << G4endl;
89  G4Exception(fType, "GeomNav0003", FatalException, message);
90  }
91  if( motherSolid->Inside(localPoint)==kOutside )
92  {
93  std::ostringstream message;
94  message << "Point is outside Current Volume - " << G4endl
95  << " Point " << localPoint / millimeter
96  << " is outside current volume '" << motherPhysical->GetName()
97  << "'" << G4endl;
98  G4double estDistToSolid= motherSolid->DistanceToIn(localPoint);
99  message << " Estimated isotropic distance to solid (distToIn)= "
100  << estDistToSolid << G4endl;
101  if( estDistToSolid > 100.0 * motherSolid->GetTolerance() )
102  {
103  message << " Solid info: " << *motherSolid << G4endl;
104  G4Exception(fType, "GeomNav0003", JustWarning, message,
105  "Point is far outside Current Volume !" );
106  }
107  else
108  {
109  G4Exception(fType, "GeomNav1001", JustWarning, message,
110  "Point is a little outside Current Volume.");
111  }
112  }
113 
114  // Verification / verbosity
115  //
116  if ( fVerbose > 1 )
117  {
118  static const G4int precVerf= 16; // Precision
119  G4int oldprec = G4cout.precision(precVerf);
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" << " "
127  << G4endl;
128  G4cout << " Mother " << std::setw(12) << motherSolid->GetName() << " "
129  << std::setw(4+precVerf) << localPoint << " "
130  << std::setw(4+precVerf) << motherSafety << " "
131  << G4endl;
132  G4cout.precision(oldprec);
133  }
134 }
135 
136 // ********************************************************************
137 // AlongComputeStepLog
138 // ********************************************************************
139 //
140 void
142  const G4ThreeVector& samplePoint,
143  const G4ThreeVector& sampleDirection,
144  const G4ThreeVector& localDirection,
145  G4double sampleSafety,
146  G4double sampleStep) const
147 {
148  // Check to see that the resulting point is indeed in/on volume.
149  // This check could eventually be made only for successful candidate.
150 
151  if ( sampleStep < kInfinity )
152  {
153  G4ThreeVector intersectionPoint;
154  intersectionPoint= samplePoint + sampleStep * sampleDirection;
155  EInside insideIntPt= sampleSolid->Inside(intersectionPoint);
156  G4String fType = fId + "::ComputeStep()";
157 
158  G4String solidResponse = "-kInside-";
159  if (insideIntPt == kOutside)
160  { solidResponse = "-kOutside-"; }
161  else if (insideIntPt == kSurface)
162  { solidResponse = "-kSurface-"; }
163 
164  if ( fVerbose == 1 || fVerbose > 4 )
165  {
166  G4cout << " Invoked Inside() for solid: "
167  << sampleSolid->GetName()
168  << ". Solid replied: " << solidResponse << G4endl
169  << " For point p: " << intersectionPoint
170  << ", considered as 'intersection' point." << G4endl;
171  }
172 
173  G4double safetyIn= -1, safetyOut= -1; // Set to invalid values
174  G4double newDistIn= -1, newDistOut= -1;
175  if( insideIntPt != kInside )
176  {
177  safetyIn= sampleSolid->DistanceToIn(intersectionPoint);
178  newDistIn= sampleSolid->DistanceToIn(intersectionPoint,
179  sampleDirection);
180  }
181  if( insideIntPt != kOutside )
182  {
183  safetyOut= sampleSolid->DistanceToOut(intersectionPoint);
184  newDistOut= sampleSolid->DistanceToOut(intersectionPoint,
185  sampleDirection);
186  }
187  if( insideIntPt != kSurface )
188  {
189  std::ostringstream message;
190  message.precision(16);
191  message << "Conflicting response from Solid." << G4endl
192  << " Inaccurate solid DistanceToIn"
193  << " for solid " << sampleSolid->GetName() << G4endl
194  << " Solid gave DistanceToIn = "
195  << sampleStep << " yet returns " << solidResponse
196  << " for this point !" << G4endl
197  << " Point = " << intersectionPoint << G4endl
198  << " Safety values: " << G4endl;
199  if ( insideIntPt != kInside )
200  {
201  message << " DistanceToIn(p) = " << safetyIn;
202  }
203  if ( insideIntPt != kOutside )
204  {
205  message << " DistanceToOut(p) = " << safetyOut;
206  }
207  message << G4endl;
208  message << " Solid Parameters: " << *sampleSolid;
209  G4Exception(fType, "GeomNav1001", JustWarning, message);
210  }
211  else
212  {
213  // If it is on the surface, *ensure* that either DistanceToIn
214  // or DistanceToOut returns a finite value ( >= Tolerance).
215  //
216  if( std::max( newDistIn, newDistOut ) <=
217  G4GeometryTolerance::GetInstance()->GetSurfaceTolerance() )
218  {
219  std::ostringstream message;
220  message << "Zero from both Solid DistanceIn and Out(p,v)." << G4endl
221  << " Identified point for which the solid "
222  << sampleSolid->GetName() << G4endl
223  << " has MAJOR problem: " << G4endl
224  << " --> Both DistanceToIn(p,v) and DistanceToOut(p,v) "
225  << "return Zero, an equivalent value or negative value."
226  << G4endl
227  << " Solid: " << sampleSolid << G4endl
228  << " Point p= " << intersectionPoint << G4endl
229  << " Direction v= " << sampleDirection << G4endl
230  << " DistanceToIn(p,v) = " << newDistIn << G4endl
231  << " DistanceToOut(p,v,..) = " << newDistOut << G4endl
232  << " Safety values: " << G4endl
233  << " DistanceToIn(p) = " << safetyIn << G4endl
234  << " DistanceToOut(p) = " << safetyOut;
235  G4Exception(fType, "GeomNav0003", FatalException, message);
236  }
237  }
238 
239  // Verification / verbosity
240  //
241  if ( fVerbose > 1 )
242  {
243  static const G4int precVerf= 20; // Precision
244  G4int oldprec = G4cout.precision(precVerf);
245  G4cout << "Daughter "
246  << std::setw(12) << sampleSolid->GetName() << " "
247  << std::setw(4+precVerf) << samplePoint << " "
248  << std::setw(4+precVerf) << sampleSafety << " "
249  << std::setw(4+precVerf) << sampleStep << " "
250  << std::setw(16) << "distanceToIn" << " "
251  << std::setw(4+precVerf) << localDirection << " "
252  << G4endl;
253  G4cout.precision(oldprec);
254  }
255  }
256 }
257 
258 // ********************************************************************
259 // CheckDaughterEntryPoint
260 // ********************************************************************
261 //
262 void
264  const G4ThreeVector& samplePoint,
265  const G4ThreeVector& sampleDirection,
266  const G4VSolid* motherSolid,
267  const G4ThreeVector& localPoint,
268  const G4ThreeVector& localDirection,
269  G4double motherStep,
270  G4double sampleStep) const
271 {
272  const G4double kCarTolerance = motherSolid->GetTolerance();
273 
274  // Double check the expected condition of being called
275  //
276  G4bool SuspiciousDaughterDist = ( sampleStep >= motherStep )
277  && ( sampleStep < kInfinity );
278 
279  if( sampleStep >= kInfinity )
280  {
282  msg.precision(12);
283  msg << " WARNING - Called with 'infinite' step. " << G4endl;
284  msg << " Checks have no meaning if daughter step is infinite." << G4endl;
285  msg << " kInfinity = " << kInfinity / millimeter << G4endl;
286  msg << " sampleStep = " << sampleStep / millimeter << G4endl;
287  msg << " sampleStep < kInfinity " << (sampleStep<kInfinity) << G4endl;
288  msg << " kInfinity - sampleStep " << (kInfinity-sampleStep) / millimeter << G4endl;
289  msg << " Returning immediately.";
290  G4Exception("G4NavigationLogger::CheckDaughterEntryPoint()",
291  "GeomNav0003", JustWarning, msg);
292  return;
293  }
294 
295  // The intersection point with the daughter is after the exit point
296  // from the mother volume !!
297  // This is legal / allowed to occur only if the mother is concave
298  // ****************************************************************
299  // If mother is convex the daughter volume must be encountered
300  // before the exit from the current volume!
301 
302  // Check #1) whether the track will re-enter the current mother
303  // in the extension past its current exit point
304  G4ThreeVector localExitMotherPos= localPoint+motherStep*localDirection;
305  G4double distExitToReEntry= motherSolid->DistanceToIn(localExitMotherPos,
306  localDirection);
307 
308  // Check #2) whether the 'entry' point in the daughter is inside the mother
309  //
310  G4ThreeVector localEntryInDaughter = localPoint+sampleStep*localDirection;
311  EInside insideMother= motherSolid->Inside( localEntryInDaughter );
312 
313  G4String solidResponse = "-kInside-";
314  if (insideMother == kOutside) { solidResponse = "-kOutside-"; }
315  else if (insideMother == kSurface) { solidResponse = "-kSurface-"; }
316 
317  G4double distToReEntry = distExitToReEntry + motherStep;
318  G4ThreeVector localReEntryPoint = localPoint+distToReEntry*localDirection;
319 
320  // Clear error -- Daughter entry point is bad
321  G4bool DaughterEntryIsOutside = SuspiciousDaughterDist
322  && ( (sampleStep < distToReEntry) || (insideMother == kOutside ) );
323  G4bool EntryIsMotherExit = std::fabs(sampleStep-motherStep) < kCarTolerance;
324 
325  // Check for more subtle error - is exit point of daughter correct ?
326  G4ThreeVector sampleEntryPoint= samplePoint+sampleStep*sampleDirection;
327  G4double sampleCrossingDist= sampleSolid->DistanceToOut( sampleEntryPoint,
328  sampleDirection );
329  G4double sampleExitDist = sampleStep+sampleCrossingDist;
330  G4ThreeVector sampleExitPoint= samplePoint+sampleExitDist*sampleDirection;
331 
332  G4bool TransitProblem = ( (sampleStep < motherStep)
333  && (sampleExitDist > motherStep + kCarTolerance) )
334  || ( EntryIsMotherExit && (sampleCrossingDist > kCarTolerance) );
335 
336  if( DaughterEntryIsOutside
337  || TransitProblem
338  || (SuspiciousDaughterDist && (fVerbose > 3) ) )
339  {
341  msg.precision(16);
342 
343  if( DaughterEntryIsOutside )
344  {
345  msg << "WARNING> Intersection distance to Daughter volume is further"
346  << " than the distance to boundary." << G4endl
347  << " It appears that part of the daughter volume is *outside*"
348  << " this mother. " << G4endl;
349  msg << " One of the following checks signaled a problem:" << G4endl
350  << " -sampleStep (dist to daugh) < mother-exit dist + distance "
351  << "to ReEntry point for mother " << G4endl
352  << " -position of daughter intersection is outside mother volume."
353  << G4endl;
354  }
355  else if( TransitProblem )
356  {
357  G4double protrusion = sampleExitDist - motherStep;
358 
359  msg << "WARNING> Daughter volume extends beyond mother boundary. "
360  << G4endl;
361  if ( ( sampleStep < motherStep )
362  && (sampleExitDist > motherStep + kCarTolerance ) )
363  {
364  // 1st Issue with Daughter
365  msg << " Crossing distance in the daughter causes is to extend"
366  << " beyond the mother exit. " << G4endl;
367  msg << " Length protruding = " << protrusion << G4endl;
368  }
369  if( EntryIsMotherExit )
370  {
371  // 1st Issue with Daughter
372  msg << " Intersection distance to Daughter is within "
373  << " tolerance of the distance" << G4endl;
374  msg << " to the mother boundary * and * " << G4endl;
375  msg << " the crossing distance in the daughter is > tolerance."
376  << G4endl;
377  }
378  }
379  else
380  {
381  msg << "NearMiss> Intersection to Daughter volume is in extension past the"
382  << " current exit point of the mother volume." << G4endl;
383  msg << " This is not an error - just an unusual occurence,"
384  << " possible in the case of concave volume. " << G4endl;
385  }
386  msg << "---- Information about intersection with daughter, mother: "
387  << G4endl;
388  msg << " sampleStep (daughter) = " << sampleStep << G4endl
389  << " motherStep = " << motherStep << G4endl
390  << " distToRentry(mother) = " << distToReEntry << G4endl
391  << " Inside(entry pnt daug): " << solidResponse << G4endl
392  << " dist across daughter = " << sampleCrossingDist << G4endl;
393  msg << " Mother Name (Solid) : " << motherSolid->GetName() << G4endl
394  << " In local (mother) coordinates: " << G4endl
395  << " Starting Point = " << localPoint << G4endl
396  << " Direction = " << localDirection << G4endl
397  << " Exit Point (mother)= " << localExitMotherPos << G4endl
398  << " Entry Point (daughter)= " << localPoint+sampleStep*localDirection
399  << G4endl;
400  if( distToReEntry < kInfinity )
401  {
402  msg << " ReEntry Point (mother)= " << localReEntryPoint << G4endl;
403  }
404  else
405  {
406  msg << " No ReEntry - track does not encounter mother volume again! "
407  << G4endl;
408  }
409  msg << " Daughter Name (Solid): " << sampleSolid->GetName() << G4endl
410  << " In daughter coordinates: " << G4endl
411  << " Starting Point = " << samplePoint << G4endl
412  << " Direction = " << sampleDirection << G4endl
413  << " Entry Point (daughter)= " << sampleEntryPoint
414  << G4endl;
415  msg << " Description of mother solid: " << G4endl
416  << *motherSolid << G4endl
417  << " Description of daughter solid: " << G4endl
418  << *sampleSolid << G4endl;
419  G4String fType = fId + "::ComputeStep()";
420 
421  if( DaughterEntryIsOutside || TransitProblem )
422  {
423  G4Exception(fType, "GeomNav0003", JustWarning, msg);
424  }
425  else
426  {
427  G4cout << fType
428  << " -- Checked distance of Entry to daughter vs exit of mother"
429  << G4endl;
430  G4cout << msg.str();
431  G4cout << G4endl;
432  }
433  }
434 }
435 
436 // ********************************************************************
437 // PostComputeStepLog
438 // ********************************************************************
439 //
440 void
442  const G4ThreeVector& localPoint,
443  const G4ThreeVector& localDirection,
444  G4double motherStep,
445  G4double motherSafety) const
446 {
447  if ( fVerbose == 1 || fVerbose > 4 )
448  {
449  G4cout << " Mother "
450  << std::setw(15) << motherSafety << " "
451  << std::setw(15) << motherStep << " " << localPoint << " - "
452  << motherSolid->GetEntityType() << ": " << motherSolid->GetName()
453  << G4endl;
454  }
455  if( ( motherStep < 0.0 ) || ( motherStep >= kInfinity) )
456  {
457  G4String fType = fId + "::ComputeStep()";
458  G4int oldPrOut= G4cout.precision(16);
459  G4int oldPrErr= G4cerr.precision(16);
460  std::ostringstream message;
461  message << "Current point is outside the current solid !" << G4endl
462  << " Problem in Navigation" << G4endl
463  << " Point (local coordinates): "
464  << localPoint << G4endl
465  << " Local Direction: " << localDirection << G4endl
466  << " Solid: " << motherSolid->GetName();
467  motherSolid->DumpInfo();
468  G4Exception(fType, "GeomNav0003", FatalException, message);
469  G4cout.precision(oldPrOut);
470  G4cerr.precision(oldPrErr);
471  }
472  if ( fVerbose > 1 )
473  {
474  static const G4int precVerf= 20; // Precision
475  G4int oldprec = G4cout.precision(precVerf);
476  G4cout << " Mother " << std::setw(12) << motherSolid->GetName() << " "
477  << std::setw(4+precVerf) << localPoint << " "
478  << std::setw(4+precVerf) << motherSafety << " "
479  << std::setw(4+precVerf) << motherStep << " "
480  << std::setw(16) << "distanceToOut" << " "
481  << std::setw(4+precVerf) << localDirection << " "
482  << G4endl;
483  G4cout.precision(oldprec);
484  }
485 }
486 
487 // ********************************************************************
488 // ComputeSafetyLog
489 // ********************************************************************
490 //
491 void
493  const G4ThreeVector& point,
494  G4double safety,
495  G4bool isMotherVolume,
496  G4int banner) const
497 {
498  if( banner < 0 )
499  {
500  banner = isMotherVolume;
501  }
502  if( fVerbose >= 1 )
503  {
504  G4String volumeType = isMotherVolume ? " Mother " : "Daughter";
505  if (banner)
506  {
507  G4cout << "************** " << fId << "::ComputeSafety() ****************"
508  << G4endl;
509  G4cout << " VolType "
510  << std::setw(15) << "Safety/mm" << " "
511  << std::setw(52) << "Position (local coordinates)"
512  << " - Solid" << G4endl;
513  }
514  G4cout << volumeType
515  << std::setw(15) << safety << " " << point << " - "
516  << solid->GetEntityType() << ": " << solid->GetName() << G4endl;
517  }
518 }
519 
520 // ********************************************************************
521 // PrintDaughterLog
522 // ********************************************************************
523 //
524 void
526  const G4ThreeVector& samplePoint,
527  G4double sampleSafety,
528  G4bool withStep,
529  const G4ThreeVector& sampleDirection, G4double sampleStep ) const
530 {
531  if ( fVerbose >= 1 )
532  {
533  G4int oldPrec= G4cout.precision(8);
534  G4cout << "Daughter "
535  << std::setw(15) << sampleSafety << " ";
536  if (withStep) // (sampleStep != -1.0 )
537  {
538  G4cout << std::setw(15) << sampleStep << " ";
539  }
540  else
541  {
542  G4cout << std::setw(15) << "Not-Available" << " ";
543  }
544  G4cout << samplePoint << " - "
545  << sampleSolid->GetEntityType() << ": " << sampleSolid->GetName();
546  if( withStep )
547  {
548  G4cout << " dir= " << sampleDirection;
549  }
550  G4cout << G4endl;
551  G4cout.precision(oldPrec);
552  }
553 }
554 
555 // ********************************************************************
556 // CheckAndReportBadNormal
557 // ********************************************************************
558 //
559 G4bool
562  const G4ThreeVector& localPoint,
563  const G4ThreeVector& localDirection,
564  G4double step,
565  const G4VSolid* solid,
566  const char* msg ) const
567 {
568  G4double normMag2 = unitNormal.mag2();
569  G4bool badLength = ( std::fabs ( normMag2 - 1.0 ) > CLHEP::perMillion );
570 
571  if( badLength )
572  {
573  G4double normMag= std::sqrt(normMag2);
574  G4ExceptionDescription message;
575  message.precision(10);
576  message << "============================================================"
577  << G4endl;
578  message << " WARNING> Normal is not a unit vector. "
579  << " Expected normal-global-frame to be valid "
580  << " i.e. a unit vector!" << G4endl
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 << "============================================================"
589  << G4endl;
590 
591  message.precision(16);
592 
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
598  << G4endl;
599  message << " Parameters of solid: " << G4endl;
600  message << *solid;
601  message << "============================================================";
602 
603  G4String fMethod = fId + "::ComputeStep()";
604  G4Exception( fMethod, "GeomNav0003", JustWarning, message);
605  }
606  return badLength;
607 }
608 
609 // ********************************************************************
610 // ReportOutsideMother
611 // ********************************************************************
612 //
613 // Report Exception if point is outside mother.
614 // Fatal exception will be used if either 'checkMode error is > triggerDist
615 //
616 void
618  const G4ThreeVector& localDirection,
619  const G4VPhysicalVolume* physical,
620  G4double triggerDist) const
621 {
622  const G4LogicalVolume* logicalVol = physical
623  ? physical->GetLogicalVolume() : 0;
624  const G4VSolid* solid = logicalVol
625  ? logicalVol->GetSolid() : 0;
626 
627  G4String fMethod = fId + "::ComputeStep()";
628 
629  if( solid == 0 )
630  {
631  G4Exception(fMethod, "GeomNav0003", FatalException,
632  "Erroneous call to ReportOutsideMother: no Solid is available");
633  return;
634  }
635  const G4double kCarTolerance = solid->GetTolerance();
636 
637  // Double check reply - it should be kInfinity
638  const G4double distToOut = solid->DistanceToOut(localPoint, localDirection);
639  // const G4double distToOutNeg = solid->DistanceToOut(localPoint, -localDirection);
640 
641  const EInside inSolid = solid->Inside(localPoint);
642  const G4double safetyToIn = solid->DistanceToIn(localPoint);
643  const G4double safetyToOut = solid->DistanceToOut(localPoint);
644 
645  const G4double distToInPos = solid->DistanceToIn(localPoint, localDirection);
646  // const G4double distToInNeg = solid->DistanceToIn(localPoint, -localDirection);
647 
648  // 1. Check consistency between Safety obtained and report from distance
649  // We must ensure that (mother)Safety <= 0.0
650  // in the case that the point is outside!
651  // [ If this is not the case, this problem can easily go undetected,
652  // except in Check mode ! ]
653  if( safetyToOut > kCarTolerance
654  && ( distToOut < 0.0 || distToOut >= kInfinity ) )
655  {
657  // fNavClerk->ReportBadSafety(localPoint, localDirection,
658  // motherPhysical, motherSafety, motherStep);
659  msg1 << " Dangerous inconsistency in response of solid." << G4endl
660  << " Solid type: " << solid->GetEntityType()
661  << " Name= " << solid->GetName() << G4endl;
662  msg1 << " Mother volume gives safety > 0 despite being called for *Outside* point "
663  << G4endl
664  << " Location = " << localPoint << G4endl
665  << " Direction= " << localDirection << G4endl
666  << " - Safety (Isotropic d) = " << safetyToOut << G4endl
667  << " - Intersection Distance= " << distToOut << G4endl
668  << G4endl;
669  G4Exception( fMethod, "GeomNav0123", JustWarning, msg1);
670  }
671 
672  // 2. Inconsistency - Too many distances are zero (or will be rounded to zero)
673 
675  if( std::fabs(distToOut) < kCarTolerance && std::fabs(distToInPos) < kCarTolerance )
676  {
677  // If both distanceToIn and distanceToOut (p,v) are zero for one direction,
678  // the particle could get stuck!
679  }
680 
682  msg.precision(10);
683  // G4bool reportIssue= true;
684 
685  if( std::fabs(distToOut) < kCarTolerance )
686  {
687  // 3. Soft error - safety is not rounded to zero
688  // Report nothing - except in 'loud' mode
689  if( fReportSoftWarnings )
690  {
691  // reportIssue= true;
692  msg << " Warning> DistanceToOut(p,v): Distance from surface is not rounded to zero" << G4endl;
693  } else {
694  // reportIssue= false;
695  return;
696  }
697  }
698  else
699  {
700  // 4. General message - complain that the point is outside!
701  // and provide all information about the current location,
702  // direction and the answers of the solid
703  msg << "============================================================" << G4endl;
704  msg << " WARNING> Current Point appears to be Outside mother volume !! " << G4endl;
705  msg << " Response of DistanceToOut was negative or kInfinity when called in "
706  << fMethod << G4endl;
707  }
708 
709  // Generate and 'print'/stream all the information needed
710  this->ReportVolumeAndIntersection( msg, localPoint, localDirection, physical );
711 
712  // Default for distance of 'major' error
713  if( triggerDist <= 0.0 ) {
714  // triggerDist = 1.e+6 * kCarTolerance; // Well beyond tolerance
715  triggerDist = std::max ( 1.0e+6 * kCarTolerance, // Well beyond tolerance
717  }
718 
719  G4bool majorError = inSolid==kOutside
720  ? ( safetyToIn > triggerDist )
721  : ( safetyToOut > triggerDist );
722 
723  G4ExceptionSeverity exceptionType = JustWarning;
724  if ( majorError )
725  {
726  exceptionType = FatalException;
727  }
728 
729  G4Exception( fMethod, "GeomNav0003", exceptionType, msg);
730 }
731 
733  const G4String EInsideNames[3] = { "kOutside", "kSurface", "kInside" };
734 }
735 
736 void
738  const G4ThreeVector& localPoint,
739  const G4ThreeVector& localDirection,
740  const G4VPhysicalVolume* physical ) const
741 {
742  G4String fMethod = fId + "::ComputeStep() / output from G4NavigatorLogger::ReportVolumeAndIntersection";
743  const G4LogicalVolume* logicalVol = physical
744  ? physical->GetLogicalVolume() : 0;
745  const G4VSolid* solid = logicalVol
746  ? logicalVol->GetSolid() : 0;
747  if( solid == 0 )
748  {
749  os << " ERROR> Solid is not available. Logical Volume = " << logicalVol << std::endl;
750  return;
751  }
752  const G4double kCarTolerance = solid->GetTolerance();
753 
754  // Double check reply - it should be kInfinity
755  const G4double distToOut = solid->DistanceToOut(localPoint, localDirection);
756  const G4double distToOutNeg = solid->DistanceToOut(localPoint, -localDirection);
757 
758  const EInside inSolid = solid->Inside(localPoint);
759  const G4double safetyToIn = solid->DistanceToIn(localPoint);
760  const G4double safetyToOut = solid->DistanceToOut(localPoint);
761 
762  const G4double distToInPos = solid->DistanceToIn(localPoint, localDirection);
763  const G4double distToInNeg = solid->DistanceToIn(localPoint, -localDirection);
764 
765  const G4ThreeVector exitNormal = solid->SurfaceNormal(localPoint);
766 
767  // Double check whether points nearby are in/surface/out
768  const G4double epsilonDist = 1000.0 * kCarTolerance;
769  const G4ThreeVector PointPlusDir = localPoint + epsilonDist * localDirection;
770  const G4ThreeVector PointMinusDir = localPoint - epsilonDist * localDirection;
771  const G4ThreeVector PointPlusNorm = localPoint + epsilonDist * exitNormal;
772  const G4ThreeVector PointMinusNorm = localPoint - epsilonDist * exitNormal;
773 
774  const EInside inPlusDir= solid->Inside(PointPlusDir);
775  const EInside inMinusDir= solid->Inside(PointMinusDir);
776  const EInside inPlusNorm= solid->Inside(PointPlusNorm);
777  const EInside inMinusNorm= solid->Inside(PointMinusNorm);
778 
779  // Basic information
780  os << " Current physical volume = " << physical->GetName() << G4endl;
781  os << " Position (loc) = " << localPoint << G4endl
782  << " Direction (dir) = " << localDirection << G4endl;
783  os << " For confirmation:" << G4endl;
784  os << " Response of DistanceToOut (loc, +dir)= " << distToOut << G4endl;
785  os << " Response of DistanceToOut (loc, -dir)= " << distToOutNeg << G4endl;
786 
787  os << " Inside responds = " << inSolid << " , ie: ";
788  if( inSolid == kOutside ) {
789  os << " Outside -- a problem, as observed in " << fMethod << G4endl;
790  } else if( inSolid == kSurface ) {
791  os << " Surface -- unexpected / inconsistent response ! " << G4endl;
792  } else {
793  os << " Inside -- unexpected / inconsistent response ! " << G4endl;
794  }
795  os << " Obtain safety(ToIn) = " << safetyToIn << G4endl;
796  os << " Obtain safety(ToOut) = " << safetyToOut << G4endl;
797  os << " Response of DistanceToIn (loc, +dir)= " << distToInPos << G4endl;
798  os << " Response of DistanceToIn (loc, -dir)= " << distToInNeg << G4endl;
799 
800  os << " Exit Normal at loc = " << exitNormal << G4endl;
801  os << " Dir . Normal = " << exitNormal.dot( localDirection );
802  os << G4endl;
803 
804  os << " Checking points moved from position by distance/dir. Solid responses: " << G4endl
805  << " +eps in direction : " << G4NavigationLogger_Namespace::EInsideNames[inPlusDir]
806  << " +eps in Normal : " << G4NavigationLogger_Namespace::EInsideNames[inPlusNorm] << G4endl
807  << " -eps in direction : " << G4NavigationLogger_Namespace::EInsideNames[inMinusDir]
808  << " -eps in Normal : " << G4NavigationLogger_Namespace::EInsideNames[inMinusNorm] << G4endl;
809 
810  os << " Parameters of solid: " << G4endl;
811  os << *solid;
812  os << "============================================================";
813 }
void AlongComputeStepLog(const G4VSolid *sampleSolid, const G4ThreeVector &samplePoint, const G4ThreeVector &sampleDirection, const G4ThreeVector &localDirection, G4double sampleSafety, G4double sampleStep) const
G4String GetName() const
void PrintDaughterLog(const G4VSolid *sampleSolid, const G4ThreeVector &samplePoint, G4double sampleSafety, G4bool onlySafety, const G4ThreeVector &sampleDirection, G4double sampleStep) const
static const G4double kInfinity
Definition: geomdefs.hh:42
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
CLHEP::Hep3Vector G4ThreeVector
G4double GetTolerance() const
virtual G4GeometryType GetEntityType() const =0
int G4int
Definition: G4Types.hh:78
void DumpInfo() const
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
bool G4bool
Definition: G4Types.hh:79
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
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static const double perMillion
Definition: G4SIunits.hh:298
G4ExceptionSeverity
G4LogicalVolume * GetLogicalVolume() const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
EInside
Definition: geomdefs.hh:58
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
Definition: G4SIunits.hh:76
#define G4endl
Definition: G4ios.hh:61
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
double G4double
Definition: G4Types.hh:76
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const =0
#define DBL_MAX
Definition: templates.hh:83
static G4GeometryTolerance * GetInstance()
G4VSolid * GetSolid() const
G4GLOB_DLL std::ostream G4cerr