Geant4 10.7.0
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 ()
 
G4double GetRadius () const
 
G4double GetRadialTolerance () const
 
void SetRadius (G4double newRmax)
 
G4double GetCubicVolume ()
 
G4double GetSurfaceArea ()
 
void ComputeDimensions (G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
 
void BoundingLimits (G4ThreeVector &pMin, G4ThreeVector &pMax) const
 
G4bool CalculateExtent (const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pmin, G4double &pmax) const
 
EInside Inside (const G4ThreeVector &p) const
 
G4ThreeVector SurfaceNormal (const G4ThreeVector &p) const
 
G4double DistanceToIn (const G4ThreeVector &p, const G4ThreeVector &v) const
 
G4double DistanceToIn (const G4ThreeVector &p) const
 
G4double DistanceToOut (const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const
 
G4double DistanceToOut (const G4ThreeVector &p) const
 
G4GeometryType GetEntityType () const
 
G4ThreeVector GetPointOnSurface () const
 
G4VSolidClone () const
 
std::ostream & StreamInfo (std::ostream &os) const
 
void DescribeYourselfTo (G4VGraphicsScene &scene) const
 
G4VisExtent GetExtent () const
 
G4PolyhedronCreatePolyhedron () const
 
 G4Orb (__void__ &)
 
 G4Orb (const G4Orb &rhs)
 
G4Orboperator= (const G4Orb &rhs)
 
- Public Member Functions inherited from G4CSGSolid
 G4CSGSolid (const G4String &pName)
 
virtual ~G4CSGSolid ()
 
virtual std::ostream & StreamInfo (std::ostream &os) const
 
virtual G4PolyhedronGetPolyhedron () const
 
 G4CSGSolid (__void__ &)
 
 G4CSGSolid (const G4CSGSolid &rhs)
 
G4CSGSolidoperator= (const G4CSGSolid &rhs)
 
- Public Member Functions inherited from G4VSolid
 G4VSolid (const G4String &name)
 
virtual ~G4VSolid ()
 
G4bool operator== (const G4VSolid &s) const
 
G4String GetName () const
 
void SetName (const G4String &name)
 
G4double GetTolerance () const
 
virtual void BoundingLimits (G4ThreeVector &pMin, G4ThreeVector &pMax) const
 
virtual G4bool CalculateExtent (const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const =0
 
virtual EInside Inside (const G4ThreeVector &p) const =0
 
virtual G4ThreeVector SurfaceNormal (const G4ThreeVector &p) const =0
 
virtual G4double DistanceToIn (const G4ThreeVector &p, const G4ThreeVector &v) const =0
 
virtual G4double DistanceToIn (const G4ThreeVector &p) const =0
 
virtual G4double DistanceToOut (const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const =0
 
virtual G4double DistanceToOut (const G4ThreeVector &p) const =0
 
virtual void ComputeDimensions (G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
 
virtual G4double GetCubicVolume ()
 
virtual G4double GetSurfaceArea ()
 
virtual G4GeometryType GetEntityType () const =0
 
virtual G4ThreeVector GetPointOnSurface () const
 
virtual G4VSolidClone () const
 
virtual std::ostream & StreamInfo (std::ostream &os) const =0
 
void DumpInfo () const
 
virtual void DescribeYourselfTo (G4VGraphicsScene &scene) const =0
 
virtual G4VisExtent GetExtent () const
 
virtual G4PolyhedronCreatePolyhedron () const
 
virtual G4PolyhedronGetPolyhedron () 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}
void Initialize()
Definition: G4Orb.cc:117

◆ ~G4Orb()

G4Orb::~G4Orb ( )

Definition at line 75 of file G4Orb.cc.

76{
77}

◆ 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)

Definition at line 83 of file G4Orb.cc.

84 : G4CSGSolid(rhs), fRmax(rhs.fRmax), halfRmaxTol(rhs.halfRmaxTol),
85 sqrRmaxPlusTol(rhs.sqrRmaxPlusTol), sqrRmaxMinusTol(rhs.sqrRmaxMinusTol)
86{
87}

Member Function Documentation

◆ BoundingLimits()

void G4Orb::BoundingLimits ( G4ThreeVector pMin,
G4ThreeVector pMax 
) const
virtual

Reimplemented from G4VSolid.

Definition at line 151 of file G4Orb.cc.

152{
153 G4double radius = GetRadius();
154 pMin.set(-radius,-radius,-radius);
155 pMax.set( radius, radius, radius);
156
157 // Check correctness of the bounding box
158 //
159 if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
160 {
161 std::ostringstream message;
162 message << "Bad bounding box (min >= max) for solid: "
163 << GetName() << " !"
164 << "\npMin = " << pMin
165 << "\npMax = " << pMax;
166 G4Exception("G4Orb::BoundingLimits()", "GeomMgt0001",
167 JustWarning, message);
168 DumpInfo();
169 }
170}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
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
virtual

Implements G4VSolid.

Definition at line 176 of file G4Orb.cc.

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

◆ Clone()

G4VSolid * G4Orb::Clone ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 415 of file G4Orb.cc.

416{
417 return new G4Orb(*this);
418}
Definition: G4Orb.hh:56

◆ ComputeDimensions()

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

Reimplemented from G4VSolid.

Definition at line 140 of file G4Orb.cc.

143{
144 p->ComputeDimensions(*this,n,pRep);
145}
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const

◆ CreatePolyhedron()

G4Polyhedron * G4Orb::CreatePolyhedron ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 461 of file G4Orb.cc.

462{
463 return new G4PolyhedronSphere (0., fRmax, 0., 2*pi, 0., pi);
464}

◆ DescribeYourselfTo()

void G4Orb::DescribeYourselfTo ( G4VGraphicsScene scene) const
virtual

Implements G4VSolid.

Definition at line 451 of file G4Orb.cc.

452{
453 scene.AddSolid (*this);
454}
virtual void AddSolid(const G4Box &)=0

◆ DistanceToIn() [1/2]

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

Implements G4VSolid.

Definition at line 324 of file G4Orb.cc.

325{
326 G4double dist = p.mag() - fRmax;
327 return (dist > 0) ? dist : 0.;
328}
double mag() const

◆ DistanceToIn() [2/2]

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

Implements G4VSolid.

Definition at line 281 of file G4Orb.cc.

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

Referenced by DistanceToIn().

◆ DistanceToOut() [1/2]

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

Implements G4VSolid.

Definition at line 380 of file G4Orb.cc.

381{
382#ifdef G4CSGDEBUG
383 if( Inside(p) == kOutside )
384 {
385 std::ostringstream message;
386 G4int oldprc = message.precision(16);
387 message << "Point p is outside (!?) of solid: " << GetName() << "\n";
388 message << "Position:\n";
389 message << " p.x() = " << p.x()/mm << " mm\n";
390 message << " p.y() = " << p.y()/mm << " mm\n";
391 message << " p.z() = " << p.z()/mm << " mm";
392 G4cout.precision(oldprc);
393 G4Exception("G4Trap::DistanceToOut(p)", "GeomSolids1002",
394 JustWarning, message );
395 DumpInfo();
396 }
397#endif
398 G4double dist = fRmax - p.mag();
399 return (dist > 0) ? dist : 0.;
400}
G4GLOB_DLL std::ostream G4cout
EInside Inside(const G4ThreeVector &p) const
Definition: G4Orb.cc:259
@ 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
virtual

Implements G4VSolid.

Definition at line 336 of file G4Orb.cc.

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

◆ GetCubicVolume()

G4double G4Orb::GetCubicVolume ( )
inlinevirtual

Reimplemented from G4VSolid.

◆ GetEntityType()

G4GeometryType G4Orb::GetEntityType ( ) const
virtual

Implements G4VSolid.

Definition at line 406 of file G4Orb.cc.

407{
408 return G4String("G4Orb");
409}

◆ GetExtent()

G4VisExtent G4Orb::GetExtent ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 456 of file G4Orb.cc.

457{
458 return G4VisExtent (-fRmax, fRmax, -fRmax, fRmax, -fRmax, fRmax);
459}

◆ GetPointOnSurface()

G4ThreeVector G4Orb::GetPointOnSurface ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 442 of file G4Orb.cc.

443{
444 return fRmax * G4RandomDirection();
445}
G4ThreeVector G4RandomDirection()

◆ GetRadialTolerance()

G4double G4Orb::GetRadialTolerance ( ) const
inline

◆ GetRadius()

◆ GetSurfaceArea()

G4double G4Orb::GetSurfaceArea ( )
inlinevirtual

Reimplemented from G4VSolid.

◆ Initialize()

void G4Orb::Initialize ( )
protected

Definition at line 117 of file G4Orb.cc.

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

Referenced by G4Orb().

◆ Inside()

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

Implements G4VSolid.

Definition at line 259 of file G4Orb.cc.

260{
261 G4double rr = p.mag2();
262 if (rr > sqrRmaxPlusTol) return kOutside;
263 return (rr > sqrRmaxMinusTol) ? kSurface : kInside;
264}
@ kInside
Definition: geomdefs.hh:70
@ kSurface
Definition: geomdefs.hh:69

Referenced by DistanceToOut().

◆ operator=()

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

Definition at line 93 of file G4Orb.cc.

94{
95 // Check assignment to self
96 //
97 if (this == &rhs) { return *this; }
98
99 // Copy base class data
100 //
102
103 // Copy data
104 //
105 fRmax = rhs.fRmax;
106 halfRmaxTol = rhs.halfRmaxTol;
107 sqrRmaxPlusTol = rhs.sqrRmaxPlusTol;
108 sqrRmaxMinusTol = rhs.sqrRmaxMinusTol;
109
110 return *this;
111}
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
virtual

Reimplemented from G4CSGSolid.

Definition at line 424 of file G4Orb.cc.

425{
426 G4int oldprc = os.precision(16);
427 os << "-----------------------------------------------------------\n"
428 << " *** Dump for solid - " << GetName() << " ***\n"
429 << " ===================================================\n"
430 << " Solid type: G4Orb\n"
431 << " Parameters: \n"
432 << " outer radius: " << fRmax/mm << " mm \n"
433 << "-----------------------------------------------------------\n";
434 os.precision(oldprc);
435 return os;
436}

◆ SurfaceNormal()

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

Implements G4VSolid.

Definition at line 270 of file G4Orb.cc.

271{
272 return (1/p.mag())*p;
273}

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