Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4GenericTrap.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// G4GenericTrap
27//
28// Class description:
29//
30// G4GenericTrap is a solid which represents an arbitrary trapezoid with
31// up to 8 vertices standing on two parallel planes perpendicular to Z axis.
32//
33// Parameters in the constructor:
34// - name - solid name
35// - halfZ - the solid half length in Z
36// - vertices - the (x,y) coordinates of vertices:
37// o first four points: vertices[i], i<4
38// are the vertices sitting on the -halfZ plane;
39// o last four points: vertices[i], i>=4
40// are the vertices sitting on the +halfZ plane.
41//
42// The order of defining the vertices of the solid is the following:
43// - point 0 is connected with points 1,3,4
44// - point 1 is connected with points 0,2,5
45// - point 2 is connected with points 1,3,6
46// - point 3 is connected with points 0,2,7
47// - point 4 is connected with points 0,5,7
48// - point 5 is connected with points 1,4,6
49// - point 6 is connected with points 2,5,7
50// - point 7 is connected with points 3,4,6
51// Points can be identical in order to create shapes with less than 8 vertices.
52// Adapted from Arb8 implementation in Root/TGeo.
53
54// Authors: T.Nikitina (CERN) & I.Hrivnacova (IPN, Orsay), 27.05.2010 - Created
55// Evgueni Tcherniaev (CERN), 27.05.2024 - Complete revision, speed up
56// -------------------------------------------------------------------
57#ifndef G4GENERICTRAP_HH
58#define G4GENERICTRAP_HH
59
60#include "G4GeomTypes.hh"
61
62#if defined(G4GEOM_USE_USOLIDS)
63#define G4GEOM_USE_UGENERICTRAP 1
64#endif
65
66#if defined(G4GEOM_USE_UGENERICTRAP)
67 #define G4UGenericTrap G4GenericTrap
68 #include "G4UGenericTrap.hh"
69#else
70
71#include <vector>
72
73#include "globals.hh"
74#include "G4TwoVector.hh"
75#include "G4VSolid.hh"
76
77/**
78 * @brief G4GenericTrap is a solid which represents an arbitrary trapezoid with
79 * up to 8 vertices standing on two parallel planes perpendicular to the Z axis.
80 * Points can be identical in order to create shapes with less than 8 vertices.
81 */
82
83class G4GenericTrap : public G4VSolid
84{
85 public:
86
87 /**
88 * Constructs an generic trapezoid, given its vertices.
89 * @param[in] name The solid name.
90 * @param[in] halfZ Half length in Z.
91 * @param[in] vertices The (x,y) coordinates of the vertices.
92 */
93 G4GenericTrap(const G4String& name, G4double halfZ,
94 const std::vector<G4TwoVector>& vertices);
95
96 /**
97 * Fake default constructor for usage restricted to direct object
98 * persistency for clients requiring preallocation of memory for
99 * persistifiable objects.
100 */
101 G4GenericTrap(__void__&);
102
103 /**
104 * Copy constructor and assignment operator.
105 */
106 G4GenericTrap(const G4GenericTrap& rhs);
108
109 /**
110 * Default Destructor.
111 */
112 ~G4GenericTrap() override = default;
113
114 /**
115 * Accessors and modifiers.
116 */
117 inline G4double GetZHalfLength() const;
118 inline G4int GetNofVertices() const;
119 inline G4TwoVector GetVertex(G4int index) const;
120 inline const std::vector<G4TwoVector>& GetVertices() const;
121 inline G4double GetTwistAngle(G4int index) const;
122 inline G4bool IsTwisted() const;
123 inline G4int GetVisSubdivisions() const;
124 inline void SetVisSubdivisions(G4int subdiv);
125
126 /**
127 * Concrete implementations of the expected query interfaces for
128 * solids, as defined in the base class G4VSolid.
129 */
130 EInside Inside(const G4ThreeVector& p) const override;
131 G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const override;
133 const G4ThreeVector& v) const override;
134 G4double DistanceToIn(const G4ThreeVector& p) const override;
136 const G4ThreeVector& v,
137 const G4bool calcNorm = false,
138 G4bool* validNorm = nullptr,
139 G4ThreeVector* n = nullptr) const override;
140 G4double DistanceToOut(const G4ThreeVector& p) const override;
141
142 /**
143 * Computes the bounding limits of the solid.
144 * @param[out] pMin The minimum bounding limit point.
145 * @param[out] pMax The maximum bounding limit point.
146 */
147 void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
148
149 /**
150 * Calculates the minimum and maximum extent of the solid, when under the
151 * specified transform, and within the specified limits.
152 * @param[in] pAxis The axis along which compute the extent.
153 * @param[in] pVoxelLimit The limiting space dictated by voxels.
154 * @param[in] pTransform The internal transformation applied to the solid.
155 * @param[out] pMin The minimum extent value.
156 * @param[out] pMax The maximum extent value.
157 * @returns True if the solid is intersected by the extent region.
158 */
159 G4bool CalculateExtent(const EAxis pAxis,
160 const G4VoxelLimits& pVoxelLimit,
161 const G4AffineTransform& pTransform,
162 G4double& pmin, G4double& pmax) const override;
163
164 /**
165 * Returns the type ID, "G4GenericTrap" of the solid.
166 */
167 G4GeometryType GetEntityType() const override;
168
169 /**
170 * Returns true if the solid has only planar faces; false if twisted.
171 */
172 G4bool IsFaceted () const override;
173
174 /**
175 * Makes a clone of the object for use in multi-treading.
176 * @returns A pointer to the new cloned allocated solid.
177 */
178 G4VSolid* Clone() const override;
179
180 /**
181 * Streams the object contents to an output stream.
182 */
183 std::ostream& StreamInfo(std::ostream& os) const override;
184
185 /**
186 * Returns a random point located and uniformly distributed on the
187 * surface of the solid.
188 */
189 G4ThreeVector GetPointOnSurface() const override ;
190
191 /**
192 * Returning an estimation of the solid volume (capacity) and
193 * surface area, in internal units.
194 */
195 G4double GetCubicVolume() override;
196 G4double GetSurfaceArea() override;
197
198 /**
199 * Methods for creating graphical representations (i.e. for visualisation).
200 */
201 void DescribeYourselfTo(G4VGraphicsScene& scene) const override;
202 G4VisExtent GetExtent() const override;
203 G4Polyhedron* CreatePolyhedron() const override;
204 G4Polyhedron* GetPolyhedron() const override;
205
206 private:
207
208 /**
209 * Algorithm for SurfaceNormal() following the original
210 * specification for points not on the surface.
211 */
212 G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector& p) const;
213
214 /**
215 * Checks the parameters of the solid and issues exception if leading
216 * to an invalid construct.
217 */
218 void CheckParameters(G4double halfZ, const std::vector<G4TwoVector>& vertices);
219
220 /**
221 * Computes surface equations and twist angles of lateral faces.
222 */
223 void ComputeLateralSurfaces();
224
225 /**
226 * Sets the bounding box.
227 */
228 void ComputeBoundingBox();
229
230 /**
231 * Sets the max length of a scratch.
232 */
233 void ComputeScratchLength();
234
235 /**
236 * Computes the lateral face area, given the face index.
237 * Used for random sampling of points on surface.
238 */
239 G4double GetLateralFaceArea(G4int iface) const;
240
241 /**
242 * Logger methods for issuing warnings.
243 */
244 void WarningSignA(const G4String& method, const G4String& icase, G4double A,
245 const G4ThreeVector& p, const G4ThreeVector& v) const;
246 void WarningSignB(const G4String& method, const G4String& icase, G4double f, G4double B,
247 const G4ThreeVector& p, const G4ThreeVector& v) const;
248 void WarningDistanceToIn(G4int k, const G4ThreeVector& p, const G4ThreeVector& v,
249 G4double tmin, G4double tmax,
250 const G4double ttin[2], const G4double ttout[2]) const;
251 void WarningDistanceToOut(const G4ThreeVector& p,
252 const G4ThreeVector& v,
253 G4double tout) const;
254
255 private:
256
257 struct G4GenericTrapPlane // Ax + By + Cz + D = 0
258 {
259 G4double A = 0.;
260 G4double B = 0.;
261 G4double C = 0.;
262 G4double D = 0.;
263 };
264 struct G4GenericTrapSurface // Axz + Byz + Czz + Dx + Ey + Fz + G = 0
265 {
266 G4double A = 0.;
267 G4double B = 0.;
268 G4double C = 0.;
269 G4double D = 0.;
270 G4double E = 0.;
271 G4double F = 0.;
272 G4double G = 0.;
273 };
274
275 // Data members
276 G4double halfTolerance = 0.;
277 G4double fScratch = 0.;
278 G4double fDz = 0.;
279 std::vector<G4TwoVector> fVertices = {0.,0.,0.,0.,0.,0.,0.,0.};
280 G4TwoVector fDelta[4];
281 G4bool fIsTwisted = false;
282 G4double fTwist[5] = {0.};
283 G4ThreeVector fMinBBox{0.};
284 G4ThreeVector fMaxBBox{0.};
285 G4int fVisSubdivisions = 0;
286 G4GenericTrapPlane fPlane[8];
287 G4GenericTrapSurface fSurf[4];
288 G4double f4k[4] = {0.}; // Lipschitz constants * 4
289 mutable G4double fArea[4] = {0.};
290 mutable G4bool fRebuildPolyhedron = false;
291 mutable G4Polyhedron* fpPolyhedron = nullptr;
292
293 // Surface and Volume
294 G4double fSurfaceArea = 0.;
295 G4double fCubicVolume = 0.;
296};
297
298#include "G4GenericTrap.icc"
299
300#endif // defined(G4GEOM_USE_UGENERICTRAP)
301
302#endif // G4GENERICTRAP_HH
G4double C(G4double temp)
G4double B(G4double temperature)
G4double D(G4double temp)
CLHEP::Hep3Vector G4ThreeVector
CLHEP::Hep2Vector G4TwoVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4String G4GeometryType
Definition G4VSolid.hh:70
const G4double A[17]
G4AffineTransform is a class for geometric affine transformations. It supports efficient arbitrary ro...
~G4GenericTrap() override=default
G4int GetNofVertices() const
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const override
G4GenericTrap & operator=(const G4GenericTrap &rhs)
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const override
G4double GetZHalfLength() const
std::ostream & StreamInfo(std::ostream &os) const override
G4TwoVector GetVertex(G4int index) const
G4GeometryType GetEntityType() const override
G4Polyhedron * GetPolyhedron() const override
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const override
G4double GetTwistAngle(G4int index) const
G4double GetCubicVolume() override
G4VisExtent GetExtent() const override
const std::vector< G4TwoVector > & GetVertices() const
G4VSolid * Clone() const override
G4int GetVisSubdivisions() const
EInside Inside(const G4ThreeVector &p) const override
G4bool IsTwisted() const
G4Polyhedron * CreatePolyhedron() const 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
void SetVisSubdivisions(G4int subdiv)
G4bool IsFaceted() const override
G4GenericTrap(const G4String &name, G4double halfZ, const std::vector< G4TwoVector > &vertices)
G4double GetSurfaceArea() override
G4ThreeVector GetPointOnSurface() const override
void DescribeYourselfTo(G4VGraphicsScene &scene) const override
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