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 G4ITNavigator1 Inline implementation
 
   31 // G4ITNavigator1 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 G4ITNavigator1::GetCurrentLocalCoordinate() const
 
   46   return fLastLocatedPointLocal;
 
   49 // ********************************************************************
 
   52 // Returns local direction of vector direction in world coord system
 
   53 // ********************************************************************
 
   56 G4ThreeVector G4ITNavigator1::ComputeLocalAxis(const G4ThreeVector& pVec) const
 
   58   return (fHistory.GetTopTransform().IsRotated())
 
   59          ? fHistory.GetTopTransform().TransformAxis(pVec) : pVec ;
 
   62 // ********************************************************************
 
   65 // Returns local coordinates of a point in the world coord system
 
   66 // ********************************************************************
 
   70 G4ITNavigator1::ComputeLocalPoint(const G4ThreeVector& pGlobalPoint) const
 
   72   return ( fHistory.GetTopTransform().TransformPoint(pGlobalPoint) ) ;
 
   75 // ********************************************************************
 
   78 // Returns the current  world (`topmost') volume
 
   79 // ********************************************************************
 
   82 G4VPhysicalVolume* G4ITNavigator1::GetWorldVolume() const
 
   87 // ********************************************************************
 
   90 // Sets the world (`topmost') volume
 
   91 // ********************************************************************
 
   94 void G4ITNavigator1::SetWorldVolume(G4VPhysicalVolume* pWorld)
 
   96   if ( !(pWorld->GetTranslation()==G4ThreeVector(0,0,0)) )
 
   98     G4Exception ("G4ITNavigator1::SetWorldVolume()", "GeomNav0002",
 
   99                  FatalException, "Volume must be centered on the origin.");
 
  101   const G4RotationMatrix* rm = pWorld->GetRotation();
 
  102   if ( rm && (!rm->isIdentity()) )
 
  104     G4Exception ("G4ITNavigator1::SetWorldVolume()", "GeomNav0002",
 
  105                  FatalException, "Volume must not be rotated.");
 
  107   fTopPhysical = pWorld;
 
  108   fHistory.SetFirstEntry(pWorld);
 
  111 // ********************************************************************
 
  112 // SetGeometrycallyLimitedStep
 
  114 // Informs the navigator that the previous Step calculated
 
  115 // by the geometry was taken in its entirety
 
  116 // ********************************************************************
 
  119 void G4ITNavigator1::SetGeometricallyLimitedStep()
 
  121   fWasLimitedByGeometry=true;
 
  124 // ********************************************************************
 
  125 // ResetStackAndState
 
  127 // Resets stack and minimum of navigator state `machine'
 
  128 // ********************************************************************
 
  131 void G4ITNavigator1::ResetStackAndState()
 
  137 // ********************************************************************
 
  139 // ********************************************************************
 
  142 EVolume G4ITNavigator1::VolumeType(const G4VPhysicalVolume *pVol) const
 
  144   return pVol->VolumeType();
 
  147 // ********************************************************************
 
  148 // CharacteriseDaughters
 
  149 // ********************************************************************
 
  152 EVolume G4ITNavigator1::CharacteriseDaughters(const G4LogicalVolume *pLog) const
 
  154   return pLog->CharacteriseDaughters();
 
  157 // ********************************************************************
 
  158 // GetDaughtersRegularStructureId
 
  159 // ********************************************************************
 
  162 G4int G4ITNavigator1::
 
  163 GetDaughtersRegularStructureId(const G4LogicalVolume *pLog) const
 
  166   G4VPhysicalVolume *pVol;
 
  168   if ( pLog->GetNoDaughters()==1 )
 
  170     pVol = pLog->GetDaughter(0);
 
  171     regId = pVol->GetRegularStructureId();
 
  176 // ********************************************************************
 
  177 // GetGlobalToLocalTransform
 
  179 // Returns local to global transformation.
 
  180 // I.e. transformation that will take point or axis in world coord system
 
  181 // and return one in the local coord system
 
  182 // ********************************************************************
 
  185 const G4AffineTransform& G4ITNavigator1::GetGlobalToLocalTransform() const
 
  187   return fHistory.GetTopTransform();
 
  190 // ********************************************************************
 
  191 // GetLocalToGlobalTransform
 
  193 // Returns global to local transformation 
 
  194 // ********************************************************************
 
  197 const G4AffineTransform G4ITNavigator1::GetLocalToGlobalTransform() const
 
  199   G4AffineTransform  tempTransform;
 
  200   tempTransform = fHistory.GetTopTransform().Inverse(); 
 
  201   return tempTransform;
 
  204 // ********************************************************************
 
  207 // Computes+returns the local->global translation of current volume
 
  208 // ********************************************************************
 
  211 G4ThreeVector G4ITNavigator1::NetTranslation() const
 
  213   G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
 
  214   return tf.NetTranslation();
 
  217 // ********************************************************************
 
  220 // Computes+returns the local->global rotation of current volume
 
  221 // ********************************************************************
 
  224 G4RotationMatrix G4ITNavigator1::NetRotation() const
 
  226   G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
 
  227   return tf.NetRotation();
 
  230 // ********************************************************************
 
  233 // `Touchable' creation method: caller has deletion responsibility
 
  234 // ********************************************************************
 
  237 G4GRSVolume* G4ITNavigator1::CreateGRSVolume() const
 
  239   G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
 
  240   return new G4GRSVolume(fHistory.GetTopVolume(),
 
  242                          tf.NetTranslation());
 
  245 // ********************************************************************
 
  248 // `Touchable' creation method: caller has deletion responsibility
 
  249 // ********************************************************************
 
  252 G4GRSSolid* G4ITNavigator1::CreateGRSSolid() const
 
  254   G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
 
  255   return new G4GRSSolid(fHistory.GetTopVolume()->GetLogicalVolume()->GetSolid(),
 
  257                         tf.NetTranslation());
 
  260 // ********************************************************************
 
  261 // CreateTouchableHistory
 
  263 // `Touchable' creation method: caller has deletion responsibility
 
  264 // ********************************************************************
 
  267 G4TouchableHistory* G4ITNavigator1::CreateTouchableHistory() const
 
  269   return new G4TouchableHistory(fHistory);
 
  272 // ********************************************************************
 
  273 // CreateTouchableHistory(history)
 
  275 // `Touchable' creation method: caller has deletion responsibility
 
  276 // ********************************************************************
 
  280 G4ITNavigator1::CreateTouchableHistory(const G4NavigationHistory* history) const
 
  282   return new G4TouchableHistory(*history);
 
  285 // ********************************************************************
 
  286 // LocateGlobalPointAndUpdateTouchableHandle
 
  287 // ********************************************************************
 
  290 void G4ITNavigator1::LocateGlobalPointAndUpdateTouchableHandle(
 
  291                                const G4ThreeVector&       position,
 
  292                                const G4ThreeVector&       direction,
 
  293                                      G4TouchableHandle&   oldTouchableToUpdate,
 
  294                                const G4bool               RelativeSearch )
 
  296   G4VPhysicalVolume* pPhysVol;
 
  297   pPhysVol = LocateGlobalPointAndSetup( position,&direction,RelativeSearch );
 
  298   if( fEnteredDaughter || fExitedMother )
 
  300      oldTouchableToUpdate = CreateTouchableHistory();
 
  303        // We want to ensure that the touchable is correct in this case.
 
  304        //  The method below should do this and recalculate a lot more ....
 
  306        oldTouchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
 
  312 // ********************************************************************
 
  313 // LocateGlobalPointAndUpdateTouchable
 
  316 // ********************************************************************
 
  319 void G4ITNavigator1::LocateGlobalPointAndUpdateTouchable(
 
  320                            const G4ThreeVector&       position,
 
  321                            const G4ThreeVector&       direction,
 
  322                                  G4VTouchable*        touchableToUpdate,
 
  323                            const G4bool               RelativeSearch  )
 
  325   G4VPhysicalVolume* pPhysVol;
 
  326   pPhysVol = LocateGlobalPointAndSetup( position, &direction, RelativeSearch);  
 
  327   touchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
 
  330 // ********************************************************************
 
  331 // LocateGlobalPointAndUpdateTouchable
 
  332 // ********************************************************************
 
  335 void G4ITNavigator1::LocateGlobalPointAndUpdateTouchable(
 
  336                            const G4ThreeVector&       position,
 
  337                                  G4VTouchable*        touchableToUpdate,
 
  338                            const G4bool               RelativeSearch )
 
  340   G4VPhysicalVolume* pPhysVol;
 
  341   pPhysVol = LocateGlobalPointAndSetup( position, 0, RelativeSearch);  
 
  342   touchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
 
  345 // ********************************************************************
 
  347 // ********************************************************************
 
  350 G4int G4ITNavigator1::GetVerboseLevel() const
 
  355 // ********************************************************************
 
  357 // ********************************************************************
 
  360 void G4ITNavigator1::SetVerboseLevel(G4int level)
 
  363   fnormalNav.SetVerboseLevel(level);
 
  364   fvoxelNav.SetVerboseLevel(level);
 
  365   fparamNav.SetVerboseLevel(level);
 
  366   freplicaNav.SetVerboseLevel(level);
 
  367   fregularNav.SetVerboseLevel(level);
 
  370 // ********************************************************************
 
  372 // ********************************************************************
 
  375 G4bool G4ITNavigator1::IsActive() const
 
  380 // ********************************************************************
 
  382 // ********************************************************************
 
  385 void G4ITNavigator1::Activate(G4bool flag)
 
  390 // ********************************************************************
 
  391 // EnteredDaughterVolume
 
  393 // To inform the caller if the track is entering a daughter volume
 
  394 // ********************************************************************
 
  397 G4bool G4ITNavigator1::EnteredDaughterVolume() const
 
  399   return fEnteredDaughter;
 
  402 // ********************************************************************
 
  403 // ExitedMotherVolume
 
  404 // ********************************************************************
 
  407 G4bool G4ITNavigator1::ExitedMotherVolume() const
 
  409   return fExitedMother;
 
  412 // ********************************************************************
 
  414 // ********************************************************************
 
  417 void  G4ITNavigator1::CheckMode(G4bool mode)
 
  420   fnormalNav.CheckMode(mode);
 
  421   fvoxelNav.CheckMode(mode);
 
  422   fparamNav.CheckMode(mode);
 
  423   freplicaNav.CheckMode(mode);
 
  424   fregularNav.CheckMode(mode);
 
  427 // ********************************************************************
 
  429 // ********************************************************************
 
  432 G4bool G4ITNavigator1::IsCheckModeActive() const
 
  437 // ********************************************************************
 
  439 // ********************************************************************
 
  442 void G4ITNavigator1::SetPushVerbosity(G4bool mode)
 
  447 // ********************************************************************
 
  448 // SeverityOfZeroStepping
 
  450 // Reports on severity of error in case Navigator is stuck
 
  451 // and is returning zero steps
 
  452 // ********************************************************************
 
  455 G4int G4ITNavigator1::SeverityOfZeroStepping( G4int* noZeroSteps ) const
 
  457   G4int severity=0, noZeros= fNumberZeroSteps;
 
  458   if( noZeroSteps) *noZeroSteps = fNumberZeroSteps;
 
  460   if( noZeros >= fAbandonThreshold_NoZeroSteps )
 
  464   if( noZeros > 0 && noZeros < fActionThreshold_NoZeroSteps )
 
  466     severity =  5 * noZeros / fActionThreshold_NoZeroSteps;
 
  468   else if( noZeros == fActionThreshold_NoZeroSteps )
 
  472   else if( noZeros >= fAbandonThreshold_NoZeroSteps - 2 )
 
  476   else if( noZeros < fAbandonThreshold_NoZeroSteps - 2 )
 
  478     severity =  5 + 4 * (noZeros-fAbandonThreshold_NoZeroSteps)
 
  479                       / fActionThreshold_NoZeroSteps;
 
  484 // ********************************************************************
 
  486 // ********************************************************************
 
  488 inline void G4ITNavigator1::EnableBestSafety( G4bool value )
 
  490   fvoxelNav.EnableBestSafety( value );