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

#include <G4Orb.hh>

+ Inheritance diagram for G4Orb:

Public Member Functions

 G4Orb (const G4String &pName, G4double pRmax)
 
 ~G4Orb () override
 
G4double GetRadius () const
 
G4double GetRadialTolerance () const
 
void SetRadius (G4double newRmax)
 
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
 
G4VSolidClone () const override
 
std::ostream & StreamInfo (std::ostream &os) const override
 
void DescribeYourselfTo (G4VGraphicsScene &scene) const override
 
G4VisExtent GetExtent () const override
 
G4PolyhedronCreatePolyhedron () const override
 
 G4Orb (__void__ &)
 
 G4Orb (const G4Orb &rhs)
 
G4Orboperator= (const G4Orb &rhs)
 
- Public Member Functions inherited from G4CSGSolid
 G4CSGSolid (const G4String &pName)
 
virtual ~G4CSGSolid ()
 
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 ()
 
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 Member Functions

void Initialize ()
 
- 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
 

Additional Inherited Members

- 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

Definition at line 55 of file G4Orb.hh.

Constructor & Destructor Documentation

◆ G4Orb() [1/3]

G4Orb::G4Orb ( const G4String & pName,
G4double pRmax )

Definition at line 55 of file G4Orb.cc.

56 : G4CSGSolid(pName), fRmax(pRmax)
57{
58 Initialize();
59}
G4CSGSolid(const G4String &pName)
Definition G4CSGSolid.cc:49
void Initialize()
Definition G4Orb.cc:111

Referenced by Clone().

◆ ~G4Orb()

G4Orb::~G4Orb ( )
overridedefault

◆ G4Orb() [2/3]

G4Orb::G4Orb ( __void__ & a)

Definition at line 66 of file G4Orb.cc.

67 : G4CSGSolid(a)
68{
69}

◆ G4Orb() [3/3]

G4Orb::G4Orb ( const G4Orb & rhs)
default

Member Function Documentation

◆ BoundingLimits()

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

Reimplemented from G4VSolid.

Definition at line 145 of file G4Orb.cc.

146{
147 G4double radius = GetRadius();
148 pMin.set(-radius,-radius,-radius);
149 pMax.set( radius, radius, radius);
150
151 // Check correctness of the bounding box
152 //
153 if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
154 {
155 std::ostringstream message;
156 message << "Bad bounding box (min >= max) for solid: "
157 << GetName() << " !"
158 << "\npMin = " << pMin
159 << "\npMax = " << pMax;
160 G4Exception("G4Orb::BoundingLimits()", "GeomMgt0001",
161 JustWarning, message);
162 DumpInfo();
163 }
164}
@ 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 GetRadius() const
G4String GetName() const
void DumpInfo() const

Referenced by CalculateExtent().

◆ CalculateExtent()

G4bool G4Orb::CalculateExtent ( const EAxis pAxis,
const G4VoxelLimits & pVoxelLimit,
const G4AffineTransform & pTransform,
G4double & pmin,
G4double & pmax ) const
overridevirtual

Implements G4VSolid.

Definition at line 170 of file G4Orb.cc.

174{
175 G4ThreeVector bmin, bmax;
176 G4bool exist;
177
178 // Get bounding box
179 BoundingLimits(bmin,bmax);
180
181 // Check bounding box
182 G4BoundingEnvelope bbox(bmin,bmax);
183#ifdef G4BBOX_EXTENT
184 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
185#endif
186 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
187 {
188 return exist = pMin < pMax;
189 }
190
191 // Find bounding envelope and calculate extent
192 //
193 static const G4int NTHETA = 8; // number of steps along Theta
194 static const G4int NPHI = 16; // number of steps along Phi
195 static const G4double sinHalfTheta = std::sin(halfpi/NTHETA);
196 static const G4double cosHalfTheta = std::cos(halfpi/NTHETA);
197 static const G4double sinHalfPhi = std::sin(pi/NPHI);
198 static const G4double cosHalfPhi = std::cos(pi/NPHI);
199 static const G4double sinStepTheta = 2.*sinHalfTheta*cosHalfTheta;
200 static const G4double cosStepTheta = 1. - 2.*sinHalfTheta*sinHalfTheta;
201 static const G4double sinStepPhi = 2.*sinHalfPhi*cosHalfPhi;
202 static const G4double cosStepPhi = 1. - 2.*sinHalfPhi*sinHalfPhi;
203
204 G4double radius = GetRadius();
205 G4double rtheta = radius/cosHalfTheta;
206 G4double rphi = rtheta/cosHalfPhi;
207
208 // set reference circle
209 G4TwoVector xy[NPHI];
210 G4double sinCurPhi = sinHalfPhi;
211 G4double cosCurPhi = cosHalfPhi;
212 for (auto & k : xy)
213 {
214 k.set(cosCurPhi,sinCurPhi);
215 G4double sinTmpPhi = sinCurPhi;
216 sinCurPhi = sinCurPhi*cosStepPhi + cosCurPhi*sinStepPhi;
217 cosCurPhi = cosCurPhi*cosStepPhi - sinTmpPhi*sinStepPhi;
218 }
219
220 // set bounding circles
221 G4ThreeVectorList circles[NTHETA];
222 for (auto & circle : circles) { circle.resize(NPHI); }
223
224 G4double sinCurTheta = sinHalfTheta;
225 G4double cosCurTheta = cosHalfTheta;
226 for (auto & circle : circles)
227 {
228 G4double z = rtheta*cosCurTheta;
229 G4double rho = rphi*sinCurTheta;
230 for (G4int k=0; k<NPHI; ++k)
231 {
232 circle[k].set(rho*xy[k].x(),rho*xy[k].y(),z);
233 }
234 G4double sinTmpTheta = sinCurTheta;
235 sinCurTheta = sinCurTheta*cosStepTheta + cosCurTheta*sinStepTheta;
236 cosCurTheta = cosCurTheta*cosStepTheta - sinTmpTheta*sinStepTheta;
237 }
238
239 // set envelope and calculate extent
240 std::vector<const G4ThreeVectorList *> polygons;
241 polygons.resize(NTHETA);
242 for (G4int i=0; i<NTHETA; ++i) { polygons[i] = &circles[i]; }
243
244 G4BoundingEnvelope benv(bmin,bmax,polygons);
245 exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
246 return exist;
247}
std::vector< G4ThreeVector > G4ThreeVectorList
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const override
Definition G4Orb.cc:145

◆ Clone()

G4VSolid * G4Orb::Clone ( ) const
overridevirtual

Reimplemented from G4VSolid.

Definition at line 409 of file G4Orb.cc.

410{
411 return new G4Orb(*this);
412}
G4Orb(const G4String &pName, G4double pRmax)
Definition G4Orb.cc:55

◆ ComputeDimensions()

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

Reimplemented from G4VSolid.

Definition at line 134 of file G4Orb.cc.

137{
138 p->ComputeDimensions(*this,n,pRep);
139}
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const

◆ CreatePolyhedron()

G4Polyhedron * G4Orb::CreatePolyhedron ( ) const
overridevirtual

Reimplemented from G4VSolid.

Definition at line 455 of file G4Orb.cc.

456{
457 return new G4PolyhedronSphere (0., fRmax, 0., 2*pi, 0., pi);
458}

◆ DescribeYourselfTo()

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

Implements G4VSolid.

Definition at line 445 of file G4Orb.cc.

446{
447 scene.AddSolid (*this);
448}
virtual void AddSolid(const G4Box &)=0

◆ DistanceToIn() [1/2]

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

Implements G4VSolid.

Definition at line 318 of file G4Orb.cc.

319{
320 G4double dist = p.mag() - fRmax;
321 return (dist > 0) ? dist : 0.;
322}
double mag() const

◆ DistanceToIn() [2/2]

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

Implements G4VSolid.

Definition at line 275 of file G4Orb.cc.

277{
278 // Check if point is on the surface and traveling away
279 //
280 G4double rr = p.mag2();
281 G4double pv = p.dot(v);
282 if (rr >= sqrRmaxMinusTol && pv >= 0) return kInfinity;
283
284 // Find intersection
285 //
286 // Sphere eqn: x^2 + y^2 + z^2 = R^2
287 //
288 // => (px + t*vx)^2 + (py + t*vy)^2 + (pz + t*vz)^2 = R^2
289 // => r^2 + 2t(p.v) + t^2 = R^2
290 // => tmin = -(p.v) - Sqrt((p.v)^2 - (r^2 - R^2))
291 //
292 G4double D = pv*pv - rr + fRmax*fRmax;
293 if (D < 0) return kInfinity; // no intersection
294
295 G4double sqrtD = std::sqrt(D);
296 G4double dist = -pv - sqrtD;
297
298 // Avoid rounding errors due to precision issues seen on 64 bits systems.
299 // Split long distances and recompute
300 //
301 G4double Dmax = 32*fRmax;
302 if (dist > Dmax)
303 {
304 dist = dist - 1.e-8*dist - fRmax; // to stay outside after the move
305 dist += DistanceToIn(p + dist*v, v);
306 return (dist >= kInfinity) ? kInfinity : dist;
307 }
308
309 if (sqrtD*2 <= halfRmaxTol) return kInfinity; // touch
310 return (dist < halfRmaxTol) ? 0. : dist;
311}
G4double D(G4double temp)
double mag2() const
double dot(const Hep3Vector &) const
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const override
Definition G4Orb.cc:275

Referenced by DistanceToIn().

◆ DistanceToOut() [1/2]

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

Implements G4VSolid.

Definition at line 374 of file G4Orb.cc.

375{
376#ifdef G4CSGDEBUG
377 if( Inside(p) == kOutside )
378 {
379 std::ostringstream message;
380 G4int oldprc = message.precision(16);
381 message << "Point p is outside (!?) of solid: " << GetName() << "\n";
382 message << "Position:\n";
383 message << " p.x() = " << p.x()/mm << " mm\n";
384 message << " p.y() = " << p.y()/mm << " mm\n";
385 message << " p.z() = " << p.z()/mm << " mm";
386 G4cout.precision(oldprc);
387 G4Exception("G4Trap::DistanceToOut(p)", "GeomSolids1002",
388 JustWarning, message );
389 DumpInfo();
390 }
391#endif
392 G4double dist = fRmax - p.mag();
393 return (dist > 0) ? dist : 0.;
394}
G4GLOB_DLL std::ostream G4cout
EInside Inside(const G4ThreeVector &p) const override
Definition G4Orb.cc:253
@ kOutside
Definition geomdefs.hh:68

◆ DistanceToOut() [2/2]

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

Implements G4VSolid.

Definition at line 330 of file G4Orb.cc.

335{
336 // Check if point is on the surface and traveling away
337 //
338 G4double rr = p.mag2();
339 G4double pv = p.dot(v);
340 if (rr >= sqrRmaxMinusTol && pv > 0)
341 {
342 if (calcNorm)
343 {
344 *validNorm = true;
345 *n = p*(1./std::sqrt(rr));
346 }
347 return 0.;
348 }
349
350 // Find intersection
351 //
352 // Sphere eqn: x^2 + y^2 + z^2 = R^2
353 //
354 // => (px + t*vx)^2 + (py + t*vy)^2 + (pz + t*vz)^2 = R^2
355 // => r^2 + 2t(p.v) + t^2 = R^2
356 // => tmax = -(p.v) + Sqrt((p.v)^2 - (r^2 - R^2))
357 //
358 G4double D = pv*pv - rr + fRmax*fRmax;
359 G4double tmax = (D <= 0) ? 0. : std::sqrt(D) - pv;
360 if (tmax < halfRmaxTol) tmax = 0.;
361 if (calcNorm)
362 {
363 *validNorm = true;
364 G4ThreeVector ptmax = p + tmax*v;
365 *n = ptmax*(1./ptmax.mag());
366 }
367 return tmax;
368}

◆ GetCubicVolume()

G4double G4Orb::GetCubicVolume ( )
inlineoverridevirtual

Reimplemented from G4VSolid.

◆ GetEntityType()

G4GeometryType G4Orb::GetEntityType ( ) const
overridevirtual

Implements G4VSolid.

Definition at line 400 of file G4Orb.cc.

401{
402 return {"G4Orb"};
403}

◆ GetExtent()

G4VisExtent G4Orb::GetExtent ( ) const
overridevirtual

Reimplemented from G4VSolid.

Definition at line 450 of file G4Orb.cc.

451{
452 return {-fRmax, fRmax, -fRmax, fRmax, -fRmax, fRmax};
453}

◆ GetPointOnSurface()

G4ThreeVector G4Orb::GetPointOnSurface ( ) const
overridevirtual

Reimplemented from G4VSolid.

Definition at line 436 of file G4Orb.cc.

437{
438 return fRmax * G4RandomDirection();
439}
G4ThreeVector G4RandomDirection()

◆ GetRadialTolerance()

G4double G4Orb::GetRadialTolerance ( ) const
inline

◆ GetRadius()

◆ GetSurfaceArea()

G4double G4Orb::GetSurfaceArea ( )
inlineoverridevirtual

Reimplemented from G4VSolid.

◆ Initialize()

void G4Orb::Initialize ( )
protected

Definition at line 111 of file G4Orb.cc.

112{
113 const G4double fEpsilon = 2.e-11; // relative tolerance of fRmax
114
115 // Check radius
116 //
117 if ( fRmax < 10*kCarTolerance )
118 {
119 G4Exception("G4Orb::Initialize()", "GeomSolids0002", FatalException,
120 "Invalid radius < 10*kCarTolerance.");
121 }
122 halfRmaxTol = 0.5 * std::max(kCarTolerance, fEpsilon*fRmax);
123 G4double rmaxPlusTol = fRmax + halfRmaxTol;
124 G4double rmaxMinusTol = fRmax - halfRmaxTol;
125 sqrRmaxPlusTol = rmaxPlusTol*rmaxPlusTol;
126 sqrRmaxMinusTol = rmaxMinusTol*rmaxMinusTol;
127}
@ FatalException
G4double kCarTolerance
Definition G4VSolid.hh:299

Referenced by G4Orb().

◆ Inside()

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

Implements G4VSolid.

Definition at line 253 of file G4Orb.cc.

254{
255 G4double rr = p.mag2();
256 if (rr > sqrRmaxPlusTol) return kOutside;
257 return (rr > sqrRmaxMinusTol) ? kSurface : kInside;
258}
@ kInside
Definition geomdefs.hh:70
@ kSurface
Definition geomdefs.hh:69

Referenced by DistanceToOut().

◆ operator=()

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

Definition at line 87 of file G4Orb.cc.

88{
89 // Check assignment to self
90 //
91 if (this == &rhs) { return *this; }
92
93 // Copy base class data
94 //
96
97 // Copy data
98 //
99 fRmax = rhs.fRmax;
100 halfRmaxTol = rhs.halfRmaxTol;
101 sqrRmaxPlusTol = rhs.sqrRmaxPlusTol;
102 sqrRmaxMinusTol = rhs.sqrRmaxMinusTol;
103
104 return *this;
105}
G4CSGSolid & operator=(const G4CSGSolid &rhs)
Definition G4CSGSolid.cc:89

◆ SetRadius()

void G4Orb::SetRadius ( G4double newRmax)
inline

◆ StreamInfo()

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

Reimplemented from G4CSGSolid.

Definition at line 418 of file G4Orb.cc.

419{
420 G4long oldprc = os.precision(16);
421 os << "-----------------------------------------------------------\n"
422 << " *** Dump for solid - " << GetName() << " ***\n"
423 << " ===================================================\n"
424 << " Solid type: G4Orb\n"
425 << " Parameters: \n"
426 << " outer radius: " << fRmax/mm << " mm \n"
427 << "-----------------------------------------------------------\n";
428 os.precision(oldprc);
429 return os;
430}
long G4long
Definition G4Types.hh:87

◆ SurfaceNormal()

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

Implements G4VSolid.

Definition at line 264 of file G4Orb.cc.

265{
266 return (1/p.mag())*p;
267}

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