Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/geometry/navigation/src/G4ParameterisedNavigation.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 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 // class G4ParameterisedNavigation Implementation
 27 //
 28 // Initial Author: P.Kent, 1996
 29 // Revisions:
 30 //  J. Apostolakis 24 Nov 2005, Revised/fixed treatment of nested params
 31 //  J. Apostolakis  4 Feb 2005, Reintroducting multi-level parameterisation
 32 //                              for materials only - see note 1 below
 33 //  G. Cosmo       11 Mar 2004, Added Check mode 
 34 //  G. Cosmo       15 May 2002, Extended to 3-d voxelisation, made subclass
 35 //  J. Apostolakis  5 Mar 1998, Enabled parameterisation of mat & solid type
 36 // --------------------------------------------------------------------
 37 
 38 // Note 1: Design/implementation note for extensions - JAp, March 1st, 2005
 39 // We cannot make the solid, dimensions and transformation dependent on
 40 // parent because the voxelisation will not have access to this. 
 41 // So the following can NOT be done:
 42 //   sampleSolid = curParam->ComputeSolid(num, curPhysical, pParentTouch);
 43 //   sampleSolid->ComputeDimensions(curParam, num, curPhysical, pParentTouch);
 44 //   curParam->ComputeTransformation(num, curPhysical, pParentTouch);
 45 
 46 #include "G4ParameterisedNavigation.hh"
 47 #include "G4TouchableHistory.hh"
 48 #include "G4VNestedParameterisation.hh"
 49 
 50 #include "G4AuxiliaryNavServices.hh"
 51 
 52 #include <cassert>
 53 
 54 // ********************************************************************
 55 // Constructor
 56 // ********************************************************************
 57 //
 58 G4ParameterisedNavigation::G4ParameterisedNavigation() = default;
 59 
 60 // ***************************************************************************
 61 // Destructor
 62 // ***************************************************************************
 63 //
 64 G4ParameterisedNavigation::~G4ParameterisedNavigation() = default;
 65 
 66 // ***************************************************************************
 67 // ComputeStep
 68 // ***************************************************************************
 69 //
 70 G4double G4ParameterisedNavigation::
 71                     ComputeStep(const G4ThreeVector& localPoint,
 72                                 const G4ThreeVector& localDirection,
 73                                 const G4double currentProposedStepLength,
 74                                       G4double& newSafety,
 75                                       G4NavigationHistory& history,
 76                                       G4bool& validExitNormal,
 77                                       G4ThreeVector& exitNormal,
 78                                       G4bool& exiting,
 79                                       G4bool& entering,
 80                                       G4VPhysicalVolume *(*pBlockedPhysical),
 81                                       G4int& blockedReplicaNo)
 82 {
 83   G4VPhysicalVolume *motherPhysical, *samplePhysical;
 84   G4VPVParameterisation *sampleParam;
 85   G4LogicalVolume *motherLogical;
 86   G4VSolid *motherSolid, *sampleSolid;
 87   G4ThreeVector sampleDirection;
 88   G4double ourStep=currentProposedStepLength, ourSafety;
 89   G4double motherSafety, motherStep = DBL_MAX;
 90   G4bool motherValidExitNormal = false;
 91   G4ThreeVector motherExitNormal;
 92   
 93   G4int sampleNo;
 94 
 95   G4bool initialNode, noStep;
 96   G4SmartVoxelNode *curVoxelNode;
 97   G4long curNoVolumes, contentNo;
 98   G4double voxelSafety;
 99 
100   // Replication data
101   //
102   EAxis axis;
103   G4int nReplicas;
104   G4double width, offset;
105   G4bool consuming;
106 
107   motherPhysical = history.GetTopVolume();
108   motherLogical = motherPhysical->GetLogicalVolume();
109   motherSolid = motherLogical->GetSolid();
110 
111   //
112   // Compute mother safety
113   //
114 
115   motherSafety = motherSolid->DistanceToOut(localPoint);
116   ourSafety = motherSafety;              // Working isotropic safety
117 
118 #ifdef G4VERBOSE
119   if ( fCheck )
120   {
121     if( motherSafety < 0.0 )
122     {
123       motherSolid->DumpInfo();
124       std::ostringstream message;
125       message << "Negative Safety In Voxel Navigation !" << G4endl
126               << "        Current solid " << motherSolid->GetName()
127               << " gave negative safety: " << motherSafety << G4endl
128               << "        for the current (local) point " << localPoint;
129       G4Exception("G4ParameterisedNavigation::ComputeStep()",
130                   "GeomNav0003", FatalException, message); 
131     }
132     if( motherSolid->Inside(localPoint) == kOutside )
133     { 
134       std::ostringstream message;
135       message << "Point is outside Current Volume !" << 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;
142       if( estDistToSolid > 100.0 * motherSolid->GetTolerance() )
143       {
144         motherSolid->DumpInfo();
145         G4Exception("G4ParameterisedNavigation::ComputeStep()",
146                     "GeomNav0003", FatalException, message,
147                     "Point is far outside Current Volume !"); 
148       }
149       else
150       {
151         G4Exception("G4ParameterisedNavigation::ComputeStep()",
152                     "GeomNav1002", JustWarning, message,
153                     "Point is a little outside Current Volume.");
154       }
155     }
156 
157     // Compute early:
158     //  a) to check whether point is (wrongly) outside
159     //               (signaled if step < 0 or step == kInfinity )
160     //  b) to check value against answer of daughters!
161     //
162     motherStep = motherSolid->DistanceToOut(localPoint,
163                                             localDirection,
164                                             true,
165                                            &motherValidExitNormal,
166                                            &motherExitNormal);
167   
168     if( (motherStep >= kInfinity) || (motherStep < 0.0) )
169     {
170       // Error - indication of being outside solid !!
171       //
172       fLogger->ReportOutsideMother(localPoint, localDirection, motherPhysical);
173 
174       ourStep = motherStep = 0.0;
175       exiting = true;
176       entering = false;
177     
178       // If we are outside the solid does the normal make sense?
179       validExitNormal = motherValidExitNormal;
180       exitNormal = motherExitNormal;
181     
182       *pBlockedPhysical = nullptr; // or motherPhysical ?
183       blockedReplicaNo = 0;  // or motherReplicaNumber ?
184     
185       newSafety = 0.0;
186       return ourStep;
187     }
188   }
189 #endif
190 
191   initialNode = true;
192   noStep = true;
193 
194   // By definition, the parameterised volume is the first
195   // (and only) daughter of the mother volume
196   //
197   samplePhysical = motherLogical->GetDaughter(0);
198   samplePhysical->GetReplicationData(axis,nReplicas,width,offset,consuming);
199   fBList.Enlarge(nReplicas);
200   fBList.Reset();
201 
202   // Exiting normal optimisation
203   //
204   if (exiting && (*pBlockedPhysical==samplePhysical) && validExitNormal)
205   {
206     if (localDirection.dot(exitNormal)>=kMinExitingNormalCosine)
207     {
208       // Block exited daughter replica; Must be on boundary => zero safety
209       //
210       fBList.BlockVolume(blockedReplicaNo);
211       ourSafety = 0;
212     }
213   }
214   exiting = false;
215   entering = false;
216 
217   sampleParam = samplePhysical->GetParameterisation();
218 
219   // Loop over voxels & compute daughter safeties & intersections
220 
221   do
222   {
223     curVoxelNode = fVoxelNode;
224     curNoVolumes = curVoxelNode->GetNoContained();
225 
226     for ( contentNo=curNoVolumes-1; contentNo>=0; contentNo-- )
227     {
228       sampleNo = curVoxelNode->GetVolume((G4int)contentNo);
229       if ( !fBList.IsBlocked(sampleNo) )
230       {
231         fBList.BlockVolume(sampleNo);
232 
233         // Call virtual methods, and copy information if needed
234         //
235         sampleSolid = IdentifyAndPlaceSolid( sampleNo, samplePhysical,
236                                              sampleParam ); 
237 
238         G4AffineTransform sampleTf(samplePhysical->GetRotation(),
239                                    samplePhysical->GetTranslation());
240         sampleTf.Invert();
241         const G4ThreeVector samplePoint = sampleTf.TransformPoint(localPoint);
242         const G4double sampleSafety = sampleSolid->DistanceToIn(samplePoint);
243         if ( sampleSafety<ourSafety )
244         {
245           ourSafety = sampleSafety;
246         }
247         if ( sampleSafety<=ourStep )
248         {
249           sampleDirection = sampleTf.TransformAxis(localDirection);
250           G4double sampleStep =
251                    sampleSolid->DistanceToIn(samplePoint, sampleDirection);
252           if ( sampleStep<=ourStep )
253           {
254             ourStep = sampleStep;
255             entering = true;
256             exiting = false;
257             *pBlockedPhysical = samplePhysical;
258             blockedReplicaNo = sampleNo;
259 #ifdef G4VERBOSE
260               // Check to see that the resulting point is indeed in/on volume.
261               // This check could eventually be made only for successful
262               // candidate.
263 
264               if ( ( fCheck ) && ( sampleStep < kInfinity ) )
265               {
266                 G4ThreeVector intersectionPoint;
267                 intersectionPoint = samplePoint + sampleStep * sampleDirection;
268                 EInside insideIntPt = sampleSolid->Inside(intersectionPoint); 
269                 if( insideIntPt != kSurface )
270                 {
271                   G4long oldcoutPrec = G4cout.precision(16); 
272                   std::ostringstream message;
273                   message << "Navigator gets conflicting response from Solid."
274                           << G4endl
275                           << "          Inaccurate solid DistanceToIn"
276                           << " for solid " << sampleSolid->GetName() << G4endl
277                           << "          Solid gave DistanceToIn = "
278                           << sampleStep << " yet returns " ;
279                   if( insideIntPt == kInside )
280                   {
281                     message << "-kInside-"; 
282                   }
283                   else if( insideIntPt == kOutside )
284                   {
285                     message << "-kOutside-";
286                   }
287                   else
288                   {
289                     message << "-kSurface-"; 
290                   }
291                   message << " for this point !" << G4endl
292                           << "          Point = " << intersectionPoint
293                           << G4endl;
294                   if ( insideIntPt != kInside )
295                   {
296                     message << "        DistanceToIn(p) = " 
297                             << sampleSolid->DistanceToIn(intersectionPoint);
298                   }
299                   if ( insideIntPt != kOutside )
300                   { 
301                     message << "        DistanceToOut(p) = " 
302                             << sampleSolid->DistanceToOut(intersectionPoint);
303                   }
304                   G4Exception("G4ParameterisedNavigation::ComputeStep()", 
305                               "GeomNav1002", JustWarning, message);
306                   G4cout.precision(oldcoutPrec);
307                 }
308               }
309 #endif
310           }
311         }
312       }
313     }
314 
315     if ( initialNode )
316     {
317       initialNode = false;
318       voxelSafety = ComputeVoxelSafety(localPoint,axis);
319       if ( voxelSafety<ourSafety )
320       {
321         ourSafety = voxelSafety;
322       }
323       if ( currentProposedStepLength<ourSafety )
324       {
325         // Guaranteed physics limited
326         //      
327         noStep = false;
328         entering = false;
329         exiting = false;
330         *pBlockedPhysical = nullptr;
331         ourStep = kInfinity;
332       }
333       else
334       {
335         // Consider intersection with mother solid
336         //
337         if ( motherSafety<=ourStep )
338         {
339           if ( !fCheck )           
340           {
341             motherStep = motherSolid->DistanceToOut(localPoint,
342                                                    localDirection,
343                                                    true,
344                                                    &motherValidExitNormal,
345                                                    &motherExitNormal);
346           }
347 
348           if( ( motherStep < 0.0 ) || ( motherStep >= kInfinity) )
349           {
350 #ifdef G4VERBOSE
351             fLogger->ReportOutsideMother(localPoint, localDirection,
352                                          motherPhysical);
353 #endif
354             ourStep = motherStep = 0.0;
355             // Rely on the code below to set the remaining state, i.e.
356             // exiting, entering,  exitNormal & validExitNormal,
357             // pBlockedPhysical etc.
358           }
359 #ifdef G4VERBOSE
360           if( motherValidExitNormal && ( fCheck || (motherStep<=ourStep)) )
361           {
362             fLogger->CheckAndReportBadNormal(motherExitNormal,
363                                              localPoint, localDirection,
364                                              motherStep, motherSolid,
365                                              "From motherSolid::DistanceToOut");
366           }
367 #endif
368           if ( motherStep<=ourStep )
369           {
370             ourStep = motherStep;
371             exiting = true;
372             entering = false;
373             if ( validExitNormal )
374             {
375               const G4RotationMatrix* rot = motherPhysical->GetRotation();
376               if (rot != nullptr)
377               {
378                 exitNormal *= rot->inverse();
379               }
380             }
381           }
382           else
383           {
384             validExitNormal = false;
385           }
386         }
387       }
388       newSafety = ourSafety;
389     }
390     if (noStep)
391     {
392       noStep = LocateNextVoxel(localPoint, localDirection, ourStep, axis);
393     }
394   } while (noStep);
395 
396   return ourStep;
397 }
398 
399 // ***************************************************************************
400 // ComputeSafety
401 // ***************************************************************************
402 //
403 G4double
404 G4ParameterisedNavigation::ComputeSafety(const G4ThreeVector& localPoint,
405                                          const G4NavigationHistory& history,
406                                          const G4double )
407 {
408   G4VPhysicalVolume *motherPhysical, *samplePhysical;
409   G4VPVParameterisation *sampleParam;
410   G4LogicalVolume *motherLogical;
411   G4VSolid *motherSolid, *sampleSolid;
412   G4double motherSafety, ourSafety;
413   G4int sampleNo, curVoxelNodeNo;
414 
415   G4SmartVoxelNode *curVoxelNode;
416   G4long curNoVolumes, contentNo;
417   G4double voxelSafety;
418 
419   // Replication data
420   //
421   EAxis axis;
422   G4int nReplicas;
423   G4double width, offset;
424   G4bool consuming;
425 
426   motherPhysical = history.GetTopVolume();
427   motherLogical = motherPhysical->GetLogicalVolume();
428   motherSolid = motherLogical->GetSolid();
429 
430   //
431   // Compute mother safety
432   //
433 
434   motherSafety = motherSolid->DistanceToOut(localPoint);
435   ourSafety = motherSafety;                     // Working isotropic safety
436 
437   //
438   // Compute daughter safeties
439   //
440 
441   // By definition, parameterised volumes exist as first
442   // daughter of the mother volume
443   //
444   samplePhysical = motherLogical->GetDaughter(0);
445   samplePhysical->GetReplicationData(axis, nReplicas,
446                                      width, offset, consuming);
447   sampleParam = samplePhysical->GetParameterisation();
448 
449   // Look inside the current Voxel only at the current point
450   //
451   if ( axis==kUndefined )      // 3D case: current voxel node is retrieved
452   {                            //          from G4VoxelNavigation.
453     curVoxelNode = fVoxelNode;
454   }
455   else                         // 1D case: current voxel node is computed here.
456   {
457     curVoxelNodeNo = G4int((localPoint(fVoxelAxis)
458                            -fVoxelHeader->GetMinExtent()) / fVoxelSliceWidth );
459     curVoxelNode = fVoxelHeader->GetSlice(curVoxelNodeNo)->GetNode();
460     fVoxelNodeNo = curVoxelNodeNo;
461     fVoxelNode = curVoxelNode;
462   }
463   curNoVolumes = curVoxelNode->GetNoContained();
464 
465   for ( contentNo=curNoVolumes-1; contentNo>=0; contentNo-- )
466   {
467     sampleNo = curVoxelNode->GetVolume((G4int)contentNo);
468     
469     // Call virtual methods, and copy information if needed
470     //
471     sampleSolid= IdentifyAndPlaceSolid( sampleNo,samplePhysical,sampleParam ); 
472 
473     G4AffineTransform sampleTf(samplePhysical->GetRotation(),
474                                samplePhysical->GetTranslation());
475     sampleTf.Invert();
476     const G4ThreeVector samplePoint = sampleTf.TransformPoint(localPoint);
477     G4double sampleSafety = sampleSolid->DistanceToIn(samplePoint);
478     if ( sampleSafety<ourSafety )
479     {
480       ourSafety = sampleSafety;
481     }
482   }
483 
484   voxelSafety = ComputeVoxelSafety(localPoint,axis);
485   if ( voxelSafety<ourSafety )
486   {
487     ourSafety=voxelSafety;
488   }
489 
490   return ourSafety;
491 }
492 
493 // ********************************************************************
494 // ComputeVoxelSafety
495 //
496 // Computes safety from specified point to collected voxel boundaries
497 // using already located point.
498 // ********************************************************************
499 //
500 G4double G4ParameterisedNavigation::
501 ComputeVoxelSafety(const G4ThreeVector& localPoint,
502                    const EAxis pAxis) const
503 {
504   // If no best axis is specified, adopt default
505   // strategy as for placements
506   //  
507   if ( pAxis==kUndefined )
508   {
509     return G4VoxelNavigation::ComputeVoxelSafety(localPoint);
510   }
511 
512   G4double voxelSafety, plusVoxelSafety, minusVoxelSafety;
513   G4double curNodeOffset, minCurCommonDelta, maxCurCommonDelta;
514   G4long minCurNodeNoDelta, maxCurNodeNoDelta;
515   
516   // Compute linear intersection distance to boundaries of max/min
517   // to collected nodes at current level
518   //
519   curNodeOffset = fVoxelNodeNo*fVoxelSliceWidth;
520   minCurCommonDelta = localPoint(fVoxelAxis)
521                     - fVoxelHeader->GetMinExtent()-curNodeOffset;
522   maxCurNodeNoDelta = fVoxelNode->GetMaxEquivalentSliceNo()-fVoxelNodeNo;
523   minCurNodeNoDelta = fVoxelNodeNo-fVoxelNode->GetMinEquivalentSliceNo();
524   maxCurCommonDelta = fVoxelSliceWidth-minCurCommonDelta;
525   plusVoxelSafety   = minCurNodeNoDelta*fVoxelSliceWidth+minCurCommonDelta;
526   minusVoxelSafety  = maxCurNodeNoDelta*fVoxelSliceWidth+maxCurCommonDelta;
527   voxelSafety = std::min(plusVoxelSafety,minusVoxelSafety);
528 
529   if ( voxelSafety<0 )
530   {
531     voxelSafety = 0;
532   }
533 
534   return voxelSafety;
535 }
536 
537 // ********************************************************************
538 // LocateNextVoxel
539 //
540 // Finds the next voxel from the current voxel and point
541 // in the specified direction.
542 //
543 // Returns false if all voxels considered
544 //         true  otherwise
545 // [current Step ends inside same voxel or leaves all voxels]
546 // ********************************************************************
547 //
548 G4bool G4ParameterisedNavigation::
549 LocateNextVoxel( const G4ThreeVector& localPoint,
550                  const G4ThreeVector& localDirection,
551                  const G4double currentStep,
552                  const EAxis pAxis)
553 {
554   // If no best axis is specified, adopt default
555   // location strategy as for placements
556   //  
557   if ( pAxis==kUndefined )
558   {
559     return G4VoxelNavigation::LocateNextVoxel(localPoint,
560                                               localDirection,
561                                               currentStep);
562   }
563 
564   G4bool isNewVoxel;
565   G4int newNodeNo;
566   G4double minVal, maxVal, curMinExtent, curCoord;
567 
568   curMinExtent = fVoxelHeader->GetMinExtent();
569   curCoord = localPoint(fVoxelAxis)+currentStep*localDirection(fVoxelAxis);
570   minVal = curMinExtent+fVoxelNode->GetMinEquivalentSliceNo()*fVoxelSliceWidth;
571   isNewVoxel = false;
572 
573   if ( minVal<=curCoord )
574   {
575     maxVal = curMinExtent
576            + (fVoxelNode->GetMaxEquivalentSliceNo()+1)*fVoxelSliceWidth;
577     if ( maxVal<curCoord )
578     {
579       newNodeNo = fVoxelNode->GetMaxEquivalentSliceNo()+1;
580       if ( newNodeNo<G4int(fVoxelHeader->GetNoSlices()) )
581       {
582         fVoxelNodeNo = newNodeNo;
583         fVoxelNode = fVoxelHeader->GetSlice(newNodeNo)->GetNode();
584         isNewVoxel = true;
585       }
586     }
587   }
588   else
589   {
590     newNodeNo = fVoxelNode->GetMinEquivalentSliceNo()-1;
591 
592     // Must locate from newNodeNo no and down to setup stack and fVoxelNode
593     // Repeat or earlier code...
594     //
595     if ( newNodeNo>=0 )
596     {
597       fVoxelNodeNo = newNodeNo;
598       fVoxelNode = fVoxelHeader->GetSlice(newNodeNo)->GetNode();
599       isNewVoxel = true;
600     }
601   }
602   return isNewVoxel;
603 }
604 
605 // ********************************************************************
606 // LevelLocate
607 // ********************************************************************
608 //
609 G4bool
610 G4ParameterisedNavigation::LevelLocate( G4NavigationHistory& history,
611                                   const G4VPhysicalVolume* blockedVol,
612                                   const G4int blockedNum,
613                                   const G4ThreeVector& globalPoint,
614                                   const G4ThreeVector* globalDirection,
615                                   const G4bool pLocatedOnEdge, 
616                                         G4ThreeVector& localPoint )
617 {
618   G4SmartVoxelHeader *motherVoxelHeader;
619   G4SmartVoxelNode *motherVoxelNode;
620   G4VPhysicalVolume *motherPhysical, *pPhysical;
621   G4VPVParameterisation *pParam;
622   G4LogicalVolume *motherLogical;
623   G4VSolid *pSolid;
624   G4ThreeVector samplePoint;
625   G4int voxelNoDaughters, replicaNo;
626   
627   motherPhysical = history.GetTopVolume();
628   motherLogical = motherPhysical->GetLogicalVolume();
629   motherVoxelHeader = motherLogical->GetVoxelHeader();
630 
631   // Find the voxel containing the point
632   //
633   motherVoxelNode = ParamVoxelLocate(motherVoxelHeader,localPoint);
634   
635   voxelNoDaughters = (G4int)motherVoxelNode->GetNoContained();
636   if ( voxelNoDaughters==0 )  { return false; }
637   
638   pPhysical = motherLogical->GetDaughter(0);
639   pParam = pPhysical->GetParameterisation();
640 
641   // Save parent history in touchable history
642   //   ... for use as parent t-h in ComputeMaterial method of param
643   //
644   G4TouchableHistory parentTouchable( history ); 
645 
646   // Search replicated daughter volume
647   //
648   for ( auto sampleNo=voxelNoDaughters-1; sampleNo>=0; sampleNo-- )
649   {
650     replicaNo = motherVoxelNode->GetVolume(sampleNo);
651     if ( (replicaNo!=blockedNum) || (pPhysical!=blockedVol) )
652     {
653       // Obtain solid (as it can vary) and obtain its parameters
654       //
655       pSolid = IdentifyAndPlaceSolid( replicaNo, pPhysical, pParam ); 
656 
657       // Setup history
658       //
659       history.NewLevel(pPhysical, kParameterised, replicaNo);
660       samplePoint = history.GetTopTransform().TransformPoint(globalPoint);
661       if ( !G4AuxiliaryNavServices::CheckPointOnSurface( pSolid, samplePoint,
662             globalDirection, history.GetTopTransform(), pLocatedOnEdge) )
663       {
664         history.BackLevel();
665       }
666       else
667       { 
668         // Enter this daughter
669         //
670         localPoint = samplePoint;
671         
672         // Set the correct copy number in physical
673         //
674         pPhysical->SetCopyNo(replicaNo);
675         
676         // Set the correct solid and material in Logical Volume
677         //
678         G4LogicalVolume *pLogical = pPhysical->GetLogicalVolume();
679         pLogical->SetSolid(pSolid);
680         pLogical->UpdateMaterial(pParam->ComputeMaterial(replicaNo,
681                                  pPhysical, &parentTouchable)  );
682         return true;
683       }
684     }
685   }
686   return false;
687 }
688 
689 void G4ParameterisedNavigation::RelocateWithinVolume( G4VPhysicalVolume*  motherPhysical,
690                                                       const G4ThreeVector& localPoint )
691 {
692   auto motherLogical = motherPhysical->GetLogicalVolume();
693 
694   /* this should only be called on parameterized volumes, which always satisfy the conditions below */
695   assert(motherPhysical->GetRegularStructureId() != 1);
696   assert(motherLogical->GetNoDaughters() == 1);
697 
698   if ( auto pVoxelHeader = motherLogical->GetVoxelHeader() )
699     ParamVoxelLocate( pVoxelHeader, localPoint );
700 }
701