Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/geometry/navigation/src/G4VoxelNavigation.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /geometry/navigation/src/G4VoxelNavigation.cc (Version 11.3.0) and /geometry/navigation/src/G4VoxelNavigation.cc (Version 9.1.p2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
                                                   >>  26 //
                                                   >>  27 // $Id: G4VoxelNavigation.cc,v 1.7 2007/05/11 13:43:59 gcosmo Exp $
                                                   >>  28 // GEANT4 tag $Name: geant4-09-01-patch-02 $
                                                   >>  29 //
                                                   >>  30 //
 26 // class G4VoxelNavigation Implementation          31 // class G4VoxelNavigation Implementation
 27 //                                                 32 //
 28 // Author: P.Kent, 1996                            33 // Author: P.Kent, 1996
 29 //                                                 34 //
 30 // -------------------------------------------     35 // --------------------------------------------------------------------
                                                   >>  36 
 31 #include "G4VoxelNavigation.hh"                    37 #include "G4VoxelNavigation.hh"
 32 #include "G4GeometryTolerance.hh"                  38 #include "G4GeometryTolerance.hh"
 33 #include "G4VoxelSafety.hh"                    << 
 34                                                << 
 35 #include "G4AuxiliaryNavServices.hh"           << 
 36                                                << 
 37 #include <cassert>                             << 
 38 #include <ostream>                             << 
 39                                                    39 
 40 // *******************************************     40 // ********************************************************************
 41 // Constructor                                     41 // Constructor
 42 // *******************************************     42 // ********************************************************************
 43 //                                                 43 //
 44 G4VoxelNavigation::G4VoxelNavigation()             44 G4VoxelNavigation::G4VoxelNavigation()
 45   : fVoxelAxisStack(kNavigatorVoxelStackMax,kX <<  45   : fVoxelDepth(-1),
                                                   >>  46     fVoxelAxisStack(kNavigatorVoxelStackMax,kXAxis),
 46     fVoxelNoSlicesStack(kNavigatorVoxelStackMa     47     fVoxelNoSlicesStack(kNavigatorVoxelStackMax,0),
 47     fVoxelSliceWidthStack(kNavigatorVoxelStack     48     fVoxelSliceWidthStack(kNavigatorVoxelStackMax,0.),
 48     fVoxelNodeNoStack(kNavigatorVoxelStackMax,     49     fVoxelNodeNoStack(kNavigatorVoxelStackMax,0),
 49     fVoxelHeaderStack(kNavigatorVoxelStackMax, <<  50     fVoxelHeaderStack(kNavigatorVoxelStackMax,(G4SmartVoxelHeader*)0),
                                                   >>  51     fVoxelNode(0),
                                                   >>  52     fCheck(false),
                                                   >>  53     fVerbose(0)
 50 {                                                  54 {
 51   fLogger= new G4NavigationLogger("G4VoxelNavi <<  55   kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
 52   fpVoxelSafety= new G4VoxelSafety();          << 
 53   fHalfTolerance= 0.5*G4GeometryTolerance::Get << 
 54                                                << 
 55 #ifdef G4DEBUG_NAVIGATION                      << 
 56   SetVerboseLevel(5);   // Reports most about  << 
 57 #endif                                         << 
 58 }                                                  56 }
 59                                                    57 
 60 // *******************************************     58 // ********************************************************************
 61 // Destructor                                      59 // Destructor
 62 // *******************************************     60 // ********************************************************************
 63 //                                                 61 //
 64 G4VoxelNavigation::~G4VoxelNavigation()            62 G4VoxelNavigation::~G4VoxelNavigation()
 65 {                                                  63 {
 66   delete fpVoxelSafety;                        <<  64 #ifdef G4DEBUG_NAVIGATION
 67   delete fLogger;                              <<  65   G4cout << "G4VoxelNavigation::~G4VoxelNavigation() called." << G4endl;
                                                   >>  66 #endif
 68 }                                                  67 }
 69                                                    68 
 70 // ------------------------------------------- << 
 71 // Input:                                      << 
 72 //    exiting:         : last step exited      << 
 73 //    blockedPhysical  : phys volume last exit << 
 74 //    blockedReplicaNo : copy/replica number o << 
 75 // Output:                                     << 
 76 //    entering         : if true, found candid << 
 77 //    blockedPhysical  : candidate phys volume << 
 78 //    blockedReplicaNo : copy/replica number   << 
 79 //    exiting:         : will exit current (mo << 
 80 // In/Out                                      << 
 81 // ------------------------------------------- << 
 82                                                << 
 83 // *******************************************     69 // ********************************************************************
 84 // ComputeStep                                     70 // ComputeStep
 85 // *******************************************     71 // ********************************************************************
 86 //                                                 72 //
 87 G4double                                           73 G4double
 88 G4VoxelNavigation::ComputeStep( const G4ThreeV     74 G4VoxelNavigation::ComputeStep( const G4ThreeVector& localPoint,
 89                                 const G4ThreeV     75                                 const G4ThreeVector& localDirection,
 90                                 const G4double     76                                 const G4double currentProposedStepLength,
 91                                       G4double     77                                       G4double& newSafety,
 92                           /* const */ G4Naviga <<  78                                       G4NavigationHistory& history,
 93                                       G4bool&      79                                       G4bool& validExitNormal,
 94                                       G4ThreeV     80                                       G4ThreeVector& exitNormal,
 95                                       G4bool&      81                                       G4bool& exiting,
 96                                       G4bool&      82                                       G4bool& entering,
 97                                       G4VPhysi <<  83                                       G4VPhysicalVolume *(*pBlockedPhysical),
 98                                       G4int& b     84                                       G4int& blockedReplicaNo )
 99 {                                                  85 {
100   G4VPhysicalVolume *motherPhysical, *samplePh <<  86   G4VPhysicalVolume *motherPhysical, *samplePhysical, *blockedExitedVol=0;
101   G4LogicalVolume *motherLogical;                  87   G4LogicalVolume *motherLogical;
102   G4VSolid *motherSolid;                           88   G4VSolid *motherSolid;
103   G4ThreeVector sampleDirection;                   89   G4ThreeVector sampleDirection;
104   G4double ourStep=currentProposedStepLength,  <<  90   G4double ourStep=currentProposedStepLength, motherSafety, ourSafety;
105   G4double motherSafety, motherStep = DBL_MAX; << 
106   G4int localNoDaughters, sampleNo;                91   G4int localNoDaughters, sampleNo;
107                                                    92 
108   G4bool initialNode, noStep;                      93   G4bool initialNode, noStep;
109   G4SmartVoxelNode *curVoxelNode;                  94   G4SmartVoxelNode *curVoxelNode;
110   G4long curNoVolumes, contentNo;              <<  95   G4int curNoVolumes, contentNo;
111   G4double voxelSafety;                            96   G4double voxelSafety;
112                                                    97 
113   motherPhysical = history.GetTopVolume();         98   motherPhysical = history.GetTopVolume();
114   motherLogical = motherPhysical->GetLogicalVo     99   motherLogical = motherPhysical->GetLogicalVolume();
115   motherSolid = motherLogical->GetSolid();        100   motherSolid = motherLogical->GetSolid();
116                                                   101 
117   //                                              102   //
118   // Compute mother safety                        103   // Compute mother safety
119   //                                              104   //
120                                                   105 
121   motherSafety = motherSolid->DistanceToOut(lo    106   motherSafety = motherSolid->DistanceToOut(localPoint);
122   ourSafety = motherSafety;                 //    107   ourSafety = motherSafety;                 // Working isotropic safety
123                                                   108   
124 #ifdef G4VERBOSE                                  109 #ifdef G4VERBOSE
125   if ( fCheck )                                   110   if ( fCheck )
126   {                                               111   {
127     fLogger->PreComputeStepLog (motherPhysical << 112     if(fVerbose == 1 )
                                                   >> 113     {
                                                   >> 114       G4cout << "*** G4VoxelNavigation::ComputeStep(): ***" << G4endl
                                                   >> 115              << "    Invoked DistanceToOut(p) for mother solid: "
                                                   >> 116              << motherSolid->GetName()
                                                   >> 117              << ". Solid replied: " << motherSafety << G4endl
                                                   >> 118              << "    For local point p: " << localPoint
                                                   >> 119              << ", to be considered as 'mother safety'." << G4endl;
                                                   >> 120     }
                                                   >> 121     if( motherSafety < 0.0 )
                                                   >> 122     {
                                                   >> 123       G4cout << "ERROR - G4VoxelNavigation::ComputeStep()" << G4endl
                                                   >> 124              << "        Current solid " << motherSolid->GetName()
                                                   >> 125              << " gave negative safety: " << motherSafety << G4endl
                                                   >> 126              << "        for the current (local) point " << localPoint
                                                   >> 127              << G4endl;
                                                   >> 128       motherSolid->DumpInfo();
                                                   >> 129       G4Exception("G4VoxelNavigation::ComputeStep()",
                                                   >> 130                   "NegativeSafetyMotherVol", FatalException,
                                                   >> 131                   "Negative Safety In Voxel Navigation !" ); 
                                                   >> 132     }
                                                   >> 133     if( motherSolid->Inside(localPoint)==kOutside )
                                                   >> 134     { 
                                                   >> 135       G4cout << "WARNING - G4VoxelNavigation::ComputeStep()" << G4endl
                                                   >> 136              << "          Point " << localPoint
                                                   >> 137              << " is outside current volume " << motherPhysical->GetName()
                                                   >> 138              << G4endl;
                                                   >> 139       G4double  estDistToSolid= motherSolid->DistanceToIn(localPoint); 
                                                   >> 140       G4cout << "          Estimated isotropic distance to solid (distToIn)= " 
                                                   >> 141              << estDistToSolid << G4endl;
                                                   >> 142       if( estDistToSolid > 100.0 * kCarTolerance )
                                                   >> 143       {
                                                   >> 144         motherSolid->DumpInfo();
                                                   >> 145         G4Exception("G4VoxelNavigation::ComputeStep()",
                                                   >> 146                     "FarOutsideCurrentVolume", FatalException,
                                                   >> 147                     "Point is far outside Current Volume !"); 
                                                   >> 148       }
                                                   >> 149       else
                                                   >> 150         G4Exception("G4VoxelNavigation::ComputeStep()", "OutsideCurrentVolume", 
                                                   >> 151                     JustWarning, "Point is a little outside Current Volume."); 
                                                   >> 152     }
128   }                                               153   }
129 #endif                                            154 #endif
130                                                   155 
131   //                                              156   //
132   // Compute daughter safeties & intersections    157   // Compute daughter safeties & intersections
133   //                                              158   //
134                                                   159 
135   // Exiting normal optimisation                  160   // Exiting normal optimisation
136   //                                              161   //
137   if ( exiting && validExitNormal )               162   if ( exiting && validExitNormal )
138   {                                               163   {
139     if ( localDirection.dot(exitNormal)>=kMinE    164     if ( localDirection.dot(exitNormal)>=kMinExitingNormalCosine )
140     {                                             165     {
141       // Block exited daughter volume             166       // Block exited daughter volume
142       //                                          167       //
143       blockedExitedVol = *pBlockedPhysical;       168       blockedExitedVol = *pBlockedPhysical;
144       ourSafety = 0;                              169       ourSafety = 0;
145     }                                             170     }
146   }                                               171   }
147   exiting = false;                                172   exiting = false;
148   entering = false;                               173   entering = false;
149                                                   174 
150   // For extra checking,  get the distance to  << 175   localNoDaughters = motherLogical->GetNoDaughters();
151   G4bool motherValidExitNormal = false;        << 
152   G4ThreeVector motherExitNormal(0.0, 0.0, 0.0 << 
153                                                << 
154 #ifdef G4VERBOSE                               << 
155   if ( fCheck )                                << 
156   {                                            << 
157     // Compute early -- a) for validity        << 
158     //                  b) to check against an << 
159     motherStep = motherSolid->DistanceToOut(lo << 
160                                             lo << 
161                                             tr << 
162                                            &mo << 
163                                            &mo << 
164   }                                            << 
165 #endif                                         << 
166                                                << 
167   localNoDaughters = (G4int)motherLogical->Get << 
168                                                   176 
169   fBList.Enlarge(localNoDaughters);               177   fBList.Enlarge(localNoDaughters);
170   fBList.Reset();                                 178   fBList.Reset();
171                                                   179 
172   initialNode = true;                             180   initialNode = true;
173   noStep = true;                                  181   noStep = true;
174                                                   182 
175   while (noStep)                                  183   while (noStep)
176   {                                               184   {
177     curVoxelNode = fVoxelNode;                    185     curVoxelNode = fVoxelNode;
178     curNoVolumes = curVoxelNode->GetNoContaine    186     curNoVolumes = curVoxelNode->GetNoContained();
179     for (contentNo=curNoVolumes-1; contentNo>=    187     for (contentNo=curNoVolumes-1; contentNo>=0; contentNo--)
180     {                                             188     {
181       sampleNo = curVoxelNode->GetVolume((G4in << 189       sampleNo = curVoxelNode->GetVolume(contentNo);
182       if ( !fBList.IsBlocked(sampleNo) )          190       if ( !fBList.IsBlocked(sampleNo) )
183       {                                           191       {
184         fBList.BlockVolume(sampleNo);             192         fBList.BlockVolume(sampleNo);
185         samplePhysical = motherLogical->GetDau    193         samplePhysical = motherLogical->GetDaughter(sampleNo);
186         if ( samplePhysical!=blockedExitedVol     194         if ( samplePhysical!=blockedExitedVol )
187         {                                         195         {
188           G4AffineTransform sampleTf(samplePhy    196           G4AffineTransform sampleTf(samplePhysical->GetRotation(),
189                                      samplePhy    197                                      samplePhysical->GetTranslation());
190           sampleTf.Invert();                      198           sampleTf.Invert();
191           const G4ThreeVector samplePoint =       199           const G4ThreeVector samplePoint =
192                      sampleTf.TransformPoint(l    200                      sampleTf.TransformPoint(localPoint);
193           const G4VSolid *sampleSolid     =       201           const G4VSolid *sampleSolid     =
194                      samplePhysical->GetLogica    202                      samplePhysical->GetLogicalVolume()->GetSolid();
195           const G4double sampleSafety     =       203           const G4double sampleSafety     =
196                      sampleSolid->DistanceToIn    204                      sampleSolid->DistanceToIn(samplePoint);
197                                                << 205 #ifdef G4VERBOSE
                                                   >> 206           if(( fCheck ) && ( fVerbose == 1 ))
                                                   >> 207           {
                                                   >> 208             G4cout << "*** G4VoxelNavigation::ComputeStep(): ***" << G4endl
                                                   >> 209                    << "    Invoked DistanceToIn(p) for daughter solid: "
                                                   >> 210                    << sampleSolid->GetName()
                                                   >> 211                    << ". Solid replied: " << sampleSafety << G4endl
                                                   >> 212                    << "    For local point p: " << samplePoint
                                                   >> 213                    << ", to be considered as 'daughter safety'." << G4endl;
                                                   >> 214           }
                                                   >> 215 #endif
198           if ( sampleSafety<ourSafety )           216           if ( sampleSafety<ourSafety )
199           {                                       217           {
200             ourSafety = sampleSafety;             218             ourSafety = sampleSafety;
201           }                                       219           }
202           if ( sampleSafety<=ourStep )            220           if ( sampleSafety<=ourStep )
203           {                                       221           {
204             sampleDirection = sampleTf.Transfo    222             sampleDirection = sampleTf.TransformAxis(localDirection);
205             G4double sampleStep =                 223             G4double sampleStep =
206                      sampleSolid->DistanceToIn    224                      sampleSolid->DistanceToIn(samplePoint, sampleDirection);
207 #ifdef G4VERBOSE                                  225 #ifdef G4VERBOSE
208             if( fCheck )                       << 226             if(( fCheck ) && ( fVerbose == 1 ))
209             {                                     227             {
210               fLogger->PrintDaughterLog(sample << 228               G4cout << "*** G4VoxelNavigation::ComputeStep(): ***" << G4endl
211                                         sample << 229                      << "    Invoked DistanceToIn(p,v) for daughter solid: "
212                                         sample << 230                      << sampleSolid->GetName()
                                                   >> 231                      << ". Solid replied: " << sampleStep << G4endl
                                                   >> 232                      << "    For local point p: " << samplePoint << G4endl
                                                   >> 233                      << "    Direction v: " << sampleDirection
                                                   >> 234                      << ", to be considered as 'daughter step'." << G4endl;
213             }                                     235             }
214 #endif                                            236 #endif
215             if ( sampleStep<=ourStep )            237             if ( sampleStep<=ourStep )
216             {                                     238             {
217               ourStep = sampleStep;               239               ourStep = sampleStep;
218               entering = true;                    240               entering = true;
219               exiting = false;                    241               exiting = false;
220               *pBlockedPhysical = samplePhysic    242               *pBlockedPhysical = samplePhysical;
221               blockedReplicaNo = -1;              243               blockedReplicaNo = -1;
222 #ifdef G4VERBOSE                                  244 #ifdef G4VERBOSE
223               // Check to see that the resulti    245               // Check to see that the resulting point is indeed in/on volume.
224               // This could be done only for s << 246               // This check could eventually be made only for successful
225               if ( fCheck )                    << 247               // candidate.
                                                   >> 248 
                                                   >> 249               if ( ( fCheck ) && ( sampleStep < kInfinity ) )
226               {                                   250               {
227                 fLogger->AlongComputeStepLog ( << 251                 G4ThreeVector intersectionPoint;
228                   sampleDirection, localDirect << 252                 intersectionPoint= samplePoint + sampleStep * sampleDirection;
                                                   >> 253                 EInside insideIntPt= sampleSolid->Inside(intersectionPoint); 
                                                   >> 254                 G4String solidResponse = "-kInside-";
                                                   >> 255                 if (insideIntPt == kOutside)
                                                   >> 256                   solidResponse = "-kOutside-";
                                                   >> 257                 else if (insideIntPt == kSurface)
                                                   >> 258                   solidResponse = "-kSurface-";
                                                   >> 259                 if( fVerbose == 1 )
                                                   >> 260                 {
                                                   >> 261                   G4cout << "*** G4VoxelNavigation::ComputeStep(): ***"<<G4endl
                                                   >> 262                          << "    Invoked Inside() for solid: "
                                                   >> 263                          << sampleSolid->GetName()
                                                   >> 264                          << ". Solid replied: " << solidResponse << G4endl
                                                   >> 265                          << "    For point p: " << intersectionPoint
                                                   >> 266                          << ", considered as 'intersection' point." << G4endl;
                                                   >> 267                 }
                                                   >> 268                 if( insideIntPt != kSurface )
                                                   >> 269                 {
                                                   >> 270                   G4int oldcoutPrec = G4cout.precision(16); 
                                                   >> 271                   G4cout << "WARNING - G4VoxelNavigation::ComputeStep()"
                                                   >> 272                          << G4endl
                                                   >> 273                          << "          Inaccurate solid DistanceToIn"
                                                   >> 274                          << " for solid " << sampleSolid->GetName() << G4endl;
                                                   >> 275                   G4cout << "          Solid gave DistanceToIn = "
                                                   >> 276                          << sampleStep << " yet returns " << solidResponse
                                                   >> 277                          << " for this point !" << G4endl; 
                                                   >> 278                   G4cout << "          Point = " << intersectionPoint << G4endl;
                                                   >> 279                   if ( insideIntPt != kInside )
                                                   >> 280                     G4cout << "        DistanceToIn(p) = " 
                                                   >> 281                            << sampleSolid->DistanceToIn(intersectionPoint)
                                                   >> 282                            << G4endl;
                                                   >> 283                   if ( insideIntPt != kOutside ) 
                                                   >> 284                     G4cout << "        DistanceToOut(p) = " 
                                                   >> 285                            << sampleSolid->DistanceToOut(intersectionPoint)
                                                   >> 286                            << G4endl;
                                                   >> 287                   G4Exception("G4VoxelNavigation::ComputeStep()", 
                                                   >> 288                               "InaccurateDistanceToIn", JustWarning,
                                                   >> 289                               "Navigator gets conflicting response from Solid.");
                                                   >> 290                   G4cout.precision(oldcoutPrec);
                                                   >> 291                 }
229               }                                   292               }
230 #endif                                            293 #endif
231             }                                     294             }
232 #ifdef G4VERBOSE                               << 
233             if ( fCheck && ( sampleStep < kInf << 
234                         && ( sampleStep >= mot << 
235             {                                  << 
236                // The intersection point with  << 
237                // point from the mother volume << 
238                fLogger->CheckDaughterEntryPoin << 
239                                                << 
240                                                << 
241                                                << 
242                                                << 
243             }                                  << 
244 #endif                                         << 
245           }                                    << 
246 #ifdef G4VERBOSE                               << 
247           else // ie if sampleSafety > outStep << 
248           {                                    << 
249             if( fCheck )                       << 
250             {                                  << 
251               fLogger->PrintDaughterLog(sample << 
252                                         sample << 
253                                         G4Thre << 
254             }                                  << 
255           }                                       295           }
256 #endif                                         << 
257         }                                         296         }
258       }                                           297       }
259     }                                             298     }
260     if (initialNode)                              299     if (initialNode)
261     {                                             300     {
262       initialNode = false;                        301       initialNode = false;
263       voxelSafety = ComputeVoxelSafety(localPo    302       voxelSafety = ComputeVoxelSafety(localPoint);
264       if ( voxelSafety<ourSafety )                303       if ( voxelSafety<ourSafety )
265       {                                           304       {
266         ourSafety = voxelSafety;                  305         ourSafety = voxelSafety;
267       }                                           306       }
268       if ( currentProposedStepLength<ourSafety    307       if ( currentProposedStepLength<ourSafety )
269       {                                           308       {
270         // Guaranteed physics limited             309         // Guaranteed physics limited
271         //                                        310         //      
272         noStep = false;                           311         noStep = false;
273         entering = false;                         312         entering = false;
274         exiting = false;                          313         exiting = false;
275         *pBlockedPhysical = nullptr;           << 314         *pBlockedPhysical = 0;
276         ourStep = kInfinity;                      315         ourStep = kInfinity;
277       }                                           316       }
278       else                                        317       else
279       {                                           318       {
280         //                                        319         //
281         // Compute mother intersection if requ    320         // Compute mother intersection if required
282         //                                        321         //
283         if ( motherSafety<=ourStep )              322         if ( motherSafety<=ourStep )
284         {                                         323         {
285           // In case of check mode this is a d << 324           G4double motherStep =
286           motherStep = motherSolid->DistanceTo << 325               motherSolid->DistanceToOut(localPoint,
287                               true, &motherVal << 326                                          localDirection,
                                                   >> 327                                          true, &validExitNormal, &exitNormal);
288 #ifdef G4VERBOSE                                  328 #ifdef G4VERBOSE
289           if ( fCheck )                           329           if ( fCheck )
290           {                                       330           {
291             fLogger->PostComputeStepLog(mother << 331             if(fVerbose == 1)
292                                         mother << 
293             if( motherValidExitNormal )        << 
294             {                                     332             {
295               fLogger->CheckAndReportBadNormal << 333               G4cout << "*** G4VoxelNavigation::ComputeStep(): ***" << G4endl
296                                                << 334                      << "    Invoked DistanceToOut(p,v,...) for mother solid: "
297                                                << 335                      << motherSolid->GetName()
298                                         "From  << 336                      << ". Solid replied: " << motherStep << G4endl
                                                   >> 337                      << "    For local point p: " << localPoint << G4endl
                                                   >> 338                      << "    Direction v: " << localDirection
                                                   >> 339                      << ", to be considered as 'mother step'." << G4endl;
299             }                                     340             }
300           }                                    << 341             if( ( motherStep < 0.0 ) || ( motherStep >= kInfinity) )
301 #endif                                         << 
302           if( (motherStep >= kInfinity) || (mo << 
303           {                                    << 
304 #ifdef G4VERBOSE                               << 
305             if( fCheck ) // Error - indication << 
306             {                                     342             {
307               fLogger->ReportOutsideMother(loc << 343               G4int oldPrOut= G4cout.precision(16); 
308                                            mot << 344               G4int oldPrErr= G4cerr.precision(16);
                                                   >> 345               G4cerr << "ERROR - G4VoxelNavigation::ComputeStep()" << G4endl
                                                   >> 346                      << "        Problem in Navigation"  << G4endl
                                                   >> 347                      << "        Point (local coordinates): "
                                                   >> 348                      << localPoint << G4endl
                                                   >> 349                      << "        Local Direction: " << localDirection << G4endl
                                                   >> 350                      << "        Solid: " << motherSolid->GetName() << G4endl; 
                                                   >> 351               motherSolid->DumpInfo();
                                                   >> 352               G4Exception("G4VoxelNavigation::ComputeStep()",
                                                   >> 353                           "PointOutsideCurrentVolume", FatalException,
                                                   >> 354                           "Current point is outside the current solid !");
                                                   >> 355               G4cout.precision(oldPrOut);
                                                   >> 356               G4cerr.precision(oldPrErr);
309             }                                     357             }
                                                   >> 358           }
310 #endif                                            359 #endif
311             motherStep = 0.0;                  << 
312             ourStep = 0.0;                     << 
313             exiting = true;                    << 
314             entering = false;                  << 
315                                                << 
316             // validExitNormal= motherValidExi << 
317             // exitNormal= motherExitNormal;   << 
318             // Useful only if the point is ver << 
319             // => but it would need to be rota << 
320             validExitNormal= false;            << 
321                                                << 
322             *pBlockedPhysical = nullptr; // or << 
323             blockedReplicaNo = 0;  // or mothe << 
324                                                << 
325             newSafety = 0.0;                   << 
326             return ourStep;                    << 
327           }                                    << 
328                                                << 
329           if ( motherStep<=ourStep )              360           if ( motherStep<=ourStep )
330           {                                       361           {
331             ourStep = motherStep;                 362             ourStep = motherStep;
332             exiting = true;                       363             exiting = true;
333             entering = false;                     364             entering = false;
334                                                << 
335             // Exit normal: Natural location t << 
336             //                                 << 
337             validExitNormal = motherValidExitN << 
338             exitNormal = motherExitNormal;     << 
339                                                << 
340             if ( validExitNormal )                365             if ( validExitNormal )
341             {                                     366             {
342               const G4RotationMatrix *rot = mo    367               const G4RotationMatrix *rot = motherPhysical->GetRotation();
343               if (rot != nullptr)              << 368               if (rot)
344               {                                   369               {
345                 exitNormal *= rot->inverse();     370                 exitNormal *= rot->inverse();
346 #ifdef G4VERBOSE                               << 
347                 if( fCheck )                   << 
348                 {                              << 
349                   fLogger->CheckAndReportBadNo << 
350                                                << 
351                                                << 
352                                                << 
353                 }                              << 
354 #endif                                         << 
355               }                                   371               }
356             }                                  << 372             }  
357           }                                       373           }
358           else                                    374           else
359           {                                       375           {
360             validExitNormal = false;              376             validExitNormal = false;
361           }                                       377           }
362         }                                         378         }
363       }                                           379       }
364       newSafety = ourSafety;                      380       newSafety = ourSafety;
365     }                                             381     }
366     if (noStep)                                   382     if (noStep)
367     {                                             383     {
368       noStep = LocateNextVoxel(localPoint, loc    384       noStep = LocateNextVoxel(localPoint, localDirection, ourStep);
369     }                                             385     }
370   }  // end -while (noStep)- loop                 386   }  // end -while (noStep)- loop
371                                                   387 
372   return ourStep;                                 388   return ourStep;
373 }                                                 389 }
374                                                   390 
375 // *******************************************    391 // ********************************************************************
376 // ComputeVoxelSafety                             392 // ComputeVoxelSafety
377 //                                                393 //
378 // Computes safety from specified point to vox    394 // Computes safety from specified point to voxel boundaries
379 // using already located point                    395 // using already located point
380 // o collected boundaries for most derived lev    396 // o collected boundaries for most derived level
381 // o adjacent boundaries for previous levels      397 // o adjacent boundaries for previous levels
382 // *******************************************    398 // ********************************************************************
383 //                                                399 //
384 G4double                                          400 G4double
385 G4VoxelNavigation::ComputeVoxelSafety(const G4    401 G4VoxelNavigation::ComputeVoxelSafety(const G4ThreeVector& localPoint) const
386 {                                                 402 {
387   G4SmartVoxelHeader *curHeader;                  403   G4SmartVoxelHeader *curHeader;
388   G4double voxelSafety, curNodeWidth;             404   G4double voxelSafety, curNodeWidth;
389   G4double curNodeOffset, minCurCommonDelta, m    405   G4double curNodeOffset, minCurCommonDelta, maxCurCommonDelta;
390   G4int minCurNodeNoDelta, maxCurNodeNoDelta;     406   G4int minCurNodeNoDelta, maxCurNodeNoDelta;
391   G4int localVoxelDepth, curNodeNo;               407   G4int localVoxelDepth, curNodeNo;
392   EAxis curHeaderAxis;                            408   EAxis curHeaderAxis;
393                                                   409 
394   localVoxelDepth = fVoxelDepth;                  410   localVoxelDepth = fVoxelDepth;
395                                                   411 
396   curHeader = fVoxelHeaderStack[localVoxelDept    412   curHeader = fVoxelHeaderStack[localVoxelDepth];
397   curHeaderAxis = fVoxelAxisStack[localVoxelDe    413   curHeaderAxis = fVoxelAxisStack[localVoxelDepth];
398   curNodeNo = fVoxelNodeNoStack[localVoxelDept    414   curNodeNo = fVoxelNodeNoStack[localVoxelDepth];
399   curNodeWidth = fVoxelSliceWidthStack[localVo    415   curNodeWidth = fVoxelSliceWidthStack[localVoxelDepth];
400                                                   416   
401   // Compute linear intersection distance to b    417   // Compute linear intersection distance to boundaries of max/min
402   // to collected nodes at current level          418   // to collected nodes at current level
403   //                                              419   //
404   curNodeOffset = curNodeNo*curNodeWidth;         420   curNodeOffset = curNodeNo*curNodeWidth;
405   maxCurNodeNoDelta = fVoxelNode->GetMaxEquiva    421   maxCurNodeNoDelta = fVoxelNode->GetMaxEquivalentSliceNo()-curNodeNo;
406   minCurNodeNoDelta = curNodeNo-fVoxelNode->Ge    422   minCurNodeNoDelta = curNodeNo-fVoxelNode->GetMinEquivalentSliceNo();
407   minCurCommonDelta = localPoint(curHeaderAxis    423   minCurCommonDelta = localPoint(curHeaderAxis)
408                       - curHeader->GetMinExten    424                       - curHeader->GetMinExtent() - curNodeOffset;
409   maxCurCommonDelta = curNodeWidth-minCurCommo    425   maxCurCommonDelta = curNodeWidth-minCurCommonDelta;
410                                                   426 
411   if ( minCurNodeNoDelta<maxCurNodeNoDelta )      427   if ( minCurNodeNoDelta<maxCurNodeNoDelta )
412   {                                               428   {
413     voxelSafety = minCurNodeNoDelta*curNodeWid    429     voxelSafety = minCurNodeNoDelta*curNodeWidth;
414     voxelSafety += minCurCommonDelta;             430     voxelSafety += minCurCommonDelta;
415   }                                               431   }
416   else if (maxCurNodeNoDelta < minCurNodeNoDel    432   else if (maxCurNodeNoDelta < minCurNodeNoDelta)
417   {                                            << 433        {
418     voxelSafety = maxCurNodeNoDelta*curNodeWid << 434          voxelSafety = maxCurNodeNoDelta*curNodeWidth;
419     voxelSafety += maxCurCommonDelta;          << 435          voxelSafety += maxCurCommonDelta;
420   }                                            << 436         }
421   else    // (maxCurNodeNoDelta == minCurNodeN << 437         else    // (maxCurNodeNoDelta == minCurNodeNoDelta)
422   {                                            << 438         {
423     voxelSafety = minCurNodeNoDelta*curNodeWid << 439           voxelSafety = minCurNodeNoDelta*curNodeWidth;
424     voxelSafety += std::min(minCurCommonDelta, << 440           voxelSafety += std::min(minCurCommonDelta,maxCurCommonDelta);
425   }                                            << 441         }
426                                                   442 
427   // Compute isotropic safety to boundaries of    443   // Compute isotropic safety to boundaries of previous levels
428   // [NOT to collected boundaries]                444   // [NOT to collected boundaries]
429                                                << 445   //
430   // Loop checking, 07.10.2016, JA             << 
431   while ( (localVoxelDepth>0) && (voxelSafety>    446   while ( (localVoxelDepth>0) && (voxelSafety>0) )
432   {                                               447   {
433     localVoxelDepth--;                            448     localVoxelDepth--;
434     curHeader = fVoxelHeaderStack[localVoxelDe    449     curHeader = fVoxelHeaderStack[localVoxelDepth];
435     curHeaderAxis = fVoxelAxisStack[localVoxel    450     curHeaderAxis = fVoxelAxisStack[localVoxelDepth];
436     curNodeNo = fVoxelNodeNoStack[localVoxelDe    451     curNodeNo = fVoxelNodeNoStack[localVoxelDepth];
437     curNodeWidth = fVoxelSliceWidthStack[local    452     curNodeWidth = fVoxelSliceWidthStack[localVoxelDepth];
438     curNodeOffset = curNodeNo*curNodeWidth;       453     curNodeOffset = curNodeNo*curNodeWidth;
439     minCurCommonDelta = localPoint(curHeaderAx    454     minCurCommonDelta = localPoint(curHeaderAxis)
440                         - curHeader->GetMinExt    455                         - curHeader->GetMinExtent() - curNodeOffset;
441     maxCurCommonDelta = curNodeWidth-minCurCom    456     maxCurCommonDelta = curNodeWidth-minCurCommonDelta;
442                                                   457     
443     if ( minCurCommonDelta<voxelSafety )          458     if ( minCurCommonDelta<voxelSafety )
444     {                                             459     {
445       voxelSafety = minCurCommonDelta;            460       voxelSafety = minCurCommonDelta;
446     }                                             461     }
447     if ( maxCurCommonDelta<voxelSafety )          462     if ( maxCurCommonDelta<voxelSafety )
448     {                                             463     {
449       voxelSafety = maxCurCommonDelta;            464       voxelSafety = maxCurCommonDelta;
450     }                                             465     }
451   }                                               466   }
452   if ( voxelSafety<0 )                            467   if ( voxelSafety<0 )
453   {                                               468   {
454     voxelSafety = 0;                              469     voxelSafety = 0;
455   }                                               470   }
456                                                   471 
457   return voxelSafety;                             472   return voxelSafety;
458 }                                                 473 }
459                                                   474 
460 // *******************************************    475 // ********************************************************************
461 // LocateNextVoxel                                476 // LocateNextVoxel
462 //                                                477 //
463 // Finds the next voxel from the current voxel    478 // Finds the next voxel from the current voxel and point
464 // in the specified direction                     479 // in the specified direction
465 //                                                480 //
466 // Returns false if all voxels considered         481 // Returns false if all voxels considered
467 //              [current Step ends inside same    482 //              [current Step ends inside same voxel or leaves all voxels]
468 //         true  otherwise                        483 //         true  otherwise
469 //              [the information on the next v    484 //              [the information on the next voxel is put into the set of
470 //               fVoxel* variables & "stacks"]    485 //               fVoxel* variables & "stacks"] 
471 // *******************************************    486 // ********************************************************************
472 //                                                487 // 
473 G4bool                                            488 G4bool
474 G4VoxelNavigation::LocateNextVoxel(const G4Thr    489 G4VoxelNavigation::LocateNextVoxel(const G4ThreeVector& localPoint,
475                                    const G4Thr    490                                    const G4ThreeVector& localDirection,
476                                    const G4dou    491                                    const G4double currentStep)
477 {                                                 492 {
478   G4SmartVoxelHeader *workHeader=nullptr, *new << 493   G4SmartVoxelHeader *workHeader=0, *newHeader=0;
479   G4SmartVoxelProxy *newProxy=nullptr;         << 494   G4SmartVoxelProxy *newProxy=0;
480   G4SmartVoxelNode *newVoxelNode=nullptr;      << 495   G4SmartVoxelNode *newVoxelNode=0;
481   G4ThreeVector targetPoint, voxelPoint;          496   G4ThreeVector targetPoint, voxelPoint;
482   G4double workNodeWidth, workMinExtent, workC    497   G4double workNodeWidth, workMinExtent, workCoord;
483   G4double minVal, maxVal, newDistance=0.;        498   G4double minVal, maxVal, newDistance=0.;
484   G4double newHeaderMin, newHeaderNodeWidth;      499   G4double newHeaderMin, newHeaderNodeWidth;
485   G4int depth=0, newDepth=0, workNodeNo=0, new    500   G4int depth=0, newDepth=0, workNodeNo=0, newNodeNo=0, newHeaderNoSlices=0;
486   EAxis workHeaderAxis, newHeaderAxis;            501   EAxis workHeaderAxis, newHeaderAxis;
487   G4bool isNewVoxel = false;                   << 502   G4bool isNewVoxel=false;
488                                                   503   
489   G4double currentDistance = currentStep;         504   G4double currentDistance = currentStep;
490                                                   505 
491   // Determine if end of Step within current v    506   // Determine if end of Step within current voxel
492   //                                              507   //
493   for (depth=0; depth<fVoxelDepth; ++depth)    << 508   for (depth=0; depth<fVoxelDepth; depth++)
494   {                                               509   {
495     targetPoint = localPoint+localDirection*cu    510     targetPoint = localPoint+localDirection*currentDistance;
496     newDistance = currentDistance;                511     newDistance = currentDistance;
497     workHeader = fVoxelHeaderStack[depth];        512     workHeader = fVoxelHeaderStack[depth];
498     workHeaderAxis = fVoxelAxisStack[depth];      513     workHeaderAxis = fVoxelAxisStack[depth];
499     workNodeNo = fVoxelNodeNoStack[depth];        514     workNodeNo = fVoxelNodeNoStack[depth];
500     workNodeWidth = fVoxelSliceWidthStack[dept    515     workNodeWidth = fVoxelSliceWidthStack[depth];
501     workMinExtent = workHeader->GetMinExtent()    516     workMinExtent = workHeader->GetMinExtent();
502     workCoord = targetPoint(workHeaderAxis);      517     workCoord = targetPoint(workHeaderAxis);
503     minVal = workMinExtent+workNodeNo*workNode    518     minVal = workMinExtent+workNodeNo*workNodeWidth;
504                                                   519 
505     if ( minVal<=workCoord+fHalfTolerance )    << 520     if ( minVal<=workCoord+kCarTolerance*0.5 )
506     {                                             521     {
507       maxVal = minVal+workNodeWidth;              522       maxVal = minVal+workNodeWidth;
508       if ( maxVal<=workCoord-fHalfTolerance )  << 523       if ( maxVal<=workCoord-kCarTolerance*0.5 )
509       {                                           524       {
510         // Must consider next voxel               525         // Must consider next voxel
511         //                                        526         //
512         newNodeNo = workNodeNo+1;                 527         newNodeNo = workNodeNo+1;
513         newHeader = workHeader;                   528         newHeader = workHeader;
514         newDistance = (maxVal-localPoint(workH    529         newDistance = (maxVal-localPoint(workHeaderAxis))
515                     / localDirection(workHeade    530                     / localDirection(workHeaderAxis);
516         isNewVoxel = true;                        531         isNewVoxel = true;
517         newDepth = depth;                         532         newDepth = depth;
518       }                                           533       }
519     }                                             534     }
520     else                                          535     else
521     {                                             536     {
522       newNodeNo = workNodeNo-1;                   537       newNodeNo = workNodeNo-1;
523       newHeader = workHeader;                     538       newHeader = workHeader;
524       newDistance = (minVal-localPoint(workHea    539       newDistance = (minVal-localPoint(workHeaderAxis))
525                   / localDirection(workHeaderA    540                   / localDirection(workHeaderAxis);
526       isNewVoxel = true;                          541       isNewVoxel = true;
527       newDepth = depth;                           542       newDepth = depth;
528     }                                             543     }
529     currentDistance = newDistance;                544     currentDistance = newDistance;
530   }                                               545   }
531   targetPoint = localPoint+localDirection*curr    546   targetPoint = localPoint+localDirection*currentDistance;
532                                                   547 
533   // Check if end of Step within collected bou    548   // Check if end of Step within collected boundaries of current voxel
534   //                                              549   //
535   depth = fVoxelDepth;                            550   depth = fVoxelDepth;
536   {                                               551   {
537     workHeader = fVoxelHeaderStack[depth];        552     workHeader = fVoxelHeaderStack[depth];
538     workHeaderAxis = fVoxelAxisStack[depth];      553     workHeaderAxis = fVoxelAxisStack[depth];
539     workNodeNo = fVoxelNodeNoStack[depth];        554     workNodeNo = fVoxelNodeNoStack[depth];
540     workNodeWidth = fVoxelSliceWidthStack[dept    555     workNodeWidth = fVoxelSliceWidthStack[depth];
541     workMinExtent = workHeader->GetMinExtent()    556     workMinExtent = workHeader->GetMinExtent();
542     workCoord = targetPoint(workHeaderAxis);      557     workCoord = targetPoint(workHeaderAxis);
543     minVal = workMinExtent+fVoxelNode->GetMinE    558     minVal = workMinExtent+fVoxelNode->GetMinEquivalentSliceNo()*workNodeWidth;
544                                                   559 
545     if ( minVal<=workCoord+fHalfTolerance )    << 560     if ( minVal<=workCoord+kCarTolerance*0.5 )
546     {                                             561     {
547       maxVal = workMinExtent+(fVoxelNode->GetM    562       maxVal = workMinExtent+(fVoxelNode->GetMaxEquivalentSliceNo()+1)
548                             *workNodeWidth;       563                             *workNodeWidth;
549       if ( maxVal<=workCoord-fHalfTolerance )  << 564       if ( maxVal<=workCoord-kCarTolerance*0.5 )
550       {                                           565       {
551         newNodeNo = fVoxelNode->GetMaxEquivale    566         newNodeNo = fVoxelNode->GetMaxEquivalentSliceNo()+1;
552         newHeader = workHeader;                   567         newHeader = workHeader;
553         newDistance = (maxVal-localPoint(workH    568         newDistance = (maxVal-localPoint(workHeaderAxis))
554                     / localDirection(workHeade    569                     / localDirection(workHeaderAxis);
555         isNewVoxel = true;                        570         isNewVoxel = true;
556         newDepth = depth;                         571         newDepth = depth;
557       }                                           572       }
558     }                                             573     }
559     else                                          574     else
560     {                                             575     {
561       newNodeNo = fVoxelNode->GetMinEquivalent    576       newNodeNo = fVoxelNode->GetMinEquivalentSliceNo()-1;
562       newHeader = workHeader;                     577       newHeader = workHeader;
563       newDistance = (minVal-localPoint(workHea    578       newDistance = (minVal-localPoint(workHeaderAxis))
564                   / localDirection(workHeaderA    579                   / localDirection(workHeaderAxis);
565       isNewVoxel = true;                          580       isNewVoxel = true;
566       newDepth = depth;                           581       newDepth = depth;
567     }                                             582     }
568     currentDistance = newDistance;                583     currentDistance = newDistance;
569   }                                               584   }
570   if (isNewVoxel)                                 585   if (isNewVoxel)
571   {                                               586   {
572     // Compute new voxel & adjust voxel stack     587     // Compute new voxel & adjust voxel stack
573     //                                            588     //
574     // newNodeNo=Candidate node no at             589     // newNodeNo=Candidate node no at 
575     // newDepth =refinement depth of crossed v    590     // newDepth =refinement depth of crossed voxel boundary
576     // newHeader=Header for crossed voxel         591     // newHeader=Header for crossed voxel
577     // newDistance=distance to crossed voxel b    592     // newDistance=distance to crossed voxel boundary (along the track)
578     //                                            593     //
579     if ( (newNodeNo<0) || (newNodeNo>=G4int(ne << 594     if ( (newNodeNo<0) || (newNodeNo>=newHeader->GetNoSlices()))
580     {                                             595     {
581       // Leaving mother volume                    596       // Leaving mother volume
582       //                                          597       //
583       isNewVoxel = false;                         598       isNewVoxel = false;
584     }                                             599     }
585     else                                          600     else
586     {                                             601     {
587       // Compute intersection point on the lea    602       // Compute intersection point on the least refined
588       // voxel boundary that is hit               603       // voxel boundary that is hit
589       //                                          604       //
590       voxelPoint = localPoint+localDirection*n    605       voxelPoint = localPoint+localDirection*newDistance;
591       fVoxelNodeNoStack[newDepth] = newNodeNo;    606       fVoxelNodeNoStack[newDepth] = newNodeNo;
592       fVoxelDepth = newDepth;                     607       fVoxelDepth = newDepth;
593       newVoxelNode = nullptr;                  << 608       newVoxelNode = 0;
594       while ( newVoxelNode == nullptr )        << 609       while ( !newVoxelNode )
595       {                                           610       {
596         newProxy = newHeader->GetSlice(newNode    611         newProxy = newHeader->GetSlice(newNodeNo);
597         if (newProxy->IsNode())                   612         if (newProxy->IsNode())
598         {                                         613         {
599           newVoxelNode = newProxy->GetNode();     614           newVoxelNode = newProxy->GetNode();
600         }                                         615         }
601         else                                      616         else
602         {                                         617         {
603           ++fVoxelDepth;                       << 618           fVoxelDepth++;
604           newHeader = newProxy->GetHeader();      619           newHeader = newProxy->GetHeader();
605           newHeaderAxis = newHeader->GetAxis()    620           newHeaderAxis = newHeader->GetAxis();
606           newHeaderNoSlices = (G4int)newHeader << 621           newHeaderNoSlices = newHeader->GetNoSlices();
607           newHeaderMin = newHeader->GetMinExte    622           newHeaderMin = newHeader->GetMinExtent();
608           newHeaderNodeWidth = (newHeader->Get    623           newHeaderNodeWidth = (newHeader->GetMaxExtent()-newHeaderMin)
609                              / newHeaderNoSlic    624                              / newHeaderNoSlices;
610           newNodeNo = G4int( (voxelPoint(newHe    625           newNodeNo = G4int( (voxelPoint(newHeaderAxis)-newHeaderMin)
611                              / newHeaderNodeWi    626                              / newHeaderNodeWidth );
612           // Rounding protection                  627           // Rounding protection
613           //                                      628           //
614           if ( newNodeNo<0 )                      629           if ( newNodeNo<0 )
615           {                                       630           {
616             newNodeNo=0;                          631             newNodeNo=0;
617           }                                       632           }
618           else if ( newNodeNo>=newHeaderNoSlic    633           else if ( newNodeNo>=newHeaderNoSlices )
619           {                                    << 634                {
620             newNodeNo = newHeaderNoSlices-1;   << 635                  newNodeNo = newHeaderNoSlices-1;
621           }                                    << 636                }
622           // Stack info for stepping              637           // Stack info for stepping
623           //                                      638           //
624           fVoxelAxisStack[fVoxelDepth] = newHe    639           fVoxelAxisStack[fVoxelDepth] = newHeaderAxis;
625           fVoxelNoSlicesStack[fVoxelDepth] = n    640           fVoxelNoSlicesStack[fVoxelDepth] = newHeaderNoSlices;
626           fVoxelSliceWidthStack[fVoxelDepth] =    641           fVoxelSliceWidthStack[fVoxelDepth] = newHeaderNodeWidth;
627           fVoxelNodeNoStack[fVoxelDepth] = new    642           fVoxelNodeNoStack[fVoxelDepth] = newNodeNo;
628           fVoxelHeaderStack[fVoxelDepth] = new    643           fVoxelHeaderStack[fVoxelDepth] = newHeader;
629         }                                         644         }
630       }                                           645       }
631       fVoxelNode = newVoxelNode;                  646       fVoxelNode = newVoxelNode;
632     }                                             647     }
633   }                                               648   }
634   return isNewVoxel;                              649   return isNewVoxel;        
635 }                                                 650 }
636                                                   651 
637 // *******************************************    652 // ********************************************************************
638 // ComputeSafety                                  653 // ComputeSafety
639 //                                                654 //
640 // Calculates the isotropic distance to the ne    655 // Calculates the isotropic distance to the nearest boundary from the
641 // specified point in the local coordinate sys    656 // specified point in the local coordinate system. 
642 // The localpoint utilised must be within the     657 // The localpoint utilised must be within the current volume.
643 // *******************************************    658 // ********************************************************************
644 //                                                659 //
645 G4double                                          660 G4double
646 G4VoxelNavigation::ComputeSafety(const G4Three    661 G4VoxelNavigation::ComputeSafety(const G4ThreeVector& localPoint,
647                                  const G4Navig    662                                  const G4NavigationHistory& history,
648                                  const G4doubl << 663                                  const G4double )
649 {                                                 664 {
650   G4VPhysicalVolume *motherPhysical, *samplePh    665   G4VPhysicalVolume *motherPhysical, *samplePhysical;
651   G4LogicalVolume *motherLogical;                 666   G4LogicalVolume *motherLogical;
652   G4VSolid *motherSolid;                          667   G4VSolid *motherSolid;
653   G4double motherSafety, ourSafety;               668   G4double motherSafety, ourSafety;
654   G4int sampleNo;                              << 669   G4int localNoDaughters, sampleNo;
655   G4SmartVoxelNode *curVoxelNode;                 670   G4SmartVoxelNode *curVoxelNode;
656   G4long curNoVolumes, contentNo;              << 671   G4int curNoVolumes, contentNo;
657   G4double voxelSafety;                           672   G4double voxelSafety;
658                                                   673 
659   motherPhysical = history.GetTopVolume();        674   motherPhysical = history.GetTopVolume();
660   motherLogical = motherPhysical->GetLogicalVo    675   motherLogical = motherPhysical->GetLogicalVolume();
661   motherSolid = motherLogical->GetSolid();        676   motherSolid = motherLogical->GetSolid();
662                                                   677 
663   if( fBestSafety )                            << 
664   {                                            << 
665     return fpVoxelSafety->ComputeSafety( local << 
666   }                                            << 
667                                                << 
668   //                                              678   //
669   // Compute mother safety                        679   // Compute mother safety
670   //                                              680   //
671                                                   681 
672   motherSafety = motherSolid->DistanceToOut(lo    682   motherSafety = motherSolid->DistanceToOut(localPoint);
673   ourSafety = motherSafety;                 //    683   ourSafety = motherSafety;                 // Working isotropic safety
674                                                   684 
675   if( motherSafety == 0.0 )                    << 
676   {                                            << 
677 #ifdef G4DEBUG_NAVIGATION                      << 
678     // Check that point is inside mother volum << 
679     EInside  insideMother = motherSolid->Insid << 
680                                                << 
681     if( insideMother == kOutside )             << 
682     {                                          << 
683       G4ExceptionDescription message;          << 
684       message << "Safety method called for loc << 
685          << "Location for safety is Outside th << 
686          << "The approximate distance to the s << 
687          << "(safety from outside) is: "       << 
688          << motherSolid->DistanceToIn( localPo << 
689       message << "  Problem occurred with phys << 
690          << " Name: " << motherPhysical->GetNa << 
691          << " Copy No: " << motherPhysical->Ge << 
692          << "    Local Point = " << localPoint << 
693       message << "  Description of solid: " << << 
694             << *motherSolid << G4endl;         << 
695       G4Exception("G4VoxelNavigation::ComputeS << 
696                   JustWarning, message);       << 
697     }                                          << 
698                                                << 
699     // Following check is NOT for an issue - i << 
700     //  It is allowed that a solid gives appro << 
701     //                                         << 
702     if( insideMother == kInside ) // && fVerbo << 
703     {                                          << 
704       G4ExceptionDescription messageIn;        << 
705                                                << 
706       messageIn << " Point is Inside, but safe << 
707       messageIn << " Inexact safety for volume << 
708              << "  Solid: Name= " << motherSol << 
709              << "   Type= " << motherSolid->Ge << 
710       messageIn << "  Local point= " << localP << 
711       messageIn << "  Solid parameters: " << G << 
712       G4Exception("G4VoxelNavigation::ComputeS << 
713                   JustWarning, messageIn);     << 
714     }                                          << 
715 #endif                                         << 
716     // if( insideMother != kInside )           << 
717     return 0.0;                                << 
718   }                                            << 
719                                                << 
720 #ifdef G4VERBOSE                                  685 #ifdef G4VERBOSE
721   if( fCheck )                                 << 686   if(( fCheck ) && ( fVerbose == 1 ))
722   {                                               687   {
723     fLogger->ComputeSafetyLog (motherSolid,loc << 688     G4cout << "*** G4VoxelNavigation::ComputeSafety(): ***" << G4endl
                                                   >> 689            << "    Invoked DistanceToOut(p) for mother solid: "
                                                   >> 690            << motherSolid->GetName()
                                                   >> 691            << ". Solid replied: " << motherSafety << G4endl
                                                   >> 692            << "    For local point p: " << localPoint
                                                   >> 693            << ", to be considered as 'mother safety'." << G4endl;
724   }                                               694   }
725 #endif                                            695 #endif
726   //                                              696   //
727   // Compute daughter safeties                 << 697   // Compute daughter safeties 
728   //                                              698   //
729   // Look only inside the current Voxel only ( << 699 
                                                   >> 700   localNoDaughters = motherLogical->GetNoDaughters();
                                                   >> 701 
                                                   >> 702   //  Look only inside the current Voxel only (in the first version).
730   //                                              703   //
731   curVoxelNode = fVoxelNode;                      704   curVoxelNode = fVoxelNode;
732   curNoVolumes = curVoxelNode->GetNoContained(    705   curNoVolumes = curVoxelNode->GetNoContained();
733                                                   706 
734   for ( contentNo=curNoVolumes-1; contentNo>=0    707   for ( contentNo=curNoVolumes-1; contentNo>=0; contentNo-- )
735   {                                               708   {
736     sampleNo = curVoxelNode->GetVolume((G4int) << 709     sampleNo = curVoxelNode->GetVolume(contentNo);
737     samplePhysical = motherLogical->GetDaughte    710     samplePhysical = motherLogical->GetDaughter(sampleNo);
738                                                   711 
739     G4AffineTransform sampleTf(samplePhysical-    712     G4AffineTransform sampleTf(samplePhysical->GetRotation(),
740                                samplePhysical-    713                                samplePhysical->GetTranslation());
741     sampleTf.Invert();                            714     sampleTf.Invert();
742     const G4ThreeVector samplePoint = sampleTf << 715     const G4ThreeVector samplePoint =
743     const G4VSolid* sampleSolid= samplePhysica << 716                           sampleTf.TransformPoint(localPoint);
                                                   >> 717     const G4VSolid *sampleSolid     =
                                                   >> 718                           samplePhysical->GetLogicalVolume()->GetSolid();
744     G4double sampleSafety = sampleSolid->Dista    719     G4double sampleSafety = sampleSolid->DistanceToIn(samplePoint);
745     if ( sampleSafety<ourSafety )                 720     if ( sampleSafety<ourSafety )
746     {                                             721     {
747       ourSafety = sampleSafety;                   722       ourSafety = sampleSafety;
748     }                                             723     }
749 #ifdef G4VERBOSE                                  724 #ifdef G4VERBOSE
750     if( fCheck )                               << 725     if(( fCheck ) && ( fVerbose == 1 ))
751     {                                             726     {
752       fLogger->ComputeSafetyLog(sampleSolid, s << 727       G4cout << "*** G4VoxelNavigation::ComputeSafety(): ***" << G4endl
753                                 sampleSafety,  << 728              << "    Invoked DistanceToIn(p) for daughter solid: "
                                                   >> 729              << sampleSolid->GetName()
                                                   >> 730              << ". Solid replied: " << sampleSafety << G4endl
                                                   >> 731              << "    For local point p: " << samplePoint
                                                   >> 732              << ", to be considered as 'daughter safety'." << G4endl;
754     }                                             733     }
755 #endif                                            734 #endif
756   }                                               735   }
757   voxelSafety = ComputeVoxelSafety(localPoint)    736   voxelSafety = ComputeVoxelSafety(localPoint);
758   if ( voxelSafety<ourSafety )                    737   if ( voxelSafety<ourSafety )
759   {                                               738   {
760     ourSafety = voxelSafety;                      739     ourSafety = voxelSafety;
761   }                                               740   }
762   return ourSafety;                               741   return ourSafety;
763 }                                              << 
764                                                << 
765 void G4VoxelNavigation::RelocateWithinVolume(  << 
766                                                << 
767 {                                              << 
768   auto motherLogical = motherPhysical->GetLogi << 
769                                                << 
770   assert(motherLogical != nullptr);            << 
771                                                << 
772   if ( auto pVoxelHeader = motherLogical->GetV << 
773     VoxelLocate( pVoxelHeader, localPoint );   << 
774 }                                              << 
775                                                << 
776 // ******************************************* << 
777 // SetVerboseLevel                             << 
778 // ******************************************* << 
779 //                                             << 
780 void  G4VoxelNavigation::SetVerboseLevel(G4int << 
781 {                                              << 
782   if( fLogger != nullptr ) { fLogger->SetVerbo << 
783   if( fpVoxelSafety != nullptr) { fpVoxelSafet << 
784 }                                                 742 }
785                                                   743