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

G4Trd is a trapezoid with the X and Y dimensions varying along Z. More...

#include <G4Trd.hh>

Inheritance diagram for G4Trd:

Public Member Functions

 G4Trd (const G4String &pName, G4double pdx1, G4double pdx2, G4double pdy1, G4double pdy2, G4double pdz)
 ~G4Trd () override=default
G4double GetXHalfLength1 () const
G4double GetXHalfLength2 () const
G4double GetYHalfLength1 () const
G4double GetYHalfLength2 () const
G4double GetZHalfLength () const
void SetXHalfLength1 (G4double val)
void SetXHalfLength2 (G4double val)
void SetYHalfLength1 (G4double val)
void SetYHalfLength2 (G4double val)
void SetZHalfLength (G4double val)
void SetAllParameters (G4double pdx1, G4double pdx2, G4double pdy1, G4double pdy2, G4double pdz)
G4double GetCubicVolume () override
G4double GetSurfaceArea () override
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
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
G4PolyhedronCreatePolyhedron () const override
 G4Trd (__void__ &)
 G4Trd (const G4Trd &rhs)
G4Trdoperator= (const G4Trd &rhs)
Public Member Functions inherited from G4CSGSolid
 G4CSGSolid (const G4String &pName)
 ~G4CSGSolid () 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 G4VisExtent GetExtent () 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

G4Trd is a trapezoid with the X and Y dimensions varying along Z.

Definition at line 64 of file G4Trd.hh.

Constructor & Destructor Documentation

◆ G4Trd() [1/3]

G4Trd::G4Trd ( const G4String & pName,
G4double pdx1,
G4double pdx2,
G4double pdy1,
G4double pdy2,
G4double pdz )

Constructs a trapezoid with name, and half lengths.

Parameters
[in]pNameThe name of the solid.
[in]pdx1Half-length along X at the surface positioned at -dz.
[in]pdx2Half-length along X at the surface positioned at +dz.
[in]pdy1Half-length along Y at the surface positioned at -dz.
[in]pdy2Half-length along Y at the surface positioned at +dz.
[in]pdzHalf-length along Z axis.

Definition at line 60 of file G4Trd.cc.

64 : G4CSGSolid(pName), halfCarTolerance(0.5*kCarTolerance),
65 fDx1(pdx1), fDx2(pdx2), fDy1(pdy1), fDy2(pdy2), fDz(pdz)
66{
67 CheckParameters();
68 MakePlanes();
69}
G4CSGSolid(const G4String &pName)
Definition G4CSGSolid.cc:49
G4double kCarTolerance
Definition G4VSolid.hh:418

Referenced by Clone(), G4Trd(), operator=(), and SetZHalfLength().

◆ ~G4Trd()

G4Trd::~G4Trd ( )
overridedefault

Default destructor.

◆ G4Trd() [2/3]

G4Trd::G4Trd ( __void__ & a)

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

Definition at line 76 of file G4Trd.cc.

77 : G4CSGSolid(a), halfCarTolerance(0.5*kCarTolerance),
78 fDx1(1.), fDx2(1.), fDy1(1.), fDy2(1.), fDz(1.)
79{
80 MakePlanes();
81}
G4double a
Definition G4Trd.hh:233

◆ G4Trd() [3/3]

G4Trd::G4Trd ( const G4Trd & rhs)

Copy constructor and assignment operator.

Definition at line 87 of file G4Trd.cc.

88 : G4CSGSolid(rhs), halfCarTolerance(rhs.halfCarTolerance),
89 fDx1(rhs.fDx1), fDx2(rhs.fDx2),
90 fDy1(rhs.fDy1), fDy2(rhs.fDy2), fDz(rhs.fDz),
91 fHx(rhs.fHx), fHy(rhs.fHy)
92{
93 for (G4int i=0; i<4; ++i) { fPlanes[i] = rhs.fPlanes[i]; }
94}
int G4int
Definition G4Types.hh:85

Member Function Documentation

◆ BoundingLimits()

void G4Trd::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 218 of file G4Trd.cc.

219{
225
226 G4double xmax = std::max(dx1,dx2);
227 G4double ymax = std::max(dy1,dy2);
228 pMin.set(-xmax,-ymax,-dz);
229 pMax.set( xmax, ymax, dz);
230
231 // Check correctness of the bounding box
232 //
233 if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
234 {
235 std::ostringstream message;
236 message << "Bad bounding box (min >= max) for solid: "
237 << GetName() << " !"
238 << "\npMin = " << pMin
239 << "\npMax = " << pMax;
240 G4Exception("G4Trd::BoundingLimits()", "GeomMgt0001", JustWarning, message);
241 DumpInfo();
242 }
243}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
double G4double
Definition G4Types.hh:83
double z() const
double x() const
double y() const
void set(double x, double y, double z)
G4double GetXHalfLength2() const
G4double GetYHalfLength2() const
G4double GetXHalfLength1() const
G4double GetYHalfLength1() const
G4double GetZHalfLength() const
G4String GetName() const
void DumpInfo() const

Referenced by CalculateExtent().

◆ CalculateExtent()

G4bool G4Trd::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 249 of file G4Trd.cc.

253{
254 G4ThreeVector bmin, bmax;
255 G4bool exist;
256
257 // Check bounding box (bbox)
258 //
259 BoundingLimits(bmin,bmax);
260 G4BoundingEnvelope bbox(bmin,bmax);
261#ifdef G4BBOX_EXTENT
262 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
263#endif
264 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
265 {
266 return exist = pMin < pMax;
267 }
268
269 // Set bounding envelope (benv) and calculate extent
270 //
276
277 G4ThreeVectorList baseA(4), baseB(4);
278 baseA[0].set(-dx1,-dy1,-dz);
279 baseA[1].set( dx1,-dy1,-dz);
280 baseA[2].set( dx1, dy1,-dz);
281 baseA[3].set(-dx1, dy1,-dz);
282 baseB[0].set(-dx2,-dy2, dz);
283 baseB[1].set( dx2,-dy2, dz);
284 baseB[2].set( dx2, dy2, dz);
285 baseB[3].set(-dx2, dy2, dz);
286
287 std::vector<const G4ThreeVectorList *> polygons(2);
288 polygons[0] = &baseA;
289 polygons[1] = &baseB;
290
291 G4BoundingEnvelope benv(bmin,bmax,polygons);
292 exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
293 return exist;
294}
std::vector< G4ThreeVector > G4ThreeVectorList
CLHEP::Hep3Vector G4ThreeVector
bool G4bool
Definition G4Types.hh:86
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const override
Definition G4Trd.cc:218

◆ Clone()

G4VSolid * G4Trd::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 678 of file G4Trd.cc.

679{
680 return new G4Trd(*this);
681}
G4Trd(const G4String &pName, G4double pdx1, G4double pdx2, G4double pdy1, G4double pdy2, G4double pdz)
Definition G4Trd.cc:60

◆ ComputeDimensions()

void G4Trd::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 207 of file G4Trd.cc.

210{
211 p->ComputeDimensions(*this,n,pRep);
212}
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const

◆ CreatePolyhedron()

G4Polyhedron * G4Trd::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 805 of file G4Trd.cc.

806{
807 return new G4PolyhedronTrd2 (fDx1, fDx2, fDy1, fDy2, fDz);
808}

◆ DescribeYourselfTo()

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

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

Implements G4VSolid.

Definition at line 800 of file G4Trd.cc.

801{
802 scene.AddSolid (*this);
803}
virtual void AddSolid(const G4Box &)=0

◆ DistanceToIn() [1/2]

G4double G4Trd::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 524 of file G4Trd.cc.

525{
526 G4double dx = fPlanes[3].a*std::abs(p.x())+fPlanes[3].c*p.z()+fPlanes[3].d;
527 G4double dy = fPlanes[1].b*std::abs(p.y())+fPlanes[1].c*p.z()+fPlanes[1].d;
528 G4double dxy = std::max(dx,dy);
529
530 G4double dz = std::abs(p.z())-fDz;
531 G4double dist = std::max(dz,dxy);
532
533 return (dist > 0) ? dist : 0.;
534}

◆ DistanceToIn() [2/2]

G4double G4Trd::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 428 of file G4Trd.cc.

430{
431 // Z intersections
432 //
433 if ((std::abs(p.z()) - fDz) >= -halfCarTolerance && p.z()*v.z() >= 0)
434 {
435 return kInfinity;
436 }
437 G4double invz = (-v.z() == 0) ? DBL_MAX : -1./v.z();
438 G4double dz = (invz < 0) ? fDz : -fDz;
439 G4double tzmin = (p.z() + dz)*invz;
440 G4double tzmax = (p.z() - dz)*invz;
441
442 // Y intersections
443 //
444 G4double tmin0 = tzmin, tmax0 = tzmax;
445 G4double ya = fPlanes[0].b*v.y(), yb = fPlanes[0].c*v.z();
446 G4double yc = fPlanes[0].b*p.y(), yd = fPlanes[0].c*p.z()+fPlanes[0].d;
447 G4double cos0 = yb + ya;
448 G4double dis0 = yd + yc;
449 if (dis0 >= -halfCarTolerance)
450 {
451 if (cos0 >= 0) { return kInfinity; }
452 G4double tmp = -dis0/cos0;
453 if (tmin0 < tmp) { tmin0 = tmp; }
454 }
455 else if (cos0 > 0)
456 {
457 G4double tmp = -dis0/cos0;
458 if (tmax0 > tmp) { tmax0 = tmp; }
459 }
460
461 G4double tmin1 = tmin0, tmax1 = tmax0;
462 G4double cos1 = yb - ya;
463 G4double dis1 = yd - yc;
464 if (dis1 >= -halfCarTolerance)
465 {
466 if (cos1 >= 0) { return kInfinity; }
467 G4double tmp = -dis1/cos1;
468 if (tmin1 < tmp) { tmin1 = tmp; }
469 }
470 else if (cos1 > 0)
471 {
472 G4double tmp = -dis1/cos1;
473 if (tmax1 > tmp) { tmax1 = tmp; }
474 }
475
476 // X intersections
477 //
478 G4double tmin2 = tmin1, tmax2 = tmax1;
479 G4double xa = fPlanes[2].a*v.x(), xb = fPlanes[2].c*v.z();
480 G4double xc = fPlanes[2].a*p.x(), xd = fPlanes[2].c*p.z()+fPlanes[2].d;
481 G4double cos2 = xb + xa;
482 G4double dis2 = xd + xc;
483 if (dis2 >= -halfCarTolerance)
484 {
485 if (cos2 >= 0) { return kInfinity; }
486 G4double tmp = -dis2/cos2;
487 if (tmin2 < tmp) { tmin2 = tmp; }
488 }
489 else if (cos2 > 0)
490 {
491 G4double tmp = -dis2/cos2;
492 if (tmax2 > tmp) { tmax2 = tmp; }
493 }
494
495 G4double tmin3 = tmin2, tmax3 = tmax2;
496 G4double cos3 = xb - xa;
497 G4double dis3 = xd - xc;
498 if (dis3 >= -halfCarTolerance)
499 {
500 if (cos3 >= 0) { return kInfinity; }
501 G4double tmp = -dis3/cos3;
502 if (tmin3 < tmp) { tmin3 = tmp; }
503 }
504 else if (cos3 > 0)
505 {
506 G4double tmp = -dis3/cos3;
507 if (tmax3 > tmp) { tmax3 = tmp; }
508 }
509
510 // Find distance
511 //
512 G4double tmin = tmin3, tmax = tmax3;
513 if (tmax <= tmin + halfCarTolerance) { return kInfinity; // touch or no hit
514}
515 return (tmin < halfCarTolerance ) ? 0. : tmin;
516}
#define DBL_MAX
Definition templates.hh:62

◆ DistanceToOut() [1/2]

G4double G4Trd::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 628 of file G4Trd.cc.

629{
630#ifdef G4CSGDEBUG
631 if( Inside(p) == kOutside )
632 {
633 std::ostringstream message;
634 G4long oldprc = message.precision(16);
635 message << "Point p is outside (!?) of solid: " << GetName() << G4endl;
636 message << "Position:\n";
637 message << " p.x() = " << p.x()/mm << " mm\n";
638 message << " p.y() = " << p.y()/mm << " mm\n";
639 message << " p.z() = " << p.z()/mm << " mm";
640 G4cout.precision(oldprc);
641 G4Exception("G4Trd::DistanceToOut(p)", "GeomSolids1002",
642 JustWarning, message );
643 DumpInfo();
644 }
645#endif
646 G4double dx = fPlanes[3].a*std::abs(p.x())+fPlanes[3].c*p.z()+fPlanes[3].d;
647 G4double dy = fPlanes[1].b*std::abs(p.y())+fPlanes[1].c*p.z()+fPlanes[1].d;
648 G4double dxy = std::max(dx,dy);
649
650 G4double dz = std::abs(p.z())-fDz;
651 G4double dist = std::max(dz,dxy);
652
653 return (dist < 0) ? -dist : 0.;
654}
long G4long
Definition G4Types.hh:87
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
EInside Inside(const G4ThreeVector &p) const override
Definition G4Trd.cc:300
@ kOutside
Definition geomdefs.hh:68

◆ DistanceToOut() [2/2]

G4double G4Trd::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 542 of file G4Trd.cc.

545{
546 // Z intersections
547 //
548 if ((std::abs(p.z()) - fDz) >= -halfCarTolerance && p.z()*v.z() > 0)
549 {
550 if (calcNorm)
551 {
552 *validNorm = true;
553 n->set(0, 0, (p.z() < 0) ? -1 : 1);
554 }
555 return 0;
556 }
557 G4double vz = v.z();
558 G4double tmax = (vz == 0) ? DBL_MAX : (std::copysign(fDz,vz) - p.z())/vz;
559 G4int iside = (vz < 0) ? -4 : -2; // little trick: (-4+3)=-1, (-2+3)=+1
560
561 // Y intersections
562 //
563 G4int i = 0;
564 for ( ; i<2; ++i)
565 {
566 G4double cosa = fPlanes[i].b*v.y() + fPlanes[i].c*v.z();
567 if (cosa > 0)
568 {
569 G4double dist = fPlanes[i].b*p.y()+fPlanes[i].c*p.z()+fPlanes[i].d;
570 if (dist >= -halfCarTolerance)
571 {
572 if (calcNorm)
573 {
574 *validNorm = true;
575 n->set(0, fPlanes[i].b, fPlanes[i].c);
576 }
577 return 0;
578 }
579 G4double tmp = -dist/cosa;
580 if (tmax > tmp) { tmax = tmp; iside = i; }
581 }
582 }
583
584 // X intersections
585 //
586 for ( ; i<4; ++i)
587 {
588 G4double cosa = fPlanes[i].a*v.x()+fPlanes[i].c*v.z();
589 if (cosa > 0)
590 {
591 G4double dist = fPlanes[i].a*p.x()+fPlanes[i].c*p.z()+fPlanes[i].d;
592 if (dist >= -halfCarTolerance)
593 {
594 if (calcNorm)
595 {
596 *validNorm = true;
597 n->set(fPlanes[i].a, fPlanes[i].b, fPlanes[i].c);
598 }
599 return 0;
600 }
601 G4double tmp = -dist/cosa;
602 if (tmax > tmp) { tmax = tmp; iside = i; }
603 }
604 }
605
606 // Set normal, if required, and return distance
607 //
608 if (calcNorm)
609 {
610 *validNorm = true;
611 if (iside < 0)
612 {
613 n->set(0, 0, iside + 3); // (-4+3)=-1, (-2+3)=+1
614 }
615 else
616 {
617 n->set(fPlanes[iside].a, fPlanes[iside].b, fPlanes[iside].c);
618 }
619 }
620 return tmax;
621}
G4double b
Definition G4Trd.hh:233
G4double c
Definition G4Trd.hh:233

◆ GetCubicVolume()

G4double G4Trd::GetCubicVolume ( )
overridevirtual

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

Reimplemented from G4VSolid.

Definition at line 770 of file G4Trd.cc.

771{
772 if (fCubicVolume == 0)
773 {
774 G4AutoLock l(&trdMutex);
775 fCubicVolume = 2*fDz*((fDx1+fDx2)*(fDy1+fDy2) + (fDx2-fDx1)*(fDy2-fDy1)/3);
776 l.unlock();
777 }
778 return fCubicVolume;
779}
G4TemplateAutoLock< G4Mutex > G4AutoLock
G4double fCubicVolume
Definition G4CSGSolid.hh:92

◆ GetEntityType()

G4GeometryType G4Trd::GetEntityType ( ) const
overridevirtual

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

Implements G4VSolid.

Definition at line 660 of file G4Trd.cc.

661{
662 return {"G4Trd"};
663}

◆ GetPointOnSurface()

G4ThreeVector G4Trd::GetPointOnSurface ( ) const
overridevirtual

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

Reimplemented from G4VSolid.

Definition at line 710 of file G4Trd.cc.

711{
712 G4double sbot = 4.*fDx1*fDy1; // area of bottom base
713 G4double stop = 4.*fDx2*fDy2; // area of top base
714 G4double sbase = sbot + stop;
715 G4double sxz = (fDx1 + fDx2)*fHx; // area of Y face
716 G4double syz = (fDy1 + fDy2)*fHy; // area of X face
717 G4double stotal = sbase + 2.*(sxz + syz);
718 G4double select = stotal*G4QuickRand();
719
721 G4double u = G4QuickRand();
722 G4double v = G4QuickRand();
723 if (select < sbase)
724 {
725 G4bool ifbottom = (select < sbot);
726 G4double x = (ifbottom) ? fDx1 : fDx2;
727 G4double y = (ifbottom) ? fDy1 : fDy2;
728 G4double z = (ifbottom) ? -fDz : fDz;
729 p.set((2.*u - 1.)*x, (2.*v - 1.)*y, z);
730 }
731 else if (select < sbase + 2.*sxz)
732 {
733 G4double ysign = (select < sbase + sxz) ? 1. : -1.;
734 if (ysign < 0.) { select -= sxz; }
735 if (u + v > 1.)
736 {
737 u = 1. - u;
738 v = 1. - v;
739 }
740 G4ThreeVector p0(-fDx1,-fDy1,-fDz);
741 G4ThreeVector p1( fDx2,-fDy2, fDz);
742 G4ThreeVector p2 = (select < sbase + fDx1*fHx) ?
743 G4ThreeVector( fDx1,-fDy1,-fDz) : G4ThreeVector(-fDx2,-fDy2, fDz);
744 p = p0*(1. - u - v) + p1*u + p2*v;
745 p.setY(ysign*p.y());
746 }
747 else
748 {
749 G4double xsign = (select < sbase + 2.*sxz + syz) ? 1. : -1.;
750 if (xsign < 0.) { select -= syz; }
751 if (u + v > 1.)
752 {
753 u = 1. - u;
754 v = 1. - v;
755 }
756 G4ThreeVector p0(-fDx1, fDy1,-fDz);
757 G4ThreeVector p1(-fDx2,-fDy2, fDz);
758 G4ThreeVector p2 = (select < sbase + 2.*sxz + fDy1*fHy) ?
759 G4ThreeVector(-fDx1,-fDy1,-fDz) : G4ThreeVector(-fDx2, fDy2, fDz);
760 p = p0*(1. - u - v) + p1*u + p2*v;
761 p.setX(xsign*p.x());
762 }
763 return p;
764}
G4double G4QuickRand(uint32_t seed=0)
void setY(double)
void setX(double)

◆ GetSurfaceArea()

G4double G4Trd::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 785 of file G4Trd.cc.

786{
787 if (fSurfaceArea == 0)
788 {
789 G4AutoLock l(&trdMutex);
790 fSurfaceArea = 4*(fDx1*fDy1+fDx2*fDy2)+2*(fDx1+fDx2)*fHx+2*(fDy1+fDy2)*fHy;
791 l.unlock();
792 }
793 return fSurfaceArea;
794}
G4double fSurfaceArea
Definition G4CSGSolid.hh:93

◆ GetXHalfLength1()

◆ GetXHalfLength2()

◆ GetYHalfLength1()

◆ GetYHalfLength2()

◆ GetZHalfLength()

◆ Inside()

EInside G4Trd::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 300 of file G4Trd.cc.

301{
302 G4double dx = fPlanes[3].a*std::abs(p.x())+fPlanes[3].c*p.z()+fPlanes[3].d;
303 G4double dy = fPlanes[1].b*std::abs(p.y())+fPlanes[1].c*p.z()+fPlanes[1].d;
304 G4double dxy = std::max(dx,dy);
305
306 G4double dz = std::abs(p.z())-fDz;
307 G4double dist = std::max(dz,dxy);
308
309 return (dist > halfCarTolerance) ? kOutside :
310 ((dist > -halfCarTolerance) ? kSurface : kInside);
311}
@ kInside
Definition geomdefs.hh:70
@ kSurface
Definition geomdefs.hh:69

Referenced by DistanceToOut().

◆ IsFaceted()

G4bool G4Trd::IsFaceted ( ) const
overridevirtual

Returns true as the solid has only planar faces.

Reimplemented from G4VSolid.

Definition at line 669 of file G4Trd.cc.

670{
671 return true;
672}

◆ operator=()

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

Definition at line 100 of file G4Trd.cc.

101{
102 // Check assignment to self
103 //
104 if (this == &rhs) { return *this; }
105
106 // Copy base class data
107 //
109
110 // Copy data
111 //
112 halfCarTolerance = rhs.halfCarTolerance;
113 fDx1 = rhs.fDx1; fDx2 = rhs.fDx2;
114 fDy1 = rhs.fDy1; fDy2 = rhs.fDy2;
115 fDz = rhs.fDz;
116 fHx = rhs.fHx; fHy = rhs.fHy;
117 for (G4int i=0; i<4; ++i) { fPlanes[i] = rhs.fPlanes[i]; }
118
119 return *this;
120}
G4CSGSolid & operator=(const G4CSGSolid &rhs)
Definition G4CSGSolid.cc:89

◆ SetAllParameters()

void G4Trd::SetAllParameters ( G4double pdx1,
G4double pdx2,
G4double pdy1,
G4double pdy2,
G4double pdz )

Sets all parameters, as for constructor. Checks and sets half-widths.

Definition at line 126 of file G4Trd.cc.

128{
129 // Reset data of the base class
130 fCubicVolume = 0.;
131 fSurfaceArea = 0.;
132 fRebuildPolyhedron = true;
133
134 // Set parameters
135 fDx1 = pdx1; fDx2 = pdx2;
136 fDy1 = pdy1; fDy2 = pdy2;
137 fDz = pdz;
138
139 CheckParameters();
140 MakePlanes();
141}
G4bool fRebuildPolyhedron
Definition G4CSGSolid.hh:94

Referenced by G4ParameterisationTrdX::ComputeDimensions(), G4ParameterisationTrdY::ComputeDimensions(), and G4ParameterisationTrdZ::ComputeDimensions().

◆ SetXHalfLength1()

void G4Trd::SetXHalfLength1 ( G4double val)
inline

Modifiers.

◆ SetXHalfLength2()

void G4Trd::SetXHalfLength2 ( G4double val)
inline

◆ SetYHalfLength1()

void G4Trd::SetYHalfLength1 ( G4double val)
inline

◆ SetYHalfLength2()

void G4Trd::SetYHalfLength2 ( G4double val)
inline

◆ SetZHalfLength()

void G4Trd::SetZHalfLength ( G4double val)
inline

◆ StreamInfo()

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

Streams the object contents to an output stream.

Reimplemented from G4CSGSolid.

Definition at line 687 of file G4Trd.cc.

688{
689 G4long oldprc = os.precision(16);
690 os << "-----------------------------------------------------------\n"
691 << " *** Dump for solid - " << GetName() << " ***\n"
692 << " ===================================================\n"
693 << " Solid type: G4Trd\n"
694 << " Parameters: \n"
695 << " half length X, surface -dZ: " << fDx1/mm << " mm \n"
696 << " half length X, surface +dZ: " << fDx2/mm << " mm \n"
697 << " half length Y, surface -dZ: " << fDy1/mm << " mm \n"
698 << " half length Y, surface +dZ: " << fDy2/mm << " mm \n"
699 << " half length Z : " << fDz/mm << " mm \n"
700 << "-----------------------------------------------------------\n";
701 os.precision(oldprc);
702
703 return os;
704}

◆ SurfaceNormal()

G4ThreeVector G4Trd::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 317 of file G4Trd.cc.

318{
319 G4int nsurf = 0; // number of surfaces where p is placed
320
321 // Check Z faces
322 //
323 G4double nz = 0;
324 G4double dz = std::abs(p.z()) - fDz;
325 if (std::abs(dz) <= halfCarTolerance)
326 {
327 nz = (p.z() < 0) ? -1 : 1;
328 ++nsurf;
329 }
330
331 // Check Y faces
332 //
333 G4double ny = 0;
334 G4double dy1 = fPlanes[0].b*p.y();
335 G4double dy2 = fPlanes[0].c*p.z() + fPlanes[0].d;
336 if (std::abs(dy2 + dy1) <= halfCarTolerance)
337 {
338 ny += fPlanes[0].b;
339 nz += fPlanes[0].c;
340 ++nsurf;
341 }
342 if (std::abs(dy2 - dy1) <= halfCarTolerance)
343 {
344 ny += fPlanes[1].b;
345 nz += fPlanes[1].c;
346 ++nsurf;
347 }
348
349 // Check X faces
350 //
351 G4double nx = 0;
352 G4double dx1 = fPlanes[2].a*p.x();
353 G4double dx2 = fPlanes[2].c*p.z() + fPlanes[2].d;
354 if (std::abs(dx2 + dx1) <= halfCarTolerance)
355 {
356 nx += fPlanes[2].a;
357 nz += fPlanes[2].c;
358 ++nsurf;
359 }
360 if (std::abs(dx2 - dx1) <= halfCarTolerance)
361 {
362 nx += fPlanes[3].a;
363 nz += fPlanes[3].c;
364 ++nsurf;
365 }
366
367 // Return normal
368 //
369 if (nsurf == 1)
370 {
371 return {nx,ny,nz};
372 }
373 if (nsurf != 0)
374 {
375 return G4ThreeVector(nx,ny,nz).unit(); // edge or corner
376 }
377
378 // Point is not on the surface
379 //
380#ifdef G4CSGDEBUG
381 std::ostringstream message;
382 G4long oldprc = message.precision(16);
383 message << "Point p is not on surface (!?) of solid: "
384 << GetName() << G4endl;
385 message << "Position:\n";
386 message << " p.x() = " << p.x()/mm << " mm\n";
387 message << " p.y() = " << p.y()/mm << " mm\n";
388 message << " p.z() = " << p.z()/mm << " mm";
389 G4cout.precision(oldprc) ;
390 G4Exception("G4Trd::SurfaceNormal(p)", "GeomSolids1002",
391 JustWarning, message );
392 DumpInfo();
393#endif
394 return ApproxSurfaceNormal(p);
395}
Hep3Vector unit() const

Member Data Documentation

◆ a

G4double G4Trd::a

Definition at line 233 of file G4Trd.hh.

Referenced by DistanceToOut(), and G4Trd().

◆ b

G4double G4Trd::b

Definition at line 233 of file G4Trd.hh.

Referenced by DistanceToOut().

◆ c

G4double G4Trd::c

Definition at line 233 of file G4Trd.hh.

Referenced by DistanceToOut().

◆ d

G4double G4Trd::d

Definition at line 233 of file G4Trd.hh.


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