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 // ********************************************************************
 
  162 // GetDaughtersRegularStructureId
 
  163 // ********************************************************************
 
  166 G4int G4ITNavigator2::
 
  167 GetDaughtersRegularStructureId(const G4LogicalVolume *pLog) const
 
  170   G4VPhysicalVolume *pVol;
 
  172   if ( pLog->GetNoDaughters()==1 )
 
  174     pVol = pLog->GetDaughter(0);
 
  175     regId = pVol->GetRegularStructureId();
 
  180 // ********************************************************************
 
  181 // GetGlobalToLocalTransform
 
  183 // Returns local to global transformation.
 
  184 // I.e. transformation that will take point or axis in world coord system
 
  185 // and return one in the local coord system
 
  186 // ********************************************************************
 
  189 const G4AffineTransform& G4ITNavigator2::GetGlobalToLocalTransform() const
 
  191     CheckNavigatorStateIsValid();
 
  192     return fpNavigatorState->fHistory.GetTopTransform();
 
  195 // ********************************************************************
 
  196 // GetLocalToGlobalTransform
 
  198 // Returns global to local transformation 
 
  199 // ********************************************************************
 
  202 const G4AffineTransform G4ITNavigator2::GetLocalToGlobalTransform() const
 
  204     CheckNavigatorStateIsValid();
 
  205     G4AffineTransform  tempTransform;
 
  206     tempTransform = fpNavigatorState->fHistory.GetTopTransform().Inverse();
 
  207     return tempTransform;
 
  210 // ********************************************************************
 
  213 // Computes+returns the local->global translation of current volume
 
  214 // ********************************************************************
 
  217 G4ThreeVector G4ITNavigator2::NetTranslation() const
 
  219     CheckNavigatorStateIsValid();
 
  220     G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
 
  221     return tf.NetTranslation();
 
  224 // ********************************************************************
 
  227 // Computes+returns the local->global rotation of current volume
 
  228 // ********************************************************************
 
  231 G4RotationMatrix G4ITNavigator2::NetRotation() const
 
  233     CheckNavigatorStateIsValid();
 
  234     G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
 
  235     return tf.NetRotation();
 
  238 // ********************************************************************
 
  241 // `Touchable' creation method: caller has deletion responsibility
 
  242 // ********************************************************************
 
  245 G4GRSVolume* G4ITNavigator2::CreateGRSVolume() const
 
  247     CheckNavigatorStateIsValid();
 
  248     G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
 
  249     return new G4GRSVolume(fpNavigatorState->fHistory.GetTopVolume(),
 
  251                            tf.NetTranslation());
 
  254 // ********************************************************************
 
  257 // `Touchable' creation method: caller has deletion responsibility
 
  258 // ********************************************************************
 
  261 G4GRSSolid* G4ITNavigator2::CreateGRSSolid() const
 
  263     CheckNavigatorStateIsValid();
 
  264     G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
 
  265     return new G4GRSSolid(fpNavigatorState->fHistory.GetTopVolume()->GetLogicalVolume()->GetSolid(),
 
  267                           tf.NetTranslation());
 
  270 // ********************************************************************
 
  271 // CreateTouchableHistory
 
  273 // `Touchable' creation method: caller has deletion responsibility
 
  274 // ********************************************************************
 
  277 G4TouchableHistory* G4ITNavigator2::CreateTouchableHistory() const
 
  279     CheckNavigatorStateIsValid();
 
  280     return new G4TouchableHistory(fpNavigatorState->fHistory);
 
  283 // ********************************************************************
 
  284 // CreateTouchableHistory(history)
 
  286 // `Touchable' creation method: caller has deletion responsibility
 
  287 // ********************************************************************
 
  291 G4ITNavigator2::CreateTouchableHistory(const G4NavigationHistory* history) const
 
  293   return new G4TouchableHistory(*history);
 
  296 // ********************************************************************
 
  297 // LocateGlobalPointAndUpdateTouchableHandle
 
  298 // ********************************************************************
 
  301 void G4ITNavigator2::LocateGlobalPointAndUpdateTouchableHandle(
 
  302                                const G4ThreeVector&       position,
 
  303                                const G4ThreeVector&       direction,
 
  304                                      G4TouchableHandle&   oldTouchableToUpdate,
 
  305                                const G4bool               RelativeSearch )
 
  307   G4VPhysicalVolume* pPhysVol;
 
  308   pPhysVol = LocateGlobalPointAndSetup( position,&direction,RelativeSearch );
 
  309   // Will check navigatorState validity
 
  310   if( fpNavigatorState->fEnteredDaughter || fpNavigatorState->fExitedMother )
 
  312      oldTouchableToUpdate = CreateTouchableHistory();
 
  315        // We want to ensure that the touchable is correct in this case.
 
  316        //  The method below should do this and recalculate a lot more ....
 
  318        oldTouchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory );
 
  324 // ********************************************************************
 
  325 // LocateGlobalPointAndUpdateTouchable
 
  328 // ********************************************************************
 
  331 void G4ITNavigator2::LocateGlobalPointAndUpdateTouchable(
 
  332                            const G4ThreeVector&       position,
 
  333                            const G4ThreeVector&       direction,
 
  334                                  G4VTouchable*        touchableToUpdate,
 
  335                            const G4bool               RelativeSearch  )
 
  337   G4VPhysicalVolume* pPhysVol;
 
  338   pPhysVol = LocateGlobalPointAndSetup( position, &direction, RelativeSearch);  
 
  339   // Will check navigatorState validity
 
  340   touchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory );
 
  343 // ********************************************************************
 
  344 // LocateGlobalPointAndUpdateTouchable
 
  345 // ********************************************************************
 
  348 void G4ITNavigator2::LocateGlobalPointAndUpdateTouchable(
 
  349                            const G4ThreeVector&       position,
 
  350                                  G4VTouchable*        touchableToUpdate,
 
  351                            const G4bool               RelativeSearch )
 
  353   G4VPhysicalVolume* pPhysVol;
 
  354   pPhysVol = LocateGlobalPointAndSetup( position, 0, RelativeSearch);  
 
  355   // Will check navigatorState validity
 
  356   touchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory );
 
  359 // ********************************************************************
 
  361 // ********************************************************************
 
  364 G4int G4ITNavigator2::GetVerboseLevel() const
 
  369 // ********************************************************************
 
  371 // ********************************************************************
 
  374 void G4ITNavigator2::SetVerboseLevel(G4int level)
 
  377   fnormalNav.SetVerboseLevel(level);
 
  378   fvoxelNav.SetVerboseLevel(level);
 
  379   fparamNav.SetVerboseLevel(level);
 
  380   freplicaNav.SetVerboseLevel(level);
 
  381   fregularNav.SetVerboseLevel(level);
 
  384 // ********************************************************************
 
  386 // ********************************************************************
 
  389 G4bool G4ITNavigator2::IsActive() const
 
  394 // ********************************************************************
 
  396 // ********************************************************************
 
  399 void G4ITNavigator2::Activate(G4bool flag)
 
  404 // ********************************************************************
 
  405 // EnteredDaughterVolume
 
  407 // To inform the caller if the track is entering a daughter volume
 
  408 // ********************************************************************
 
  411 G4bool G4ITNavigator2::EnteredDaughterVolume() const
 
  413     CheckNavigatorStateIsValid();
 
  414     return fpNavigatorState->fEnteredDaughter;
 
  417 // ********************************************************************
 
  418 // ExitedMotherVolume
 
  419 // ********************************************************************
 
  422 G4bool G4ITNavigator2::ExitedMotherVolume() const
 
  424     CheckNavigatorStateIsValid();
 
  425     return fpNavigatorState->fExitedMother;
 
  428 // ********************************************************************
 
  430 // ********************************************************************
 
  433 void  G4ITNavigator2::CheckMode(G4bool mode)
 
  436   fnormalNav.CheckMode(mode);
 
  437   fvoxelNav.CheckMode(mode);
 
  438   fparamNav.CheckMode(mode);
 
  439   freplicaNav.CheckMode(mode);
 
  440   fregularNav.CheckMode(mode);
 
  443 // ********************************************************************
 
  445 // ********************************************************************
 
  448 G4bool G4ITNavigator2::IsCheckModeActive() const
 
  453 // ********************************************************************
 
  455 // ********************************************************************
 
  458 void G4ITNavigator2::SetPushVerbosity(G4bool mode)
 
  463 // ********************************************************************
 
  464 // SeverityOfZeroStepping
 
  466 // Reports on severity of error in case Navigator is stuck
 
  467 // and is returning zero steps
 
  468 // ********************************************************************
 
  471 G4int G4ITNavigator2::SeverityOfZeroStepping( G4int* noZeroSteps ) const
 
  473     CheckNavigatorStateIsValid();
 
  474     G4int severity=0, noZeros= fpNavigatorState->fNumberZeroSteps;
 
  475     if( noZeroSteps) *noZeroSteps = fpNavigatorState->fNumberZeroSteps;
 
  477   if( noZeros >= fAbandonThreshold_NoZeroSteps )
 
  481   if( noZeros > 0 && noZeros < fActionThreshold_NoZeroSteps )
 
  483     severity =  5 * noZeros / fActionThreshold_NoZeroSteps;
 
  485   else if( noZeros == fActionThreshold_NoZeroSteps )
 
  489   else if( noZeros >= fAbandonThreshold_NoZeroSteps - 2 )
 
  493   else if( noZeros < fAbandonThreshold_NoZeroSteps - 2 )
 
  495     severity =  5 + 4 * (noZeros-fAbandonThreshold_NoZeroSteps)
 
  496                       / fActionThreshold_NoZeroSteps;
 
  501 // ********************************************************************
 
  503 // ********************************************************************
 
  505 inline void G4ITNavigator2::EnableBestSafety( G4bool value )
 
  507   fvoxelNav.EnableBestSafety( value );