Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Sphere.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4Sphere
27//
28// Class description:
29//
30// A G4Sphere is, in the general case, a section of a spherical shell,
31// between specified phi and theta angles
32//
33// The phi and theta segments are described by a starting angle,
34// and the +ve delta angle for the shape.
35// If the delta angle is >=2*pi, or >=pi the shape is treated as
36// continuous in phi or theta respectively.
37//
38// Theta must lie between 0-pi (incl).
39//
40// Member Data:
41//
42// fRmin inner radius
43// fRmax outer radius
44//
45// fSPhi starting angle of the segment in radians
46// fDPhi delta angle of the segment in radians
47//
48// fSTheta starting angle of the segment in radians
49// fDTheta delta angle of the segment in radians
50//
51//
52// Note:
53// Internally fSPhi & fDPhi are adjusted so that fDPhi<=2PI,
54// and fDPhi+fSPhi<=2PI. This enables simpler comparisons to be
55// made with (say) Phi of a point.
56
57// Author: Paul Kent (CERN), 28.03.1994 - Code converted to tolerant geometry
58// --------------------------------------------------------------------
59#ifndef G4SPHERE_HH
60#define G4SPHERE_HH
61
62#include "G4GeomTypes.hh"
63
64#if defined(G4GEOM_USE_USOLIDS)
65#define G4GEOM_USE_USPHERE 1
66#endif
67
68#if defined(G4GEOM_USE_USPHERE)
69 #define G4USphere G4Sphere
70 #include "G4USphere.hh"
71#else
72
74#include "G4CSGSolid.hh"
75#include "G4Polyhedron.hh"
76
77class G4VisExtent;
78
79/**
80 * @brief G4Sphere is, in the general case, a section of a spherical shell,
81 * between specified phi and theta angles.
82 * The phi and theta segments are described by a starting angle and the +ve
83 * delta angle for the shape. If the delta angle is >=2*pi, or >=pi the shape
84 * is treated as continuous in phi or theta respectively.
85 * Theta must lie between [0..pi].
86 */
87
88class G4Sphere : public G4CSGSolid
89{
90 public:
91
92 /**
93 * Constructs a sphere or sphere shell section with the given
94 * name and dimensions.
95 * @param[in] pName The name of the solid.
96 * @param[in] pRmin Inner radius.
97 * @param[in] pRmax Outer radius.
98 * @param[in] pSPhi Starting Phi angle of the segment in radians.
99 * @param[in] pDPhi Delta Phi angle of the segment in radians.
100 * @param[in] pSTheta Starting Theta angle of the segment in radians.
101 * @param[in] pDTheta Delta Theta angle of the segment in radians.
102 */
103 G4Sphere(const G4String& pName,
104 G4double pRmin, G4double pRmax,
105 G4double pSPhi, G4double pDPhi,
106 G4double pSTheta, G4double pDTheta);
107
108 /**
109 * Default destructor.
110 */
111 ~G4Sphere() override = default;
112
113 /**
114 * Accessors.
115 */
116 inline G4double GetInnerRadius () const;
117 inline G4double GetOuterRadius () const;
118 inline G4double GetStartPhiAngle () const;
119 inline G4double GetDeltaPhiAngle () const;
122 inline G4double GetSinStartPhi () const;
123 inline G4double GetCosStartPhi () const;
124 inline G4double GetSinEndPhi () const;
125 inline G4double GetCosEndPhi () const;
126 inline G4double GetSinStartTheta () const;
127 inline G4double GetCosStartTheta () const;
128 inline G4double GetSinEndTheta () const;
129 inline G4double GetCosEndTheta () const;
130
131 /**
132 * Modifiers.
133 */
134 inline void SetInnerRadius (G4double newRMin);
135 inline void SetOuterRadius (G4double newRmax);
136 inline void SetStartPhiAngle (G4double newSphi, G4bool trig = true);
137 inline void SetDeltaPhiAngle (G4double newDphi);
138 inline void SetStartThetaAngle(G4double newSTheta);
139 inline void SetDeltaThetaAngle(G4double newDTheta);
140
141 /**
142 * Returning an estimation of the solid volume (capacity) and
143 * surface area, in internal units.
144 */
145 G4double GetCubicVolume() override;
146 G4double GetSurfaceArea() override;
147
148 /**
149 * Dispatch method for parameterisation replication mechanism and
150 * dimension computation.
151 */
153 const G4int n,
154 const G4VPhysicalVolume* pRep) override;
155
156 /**
157 * Computes the bounding limits of the solid.
158 * @param[out] pMin The minimum bounding limit point.
159 * @param[out] pMax The maximum bounding limit point.
160 */
161 void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
162
163 /**
164 * Calculates the minimum and maximum extent of the solid, when under the
165 * specified transform, and within the specified limits.
166 * @param[in] pAxis The axis along which compute the extent.
167 * @param[in] pVoxelLimit The limiting space dictated by voxels.
168 * @param[in] pTransform The internal transformation applied to the solid.
169 * @param[out] pMin The minimum extent value.
170 * @param[out] pMax The maximum extent value.
171 * @returns True if the solid is intersected by the extent region.
172 */
173 G4bool CalculateExtent(const EAxis pAxis,
174 const G4VoxelLimits& pVoxelLimit,
175 const G4AffineTransform& pTransform,
176 G4double& pmin, G4double& pmax) const override;
177
178 /**
179 * Concrete implementations of the expected query interfaces for
180 * solids, as defined in the base class G4VSolid.
181 */
182 EInside Inside(const G4ThreeVector& p) const override;
183 G4ThreeVector SurfaceNormal( const G4ThreeVector& p) const override;
185 const G4ThreeVector& v) const override;
186 G4double DistanceToIn(const G4ThreeVector& p) const override;
188 const G4ThreeVector& v,
189 const G4bool calcNorm = false,
190 G4bool* validNorm = nullptr,
191 G4ThreeVector* n = nullptr) const override;
192 G4double DistanceToOut(const G4ThreeVector& p) const override;
193
194 /**
195 * Returns the type ID, "G4Sphere" of the solid.
196 */
197 G4GeometryType GetEntityType() const override;
198
199 /**
200 * Returns a random point located and uniformly distributed on the
201 * surface of the solid.
202 */
203 G4ThreeVector GetPointOnSurface() const override;
204
205 /**
206 * Makes a clone of the object for use in multi-treading.
207 * @returns A pointer to the new cloned allocated solid.
208 */
209 G4VSolid* Clone() const override;
210
211 /**
212 * Streams the object contents to an output stream.
213 */
214 std::ostream& StreamInfo(std::ostream& os) const override;
215
216 /**
217 * Methods for creating graphical representations (i.e. for visualisation).
218 */
219 G4VisExtent GetExtent() const override;
220 void DescribeYourselfTo(G4VGraphicsScene& scene) const override;
221 G4Polyhedron* CreatePolyhedron() const override;
222
223 /**
224 * Fake default constructor for usage restricted to direct object
225 * persistency for clients requiring preallocation of memory for
226 * persistifiable objects.
227 */
228 G4Sphere(__void__&);
229
230 /**
231 * Copy constructor and assignment operator.
232 */
233 G4Sphere(const G4Sphere& rhs) = default;
234 G4Sphere& operator=(const G4Sphere& rhs);
235
236 private:
237
238 /**
239 * Resets relevant values to zero.
240 */
241 inline void Initialize();
242
243 /**
244 * Reset relevant flags and angle values.
245 */
246 inline void CheckThetaAngles(G4double sTheta, G4double dTheta);
247 inline void CheckSPhiAngle(G4double sPhi);
248 inline void CheckDPhiAngle(G4double dPhi);
249 inline void CheckPhiAngles(G4double sPhi, G4double dPhi);
250
251 /**
252 * Recompute relevant trigonometric values and cache them.
253 */
254 inline void InitializePhiTrigonometry();
255 inline void InitializeThetaTrigonometry();
256
257 /**
258 * Algorithm for SurfaceNormal() following the original specification
259 * for points not on the surface.
260 */
261 G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector& p) const;
262
263 private:
264
265 /** Radial and angular tolerances. */
266 G4double fRminTolerance, fRmaxTolerance, kAngTolerance,
267 kRadTolerance, fEpsilon = 2.e-11;
268
269 /** Radial and angular dimensions. */
270 G4double fRmin, fRmax, fSPhi, fDPhi, fSTheta, fDTheta;
271
272 /** Cached trigonometric values for Phi angle. */
273 G4double sinCPhi, cosCPhi, cosHDPhi, cosHDPhiOT, cosHDPhiIT,
274 sinSPhi, cosSPhi, sinEPhi, cosEPhi, hDPhi, cPhi, ePhi;
275
276 /** Cached trigonometric values for Theta angle. */
277 G4double sinSTheta, cosSTheta, sinETheta, cosETheta,
278 tanSTheta, tanSTheta2, tanETheta, tanETheta2, eTheta;
279
280 /** Flags for identification of section, shell or full sphere. */
281 G4bool fFullPhiSphere=false, fFullThetaSphere=false, fFullSphere=true;
282
283 /** Cached half tolerance values. */
284 G4double halfCarTolerance, halfAngTolerance;
285};
286
287#include "G4Sphere.icc"
288
289#endif
290
291#endif
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4String G4GeometryType
Definition G4VSolid.hh:70
G4AffineTransform is a class for geometric affine transformations. It supports efficient arbitrary ro...
G4CSGSolid(const G4String &pName)
Definition G4CSGSolid.cc:49
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const override
Definition G4Sphere.cc:367
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const override
Definition G4Sphere.cc:669
EInside Inside(const G4ThreeVector &p) const override
Definition G4Sphere.cc:255
G4double GetStartPhiAngle() const
void SetDeltaPhiAngle(G4double newDphi)
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep) override
Definition G4Sphere.cc:166
G4Sphere(const G4String &pName, G4double pRmin, G4double pRmax, G4double pSPhi, G4double pDPhi, G4double pSTheta, G4double pDTheta)
Definition G4Sphere.cc:81
G4VSolid * Clone() const override
Definition G4Sphere.cc:2711
G4double GetSinStartTheta() const
G4VisExtent GetExtent() const override
Definition G4Sphere.cc:2832
G4double GetCosStartPhi() const
void SetStartThetaAngle(G4double newSTheta)
G4ThreeVector GetPointOnSurface() const override
Definition G4Sphere.cc:2781
G4Sphere(const G4Sphere &rhs)=default
G4double GetCubicVolume() override
Definition G4Sphere.cc:2744
G4double GetDeltaPhiAngle() const
~G4Sphere() override=default
G4double GetCosEndTheta() const
void SetOuterRadius(G4double newRmax)
void SetDeltaThetaAngle(G4double newDTheta)
void SetInnerRadius(G4double newRMin)
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pmin, G4double &pmax) const override
Definition G4Sphere.cc:234
G4double GetInnerRadius() const
G4double GetOuterRadius() const
G4double GetCosEndPhi() const
G4double GetSinEndTheta() const
G4double GetDeltaThetaAngle() const
G4double GetSinEndPhi() const
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const override
Definition G4Sphere.cc:177
G4double GetSinStartPhi() const
G4Sphere & operator=(const G4Sphere &rhs)
Definition G4Sphere.cc:127
G4double GetStartThetaAngle() const
void DescribeYourselfTo(G4VGraphicsScene &scene) const override
Definition G4Sphere.cc:2838
G4double GetCosStartTheta() const
G4double GetSurfaceArea() override
Definition G4Sphere.cc:2761
G4GeometryType GetEntityType() const override
Definition G4Sphere.cc:2702
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const override
Definition G4Sphere.cc:1714
void SetStartPhiAngle(G4double newSphi, G4bool trig=true)
std::ostream & StreamInfo(std::ostream &os) const override
Definition G4Sphere.cc:2720
G4Polyhedron * CreatePolyhedron() const override
Definition G4Sphere.cc:2843
G4VPVParameterisation ia an abstract base class for Parameterisation, able to compute the transformat...
G4VPhysicalVolume is an abstract base class for the representation of a positioned volume....
G4VSolid(const G4String &name)
Definition G4VSolid.cc:59
G4VoxelLimits represents limitation/restrictions of space, where restrictions are only made perpendic...
EAxis
Definition geomdefs.hh:54
EInside
Definition geomdefs.hh:67