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

G4Para represents a parallelepiped, essentially a box with half lengths dx,dy,dz 'skewed' so that there are angles theta & phi of the polar line joining the faces at +-dz in z, and alpha formed by the y axis and the plane joining the centre of the faces parallel to the z-x plane at -dy and +dy. More...

#include <G4Para.hh>

Inheritance diagram for G4Para:

Public Member Functions

 G4Para (const G4String &pName, G4double pDx, G4double pDy, G4double pDz, G4double pAlpha, G4double pTheta, G4double pPhi)
 G4Para (const G4String &pName, const G4ThreeVector pt[8])
 ~G4Para () override=default
G4double GetZHalfLength () const
G4ThreeVector GetSymAxis () const
G4double GetYHalfLength () const
G4double GetXHalfLength () const
G4double GetTanAlpha () const
G4double GetAlpha () const
G4double GetTheta () const
G4double GetPhi () const
void SetXHalfLength (G4double val)
void SetYHalfLength (G4double val)
void SetZHalfLength (G4double val)
void SetAlpha (G4double alpha)
void SetTanAlpha (G4double val)
void SetThetaAndPhi (G4double pTheta, G4double pPhi)
void SetAllParameters (G4double pDx, G4double pDy, G4double pDz, G4double pAlpha, G4double pTheta, G4double pPhi)
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
 G4Para (__void__ &)
 G4Para (const G4Para &rhs)
G4Paraoperator= (const G4Para &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

G4Para represents a parallelepiped, essentially a box with half lengths dx,dy,dz 'skewed' so that there are angles theta & phi of the polar line joining the faces at +-dz in z, and alpha formed by the y axis and the plane joining the centre of the faces parallel to the z-x plane at -dy and +dy.

Definition at line 85 of file G4Para.hh.

Constructor & Destructor Documentation

◆ G4Para() [1/4]

G4Para::G4Para ( const G4String & pName,
G4double pDx,
G4double pDy,
G4double pDz,
G4double pAlpha,
G4double pTheta,
G4double pPhi )

Constructs a parallelepiped, given a name and its parameters.

Parameters
[in]pNameThe name of the solid.
[in]pDxHalf-length in x.
[in]pDyHalf-length in y.
[in]pDzHalf-length in z.
[in]pAlphaAngle formed by the Y axis and by the plane joining the centre of the faces parallel to the Z-X plane at -dy and +dy.
[in]pThetaPolar angle of the line joining the centres of the faces at -dz and +dz in Z.
[in]pPhiAzimuthal angle of the line joining the centres of the faces at -dz and +dz in Z.

Definition at line 59 of file G4Para.cc.

62 : G4CSGSolid(pName), halfCarTolerance(0.5*kCarTolerance)
63{
64 SetAllParameters(pDx, pDy, pDz, pAlpha, pTheta, pPhi);
65 fRebuildPolyhedron = false; // default value for G4CSGSolid
66}
G4bool fRebuildPolyhedron
Definition G4CSGSolid.hh:94
G4CSGSolid(const G4String &pName)
Definition G4CSGSolid.cc:49
void SetAllParameters(G4double pDx, G4double pDy, G4double pDz, G4double pAlpha, G4double pTheta, G4double pPhi)
Definition G4Para.cc:183
G4double kCarTolerance
Definition G4VSolid.hh:418

Referenced by Clone(), G4Para(), operator=(), and SetThetaAndPhi().

◆ G4Para() [2/4]

G4Para::G4Para ( const G4String & pName,
const G4ThreeVector pt[8] )

Constructs a parallelepiped, given a name and its 8 vertices.

Parameters
[in]pNameThe name of the solid.
[in]ptPoints of the 8 vertices.

Definition at line 72 of file G4Para.cc.

74 : G4CSGSolid(pName), halfCarTolerance(0.5*kCarTolerance)
75{
76 // Find dimensions and trigonometric values
77 //
78 fDx = (pt[3].x() - pt[2].x())*0.5;
79 fDy = (pt[2].y() - pt[1].y())*0.5;
80 fDz = pt[7].z();
81 CheckParameters(); // check dimensions
82
83 fTalpha = (pt[2].x() + pt[3].x() - pt[1].x() - pt[0].x())*0.25/fDy;
84 fTthetaCphi = (pt[4].x() + fDy*fTalpha + fDx)/fDz;
85 fTthetaSphi = (pt[4].y() + fDy)/fDz;
86 MakePlanes();
87
88 // Recompute vertices
89 //
90 G4ThreeVector v[8];
91 G4double DyTalpha = fDy*fTalpha;
92 G4double DzTthetaSphi = fDz*fTthetaSphi;
93 G4double DzTthetaCphi = fDz*fTthetaCphi;
94 v[0].set(-DzTthetaCphi-DyTalpha-fDx, -DzTthetaSphi-fDy, -fDz);
95 v[1].set(-DzTthetaCphi-DyTalpha+fDx, -DzTthetaSphi-fDy, -fDz);
96 v[2].set(-DzTthetaCphi+DyTalpha-fDx, -DzTthetaSphi+fDy, -fDz);
97 v[3].set(-DzTthetaCphi+DyTalpha+fDx, -DzTthetaSphi+fDy, -fDz);
98 v[4].set( DzTthetaCphi-DyTalpha-fDx, DzTthetaSphi-fDy, fDz);
99 v[5].set( DzTthetaCphi-DyTalpha+fDx, DzTthetaSphi-fDy, fDz);
100 v[6].set( DzTthetaCphi+DyTalpha-fDx, DzTthetaSphi+fDy, fDz);
101 v[7].set( DzTthetaCphi+DyTalpha+fDx, DzTthetaSphi+fDy, fDz);
102
103 // Compare with original vertices
104 //
105 for (G4int i=0; i<8; ++i)
106 {
107 G4double delx = std::abs(pt[i].x() - v[i].x());
108 G4double dely = std::abs(pt[i].y() - v[i].y());
109 G4double delz = std::abs(pt[i].z() - v[i].z());
110 G4double discrepancy = std::max(std::max(delx,dely),delz);
111 if (discrepancy > 0.1*kCarTolerance)
112 {
113 std::ostringstream message;
114 G4long oldprc = message.precision(16);
115 message << "Invalid vertice coordinates for Solid: " << GetName()
116 << "\nVertix #" << i << ", discrepancy = " << discrepancy
117 << "\n original : " << pt[i]
118 << "\n recomputed : " << v[i];
119 G4cout.precision(oldprc);
120 G4Exception("G4Para::G4Para()", "GeomSolids0002",
121 FatalException, message);
122
123 }
124 }
125}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
long G4long
Definition G4Types.hh:87
int G4int
Definition G4Types.hh:85
G4GLOB_DLL std::ostream G4cout
double z() const
double x() const
double y() const
void set(double x, double y, double z)
G4String GetName() const

◆ ~G4Para()

G4Para::~G4Para ( )
overridedefault

Default destructor.

◆ G4Para() [3/4]

G4Para::G4Para ( __void__ & a)

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

Definition at line 132 of file G4Para.cc.

133 : G4CSGSolid(a), halfCarTolerance(0.5*kCarTolerance)
134{
135 SetAllParameters(1., 1., 1., 0., 0., 0.);
136 fRebuildPolyhedron = false; // default value for G4CSGSolid
137}
G4double a
Definition G4Para.hh:269

◆ G4Para() [4/4]

G4Para::G4Para ( const G4Para & rhs)

Copy constructor and assignment operator.

Definition at line 143 of file G4Para.cc.

144 : G4CSGSolid(rhs), halfCarTolerance(rhs.halfCarTolerance),
145 fDx(rhs.fDx), fDy(rhs.fDy), fDz(rhs.fDz), fTalpha(rhs.fTalpha),
146 fTthetaCphi(rhs.fTthetaCphi),fTthetaSphi(rhs.fTthetaSphi)
147{
148 for (G4int i=0; i<4; ++i) { fPlanes[i] = rhs.fPlanes[i]; }
149}

Member Function Documentation

◆ BoundingLimits()

void G4Para::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 279 of file G4Para.cc.

280{
284
285 G4double x0 = dz*fTthetaCphi;
286 G4double x1 = dy*GetTanAlpha();
287 G4double xmin =
288 std::min(
289 std::min(
290 std::min(-x0-x1-dx,-x0+x1-dx),x0-x1-dx),x0+x1-dx);
291 G4double xmax =
292 std::max(
293 std::max(
294 std::max(-x0-x1+dx,-x0+x1+dx),x0-x1+dx),x0+x1+dx);
295
296 G4double y0 = dz*fTthetaSphi;
297 G4double ymin = std::min(-y0-dy,y0-dy);
298 G4double ymax = std::max(-y0+dy,y0+dy);
299
300 pMin.set(xmin,ymin,-dz);
301 pMax.set(xmax,ymax, dz);
302
303 // Check correctness of the bounding box
304 //
305 if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
306 {
307 std::ostringstream message;
308 message << "Bad bounding box (min >= max) for solid: "
309 << GetName() << " !"
310 << "\npMin = " << pMin
311 << "\npMax = " << pMax;
312 G4Exception("G4Para::BoundingLimits()", "GeomMgt0001",
313 JustWarning, message);
314 DumpInfo();
315 }
316}
@ JustWarning
G4double GetTanAlpha() const
G4double GetYHalfLength() const
G4double GetZHalfLength() const
G4double GetXHalfLength() const
void DumpInfo() const

Referenced by CalculateExtent().

◆ CalculateExtent()

G4bool G4Para::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 322 of file G4Para.cc.

326{
327 G4ThreeVector bmin, bmax;
328 G4bool exist;
329
330 // Check bounding box (bbox)
331 //
332 BoundingLimits(bmin,bmax);
333 G4BoundingEnvelope bbox(bmin,bmax);
334#ifdef G4BBOX_EXTENT
335 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
336#endif
337 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
338 {
339 return exist = pMin < pMax;
340 }
341
342 // Set bounding envelope (benv) and calculate extent
343 //
347
348 G4double x0 = dz*fTthetaCphi;
349 G4double x1 = dy*GetTanAlpha();
350 G4double y0 = dz*fTthetaSphi;
351
352 G4ThreeVectorList baseA(4), baseB(4);
353 baseA[0].set(-x0-x1-dx,-y0-dy,-dz);
354 baseA[1].set(-x0-x1+dx,-y0-dy,-dz);
355 baseA[2].set(-x0+x1+dx,-y0+dy,-dz);
356 baseA[3].set(-x0+x1-dx,-y0+dy,-dz);
357
358 baseB[0].set(+x0-x1-dx, y0-dy, dz);
359 baseB[1].set(+x0-x1+dx, y0-dy, dz);
360 baseB[2].set(+x0+x1+dx, y0+dy, dz);
361 baseB[3].set(+x0+x1-dx, y0+dy, dz);
362
363 std::vector<const G4ThreeVectorList *> polygons(2);
364 polygons[0] = &baseA;
365 polygons[1] = &baseB;
366
367 G4BoundingEnvelope benv(bmin,bmax,polygons);
368 exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
369 return exist;
370}
std::vector< G4ThreeVector > G4ThreeVectorList
bool G4bool
Definition G4Types.hh:86
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const override
Definition G4Para.cc:279

◆ Clone()

G4VSolid * G4Para::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 786 of file G4Para.cc.

787{
788 return new G4Para(*this);
789}
G4Para(const G4String &pName, G4double pDx, G4double pDy, G4double pDz, G4double pAlpha, G4double pTheta, G4double pPhi)
Definition G4Para.cc:59

◆ ComputeDimensions()

void G4Para::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 268 of file G4Para.cc.

271{
272 p->ComputeDimensions(*this,n,pRep);
273}
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const

◆ CreatePolyhedron()

G4Polyhedron * G4Para::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 898 of file G4Para.cc.

899{
900 G4double phi = std::atan2(fTthetaSphi, fTthetaCphi);
901 G4double alpha = std::atan(fTalpha);
902 G4double theta = std::atan(std::sqrt(fTthetaCphi*fTthetaCphi +
903 fTthetaSphi*fTthetaSphi));
904
905 return new G4PolyhedronPara(fDx, fDy, fDz, alpha, theta, phi);
906}

◆ DescribeYourselfTo()

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

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

Implements G4VSolid.

Definition at line 893 of file G4Para.cc.

894{
895 scene.AddSolid (*this);
896}
virtual void AddSolid(const G4Box &)=0

◆ DistanceToIn() [1/2]

G4double G4Para::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 604 of file G4Para.cc.

605{
606 G4double xx = fPlanes[2].a*p.x()+fPlanes[2].b*p.y()+fPlanes[2].c*p.z();
607 G4double dx = std::abs(xx) + fPlanes[2].d;
608
609 G4double yy = fPlanes[0].b*p.y()+fPlanes[0].c*p.z();
610 G4double dy = std::abs(yy) + fPlanes[0].d;
611 G4double dxy = std::max(dx,dy);
612
613 G4double dz = std::abs(p.z())-fDz;
614 G4double dist = std::max(dxy,dz);
615
616 return (dist > 0) ? dist : 0.;
617}

◆ DistanceToIn() [2/2]

G4double G4Para::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 510 of file G4Para.cc.

512{
513 // Z intersections
514 //
515 if ((std::abs(p.z()) - fDz) >= -halfCarTolerance && p.z()*v.z() >= 0)
516 {
517 return kInfinity;
518 }
519
520 G4double invz = (-v.z() == 0) ? DBL_MAX : -1./v.z();
521 G4double dz = (invz < 0) ? fDz : -fDz;
522 G4double tzmin = (p.z() + dz)*invz;
523 G4double tzmax = (p.z() - dz)*invz;
524
525 // Y intersections
526 //
527 G4double tmin0 = tzmin, tmax0 = tzmax;
528 G4double cos0 = fPlanes[0].b*v.y() + fPlanes[0].c*v.z();
529 G4double disy = fPlanes[0].b*p.y() + fPlanes[0].c*p.z();
530 G4double dis0 = fPlanes[0].d + disy;
531 if (dis0 >= -halfCarTolerance)
532 {
533 if (cos0 >= 0) { return kInfinity; }
534 G4double tmp = -dis0/cos0;
535 if (tmin0 < tmp) { tmin0 = tmp; }
536 }
537 else if (cos0 > 0)
538 {
539 G4double tmp = -dis0/cos0;
540 if (tmax0 > tmp) { tmax0 = tmp; }
541 }
542
543 G4double tmin1 = tmin0, tmax1 = tmax0;
544 G4double cos1 = -cos0;
545 G4double dis1 = fPlanes[1].d - disy;
546 if (dis1 >= -halfCarTolerance)
547 {
548 if (cos1 >= 0) { return kInfinity; }
549 G4double tmp = -dis1/cos1;
550 if (tmin1 < tmp) { tmin1 = tmp; }
551 }
552 else if (cos1 > 0)
553 {
554 G4double tmp = -dis1/cos1;
555 if (tmax1 > tmp) { tmax1 = tmp; }
556 }
557
558 // X intersections
559 //
560 G4double tmin2 = tmin1, tmax2 = tmax1;
561 G4double cos2 = fPlanes[2].a*v.x() + fPlanes[2].b*v.y() + fPlanes[2].c*v.z();
562 G4double disx = fPlanes[2].a*p.x() + fPlanes[2].b*p.y() + fPlanes[2].c*p.z();
563 G4double dis2 = fPlanes[2].d + disx;
564 if (dis2 >= -halfCarTolerance)
565 {
566 if (cos2 >= 0) { return kInfinity; }
567 G4double tmp = -dis2/cos2;
568 if (tmin2 < tmp) { tmin2 = tmp; }
569 }
570 else if (cos2 > 0)
571 {
572 G4double tmp = -dis2/cos2;
573 if (tmax2 > tmp) { tmax2 = tmp; }
574 }
575
576 G4double tmin3 = tmin2, tmax3 = tmax2;
577 G4double cos3 = -cos2;
578 G4double dis3 = fPlanes[3].d - disx;
579 if (dis3 >= -halfCarTolerance)
580 {
581 if (cos3 >= 0) { return kInfinity; }
582 G4double tmp = -dis3/cos3;
583 if (tmin3 < tmp) { tmin3 = tmp; }
584 }
585 else if (cos3 > 0)
586 {
587 G4double tmp = -dis3/cos3;
588 if (tmax3 > tmp) { tmax3 = tmp; }
589 }
590
591 // Find distance
592 //
593 G4double tmin = tmin3, tmax = tmax3;
594 if (tmax <= tmin + halfCarTolerance) { return kInfinity; } // touch or no hit
595
596 return (tmin < halfCarTolerance ) ? 0. : tmin;
597}
#define DBL_MAX
Definition templates.hh:62

◆ DistanceToOut() [1/2]

G4double G4Para::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 733 of file G4Para.cc.

734{
735#ifdef G4CSGDEBUG
736 if( Inside(p) == kOutside )
737 {
738 std::ostringstream message;
739 G4int oldprc = message.precision(16);
740 message << "Point p is outside (!?) of solid: " << GetName() << G4endl;
741 message << "Position:\n";
742 message << " p.x() = " << p.x()/mm << " mm\n";
743 message << " p.y() = " << p.y()/mm << " mm\n";
744 message << " p.z() = " << p.z()/mm << " mm";
745 G4cout.precision(oldprc) ;
746 G4Exception("G4Para::DistanceToOut(p)", "GeomSolids1002",
747 JustWarning, message );
748 DumpInfo();
749 }
750#endif
751 G4double xx = fPlanes[2].a*p.x()+fPlanes[2].b*p.y()+fPlanes[2].c*p.z();
752 G4double dx = std::abs(xx) + fPlanes[2].d;
753
754 G4double yy = fPlanes[0].b*p.y()+fPlanes[0].c*p.z();
755 G4double dy = std::abs(yy) + fPlanes[0].d;
756 G4double dxy = std::max(dx,dy);
757
758 G4double dz = std::abs(p.z())-fDz;
759 G4double dist = std::max(dxy,dz);
760
761 return (dist < 0) ? -dist : 0.;
762}
#define G4endl
Definition G4ios.hh:67
EInside Inside(const G4ThreeVector &p) const override
Definition G4Para.cc:377
@ kOutside
Definition geomdefs.hh:68

◆ DistanceToOut() [2/2]

G4double G4Para::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 625 of file G4Para.cc.

628{
629 // Z intersections
630 //
631 if ((std::abs(p.z()) - fDz) >= -halfCarTolerance && p.z()*v.z() > 0)
632 {
633 if (calcNorm)
634 {
635 *validNorm = true;
636 n->set(0, 0, (p.z() < 0) ? -1 : 1);
637 }
638 return 0.;
639 }
640 G4double vz = v.z();
641 G4double tmax = (vz == 0) ? DBL_MAX : (std::copysign(fDz,vz) - p.z())/vz;
642 G4int iside = (vz < 0) ? -4 : -2; // little trick: (-4+3)=-1, (-2+3)=+1
643
644 // Y intersections
645 //
646 G4double cos0 = fPlanes[0].b*v.y() + fPlanes[0].c*v.z();
647 if (cos0 > 0)
648 {
649 G4double dis0 = fPlanes[0].b*p.y() + fPlanes[0].c*p.z() + fPlanes[0].d;
650 if (dis0 >= -halfCarTolerance)
651 {
652 if (calcNorm)
653 {
654 *validNorm = true;
655 n->set(0, fPlanes[0].b, fPlanes[0].c);
656 }
657 return 0.;
658 }
659 G4double tmp = -dis0/cos0;
660 if (tmax > tmp) { tmax = tmp; iside = 0; }
661 }
662
663 G4double cos1 = -cos0;
664 if (cos1 > 0)
665 {
666 G4double dis1 = fPlanes[1].b*p.y() + fPlanes[1].c*p.z() + fPlanes[1].d;
667 if (dis1 >= -halfCarTolerance)
668 {
669 if (calcNorm)
670 {
671 *validNorm = true;
672 n->set(0, fPlanes[1].b, fPlanes[1].c);
673 }
674 return 0.;
675 }
676 G4double tmp = -dis1/cos1;
677 if (tmax > tmp) { tmax = tmp; iside = 1; }
678 }
679
680 // X intersections
681 //
682 G4double cos2 = fPlanes[2].a*v.x() + fPlanes[2].b*v.y() + fPlanes[2].c*v.z();
683 if (cos2 > 0)
684 {
685 G4double dis2 = fPlanes[2].a*p.x()+fPlanes[2].b*p.y()+fPlanes[2].c*p.z()+fPlanes[2].d;
686 if (dis2 >= -halfCarTolerance)
687 {
688 if (calcNorm)
689 {
690 *validNorm = true;
691 n->set(fPlanes[2].a, fPlanes[2].b, fPlanes[2].c);
692 }
693 return 0.;
694 }
695 G4double tmp = -dis2/cos2;
696 if (tmax > tmp) { tmax = tmp; iside = 2; }
697 }
698
699 G4double cos3 = -cos2;
700 if (cos3 > 0)
701 {
702 G4double dis3 = fPlanes[3].a*p.x()+fPlanes[3].b*p.y()
703 + fPlanes[3].c*p.z()+fPlanes[3].d;
704 if (dis3 >= -halfCarTolerance)
705 {
706 if (calcNorm)
707 {
708 *validNorm = true;
709 n->set(fPlanes[3].a, fPlanes[3].b, fPlanes[3].c);
710 }
711 return 0.;
712 }
713 G4double tmp = -dis3/cos3;
714 if (tmax > tmp) { tmax = tmp; iside = 3; }
715 }
716
717 // Set normal, if required, and return distance
718 //
719 if (calcNorm)
720 {
721 *validNorm = true;
722 (iside < 0) ? (n->set(0, 0, iside + 3)) // (-4+3)=-1, (-2+3)=+1
723 : (n->set(fPlanes[iside].a, fPlanes[iside].b, fPlanes[iside].c));
724 }
725 return tmax;
726}
G4double b
Definition G4Para.hh:269
G4double c
Definition G4Para.hh:269

◆ GetAlpha()

G4double G4Para::GetAlpha ( ) const
inline

◆ GetCubicVolume()

G4double G4Para::GetCubicVolume ( )
overridevirtual

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

Reimplemented from G4VSolid.

Definition at line 860 of file G4Para.cc.

861{
862 if (fCubicVolume == 0)
863 {
864 G4AutoLock l(&paraMutex);
865 fCubicVolume = 8*fDx*fDy*fDz;
866 l.unlock();
867 }
868 return fCubicVolume;
869}
G4TemplateAutoLock< G4Mutex > G4AutoLock
G4double fCubicVolume
Definition G4CSGSolid.hh:92

◆ GetEntityType()

G4GeometryType G4Para::GetEntityType ( ) const
overridevirtual

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

Implements G4VSolid.

Definition at line 768 of file G4Para.cc.

769{
770 return {"G4Para"};
771}

◆ GetPhi()

G4double G4Para::GetPhi ( ) const
inline

◆ GetPointOnSurface()

G4ThreeVector G4Para::GetPointOnSurface ( ) const
overridevirtual

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

Reimplemented from G4VSolid.

Definition at line 824 of file G4Para.cc.

825{
826 G4double sxy = fDx*fDy;
827 G4double sxz = fDx*fDz*std::sqrt(1. + sqr(fTthetaSphi));
828 G4double syz = fDy*fDz*std::sqrt(1. + sqr(fTalpha) + sqr(fTalpha*fTthetaSphi - fTthetaCphi));
829
830 G4double select = (sxy + sxz + syz)*G4QuickRand();
831 G4double u = 2.*G4QuickRand() - 1.;
832 G4double v = 2.*G4QuickRand() - 1.;
833
834 G4double x, y, z;
835 if (select < sxy)
836 {
837 x = u*fDx;
838 y = v*fDy;
839 z = (select < 0.5*sxy) ? -fDz : fDz;
840 }
841 else if (select < sxy + sxz)
842 {
843 x = u*fDx;
844 y = (select < sxy + 0.5*sxz) ? -fDy : fDy;
845 z = v*fDz;
846 }
847 else
848 {
849 x = (select < sxy + sxz + 0.5*syz) ? -fDx : fDx;
850 y = u*fDy;
851 z = v*fDz;
852 }
853 return { x + y*fTalpha + z*fTthetaCphi, y + z*fTthetaSphi, z };
854}
G4double G4QuickRand(uint32_t seed=0)
T sqr(const T &x)
Definition templates.hh:128

◆ GetSurfaceArea()

G4double G4Para::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 875 of file G4Para.cc.

876{
877 if (fSurfaceArea == 0)
878 {
879 G4AutoLock l(&paraMutex);
880 G4double sxy = fDx*fDy;
881 G4double sxz = fDx*fDz*std::sqrt(1. + sqr(fTthetaSphi));
882 G4double syz = fDy*fDz*std::sqrt(1. + sqr(fTalpha) + sqr(fTalpha*fTthetaSphi - fTthetaCphi));
883 fSurfaceArea = 8*(sxy+sxz+syz);
884 l.unlock();
885 }
886 return fSurfaceArea;
887}
G4double fSurfaceArea
Definition G4CSGSolid.hh:93

◆ GetSymAxis()

◆ GetTanAlpha()

◆ GetTheta()

G4double G4Para::GetTheta ( ) const
inline

◆ GetXHalfLength()

◆ GetYHalfLength()

◆ GetZHalfLength()

G4double G4Para::GetZHalfLength ( ) const
inline

◆ Inside()

EInside G4Para::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 377 of file G4Para.cc.

378{
379 G4double xx = fPlanes[2].a*p.x()+fPlanes[2].b*p.y()+fPlanes[2].c*p.z();
380 G4double dx = std::abs(xx) + fPlanes[2].d;
381
382 G4double yy = fPlanes[0].b*p.y()+fPlanes[0].c*p.z();
383 G4double dy = std::abs(yy) + fPlanes[0].d;
384 G4double dxy = std::max(dx,dy);
385
386 G4double dz = std::abs(p.z())-fDz;
387 G4double dist = std::max(dxy,dz);
388
389 if (dist > halfCarTolerance) { return kOutside; }
390
391 return (dist > -halfCarTolerance) ? kSurface : kInside;
392}
@ kInside
Definition geomdefs.hh:70
@ kSurface
Definition geomdefs.hh:69

Referenced by DistanceToOut().

◆ IsFaceted()

G4bool G4Para::IsFaceted ( ) const
overridevirtual

Returns true as the solid has only planar faces.

Reimplemented from G4VSolid.

Definition at line 777 of file G4Para.cc.

778{
779 return true;
780}

◆ operator=()

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

Definition at line 155 of file G4Para.cc.

156{
157 // Check assignment to self
158 //
159 if (this == &rhs) { return *this; }
160
161 // Copy base class data
162 //
164
165 // Copy data
166 //
167 halfCarTolerance = rhs.halfCarTolerance;
168 fDx = rhs.fDx;
169 fDy = rhs.fDy;
170 fDz = rhs.fDz;
171 fTalpha = rhs.fTalpha;
172 fTthetaCphi = rhs.fTthetaCphi;
173 fTthetaSphi = rhs.fTthetaSphi;
174 for (G4int i=0; i<4; ++i) { fPlanes[i] = rhs.fPlanes[i]; }
175
176 return *this;
177}
G4CSGSolid & operator=(const G4CSGSolid &rhs)
Definition G4CSGSolid.cc:89

◆ SetAllParameters()

void G4Para::SetAllParameters ( G4double pDx,
G4double pDy,
G4double pDz,
G4double pAlpha,
G4double pTheta,
G4double pPhi )

Sets all parameters, as for constructor.

Definition at line 183 of file G4Para.cc.

185{
186 // Reset data of the base class
187 fCubicVolume = 0;
188 fSurfaceArea = 0;
189 fRebuildPolyhedron = true;
190
191 // Set parameters
192 fDx = pDx;
193 fDy = pDy;
194 fDz = pDz;
195 fTalpha = std::tan(pAlpha);
196 fTthetaCphi = std::tan(pTheta)*std::cos(pPhi);
197 fTthetaSphi = std::tan(pTheta)*std::sin(pPhi);
198
199 CheckParameters();
200 MakePlanes();
201}

Referenced by G4ParameterisationParaX::ComputeDimensions(), G4ParameterisationParaY::ComputeDimensions(), G4ParameterisationParaZ::ComputeDimensions(), G4Para(), and G4Para().

◆ SetAlpha()

void G4Para::SetAlpha ( G4double alpha)
inline

◆ SetTanAlpha()

void G4Para::SetTanAlpha ( G4double val)
inline

◆ SetThetaAndPhi()

void G4Para::SetThetaAndPhi ( G4double pTheta,
G4double pPhi )
inline

◆ SetXHalfLength()

void G4Para::SetXHalfLength ( G4double val)
inline

Modifiers.

◆ SetYHalfLength()

void G4Para::SetYHalfLength ( G4double val)
inline

◆ SetZHalfLength()

void G4Para::SetZHalfLength ( G4double val)
inline

◆ StreamInfo()

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

Streams the object contents to an output stream.

Reimplemented from G4CSGSolid.

Definition at line 795 of file G4Para.cc.

796{
797 G4double alpha = std::atan(fTalpha);
798 G4double theta = std::atan(std::sqrt(fTthetaCphi*fTthetaCphi +
799 fTthetaSphi*fTthetaSphi));
800 G4double phi = std::atan2(fTthetaSphi,fTthetaCphi);
801
802 G4long oldprc = os.precision(16);
803 os << "-----------------------------------------------------------\n"
804 << " *** Dump for solid - " << GetName() << " ***\n"
805 << " ===================================================\n"
806 << " Solid type: G4Para\n"
807 << " Parameters:\n"
808 << " half length X: " << fDx/mm << " mm\n"
809 << " half length Y: " << fDy/mm << " mm\n"
810 << " half length Z: " << fDz/mm << " mm\n"
811 << " alpha: " << alpha/degree << "degrees\n"
812 << " theta: " << theta/degree << "degrees\n"
813 << " phi: " << phi/degree << "degrees\n"
814 << "-----------------------------------------------------------\n";
815 os.precision(oldprc);
816
817 return os;
818}

◆ SurfaceNormal()

G4ThreeVector G4Para::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 398 of file G4Para.cc.

399{
400 G4int nsurf = 0; // number of surfaces where p is placed
401
402 // Check Z faces
403 //
404 G4double nz = 0;
405 G4double dz = std::abs(p.z()) - fDz;
406 if (std::abs(dz) <= halfCarTolerance)
407 {
408 nz = (p.z() < 0) ? -1 : 1;
409 ++nsurf;
410 }
411
412 // Check Y faces
413 //
414 G4double ny = 0;
415 G4double yy = fPlanes[0].b*p.y()+fPlanes[0].c*p.z();
416 if (std::abs(fPlanes[0].d + yy) <= halfCarTolerance)
417 {
418 ny = fPlanes[0].b;
419 nz += fPlanes[0].c;
420 ++nsurf;
421 }
422 else if (std::abs(fPlanes[1].d - yy) <= halfCarTolerance)
423 {
424 ny = fPlanes[1].b;
425 nz += fPlanes[1].c;
426 ++nsurf;
427 }
428
429 // Check X faces
430 //
431 G4double nx = 0;
432 G4double xx = fPlanes[2].a*p.x()+fPlanes[2].b*p.y()+fPlanes[2].c*p.z();
433 if (std::abs(fPlanes[2].d + xx) <= halfCarTolerance)
434 {
435 nx = fPlanes[2].a;
436 ny += fPlanes[2].b;
437 nz += fPlanes[2].c;
438 ++nsurf;
439 }
440 else if (std::abs(fPlanes[3].d - xx) <= halfCarTolerance)
441 {
442 nx = fPlanes[3].a;
443 ny += fPlanes[3].b;
444 nz += fPlanes[3].c;
445 ++nsurf;
446 }
447
448 // Return normal
449 //
450 if (nsurf == 1)
451 {
452 return {nx,ny,nz};
453 }
454 if (nsurf != 0)
455 {
456 return G4ThreeVector(nx,ny,nz).unit(); // edge or corner
457 }
458
459 // Point is not on the surface
460 //
461#ifdef G4CSGDEBUG
462 std::ostringstream message;
463 G4int oldprc = message.precision(16);
464 message << "Point p is not on surface (!?) of solid: "
465 << GetName() << G4endl;
466 message << "Position:\n";
467 message << " p.x() = " << p.x()/mm << " mm\n";
468 message << " p.y() = " << p.y()/mm << " mm\n";
469 message << " p.z() = " << p.z()/mm << " mm";
470 G4cout.precision(oldprc) ;
471 G4Exception("G4Para::SurfaceNormal(p)", "GeomSolids1002",
472 JustWarning, message );
473 DumpInfo();
474#endif
475
476 return ApproxSurfaceNormal(p);
477}
Hep3Vector unit() const
G4double d
Definition G4Para.hh:269

Member Data Documentation

◆ a

G4double G4Para::a

Definition at line 269 of file G4Para.hh.

Referenced by DistanceToOut(), and G4Para().

◆ b

G4double G4Para::b

Definition at line 269 of file G4Para.hh.

Referenced by DistanceToOut().

◆ c

G4double G4Para::c

Definition at line 269 of file G4Para.hh.

Referenced by DistanceToOut().

◆ d

G4double G4Para::d

Definition at line 269 of file G4Para.hh.

Referenced by SurfaceNormal().


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