Import Geant4 0.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-01 15:25:35 +02:00
parent 54d6b71f95
commit b97f8d0df7
3237 changed files with 807095 additions and 0 deletions
@@ -0,0 +1,10 @@
#include "G4AuxiliaryNavServices.hh"
#include "globals.hh"
// This method currently exists only to allow compilers to find
// the inline method (which are the core of this class)
G4bool G4AuxiliaryNavServices::testOne()
{
return true;
}
@@ -0,0 +1,27 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4BlockingList.cc,v 2.1 1998/07/12 02:58:25 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// class G4BlockingList Implementation
//
#include "G4BlockingList.hh"
// Clear List and reset tag
// Fix: Out of line for HP-CC
void G4BlockingList::FullyReset()
{
fBlockTagNo=1;
for (G4int i=fBlockingList.length()-1;i>=0;i--)
{
fBlockingList(i)=0;
}
}
+19
View File
@@ -0,0 +1,19 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4GRSSolid.cc,v 2.0 1998/07/02 17:06:27 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// class G4GRSSolid Implementation
#include "G4GRSSolid.hh"
G4GRSSolid::~G4GRSSolid()
{
delete frot; // safe if null
}
@@ -0,0 +1,19 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4GRSVolume.cc,v 2.0 1998/07/02 17:06:28 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// class G4GRSVolume Implementation
#include "G4GRSVolume.hh"
G4GRSVolume::~G4GRSVolume()
{
delete frot; // safe if null
}
@@ -0,0 +1,112 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4LogicalBorderSurface.cc,v 2.1 1998/07/13 16:55:04 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
////////////////////////////////////////////////////////////////////////
// G4LogicalBorderSurface Implementation
////////////////////////////////////////////////////////////////////////
//
// File: G4LogicalBorderSurface.cc
// Description: A Logical Surface class for surfaces defined by the
// boundary of two physical volumes.
// Version: 1.0
// Created: 1997-06-26
// Author: John Apostolakis
// mail: John.Apostolakis@cern.ch
// Modified: 1997-06-26 John Apostolakis
//
// Id tag:
////////////////////////////////////////////////////////////////////////
#include "G4LogicalBorderSurface.hh"
G4LogicalBorderSurfaceTable G4LogicalBorderSurface::theBorderSurfaceTable;
/////////////////////////
// Class Implementation
/////////////////////////
/////////////////
// Constructors
/////////////////
G4LogicalBorderSurface::G4LogicalBorderSurface(const G4String& name,
G4VPhysicalVolume* vol1,
G4VPhysicalVolume* vol2,
G4OpticalSurface* opticsSurface)
: G4LogicalSurface(name, opticsSurface),
Volume1(vol1),
Volume2(vol2)
{
// Store in the table of Surfaces
theBorderSurfaceTable.insert(this);
theIndexInTable = theBorderSurfaceTable.index(this);
}
G4LogicalBorderSurface::G4LogicalBorderSurface(const G4LogicalBorderSurface &right)
: G4LogicalSurface(right.GetName(), right.GetOpticalSurface())
{
*this = right;
}
G4LogicalBorderSurface::~G4LogicalBorderSurface(){}
//////////////
// Operators
//////////////
const G4LogicalBorderSurface& G4LogicalBorderSurface::operator=(const G4LogicalBorderSurface &right)
{
return right;
}
G4int G4LogicalBorderSurface::operator==(const G4LogicalBorderSurface &right) const
{
return (this == (G4LogicalBorderSurface *) &right);
}
G4int G4LogicalBorderSurface::operator!=(const G4LogicalBorderSurface &right) const
{
return (this != (G4LogicalBorderSurface *) &right);
}
////////////
// Methods
////////////
G4LogicalBorderSurface* G4LogicalBorderSurface::GetSurface(const G4VPhysicalVolume* vol1,
const G4VPhysicalVolume* vol2)
{
for (int i=0; i<theBorderSurfaceTable.length(); i++) {
if(theBorderSurfaceTable[i]->GetVolume1() == vol1 &&
theBorderSurfaceTable[i]->GetVolume2() == vol2 )
return theBorderSurfaceTable[i];
}
return NULL;
}
void G4LogicalBorderSurface::DumpInfo() // Class method (it is really const)
{
// Dump info for known surfaces
G4cout << "***** Surface Table : Nb of Surfaces = " <<
GetNumberOfBorderSurfaces() << " *****" << endl;
for (int i=0; i<theBorderSurfaceTable.length(); i++) {
G4cout << theBorderSurfaceTable[i]->GetName() << " : " << endl <<
" Surface type = " << theBorderSurfaceTable[i]->GetName() << endl;
#ifdef PRINT_INFO
" Surface type = " << theBorderSurfaceTable[i]->GetOpticalSurface()->GetType() << endl;
" Surface finish = " << theBorderSurfaceTable[i]->GetFinish() << endl <<
" Surface model = " << theBorderSurfaceTable[i]->GetModel() << endl;
#endif
}
G4cout << endl;
}
@@ -0,0 +1,129 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4LogicalSkinSurface.cc,v 2.1 1998/07/13 16:55:06 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
////////////////////////////////////////////////////////////////////////
// G4LogicalSkinSurface Implementation
////////////////////////////////////////////////////////////////////////
//
// File: G4LogicalSkinSurface.cc
// Description: A Logical Surface class for the surface
// surrounding a single logical volume.
// Version: 1.0
// Created: 1997-06-26
// Author: John Apostolakis
// mail: John.Apostolakis@cern.ch
// Modified: 1997-06-26 John Apostolakis
//
// CVS Id tag:
////////////////////////////////////////////////////////////////////////
#include "G4LogicalSkinSurface.hh"
#include "G4ios.hh"
// #include "G4OpticalSurface.hh"
G4LogicalSkinSurfaceTable G4LogicalSkinSurface::theSurfaceTable;
/////////////////////////
// Class Implementation
/////////////////////////
/////////////////
// Constructors
/////////////////
G4LogicalSkinSurface::G4LogicalSkinSurface(const G4String& name,
G4LogicalVolume* logicalVolume,
G4OpticalSurface* opticalSurface)
: G4LogicalSurface(name, opticalSurface),
LogVolume(logicalVolume)
{
// Store in the table of Surfaces
theSurfaceTable.insert(this);
theIndexInTable = theSurfaceTable.index(this);
}
G4LogicalSkinSurface::G4LogicalSkinSurface(const G4LogicalSkinSurface &right)
: G4LogicalSurface(right.GetName(), right.GetOpticalSurface())
{
*this = right;
}
G4LogicalSkinSurface::~G4LogicalSkinSurface(){}
//////////////
// Operators
//////////////
const G4LogicalSkinSurface& G4LogicalSkinSurface::operator=(const G4LogicalSkinSurface &right)
{
return right;
}
G4int G4LogicalSkinSurface::operator==(const G4LogicalSkinSurface &right) const
{
return (this == (G4LogicalSkinSurface *) &right);
}
G4int G4LogicalSkinSurface::operator!=(const G4LogicalSkinSurface &right) const
{
return (this != (G4LogicalSkinSurface *) &right);
}
////////////
// Methods
////////////
G4LogicalSkinSurface* G4LogicalSkinSurface::GetSurface(const G4LogicalVolume* vol)
{
for (int i=0; i<theSurfaceTable.length(); i++) {
if(theSurfaceTable[i]->GetLogicalVolume() == vol)
return theSurfaceTable[i];
}
return NULL;
}
void G4LogicalSkinSurface::DumpInfo()
{
// Dump info for known surfaces
G4cout << "***** Surface Table : Nb of Surfaces = " <<
// G4LogicalSkinSurface::
GetNumberOfSkinSurfaces() << " *****" << endl;
for (int i=0; i<theSurfaceTable.length(); i++) {
G4LogicalSkinSurface *pSkinSurface= theSurfaceTable[i];
G4cout << theSurfaceTable[i]->GetName() << " : " << endl <<
" Skin of logical volume " << pSkinSurface->GetLogicalVolume()->GetName ()
<< endl <<
" Optical Surface Ptr = " << (long) (pSkinSurface->GetOpticalSurface() )
<< endl;
#ifdef PRINT_INFO
// DOES NOT COMPILE without including "G4OpticalSurface.hh"
// G4cout << pSkinSurface->GetOpticalSurface() << endl ;
G4pticalSurface opticalSurface= pSkinSurface->GetOpticalSurface();
G4cout <<
" Surface type = " << opticalSurface->GetType() << endl <<
" Surface finish = " << opticalSurface->GetFinish() << endl <<
" Surface model = " << opticalSurface->GetModel() << endl;
/*
operator << ( G4OpticalSurface opticalSurface ) should exist
and do something like:
" Surface type = " << opticalSurface->GetType() << endl <<
" Surface finish = " << opticalSurface->GetFinish() << endl <<
" Surface model = " << opticalSurface->GetModel() << endl;
*/
#endif
}
G4cout << endl;
}
@@ -0,0 +1,46 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4NavigationHistory.cc,v 2.1 1998/07/13 16:55:07 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// G4NavigationHistory Implementation P.Kent August 96
#include "G4NavigationHistory.hh"
#include "G4ios.hh"
ostream& operator << (ostream& os, const G4NavigationHistory& nav)
{
G4cout << "History depth="<<nav.GetDepth()<< endl;
for (G4int i=0;i<=nav.GetDepth();i++)
{
os << "Level=["<<i<<"]: " ;
if( nav.GetVolume(i) != 0 ) {
os << "Phys Name=["<< nav.GetVolume(i)->GetName()
<< "] Type=[";
switch(nav.GetVolumeType(i))
{
case kNormal:
os <<"N";
break;
case kReplica:
os <<"R" << nav.GetReplicaNo(i);
break;
case kParameterised:
os <<"P" << nav.GetReplicaNo(i);
break;
}
os << "]";
}else{
os << "Phys = <Null>";
}
os << endl;
}
return os;
}
@@ -0,0 +1,14 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4NavigationLevel.cc,v 2.0 1998/07/02 17:06:33 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
#include "G4NavigationLevel.hh"
G4Allocator<G4NavigationLevel> aNavigationLevelAllocator;
G4Allocator<G4NavigationLevelRep> aNavigLevelRepAllocator;
+942
View File
@@ -0,0 +1,942 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4Navigator.cc,v 2.6 1998/11/25 17:57:23 japost Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// class G4Navigator Implementation Paul Kent July 95/96
#include "G4Navigator.hh"
#include "G4ios.hh"
#include <iomanip.h>
G4Navigator::G4Navigator() :
fWasLimitedByGeometry(false),
fTopPhysical(0),
fVerbose(0)
{
ResetStackAndState();
}
G4Navigator::~G4Navigator()
{;}
// Set the world (`topmost') volume
void G4Navigator::SetWorldVolume(G4VPhysicalVolume* pWorld)
{
// Setup the volume
pWorld->Setup(0); // No mother since world volume
if (!(pWorld->GetTranslation()==G4ThreeVector(0,0,0)))
{
G4Exception ("G4Navigator::SetWorldVolume - Must be centred on origin");
}
const G4RotationMatrix* rm=pWorld->GetRotation();
if (rm&&(!rm->isIdentity()))
{
G4Exception ("G4Navigator::SetWorldVolume - Must not be rotated");
}
fTopPhysical=pWorld;
fHistory.SetFirstEntry(pWorld);
}
// define DEBUG_HIST 1
// Locate the point in the hierarchy return 0 if outside
//
// ( The direction is required only if we are on an edge shared by
// two or more surfaces. )
//
G4VPhysicalVolume*
G4Navigator::LocateGlobalPointAndSetup(const G4ThreeVector& globalPoint,
const G4ThreeVector* pGlobalDirection,
const G4bool relativeSearch)
{
G4bool notKnownContained=true,noResult;
G4VPhysicalVolume *targetPhysical;
G4LogicalVolume *targetLogical;
G4VSolid *targetSolid;
G4ThreeVector localPoint;
EInside insideCode;
#ifdef DEBUG_HIST
G4cerr << "Upon entering LocateGlobalPointAndSetup " << endl;
G4cerr << " History = " << endl << fHistory << endl << endl;
#endif
#ifdef G4VERBOSE
if( fVerbose > 0 )
{
cout << "G4Navigator::LocateGlobalPointAndSetup: " << endl;
cout.precision(8);
cout << " I was called with the following arguments: " << endl
<< " Globalpoint = " << globalPoint << endl
<< " relativeSearch = " << relativeSearch << endl;
// << " = " << << endl
cout << " Upon entering my state is: " << endl;
PrintState();
}
#endif
if (!relativeSearch)
{
ResetStackAndState();
}
else
{
if (fWasLimitedByGeometry)
{
fWasLimitedByGeometry=false;
fEnteredDaughter=fEntering; // Remember
fExitedMother= fExiting; // Remember
if (fExiting)
{
if (fHistory.GetDepth())
{
fBlockedPhysicalVolume=fHistory.GetTopVolume();
fBlockedReplicaNo=fHistory.GetTopReplicaNo();
fHistory.BackLevel();
}
else
{
// Have exited world volume
return 0;
}
// A fix for the case where a volume is "entered" at an edge
// and a coincident surface exists outside it.
// This stops it from exiting further volumes and cycling
if( fLastStepWasZero )
{
fExiting= false;
}
}
else if (fEntering)
{
G4VPhysicalVolume *curPhysical=fHistory.GetTopVolume();
switch (VolumeType(fBlockedPhysicalVolume))
{
case kNormal:
fBlockedPhysicalVolume->Setup(curPhysical);
fHistory.NewLevel(fBlockedPhysicalVolume);
break;
case kReplica:
freplicaNav.ComputeTransformation(fBlockedReplicaNo,
fBlockedPhysicalVolume);
fBlockedPhysicalVolume->Setup(curPhysical);
fHistory.NewLevel(fBlockedPhysicalVolume,
kReplica,
fBlockedReplicaNo);
fBlockedPhysicalVolume->SetCopyNo(fBlockedReplicaNo);
break;
case kParameterised:
G4VSolid *pSolid;
// G4VSolid *pSolid=fBlockedPhysicalVolume->
// GetLogicalVolume()-> GetSolid();
G4VPVParameterisation *pParam=fBlockedPhysicalVolume->
GetParameterisation();
pSolid= pParam->ComputeSolid(fBlockedReplicaNo,
fBlockedPhysicalVolume);
pSolid->ComputeDimensions(pParam,
fBlockedReplicaNo,
fBlockedPhysicalVolume);
pParam->ComputeTransformation(fBlockedReplicaNo,
fBlockedPhysicalVolume);
fBlockedPhysicalVolume->Setup(curPhysical);
fHistory.NewLevel(fBlockedPhysicalVolume,
kParameterised,
fBlockedReplicaNo);
fBlockedPhysicalVolume->SetCopyNo(fBlockedReplicaNo);
// Set the correct solid and material in Logical Volume
G4LogicalVolume *pLogical;
pLogical= fBlockedPhysicalVolume->GetLogicalVolume();
pLogical->SetSolid( pSolid );
pLogical->SetMaterial(
pParam->ComputeMaterial(fBlockedReplicaNo,
fBlockedPhysicalVolume));
break;
}
fEntering=false;
fBlockedPhysicalVolume=0;
localPoint=fHistory.GetTopTransform().TransformPoint(globalPoint);
notKnownContained=false;
}
}
else
{
fBlockedPhysicalVolume=0;
fEntering=false;
fEnteredDaughter=false; // Full Step was not taken, did not enter
fExiting=false;
fExitedMother=false; // Full Step was not taken, did not exit
}
}
//
// Search from top of history up through geometry until
// containing volume found:
//
// If on
// o OUTSIDE - Back up level, not/no longer exiting volumes
// o SURFACE and EXITING - Back up level, setting new blocking no.s
// else
// o containing volume found
//
while (notKnownContained)
{
if (fHistory.GetTopVolumeType()!=kReplica)
{
targetSolid=fHistory.GetTopVolume()->GetLogicalVolume()->GetSolid();
localPoint=fHistory.GetTopTransform().TransformPoint(globalPoint);
insideCode=targetSolid->Inside(localPoint);
}
else
{
insideCode=freplicaNav.BackLocate(fHistory,globalPoint,localPoint,fExiting,notKnownContained);
// !CARE! if notKnownContained returns false then the point is within
// the containing placement volume of the replica(s). If insidecode
// will result in the history being backed up one level, then the
// local point returned is the point in the system of this new level
}
if (insideCode==kOutside)
{
if (fHistory.GetDepth())
{
fBlockedPhysicalVolume=fHistory.GetTopVolume();
fBlockedReplicaNo=fHistory.GetTopReplicaNo();
fHistory.BackLevel();
fExiting=false;
}
else
{
// Have exited world volume
return 0;
}
}
else if (insideCode==kSurface&&fExiting)
{
if (fHistory.GetDepth())
{
fBlockedPhysicalVolume=fHistory.GetTopVolume();
fBlockedReplicaNo=fHistory.GetTopReplicaNo();
fHistory.BackLevel();
// Still on surface but exited volume not necessarily convex
fValidExitNormal=false;
}
else
{
// Have exited world volume
return 0;
}
}
else
{
notKnownContained=false;
}
}
//
// Search downwards until deepest containing volume found,
// blocking fBlockedPhysicalVolume/BlockedReplicaNum
//
// 3 Cases:
//
// o Parameterised daughters
// =>Must be one G4PVParameterised daughter & voxels
// o Positioned daughters & voxels
// o Positioned daughters & no voxels
noResult=true; // noResult should be renamed to
// something like enteredLevel, as that is its meaning.
do
{
// Determine `type' of current mother volume
targetPhysical=fHistory.GetTopVolume();
targetLogical=targetPhysical->GetLogicalVolume();
switch(CharacteriseDaughters(targetLogical))
{
case kNormal:
if (targetLogical->GetVoxelHeader())
{
noResult=fvoxelNav.LevelLocate(fHistory,
fBlockedPhysicalVolume,
fBlockedReplicaNo,
globalPoint,
pGlobalDirection,
fLocatedOnEdge,
localPoint);
}
else
{
noResult=fnormalNav.LevelLocate(fHistory,
fBlockedPhysicalVolume,
fBlockedReplicaNo,
globalPoint,
pGlobalDirection,
fLocatedOnEdge,
localPoint);
}
break;
case kReplica:
noResult=freplicaNav.LevelLocate(fHistory,
fBlockedPhysicalVolume,
fBlockedReplicaNo,
globalPoint,
pGlobalDirection,
fLocatedOnEdge,
localPoint);
break;
case kParameterised:
noResult=fparamNav.LevelLocate(fHistory,
fBlockedPhysicalVolume,
fBlockedReplicaNo,
globalPoint,
pGlobalDirection,
fLocatedOnEdge,
localPoint);
break;
}
// LevelLocate returns true if it finds a daughter volume
// in which globalPoint is inside (or on the surface).
if (noResult)
{
// The blocked volume is no longer valid - it was for another level
fBlockedPhysicalVolume= 0;
fBlockedReplicaNo= -1;
}
} while (noResult);
fLastLocatedPointLocal=localPoint;
#ifdef G4VERBOSE
if( fVerbose > 0 ) PrintState();
if( fVerbose > 1 )
{
cout.precision(6);
cout << " Return value = new volume = "
<< (targetPhysical==0 ? G4String("None") :
targetPhysical->GetName() ) << endl;
}
#endif
#ifdef DEBUG_HIST
G4cerr << "Upon exiting LocateGlobalPointAndSetup " << endl;
G4cerr << " History = " << endl << fHistory << endl << endl;
#endif
return targetPhysical;
}
// Compute the next geometric Step: Intersections with current
// mother and `daughter' volumes.
//
// NOTE:
//
// Flags on entry:
//
// fValidExitNormal - Normal of exited volume is valid (convex, not a
// coincident boundary)
// fExitNormal - Surface normal of exited volume
// fExiting - True if have exited solid
//
// fBlockedPhysicalVolume - Ptr to exited volume (or 0)
// fBlockedReplicaNo - Replication no of exited volume
// fLastStepWasZero - True if last Step size was zero.
//
// Flags on exit:
// fValidExitNormal - True if surface normal of exited volume is valid
// fExitNormal - Surface normal of exited volume rotated to mothers
// reference system
// fExiting - True if exiting mother
// fEntering - True if entering `daughter' volume (or replica)
// fBlockedPhysicalVolume - Ptr to candidate (entered) volume
// fBlockedReplicaNo - Replication no of candidate (entered) volume
// fLastStepWasZero - True if this Step size was zero.
G4double G4Navigator::ComputeStep(const G4ThreeVector &pGlobalpoint,
const G4ThreeVector &pDirection,
const G4double pCurrentProposedStepLength,
G4double &pNewSafety)
{
G4double Step;
G4ThreeVector localDirection=ComputeLocalAxis(pDirection);
G4VPhysicalVolume *motherPhysical=fHistory.GetTopVolume();
G4LogicalVolume *motherLogical=motherPhysical->GetLogicalVolume();
#ifdef G4VERBOSE
cout.precision(8);
if( fVerbose > 1 )
{
cout << "*** G4Navigator::ComputeStep: ***" << endl;
cout.precision(8);
cout << " I was called with the following arguments: " << endl
<< " Globalpoint = " << setw(25) << pGlobalpoint << endl
<< " Direction = " << setw(25) << pDirection << endl
<< " ProposedStepLength= " << pCurrentProposedStepLength << endl;
// << " = " << << endl
}
if( fVerbose > 2 )
{
// cout.precision(3);
cout << " Upon entering my state is: " << endl;
PrintState();
}
#endif
G4ThreeVector newLocalPoint =ComputeLocalPoint(pGlobalpoint);
if( newLocalPoint != fLastLocatedPointLocal )
{
// Check whether the relocation is within safety
//
G4ThreeVector oldLocalPoint= fLastLocatedPointLocal;
G4double moveLenSq= (newLocalPoint-oldLocalPoint).mag2();
if (moveLenSq >= kCarTolerance*kCarTolerance){
//
// The following checks only make sense if the move is larger
// than the tolerance.
//
G4ThreeVector OriginalGlobalpoint;
OriginalGlobalpoint = fHistory.GetTopTransform().Inverse()
.TransformPoint(fLastLocatedPointLocal);
G4double shiftOriginSafSq= (fPreviousSftOrigin-pGlobalpoint).mag2();
#if 0
// Reset point before computing safety
LocateGlobalPointWithinVolume(OriginalGlobalpoint);
G4double safety= ComputeSafety(OriginalGlobalpoint);
if( moveLenSq >= sqr(safety) ){
G4double moveLen=sqrt(moveLenSq);
if( moveLen > safety + kCarTolerance ){
G4cerr << " ERROR in G4Navigator::ComputeStep: " << endl
<< "The Step's starting point has moved " << moveLen
<< " since the last call to one of the Locate methods " << endl
<< " which is more than the current safety=" << safety << endl;
}else{
G4cerr << " Warning in G4Navigator::ComputeStep: " << endl
<< "The Step's starting point has moved " << moveLen
<< " which is equal to the current safety. " << endl;
}
}
G4double safetyPlus = safety + kCarTolerance;
assert( moveLenSq <= sqr(safetyPlus) );
#endif
if( shiftOriginSafSq >= sqr(fPreviousSafety) ){
G4double shiftOrigin=sqrt(shiftOriginSafSq);
if( shiftOrigin > fPreviousSafety + kCarTolerance ){
G4cerr << " ERROR in G4Navigator::ComputeStep: " << endl
<< "The Step's starting point has moved " << sqrt(moveLenSq)
<< " since the last call to one of the Locate methods " << endl
<< " This has resulted in moving " << shiftOrigin
<< " from the last point at which the safety was calculated "
<< endl
<< " which is more than the computed safety= "
<< fPreviousSafety << "at that point." << endl;
}
#ifdef DEBUG
else
{
G4cerr << " Warning in G4Navigator::ComputeStep: " << endl
<< "The Step's starting point has moved " << sqrt(moveLenSq)
<< " which has taken it to the limit of the current safety. "
<< endl;
}
#endif
}
G4double safetyPlus = fPreviousSafety+ kCarTolerance;
assert( shiftOriginSafSq <= sqr(safetyPlus) );
// Relocate the point within the same volume
//
LocateGlobalPointWithinVolume( pGlobalpoint );
}
}
if (fHistory.GetTopVolumeType()!=kReplica)
{
switch(CharacteriseDaughters(motherLogical))
{
case kNormal:
if (motherLogical->GetVoxelHeader())
{
Step=fvoxelNav.ComputeStep(fLastLocatedPointLocal,
localDirection,
pCurrentProposedStepLength,
pNewSafety,
fHistory,
fValidExitNormal,
fExitNormal,
fExiting,
fEntering,
&fBlockedPhysicalVolume,
fBlockedReplicaNo);
}
else
{
Step=fnormalNav.ComputeStep(fLastLocatedPointLocal,
localDirection,
pCurrentProposedStepLength,
pNewSafety,
fHistory,
fValidExitNormal,
fExitNormal,
fExiting,
fEntering,
&fBlockedPhysicalVolume,
fBlockedReplicaNo);
}
break;
case kParameterised:
Step=fparamNav.ComputeStep(fLastLocatedPointLocal,
localDirection,
pCurrentProposedStepLength,
pNewSafety,
fHistory,
fValidExitNormal,
fExitNormal,
fExiting,
fEntering,
&fBlockedPhysicalVolume,
fBlockedReplicaNo);
break;
case kReplica:
G4Exception("Logic Error in G4Navigator::ComputeStep()");
break;
}
}
else
{
Step=freplicaNav.ComputeStep(pGlobalpoint,
pDirection,
fLastLocatedPointLocal,
localDirection,
pCurrentProposedStepLength,
pNewSafety,
fHistory,
fValidExitNormal,
fExitNormal,
fExiting,
fEntering,
&fBlockedPhysicalVolume,
fBlockedReplicaNo);
}
if( (Step == pCurrentProposedStepLength) && (!fExiting) && (!fEntering) )
{
// This is Step is not really limited by the geometry.
// The Navigator is obliged to return "infinity"
Step = kInfinity;
}
// Remember last safety origin & value.
fPreviousSftOrigin= pGlobalpoint;
fPreviousSafety= pNewSafety;
fLocatedOnEdge= fLastStepWasZero && (Step==0); // Edge if two consecutive
// steps are zero, because
// at least two candidate volumes must have been checked
fLastStepWasZero= (Step==0);
fEnteredDaughter=fEntering; // I expect to enter a volume in this Step
fExitedMother=fExiting;
if(fExiting && !fValidExitNormal)
{
// We must calculate the normal anyway (in order to have it if requested)
G4ThreeVector FinalPoint= fLastLocatedPointLocal + localDirection*Step;
fExitNormal= motherLogical->GetSolid()->SurfaceNormal(FinalPoint);
}
#ifdef G4VERBOSE
if( fVerbose > 1 )
{
cout << " Upon exiting my state is: " << endl;
PrintState();
}
#endif
return Step;
}
G4VPhysicalVolume* G4Navigator::LocateGlobalPointAndSetup(const G4ThreeVector &p,
const G4TouchableHistory &h)
{
fHistory=*h.GetHistory();
SetupHierarchy();
return LocateGlobalPointAndSetup(p, 0);
}
G4ThreeVector G4Navigator::NetTranslation() const
{
G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
return tf.NetTranslation();
}
G4RotationMatrix G4Navigator::NetRotation() const
{
G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
return tf.NetRotation();
}
G4GRSVolume* G4Navigator::CreateGRSVolume() const
{
G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
return new G4GRSVolume(fHistory.GetTopVolume(),
tf.NetRotation(),
tf.NetTranslation());
}
G4GRSSolid* G4Navigator::CreateGRSSolid() const
{
G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
return new G4GRSSolid(fHistory.GetTopVolume()->GetLogicalVolume()->GetSolid(),
tf.NetRotation(),
tf.NetTranslation());
}
G4TouchableHistory* G4Navigator::CreateTouchableHistory() const
{
return new G4TouchableHistory(fHistory);
}
// Renavigate & reset hierarchy described by current history
// o Reset volumes
// o Recompute transforms and/or solids of replicated/parameterised vols
void G4Navigator::SetupHierarchy()
{
G4int i;
const G4int cdepth=fHistory.GetDepth();
G4VPhysicalVolume *mother,*current;
G4VSolid *pSolid;
G4VPVParameterisation *pParam;
mother=fHistory.GetVolume(0);
for (i=1;i<=cdepth;i++)
{
current=fHistory.GetVolume(i);
switch (fHistory.GetVolumeType(i))
{
case kNormal:
break;
case kReplica:
freplicaNav.ComputeTransformation(fHistory.GetReplicaNo(i),
current);
break;
case kParameterised:
G4int replicaNo;
// pSolid=current->GetLogicalVolume()->GetSolid();
pParam=current->GetParameterisation();
replicaNo= fHistory.GetReplicaNo(i);
pSolid= pParam->ComputeSolid(replicaNo, current);
// Set up dimensions & transform in solid/physical volume
pSolid->ComputeDimensions(pParam, replicaNo, current);
pParam->ComputeTransformation(replicaNo, current);
// Set up the correct solid and material in Logical Volume
G4LogicalVolume *pLogical;
pLogical= current->GetLogicalVolume();
pLogical->SetSolid( pSolid );
pLogical->SetMaterial( pParam->ComputeMaterial(replicaNo,
current));
break;
}
current->Setup(mother);
mother=current;
}
}
ostream& operator << (ostream &os,const G4Navigator &n)
{
os << "Current History: " << endl << n.fHistory;
return os;
}
// Return global to local transformation
const G4AffineTransform G4Navigator::GetLocalToGlobalTransform() const
{
G4AffineTransform tempTransform;
tempTransform= fHistory.GetTopTransform().Inverse();
return tempTransform;
}
// Obtain the Normal vector to a surface (in local coordinates)
// pointing out of previous volume and into current volume
//
G4ThreeVector G4Navigator::GetLocalExitNormal(G4bool* valid)
{
G4ThreeVector ExitNormal(0.,0.,0.);
if( fExitedMother ){
ExitNormal=fExitNormal;
*valid = true;
}else if (EnteredDaughterVolume()) {
ExitNormal= -(fHistory.GetTopVolume()->GetLogicalVolume()
->GetSolid()->SurfaceNormal(fLastLocatedPointLocal));
*valid = true;
}else{
// We are not at a boundary.
// ExitNormal remains (0,0,0)
*valid = false;
}
return ExitNormal;
}
// It assumes that it assumes that it will be
// i) called with the Point equal to the EndPoint of the ComputeStep.
// ii) after (or at the end of) ComputeStep OR after the relocation.
G4double G4Navigator::ComputeSafety(const G4ThreeVector &pGlobalpoint,
const G4double pMaxLength)
// A sort of MaximumLength ... ?
{
G4double newSafety=0.0;
#ifdef G4VERBOSE
if( fVerbose > 0 )
{
cout << "*** G4Navigator::ComputeSafety: ***" << endl;
cout.precision(8);
cout << " I was called with the following arguments: " << endl
<< " Globalpoint = " << pGlobalpoint << endl;
// cout << " pMaxLength = " << pMaxLength << endl;
cout << " Upon entering my state is: " << endl;
PrintState();
}
#endif
if( ! (fEnteredDaughter || fExitedMother ) )
{
G4VPhysicalVolume *motherPhysical=fHistory.GetTopVolume();
G4LogicalVolume *motherLogical=motherPhysical->GetLogicalVolume();
G4ThreeVector localPoint= ComputeLocalPoint(pGlobalpoint);
if (fHistory.GetTopVolumeType()!=kReplica)
{
switch(CharacteriseDaughters(motherLogical))
{
case kNormal:
if (motherLogical->GetVoxelHeader())
{
newSafety=fvoxelNav.ComputeSafety(localPoint,
fHistory,
pMaxLength);
}
else
{
newSafety=fnormalNav.ComputeSafety(localPoint,
fHistory,
pMaxLength);
}
break;
case kParameterised:
newSafety=fparamNav.ComputeSafety(localPoint,
fHistory,
pMaxLength);
break;
case kReplica:
G4Exception("Logic Error in G4Navigator::ComputeSafety()");
break;
}
}
else
{
newSafety=freplicaNav.ComputeSafety(pGlobalpoint,
localPoint,
fHistory,
pMaxLength);
}
}
// Remember last safety origin & value.
fPreviousSftOrigin= pGlobalpoint;
fPreviousSafety= newSafety;
#ifdef G4VERBOSE
if( fVerbose > 1 )
{
cout.precision(8);
cout << " Upon exiting my state is: " << endl;
PrintState();
cout << " and I return a value of Safety = " << newSafety << endl;
}
#endif
return newSafety;
}
G4bool G4Navigator::EnteredDaughterVolume()
{
return fEnteredDaughter;
}
// G4bool G4Navigator::ExitedVolume()
// {
// return fExitedCurrent;
// }
void G4Navigator::PrintState()
{
if( fVerbose >= 4 )
{
cout.precision(3);
cout << " Upon exiting my state is: " << endl;
cout << " ValidExitNormal= " << fValidExitNormal << endl
<< " ExitNormal = " << fExitNormal << endl
<< " Exiting = " << fExiting << endl
<< " Entering = " << fEntering << endl
<< " BlockedPhysicalVolume= " << (fBlockedPhysicalVolume==0 ? G4String("None") :
fBlockedPhysicalVolume->GetName() ) << endl
<< " BlockedReplicaNo = " << fBlockedReplicaNo << endl
<< " LastStepWasZero = " << fLastStepWasZero << endl
<< endl;
}
if( ( 1 < fVerbose) && (fVerbose < 4) )
{
cout.precision(3);
cout << setw(18) << " ExitNormal " << " "
<< setw( 9) << " Valid " << " "
<< setw( 9) << " Exiting " << " "
<< setw( 9) << " Entering" << " "
<< setw(15) << " Blocked:Volume " << " "
<< setw( 9) << " ReplicaNo" << " "
<< setw( 8) << " LastStepZero " << " "
<< endl;
cout << setw(24) << fExitNormal << " "
<< setw( 3) << fValidExitNormal << " "
<< setw( 9) << fExiting << " "
<< setw( 9) << fEntering << " "
<< setw(15) << (fBlockedPhysicalVolume==0 ? G4String("None") :
fBlockedPhysicalVolume->GetName() ) << " "
<< setw( 9) << fBlockedReplicaNo << " "
<< setw( 8) << fLastStepWasZero << " "
<< endl;
}
if( fVerbose > 2 )
{
cout.precision(8);
cout << " Current Localpoint = " << fLastLocatedPointLocal << endl;
cout << " PreviousSftOrigin = " << fPreviousSftOrigin << endl;
cout << " PreviousSafety = " << fPreviousSafety << endl;
}
}
void G4Navigator::LocateGlobalPointWithinVolume(const G4ThreeVector& pGlobalpoint)
{
// The new implementation of LocateGlobalPointWithinVolume
//
// -> the state information of this Navigator and its subNavigators
// is updated in order to start the next step at pGlobalpoint
// -> no check is performed whether pGlobalpoint is inside the
// original volume (this must be the case).
//
// Note: a direction could be added to the arguments, to aid in
// future optional checking (via the Old code below).
// [ This would be done only in verbose mode ]
fLastLocatedPointLocal =ComputeLocalPoint(pGlobalpoint);
// For the case of Voxel (or Parameterised) volume the respective
// Navigator must be messaged to update its voxel information etc.o
// Update the state of the Sub Navigators
// - in particular any voxel information they store/cache
//.
G4VPhysicalVolume* motherPhysical=fHistory.GetTopVolume();
G4LogicalVolume* motherLogical= motherPhysical->GetLogicalVolume();
G4SmartVoxelHeader* pVoxelHeader= motherLogical->GetVoxelHeader();
G4ThreeVector localPoint= ComputeLocalPoint(pGlobalpoint);
if (fHistory.GetTopVolumeType()!=kReplica)
{
switch(CharacteriseDaughters(motherLogical))
{
case kNormal:
if (pVoxelHeader)
{
fvoxelNav.VoxelLocate( pVoxelHeader, localPoint );
}
// else { fnormalNav. nothing !? }
break;
case kParameterised:
// Resets state & returns voxel node
fparamNav.VoxelLocate( pVoxelHeader, localPoint );
break;
case kReplica:
G4Exception("Logic Error in G4Navigator::LocateGlobalPointWithinVolume()");
break;
}
}
#if 0
else
{
// There is no state stored in G4ReplicaNavigation
// freplicaNav.VoxelLocate( pVoxelHeader, localPoint );
}
#endif
#ifdef OLD_LOCATE
// An alternative implementation using LocateGlobalPointAndSetup.
// It can also be used to check the method's assumptions.
//
G4VPhysicalVolume *pOldVol, *pNewVol;
pOldVol= fHistory.GetTopVolume();
pNewVol= LocateGlobalPointAndSetup(pGlobalpoint, 0);
// , G4ThreeVector(1.,0.,0.));
if( pOldVol != pNewVol ){
// This is abnormal behaviour.
cerr << " ERROR in G4Navigator::LocateGlobalPointWithinVolume " << endl;
cerr << " A volume change has occured - this is not expected & illegal" << endl;
cerr << " Old volume name = " << pOldVol->GetName() << endl;
cerr << " New volume name = " << pNewVol->GetName() << endl;
G4VPhysicalVolume *pNewVol2;
pNewVol2= LocateGlobalPointAndSetup(pGlobalpoint, 0);
//, G4ThreeVector(1.,0.,0.));
cerr << " Tried again & found volume= " << pNewVol2->GetName() << endl;
}
// Check that the new volume located is same as the old one.
assert( pOldVol == pNewVol );
#endif
}
G4int G4Navigator::GetVerboseLevel()
{
return fVerbose;
}
void G4Navigator::SetVerboseLevel(G4int level)
{
fVerbose=level;
}
@@ -0,0 +1,195 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4NormalNavigation.cc,v 2.0 1998/07/02 17:06:37 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// class G4NormalNavigation Implementation
//
#include "G4NormalNavigation.hh"
G4double G4NormalNavigation::ComputeStep(const G4ThreeVector &localPoint,
const G4ThreeVector &localDirection,
const G4double currentProposedStepLength,
G4double &newSafety,
G4NavigationHistory &history,
G4bool &validExitNormal,
G4ThreeVector &exitNormal,
G4bool &exiting,
G4bool &entering,
G4VPhysicalVolume *(*pBlockedPhysical),
G4int &blockedReplicaNo)
{
G4VPhysicalVolume *motherPhysical,*samplePhysical,*blockedExitedVol=0;
G4LogicalVolume *motherLogical;
G4VSolid *motherSolid;
G4ThreeVector sampleDirection;
G4double ourStep=currentProposedStepLength,motherSafety,ourSafety;
G4int localNoDaughters,sampleNo;
motherPhysical=history.GetTopVolume();
motherLogical=motherPhysical->GetLogicalVolume();
motherSolid=motherLogical->GetSolid();
//
// Compute mother safety
//
motherSafety=motherSolid->DistanceToOut(localPoint);
ourSafety=motherSafety; // Working isotropic safety
//
// Compute daughter safeties & intersections
//
// Exiting normal optimisation
if (exiting&&validExitNormal)
{
if (localDirection.dot(exitNormal)>=kMinExitingNormalCosine)
{
// Block exited daughter volume
blockedExitedVol=*pBlockedPhysical;
ourSafety=0;
}
}
exiting=false;
entering=false;
localNoDaughters=motherLogical->GetNoDaughters();
for (sampleNo=localNoDaughters-1;sampleNo>=0;sampleNo--)
{
samplePhysical=motherLogical->GetDaughter(sampleNo);
if (samplePhysical!=blockedExitedVol)
{
samplePhysical->Setup(motherPhysical);
G4AffineTransform sampleTf(samplePhysical->GetRotation(),
samplePhysical->GetTranslation());
sampleTf.Invert();
const G4ThreeVector samplePoint=sampleTf.TransformPoint(localPoint);
const G4VSolid *sampleSolid=samplePhysical
->GetLogicalVolume()
->GetSolid();
const G4double sampleSafety=sampleSolid
->DistanceToIn(samplePoint);
if (sampleSafety<ourSafety)
{
ourSafety=sampleSafety;
}
if (sampleSafety<=ourStep)
{
sampleDirection=sampleTf.TransformAxis(localDirection);
const G4double sampleStep=sampleSolid
->DistanceToIn(samplePoint,
sampleDirection);
if (sampleStep<=ourStep)
{
ourStep=sampleStep;
entering=true;
exiting=false;
*pBlockedPhysical=samplePhysical;
blockedReplicaNo=-1;
}
}
}
}
if (currentProposedStepLength<ourSafety)
{
//
// Guaranteed physics limited
//
entering=false;
exiting=false;
*pBlockedPhysical=0;
ourStep=kInfinity;
}
else
{
//
// Compute mother intersection if required
//
if (motherSafety<=ourStep)
{
G4double motherStep=motherSolid
->DistanceToOut(localPoint,
localDirection,
true,
&validExitNormal,
&exitNormal);
if (motherStep<=ourStep)
{
ourStep=motherStep;
exiting=true;
entering=false;
if (validExitNormal)
{
const G4RotationMatrix *rot=motherPhysical->GetRotation();
if (rot)
{
exitNormal*=rot->inverse();
}
}
}
else
{
validExitNormal=false;
}
}
}
newSafety=ourSafety;
return ourStep;
}
G4double G4NormalNavigation::ComputeSafety(const G4ThreeVector &localPoint,
const G4NavigationHistory &history,
const G4double currentProposedStepLength)
{
G4VPhysicalVolume *motherPhysical,*samplePhysical;
G4LogicalVolume *motherLogical;
G4VSolid *motherSolid;
G4double ourStep=currentProposedStepLength,motherSafety,ourSafety;
G4int localNoDaughters,sampleNo;
motherPhysical=history.GetTopVolume();
motherLogical=motherPhysical->GetLogicalVolume();
motherSolid=motherLogical->GetSolid();
//
// Compute mother safety
//
motherSafety=motherSolid->DistanceToOut(localPoint);
ourSafety=motherSafety; // Working isotropic safety
//
// Compute daughter safeties
//
localNoDaughters=motherLogical->GetNoDaughters();
for (sampleNo=localNoDaughters-1;sampleNo>=0;sampleNo--)
{
samplePhysical=motherLogical->GetDaughter(sampleNo);
samplePhysical->Setup(motherPhysical);
G4AffineTransform sampleTf(samplePhysical->GetRotation(),
samplePhysical->GetTranslation());
sampleTf.Invert();
const G4ThreeVector samplePoint=sampleTf.TransformPoint(localPoint);
const G4VSolid *sampleSolid=samplePhysical
->GetLogicalVolume()
->GetSolid();
const G4double sampleSafety=sampleSolid
->DistanceToIn(samplePoint);
if (sampleSafety<ourSafety)
{
ourSafety=sampleSafety;
}
}
return ourSafety;
}
@@ -0,0 +1,327 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4ParameterisedNavigation.cc,v 2.4 1998/09/15 13:57:33 japost Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// class G4ParameterisedNavigation Implementation
//
#include "G4ParameterisedNavigation.hh"
G4ParameterisedNavigation::~G4ParameterisedNavigation()
{
#ifdef G4DEBUG_NAVIGATION
cout << "G4ParameterisedNavigation::~G4ParameterisedNavigation() called."
<< endl;
#endif
}
G4double G4ParameterisedNavigation::ComputeStep(const G4ThreeVector &localPoint,
const G4ThreeVector &localDirection,
const G4double currentProposedStepLength,
G4double &newSafety,
G4NavigationHistory &history,
G4bool &validExitNormal,
G4ThreeVector &exitNormal,
G4bool &exiting,
G4bool &entering,
G4VPhysicalVolume *(*pBlockedPhysical),
G4int &blockedReplicaNo)
{
G4VPhysicalVolume *motherPhysical,*samplePhysical;
G4VPVParameterisation *sampleParam;
G4LogicalVolume *motherLogical;
G4VSolid *motherSolid,*sampleSolid;
G4ThreeVector sampleDirection;
G4double ourStep=currentProposedStepLength,motherSafety,ourSafety;
G4int sampleNo,blockedExitedReplicaNo=-1;
G4bool initialNode,noStep;
G4SmartVoxelNode *curVoxelNode;
G4int curNoVolumes,contentNo;
G4double voxelSafety;
// Replication data
EAxis axis;
G4int nReplicas;
G4double width,offset;
G4bool consuming;
motherPhysical=history.GetTopVolume();
motherLogical=motherPhysical->GetLogicalVolume();
motherSolid=motherLogical->GetSolid();
//
// Compute mother safety
//
motherSafety=motherSolid->DistanceToOut(localPoint);
ourSafety=motherSafety; // Working isotropic safety
//
// Compute daughter safeties & intersections
//
initialNode=true;
noStep=true;
// By definition, parameterised volumes exist as first
// daughter of mother volume
samplePhysical=motherLogical->GetDaughter(0);
samplePhysical->GetReplicationData(axis,nReplicas,width,offset,consuming);
fBList.Enlarge(nReplicas);
fBList.Reset();
// Exiting normal optimisation
if (exiting && (*pBlockedPhysical==samplePhysical) && validExitNormal)
{
if (localDirection.dot(exitNormal)>=kMinExitingNormalCosine)
{
assert( (0 <= blockedReplicaNo)
&&(blockedReplicaNo<nReplicas));
// Block exited daughter replica; Must be on boundary => zero safety
fBList.BlockVolume(blockedReplicaNo);
ourSafety=0;
}
}
exiting=false;
entering=false;
// sampleSolid=samplePhysical ->GetLogicalVolume() ->GetSolid();
sampleParam=samplePhysical->GetParameterisation();
do {
curVoxelNode=fVoxelNode;
curNoVolumes=curVoxelNode->GetNoContained();
for (contentNo=curNoVolumes-1;contentNo>=0;contentNo--)
{
sampleNo=curVoxelNode->GetVolume(contentNo);
if (!fBList.IsBlocked(sampleNo))
{
fBList.BlockVolume(sampleNo);
sampleSolid=sampleParam->ComputeSolid(sampleNo,
samplePhysical);
sampleSolid->ComputeDimensions(sampleParam,
sampleNo,
samplePhysical);
sampleParam->ComputeTransformation(sampleNo,
samplePhysical);
samplePhysical->Setup(motherPhysical);
G4AffineTransform sampleTf(samplePhysical->GetRotation(),
samplePhysical->GetTranslation());
sampleTf.Invert();
const G4ThreeVector samplePoint=sampleTf.TransformPoint(localPoint);
const G4double sampleSafety=sampleSolid
->DistanceToIn(samplePoint);
if (sampleSafety<ourSafety)
{
ourSafety=sampleSafety;
}
if (sampleSafety<=ourStep)
{
sampleDirection=sampleTf.TransformAxis(localDirection);
const G4double sampleStep=sampleSolid
->DistanceToIn(samplePoint,
sampleDirection);
if (sampleStep<=ourStep)
{
ourStep=sampleStep;
entering=true;
exiting=false;
*pBlockedPhysical=samplePhysical;
blockedReplicaNo=sampleNo;
}
}
}
}
if (initialNode)
{
initialNode=false;
voxelSafety=ComputeVoxelSafety(localPoint);
if (voxelSafety<ourSafety)
{
ourSafety=voxelSafety;
}
if (currentProposedStepLength<ourSafety)
{
//
// Guaranteed physics limited
//
noStep=false;
entering=false;
exiting=false;
*pBlockedPhysical=0;
ourStep=kInfinity;
}
else
{
//
// Compute mother intersection if required
//
if (motherSafety<=ourStep)
{
G4double motherStep=motherSolid
->DistanceToOut(localPoint,
localDirection,
true,
&validExitNormal,
&exitNormal);
if (motherStep<=ourStep)
{
ourStep=motherStep;
exiting=true;
entering=false;
if (validExitNormal)
{
const G4RotationMatrix *rot=motherPhysical->GetRotation();
if (rot)
{
exitNormal*=rot->inverse();
}
}
}
else
{
validExitNormal=false;
}
}
}
newSafety=ourSafety;
}
if (noStep)
{
noStep=LocateNextVoxel(localPoint,
localDirection,
ourStep);
}
} while (noStep);
return ourStep;
}
G4double G4ParameterisedNavigation::ComputeSafety(const G4ThreeVector &localPoint,
const G4NavigationHistory &history,
const G4double pProposedMaxLength )
{
G4VPhysicalVolume *motherPhysical,*samplePhysical;
G4VPVParameterisation *sampleParam;
G4LogicalVolume *motherLogical;
G4VSolid *motherSolid,*sampleSolid;
G4double motherSafety,ourSafety;
G4int sampleNo, curVoxelNodeNo;
G4SmartVoxelNode *curVoxelNode;
G4int curNoVolumes,contentNo;
G4double voxelSafety;
// Replication data
EAxis axis;
G4int nReplicas;
G4double width,offset;
G4bool consuming;
motherPhysical=history.GetTopVolume();
motherLogical=motherPhysical->GetLogicalVolume();
motherSolid=motherLogical->GetSolid();
//
// Compute mother safety
//
motherSafety=motherSolid->DistanceToOut(localPoint);
ourSafety=motherSafety; // Working isotropic safety
//
// Compute daughter safeties
//
// By definition, parameterised volumes exist as first
// daughter of mother volume
samplePhysical=motherLogical->GetDaughter(0);
samplePhysical->GetReplicationData(axis,nReplicas,width,offset,consuming);
sampleParam=samplePhysical->GetParameterisation();
// Calculate new VoxelNode of current point
curVoxelNodeNo= G4int (
(localPoint(fVoxelAxis) -fVoxelHeader->GetMinExtent())
/ fVoxelSliceWidth
);
curVoxelNode = fVoxelHeader->GetSlice(curVoxelNodeNo)->GetNode();
curNoVolumes=curVoxelNode->GetNoContained();
for (contentNo=curNoVolumes-1;contentNo>=0;contentNo--)
{
sampleNo=curVoxelNode->GetVolume(contentNo);
sampleSolid=sampleParam->ComputeSolid(sampleNo,
samplePhysical);
sampleSolid->ComputeDimensions(sampleParam,
sampleNo,
samplePhysical);
sampleParam->ComputeTransformation(sampleNo,
samplePhysical);
G4AffineTransform sampleTf(samplePhysical->GetRotation(),
samplePhysical->GetTranslation());
sampleTf.Invert();
const G4ThreeVector samplePoint=sampleTf.TransformPoint(localPoint);
const G4double sampleSafety=sampleSolid
->DistanceToIn(samplePoint);
if (sampleSafety<ourSafety)
{
ourSafety=sampleSafety;
}
}
// These must be current for ComputeVoxelSafety
fVoxelNodeNo= curVoxelNodeNo;
fVoxelNode = curVoxelNode;
voxelSafety=ComputeVoxelSafety(localPoint);
if (voxelSafety<ourSafety)
{
ourSafety=voxelSafety;
}
return ourSafety;
}
@@ -0,0 +1,880 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4ReplicaNavigation.cc,v 2.1 1998/07/12 02:58:28 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// class G4REplicaNavigation Implementation
#include "G4ReplicaNavigation.hh"
#include <assert.h>
G4ReplicaNavigation::G4ReplicaNavigation()
{
}
EInside G4ReplicaNavigation::Inside(const G4VPhysicalVolume *pVol,
const G4int replicaNo,
const G4ThreeVector &localPoint) const
{
EInside in=kOutside;
// Replication data
EAxis axis;
G4int nReplicas;
G4double width,offset;
G4bool consuming;
G4double coord,rad2,rmin,tolRMax2,rmax,tolRMin2;
pVol->GetReplicationData(axis,nReplicas,width,offset,consuming);
assert(consuming);
switch (axis)
{
case kXAxis:
case kYAxis:
case kZAxis:
coord=fabs(localPoint(axis))-width*0.5;
if (coord<=-kCarTolerance*0.5)
{
in=kInside;
}
else if (coord<=kCarTolerance*0.5)
{
in=kSurface;
}
break;
case kPhi:
if (localPoint.y()||localPoint.x())
{
coord=fabs(atan2(localPoint.y(),localPoint.x()))-width*0.5;
if (coord<=-kAngTolerance*0.5)
{
in=kInside;
}
else if (coord<=kAngTolerance*0.5)
{
in=kSurface;
}
}
else
{
in=kSurface;
}
break;
case kRho:
rad2=localPoint.perp2();
rmax=(replicaNo+1)*width+offset;
tolRMax2=rmax-kRadTolerance*0.5;
tolRMax2*=tolRMax2;
if (rad2>tolRMax2)
{
tolRMax2=rmax+kRadTolerance*0.5;
tolRMax2*=tolRMax2;
if (rad2<=tolRMax2)
{
in=kSurface;
}
}
else
{
// Known to be inside outer radius
if (replicaNo||offset)
{
rmin=rmax-width;
tolRMin2=rmin-kRadTolerance*0.5;
tolRMin2*=tolRMin2;
if (rad2>tolRMin2)
{
tolRMin2=rmin+kRadTolerance*0.5;
tolRMin2*=tolRMin2;
if (rad2>=tolRMin2)
{
in=kInside;
}
else
{
in=kSurface;
}
}
}
else
{
in=kInside;
}
}
break;
default:
G4Exception("Unknown axis in G4ReplicaNavigation::Inside");
break;
}
return in;
}
G4double G4ReplicaNavigation::DistanceToOut(const G4VPhysicalVolume *pVol,
const G4int replicaNo,
const G4ThreeVector &localPoint) const
{
// Replication data
EAxis axis;
G4int nReplicas;
G4double width,offset;
G4bool consuming;
G4double safety,safe1,safe2;
G4double coord,rho,rmin,rmax;
pVol->GetReplicationData(axis,nReplicas,width,offset,consuming);
assert(consuming);
switch(axis)
{
case kXAxis:
case kYAxis:
case kZAxis:
coord=localPoint(axis);
safe1=width*0.5-coord;
safe2=width*0.5+coord;
safety=(safe1<=safe2) ? safe1 : safe2;
break;
case kPhi:
if (localPoint.y()<=0)
{
safety=localPoint.x()*sin(width*0.5)+localPoint.y()*cos(width*0.5);
}
else
{
safety=localPoint.x()*sin(width*0.5)-localPoint.y()*cos(width*0.5);
}
break;
case kRho:
rho=localPoint.perp();
rmax=width*(replicaNo+1)+offset;
if (replicaNo||offset)
{
rmin=rmax-width;
safe1=rho-rmin;
safe2=rmax-rho;
safety=(safe1<=safe2) ? safe1 : safe2;
}
else
{
safety=rmax-rho;
}
break;
default:
G4Exception("Unknown axis in G4ReplicaNavigation::DistanceToOut");
break;
}
if (safety<0) safety=0;
return safety;
}
G4double G4ReplicaNavigation::DistanceToOut(const G4VPhysicalVolume *pVol,
const G4int replicaNo,
const G4ThreeVector &localPoint,
const G4ThreeVector &localDirection) const
{
// Replication data
EAxis axis;
G4int nReplicas;
G4double width,offset;
G4bool consuming;
G4double coord,Comp,Dist,lindist;
pVol->GetReplicationData(axis,nReplicas,width,offset,consuming);
assert(consuming);
switch(axis)
{
case kXAxis:
case kYAxis:
case kZAxis:
coord=localPoint(axis);
Comp=localDirection(axis);
if (Comp>0)
{
lindist=width*0.5-coord;
Dist= (lindist>kCarTolerance*0.5) ? lindist/Comp : 0;
}
else if (Comp<0)
{
lindist=width*0.5+coord;
Dist= (lindist>kCarTolerance*0.5) ? -lindist/Comp : 0;
}
else
{
Dist=kInfinity;
}
break;
case kPhi:
Dist=DistanceToOutPhi(localPoint,localDirection,width);
break;
case kRho:
Dist=DistanceToOutRad(localPoint,localDirection,width,offset,replicaNo);
break;
default:
G4Exception("Unknown axis in G4ReplicaNavigation::DistanceToOut");
break;
}
return Dist;
}
G4double G4ReplicaNavigation::DistanceToOutPhi(const G4ThreeVector &localPoint,
const G4ThreeVector &localDirection,
const G4double width) const
{
// Phi Intersection
// NOTE: width<=M_PI by definition
G4double sinSPhi,cosSPhi;
G4double pDistS,pDistE,compS,compE,Dist,dist2,yi;
if (localPoint.x()||localPoint.y())
{
sinSPhi=sin(-width*0.5); // SIN of starting phi plane
cosSPhi=cos(width*0.5); // COS of starting phi plane
// pDist -ve when inside
pDistS=localPoint.x()*sinSPhi-localPoint.y()*cosSPhi;
pDistE=localPoint.x()*sinSPhi+localPoint.y()*cosSPhi;
// Comp -ve when in direction of outwards normal
compS=-sinSPhi*localDirection.x()+cosSPhi*localDirection.y();
compE=-sinSPhi*localDirection.x()-cosSPhi*localDirection.y();
if (pDistS<=0&&pDistE<=0)
{
// Inside both phi *full* planes
if (compS<0)
{
dist2=pDistS/compS;
yi=localPoint.y()+dist2*localDirection.y();
// Check intersecting with correct half-plane (no -> no intersect)
if (yi<=0)
{
Dist=(pDistS<=-kCarTolerance*0.5) ? dist2 : 0;
}
else
{
Dist=kInfinity;
}
}
else
{
Dist=kInfinity;
}
if (compE<0)
{
dist2=pDistE/compE;
// Only check further if < starting phi intersection
if (dist2<Dist)
{
yi=localPoint.y()+dist2*localDirection.y();
// Check intersecting with correct half-plane
if (yi>=0)
{
// Leaving via ending phi
Dist=(pDistE<=-kCarTolerance*0.5) ? dist2 : 0;
}
}
}
}
else if (pDistS>=0&&pDistE>=0)
{
// Outside both *full* phi planes
// if towards both >=0 then once inside will remain inside
Dist= (compS>=0&&compE>=0) ? kInfinity : 0;
}
else if (pDistS>0&&pDistE<0)
{
// Outside full starting plane, inside full ending plane
if (compS>=0)
{
if (compE<0)
{
dist2=pDistE/compE;
yi=localPoint.y()+dist2*localDirection.y();
// Check intersection in correct half-plane (if not -> remain in extent)
Dist=(yi>0) ? dist2 : kInfinity;
}
else Dist=kInfinity;
}
else
{
// leaving immediately by starting phi
Dist=0;
}
}
else
{
// Must be pDistS<0&&pDistE>0
// Inside full starting plane, outside full ending plane
if (compE>=0)
{
if (compS<0)
{
dist2=pDistS/compS;
yi=localPoint.y()+dist2*localDirection.y();
// Check intersection in correct half-plane (if not -> remain in extent)
Dist=(yi<0) ? dist2 : kInfinity;
}
else
{
Dist=kInfinity;
}
}
else
{
// leaving immediately by ending phi
Dist=0;
}
}
}
else
{
// On z axis + travel not || to z axis -> use direction vector
Dist = (fabs(localDirection.phi())<=width*0.5) ? kInfinity : 0;
}
return Dist;
}
G4double G4ReplicaNavigation::DistanceToOutRad(const G4ThreeVector &localPoint,
const G4ThreeVector &localDirection,
const G4double width,
const G4double offset,
const G4int replicaNo) const
{
G4double rmin,rmax,t1,t2,t3,deltaR;
G4double b,c,d2,sr;
//
// Radial Intersections
//
// Find intersction with cylinders at rmax/rmin
// Intersection point (xi,yi,zi) on line
// x=localPoint.x+t*localDirection.x etc.
//
// Intersects with x^2+y^2=R^2
//
// Hence (localDirection.x^2+localDirection.y^2)t^2+
// 2t(localPoint.x*localDirection.x+localPoint.y*localDirection.y)+
// localPoint.x^2+localPoint.y^2-R^2=0
//
// t1 t2 t3
rmin=replicaNo*width+offset;
rmax=(replicaNo+1)*width+offset;
t1=1.0-localDirection.z()*localDirection.z(); // since v normalised
t2=localPoint.x()*localDirection.x()+localPoint.y()*localDirection.y();
t3=localPoint.x()*localPoint.x()+localPoint.y()*localPoint.y();
if (t1>0) // Check not parallel
{
// Calculate sr, r exit distance
if (t2>=0)
{
// Delta r not negative => leaving via rmax
deltaR=t3-rmax*rmax;
// NOTE: Should use rho-rmax<-kRadTolerance*0.5 - [no sqrts for efficiency]
if (deltaR<-kRadTolerance*0.5)
{
b=t2/t1;
c=deltaR/t1;
sr=-b+sqrt(b*b-c);
}
else
{
// On tolerant boundary & heading outwards (or locally perpendicular to)
// outer radial surface -> leaving immediately
sr=0;
}
}
else
{
// Possible rmin intersection
if (rmin)
{
deltaR=t3-rmin*rmin;
b=t2/t1;
c=deltaR/t1;
d2=b*b-c;
if (d2>=0)
{
// Leaving via rmin
// NOTE: Should use rho-rmin>kRadTolerance*0.5 - [no sqrts for efficiency]
sr= (deltaR>kRadTolerance*0.5) ? -b-sqrt(d2) : 0;
}
else
{
// No rmin intersect -> must be rmax intersect
deltaR=t3-rmax*rmax;
c=deltaR/t1;
sr=-b+sqrt(b*b-c);
}
}
else
{
// No rmin intersect -> must be rmax intersect
deltaR=t3-rmax*rmax;
b=t2/t1;
c=deltaR/t1;
sr=-b+sqrt(b*b-c);
}
}
}
else
{
sr=kInfinity;
}
return sr;
}
// Setup transformation and transform point into local system
void G4ReplicaNavigation::ComputeTransformation(const G4int replicaNo,
G4VPhysicalVolume *pVol,
G4ThreeVector& point) const
{
G4double val,cosv,sinv,tmp;
// Replication data
EAxis axis;
G4int nReplicas;
G4double width,offset;
G4bool consuming;
pVol->GetReplicationData(axis,nReplicas,width,offset,consuming);
assert(consuming);
switch (axis)
{
case kXAxis:
val=-width*0.5*(nReplicas-1)+width*replicaNo;
pVol->SetTranslation(G4ThreeVector(val,0,0));
point.setX(point.x()-val);
break;
case kYAxis:
val=-width*0.5*(nReplicas-1)+width*replicaNo;
pVol->SetTranslation(G4ThreeVector(0,val,0));
point.setY(point.y()-val);
break;
case kZAxis:
val=-width*0.5*(nReplicas-1)+width*replicaNo;
pVol->SetTranslation(G4ThreeVector(0,0,val));
point.setZ(point.z()-val);
break;
case kPhi:
val=-(offset+width*(replicaNo+0.5));
SetPhiTransformation(val,pVol);
cosv=cos(val);
sinv=sin(val);
tmp=point.x()*cosv-point.y()*sinv;
point.setY(point.x()*sinv+point.y()*cosv);
point.setX(tmp);
break;
case kRho:
// No setup required for radial case
default:
break;
}
}
// Setup transformation
void G4ReplicaNavigation::ComputeTransformation(const G4int replicaNo,
G4VPhysicalVolume *pVol) const
{
G4double val;
// Replication data
EAxis axis;
G4int nReplicas;
G4double width,offset;
G4bool consuming;
pVol->GetReplicationData(axis,nReplicas,width,offset,consuming);
assert(consuming);
switch (axis)
{
case kXAxis:
val=-width*0.5*(nReplicas-1)+width*replicaNo;
pVol->SetTranslation(G4ThreeVector(val,0,0));
break;
case kYAxis:
val=-width*0.5*(nReplicas-1)+width*replicaNo;
pVol->SetTranslation(G4ThreeVector(0,val,0));
break;
case kZAxis:
val=-width*0.5*(nReplicas-1)+width*replicaNo;
pVol->SetTranslation(G4ThreeVector(0,0,val));
break;
case kPhi:
val=-(offset+width*(replicaNo+0.5));
SetPhiTransformation(val);
break;
case kRho:
// No setup required for radial case
default:
break;
}
}
G4double G4ReplicaNavigation::ComputeStep(const G4ThreeVector &globalPoint,
const G4ThreeVector &globalDirection,
const G4ThreeVector &localPoint,
const G4ThreeVector &localDirection,
const G4double currentProposedStepLength,
G4double &newSafety,
G4NavigationHistory &history,
G4bool &validExitNormal,
G4ThreeVector &exitNormal,
G4bool &exiting,
G4bool &entering,
G4VPhysicalVolume *(*pBlockedPhysical),
G4int &blockedReplicaNo)
{
G4VPhysicalVolume *repPhysical,*motherPhysical;
G4VPhysicalVolume *samplePhysical,*blockedExitedVol=0;
G4LogicalVolume *repLogical;
G4VSolid *motherSolid;
G4ThreeVector repPoint,repDirection,sampleDirection;
G4double ourStep=currentProposedStepLength;
G4double ourSafety=kInfinity;
G4double sampleStep,sampleSafety;
G4int localNoDaughters,sampleNo;
G4int depth;
// Exiting normal optimisation
if (exiting&&validExitNormal)
{
if (localDirection.dot(exitNormal)>=kMinExitingNormalCosine)
{
// Block exited daughter volume
blockedExitedVol=*pBlockedPhysical;
ourSafety=0;
}
}
exiting=false;
entering=false;
repPhysical=history.GetTopVolume();
repLogical=repPhysical->GetLogicalVolume();
//
// Compute intersection with replica boundaries & replica safety
//
sampleSafety=DistanceToOut(history.GetTopVolume(),
history.GetTopReplicaNo(),
localPoint);
if (sampleSafety<ourSafety)
{
ourSafety=sampleSafety;
}
if (sampleSafety<ourStep)
{
sampleStep=DistanceToOut(history.GetTopVolume(),
history.GetTopReplicaNo(),
localPoint,
localDirection);
if (sampleStep<ourStep)
{
ourStep=sampleStep;
exiting=true;
validExitNormal=false;
}
}
depth=history.GetDepth()-1;
while (history.GetVolumeType(depth)==kReplica)
{
repPoint=history.GetTransform(depth).TransformPoint(globalPoint);
sampleSafety=DistanceToOut(history.GetVolume(depth),
history.GetReplicaNo(depth),
repPoint);
if (sampleSafety<ourSafety)
{
ourSafety=sampleSafety;
}
if (sampleSafety<ourStep)
{
sampleStep=DistanceToOut(history.GetVolume(depth),
history.GetReplicaNo(depth),
repPoint,
history.GetTransform(depth).TransformAxis(globalDirection));
if (sampleStep<ourStep)
{
ourStep=sampleStep;
exiting=true;
validExitNormal=false;
}
}
depth--;
}
// Compute mother safety & intersection
repPoint=history.GetTransform(depth).TransformPoint(globalPoint);
motherPhysical=history.GetVolume(depth);
motherSolid=motherPhysical->GetLogicalVolume()->GetSolid();
sampleSafety=motherSolid->DistanceToOut(repPoint);
if (sampleSafety<ourSafety)
{
ourSafety=sampleSafety;
}
// May need precision protection
if (sampleSafety<=ourStep)
{
repDirection=history.GetTransform(depth).TransformAxis(globalDirection);
sampleStep=motherSolid
->DistanceToOut(repPoint,
repDirection,
true,
&validExitNormal,
&exitNormal);
if (sampleStep<=ourStep)
{
ourStep=sampleStep;
exiting=true;
if (validExitNormal)
{
const G4RotationMatrix *rot=motherPhysical->GetRotation();
if (rot)
{
exitNormal*=rot->inverse();
}
}
}
else
{
validExitNormal=false;
}
}
//
// Compute daughter safeties & intersections
//
localNoDaughters=repLogical->GetNoDaughters();
for (sampleNo=localNoDaughters-1;sampleNo>=0;sampleNo--)
{
samplePhysical=repLogical->GetDaughter(sampleNo);
if (samplePhysical!=blockedExitedVol)
{
samplePhysical->Setup(repPhysical);
G4AffineTransform sampleTf(samplePhysical->GetRotation(),
samplePhysical->GetTranslation());
sampleTf.Invert();
const G4ThreeVector samplePoint=sampleTf.TransformPoint(localPoint);
const G4VSolid *sampleSolid=samplePhysical
->GetLogicalVolume()
->GetSolid();
const G4double sampleSafety=sampleSolid
->DistanceToIn(samplePoint);
if (sampleSafety<ourSafety)
{
ourSafety=sampleSafety;
}
if (sampleSafety<=ourStep)
{
sampleDirection=sampleTf.TransformAxis(localDirection);
const G4double sampleStep=sampleSolid
->DistanceToIn(samplePoint,
sampleDirection);
if (sampleStep<=ourStep)
{
ourStep=sampleStep;
entering=true;
exiting=false;
*pBlockedPhysical=samplePhysical;
blockedReplicaNo=-1;
}
}
}
}
newSafety=ourSafety;
return ourStep;
}
// Compute the isotropic distance to current volume's boundaries and
// to daughter volumes.
//
G4double G4ReplicaNavigation::ComputeSafety(const G4ThreeVector &globalPoint,
const G4ThreeVector &localPoint,
G4NavigationHistory &history,
// const G4NavigationHistory &history, // -> NON-CONST
const G4double pProposedMaxLength )
{
G4VPhysicalVolume *repPhysical,*motherPhysical;
G4VPhysicalVolume *samplePhysical,*blockedExitedVol=0;
G4LogicalVolume *repLogical;
G4VSolid *motherSolid;
G4ThreeVector repPoint;
G4double ourSafety=kInfinity;
G4double sampleSafety;
G4int localNoDaughters,sampleNo;
G4int depth;
repPhysical=history.GetTopVolume();
repLogical=repPhysical->GetLogicalVolume();
//
// Compute intersection with replica boundaries & replica safety
//
sampleSafety=DistanceToOut(history.GetTopVolume(),
history.GetTopReplicaNo(),
localPoint);
if (sampleSafety<ourSafety)
{
ourSafety=sampleSafety;
}
depth=history.GetDepth()-1;
while (history.GetVolumeType(depth)==kReplica)
{
repPoint=history.GetTransform(depth).TransformPoint(globalPoint);
sampleSafety=DistanceToOut(history.GetVolume(depth),
history.GetReplicaNo(depth),
repPoint);
if (sampleSafety<ourSafety)
{
ourSafety=sampleSafety;
}
depth--;
}
// Compute mother safety & intersection
repPoint=history.GetTransform(depth).TransformPoint(globalPoint);
motherPhysical=history.GetVolume(depth);
motherSolid=motherPhysical->GetLogicalVolume()->GetSolid();
sampleSafety=motherSolid->DistanceToOut(repPoint);
if (sampleSafety<ourSafety)
{
ourSafety=sampleSafety;
}
//
// Compute daughter safeties & intersections
//
localNoDaughters=repLogical->GetNoDaughters();
for (sampleNo=localNoDaughters-1;sampleNo>=0;sampleNo--)
{
samplePhysical=repLogical->GetDaughter(sampleNo);
if (samplePhysical!=blockedExitedVol)
{
samplePhysical->Setup(repPhysical);
G4AffineTransform sampleTf(samplePhysical->GetRotation(),
samplePhysical->GetTranslation());
sampleTf.Invert();
const G4ThreeVector samplePoint=sampleTf.TransformPoint(localPoint);
const G4VSolid *sampleSolid=samplePhysical
->GetLogicalVolume()
->GetSolid();
const G4double sampleSafety=sampleSolid
->DistanceToIn(samplePoint);
if (sampleSafety<ourSafety)
{
ourSafety=sampleSafety;
}
}
}
return ourSafety;
}
EInside G4ReplicaNavigation::BackLocate(G4NavigationHistory &history,
const G4ThreeVector &globalPoint,
G4ThreeVector &localPoint,
const G4bool &exiting,
G4bool &notKnownInside) const
{
G4VPhysicalVolume *pNRMother=0;
G4VSolid *motherSolid;
G4ThreeVector repPoint,goodPoint;
G4int mdepth,depth,cdepth;
EInside insideCode;
cdepth=history.GetDepth();
// Find non replicated mother
for (mdepth=cdepth-1;mdepth>=0;mdepth--)
{
if (history.GetVolumeType(mdepth)!=kReplica)
{
pNRMother=history.GetVolume(mdepth);
break;
}
}
if( pNRMother == 0 )
{
// All the tree of mother volumes were Replicas.
// This is an error, as the World volume must be a Placement
G4Exception( "G4ReplicaNavigation::BackLocate - World volume must be a Placement" );
}
motherSolid=pNRMother->GetLogicalVolume()->GetSolid();
goodPoint=history.GetTransform(mdepth).TransformPoint(globalPoint);
insideCode=motherSolid->Inside(goodPoint);
if (insideCode==kOutside||insideCode==kSurface&&exiting)
{
// Outside mother -> back up to mother level
// Locate.. in Navigator will back up one more level
// localPoint not reqd
history.BackLevel(cdepth-mdepth);
// localPoint=goodPoint;
}
else
{
notKnownInside=false;
// Still within replications
// Check down: if on outside stop at this level
for (depth=mdepth+1;depth<cdepth;depth++)
{
repPoint=history.GetTransform(depth).TransformPoint(globalPoint);
insideCode=Inside(history.GetVolume(depth),
history.GetReplicaNo(depth),
repPoint);
if (insideCode==kOutside||insideCode==kSurface&&exiting)
{
localPoint=goodPoint;
history.BackLevel(cdepth-depth);
return insideCode;
}
else
{
goodPoint=repPoint;
}
}
localPoint=history.GetTransform(depth).TransformPoint(globalPoint);
insideCode=Inside(history.GetVolume(depth),
history.GetReplicaNo(depth),
localPoint);
// If outside level, set localPoint = coordinates in reference system
// of *previous* level - location code in navigator will back up one
// level [And also manage blocking]
if (insideCode==kOutside||insideCode==kSurface&&exiting)
{
localPoint=goodPoint;
}
}
return insideCode;
}
@@ -0,0 +1,19 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4TouchableHistory.cc,v 2.1 1998/11/02 12:12:18 japost Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// class G4TouchableHistory Implementation
#include "G4TouchableHistory.hh"
G4TouchableHistory::~G4TouchableHistory()
{
}
@@ -0,0 +1,38 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4TransportationManager.cc,v 2.0 1998/07/02 17:06:47 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// G4TransportationManager
//
//
#include "G4TransportationManager.hh"
// The following inclusions should be left here, as only
// the constructor and destructor require them.
#include "G4PropagatorInField.hh"
#include "G4FieldManager.hh"
G4TransportationManager G4TransportationManager::fTransportationManager;
G4TransportationManager::G4TransportationManager()
{
fNavigatorForTracking= new G4Navigator() ;
fFieldManager= new G4FieldManager() ;
fPropagatorInField= new G4PropagatorInField( fNavigatorForTracking,
fFieldManager);
}
G4TransportationManager::~G4TransportationManager()
{
delete fNavigatorForTracking;
delete fPropagatorInField;
delete fFieldManager;
}
@@ -0,0 +1,528 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4VoxelNavigation.cc,v 2.6 1998/11/02 12:12:19 japost Exp $
// GEANT4 tag $Name: geant4-00 $
//
//
// class G4VoxelNavigation Implementation
//
// $ Id: $
//
// Modified by:
// J. Apostolakis, 29 Apr 98 Fixed error in LocateNextVoxel that
// ignored voxels at lower levels
#include "G4VoxelNavigation.hh"
G4double G4VoxelNavigation::ComputeStep(const G4ThreeVector &localPoint,
const G4ThreeVector &localDirection,
const G4double currentProposedStepLength,
G4double &newSafety,
G4NavigationHistory &history,
G4bool &validExitNormal,
G4ThreeVector &exitNormal,
G4bool &exiting,
G4bool &entering,
G4VPhysicalVolume *(*pBlockedPhysical),
G4int &blockedReplicaNo)
{
G4VPhysicalVolume *motherPhysical,*samplePhysical,*blockedExitedVol=0;
G4LogicalVolume *motherLogical;
G4VSolid *motherSolid;
G4ThreeVector sampleDirection;
G4double ourStep=currentProposedStepLength,motherSafety,ourSafety;
G4int localNoDaughters,sampleNo;
G4bool initialNode,noStep;
G4SmartVoxelNode *curVoxelNode;
G4int curNoVolumes,contentNo;
G4double voxelSafety;
motherPhysical=history.GetTopVolume();
motherLogical=motherPhysical->GetLogicalVolume();
motherSolid=motherLogical->GetSolid();
//
// Compute mother safety
//
motherSafety=motherSolid->DistanceToOut(localPoint);
ourSafety=motherSafety; // Working isotropic safety
//
// Compute daughter safeties & intersections
//
// Exiting normal optimisation
if (exiting&&validExitNormal)
{
if (localDirection.dot(exitNormal)>=kMinExitingNormalCosine)
{
// Block exited daughter volume
blockedExitedVol=*pBlockedPhysical;
ourSafety=0;
}
}
exiting=false;
entering=false;
localNoDaughters=motherLogical->GetNoDaughters();
fBList.Enlarge(localNoDaughters);
fBList.Reset();
initialNode=true;
noStep=true;
do {
curVoxelNode=fVoxelNode;
curNoVolumes=curVoxelNode->GetNoContained();
for (contentNo=curNoVolumes-1;contentNo>=0;contentNo--)
{
sampleNo=curVoxelNode->GetVolume(contentNo);
if (!fBList.IsBlocked(sampleNo))
{
fBList.BlockVolume(sampleNo);
samplePhysical=motherLogical->GetDaughter(sampleNo);
if (samplePhysical!=blockedExitedVol)
{
samplePhysical->Setup(motherPhysical);
G4AffineTransform sampleTf(samplePhysical->GetRotation(),
samplePhysical->GetTranslation());
sampleTf.Invert();
const G4ThreeVector samplePoint=sampleTf.TransformPoint(localPoint);
const G4VSolid *sampleSolid=samplePhysical
->GetLogicalVolume()
->GetSolid();
const G4double sampleSafety=sampleSolid
->DistanceToIn(samplePoint);
if (sampleSafety<ourSafety)
{
ourSafety=sampleSafety;
}
if (sampleSafety<=ourStep)
{
sampleDirection=sampleTf.TransformAxis(localDirection);
const G4double sampleStep=sampleSolid
->DistanceToIn(samplePoint,
sampleDirection);
if (sampleStep<=ourStep)
{
ourStep=sampleStep;
entering=true;
exiting=false;
*pBlockedPhysical=samplePhysical;
blockedReplicaNo=-1;
}
}
}
}
}
if (initialNode)
{
initialNode=false;
voxelSafety=ComputeVoxelSafety(localPoint);
if (voxelSafety<ourSafety)
{
ourSafety=voxelSafety;
}
if (currentProposedStepLength<ourSafety)
{
//
// Guaranteed physics limited
//
noStep=false;
entering=false;
exiting=false;
*pBlockedPhysical=0;
ourStep=kInfinity;
}
else
{
//
// Compute mother intersection if required
//
if (motherSafety<=ourStep)
{
G4double motherStep=motherSolid
->DistanceToOut(localPoint,
localDirection,
true,
&validExitNormal,
&exitNormal);
if (motherStep<=ourStep)
{
ourStep=motherStep;
exiting=true;
entering=false;
if (validExitNormal)
{
const G4RotationMatrix *rot=motherPhysical->GetRotation();
if (rot)
{
exitNormal*=rot->inverse();
}
}
}
else
{
validExitNormal=false;
}
}
}
newSafety=ourSafety;
}
if (noStep)
{
noStep=LocateNextVoxel(localPoint,
localDirection,
ourStep);
}
} while (noStep);
return ourStep;
}
// Compute safety from specified point to voxel boundaries
// using already located point
// o collected boundaries for most derived level
// o adjacent boundaries for previous levels
G4double G4VoxelNavigation::ComputeVoxelSafety(const G4ThreeVector&localPoint) const
{
G4SmartVoxelHeader *curHeader;
G4double voxelSafety,curNodeWidth;
G4double curNodeOffset,minCurCommonDelta,maxCurCommonDelta;
G4int minCurNodeNoDelta,maxCurNodeNoDelta;
G4int localVoxelDepth,curNodeNo;
EAxis curHeaderAxis;
localVoxelDepth=fVoxelDepth;
curHeader=fVoxelHeaderStack(localVoxelDepth);
curHeaderAxis=fVoxelAxisStack(localVoxelDepth);
curNodeNo=fVoxelNodeNoStack(localVoxelDepth);
curNodeWidth=fVoxelSliceWidthStack(localVoxelDepth);
// Compute linear intersection distance to boundaries of max/min
// to collected nodes at current level
curNodeOffset=curNodeNo*curNodeWidth;
maxCurNodeNoDelta=fVoxelNode->GetMaxEquivalentSliceNo()-curNodeNo;
minCurNodeNoDelta=curNodeNo-fVoxelNode->GetMinEquivalentSliceNo();
minCurCommonDelta=localPoint(curHeaderAxis)
-curHeader->GetMinExtent()
-curNodeOffset;
maxCurCommonDelta=curNodeWidth-minCurCommonDelta;
if (minCurNodeNoDelta<maxCurNodeNoDelta)
{
voxelSafety=minCurNodeNoDelta*curNodeWidth;
voxelSafety+=minCurCommonDelta;
}
else if (maxCurNodeNoDelta<minCurNodeNoDelta)
{
voxelSafety=maxCurNodeNoDelta*curNodeWidth;
voxelSafety+=maxCurCommonDelta;
}
else // (maxCurNodeNoDelta == minCurNodeNoDelta)
{
voxelSafety=minCurNodeNoDelta*curNodeWidth;
voxelSafety+=min(minCurCommonDelta,maxCurCommonDelta);
}
// Compute isotropic safety to boundaries of previous levels
// [NOT to collected boundaries]
while (localVoxelDepth>0&&voxelSafety>0)
{
localVoxelDepth--;
curHeader=fVoxelHeaderStack(localVoxelDepth);
curHeaderAxis=fVoxelAxisStack(localVoxelDepth);
curNodeNo=fVoxelNodeNoStack(localVoxelDepth);
curNodeWidth=fVoxelSliceWidthStack(localVoxelDepth);
curNodeOffset=curNodeNo*curNodeWidth;
minCurCommonDelta=localPoint(curHeaderAxis)
-curHeader->GetMinExtent()
-curNodeOffset;
maxCurCommonDelta=curNodeWidth-minCurCommonDelta;
if (minCurCommonDelta<voxelSafety)
{
voxelSafety=minCurCommonDelta;
}
if (maxCurCommonDelta<voxelSafety)
{
voxelSafety=maxCurCommonDelta;
}
}
if (voxelSafety<0)
{
voxelSafety=0;
}
return voxelSafety;
}
// Find the next voxel from the current voxel and point in the specified
// direction
//
// Return false if all voxels considered
// [current Step ends inside same voxel or leaves all voxels]
// true otherwise
// [the information on the next voxel is put into the set of
// fVoxel* variables & "stacks" ]
//
//
G4bool G4VoxelNavigation::LocateNextVoxel(const G4ThreeVector& localPoint,
const G4ThreeVector& localDirection,
const G4double currentStep)
{
G4SmartVoxelHeader *workHeader,*newHeader;
G4SmartVoxelProxy *newProxy;
G4SmartVoxelNode *newVoxelNode;
G4ThreeVector targetPoint,voxelPoint;
G4double workNodeWidth,workMinExtent,workCoord;
G4double minVal,maxVal,newDistance;
G4double newHeaderMin,newHeaderNodeWidth;
G4int depth, newDepth,workNodeNo,newNodeNo,newHeaderNoSlices;
EAxis workHeaderAxis,newHeaderAxis;
G4bool isNewVoxel=false;
G4double currentDistance= currentStep;
// Determine if end of Step within current voxel
for (depth=0;depth<fVoxelDepth;depth++)
{
targetPoint=localPoint+localDirection*currentDistance;
newDistance= currentDistance;
workHeader=fVoxelHeaderStack(depth);
workHeaderAxis=fVoxelAxisStack(depth);
workNodeNo=fVoxelNodeNoStack(depth);
workNodeWidth=fVoxelSliceWidthStack(depth);
workMinExtent=workHeader->GetMinExtent();
workCoord=targetPoint(workHeaderAxis);
minVal=workMinExtent+workNodeNo*workNodeWidth;
if (minVal<=workCoord+kCarTolerance*0.5)
{
maxVal=minVal+workNodeWidth;
if (maxVal<=workCoord-kCarTolerance*0.5)
{
// G4cout << "Must consider next voxel" << endl;
newNodeNo=workNodeNo+1;
newHeader=workHeader;
newDistance=(maxVal-localPoint(workHeaderAxis))/localDirection(workHeaderAxis);
isNewVoxel=true;
newDepth= depth;
}
}
else
{
newNodeNo=workNodeNo-1;
newHeader=workHeader;
newDistance=(minVal-localPoint(workHeaderAxis))/localDirection(workHeaderAxis);
isNewVoxel=true;
newDepth= depth;
}
currentDistance= newDistance;
}
targetPoint=localPoint+localDirection*currentDistance;
// Check if end of Step within collected boundaries of current voxel
depth=fVoxelDepth;
{
workHeader=fVoxelHeaderStack(depth);
workHeaderAxis=fVoxelAxisStack(depth);
workNodeNo=fVoxelNodeNoStack(depth);
workNodeWidth=fVoxelSliceWidthStack(depth);
workMinExtent=workHeader->GetMinExtent();
workCoord=targetPoint(workHeaderAxis);
minVal=workMinExtent+fVoxelNode->GetMinEquivalentSliceNo()*workNodeWidth;
if (minVal<=workCoord+kCarTolerance*0.5)
{
maxVal=workMinExtent+(fVoxelNode->GetMaxEquivalentSliceNo()+1)*workNodeWidth;
if (maxVal<=workCoord-kCarTolerance*0.5)
{
newNodeNo=fVoxelNode->GetMaxEquivalentSliceNo()+1;
newHeader=workHeader;
newDistance=(maxVal-localPoint(workHeaderAxis))/localDirection(workHeaderAxis);
isNewVoxel=true;
newDepth= depth;
}
}
else
{
newNodeNo=fVoxelNode->GetMinEquivalentSliceNo()-1;
newHeader=workHeader;
newDistance=(minVal-localPoint(workHeaderAxis))/localDirection(workHeaderAxis);
isNewVoxel=true;
newDepth= depth;
}
currentDistance= newDistance;
}
if (isNewVoxel)
{
// Compute new voxel & adjust voxel stack
//
// newNodeNo=Candidate node no at
// newDepth =refinement depth of crossed voxel boundary
// newHeader=Header for crossed voxel
// newDistance=distance to crossed voxel boundary (along the track)
//
if (newNodeNo<0||newNodeNo>=newHeader->GetNoSlices())
{
// Leaving mother volume
isNewVoxel=false;
}
else
{
// Compute intersection point on the least refined voxel boundary that is Hit
voxelPoint=localPoint+localDirection*newDistance;
fVoxelNodeNoStack(newDepth)=newNodeNo;
fVoxelDepth=newDepth;
newVoxelNode=0;
while (!newVoxelNode)
{
newProxy=newHeader->GetSlice(newNodeNo);
if (newProxy->IsNode())
{
newVoxelNode=newProxy->GetNode();
}
else
{
fVoxelDepth++;
newHeader=newProxy->GetHeader();
newHeaderAxis=newHeader->GetAxis();
newHeaderNoSlices=newHeader->GetNoSlices();
newHeaderMin=newHeader->GetMinExtent();
newHeaderNodeWidth=(newHeader->GetMaxExtent()-newHeaderMin)/newHeaderNoSlices;
newNodeNo=G4int ((voxelPoint(newHeaderAxis)-newHeaderMin)/newHeaderNodeWidth);
// Rounding protection
if (newNodeNo<0)
{
newNodeNo=0;
}
else if (newNodeNo>=newHeaderNoSlices)
{
newNodeNo=newHeaderNoSlices-1;
}
// Stack info for stepping
fVoxelAxisStack(fVoxelDepth)=newHeaderAxis;
fVoxelNoSlicesStack(fVoxelDepth)=newHeaderNoSlices;
fVoxelSliceWidthStack(fVoxelDepth)=newHeaderNodeWidth;
fVoxelNodeNoStack(fVoxelDepth)=newNodeNo;
fVoxelHeaderStack(fVoxelDepth)=newHeader;
}
}
fVoxelNode=newVoxelNode;
}
}
return isNewVoxel;
}
//-----------------------------------------------------------------------------
// Calculate the isotropic distance to the nearest boundary from the
// specified point in the local coordinate system.
// The localpoint utilised must be within the current volume.
G4double G4VoxelNavigation::ComputeSafety(const G4ThreeVector &localPoint,
const G4NavigationHistory &history,
const G4double pMaxLength )
{
G4VPhysicalVolume *motherPhysical,*samplePhysical;
G4LogicalVolume *motherLogical;
G4VSolid *motherSolid;
G4double motherSafety,ourSafety;
G4int localNoDaughters,sampleNo;
G4SmartVoxelNode *curVoxelNode;
G4int curNoVolumes,contentNo;
G4double voxelSafety;
motherPhysical=history.GetTopVolume();
motherLogical=motherPhysical->GetLogicalVolume();
motherSolid=motherLogical->GetSolid();
//
// Compute mother safety
//
motherSafety=motherSolid->DistanceToOut(localPoint);
ourSafety=motherSafety; // Working isotropic safety
//
// Compute daughter safeties
//
localNoDaughters=motherLogical->GetNoDaughters();
//
// Look only inside the current Voxel only (in the first version).
//
curVoxelNode=fVoxelNode;
curNoVolumes=curVoxelNode->GetNoContained();
for (contentNo=curNoVolumes-1;contentNo>=0;contentNo--)
{
sampleNo=curVoxelNode->GetVolume(contentNo);
samplePhysical=motherLogical->GetDaughter(sampleNo);
samplePhysical->Setup(motherPhysical);
G4AffineTransform sampleTf(samplePhysical->GetRotation(),
samplePhysical->GetTranslation());
sampleTf.Invert();
const G4ThreeVector samplePoint=sampleTf.TransformPoint(localPoint);
const G4VSolid *sampleSolid=samplePhysical ->GetLogicalVolume()
->GetSolid();
const G4double sampleSafety=sampleSolid
->DistanceToIn(samplePoint);
if (sampleSafety<ourSafety)
{
ourSafety=sampleSafety;
}
}
voxelSafety=ComputeVoxelSafety(localPoint);
if (voxelSafety<ourSafety)
{
ourSafety=voxelSafety;
}
return ourSafety;
}
G4VoxelNavigation::~G4VoxelNavigation()
{
#ifdef G4DEBUG_NAVIGATION
cout << "G4VoxelNavigation::~G4VoxelNavigation() called." << endl;
#endif
}