Import Geant4 9.0.0 source tree
This commit is contained in:
@@ -23,131 +23,141 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4SafetyHelper.cc,v 1.7 2006/11/14 10:22:12 japost Exp $
|
||||
// $Id: G4SafetyHelper.cc,v 1.12 2007/05/09 12:57:31 japost Exp $
|
||||
// GEANT4 tag $ Name: $
|
||||
|
||||
//
|
||||
// class G4SafetyHelper Implementation
|
||||
//
|
||||
// Original author: John Apostolakis, 2006
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4SafetyHelper.hh"
|
||||
#include "G4PathFinder.hh"
|
||||
#include "G4TransportationManager.hh"
|
||||
#include "G4Navigator.hh"
|
||||
|
||||
// #include "G4Exception.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
G4bool G4SafetyHelper::fUseParallelGeometries= false;
|
||||
// By default, one geometry only
|
||||
|
||||
G4SafetyHelper::G4SafetyHelper()
|
||||
G4SafetyHelper::G4SafetyHelper() :
|
||||
fUseParallelGeometries(false), // By default, one geometry only
|
||||
fFirstCall(true),
|
||||
fLastSafetyPosition(0.0,0.0,0.0),
|
||||
fLastSafety(0.0),
|
||||
fRecomputeFactor(0.2)
|
||||
{
|
||||
fpPathFinder= G4PathFinder::GetInstance();
|
||||
|
||||
InitialiseNavigator();
|
||||
fpPathFinder= 0; // Cannot initialise this yet - a loop results
|
||||
|
||||
// Initialization of the Navigator pointer is postponed, and must
|
||||
// be undertaken by another class calling InitialiseHelper()
|
||||
fpMassNavigator= 0;
|
||||
fMassNavigatorId= -1;
|
||||
}
|
||||
|
||||
void G4SafetyHelper::InitialiseNavigator()
|
||||
{
|
||||
// G4Navigator*
|
||||
static G4TransportationManager* pTransportMgr=
|
||||
G4TransportationManager::GetTransportationManager();
|
||||
fpPathFinder= G4PathFinder::GetInstance();
|
||||
|
||||
G4TransportationManager* pTransportMgr=
|
||||
G4TransportationManager::GetTransportationManager();
|
||||
|
||||
fpMassNavigator = pTransportMgr->GetNavigatorForTracking();
|
||||
fpMassNavigator = pTransportMgr->GetNavigatorForTracking();
|
||||
|
||||
fMassNavigatorId = pTransportMgr->ActivateNavigator( fpMassNavigator );
|
||||
}
|
||||
// Check
|
||||
G4VPhysicalVolume* worldPV = fpMassNavigator->GetWorldVolume();
|
||||
if( worldPV == 0 )
|
||||
{
|
||||
G4Exception("G4SafetyHelper::InitialiseNavigator",
|
||||
"InvalidNavigatorWorld", FatalException,
|
||||
"Found that existing tracking Navigator has NULL world");
|
||||
}
|
||||
|
||||
fMassNavigatorId = pTransportMgr->ActivateNavigator( fpMassNavigator );
|
||||
}
|
||||
|
||||
void G4SafetyHelper::InitialiseHelper()
|
||||
{
|
||||
fLastSafetyPosition = G4ThreeVector(0.0,0.0,0.0);
|
||||
fLastSafety = 0.0;
|
||||
if (fFirstCall) { InitialiseNavigator(); }
|
||||
fFirstCall = false;
|
||||
}
|
||||
|
||||
G4SafetyHelper::~G4SafetyHelper()
|
||||
{}
|
||||
|
||||
G4double
|
||||
G4SafetyHelper::ComputeMassStep( const G4ThreeVector &position,
|
||||
const G4ThreeVector &direction,
|
||||
G4double &newSafety )
|
||||
{
|
||||
// Step for mass geometry
|
||||
G4double linearStep;
|
||||
const G4double proposedStep = DBL_MAX;
|
||||
G4SafetyHelper::CheckNextStep(const G4ThreeVector &position,
|
||||
const G4ThreeVector &direction,
|
||||
const G4double currentMaxStep,
|
||||
G4double& newSafety )
|
||||
{
|
||||
// Distance in the Mass geometry
|
||||
//
|
||||
G4double linstep = fpMassNavigator->CheckNextStep( position,
|
||||
direction,
|
||||
currentMaxStep,
|
||||
newSafety);
|
||||
fLastSafetyPosition = position;
|
||||
fLastSafety = newSafety;
|
||||
|
||||
// Check
|
||||
G4VPhysicalVolume* worldPV= fpMassNavigator->GetWorldVolume();
|
||||
if( worldPV == 0 ) {
|
||||
G4Exception("G4SafetyHelper::ComputeMassStep",
|
||||
"InvalidNavigatorWorld",
|
||||
FatalException,
|
||||
"Found that existing mass Navigator has null world");
|
||||
// TO-DO: Can replace this with a call to PathFinder
|
||||
// giving id of Mass Geometry --> this avoid doing the work twice
|
||||
return linstep;
|
||||
}
|
||||
|
||||
G4double G4SafetyHelper::ComputeSafety( const G4ThreeVector& position )
|
||||
{
|
||||
G4double newSafety;
|
||||
|
||||
// return last value if position is not significantly changed
|
||||
//
|
||||
G4double moveLen = (position-fLastSafetyPosition).mag();
|
||||
if(moveLen >= fRecomputeFactor*fLastSafety)
|
||||
{
|
||||
fLastSafetyPosition = position;
|
||||
|
||||
if( !fUseParallelGeometries )
|
||||
{
|
||||
// Safety for mass geometry
|
||||
fLastSafety = fpMassNavigator->ComputeSafety(position);
|
||||
}
|
||||
|
||||
fpMassNavigator->LocateGlobalPointWithinVolume(position);
|
||||
// Potentially dangerous to relocate the point.
|
||||
// Safe in PostStepDoIt -- and possibly in AlongStepGPIL
|
||||
|
||||
G4cout << "G4SafetyHelper::ComputeMassStep "
|
||||
<< " trial step size = " << proposedStep << " ." << G4endl;
|
||||
|
||||
// Distance in the Mass geometry
|
||||
linearStep = fpMassNavigator->ComputeStep( position,
|
||||
direction,
|
||||
proposedStep,
|
||||
newSafety);
|
||||
|
||||
fpMassNavigator->LocateGlobalPointWithinVolume(position);
|
||||
G4cout << "G4UrbanMscModel relocates mass Navigator back to "
|
||||
<< position << G4endl;
|
||||
|
||||
// TO-DO: Can replace this with a call to PathFinder
|
||||
// giving id of Mass Geometry --> this avoid doing the work twice
|
||||
|
||||
return linearStep;
|
||||
else
|
||||
{
|
||||
// Safety for all geometries
|
||||
fLastSafety = fpPathFinder->ComputeSafety( position );
|
||||
}
|
||||
newSafety = fLastSafety;
|
||||
}
|
||||
else
|
||||
{
|
||||
newSafety = fLastSafety-moveLen;
|
||||
}
|
||||
return newSafety;
|
||||
}
|
||||
|
||||
G4double G4SafetyHelper::ComputeSafety( const G4ThreeVector& position )
|
||||
void G4SafetyHelper::ReLocateWithinVolume( const G4ThreeVector &newPosition )
|
||||
{
|
||||
// Safety for all geometries
|
||||
G4double newsafety= 0.0;
|
||||
|
||||
if( !fUseParallelGeometries) {
|
||||
// Old code: safety for mass geometry
|
||||
fpMassNavigator->LocateGlobalPointWithinVolume(position);
|
||||
newsafety = fpMassNavigator->ComputeSafety(position);
|
||||
}else{
|
||||
|
||||
// fpPathFinder->ReLocate( position ); // Safe in PostStepDoIt only ??
|
||||
newsafety= fpPathFinder->ComputeSafety( position );
|
||||
|
||||
#ifdef CHECK_WITH_ONE_GEOM
|
||||
// Check against mass safety
|
||||
fpMassNavigator->LocateGlobalPointWithinVolume(position);
|
||||
G4double mass_safety = fpMassNavigator->ComputeSafety(position);
|
||||
|
||||
// For initial tests check assume that mass is only geometry
|
||||
if( (mass_safety - newsafety) > 1e-4 * newsafety ){
|
||||
G4cerr << " ERROR in G4SafetyHelper " << G4endl
|
||||
<< " Safety from PathFinder is " << newsafety << " "
|
||||
<< " not equal to " << mass_safety << " " << G4endl;
|
||||
G4Exception("G4SafetyHelper::ComputeSafety", "SafetyError",
|
||||
FatalException,
|
||||
"Incompatible safeties between navigator and pathfinder" );
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return newsafety;
|
||||
if( !fUseParallelGeometries )
|
||||
{
|
||||
fpMassNavigator->LocateGlobalPointWithinVolume( newPosition );
|
||||
}
|
||||
else
|
||||
{
|
||||
fpPathFinder->ReLocate( newPosition );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void G4SafetyHelper::ReLocateWithinVolume( const G4ThreeVector &newPosition )
|
||||
void G4SafetyHelper::Locate( const G4ThreeVector& newPosition,
|
||||
const G4ThreeVector& newDirection)
|
||||
{
|
||||
|
||||
#ifdef G4VERBOSE_HELPER
|
||||
G4int oldPrec= G4cout.precision( 10 );
|
||||
G4cout << " G4SafetyHelper::ReLocateWithinVolume "
|
||||
<< " calling PathFinder->ReLocating at position " << newPosition << G4endl;
|
||||
G4cout.precision( oldPrec );
|
||||
#endif
|
||||
|
||||
if( !fUseParallelGeometries) {
|
||||
fpMassNavigator->LocateGlobalPointWithinVolume( newPosition );
|
||||
}else{
|
||||
fpPathFinder->ReLocate( newPosition );
|
||||
}
|
||||
if( !fUseParallelGeometries)
|
||||
{
|
||||
fpMassNavigator->LocateGlobalPointAndSetup(newPosition, &newDirection,
|
||||
true, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
fpPathFinder->Locate( newPosition, newDirection );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user