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
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,593 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
// $Id: $
//
//
// class G4GeomTools Implementation
//
// Author: evgueni.tcherniaev@cern.ch
//
// 10.10.2016 E.Tcherniaev: initial version.
// --------------------------------------------------------------------
#include "G4GeomTools.hh"
#include "geomdefs.hh"
#include "G4SystemOfUnits.hh"
#include "G4GeometryTolerance.hh"
///////////////////////////////////////////////////////////////////////
//
// Calculate area of a triangle in 2D
G4double G4GeomTools::TriangleArea(G4double Ax, G4double Ay,
G4double Bx, G4double By,
G4double Cx, G4double Cy)
{
return ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax))*0.5;
}
///////////////////////////////////////////////////////////////////////
//
// Calculate area of a triangle in 2D
G4double G4GeomTools::TriangleArea(const G4TwoVector& A,
const G4TwoVector& B,
const G4TwoVector& C)
{
G4double Ax = A.x(), Ay = A.y();
return ((B.x()-Ax)*(C.y()-Ay) - (B.y()-Ay)*(C.x()-Ax))*0.5;
}
///////////////////////////////////////////////////////////////////////
//
// Calculate area of a quadrilateral in 2D
G4double G4GeomTools::QuadArea(const G4TwoVector& A,
const G4TwoVector& B,
const G4TwoVector& C,
const G4TwoVector& D)
{
return ((C.x()-A.x())*(D.y()-B.y()) - (C.y()-A.y())*(D.x()-B.x()))*0.5;
}
///////////////////////////////////////////////////////////////////////
//
// Calculate area of a polygon in 2D
G4double G4GeomTools::PolygonArea(const G4TwoVectorList& p)
{
G4double area = 0.0;
G4int n = p.size();
for(G4int i=0,k=n-1; i<n; k=i,++i)
{
area += p[k].x()*p[i].y() - p[i].x()*p[k].y();
}
return area*0.5;
}
///////////////////////////////////////////////////////////////////////
//
// Point inside 2D triangle
G4bool G4GeomTools::PointInTriangle(G4double Ax, G4double Ay,
G4double Bx, G4double By,
G4double Cx, G4double Cy,
G4double Px, G4double Py)
{
if ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax) > 0.)
{
if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) < 0.) return false;
if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) < 0.) return false;
if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) < 0.) return false;
}
else
{
if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) > 0.) return false;
if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) > 0.) return false;
if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) > 0.) return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////
//
// Point inside 2D triangle
G4bool G4GeomTools::PointInTriangle(const G4TwoVector& A,
const G4TwoVector& B,
const G4TwoVector& C,
const G4TwoVector& P)
{
G4double Ax = A.x(), Ay = A.y();
G4double Bx = B.x(), By = B.y();
G4double Cx = C.x(), Cy = C.y();
G4double Px = P.x(), Py = P.y();
if ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax) > 0.)
{
if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) < 0.) return false;
if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) < 0.) return false;
if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) < 0.) return false;
}
else
{
if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) > 0.) return false;
if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) > 0.) return false;
if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) > 0.) return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////
//
// Detemine whether 2D polygon is convex or not
G4bool G4GeomTools::IsConvex(const G4TwoVectorList& polygon)
{
static const G4double kCarTolerance =
G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
G4bool gotNegative = false;
G4bool gotPositive = false;
G4int n = polygon.size();
if (n <= 0) return false;
for (G4int icur=0; icur<n; ++icur)
{
G4int iprev = (icur == 0) ? n-1 : icur-1;
G4int inext = (icur == n-1) ? 0 : icur+1;
G4TwoVector e1 = polygon[icur] - polygon[iprev];
G4TwoVector e2 = polygon[inext] - polygon[icur];
G4double cross = e1.x()*e2.y() - e1.y()*e2.x();
if (std::abs(cross) < kCarTolerance) return false;
if (cross < 0) gotNegative = true;
if (cross > 0) gotPositive = true;
if (gotNegative && gotPositive) return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////
//
// Triangulate simple polygon
G4bool G4GeomTools::TriangulatePolygon(const G4TwoVectorList& polygon,
G4TwoVectorList& result)
{
result.resize(0);
std::vector<G4int> triangles;
G4bool reply = TriangulatePolygon(polygon,triangles);
G4int n = triangles.size();
for (G4int i=0; i<n; ++i) result.push_back(polygon[triangles[i]]);
return reply;
}
///////////////////////////////////////////////////////////////////////
//
// Triangulation of a simple polygon by "ear clipping"
G4bool G4GeomTools::TriangulatePolygon(const G4TwoVectorList& polygon,
std::vector<G4int>& result)
{
result.resize(0);
// allocate and initialize list of Vertices in polygon
//
G4int n = polygon.size();
if (n < 3) return false;
// we want a counter-clockwise polygon in V
//
G4double area = G4GeomTools::PolygonArea(polygon);
G4int* V = new G4int[n];
if (area > 0.)
for (G4int i=0; i<n; ++i) V[i] = i;
else
for (G4int i=0; i<n; ++i) V[i] = (n-1)-i;
// Triangulation: remove nv-2 Vertices, creating 1 triangle every time
//
G4int nv = n;
G4int count = 2*nv; // error detection counter
for(G4int b=nv-1; nv>2; )
{
// ERROR: if we loop, it is probably a non-simple polygon
if ((count--) <= 0)
{
delete[] V;
if (area < 0.) std::reverse(result.begin(),result.end());
return false;
}
// three consecutive vertices in current polygon, <a,b,c>
G4int a = (b < nv) ? b : 0; // previous
b = (a+1 < nv) ? a+1 : 0; // current
G4int c = (b+1 < nv) ? b+1 : 0; // next
if (CheckSnip(polygon, a,b,c, nv,V))
{
// output Triangle
result.push_back(V[a]);
result.push_back(V[b]);
result.push_back(V[c]);
// remove vertex b from remaining polygon
nv--;
for(G4int i=b; i<nv; ++i) V[i] = V[i+1];
count = 2*nv; // resest error detection counter
}
}
delete[] V;
if (area < 0.) std::reverse(result.begin(),result.end());
return true;
}
///////////////////////////////////////////////////////////////////////
//
// Helper function for "ear clipping" polygon triangulation.
// Check for a valid snip
G4bool G4GeomTools::CheckSnip(const G4TwoVectorList& contour,
G4int a, G4int b, G4int c,
G4int n, const G4int* V)
{
static const G4double kCarTolerance =
G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
// check orientation of Triangle
G4double Ax = contour[V[a]].x(), Ay = contour[V[a]].y();
G4double Bx = contour[V[b]].x(), By = contour[V[b]].y();
G4double Cx = contour[V[c]].x(), Cy = contour[V[c]].y();
if ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax) < kCarTolerance) return false;
// check that there is no point inside Triangle
G4double xmin = std::min(std::min(Ax,Bx),Cx);
G4double xmax = std::max(std::max(Ax,Bx),Cx);
G4double ymin = std::min(std::min(Ay,By),Cy);
G4double ymax = std::max(std::max(Ay,By),Cy);
for (G4int i=0; i<n; ++i)
{
if((i == a) || (i == b) || (i == c)) continue;
G4double Px = contour[V[i]].x();
if (Px < xmin || Px > xmax) continue;
G4double Py = contour[V[i]].y();
if (Py < ymin || Py > ymax) continue;
if (PointInTriangle(Ax,Ay,Bx,By,Cx,Cy,Px,Py)) return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////
//
// Remove collinear and coincident points from 2D polygon
void G4GeomTools::RemoveRedundantVertices(G4TwoVectorList& polygon,
std::vector<G4int>& iout,
G4double tolerance)
{
iout.resize(0);
// set tolerance squared
G4double delta = tolerance*tolerance;
// set special value to mark vertices for removal
G4double removeIt = kInfinity;
G4int nv = polygon.size();
// Main loop: check every three consecutive points, if the points
// are collinear then mark middle point for removal
//
G4int icur = 0, iprev = 0, inext = 0, nout = 0;
for (G4int i=0; i<nv; ++i)
{
icur = i; // index of current point
for (G4int k=1; k<nv+1; ++k) // set index of previous point
{
iprev = icur - k;
if (iprev < 0) iprev += nv;
if (polygon[iprev].x() != removeIt) break;
}
for (G4int k=1; k<nv+1; ++k) // set index of next point
{
inext = icur + k;
if (inext >= nv) inext -= nv;
if (polygon[inext].x() != removeIt) break;
}
if (iprev == inext) break; // degenerate polygon, stop
// Calculate parameters of triangle (iprev->icur->inext),
// if triangle is too small or too narrow then mark current
// point for removal
G4TwoVector e1 = polygon[iprev] - polygon[icur];
G4TwoVector e2 = polygon[inext] - polygon[icur];
// Check length of edges, then check height of the triangle
G4double leng1 = e1.mag2();
G4double leng2 = e2.mag2();
G4double leng3 = (e2-e1).mag2();
if (leng1 <= delta || leng2 <= delta || leng3 <= delta)
{
polygon[icur].setX(removeIt); nout++;
}
else
{
G4double lmax = std::max(std::max(leng1,leng2),leng3);
G4double area = std::abs(e1.x()*e2.y()-e1.y()*e2.x())*0.5;
if (area/std::sqrt(lmax) <= std::abs(tolerance))
{
polygon[icur].setX(removeIt); nout++;
}
}
}
// Remove marked points
//
icur = 0;
if (nv - nout < 3) // degenerate polygon, remove all points
{
for (G4int i=0; i<nv; ++i) iout.push_back(i);
polygon.resize(0);
nv = 0;
}
for (G4int i=0; i<nv; ++i) // move points, if required
{
if (polygon[i].x() != removeIt)
polygon[icur++] = polygon[i];
else
iout.push_back(i);
}
if (icur < nv) polygon.resize(icur);
return;
}
///////////////////////////////////////////////////////////////////////
//
// Find bounding box of a disk sector
G4bool G4GeomTools::DiskExtent(G4double rmin, G4double rmax,
G4double startPhi, G4double delPhi,
G4TwoVector& pmin, G4TwoVector& pmax)
{
static const G4double kCarTolerance =
G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
// check parameters
//
pmin.set(0,0);
pmax.set(0,0);
if (rmin < 0) return false;
if (rmax <= rmin + kCarTolerance) return false;
if (delPhi <= 0 + kCarTolerance) return false;
// calculate extent
//
pmin.set(-rmax,-rmax);
pmax.set( rmax, rmax);
if (delPhi >= CLHEP::twopi) return true;
DiskExtent(rmin,rmax,
std::sin(startPhi),std::cos(startPhi),
std::sin(startPhi+delPhi),std::cos(startPhi+delPhi),
pmin,pmax);
return true;
}
///////////////////////////////////////////////////////////////////////
//
// Find bounding box of a disk sector, fast version.
// No check of parameters !!!
void G4GeomTools::DiskExtent(G4double rmin, G4double rmax,
G4double sinStart, G4double cosStart,
G4double sinEnd, G4double cosEnd,
G4TwoVector& pmin, G4TwoVector& pmax)
{
static const G4double kCarTolerance =
G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
// check if 360 degrees
//
pmin.set(-rmax,-rmax);
pmax.set( rmax, rmax);
if (std::abs(sinEnd-sinStart) < kCarTolerance &&
std::abs(cosEnd-cosStart) < kCarTolerance) return;
// get start and end quadrants
//
// 1 | 0
// ---+---
// 3 | 2
//
G4int icase = (cosEnd < 0) ? 1 : 0;
if (sinEnd < 0) icase += 2;
if (cosStart < 0) icase += 4;
if (sinStart < 0) icase += 8;
switch (icase)
{
// start quadrant 0
case 0: // start->end : 0->0
if (sinEnd < sinStart) break;
pmin.set(rmin*cosEnd,rmin*sinStart);
pmax.set(rmax*cosStart,rmax*sinEnd );
break;
case 1: // start->end : 0->1
pmin.set(rmax*cosEnd,std::min(rmin*sinStart,rmin*sinEnd));
pmax.set(rmax*cosStart,rmax );
break;
case 2: // start->end : 0->2
pmin.set(-rmax,-rmax);
pmax.set(std::max(rmax*cosStart,rmax*cosEnd),rmax);
break;
case 3: // start->end : 0->3
pmin.set(-rmax,rmax*sinEnd);
pmax.set(rmax*cosStart,rmax);
break;
// start quadrant 1
case 4: // start->end : 1->0
pmin.set(-rmax,-rmax);
pmax.set(rmax,std::max(rmax*sinStart,rmax*sinEnd));
break;
case 5: // start->end : 1->1
if (sinEnd > sinStart) break;
pmin.set(rmax*cosEnd,rmin*sinEnd );
pmax.set(rmin*cosStart,rmax*sinStart);
break;
case 6: // start->end : 1->2
pmin.set(-rmax,-rmax);
pmax.set(rmax*cosEnd,rmax*sinStart);
break;
case 7: // start->end : 1->3
pmin.set(-rmax,rmax*sinEnd);
pmax.set(std::max(rmin*cosStart,rmin*cosEnd),rmax*sinStart);
break;
// start quadrant 2
case 8: // start->end : 2->0
pmin.set(std::min(rmin*cosStart,rmin*cosEnd),rmax*sinStart);
pmax.set(rmax,rmax*sinEnd);
break;
case 9: // start->end : 2->1
pmin.set(rmax*cosEnd,rmax*sinStart);
pmax.set(rmax,rmax);
break;
case 10: // start->end : 2->2
if (sinEnd < sinStart) break;
pmin.set(rmin*cosStart,rmax*sinStart);
pmax.set(rmax*cosEnd,rmin*sinEnd );
break;
case 11: // start->end : 2->3
pmin.set(-rmax,std::min(rmax*sinStart,rmax*sinEnd));
pmax.set(rmax,rmax);
break;
// start quadrant 3
case 12: // start->end : 3->0
pmin.set(rmax*cosStart,-rmax);
pmax.set(rmax,rmax*sinEnd);
break;
case 13: // start->end : 3->1
pmin.set(std::min(rmax*cosStart,rmax*cosEnd),-rmax);
pmax.set(rmax,rmax);
break;
case 14: // start->end : 3->2
pmin.set(rmax*cosStart,-rmax);
pmax.set(rmax*cosEnd,std::max(rmin*sinStart,rmin*sinEnd));
break;
case 15: // start->end : 3->3
if (sinEnd > sinStart) break;
pmin.set(rmax*cosStart,rmax*sinEnd);
pmax.set(rmin*cosEnd,rmin*sinStart);
break;
}
return;
}
///////////////////////////////////////////////////////////////////////
//
// Calculate distance between point P and line segment AB in 3D
G4double G4GeomTools::DistancePointSegment(G4ThreeVector P,
G4ThreeVector A,
G4ThreeVector B)
{
G4ThreeVector AP = P - A;
G4ThreeVector AB = B - A;
G4double u = AP.dot(AB);
if (u <= 0) return AP.mag(); // closest point is A
G4double len2 = AB.mag2();
if (u >= len2) return (B-P).mag(); // closest point is B
return ((u/len2)*AB - AP).mag(); // distance to line
}
///////////////////////////////////////////////////////////////////////
//
// Calculate bounding box of a spherical sector
G4bool
G4GeomTools::SphereExtent(G4double rmin, G4double rmax,
G4double startTheta, G4double delTheta,
G4double startPhi, G4double delPhi,
G4ThreeVector& pmin, G4ThreeVector& pmax)
{
static const G4double kCarTolerance =
G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
// check parameters
//
pmin.set(0,0,0);
pmax.set(0,0,0);
if (rmin < 0) return false;
if (rmax <= rmin + kCarTolerance) return false;
if (delTheta <= 0 + kCarTolerance) return false;
if (delPhi <= 0 + kCarTolerance) return false;
G4double stheta = startTheta;
G4double dtheta = delTheta;
if (stheta < 0 && stheta > CLHEP::pi) return false;
if (stheta + dtheta > CLHEP::pi) dtheta = CLHEP::pi - stheta;
if (dtheta <= 0 + kCarTolerance) return false;
// calculate extent
//
pmin.set(-rmax,-rmax,-rmax);
pmax.set( rmax, rmax, rmax);
if (dtheta >= CLHEP::pi && delPhi >= CLHEP::twopi) return true;
G4double etheta = stheta + dtheta;
G4double sinStart = std::sin(stheta);
G4double cosStart = std::cos(stheta);
G4double sinEnd = std::sin(etheta);
G4double cosEnd = std::cos(etheta);
G4double rhomin = rmin*std::min(sinStart,sinEnd);
G4double rhomax = rmax;
if (stheta > CLHEP::halfpi) rhomax = rmax*sinStart;
if (etheta < CLHEP::halfpi) rhomax = rmax*sinEnd;
G4TwoVector xymin,xymax;
DiskExtent(rhomin,rhomax,
std::sin(startPhi),std::cos(startPhi),
std::sin(startPhi+delPhi),std::cos(startPhi+delPhi),
xymin,xymax);
G4double zmin = std::min(rmin*cosEnd,rmax*cosEnd);
G4double zmax = std::max(rmin*cosStart,rmax*cosStart);
pmin.set(xymin.x(),xymin.y(),zmin);
pmax.set(xymax.x(),xymax.y(),zmax);
return true;
}
@@ -0,0 +1,138 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
// $Id:$
//
//
// Implementation of G4LogicalCrystalVolume
//
// 21-04-16, created by E.Bagli
//
// --------------------------------------------------------------------
#include "G4LogicalCrystalVolume.hh"
#include "G4ExtendedMaterial.hh"
#include "G4CrystalExtension.hh"
#include "G4VMaterialExtension.hh"
std::vector<G4LogicalVolume*> G4LogicalCrystalVolume::fLCVvec;
// --------------------------------------------------------------------
G4LogicalCrystalVolume::
G4LogicalCrystalVolume(G4VSolid* pSolid, G4ExtendedMaterial* pMaterial,
const G4String& name, G4FieldManager* pFieldMgr,
G4VSensitiveDetector* pSDetector,
G4UserLimits* pULimits, G4bool optimise,
G4int h, G4int k, G4int l, G4double rot)
: G4LogicalVolume(pSolid,pMaterial,name,pFieldMgr,pSDetector,pULimits,optimise),
hMiller(1), kMiller(0), lMiller(0), fRot(0), verboseLevel(0)
{
SetMillerOrientation(h, k, l, rot);
fLCVvec.push_back(this);
}
// --------------------------------------------------------------------
G4LogicalCrystalVolume::~G4LogicalCrystalVolume()
{
fLCVvec.erase( std::remove(fLCVvec.begin(),fLCVvec.end(), this ),
fLCVvec.end() );
}
// --------------------------------------------------------------------
G4bool G4LogicalCrystalVolume::IsLattice(G4LogicalVolume* aLV)
{
return std::find(fLCVvec.begin(), fLCVvec.end(), aLV) != fLCVvec.end();
}
// --------------------------------------------------------------------
const G4CrystalExtension* G4LogicalCrystalVolume::GetCrystal() const
{
return dynamic_cast<G4CrystalExtension*>(dynamic_cast<G4ExtendedMaterial*>(GetMaterial())
->RetrieveExtension("crystal"));
}
// --------------------------------------------------------------------
const G4ThreeVector& G4LogicalCrystalVolume::GetBasis(G4int i) const
{
return GetCrystal()->GetUnitCell()->GetBasis(i);
}
// --------------------------------------------------------------------
void G4LogicalCrystalVolume::SetMillerOrientation(G4int h,
G4int k,
G4int l,
G4double rot)
{
// Align Miller normal vector (hkl) with +Z axis, and rotation about axis
if (verboseLevel)
{
G4cout << "G4LatticePhysical::SetMillerOrientation(" << h << " "
<< k << " " << l << ", " << rot/CLHEP::deg << " deg)" << G4endl;
}
hMiller = h;
kMiller = k;
lMiller = l;
fRot = rot;
G4ThreeVector norm = (h*GetBasis(0)+k*GetBasis(1)+l*GetBasis(2)).unit();
if (verboseLevel>1) G4cout << " norm = " << norm << G4endl;
// Aligns geometry +Z axis with lattice (hkl) normal
fOrient = G4RotationMatrix::IDENTITY;
fOrient.rotateZ(rot).rotateY(norm.theta()).rotateZ(norm.phi());
fInverse = fOrient.inverse();
if (verboseLevel>1) G4cout << " fOrient = " << fOrient << G4endl;
// FIXME: Is this equivalent to (phi,theta,rot) Euler angles???
}
// --------------------------------------------------------------------
// Rotate input vector between lattice and solid orientations
const G4ThreeVector&
G4LogicalCrystalVolume::RotateToLattice(G4ThreeVector& dir) const
{
return dir.transform(fOrient);
}
const G4ThreeVector&
G4LogicalCrystalVolume::RotateToSolid(G4ThreeVector& dir) const
{
return dir.transform(fInverse);
}
// --------------------------------------------------------------------
+289 -71
View File
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4LogicalVolume.cc 93287 2015-10-15 09:50:22Z gcosmo $
// $Id: G4LogicalVolume.cc 100906 2016-11-03 09:59:32Z gcosmo $
//
//
// class G4LogicalVolume Implementation
@@ -40,12 +40,6 @@
// --------------------------------------------------------------------
#include "G4LogicalVolume.hh"
#ifdef NO_INLINE
#define inline
#include "G4LogicalVolume.icc"
#undef inline
#endif
#include "G4LogicalVolumeStore.hh"
#include "G4VSolid.hh"
#include "G4Material.hh"
@@ -54,12 +48,6 @@
#include "G4UnitsTable.hh"
// This static member is thread local. For each thread, it points to the
// array of G4LVData instances.
//
template <class G4LVData> G4ThreadLocal
G4LVData* G4GeomSplitter<G4LVData>::offset = 0;
G4LVData::G4LVData()
: fSolid(0),fSensitiveDetector(0),fFieldManager(0),
fMaterial(0),fMass(0.),fCutsCouple(0)
@@ -69,65 +57,16 @@ G4LVData::G4LVData()
//
G4LVManager G4LogicalVolume::subInstanceManager;
// ********************************************************************
// InitialiseWorker
// These macros change the references to fields that are now encapsulated
// in the class G4LVData.
//
// This method is similar to the constructor. It is used by each worker
// thread to achieve the same effect as that of the master thread exept
// to register the new created instance. This method is invoked explicitly.
// It does not create a new G4LogicalVolume instance. It only assign the value
// for the fields encapsulated by the class G4LVData.
// ********************************************************************
//
void G4LogicalVolume::
InitialiseWorker( G4LogicalVolume* /*pMasterObject*/,
G4VSolid* pSolid,
G4VSensitiveDetector* pSDetector)
{
subInstanceManager.SlaveCopySubInstanceArray();
SetSolid(pSolid);
SetSensitiveDetector(pSDetector); // How this object is available now ?
AssignFieldManager(fFieldManager); // Should be set - but a per-thread copy is not available yet
// G4MT_fmanager= fFieldManager;
// Must not call SetFieldManager(fFieldManager, false); which propagates FieldMgr
#ifdef CLONE_FIELD_MGR
// Create a field FieldManager by cloning
G4FieldManager workerFldMgr= fFieldManager->GetWorkerClone(G4bool* created);
if( created || (GetFieldManager()!=workerFldMgr) )
{
SetFieldManager(fFieldManager, false); // which propagates FieldMgr
}else{
// Field manager existed and is equal to current one
AssignFieldManager(workerFldMgr);
}
#endif
}
// ********************************************************************
// TerminateWorker
//
// This method is similar to the destructor. It is used by each worker
// thread to achieve the partial effect as that of the master thread.
// For G4LogicalVolume instances, nothing more to do here.
// ********************************************************************
//
void G4LogicalVolume::
TerminateWorker( G4LogicalVolume* /*pMasterObject*/)
{
}
// ********************************************************************
// GetSubInstanceManager
//
// Returns the private data instance manager.
// ********************************************************************
//
const G4LVManager& G4LogicalVolume::GetSubInstanceManager()
{
return subInstanceManager;
}
#define G4MT_solid ((subInstanceManager.offset[instanceID]).fSolid)
#define G4MT_sdetector ((subInstanceManager.offset[instanceID]).fSensitiveDetector)
#define G4MT_fmanager ((subInstanceManager.offset[instanceID]).fFieldManager)
#define G4MT_material ((subInstanceManager.offset[instanceID]).fMaterial)
#define G4MT_mass ((subInstanceManager.offset[instanceID]).fMass)
#define G4MT_ccouple ((subInstanceManager.offset[instanceID]).fCutsCouple)
#define G4MT_instance (subInstanceManager.offset[instanceID])
// ********************************************************************
// Constructor - sets member data and adds to logical Store,
@@ -215,6 +154,94 @@ G4LogicalVolume::~G4LogicalVolume()
G4LogicalVolumeStore::DeRegister(this);
}
// ********************************************************************
// InitialiseWorker
//
// This method is similar to the constructor. It is used by each worker
// thread to achieve the same effect as that of the master thread exept
// to register the new created instance. This method is invoked explicitly.
// It does not create a new G4LogicalVolume instance. It only assign the value
// for the fields encapsulated by the class G4LVData.
// ********************************************************************
//
void G4LogicalVolume::
InitialiseWorker( G4LogicalVolume* /*pMasterObject*/,
G4VSolid* pSolid,
G4VSensitiveDetector* pSDetector)
{
subInstanceManager.SlaveCopySubInstanceArray();
SetSolid(pSolid);
SetSensitiveDetector(pSDetector); // How this object is available now ?
AssignFieldManager(fFieldManager); // Should be set - but a per-thread copy is not available yet
// G4MT_fmanager= fFieldManager;
// Must not call SetFieldManager(fFieldManager, false); which propagates FieldMgr
#ifdef CLONE_FIELD_MGR
// Create a field FieldManager by cloning
G4FieldManager workerFldMgr= fFieldManager->GetWorkerClone(G4bool* created);
if( created || (GetFieldManager()!=workerFldMgr) )
{
SetFieldManager(fFieldManager, false); // which propagates FieldMgr
}else{
// Field manager existed and is equal to current one
AssignFieldManager(workerFldMgr);
}
#endif
}
// ********************************************************************
// TerminateWorker
//
// This method is similar to the destructor. It is used by each worker
// thread to achieve the partial effect as that of the master thread.
// For G4LogicalVolume instances, nothing more to do here.
// ********************************************************************
//
void G4LogicalVolume::
TerminateWorker( G4LogicalVolume* /*pMasterObject*/)
{
}
// ********************************************************************
// GetSubInstanceManager
//
// Returns the private data instance manager.
// ********************************************************************
//
const G4LVManager& G4LogicalVolume::GetSubInstanceManager()
{
return subInstanceManager;
}
// ********************************************************************
// GetFieldManager
// ********************************************************************
//
G4FieldManager* G4LogicalVolume::GetFieldManager() const
{
return G4MT_fmanager;
}
// ********************************************************************
// AssignFieldManager
// ********************************************************************
//
void G4LogicalVolume::AssignFieldManager( G4FieldManager *fldMgr)
{
G4MT_fmanager= fldMgr;
if(G4Threading::IsMasterThread()) fFieldManager = fldMgr;
}
// ********************************************************************
// IsExtended
// ********************************************************************
//
G4bool G4LogicalVolume::IsExtended() const
{
return false;
}
// ********************************************************************
// SetFieldManager
// ********************************************************************
@@ -238,6 +265,196 @@ G4LogicalVolume::SetFieldManager(G4FieldManager* pNewFieldMgr,
}
}
// ********************************************************************
// AddDaughter
// ********************************************************************
//
void G4LogicalVolume::AddDaughter(G4VPhysicalVolume* pNewDaughter)
{
if( !fDaughters.empty() && fDaughters[0]->IsReplicated() )
{
std::ostringstream message;
message << "ERROR - Attempt to place a volume in a mother volume" << G4endl
<< " already containing a replicated volume." << G4endl
<< " A volume can either contain several placements" << G4endl
<< " or a unique replica or parameterised volume !" << G4endl
<< " Mother logical volume: " << GetName() << G4endl
<< " Placing volume: " << pNewDaughter->GetName() << G4endl;
G4Exception("G4LogicalVolume::AddDaughter()", "GeomMgt0002",
FatalException, message,
"Replica or parameterised volume must be the only daughter !");
}
// Invalidate previous calculation of mass - if any - for all threads
G4MT_mass = 0.;
// SignalVolumeChange(); // fVolumeChanged= true;
fDaughters.push_back(pNewDaughter);
G4LogicalVolume* pDaughterLogical = pNewDaughter->GetLogicalVolume();
// Propagate the Field Manager, if the daughter has no field Manager.
//
G4FieldManager* pDaughterFieldManager = pDaughterLogical->GetFieldManager();
if( pDaughterFieldManager == 0 )
{
pDaughterLogical->SetFieldManager(G4MT_fmanager, false);
}
if (fRegion)
{
PropagateRegion();
fRegion->RegionModified(true);
}
}
// ********************************************************************
// RemoveDaughter
// ********************************************************************
//
void G4LogicalVolume::RemoveDaughter(const G4VPhysicalVolume* p)
{
G4PhysicalVolumeList::iterator i;
for ( i=fDaughters.begin(); i!=fDaughters.end(); ++i )
{
if (**i==*p)
{
fDaughters.erase(i);
break;
}
}
if (fRegion)
{
fRegion->RegionModified(true);
}
G4MT_mass = 0.;
}
// ********************************************************************
// ClearDaughters
// ********************************************************************
//
void G4LogicalVolume::ClearDaughters()
{
fDaughters.erase(fDaughters.begin(), fDaughters.end());
if (fRegion)
{
fRegion->RegionModified(true);
}
G4MT_mass = 0.;
}
// ********************************************************************
// ResetMass
// ********************************************************************
//
void G4LogicalVolume::ResetMass()
{
G4MT_mass= 0.0;
}
// ********************************************************************
// GetSolid
// ********************************************************************
//
G4VSolid* G4LogicalVolume::GetSolid(G4LVData &instLVdata) // const
{
return instLVdata.fSolid;
}
G4VSolid* G4LogicalVolume::GetSolid() const
{
// return G4MT_solid;
// return ((subInstanceManager.offset[instanceID]).fSolid);
return this->GetSolid( subInstanceManager.offset[instanceID] );
}
// ********************************************************************
// SetSolid
// ********************************************************************
//
void G4LogicalVolume::SetSolid(G4VSolid *pSolid)
{
// ((subInstanceManager.offset[instanceID]).fSolid) = pSolid;
G4MT_solid=pSolid;
// G4MT_mass = 0.;
this->ResetMass();
}
void G4LogicalVolume::SetSolid(G4LVData &instLVdata, G4VSolid *pSolid)
{
instLVdata.fSolid = pSolid;
// G4MT_solid=pSolid;
instLVdata.fMass= 0;
// A fast way to reset the mass ... ie G4MT_mass = 0.;
}
// ********************************************************************
// GetMaterial
// ********************************************************************
//
G4Material* G4LogicalVolume::GetMaterial() const
{
return G4MT_material;
}
// ********************************************************************
// SetMaterial
// ********************************************************************
//
void G4LogicalVolume::SetMaterial(G4Material *pMaterial)
{
G4MT_material=pMaterial;
G4MT_mass = 0.;
}
// ********************************************************************
// UpdateMaterial
// ********************************************************************
//
void G4LogicalVolume::UpdateMaterial(G4Material *pMaterial)
{
G4MT_material=pMaterial;
if(fRegion) { G4MT_ccouple = fRegion->FindCouple(pMaterial); }
G4MT_mass = 0.;
}
// ********************************************************************
// GetSensitiveDetector
// ********************************************************************
//
G4VSensitiveDetector* G4LogicalVolume::GetSensitiveDetector() const
{
return G4MT_sdetector;
}
// ********************************************************************
// SetSensitiveDetector
// ********************************************************************
//
void G4LogicalVolume::SetSensitiveDetector(G4VSensitiveDetector* pSDetector)
{
G4MT_sdetector = pSDetector;
if(G4Threading::IsMasterThread()) fSensitiveDetector = pSDetector;
}
// ********************************************************************
// GetMaterialCutsCouple
// ********************************************************************
//
const G4MaterialCutsCouple* G4LogicalVolume::GetMaterialCutsCouple() const
{
return G4MT_ccouple;
}
// ********************************************************************
// SetMaterialCutsCouple
// ********************************************************************
//
void G4LogicalVolume::SetMaterialCutsCouple(G4MaterialCutsCouple* cuts)
{
G4MT_ccouple = cuts;
}
// ********************************************************************
// IsAncestor
@@ -392,3 +609,4 @@ void G4LogicalVolume::SetVisAttributes (const G4VisAttributes& VA)
{
fVisAttributes = new G4VisAttributes(VA);
}
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4ReflectedSolid.cc 97686 2016-06-07 09:27:32Z gcosmo $
// $Id: G4ReflectedSolid.cc 100906 2016-11-03 09:59:32Z gcosmo $
//
//
// Implementation for G4ReflectedSolid class
@@ -34,7 +34,6 @@
// --------------------------------------------------------------------
#include "G4ReflectedSolid.hh"
#include "G4BoundingEnvelope.hh"
#include <sstream>
@@ -42,6 +41,7 @@
#include "G4Vector3D.hh"
#include "G4AffineTransform.hh"
#include "G4Transform3D.hh"
#include "G4VoxelLimits.hh"
#include "G4VPVParameterisation.hh"
@@ -129,6 +129,7 @@ G4VSolid* G4ReflectedSolid::GetConstituentMovedSolid() const
}
/////////////////////////////////////////////////////////////////////////////
//
G4Transform3D G4ReflectedSolid::GetTransform3D() const
{
@@ -147,37 +148,113 @@ void G4ReflectedSolid::SetDirectTransform3D(G4Transform3D& transform)
fRebuildPolyhedron = true;
}
///////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
// Get bounding box
void G4ReflectedSolid::Extent(G4ThreeVector& pMin, G4ThreeVector& pMax) const
{
fPtrSolid->Extent(pMin,pMax);
G4double xmin = pMin.x(), ymin = pMin.y(), zmin = pMin.z();
G4double xmax = pMax.x(), ymax = pMax.y(), zmax = pMax.z();
G4double xx = fDirectTransform3D->xx();
G4double yy = fDirectTransform3D->yy();
G4double zz = fDirectTransform3D->zz();
if (std::abs(xx) == 1 && std::abs(yy) == 1 && std::abs(zz) == 1)
{
// Special case of reflection in axis and pure translation
//
if (xx == -1) { G4double tmp = -xmin; xmin = -xmax; xmax = tmp; }
if (yy == -1) { G4double tmp = -ymin; ymin = -ymax; ymax = tmp; }
if (zz == -1) { G4double tmp = -zmin; zmin = -zmax; zmax = tmp; }
xmin += fDirectTransform3D->dx();
xmax += fDirectTransform3D->dx();
ymin += fDirectTransform3D->dy();
ymax += fDirectTransform3D->dy();
zmin += fDirectTransform3D->dz();
zmax += fDirectTransform3D->dz();
}
else
{
// Use additional reflection in Z to set up affine transformation
//
G4Transform3D transform3D = G4ReflectZ3D()*(*fDirectTransform3D);
G4AffineTransform transform(transform3D.getRotation().inverse(),
transform3D.getTranslation());
// Find bounding box
//
G4VoxelLimits unLimit;
fPtrSolid->CalculateExtent(kXAxis,unLimit,transform,xmin,xmax);
fPtrSolid->CalculateExtent(kYAxis,unLimit,transform,ymin,ymax);
fPtrSolid->CalculateExtent(kZAxis,unLimit,transform,zmin,zmax);
}
pMin.set(xmin,ymin,-zmax);
pMax.set(xmax,ymax,-zmin);
// 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("G4ReflectedSolid::Extent()", "GeomMgt0001",
JustWarning, message);
DumpInfo();
}
}
//////////////////////////////////////////////////////////////////////////
//
// Calculate extent under transform and specified limit
G4bool
G4ReflectedSolid::CalculateExtent( const EAxis pAxis,
const G4VoxelLimits& pVoxelLimit,
const G4VoxelLimits& pVoxelLimits,
const G4AffineTransform& pTransform,
G4double& pMin,
G4double& pMax ) const
{
G4VoxelLimits unLimit;
G4AffineTransform unTransform;
// Separation of transformations. Calculation of the extent is done
// in a reflection of the global space. In such way, the voxel is
// reflected, but the solid is transformed just by G4AffineTransform.
// It allows to use CalculateExtent() of the solid.
// Find bounding box
G4double x1,x2,y1,y2,z1,z2;
fPtrSolid->CalculateExtent(kXAxis,unLimit,unTransform,x1,x2);
fPtrSolid->CalculateExtent(kYAxis,unLimit,unTransform,y1,y2);
fPtrSolid->CalculateExtent(kZAxis,unLimit,unTransform,z1,z2);
G4BoundingEnvelope bbox(G4Point3D(x1,y1,z1),
G4Point3D(x2,y2,z2),kCarTolerance);
// Reflect voxel limits in Z
//
G4VoxelLimits limits;
limits.AddLimit(kXAxis, pVoxelLimits.GetMinXExtent(),
pVoxelLimits.GetMaxXExtent());
limits.AddLimit(kYAxis, pVoxelLimits.GetMinYExtent(),
pVoxelLimits.GetMaxYExtent());
limits.AddLimit(kZAxis,-pVoxelLimits.GetMaxZExtent(),
-pVoxelLimits.GetMinZExtent());
// Set combined transformation
G4Transform3D transform3D =
G4Transform3D(pTransform.NetRotation().inverse(),
pTransform.NetTranslation())*(*fDirectTransform3D);
// Set affine transformation
//
G4Transform3D transform3D = G4ReflectZ3D()*pTransform*(*fDirectTransform3D);
G4AffineTransform transform(transform3D.getRotation().inverse(),
transform3D.getTranslation());
// Find extent
return bbox.CalculateExtent(pAxis,pVoxelLimit,transform3D,pMin,pMax);
//
if (!fPtrSolid->CalculateExtent(pAxis, limits, transform, pMin, pMax))
{
return false;
}
if (pAxis == kZAxis)
{
G4double tmp= -pMin; pMin= -pMax; pMax= tmp;
}
return true;
}
//////////////////////////////////////////////////////////////
//
//
+41 -5
View File
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4Region.cc 91803 2015-08-06 12:17:01Z gcosmo $
// $Id: G4Region.cc 100428 2016-10-21 12:59:37Z gcosmo $
//
//
// class G4Region Implementation
@@ -40,11 +40,11 @@
#include "G4VUserRegionInformation.hh"
#include "G4Material.hh"
// This static member is thread local. For each thread, it points to the
// array of G4RegionData instances.
// These macros changes the references to fields that are now encapsulated
// in the class G4RegionData.
//
template <class G4RegionData> G4ThreadLocal
G4RegionData* G4GeomSplitter<G4RegionData>::offset = 0;
#define G4MT_fsmanager ((subInstanceManager.offset[instanceID]).fFastSimulationManager)
#define G4MT_rsaction ((subInstanceManager.offset[instanceID]).fRegionalSteppingAction)
// This new field helps to use the class G4RegionManager
//
@@ -121,6 +121,42 @@ G4Region::~G4Region()
if(fUserInfo) delete fUserInfo;
}
// ********************************************************************
// SetFastSimulationManager
// ********************************************************************
//
void G4Region::SetFastSimulationManager(G4FastSimulationManager* fsm)
{
G4MT_fsmanager = fsm;
}
// ********************************************************************
// GetFastSimulationManager
// ********************************************************************
//
G4FastSimulationManager* G4Region::GetFastSimulationManager() const
{
return G4MT_fsmanager;
}
// ********************************************************************
// SetRegionalSteppingAction
// ********************************************************************
//
void G4Region::SetRegionalSteppingAction(G4UserSteppingAction* rusa)
{
G4MT_rsaction = rusa;
}
// ********************************************************************
// GetRegionalSteppingAction
// ********************************************************************
//
G4UserSteppingAction* G4Region::GetRegionalSteppingAction() const
{
return G4MT_rsaction;
}
// *******************************************************************
// ScanVolumeTree:
// - Scans recursively the 'lv' logical volume tree, retrieves
+25 -201
View File
@@ -43,6 +43,7 @@
#include "G4VisExtent.hh"
#include "G4PhysicalConstants.hh"
#include "G4GeometryTolerance.hh"
#include "G4BoundingEnvelope.hh"
#include "G4AutoLock.hh"
@@ -194,154 +195,27 @@ G4bool G4USolid::CalculateExtent(const EAxis pAxis,
const G4AffineTransform& pTransform,
G4double& pMin, G4double& pMax) const
{
if (!pTransform.IsRotated())
UVector3 vmin, vmax;
fShape->Extent(vmin,vmax);
G4ThreeVector bmin(vmin.x(),vmin.y(),vmin.z());
G4ThreeVector bmax(vmax.x(),vmax.y(),vmax.z());
// Check correctness of the bounding box
//
if (bmin.x() >= bmax.x() || bmin.y() >= bmax.y() || bmin.z() >= bmax.z())
{
VUSolid::EAxisType eAxis = VUSolid::eXaxis;
G4double offset = pTransform.NetTranslation().x();
if (pAxis == kYAxis)
{
eAxis = VUSolid::eYaxis;
offset = pTransform.NetTranslation().y();
}
if (pAxis == kZAxis)
{
eAxis = VUSolid::eZaxis;
offset = pTransform.NetTranslation().z();
}
fShape->ExtentAxis(eAxis, pMin, pMax);
pMin += offset;
pMax += offset;
if (pVoxelLimit.IsLimited())
{
switch (pAxis)
{
case kXAxis:
if ((pMin > pVoxelLimit.GetMaxXExtent() + kCarTolerance) ||
(pMax < pVoxelLimit.GetMinXExtent() - kCarTolerance))
{
return false;
}
else
{
pMin = std::max(pMin, pVoxelLimit.GetMinXExtent());
pMax = std::min(pMax, pVoxelLimit.GetMaxXExtent());
}
break;
case kYAxis:
if ((pMin > pVoxelLimit.GetMaxYExtent() + kCarTolerance) ||
(pMax < pVoxelLimit.GetMinYExtent() - kCarTolerance))
{
return false;
}
else
{
pMin = std::max(pMin, pVoxelLimit.GetMinYExtent());
pMax = std::min(pMax, pVoxelLimit.GetMaxYExtent());
}
break;
case kZAxis:
if ((pMin > pVoxelLimit.GetMaxZExtent() + kCarTolerance) ||
(pMax < pVoxelLimit.GetMinZExtent() - kCarTolerance))
{
return false;
}
else
{
pMin = std::max(pMin, pVoxelLimit.GetMinZExtent());
pMax = std::min(pMax, pVoxelLimit.GetMaxZExtent());
}
break;
default:
break;
}
pMin -= kCarTolerance ;
pMax += kCarTolerance ;
}
return true;
std::ostringstream message;
message << "Bad bounding box (min >= max) for solid: "
<< GetName() << " - " << GetEntityType() << " !"
<< "\nmin = " << bmin
<< "\nmax = " << bmax;
G4Exception("G4USolid::CalculateExtent()", "GeomMgt0001",
JustWarning, message);
StreamInfo(G4cout);
}
else // General rotated case - create and clip mesh to boundaries
{
// Rotate BoundingBox and Calculate Extent as for BREPS
G4bool existsAfterClip = false ;
G4ThreeVectorList* vertices ;
pMin = +kInfinity ;
pMax = -kInfinity ;
// Calculate rotated vertex coordinates
vertices = CreateRotatedVertices(pTransform) ;
ClipCrossSection(vertices, 0, pVoxelLimit, pAxis, pMin, pMax) ;
ClipCrossSection(vertices, 4, pVoxelLimit, pAxis, pMin, pMax) ;
ClipBetweenSections(vertices, 0, pVoxelLimit, pAxis, pMin, pMax) ;
if (pVoxelLimit.IsLimited(pAxis) == false)
{
if ((pMin != kInfinity) || (pMax != -kInfinity))
{
existsAfterClip = true ;
// Add 2*tolerance to avoid precision troubles
pMin -= kCarTolerance;
pMax += kCarTolerance;
}
}
else
{
G4ThreeVector clipCentre(
(pVoxelLimit.GetMinXExtent() + pVoxelLimit.GetMaxXExtent()) * 0.5,
(pVoxelLimit.GetMinYExtent() + pVoxelLimit.GetMaxYExtent()) * 0.5,
(pVoxelLimit.GetMinZExtent() + pVoxelLimit.GetMaxZExtent()) * 0.5);
if ((pMin != kInfinity) || (pMax != -kInfinity))
{
existsAfterClip = true ;
// Check to see if endpoints are in the solid
clipCentre(pAxis) = pVoxelLimit.GetMinExtent(pAxis);
if (Inside(pTransform.Inverse().TransformPoint(clipCentre)) != kOutside)
{
pMin = pVoxelLimit.GetMinExtent(pAxis);
}
else
{
pMin -= kCarTolerance;
}
clipCentre(pAxis) = pVoxelLimit.GetMaxExtent(pAxis);
if (Inside(pTransform.Inverse().TransformPoint(clipCentre)) != kOutside)
{
pMax = pVoxelLimit.GetMaxExtent(pAxis);
}
else
{
pMax += kCarTolerance;
}
}
// Check for case where completely enveloping clipping volume
// If point inside then we are confident that the solid completely
// envelopes the clipping volume. Hence set min/max extents according
// to clipping volume extents along the specified axis.
else if (Inside(pTransform.Inverse().TransformPoint(clipCentre))
!= kOutside)
{
existsAfterClip = true ;
pMin = pVoxelLimit.GetMinExtent(pAxis) ;
pMax = pVoxelLimit.GetMaxExtent(pAxis) ;
}
}
delete vertices;
return existsAfterClip;
}
G4BoundingEnvelope bbox(bmin,bmax);
return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
}
void G4USolid::ComputeDimensions(G4VPVParameterisation*,
@@ -410,47 +284,6 @@ G4VSolid* G4USolid::Clone() const
return 0;
}
G4ThreeVectorList*
G4USolid::CreateRotatedVertices(const G4AffineTransform& pTransform) const
{
G4double xMin, xMax, yMin, yMax, zMin, zMax;
fShape->ExtentAxis(VUSolid::eXaxis, xMin, xMax);
fShape->ExtentAxis(VUSolid::eYaxis, yMin, yMax);
fShape->ExtentAxis(VUSolid::eZaxis, zMin, zMax);
G4ThreeVectorList* vertices;
vertices = new G4ThreeVectorList();
if (vertices)
{
vertices->reserve(8);
G4ThreeVector vertex0(xMin, yMin, zMin);
G4ThreeVector vertex1(xMax, yMin, zMin);
G4ThreeVector vertex2(xMax, yMax, zMin);
G4ThreeVector vertex3(xMin, yMax, zMin);
G4ThreeVector vertex4(xMin, yMin, zMax);
G4ThreeVector vertex5(xMax, yMin, zMax);
G4ThreeVector vertex6(xMax, yMax, zMax);
G4ThreeVector vertex7(xMin, yMax, zMax);
vertices->push_back(pTransform.TransformPoint(vertex0));
vertices->push_back(pTransform.TransformPoint(vertex1));
vertices->push_back(pTransform.TransformPoint(vertex2));
vertices->push_back(pTransform.TransformPoint(vertex3));
vertices->push_back(pTransform.TransformPoint(vertex4));
vertices->push_back(pTransform.TransformPoint(vertex5));
vertices->push_back(pTransform.TransformPoint(vertex6));
vertices->push_back(pTransform.TransformPoint(vertex7));
}
else
{
G4Exception("G4VUSolid::CreateRotatedVertices()", "FatalError",
FatalException, "Out of memory - Cannot allocate vertices!");
}
return vertices;
}
G4Polyhedron* G4USolid::CreatePolyhedron() const
{
// Must be implemented in concrete wrappers...
@@ -479,22 +312,13 @@ G4Polyhedron* G4USolid::GetPolyhedron() const
return fPolyhedron;
}
G4VisExtent G4USolid:: GetExtent() const
G4VisExtent G4USolid::GetExtent() const
{
G4VisExtent extent;
G4VoxelLimits voxelLimits; // Defaults to "infinite" limits.
G4AffineTransform affineTransform;
G4double vmin, vmax;
CalculateExtent(kXAxis, voxelLimits, affineTransform, vmin, vmax);
extent.SetXmin(vmin);
extent.SetXmax(vmax);
CalculateExtent(kYAxis, voxelLimits, affineTransform, vmin, vmax);
extent.SetYmin(vmin);
extent.SetYmax(vmax);
CalculateExtent(kZAxis, voxelLimits, affineTransform, vmin, vmax);
extent.SetZmin(vmin);
extent.SetZmax(vmax);
return extent;
UVector3 vmin, vmax;
fShape->Extent(vmin,vmax);
return G4VisExtent(vmin.x(),vmax.x(),
vmin.y(),vmax.y(),
vmin.z(),vmax.z());
}
#endif // G4GEOM_USE_USOLIDS
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4VPhysicalVolume.cc 93287 2015-10-15 09:50:22Z gcosmo $
// $Id: G4VPhysicalVolume.cc 100428 2016-10-21 12:59:37Z gcosmo $
//
//
// class G4VPhysicalVolume Implementation
@@ -36,48 +36,16 @@
#include "G4PhysicalVolumeStore.hh"
#include "G4LogicalVolume.hh"
// This static member is thread local. For each thread, it points to the
// array of G4PVData instances.
//
template <class G4PVData> G4ThreadLocal
G4PVData* G4GeomSplitter<G4PVData>::offset = 0;
// This new field helps to use the class G4PVManager
//
G4PVManager G4VPhysicalVolume::subInstanceManager;
// This method is similar to the constructor. It is used by each worker
// thread to achieve the same effect as that of the master thread exept
// to register the new created instance. This method is invoked explicitly.
// It does not create a new G4VPhysicalVolume instance.
// It only assign the value for the fields encapsulated by the class G4PVData.
// These macros change the references to fields that are now encapsulated
// in the class G4PVData.
//
void G4VPhysicalVolume::
InitialiseWorker( G4VPhysicalVolume* /*pMasterObject*/,
G4RotationMatrix *pRot,
const G4ThreeVector &tlate)
{
subInstanceManager.SlaveCopySubInstanceArray();
this->SetRotation( pRot ); // G4MT_rot = pRot;
this->SetTranslation( tlate ); // G4MT_trans = tlate;
// G4PhysicalVolumeStore::Register(this);
}
// This method is similar to the destructor. It is used by each worker
// thread to achieve the partial effect as that of the master thread.
// For G4VPhysicalVolume instances, nothing more to do here.
//
void G4VPhysicalVolume::TerminateWorker( G4VPhysicalVolume* /*pMasterObject*/)
{
}
// Returns the private data instance manager.
//
const G4PVManager& G4VPhysicalVolume::GetSubInstanceManager()
{
return subInstanceManager;
}
#define G4MT_rot ((subInstanceManager.offset[instanceID]).frot)
#define G4MT_trans ((subInstanceManager.offset[instanceID]).ftrans)
#define G4MT_pvdata (subInstanceManager.offset[instanceID])
// Constructor: init parameters and register in Store
//
@@ -123,11 +91,69 @@ G4VPhysicalVolume::~G4VPhysicalVolume()
G4PhysicalVolumeStore::DeRegister(this);
}
// This method is similar to the constructor. It is used by each worker
// thread to achieve the same effect as that of the master thread exept
// to register the new created instance. This method is invoked explicitly.
// It does not create a new G4VPhysicalVolume instance.
// It only assign the value for the fields encapsulated by the class G4PVData.
//
void G4VPhysicalVolume::
InitialiseWorker( G4VPhysicalVolume* /*pMasterObject*/,
G4RotationMatrix *pRot,
const G4ThreeVector &tlate)
{
subInstanceManager.SlaveCopySubInstanceArray();
this->SetRotation( pRot ); // G4MT_rot = pRot;
this->SetTranslation( tlate ); // G4MT_trans = tlate;
// G4PhysicalVolumeStore::Register(this);
}
// This method is similar to the destructor. It is used by each worker
// thread to achieve the partial effect as that of the master thread.
// For G4VPhysicalVolume instances, nothing more to do here.
//
void G4VPhysicalVolume::TerminateWorker( G4VPhysicalVolume* /*pMasterObject*/)
{
}
// Returns the private data instance manager.
//
const G4PVManager& G4VPhysicalVolume::GetSubInstanceManager()
{
return subInstanceManager;
}
G4int G4VPhysicalVolume::GetMultiplicity() const
{
return 1;
}
const G4ThreeVector& G4VPhysicalVolume::GetTranslation() const
{
return G4MT_trans;
}
void G4VPhysicalVolume::SetTranslation(const G4ThreeVector &vec)
{
G4MT_trans=vec;
}
const G4RotationMatrix* G4VPhysicalVolume::GetRotation() const
{
return G4MT_rot;
}
G4RotationMatrix* G4VPhysicalVolume::GetRotation()
{
return G4MT_rot;
}
void G4VPhysicalVolume::SetRotation(G4RotationMatrix *pRot)
{
G4MT_rot=pRot;
}
G4RotationMatrix* G4VPhysicalVolume::GetObjectRotation() const
{
static G4RotationMatrix aRotM;
@@ -144,6 +170,33 @@ G4RotationMatrix* G4VPhysicalVolume::GetObjectRotation() const
return retval;
}
G4RotationMatrix G4VPhysicalVolume::GetObjectRotationValue() const
{
G4RotationMatrix aRotM; // Initialised to identity
// Insure against G4MT_rot being a null pointer
if(G4MT_rot)
{
aRotM= G4MT_rot->inverse();
}
return aRotM;
}
G4ThreeVector G4VPhysicalVolume::GetObjectTranslation() const
{
return G4MT_trans;
}
const G4RotationMatrix* G4VPhysicalVolume::GetFrameRotation() const
{
return G4MT_rot;
}
G4ThreeVector G4VPhysicalVolume::GetFrameTranslation() const
{
return -G4MT_trans;
}
// Only implemented for placed and parameterised volumes.
// Not required for replicas.
//
+22 -1
View File
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4VSolid.cc 72936 2013-08-14 13:17:11Z gcosmo $
// $Id: G4VSolid.cc 100906 2016-11-03 09:59:32Z gcosmo $
//
// class G4VSolid
//
@@ -32,6 +32,7 @@
//
// History:
//
// 03.11.16 E.Tcherniaev, added Extent()
// 06.12.02 V.Grichine, restored original conditions in ClipPolygon()
// 10.05.02 V.Grichine, ClipPolygon(): clip only other axis and limited voxels
// 15.04.02 V.Grichine, bug fixed in ClipPolygon(): clip only one axis
@@ -618,6 +619,26 @@ G4VSolid::ClipPolygonToSimpleLimits( G4ThreeVectorList& pPolygon,
}
}
//////////////////////////////////////////////////////////////////////////
//
// Throw exception (warning) for solids not implementing the method
void G4VSolid::Extent(G4ThreeVector& pMin, G4ThreeVector& pMax) const
{
std::ostringstream message;
message << "Not implemented for solid: "
<< GetEntityType() << " !"
<< "\nReturning infinite boundinx box.";
G4Exception("G4VSolid::Extent()", "GeomMgt1001", JustWarning, message);
pMin.set(-kInfinity,-kInfinity,-kInfinity);
pMax.set( kInfinity, kInfinity, kInfinity);
}
//////////////////////////////////////////////////////////////////////////
//
// Get G4VisExtent - bounding box for graphics
G4VisExtent G4VSolid::GetExtent () const
{
G4VisExtent extent;