Import Geant4 10.7.0 source tree
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Optical Photon Rayleigh Scattering Class Implementation
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
@@ -36,7 +36,7 @@
|
||||
// Version: 1.0
|
||||
// Created: 1996-05-31
|
||||
// Author: Juliet Armstrong
|
||||
// Updated: 2014-10-10 - This version calculates the Rayleigh scattering
|
||||
// Updated: 2014-10-10 - This version calculates the Rayleigh scattering
|
||||
// length for more materials than just Water (although the Water
|
||||
// default is kept). To do this the user would need to specify the
|
||||
// ISOTHERMAL_COMPRESSIBILITY as a material property and
|
||||
@@ -64,16 +64,19 @@
|
||||
#include "G4ios.hh"
|
||||
#include "G4PhysicalConstants.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
#include "G4OpticalParameters.hh"
|
||||
#include "G4OpProcessSubType.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
G4OpRayleigh::G4OpRayleigh(const G4String& processName, G4ProcessType type)
|
||||
: G4VDiscreteProcess(processName, type)
|
||||
: G4VDiscreteProcess(processName, type)
|
||||
{
|
||||
Initialise();
|
||||
SetProcessSubType(fOpRayleigh);
|
||||
thePhysicsTable = nullptr;
|
||||
|
||||
if (verboseLevel > 0) {
|
||||
if(verboseLevel > 0)
|
||||
{
|
||||
G4cout << GetProcessName() << " is created " << G4endl;
|
||||
}
|
||||
}
|
||||
@@ -82,25 +85,38 @@ G4OpRayleigh::G4OpRayleigh(const G4String& processName, G4ProcessType type)
|
||||
G4OpRayleigh::~G4OpRayleigh()
|
||||
{
|
||||
// VI: inside this PhysicsTable all properties are unique
|
||||
// it is not possible to destroy
|
||||
if (thePhysicsTable) {
|
||||
// it is not possible to destroy
|
||||
if(thePhysicsTable)
|
||||
{
|
||||
delete thePhysicsTable;
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
G4VParticleChange*
|
||||
G4OpRayleigh::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep)
|
||||
void G4OpRayleigh::PreparePhysicsTable(const G4ParticleDefinition&)
|
||||
{
|
||||
Initialise();
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void G4OpRayleigh::Initialise()
|
||||
{
|
||||
SetVerboseLevel(G4OpticalParameters::Instance()->GetRayleighVerboseLevel());
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
G4VParticleChange* G4OpRayleigh::PostStepDoIt(const G4Track& aTrack,
|
||||
const G4Step& aStep)
|
||||
{
|
||||
aParticleChange.Initialize(aTrack);
|
||||
const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();
|
||||
|
||||
if (verboseLevel > 1) {
|
||||
if(verboseLevel > 1)
|
||||
{
|
||||
G4cout << "OpRayleigh: Scattering Photon!" << G4endl
|
||||
<< "Old Momentum Direction: "
|
||||
<< aParticle->GetMomentumDirection() << G4endl
|
||||
<< "Old Polarization: "
|
||||
<< aParticle->GetPolarization() << G4endl;
|
||||
<< "Old Momentum Direction: " << aParticle->GetMomentumDirection()
|
||||
<< G4endl << "Old Polarization: " << aParticle->GetPolarization()
|
||||
<< G4endl;
|
||||
}
|
||||
|
||||
G4double cosTheta;
|
||||
@@ -109,107 +125,117 @@ G4OpRayleigh::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep)
|
||||
G4double rand;
|
||||
G4double cost, sint, sinphi, cosphi;
|
||||
|
||||
do {
|
||||
// Try to simulate the scattered photon momentum direction
|
||||
// w.r.t. the initial photon momentum direction
|
||||
cost = G4UniformRand();
|
||||
sint = std::sqrt(1.-cost*cost);
|
||||
// consider for the angle 90-180 degrees
|
||||
if (G4UniformRand() < 0.5) cost = -cost;
|
||||
do
|
||||
{
|
||||
// Try to simulate the scattered photon momentum direction
|
||||
// w.r.t. the initial photon momentum direction
|
||||
cost = G4UniformRand();
|
||||
sint = std::sqrt(1. - cost * cost);
|
||||
// consider for the angle 90-180 degrees
|
||||
if(G4UniformRand() < 0.5)
|
||||
cost = -cost;
|
||||
|
||||
// simulate the phi angle
|
||||
rand = twopi*G4UniformRand();
|
||||
sinphi = std::sin(rand);
|
||||
cosphi = std::cos(rand);
|
||||
// simulate the phi angle
|
||||
rand = twopi * G4UniformRand();
|
||||
sinphi = std::sin(rand);
|
||||
cosphi = std::cos(rand);
|
||||
|
||||
// construct the new momentum direction
|
||||
newMomDir.set(sint*cosphi, sint*sinphi, cost);
|
||||
oldMomDir = aParticle->GetMomentumDirection();
|
||||
newMomDir.rotateUz(oldMomDir);
|
||||
// construct the new momentum direction
|
||||
newMomDir.set(sint * cosphi, sint * sinphi, cost);
|
||||
oldMomDir = aParticle->GetMomentumDirection();
|
||||
newMomDir.rotateUz(oldMomDir);
|
||||
|
||||
// calculate the new polarization direction
|
||||
// The new polarization needs to be in the same plane as the new
|
||||
// momentum direction and the old polarization direction
|
||||
oldPol = aParticle->GetPolarization();
|
||||
newPol = (oldPol - newMomDir.dot(oldPol) * newMomDir).unit();
|
||||
// calculate the new polarization direction
|
||||
// The new polarization needs to be in the same plane as the new
|
||||
// momentum direction and the old polarization direction
|
||||
oldPol = aParticle->GetPolarization();
|
||||
newPol = (oldPol - newMomDir.dot(oldPol) * newMomDir).unit();
|
||||
|
||||
// There is a corner case, where the new momentum direction
|
||||
// is the same as old polarization direction:
|
||||
// random generate the azimuthal angle w.r.t. new momentum direction
|
||||
if (newPol.mag() == 0.) {
|
||||
rand = G4UniformRand()*twopi;
|
||||
newPol.set(std::cos(rand), std::sin(rand), 0.);
|
||||
newPol.rotateUz(newMomDir);
|
||||
} else {
|
||||
// There are two directions perpendicular to the new momentum direction
|
||||
if (G4UniformRand() < 0.5) newPol = -newPol;
|
||||
}
|
||||
// There is a corner case, where the new momentum direction
|
||||
// is the same as old polarization direction:
|
||||
// random generate the azimuthal angle w.r.t. new momentum direction
|
||||
if(newPol.mag() == 0.)
|
||||
{
|
||||
rand = G4UniformRand() * twopi;
|
||||
newPol.set(std::cos(rand), std::sin(rand), 0.);
|
||||
newPol.rotateUz(newMomDir);
|
||||
}
|
||||
else
|
||||
{
|
||||
// There are two directions perpendicular to the new momentum direction
|
||||
if(G4UniformRand() < 0.5)
|
||||
newPol = -newPol;
|
||||
}
|
||||
|
||||
// simulate according to the distribution cos^2(theta)
|
||||
cosTheta = newPol.dot(oldPol);
|
||||
// Loop checking, 13-Aug-2015, Peter Gumplinger
|
||||
} while (std::pow(cosTheta,2) < G4UniformRand());
|
||||
// simulate according to the distribution cos^2(theta)
|
||||
cosTheta = newPol.dot(oldPol);
|
||||
// Loop checking, 13-Aug-2015, Peter Gumplinger
|
||||
} while(std::pow(cosTheta, 2) < G4UniformRand());
|
||||
|
||||
aParticleChange.ProposePolarization(newPol);
|
||||
aParticleChange.ProposeMomentumDirection(newMomDir);
|
||||
aParticleChange.ProposePolarization(newPol);
|
||||
aParticleChange.ProposeMomentumDirection(newMomDir);
|
||||
|
||||
if (verboseLevel > 1) {
|
||||
G4cout << "New Polarization: " << newPol << G4endl
|
||||
<< "Polarization Change: "
|
||||
<< *(aParticleChange.GetPolarization()) << G4endl
|
||||
<< "New Momentum Direction: " << newMomDir << G4endl
|
||||
<< "Momentum Change: " << *(aParticleChange.GetMomentumDirection())
|
||||
<< G4endl;
|
||||
}
|
||||
if(verboseLevel > 1)
|
||||
{
|
||||
G4cout << "New Polarization: " << newPol << G4endl
|
||||
<< "Polarization Change: " << *(aParticleChange.GetPolarization())
|
||||
<< G4endl << "New Momentum Direction: " << newMomDir << G4endl
|
||||
<< "Momentum Change: " << *(aParticleChange.GetMomentumDirection())
|
||||
<< G4endl;
|
||||
}
|
||||
|
||||
return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
|
||||
return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void G4OpRayleigh::BuildPhysicsTable(const G4ParticleDefinition&)
|
||||
{
|
||||
if (thePhysicsTable) {
|
||||
//thePhysicsTable->clearAndDestroy();
|
||||
if(thePhysicsTable)
|
||||
{
|
||||
// thePhysicsTable->clearAndDestroy();
|
||||
delete thePhysicsTable;
|
||||
thePhysicsTable = nullptr;
|
||||
}
|
||||
|
||||
const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
|
||||
const size_t numOfMaterials = G4Material::GetNumberOfMaterials();
|
||||
thePhysicsTable = new G4PhysicsTable(numOfMaterials);
|
||||
const size_t numOfMaterials = G4Material::GetNumberOfMaterials();
|
||||
thePhysicsTable = new G4PhysicsTable(numOfMaterials);
|
||||
|
||||
for (size_t i=0; i<numOfMaterials; ++i) {
|
||||
G4Material* material = (*theMaterialTable)[i];
|
||||
for(size_t i = 0; i < numOfMaterials; ++i)
|
||||
{
|
||||
G4Material* material = (*theMaterialTable)[i];
|
||||
G4MaterialPropertiesTable* matProp = material->GetMaterialPropertiesTable();
|
||||
G4PhysicsOrderedFreeVector* rayleigh = nullptr;
|
||||
if (matProp) {
|
||||
if(matProp)
|
||||
{
|
||||
rayleigh = matProp->GetProperty(kRAYLEIGH);
|
||||
if (rayleigh == nullptr) rayleigh = CalculateRayleighMeanFreePaths(material);
|
||||
if(rayleigh == nullptr)
|
||||
rayleigh = CalculateRayleighMeanFreePaths(material);
|
||||
}
|
||||
thePhysicsTable->insertAt(i, rayleigh);
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
G4double G4OpRayleigh::GetMeanFreePath(const G4Track& aTrack,
|
||||
G4double ,
|
||||
G4double G4OpRayleigh::GetMeanFreePath(const G4Track& aTrack, G4double,
|
||||
G4ForceCondition*)
|
||||
{
|
||||
G4PhysicsOrderedFreeVector* rayleigh =
|
||||
static_cast<G4PhysicsOrderedFreeVector*>
|
||||
((*thePhysicsTable)(aTrack.GetMaterial()->GetIndex()));
|
||||
static_cast<G4PhysicsOrderedFreeVector*>(
|
||||
(*thePhysicsTable)(aTrack.GetMaterial()->GetIndex()));
|
||||
|
||||
G4double rsLength = DBL_MAX;
|
||||
if (rayleigh) {
|
||||
rsLength =rayleigh->Value(aTrack.GetDynamicParticle()->GetTotalMomentum(),
|
||||
idx_rslength);
|
||||
if(rayleigh)
|
||||
{
|
||||
rsLength = rayleigh->Value(aTrack.GetDynamicParticle()->GetTotalMomentum(),
|
||||
idx_rslength);
|
||||
}
|
||||
return rsLength;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
G4PhysicsOrderedFreeVector*
|
||||
G4OpRayleigh::CalculateRayleighMeanFreePaths(const G4Material* material) const
|
||||
G4PhysicsOrderedFreeVector* G4OpRayleigh::CalculateRayleighMeanFreePaths(
|
||||
const G4Material* material) const
|
||||
{
|
||||
G4MaterialPropertiesTable* MPT = material->GetMaterialPropertiesTable();
|
||||
|
||||
@@ -217,52 +243,62 @@ G4OpRayleigh::CalculateRayleighMeanFreePaths(const G4Material* material) const
|
||||
// compatibility use a constant if the material is "Water". If the material
|
||||
// doesn't have an ISOTHERMAL_COMPRESSIBILITY constant then return
|
||||
G4double betat;
|
||||
if (material->GetName() == "Water") {
|
||||
betat = 7.658e-23*m3/MeV;
|
||||
if(material->GetName() == "Water")
|
||||
{
|
||||
betat = 7.658e-23 * m3 / MeV;
|
||||
}
|
||||
else if (MPT->ConstPropertyExists(kISOTHERMAL_COMPRESSIBILITY)) {
|
||||
else if(MPT->ConstPropertyExists(kISOTHERMAL_COMPRESSIBILITY))
|
||||
{
|
||||
betat = MPT->GetConstProperty(kISOTHERMAL_COMPRESSIBILITY);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// If the material doesn't have a RINDEX property vector then return
|
||||
G4MaterialPropertyVector* rIndex = MPT->GetProperty(kRINDEX);
|
||||
if (rIndex == nullptr) return nullptr;
|
||||
if(rIndex == nullptr)
|
||||
return nullptr;
|
||||
|
||||
// Retrieve the optional scale factor (scales the scattering length)
|
||||
G4double scaleFactor = 1.0;
|
||||
if (MPT->ConstPropertyExists(kRS_SCALE_FACTOR)) {
|
||||
if(MPT->ConstPropertyExists(kRS_SCALE_FACTOR))
|
||||
{
|
||||
scaleFactor = MPT->GetConstProperty(kRS_SCALE_FACTOR);
|
||||
}
|
||||
|
||||
// Retrieve the material temperature. For backwards compatibility use a
|
||||
// constant if the material is "Water"
|
||||
G4double temperature;
|
||||
if (material->GetName() == "Water") {
|
||||
temperature = 283.15*kelvin; // Temperature of water is 10 degrees celsius
|
||||
if(material->GetName() == "Water")
|
||||
{
|
||||
temperature =
|
||||
283.15 * kelvin; // Temperature of water is 10 degrees celsius
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
temperature = material->GetTemperature();
|
||||
}
|
||||
|
||||
G4PhysicsOrderedFreeVector* rayleighMFPs = new G4PhysicsOrderedFreeVector();
|
||||
// This calculates the meanFreePath via the Einstein-Smoluchowski formula
|
||||
const G4double c1 = scaleFactor * betat * temperature * k_Boltzmann / (6.0*pi);
|
||||
const G4double c1 =
|
||||
scaleFactor * betat * temperature * k_Boltzmann / (6.0 * pi);
|
||||
|
||||
for (size_t uRIndex = 0; uRIndex < rIndex->GetVectorLength(); ++uRIndex)
|
||||
for(size_t uRIndex = 0; uRIndex < rIndex->GetVectorLength(); ++uRIndex)
|
||||
{
|
||||
const G4double energy = rIndex->Energy(uRIndex);
|
||||
const G4double energy = rIndex->Energy(uRIndex);
|
||||
const G4double rIndexSquared = (*rIndex)[uRIndex] * (*rIndex)[uRIndex];
|
||||
const G4double xlambda = h_Planck * c_light / energy;
|
||||
const G4double c2 = std::pow(twopi/xlambda,4);
|
||||
const G4double xlambda = h_Planck * c_light / energy;
|
||||
const G4double c2 = std::pow(twopi / xlambda, 4);
|
||||
const G4double c3 =
|
||||
std::pow(((rIndexSquared-1.0)*(rIndexSquared+2.0)/3.0),2);
|
||||
std::pow(((rIndexSquared - 1.0) * (rIndexSquared + 2.0) / 3.0), 2);
|
||||
|
||||
const G4double meanFreePath = 1.0 / (c1*c2*c3);
|
||||
const G4double meanFreePath = 1.0 / (c1 * c2 * c3);
|
||||
|
||||
if( verboseLevel > 0) {
|
||||
if(verboseLevel > 0)
|
||||
{
|
||||
G4cout << energy << "MeV\t" << meanFreePath << "mm" << G4endl;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user