Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // >> 26 // >> 27 // $Id: G4PhantomParameterisation.cc,v 1.7 2010-07-13 15:59:42 gcosmo Exp $ >> 28 // GEANT4 tag $ Name:$ >> 29 // 26 // class G4PhantomParameterisation implementat 30 // class G4PhantomParameterisation implementation 27 // 31 // 28 // May 2007 Pedro Arce, first version << 32 // May 2007 Pedro Arce, first version 29 // 33 // 30 // ------------------------------------------- 34 // -------------------------------------------------------------------- 31 35 32 #include "G4PhantomParameterisation.hh" 36 #include "G4PhantomParameterisation.hh" 33 37 34 #include "globals.hh" 38 #include "globals.hh" 35 #include "G4VSolid.hh" 39 #include "G4VSolid.hh" 36 #include "G4VPhysicalVolume.hh" 40 #include "G4VPhysicalVolume.hh" 37 #include "G4LogicalVolume.hh" 41 #include "G4LogicalVolume.hh" 38 #include "G4VVolumeMaterialScanner.hh" 42 #include "G4VVolumeMaterialScanner.hh" 39 #include "G4GeometryTolerance.hh" 43 #include "G4GeometryTolerance.hh" 40 44 41 //-------------------------------------------- 45 //------------------------------------------------------------------ 42 G4PhantomParameterisation::G4PhantomParameteri 46 G4PhantomParameterisation::G4PhantomParameterisation() >> 47 : fVoxelHalfX(0.), fVoxelHalfY(0.), fVoxelHalfZ(0.), >> 48 fNoVoxelX(0), fNoVoxelY(0), fNoVoxelZ(0), fNoVoxelXY(0), fNoVoxel(0), >> 49 fMaterialIndices(0), fContainerSolid(0), >> 50 fContainerWallX(0.), fContainerWallY(0.), fContainerWallZ(0.), >> 51 bSkipEqualMaterials(true) 43 { 52 { 44 kCarTolerance = G4GeometryTolerance::GetInst 53 kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); 45 } 54 } 46 55 47 << 56 48 //-------------------------------------------- 57 //------------------------------------------------------------------ 49 G4PhantomParameterisation::~G4PhantomParameter << 58 G4PhantomParameterisation::~G4PhantomParameterisation() >> 59 { >> 60 } 50 61 51 62 52 //-------------------------------------------- 63 //------------------------------------------------------------------ 53 void G4PhantomParameterisation:: 64 void G4PhantomParameterisation:: 54 BuildContainerSolid( G4VPhysicalVolume* pMothe << 65 BuildContainerSolid( G4VPhysicalVolume *pMotherPhysical ) 55 { 66 { 56 fContainerSolid = pMotherPhysical->GetLogica 67 fContainerSolid = pMotherPhysical->GetLogicalVolume()->GetSolid(); 57 fContainerWallX = fNoVoxelsX * fVoxelHalfX; << 68 fContainerWallX = fNoVoxelX * fVoxelHalfX; 58 fContainerWallY = fNoVoxelsY * fVoxelHalfY; << 69 fContainerWallY = fNoVoxelY * fVoxelHalfY; 59 fContainerWallZ = fNoVoxelsZ * fVoxelHalfZ; << 70 fContainerWallZ = fNoVoxelZ * fVoxelHalfZ; 60 71 61 // CheckVoxelsFillContainer(); 72 // CheckVoxelsFillContainer(); 62 } 73 } 63 74 64 << 65 //-------------------------------------------- 75 //------------------------------------------------------------------ 66 void G4PhantomParameterisation:: 76 void G4PhantomParameterisation:: 67 BuildContainerSolid( G4VSolid* pMotherSolid ) << 77 BuildContainerSolid( G4VSolid *pMotherSolid ) 68 { 78 { 69 fContainerSolid = pMotherSolid; 79 fContainerSolid = pMotherSolid; 70 fContainerWallX = fNoVoxelsX * fVoxelHalfX; << 80 fContainerWallX = fNoVoxelX * fVoxelHalfX; 71 fContainerWallY = fNoVoxelsY * fVoxelHalfY; << 81 fContainerWallY = fNoVoxelY * fVoxelHalfY; 72 fContainerWallZ = fNoVoxelsZ * fVoxelHalfZ; << 82 fContainerWallZ = fNoVoxelZ * fVoxelHalfZ; 73 83 74 // CheckVoxelsFillContainer(); 84 // CheckVoxelsFillContainer(); 75 } 85 } 76 86 77 87 78 //-------------------------------------------- 88 //------------------------------------------------------------------ 79 void G4PhantomParameterisation:: 89 void G4PhantomParameterisation:: 80 ComputeTransformation(const G4int copyNo, G4VP << 90 ComputeTransformation(const G4int copyNo, G4VPhysicalVolume *physVol ) const 81 { 91 { 82 // Voxels cannot be rotated, return translat 92 // Voxels cannot be rotated, return translation 83 // 93 // 84 G4ThreeVector trans = GetTranslation( copyNo 94 G4ThreeVector trans = GetTranslation( copyNo ); 85 95 86 physVol->SetTranslation( trans ); 96 physVol->SetTranslation( trans ); 87 } 97 } 88 98 89 99 90 //-------------------------------------------- 100 //------------------------------------------------------------------ 91 G4ThreeVector G4PhantomParameterisation:: 101 G4ThreeVector G4PhantomParameterisation:: 92 GetTranslation(const G4int copyNo ) const 102 GetTranslation(const G4int copyNo ) const 93 { 103 { 94 CheckCopyNo( copyNo ); 104 CheckCopyNo( copyNo ); 95 105 96 std::size_t nx; << 106 size_t nx; 97 std::size_t ny; << 107 size_t ny; 98 std::size_t nz; << 108 size_t nz; 99 109 100 ComputeVoxelIndices( copyNo, nx, ny, nz ); 110 ComputeVoxelIndices( copyNo, nx, ny, nz ); 101 111 102 G4ThreeVector trans( (2*nx+1)*fVoxelHalfX - 112 G4ThreeVector trans( (2*nx+1)*fVoxelHalfX - fContainerWallX, 103 (2*ny+1)*fVoxelHalfY - 113 (2*ny+1)*fVoxelHalfY - fContainerWallY, 104 (2*nz+1)*fVoxelHalfZ - 114 (2*nz+1)*fVoxelHalfZ - fContainerWallZ); 105 return trans; 115 return trans; 106 } 116 } 107 117 108 118 109 //-------------------------------------------- 119 //------------------------------------------------------------------ 110 G4VSolid* G4PhantomParameterisation:: 120 G4VSolid* G4PhantomParameterisation:: 111 ComputeSolid(const G4int, G4VPhysicalVolume* p << 121 ComputeSolid(const G4int, G4VPhysicalVolume *pPhysicalVol) 112 { 122 { 113 return pPhysicalVol->GetLogicalVolume()->Get 123 return pPhysicalVol->GetLogicalVolume()->GetSolid(); 114 } 124 } 115 125 116 126 117 //-------------------------------------------- 127 //------------------------------------------------------------------ 118 G4Material* G4PhantomParameterisation:: 128 G4Material* G4PhantomParameterisation:: 119 ComputeMaterial(const G4int copyNo, G4VPhysica 129 ComputeMaterial(const G4int copyNo, G4VPhysicalVolume *, const G4VTouchable *) 120 { 130 { 121 CheckCopyNo( copyNo ); 131 CheckCopyNo( copyNo ); 122 std::size_t matIndex = GetMaterialIndex(copy << 132 size_t matIndex = GetMaterialIndex(copyNo); 123 133 124 return fMaterials[ matIndex ]; 134 return fMaterials[ matIndex ]; 125 } 135 } 126 136 127 137 128 //-------------------------------------------- 138 //------------------------------------------------------------------ 129 std::size_t G4PhantomParameterisation:: << 139 size_t G4PhantomParameterisation:: 130 GetMaterialIndex( std::size_t copyNo ) const << 140 GetMaterialIndex( size_t copyNo ) const 131 { 141 { 132 CheckCopyNo( copyNo ); 142 CheckCopyNo( copyNo ); 133 143 134 if( fMaterialIndices == nullptr ) { return 0 << 144 if( !fMaterialIndices ) { return 0; } 135 return *(fMaterialIndices+copyNo); 145 return *(fMaterialIndices+copyNo); 136 } 146 } 137 147 138 148 139 //-------------------------------------------- 149 //------------------------------------------------------------------ 140 std::size_t G4PhantomParameterisation:: << 150 size_t G4PhantomParameterisation:: 141 GetMaterialIndex( std::size_t nx, std::size_t << 151 GetMaterialIndex( size_t nx, size_t ny, size_t nz ) const 142 { 152 { 143 std::size_t copyNo = nx + fNoVoxelsX*ny + fN << 153 size_t copyNo = nx + fNoVoxelX*ny + fNoVoxelXY*nz; 144 return GetMaterialIndex( copyNo ); 154 return GetMaterialIndex( copyNo ); 145 } 155 } 146 156 147 157 148 //-------------------------------------------- 158 //------------------------------------------------------------------ 149 G4Material* << 159 G4Material* G4PhantomParameterisation::GetMaterial( size_t nx, size_t ny, size_t nz) const 150 G4PhantomParameterisation::GetMaterial( std::s << 151 { 160 { 152 return fMaterials[GetMaterialIndex(nx,ny,nz) 161 return fMaterials[GetMaterialIndex(nx,ny,nz)]; 153 } 162 } 154 163 155 << 156 //-------------------------------------------- 164 //------------------------------------------------------------------ 157 G4Material* G4PhantomParameterisation::GetMate << 165 G4Material* G4PhantomParameterisation::GetMaterial( size_t copyNo ) const 158 { 166 { 159 return fMaterials[GetMaterialIndex(copyNo)]; 167 return fMaterials[GetMaterialIndex(copyNo)]; 160 } 168 } 161 169 162 << 163 //-------------------------------------------- 170 //------------------------------------------------------------------ 164 void G4PhantomParameterisation:: 171 void G4PhantomParameterisation:: 165 ComputeVoxelIndices(const G4int copyNo, std::s << 172 ComputeVoxelIndices(const G4int copyNo, size_t& nx, 166 std::size_t& ny, std << 173 size_t& ny, size_t& nz ) const 167 { 174 { 168 CheckCopyNo( copyNo ); 175 CheckCopyNo( copyNo ); 169 nx = std::size_t(copyNo%fNoVoxelsX); << 176 nx = size_t(copyNo%fNoVoxelX); 170 ny = std::size_t( (copyNo/fNoVoxelsX)%fNoVox << 177 ny = size_t( (copyNo/fNoVoxelX)%fNoVoxelY ); 171 nz = std::size_t(copyNo/fNoVoxelsXY); << 178 nz = size_t(copyNo/fNoVoxelXY); 172 } 179 } 173 180 174 181 175 //-------------------------------------------- 182 //------------------------------------------------------------------ 176 void G4PhantomParameterisation:: 183 void G4PhantomParameterisation:: 177 CheckVoxelsFillContainer( G4double contX, G4do 184 CheckVoxelsFillContainer( G4double contX, G4double contY, G4double contZ ) const 178 { 185 { 179 G4double toleranceForWarning = 0.25*kCarTole 186 G4double toleranceForWarning = 0.25*kCarTolerance; 180 187 181 // Any bigger value than 0.25*kCarTolerance 188 // Any bigger value than 0.25*kCarTolerance will give a warning in 182 // G4NormalNavigation::ComputeStep(), becaus 189 // G4NormalNavigation::ComputeStep(), because the Inverse of a container 183 // translation that is Z+epsilon gives -Z+ep 190 // translation that is Z+epsilon gives -Z+epsilon (and the maximum tolerance 184 // in G4Box::Inside is 0.5*kCarTolerance 191 // in G4Box::Inside is 0.5*kCarTolerance 185 // 192 // 186 G4double toleranceForError = 1.*kCarToleranc 193 G4double toleranceForError = 1.*kCarTolerance; 187 194 188 // Any bigger value than kCarTolerance will 195 // Any bigger value than kCarTolerance will give an error in GetReplicaNo() 189 // 196 // 190 if( std::fabs(contX-fNoVoxelsX*fVoxelHalfX) << 197 if( std::fabs(contX-fNoVoxelX*fVoxelHalfX) >= toleranceForError 191 || std::fabs(contY-fNoVoxelsY*fVoxelHalfY) << 198 || std::fabs(contY-fNoVoxelY*fVoxelHalfY) >= toleranceForError 192 || std::fabs(contZ-fNoVoxelsZ*fVoxelHalfZ) << 199 || std::fabs(contZ-fNoVoxelZ*fVoxelHalfZ) >= toleranceForError ) 193 { << 200 { 194 std::ostringstream message; << 201 G4cerr << "ERROR - G4PhantomParameterisation::CheckVoxelsFillContainer()" 195 message << "Voxels do not fully fill the c << 202 << G4endl 196 << fContainerSolid->GetName() << G << 203 << " Voxels do not fully fill the container: " 197 << " DiffX= " << contX-fNoV << 204 << fContainerSolid->GetName() << G4endl 198 << " DiffY= " << contY-fNoV << 205 << " DiffX= " << contX-fNoVoxelX*fVoxelHalfX << G4endl 199 << " DiffZ= " << contZ-fNoV << 206 << " DiffY= " << contY-fNoVoxelY*fVoxelHalfY << G4endl 200 << " Maximum difference is: << 207 << " DiffZ= " << contZ-fNoVoxelZ*fVoxelHalfZ << G4endl >> 208 << " Maximum difference is: " << toleranceForError << G4endl; 201 G4Exception("G4PhantomParameterisation::Ch 209 G4Exception("G4PhantomParameterisation::CheckVoxelsFillContainer()", 202 "GeomNav0002", FatalException, << 210 "InvalidSetup", FatalException, >> 211 "Voxels do not fully fill the container!"); 203 212 204 } 213 } 205 else if( std::fabs(contX-fNoVoxelsX*fVoxelHa << 214 else if( std::fabs(contX-fNoVoxelX*fVoxelHalfX) >= toleranceForWarning 206 || std::fabs(contY-fNoVoxelsY*fVoxelHa << 215 || std::fabs(contY-fNoVoxelY*fVoxelHalfY) >= toleranceForWarning 207 || std::fabs(contZ-fNoVoxelsZ*fVoxelHa << 216 || std::fabs(contZ-fNoVoxelZ*fVoxelHalfZ) >= toleranceForWarning ) 208 { << 217 { 209 std::ostringstream message; << 218 G4cerr << "WARNING - G4PhantomParameterisation::CheckVoxelsFillContainer()" 210 message << "Voxels do not fully fill the c << 219 << G4endl 211 << fContainerSolid->GetName() << G << 220 << " Voxels do not fully fill the container: " 212 << " DiffX= " << contX-fN << 221 << fContainerSolid->GetName() << G4endl 213 << " DiffY= " << contY-fN << 222 << " DiffX= " << contX-fNoVoxelX*fVoxelHalfX << G4endl 214 << " DiffZ= " << contZ-fN << 223 << " DiffY= " << contY-fNoVoxelY*fVoxelHalfY << G4endl 215 << " Maximum difference i << 224 << " DiffZ= " << contZ-fNoVoxelZ*fVoxelHalfZ << G4endl >> 225 << " Maximum difference is: " << toleranceForWarning >> 226 << G4endl; 216 G4Exception("G4PhantomParameterisation::Ch 227 G4Exception("G4PhantomParameterisation::CheckVoxelsFillContainer()", 217 "GeomNav1002", JustWarning, me << 228 "InvalidSetup", JustWarning, >> 229 "Voxels do not fully fill the container!"); 218 } 230 } 219 } 231 } 220 232 221 233 222 //-------------------------------------------- 234 //------------------------------------------------------------------ 223 G4int G4PhantomParameterisation:: 235 G4int G4PhantomParameterisation:: 224 GetReplicaNo( const G4ThreeVector& localPoint, 236 GetReplicaNo( const G4ThreeVector& localPoint, const G4ThreeVector& localDir ) 225 { 237 { 226 238 227 // Check first that point is really inside v 239 // Check first that point is really inside voxels 228 // 240 // 229 if( fContainerSolid->Inside( localPoint ) == 241 if( fContainerSolid->Inside( localPoint ) == kOutside ) 230 { 242 { 231 if( std::fabs(localPoint.x()) - fContainer << 243 G4cerr << "ERROR - G4PhantomParameterisation::GetReplicaNo()" << G4endl 232 && std::fabs(localPoint.y()) - fContainerWal << 244 << " localPoint - " << localPoint 233 && std::fabs(localPoint.z()) - fContainerWal << 245 << " - is outside container solid: " 234 { << 246 << fContainerSolid->GetName() << G4endl; 235 std::ostringstream message; << 247 G4Exception("G4PhantomParameterisation::GetReplicaNo()", "InvalidSetup", 236 message << "Point outside voxels!" << G4 << 248 FatalErrorInArgument, "Point outside voxels!"); 237 << " localPoint - " << localPoi << 238 << " - is outside container solid: " << 239 << fContainerSolid->GetName() << G4end << 240 << "DIFFERENCE WITH PHANTOM WALLS X: " << 241 << std::fabs(localPoint.x()) - fContai << 242 << " Y: " << std::fabs(localPoint.y()) << 243 << " Z: " << std::fabs(localPoint.z()) << 244 G4Exception("G4PhantomParameterisation:: << 245 FatalErrorInArgument, message); << 246 } << 247 } 249 } 248 250 249 // Check the voxel numbers corresponding to 251 // Check the voxel numbers corresponding to localPoint 250 // When a particle is on a surface, it may b 252 // When a particle is on a surface, it may be between -kCarTolerance and 251 // +kCartolerance. By a simple distance as: 253 // +kCartolerance. By a simple distance as: 252 // G4int nx = G4int( (localPoint.x()+)/fVo 254 // G4int nx = G4int( (localPoint.x()+)/fVoxelHalfX/2.); 253 // those between -kCartolerance and 0 will b 255 // those between -kCartolerance and 0 will be placed on voxel N-1 and those 254 // between 0 and kCarTolerance on voxel N. 256 // between 0 and kCarTolerance on voxel N. 255 // To avoid precision problems place the tra 257 // To avoid precision problems place the tracks that are on the surface on 256 // voxel N-1 if they have negative direction 258 // voxel N-1 if they have negative direction and on voxel N if they have 257 // positive direction. 259 // positive direction. 258 // Add +kCarTolerance so that they are first 260 // Add +kCarTolerance so that they are first placed on voxel N, and then 259 // if the direction is negative substract 1 261 // if the direction is negative substract 1 260 262 261 G4double fx = (localPoint.x()+fContainerWall 263 G4double fx = (localPoint.x()+fContainerWallX+kCarTolerance)/(fVoxelHalfX*2.); 262 auto nx = G4int(fx); << 264 G4int nx = G4int(fx); 263 265 264 G4double fy = (localPoint.y()+fContainerWall << 266 G4double fy = (localPoint.y()+fContainerWallY+kCarTolerance)/(fVoxelHalfY*2.); 265 auto ny = G4int(fy); << 267 G4int ny = G4int(fy); 266 268 267 G4double fz = (localPoint.z()+fContainerWall 269 G4double fz = (localPoint.z()+fContainerWallZ+kCarTolerance)/(fVoxelHalfZ*2.); 268 auto nz = G4int(fz); << 270 G4int nz = G4int(fz); 269 271 270 // If it is on the surface side, check the d 272 // If it is on the surface side, check the direction: if direction is 271 // negative place it in the previous voxel ( << 273 // negative place it on the previous voxel (if direction is positive it is 272 // already in the next voxel). << 274 // already in the next voxel...). 273 // Correct also cases where n = -1 or n = fN << 275 // Correct also cases where n = -1 or n = fNoVoxel. It is always traced to be 274 // due to multiple scattering: track is ente 276 // due to multiple scattering: track is entering a voxel but multiple 275 // scattering changes the angle towards outs 277 // scattering changes the angle towards outside 276 // 278 // 277 if( fx - nx < kCarTolerance*fVoxelHalfX ) << 279 if( fx - nx < kCarTolerance/fVoxelHalfX ) 278 { 280 { 279 if( localDir.x() < 0 ) 281 if( localDir.x() < 0 ) 280 { 282 { 281 if( nx != 0 ) 283 if( nx != 0 ) 282 { 284 { 283 nx -= 1; 285 nx -= 1; 284 } 286 } 285 } 287 } 286 else 288 else 287 { 289 { 288 if( nx == G4int(fNoVoxelsX) ) << 290 if( nx == G4int(fNoVoxelX) ) 289 { 291 { 290 nx -= 1; 292 nx -= 1; 291 } 293 } 292 } 294 } 293 } 295 } 294 if( fy - ny < kCarTolerance*fVoxelHalfY ) << 296 if( fy - ny < kCarTolerance/fVoxelHalfY ) 295 { 297 { 296 if( localDir.y() < 0 ) 298 if( localDir.y() < 0 ) 297 { 299 { 298 if( ny != 0 ) 300 if( ny != 0 ) 299 { 301 { 300 ny -= 1; 302 ny -= 1; 301 } 303 } 302 } 304 } 303 else 305 else 304 { 306 { 305 if( ny == G4int(fNoVoxelsY) ) << 307 if( ny == G4int(fNoVoxelY) ) 306 { 308 { 307 ny -= 1; 309 ny -= 1; 308 } 310 } 309 } 311 } 310 } 312 } 311 if( fz - nz < kCarTolerance*fVoxelHalfZ ) << 313 if( fz - nz < kCarTolerance/fVoxelHalfZ ) 312 { 314 { 313 if( localDir.z() < 0 ) 315 if( localDir.z() < 0 ) 314 { 316 { 315 if( nz != 0 ) 317 if( nz != 0 ) 316 { 318 { 317 nz -= 1; 319 nz -= 1; 318 } 320 } 319 } 321 } 320 else 322 else 321 { 323 { 322 if( nz == G4int(fNoVoxelsZ) ) << 324 if( nz == G4int(fNoVoxelZ) ) 323 { 325 { 324 nz -= 1; 326 nz -= 1; 325 } 327 } 326 } 328 } 327 } 329 } 328 330 329 auto copyNo = G4int(nx + fNoVoxelsX*ny + fN << 331 G4int copyNo = nx + fNoVoxelX*ny + fNoVoxelXY*nz; 330 332 331 // Check if there are still errors 333 // Check if there are still errors 332 // 334 // 333 G4bool isOK = true; 335 G4bool isOK = true; 334 if( nx < 0 ) 336 if( nx < 0 ) 335 { 337 { 336 nx = 0; 338 nx = 0; 337 isOK = false; 339 isOK = false; 338 } 340 } 339 else if( nx >= G4int(fNoVoxelsX) ) << 341 else if( nx >= G4int(fNoVoxelX) ) 340 { 342 { 341 nx = G4int(fNoVoxelsX)-1; << 343 nx = fNoVoxelX-1; 342 isOK = false; 344 isOK = false; 343 } 345 } 344 if( ny < 0 ) 346 if( ny < 0 ) 345 { 347 { 346 ny = 0; 348 ny = 0; 347 isOK = false; 349 isOK = false; 348 } 350 } 349 else if( ny >= G4int(fNoVoxelsY) ) << 351 else if( ny >= G4int(fNoVoxelY) ) 350 { 352 { 351 ny = G4int(fNoVoxelsY)-1; << 353 ny = fNoVoxelY-1; 352 isOK = false; 354 isOK = false; 353 } 355 } 354 if( nz < 0 ) 356 if( nz < 0 ) 355 { 357 { 356 nz = 0; 358 nz = 0; 357 isOK = false; 359 isOK = false; 358 } 360 } 359 else if( nz >= G4int(fNoVoxelsZ) ) << 361 else if( nz >= G4int(fNoVoxelZ) ) 360 { 362 { 361 nz = G4int(fNoVoxelsZ)-1; << 363 nz = fNoVoxelZ-1; 362 isOK = false; 364 isOK = false; 363 } 365 } 364 if( !isOK ) 366 if( !isOK ) 365 { 367 { 366 if( std::fabs(localPoint.x()-fContainerWal << 368 G4cerr << "WARNING - G4PhantomParameterisation::GetReplicaNo()" << G4endl 367 std::fabs(localPoint.y()-fContainerWallY) > << 369 << " LocalPoint: " << localPoint << G4endl 368 std::fabs(localPoint.z()-fContainerWallZ) > << 370 << " LocalDir: " << localDir << G4endl 369 std::ostringstream message; << 371 << " Voxel container size: " << fContainerWallX 370 message << "Corrected the copy number! I << 372 << " " << fContainerWallY << " " << fContainerWallZ << G4endl 371 << " LocalPoint: " << localPo << 373 << " LocalPoint - wall: " 372 << " LocalDir: " << localDir << 374 << localPoint.x()-fContainerWallX << " " 373 << " Voxel container size: " << 375 << localPoint.y()-fContainerWallY << " " 374 << " " << fContainerWallY << " " << fC << 376 << localPoint.z()-fContainerWallZ << G4endl; 375 << " LocalPoint - wall: " << 377 G4Exception("G4PhantomParameterisation::GetReplicaNo()", 376 << localPoint.x()-fContainerWallX << " << 378 "Wrong-copy-number", JustWarning, 377 << localPoint.y()-fContainerWallY << " << 379 "Corrected the copy number! It was negative or too big"); 378 << localPoint.z()-fContainerWallZ; << 380 copyNo = nx + fNoVoxelX*ny + fNoVoxelXY*nz; 379 G4Exception("G4PhantomParameterisation:: << 380 "GeomNav1002", JustWarning, message); << 381 } << 382 << 383 copyNo = G4int(nx + fNoVoxelsX*ny + fNoVox << 384 } 381 } 385 382 >> 383 // CheckCopyNo( copyNo ); // not needed, just for debugging code >> 384 386 return copyNo; 385 return copyNo; 387 } 386 } 388 387 389 388 390 //-------------------------------------------- 389 //------------------------------------------------------------------ 391 void G4PhantomParameterisation::CheckCopyNo( c << 390 void G4PhantomParameterisation::CheckCopyNo( const G4int copyNo ) const 392 { 391 { 393 if( copyNo < 0 || copyNo >= G4int(fNoVoxels) << 392 if( copyNo < 0 || copyNo >= G4int(fNoVoxel) ) 394 { 393 { 395 std::ostringstream message; << 394 G4cerr << "ERROR - G4PhantomParameterisation::CheckCopyNo()" << G4endl 396 message << "Copy number is negative or too << 395 << " Copy number: " << copyNo << G4endl 397 << " Copy number: " << copy << 396 << " Total number of voxels: " << fNoVoxel << G4endl; 398 << " Total number of voxels << 399 G4Exception("G4PhantomParameterisation::Ch 397 G4Exception("G4PhantomParameterisation::CheckCopyNo()", 400 "GeomNav0002", FatalErrorInArg << 398 "Wrong-copy-number", FatalErrorInArgument, >> 399 "Copy number is negative or too big!"); 401 } 400 } 402 } 401 } 403 402