2 // ********************************************************************
3 // * License and Disclaimer *
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. *
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. *
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 // ********************************************************************
29 // class G4ITNavigator2 Inline implementation
31 // G4ITNavigator2 is a duplicate version of G4Navigator started from Geant4.9.5
32 // initially written by Paul Kent and colleagues.
33 // The only difference resides in the way the information is saved and managed
35 // ********************************************************************
37 // ********************************************************************
38 // GetCurrentLocalCoordinate
40 // Returns the local coordinate of the current track
41 // ********************************************************************
44 G4ThreeVector G4ITNavigator2::GetCurrentLocalCoordinate() const
46 CheckNavigatorStateIsValid();
47 return fpNavigatorState->fLastLocatedPointLocal;
50 // ********************************************************************
53 // Returns local direction of vector direction in world coord system
54 // ********************************************************************
57 G4ThreeVector G4ITNavigator2::ComputeLocalAxis(const G4ThreeVector& pVec) const
59 CheckNavigatorStateIsValid();
60 return (fpNavigatorState->fHistory.GetTopTransform().IsRotated())
61 ? fpNavigatorState->fHistory.GetTopTransform().TransformAxis(pVec) : pVec ;
64 // ********************************************************************
67 // Returns local coordinates of a point in the world coord system
68 // ********************************************************************
72 G4ITNavigator2::ComputeLocalPoint(const G4ThreeVector& pGlobalPoint) const
74 CheckNavigatorStateIsValid();
75 return ( fpNavigatorState->fHistory.GetTopTransform().TransformPoint(pGlobalPoint) ) ;
78 // ********************************************************************
81 // Returns the current world (`topmost') volume
82 // ********************************************************************
85 G4VPhysicalVolume* G4ITNavigator2::GetWorldVolume() const
90 // ********************************************************************
93 // Sets the world (`topmost') volume
94 // ********************************************************************
97 void G4ITNavigator2::SetWorldVolume(G4VPhysicalVolume* pWorld)
99 if ( !(pWorld->GetTranslation()==G4ThreeVector(0,0,0)) )
101 G4Exception ("G4ITNavigator2::SetWorldVolume()", "GeomNav0002",
102 FatalException, "Volume must be centered on the origin.");
104 const G4RotationMatrix* rm = pWorld->GetRotation();
105 if ( rm && (!rm->isIdentity()) )
107 G4Exception ("G4ITNavigator2::SetWorldVolume()", "GeomNav0002",
108 FatalException, "Volume must not be rotated.");
110 fTopPhysical = pWorld;
112 fpNavigatorState->fHistory.SetFirstEntry(pWorld);
115 // ********************************************************************
116 // SetGeometrycallyLimitedStep
118 // Informs the navigator that the previous Step calculated
119 // by the geometry was taken in its entirety
120 // ********************************************************************
123 void G4ITNavigator2::SetGeometricallyLimitedStep()
125 fpNavigatorState->fWasLimitedByGeometry=true;
128 // ********************************************************************
129 // ResetStackAndState
131 // Resets stack and minimum of navigator state `machine'
132 // ********************************************************************
135 void G4ITNavigator2::ResetStackAndState()
137 fpNavigatorState->fHistory.Reset();
141 // ********************************************************************
143 // ********************************************************************
146 EVolume G4ITNavigator2::VolumeType(const G4VPhysicalVolume *pVol) const
148 return pVol->VolumeType();
151 // ********************************************************************
152 // CharacteriseDaughters
153 // ********************************************************************
156 EVolume G4ITNavigator2::CharacteriseDaughters(const G4LogicalVolume *pLog) const
158 return pLog->CharacteriseDaughters();
161 inline std::shared_ptr<G4ITNavigatorState_Lock2> G4ITNavigator2::GetSnapshotOfState()
165 std::shared_ptr<G4ITNavigatorState_Lock2>
166 snapShot(new G4NavigatorState(*fpNavigatorState));
171 return std::shared_ptr<G4ITNavigatorState_Lock2>(0);
175 inline void G4ITNavigator2::ResetFromSnapshot(std::shared_ptr<G4ITNavigatorState_Lock2> snapShot)
177 if(fpNavigatorState && snapShot)
179 *fpNavigatorState = *((G4NavigatorState*) snapShot.get());
183 // ********************************************************************
184 // GetDaughtersRegularStructureId
185 // ********************************************************************
188 G4int G4ITNavigator2::
189 GetDaughtersRegularStructureId(const G4LogicalVolume *pLog) const
192 G4VPhysicalVolume *pVol;
194 if ( pLog->GetNoDaughters()==1 )
196 pVol = pLog->GetDaughter(0);
197 regId = pVol->GetRegularStructureId();
202 // ********************************************************************
203 // GetGlobalToLocalTransform
205 // Returns local to global transformation.
206 // I.e. transformation that will take point or axis in world coord system
207 // and return one in the local coord system
208 // ********************************************************************
211 const G4AffineTransform& G4ITNavigator2::GetGlobalToLocalTransform() const
213 CheckNavigatorStateIsValid();
214 return fpNavigatorState->fHistory.GetTopTransform();
217 // ********************************************************************
218 // GetLocalToGlobalTransform
220 // Returns global to local transformation
221 // ********************************************************************
224 const G4AffineTransform G4ITNavigator2::GetLocalToGlobalTransform() const
226 CheckNavigatorStateIsValid();
227 G4AffineTransform tempTransform;
228 tempTransform = fpNavigatorState->fHistory.GetTopTransform().Inverse();
229 return tempTransform;
232 // ********************************************************************
235 // Computes+returns the local->global translation of current volume
236 // ********************************************************************
239 G4ThreeVector G4ITNavigator2::NetTranslation() const
241 CheckNavigatorStateIsValid();
242 G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
243 return tf.NetTranslation();
246 // ********************************************************************
249 // Computes+returns the local->global rotation of current volume
250 // ********************************************************************
253 G4RotationMatrix G4ITNavigator2::NetRotation() const
255 CheckNavigatorStateIsValid();
256 G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
257 return tf.NetRotation();
260 // ********************************************************************
263 // `Touchable' creation method: caller has deletion responsibility
264 // ********************************************************************
267 G4GRSVolume* G4ITNavigator2::CreateGRSVolume() const
269 CheckNavigatorStateIsValid();
270 G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
271 return new G4GRSVolume(fpNavigatorState->fHistory.GetTopVolume(),
273 tf.NetTranslation());
276 // ********************************************************************
279 // `Touchable' creation method: caller has deletion responsibility
280 // ********************************************************************
283 G4GRSSolid* G4ITNavigator2::CreateGRSSolid() const
285 CheckNavigatorStateIsValid();
286 G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
287 return new G4GRSSolid(fpNavigatorState->fHistory.GetTopVolume()->GetLogicalVolume()->GetSolid(),
289 tf.NetTranslation());
292 // ********************************************************************
293 // CreateTouchableHistory
295 // `Touchable' creation method: caller has deletion responsibility
296 // ********************************************************************
299 G4TouchableHistory* G4ITNavigator2::CreateTouchableHistory() const
301 CheckNavigatorStateIsValid();
302 return new G4TouchableHistory(fpNavigatorState->fHistory);
305 // ********************************************************************
306 // CreateTouchableHistory(history)
308 // `Touchable' creation method: caller has deletion responsibility
309 // ********************************************************************
313 G4ITNavigator2::CreateTouchableHistory(const G4NavigationHistory* history) const
315 return new G4TouchableHistory(*history);
318 // ********************************************************************
319 // LocateGlobalPointAndUpdateTouchableHandle
320 // ********************************************************************
323 void G4ITNavigator2::LocateGlobalPointAndUpdateTouchableHandle(
324 const G4ThreeVector& position,
325 const G4ThreeVector& direction,
326 G4TouchableHandle& oldTouchableToUpdate,
327 const G4bool RelativeSearch )
329 G4VPhysicalVolume* pPhysVol;
330 pPhysVol = LocateGlobalPointAndSetup( position,&direction,RelativeSearch );
331 // Will check navigatorState validity
332 if( fpNavigatorState->fEnteredDaughter || fpNavigatorState->fExitedMother )
334 oldTouchableToUpdate = CreateTouchableHistory();
337 // We want to ensure that the touchable is correct in this case.
338 // The method below should do this and recalculate a lot more ....
340 oldTouchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory );
346 // ********************************************************************
347 // LocateGlobalPointAndUpdateTouchable
350 // ********************************************************************
353 void G4ITNavigator2::LocateGlobalPointAndUpdateTouchable(
354 const G4ThreeVector& position,
355 const G4ThreeVector& direction,
356 G4VTouchable* touchableToUpdate,
357 const G4bool RelativeSearch )
359 G4VPhysicalVolume* pPhysVol;
360 pPhysVol = LocateGlobalPointAndSetup( position, &direction, RelativeSearch);
361 // Will check navigatorState validity
362 touchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory );
365 // ********************************************************************
366 // LocateGlobalPointAndUpdateTouchable
367 // ********************************************************************
370 void G4ITNavigator2::LocateGlobalPointAndUpdateTouchable(
371 const G4ThreeVector& position,
372 G4VTouchable* touchableToUpdate,
373 const G4bool RelativeSearch )
375 G4VPhysicalVolume* pPhysVol;
376 pPhysVol = LocateGlobalPointAndSetup( position, 0, RelativeSearch);
377 // Will check navigatorState validity
378 touchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory );
381 // ********************************************************************
383 // ********************************************************************
386 G4int G4ITNavigator2::GetVerboseLevel() const
391 // ********************************************************************
393 // ********************************************************************
396 void G4ITNavigator2::SetVerboseLevel(G4int level)
399 fnormalNav.SetVerboseLevel(level);
400 fvoxelNav.SetVerboseLevel(level);
401 fparamNav.SetVerboseLevel(level);
402 freplicaNav.SetVerboseLevel(level);
403 fregularNav.SetVerboseLevel(level);
406 // ********************************************************************
408 // ********************************************************************
411 G4bool G4ITNavigator2::IsActive() const
416 // ********************************************************************
418 // ********************************************************************
421 void G4ITNavigator2::Activate(G4bool flag)
426 // ********************************************************************
427 // EnteredDaughterVolume
429 // To inform the caller if the track is entering a daughter volume
430 // ********************************************************************
433 G4bool G4ITNavigator2::EnteredDaughterVolume() const
435 CheckNavigatorStateIsValid();
436 return fpNavigatorState->fEnteredDaughter;
439 // ********************************************************************
440 // ExitedMotherVolume
441 // ********************************************************************
444 G4bool G4ITNavigator2::ExitedMotherVolume() const
446 CheckNavigatorStateIsValid();
447 return fpNavigatorState->fExitedMother;
450 // ********************************************************************
452 // ********************************************************************
455 void G4ITNavigator2::CheckMode(G4bool mode)
458 fnormalNav.CheckMode(mode);
459 fvoxelNav.CheckMode(mode);
460 fparamNav.CheckMode(mode);
461 freplicaNav.CheckMode(mode);
462 fregularNav.CheckMode(mode);
465 // ********************************************************************
467 // ********************************************************************
470 G4bool G4ITNavigator2::IsCheckModeActive() const
475 // ********************************************************************
477 // ********************************************************************
480 void G4ITNavigator2::SetPushVerbosity(G4bool mode)
485 // ********************************************************************
486 // SeverityOfZeroStepping
488 // Reports on severity of error in case Navigator is stuck
489 // and is returning zero steps
490 // ********************************************************************
493 G4int G4ITNavigator2::SeverityOfZeroStepping( G4int* noZeroSteps ) const
495 CheckNavigatorStateIsValid();
496 G4int severity=0, noZeros= fpNavigatorState->fNumberZeroSteps;
497 if( noZeroSteps) *noZeroSteps = fpNavigatorState->fNumberZeroSteps;
499 if( noZeros >= fAbandonThreshold_NoZeroSteps )
503 if( noZeros > 0 && noZeros < fActionThreshold_NoZeroSteps )
505 severity = 5 * noZeros / fActionThreshold_NoZeroSteps;
507 else if( noZeros == fActionThreshold_NoZeroSteps )
511 else if( noZeros >= fAbandonThreshold_NoZeroSteps - 2 )
515 else if( noZeros < fAbandonThreshold_NoZeroSteps - 2 )
517 severity = 5 + 4 * (noZeros-fAbandonThreshold_NoZeroSteps)
518 / fActionThreshold_NoZeroSteps;
523 // ********************************************************************
525 // ********************************************************************
527 inline void G4ITNavigator2::EnableBestSafety( G4bool value )
529 fvoxelNav.EnableBestSafety( value );