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 G4ITNavigator1 Inline implementation
30// G4ITNavigator1 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 G4ITNavigator1::GetCurrentLocalCoordinate() const
45 return fLastLocatedPointLocal;
48// ********************************************************************
51// Returns local direction of vector direction in world coord system
52// ********************************************************************
55G4ThreeVector G4ITNavigator1::ComputeLocalAxis(const G4ThreeVector& pVec) const
57 return (fHistory.GetTopTransform().IsRotated())
58 ? fHistory.GetTopTransform().TransformAxis(pVec) : pVec ;
61// ********************************************************************
64// Returns local coordinates of a point in the world coord system
65// ********************************************************************
69G4ITNavigator1::ComputeLocalPoint(const G4ThreeVector& pGlobalPoint) const
71 return ( fHistory.GetTopTransform().TransformPoint(pGlobalPoint) ) ;
74// ********************************************************************
77// Returns the current world (`topmost') volume
78// ********************************************************************
81G4VPhysicalVolume* G4ITNavigator1::GetWorldVolume() const
86// ********************************************************************
89// Sets the world (`topmost') volume
90// ********************************************************************
93void G4ITNavigator1::SetWorldVolume(G4VPhysicalVolume* pWorld)
95 if ( !(pWorld->GetTranslation()==G4ThreeVector(0,0,0)) )
97 G4Exception ("G4ITNavigator1::SetWorldVolume()", "GeomNav0002",
98 FatalException, "Volume must be centered on the origin.");
100 const G4RotationMatrix* rm = pWorld->GetRotation();
101 if ( rm && (!rm->isIdentity()) )
103 G4Exception ("G4ITNavigator1::SetWorldVolume()", "GeomNav0002",
104 FatalException, "Volume must not be rotated.");
106 fTopPhysical = pWorld;
107 fHistory.SetFirstEntry(pWorld);
110// ********************************************************************
111// SetGeometrycallyLimitedStep
113// Informs the navigator that the previous Step calculated
114// by the geometry was taken in its entirety
115// ********************************************************************
118void G4ITNavigator1::SetGeometricallyLimitedStep()
120 fWasLimitedByGeometry=true;
123// ********************************************************************
126// Resets stack and minimum of navigator state `machine'
127// ********************************************************************
130void G4ITNavigator1::ResetStackAndState()
136// ********************************************************************
138// ********************************************************************
141EVolume G4ITNavigator1::VolumeType(const G4VPhysicalVolume *pVol) const
143 return pVol->VolumeType();
146// ********************************************************************
147// CharacteriseDaughters
148// ********************************************************************
151EVolume G4ITNavigator1::CharacteriseDaughters(const G4LogicalVolume *pLog) const
153 return pLog->CharacteriseDaughters();
156// ********************************************************************
157// GetDaughtersRegularStructureId
158// ********************************************************************
161G4int G4ITNavigator1::
162GetDaughtersRegularStructureId(const G4LogicalVolume *pLog) const
165 G4VPhysicalVolume *pVol;
167 if ( pLog->GetNoDaughters()==1 )
169 pVol = pLog->GetDaughter(0);
170 regId = pVol->GetRegularStructureId();
175// ********************************************************************
176// GetGlobalToLocalTransform
178// Returns local to global transformation.
179// I.e. transformation that will take point or axis in world coord system
180// and return one in the local coord system
181// ********************************************************************
184const G4AffineTransform& G4ITNavigator1::GetGlobalToLocalTransform() const
186 return fHistory.GetTopTransform();
189// ********************************************************************
190// GetLocalToGlobalTransform
192// Returns global to local transformation
193// ********************************************************************
196const G4AffineTransform G4ITNavigator1::GetLocalToGlobalTransform() const
198 G4AffineTransform tempTransform;
199 tempTransform = fHistory.GetTopTransform().Inverse();
200 return tempTransform;
203// ********************************************************************
206// Computes+returns the local->global translation of current volume
207// ********************************************************************
210G4ThreeVector G4ITNavigator1::NetTranslation() const
212 G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
213 return tf.NetTranslation();
216// ********************************************************************
219// Computes+returns the local->global rotation of current volume
220// ********************************************************************
223G4RotationMatrix G4ITNavigator1::NetRotation() const
225 G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
226 return tf.NetRotation();
229// ********************************************************************
232// `Touchable' creation method: caller has deletion responsibility
233// ********************************************************************
236G4GRSVolume* G4ITNavigator1::CreateGRSVolume() const
238 G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
239 return new G4GRSVolume(fHistory.GetTopVolume(),
241 tf.NetTranslation());
244// ********************************************************************
247// `Touchable' creation method: caller has deletion responsibility
248// ********************************************************************
251G4GRSSolid* G4ITNavigator1::CreateGRSSolid() const
253 G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
254 return new G4GRSSolid(fHistory.GetTopVolume()->GetLogicalVolume()->GetSolid(),
256 tf.NetTranslation());
259// ********************************************************************
260// CreateTouchableHistory
262// `Touchable' creation method: caller has deletion responsibility
263// ********************************************************************
266G4TouchableHistory* G4ITNavigator1::CreateTouchableHistory() const
268 return new G4TouchableHistory(fHistory);
271// ********************************************************************
272// CreateTouchableHistory(history)
274// `Touchable' creation method: caller has deletion responsibility
275// ********************************************************************
279G4ITNavigator1::CreateTouchableHistory(const G4NavigationHistory* history) const
281 return new G4TouchableHistory(*history);
284// ********************************************************************
285// LocateGlobalPointAndUpdateTouchableHandle
286// ********************************************************************
289void G4ITNavigator1::LocateGlobalPointAndUpdateTouchableHandle(
290 const G4ThreeVector& position,
291 const G4ThreeVector& direction,
292 G4TouchableHandle& oldTouchableToUpdate,
293 const G4bool RelativeSearch )
295 G4VPhysicalVolume* pPhysVol;
296 pPhysVol = LocateGlobalPointAndSetup( position,&direction,RelativeSearch );
297 if( fEnteredDaughter || fExitedMother )
299 oldTouchableToUpdate = CreateTouchableHistory();
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 ....
305 oldTouchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
311// ********************************************************************
312// LocateGlobalPointAndUpdateTouchable
315// ********************************************************************
318void G4ITNavigator1::LocateGlobalPointAndUpdateTouchable(
319 const G4ThreeVector& position,
320 const G4ThreeVector& direction,
321 G4VTouchable* touchableToUpdate,
322 const G4bool RelativeSearch )
324 G4VPhysicalVolume* pPhysVol;
325 pPhysVol = LocateGlobalPointAndSetup( position, &direction, RelativeSearch);
326 touchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
329// ********************************************************************
330// LocateGlobalPointAndUpdateTouchable
331// ********************************************************************
334void G4ITNavigator1::LocateGlobalPointAndUpdateTouchable(
335 const G4ThreeVector& position,
336 G4VTouchable* touchableToUpdate,
337 const G4bool RelativeSearch )
339 G4VPhysicalVolume* pPhysVol;
340 pPhysVol = LocateGlobalPointAndSetup( position, 0, RelativeSearch);
341 touchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
344// ********************************************************************
346// ********************************************************************
349G4int G4ITNavigator1::GetVerboseLevel() const
354// ********************************************************************
356// ********************************************************************
359void G4ITNavigator1::SetVerboseLevel(G4int level)
362 fnormalNav.SetVerboseLevel(level);
363 fvoxelNav.SetVerboseLevel(level);
364 fparamNav.SetVerboseLevel(level);
365 freplicaNav.SetVerboseLevel(level);
366 fregularNav.SetVerboseLevel(level);
369// ********************************************************************
371// ********************************************************************
374G4bool G4ITNavigator1::IsActive() const
379// ********************************************************************
381// ********************************************************************
384void G4ITNavigator1::Activate(G4bool flag)
389// ********************************************************************
390// EnteredDaughterVolume
392// To inform the caller if the track is entering a daughter volume
393// ********************************************************************
396G4bool G4ITNavigator1::EnteredDaughterVolume() const
398 return fEnteredDaughter;
401// ********************************************************************
403// ********************************************************************
406G4bool G4ITNavigator1::ExitedMotherVolume() const
408 return fExitedMother;
411// ********************************************************************
413// ********************************************************************
416void G4ITNavigator1::CheckMode(G4bool mode)
419 fnormalNav.CheckMode(mode);
420 fvoxelNav.CheckMode(mode);
421 fparamNav.CheckMode(mode);
422 freplicaNav.CheckMode(mode);
423 fregularNav.CheckMode(mode);
426// ********************************************************************
428// ********************************************************************
431G4bool G4ITNavigator1::IsCheckModeActive() const
436// ********************************************************************
438// ********************************************************************
441void G4ITNavigator1::SetPushVerbosity(G4bool mode)
446// ********************************************************************
447// SeverityOfZeroStepping
449// Reports on severity of error in case Navigator is stuck
450// and is returning zero steps
451// ********************************************************************
454G4int G4ITNavigator1::SeverityOfZeroStepping( G4int* noZeroSteps ) const
456 G4int severity=0, noZeros= fNumberZeroSteps;
457 if( noZeroSteps) *noZeroSteps = fNumberZeroSteps;
459 if( noZeros >= fAbandonThreshold_NoZeroSteps )
463 if( noZeros > 0 && noZeros < fActionThreshold_NoZeroSteps )
465 severity = 5 * noZeros / fActionThreshold_NoZeroSteps;
467 else if( noZeros == fActionThreshold_NoZeroSteps )
471 else if( noZeros >= fAbandonThreshold_NoZeroSteps - 2 )
475 else if( noZeros < fAbandonThreshold_NoZeroSteps - 2 )
477 severity = 5 + 4 * (noZeros-fAbandonThreshold_NoZeroSteps)
478 / fActionThreshold_NoZeroSteps;
483// ********************************************************************
485// ********************************************************************
487inline void G4ITNavigator1::EnableBestSafety( G4bool value )
489 fvoxelNav.EnableBestSafety( value );