Import Geant4 10.7.0.beta source tree
This commit is contained in:
@@ -23,14 +23,12 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4AdjointPosOnPhysVolGenerator class implementation
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Class Name: G4AdjointCrossSurfChecker
|
||||
// Author: L. Desorgher
|
||||
// Organisation: SpaceIT GmbH
|
||||
// Contract: ESA contract 21435/08/NL/AT
|
||||
// Customer: ESA/ESTEC
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Author: L. Desorgher, SpaceIT GmbH - 01.06.2006
|
||||
// Contract: ESA contract 21435/08/NL/AT
|
||||
// Customer: ESA/ESTEC
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4AdjointPosOnPhysVolGenerator.hh"
|
||||
#include "G4VSolid.hh"
|
||||
@@ -41,20 +39,21 @@
|
||||
#include "G4PhysicalVolumeStore.hh"
|
||||
#include "G4LogicalVolumeStore.hh"
|
||||
|
||||
G4ThreadLocal G4AdjointPosOnPhysVolGenerator* G4AdjointPosOnPhysVolGenerator::theInstance = 0;
|
||||
G4ThreadLocal G4AdjointPosOnPhysVolGenerator*
|
||||
G4AdjointPosOnPhysVolGenerator::theInstance = nullptr;
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
G4AdjointPosOnPhysVolGenerator* G4AdjointPosOnPhysVolGenerator::GetInstance()
|
||||
{
|
||||
if(!theInstance)
|
||||
if(theInstance == nullptr)
|
||||
{
|
||||
theInstance = new G4AdjointPosOnPhysVolGenerator;
|
||||
theInstance = new G4AdjointPosOnPhysVolGenerator;
|
||||
}
|
||||
return theInstance;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
G4AdjointPosOnPhysVolGenerator::~G4AdjointPosOnPhysVolGenerator()
|
||||
{
|
||||
@@ -63,168 +62,222 @@ G4AdjointPosOnPhysVolGenerator::~G4AdjointPosOnPhysVolGenerator()
|
||||
////////////////////////////////////////////////////
|
||||
//
|
||||
G4AdjointPosOnPhysVolGenerator::G4AdjointPosOnPhysVolGenerator()
|
||||
: theSolid(0), thePhysicalVolume(0),
|
||||
UseSphere(true), ModelOfSurfaceSource("OnSolid"),
|
||||
: UseSphere(true), ModelOfSurfaceSource("OnSolid"),
|
||||
AreaOfExtSurfaceOfThePhysicalVolume(0.), CosThDirComparedToNormal(0.)
|
||||
{
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
G4VPhysicalVolume* G4AdjointPosOnPhysVolGenerator::DefinePhysicalVolume(const G4String& aName)
|
||||
G4VPhysicalVolume*
|
||||
G4AdjointPosOnPhysVolGenerator::DefinePhysicalVolume(const G4String& aName)
|
||||
{
|
||||
thePhysicalVolume = 0;
|
||||
theSolid =0;
|
||||
G4PhysicalVolumeStore* thePhysVolStore =G4PhysicalVolumeStore::GetInstance();
|
||||
for ( unsigned int i=0; i< thePhysVolStore->size();i++){
|
||||
G4String vol_name =(*thePhysVolStore)[i]->GetName();
|
||||
if (vol_name == ""){
|
||||
vol_name = (*thePhysVolStore)[i]->GetLogicalVolume()->GetName();
|
||||
}
|
||||
if (vol_name == aName){
|
||||
thePhysicalVolume = (*thePhysVolStore)[i];
|
||||
}
|
||||
thePhysicalVolume = nullptr;
|
||||
theSolid = nullptr;
|
||||
G4PhysicalVolumeStore* thePhysVolStore = G4PhysicalVolumeStore::GetInstance();
|
||||
for ( unsigned int i=0; i< thePhysVolStore->size(); ++i )
|
||||
{
|
||||
G4String vol_name =(*thePhysVolStore)[i]->GetName();
|
||||
if (vol_name == "")
|
||||
{
|
||||
vol_name = (*thePhysVolStore)[i]->GetLogicalVolume()->GetName();
|
||||
}
|
||||
if (vol_name == aName)
|
||||
{
|
||||
thePhysicalVolume = (*thePhysVolStore)[i];
|
||||
}
|
||||
}
|
||||
if (thePhysicalVolume){
|
||||
theSolid = thePhysicalVolume->GetLogicalVolume()->GetSolid();
|
||||
ComputeTransformationFromPhysVolToWorld();
|
||||
/*AreaOfExtSurfaceOfThePhysicalVolume=ComputeAreaOfExtSurface(1.e-3);
|
||||
G4cout<<"Monte Carlo Estimate of the area of the external surface :"<<AreaOfExtSurfaceOfThePhysicalVolume/m/m<<" m2"<<std::endl;*/
|
||||
if (thePhysicalVolume != nullptr)
|
||||
{
|
||||
theSolid = thePhysicalVolume->GetLogicalVolume()->GetSolid();
|
||||
ComputeTransformationFromPhysVolToWorld();
|
||||
}
|
||||
else {
|
||||
G4cout<<"The physical volume with name "<<aName<<" does not exist!!"<<std::endl;
|
||||
G4cout<<"Before generating a source on an external surface of a volume you should select another physical volume"<<std::endl;
|
||||
else
|
||||
{
|
||||
G4cout << "The physical volume with name " << aName
|
||||
<< " does not exist!!" << G4endl;
|
||||
G4cout << "Before generating a source on an external surface " << G4endl
|
||||
<< "of a volume you should select another physical volume."
|
||||
<< G4endl;
|
||||
}
|
||||
return thePhysicalVolume;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
void G4AdjointPosOnPhysVolGenerator::DefinePhysicalVolume1(const G4String& aName)
|
||||
void
|
||||
G4AdjointPosOnPhysVolGenerator::DefinePhysicalVolume1(const G4String& aName)
|
||||
{
|
||||
thePhysicalVolume = DefinePhysicalVolume(aName);
|
||||
thePhysicalVolume = DefinePhysicalVolume(aName);
|
||||
}
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
G4double G4AdjointPosOnPhysVolGenerator::ComputeAreaOfExtSurface()
|
||||
{
|
||||
return ComputeAreaOfExtSurface(theSolid);
|
||||
return ComputeAreaOfExtSurface(theSolid);
|
||||
}
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
G4double G4AdjointPosOnPhysVolGenerator::ComputeAreaOfExtSurface(G4int NStats)
|
||||
{
|
||||
return ComputeAreaOfExtSurface(theSolid,NStats);
|
||||
return ComputeAreaOfExtSurface(theSolid,NStats);
|
||||
}
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
G4double G4AdjointPosOnPhysVolGenerator::ComputeAreaOfExtSurface(G4double eps)
|
||||
{
|
||||
return ComputeAreaOfExtSurface(theSolid,eps);
|
||||
}
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
G4double G4AdjointPosOnPhysVolGenerator::ComputeAreaOfExtSurface(G4VSolid* aSolid)
|
||||
G4double
|
||||
G4AdjointPosOnPhysVolGenerator::ComputeAreaOfExtSurface(G4VSolid* aSolid)
|
||||
{
|
||||
return ComputeAreaOfExtSurface(aSolid,1.e-3);
|
||||
}
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
G4double G4AdjointPosOnPhysVolGenerator::ComputeAreaOfExtSurface(G4VSolid* aSolid,G4int NStats)
|
||||
G4double
|
||||
G4AdjointPosOnPhysVolGenerator::ComputeAreaOfExtSurface(G4VSolid* aSolid,
|
||||
G4int NStats)
|
||||
{
|
||||
if (ModelOfSurfaceSource == "OnSolid" ){
|
||||
if (UseSphere){
|
||||
return ComputeAreaOfExtSurfaceStartingFromSphere(aSolid,NStats);
|
||||
}
|
||||
else {
|
||||
return ComputeAreaOfExtSurfaceStartingFromBox(aSolid,NStats);
|
||||
}
|
||||
if (ModelOfSurfaceSource == "OnSolid")
|
||||
{
|
||||
if (UseSphere)
|
||||
{
|
||||
return ComputeAreaOfExtSurfaceStartingFromSphere(aSolid,NStats);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ComputeAreaOfExtSurfaceStartingFromBox(aSolid,NStats);
|
||||
}
|
||||
}
|
||||
else {
|
||||
G4ThreeVector p,dir;
|
||||
if (ModelOfSurfaceSource == "ExternalSphere" ) return GenerateAPositionOnASphereBoundary(aSolid, p,dir);
|
||||
return GenerateAPositionOnABoxBoundary(aSolid, p,dir);
|
||||
else
|
||||
{
|
||||
G4ThreeVector p, dir;
|
||||
if (ModelOfSurfaceSource == "ExternalSphere")
|
||||
{
|
||||
return GenerateAPositionOnASphereBoundary(aSolid, p,dir);
|
||||
}
|
||||
return GenerateAPositionOnABoxBoundary(aSolid, p,dir);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
G4double G4AdjointPosOnPhysVolGenerator::ComputeAreaOfExtSurface(G4VSolid* aSolid,G4double eps)
|
||||
G4double
|
||||
G4AdjointPosOnPhysVolGenerator::ComputeAreaOfExtSurface(G4VSolid* aSolid,
|
||||
G4double eps)
|
||||
{
|
||||
G4int Nstats = G4int(1./(eps*eps));
|
||||
return ComputeAreaOfExtSurface(aSolid,Nstats);
|
||||
}
|
||||
////////////////////////////////////////////////////
|
||||
void G4AdjointPosOnPhysVolGenerator::GenerateAPositionOnTheExtSurfaceOfASolid(G4VSolid* aSolid,G4ThreeVector& p, G4ThreeVector& direction)
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
void G4AdjointPosOnPhysVolGenerator::
|
||||
GenerateAPositionOnTheExtSurfaceOfASolid(G4VSolid* aSolid, G4ThreeVector& p,
|
||||
G4ThreeVector& direction)
|
||||
{
|
||||
if (ModelOfSurfaceSource == "OnSolid" ){
|
||||
GenerateAPositionOnASolidBoundary(aSolid, p,direction);
|
||||
return;
|
||||
if (ModelOfSurfaceSource == "OnSolid")
|
||||
{
|
||||
GenerateAPositionOnASolidBoundary(aSolid, p,direction);
|
||||
return;
|
||||
}
|
||||
if (ModelOfSurfaceSource == "ExternalSphere" ) {
|
||||
GenerateAPositionOnASphereBoundary(aSolid, p, direction);
|
||||
return;
|
||||
}
|
||||
GenerateAPositionOnABoxBoundary(aSolid, p, direction);
|
||||
return;
|
||||
if (ModelOfSurfaceSource == "ExternalSphere")
|
||||
{
|
||||
GenerateAPositionOnASphereBoundary(aSolid, p, direction);
|
||||
return;
|
||||
}
|
||||
GenerateAPositionOnABoxBoundary(aSolid, p, direction);
|
||||
return;
|
||||
}
|
||||
////////////////////////////////////////////////////
|
||||
void G4AdjointPosOnPhysVolGenerator::GenerateAPositionOnTheExtSurfaceOfTheSolid(G4ThreeVector& p, G4ThreeVector& direction)
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
void G4AdjointPosOnPhysVolGenerator::
|
||||
GenerateAPositionOnTheExtSurfaceOfTheSolid(G4ThreeVector& p,
|
||||
G4ThreeVector& direction)
|
||||
{
|
||||
GenerateAPositionOnTheExtSurfaceOfASolid(theSolid,p,direction);
|
||||
}
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
G4double G4AdjointPosOnPhysVolGenerator::ComputeAreaOfExtSurfaceStartingFromBox(G4VSolid* aSolid,G4int Nstat)
|
||||
G4double G4AdjointPosOnPhysVolGenerator::
|
||||
ComputeAreaOfExtSurfaceStartingFromBox(G4VSolid* aSolid, G4int Nstat)
|
||||
{
|
||||
if ( Nstat <= 0 ) return 0.;
|
||||
if ( Nstat <= 0 ) { return 0.; }
|
||||
G4double area=1.;
|
||||
G4int i=0;
|
||||
G4int j=0;
|
||||
while (i<Nstat){
|
||||
G4ThreeVector p, direction;
|
||||
area = GenerateAPositionOnABoxBoundary( aSolid,p, direction);
|
||||
G4double dist_to_in = aSolid->DistanceToIn(p,direction);
|
||||
if (dist_to_in<kInfinity/2.) i++;
|
||||
j++;
|
||||
}
|
||||
area=area*double(i)/double(j);
|
||||
return area;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
G4double G4AdjointPosOnPhysVolGenerator::ComputeAreaOfExtSurfaceStartingFromSphere(G4VSolid* aSolid,G4int Nstat)
|
||||
{
|
||||
if ( Nstat <= 0 ) return 0.;
|
||||
G4double area=1.;
|
||||
G4int i=0;
|
||||
G4int j=0;
|
||||
while (i<Nstat){
|
||||
G4ThreeVector p, direction;
|
||||
area = GenerateAPositionOnASphereBoundary( aSolid,p, direction);
|
||||
G4double dist_to_in = aSolid->DistanceToIn(p,direction);
|
||||
if (dist_to_in<kInfinity/2.) i++;
|
||||
j++;
|
||||
}
|
||||
area=area*double(i)/double(j);
|
||||
return area;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
void G4AdjointPosOnPhysVolGenerator::GenerateAPositionOnASolidBoundary(G4VSolid* aSolid,G4ThreeVector& p, G4ThreeVector& direction)
|
||||
{
|
||||
G4bool find_pos =false;
|
||||
while (!find_pos){
|
||||
if (UseSphere) GenerateAPositionOnASphereBoundary( aSolid,p, direction);
|
||||
else GenerateAPositionOnABoxBoundary( aSolid,p, direction);
|
||||
G4int i=0, j=0;
|
||||
while (i<Nstat)
|
||||
{
|
||||
G4ThreeVector p, direction;
|
||||
area = GenerateAPositionOnABoxBoundary( aSolid,p, direction);
|
||||
G4double dist_to_in = aSolid->DistanceToIn(p,direction);
|
||||
if (dist_to_in<kInfinity/2.) {
|
||||
find_pos =true;
|
||||
p+= 0.999999*direction*dist_to_in;
|
||||
if (dist_to_in<kInfinity/2.) { ++i; }
|
||||
++j;
|
||||
}
|
||||
area=area*G4double(i)/G4double(j);
|
||||
return area;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
G4double G4AdjointPosOnPhysVolGenerator::
|
||||
ComputeAreaOfExtSurfaceStartingFromSphere(G4VSolid* aSolid, G4int Nstat)
|
||||
{
|
||||
if ( Nstat <= 0 ) { return 0.; }
|
||||
G4double area=1.;
|
||||
G4int i=0, j=0;
|
||||
while (i<Nstat)
|
||||
{
|
||||
G4ThreeVector p, direction;
|
||||
area = GenerateAPositionOnASphereBoundary( aSolid,p, direction);
|
||||
G4double dist_to_in = aSolid->DistanceToIn(p,direction);
|
||||
if (dist_to_in<kInfinity/2.) { ++i; }
|
||||
++j;
|
||||
}
|
||||
area=area*G4double(i)/G4double(j);
|
||||
return area;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
void G4AdjointPosOnPhysVolGenerator::
|
||||
GenerateAPositionOnASolidBoundary(G4VSolid* aSolid, G4ThreeVector& p,
|
||||
G4ThreeVector& direction)
|
||||
{
|
||||
G4bool find_pos = false;
|
||||
while (!find_pos)
|
||||
{
|
||||
if (UseSphere)
|
||||
{
|
||||
GenerateAPositionOnASphereBoundary( aSolid,p, direction );
|
||||
}
|
||||
else
|
||||
{
|
||||
GenerateAPositionOnABoxBoundary( aSolid,p, direction);
|
||||
}
|
||||
G4double dist_to_in = aSolid->DistanceToIn(p,direction);
|
||||
if (dist_to_in<kInfinity/2.)
|
||||
{
|
||||
find_pos = true;
|
||||
p += 0.999999*direction*dist_to_in;
|
||||
}
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
G4double G4AdjointPosOnPhysVolGenerator::GenerateAPositionOnASphereBoundary(G4VSolid* aSolid,G4ThreeVector& p, G4ThreeVector& direction)
|
||||
G4double G4AdjointPosOnPhysVolGenerator::
|
||||
GenerateAPositionOnASphereBoundary(G4VSolid* aSolid, G4ThreeVector& p,
|
||||
G4ThreeVector& direction)
|
||||
{
|
||||
G4double minX,maxX,minY,maxY,minZ,maxZ;
|
||||
|
||||
@@ -239,8 +292,9 @@ G4double G4AdjointPosOnPhysVolGenerator::GenerateAPositionOnASphereBoundary(G4VS
|
||||
aSolid->CalculateExtent(kYAxis,limit,origin,minY,maxY);
|
||||
aSolid->CalculateExtent(kZAxis,limit,origin,minZ,maxZ);
|
||||
|
||||
G4ThreeVector center = G4ThreeVector((minX+maxX)/2.,(minY+maxY)/2.,(minZ+maxZ)/2.);
|
||||
|
||||
G4ThreeVector center = G4ThreeVector((minX+maxX)/2.,
|
||||
(minY+maxY)/2.,
|
||||
(minZ+maxZ)/2.);
|
||||
G4double dX=(maxX-minX)/2.;
|
||||
G4double dY=(maxY-minY)/2.;
|
||||
G4double dZ=(maxZ-minZ)/2.;
|
||||
@@ -249,22 +303,25 @@ G4double G4AdjointPosOnPhysVolGenerator::GenerateAPositionOnASphereBoundary(G4VS
|
||||
|
||||
G4double cos_th2 = G4UniformRand();
|
||||
G4double theta = std::acos(std::sqrt(cos_th2));
|
||||
G4double phi=G4UniformRand()*3.1415926*2;
|
||||
G4double phi=G4UniformRand()*CLHEP::twopi;
|
||||
direction.setRThetaPhi(1.,theta,phi);
|
||||
direction=-direction;
|
||||
G4double cos_th = (1.-2.*G4UniformRand());
|
||||
theta = std::acos(cos_th);
|
||||
if (G4UniformRand() <0.5) theta=3.1415926-theta;
|
||||
phi=G4UniformRand()*3.1415926*2;
|
||||
if (G4UniformRand() < 0.5) { theta=CLHEP::pi-theta; }
|
||||
phi=G4UniformRand()*CLHEP::twopi;
|
||||
p.setRThetaPhi(r,theta,phi);
|
||||
p+=center;
|
||||
direction.rotateY(theta);
|
||||
direction.rotateZ(phi);
|
||||
return 4.*3.1415926*r*r;;
|
||||
return 4.*CLHEP::pi*r*r;;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
G4double G4AdjointPosOnPhysVolGenerator::GenerateAPositionOnABoxBoundary(G4VSolid* aSolid,G4ThreeVector& p, G4ThreeVector& direction)
|
||||
G4double G4AdjointPosOnPhysVolGenerator::
|
||||
GenerateAPositionOnABoxBoundary(G4VSolid* aSolid, G4ThreeVector& p,
|
||||
G4ThreeVector& direction)
|
||||
{
|
||||
|
||||
G4double ran_var,px,py,pz,minX,maxX,minY,maxY,minZ,maxZ;
|
||||
@@ -304,104 +361,124 @@ G4double G4AdjointPosOnPhysVolGenerator::GenerateAPositionOnABoxBoundary(G4VSoli
|
||||
G4double cos_th2 = G4UniformRand();
|
||||
G4double sth = std::sqrt(1.-cos_th2);
|
||||
G4double cth = std::sqrt(cos_th2);
|
||||
G4double phi=G4UniformRand()*3.1415926*2;
|
||||
G4double phi = G4UniformRand()*CLHEP::twopi;
|
||||
G4double dirX = sth*std::cos(phi);
|
||||
G4double dirY = sth*std::sin(phi);
|
||||
G4double dirZ = cth;
|
||||
if (ran_var <=XY_prob){ //on the XY faces
|
||||
G4double ran_var1=ran_var/XY_prob;
|
||||
G4double ranX=ran_var1;
|
||||
if (ran_var1<=0.5){
|
||||
pz=minZ;
|
||||
direction=G4ThreeVector(dirX,dirY,dirZ);
|
||||
ranX=ran_var1*2.;
|
||||
}
|
||||
else{
|
||||
pz=maxZ;
|
||||
direction=-G4ThreeVector(dirX,dirY,dirZ);
|
||||
ranX=(ran_var1-0.5)*2.;
|
||||
}
|
||||
G4double ranY=G4UniformRand();
|
||||
px=minX+(maxX-minX)*ranX;
|
||||
py=minY+(maxY-minY)*ranY;
|
||||
if (ran_var <=XY_prob) // on the XY faces
|
||||
{
|
||||
G4double ran_var1=ran_var/XY_prob;
|
||||
G4double ranX=ran_var1;
|
||||
if (ran_var1<=0.5)
|
||||
{
|
||||
pz=minZ;
|
||||
direction=G4ThreeVector(dirX,dirY,dirZ);
|
||||
ranX=ran_var1*2.;
|
||||
}
|
||||
else
|
||||
{
|
||||
pz=maxZ;
|
||||
direction=-G4ThreeVector(dirX,dirY,dirZ);
|
||||
ranX=(ran_var1-0.5)*2.;
|
||||
}
|
||||
G4double ranY=G4UniformRand();
|
||||
px=minX+(maxX-minX)*ranX;
|
||||
py=minY+(maxY-minY)*ranY;
|
||||
}
|
||||
else if (ran_var <=(XY_prob+YZ_prob)){ //on the YZ faces
|
||||
G4double ran_var1=(ran_var-XY_prob)/YZ_prob;
|
||||
G4double ranY=ran_var1;
|
||||
if (ran_var1<=0.5){
|
||||
px=minX;
|
||||
direction=G4ThreeVector(dirZ,dirX,dirY);
|
||||
ranY=ran_var1*2.;
|
||||
}
|
||||
else{
|
||||
px=maxX;
|
||||
direction=-G4ThreeVector(dirZ,dirX,dirY);
|
||||
ranY=(ran_var1-0.5)*2.;
|
||||
}
|
||||
G4double ranZ=G4UniformRand();
|
||||
py=minY+(maxY-minY)*ranY;
|
||||
pz=minZ+(maxZ-minZ)*ranZ;
|
||||
|
||||
else if (ran_var <=(XY_prob+YZ_prob)) // on the YZ faces
|
||||
{
|
||||
G4double ran_var1=(ran_var-XY_prob)/YZ_prob;
|
||||
G4double ranY=ran_var1;
|
||||
if (ran_var1<=0.5)
|
||||
{
|
||||
px=minX;
|
||||
direction=G4ThreeVector(dirZ,dirX,dirY);
|
||||
ranY=ran_var1*2.;
|
||||
}
|
||||
else
|
||||
{
|
||||
px=maxX;
|
||||
direction=-G4ThreeVector(dirZ,dirX,dirY);
|
||||
ranY=(ran_var1-0.5)*2.;
|
||||
}
|
||||
G4double ranZ=G4UniformRand();
|
||||
py=minY+(maxY-minY)*ranY;
|
||||
pz=minZ+(maxZ-minZ)*ranZ;
|
||||
}
|
||||
else{ //on the ZX faces
|
||||
G4double ran_var1=(ran_var-XY_prob-YZ_prob)/ZX_prob;
|
||||
G4double ranZ=ran_var1;
|
||||
if (ran_var1<=0.5){
|
||||
py=minY;
|
||||
direction=G4ThreeVector(dirY,dirZ,dirX);
|
||||
ranZ=ran_var1*2.;
|
||||
}
|
||||
else{
|
||||
py=maxY;
|
||||
direction=-G4ThreeVector(dirY,dirZ,dirX);
|
||||
ranZ=(ran_var1-0.5)*2.;
|
||||
}
|
||||
G4double ranX=G4UniformRand();
|
||||
px=minX+(maxX-minX)*ranX;
|
||||
pz=minZ+(maxZ-minZ)*ranZ;
|
||||
else // on the ZX faces
|
||||
{
|
||||
G4double ran_var1=(ran_var-XY_prob-YZ_prob)/ZX_prob;
|
||||
G4double ranZ=ran_var1;
|
||||
if (ran_var1<=0.5)
|
||||
{
|
||||
py=minY;
|
||||
direction=G4ThreeVector(dirY,dirZ,dirX);
|
||||
ranZ=ran_var1*2.;
|
||||
}
|
||||
else
|
||||
{
|
||||
py=maxY;
|
||||
direction=-G4ThreeVector(dirY,dirZ,dirX);
|
||||
ranZ=(ran_var1-0.5)*2.;
|
||||
}
|
||||
G4double ranX=G4UniformRand();
|
||||
px=minX+(maxX-minX)*ranX;
|
||||
pz=minZ+(maxZ-minZ)*ranZ;
|
||||
}
|
||||
|
||||
p=G4ThreeVector(px,py,pz);
|
||||
return area;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
void G4AdjointPosOnPhysVolGenerator::GenerateAPositionOnTheExtSurfaceOfThePhysicalVolume(G4ThreeVector& p, G4ThreeVector& direction)
|
||||
void G4AdjointPosOnPhysVolGenerator::
|
||||
GenerateAPositionOnTheExtSurfaceOfThePhysicalVolume(G4ThreeVector& p,
|
||||
G4ThreeVector& direction)
|
||||
{
|
||||
if (!thePhysicalVolume) {
|
||||
G4cout<<"Before generating a source on an external surface of volume you should select a physical volume"<<std::endl;
|
||||
return;
|
||||
};
|
||||
if (thePhysicalVolume == nullptr)
|
||||
{
|
||||
G4cout << "Before generating a source on an external surface" << G4endl
|
||||
<< "of volume you should select a physical volume" << G4endl;
|
||||
return;
|
||||
}
|
||||
GenerateAPositionOnTheExtSurfaceOfTheSolid(p,direction);
|
||||
p = theTransformationFromPhysVolToWorld.TransformPoint(p);
|
||||
direction = theTransformationFromPhysVolToWorld.TransformAxis(direction);
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
void G4AdjointPosOnPhysVolGenerator::GenerateAPositionOnTheExtSurfaceOfThePhysicalVolume(G4ThreeVector& p, G4ThreeVector& direction,
|
||||
G4double& costh_to_normal)
|
||||
void G4AdjointPosOnPhysVolGenerator::
|
||||
GenerateAPositionOnTheExtSurfaceOfThePhysicalVolume(G4ThreeVector& p,
|
||||
G4ThreeVector& direction,
|
||||
G4double& costh_to_normal)
|
||||
{
|
||||
GenerateAPositionOnTheExtSurfaceOfThePhysicalVolume(p, direction);
|
||||
costh_to_normal = CosThDirComparedToNormal;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
void G4AdjointPosOnPhysVolGenerator::ComputeTransformationFromPhysVolToWorld()
|
||||
{
|
||||
G4VPhysicalVolume* daughter =thePhysicalVolume;
|
||||
G4VPhysicalVolume* daughter = thePhysicalVolume;
|
||||
G4LogicalVolume* mother = thePhysicalVolume->GetMotherLogical();
|
||||
theTransformationFromPhysVolToWorld = G4AffineTransform();
|
||||
G4PhysicalVolumeStore* thePhysVolStore =G4PhysicalVolumeStore::GetInstance();
|
||||
while (mother){
|
||||
theTransformationFromPhysVolToWorld *=
|
||||
G4AffineTransform(daughter->GetFrameRotation(),daughter->GetObjectTranslation());
|
||||
for ( unsigned int i=0; i< thePhysVolStore->size();i++){
|
||||
if ((*thePhysVolStore)[i]->GetLogicalVolume() == mother){
|
||||
daughter = (*thePhysVolStore)[i];
|
||||
mother =daughter->GetMotherLogical();
|
||||
break;
|
||||
};
|
||||
}
|
||||
G4PhysicalVolumeStore* thePhysVolStore = G4PhysicalVolumeStore::GetInstance();
|
||||
while (mother != nullptr)
|
||||
{
|
||||
theTransformationFromPhysVolToWorld *=
|
||||
G4AffineTransform(daughter->GetFrameRotation(),
|
||||
daughter->GetObjectTranslation());
|
||||
for ( unsigned int i=0; i<thePhysVolStore->size(); ++i )
|
||||
{
|
||||
if ((*thePhysVolStore)[i]->GetLogicalVolume() == mother)
|
||||
{
|
||||
daughter = (*thePhysVolStore)[i];
|
||||
mother = daughter->GetMotherLogical();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user