Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Trap.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// G4Trap
27//
28// Class description:
29//
30// A G4Trap is a general trapezoid: The faces perpendicular to the
31// z planes are trapezia, and their centres are not necessarily on
32// a line parallel to the z axis.
33//
34// Note that of the 11 parameters described below, only 9 are really
35// independent - a check for planarity is made in the calculation of the
36// equation for each plane. If the planes are not parallel, a call to
37// G4Exception is made.
38//
39// pDz Half-length along the z-axis
40// pTheta Polar angle of the line joining the centres of the faces
41// at -/+pDz
42// pPhi Azimuthal angle of the line joining the centre of the face at
43// -pDz to the centre of the face at +pDz
44// pDy1 Half-length along y of the face at -pDz
45// pDx1 Half-length along x of the side at y=-pDy1 of the face at -pDz
46// pDx2 Half-length along x of the side at y=+pDy1 of the face at -pDz
47// pAlp1 Angle with respect to the y axis from the centre of the side
48// at y=-pDy1 to the centre at y=+pDy1 of the face at -pDz
49//
50// pDy2 Half-length along y of the face at +pDz
51// pDx3 Half-length along x of the side at y=-pDy2 of the face at +pDz
52// pDx4 Half-length along x of the side at y=+pDy2 of the face at +pDz
53// pAlp2 Angle with respect to the y axis from the centre of the side
54// at y=-pDy2 to the centre at y=+pDy2 of the face at +pDz
55//
56//
57// Member Data:
58//
59// fDz Half-length along the z axis
60// fTthetaCphi = std::tan(pTheta)*std::cos(pPhi)
61// fTthetaSphi = std::tan(pTheta)*std::sin(pPhi)
62// These combinations are suitable for creation of the trapezoid corners
63//
64// fDy1 Half-length along y of the face at -fDz
65// fDx1 Half-length along x of the side at y=-fDy1 of the face at -fDz
66// fDx2 Half-length along x of the side at y=+fDy1 of the face at -fDz
67// fTalpha1 Tan of Angle with respect to the y axis from the centre of
68// the side at y=-fDy1 to the centre at y=+fDy1 of the face
69// at -fDz
70//
71// fDy2 Half-length along y of the face at +fDz
72// fDx3 Half-length along x of the side at y=-fDy2 of the face at +fDz
73// fDx4 Half-length along x of the side at y=+fDy2 of the face at +fDz
74// fTalpha2 Tan of Angle with respect to the y axis from the centre of
75// the side at y=-fDy2 to the centre at y=+fDy2 of the face
76// at +fDz
77//
78// TrapSidePlane fPlanes[4] Plane equations of the faces not at +/-fDz
79// NOTE: order is important !!!
80
81// Author: Paul Kent, 23.03.1994 - Code converted to tolerant geometry
82// --------------------------------------------------------------------
83#ifndef G4TRAP_HH
84#define G4TRAP_HH
85
86#include "G4Types.hh"
87
89{
90 G4double a,b,c,d; // Normal unit vector (a,b,c) and offset (d)
91 // => Ax+By+Cz+D=0
92};
93
94#include "G4GeomTypes.hh"
95
96#if defined(G4GEOM_USE_USOLIDS)
97#define G4GEOM_USE_UTRAP 1
98#endif
99
100#if defined(G4GEOM_USE_UTRAP)
101 #define G4UTrap G4Trap
102 #include "G4UTrap.hh"
103#else
104
105#include "G4CSGSolid.hh"
106
107/**
108 * @brief G4Trap is a general trapezoid: the faces perpendicular to the Z
109 * planes are trapezia, and their centres are not necessarily on a line parallel
110 * to the Z axis. A check for planarity is made in the calculation of the
111 * equation for each plane. If the planes are not parallel, a call to
112 * G4Exception is made.
113 */
114
115class G4Trap : public G4CSGSolid
116{
117 public:
118
119 /**
120 * The most general constructor for G4Trap which prepares plane
121 * equations and corner coordinates from parameters.
122 * @param[in] pName The name of the solid.
123 * @param[in] pDz Half-length along the Z-axis.
124 * @param[in] pTheta Polar angle of the line joining the centres
125 * of the faces at -/+pDz.
126 * @param[in] pPhi Azimuthal angle of the line joining the centre
127 * of the face at -pDz to the centre of the face at +pDz.
128 * @param[in] pDy1 Half-length along Y of the face at -pDz.
129 * @param[in] pDx1 Half-length along X of the side at y=-pDy1
130 * of the face at -pDz.
131 * @param[in] pDx2 Half-length along X of the side at y=+pDy1
132 * of the face at -pDz.
133 * @param[in] pAlp1 Angle with respect to the Y axis from the centre of the
134 * side at y=-pDy1 to the centre at y=+pDy1 of the face at -pDz.
135 * @param[in] pDy2 Half-length along Y of the face at +pDz.
136 * @param[in] pDx3 Half-length along X of the side at y=-pDy2
137 * of the face at +pDz.
138 * @param[in] pDx4 Half-length along X of the side at y=+pDy2
139 * of the face at +pDz.
140 * @param[in] pAlp2 Angle with respect to the Y axis from the centre of the
141 * side at y=-pDy2 to the centre at y=+pDy2 of the face at +pDz.
142 */
143 G4Trap( const G4String& pName,
144 G4double pDz,
145 G4double pTheta, G4double pPhi,
146 G4double pDy1, G4double pDx1, G4double pDx2,
147 G4double pAlp1,
148 G4double pDy2, G4double pDx3, G4double pDx4,
149 G4double pAlp2 );
150
151 /**
152 * Prepares plane equations and parameters from corner coordinates.
153 * @param[in] pName The name of the solid.
154 * @param[in] pt Points of the 8 vertices.
155 */
156 G4Trap( const G4String& pName,
157 const G4ThreeVector pt[8] ) ;
158
159 /**
160 * Constructor for Right Angular Wedge from STEP (assumes pLTX<=pX).
161 * @param[in] pName The name of the solid.
162 * @param[in] pZ Length along Z.
163 * @param[in] pY Length along Y.
164 * @param[in] pX Length along X at the wider side.
165 * @param[in] pLTX Length along X at the narrower side (plTX<=pX).
166 */
167 G4Trap( const G4String& pName,
168 G4double pZ,
169 G4double pY,
170 G4double pX, G4double pLTX );
171
172 /**
173 * Constructor for G4Trd.
174 * @param[in] pName The name of the solid.
175 * @param[in] pDx1 Half-length along X at the surface positioned at -dz.
176 * @param[in] pDx2 Half-length along X at the surface positioned at +dz.
177 * @param[in] pDy1 Half-length along Y at the surface positioned at -dz.
178 * @param[in] pDy2 Half-length along Y at the surface positioned at +dz.
179 * @param[in] pDz Half-length along Z axis.
180 */
181 G4Trap( const G4String& pName,
182 G4double pDx1, G4double pDx2,
183 G4double pDy1, G4double pDy2,
184 G4double pDz );
185
186 /**
187 * Constructor for G4Para.
188 * @param[in] pName The name of the solid.
189 * @param[in] pDx Half-length in X.
190 * @param[in] pDy Half-length in Y.
191 * @param[in] pDz Half-length in Z.
192 * @param[in] pAlpha Angle formed by the Y axis and the plane joining the
193 * centre of the faces parallel to the Z-X plane at -dy and +dy.
194 * @param[in] pTheta Polar angle of the line joining the centres of the
195 * faces at -dz and +dz in Z.
196 * @param[in] pPhi Azimuthal angle of the line joining the centres of
197 * the faces at -dz and +dz in Z.
198 */
199 G4Trap(const G4String& pName,
200 G4double pDx, G4double pDy, G4double pDz,
201 G4double pAlpha, G4double pTheta, G4double pPhi );
202
203 /**
204 * Constructor for "nominal" G4Trap whose parameters are to be set
205 * by a G4VPVParamaterisation later on.
206 * @param[in] pName The name of the solid.
207 */
208 G4Trap( const G4String& pName );
209
210 /**
211 * Default destructor.
212 */
213 ~G4Trap() override = default;
214
215 /**
216 * Accessors. Returning the coordinates of a unit vector along a straight
217 * line joining centers of -/+fDz planes.
218 */
219 inline G4double GetZHalfLength() const;
220 inline G4double GetYHalfLength1() const;
221 inline G4double GetXHalfLength1() const;
222 inline G4double GetXHalfLength2() const;
223 inline G4double GetTanAlpha1() const;
224 inline G4double GetYHalfLength2() const;
225 inline G4double GetXHalfLength3() const;
226 inline G4double GetXHalfLength4() const;
227 inline G4double GetTanAlpha2() const;
228
229 /**
230 * More accessors.
231 */
233 inline G4ThreeVector GetSymAxis() const;
234
235 /**
236 * Accessors obtaining (re)computed values of the original parameters.
237 */
238 inline G4double GetPhi() const;
239 inline G4double GetTheta() const;
240 inline G4double GetAlpha1() const;
241 inline G4double GetAlpha2() const;
242
243 /**
244 * Sets all parameters, as for constructor. Checks and sets half-widths
245 * as well as angles. Makes a final check of co-planarity.
246 */
247 void SetAllParameters ( G4double pDz,
248 G4double pTheta,
249 G4double pPhi,
250 G4double pDy1,
251 G4double pDx1,
252 G4double pDx2,
253 G4double pAlp1,
254 G4double pDy2,
255 G4double pDx3,
256 G4double pDx4,
257 G4double pAlp2 );
258
259 /**
260 * Returning an estimation of the solid volume (capacity) and
261 * surface area, in internal units.
262 */
263 G4double GetCubicVolume() override;
264 G4double GetSurfaceArea() override;
265
266 /**
267 * Dispatch method for parameterisation replication mechanism and
268 * dimension computation.
269 */
271 const G4int n,
272 const G4VPhysicalVolume* pRep ) override;
273
274 /**
275 * Computes the bounding limits of the solid.
276 * @param[out] pMin The minimum bounding limit point.
277 * @param[out] pMax The maximum bounding limit point.
278 */
279 void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
280
281 /**
282 * Calculates the minimum and maximum extent of the solid, when under the
283 * specified transform, and within the specified limits.
284 * @param[in] pAxis The axis along which compute the extent.
285 * @param[in] pVoxelLimit The limiting space dictated by voxels.
286 * @param[in] pTransform The internal transformation applied to the solid.
287 * @param[out] pMin The minimum extent value.
288 * @param[out] pMax The maximum extent value.
289 * @returns True if the solid is intersected by the extent region.
290 */
291 G4bool CalculateExtent(const EAxis pAxis,
292 const G4VoxelLimits& pVoxelLimit,
293 const G4AffineTransform& pTransform,
294 G4double& pMin, G4double& pMax) const override;
295
296 /**
297 * Concrete implementations of the expected query interfaces for
298 * solids, as defined in the base class G4VSolid.
299 */
300 EInside Inside( const G4ThreeVector& p ) const override;
301 G4ThreeVector SurfaceNormal( const G4ThreeVector& p ) const override;
303 const G4ThreeVector& v) const override;
304 G4double DistanceToIn( const G4ThreeVector& p ) const override;
306 const G4bool calcNorm = false,
307 G4bool* validNorm = nullptr,
308 G4ThreeVector* n = nullptr) const override;
309 G4double DistanceToOut( const G4ThreeVector& p ) const override;
310
311 /**
312 * Returns the type ID, "G4Trap" of the solid.
313 */
314 G4GeometryType GetEntityType() const override;
315
316 /**
317 * Returns a random point located and uniformly distributed on the
318 * surface of the solid.
319 */
320 G4ThreeVector GetPointOnSurface() const override;
321
322 /**
323 * Returns true as the solid has only planar faces.
324 */
325 G4bool IsFaceted() const override;
326
327 /**
328 * Makes a clone of the object for use in multi-treading.
329 * @returns A pointer to the new cloned allocated solid.
330 */
331 G4VSolid* Clone() const override;
332
333 /**
334 * Streams the object contents to an output stream.
335 */
336 std::ostream& StreamInfo( std::ostream& os ) const override;
337
338 /**
339 * Methods for creating graphical representations (i.e. for visualisation).
340 */
341 void DescribeYourselfTo (G4VGraphicsScene& scene) const override;
342 G4Polyhedron* CreatePolyhedron () const override;
343
344 /**
345 * Fake default constructor for usage restricted to direct object
346 * persistency for clients requiring preallocation of memory for
347 * persistifiable objects.
348 */
349 G4Trap(__void__&);
350
351 /**
352 * Copy constructor and assignment operator.
353 */
354 G4Trap(const G4Trap& rhs);
355 G4Trap& operator=(const G4Trap& rhs);
356
357 protected:
358
359 /**
360 * Internal methods for checking and building planes.
361 * Computing the vertices and setting side planes, checking for planarity.
362 */
363 void MakePlanes();
364 void MakePlanes( const G4ThreeVector pt[8] );
365
366 /**
367 * Calculates the coefficents of the plane p1->p2->p3->p4->p1
368 * where the ThreeVectors 1-4 are in anti-clockwise order when viewed
369 * from infront of the plane (i.e. from normal direction).
370 * @return true if the points are co-planar, false otherwise.
371 */
372 G4bool MakePlane( const G4ThreeVector& p1,
373 const G4ThreeVector& p2,
374 const G4ThreeVector& p3,
375 const G4ThreeVector& p4,
376 TrapSidePlane& plane ) ;
377 /**
378 * Recomputes parameters using planes.
379 */
380 void SetCachedValues();
381
382 private:
383
384 /**
385 * Checks the input parameters.
386 */
387 void CheckParameters();
388
389 /**
390 * Computes the coordinates of the trap vertices from planes.
391 */
392 void GetVertices(G4ThreeVector pt[8]) const;
393
394 /**
395 * Algorithm for SurfaceNormal() following the original specification
396 * for points not on the surface.
397 */
398 G4ThreeVector ApproxSurfaceNormal( const G4ThreeVector& p ) const;
399
400 private:
401
402 G4double halfCarTolerance;
403 G4double fDz,fTthetaCphi,fTthetaSphi;
404 G4double fDy1,fDx1,fDx2,fTalpha1;
405 G4double fDy2,fDx3,fDx4,fTalpha2;
406 TrapSidePlane fPlanes[4];
407 G4double fAreas[6];
408 G4int fTrapType;
409};
410
411#include "G4Trap.icc"
412
413#endif
414
415#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
G4double GetCubicVolume() override
Definition G4Trap.cc:1190
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep) override
Definition G4Trap.cc:487
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const override
Definition G4Trap.cc:538
G4bool IsFaceted() const override
Definition G4Trap.cc:1079
G4GeometryType GetEntityType() const override
Definition G4Trap.cc:1070
G4double GetYHalfLength1() const
void SetAllParameters(G4double pDz, G4double pTheta, G4double pPhi, G4double pDy1, G4double pDx1, G4double pDx2, G4double pAlp1, G4double pDy2, G4double pDx3, G4double pDx4, G4double pAlp2)
Definition G4Trap.cc:280
G4ThreeVector GetPointOnSurface() const override
Definition G4Trap.cc:1149
G4double GetAlpha2() const
G4double GetTanAlpha2() const
G4double GetAlpha1() const
G4double GetTheta() const
~G4Trap() override=default
G4double GetPhi() const
G4double GetXHalfLength2() const
void SetCachedValues()
Definition G4Trap.cc:432
G4VSolid * Clone() const override
Definition G4Trap.cc:1088
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const override
Definition G4Trap.cc:783
G4ThreeVector GetSymAxis() const
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const override
Definition G4Trap.cc:650
std::ostream & StreamInfo(std::ostream &os) const override
Definition G4Trap.cc:1097
G4double GetXHalfLength4() const
EInside Inside(const G4ThreeVector &p) const override
Definition G4Trap.cc:587
G4double GetSurfaceArea() override
Definition G4Trap.cc:1217
G4double GetZHalfLength() const
G4double GetYHalfLength2() const
G4Polyhedron * CreatePolyhedron() const override
Definition G4Trap.cc:1248
void MakePlanes()
Definition G4Trap.cc:333
G4double GetTanAlpha1() const
TrapSidePlane GetSidePlane(G4int n) const
G4Trap(const G4String &pName, G4double pDz, G4double pTheta, G4double pPhi, G4double pDy1, G4double pDx1, G4double pDx2, G4double pAlp1, G4double pDy2, G4double pDx3, G4double pDx4, G4double pAlp2)
Definition G4Trap.cc:66
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const override
Definition G4Trap.cc:912
G4bool MakePlane(const G4ThreeVector &p1, const G4ThreeVector &p2, const G4ThreeVector &p3, const G4ThreeVector &p4, TrapSidePlane &plane)
Definition G4Trap.cc:400
void DescribeYourselfTo(G4VGraphicsScene &scene) const override
Definition G4Trap.cc:1243
G4double GetXHalfLength3() const
G4double GetXHalfLength1() const
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const override
Definition G4Trap.cc:498
G4Trap & operator=(const G4Trap &rhs)
Definition G4Trap.cc:253
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
G4double b
Definition G4Trap.hh:90
G4double c
Definition G4Trap.hh:90
G4double d
Definition G4Trap.hh:90
G4double a
Definition G4Trap.hh:90