Geant4  10.00.p03
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 66872 2013-01-15 01:25:57Z japost $
28 //
29 //
30 // class G4NavigationLogger Implementation
31 //
32 // Author: G.Cosmo, 2010
33 //
34 // --------------------------------------------------------------------
35 
36 #include <iomanip>
37 
38 #include "G4NavigationLogger.hh"
39 #include "G4GeometryTolerance.hh"
40 
42  : fId(id), fVerbose(0)
43 {
44 }
45 
47 {
48 }
49 
50 void
52  G4double motherSafety,
53  const G4ThreeVector& localPoint) const
54 {
55  G4VSolid* motherSolid = motherPhysical->GetLogicalVolume()->GetSolid();
56  G4String fType = fId + "::ComputeStep()";
57  if( fVerbose == 1 )
58  {
59  G4cout << "*************** " << fType << " *****************" << G4endl
60  << " VolType "
61  << std::setw(15) << "Safety/mm" << " "
62  << std::setw(15) << "Distance/mm" << " "
63  << std::setw(52) << "Position (local coordinates)"
64  << " - Solid" << G4endl;
65  G4cout << " Mother "
66  << std::setw(15) << motherSafety << " "
67  << std::setw(15) << "N/C" << " " << localPoint << " - "
68  << motherSolid->GetEntityType() << ": " << motherSolid->GetName()
69  << G4endl;
70  }
71  if ( motherSafety < 0.0 )
72  {
73  std::ostringstream message;
74  message << "Negative Safety In Voxel Navigation !" << G4endl
75  << " Current solid " << motherSolid->GetName()
76  << " gave negative safety: " << motherSafety << G4endl
77  << " for the current (local) point " << localPoint;
78  motherSolid->DumpInfo();
79  G4Exception(fType, "GeomNav0003", FatalException, message);
80  }
81  if( motherSolid->Inside(localPoint)==kOutside )
82  {
83  std::ostringstream message;
84  message << "Point is outside Current Volume - " << G4endl
85  << " Point " << localPoint
86  << " is outside current volume " << motherPhysical->GetName()
87  << G4endl;
88  G4double estDistToSolid= motherSolid->DistanceToIn(localPoint);
89  message << " Estimated isotropic distance to solid (distToIn)= "
90  << estDistToSolid;
91  if( estDistToSolid > 100.0 * motherSolid->GetTolerance() )
92  {
93  motherSolid->DumpInfo();
94  G4Exception(fType, "GeomNav0003", FatalException, message,
95  "Point is far outside Current Volume !" );
96  }
97  else
98  G4Exception(fType, "GeomNav1001", JustWarning, message,
99  "Point is a little outside Current Volume.");
100  }
101 
102  // Verification / verbosity
103  //
104  if ( fVerbose > 1 )
105  {
106  static G4ThreadLocal G4int precVerf= 20; // Precision
107  G4int oldprec = G4cout.precision(precVerf);
108  G4cout << " - Information on mother / key daughters ..." << G4endl;
109  G4cout << " Type " << std::setw(12) << "Solid-Name" << " "
110  << std::setw(3*(6+precVerf)) << " local point" << " "
111  << std::setw(4+precVerf) << "solid-Safety" << " "
112  << std::setw(4+precVerf) << "solid-Step" << " "
113  << std::setw(17) << "distance Method "
114  << std::setw(3*(6+precVerf)) << " local direction" << " "
115  << G4endl;
116  G4cout << " Mother " << std::setw(12) << motherSolid->GetName() << " "
117  << std::setw(4+precVerf) << localPoint << " "
118  << std::setw(4+precVerf) << motherSafety << " "
119  << G4endl;
120  G4cout.precision(oldprec);
121  }
122 }
123 
124 void
126  const G4ThreeVector& samplePoint,
127  const G4ThreeVector& sampleDirection,
128  const G4ThreeVector& localDirection,
129  G4double sampleSafety,
130  G4double sampleStep) const
131 {
132  // Check to see that the resulting point is indeed in/on volume.
133  // This check could eventually be made only for successful candidate.
134 
135  if ( sampleStep < kInfinity )
136  {
137  G4ThreeVector intersectionPoint;
138  intersectionPoint= samplePoint + sampleStep * sampleDirection;
139  EInside insideIntPt= sampleSolid->Inside(intersectionPoint);
140  G4String fType = fId + "::ComputeStep()";
141 
142  G4String solidResponse = "-kInside-";
143  if (insideIntPt == kOutside)
144  { solidResponse = "-kOutside-"; }
145  else if (insideIntPt == kSurface)
146  { solidResponse = "-kSurface-"; }
147 
148  if ( fVerbose == 1 )
149  {
150  G4cout << " Invoked Inside() for solid: "
151  << sampleSolid->GetName()
152  << ". Solid replied: " << solidResponse << G4endl
153  << " For point p: " << intersectionPoint
154  << ", considered as 'intersection' point." << G4endl;
155  }
156 
157  G4double safetyIn= -1, safetyOut= -1; // Set to invalid values
158  G4double newDistIn= -1, newDistOut= -1;
159  if( insideIntPt != kInside )
160  {
161  safetyIn= sampleSolid->DistanceToIn(intersectionPoint);
162  newDistIn= sampleSolid->DistanceToIn(intersectionPoint,
163  sampleDirection);
164  }
165  if( insideIntPt != kOutside )
166  {
167  safetyOut= sampleSolid->DistanceToOut(intersectionPoint);
168  newDistOut= sampleSolid->DistanceToOut(intersectionPoint,
169  sampleDirection);
170  }
171  if( insideIntPt != kSurface )
172  {
173  G4int oldcoutPrec = G4cout.precision(16);
174  std::ostringstream message;
175  message << "Conflicting response from Solid." << G4endl
176  << " Inaccurate solid DistanceToIn"
177  << " for solid " << sampleSolid->GetName() << G4endl
178  << " Solid gave DistanceToIn = "
179  << sampleStep << " yet returns " << solidResponse
180  << " for this point !" << G4endl
181  << " Point = " << intersectionPoint << G4endl
182  << " Safety values: " << G4endl;
183  if ( insideIntPt != kInside )
184  {
185  message << " DistanceToIn(p) = " << safetyIn;
186  }
187  if ( insideIntPt != kOutside )
188  {
189  message << " DistanceToOut(p) = " << safetyOut;
190  }
191  G4Exception(fType, "GeomNav1001", JustWarning, message);
192  G4cout.precision(oldcoutPrec);
193  }
194  else
195  {
196  // If it is on the surface, *ensure* that either DistanceToIn
197  // or DistanceToOut returns a finite value ( >= Tolerance).
198  //
199  if( std::max( newDistIn, newDistOut ) <=
200  G4GeometryTolerance::GetInstance()->GetSurfaceTolerance() )
201  {
202  std::ostringstream message;
203  message << "Zero from both Solid DistanceIn and Out(p,v)." << G4endl
204  << " Identified point for which the solid "
205  << sampleSolid->GetName() << G4endl
206  << " has MAJOR problem: " << G4endl
207  << " --> Both DistanceToIn(p,v) and DistanceToOut(p,v) "
208  << "return Zero, an equivalent value or negative value."
209  << G4endl
210  << " Solid: " << sampleSolid << G4endl
211  << " Point p= " << intersectionPoint << G4endl
212  << " Direction v= " << sampleDirection << G4endl
213  << " DistanceToIn(p,v) = " << newDistIn << G4endl
214  << " DistanceToOut(p,v,..) = " << newDistOut << G4endl
215  << " Safety values: " << G4endl
216  << " DistanceToIn(p) = " << safetyIn << G4endl
217  << " DistanceToOut(p) = " << safetyOut;
218  G4Exception(fType, "GeomNav0003", FatalException, message);
219  }
220  }
221 
222  // Verification / verbosity
223  //
224  if ( fVerbose > 1 )
225  {
226  static G4ThreadLocal G4int precVerf= 20; // Precision
227  G4int oldprec = G4cout.precision(precVerf);
228  G4cout << "Daughter "
229  << std::setw(12) << sampleSolid->GetName() << " "
230  << std::setw(4+precVerf) << samplePoint << " "
231  << std::setw(4+precVerf) << sampleSafety << " "
232  << std::setw(4+precVerf) << sampleStep << " "
233  << std::setw(16) << "distanceToIn" << " "
234  << std::setw(4+precVerf) << localDirection << " "
235  << G4endl;
236  G4cout.precision(oldprec);
237  }
238  }
239 }
240 
241 void
243  const G4ThreeVector& localPoint,
244  const G4ThreeVector& localDirection,
245  G4double motherStep,
246  G4double motherSafety) const
247 {
248  if( fVerbose == 1 )
249  {
250  G4cout << " Mother "
251  << std::setw(15) << motherSafety << " "
252  << std::setw(15) << motherStep << " " << localPoint << " - "
253  << motherSolid->GetEntityType() << ": " << motherSolid->GetName()
254  << G4endl;
255  }
256  if( ( motherStep < 0.0 ) || ( motherStep >= kInfinity) )
257  {
258  G4String fType = fId + "::ComputeStep()";
259  G4int oldPrOut= G4cout.precision(16);
260  G4int oldPrErr= G4cerr.precision(16);
261  std::ostringstream message;
262  message << "Current point is outside the current solid !" << G4endl
263  << " Problem in Navigation" << G4endl
264  << " Point (local coordinates): "
265  << localPoint << G4endl
266  << " Local Direction: " << localDirection << G4endl
267  << " Solid: " << motherSolid->GetName();
268  motherSolid->DumpInfo();
269  G4Exception(fType, "GeomNav0003", FatalException, message);
270  G4cout.precision(oldPrOut);
271  G4cerr.precision(oldPrErr);
272  }
273  if ( fVerbose > 1 )
274  {
275  static G4ThreadLocal G4int precVerf= 20; // Precision
276  G4int oldprec = G4cout.precision(precVerf);
277  G4cout << " Mother " << std::setw(12) << motherSolid->GetName() << " "
278  << std::setw(4+precVerf) << localPoint << " "
279  << std::setw(4+precVerf) << motherSafety << " "
280  << std::setw(4+precVerf) << motherStep << " "
281  << std::setw(16) << "distanceToOut" << " "
282  << std::setw(4+precVerf) << localDirection << " "
283  << G4endl;
284  G4cout.precision(oldprec);
285  }
286 }
287 
288 void
290  const G4ThreeVector& point,
291  G4double safety,
292  G4bool banner) const
293 {
294  G4String volumeType = "Daughter ";
295  if (banner)
296  {
297  G4cout << "************** " << fId << "::ComputeSafety() ****************" << G4endl;
298  G4cout << " VolType "
299  << std::setw(15) << "Safety/mm" << " "
300  << std::setw(52) << "Position (local coordinates)"
301  << " - Solid" << G4endl;
302  volumeType = " Mother ";
303  }
304  G4cout << volumeType
305  << std::setw(15) << safety << " " << point << " - "
306  << solid->GetEntityType() << ": " << solid->GetName() << G4endl;
307 }
308 
309 void
311  const G4ThreeVector& samplePoint,
312  G4double sampleSafety,
313  G4double sampleStep) const
314 {
315  if ( fVerbose == 1 )
316  {
317  G4cout << "Daughter "
318  << std::setw(15) << sampleSafety << " ";
319  if (sampleStep)
320  {
321  G4cout << std::setw(15) << sampleStep << " ";
322  }
323  else
324  {
325  G4cout << std::setw(15) << "N/C" << " ";
326  }
327  G4cout << samplePoint << " - "
328  << sampleSolid->GetEntityType() << ": " << sampleSolid->GetName()
329  << G4endl;
330  }
331 }
void AlongComputeStepLog(const G4VSolid *sampleSolid, const G4ThreeVector &samplePoint, const G4ThreeVector &sampleDirection, const G4ThreeVector &localDirection, G4double sampleSafety, G4double sampleStep) const
G4String GetName() const
static const G4double kInfinity
Definition: geomdefs.hh:42
CLHEP::Hep3Vector G4ThreeVector
void PrintDaughterLog(const G4VSolid *sampleSolid, const G4ThreeVector &samplePoint, G4double sampleSafety, G4double sampleStep) const
void ComputeSafetyLog(const G4VSolid *solid, const G4ThreeVector &point, G4double safety, G4bool banner) const
G4double GetTolerance() const
virtual G4GeometryType GetEntityType() const =0
#define G4ThreadLocal
Definition: tls.hh:52
int G4int
Definition: G4Types.hh:78
void DumpInfo() const
G4NavigationLogger(const G4String &id)
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
virtual EInside Inside(const G4ThreeVector &p) const =0
bool G4bool
Definition: G4Types.hh:79
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
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 PreComputeStepLog(const G4VPhysicalVolume *motherPhysical, G4double motherSafety, const G4ThreeVector &localPoint) const
#define G4endl
Definition: G4ios.hh:61
void PostComputeStepLog(const G4VSolid *motherSolid, const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, G4double motherStep, G4double motherSafety) 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
static G4GeometryTolerance * GetInstance()
G4VSolid * GetSolid() const
G4GLOB_DLL std::ostream G4cerr