Import Geant4 10.4.0.beta source tree
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
$Id: History 102724 2017-02-20 13:00:39Z gcosmo $
|
||||
$Id: History 104779 2017-06-16 09:20:56Z gcosmo $
|
||||
-------------------------------------------------------------------
|
||||
|
||||
==========================================================
|
||||
@@ -15,16 +15,35 @@ code and to keep track of all tags.
|
||||
* Please list in reverse chronological order (last date on top)
|
||||
---------------------------------------------------------------
|
||||
|
||||
16 February 2017 Vladimir Ivanchenko (hadr-mod-util-V10-02-10)
|
||||
16 June 2017 Vladimir Ivanchenko (hadr-mod-util-V10-03-07)
|
||||
- G4Fragment - improved printout
|
||||
|
||||
14 June 2017 Vladimir Ivanchenko (hadr-mod-util-V10-03-06)
|
||||
- G4Fragment - added non-const method NuclearPolarization() allowing
|
||||
get non-const pointer to the G4NuclearPolarization object;
|
||||
removed G4Fragment printout by pointer, because this method
|
||||
is a problem for debigging
|
||||
|
||||
13 June 2017 Alberto Ribon (hadr-mod-util-V10-03-05)
|
||||
- G4LegendrePolynomial : applied Jason Detwiler's caching to speed up
|
||||
the calculations.
|
||||
|
||||
1 June 2017 Dennis Wright (hadr-mod-util-V10-03-04)
|
||||
- G4PolynomialPDF: apply Jason Detwiler's fix to divide by zero bug
|
||||
|
||||
30 May 2017 Vladimir Ivanchenko (hadr-mod-util-V10-03-03)
|
||||
- G4Fragment - fixed destructor and printout
|
||||
|
||||
16 February 2017 Vladimir Ivanchenko (hadr-mod-util-V10-03-02)
|
||||
- G4PolynomialPDF - added control on printout
|
||||
|
||||
14 February 2017 Vladimir Ivanchenko
|
||||
14 February 2017 Vladimir Ivanchenko (hadr-mod-util-V10-03-01)
|
||||
- G4Fragment - added method SetExcEnergyAndMomentum(...) allowing preserve
|
||||
excitation energy value without any precision lost, 4-momentum
|
||||
is recomputed; added class member and Get/Set method for floating
|
||||
levels number which was missing before
|
||||
|
||||
16 December 2016 Vladimir Ivanchenko (hadr-mod-util-V10-02-09)
|
||||
16 December 2016 Vladimir Ivanchenko (hadr-mod-util-V10-03-00)
|
||||
- G4Fragment - minor cleanup of check on excitation energy of
|
||||
a ground state
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4Fragment.hh 102724 2017-02-20 13:00:39Z gcosmo $
|
||||
// $Id: G4Fragment.hh 104779 2017-06-16 09:20:56Z gcosmo $
|
||||
//
|
||||
//---------------------------------------------------------------------
|
||||
//
|
||||
@@ -91,7 +91,6 @@ public:
|
||||
G4bool operator==(const G4Fragment &right) const;
|
||||
G4bool operator!=(const G4Fragment &right) const;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream&, const G4Fragment*);
|
||||
friend std::ostream& operator<<(std::ostream&, const G4Fragment&);
|
||||
|
||||
// new/delete operators are overloded to use G4Allocator
|
||||
@@ -161,8 +160,9 @@ public:
|
||||
inline G4double GetCreationTime() const;
|
||||
inline void SetCreationTime(G4double time);
|
||||
|
||||
inline G4NuclearPolarization* NuclearPolarization();
|
||||
inline G4NuclearPolarization* GetNuclearPolarization() const;
|
||||
inline void SetNuclearPolarization(G4NuclearPolarization*);
|
||||
void SetNuclearPolarization(G4NuclearPolarization*);
|
||||
|
||||
void SetAngularMomentum(const G4ThreeVector&);
|
||||
G4ThreeVector GetAngularMomentum() const;
|
||||
@@ -216,7 +216,7 @@ private:
|
||||
};
|
||||
|
||||
// ============= INLINE METHOD IMPLEMENTATIONS ===================
|
||||
|
||||
/*
|
||||
inline void G4Fragment::SetNuclearPolarization(G4NuclearPolarization* p)
|
||||
{
|
||||
if(p != thePolarization) {
|
||||
@@ -224,7 +224,7 @@ inline void G4Fragment::SetNuclearPolarization(G4NuclearPolarization* p)
|
||||
thePolarization = p;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
#if defined G4HADRONIC_ALLOC_EXPORT
|
||||
extern G4DLLEXPORT G4ThreadLocal G4Allocator<G4Fragment> *pFragmentAllocator;
|
||||
#else
|
||||
@@ -455,6 +455,11 @@ inline void G4Fragment::SetCreationTime(G4double time)
|
||||
theCreationTime = time;
|
||||
}
|
||||
|
||||
inline G4NuclearPolarization* G4Fragment::NuclearPolarization()
|
||||
{
|
||||
return thePolarization;
|
||||
}
|
||||
|
||||
inline G4NuclearPolarization* G4Fragment::GetNuclearPolarization() const
|
||||
{
|
||||
return thePolarization;
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
|
||||
#include "globals.hh"
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
class G4LegendrePolynomial
|
||||
{
|
||||
@@ -55,7 +56,8 @@ class G4LegendrePolynomial
|
||||
|
||||
// Evaluation functions
|
||||
G4double EvalLegendrePoly(G4int order, G4double x);
|
||||
G4double EvalAssocLegendrePoly(G4int l, G4int m, G4double x);
|
||||
G4double EvalAssocLegendrePoly(G4int l, G4int m, G4double x,
|
||||
std::map<G4int, std::map<G4int, G4double> >* cache = NULL);
|
||||
|
||||
protected: // Cache coefficients for speed
|
||||
void BuildUpToOrder(size_t order);
|
||||
|
||||
@@ -56,10 +56,13 @@ class G4PolynomialPDF
|
||||
// Setters and Getters for coefficients
|
||||
inline void SetNCoefficients(size_t n) { fCoefficients.resize(n); fChanged = true; }
|
||||
inline size_t GetNCoefficients() const { return fCoefficients.size(); }
|
||||
inline void SetCoefficients(const std::vector<G4double>& v) { fCoefficients = v; }
|
||||
inline void SetCoefficients(const std::vector<G4double>& v) {
|
||||
fCoefficients = v; fChanged = true; Simplify();
|
||||
}
|
||||
inline G4double GetCoefficient(size_t i) const { return fCoefficients[i]; }
|
||||
void SetCoefficient(size_t i, G4double value);
|
||||
void SetCoefficient(size_t i, G4double value, bool doSimplify);
|
||||
void SetCoefficients(size_t n, const G4double* coeffs);
|
||||
void Simplify();
|
||||
|
||||
// Set the domain over which random numbers are generated and over which
|
||||
// the CDF is evaluated
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user