Import Geant4 10.3.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-12-09 12:35:28 +01:00
parent 4ec577e5c4
commit a3452e42ac
3514 changed files with 210500 additions and 89628 deletions
@@ -34,9 +34,12 @@
#if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
#include "G4GeomTools.hh"
#include "G4AffineTransform.hh"
#include "G4VPVParameterisation.hh"
#include "G4BoundingEnvelope.hh"
using CLHEP::twopi;
using namespace CLHEP;
////////////////////////////////////////////////////////////////////////
//
@@ -55,6 +58,29 @@ G4UPolyhedra::G4UPolyhedra(const G4String& name,
: G4USolid(name, new UPolyhedra(name,phiStart, phiTotal, numSide,
numZPlanes, zPlane, rInner, rOuter))
{
wrStart = phiStart; while (wrStart < 0) wrStart += twopi;
wrDelta = phiTotal;
if (wrDelta <= 0 || wrDelta >= twopi*(1-DBL_EPSILON))
{
wrDelta = twopi;
}
wrNumSide = numSide;
G4double convertRad = 1./std::cos(0.5*wrDelta/wrNumSide);
rzcorners.resize(0);
for (G4int i=0; i<numZPlanes; ++i)
{
G4double z = zPlane[i];
G4double r = rOuter[i]*convertRad;
rzcorners.push_back(G4TwoVector(r,z));
}
for (G4int i=numZPlanes-1; i>=0; --i)
{
G4double z = zPlane[i];
G4double r = rInner[i]*convertRad;
rzcorners.push_back(G4TwoVector(r,z));
}
std::vector<G4int> iout;
G4GeomTools::RemoveRedundantVertices(rzcorners,iout,2*kCarTolerance);
}
@@ -71,7 +97,22 @@ G4UPolyhedra::G4UPolyhedra(const G4String& name,
const G4double z[] )
: G4USolid(name, new UPolyhedra(name, phiStart, phiTotal, numSide,
numRZ, r, z))
{
{
wrStart = phiStart; while (wrStart < 0) wrStart += twopi;
wrDelta = phiTotal;
if (wrDelta <= 0 || wrDelta >= twopi*(1-DBL_EPSILON))
{
wrDelta = twopi;
}
wrNumSide = numSide;
G4double convertRad = 1./std::cos(0.5*wrDelta/wrNumSide);
rzcorners.resize(0);
for (G4int i=0; i<numRZ; ++i)
{
rzcorners.push_back(G4TwoVector(r[i]*convertRad,z[i]));
}
std::vector<G4int> iout;
G4GeomTools::RemoveRedundantVertices(rzcorners,iout,2*kCarTolerance);
}
@@ -102,6 +143,10 @@ G4UPolyhedra::~G4UPolyhedra()
G4UPolyhedra::G4UPolyhedra( const G4UPolyhedra &source )
: G4USolid( source )
{
wrStart = source.wrStart;
wrDelta = source.wrDelta;
wrNumSide = source.wrNumSide;
rzcorners = source.rzcorners;
}
@@ -114,7 +159,11 @@ G4UPolyhedra& G4UPolyhedra::operator=( const G4UPolyhedra &source )
if (this == &source) return *this;
G4USolid::operator=( source );
wrStart = source.wrStart;
wrDelta = source.wrDelta;
wrNumSide = source.wrNumSide;
rzcorners = source.rzcorners;
return *this;
}
@@ -125,19 +174,39 @@ G4UPolyhedra& G4UPolyhedra::operator=( const G4UPolyhedra &source )
//
G4int G4UPolyhedra::GetNumSide() const
{
return GetShape()->GetNumSide();
return wrNumSide;
}
G4double G4UPolyhedra::GetStartPhi() const
{
return GetShape()->GetStartPhi();
return wrStart;
}
G4double G4UPolyhedra::GetEndPhi() const
{
return GetShape()->GetEndPhi();
return (wrStart + wrDelta);
}
G4double G4UPolyhedra::GetSinStartPhi() const
{
G4double phi = GetStartPhi();
return std::sin(phi);
}
G4double G4UPolyhedra::GetCosStartPhi() const
{
G4double phi = GetStartPhi();
return std::cos(phi);
}
G4double G4UPolyhedra::GetSinEndPhi() const
{
G4double phi = GetEndPhi();
return std::sin(phi);
}
G4double G4UPolyhedra::GetCosEndPhi() const
{
G4double phi = GetEndPhi();
return std::cos(phi);
}
G4bool G4UPolyhedra::IsOpen() const
{
return GetShape()->IsOpen();
return (wrDelta < twopi);
}
G4bool G4UPolyhedra::IsGeneric() const
{
@@ -145,12 +214,12 @@ G4bool G4UPolyhedra::IsGeneric() const
}
G4int G4UPolyhedra::GetNumRZCorner() const
{
return GetShape()->GetNumRZCorner();
return rzcorners.size();
}
G4PolyhedraSideRZ G4UPolyhedra::GetCorner(G4int index) const
{
UPolyhedraSideRZ pside = GetShape()->GetCorner(index);
G4PolyhedraSideRZ psiderz = { pside.r, pside.z };
G4TwoVector rz = rzcorners.at(index);
G4PolyhedraSideRZ psiderz = { rz.x(), rz.y() };
return psiderz;
}
@@ -183,6 +252,30 @@ void G4UPolyhedra::SetOriginalParameters(G4PolyhedraHistorical* pars)
pdata->Rmax[i] = pars->Rmax[i];
}
fRebuildPolyhedron = true;
wrStart = pdata->fStartAngle; while (wrStart < 0) wrStart += twopi;
wrDelta = pdata->fOpeningAngle;
if (wrDelta <= 0 || wrDelta >= twopi*(1-DBL_EPSILON))
{
wrDelta = twopi;
}
wrNumSide = pdata->fNumSide;
G4double convertRad = 1./std::cos(0.5*wrDelta/wrNumSide);
rzcorners.resize(0);
for (G4int i=0; i<pdata->fNumZPlanes; ++i)
{
G4double z = pdata->fZValues[i];
G4double r = pdata->Rmax[i]*convertRad;
rzcorners.push_back(G4TwoVector(r,z));
}
for (G4int i=pdata->fNumZPlanes-1; i>=0; --i)
{
G4double z = pdata->fZValues[i];
G4double r = pdata->Rmin[i]*convertRad;
rzcorners.push_back(G4TwoVector(r,z));
}
std::vector<G4int> iout;
G4GeomTools::RemoveRedundantVertices(rzcorners,iout,2*kCarTolerance);
}
G4bool G4UPolyhedra::Reset()
{
@@ -213,6 +306,244 @@ G4VSolid* G4UPolyhedra::Clone() const
}
//////////////////////////////////////////////////////////////////////////
//
// Get bounding box
void G4UPolyhedra::Extent(G4ThreeVector& pMin, G4ThreeVector& pMax) const
{
static G4bool checkBBox = true;
static G4bool checkPhi = true;
G4double rmin = kInfinity, rmax = -kInfinity;
G4double zmin = kInfinity, zmax = -kInfinity;
for (G4int i=0; i<GetNumRZCorner(); ++i)
{
G4PolyhedraSideRZ corner = GetCorner(i);
if (corner.r < rmin) rmin = corner.r;
if (corner.r > rmax) rmax = corner.r;
if (corner.z < zmin) zmin = corner.z;
if (corner.z > zmax) zmax = corner.z;
}
G4double sphi = GetStartPhi();
G4double ephi = GetEndPhi();
G4double dphi = IsOpen() ? ephi-sphi : twopi;
G4int ksteps = GetNumSide();
G4double astep = dphi/ksteps;
G4double sinStep = std::sin(astep);
G4double cosStep = std::cos(astep);
G4double sinCur = GetSinStartPhi();
G4double cosCur = GetCosStartPhi();
if (!IsOpen()) rmin = 0;
G4double xmin = rmin*cosCur, xmax = xmin;
G4double ymin = rmin*sinCur, ymax = ymin;
for (G4int k=0; k<ksteps+1; ++k)
{
G4double x = rmax*cosCur;
if (x < xmin) xmin = x;
if (x > xmax) xmax = x;
G4double y = rmax*sinCur;
if (y < ymin) ymin = y;
if (y > ymax) ymax = y;
if (rmin > 0)
{
G4double xx = rmin*cosCur;
if (xx < xmin) xmin = xx;
if (xx > xmax) xmax = xx;
G4double yy = rmin*sinCur;
if (yy < ymin) ymin = yy;
if (yy > ymax) ymax = yy;
}
G4double sinTmp = sinCur;
sinCur = sinCur*cosStep + cosCur*sinStep;
cosCur = cosCur*cosStep - sinTmp*sinStep;
}
pMin.set(xmin,ymin,zmin);
pMax.set(xmax,ymax,zmax);
// Check correctness of the bounding box
//
if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
{
std::ostringstream message;
message << "Bad bounding box (min >= max) for solid: "
<< GetName() << " !"
<< "\npMin = " << pMin
<< "\npMax = " << pMax;
G4Exception("G4UPolyhedra::Extent()", "GeomMgt0001", JustWarning, message);
StreamInfo(G4cout);
}
// Check consistency of bounding boxes
//
if (checkBBox)
{
UVector3 vmin, vmax;
GetShape()->Extent(vmin,vmax);
if (std::abs(pMin.x()-vmin.x()) > kCarTolerance ||
std::abs(pMin.y()-vmin.y()) > kCarTolerance ||
std::abs(pMin.z()-vmin.z()) > kCarTolerance ||
std::abs(pMax.x()-vmax.x()) > kCarTolerance ||
std::abs(pMax.y()-vmax.y()) > kCarTolerance ||
std::abs(pMax.z()-vmax.z()) > kCarTolerance)
{
std::ostringstream message;
message << "Inconsistency in bounding boxes for solid: "
<< GetName() << " !"
<< "\nBBox min: wrapper = " << pMin << " solid = " << vmin
<< "\nBBox max: wrapper = " << pMax << " solid = " << vmax;
G4Exception("G4UPolyhedra::Extent()", "GeomMgt0001", JustWarning, message);
checkBBox = false;
}
}
// Check consistency of angles
//
if (checkPhi)
{
if (GetStartPhi() != GetShape()->GetStartPhi() ||
GetEndPhi() != GetShape()->GetEndPhi() ||
IsOpen() != GetShape()->IsOpen() ||
GetNumSide() != GetShape()->GetNumSide())
{
std::ostringstream message;
message << "Inconsistency in Phi angles or # of sides for solid: "
<< GetName() << " !"
<< "\nPhi start : wrapper = " << GetStartPhi()
<< " solid = " << GetShape()->GetStartPhi()
<< "\nPhi end : wrapper = " << GetEndPhi()
<< " solid = " << GetShape()->GetEndPhi()
<< "\nPhi is open: wrapper = " << (IsOpen() ? "true" : "false")
<< " solid = " << (GetShape()->IsOpen() ? "true" : "false")
<< "\nPhi # sides: wrapper = " << GetNumSide()
<< " solid = " << GetShape()->GetNumSide();
G4Exception("G4UPolyhedra::Extent()", "GeomMgt0001", JustWarning, message);
checkPhi = false;
}
}
}
//////////////////////////////////////////////////////////////////////////
//
// Calculate extent under transform and specified limit
G4bool
G4UPolyhedra::CalculateExtent(const EAxis pAxis,
const G4VoxelLimits& pVoxelLimit,
const G4AffineTransform& pTransform,
G4double& pMin, G4double& pMax) const
{
G4ThreeVector bmin, bmax;
G4bool exist;
// Check bounding box (bbox)
//
Extent(bmin,bmax);
G4BoundingEnvelope bbox(bmin,bmax);
#ifdef G4BBOX_EXTENT
if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
#endif
if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
{
return exist = (pMin < pMax) ? true : false;
}
// To find the extent, RZ contour of the polycone is subdivided
// in triangles. The extent is calculated as cumulative extent of
// all sub-polycones formed by rotation of triangles around Z
//
G4TwoVectorList contourRZ;
G4TwoVectorList triangles;
std::vector<G4int> iout;
G4double eminlim = pVoxelLimit.GetMinExtent(pAxis);
G4double emaxlim = pVoxelLimit.GetMaxExtent(pAxis);
// get RZ contour, ensure anticlockwise order of corners
for (G4int i=0; i<GetNumRZCorner(); ++i)
{
G4PolyhedraSideRZ corner = GetCorner(i);
contourRZ.push_back(G4TwoVector(corner.r,corner.z));
}
G4GeomTools::RemoveRedundantVertices(contourRZ,iout,2*kCarTolerance);
G4double area = G4GeomTools::PolygonArea(contourRZ);
if (area < 0.) std::reverse(contourRZ.begin(),contourRZ.end());
// triangulate RZ countour
if (!G4GeomTools::TriangulatePolygon(contourRZ,triangles))
{
std::ostringstream message;
message << "Triangulation of RZ contour has failed for solid: "
<< GetName() << " !"
<< "\nExtent has been calculated using boundary box";
G4Exception("G4UPolyhedra::CalculateExtent()",
"GeomMgt1002",JustWarning,message);
return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
}
// set trigonometric values
G4double sphi = GetStartPhi();
G4double ephi = GetEndPhi();
G4double dphi = IsOpen() ? ephi-sphi : twopi;
G4int ksteps = GetNumSide();
G4double astep = dphi/ksteps;
G4double sinStep = std::sin(astep);
G4double cosStep = std::cos(astep);
G4double sinStart = GetSinStartPhi();
G4double cosStart = GetCosStartPhi();
// allocate vector lists
std::vector<const G4ThreeVectorList *> polygons;
polygons.resize(ksteps+1);
for (G4int k=0; k<ksteps+1; ++k) {
polygons[k] = new G4ThreeVectorList(3);
}
// main loop along triangles
pMin = kInfinity;
pMax = -kInfinity;
G4int ntria = triangles.size()/3;
for (G4int i=0; i<ntria; ++i)
{
G4double sinCur = sinStart;
G4double cosCur = cosStart;
G4int i3 = i*3;
for (G4int k=0; k<ksteps+1; ++k) // rotate triangle
{
G4ThreeVectorList* ptr = const_cast<G4ThreeVectorList*>(polygons[k]);
G4ThreeVectorList::iterator iter = ptr->begin();
iter->set(triangles[i3+0].x()*cosCur,
triangles[i3+0].x()*sinCur,
triangles[i3+0].y());
iter++;
iter->set(triangles[i3+1].x()*cosCur,
triangles[i3+1].x()*sinCur,
triangles[i3+1].y());
iter++;
iter->set(triangles[i3+2].x()*cosCur,
triangles[i3+2].x()*sinCur,
triangles[i3+2].y());
G4double sinTmp = sinCur;
sinCur = sinCur*cosStep + cosCur*sinStep;
cosCur = cosCur*cosStep - sinTmp*sinStep;
}
// set sub-envelope and adjust extent
G4double emin,emax;
G4BoundingEnvelope benv(polygons);
if (!benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,emin,emax)) continue;
if (emin < pMin) pMin = emin;
if (emax > pMax) pMax = emax;
if (eminlim > pMin && emaxlim < pMax) break; // max possible extent
}
// free memory
for (G4int k=0; k<ksteps+1; ++k) { delete polygons[k]; polygons[k]=0;}
return (pMin < pMax);
}
////////////////////////////////////////////////////////////////////////
//
// CreatePolyhedron
@@ -406,7 +737,8 @@ G4Polyhedron* G4UPolyhedra::CreatePolyhedron() const
xyz = new double3[nNodes];
faces_vec = new int4[nFaces];
// const G4double dPhi = (endPhi - startPhi) / numSide;
const G4double dPhi = twopi / GetNumSide(); // !phiIsOpen endPhi-startPhi = 360 degrees.
const G4double dPhi = twopi / GetNumSide();
// !phiIsOpen endPhi-startPhi = 360 degrees.
G4double phi = GetStartPhi();
G4int ixyz = 0, iface = 0;
for (G4int iSide = 0; iSide < GetNumSide(); ++iSide)
@@ -457,10 +789,10 @@ G4Polyhedron* G4UPolyhedra::CreatePolyhedron() const
}
}
G4Polyhedron* polyhedron = new G4Polyhedron;
G4int problem = polyhedron->createPolyhedron(nNodes, nFaces, xyz, faces_vec);
G4int prob = polyhedron->createPolyhedron(nNodes, nFaces, xyz, faces_vec);
delete [] faces_vec;
delete [] xyz;
if (problem)
if (prob)
{
std::ostringstream message;
message << "Problem creating G4Polyhedron for: " << GetName();