Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Box Class Reference

G4Box is a cuboid of given half lengths dx,dy,dz. The Box is centred on the origin with sides parallel to the x/y/z axes. More...

#include <G4Box.hh>

Inheritance diagram for G4Box:

Public Member Functions

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

Additional Inherited Members

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
Protected Attributes inherited from G4CSGSolid
G4double fCubicVolume = 0.0
G4double fSurfaceArea = 0.0
G4bool fRebuildPolyhedron = false
G4PolyhedronfpPolyhedron = nullptr
Protected Attributes inherited from G4VSolid
G4double kCarTolerance

Detailed Description

G4Box is a cuboid of given half lengths dx,dy,dz. The Box is centred on the origin with sides parallel to the x/y/z axes.

Definition at line 57 of file G4Box.hh.

Constructor & Destructor Documentation

◆ G4Box() [1/3]

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

Constructs a box with name, and half lengths pX, pY, pZ.

Parameters
[in]pNameThe name of the solid.
[in]pXHalf length in X.
[in]pYHalf length in Y.
[in]pZHalf length in Z.

Definition at line 58 of file G4Box.cc.

62 : G4CSGSolid(pName), fDx(pX), fDy(pY), fDz(pZ)
63{
64 delta = 0.5*kCarTolerance;
65 if (pX < 2*kCarTolerance ||
66 pY < 2*kCarTolerance ||
67 pZ < 2*kCarTolerance) // limit to thickness of surfaces
68 {
69 std::ostringstream message;
70 message << "Dimensions too small for Solid: " << GetName() << "!" << G4endl
71 << " hX, hY, hZ = " << pX << ", " << pY << ", " << pZ;
72 G4Exception("G4Box::G4Box()", "GeomSolids0002", FatalException, message);
73 }
74}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
#define G4endl
Definition G4ios.hh:67
G4CSGSolid(const G4String &pName)
Definition G4CSGSolid.cc:49
G4String GetName() const
G4double kCarTolerance
Definition G4VSolid.hh:418

Referenced by Clone(), G4Box(), and operator=().

◆ ~G4Box()

G4Box::~G4Box ( )
overridedefault

Default destructor.

◆ G4Box() [2/3]

G4Box::G4Box ( __void__ & a)

Fake default constructor for usage restricted to direct object persistency for clients requiring preallocation of memory for persistifiable objects.

Definition at line 81 of file G4Box.cc.

82 : G4CSGSolid(a)
83{
84}

◆ G4Box() [3/3]

G4Box::G4Box ( const G4Box & rhs)
default

Copy constructor and assignment operator.

Member Function Documentation

◆ BoundingLimits()

void G4Box::BoundingLimits ( G4ThreeVector & pMin,
G4ThreeVector & pMax ) const
overridevirtual

Computes the bounding limits of the solid.

Parameters
[out]pMinThe minimum bounding limit point.
[out]pMaxThe maximum bounding limit point.

Reimplemented from G4VSolid.

Definition at line 196 of file G4Box.cc.

197{
198 pMin.set(-fDx,-fDy,-fDz);
199 pMax.set( fDx, fDy, fDz);
200
201 // Check correctness of the bounding box
202 //
203 if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
204 {
205 std::ostringstream message;
206 message << "Bad bounding box (min >= max) for solid: "
207 << GetName() << " !"
208 << "\npMin = " << pMin
209 << "\npMax = " << pMax;
210 G4Exception("G4Box::BoundingLimits()", "GeomMgt0001", JustWarning, message);
211 DumpInfo();
212 }
213}
@ JustWarning
double z() const
double x() const
double y() const
void set(double x, double y, double z)
void DumpInfo() const

Referenced by CalculateExtent().

◆ CalculateExtent()

G4bool G4Box::CalculateExtent ( const EAxis pAxis,
const G4VoxelLimits & pVoxelLimit,
const G4AffineTransform & pTransform,
G4double & pMin,
G4double & pMax ) const
overridevirtual

Calculates the minimum and maximum extent of the solid, when under the specified transform, and within the specified limits.

Parameters
[in]pAxisThe axis along which compute the extent.
[in]pVoxelLimitThe limiting space dictated by voxels.
[in]pTransformThe internal transformation applied to the solid.
[out]pMinThe minimum extent value.
[out]pMaxThe maximum extent value.
Returns
True if the solid is intersected by the extent region.

Implements G4VSolid.

Definition at line 219 of file G4Box.cc.

223{
224 G4ThreeVector bmin, bmax;
225
226 // Get bounding box
227 BoundingLimits(bmin,bmax);
228
229 // Find extent
230 G4BoundingEnvelope bbox(bmin,bmax);
231 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
232}
CLHEP::Hep3Vector G4ThreeVector
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const override
Definition G4Box.cc:196

◆ Clone()

G4VSolid * G4Box::Clone ( ) const
overridevirtual

Makes a clone of the object for use in multi-treading.

Returns
A pointer to the new cloned allocated solid.

Reimplemented from G4VSolid.

Definition at line 563 of file G4Box.cc.

564{
565 return new G4Box(*this);
566}
G4Box(const G4String &pName, G4double pX, G4double pY, G4double pZ)
Definition G4Box.cc:58

◆ ComputeDimensions()

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

Dispatch method for parameterisation replication mechanism and dimension computation.

Reimplemented from G4VSolid.

Definition at line 185 of file G4Box.cc.

188{
189 p->ComputeDimensions(*this,n,pRep);
190}
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const

◆ CreatePolyhedron()

G4Polyhedron * G4Box::CreatePolyhedron ( ) const
overridevirtual

Creates a Polyhedron used for Visualisation. It is the caller's responsibility to delete it. A null pointer means "not created".

Reimplemented from G4VSolid.

Definition at line 582 of file G4Box.cc.

583{
584 return new G4PolyhedronBox (fDx, fDy, fDz);
585}

Referenced by G4GMocrenFileSceneHandler::AddSolid().

◆ DescribeYourselfTo()

void G4Box::DescribeYourselfTo ( G4VGraphicsScene & scene) const
overridevirtual

Methods for creating graphical representations (i.e. for visualisation).

Implements G4VSolid.

Definition at line 572 of file G4Box.cc.

573{
574 scene.AddSolid (*this);
575}
virtual void AddSolid(const G4Box &)=0

◆ DistanceToIn() [1/2]

G4double G4Box::DistanceToIn ( const G4ThreeVector & p) const
overridevirtual

Calculates the distance to the nearest surface of a shape from an outside point. The distance can be an underestimate.

Parameters
[in]pThe point at offset p.
Returns
The safety distance to enter the shape.

Implements G4VSolid.

Definition at line 357 of file G4Box.cc.

358{
359 G4double dist = std::max(std::max(
360 std::abs(p.x())-fDx,
361 std::abs(p.y())-fDy),
362 std::abs(p.z())-fDz);
363 return (dist > 0) ? dist : 0.;
364}
double G4double
Definition G4Types.hh:83

◆ DistanceToIn() [2/2]

G4double G4Box::DistanceToIn ( const G4ThreeVector & p,
const G4ThreeVector & v ) const
overridevirtual

Returns the distance along the normalised vector 'v' to the shape, from the point at offset 'p'. If there is no intersection, returns kInfinity. The first intersection resulting from 'leaving' a surface/volume is discarded. Hence, it is tolerant of points on the surface of the shape.

Parameters
[in]pThe point at offset p.
[in]vThe normalised direction vector.
Returns
The distance to enter the shape.

Implements G4VSolid.

Definition at line 319 of file G4Box.cc.

321{
322 // Check if point is on the surface and traveling away
323 //
324 if ((std::abs(p.x())-fDx) >= -delta && p.x()*v.x() >= 0) { return kInfinity; }
325 if ((std::abs(p.y())-fDy) >= -delta && p.y()*v.y() >= 0) { return kInfinity; }
326 if ((std::abs(p.z())-fDz) >= -delta && p.z()*v.z() >= 0) { return kInfinity; }
327
328 // Find intersection
329 //
330 G4double invx = (v.x() == 0) ? DBL_MAX : -1./v.x();
331 G4double dx = std::copysign(fDx,invx);
332 G4double txmin = (p.x() - dx)*invx;
333 G4double txmax = (p.x() + dx)*invx;
334
335 G4double invy = (v.y() == 0) ? DBL_MAX : -1./v.y();
336 G4double dy = std::copysign(fDy,invy);
337 G4double tymin = std::max(txmin,(p.y() - dy)*invy);
338 G4double tymax = std::min(txmax,(p.y() + dy)*invy);
339
340 G4double invz = (v.z() == 0) ? DBL_MAX : -1./v.z();
341 G4double dz = std::copysign(fDz,invz);
342 G4double tmin = std::max(tymin,(p.z() - dz)*invz);
343 G4double tmax = std::min(tymax,(p.z() + dz)*invz);
344
345 if (tmax <= tmin + delta) { return kInfinity; } // touch or no hit
346
347 return (tmin < delta) ? 0. : tmin;
348}
#define DBL_MAX
Definition templates.hh:62

◆ DistanceToOut() [1/2]

G4double G4Box::DistanceToOut ( const G4ThreeVector & p) const
overridevirtual

Calculates the distance to the nearest surface of a shape from an inside point 'p'. The distance can be an underestimate.

Parameters
[in]pThe point at offset p.
Returns
The safety distance to exit the shape.

Implements G4VSolid.

Definition at line 433 of file G4Box.cc.

434{
435#ifdef G4CSGDEBUG
436 if( Inside(p) == kOutside )
437 {
438 std::ostringstream message;
439 G4int oldprc = message.precision(16);
440 message << "Point p is outside (!?) of solid: " << GetName() << G4endl;
441 message << "Position:\n";
442 message << " p.x() = " << p.x()/mm << " mm\n";
443 message << " p.y() = " << p.y()/mm << " mm\n";
444 message << " p.z() = " << p.z()/mm << " mm";
445 G4cout.precision(oldprc);
446 G4Exception("G4Box::DistanceToOut(p)", "GeomSolids1002",
447 JustWarning, message );
448 DumpInfo();
449 }
450#endif
451 G4double dist = std::min(std::min(
452 fDx-std::abs(p.x()),
453 fDy-std::abs(p.y())),
454 fDz-std::abs(p.z()));
455 return (dist > 0) ? dist : 0.;
456}
int G4int
Definition G4Types.hh:85
G4GLOB_DLL std::ostream G4cout
EInside Inside(const G4ThreeVector &p) const override
Definition G4Box.cc:238
@ kOutside
Definition geomdefs.hh:68

◆ DistanceToOut() [2/2]

G4double G4Box::DistanceToOut ( const G4ThreeVector & p,
const G4ThreeVector & v,
const G4bool calcNorm = false,
G4bool * validNorm = nullptr,
G4ThreeVector * n = nullptr ) const
overridevirtual

Returns the distance along the normalised vector 'v' to the shape, from a point at an offset 'p' inside or on the surface of the shape. Intersections with surfaces, when the point is less than Tolerance/2 from a surface must be ignored.

Parameters
[in]pThe point at offset p.
[in]vThe normalised direction vector.
[in]calcNormFlag to indicate if to calculate the normal or not.
[out]validNormFlag set to true if the solid lies entirely behind or on the exiting surface. It is set false if the solid does not lie entirely behind or on the exiting surface. 'calcNorm' must be true, otherwise it is unused.
[out]nThe exiting outwards normal vector (undefined Magnitude). 'calcNorm' must be true, otherwise it is unused.
Returns
The distance to exit the shape.

Implements G4VSolid.

Definition at line 372 of file G4Box.cc.

376{
377 G4double px = p.x(), vx = v.x();
378 G4double py = p.y(), vy = v.y();
379 G4double pz = p.z(), vz = v.z();
380
381 if (!calcNorm) // calculation of normal is not needed
382 {
383 if ((std::abs(px) - fDx) >= -delta && px*vx > 0) { return 0.; }
384 if ((std::abs(py) - fDy) >= -delta && py*vy > 0) { return 0.; }
385 if ((std::abs(pz) - fDz) >= -delta && pz*vz > 0) { return 0.; }
386 G4double tx = (vx == 0) ? DBL_MAX : (std::copysign(fDx,vx) - px)/vx;
387 G4double ty = (vy == 0) ? DBL_MAX : (std::copysign(fDy,vy) - py)/vy;
388 G4double tz = (vz == 0) ? DBL_MAX : (std::copysign(fDz,vz) - pz)/vz;
389 G4double tmax = std::min(std::min(tx,ty),tz);
390 return tmax;
391 }
392
393 *validNorm = true;
394 // Check if point is on the surface and traveling away
395 if ((std::abs(px) - fDx) >= -delta && px*vx > 0)
396 {
397 n->set(std::copysign(1.,px), 0., 0.);
398 return 0.;
399 }
400 if ((std::abs(py) - fDy) >= -delta && py*vy > 0)
401 {
402 n->set(0., std::copysign(1.,py), 0.);
403 return 0.;
404 }
405 if ((std::abs(pz) - fDz) >= -delta && pz*vz > 0)
406 {
407 n->set(0., 0., std::copysign(1.,pz));
408 return 0.;
409 }
410
411 // Find intersection
412 G4double tx = (vx == 0) ? DBL_MAX : (std::copysign(fDx,vx) - px)/vx;
413 G4double ty = (vy == 0) ? DBL_MAX : (std::copysign(fDy,vy) - py)/vy;
414 G4double tz = (vz == 0) ? DBL_MAX : (std::copysign(fDz,vz) - pz)/vz;
415 G4double tmax = std::min(std::min(tx, ty), tz);
416
417 // Find normal
418 G4bool pickZ = (tmax == tz);
419 G4bool pickX = (!pickZ) && (tmax == tx);
420 G4bool pickY = (!pickZ) && (!pickX);
421 G4double nz = std::copysign((G4double)pickZ, vz);
422 G4double nx = std::copysign((G4double)pickX, vx);
423 G4double ny = std::copysign((G4double)pickY, vy);
424 n->set(nx, ny, nz);
425 return tmax;
426}
bool G4bool
Definition G4Types.hh:86

◆ GetCubicVolume()

G4double G4Box::GetCubicVolume ( )
overridevirtual

Returning an estimation of the solid volume (capacity) and surface area, in internal units.

Reimplemented from G4VSolid.

Definition at line 533 of file G4Box.cc.

534{
535 if (fCubicVolume == 0)
536 {
537 G4AutoLock l(&boxMutex);
538 fCubicVolume = 8*fDx*fDy*fDz;
539 l.unlock();
540 }
541 return fCubicVolume;
542}
G4TemplateAutoLock< G4Mutex > G4AutoLock
G4double fCubicVolume
Definition G4CSGSolid.hh:92

◆ GetEntityType()

G4GeometryType G4Box::GetEntityType ( ) const
overridevirtual

Returns the type ID, "G4Box" of the solid.

Implements G4VSolid.

Definition at line 462 of file G4Box.cc.

463{
464 return {"G4Box"};
465}

◆ GetExtent()

G4VisExtent G4Box::GetExtent ( ) const
overridevirtual

Provides extent (bounding box) as possible hint to the graphics view.

Reimplemented from G4VSolid.

Definition at line 577 of file G4Box.cc.

578{
579 return { -fDx, fDx, -fDy, fDy, -fDz, fDz };
580}

◆ GetPointOnSurface()

G4ThreeVector G4Box::GetPointOnSurface ( ) const
overridevirtual

Returns a random point located and uniformly distributed on the surface of the solid.

Reimplemented from G4VSolid.

Definition at line 500 of file G4Box.cc.

501{
502 G4double sxy = fDx*fDy, sxz = fDx*fDz, syz = fDy*fDz;
503 G4double select = (sxy + sxz + syz)*G4QuickRand();
504 G4double u = 2.*G4QuickRand() - 1.;
505 G4double v = 2.*G4QuickRand() - 1.;
506
507 G4double x, y, z;
508 if (select < sxy)
509 {
510 x = u*fDx;
511 y = v*fDy;
512 z = (select < 0.5*sxy) ? -fDz : fDz;
513 }
514 else if (select < sxy + sxz)
515 {
516 x = u*fDx;
517 y = (select < sxy + 0.5*sxz) ? -fDy : fDy;
518 z = v*fDz;
519 }
520 else
521 {
522 x = (select < sxy + sxz + 0.5*syz) ? -fDx : fDx;
523 y = u*fDy;
524 z = v*fDz;
525 }
526 return { x, y, z };
527}
G4double G4QuickRand(uint32_t seed=0)

◆ GetSurfaceArea()

G4double G4Box::GetSurfaceArea ( )
overridevirtual

Returns an estimation of the solid surface area in internal units. This method may be overloaded by derived classes to compute the exact geometrical quantity for solids where this is possible, or anyway to cache the computed value. Note: the computed value is NOT cached.

Reimplemented from G4VSolid.

Definition at line 548 of file G4Box.cc.

549{
550 if (fSurfaceArea == 0)
551 {
552 G4AutoLock l(&boxMutex);
553 fSurfaceArea = 8*(fDx*fDy+fDx*fDz+fDy*fDz);
554 l.unlock();
555 }
556 return fSurfaceArea;
557}
G4double fSurfaceArea
Definition G4CSGSolid.hh:93

◆ GetXHalfLength()

◆ GetYHalfLength()

◆ GetZHalfLength()

◆ Inside()

EInside G4Box::Inside ( const G4ThreeVector & p) const
overridevirtual

Concrete implementations of the expected query interfaces for solids, as defined in the base class G4VSolid.

Implements G4VSolid.

Definition at line 238 of file G4Box.cc.

239{
240 G4double dist = std::max(std::max(
241 std::abs(p.x())-fDx,
242 std::abs(p.y())-fDy),
243 std::abs(p.z())-fDz);
244 return (dist > delta) ? kOutside :
245 ((dist > -delta) ? kSurface : kInside);
246}
@ kInside
Definition geomdefs.hh:70
@ kSurface
Definition geomdefs.hh:69

Referenced by DistanceToOut().

◆ IsFaceted()

G4bool G4Box::IsFaceted ( ) const
overridevirtual

Returns true as the solid has only planar faces.

Reimplemented from G4VSolid.

Definition at line 471 of file G4Box.cc.

472{
473 return true;
474}

◆ operator=()

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

Definition at line 90 of file G4Box.cc.

91{
92 // Check assignment to self
93 //
94 if (this == &rhs) { return *this; }
95
96 // Copy base class data
97 //
99
100 // Copy data
101 //
102 fDx = rhs.fDx;
103 fDy = rhs.fDy;
104 fDz = rhs.fDz;
105 delta = rhs.delta;
106
107 return *this;
108}
G4CSGSolid & operator=(const G4CSGSolid &rhs)
Definition G4CSGSolid.cc:89

◆ SetXHalfLength()

void G4Box::SetXHalfLength ( G4double dx)

Definition at line 114 of file G4Box.cc.

115{
116 if(dx > 2*kCarTolerance) // limit to thickness of surfaces
117 {
118 fDx = dx;
119 }
120 else
121 {
122 std::ostringstream message;
123 message << "Dimension X too small for solid: " << GetName() << "!"
124 << G4endl
125 << " hX = " << dx;
126 G4Exception("G4Box::SetXHalfLength()", "GeomSolids0002",
127 FatalException, message);
128 }
129 fCubicVolume = 0.;
130 fSurfaceArea = 0.;
131 fRebuildPolyhedron = true;
132}
G4bool fRebuildPolyhedron
Definition G4CSGSolid.hh:94

Referenced by G4ParameterisationBoxX::ComputeDimensions(), G4ParameterisationBoxY::ComputeDimensions(), and G4ParameterisationBoxZ::ComputeDimensions().

◆ SetYHalfLength()

void G4Box::SetYHalfLength ( G4double dy)

Definition at line 138 of file G4Box.cc.

139{
140 if(dy > 2*kCarTolerance) // limit to thickness of surfaces
141 {
142 fDy = dy;
143 }
144 else
145 {
146 std::ostringstream message;
147 message << "Dimension Y too small for solid: " << GetName() << "!\n"
148 << " hY = " << dy;
149 G4Exception("G4Box::SetYHalfLength()", "GeomSolids0002",
150 FatalException, message);
151 }
152 fCubicVolume = 0.;
153 fSurfaceArea = 0.;
154 fRebuildPolyhedron = true;
155}

Referenced by G4ParameterisationBoxX::ComputeDimensions(), G4ParameterisationBoxY::ComputeDimensions(), and G4ParameterisationBoxZ::ComputeDimensions().

◆ SetZHalfLength()

void G4Box::SetZHalfLength ( G4double dz)

Definition at line 161 of file G4Box.cc.

162{
163 if(dz > 2*kCarTolerance) // limit to thickness of surfaces
164 {
165 fDz = dz;
166 }
167 else
168 {
169 std::ostringstream message;
170 message << "Dimension Z too small for solid: " << GetName() << "!\n"
171 << " hZ = " << dz;
172 G4Exception("G4Box::SetZHalfLength()", "GeomSolids0002",
173 FatalException, message);
174 }
175 fCubicVolume = 0.;
176 fSurfaceArea = 0.;
177 fRebuildPolyhedron = true;
178}

Referenced by G4ParameterisationBoxX::ComputeDimensions(), G4ParameterisationBoxY::ComputeDimensions(), and G4ParameterisationBoxZ::ComputeDimensions().

◆ StreamInfo()

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

Streams the object contents to an output stream.

Implements G4VSolid.

Definition at line 480 of file G4Box.cc.

481{
482 G4long oldprc = os.precision(16);
483 os << "-----------------------------------------------------------\n"
484 << " *** Dump for solid - " << GetName() << " ***\n"
485 << " ===================================================\n"
486 << "Solid type: G4Box\n"
487 << "Parameters: \n"
488 << " half length X: " << fDx/mm << " mm \n"
489 << " half length Y: " << fDy/mm << " mm \n"
490 << " half length Z: " << fDz/mm << " mm \n"
491 << "-----------------------------------------------------------\n";
492 os.precision(oldprc);
493 return os;
494}
long G4long
Definition G4Types.hh:87

◆ SurfaceNormal()

G4ThreeVector G4Box::SurfaceNormal ( const G4ThreeVector & p) const
overridevirtual

Returns the outwards pointing unit normal of the shape for the surface closest to the point at offset 'p'.

Parameters
[in]pThe point at offset p.
Returns
The outwards pointing unit normal.

Implements G4VSolid.

Definition at line 252 of file G4Box.cc.

253{
254 G4double px = p.x(), py = p.y(), pz = p.z();
255 G4ThreeVector norm(0.,0.,0.);
256 if (std::abs(std::abs(px)-fDx) <= delta) { norm.setX(std::copysign(1.,px)); }
257 if (std::abs(std::abs(py)-fDy) <= delta) { norm.setY(std::copysign(1.,py)); }
258 if (std::abs(std::abs(pz)-fDz) <= delta) { norm.setZ(std::copysign(1.,pz)); }
259
260 G4double nside = norm.mag2(); // number of sides = magnitude squared
261 if (nside == 1)
262 {
263 return norm;
264 }
265 if (nside > 1)
266 {
267 return norm.unit(); // edge or corner
268 }
269
270 // Point is not on the surface
271 //
272#ifdef G4CSGDEBUG
273 std::ostringstream message;
274 G4int oldprc = message.precision(16);
275 message << "Point p is not on surface (!?) of solid: "
276 << GetName() << G4endl;
277 message << "Position:\n";
278 message << " p.x() = " << p.x()/mm << " mm\n";
279 message << " p.y() = " << p.y()/mm << " mm\n";
280 message << " p.z() = " << p.z()/mm << " mm";
281 G4cout.precision(oldprc);
282 G4Exception("G4Box::SurfaceNormal(p)", "GeomSolids1002",
283 JustWarning, message );
284 DumpInfo();
285#endif
286
287 return ApproxSurfaceNormal(p);
288}

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