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 G4ITNavigator Inline implementation
 
   31 // G4ITNavigator 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 G4ITNavigator::GetCurrentLocalCoordinate() const
 
   46   return fLastLocatedPointLocal;
 
   49 // ********************************************************************
 
   52 // Returns local direction of vector direction in world coord system
 
   53 // ********************************************************************
 
   56 G4ThreeVector G4ITNavigator::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 G4ITNavigator::ComputeLocalPoint(const G4ThreeVector& pGlobalPoint) const
 
   72   return ( fHistory.GetTopTransform().TransformPoint(pGlobalPoint) ) ;
 
   75 // ********************************************************************
 
   78 // Returns the current  world (`topmost') volume
 
   79 // ********************************************************************
 
   82 G4VPhysicalVolume* G4ITNavigator::GetWorldVolume() const
 
   87 // ********************************************************************
 
   90 // Sets the world (`topmost') volume
 
   91 // ********************************************************************
 
   94 void G4ITNavigator::SetWorldVolume(G4VPhysicalVolume* pWorld)
 
   96   if ( !(pWorld->GetTranslation()==G4ThreeVector(0,0,0)) )
 
   98     G4Exception ("G4ITNavigator::SetWorldVolume()", "GeomNav0002",
 
   99                  FatalException, "Volume must be centered on the origin.");
 
  101   const G4RotationMatrix* rm = pWorld->GetRotation();
 
  102   if ( rm && (!rm->isIdentity()) )
 
  104     G4Exception ("G4ITNavigator::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 G4ITNavigator::SetGeometricallyLimitedStep()
 
  121   fWasLimitedByGeometry=true;
 
  124 // ********************************************************************
 
  125 // ResetStackAndState
 
  127 // Resets stack and minimum of navigator state `machine'
 
  128 // ********************************************************************
 
  131 void G4ITNavigator::ResetStackAndState()
 
  137 // ********************************************************************
 
  139 // ********************************************************************
 
  142 EVolume G4ITNavigator::VolumeType(const G4VPhysicalVolume *pVol) const
 
  147   G4double width,offset;
 
  149   if ( pVol->IsReplicated() )
 
  151     pVol->GetReplicationData(axis,nReplicas,width,offset,consuming);
 
  152     type = (consuming) ? kReplica : kParameterised;
 
  161 // ********************************************************************
 
  162 // CharacteriseDaughters
 
  163 // ********************************************************************
 
  166 EVolume G4ITNavigator::CharacteriseDaughters(const G4LogicalVolume *pLog) const
 
  171   G4double width,offset;
 
  173   G4VPhysicalVolume *pVol;
 
  175   if ( pLog->GetNoDaughters()==1 )
 
  177     pVol = pLog->GetDaughter(0);
 
  178     if (pVol->IsReplicated())
 
  180       pVol->GetReplicationData(axis,nReplicas,width,offset,consuming);
 
  181       type = (consuming) ? kReplica : kParameterised;
 
  195 // ********************************************************************
 
  196 // GetDaughtersRegularStructureId
 
  197 // ********************************************************************
 
  200 G4int G4ITNavigator::
 
  201 GetDaughtersRegularStructureId(const G4LogicalVolume *pLog) const
 
  204   G4VPhysicalVolume *pVol;
 
  206   if ( pLog->GetNoDaughters()==1 )
 
  208     pVol = pLog->GetDaughter(0);
 
  209     regId = pVol->GetRegularStructureId();
 
  214 // ********************************************************************
 
  215 // GetGlobalToLocalTransform
 
  217 // Returns local to global transformation.
 
  218 // I.e. transformation that will take point or axis in world coord system
 
  219 // and return one in the local coord system
 
  220 // ********************************************************************
 
  223 const G4AffineTransform& G4ITNavigator::GetGlobalToLocalTransform() const
 
  225   return fHistory.GetTopTransform();
 
  228 // ********************************************************************
 
  229 // GetLocalToGlobalTransform
 
  231 // Returns global to local transformation 
 
  232 // ********************************************************************
 
  235 const G4AffineTransform G4ITNavigator::GetLocalToGlobalTransform() const
 
  237   G4AffineTransform  tempTransform;
 
  238   tempTransform = fHistory.GetTopTransform().Inverse(); 
 
  239   return tempTransform;
 
  242 // ********************************************************************
 
  245 // Computes+returns the local->global translation of current volume
 
  246 // ********************************************************************
 
  249 G4ThreeVector G4ITNavigator::NetTranslation() const
 
  251   G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
 
  252   return tf.NetTranslation();
 
  255 // ********************************************************************
 
  258 // Computes+returns the local->global rotation of current volume
 
  259 // ********************************************************************
 
  262 G4RotationMatrix G4ITNavigator::NetRotation() const
 
  264   G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
 
  265   return tf.NetRotation();
 
  268 // ********************************************************************
 
  271 // `Touchable' creation method: caller has deletion responsibility
 
  272 // ********************************************************************
 
  275 G4GRSVolume* G4ITNavigator::CreateGRSVolume() const
 
  277   G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
 
  278   return new G4GRSVolume(fHistory.GetTopVolume(),
 
  280                          tf.NetTranslation());
 
  283 // ********************************************************************
 
  286 // `Touchable' creation method: caller has deletion responsibility
 
  287 // ********************************************************************
 
  290 G4GRSSolid* G4ITNavigator::CreateGRSSolid() const
 
  292   G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
 
  293   return new G4GRSSolid(fHistory.GetTopVolume()->GetLogicalVolume()->GetSolid(),
 
  295                         tf.NetTranslation());
 
  298 // ********************************************************************
 
  299 // CreateTouchableHistory
 
  301 // `Touchable' creation method: caller has deletion responsibility
 
  302 // ********************************************************************
 
  305 G4TouchableHistory* G4ITNavigator::CreateTouchableHistory() const
 
  307   return new G4TouchableHistory(fHistory);
 
  310 // ********************************************************************
 
  311 // CreateTouchableHistory(history)
 
  313 // `Touchable' creation method: caller has deletion responsibility
 
  314 // ********************************************************************
 
  318 G4ITNavigator::CreateTouchableHistory(const G4NavigationHistory* history) const
 
  320   return new G4TouchableHistory(*history);
 
  323 // ********************************************************************
 
  324 // LocateGlobalPointAndUpdateTouchableHandle
 
  325 // ********************************************************************
 
  328 void G4ITNavigator::LocateGlobalPointAndUpdateTouchableHandle(
 
  329                                const G4ThreeVector&       position,
 
  330                                const G4ThreeVector&       direction,
 
  331                                      G4TouchableHandle&   oldTouchableToUpdate,
 
  332                                const G4bool               RelativeSearch )
 
  334   G4VPhysicalVolume* pPhysVol;
 
  335   pPhysVol = LocateGlobalPointAndSetup( position,&direction,RelativeSearch );
 
  336   if( fEnteredDaughter || fExitedMother )
 
  338      oldTouchableToUpdate = CreateTouchableHistory();
 
  341        // We want to ensure that the touchable is correct in this case.
 
  342        //  The method below should do this and recalculate a lot more ....
 
  344        oldTouchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
 
  350 // ********************************************************************
 
  351 // LocateGlobalPointAndUpdateTouchable
 
  354 // ********************************************************************
 
  357 void G4ITNavigator::LocateGlobalPointAndUpdateTouchable(
 
  358                            const G4ThreeVector&       position,
 
  359                            const G4ThreeVector&       direction,
 
  360                                  G4VTouchable*        touchableToUpdate,
 
  361                            const G4bool               RelativeSearch  )
 
  363   G4VPhysicalVolume* pPhysVol;
 
  364   pPhysVol = LocateGlobalPointAndSetup( position, &direction, RelativeSearch);  
 
  365   touchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
 
  368 // ********************************************************************
 
  369 // LocateGlobalPointAndUpdateTouchable
 
  370 // ********************************************************************
 
  373 void G4ITNavigator::LocateGlobalPointAndUpdateTouchable(
 
  374                            const G4ThreeVector&       position,
 
  375                                  G4VTouchable*        touchableToUpdate,
 
  376                            const G4bool               RelativeSearch )
 
  378   G4VPhysicalVolume* pPhysVol;
 
  379   pPhysVol = LocateGlobalPointAndSetup( position, 0, RelativeSearch);  
 
  380   touchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
 
  383 // ********************************************************************
 
  385 // ********************************************************************
 
  388 G4int G4ITNavigator::GetVerboseLevel() const
 
  393 // ********************************************************************
 
  395 // ********************************************************************
 
  398 void G4ITNavigator::SetVerboseLevel(G4int level)
 
  401   fnormalNav.SetVerboseLevel(level);
 
  402   fvoxelNav.SetVerboseLevel(level);
 
  403   fparamNav.SetVerboseLevel(level);
 
  404   freplicaNav.SetVerboseLevel(level);
 
  405   fregularNav.SetVerboseLevel(level);
 
  408 // ********************************************************************
 
  410 // ********************************************************************
 
  413 G4bool G4ITNavigator::IsActive() const
 
  418 // ********************************************************************
 
  420 // ********************************************************************
 
  423 void G4ITNavigator::Activate(G4bool flag)
 
  428 // ********************************************************************
 
  429 // EnteredDaughterVolume
 
  431 // To inform the caller if the track is entering a daughter volume
 
  432 // ********************************************************************
 
  435 G4bool G4ITNavigator::EnteredDaughterVolume() const
 
  437   return fEnteredDaughter;
 
  440 // ********************************************************************
 
  441 // ExitedMotherVolume
 
  442 // ********************************************************************
 
  445 G4bool G4ITNavigator::ExitedMotherVolume() const
 
  447   return fExitedMother;
 
  450 // ********************************************************************
 
  452 // ********************************************************************
 
  455 void  G4ITNavigator::CheckMode(G4bool mode)
 
  458   fnormalNav.CheckMode(mode);
 
  459   fvoxelNav.CheckMode(mode);
 
  460   fparamNav.CheckMode(mode);
 
  461   freplicaNav.CheckMode(mode);
 
  462   fregularNav.CheckMode(mode);
 
  465 // ********************************************************************
 
  467 // ********************************************************************
 
  470 G4bool G4ITNavigator::IsCheckModeActive() const
 
  475 // ********************************************************************
 
  477 // ********************************************************************
 
  480 void G4ITNavigator::SetPushVerbosity(G4bool mode)
 
  485 // ********************************************************************
 
  486 // SeverityOfZeroStepping
 
  488 // Reports on severity of error in case Navigator is stuck
 
  489 // and is returning zero steps
 
  490 // ********************************************************************
 
  493 G4int G4ITNavigator::SeverityOfZeroStepping( G4int* noZeroSteps ) const
 
  495   G4int severity=0, noZeros= fNumberZeroSteps;
 
  496   if( noZeroSteps) *noZeroSteps = 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 // ********************************************************************
 
  526 inline void G4ITNavigator::EnableBestSafety( G4bool value )
 
  528   fvoxelNav.EnableBestSafety( value );