source: trunk/source/geometry/navigation/src/G4NavigationLogger.cc @ 1350

Last change on this file since 1350 was 1350, checked in by garnier, 13 years ago

update to last version 4.9.4

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