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