Geant4  10.02.p03
G4Box Class Reference

#include <G4Box.hh>

Inheritance diagram for G4Box:
Collaboration diagram for G4Box:

Public Member Functions

 G4Box (const G4String &pName, G4double pX, G4double pY, G4double pZ)
 
virtual ~G4Box ()
 
void ComputeDimensions (G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
 
G4bool CalculateExtent (const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pmin, G4double &pmax) const
 
G4double GetXHalfLength () const
 
G4double GetYHalfLength () const
 
G4double GetZHalfLength () const
 
void SetXHalfLength (G4double dx)
 
void SetYHalfLength (G4double dy)
 
void SetZHalfLength (G4double dz)
 
G4double GetCubicVolume ()
 
G4double GetSurfaceArea ()
 
EInside Inside (const G4ThreeVector &p) const
 
G4ThreeVector SurfaceNormal (const G4ThreeVector &p) const
 
G4double DistanceToIn (const G4ThreeVector &p, const G4ThreeVector &v) const
 
G4double DistanceToIn (const G4ThreeVector &p) const
 
G4double DistanceToOut (const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const
 
G4double DistanceToOut (const G4ThreeVector &p) const
 
G4GeometryType GetEntityType () const
 
G4ThreeVector GetPointOnSurface () const
 
G4VSolidClone () const
 
std::ostream & StreamInfo (std::ostream &os) const
 
void DescribeYourselfTo (G4VGraphicsScene &scene) const
 
G4VisExtent GetExtent () const
 
G4PolyhedronCreatePolyhedron () const
 
 G4Box (__void__ &)
 
 G4Box (const G4Box &rhs)
 
G4Boxoperator= (const G4Box &rhs)
 
- Public Member Functions inherited from G4CSGSolid
 G4CSGSolid (const G4String &pName)
 
virtual ~G4CSGSolid ()
 
virtual G4PolyhedronGetPolyhedron () const
 
 G4CSGSolid (__void__ &)
 
 G4CSGSolid (const G4CSGSolid &rhs)
 
G4CSGSolidoperator= (const G4CSGSolid &rhs)
 
- Public Member Functions inherited from G4VSolid
 G4VSolid (const G4String &name)
 
virtual ~G4VSolid ()
 
G4bool operator== (const G4VSolid &s) const
 
G4String GetName () const
 
void SetName (const G4String &name)
 
G4double GetTolerance () const
 
void DumpInfo () const
 
virtual const G4VSolidGetConstituentSolid (G4int no) const
 
virtual G4VSolidGetConstituentSolid (G4int no)
 
virtual const G4DisplacedSolidGetDisplacedSolidPtr () const
 
virtual G4DisplacedSolidGetDisplacedSolidPtr ()
 
 G4VSolid (__void__ &)
 
 G4VSolid (const G4VSolid &rhs)
 
G4VSolidoperator= (const G4VSolid &rhs)
 
G4double EstimateCubicVolume (G4int nStat, G4double epsilon) const
 
G4double EstimateSurfaceArea (G4int nStat, G4double ell) const
 

Protected Types

enum  ESide {
  kUndefined, kPX, kMX, kPY,
  kMY, kPZ, kMZ
}
 

Protected Member Functions

G4ThreeVectorListCreateRotatedVertices (const G4AffineTransform &pTransform) const
 
- Protected Member Functions inherited from G4CSGSolid
G4double GetRadiusInRing (G4double rmin, G4double rmax) const
 
- Protected Member Functions inherited from G4VSolid
void CalculateClippedPolygonExtent (G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipCrossSection (G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipBetweenSections (G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipPolygon (G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis) const
 

Private Member Functions

G4ThreeVector ApproxSurfaceNormal (const G4ThreeVector &p) const
 

Private Attributes

G4double fDx
 
G4double fDy
 
G4double fDz
 
G4double delta
 

Additional Inherited Members

- Protected Attributes inherited from G4CSGSolid
G4double fCubicVolume
 
G4double fSurfaceArea
 
G4bool fRebuildPolyhedron
 
G4PolyhedronfpPolyhedron
 
- Protected Attributes inherited from G4VSolid
G4double kCarTolerance
 

Detailed Description

Definition at line 64 of file G4Box.hh.

Member Enumeration Documentation

◆ ESide

enum G4Box::ESide
protected
Enumerator
kUndefined 
kPX 
kMX 
kPY 
kMY 
kPZ 
kMZ 

Definition at line 140 of file G4Box.hh.

Constructor & Destructor Documentation

◆ G4Box() [1/3]

G4Box::G4Box ( const G4String pName,
G4double  pX,
G4double  pY,
G4double  pZ 
)

Definition at line 60 of file G4Box.cc.

64  : G4CSGSolid(pName), fDx(pX), fDy(pY), fDz(pZ)
65 {
66  delta = 0.5*kCarTolerance;
67  if ( (pX < 2*kCarTolerance)
68  || (pY < 2*kCarTolerance)
69  || (pZ < 2*kCarTolerance) ) // limit to thickness of surfaces
70  {
71  std::ostringstream message;
72  message << "Dimensions too small for Solid: " << GetName() << "!" << G4endl
73  << " hX, hY, hZ = " << pX << ", " << pY << ", " << pZ;
74  G4Exception("G4Box::G4Box()", "GeomSolids0002", FatalException, message);
75  }
76 }
G4double fDy
Definition: G4Box.hh:151
G4double delta
Definition: G4Box.hh:152
G4String GetName() const
G4double fDz
Definition: G4Box.hh:151
G4double fDx
Definition: G4Box.hh:151
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4CSGSolid(const G4String &pName)
Definition: G4CSGSolid.cc:49
#define G4endl
Definition: G4ios.hh:61
G4double kCarTolerance
Definition: G4VSolid.hh:304
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~G4Box()

G4Box::~G4Box ( )
virtual

Definition at line 92 of file G4Box.cc.

93 {
94 }

◆ G4Box() [2/3]

G4Box::G4Box ( __void__ &  a)

Definition at line 83 of file G4Box.cc.

84  : G4CSGSolid(a), fDx(0.), fDy(0.), fDz(0.), delta(0.)
85 {
86 }
G4double fDy
Definition: G4Box.hh:151
G4double delta
Definition: G4Box.hh:152
G4double fDz
Definition: G4Box.hh:151
G4double fDx
Definition: G4Box.hh:151
G4CSGSolid(const G4String &pName)
Definition: G4CSGSolid.cc:49

◆ G4Box() [3/3]

G4Box::G4Box ( const G4Box rhs)

Definition at line 100 of file G4Box.cc.

101  : G4CSGSolid(rhs), fDx(rhs.fDx), fDy(rhs.fDy), fDz(rhs.fDz), delta(rhs.delta)
102 {
103 }
G4double fDy
Definition: G4Box.hh:151
G4double delta
Definition: G4Box.hh:152
G4double fDz
Definition: G4Box.hh:151
G4double fDx
Definition: G4Box.hh:151
G4CSGSolid(const G4String &pName)
Definition: G4CSGSolid.cc:49

Member Function Documentation

◆ ApproxSurfaceNormal()

G4ThreeVector G4Box::ApproxSurfaceNormal ( const G4ThreeVector p) const
private

Definition at line 494 of file G4Box.cc.

495 {
496  G4double distx, disty, distz ;
497  G4ThreeVector norm(0.,0.,0.);
498 
499  // Calculate distances as if in 1st octant
500 
501  distx = std::fabs(std::fabs(p.x()) - fDx) ;
502  disty = std::fabs(std::fabs(p.y()) - fDy) ;
503  distz = std::fabs(std::fabs(p.z()) - fDz) ;
504 
505  if ( distx <= disty )
506  {
507  if ( distx <= distz ) // Closest to X
508  {
509  if ( p.x() < 0 ) { norm = G4ThreeVector(-1.0,0,0) ; }
510  else { norm = G4ThreeVector( 1.0,0,0) ; }
511  }
512  else // Closest to Z
513  {
514  if ( p.z() < 0 ) { norm = G4ThreeVector(0,0,-1.0) ; }
515  else { norm = G4ThreeVector(0,0, 1.0) ; }
516  }
517  }
518  else
519  {
520  if ( disty <= distz ) // Closest to Y
521  {
522  if ( p.y() < 0 ) { norm = G4ThreeVector(0,-1.0,0) ; }
523  else { norm = G4ThreeVector(0, 1.0,0) ; }
524  }
525  else // Closest to Z
526  {
527  if ( p.z() < 0 ) { norm = G4ThreeVector(0,0,-1.0) ; }
528  else { norm = G4ThreeVector(0,0, 1.0) ; }
529  }
530  }
531  return norm;
532 }
G4double fDy
Definition: G4Box.hh:151
CLHEP::Hep3Vector G4ThreeVector
Float_t norm
G4double fDz
Definition: G4Box.hh:151
G4double fDx
Definition: G4Box.hh:151
double x() const
double y() const
double z() const
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CalculateExtent()

G4bool G4Box::CalculateExtent ( const EAxis  pAxis,
const G4VoxelLimits pVoxelLimit,
const G4AffineTransform pTransform,
G4double pmin,
G4double pmax 
) const
virtual

Implements G4VSolid.

Definition at line 207 of file G4Box.cc.

211 {
212  if (!pTransform.IsRotated())
213  {
214  // Special case handling for unrotated boxes
215  // Compute x/y/z mins and maxs respecting limits, with early returns
216  // if outside limits. Then switch() on pAxis
217 
218  G4double xoffset,xMin,xMax;
219  G4double yoffset,yMin,yMax;
220  G4double zoffset,zMin,zMax;
221 
222  xoffset = pTransform.NetTranslation().x() ;
223  xMin = xoffset - fDx ;
224  xMax = xoffset + fDx ;
225 
226  if (pVoxelLimit.IsXLimited())
227  {
228  if ((xMin > pVoxelLimit.GetMaxXExtent()+kCarTolerance) ||
229  (xMax < pVoxelLimit.GetMinXExtent()-kCarTolerance)) { return false ; }
230  else
231  {
232  xMin = std::max(xMin, pVoxelLimit.GetMinXExtent());
233  xMax = std::min(xMax, pVoxelLimit.GetMaxXExtent());
234  }
235  }
236  yoffset = pTransform.NetTranslation().y() ;
237  yMin = yoffset - fDy ;
238  yMax = yoffset + fDy ;
239 
240  if (pVoxelLimit.IsYLimited())
241  {
242  if ((yMin > pVoxelLimit.GetMaxYExtent()+kCarTolerance) ||
243  (yMax < pVoxelLimit.GetMinYExtent()-kCarTolerance)) { return false ; }
244  else
245  {
246  yMin = std::max(yMin, pVoxelLimit.GetMinYExtent());
247  yMax = std::min(yMax, pVoxelLimit.GetMaxYExtent());
248  }
249  }
250  zoffset = pTransform.NetTranslation().z() ;
251  zMin = zoffset - fDz ;
252  zMax = zoffset + fDz ;
253 
254  if (pVoxelLimit.IsZLimited())
255  {
256  if ((zMin > pVoxelLimit.GetMaxZExtent()+kCarTolerance) ||
257  (zMax < pVoxelLimit.GetMinZExtent()-kCarTolerance)) { return false ; }
258  else
259  {
260  zMin = std::max(zMin, pVoxelLimit.GetMinZExtent());
261  zMax = std::min(zMax, pVoxelLimit.GetMaxZExtent());
262  }
263  }
264  switch (pAxis)
265  {
266  case kXAxis:
267  pMin = xMin ;
268  pMax = xMax ;
269  break ;
270  case kYAxis:
271  pMin=yMin;
272  pMax=yMax;
273  break;
274  case kZAxis:
275  pMin=zMin;
276  pMax=zMax;
277  break;
278  default:
279  break;
280  }
281  pMin -= kCarTolerance ;
282  pMax += kCarTolerance ;
283 
284  return true;
285  }
286  else // General rotated case - create and clip mesh to boundaries
287  {
288  G4bool existsAfterClip = false ;
289  G4ThreeVectorList* vertices ;
290 
291  pMin = +kInfinity ;
292  pMax = -kInfinity ;
293 
294  // Calculate rotated vertex coordinates
295 
296  vertices = CreateRotatedVertices(pTransform) ;
297  ClipCrossSection(vertices,0,pVoxelLimit,pAxis,pMin,pMax) ;
298  ClipCrossSection(vertices,4,pVoxelLimit,pAxis,pMin,pMax) ;
299  ClipBetweenSections(vertices,0,pVoxelLimit,pAxis,pMin,pMax) ;
300 
301  if (pVoxelLimit.IsLimited(pAxis) == false)
302  {
303  if ( (pMin != kInfinity) || (pMax != -kInfinity) )
304  {
305  existsAfterClip = true ;
306 
307  // Add 2*tolerance to avoid precision troubles
308 
309  pMin -= kCarTolerance;
310  pMax += kCarTolerance;
311  }
312  }
313  else
314  {
315  G4ThreeVector clipCentre(
316  ( pVoxelLimit.GetMinXExtent()+pVoxelLimit.GetMaxXExtent())*0.5,
317  ( pVoxelLimit.GetMinYExtent()+pVoxelLimit.GetMaxYExtent())*0.5,
318  ( pVoxelLimit.GetMinZExtent()+pVoxelLimit.GetMaxZExtent())*0.5);
319 
320  if ( (pMin != kInfinity) || (pMax != -kInfinity) )
321  {
322  existsAfterClip = true ;
323 
324 
325  // Check to see if endpoints are in the solid
326 
327  clipCentre(pAxis) = pVoxelLimit.GetMinExtent(pAxis);
328 
329  if (Inside(pTransform.Inverse().TransformPoint(clipCentre)) != kOutside)
330  {
331  pMin = pVoxelLimit.GetMinExtent(pAxis);
332  }
333  else
334  {
335  pMin -= kCarTolerance;
336  }
337  clipCentre(pAxis) = pVoxelLimit.GetMaxExtent(pAxis);
338 
339  if (Inside(pTransform.Inverse().TransformPoint(clipCentre)) != kOutside)
340  {
341  pMax = pVoxelLimit.GetMaxExtent(pAxis);
342  }
343  else
344  {
345  pMax += kCarTolerance;
346  }
347  }
348 
349  // Check for case where completely enveloping clipping volume
350  // If point inside then we are confident that the solid completely
351  // envelopes the clipping volume. Hence set min/max extents according
352  // to clipping volume extents along the specified axis.
353 
354  else if (Inside(pTransform.Inverse().TransformPoint(clipCentre))
355  != kOutside)
356  {
357  existsAfterClip = true ;
358  pMin = pVoxelLimit.GetMinExtent(pAxis) ;
359  pMax = pVoxelLimit.GetMaxExtent(pAxis) ;
360  }
361  }
362  delete vertices;
363  return existsAfterClip;
364  }
365 }
void ClipBetweenSections(G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
Definition: G4VSolid.cc:378
G4ThreeVectorList * CreateRotatedVertices(const G4AffineTransform &pTransform) const
Definition: G4Box.cc:917
EInside Inside(const G4ThreeVector &p) const
Definition: G4Box.cc:371
G4double GetMinXExtent() const
G4double fDy
Definition: G4Box.hh:151
static const G4double kInfinity
Definition: geomdefs.hh:42
G4double GetMinYExtent() const
G4double GetMinZExtent() const
G4bool IsYLimited() const
G4ThreeVector TransformPoint(const G4ThreeVector &vec) const
G4bool IsLimited() const
void ClipCrossSection(G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
Definition: G4VSolid.cc:347
G4bool IsXLimited() const
G4bool IsRotated() const
G4double GetMaxZExtent() const
G4double fDz
Definition: G4Box.hh:151
G4double GetMaxXExtent() const
G4AffineTransform Inverse() const
G4ThreeVector NetTranslation() const
bool G4bool
Definition: G4Types.hh:79
G4double fDx
Definition: G4Box.hh:151
std::vector< G4ThreeVector > G4ThreeVectorList
Definition: G4VSolid.hh:79
G4double GetMinExtent(const EAxis pAxis) const
double x() const
G4bool IsZLimited() const
double y() const
double z() const
G4double GetMaxExtent(const EAxis pAxis) const
G4double kCarTolerance
Definition: G4VSolid.hh:304
double G4double
Definition: G4Types.hh:76
G4double GetMaxYExtent() const
Here is the call graph for this function:

◆ Clone()

G4VSolid * G4Box::Clone ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 1028 of file G4Box.cc.

1029 {
1030  return new G4Box(*this);
1031 }
G4Box(const G4String &pName, G4double pX, G4double pY, G4double pZ)
Definition: G4Box.cc:60
Here is the call graph for this function:

◆ ComputeDimensions()

void G4Box::ComputeDimensions ( G4VPVParameterisation p,
const G4int  n,
const G4VPhysicalVolume pRep 
)
virtual

Reimplemented from G4VSolid.

Definition at line 196 of file G4Box.cc.

199 {
200  p->ComputeDimensions(*this,n,pRep);
201 }
Char_t n[5]
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
Here is the call graph for this function:

◆ CreatePolyhedron()

G4Polyhedron * G4Box::CreatePolyhedron ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 1047 of file G4Box.cc.

1048 {
1049  return new G4PolyhedronBox (fDx, fDy, fDz);
1050 }
G4double fDy
Definition: G4Box.hh:151
G4double fDz
Definition: G4Box.hh:151
G4double fDx
Definition: G4Box.hh:151
Here is the caller graph for this function:

◆ CreateRotatedVertices()

G4ThreeVectorList * G4Box::CreateRotatedVertices ( const G4AffineTransform pTransform) const
protected

Definition at line 917 of file G4Box.cc.

918 {
919  G4ThreeVectorList* vertices = new G4ThreeVectorList();
920 
921  if (vertices)
922  {
923  vertices->reserve(8);
924  G4ThreeVector vertex0(-fDx,-fDy,-fDz) ;
925  G4ThreeVector vertex1(fDx,-fDy,-fDz) ;
926  G4ThreeVector vertex2(fDx,fDy,-fDz) ;
927  G4ThreeVector vertex3(-fDx,fDy,-fDz) ;
928  G4ThreeVector vertex4(-fDx,-fDy,fDz) ;
929  G4ThreeVector vertex5(fDx,-fDy,fDz) ;
930  G4ThreeVector vertex6(fDx,fDy,fDz) ;
931  G4ThreeVector vertex7(-fDx,fDy,fDz) ;
932 
933  vertices->push_back(pTransform.TransformPoint(vertex0));
934  vertices->push_back(pTransform.TransformPoint(vertex1));
935  vertices->push_back(pTransform.TransformPoint(vertex2));
936  vertices->push_back(pTransform.TransformPoint(vertex3));
937  vertices->push_back(pTransform.TransformPoint(vertex4));
938  vertices->push_back(pTransform.TransformPoint(vertex5));
939  vertices->push_back(pTransform.TransformPoint(vertex6));
940  vertices->push_back(pTransform.TransformPoint(vertex7));
941  }
942  else
943  {
944  DumpInfo();
945  G4Exception("G4Box::CreateRotatedVertices()",
946  "GeomSolids0003", FatalException,
947  "Error in allocation of vertices. Out of memory !");
948  }
949  return vertices;
950 }
G4double fDy
Definition: G4Box.hh:151
G4ThreeVector TransformPoint(const G4ThreeVector &vec) const
void DumpInfo() const
G4double fDz
Definition: G4Box.hh:151
G4double fDx
Definition: G4Box.hh:151
std::vector< G4ThreeVector > G4ThreeVectorList
Definition: G4VSolid.hh:79
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DescribeYourselfTo()

void G4Box::DescribeYourselfTo ( G4VGraphicsScene scene) const
virtual

Implements G4VSolid.

Definition at line 1037 of file G4Box.cc.

1038 {
1039  scene.AddSolid (*this);
1040 }
virtual void AddSolid(const G4Box &)=0
Here is the call graph for this function:

◆ DistanceToIn() [1/2]

G4double G4Box::DistanceToIn ( const G4ThreeVector p,
const G4ThreeVector v 
) const
virtual

Implements G4VSolid.

Definition at line 555 of file G4Box.cc.

557 {
558  G4double safx, safy, safz ;
559  G4double smin=0.0, sminy, sminz ; // , sminx ;
560  G4double smax=kInfinity, smaxy, smaxz ; // , smaxx ; // they always > 0
561  G4double stmp ;
562  G4double sOut=kInfinity, sOuty=kInfinity, sOutz=kInfinity ;
563 
564  safx = std::fabs(p.x()) - fDx ; // minimum distance to x surface of shape
565  safy = std::fabs(p.y()) - fDy ;
566  safz = std::fabs(p.z()) - fDz ;
567 
568  // Will we intersect?
569  // If safx/y/z is >-tol/2 the point is outside/on the box's x/y/z extent.
570  // If both p.x/y/z and v.x/y/z repectively are both positive/negative,
571  // travel is in a direction away from the shape.
572 
573  if ( ((p.x()*v.x() >= 0.0) && (safx > -delta))
574  || ((p.y()*v.y() >= 0.0) && (safy > -delta))
575  || ((p.z()*v.z() >= 0.0) && (safz > -delta)) )
576  {
577  return kInfinity ; // travel away or parallel within tolerance
578  }
579 
580  // Compute min / max distances for x/y/z travel:
581  // X Planes
582 
583  if ( v.x() ) // != 0
584  {
585  stmp = 1.0/std::fabs(v.x()) ;
586 
587  if (safx >= 0.0)
588  {
589  smin = safx*stmp ;
590  smax = (fDx+std::fabs(p.x()))*stmp ;
591  }
592  else
593  {
594  if (v.x() < 0) { sOut = (fDx + p.x())*stmp ; }
595  else { sOut = (fDx - p.x())*stmp ; }
596  }
597  }
598 
599  // Y Planes
600 
601  if ( v.y() ) // != 0
602  {
603  stmp = 1.0/std::fabs(v.y()) ;
604 
605  if (safy >= 0.0)
606  {
607  sminy = safy*stmp ;
608  smaxy = (fDy+std::fabs(p.y()))*stmp ;
609 
610  if (sminy > smin) { smin=sminy ; }
611  if (smaxy < smax) { smax=smaxy ; }
612 
613  if (smin >= (smax-delta))
614  {
615  return kInfinity ; // touch XY corner
616  }
617  }
618  else
619  {
620  if (v.y() < 0) { sOuty = (fDy + p.y())*stmp ; }
621  else { sOuty = (fDy - p.y())*stmp ; }
622  if( sOuty < sOut ) { sOut = sOuty ; }
623  }
624  }
625 
626  // Z planes
627 
628  if ( v.z() ) // != 0
629  {
630  stmp = 1.0/std::fabs(v.z()) ;
631 
632  if ( safz >= 0.0 )
633  {
634  sminz = safz*stmp ;
635  smaxz = (fDz+std::fabs(p.z()))*stmp ;
636 
637  if (sminz > smin) { smin = sminz ; }
638  if (smaxz < smax) { smax = smaxz ; }
639 
640  if (smin >= (smax-delta))
641  {
642  return kInfinity ; // touch ZX or ZY corners
643  }
644  }
645  else
646  {
647  if (v.z() < 0) { sOutz = (fDz + p.z())*stmp ; }
648  else { sOutz = (fDz - p.z())*stmp ; }
649  if( sOutz < sOut ) { sOut = sOutz ; }
650  }
651  }
652 
653  if (sOut <= (smin + delta)) // travel over edge
654  {
655  return kInfinity ;
656  }
657  if (smin < delta) { smin = 0.0 ; }
658 
659  return smin ;
660 }
G4double fDy
Definition: G4Box.hh:151
static const G4double kInfinity
Definition: geomdefs.hh:42
G4double delta
Definition: G4Box.hh:152
const G4int smax
G4double fDz
Definition: G4Box.hh:151
G4double fDx
Definition: G4Box.hh:151
double x() const
double y() const
double z() const
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DistanceToIn() [2/2]

G4double G4Box::DistanceToIn ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Definition at line 669 of file G4Box.cc.

670 {
671  G4double safex, safey, safez, safe = 0.0 ;
672 
673  safex = std::fabs(p.x()) - fDx ;
674  safey = std::fabs(p.y()) - fDy ;
675  safez = std::fabs(p.z()) - fDz ;
676 
677  if (safex > safe) { safe = safex ; }
678  if (safey > safe) { safe = safey ; }
679  if (safez > safe) { safe = safez ; }
680 
681  return safe ;
682 }
G4double fDy
Definition: G4Box.hh:151
G4double fDz
Definition: G4Box.hh:151
G4double fDx
Definition: G4Box.hh:151
double x() const
double y() const
double z() const
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:

◆ DistanceToOut() [1/2]

G4double G4Box::DistanceToOut ( const G4ThreeVector p,
const G4ThreeVector v,
const G4bool  calcNorm = false,
G4bool validNorm = 0,
G4ThreeVector n = 0 
) const
virtual

Implements G4VSolid.

Definition at line 692 of file G4Box.cc.

695 {
696  ESide side = kUndefined ;
697  G4double pdist,stmp,snxt=kInfinity;
698 
699  if (calcNorm) { *validNorm = true ; } // All normals are valid
700 
701  if (v.x() > 0) // X planes
702  {
703  pdist = fDx - p.x() ;
704 
705  if (pdist > delta)
706  {
707  snxt = pdist/v.x() ;
708  side = kPX ;
709  }
710  else
711  {
712  if (calcNorm) { *n = G4ThreeVector(1,0,0) ; }
713  return snxt = 0 ;
714  }
715  }
716  else if (v.x() < 0)
717  {
718  pdist = fDx + p.x() ;
719 
720  if (pdist > delta)
721  {
722  snxt = -pdist/v.x() ;
723  side = kMX ;
724  }
725  else
726  {
727  if (calcNorm) { *n = G4ThreeVector(-1,0,0) ; }
728  return snxt = 0 ;
729  }
730  }
731 
732  if (v.y() > 0) // Y planes
733  {
734  pdist = fDy-p.y();
735 
736  if (pdist > delta)
737  {
738  stmp = pdist/v.y();
739 
740  if (stmp < snxt)
741  {
742  snxt = stmp;
743  side = kPY;
744  }
745  }
746  else
747  {
748  if (calcNorm) { *n = G4ThreeVector(0,1,0) ; }
749  return snxt = 0 ;
750  }
751  }
752  else if (v.y() < 0)
753  {
754  pdist = fDy + p.y() ;
755 
756  if (pdist > delta)
757  {
758  stmp = -pdist/v.y();
759 
760  if ( stmp < snxt )
761  {
762  snxt = stmp;
763  side = kMY;
764  }
765  }
766  else
767  {
768  if (calcNorm) { *n = G4ThreeVector(0,-1,0) ; }
769  return snxt = 0 ;
770  }
771  }
772 
773  if (v.z() > 0) // Z planes
774  {
775  pdist = fDz-p.z();
776 
777  if ( pdist > delta )
778  {
779  stmp = pdist/v.z();
780 
781  if ( stmp < snxt )
782  {
783  snxt = stmp;
784  side = kPZ;
785  }
786  }
787  else
788  {
789  if (calcNorm) { *n = G4ThreeVector(0,0,1) ; }
790  return snxt = 0 ;
791  }
792  }
793  else if (v.z() < 0)
794  {
795  pdist = fDz + p.z();
796 
797  if ( pdist > delta )
798  {
799  stmp = -pdist/v.z();
800 
801  if ( stmp < snxt )
802  {
803  snxt = stmp;
804  side = kMZ;
805  }
806  }
807  else
808  {
809  if (calcNorm) { *n = G4ThreeVector(0,0,-1) ; }
810  return snxt = 0 ;
811  }
812  }
813 
814  if (calcNorm)
815  {
816  switch (side)
817  {
818  case kPX:
819  *n=G4ThreeVector(1,0,0);
820  break;
821  case kMX:
822  *n=G4ThreeVector(-1,0,0);
823  break;
824  case kPY:
825  *n=G4ThreeVector(0,1,0);
826  break;
827  case kMY:
828  *n=G4ThreeVector(0,-1,0);
829  break;
830  case kPZ:
831  *n=G4ThreeVector(0,0,1);
832  break;
833  case kMZ:
834  *n=G4ThreeVector(0,0,-1);
835  break;
836  default:
837  G4cout << G4endl;
838  DumpInfo();
839  std::ostringstream message;
840  G4int oldprc = message.precision(16);
841  message << "Undefined side for valid surface normal to solid."
842  << G4endl
843  << "Position:" << G4endl << G4endl
844  << "p.x() = " << p.x()/mm << " mm" << G4endl
845  << "p.y() = " << p.y()/mm << " mm" << G4endl
846  << "p.z() = " << p.z()/mm << " mm" << G4endl << G4endl
847  << "Direction:" << G4endl << G4endl
848  << "v.x() = " << v.x() << G4endl
849  << "v.y() = " << v.y() << G4endl
850  << "v.z() = " << v.z() << G4endl << G4endl
851  << "Proposed distance :" << G4endl << G4endl
852  << "snxt = " << snxt/mm << " mm" << G4endl;
853  message.precision(oldprc);
854  G4Exception("G4Box::DistanceToOut(p,v,..)", "GeomSolids1002",
855  JustWarning, message);
856  break;
857  }
858  }
859  return snxt;
860 }
G4double fDy
Definition: G4Box.hh:151
static const G4double kInfinity
Definition: geomdefs.hh:42
CLHEP::Hep3Vector G4ThreeVector
G4double delta
Definition: G4Box.hh:152
int G4int
Definition: G4Types.hh:78
void DumpInfo() const
G4double fDz
Definition: G4Box.hh:151
G4GLOB_DLL std::ostream G4cout
G4double fDx
Definition: G4Box.hh:151
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double x() const
double y() const
double z() const
#define G4endl
Definition: G4ios.hh:61
ESide
Definition: G4Cons.cc:71
double G4double
Definition: G4Types.hh:76
static const double mm
Definition: G4SIunits.hh:114
Here is the call graph for this function:

◆ DistanceToOut() [2/2]

G4double G4Box::DistanceToOut ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Definition at line 867 of file G4Box.cc.

868 {
869  G4double safx1,safx2,safy1,safy2,safz1,safz2,safe=0.0;
870 
871 #ifdef G4CSGDEBUG
872  if( Inside(p) == kOutside )
873  {
874  G4int oldprc = G4cout.precision(16) ;
875  G4cout << G4endl ;
876  DumpInfo();
877  G4cout << "Position:" << G4endl << G4endl ;
878  G4cout << "p.x() = " << p.x()/mm << " mm" << G4endl ;
879  G4cout << "p.y() = " << p.y()/mm << " mm" << G4endl ;
880  G4cout << "p.z() = " << p.z()/mm << " mm" << G4endl << G4endl ;
881  G4cout.precision(oldprc) ;
882  G4Exception("G4Box::DistanceToOut(p)", "GeomSolids1002",
883  JustWarning, "Point p is outside !?" );
884  }
885 #endif
886 
887  safx1 = fDx - p.x() ;
888  safx2 = fDx + p.x() ;
889  safy1 = fDy - p.y() ;
890  safy2 = fDy + p.y() ;
891  safz1 = fDz - p.z() ;
892  safz2 = fDz + p.z() ;
893 
894  // shortest Dist to any boundary now MIN(safx1,safx2,safy1..)
895 
896  if (safx2 < safx1) { safe = safx2; }
897  else { safe = safx1; }
898  if (safy1 < safe) { safe = safy1; }
899  if (safy2 < safe) { safe = safy2; }
900  if (safz1 < safe) { safe = safz1; }
901  if (safz2 < safe) { safe = safz2; }
902 
903  if (safe < 0) { safe = 0 ; }
904  return safe ;
905 }
EInside Inside(const G4ThreeVector &p) const
Definition: G4Box.cc:371
G4double fDy
Definition: G4Box.hh:151
int G4int
Definition: G4Types.hh:78
void DumpInfo() const
G4double fDz
Definition: G4Box.hh:151
G4GLOB_DLL std::ostream G4cout
G4double fDx
Definition: G4Box.hh:151
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double x() const
double y() const
double z() const
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
static const double mm
Definition: G4SIunits.hh:114
Here is the call graph for this function:

◆ GetCubicVolume()

G4double G4Box::GetCubicVolume ( )
inlinevirtual

Reimplemented from G4VSolid.

◆ GetEntityType()

G4GeometryType G4Box::GetEntityType ( ) const
virtual

Implements G4VSolid.

Definition at line 956 of file G4Box.cc.

◆ GetExtent()

G4VisExtent G4Box::GetExtent ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 1042 of file G4Box.cc.

1043 {
1044  return G4VisExtent (-fDx, fDx, -fDy, fDy, -fDz, fDz);
1045 }
G4double fDy
Definition: G4Box.hh:151
G4double fDz
Definition: G4Box.hh:151
G4double fDx
Definition: G4Box.hh:151

◆ GetPointOnSurface()

G4ThreeVector G4Box::GetPointOnSurface ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 989 of file G4Box.cc.

990 {
991  G4double px, py, pz, select, sumS;
992  G4double Sxy = fDx*fDy, Sxz = fDx*fDz, Syz = fDy*fDz;
993 
994  sumS = Sxy + Sxz + Syz;
995  select = sumS*G4UniformRand();
996 
997  if( select < Sxy )
998  {
999  px = -fDx +2*fDx*G4UniformRand();
1000  py = -fDy +2*fDy*G4UniformRand();
1001 
1002  if(G4UniformRand() > 0.5) { pz = fDz; }
1003  else { pz = -fDz; }
1004  }
1005  else if ( ( select - Sxy ) < Sxz )
1006  {
1007  px = -fDx +2*fDx*G4UniformRand();
1008  pz = -fDz +2*fDz*G4UniformRand();
1009 
1010  if(G4UniformRand() > 0.5) { py = fDy; }
1011  else { py = -fDy; }
1012  }
1013  else
1014  {
1015  py = -fDy +2*fDy*G4UniformRand();
1016  pz = -fDz +2*fDz*G4UniformRand();
1017 
1018  if(G4UniformRand() > 0.5) { px = fDx; }
1019  else { px = -fDx; }
1020  }
1021  return G4ThreeVector(px,py,pz);
1022 }
G4double fDy
Definition: G4Box.hh:151
CLHEP::Hep3Vector G4ThreeVector
G4double fDz
Definition: G4Box.hh:151
#define G4UniformRand()
Definition: Randomize.hh:97
G4double fDx
Definition: G4Box.hh:151
double G4double
Definition: G4Types.hh:76

◆ GetSurfaceArea()

G4double G4Box::GetSurfaceArea ( )
inlinevirtual

Reimplemented from G4VSolid.

◆ GetXHalfLength()

G4double G4Box::GetXHalfLength ( ) const
inline
Here is the caller graph for this function:

◆ GetYHalfLength()

G4double G4Box::GetYHalfLength ( ) const
inline
Here is the caller graph for this function:

◆ GetZHalfLength()

G4double G4Box::GetZHalfLength ( ) const
inline
Here is the caller graph for this function:

◆ Inside()

EInside G4Box::Inside ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Definition at line 371 of file G4Box.cc.

372 {
373  EInside in = kOutside ;
374  G4ThreeVector q(std::fabs(p.x()), std::fabs(p.y()), std::fabs(p.z()));
375 
376  if ( q.x() <= (fDx - delta) )
377  {
378  if (q.y() <= (fDy - delta) )
379  {
380  if ( q.z() <= (fDz - delta) ) { in = kInside ; }
381  else if ( q.z() <= (fDz + delta) ) { in = kSurface ; }
382  }
383  else if ( q.y() <= (fDy + delta) )
384  {
385  if ( q.z() <= (fDz + delta) ) { in = kSurface ; }
386  }
387  }
388  else if ( q.x() <= (fDx + delta) )
389  {
390  if ( q.y() <= (fDy + delta) )
391  {
392  if ( q.z() <= (fDz + delta) ) { in = kSurface ; }
393  }
394  }
395  return in ;
396 }
G4double fDy
Definition: G4Box.hh:151
G4double delta
Definition: G4Box.hh:152
ifstream in
Definition: comparison.C:7
G4double fDz
Definition: G4Box.hh:151
G4double fDx
Definition: G4Box.hh:151
double x() const
double y() const
EInside
Definition: geomdefs.hh:58
double z() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

G4Box & G4Box::operator= ( const G4Box rhs)

Definition at line 109 of file G4Box.cc.

110 {
111  // Check assignment to self
112  //
113  if (this == &rhs) { return *this; }
114 
115  // Copy base class data
116  //
118 
119  // Copy data
120  //
121  fDx = rhs.fDx;
122  fDy = rhs.fDy;
123  fDz = rhs.fDz;
124  delta = rhs.delta;
125 
126  return *this;
127 }
G4double fDy
Definition: G4Box.hh:151
G4double delta
Definition: G4Box.hh:152
G4double fDz
Definition: G4Box.hh:151
G4double fDx
Definition: G4Box.hh:151
G4CSGSolid & operator=(const G4CSGSolid &rhs)
Definition: G4CSGSolid.cc:91
Here is the call graph for this function:

◆ SetXHalfLength()

void G4Box::SetXHalfLength ( G4double  dx)

Definition at line 131 of file G4Box.cc.

132 {
133  if(dx > 2*kCarTolerance) // limit to thickness of surfaces
134  {
135  fDx = dx;
136  }
137  else
138  {
139  std::ostringstream message;
140  message << "Dimension X too small for solid: " << GetName() << "!"
141  << G4endl
142  << " hX = " << dx;
143  G4Exception("G4Box::SetXHalfLength()", "GeomSolids0002",
144  FatalException, message);
145  }
146  fCubicVolume= 0.;
147  fSurfaceArea= 0.;
148  fRebuildPolyhedron = true;
149 }
G4bool fRebuildPolyhedron
Definition: G4CSGSolid.hh:80
G4double fCubicVolume
Definition: G4CSGSolid.hh:78
G4String GetName() const
G4double fSurfaceArea
Definition: G4CSGSolid.hh:79
G4double fDx
Definition: G4Box.hh:151
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define G4endl
Definition: G4ios.hh:61
G4double kCarTolerance
Definition: G4VSolid.hh:304
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetYHalfLength()

void G4Box::SetYHalfLength ( G4double  dy)

Definition at line 151 of file G4Box.cc.

152 {
153  if(dy > 2*kCarTolerance) // limit to thickness of surfaces
154  {
155  fDy = dy;
156  }
157  else
158  {
159  std::ostringstream message;
160  message << "Dimension Y too small for solid: " << GetName() << "!"
161  << G4endl
162  << " hY = " << dy;
163  G4Exception("G4Box::SetYHalfLength()", "GeomSolids0002",
164  FatalException, message);
165  }
166  fCubicVolume= 0.;
167  fSurfaceArea= 0.;
168  fRebuildPolyhedron = true;
169 }
G4double fDy
Definition: G4Box.hh:151
G4bool fRebuildPolyhedron
Definition: G4CSGSolid.hh:80
G4double fCubicVolume
Definition: G4CSGSolid.hh:78
G4String GetName() const
G4double fSurfaceArea
Definition: G4CSGSolid.hh:79
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define G4endl
Definition: G4ios.hh:61
G4double kCarTolerance
Definition: G4VSolid.hh:304
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetZHalfLength()

void G4Box::SetZHalfLength ( G4double  dz)

Definition at line 171 of file G4Box.cc.

172 {
173  if(dz > 2*kCarTolerance) // limit to thickness of surfaces
174  {
175  fDz = dz;
176  }
177  else
178  {
179  std::ostringstream message;
180  message << "Dimension Z too small for solid: " << GetName() << "!"
181  << G4endl
182  << " hZ = " << dz;
183  G4Exception("G4Box::SetZHalfLength()", "GeomSolids0002",
184  FatalException, message);
185  }
186  fCubicVolume= 0.;
187  fSurfaceArea= 0.;
188  fRebuildPolyhedron = true;
189 }
G4bool fRebuildPolyhedron
Definition: G4CSGSolid.hh:80
G4double fCubicVolume
Definition: G4CSGSolid.hh:78
G4String GetName() const
G4double fDz
Definition: G4Box.hh:151
G4double fSurfaceArea
Definition: G4CSGSolid.hh:79
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define G4endl
Definition: G4ios.hh:61
G4double kCarTolerance
Definition: G4VSolid.hh:304
Here is the call graph for this function:
Here is the caller graph for this function:

◆ StreamInfo()

std::ostream & G4Box::StreamInfo ( std::ostream &  os) const
virtual

Reimplemented from G4CSGSolid.

Definition at line 965 of file G4Box.cc.

966 {
967  G4int oldprc = os.precision(16);
968  os << "-----------------------------------------------------------\n"
969  << " *** Dump for solid - " << GetName() << " ***\n"
970  << " ===================================================\n"
971  << " Solid type: G4Box\n"
972  << " Parameters: \n"
973  << " half length X: " << fDx/mm << " mm \n"
974  << " half length Y: " << fDy/mm << " mm \n"
975  << " half length Z: " << fDz/mm << " mm \n"
976  << "-----------------------------------------------------------\n";
977  os.precision(oldprc);
978 
979  return os;
980 }
G4double fDy
Definition: G4Box.hh:151
int G4int
Definition: G4Types.hh:78
G4String GetName() const
G4double fDz
Definition: G4Box.hh:151
G4double fDx
Definition: G4Box.hh:151
static const double mm
Definition: G4SIunits.hh:114
Here is the call graph for this function:

◆ SurfaceNormal()

G4ThreeVector G4Box::SurfaceNormal ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Definition at line 404 of file G4Box.cc.

405 {
406  G4double distx, disty, distz ;
407  G4ThreeVector norm(0.,0.,0.);
408 
409  // Calculate distances as if in 1st octant
410 
411  distx = std::fabs(std::fabs(p.x()) - fDx) ;
412  disty = std::fabs(std::fabs(p.y()) - fDy) ;
413  distz = std::fabs(std::fabs(p.z()) - fDz) ;
414 
415  // New code for particle on surface including edges and corners with specific
416  // normals
417 
418  const G4ThreeVector nX = G4ThreeVector( 1.0, 0,0 );
419  const G4ThreeVector nmX = G4ThreeVector(-1.0, 0,0 );
420  const G4ThreeVector nY = G4ThreeVector( 0, 1.0,0 );
421  const G4ThreeVector nmY = G4ThreeVector( 0,-1.0,0 );
422  const G4ThreeVector nZ = G4ThreeVector( 0, 0, 1.0);
423  const G4ThreeVector nmZ = G4ThreeVector( 0, 0,- 1.0);
424 
425  G4ThreeVector normX(0.,0.,0.), normY(0.,0.,0.), normZ(0.,0.,0.);
426  G4ThreeVector sumnorm(0., 0., 0.);
427  G4int noSurfaces=0;
428 
429  if (distx <= delta) // on X/mX surface and around
430  {
431  noSurfaces ++;
432  if ( p.x() >= 0. ) { normX= nX ; } // on +X surface : (1,0,0)
433  else { normX= nmX; } // (-1,0,0)
434  sumnorm= normX;
435  }
436 
437  if (disty <= delta) // on one of the +Y or -Y surfaces
438  {
439  noSurfaces ++;
440  if ( p.y() >= 0. ) { normY= nY; } // on +Y surface
441  else { normY= nmY; }
442  sumnorm += normY;
443  }
444 
445  if (distz <= delta) // on one of the +Z or -Z surfaces
446  {
447  noSurfaces ++;
448  if ( p.z() >= 0. ) { normZ= nZ; } // on +Z surface
449  else { normZ= nmZ; }
450  sumnorm += normZ;
451  }
452 
453  static const G4double invSqrt2 = 1.0 / std::sqrt(2.0);
454  static const G4double invSqrt3 = 1.0 / std::sqrt(3.0);
455 
456  if( noSurfaces > 0 )
457  {
458  if( noSurfaces == 1 )
459  {
460  norm= sumnorm;
461  }
462  else
463  {
464  // norm = sumnorm . unit();
465  if( noSurfaces == 2 )
466  {
467  // 2 surfaces -> on edge
468  norm = invSqrt2 * sumnorm;
469  }
470  else
471  {
472  // 3 surfaces (on corner)
473  norm = invSqrt3 * sumnorm;
474  }
475  }
476  }
477  else
478  {
479 #ifdef G4CSGDEBUG
480  G4Exception("G4Box::SurfaceNormal(p)", "Notification", JustWarning,
481  "Point p is not on surface !?" );
482 #endif
484  }
485 
486  return norm;
487 }
G4double fDy
Definition: G4Box.hh:151
CLHEP::Hep3Vector G4ThreeVector
G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector &p) const
Definition: G4Box.cc:494
G4double delta
Definition: G4Box.hh:152
Float_t norm
int G4int
Definition: G4Types.hh:78
G4double fDz
Definition: G4Box.hh:151
G4double fDx
Definition: G4Box.hh:151
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double x() const
double y() const
double z() const
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:

Member Data Documentation

◆ delta

G4double G4Box::delta
private

Definition at line 152 of file G4Box.hh.

◆ fDx

G4double G4Box::fDx
private

Definition at line 151 of file G4Box.hh.

◆ fDy

G4double G4Box::fDy
private

Definition at line 151 of file G4Box.hh.

◆ fDz

G4double G4Box::fDz
private

Definition at line 151 of file G4Box.hh.


The documentation for this class was generated from the following files: