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// ********************************************************************
28// class G4ITNavigator2 Inline implementation
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
34// ********************************************************************
36// ********************************************************************
37// GetCurrentLocalCoordinate
39// Returns the local coordinate of the current track
40// ********************************************************************
43G4ThreeVector G4ITNavigator2::GetCurrentLocalCoordinate() const
45 CheckNavigatorStateIsValid();
46 return fpNavigatorState->fLastLocatedPointLocal;
49// ********************************************************************
52// Returns local direction of vector direction in world coord system
53// ********************************************************************
56G4ThreeVector G4ITNavigator2::ComputeLocalAxis(const G4ThreeVector& pVec) const
58 CheckNavigatorStateIsValid();
59 return (fpNavigatorState->fHistory.GetTopTransform().IsRotated())
60 ? fpNavigatorState->fHistory.GetTopTransform().TransformAxis(pVec) : pVec ;
63// ********************************************************************
66// Returns local coordinates of a point in the world coord system
67// ********************************************************************
71G4ITNavigator2::ComputeLocalPoint(const G4ThreeVector& pGlobalPoint) const
73 CheckNavigatorStateIsValid();
74 return ( fpNavigatorState->fHistory.GetTopTransform().TransformPoint(pGlobalPoint) ) ;
77// ********************************************************************
80// Returns the current world (`topmost') volume
81// ********************************************************************
84G4VPhysicalVolume* G4ITNavigator2::GetWorldVolume() const
89// ********************************************************************
92// Sets the world (`topmost') volume
93// ********************************************************************
96void G4ITNavigator2::SetWorldVolume(G4VPhysicalVolume* pWorld)
98 if ( !(pWorld->GetTranslation()==G4ThreeVector(0,0,0)) )
100 G4Exception ("G4ITNavigator2::SetWorldVolume()", "GeomNav0002",
101 FatalException, "Volume must be centered on the origin.");
103 const G4RotationMatrix* rm = pWorld->GetRotation();
104 if ( rm && (!rm->isIdentity()) )
106 G4Exception ("G4ITNavigator2::SetWorldVolume()", "GeomNav0002",
107 FatalException, "Volume must not be rotated.");
109 fTopPhysical = pWorld;
111 fpNavigatorState->fHistory.SetFirstEntry(pWorld);
114// ********************************************************************
115// SetGeometrycallyLimitedStep
117// Informs the navigator that the previous Step calculated
118// by the geometry was taken in its entirety
119// ********************************************************************
122void G4ITNavigator2::SetGeometricallyLimitedStep()
124 fpNavigatorState->fWasLimitedByGeometry=true;
127// ********************************************************************
130// Resets stack and minimum of navigator state `machine'
131// ********************************************************************
134void G4ITNavigator2::ResetStackAndState()
136 fpNavigatorState->fHistory.Reset();
140// ********************************************************************
142// ********************************************************************
145EVolume G4ITNavigator2::VolumeType(const G4VPhysicalVolume *pVol) const
147 return pVol->VolumeType();
150// ********************************************************************
151// CharacteriseDaughters
152// ********************************************************************
155EVolume G4ITNavigator2::CharacteriseDaughters(const G4LogicalVolume *pLog) const
157 return pLog->CharacteriseDaughters();
160inline std::shared_ptr<G4ITNavigatorState_Lock2> G4ITNavigator2::GetSnapshotOfState()
164 std::shared_ptr<G4ITNavigatorState_Lock2>
165 snapShot(new G4NavigatorState(*fpNavigatorState));
170 return std::shared_ptr<G4ITNavigatorState_Lock2>(0);
174inline void G4ITNavigator2::ResetFromSnapshot(std::shared_ptr<G4ITNavigatorState_Lock2> snapShot)
176 if(fpNavigatorState && snapShot)
178 *fpNavigatorState = *((G4NavigatorState*) snapShot.get());
182// ********************************************************************
183// GetDaughtersRegularStructureId
184// ********************************************************************
187G4int G4ITNavigator2::
188GetDaughtersRegularStructureId(const G4LogicalVolume *pLog) const
191 G4VPhysicalVolume *pVol;
193 if ( pLog->GetNoDaughters()==1 )
195 pVol = pLog->GetDaughter(0);
196 regId = pVol->GetRegularStructureId();
201// ********************************************************************
202// GetGlobalToLocalTransform
204// Returns local to global transformation.
205// I.e. transformation that will take point or axis in world coord system
206// and return one in the local coord system
207// ********************************************************************
210const G4AffineTransform& G4ITNavigator2::GetGlobalToLocalTransform() const
212 CheckNavigatorStateIsValid();
213 return fpNavigatorState->fHistory.GetTopTransform();
216// ********************************************************************
217// GetLocalToGlobalTransform
219// Returns global to local transformation
220// ********************************************************************
223const G4AffineTransform G4ITNavigator2::GetLocalToGlobalTransform() const
225 CheckNavigatorStateIsValid();
226 G4AffineTransform tempTransform;
227 tempTransform = fpNavigatorState->fHistory.GetTopTransform().Inverse();
228 return tempTransform;
231// ********************************************************************
234// Computes+returns the local->global translation of current volume
235// ********************************************************************
238G4ThreeVector G4ITNavigator2::NetTranslation() const
240 CheckNavigatorStateIsValid();
241 G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
242 return tf.NetTranslation();
245// ********************************************************************
248// Computes+returns the local->global rotation of current volume
249// ********************************************************************
252G4RotationMatrix G4ITNavigator2::NetRotation() const
254 CheckNavigatorStateIsValid();
255 G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
256 return tf.NetRotation();
259// ********************************************************************
262// `Touchable' creation method: caller has deletion responsibility
263// ********************************************************************
266G4GRSVolume* G4ITNavigator2::CreateGRSVolume() const
268 CheckNavigatorStateIsValid();
269 G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
270 return new G4GRSVolume(fpNavigatorState->fHistory.GetTopVolume(),
272 tf.NetTranslation());
275// ********************************************************************
278// `Touchable' creation method: caller has deletion responsibility
279// ********************************************************************
282G4GRSSolid* G4ITNavigator2::CreateGRSSolid() const
284 CheckNavigatorStateIsValid();
285 G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
286 return new G4GRSSolid(fpNavigatorState->fHistory.GetTopVolume()->GetLogicalVolume()->GetSolid(),
288 tf.NetTranslation());
291// ********************************************************************
292// CreateTouchableHistory
294// `Touchable' creation method: caller has deletion responsibility
295// ********************************************************************
298G4TouchableHistory* G4ITNavigator2::CreateTouchableHistory() const
300 CheckNavigatorStateIsValid();
301 return new G4TouchableHistory(fpNavigatorState->fHistory);
304// ********************************************************************
305// CreateTouchableHistory(history)
307// `Touchable' creation method: caller has deletion responsibility
308// ********************************************************************
312G4ITNavigator2::CreateTouchableHistory(const G4NavigationHistory* history) const
314 return new G4TouchableHistory(*history);
317// ********************************************************************
318// LocateGlobalPointAndUpdateTouchableHandle
319// ********************************************************************
322void G4ITNavigator2::LocateGlobalPointAndUpdateTouchableHandle(
323 const G4ThreeVector& position,
324 const G4ThreeVector& direction,
325 G4TouchableHandle& oldTouchableToUpdate,
326 const G4bool RelativeSearch )
328 G4VPhysicalVolume* pPhysVol;
329 pPhysVol = LocateGlobalPointAndSetup( position,&direction,RelativeSearch );
330 // Will check navigatorState validity
331 if( fpNavigatorState->fEnteredDaughter || fpNavigatorState->fExitedMother )
333 oldTouchableToUpdate = CreateTouchableHistory();
336 // We want to ensure that the touchable is correct in this case.
337 // The method below should do this and recalculate a lot more ....
339 oldTouchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory );
345// ********************************************************************
346// LocateGlobalPointAndUpdateTouchable
349// ********************************************************************
352void G4ITNavigator2::LocateGlobalPointAndUpdateTouchable(
353 const G4ThreeVector& position,
354 const G4ThreeVector& direction,
355 G4VTouchable* touchableToUpdate,
356 const G4bool RelativeSearch )
358 G4VPhysicalVolume* pPhysVol;
359 pPhysVol = LocateGlobalPointAndSetup( position, &direction, RelativeSearch);
360 // Will check navigatorState validity
361 touchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory );
364// ********************************************************************
365// LocateGlobalPointAndUpdateTouchable
366// ********************************************************************
369void G4ITNavigator2::LocateGlobalPointAndUpdateTouchable(
370 const G4ThreeVector& position,
371 G4VTouchable* touchableToUpdate,
372 const G4bool RelativeSearch )
374 G4VPhysicalVolume* pPhysVol;
375 pPhysVol = LocateGlobalPointAndSetup( position, 0, RelativeSearch);
376 // Will check navigatorState validity
377 touchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory );
380// ********************************************************************
382// ********************************************************************
385G4int G4ITNavigator2::GetVerboseLevel() const
390// ********************************************************************
392// ********************************************************************
395void G4ITNavigator2::SetVerboseLevel(G4int level)
398 fnormalNav.SetVerboseLevel(level);
399 fvoxelNav.SetVerboseLevel(level);
400 fparamNav.SetVerboseLevel(level);
401 freplicaNav.SetVerboseLevel(level);
402 fregularNav.SetVerboseLevel(level);
405// ********************************************************************
407// ********************************************************************
410G4bool G4ITNavigator2::IsActive() const
415// ********************************************************************
417// ********************************************************************
420void G4ITNavigator2::Activate(G4bool flag)
425// ********************************************************************
426// EnteredDaughterVolume
428// To inform the caller if the track is entering a daughter volume
429// ********************************************************************
432G4bool G4ITNavigator2::EnteredDaughterVolume() const
434 CheckNavigatorStateIsValid();
435 return fpNavigatorState->fEnteredDaughter;
438// ********************************************************************
440// ********************************************************************
443G4bool G4ITNavigator2::ExitedMotherVolume() const
445 CheckNavigatorStateIsValid();
446 return fpNavigatorState->fExitedMother;
449// ********************************************************************
451// ********************************************************************
454void G4ITNavigator2::CheckMode(G4bool mode)
457 fnormalNav.CheckMode(mode);
458 fvoxelNav.CheckMode(mode);
459 fparamNav.CheckMode(mode);
460 freplicaNav.CheckMode(mode);
461 fregularNav.CheckMode(mode);
464// ********************************************************************
466// ********************************************************************
469G4bool G4ITNavigator2::IsCheckModeActive() const
474// ********************************************************************
476// ********************************************************************
479void G4ITNavigator2::SetPushVerbosity(G4bool mode)
484// ********************************************************************
485// SeverityOfZeroStepping
487// Reports on severity of error in case Navigator is stuck
488// and is returning zero steps
489// ********************************************************************
492G4int G4ITNavigator2::SeverityOfZeroStepping( G4int* noZeroSteps ) const
494 CheckNavigatorStateIsValid();
495 G4int severity=0, noZeros= fpNavigatorState->fNumberZeroSteps;
496 if( noZeroSteps) *noZeroSteps = fpNavigatorState->fNumberZeroSteps;
498 if( noZeros >= fAbandonThreshold_NoZeroSteps )
502 if( noZeros > 0 && noZeros < fActionThreshold_NoZeroSteps )
504 severity = 5 * noZeros / fActionThreshold_NoZeroSteps;
506 else if( noZeros == fActionThreshold_NoZeroSteps )
510 else if( noZeros >= fAbandonThreshold_NoZeroSteps - 2 )
514 else if( noZeros < fAbandonThreshold_NoZeroSteps - 2 )
516 severity = 5 + 4 * (noZeros-fAbandonThreshold_NoZeroSteps)
517 / fActionThreshold_NoZeroSteps;
522// ********************************************************************
524// ********************************************************************
526inline void G4ITNavigator2::EnableBestSafety( G4bool value )
528 fvoxelNav.EnableBestSafety( value );