Import Geant4 10.4.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2017-06-30 10:49:55 +02:00
parent 3a5407696b
commit 1a1316fea4
2180 changed files with 237880 additions and 59109 deletions
@@ -23,7 +23,7 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4Fragment.cc 102724 2017-02-20 13:00:39Z gcosmo $
// $Id: G4Fragment.cc 104779 2017-06-16 09:20:56Z gcosmo $
//
//---------------------------------------------------------------------
//
@@ -92,8 +92,15 @@ G4Fragment::G4Fragment(const G4Fragment &right) :
G4Fragment::~G4Fragment()
{
delete thePolarization;
thePolarization = nullptr;
SetNuclearPolarization(nullptr);
}
void G4Fragment::SetNuclearPolarization(G4NuclearPolarization* p)
{
if(p != thePolarization) {
delete thePolarization;
thePolarization = p;
}
}
G4Fragment::G4Fragment(G4int A, G4int Z, const G4LorentzVector& aMomentum) :
@@ -185,54 +192,49 @@ G4bool G4Fragment::operator!=(const G4Fragment &right) const
return (this != (G4Fragment *) &right);
}
std::ostream& operator << (std::ostream &out, const G4Fragment *theFragment)
std::ostream& operator << (std::ostream &out, const G4Fragment &theFragment)
{
if (!theFragment) {
out << "Fragment: null pointer ";
return out;
}
std::ios::fmtflags old_floatfield = out.flags();
out.setf(std::ios::floatfield);
out << "Fragment: A = " << std::setw(3) << theFragment->theA
<< ", Z = " << std::setw(3) << theFragment->theZ ;
out << "Fragment: A = " << std::setw(3) << theFragment.theA
<< ", Z = " << std::setw(3) << theFragment.theZ ;
out.setf(std::ios::scientific,std::ios::floatfield);
// Store user's precision setting and reset to (3) here: back-compatibility
std::streamsize floatPrec = out.precision();
out << std::setprecision(3)
<< ", U = " << theFragment->GetExcitationEnergy()/CLHEP::MeV
<< ", U = " << theFragment.GetExcitationEnergy()/CLHEP::MeV
<< " MeV ";
if(theFragment->GetCreatorModelType() >= 0) {
out << " creatorModelType= " << theFragment->GetCreatorModelType();
if(theFragment.GetCreatorModelType() >= 0) {
out << " creatorModelType= " << theFragment.GetCreatorModelType();
}
if(theFragment->GetCreationTime() > 0.0) {
out << " Time= " << theFragment->GetCreationTime()/CLHEP::ns << " ns";
if(theFragment.GetCreationTime() > 0.0) {
out << " Time= " << theFragment.GetCreationTime()/CLHEP::ns << " ns";
}
out << G4endl
<< " P = ("
<< theFragment->GetMomentum().x()/CLHEP::MeV << ","
<< theFragment->GetMomentum().y()/CLHEP::MeV << ","
<< theFragment->GetMomentum().z()/CLHEP::MeV
<< theFragment.GetMomentum().x()/CLHEP::MeV << ","
<< theFragment.GetMomentum().y()/CLHEP::MeV << ","
<< theFragment.GetMomentum().z()/CLHEP::MeV
<< ") MeV E = "
<< theFragment->GetMomentum().t()/CLHEP::MeV << " MeV"
<< theFragment.GetMomentum().t()/CLHEP::MeV << " MeV"
<< G4endl;
out << " #spin= " << theFragment->GetSpin()
<< " #floatLevelNo= " << theFragment->GetFloatingLevelNumber();
if(theFragment->GetNuclearPolarization()) {
out << theFragment->GetNuclearPolarization();
}
if (theFragment->GetNumberOfExcitons() != 0) {
out << " "
<< "#Particles= " << theFragment->GetNumberOfParticles()
<< ", #Charged= " << theFragment->GetNumberOfCharged()
<< ", #Holes= " << theFragment->GetNumberOfHoles()
<< ", #ChargedHoles= " << theFragment->GetNumberOfChargedHoles();
out << " #spin= " << theFragment.GetSpin()
<< " #floatLevelNo= " << theFragment.GetFloatingLevelNumber() << " ";
if (theFragment.GetNumberOfExcitons() != 0) {
out << " "
<< "#Particles= " << theFragment.GetNumberOfParticles()
<< ", #Charged= " << theFragment.GetNumberOfCharged()
<< ", #Holes= " << theFragment.GetNumberOfHoles()
<< ", #ChargedHoles= " << theFragment.GetNumberOfChargedHoles();
}
out << G4endl;
if(theFragment.GetNuclearPolarization()) {
out << *(theFragment.GetNuclearPolarization());
}
out << G4endl;
out.setf(old_floatfield,std::ios::floatfield);
@@ -241,12 +243,6 @@ std::ostream& operator << (std::ostream &out, const G4Fragment *theFragment)
return out;
}
std::ostream& operator << (std::ostream &out, const G4Fragment &theFragment)
{
out << &theFragment;
return out;
}
void G4Fragment::ExcitationEnergyWarning()
{
#ifdef G4VERBOSE
@@ -46,18 +46,28 @@ G4double G4LegendrePolynomial::EvalLegendrePoly(G4int order, G4double x)
return (EvalAssocLegendrePoly(order,0,x));
}
G4double G4LegendrePolynomial::EvalAssocLegendrePoly(G4int l, G4int m, G4double x)
G4double G4LegendrePolynomial::EvalAssocLegendrePoly(G4int l, G4int m, G4double x,
map<G4int, map<G4int, G4double> >* cache)
{
// Calculate P_l^m(x).
// If cache ptr is non-null, use cache[l][m] if it exists, otherwise compute
// P_l^m(x) and cache it in that position. The cache speeds up calculations
// where many P_l^m computations are need at the same value of x.
if(l<0 || m<-l || m>l) return 0;
G4Pow* g4pow = G4Pow::GetInstance();
// Use non-log factorial, which is more efficient until l and m get
// above 10 or so.
// Use non-log factorial for low l, m: it is more efficient until
// l and m get above 10 or so.
// FIXME: G4Pow doesn't check whether the argument gets too large,
// which is unsafe! Max is 512; VI: It is assume that Geant4 does not
// need higher order
if(m<0) return (m%2 ? -1. : 1.) * g4pow->factorial(l+m)/g4pow->factorial(l-m)
* EvalAssocLegendrePoly(l, -m, x);
if(m<0) {
G4double value = (m%2 ? -1. : 1.) * EvalAssocLegendrePoly(l, -m, x);
if(l < 10) return value * g4pow->factorial(l+m)/g4pow->factorial(l-m);
else { return value * G4Exp(g4pow->logfactorial(l+m) - g4pow->logfactorial(l-m));
}
}
// hard-code the first few orders for speed
if(l==0) return 1;
@@ -94,9 +104,20 @@ G4double G4LegendrePolynomial::EvalAssocLegendrePoly(G4int l, G4int m, G4double
G4Exp(G4Log((1.-x*x)*0.25)*0.5*G4double(l));
if(m==l-1) return x*(2.*G4double(m)+1.)*EvalAssocLegendrePoly(m,m,x);
// See if we have this value cached.
if(cache != NULL && cache->count(l) > 0 && (*cache)[l].count(m) > 0) {
return (*cache)[l][m];
}
// Otherwise calculate recursively
return (x*G4double(2*l-1)*EvalAssocLegendrePoly(l-1,m,x) -
(G4double(l+m-1))*EvalAssocLegendrePoly(l-2,m,x))/G4double(l-m);
G4double value = (x*G4double(2*l-1)*EvalAssocLegendrePoly(l-1,m,x) -
(G4double(l+m-1))*EvalAssocLegendrePoly(l-2,m,x))/G4double(l-m);
// If we are working with a cache, cache this value.
if(cache != NULL) {
(*cache)[l][m] = value;
}
return value;
}
void G4LegendrePolynomial::BuildUpToOrder(size_t orderMax)
@@ -51,12 +51,13 @@ G4PolynomialPDF::G4PolynomialPDF(size_t n, const G4double* coeffs,
G4PolynomialPDF::~G4PolynomialPDF()
{}
void G4PolynomialPDF::SetCoefficient(size_t i, G4double value)
void G4PolynomialPDF::SetCoefficient(size_t i, G4double value, bool doSimplify)
{
while(i >= fCoefficients.size()) fCoefficients.push_back(0);
/* Loop checking, 30-Oct-2015, G.Folger */
fCoefficients[i] = value;
fChanged = true;
if(doSimplify) Simplify();
}
void G4PolynomialPDF::SetCoefficients(size_t nCoeffs,
@@ -64,9 +65,22 @@ void G4PolynomialPDF::SetCoefficients(size_t nCoeffs,
{
SetNCoefficients(nCoeffs);
for(size_t i=0; i<GetNCoefficients(); ++i) {
SetCoefficient(i, coefficients[i]);
SetCoefficient(i, coefficients[i], false);
}
fChanged = true;
Simplify();
}
void G4PolynomialPDF::Simplify()
{
while(fCoefficients.size() && fCoefficients[fCoefficients.size()-1] == 0) {
if(fVerbose > 0) {
G4cout << "G4PolynomialPDF::Simplify() WARNING: had to pop coefficient "
<< fCoefficients.size()-1 << G4endl;
}
fCoefficients.pop_back();
fChanged = true;
}
}
void G4PolynomialPDF::SetDomain(G4double x1, G4double x2)
@@ -109,8 +123,9 @@ void G4PolynomialPDF::Normalize()
}
for(size_t i=0; i<GetNCoefficients(); ++i) {
SetCoefficient(i, GetCoefficient(i)/sum);
SetCoefficient(i, GetCoefficient(i)/sum, false);
}
Simplify();
}
G4double G4PolynomialPDF::Evaluate(G4double x, G4int ddxPower)
@@ -167,7 +182,7 @@ G4bool G4PolynomialPDF::HasNegativeMinimum(G4double x1, G4double x2)
// If linear, or if quadratic with negative second derivative,
// just check the endpoints
if(GetNCoefficients() == 2 ||
(GetNCoefficients() == 3 && GetCoefficient(2) < 0)) {
(GetNCoefficients() == 3 && GetCoefficient(2) <= 0)) {
return (Evaluate(x1) < -fTolerance) || (Evaluate(x2) < -fTolerance);
}
@@ -254,7 +269,14 @@ G4double G4PolynomialPDF::GetX(G4double p, G4double x1, G4double x2,
(ddxPower == 0 && GetNCoefficients() == 2) ||
(ddxPower == 1 && GetNCoefficients() == 3)) {
G4double b = (ddxPower > -1) ? GetCoefficient(ddxPower) : -GetCoefficient(0)*fX1;
G4double slope = GetCoefficient(ddxPower+1);
G4double slope = GetCoefficient(ddxPower+1); // the highest-order coefficient
if(slope == 0) { // the highest-order coefficient should never be zero if simplified
if(fVerbose > 0) {
G4cout << "G4PolynomialPDF::GetX() WARNING: Got slope = 0. "
<< "Did you forget to Simplify()?" << G4endl;
}
return x2;
}
if(ddxPower == 1) slope *= 2.;
G4double value = (p-b)/slope;
if(value < x1) {
@@ -276,7 +298,14 @@ G4double G4PolynomialPDF::GetX(G4double p, G4double x1, G4double x2,
if(ddxPower == -1) c -= (GetCoefficient(0) + GetCoefficient(1)/2.*fX1)*fX1;
G4double b = GetCoefficient(ddxPower+1);
if(ddxPower == 1) b *= 2.;
G4double a = GetCoefficient(ddxPower+2);
G4double a = GetCoefficient(ddxPower+2); // the highest-order coefficient
if(a == 0) { // the highest-order coefficient should never be 0 if simplified
if(fVerbose > 0) {
G4cout << "G4PolynomialPDF::GetX() WARNING: Got a = 0. "
<< "Did you forget to Simplify()?" << G4endl;
}
return x2;
}
if(ddxPower == 1) a *= 3;
else if(ddxPower == -1) a *= 0.5;
double sqrtFactor = b*b - 4.*a*c;