Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4PolyconeSide.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// G4PolyconeSide
27//
28// Class description:
29//
30// Class implementing a face that represents one conical side of a polycone:
31//
32// G4PolyconeSide( const G4PolyconeSideRZ* prevRZ,
33// const G4PolyconeSideRZ* tail,
34// const G4PolyconeSideRZ* head,
35// const G4PolyconeSideRZ* nextRZ,
36// G4double phiStart, G4double deltaPhi,
37// G4bool phiIsOpen, G4bool isAllBehind=false )
38//
39// Values for r1,z1 and r2,z2 should be specified in clockwise order in (r,z).
40
41// Author: David C. Williams (UCSC), 1998 - Created
42// --------------------------------------------------------------------
43#ifndef G4POLYCONESIDE_HH
44#define G4POLYCONESIDE_HH
45
46#include "G4VCSGface.hh"
47
49
51{
52 G4double r, z; // start of vector
53};
54
55// ----------------------------------------------------------------------------
56// MT-specific utility code
57
58#include "G4GeomSplitter.hh"
59
60// The class G4PlSideData is introduced to encapsulate the
61// fields of the class G4PolyconeSide that may not be read-only.
62//
64{
65 public:
66
68 {
69 fPhix = 0.; fPhiy = 0.; fPhiz = 0.; fPhik = 0.;
70 }
71
72 G4double fPhix=0., fPhiy=0., fPhiz=0., fPhik=0.; // Cached values for phi
73};
74
75// The type G4PlSideManager is introduced to
76// encapsulate the methods used by both the master thread and
77// worker threads to allocate memory space for the fields encapsulated
78// by the class G4PlSideData.
79//
81
82//
83// ----------------------------------------------------------------------------
84
85/**
86 * @brief G4PolyconeSide is a utility class implementing a face that
87 * represents one conical side of a polycone.
88 */
89
91{
92 public:
93
94 /**
95 * Constructor for the conical side of a polycone.
96 * @param[in] prevRZ Pointer to previous r,Z section.
97 * @param[in] tail Pointer to r,Z tail of section.
98 * @param[in] head Pointer to r,Z head of section.
99 * @param[in] nextRZ Pointer to next r,Z section.
100 * @param[in] phiStart Initial Phi starting angle.
101 * @param[in] deltaPhi Total Phi angle.
102 * @param[in] phiIsOpen Flag indicating if it is a Phi section.
103 * @param[in] isAllBehind Indicating if entire surface is behind normal.
104 */
105 G4PolyconeSide( const G4PolyconeSideRZ* prevRZ,
106 const G4PolyconeSideRZ* tail,
107 const G4PolyconeSideRZ* head,
108 const G4PolyconeSideRZ* nextRZ,
109 G4double phiStart, G4double deltaPhi,
110 G4bool phiIsOpen, G4bool isAllBehind = false );
111
112 /**
113 * Destructor.
114 */
115 ~G4PolyconeSide() override;
116
117 /**
118 * Copy constructor and assignment operator.
119 */
120 G4PolyconeSide( const G4PolyconeSide& source );
121 G4PolyconeSide& operator=( const G4PolyconeSide& source );
122
123 /**
124 * Determines the distance along a line to the face.
125 * @param[in] p Position.
126 * @param[in] v Direction (assumed to be a unit vector).
127 * @param[in] outgoing Flag true, to consider only inside surfaces;
128 * false, to consider only outside surfaces.
129 * @param[in] surfTolerance Minimum distance from the surface.
130 * @param[out] distance Distance to intersection.
131 * @param[out] distFromSurface Distance from surface (along surface normal),
132 * < 0 if the point is in front of the surface.
133 * @param[out] normal Normal of surface at intersection point.
134 * @param[out] allBehind Flag, true, if entire surface is behind normal.
135 * @returns true if there is an intersection, false otherwise.
136 */
137 G4bool Intersect(const G4ThreeVector& p, const G4ThreeVector& v,
138 G4bool outgoing, G4double surfTolerance,
139 G4double& distance, G4double &distFromSurface,
140 G4ThreeVector& normal, G4bool& isAllBehind) override;
141
142 /**
143 * Determines the distance of a point from either the inside or outside
144 * surfaces of the face.
145 * @param[in] p Position.
146 * @param[in] outgoing Flag, true, to consider only inside surfaces
147 * or false, to consider only outside surfaces.
148 * @returns The distance to the closest surface satisfying requirements
149 * or kInfinity if no such surface exists.
150 */
151 G4double Distance( const G4ThreeVector& p, G4bool outgoing ) override;
152
153 /**
154 * Determines whether a point is inside, outside, or on the surface of
155 * the face.
156 * @param[in] p Position.
157 * @param[in] tolerance Tolerance defining the bounds of the "kSurface",
158 * nominally equal to kCarTolerance/2.
159 * @param[out] bestDistance Distance to the closest surface (in or out).
160 * @returns kInside if the point is closest to the inside surface;
161 * kOutside if the point is closest to the outside surface;
162 * kSurface if the point is withing tolerance of the surface.
163 */
164 EInside Inside( const G4ThreeVector& p, G4double tolerance,
165 G4double* bestDistance ) override;
166
167 /**
168 * Returns the normal of surface closest to the point.
169 * @param[in] p Position.
170 * @param[out] bestDistance Distance to the closest surface (in or out).
171 * @returns The normal of the surface nearest the point.
172 */
174 G4double* bestDistance ) override;
175
176 /**
177 * Returns the face extent along the axis.
178 * @param[in] axis Unit vector defining the direction.
179 * @returns The largest point along the given axis of the face's extent.
180 */
181 G4double Extent( const G4ThreeVector axis ) override;
182
183 /**
184 * Calculates the extent of the face for the voxel navigator.
185 * @param[in] axis The axis in which to check the shapes 3D extent against.
186 * @param[in] voxelLimit Limits along x, y, and/or z axes.
187 * @param[in] tranform A coordinate transformation on which to apply to
188 * the shape before testing.
189 * @param[out] extentList The list of (voxel) extents along the axis.
190 */
191 void CalculateExtent( const EAxis axis,
192 const G4VoxelLimits& voxelLimit,
193 const G4AffineTransform& tranform,
194 G4SolidExtentList& extentList ) override;
195
196 /**
197 * Method invoked by the copy constructor or the assignment operator.
198 * Its purpose is to return a pointer to a duplicate copy of the face.
199 */
200 inline G4VCSGface* Clone() override { return new G4PolyconeSide( *this ); }
201
202 /**
203 * Returning an estimation of the face surface area, in internal units.
204 */
205 G4double SurfaceArea() override;
206
207 /**
208 * Returns a random point located and uniformly distributed on the face.
209 */
210 G4ThreeVector GetPointOnFace() override;
211
212 /**
213 * Fake default constructor for usage restricted to direct object
214 * persistency for clients requiring preallocation of memory for
215 * persistifiable objects.
216 */
217 G4PolyconeSide(__void__&);
218
219 /**
220 * Returns the instance ID.
221 */
222 inline G4int GetInstanceID() const { return instanceID; }
223
224 /**
225 * Returns the private data instance manager.
226 */
228
229 private:
230
231 /**
232 * Calculates the distance of a point from the conical surface, including
233 * the effect of any phi segmentation.
234 * @param[in] p The point to check.
235 * @param[in] opposite If true, check the opposite hemisphere (see below).
236 * @param[out] distOutside Additional distance outside the edges of surface.
237 * @param[out] rzNorm If negative, the point is inside.
238 * @returns The distance from the conical plane, if extrapolated beyond
239 * edges, signed by whether the point is in inside or outside
240 * the shape.
241 */
242 G4double DistanceAway( const G4ThreeVector& p, G4bool opposite,
243 G4double& distOutside,
244 G4double* rzNorm = nullptr );
245
246 /**
247 * Special version of DistanceAway() for Inside. Opposite parameter is not
248 * used, instead use sign of rx for choosing the side.
249 * @param[in] p The point to check.
250 * @param[out] distOutside Additional distance outside the edges of surface.
251 * @param[out] edgeRZnorm If negative, the point is inside.
252 * @returns The distance from the conical plane.
253 */
254 G4double DistanceAway( const G4ThreeVector& p, G4double& distOutside,
255 G4double* edgeRZnorm );
256
257 /**
258 * Decides if a point is on a cone and returns the 'normal' if it is.
259 * @returns true if the point is on the cone.
260 */
261 G4bool PointOnCone( const G4ThreeVector& hit, G4double normSign,
262 const G4ThreeVector& p,
263 const G4ThreeVector& v, G4ThreeVector& normal );
264
265 /**
266 * Copies parameters from other object; used in copy constructor and
267 * assignment operator.
268 */
269 void CopyStuff( const G4PolyconeSide& source );
270
271 /**
272 * Decides the point at which two 2-dimensional lines intersect.
273 * It is assumed that the lines are *not* parallel.
274 */
275 static void FindLineIntersect( G4double x1, G4double y1,
276 G4double tx1, G4double ty1,
277 G4double x2, G4double y2,
278 G4double tx2, G4double ty2,
279 G4double& x, G4double& y );
280
281 /**
282 * Calculates Phi for a given 3-vector (point 'p'), if not already cached
283 * for the same point, in the attempt to avoid consecutive computation of
284 * the same quantity.
285 */
286 G4double GetPhi( const G4ThreeVector& p );
287
288 private:
289
290 G4double r[2], z[2]; // r, z parameters, in specified order
291 G4double startPhi, // Start phi (0 to 2pi), if phiIsOpen
292 deltaPhi; // Delta phi (0 to 2pi), if phiIsOpen
293 G4bool phiIsOpen = false; // True if there is a phi slice
294 G4bool allBehind = false; // True if the entire solid is "behind" this face
295
296 G4IntersectingCone* cone = nullptr; // Our intersecting utility class
297
298 G4double rNorm, zNorm; // Normal to surface in r,z space
299 G4double rS, zS; // Unit vector along surface in r,z space
300 G4double length; // Length of face in r,z space
301 G4double prevRS,
302 prevZS; // Unit vector along previous polyconeSide
303 G4double nextRS,
304 nextZS; // Unit vector along next polyconeSide
305
306 G4double rNormEdge[2],
307 zNormEdge[2]; // Normal to edges
308
309 G4int ncorners = 0;
310 G4ThreeVector* corners = nullptr; // The coordinates of the corners
311 // (if phiIsOpen)
312
313 G4double kCarTolerance; // Geometrical surface thickness
314 G4double fSurfaceArea = 0.0; // Used for surface calculation
315
316 G4int instanceID;
317 // This field is used as instance ID.
318 G4GEOM_DLL static G4PlSideManager subInstanceManager;
319 // This field helps to use the class G4PlSideManager introduced above.
320};
321
322#endif
const G4double kCarTolerance
G4GeomSplitter< G4PlSideData > G4PlSideManager
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4AffineTransform is a class for geometric affine transformations. It supports efficient arbitrary ro...
G4GeomSplitter is an utility class for splitting of R/W data for thread-safety from geometry classes....
G4IntersectingCone is a utility class used to calculate the intersection of an arbitrary line with a ...
G4PolyconeSide is a utility class implementing a face that represents one conical side of a polycone.
void CalculateExtent(const EAxis axis, const G4VoxelLimits &voxelLimit, const G4AffineTransform &tranform, G4SolidExtentList &extentList) override
G4int GetInstanceID() const
~G4PolyconeSide() override
G4ThreeVector GetPointOnFace() override
G4PolyconeSide(const G4PolyconeSideRZ *prevRZ, const G4PolyconeSideRZ *tail, const G4PolyconeSideRZ *head, const G4PolyconeSideRZ *nextRZ, G4double phiStart, G4double deltaPhi, G4bool phiIsOpen, G4bool isAllBehind=false)
G4ThreeVector Normal(const G4ThreeVector &p, G4double *bestDistance) override
G4double SurfaceArea() override
EInside Inside(const G4ThreeVector &p, G4double tolerance, G4double *bestDistance) override
G4VCSGface * Clone() override
G4double Distance(const G4ThreeVector &p, G4bool outgoing) override
G4bool Intersect(const G4ThreeVector &p, const G4ThreeVector &v, G4bool outgoing, G4double surfTolerance, G4double &distance, G4double &distFromSurface, G4ThreeVector &normal, G4bool &isAllBehind) override
static const G4PlSideManager & GetSubInstanceManager()
G4double Extent(const G4ThreeVector axis) override
G4PolyconeSide & operator=(const G4PolyconeSide &source)
G4SolidExtentList is utility class designed for calculating the extent of a CSG-like solid for a voxe...
G4VCSGface()=default
G4VoxelLimits represents limitation/restrictions of space, where restrictions are only made perpendic...
EAxis
Definition geomdefs.hh:54
EInside
Definition geomdefs.hh:67
#define G4GEOM_DLL
Definition geomwdefs.hh:45
const axis_t axis_to_type< N >::axis
Definition pugixml.cc:9668