Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:33

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 //
0028 // class G4ITNavigator2 Inline implementation
0029 // 
0030 // G4ITNavigator2 is a duplicate version of G4Navigator started from Geant4.9.5
0031 // initially written by Paul Kent and colleagues.
0032 // The only difference resides in the way the information is saved and managed
0033 //
0034 // ********************************************************************
0035 
0036 // ********************************************************************
0037 // GetCurrentLocalCoordinate
0038 //
0039 // Returns the local coordinate of the current track
0040 // ********************************************************************
0041 //
0042 inline
0043 G4ThreeVector G4ITNavigator2::GetCurrentLocalCoordinate() const
0044 {
0045     CheckNavigatorStateIsValid();
0046   return fpNavigatorState->fLastLocatedPointLocal;
0047 }
0048 
0049 // ********************************************************************
0050 // ComputeLocalAxis
0051 //
0052 // Returns local direction of vector direction in world coord system
0053 // ********************************************************************
0054 //
0055 inline
0056 G4ThreeVector G4ITNavigator2::ComputeLocalAxis(const G4ThreeVector& pVec) const
0057 {
0058     CheckNavigatorStateIsValid();
0059   return (fpNavigatorState->fHistory.GetTopTransform().IsRotated())
0060          ? fpNavigatorState->fHistory.GetTopTransform().TransformAxis(pVec) : pVec ;
0061 }
0062 
0063 // ********************************************************************
0064 // ComputeLocalPoint
0065 //
0066 // Returns local coordinates of a point in the world coord system
0067 // ********************************************************************
0068 //
0069 inline
0070 G4ThreeVector
0071 G4ITNavigator2::ComputeLocalPoint(const G4ThreeVector& pGlobalPoint) const
0072 {
0073     CheckNavigatorStateIsValid();
0074     return ( fpNavigatorState->fHistory.GetTopTransform().TransformPoint(pGlobalPoint) ) ;
0075 }
0076 
0077 // ********************************************************************
0078 // GetWorldVolume
0079 //
0080 // Returns the current  world (`topmost') volume
0081 // ********************************************************************
0082 //
0083 inline
0084 G4VPhysicalVolume* G4ITNavigator2::GetWorldVolume() const
0085 {
0086   return fTopPhysical;
0087 }
0088 
0089 // ********************************************************************
0090 // SetWorldVolume
0091 //
0092 // Sets the world (`topmost') volume
0093 // ********************************************************************
0094 //
0095 inline
0096 void G4ITNavigator2::SetWorldVolume(G4VPhysicalVolume* pWorld)
0097 {
0098   if ( !(pWorld->GetTranslation()==G4ThreeVector(0,0,0)) )
0099   {
0100     G4Exception ("G4ITNavigator2::SetWorldVolume()", "GeomNav0002",
0101                  FatalException, "Volume must be centered on the origin.");
0102   }
0103   const G4RotationMatrix* rm = pWorld->GetRotation();
0104   if ( (rm != nullptr) && (!rm->isIdentity()) )
0105   {
0106     G4Exception ("G4ITNavigator2::SetWorldVolume()", "GeomNav0002",
0107                  FatalException, "Volume must not be rotated.");
0108   }
0109   fTopPhysical = pWorld;
0110   if(fpNavigatorState != nullptr)
0111       fpNavigatorState->fHistory.SetFirstEntry(pWorld);
0112 }
0113 
0114 // ********************************************************************
0115 // SetGeometrycallyLimitedStep
0116 //
0117 // Informs the navigator that the previous Step calculated
0118 // by the geometry was taken in its entirety
0119 // ********************************************************************
0120 //
0121 inline
0122 void G4ITNavigator2::SetGeometricallyLimitedStep()
0123 {
0124     fpNavigatorState->fWasLimitedByGeometry=true;
0125 }
0126 
0127 // ********************************************************************
0128 // ResetStackAndState
0129 //
0130 // Resets stack and minimum of navigator state `machine'
0131 // ********************************************************************
0132 //
0133 inline
0134 void G4ITNavigator2::ResetStackAndState()
0135 {
0136   fpNavigatorState->fHistory.Reset();
0137   ResetState();
0138 }
0139 
0140 // ********************************************************************
0141 // VolumeType
0142 // ********************************************************************
0143 //
0144 inline
0145 EVolume G4ITNavigator2::VolumeType(const G4VPhysicalVolume *pVol) const
0146 {
0147   return pVol->VolumeType();
0148 }
0149 
0150 // ********************************************************************
0151 // CharacteriseDaughters
0152 // ********************************************************************
0153 //
0154 inline
0155 EVolume G4ITNavigator2::CharacteriseDaughters(const G4LogicalVolume *pLog) const
0156 {
0157   return pLog->CharacteriseDaughters();
0158 }
0159 
0160 inline std::shared_ptr<G4ITNavigatorState_Lock2> G4ITNavigator2::GetSnapshotOfState()
0161 {
0162   if(fpNavigatorState != nullptr)
0163   {
0164     std::shared_ptr<G4ITNavigatorState_Lock2>
0165       snapShot(new G4NavigatorState(*fpNavigatorState));
0166    return snapShot;
0167   }
0168   
0169   return std::shared_ptr<G4ITNavigatorState_Lock2>(nullptr);
0170 }
0171 
0172 inline void G4ITNavigator2::ResetFromSnapshot(std::shared_ptr<G4ITNavigatorState_Lock2> snapShot)
0173 {
0174   if((fpNavigatorState != nullptr) && snapShot)
0175   {
0176     *fpNavigatorState = *((G4NavigatorState*) snapShot.get());
0177   }
0178 }
0179 
0180 // ********************************************************************
0181 // GetDaughtersRegularStructureId
0182 // ********************************************************************
0183 //
0184 inline
0185 G4int G4ITNavigator2::
0186 GetDaughtersRegularStructureId(const G4LogicalVolume *pLog) const
0187 {
0188   G4int regId = 0;
0189   G4VPhysicalVolume *pVol;
0190 
0191   if ( pLog->GetNoDaughters()==1 )
0192   {
0193     pVol = pLog->GetDaughter(0);
0194     regId = pVol->GetRegularStructureId();
0195   }
0196   return regId;
0197 }
0198 
0199 // ********************************************************************
0200 // GetGlobalToLocalTransform
0201 //
0202 // Returns local to global transformation.
0203 // I.e. transformation that will take point or axis in world coord system
0204 // and return one in the local coord system
0205 // ********************************************************************
0206 //
0207 inline
0208 const G4AffineTransform& G4ITNavigator2::GetGlobalToLocalTransform() const
0209 {
0210     CheckNavigatorStateIsValid();
0211     return fpNavigatorState->fHistory.GetTopTransform();
0212 }
0213 
0214 // ********************************************************************
0215 // GetLocalToGlobalTransform
0216 //
0217 // Returns global to local transformation 
0218 // ********************************************************************
0219 //
0220 inline
0221 const G4AffineTransform G4ITNavigator2::GetLocalToGlobalTransform() const
0222 {
0223     CheckNavigatorStateIsValid();
0224     G4AffineTransform  tempTransform;
0225     tempTransform = fpNavigatorState->fHistory.GetTopTransform().Inverse();
0226     return tempTransform;
0227 }
0228 
0229 // ********************************************************************
0230 // NetTranslation
0231 //
0232 // Computes+returns the local->global translation of current volume
0233 // ********************************************************************
0234 //
0235 inline
0236 G4ThreeVector G4ITNavigator2::NetTranslation() const
0237 {
0238     CheckNavigatorStateIsValid();
0239     G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
0240     return tf.NetTranslation();
0241 }
0242 
0243 // ********************************************************************
0244 // NetRotation
0245 //
0246 // Computes+returns the local->global rotation of current volume
0247 // ********************************************************************
0248 //
0249 inline
0250 G4RotationMatrix G4ITNavigator2::NetRotation() const
0251 {
0252     CheckNavigatorStateIsValid();
0253     G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
0254     return tf.NetRotation();
0255 }
0256 
0257 // ********************************************************************
0258 // CreateTouchableHistory
0259 //
0260 // `Touchable' creation method: caller has deletion responsibility
0261 // ********************************************************************
0262 //
0263 inline
0264 G4TouchableHistory* G4ITNavigator2::CreateTouchableHistory() const
0265 {
0266     CheckNavigatorStateIsValid();
0267     return new G4TouchableHistory(fpNavigatorState->fHistory);
0268 }
0269 
0270 // ********************************************************************
0271 // CreateTouchableHistory(history)
0272 //
0273 // `Touchable' creation method: caller has deletion responsibility
0274 // ********************************************************************
0275 //
0276 inline
0277 G4TouchableHistory*
0278 G4ITNavigator2::CreateTouchableHistory(const G4NavigationHistory* history) const
0279 {
0280   return new G4TouchableHistory(*history);
0281 }
0282 
0283 // ********************************************************************
0284 // LocateGlobalPointAndUpdateTouchableHandle
0285 // ********************************************************************
0286 //
0287 inline
0288 void G4ITNavigator2::LocateGlobalPointAndUpdateTouchableHandle(
0289                                const G4ThreeVector&       position,
0290                                const G4ThreeVector&       direction,
0291                                      G4TouchableHandle&   oldTouchableToUpdate,
0292                                const G4bool               RelativeSearch )
0293 {
0294   G4VPhysicalVolume* pPhysVol;
0295   pPhysVol = LocateGlobalPointAndSetup( position,&direction,RelativeSearch );
0296   // Will check navigatorState validity
0297   if( fpNavigatorState->fEnteredDaughter || fpNavigatorState->fExitedMother )
0298   {
0299      oldTouchableToUpdate = CreateTouchableHistory();
0300      if( pPhysVol == nullptr )
0301      {
0302        // We want to ensure that the touchable is correct in this case.
0303        //  The method below should do this and recalculate a lot more ....
0304        //
0305        oldTouchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory );
0306      }
0307   }
0308   return;
0309 }
0310 
0311 // ********************************************************************
0312 // LocateGlobalPointAndUpdateTouchable
0313 //
0314 // Use direction
0315 // ********************************************************************
0316 //
0317 inline
0318 void G4ITNavigator2::LocateGlobalPointAndUpdateTouchable(
0319                            const G4ThreeVector&       position,
0320                            const G4ThreeVector&       direction,
0321                                  G4VTouchable*        touchableToUpdate,
0322                            const G4bool               RelativeSearch  )
0323 {
0324   G4VPhysicalVolume* pPhysVol;
0325   pPhysVol = LocateGlobalPointAndSetup( position, &direction, RelativeSearch);  
0326   // Will check navigatorState validity
0327   touchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory );
0328 }
0329 
0330 // ********************************************************************
0331 // LocateGlobalPointAndUpdateTouchable
0332 // ********************************************************************
0333 //
0334 inline
0335 void G4ITNavigator2::LocateGlobalPointAndUpdateTouchable(
0336                            const G4ThreeVector&       position,
0337                                  G4VTouchable*        touchableToUpdate,
0338                            const G4bool               RelativeSearch )
0339 {
0340   G4VPhysicalVolume* pPhysVol;
0341   pPhysVol = LocateGlobalPointAndSetup( position, nullptr, RelativeSearch);  
0342   // Will check navigatorState validity
0343   touchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory );
0344 }
0345 
0346 // ********************************************************************
0347 // GetVerboseLevel
0348 // ********************************************************************
0349 //
0350 inline
0351 G4int G4ITNavigator2::GetVerboseLevel() const
0352 {
0353   return fVerbose;
0354 }
0355 
0356 // ********************************************************************
0357 // SetVerboseLevel
0358 // ********************************************************************
0359 //
0360 inline
0361 void G4ITNavigator2::SetVerboseLevel(G4int level)
0362 {
0363   fVerbose = level;
0364   fnormalNav.SetVerboseLevel(level);
0365   fvoxelNav.SetVerboseLevel(level);
0366   fparamNav.SetVerboseLevel(level);
0367   freplicaNav.SetVerboseLevel(level);
0368   fregularNav.SetVerboseLevel(level);
0369 }
0370 
0371 // ********************************************************************
0372 // IsActive
0373 // ********************************************************************
0374 //
0375 inline
0376 G4bool G4ITNavigator2::IsActive() const
0377 {
0378   return fActive;
0379 }
0380 
0381 // ********************************************************************
0382 // Activate
0383 // ********************************************************************
0384 //
0385 inline
0386 void G4ITNavigator2::Activate(G4bool flag)
0387 {
0388   fActive = flag;
0389 }
0390 
0391 // ********************************************************************
0392 // EnteredDaughterVolume
0393 //
0394 // To inform the caller if the track is entering a daughter volume
0395 // ********************************************************************
0396 //
0397 inline
0398 G4bool G4ITNavigator2::EnteredDaughterVolume() const
0399 {
0400     CheckNavigatorStateIsValid();
0401     return fpNavigatorState->fEnteredDaughter;
0402 }
0403 
0404 // ********************************************************************
0405 // ExitedMotherVolume
0406 // ********************************************************************
0407 //
0408 inline
0409 G4bool G4ITNavigator2::ExitedMotherVolume() const
0410 {
0411     CheckNavigatorStateIsValid();
0412     return fpNavigatorState->fExitedMother;
0413 }
0414 
0415 // ********************************************************************
0416 // CheckMode
0417 // ********************************************************************
0418 //
0419 inline
0420 void  G4ITNavigator2::CheckMode(G4bool mode)
0421 {
0422   fCheck = mode;
0423   fnormalNav.CheckMode(mode);
0424   fvoxelNav.CheckMode(mode);
0425   fparamNav.CheckMode(mode);
0426   freplicaNav.CheckMode(mode);
0427   fregularNav.CheckMode(mode);
0428 }
0429 
0430 // ********************************************************************
0431 // IsCheckModeActive
0432 // ********************************************************************
0433 //
0434 inline
0435 G4bool G4ITNavigator2::IsCheckModeActive() const
0436 {
0437   return fCheck;
0438 }
0439 
0440 // ********************************************************************
0441 // SetPushVerbosity
0442 // ********************************************************************
0443 //
0444 inline
0445 void G4ITNavigator2::SetPushVerbosity(G4bool mode)
0446 {
0447   fWarnPush = mode;
0448 }
0449 
0450 // ********************************************************************
0451 // SeverityOfZeroStepping
0452 //
0453 // Reports on severity of error in case Navigator is stuck
0454 // and is returning zero steps
0455 // ********************************************************************
0456 //
0457 inline 
0458 G4int G4ITNavigator2::SeverityOfZeroStepping( G4int* noZeroSteps ) const
0459 {
0460     CheckNavigatorStateIsValid();
0461     G4int severity=0, noZeros= fpNavigatorState->fNumberZeroSteps;
0462     if( noZeroSteps != nullptr) *noZeroSteps = fpNavigatorState->fNumberZeroSteps;
0463 
0464   if( noZeros >= fAbandonThreshold_NoZeroSteps )
0465   {
0466     severity = 10;
0467   }
0468   if( noZeros > 0 && noZeros < fActionThreshold_NoZeroSteps )
0469   {
0470     severity =  5 * noZeros / fActionThreshold_NoZeroSteps;
0471   }
0472   else if( noZeros == fActionThreshold_NoZeroSteps )
0473   {
0474     severity =  5; 
0475   }
0476   else if( noZeros >= fAbandonThreshold_NoZeroSteps - 2 )
0477   {
0478     severity =  9; 
0479   }
0480   else if( noZeros < fAbandonThreshold_NoZeroSteps - 2 )
0481   {
0482     severity =  5 + 4 * (noZeros-fAbandonThreshold_NoZeroSteps)
0483                       / fActionThreshold_NoZeroSteps;
0484   }
0485   return severity;
0486 }
0487 
0488 // ********************************************************************
0489 // EnableBestSafety
0490 // ********************************************************************
0491 //
0492 inline void G4ITNavigator2::EnableBestSafety( G4bool value )
0493 {
0494   fvoxelNav.EnableBestSafety( value );
0495 }