Import Geant4 11.2.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2023-06-30 09:09:57 +02:00
parent aef78ca386
commit dd1f179cda
3780 changed files with 212808 additions and 142780 deletions
@@ -28,6 +28,7 @@
#include "G4PhysicalConstants.hh"
#include "G4BetaDecayType.hh"
#include "G4BetaDecayCorrections.hh"
#include "G4Pow.hh"
G4BetaDecayCorrections::G4BetaDecayCorrections(const G4int theZ, const G4int theA)
: Z(theZ), A(theA)
@@ -36,14 +37,20 @@ G4BetaDecayCorrections::G4BetaDecayCorrections(const G4int theZ, const G4int the
alphaZ = fine_structure_const*Z;
// Nuclear radius in units of hbar/m_e/c
Rnuc = 0.5*fine_structure_const*std::pow(A, 0.33333);
G4double a13 = G4Pow::GetInstance()->Z13(A);
Rnuc = 0.5*fine_structure_const*a13;
// Electron screening potential in units of electron mass
V0 = 1.13*fine_structure_const*fine_structure_const
*std::pow(std::abs(Z), 1.33333);
*std::pow(std::abs(Z), 4./3.);
gamma0 = std::sqrt(1. - alphaZ*alphaZ);
// Largest allowed value of im argument in ModSquared
// imMax = std::log(DBL_MAX)/pi;
imMax = 200.; // actual value = 225.931, but use 200 to be safe
// G4cout << " imMax = " << imMax << G4endl;
// Coefficients for gamma function with real argument
gc[0] = -0.1010678;
gc[1] = 0.4245549;
@@ -86,13 +93,14 @@ G4double G4BetaDecayCorrections::FermiFunction(const G4double& W)
G4double
G4BetaDecayCorrections::ModSquared(const G4double& re, const G4double& im)
G4BetaDecayCorrections::ModSquared(const G4double& re, G4double im)
{
// Calculate the squared modulus of the Gamma function
// with complex argument (re, im) using approximation B
// of Wilkinson, Nucl. Instr. & Meth. 82, 122 (1970).
// Here, choose N = 1 in Wilkinson's notation for approximation B
im = std::max(std::min(im, imMax), -imMax);
G4double factor1 = std::pow( (1+re)*(1+re) + im*im, re+0.5);
G4double factor2 = std::exp(2*im * std::atan(im/(1+re)));
G4double factor3 = std::exp(2*(1+re));
@@ -238,6 +246,7 @@ G4BetaDecayCorrections::ShapeFactor(const G4BetaDecayType& bdt,
"Transition not yet implemented - using allowed shape");
break;
}
return factor;
}
@@ -66,7 +66,7 @@ G4BetaMinusDecay::G4BetaMinusDecay(const G4ParticleDefinition* theParentNucleus,
G4BetaMinusDecay::~G4BetaMinusDecay()
{
delete spectrumSampler;
delete betaSampler;
}
@@ -87,9 +87,9 @@ G4DecayProducts* G4BetaMinusDecay::DecayIt(G4double)
G4DynamicParticle parentParticle(G4MT_parent, G4ThreeVector(0,0,0), 0.0);
G4DecayProducts* products = new G4DecayProducts(parentParticle);
if (spectrumSampler) {
if (betaSampler) {
// Electron, neutrino and daughter nucleus energies
G4double eKE = endpointEnergy*spectrumSampler->shoot(G4Random::getTheEngine() );
G4double eKE = endpointEnergy*betaSampler->shoot();
G4double eMomentum = std::sqrt(eKE*(eKE + 2.*eMass) );
G4double cosThetaENu = 2.*G4UniformRand() - 1.;
@@ -166,30 +166,30 @@ G4BetaMinusDecay::SetUpBetaSpectrumSampler(const G4int& daughterZ,
{
G4double e0 = endpointEnergy/CLHEP::electron_mass_c2;
G4BetaDecayCorrections corrections(daughterZ, daughterA);
spectrumSampler = 0;
betaSampler = 0;
if (e0 > 0) {
// Array to store spectrum pdf
G4int npti = 100;
G4int npti = 101;
G4double* pdf = new G4double[npti];
G4double e; // Total electron energy in units of electron mass
G4double ex;
G4double p; // Electron momentum in units of electron mass
G4double f; // Spectral shape function
for (G4int ptn = 0; ptn < npti; ptn++) {
// Calculate simple phase space
e = 1. + e0*(G4double(ptn) + 0.5)/G4double(npti);
p = std::sqrt(e*e - 1.);
f = p*e*(e0 - e + 1.)*(e0 - e + 1.);
for (G4int i = 0; i < npti; i++) {
ex = e0*std::max(1.e-6, G4double(i)/G4double(npti-1) );
p = std::sqrt(ex*(ex+2.) );
f = p*(1. + ex)*(e0 - ex)*(e0 - ex);
// Apply Fermi factor to get allowed shape
f *= corrections.FermiFunction(e);
f *= corrections.FermiFunction(1. + ex);
// Apply shape factor for forbidden transitions
f *= corrections.ShapeFactor(betaType, p, e0-e+1.);
pdf[ptn] = f;
f *= corrections.ShapeFactor(betaType, p, e0-ex);
pdf[i] = f;
}
spectrumSampler = new G4RandGeneral(pdf, npti);
betaSampler = new G4BetaSpectrumSampler(pdf, npti, e0);
delete[] pdf;
}
}
@@ -57,7 +57,7 @@ G4BetaPlusDecay::G4BetaPlusDecay(const G4ParticleDefinition* theParentNucleus,
G4IonTable* theIonTable =
(G4IonTable*)(G4ParticleTable::GetParticleTable()->GetIonTable());
G4int daughterZ = theParentNucleus->GetAtomicNumber() - 1;
G4int daughterA = theParentNucleus->GetAtomicMass();
G4int daughterA = theParentNucleus->GetAtomicMass();
SetDaughter(0, theIonTable->GetIon(daughterZ, daughterA, excitationE, flb) );
SetUpBetaSpectrumSampler(daughterZ, daughterA, betaType);
SetDaughter(1, "e+");
@@ -67,7 +67,7 @@ G4BetaPlusDecay::G4BetaPlusDecay(const G4ParticleDefinition* theParentNucleus,
G4BetaPlusDecay::~G4BetaPlusDecay()
{
delete spectrumSampler;
delete betaSampler;
}
@@ -88,9 +88,9 @@ G4DecayProducts* G4BetaPlusDecay::DecayIt(G4double)
G4DynamicParticle parentParticle(G4MT_parent, G4ThreeVector(0,0,0), 0.0);
G4DecayProducts* products = new G4DecayProducts(parentParticle);
if (spectrumSampler) {
if (betaSampler) {
// Generate positron isotropic in angle, with energy from stored spectrum
G4double eKE = endpointEnergy*spectrumSampler->shoot(G4Random::getTheEngine() );
G4double eKE = endpointEnergy*betaSampler->shoot();
G4double eMomentum = std::sqrt(eKE*(eKE + 2.*eMass) );
G4double cosTheta = 2.*G4UniformRand() - 1.0;
@@ -164,31 +164,32 @@ G4BetaPlusDecay::SetUpBetaSpectrumSampler(const G4int& daughterZ,
{
G4double e0 = endpointEnergy/CLHEP::electron_mass_c2;
G4BetaDecayCorrections corrections(-daughterZ, daughterA);
spectrumSampler = 0;
betaSampler = 0;
// Check for cases in which Q < 2Me (e.g. z67.a162)
if (e0 > 0.) {
// Array to store spectrum pdf
G4int npti = 100;
G4int npti = 101;
G4double* pdf = new G4double[npti];
G4double e; // Total positron energy in units of electron mass
G4double p; // Positron momentum in units of electron mass
G4double f; // Spectral shap function
for (G4int ptn = 0; ptn < npti; ptn++) {
// Calculate simple phase space
e = 1. + e0*(ptn + 0.5)/G4double(npti);
p = std::sqrt(e*e - 1.);
f = p*e*(e0 - e + 1.)*(e0 - e + 1.);
G4double ex;
G4double p; // Positron momentum in units of electron mass
G4double f; // Spectral shape function
for (G4int i = 0; i < npti; i++) {
ex = e0*std::max(1.e-6, G4double(i)/G4double(npti-1) );
p = std::sqrt(ex*(ex+2.) );
f = p*(1. + ex)*(e0 - ex)*(e0 - ex);
// Apply Fermi factor to get allowed shape
f *= corrections.FermiFunction(e);
f *= corrections.FermiFunction(1. + ex);
// Apply shape factor for forbidden transitions
f *= corrections.ShapeFactor(betaType, p, e0-e+1.);
pdf[ptn] = f;
f *= corrections.ShapeFactor(betaType, p, e0-ex);
pdf[i] = f;
}
spectrumSampler = new G4RandGeneral(pdf, npti);
betaSampler = new G4BetaSpectrumSampler(pdf, npti, e0);
delete[] pdf;
}
}
@@ -0,0 +1,98 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
////////////////////////////////////////////////////////////////////////////////
// //
// File: G4BetaSpectrumSampler.cc //
// Author: D.H. Wright //
// Date: 21 November 2022 //
// Description: samples a spectrum which is a piece-wise linear function of //
// energy. The CDF is calculated by trapezoidal integration //
// and within bins the line y = mx + b is sampled. //
// //
////////////////////////////////////////////////////////////////////////////////
#include "G4BetaSpectrumSampler.hh"
G4BetaSpectrumSampler::
G4BetaSpectrumSampler(const G4double* aPDF, G4int pdfSize, G4double e)
{
pdf.resize(pdfSize);
nBins = pdfSize-1;
cdf.resize(nBins);
eEnd = e;
lowerBinEdge = 0;
upperBinEdge = 1;
for (G4int i = 0; i < pdfSize; i++) pdf[i] = aPDF[i];
// Caclulate binwise CDF using trapezoidal integration
G4double sum = pdf[0]/2.;
for (G4int i = 1; i < pdfSize; i++) {
sum += pdf[i];
cdf[i-1] = sum - pdf[i]/2.;
}
}
G4double G4BetaSpectrumSampler::shoot()
{
G4double rand = G4UniformRand()*cdf[nBins-1];
G4int ibin = 0;
while (rand > cdf[ibin]) ibin++;
G4double x = nBins;
if (ibin < nBins) {
lowerBinEdge = ibin;
upperBinEdge = ibin+1;
x = sampleSlopedLine();
}
return x/nBins;
}
G4double G4BetaSpectrumSampler::sampleSlopedLine()
{
G4double x;
G4double rand = G4UniformRand();
ylower = pdf[lowerBinEdge];
yupper = pdf[upperBinEdge];
if (std::abs(2.*(yupper - ylower)/(yupper + ylower) ) < 1.E-6) {
// Slope is near zero, sample flat
x = lowerBinEdge + rand*(upperBinEdge - lowerBinEdge);
} else {
// Sample incline
x = (yupper*lowerBinEdge - ylower*upperBinEdge +
std::sqrt(ylower*ylower + rand*(yupper*yupper - ylower*ylower) ) )
/(yupper - ylower);
}
return x;
}