G4NavigationLogger.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 //
00030 // class G4NavigationLogger Implementation
00031 //
00032 // Author: G.Cosmo, 2010
00033 //
00034 // --------------------------------------------------------------------
00035 
00036 #include <iomanip>
00037 
00038 #include "G4NavigationLogger.hh"
00039 #include "G4GeometryTolerance.hh"
00040 
00041 G4NavigationLogger::G4NavigationLogger(const G4String& id)
00042   : fId(id), fVerbose(0)
00043 {
00044 }
00045 
00046 G4NavigationLogger::~G4NavigationLogger()
00047 {
00048 }
00049 
00050 void
00051 G4NavigationLogger::PreComputeStepLog(const G4VPhysicalVolume* motherPhysical,
00052                                             G4double motherSafety,
00053                                       const G4ThreeVector& localPoint) const
00054 {
00055     G4VSolid* motherSolid = motherPhysical->GetLogicalVolume()->GetSolid();
00056     G4String fType = fId + "::ComputeStep()";
00057     if( fVerbose == 1 )
00058     {
00059       G4cout << "*************** " << fType << " *****************" << G4endl
00060              << " VolType "
00061              << std::setw(15) << "Safety/mm" << " "
00062              << std::setw(15) << "Distance/mm" << " "
00063              << std::setw(52) << "Position (local coordinates)"
00064              << " - Solid" << G4endl;
00065       G4cout << "  Mother "
00066              << std::setw(15) << motherSafety << " " 
00067              << std::setw(15) << "N/C"        << " " << localPoint << " - "
00068              << motherSolid->GetEntityType() << ": " << motherSolid->GetName()
00069              << G4endl;
00070     }
00071     if ( motherSafety < 0.0 )
00072     {
00073       std::ostringstream message;
00074       message << "Negative Safety In Voxel Navigation !" << G4endl
00075              << "        Current solid " << motherSolid->GetName()
00076              << " gave negative safety: " << motherSafety << G4endl
00077              << "        for the current (local) point " << localPoint;
00078       motherSolid->DumpInfo();
00079       G4Exception(fType, "GeomNav0003", FatalException, message);
00080     }
00081     if( motherSolid->Inside(localPoint)==kOutside )
00082     {
00083       std::ostringstream message;
00084       message << "Point is outside Current Volume - " << G4endl
00085               << "          Point " << localPoint
00086               << " is outside current volume " << motherPhysical->GetName()
00087               << G4endl;
00088       G4double estDistToSolid= motherSolid->DistanceToIn(localPoint); 
00089       message << "          Estimated isotropic distance to solid (distToIn)= " 
00090               << estDistToSolid;
00091       if( estDistToSolid > 100.0 * motherSolid->GetTolerance() )
00092       {
00093         motherSolid->DumpInfo();
00094         G4Exception(fType, "GeomNav0003", FatalException, message,
00095                     "Point is far outside Current Volume !" ); 
00096       }
00097       else
00098         G4Exception(fType, "GeomNav1001", JustWarning, message,
00099                     "Point is a little outside Current Volume."); 
00100     }
00101 
00102     // Verification / verbosity
00103     //
00104     if ( fVerbose > 1 )
00105     {
00106       static G4int precVerf= 20;  // Precision 
00107       G4int oldprec = G4cout.precision(precVerf);
00108       G4cout << " - Information on mother / key daughters ..." << G4endl;
00109       G4cout << "  Type   " << std::setw(12) << "Solid-Name"   << " " 
00110              << std::setw(3*(6+precVerf))    << " local point" << " "
00111              << std::setw(4+precVerf)        << "solid-Safety" << " "
00112              << std::setw(4+precVerf)        << "solid-Step"   << " "
00113              << std::setw(17)                << "distance Method "
00114              << std::setw(3*(6+precVerf))    << " local direction" << " "
00115              << G4endl;
00116       G4cout << "  Mother " << std::setw(12) << motherSolid->GetName() << " "
00117              << std::setw(4+precVerf)        << localPoint   << " "
00118              << std::setw(4+precVerf)        << motherSafety << " "
00119              << G4endl;
00120       G4cout.precision(oldprec);
00121     }
00122 }
00123 
00124 void
00125 G4NavigationLogger::AlongComputeStepLog(const G4VSolid* sampleSolid,
00126                                         const G4ThreeVector& samplePoint,
00127                                         const G4ThreeVector& sampleDirection,
00128                                         const G4ThreeVector& localDirection,
00129                                               G4double sampleSafety,
00130                                               G4double sampleStep) const
00131 {
00132   // Check to see that the resulting point is indeed in/on volume.
00133   // This check could eventually be made only for successful candidate.
00134 
00135   if ( sampleStep < kInfinity )
00136   {
00137     G4ThreeVector intersectionPoint;
00138     intersectionPoint= samplePoint + sampleStep * sampleDirection;
00139     EInside insideIntPt= sampleSolid->Inside(intersectionPoint); 
00140     G4String fType = fId + "::ComputeStep()";
00141 
00142     G4String solidResponse = "-kInside-";
00143     if (insideIntPt == kOutside)
00144       { solidResponse = "-kOutside-"; }
00145     else if (insideIntPt == kSurface)
00146       { solidResponse = "-kSurface-"; }
00147 
00148     if ( fVerbose == 1 )
00149     {
00150       G4cout << "    Invoked Inside() for solid: "
00151              << sampleSolid->GetName()
00152              << ". Solid replied: " << solidResponse << G4endl
00153              << "    For point p: " << intersectionPoint
00154              << ", considered as 'intersection' point." << G4endl;
00155     }
00156 
00157     G4double safetyIn= -1, safetyOut= -1;  //  Set to invalid values
00158     G4double newDistIn= -1,  newDistOut= -1;
00159     if( insideIntPt != kInside )
00160     {
00161       safetyIn= sampleSolid->DistanceToIn(intersectionPoint);
00162       newDistIn= sampleSolid->DistanceToIn(intersectionPoint,
00163                                            sampleDirection);
00164     }
00165     if( insideIntPt != kOutside )
00166     {
00167       safetyOut= sampleSolid->DistanceToOut(intersectionPoint);
00168       newDistOut= sampleSolid->DistanceToOut(intersectionPoint,
00169                                              sampleDirection);
00170     }
00171     if( insideIntPt != kSurface )
00172     {
00173       G4int oldcoutPrec = G4cout.precision(16); 
00174       std::ostringstream message;
00175       message << "Conflicting response from Solid." << G4endl
00176               << "          Inaccurate solid DistanceToIn"
00177               << " for solid " << sampleSolid->GetName() << G4endl
00178               << "          Solid gave DistanceToIn = "
00179               << sampleStep << " yet returns " << solidResponse
00180               << " for this point !" << G4endl
00181               << "          Point = " << intersectionPoint << G4endl
00182               << "          Safety values: " << G4endl;
00183       if ( insideIntPt != kInside )
00184       {
00185         message << "          DistanceToIn(p)  = " << safetyIn;
00186       }
00187       if ( insideIntPt != kOutside )
00188       {
00189         message << "          DistanceToOut(p) = " << safetyOut;
00190       }
00191       G4Exception(fType, "GeomNav1001", JustWarning, message);
00192       G4cout.precision(oldcoutPrec);
00193     }
00194     else
00195     {  
00196       // If it is on the surface, *ensure* that either DistanceToIn
00197       // or DistanceToOut returns a finite value ( >= Tolerance).
00198       //
00199       if( std::max( newDistIn, newDistOut ) <=
00200           G4GeometryTolerance::GetInstance()->GetSurfaceTolerance() )
00201       { 
00202         std::ostringstream message;
00203         message << "Zero from both Solid DistanceIn and Out(p,v)." << G4endl
00204                 << "  Identified point for which the solid " 
00205                 << sampleSolid->GetName() << G4endl
00206                 << "  has MAJOR problem:  " << G4endl
00207                 << "  --> Both DistanceToIn(p,v) and DistanceToOut(p,v) "
00208                 << "return Zero, an equivalent value or negative value."
00209                 << G4endl 
00210                 << "    Solid: " << sampleSolid << G4endl
00211                 << "    Point p= " << intersectionPoint << G4endl
00212                 << "    Direction v= " << sampleDirection << G4endl
00213                 << "    DistanceToIn(p,v)     = " << newDistIn << G4endl
00214                 << "    DistanceToOut(p,v,..) = " << newDistOut << G4endl
00215                 << "    Safety values: " << G4endl
00216                 << "      DistanceToIn(p)  = " << safetyIn << G4endl
00217                 << "      DistanceToOut(p) = " << safetyOut;
00218         G4Exception(fType, "GeomNav0003", FatalException, message);
00219       }
00220     }
00221 
00222     // Verification / verbosity
00223     //
00224     if ( fVerbose > 1 )
00225     {
00226       static G4int precVerf= 20;  // Precision 
00227       G4int oldprec = G4cout.precision(precVerf);
00228       G4cout << "Daughter "
00229              << std::setw(12)         << sampleSolid->GetName() << " "
00230              << std::setw(4+precVerf) << samplePoint  << " "
00231              << std::setw(4+precVerf) << sampleSafety << " "
00232              << std::setw(4+precVerf) << sampleStep   << " "
00233              << std::setw(16)         << "distanceToIn" << " "
00234              << std::setw(4+precVerf) << localDirection << " "
00235              << G4endl;
00236       G4cout.precision(oldprec);
00237     }
00238   }
00239 }
00240 
00241 void
00242 G4NavigationLogger::PostComputeStepLog(const G4VSolid* motherSolid,
00243                                        const G4ThreeVector& localPoint,
00244                                        const G4ThreeVector& localDirection,
00245                                              G4double motherStep,
00246                                              G4double motherSafety) const
00247 {
00248   if( fVerbose == 1 )
00249   {
00250     G4cout << "  Mother "
00251            << std::setw(15) << motherSafety << " " 
00252            << std::setw(15) << motherStep   << " " << localPoint   << " - "
00253            << motherSolid->GetEntityType() << ": " << motherSolid->GetName()
00254            << G4endl;
00255   }
00256   if( ( motherStep < 0.0 ) || ( motherStep >= kInfinity) )
00257   {
00258     G4String fType = fId + "::ComputeStep()";
00259     G4int oldPrOut= G4cout.precision(16); 
00260     G4int oldPrErr= G4cerr.precision(16);
00261     std::ostringstream message;
00262     message << "Current point is outside the current solid !" << G4endl
00263             << "        Problem in Navigation"  << G4endl
00264             << "        Point (local coordinates): "
00265             << localPoint << G4endl
00266             << "        Local Direction: " << localDirection << G4endl
00267             << "        Solid: " << motherSolid->GetName(); 
00268     motherSolid->DumpInfo();
00269     G4Exception(fType, "GeomNav0003", FatalException, message);
00270     G4cout.precision(oldPrOut);
00271     G4cerr.precision(oldPrErr);
00272   }
00273   if ( fVerbose > 1 )
00274   {
00275     static G4int precVerf= 20;  // Precision 
00276     G4int oldprec = G4cout.precision(precVerf);
00277     G4cout << "  Mother " << std::setw(12) << motherSolid->GetName() << " "
00278            << std::setw(4+precVerf)       << localPoint   << " "
00279            << std::setw(4+precVerf)       << motherSafety << " "
00280            << std::setw(4+precVerf)       << motherStep   << " "
00281            << std::setw(16)               << "distanceToOut" << " "
00282            << std::setw(4+precVerf)       << localDirection << " "
00283            << G4endl;
00284     G4cout.precision(oldprec);      
00285   }
00286 }
00287 
00288 void
00289 G4NavigationLogger::ComputeSafetyLog(const G4VSolid* solid,
00290                                      const G4ThreeVector& point,
00291                                            G4double safety,
00292                                            G4bool banner) const
00293 {
00294   G4String volumeType = "Daughter ";
00295   if (banner)
00296   {
00297     G4cout << "************** " << fId << "::ComputeSafety() ****************" << G4endl;
00298     G4cout << " VolType "
00299            << std::setw(15) << "Safety/mm" << " "
00300            << std::setw(52) << "Position (local coordinates)"
00301            << " - Solid" << G4endl;
00302     volumeType = "  Mother ";
00303   }
00304   G4cout << volumeType
00305          << std::setw(15) << safety << " " << point  << " - "
00306          << solid->GetEntityType() << ": " << solid->GetName() << G4endl;
00307 }
00308 
00309 void
00310 G4NavigationLogger::PrintDaughterLog (const G4VSolid* sampleSolid,
00311                                       const G4ThreeVector& samplePoint,
00312                                             G4double sampleSafety,
00313                                             G4double sampleStep) const
00314 {
00315   if ( fVerbose == 1 )
00316   {
00317     G4cout << "Daughter "
00318            << std::setw(15) << sampleSafety << " ";
00319     if (sampleStep)
00320     {
00321       G4cout << std::setw(15) << sampleStep << " ";
00322     }
00323     else
00324     {
00325       G4cout << std::setw(15) << "N/C" << " ";
00326     }
00327     G4cout << samplePoint   << " - "
00328            << sampleSolid->GetEntityType() << ": " << sampleSolid->GetName()
00329            << G4endl;
00330   }
00331 }

Generated on Mon May 27 17:48:57 2013 for Geant4 by  doxygen 1.4.7