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 // 27 // 28 // class G4ITNavigator2 Inline implementation 29 // 30 // G4ITNavigator2 is a duplicate version of G4Navigator started from Geant4.9.5 31 // initially written by Paul Kent and colleagues. 32 // The only difference resides in the way the information is saved and managed 33 // 34 // ******************************************************************** 35 36 // ******************************************************************** 37 // GetCurrentLocalCoordinate 38 // 39 // Returns the local coordinate of the current track 40 // ******************************************************************** 41 // 42 inline 43 G4ThreeVector G4ITNavigator2::GetCurrentLocalCoordinate() const 44 { 45 CheckNavigatorStateIsValid(); 46 return fpNavigatorState->fLastLocatedPointLocal; 47 } 48 49 // ******************************************************************** 50 // ComputeLocalAxis 51 // 52 // Returns local direction of vector direction in world coord system 53 // ******************************************************************** 54 // 55 inline 56 G4ThreeVector G4ITNavigator2::ComputeLocalAxis(const G4ThreeVector& pVec) const 57 { 58 CheckNavigatorStateIsValid(); 59 return (fpNavigatorState->fHistory.GetTopTransform().IsRotated()) 60 ? fpNavigatorState->fHistory.GetTopTransform().TransformAxis(pVec) : pVec ; 61 } 62 63 // ******************************************************************** 64 // ComputeLocalPoint 65 // 66 // Returns local coordinates of a point in the world coord system 67 // ******************************************************************** 68 // 69 inline 70 G4ThreeVector 71 G4ITNavigator2::ComputeLocalPoint(const G4ThreeVector& pGlobalPoint) const 72 { 73 CheckNavigatorStateIsValid(); 74 return ( fpNavigatorState->fHistory.GetTopTransform().TransformPoint(pGlobalPoint) ) ; 75 } 76 77 // ******************************************************************** 78 // GetWorldVolume 79 // 80 // Returns the current world (`topmost') volume 81 // ******************************************************************** 82 // 83 inline 84 G4VPhysicalVolume* G4ITNavigator2::GetWorldVolume() const 85 { 86 return fTopPhysical; 87 } 88 89 // ******************************************************************** 90 // SetWorldVolume 91 // 92 // Sets the world (`topmost') volume 93 // ******************************************************************** 94 // 95 inline 96 void G4ITNavigator2::SetWorldVolume(G4VPhysicalVolume* pWorld) 97 { 98 if ( !(pWorld->GetTranslation()==G4ThreeVector(0,0,0)) ) 99 { 100 G4Exception ("G4ITNavigator2::SetWorldVolume()", "GeomNav0002", 101 FatalException, "Volume must be centered on the origin."); 102 } 103 const G4RotationMatrix* rm = pWorld->GetRotation(); 104 if ( (rm != nullptr) && (!rm->isIdentity()) ) 105 { 106 G4Exception ("G4ITNavigator2::SetWorldVolume()", "GeomNav0002", 107 FatalException, "Volume must not be rotated."); 108 } 109 fTopPhysical = pWorld; 110 if(fpNavigatorState != nullptr) 111 fpNavigatorState->fHistory.SetFirstEntry(pWorld); 112 } 113 114 // ******************************************************************** 115 // SetGeometrycallyLimitedStep 116 // 117 // Informs the navigator that the previous Step calculated 118 // by the geometry was taken in its entirety 119 // ******************************************************************** 120 // 121 inline 122 void G4ITNavigator2::SetGeometricallyLimitedStep() 123 { 124 fpNavigatorState->fWasLimitedByGeometry=true; 125 } 126 127 // ******************************************************************** 128 // ResetStackAndState 129 // 130 // Resets stack and minimum of navigator state `machine' 131 // ******************************************************************** 132 // 133 inline 134 void G4ITNavigator2::ResetStackAndState() 135 { 136 fpNavigatorState->fHistory.Reset(); 137 ResetState(); 138 } 139 140 // ******************************************************************** 141 // VolumeType 142 // ******************************************************************** 143 // 144 inline 145 EVolume G4ITNavigator2::VolumeType(const G4VPhysicalVolume *pVol) const 146 { 147 return pVol->VolumeType(); 148 } 149 150 // ******************************************************************** 151 // CharacteriseDaughters 152 // ******************************************************************** 153 // 154 inline 155 EVolume G4ITNavigator2::CharacteriseDaughters(const G4LogicalVolume *pLog) const 156 { 157 return pLog->CharacteriseDaughters(); 158 } 159 160 inline std::shared_ptr<G4ITNavigatorState_Lock2> G4ITNavigator2::GetSnapshotOfState() 161 { 162 if(fpNavigatorState != nullptr) 163 { 164 std::shared_ptr<G4ITNavigatorState_Lock2> 165 snapShot(new G4NavigatorState(*fpNavigatorState)); 166 return snapShot; 167 } 168 169 return std::shared_ptr<G4ITNavigatorState_Lock2>(nullptr); 170 } 171 172 inline void G4ITNavigator2::ResetFromSnapshot(std::shared_ptr<G4ITNavigatorState_Lock2> snapShot) 173 { 174 if((fpNavigatorState != nullptr) && snapShot) 175 { 176 *fpNavigatorState = *((G4NavigatorState*) snapShot.get()); 177 } 178 } 179 180 // ******************************************************************** 181 // GetDaughtersRegularStructureId 182 // ******************************************************************** 183 // 184 inline 185 G4int G4ITNavigator2:: 186 GetDaughtersRegularStructureId(const G4LogicalVolume *pLog) const 187 { 188 G4int regId = 0; 189 G4VPhysicalVolume *pVol; 190 191 if ( pLog->GetNoDaughters()==1 ) 192 { 193 pVol = pLog->GetDaughter(0); 194 regId = pVol->GetRegularStructureId(); 195 } 196 return regId; 197 } 198 199 // ******************************************************************** 200 // GetGlobalToLocalTransform 201 // 202 // Returns local to global transformation. 203 // I.e. transformation that will take point or axis in world coord system 204 // and return one in the local coord system 205 // ******************************************************************** 206 // 207 inline 208 const G4AffineTransform& G4ITNavigator2::GetGlobalToLocalTransform() const 209 { 210 CheckNavigatorStateIsValid(); 211 return fpNavigatorState->fHistory.GetTopTransform(); 212 } 213 214 // ******************************************************************** 215 // GetLocalToGlobalTransform 216 // 217 // Returns global to local transformation 218 // ******************************************************************** 219 // 220 inline 221 const G4AffineTransform G4ITNavigator2::GetLocalToGlobalTransform() const 222 { 223 CheckNavigatorStateIsValid(); 224 G4AffineTransform tempTransform; 225 tempTransform = fpNavigatorState->fHistory.GetTopTransform().Inverse(); 226 return tempTransform; 227 } 228 229 // ******************************************************************** 230 // NetTranslation 231 // 232 // Computes+returns the local->global translation of current volume 233 // ******************************************************************** 234 // 235 inline 236 G4ThreeVector G4ITNavigator2::NetTranslation() const 237 { 238 CheckNavigatorStateIsValid(); 239 G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse()); 240 return tf.NetTranslation(); 241 } 242 243 // ******************************************************************** 244 // NetRotation 245 // 246 // Computes+returns the local->global rotation of current volume 247 // ******************************************************************** 248 // 249 inline 250 G4RotationMatrix G4ITNavigator2::NetRotation() const 251 { 252 CheckNavigatorStateIsValid(); 253 G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse()); 254 return tf.NetRotation(); 255 } 256 257 // ******************************************************************** 258 // CreateTouchableHistory 259 // 260 // `Touchable' creation method: caller has deletion responsibility 261 // ******************************************************************** 262 // 263 inline 264 G4TouchableHistory* G4ITNavigator2::CreateTouchableHistory() const 265 { 266 CheckNavigatorStateIsValid(); 267 return new G4TouchableHistory(fpNavigatorState->fHistory); 268 } 269 270 // ******************************************************************** 271 // CreateTouchableHistory(history) 272 // 273 // `Touchable' creation method: caller has deletion responsibility 274 // ******************************************************************** 275 // 276 inline 277 G4TouchableHistory* 278 G4ITNavigator2::CreateTouchableHistory(const G4NavigationHistory* history) const 279 { 280 return new G4TouchableHistory(*history); 281 } 282 283 // ******************************************************************** 284 // LocateGlobalPointAndUpdateTouchableHandle 285 // ******************************************************************** 286 // 287 inline 288 void G4ITNavigator2::LocateGlobalPointAndUpdateTouchableHandle( 289 const G4ThreeVector& position, 290 const G4ThreeVector& direction, 291 G4TouchableHandle& oldTouchableToUpdate, 292 const G4bool RelativeSearch ) 293 { 294 G4VPhysicalVolume* pPhysVol; 295 pPhysVol = LocateGlobalPointAndSetup( position,&direction,RelativeSearch ); 296 // Will check navigatorState validity 297 if( fpNavigatorState->fEnteredDaughter || fpNavigatorState->fExitedMother ) 298 { 299 oldTouchableToUpdate = CreateTouchableHistory(); 300 if( pPhysVol == nullptr ) 301 { 302 // We want to ensure that the touchable is correct in this case. 303 // The method below should do this and recalculate a lot more .... 304 // 305 oldTouchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory ); 306 } 307 } 308 return; 309 } 310 311 // ******************************************************************** 312 // LocateGlobalPointAndUpdateTouchable 313 // 314 // Use direction 315 // ******************************************************************** 316 // 317 inline 318 void G4ITNavigator2::LocateGlobalPointAndUpdateTouchable( 319 const G4ThreeVector& position, 320 const G4ThreeVector& direction, 321 G4VTouchable* touchableToUpdate, 322 const G4bool RelativeSearch ) 323 { 324 G4VPhysicalVolume* pPhysVol; 325 pPhysVol = LocateGlobalPointAndSetup( position, &direction, RelativeSearch); 326 // Will check navigatorState validity 327 touchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory ); 328 } 329 330 // ******************************************************************** 331 // LocateGlobalPointAndUpdateTouchable 332 // ******************************************************************** 333 // 334 inline 335 void G4ITNavigator2::LocateGlobalPointAndUpdateTouchable( 336 const G4ThreeVector& position, 337 G4VTouchable* touchableToUpdate, 338 const G4bool RelativeSearch ) 339 { 340 G4VPhysicalVolume* pPhysVol; 341 pPhysVol = LocateGlobalPointAndSetup( position, nullptr, RelativeSearch); 342 // Will check navigatorState validity 343 touchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory ); 344 } 345 346 // ******************************************************************** 347 // GetVerboseLevel 348 // ******************************************************************** 349 // 350 inline 351 G4int G4ITNavigator2::GetVerboseLevel() const 352 { 353 return fVerbose; 354 } 355 356 // ******************************************************************** 357 // SetVerboseLevel 358 // ******************************************************************** 359 // 360 inline 361 void G4ITNavigator2::SetVerboseLevel(G4int level) 362 { 363 fVerbose = level; 364 fnormalNav.SetVerboseLevel(level); 365 fvoxelNav.SetVerboseLevel(level); 366 fparamNav.SetVerboseLevel(level); 367 freplicaNav.SetVerboseLevel(level); 368 fregularNav.SetVerboseLevel(level); 369 } 370 371 // ******************************************************************** 372 // IsActive 373 // ******************************************************************** 374 // 375 inline 376 G4bool G4ITNavigator2::IsActive() const 377 { 378 return fActive; 379 } 380 381 // ******************************************************************** 382 // Activate 383 // ******************************************************************** 384 // 385 inline 386 void G4ITNavigator2::Activate(G4bool flag) 387 { 388 fActive = flag; 389 } 390 391 // ******************************************************************** 392 // EnteredDaughterVolume 393 // 394 // To inform the caller if the track is entering a daughter volume 395 // ******************************************************************** 396 // 397 inline 398 G4bool G4ITNavigator2::EnteredDaughterVolume() const 399 { 400 CheckNavigatorStateIsValid(); 401 return fpNavigatorState->fEnteredDaughter; 402 } 403 404 // ******************************************************************** 405 // ExitedMotherVolume 406 // ******************************************************************** 407 // 408 inline 409 G4bool G4ITNavigator2::ExitedMotherVolume() const 410 { 411 CheckNavigatorStateIsValid(); 412 return fpNavigatorState->fExitedMother; 413 } 414 415 // ******************************************************************** 416 // CheckMode 417 // ******************************************************************** 418 // 419 inline 420 void G4ITNavigator2::CheckMode(G4bool mode) 421 { 422 fCheck = mode; 423 fnormalNav.CheckMode(mode); 424 fvoxelNav.CheckMode(mode); 425 fparamNav.CheckMode(mode); 426 freplicaNav.CheckMode(mode); 427 fregularNav.CheckMode(mode); 428 } 429 430 // ******************************************************************** 431 // IsCheckModeActive 432 // ******************************************************************** 433 // 434 inline 435 G4bool G4ITNavigator2::IsCheckModeActive() const 436 { 437 return fCheck; 438 } 439 440 // ******************************************************************** 441 // SetPushVerbosity 442 // ******************************************************************** 443 // 444 inline 445 void G4ITNavigator2::SetPushVerbosity(G4bool mode) 446 { 447 fWarnPush = mode; 448 } 449 450 // ******************************************************************** 451 // SeverityOfZeroStepping 452 // 453 // Reports on severity of error in case Navigator is stuck 454 // and is returning zero steps 455 // ******************************************************************** 456 // 457 inline 458 G4int G4ITNavigator2::SeverityOfZeroStepping( G4int* noZeroSteps ) const 459 { 460 CheckNavigatorStateIsValid(); 461 G4int severity=0, noZeros= fpNavigatorState->fNumberZeroSteps; 462 if( noZeroSteps != nullptr) *noZeroSteps = fpNavigatorState->fNumberZeroSteps; 463 464 if( noZeros >= fAbandonThreshold_NoZeroSteps ) 465 { 466 severity = 10; 467 } 468 if( noZeros > 0 && noZeros < fActionThreshold_NoZeroSteps ) 469 { 470 severity = 5 * noZeros / fActionThreshold_NoZeroSteps; 471 } 472 else if( noZeros == fActionThreshold_NoZeroSteps ) 473 { 474 severity = 5; 475 } 476 else if( noZeros >= fAbandonThreshold_NoZeroSteps - 2 ) 477 { 478 severity = 9; 479 } 480 else if( noZeros < fAbandonThreshold_NoZeroSteps - 2 ) 481 { 482 severity = 5 + 4 * (noZeros-fAbandonThreshold_NoZeroSteps) 483 / fActionThreshold_NoZeroSteps; 484 } 485 return severity; 486 } 487 488 // ******************************************************************** 489 // EnableBestSafety 490 // ******************************************************************** 491 // 492 inline void G4ITNavigator2::EnableBestSafety( G4bool value ) 493 { 494 fvoxelNav.EnableBestSafety( value ); 495 } 496