Geant4 Cross Reference |
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 // 34 inline 35 G4int 36 G4ReplicaNavigation::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 { 110 targetNodeNo = targetHeaderNoSlices-1; 111 } 112 else if ( targetNodeNo>=targetHeaderNoSlices ) 113 { 114 targetNodeNo = 0; 115 } 116 } 117 else 118 { 119 if( targetNodeNo<0 ) 120 { 121 targetNodeNo = 0; 122 } 123 else if ( targetNodeNo>=targetHeaderNoSlices ) 124 { 125 targetNodeNo = targetHeaderNoSlices-1; 126 } 127 } 128 } 129 } 130 else 131 { 132 // Rounding protection 133 // 134 if ( targetNodeNo<0 ) 135 { 136 targetNodeNo = 0; 137 } 138 else if ( targetNodeNo>=targetHeaderNoSlices ) 139 { 140 targetNodeNo = targetHeaderNoSlices-1; 141 } 142 } 143 return targetNodeNo; 144 } 145 146 // ******************************************************************** 147 // LevelLocate 148 // ******************************************************************** 149 // 150 inline 151 G4bool 152 G4ReplicaNavigation::LevelLocate( G4NavigationHistory& history, 153 const G4VPhysicalVolume* blockedVol, 154 const G4int blockedNum, 155 const G4ThreeVector&, // globalPoint 156 const G4ThreeVector*, // globalDirection 157 const G4bool, // pLocatedOnEdge 158 G4ThreeVector& localPoint ) 159 { 160 G4VPhysicalVolume *motherPhysical, *pPhysical; 161 G4LogicalVolume *motherLogical; 162 G4SmartVoxelHeader *motherVoxelHeader; 163 G4int nodeNo; 164 165 motherPhysical = history.GetTopVolume(); 166 motherLogical = motherPhysical->GetLogicalVolume(); 167 motherVoxelHeader = motherLogical->GetVoxelHeader(); 168 pPhysical = motherLogical->GetDaughter(0); 169 170 if ( blockedVol==pPhysical ) 171 { 172 nodeNo = VoxelLocate(motherVoxelHeader, localPoint, blockedNum); 173 } 174 else 175 { 176 nodeNo = VoxelLocate(motherVoxelHeader, localPoint); 177 } 178 179 ComputeTransformation(nodeNo, pPhysical, localPoint); 180 history.NewLevel(pPhysical, kReplica, nodeNo); 181 pPhysical->SetCopyNo(nodeNo); 182 183 return true; 184 } 185 186 // ******************************************************************** 187 // SetPhiTransformation 188 // ******************************************************************** 189 // 190 inline 191 void 192 G4ReplicaNavigation::SetPhiTransformation( const G4double ang, 193 G4VPhysicalVolume* pVol ) const 194 { 195 G4RotationMatrix rm; 196 rm.rotateZ(ang); 197 if ( pVol != nullptr ) 198 { 199 *pVol->GetRotation() = rm; 200 } 201 } 202 203 // ******************************************************************** 204 // GetVerboseLevel 205 // ******************************************************************** 206 // 207 inline 208 G4int G4ReplicaNavigation::GetVerboseLevel() const 209 { 210 return fVerbose; 211 } 212 213 // ******************************************************************** 214 // SetVerboseLevel 215 // ******************************************************************** 216 // 217 inline 218 void G4ReplicaNavigation::SetVerboseLevel(G4int level) 219 { 220 fVerbose = level; 221 } 222 223 // ******************************************************************** 224 // CheckMode 225 // ******************************************************************** 226 // 227 inline 228 void G4ReplicaNavigation::CheckMode(G4bool mode) 229 { 230 fCheck = mode; 231 } 232