Import Geant4 8.3.0 source tree
This commit is contained in:
@@ -24,13 +24,12 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
// GEANT4 physics class: G4CrossSectionDataStore
|
||||
// F.W. Jones, TRIUMF, 19-NOV-97
|
||||
//
|
||||
|
||||
#include "G4CrossSectionDataStore.hh"
|
||||
#include "G4HadronicException.hh"
|
||||
#include "G4StableIsotopes.hh"
|
||||
#include "G4HadTmpUtil.hh"
|
||||
#include "Randomize.hh"
|
||||
|
||||
|
||||
G4double
|
||||
@@ -38,20 +37,186 @@ G4CrossSectionDataStore::GetCrossSection(const G4DynamicParticle* aParticle,
|
||||
const G4Element* anElement,
|
||||
G4double aTemperature)
|
||||
{
|
||||
if (NDataSetList == 0)
|
||||
{
|
||||
throw G4HadronicException(__FILE__, __LINE__,
|
||||
"G4CrossSectionDataStore: no data sets registered");
|
||||
return DBL_MIN;
|
||||
}
|
||||
for (G4int i = NDataSetList-1; i >= 0; i--) {
|
||||
if (DataSetList[i]->IsApplicable(aParticle, anElement))
|
||||
return DataSetList[i]->GetCrossSection(aParticle, anElement, aTemperature);
|
||||
}
|
||||
throw G4HadronicException(__FILE__, __LINE__,
|
||||
"G4CrossSectionDataStore: no applicable data set found "
|
||||
"for particle/element");
|
||||
return DBL_MIN;
|
||||
if (NDataSetList == 0)
|
||||
{
|
||||
throw G4HadronicException(__FILE__, __LINE__,
|
||||
"G4CrossSectionDataStore: no data sets registered");
|
||||
return DBL_MIN;
|
||||
}
|
||||
for (G4int i = NDataSetList-1; i >= 0; i--) {
|
||||
if (DataSetList[i]->IsApplicable(aParticle, anElement))
|
||||
return DataSetList[i]->GetCrossSection(aParticle,anElement,aTemperature);
|
||||
}
|
||||
throw G4HadronicException(__FILE__, __LINE__,
|
||||
"G4CrossSectionDataStore: no applicable data set found "
|
||||
"for particle/element");
|
||||
return DBL_MIN;
|
||||
}
|
||||
|
||||
|
||||
G4double
|
||||
G4CrossSectionDataStore::GetCrossSection(const G4DynamicParticle* aParticle,
|
||||
const G4Isotope* anIsotope,
|
||||
G4double aTemperature)
|
||||
{
|
||||
if (NDataSetList == 0)
|
||||
{
|
||||
throw G4HadronicException(__FILE__, __LINE__,
|
||||
"G4CrossSectionDataStore: no data sets registered");
|
||||
return DBL_MIN;
|
||||
}
|
||||
for (G4int i = NDataSetList-1; i >= 0; i--) {
|
||||
if (DataSetList[i]->IsZAApplicable(aParticle, anIsotope->GetZ(), anIsotope->GetN()))
|
||||
return DataSetList[i]->GetIsoCrossSection(aParticle,anIsotope,aTemperature);
|
||||
}
|
||||
throw G4HadronicException(__FILE__, __LINE__,
|
||||
"G4CrossSectionDataStore: no applicable data set found "
|
||||
"for particle/element");
|
||||
return DBL_MIN;
|
||||
}
|
||||
|
||||
|
||||
G4double
|
||||
G4CrossSectionDataStore::GetCrossSection(const G4DynamicParticle* aParticle,
|
||||
G4double Z, G4double A,
|
||||
G4double aTemperature)
|
||||
{
|
||||
if (NDataSetList == 0)
|
||||
{
|
||||
throw G4HadronicException(__FILE__, __LINE__,
|
||||
"G4CrossSectionDataStore: no data sets registered");
|
||||
return DBL_MIN;
|
||||
}
|
||||
for (G4int i = NDataSetList-1; i >= 0; i--) {
|
||||
if (DataSetList[i]->IsZAApplicable(aParticle, Z, A))
|
||||
return DataSetList[i]->GetIsoZACrossSection(aParticle,Z,A,aTemperature);
|
||||
}
|
||||
throw G4HadronicException(__FILE__, __LINE__,
|
||||
"G4CrossSectionDataStore: no applicable data set found "
|
||||
"for particle/element");
|
||||
return DBL_MIN;
|
||||
}
|
||||
|
||||
|
||||
G4double
|
||||
G4CrossSectionDataStore::GetCrossSection(const G4DynamicParticle* aParticle,
|
||||
const G4Material* aMaterial)
|
||||
{
|
||||
G4double sigma(0);
|
||||
G4double aTemp = aMaterial->GetTemperature();
|
||||
G4int nElements = aMaterial->GetNumberOfElements();
|
||||
const G4double* theAtomsPerVolumeVector = aMaterial->GetVecNbOfAtomsPerVolume();
|
||||
G4double xSection(0);
|
||||
|
||||
for(G4int i=0; i<nElements; i++) {
|
||||
xSection = GetCrossSection( aParticle, (*aMaterial->GetElementVector())[i], aTemp);
|
||||
sigma += theAtomsPerVolumeVector[i] * xSection;
|
||||
}
|
||||
|
||||
return sigma;
|
||||
}
|
||||
|
||||
|
||||
std::pair<G4double, G4double>
|
||||
G4CrossSectionDataStore::SelectRandomIsotope(const G4DynamicParticle* particle,
|
||||
const G4Material* aMaterial)
|
||||
{
|
||||
static G4StableIsotopes theDefaultIsotopes; // natural abundances and
|
||||
// stable isotopes
|
||||
G4double aTemp = aMaterial->GetTemperature();
|
||||
G4int nElements = aMaterial->GetNumberOfElements();
|
||||
const G4ElementVector* theElementVector = aMaterial->GetElementVector();
|
||||
const G4double* theAtomsPerVolumeVector = aMaterial->GetVecNbOfAtomsPerVolume();
|
||||
std::vector<std::vector<G4double> > awicsPerElement;
|
||||
std::vector<std::vector<G4double> > AvaluesPerElement;
|
||||
G4Element* anElement;
|
||||
|
||||
// Collect abundance weighted cross sections and A values for each isotope
|
||||
// in each element
|
||||
|
||||
for (G4int i = 0; i < nElements; i++) {
|
||||
anElement = (*theElementVector)[i];
|
||||
G4int nIsoPerElement = anElement->GetNumberOfIsotopes();
|
||||
std::vector<G4double> isoholder;
|
||||
std::vector<G4double> aholder;
|
||||
G4double iso_xs;
|
||||
|
||||
if (nIsoPerElement) { // user-defined isotope abundances
|
||||
G4IsotopeVector* isoVector = anElement->GetIsotopeVector();
|
||||
G4double* abundVector = anElement->GetRelativeAbundanceVector();
|
||||
for (G4int j = 0; j < nIsoPerElement; j++) {
|
||||
iso_xs = GetCrossSection(particle, (*isoVector)[j], aTemp);
|
||||
isoholder.push_back(abundVector[j]*iso_xs);
|
||||
aholder.push_back(G4double((*isoVector)[j]->GetN()));
|
||||
}
|
||||
|
||||
} else { // natural abundances
|
||||
G4int ZZ = G4lrint(anElement->GetZ());
|
||||
nIsoPerElement = theDefaultIsotopes.GetNumberOfIsotopes(ZZ);
|
||||
G4int index = theDefaultIsotopes.GetFirstIsotope(ZZ);
|
||||
G4double AA;
|
||||
G4double abundance;
|
||||
for (G4int j = 0; j < nIsoPerElement; j++) {
|
||||
AA = G4double(theDefaultIsotopes.GetIsotopeNucleonCount(index+j));
|
||||
aholder.push_back(AA);
|
||||
iso_xs = GetCrossSection(particle, G4double(ZZ), AA, aTemp);
|
||||
abundance = theDefaultIsotopes.GetAbundance(index+j)/100.0;
|
||||
isoholder.push_back(abundance*iso_xs);
|
||||
}
|
||||
}
|
||||
|
||||
awicsPerElement.push_back(isoholder);
|
||||
AvaluesPerElement.push_back(aholder);
|
||||
}
|
||||
|
||||
// Calculate running sums for isotope selection
|
||||
|
||||
G4double crossSectionTotal = 0;
|
||||
G4double xSectionPerElement;
|
||||
std::vector<G4double> runningSum;
|
||||
|
||||
for (G4int i=0; i < nElements; i++) {
|
||||
xSectionPerElement = 0;
|
||||
for (G4int j=0; j < G4int(awicsPerElement[i].size()); j++)
|
||||
xSectionPerElement += awicsPerElement[i][j];
|
||||
runningSum.push_back(theAtomsPerVolumeVector[i]*xSectionPerElement);
|
||||
crossSectionTotal += runningSum[i];
|
||||
}
|
||||
|
||||
// Compare random number to running sum over element xc to choose Z
|
||||
|
||||
// Initialize Z and A to first element and first isotope in case
|
||||
// cross section is zero
|
||||
|
||||
G4double ZZ = (*theElementVector)[0]->GetZ();
|
||||
G4double AA = AvaluesPerElement[0][0];
|
||||
if (crossSectionTotal != 0.) {
|
||||
G4double random = G4UniformRand();
|
||||
for(G4int i=0; i < nElements; i++) {
|
||||
if(i!=0) runningSum[i] += runningSum[i-1];
|
||||
if(random <= runningSum[i]/crossSectionTotal) {
|
||||
ZZ = ((*theElementVector)[i])->GetZ();
|
||||
|
||||
// Compare random number to running sum over isotope xc to choose A
|
||||
|
||||
G4int nIso = awicsPerElement[i].size();
|
||||
G4double* running = new G4double[nIso];
|
||||
for (G4int j=0; j < nIso; j++) {
|
||||
running[j] = awicsPerElement[i][j];
|
||||
if(j!=0) running[j] += running[j-1];
|
||||
}
|
||||
|
||||
G4double trial = G4UniformRand();
|
||||
for (G4int j=0; j < nIso; j++) {
|
||||
AA = AvaluesPerElement[i][j];
|
||||
if (trial <= running[j]/running[nIso-1]) break;
|
||||
}
|
||||
delete [] running;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return std::pair<G4double, G4double>(ZZ, AA);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user