Geant4  10.02.p01
G4VoxelNavigation.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4VoxelNavigation.cc 93289 2015-10-15 10:01:15Z gcosmo $
28 //
29 //
30 // class G4VoxelNavigation Implementation
31 //
32 // Author: P.Kent, 1996
33 //
34 // --------------------------------------------------------------------
35 #include <ostream>
36 
37 #include "G4VoxelNavigation.hh"
38 #include "G4GeometryTolerance.hh"
39 #include "G4VoxelSafety.hh"
40 
42 
43 #ifdef G4DEBUG_NAVIGATION
44 static int debugVerboseLevel= 5; // Reports most about daughter volumes
45 #endif
46 
47 // ********************************************************************
48 // Constructor
49 // ********************************************************************
50 //
52  : fBList(), fVoxelDepth(-1),
53  fVoxelAxisStack(kNavigatorVoxelStackMax,kXAxis),
54  fVoxelNoSlicesStack(kNavigatorVoxelStackMax,0),
55  fVoxelSliceWidthStack(kNavigatorVoxelStackMax,0.),
56  fVoxelNodeNoStack(kNavigatorVoxelStackMax,0),
57  fVoxelHeaderStack(kNavigatorVoxelStackMax,(G4SmartVoxelHeader*)0),
58  fVoxelNode(0), fpVoxelSafety(0), fCheck(false), fBestSafety(false)
59 {
60  fLogger = new G4NavigationLogger("G4VoxelNavigation");
62 
63 #ifdef G4DEBUG_NAVIGATION
64  SetVerboseLevel(debugVerboseLevel); // Reports most about daughter volumes
65 #endif
66 }
67 
68 // ********************************************************************
69 // Destructor
70 // ********************************************************************
71 //
73 {
74  delete fpVoxelSafety;
75  delete fLogger;
76 }
77 
78 // ********************************************************************
79 // ComputeStep
80 // ********************************************************************
81 //
84  const G4ThreeVector& localDirection,
85  const G4double currentProposedStepLength,
86  G4double& newSafety,
87  G4NavigationHistory& history,
88  G4bool& validExitNormal,
89  G4ThreeVector& exitNormal,
90  G4bool& exiting,
91  G4bool& entering,
92  G4VPhysicalVolume *(*pBlockedPhysical),
93  G4int& blockedReplicaNo )
94 {
95  G4VPhysicalVolume *motherPhysical, *samplePhysical, *blockedExitedVol=0;
96  G4LogicalVolume *motherLogical;
97  G4VSolid *motherSolid;
98  G4ThreeVector sampleDirection;
99  G4double ourStep=currentProposedStepLength, ourSafety;
100  G4double motherSafety, motherStep=DBL_MAX;
101  G4int localNoDaughters, sampleNo;
102 
103  G4bool initialNode, noStep;
104  G4SmartVoxelNode *curVoxelNode;
105  G4int curNoVolumes, contentNo;
106  G4double voxelSafety;
107 
108  motherPhysical = history.GetTopVolume();
109  motherLogical = motherPhysical->GetLogicalVolume();
110  motherSolid = motherLogical->GetSolid();
111 
112  //
113  // Compute mother safety
114  //
115 
116  motherSafety = motherSolid->DistanceToOut(localPoint);
117  ourSafety = motherSafety; // Working isotropic safety
118 
119 #ifdef G4VERBOSE
120  if ( fCheck )
121  {
122  fLogger->PreComputeStepLog (motherPhysical, motherSafety, localPoint);
123  }
124 #endif
125 
126  //
127  // Compute daughter safeties & intersections
128  //
129 
130  // Exiting normal optimisation
131  //
132  if ( exiting && validExitNormal )
133  {
134  if ( localDirection.dot(exitNormal)>=kMinExitingNormalCosine )
135  {
136  // Block exited daughter volume
137  //
138  blockedExitedVol = *pBlockedPhysical;
139  ourSafety = 0;
140  }
141  }
142  exiting = false;
143  entering = false;
144 
145  // For extra checking, get the distance to Mother early !!
146  G4bool motherValidExitNormal= false;
147  G4ThreeVector motherExitNormal(0.0, 0.0, 0.0);
148 
149 #ifdef G4VERBOSE
150  if ( fCheck )
151  {
152  // Compute early -- a) for validity
153  // b) to check against answer of daughters!
154  motherStep = motherSolid->DistanceToOut(localPoint,
155  localDirection,
156  true,
157  &motherValidExitNormal,
158  &motherExitNormal);
159 
160  fLogger->PostComputeStepLog(motherSolid, localPoint, localDirection,
161  motherStep, motherSafety);
162 
163  if( (motherStep >= kInfinity) || (motherStep < 0.0) )
164  {
165  // Error - indication of being outside solid !!
166  fLogger->ReportOutsideMother(localPoint, localDirection, motherPhysical);
167 
168  ourStep = 0.0;
169 
170  exiting= true;
171  entering= false;
172 
173  // validExitNormal= motherValidExitNormal;
174  // exitNormal= motherExitNormal;
175  // Makes sense and is useful only if the point is very close ...
176  // Alternatives: i) validExitNormal= false;
177  // ii) Check safety from outside and choose !!
178  validExitNormal= false;
179 
180  *pBlockedPhysical= 0; // or motherPhysical ?
181  blockedReplicaNo= 0; // or motherReplicaNumber ?
182 
183  newSafety= 0.0;
184  return ourStep;
185  }
186  }
187 #endif
188 
189  localNoDaughters = motherLogical->GetNoDaughters();
190 
191  fBList.Enlarge(localNoDaughters);
192  fBList.Reset();
193 
194  initialNode = true;
195  noStep = true;
196 
197  while (noStep)
198  {
199  curVoxelNode = fVoxelNode;
200  curNoVolumes = curVoxelNode->GetNoContained();
201  for (contentNo=curNoVolumes-1; contentNo>=0; contentNo--)
202  {
203  sampleNo = curVoxelNode->GetVolume(contentNo);
204  if ( !fBList.IsBlocked(sampleNo) )
205  {
206  fBList.BlockVolume(sampleNo);
207  samplePhysical = motherLogical->GetDaughter(sampleNo);
208  if ( samplePhysical!=blockedExitedVol )
209  {
210  G4AffineTransform sampleTf(samplePhysical->GetRotation(),
211  samplePhysical->GetTranslation());
212  sampleTf.Invert();
213  const G4ThreeVector samplePoint =
214  sampleTf.TransformPoint(localPoint);
215  const G4VSolid *sampleSolid =
216  samplePhysical->GetLogicalVolume()->GetSolid();
217  const G4double sampleSafety =
218  sampleSolid->DistanceToIn(samplePoint);
219 
220  if ( sampleSafety<ourSafety )
221  {
222  ourSafety = sampleSafety;
223  }
224  if ( sampleSafety<=ourStep )
225  {
226  sampleDirection = sampleTf.TransformAxis(localDirection);
227  G4double sampleStep =
228  sampleSolid->DistanceToIn(samplePoint, sampleDirection);
229 #ifdef G4VERBOSE
230  if( fCheck )
231  {
232  fLogger->PrintDaughterLog(sampleSolid, samplePoint,
233  sampleSafety, true,
234  sampleDirection, sampleStep);
235  }
236 #endif
237  if ( sampleStep<=ourStep )
238  {
239  ourStep = sampleStep;
240  entering = true;
241  exiting = false;
242  *pBlockedPhysical = samplePhysical;
243  blockedReplicaNo = -1;
244 #ifdef G4VERBOSE
245  // Check to see that the resulting point is indeed in/on volume.
246  // This could be done only for successful candidate.
247  if ( fCheck )
248  {
249  fLogger->AlongComputeStepLog (sampleSolid, samplePoint,
250  sampleDirection, localDirection, sampleSafety, sampleStep);
251  }
252 #endif
253  }
254 #ifdef G4VERBOSE
255  if ( fCheck && ( sampleStep < kInfinity )
256  && ( sampleStep >= motherStep ) )
257  {
258  // The intersection point with the daughter is after the exit
259  // point from the mother volume. Double check this !!
260  fLogger->CheckDaughterEntryPoint(sampleSolid,
261  samplePoint, sampleDirection,
262  motherSolid,
263  localPoint, localDirection,
264  motherStep, sampleStep);
265  }
266 #endif
267  }
268 #ifdef G4VERBOSE
269  else // ie if sampleSafety > outStep
270  {
271  if( fCheck )
272  {
273  fLogger->PrintDaughterLog(sampleSolid, samplePoint,
274  sampleSafety, false,
275  G4ThreeVector(0.,0.,0.), -1.0 );
276  }
277  }
278 #endif
279  }
280  }
281  }
282  if (initialNode)
283  {
284  initialNode = false;
285  voxelSafety = ComputeVoxelSafety(localPoint);
286  if ( voxelSafety<ourSafety )
287  {
288  ourSafety = voxelSafety;
289  }
290  if ( currentProposedStepLength<ourSafety )
291  {
292  // Guaranteed physics limited
293  //
294  noStep = false;
295  entering = false;
296  exiting = false;
297  *pBlockedPhysical = 0;
298  ourStep = kInfinity;
299  }
300  else
301  {
302  //
303  // Compute mother intersection if required
304  //
305  if ( motherSafety<=ourStep )
306  {
307  if( !fCheck )
308  {
309  motherStep = motherSolid->DistanceToOut(localPoint, localDirection,
310  true, &motherValidExitNormal, &motherExitNormal);
311  }
312  // Not correct - unless mother limits step (see below)
313  // validExitNormal= motherValidExitNormal;
314  // exitNormal= motherExitNormal;
315 #ifdef G4VERBOSE
316  else // check_mode
317  {
318  fLogger->PostComputeStepLog(motherSolid, localPoint, localDirection,
319  motherStep, motherSafety);
320  if( motherValidExitNormal )
321  {
322  fLogger->CheckAndReportBadNormal(motherExitNormal,
323  localPoint, localDirection,
324  motherStep, motherSolid,
325  "From motherSolid::DistanceToOut" );
326  }
327  }
328 #endif
329  if( (motherStep >= kInfinity) || (motherStep < 0.0) )
330  {
331  // Error - indication of being outside solid !!
332  //
333  fLogger->ReportOutsideMother(localPoint, localDirection, motherPhysical);
334 
335  motherStep = 0.0;
336  ourStep = 0.0;
337  exiting = true;
338  entering = false;
339 
340  // validExitNormal= motherValidExitNormal;
341  // exitNormal= motherExitNormal;
342  // Useful only if the point is very close to surface
343  // => but it would need to be rotated to grand-mother ref frame !
344  validExitNormal= false;
345 
346  *pBlockedPhysical= 0; // or motherPhysical ?
347  blockedReplicaNo= 0; // or motherReplicaNumber ?
348 
349  newSafety= 0.0;
350  return ourStep;
351  }
352 
353  if ( motherStep<=ourStep )
354  {
355  ourStep = motherStep;
356  exiting = true;
357  entering = false;
358 
359  // Exit normal: Natural location to set these;confirmed short step
360  //
361  validExitNormal= motherValidExitNormal;
362  exitNormal= motherExitNormal;
363 
364  if ( validExitNormal )
365  {
366  const G4RotationMatrix *rot = motherPhysical->GetRotation();
367  if (rot)
368  {
369  exitNormal *= rot->inverse();
370 #ifdef G4VERBOSE
371  if( fCheck )
372  fLogger->CheckAndReportBadNormal(exitNormal, // rotated
373  motherExitNormal, // original
374  *rot,
375  // motherPhysical,
376  "From RotationMatrix" );
377 
378 #endif
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);
393  }
394  } // end -while (noStep)- loop
395 
396  return ourStep;
397 }
398 
399 // ********************************************************************
400 // ComputeVoxelSafety
401 //
402 // Computes safety from specified point to voxel boundaries
403 // using already located point
404 // o collected boundaries for most derived level
405 // o adjacent boundaries for previous levels
406 // ********************************************************************
407 //
408 G4double
410 {
411  G4SmartVoxelHeader *curHeader;
412  G4double voxelSafety, curNodeWidth;
413  G4double curNodeOffset, minCurCommonDelta, maxCurCommonDelta;
414  G4int minCurNodeNoDelta, maxCurNodeNoDelta;
415  G4int localVoxelDepth, curNodeNo;
416  EAxis curHeaderAxis;
417 
418  localVoxelDepth = fVoxelDepth;
419 
420  curHeader = fVoxelHeaderStack[localVoxelDepth];
421  curHeaderAxis = fVoxelAxisStack[localVoxelDepth];
422  curNodeNo = fVoxelNodeNoStack[localVoxelDepth];
423  curNodeWidth = fVoxelSliceWidthStack[localVoxelDepth];
424 
425  // Compute linear intersection distance to boundaries of max/min
426  // to collected nodes at current level
427  //
428  curNodeOffset = curNodeNo*curNodeWidth;
429  maxCurNodeNoDelta = fVoxelNode->GetMaxEquivalentSliceNo()-curNodeNo;
430  minCurNodeNoDelta = curNodeNo-fVoxelNode->GetMinEquivalentSliceNo();
431  minCurCommonDelta = localPoint(curHeaderAxis)
432  - curHeader->GetMinExtent() - curNodeOffset;
433  maxCurCommonDelta = curNodeWidth-minCurCommonDelta;
434 
435  if ( minCurNodeNoDelta<maxCurNodeNoDelta )
436  {
437  voxelSafety = minCurNodeNoDelta*curNodeWidth;
438  voxelSafety += minCurCommonDelta;
439  }
440  else if (maxCurNodeNoDelta < minCurNodeNoDelta)
441  {
442  voxelSafety = maxCurNodeNoDelta*curNodeWidth;
443  voxelSafety += maxCurCommonDelta;
444  }
445  else // (maxCurNodeNoDelta == minCurNodeNoDelta)
446  {
447  voxelSafety = minCurNodeNoDelta*curNodeWidth;
448  voxelSafety += std::min(minCurCommonDelta,maxCurCommonDelta);
449  }
450 
451  // Compute isotropic safety to boundaries of previous levels
452  // [NOT to collected boundaries]
453  //
454  while ( (localVoxelDepth>0) && (voxelSafety>0) )
455  {
456  localVoxelDepth--;
457  curHeader = fVoxelHeaderStack[localVoxelDepth];
458  curHeaderAxis = fVoxelAxisStack[localVoxelDepth];
459  curNodeNo = fVoxelNodeNoStack[localVoxelDepth];
460  curNodeWidth = fVoxelSliceWidthStack[localVoxelDepth];
461  curNodeOffset = curNodeNo*curNodeWidth;
462  minCurCommonDelta = localPoint(curHeaderAxis)
463  - curHeader->GetMinExtent() - curNodeOffset;
464  maxCurCommonDelta = curNodeWidth-minCurCommonDelta;
465 
466  if ( minCurCommonDelta<voxelSafety )
467  {
468  voxelSafety = minCurCommonDelta;
469  }
470  if ( maxCurCommonDelta<voxelSafety )
471  {
472  voxelSafety = maxCurCommonDelta;
473  }
474  }
475  if ( voxelSafety<0 )
476  {
477  voxelSafety = 0;
478  }
479 
480  return voxelSafety;
481 }
482 
483 // ********************************************************************
484 // LocateNextVoxel
485 //
486 // Finds the next voxel from the current voxel and point
487 // in the specified direction
488 //
489 // Returns false if all voxels considered
490 // [current Step ends inside same voxel or leaves all voxels]
491 // true otherwise
492 // [the information on the next voxel is put into the set of
493 // fVoxel* variables & "stacks"]
494 // ********************************************************************
495 //
496 G4bool
498  const G4ThreeVector& localDirection,
499  const G4double currentStep)
500 {
501  G4SmartVoxelHeader *workHeader=0, *newHeader=0;
502  G4SmartVoxelProxy *newProxy=0;
503  G4SmartVoxelNode *newVoxelNode=0;
504  G4ThreeVector targetPoint, voxelPoint;
505  G4double workNodeWidth, workMinExtent, workCoord;
506  G4double minVal, maxVal, newDistance=0.;
507  G4double newHeaderMin, newHeaderNodeWidth;
508  G4int depth=0, newDepth=0, workNodeNo=0, newNodeNo=0, newHeaderNoSlices=0;
509  EAxis workHeaderAxis, newHeaderAxis;
510  G4bool isNewVoxel=false;
511 
512  G4double currentDistance = currentStep;
513  static const G4double sigma = 0.5*G4GeometryTolerance::GetInstance()
515 
516  // Determine if end of Step within current voxel
517  //
518  for (depth=0; depth<fVoxelDepth; depth++)
519  {
520  targetPoint = localPoint+localDirection*currentDistance;
521  newDistance = currentDistance;
522  workHeader = fVoxelHeaderStack[depth];
523  workHeaderAxis = fVoxelAxisStack[depth];
524  workNodeNo = fVoxelNodeNoStack[depth];
525  workNodeWidth = fVoxelSliceWidthStack[depth];
526  workMinExtent = workHeader->GetMinExtent();
527  workCoord = targetPoint(workHeaderAxis);
528  minVal = workMinExtent+workNodeNo*workNodeWidth;
529 
530  if ( minVal<=workCoord+sigma )
531  {
532  maxVal = minVal+workNodeWidth;
533  if ( maxVal<=workCoord-sigma )
534  {
535  // Must consider next voxel
536  //
537  newNodeNo = workNodeNo+1;
538  newHeader = workHeader;
539  newDistance = (maxVal-localPoint(workHeaderAxis))
540  / localDirection(workHeaderAxis);
541  isNewVoxel = true;
542  newDepth = depth;
543  }
544  }
545  else
546  {
547  newNodeNo = workNodeNo-1;
548  newHeader = workHeader;
549  newDistance = (minVal-localPoint(workHeaderAxis))
550  / localDirection(workHeaderAxis);
551  isNewVoxel = true;
552  newDepth = depth;
553  }
554  currentDistance = newDistance;
555  }
556  targetPoint = localPoint+localDirection*currentDistance;
557 
558  // Check if end of Step within collected boundaries of current voxel
559  //
560  depth = fVoxelDepth;
561  {
562  workHeader = fVoxelHeaderStack[depth];
563  workHeaderAxis = fVoxelAxisStack[depth];
564  workNodeNo = fVoxelNodeNoStack[depth];
565  workNodeWidth = fVoxelSliceWidthStack[depth];
566  workMinExtent = workHeader->GetMinExtent();
567  workCoord = targetPoint(workHeaderAxis);
568  minVal = workMinExtent+fVoxelNode->GetMinEquivalentSliceNo()*workNodeWidth;
569 
570  if ( minVal<=workCoord+sigma )
571  {
572  maxVal = workMinExtent+(fVoxelNode->GetMaxEquivalentSliceNo()+1)
573  *workNodeWidth;
574  if ( maxVal<=workCoord-sigma )
575  {
576  newNodeNo = fVoxelNode->GetMaxEquivalentSliceNo()+1;
577  newHeader = workHeader;
578  newDistance = (maxVal-localPoint(workHeaderAxis))
579  / localDirection(workHeaderAxis);
580  isNewVoxel = true;
581  newDepth = depth;
582  }
583  }
584  else
585  {
586  newNodeNo = fVoxelNode->GetMinEquivalentSliceNo()-1;
587  newHeader = workHeader;
588  newDistance = (minVal-localPoint(workHeaderAxis))
589  / localDirection(workHeaderAxis);
590  isNewVoxel = true;
591  newDepth = depth;
592  }
593  currentDistance = newDistance;
594  }
595  if (isNewVoxel)
596  {
597  // Compute new voxel & adjust voxel stack
598  //
599  // newNodeNo=Candidate node no at
600  // newDepth =refinement depth of crossed voxel boundary
601  // newHeader=Header for crossed voxel
602  // newDistance=distance to crossed voxel boundary (along the track)
603  //
604  if ( (newNodeNo<0) || (newNodeNo>=newHeader->GetNoSlices()))
605  {
606  // Leaving mother volume
607  //
608  isNewVoxel = false;
609  }
610  else
611  {
612  // Compute intersection point on the least refined
613  // voxel boundary that is hit
614  //
615  voxelPoint = localPoint+localDirection*newDistance;
616  fVoxelNodeNoStack[newDepth] = newNodeNo;
617  fVoxelDepth = newDepth;
618  newVoxelNode = 0;
619  while ( !newVoxelNode )
620  {
621  newProxy = newHeader->GetSlice(newNodeNo);
622  if (newProxy->IsNode())
623  {
624  newVoxelNode = newProxy->GetNode();
625  }
626  else
627  {
628  fVoxelDepth++;
629  newHeader = newProxy->GetHeader();
630  newHeaderAxis = newHeader->GetAxis();
631  newHeaderNoSlices = newHeader->GetNoSlices();
632  newHeaderMin = newHeader->GetMinExtent();
633  newHeaderNodeWidth = (newHeader->GetMaxExtent()-newHeaderMin)
634  / newHeaderNoSlices;
635  newNodeNo = G4int( (voxelPoint(newHeaderAxis)-newHeaderMin)
636  / newHeaderNodeWidth );
637  // Rounding protection
638  //
639  if ( newNodeNo<0 )
640  {
641  newNodeNo=0;
642  }
643  else if ( newNodeNo>=newHeaderNoSlices )
644  {
645  newNodeNo = newHeaderNoSlices-1;
646  }
647  // Stack info for stepping
648  //
649  fVoxelAxisStack[fVoxelDepth] = newHeaderAxis;
650  fVoxelNoSlicesStack[fVoxelDepth] = newHeaderNoSlices;
651  fVoxelSliceWidthStack[fVoxelDepth] = newHeaderNodeWidth;
652  fVoxelNodeNoStack[fVoxelDepth] = newNodeNo;
653  fVoxelHeaderStack[fVoxelDepth] = newHeader;
654  }
655  }
656  fVoxelNode = newVoxelNode;
657  }
658  }
659  return isNewVoxel;
660 }
661 
662 // ********************************************************************
663 // ComputeSafety
664 //
665 // Calculates the isotropic distance to the nearest boundary from the
666 // specified point in the local coordinate system.
667 // The localpoint utilised must be within the current volume.
668 // ********************************************************************
669 //
670 G4double
672  const G4NavigationHistory& history,
673  const G4double maxLength)
674 {
675  G4VPhysicalVolume *motherPhysical, *samplePhysical;
676  G4LogicalVolume *motherLogical;
677  G4VSolid *motherSolid;
678  G4double motherSafety, ourSafety;
679  G4int sampleNo;
680  G4SmartVoxelNode *curVoxelNode;
681  G4int curNoVolumes, contentNo;
682  G4double voxelSafety;
683 
684  motherPhysical = history.GetTopVolume();
685  motherLogical = motherPhysical->GetLogicalVolume();
686  motherSolid = motherLogical->GetSolid();
687 
688  if( fBestSafety )
689  {
690  return fpVoxelSafety->ComputeSafety( localPoint,*motherPhysical,maxLength );
691  }
692 
693  //
694  // Compute mother safety
695  //
696 
697  motherSafety = motherSolid->DistanceToOut(localPoint);
698  ourSafety = motherSafety; // Working isotropic safety
699 
700  if( motherSafety == 0.0 )
701  {
702 #ifdef G4DEBUG_NAVIGATION
703  // Check that point is inside mother volume
704  EInside insideMother= motherSolid->Inside(localPoint);
705 
706  if( insideMother == kOutside )
707  {
708  G4ExceptionDescription message;
709  message << "Safety method called for location outside current Volume." << G4endl
710  << "Location for safety is Outside this volume. " << G4endl
711  << "The approximate distance to the solid "
712  << "(safety from outside) is: "
713  << motherSolid->DistanceToIn( localPoint ) << G4endl;
714  message << " Problem occurred with physical volume: "
715  << " Name: " << motherPhysical->GetName()
716  << " Copy No: " << motherPhysical->GetCopyNo() << G4endl
717  << " Local Point = " << localPoint << G4endl;
718  message << " Description of solid: " << G4endl
719  << *motherSolid << G4endl;
720  G4Exception("G4VoxelNavigation::ComputeSafety()", "GeomNav0003",
721  JustWarning, // FatalException,
722  message);
723  }
724 
725  // Following check is NOT for an issue - it is only for information
726  // It is allowed that a solid gives approximate safety - even zero.
727  //
728  if( insideMother == kInside ) // && fVerbose )
729  {
730  G4ExceptionDescription messageIn;
731 
732  messageIn << " Point is Inside, but safety is Zero ." << G4endl;
733  messageIn << " Inexact safety for volume " << motherPhysical->GetName() << G4endl
734  << " Solid: Name= " << motherSolid->GetName()
735  << " Type= " << motherSolid->GetEntityType() << G4endl;
736  messageIn << " Local point= " << localPoint << G4endl;
737  messageIn << " Solid parameters: " << G4endl << *motherSolid << G4endl;
738  G4Exception("G4VoxelNavigation::ComputeSafety()", "GeomNav0003",
739  JustWarning, messageIn);
740  }
741 #endif
742  // if( insideMother != kInside )
743  return 0.0;
744  }
745 
746 #ifdef G4VERBOSE
747  if( fCheck )
748  {
749  fLogger->ComputeSafetyLog (motherSolid,localPoint,motherSafety,true,true);
750  }
751 #endif
752  //
753  // Compute daughter safeties
754  //
755  // Look only inside the current Voxel only (in the first version).
756  //
757  curVoxelNode = fVoxelNode;
758  curNoVolumes = curVoxelNode->GetNoContained();
759 
760  for ( contentNo=curNoVolumes-1; contentNo>=0; contentNo-- )
761  {
762  sampleNo = curVoxelNode->GetVolume(contentNo);
763  samplePhysical = motherLogical->GetDaughter(sampleNo);
764 
765  G4AffineTransform sampleTf(samplePhysical->GetRotation(),
766  samplePhysical->GetTranslation());
767  sampleTf.Invert();
768  const G4ThreeVector samplePoint =
769  sampleTf.TransformPoint(localPoint);
770  const G4VSolid *sampleSolid =
771  samplePhysical->GetLogicalVolume()->GetSolid();
772  G4double sampleSafety = sampleSolid->DistanceToIn(samplePoint);
773  if ( sampleSafety<ourSafety )
774  {
775  ourSafety = sampleSafety;
776  }
777 #ifdef G4VERBOSE
778  if( fCheck )
779  {
780  fLogger->ComputeSafetyLog(sampleSolid,samplePoint,sampleSafety,false,false);
781  }
782 #endif
783  }
784  voxelSafety = ComputeVoxelSafety(localPoint);
785  if ( voxelSafety<ourSafety )
786  {
787  ourSafety = voxelSafety;
788  }
789  return ourSafety;
790 }
791 
792 // ********************************************************************
793 // SetVerboseLevel
794 // ********************************************************************
795 //
797 {
798  if( fLogger ) fLogger->SetVerboseLevel(level);
800 }
void SetVerboseLevel(G4int level)
void AlongComputeStepLog(const G4VSolid *sampleSolid, const G4ThreeVector &samplePoint, const G4ThreeVector &sampleDirection, const G4ThreeVector &localDirection, G4double sampleSafety, G4double sampleStep) const
G4String GetName() const
G4SmartVoxelHeader * GetHeader() const
G4VPhysicalVolume * GetTopVolume() const
G4int GetMinEquivalentSliceNo() const
void PrintDaughterLog(const G4VSolid *sampleSolid, const G4ThreeVector &samplePoint, G4double sampleSafety, G4bool onlySafety, const G4ThreeVector &sampleDirection, G4double sampleStep) const
const G4ThreeVector & GetTranslation() const
static const G4double kInfinity
Definition: geomdefs.hh:42
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
CLHEP::Hep3Vector G4ThreeVector
CLHEP::HepRotation G4RotationMatrix
G4int GetVolume(G4int pVolumeNo) const
G4double ComputeVoxelSafety(const G4ThreeVector &localPoint) const
G4double GetSurfaceTolerance() const
G4VPhysicalVolume * GetDaughter(const G4int i) const
G4double ComputeSafety(const G4ThreeVector &localPoint, const G4VPhysicalVolume &currentPhysical, G4double maxLength=DBL_MAX)
virtual G4GeometryType GetEntityType() const =0
std::vector< G4SmartVoxelHeader * > fVoxelHeaderStack
int G4int
Definition: G4Types.hh:78
std::vector< EAxis > fVoxelAxisStack
G4int GetNoContained() const
G4int GetMaxEquivalentSliceNo() const
void ReportOutsideMother(const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, const G4VPhysicalVolume *motherPV, G4double tDist=30.0 *CLHEP::cm) const
G4bool IsNode() const
std::vector< G4double > fVoxelSliceWidthStack
G4AffineTransform & Invert()
EAxis GetAxis() const
G4BlockingList fBList
G4double GetMinExtent() const
const G4String & GetName() const
virtual EInside Inside(const G4ThreeVector &p) const =0
bool G4bool
Definition: G4Types.hh:79
G4bool LocateNextVoxel(const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, const G4double currentStep)
std::vector< G4int > fVoxelNodeNoStack
void BlockVolume(const G4int v)
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4NavigationHistory &history, const G4double pMaxLength=DBL_MAX)
G4bool IsBlocked(const G4int v) const
std::vector< G4int > fVoxelNoSlicesStack
G4bool CheckAndReportBadNormal(const G4ThreeVector &unitNormal, const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, G4double step, const G4VSolid *solid, const char *msg) const
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
static const double kMinExitingNormalCosine
Definition: geomdefs.hh:46
G4NavigationLogger * fLogger
G4int GetNoDaughters() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void SetVerboseLevel(G4int level)
G4ThreeVector TransformPoint(const G4ThreeVector &vec) const
virtual ~G4VoxelNavigation()
G4LogicalVolume * GetLogicalVolume() const
G4SmartVoxelNode * GetNode() const
EInside
Definition: geomdefs.hh:58
void ComputeSafetyLog(const G4VSolid *solid, const G4ThreeVector &point, G4double safety, G4bool isMotherVolume, G4int banner=-1) const
EAxis
Definition: geomdefs.hh:54
void SetVerboseLevel(G4int level)
void PreComputeStepLog(const G4VPhysicalVolume *motherPhysical, G4double motherSafety, const G4ThreeVector &localPoint) const
virtual G4int GetCopyNo() const =0
const G4RotationMatrix * GetRotation() const
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4VoxelSafety * fpVoxelSafety
static const G4int kNavigatorVoxelStackMax
Definition: geomdefs.hh:80
G4SmartVoxelNode * fVoxelNode
#define G4endl
Definition: G4ios.hh:61
void PostComputeStepLog(const G4VSolid *motherSolid, const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, G4double motherStep, G4double motherSafety) const
void CheckDaughterEntryPoint(const G4VSolid *sampleSolid, const G4ThreeVector &samplePoint, const G4ThreeVector &sampleDirection, const G4VSolid *motherSolid, const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, G4double motherStep, G4double sampleStep) const
double G4double
Definition: G4Types.hh:76
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const =0
virtual G4double ComputeStep(const G4ThreeVector &globalPoint, const G4ThreeVector &globalDirection, const G4double currentProposedStepLength, G4double &newSafety, G4NavigationHistory &history, G4bool &validExitNormal, G4ThreeVector &exitNormal, G4bool &exiting, G4bool &entering, G4VPhysicalVolume *(*pBlockedPhysical), G4int &blockedReplicaNo)
#define DBL_MAX
Definition: templates.hh:83
static G4GeometryTolerance * GetInstance()
G4VSolid * GetSolid() const
void Enlarge(const G4int nv)