Geant4-11
G4ReplicaNavigation.icc
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// class G4ReplicaNavigation Inline implementation
27//
28// --------------------------------------------------------------------
29
30// ********************************************************************
31// VoxelLocate
32// ********************************************************************
33//
34inline
35G4int
36G4ReplicaNavigation::VoxelLocate( const G4SmartVoxelHeader* pHead,
37 const G4ThreeVector& localPoint,
38 const G4int blocked ) const
39{
40 EAxis targetHeaderAxis;
41 G4double coord = 0.;
42 G4double targetHeaderMin, targetHeaderMax;
43 G4double targetHeaderNodeWidth, targetNodePos;
44 G4int targetHeaderNoSlices, targetNodeNo;
45
46 targetHeaderAxis = pHead->GetAxis();
47 targetHeaderNoSlices = G4int(pHead->GetNoSlices());
48 targetHeaderMin = pHead->GetMinExtent();
49 targetHeaderMax = pHead->GetMaxExtent();
50 targetHeaderNodeWidth = ( targetHeaderMax-targetHeaderMin )
51 / targetHeaderNoSlices;
52
53 switch (targetHeaderAxis)
54 {
55 case kXAxis:
56 coord = localPoint.x();
57 break;
58 case kYAxis:
59 coord = localPoint.y();
60 break;
61 case kZAxis:
62 coord = localPoint.z();
63 break;
64 case kRho:
65 coord = localPoint.perp();
66 break;
67 case kPhi:
68 coord = localPoint.phi();
69 if ( (coord<0) && (coord<targetHeaderMin) ) coord += CLHEP::twopi;
70 break;
71 case kRadial3D:
72 default:
73 break;
74 }
75 targetNodePos = (coord-targetHeaderMin)/targetHeaderNodeWidth;
76 targetNodeNo = (G4int) targetNodePos;
77
78 if ( targetNodeNo==blocked )
79 {
80 targetNodeNo = (targetNodePos-targetNodeNo<0.5)
81 ? targetNodeNo-1 : targetNodeNo+1;
82
83 // Do not need to check range: If on outer edge of zeroth
84 // voxel & it is blocked => should have exited mother
85 // (or similar) P.Kent
86 // assert(targetNodeNo>=0&&targetNodeNo<targetHeaderNoSlices);
87
88 if( (targetNodeNo<0) || (targetNodeNo>=targetHeaderNoSlices) )
89 {
90
91#ifdef G4DEBUG_NAVIGATION
92 std::ostringstream message;
93 message << "Voxel location failed:" << G4endl
94 << " (targetNodeNo>=0&&targetNodeNo<targetHeaderNoSlices) "
95 << G4endl
96 << " - targetNodeNo= " << targetNodeNo << G4endl
97 << " - Number of Slices = " << targetHeaderNoSlices;
98 G4Exception("G4ReplicaNavigation::VoxelLocate()",
99 "GeomNav1002", JustWarning, message);
100#endif
101 // In the case of rotational symmetry and an extent over the
102 // whole 360 degrees, the above is not true and you can go from
103 // the last voxel to the zeroth and vice versa
104 // H.Boie, April 30, 2001
105 if ( (targetHeaderAxis==kPhi)
106 && (targetHeaderMin==0) && (targetHeaderMax==CLHEP::twopi) )
107 {
108 if ( targetNodeNo<0 )
109 targetNodeNo = targetHeaderNoSlices-1;
110 else if ( targetNodeNo>=targetHeaderNoSlices )
111 targetNodeNo = 0;
112 }
113 else
114 {
115 if( targetNodeNo<0 )
116 targetNodeNo = 0;
117 else if ( targetNodeNo>=targetHeaderNoSlices )
118 targetNodeNo = targetHeaderNoSlices-1;
119 }
120 }
121 }
122 else
123 {
124 // Rounding protection
125 //
126 if ( targetNodeNo<0 )
127 {
128 targetNodeNo = 0;
129 }
130 else if ( targetNodeNo>=targetHeaderNoSlices )
131 {
132 targetNodeNo = targetHeaderNoSlices-1;
133 }
134 }
135 return targetNodeNo;
136}
137
138// ********************************************************************
139// LevelLocate
140// ********************************************************************
141//
142inline
143G4bool
144G4ReplicaNavigation::LevelLocate( G4NavigationHistory& history,
145 const G4VPhysicalVolume* blockedVol,
146 const G4int blockedNum,
147 const G4ThreeVector&, // globalPoint
148 const G4ThreeVector*, // globalDirection
149 const G4bool, // pLocatedOnEdge
150 G4ThreeVector& localPoint )
151{
152 G4VPhysicalVolume *motherPhysical, *pPhysical;
153 G4LogicalVolume *motherLogical;
154 G4SmartVoxelHeader *motherVoxelHeader;
155 G4int nodeNo;
156
157 motherPhysical = history.GetTopVolume();
158 motherLogical = motherPhysical->GetLogicalVolume();
159 motherVoxelHeader = motherLogical->GetVoxelHeader();
160 pPhysical = motherLogical->GetDaughter(0);
161
162 if ( blockedVol==pPhysical )
163 {
164 nodeNo = VoxelLocate(motherVoxelHeader, localPoint, blockedNum);
165 }
166 else
167 {
168 nodeNo = VoxelLocate(motherVoxelHeader, localPoint);
169 }
170
171 ComputeTransformation(nodeNo, pPhysical, localPoint);
172 history.NewLevel(pPhysical, kReplica, nodeNo);
173 pPhysical->SetCopyNo(nodeNo);
174
175 return true;
176}
177
178// ********************************************************************
179// SetPhiTransformation
180// ********************************************************************
181//
182inline
183void
184G4ReplicaNavigation::SetPhiTransformation( const G4double ang,
185 G4VPhysicalVolume* pVol ) const
186{
187 G4RotationMatrix rm;
188 rm.rotateZ(ang);
189 if ( pVol != nullptr )
190 {
191 *pVol->GetRotation() = rm;
192 }
193}
194
195// ********************************************************************
196// GetVerboseLevel
197// ********************************************************************
198//
199inline
200G4int G4ReplicaNavigation::GetVerboseLevel() const
201{
202 return fVerbose;
203}
204
205// ********************************************************************
206// SetVerboseLevel
207// ********************************************************************
208//
209inline
210void G4ReplicaNavigation::SetVerboseLevel(G4int level)
211{
212 fVerbose = level;
213}
214
215// ********************************************************************
216// CheckMode
217// ********************************************************************
218//
219inline
220void G4ReplicaNavigation::CheckMode(G4bool mode)
221{
222 fCheck = mode;
223}