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