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 // ********************************************************************
 
   27 // $Id: G4Navigator.icc 73164 2013-08-21 08:55:28Z gcosmo $
 
   30 // class G4Navigator Inline implementation
 
   32 // ********************************************************************
 
   34 // ********************************************************************
 
   35 // GetCurrentLocalCoordinate
 
   37 // Returns the local coordinate of the current track
 
   38 // ********************************************************************
 
   41 G4ThreeVector G4Navigator::GetCurrentLocalCoordinate() const
 
   43   return fLastLocatedPointLocal;
 
   46 // ********************************************************************
 
   49 // Returns local direction of vector direction in world coord system
 
   50 // ********************************************************************
 
   53 G4ThreeVector G4Navigator::ComputeLocalAxis(const G4ThreeVector& pVec) const
 
   55   return (fHistory.GetTopTransform().IsRotated())
 
   56          ? fHistory.GetTopTransform().TransformAxis(pVec) : pVec ;
 
   59 // ********************************************************************
 
   62 // Returns local coordinates of a point in the world coord system
 
   63 // ********************************************************************
 
   67 G4Navigator::ComputeLocalPoint(const G4ThreeVector& pGlobalPoint) const
 
   69   return ( fHistory.GetTopTransform().TransformPoint(pGlobalPoint) ) ;
 
   72 // ********************************************************************
 
   75 // Returns the current  world (`topmost') volume
 
   76 // ********************************************************************
 
   79 G4VPhysicalVolume* G4Navigator::GetWorldVolume() const
 
   84 // ********************************************************************
 
   87 // Sets the world (`topmost') volume
 
   88 // ********************************************************************
 
   91 void G4Navigator::SetWorldVolume(G4VPhysicalVolume* pWorld)
 
   93   if ( !(pWorld->GetTranslation()==G4ThreeVector(0,0,0)) )
 
   95     G4Exception ("G4Navigator::SetWorldVolume()", "GeomNav0002",
 
   96                  FatalException, "Volume must be centered on the origin.");
 
   98   const G4RotationMatrix* rm = pWorld->GetRotation();
 
   99   if ( rm && (!rm->isIdentity()) )
 
  101     G4Exception ("G4Navigator::SetWorldVolume()", "GeomNav0002",
 
  102                  FatalException, "Volume must not be rotated.");
 
  104   fTopPhysical = pWorld;
 
  105   fHistory.SetFirstEntry(pWorld);
 
  108 // ********************************************************************
 
  109 // SetGeometrycallyLimitedStep
 
  111 // Informs the navigator that the previous Step calculated
 
  112 // by the geometry was taken in its entirety
 
  113 // ********************************************************************
 
  116 void G4Navigator::SetGeometricallyLimitedStep()
 
  118   fWasLimitedByGeometry=true;
 
  121 // ********************************************************************
 
  122 // ResetStackAndState
 
  124 // Resets stack and minimum of navigator state `machine'
 
  125 // ********************************************************************
 
  128 void G4Navigator::ResetStackAndState()
 
  134 // ********************************************************************
 
  136 // ********************************************************************
 
  139 EVolume G4Navigator::VolumeType(const G4VPhysicalVolume *pVol) const
 
  141   return pVol->VolumeType();
 
  144 // ********************************************************************
 
  145 // CharacteriseDaughters
 
  146 // ********************************************************************
 
  149 EVolume G4Navigator::CharacteriseDaughters(const G4LogicalVolume *pLog) const
 
  151   return pLog->CharacteriseDaughters();
 
  154 // ********************************************************************
 
  155 // GetDaughtersRegularStructureId
 
  156 // ********************************************************************
 
  160 GetDaughtersRegularStructureId(const G4LogicalVolume *pLog) const
 
  163   G4VPhysicalVolume *pVol;
 
  165   if ( pLog->GetNoDaughters()==1 )
 
  167     pVol = pLog->GetDaughter(0);
 
  168     regId = pVol->GetRegularStructureId();
 
  173 // ********************************************************************
 
  174 // GetGlobalToLocalTransform
 
  176 // Returns local to global transformation.
 
  177 // I.e. transformation that will take point or axis in world coord system
 
  178 // and return one in the local coord system
 
  179 // ********************************************************************
 
  182 const G4AffineTransform& G4Navigator::GetGlobalToLocalTransform() const
 
  184   return fHistory.GetTopTransform();
 
  187 // ********************************************************************
 
  188 // GetLocalToGlobalTransform
 
  190 // Returns global to local transformation 
 
  191 // ********************************************************************
 
  194 const G4AffineTransform G4Navigator::GetLocalToGlobalTransform() const
 
  196   G4AffineTransform  tempTransform;
 
  197   tempTransform = fHistory.GetTopTransform().Inverse(); 
 
  198   return tempTransform;
 
  201 // ********************************************************************
 
  204 // Computes+returns the local->global translation of current volume
 
  205 // ********************************************************************
 
  208 G4ThreeVector G4Navigator::NetTranslation() const
 
  210   G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
 
  211   return tf.NetTranslation();
 
  214 // ********************************************************************
 
  217 // Computes+returns the local->global rotation of current volume
 
  218 // ********************************************************************
 
  221 G4RotationMatrix G4Navigator::NetRotation() const
 
  223   G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
 
  224   return tf.NetRotation();
 
  227 // ********************************************************************
 
  230 // `Touchable' creation method: caller has deletion responsibility
 
  231 // ********************************************************************
 
  234 G4GRSVolume* G4Navigator::CreateGRSVolume() const
 
  236   G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
 
  237   return new G4GRSVolume(fHistory.GetTopVolume(),
 
  239                          tf.NetTranslation());
 
  242 // ********************************************************************
 
  245 // `Touchable' creation method: caller has deletion responsibility
 
  246 // ********************************************************************
 
  249 G4GRSSolid* G4Navigator::CreateGRSSolid() const
 
  251   G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
 
  252   return new G4GRSSolid(fHistory.GetTopVolume()->GetLogicalVolume()->GetSolid(),
 
  254                         tf.NetTranslation());
 
  257 // ********************************************************************
 
  258 // CreateTouchableHistory
 
  260 // `Touchable' creation method: caller has deletion responsibility
 
  261 // ********************************************************************
 
  264 G4TouchableHistory* G4Navigator::CreateTouchableHistory() const
 
  266   return new G4TouchableHistory(fHistory);
 
  269 // ********************************************************************
 
  270 // CreateTouchableHistory(history)
 
  272 // `Touchable' creation method: caller has deletion responsibility
 
  273 // ********************************************************************
 
  277 G4Navigator::CreateTouchableHistory(const G4NavigationHistory* history) const
 
  279   return new G4TouchableHistory(*history);
 
  282 // ********************************************************************
 
  283 // LocateGlobalPointAndUpdateTouchableHandle
 
  284 // ********************************************************************
 
  287 void G4Navigator::LocateGlobalPointAndUpdateTouchableHandle(
 
  288                                const G4ThreeVector&       position,
 
  289                                const G4ThreeVector&       direction,
 
  290                                      G4TouchableHandle&   oldTouchableToUpdate,
 
  291                                const G4bool               RelativeSearch )
 
  293   G4VPhysicalVolume* pPhysVol;
 
  294   pPhysVol = LocateGlobalPointAndSetup( position,&direction,RelativeSearch );
 
  295   if( fEnteredDaughter || fExitedMother )
 
  297      oldTouchableToUpdate = CreateTouchableHistory();
 
  300        // We want to ensure that the touchable is correct in this case.
 
  301        //  The method below should do this and recalculate a lot more ....
 
  303        oldTouchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
 
  309 // ********************************************************************
 
  310 // LocateGlobalPointAndUpdateTouchable
 
  313 // ********************************************************************
 
  316 void G4Navigator::LocateGlobalPointAndUpdateTouchable(
 
  317                            const G4ThreeVector&       position,
 
  318                            const G4ThreeVector&       direction,
 
  319                                  G4VTouchable*        touchableToUpdate,
 
  320                            const G4bool               RelativeSearch  )
 
  322   G4VPhysicalVolume* pPhysVol;
 
  323   pPhysVol = LocateGlobalPointAndSetup( position, &direction, RelativeSearch);  
 
  324   touchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
 
  327 // ********************************************************************
 
  328 // LocateGlobalPointAndUpdateTouchable
 
  329 // ********************************************************************
 
  332 void G4Navigator::LocateGlobalPointAndUpdateTouchable(
 
  333                            const G4ThreeVector&       position,
 
  334                                  G4VTouchable*        touchableToUpdate,
 
  335                            const G4bool               RelativeSearch )
 
  337   G4VPhysicalVolume* pPhysVol;
 
  338   pPhysVol = LocateGlobalPointAndSetup( position, 0, RelativeSearch);  
 
  339   touchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
 
  342 // ********************************************************************
 
  344 // ********************************************************************
 
  347 G4int G4Navigator::GetVerboseLevel() const
 
  352 // ********************************************************************
 
  354 // ********************************************************************
 
  357 void G4Navigator::SetVerboseLevel(G4int level)
 
  360   fnormalNav.SetVerboseLevel(level);
 
  361   fvoxelNav.SetVerboseLevel(level);
 
  362   fparamNav.SetVerboseLevel(level);
 
  363   freplicaNav.SetVerboseLevel(level);
 
  364   fregularNav.SetVerboseLevel(level);
 
  367 // ********************************************************************
 
  369 // ********************************************************************
 
  372 G4bool G4Navigator::IsActive() const
 
  377 // ********************************************************************
 
  379 // ********************************************************************
 
  382 void G4Navigator::Activate(G4bool flag)
 
  387 // ********************************************************************
 
  388 // EnteredDaughterVolume
 
  390 // To inform the caller if the track is entering a daughter volume
 
  391 // ********************************************************************
 
  394 G4bool G4Navigator::EnteredDaughterVolume() const
 
  396   return fEnteredDaughter;
 
  399 // ********************************************************************
 
  400 // ExitedMotherVolume
 
  401 // ********************************************************************
 
  404 G4bool G4Navigator::ExitedMotherVolume() const
 
  406   return fExitedMother;
 
  409 // ********************************************************************
 
  411 // ********************************************************************
 
  414 void  G4Navigator::CheckMode(G4bool mode)
 
  417   fnormalNav.CheckMode(mode);
 
  418   fvoxelNav.CheckMode(mode);
 
  419   fparamNav.CheckMode(mode);
 
  420   freplicaNav.CheckMode(mode);
 
  421   fregularNav.CheckMode(mode);
 
  424 // ********************************************************************
 
  426 // ********************************************************************
 
  429 G4bool G4Navigator::IsCheckModeActive() const
 
  434 // ********************************************************************
 
  436 // ********************************************************************
 
  439 void G4Navigator::SetPushVerbosity(G4bool mode)
 
  444 // ********************************************************************
 
  445 // SeverityOfZeroStepping
 
  447 // Reports on severity of error in case Navigator is stuck
 
  448 // and is returning zero steps
 
  449 // ********************************************************************
 
  452 G4int G4Navigator::SeverityOfZeroStepping( G4int* noZeroSteps ) const 
 
  454   G4int severity=0, noZeros= fNumberZeroSteps;
 
  455   if( noZeroSteps) *noZeroSteps = fNumberZeroSteps;
 
  457   if( noZeros >= fAbandonThreshold_NoZeroSteps )
 
  461   if( noZeros > 0 && noZeros < fActionThreshold_NoZeroSteps )
 
  463     severity =  5 * noZeros / fActionThreshold_NoZeroSteps;
 
  465   else if( noZeros == fActionThreshold_NoZeroSteps )
 
  469   else if( noZeros >= fAbandonThreshold_NoZeroSteps - 2 )
 
  473   else if( noZeros < fAbandonThreshold_NoZeroSteps - 2 )
 
  475     severity =  5 + 4 * (noZeros-fAbandonThreshold_NoZeroSteps)
 
  476                       / fActionThreshold_NoZeroSteps;
 
  481 // ********************************************************************
 
  483 // ********************************************************************
 
  485 inline void G4Navigator::EnableBestSafety( G4bool value )
 
  487   fvoxelNav.EnableBestSafety( value );