Geant4  10.02.p02
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 97507 2016-06-03 12:48:42Z 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 // ********************************************************************
44 // Constructor
45 // ********************************************************************
46 //
48  : fBList(), fVoxelDepth(-1),
49  fVoxelAxisStack(kNavigatorVoxelStackMax,kXAxis),
50  fVoxelNoSlicesStack(kNavigatorVoxelStackMax,0),
51  fVoxelSliceWidthStack(kNavigatorVoxelStackMax,0.),
52  fVoxelNodeNoStack(kNavigatorVoxelStackMax,0),
53  fVoxelHeaderStack(kNavigatorVoxelStackMax,(G4SmartVoxelHeader*)0),
54  fVoxelNode(0), fpVoxelSafety(0), fCheck(false), fBestSafety(false)
55 {
56  fLogger= new G4NavigationLogger("G4VoxelNavigation");
59 
60 #ifdef G4DEBUG_NAVIGATION
61  SetVerboseLevel(5); // Reports most about daughter volumes
62 #endif
63 }
64 
65 // ********************************************************************
66 // Destructor
67 // ********************************************************************
68 //
70 {
71  delete fpVoxelSafety;
72  delete fLogger;
73 }
74 
75 // ********************************************************************
76 // ComputeStep
77 // ********************************************************************
78 //
81  const G4ThreeVector& localDirection,
82  const G4double currentProposedStepLength,
83  G4double& newSafety,
84  G4NavigationHistory& history,
85  G4bool& validExitNormal,
86  G4ThreeVector& exitNormal,
87  G4bool& exiting,
88  G4bool& entering,
89  G4VPhysicalVolume *(*pBlockedPhysical),
90  G4int& blockedReplicaNo )
91 {
92  G4VPhysicalVolume *motherPhysical, *samplePhysical, *blockedExitedVol=0;
93  G4LogicalVolume *motherLogical;
94  G4VSolid *motherSolid;
95  G4ThreeVector sampleDirection;
96  G4double ourStep=currentProposedStepLength, ourSafety;
97  G4double motherSafety, motherStep=DBL_MAX;
98  G4int localNoDaughters, sampleNo;
99 
100  G4bool initialNode, noStep;
101  G4SmartVoxelNode *curVoxelNode;
102  G4int curNoVolumes, contentNo;
103  G4double voxelSafety;
104 
105  motherPhysical = history.GetTopVolume();
106  motherLogical = motherPhysical->GetLogicalVolume();
107  motherSolid = motherLogical->GetSolid();
108 
109  //
110  // Compute mother safety
111  //
112 
113  motherSafety = motherSolid->DistanceToOut(localPoint);
114  ourSafety = motherSafety; // Working isotropic safety
115 
116 #ifdef G4VERBOSE
117  if ( fCheck )
118  {
119  fLogger->PreComputeStepLog (motherPhysical, motherSafety, localPoint);
120  }
121 #endif
122 
123  //
124  // Compute daughter safeties & intersections
125  //
126 
127  // Exiting normal optimisation
128  //
129  if ( exiting && validExitNormal )
130  {
131  if ( localDirection.dot(exitNormal)>=kMinExitingNormalCosine )
132  {
133  // Block exited daughter volume
134  //
135  blockedExitedVol = *pBlockedPhysical;
136  ourSafety = 0;
137  }
138  }
139  exiting = false;
140  entering = false;
141 
142  // For extra checking, get the distance to Mother early !!
143  G4bool motherValidExitNormal= false;
144  G4ThreeVector motherExitNormal(0.0, 0.0, 0.0);
145 
146 #ifdef G4VERBOSE
147  if ( fCheck )
148  {
149  // Compute early -- a) for validity
150  // b) to check against answer of daughters!
151  motherStep = motherSolid->DistanceToOut(localPoint,
152  localDirection,
153  true,
154  &motherValidExitNormal,
155  &motherExitNormal);
156 
157  fLogger->PostComputeStepLog(motherSolid, localPoint, localDirection,
158  motherStep, motherSafety);
159 
160  if( (motherStep >= kInfinity) || (motherStep < 0.0) )
161  {
162  // Error - indication of being outside solid !!
163  //
164  fLogger->ReportOutsideMother(localPoint, localDirection, motherPhysical);
165 
166  ourStep = 0.0;
167 
168  exiting= true;
169  entering= false;
170 
171  // validExitNormal= motherValidExitNormal;
172  // exitNormal= motherExitNormal;
173  // Makes sense and is useful only if the point is very close ...
174  // Alternatives: i) validExitNormal= false;
175  // ii) Check safety from outside and choose !!
176  validExitNormal= false;
177 
178  *pBlockedPhysical= 0; // or motherPhysical ?
179  blockedReplicaNo= 0; // or motherReplicaNumber ?
180 
181  newSafety= 0.0;
182  return ourStep;
183  }
184  }
185 #endif
186 
187  localNoDaughters = motherLogical->GetNoDaughters();
188 
189  fBList.Enlarge(localNoDaughters);
190  fBList.Reset();
191 
192  initialNode = true;
193  noStep = true;
194 
195  while (noStep)
196  {
197  curVoxelNode = fVoxelNode;
198  curNoVolumes = curVoxelNode->GetNoContained();
199  for (contentNo=curNoVolumes-1; contentNo>=0; contentNo--)
200  {
201  sampleNo = curVoxelNode->GetVolume(contentNo);
202  if ( !fBList.IsBlocked(sampleNo) )
203  {
204  fBList.BlockVolume(sampleNo);
205  samplePhysical = motherLogical->GetDaughter(sampleNo);
206  if ( samplePhysical!=blockedExitedVol )
207  {
208  G4AffineTransform sampleTf(samplePhysical->GetRotation(),
209  samplePhysical->GetTranslation());
210  sampleTf.Invert();
211  const G4ThreeVector samplePoint =
212  sampleTf.TransformPoint(localPoint);
213  const G4VSolid *sampleSolid =
214  samplePhysical->GetLogicalVolume()->GetSolid();
215  const G4double sampleSafety =
216  sampleSolid->DistanceToIn(samplePoint);
217 
218  if ( sampleSafety<ourSafety )
219  {
220  ourSafety = sampleSafety;
221  }
222  if ( sampleSafety<=ourStep )
223  {
224  sampleDirection = sampleTf.TransformAxis(localDirection);
225  G4double sampleStep =
226  sampleSolid->DistanceToIn(samplePoint, sampleDirection);
227 #ifdef G4VERBOSE
228  if( fCheck )
229  {
230  fLogger->PrintDaughterLog(sampleSolid, samplePoint,
231  sampleSafety, true,
232  sampleDirection, sampleStep);
233  }
234 #endif
235  if ( sampleStep<=ourStep )
236  {
237  ourStep = sampleStep;
238  entering = true;
239  exiting = false;
240  *pBlockedPhysical = samplePhysical;
241  blockedReplicaNo = -1;
242 #ifdef G4VERBOSE
243  // Check to see that the resulting point is indeed in/on volume.
244  // This could be done only for successful candidate.
245  if ( fCheck )
246  {
247  fLogger->AlongComputeStepLog (sampleSolid, samplePoint,
248  sampleDirection, localDirection, sampleSafety, sampleStep);
249  }
250 #endif
251  }
252 #ifdef G4VERBOSE
253  if ( fCheck && ( sampleStep < kInfinity )
254  && ( sampleStep >= motherStep ) )
255  {
256  // The intersection point with the daughter is after the exit
257  // point from the mother volume. Double check this !!
258  fLogger->CheckDaughterEntryPoint(sampleSolid,
259  samplePoint, sampleDirection,
260  motherSolid,
261  localPoint, localDirection,
262  motherStep, sampleStep);
263  }
264 #endif
265  }
266 #ifdef G4VERBOSE
267  else // ie if sampleSafety > outStep
268  {
269  if( fCheck )
270  {
271  fLogger->PrintDaughterLog(sampleSolid, samplePoint,
272  sampleSafety, false,
273  G4ThreeVector(0.,0.,0.), -1.0 );
274  }
275  }
276 #endif
277  }
278  }
279  }
280  if (initialNode)
281  {
282  initialNode = false;
283  voxelSafety = ComputeVoxelSafety(localPoint);
284  if ( voxelSafety<ourSafety )
285  {
286  ourSafety = voxelSafety;
287  }
288  if ( currentProposedStepLength<ourSafety )
289  {
290  // Guaranteed physics limited
291  //
292  noStep = false;
293  entering = false;
294  exiting = false;
295  *pBlockedPhysical = 0;
296  ourStep = kInfinity;
297  }
298  else
299  {
300  //
301  // Compute mother intersection if required
302  //
303  if ( motherSafety<=ourStep )
304  {
305  if( !fCheck )
306  {
307  motherStep = motherSolid->DistanceToOut(localPoint, localDirection,
308  true, &motherValidExitNormal, &motherExitNormal);
309  }
310  // Not correct - unless mother limits step (see below)
311  // validExitNormal= motherValidExitNormal;
312  // exitNormal= motherExitNormal;
313 #ifdef G4VERBOSE
314  else // check_mode
315  {
316  fLogger->PostComputeStepLog(motherSolid, localPoint, localDirection,
317  motherStep, motherSafety);
318  if( motherValidExitNormal )
319  {
320  fLogger->CheckAndReportBadNormal(motherExitNormal,
321  localPoint, localDirection,
322  motherStep, motherSolid,
323  "From motherSolid::DistanceToOut" );
324  }
325  }
326 #endif
327  if( (motherStep >= kInfinity) || (motherStep < 0.0) )
328  {
329 #ifdef G4VERBOSE
330  if( fCheck ) // Error - indication of being outside solid !!
331  {
332  fLogger->ReportOutsideMother(localPoint, localDirection,
333  motherPhysical);
334  }
335 #endif
336  motherStep = 0.0;
337  ourStep = 0.0;
338  exiting = true;
339  entering = false;
340 
341  // validExitNormal= motherValidExitNormal;
342  // exitNormal= motherExitNormal;
343  // Useful only if the point is very close to surface
344  // => but it would need to be rotated to grand-mother ref frame !
345  validExitNormal= false;
346 
347  *pBlockedPhysical= 0; // or motherPhysical ?
348  blockedReplicaNo= 0; // or motherReplicaNumber ?
349 
350  newSafety= 0.0;
351  return ourStep;
352  }
353 
354  if ( motherStep<=ourStep )
355  {
356  ourStep = motherStep;
357  exiting = true;
358  entering = false;
359 
360  // Exit normal: Natural location to set these;confirmed short step
361  //
362  validExitNormal= motherValidExitNormal;
363  exitNormal= motherExitNormal;
364 
365  if ( validExitNormal )
366  {
367  const G4RotationMatrix *rot = motherPhysical->GetRotation();
368  if (rot)
369  {
370  exitNormal *= rot->inverse();
371 #ifdef G4VERBOSE
372  if( fCheck )
373  fLogger->CheckAndReportBadNormal(exitNormal, // rotated
374  motherExitNormal, // original
375  *rot,
376  // motherPhysical,
377  "From RotationMatrix" );
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 
514  // Determine if end of Step within current voxel
515  //
516  for (depth=0; depth<fVoxelDepth; depth++)
517  {
518  targetPoint = localPoint+localDirection*currentDistance;
519  newDistance = currentDistance;
520  workHeader = fVoxelHeaderStack[depth];
521  workHeaderAxis = fVoxelAxisStack[depth];
522  workNodeNo = fVoxelNodeNoStack[depth];
523  workNodeWidth = fVoxelSliceWidthStack[depth];
524  workMinExtent = workHeader->GetMinExtent();
525  workCoord = targetPoint(workHeaderAxis);
526  minVal = workMinExtent+workNodeNo*workNodeWidth;
527 
528  if ( minVal<=workCoord+fHalfTolerance )
529  {
530  maxVal = minVal+workNodeWidth;
531  if ( maxVal<=workCoord-fHalfTolerance )
532  {
533  // Must consider next voxel
534  //
535  newNodeNo = workNodeNo+1;
536  newHeader = workHeader;
537  newDistance = (maxVal-localPoint(workHeaderAxis))
538  / localDirection(workHeaderAxis);
539  isNewVoxel = true;
540  newDepth = depth;
541  }
542  }
543  else
544  {
545  newNodeNo = workNodeNo-1;
546  newHeader = workHeader;
547  newDistance = (minVal-localPoint(workHeaderAxis))
548  / localDirection(workHeaderAxis);
549  isNewVoxel = true;
550  newDepth = depth;
551  }
552  currentDistance = newDistance;
553  }
554  targetPoint = localPoint+localDirection*currentDistance;
555 
556  // Check if end of Step within collected boundaries of current voxel
557  //
558  depth = fVoxelDepth;
559  {
560  workHeader = fVoxelHeaderStack[depth];
561  workHeaderAxis = fVoxelAxisStack[depth];
562  workNodeNo = fVoxelNodeNoStack[depth];
563  workNodeWidth = fVoxelSliceWidthStack[depth];
564  workMinExtent = workHeader->GetMinExtent();
565  workCoord = targetPoint(workHeaderAxis);
566  minVal = workMinExtent+fVoxelNode->GetMinEquivalentSliceNo()*workNodeWidth;
567 
568  if ( minVal<=workCoord+fHalfTolerance )
569  {
570  maxVal = workMinExtent+(fVoxelNode->GetMaxEquivalentSliceNo()+1)
571  *workNodeWidth;
572  if ( maxVal<=workCoord-fHalfTolerance )
573  {
574  newNodeNo = fVoxelNode->GetMaxEquivalentSliceNo()+1;
575  newHeader = workHeader;
576  newDistance = (maxVal-localPoint(workHeaderAxis))
577  / localDirection(workHeaderAxis);
578  isNewVoxel = true;
579  newDepth = depth;
580  }
581  }
582  else
583  {
584  newNodeNo = fVoxelNode->GetMinEquivalentSliceNo()-1;
585  newHeader = workHeader;
586  newDistance = (minVal-localPoint(workHeaderAxis))
587  / localDirection(workHeaderAxis);
588  isNewVoxel = true;
589  newDepth = depth;
590  }
591  currentDistance = newDistance;
592  }
593  if (isNewVoxel)
594  {
595  // Compute new voxel & adjust voxel stack
596  //
597  // newNodeNo=Candidate node no at
598  // newDepth =refinement depth of crossed voxel boundary
599  // newHeader=Header for crossed voxel
600  // newDistance=distance to crossed voxel boundary (along the track)
601  //
602  if ( (newNodeNo<0) || (newNodeNo>=newHeader->GetNoSlices()))
603  {
604  // Leaving mother volume
605  //
606  isNewVoxel = false;
607  }
608  else
609  {
610  // Compute intersection point on the least refined
611  // voxel boundary that is hit
612  //
613  voxelPoint = localPoint+localDirection*newDistance;
614  fVoxelNodeNoStack[newDepth] = newNodeNo;
615  fVoxelDepth = newDepth;
616  newVoxelNode = 0;
617  while ( !newVoxelNode )
618  {
619  newProxy = newHeader->GetSlice(newNodeNo);
620  if (newProxy->IsNode())
621  {
622  newVoxelNode = newProxy->GetNode();
623  }
624  else
625  {
626  fVoxelDepth++;
627  newHeader = newProxy->GetHeader();
628  newHeaderAxis = newHeader->GetAxis();
629  newHeaderNoSlices = newHeader->GetNoSlices();
630  newHeaderMin = newHeader->GetMinExtent();
631  newHeaderNodeWidth = (newHeader->GetMaxExtent()-newHeaderMin)
632  / newHeaderNoSlices;
633  newNodeNo = G4int( (voxelPoint(newHeaderAxis)-newHeaderMin)
634  / newHeaderNodeWidth );
635  // Rounding protection
636  //
637  if ( newNodeNo<0 )
638  {
639  newNodeNo=0;
640  }
641  else if ( newNodeNo>=newHeaderNoSlices )
642  {
643  newNodeNo = newHeaderNoSlices-1;
644  }
645  // Stack info for stepping
646  //
647  fVoxelAxisStack[fVoxelDepth] = newHeaderAxis;
648  fVoxelNoSlicesStack[fVoxelDepth] = newHeaderNoSlices;
649  fVoxelSliceWidthStack[fVoxelDepth] = newHeaderNodeWidth;
650  fVoxelNodeNoStack[fVoxelDepth] = newNodeNo;
651  fVoxelHeaderStack[fVoxelDepth] = newHeader;
652  }
653  }
654  fVoxelNode = newVoxelNode;
655  }
656  }
657  return isNewVoxel;
658 }
659 
660 // ********************************************************************
661 // ComputeSafety
662 //
663 // Calculates the isotropic distance to the nearest boundary from the
664 // specified point in the local coordinate system.
665 // The localpoint utilised must be within the current volume.
666 // ********************************************************************
667 //
668 G4double
670  const G4NavigationHistory& history,
671  const G4double maxLength)
672 {
673  G4VPhysicalVolume *motherPhysical, *samplePhysical;
674  G4LogicalVolume *motherLogical;
675  G4VSolid *motherSolid;
676  G4double motherSafety, ourSafety;
677  G4int sampleNo;
678  G4SmartVoxelNode *curVoxelNode;
679  G4int curNoVolumes, contentNo;
680  G4double voxelSafety;
681 
682  motherPhysical = history.GetTopVolume();
683  motherLogical = motherPhysical->GetLogicalVolume();
684  motherSolid = motherLogical->GetSolid();
685 
686  if( fBestSafety )
687  {
688  return fpVoxelSafety->ComputeSafety( localPoint,*motherPhysical,maxLength );
689  }
690 
691  //
692  // Compute mother safety
693  //
694 
695  motherSafety = motherSolid->DistanceToOut(localPoint);
696  ourSafety = motherSafety; // Working isotropic safety
697 
698  if( motherSafety == 0.0 )
699  {
700 #ifdef G4DEBUG_NAVIGATION
701  // Check that point is inside mother volume
702  EInside insideMother= motherSolid->Inside(localPoint);
703 
704  if( insideMother == kOutside )
705  {
706  G4ExceptionDescription message;
707  message << "Safety method called for location outside current Volume." << G4endl
708  << "Location for safety is Outside this volume. " << G4endl
709  << "The approximate distance to the solid "
710  << "(safety from outside) is: "
711  << motherSolid->DistanceToIn( localPoint ) << G4endl;
712  message << " Problem occurred with physical volume: "
713  << " Name: " << motherPhysical->GetName()
714  << " Copy No: " << motherPhysical->GetCopyNo() << G4endl
715  << " Local Point = " << localPoint << G4endl;
716  message << " Description of solid: " << G4endl
717  << *motherSolid << G4endl;
718  G4Exception("G4VoxelNavigation::ComputeSafety()", "GeomNav0003",
719  JustWarning, // FatalException,
720  message);
721  }
722 
723  // Following check is NOT for an issue - it is only for information
724  // It is allowed that a solid gives approximate safety - even zero.
725  //
726  if( insideMother == kInside ) // && fVerbose )
727  {
728  G4ExceptionDescription messageIn;
729 
730  messageIn << " Point is Inside, but safety is Zero ." << G4endl;
731  messageIn << " Inexact safety for volume " << motherPhysical->GetName() << G4endl
732  << " Solid: Name= " << motherSolid->GetName()
733  << " Type= " << motherSolid->GetEntityType() << G4endl;
734  messageIn << " Local point= " << localPoint << G4endl;
735  messageIn << " Solid parameters: " << G4endl << *motherSolid << G4endl;
736  G4Exception("G4VoxelNavigation::ComputeSafety()", "GeomNav0003",
737  JustWarning, messageIn);
738  }
739 #endif
740  // if( insideMother != kInside )
741  return 0.0;
742  }
743 
744 #ifdef G4VERBOSE
745  if( fCheck )
746  {
747  fLogger->ComputeSafetyLog (motherSolid,localPoint,motherSafety,true,true);
748  }
749 #endif
750  //
751  // Compute daughter safeties
752  //
753  // Look only inside the current Voxel only (in the first version).
754  //
755  curVoxelNode = fVoxelNode;
756  curNoVolumes = curVoxelNode->GetNoContained();
757 
758  for ( contentNo=curNoVolumes-1; contentNo>=0; contentNo-- )
759  {
760  sampleNo = curVoxelNode->GetVolume(contentNo);
761  samplePhysical = motherLogical->GetDaughter(sampleNo);
762 
763  G4AffineTransform sampleTf(samplePhysical->GetRotation(),
764  samplePhysical->GetTranslation());
765  sampleTf.Invert();
766  const G4ThreeVector samplePoint =
767  sampleTf.TransformPoint(localPoint);
768  const G4VSolid *sampleSolid =
769  samplePhysical->GetLogicalVolume()->GetSolid();
770  G4double sampleSafety = sampleSolid->DistanceToIn(samplePoint);
771  if ( sampleSafety<ourSafety )
772  {
773  ourSafety = sampleSafety;
774  }
775 #ifdef G4VERBOSE
776  if( fCheck )
777  {
778  fLogger->ComputeSafetyLog(sampleSolid,samplePoint,sampleSafety,false,false);
779  }
780 #endif
781  }
782  voxelSafety = ComputeVoxelSafety(localPoint);
783  if ( voxelSafety<ourSafety )
784  {
785  ourSafety = voxelSafety;
786  }
787  return ourSafety;
788 }
789 
790 // ********************************************************************
791 // SetVerboseLevel
792 // ********************************************************************
793 //
795 {
796  if( fLogger ) fLogger->SetVerboseLevel(level);
798 }
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)