Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4UEllipticalTube.cc
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// Implementation for G4UEllipticalTube wrapper class
27//
28// 13-08-2019 Gabriele Cosmo, CERN
29// --------------------------------------------------------------------
30
31#include "G4EllipticalTube.hh"
32#include "G4UEllipticalTube.hh"
33
34#if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
35
36#include "G4AffineTransform.hh"
39#include "G4BoundingEnvelope.hh"
40#include "G4Polyhedron.hh"
41
42////////////////////////////////////////////////////////////////////////
43//
44// Constructor - check & set half widths
45
46
47G4UEllipticalTube::G4UEllipticalTube(const G4String& pName,
48 G4double dx,
49 G4double dy,
50 G4double dz )
51 : Base_t(pName, dx, dy, dz)
52{ }
53
54//////////////////////////////////////////////////////////////////////////
55//
56// Copy constructor
57
58G4UEllipticalTube::G4UEllipticalTube(const G4UEllipticalTube& rhs)
59 : Base_t(rhs)
60{ }
61
62//////////////////////////////////////////////////////////////////////////
63//
64// Assignment operator
65
66G4UEllipticalTube& G4UEllipticalTube::operator = (const G4UEllipticalTube& rhs)
67{
68 // Check assignment to self
69 //
70 if (this == &rhs) { return *this; }
71
72 // Copy base class data
73 //
74 Base_t::operator=(rhs);
75
76 return *this;
77}
78
79//////////////////////////////////////////////////////////////////////////
80//
81// Accessors
82
83G4double G4UEllipticalTube::GetDx() const
84{
85 return Base_t::GetDx();
86}
87
88G4double G4UEllipticalTube::GetDy() const
89{
90 return Base_t::GetDy();
91}
92
93G4double G4UEllipticalTube::GetDz() const
94{
95 return Base_t::GetDz();
96}
97
98//////////////////////////////////////////////////////////////////////////
99//
100// Modifiers
101
102void G4UEllipticalTube::SetDx(G4double dx)
103{
104 Base_t::SetDx(dx);
105}
106
107void G4UEllipticalTube::SetDy(G4double dy)
108{
109 Base_t::SetDy(dy);
110}
111
112void G4UEllipticalTube::SetDz(G4double dz)
113{
114 Base_t::SetDz(dz);
115}
116
117//////////////////////////////////////////////////////////////////////////
118//
119// Make a clone of the object
120
121G4VSolid* G4UEllipticalTube::Clone() const
122{
123 return new G4UEllipticalTube(*this);
124}
125
126//////////////////////////////////////////////////////////////////////////
127//
128// Get bounding box
129
130void G4UEllipticalTube::BoundingLimits(G4ThreeVector& pMin,
131 G4ThreeVector& pMax) const
132{
133 G4double dx = GetDx();
134 G4double dy = GetDy();
135 G4double dz = GetDz();
136
137 pMin.set(-dx,-dy,-dz);
138 pMax.set( dx, dy, dz);
139}
140
141//////////////////////////////////////////////////////////////////////////
142//
143// Calculate extent under transform and specified limit
144
145G4bool
146G4UEllipticalTube::CalculateExtent(const EAxis pAxis,
147 const G4VoxelLimits& pVoxelLimit,
148 const G4AffineTransform& pTransform,
149 G4double& pMin, G4double& pMax) const
150{
151 G4ThreeVector bmin, bmax;
152 G4bool exist;
153
154 // Check bounding box (bbox)
155 //
156 BoundingLimits(bmin,bmax);
157 G4BoundingEnvelope bbox(bmin,bmax);
158#ifdef G4BBOX_EXTENT
159 return bbox.CalculateExtent(pAxis,pVoxelLimit, pTransform, pMin, pMax);
160#endif
161 if (bbox.BoundingBoxVsVoxelLimits(pAxis, pVoxelLimit, pTransform, pMin, pMax))
162 {
163 return exist = pMin < pMax;
164 }
165
166 G4double dx = GetDx();
167 G4double dy = GetDy();
168 G4double dz = GetDz();
169
170 // Set bounding envelope (benv) and calculate extent
171 //
172 const G4int NSTEPS = 24; // number of steps for whole circle
173 G4double ang = twopi/NSTEPS;
174
175 G4double sinHalf = std::sin(0.5*ang);
176 G4double cosHalf = std::cos(0.5*ang);
177 G4double sinStep = 2.*sinHalf*cosHalf;
178 G4double cosStep = 1. - 2.*sinHalf*sinHalf;
179 G4double sx = dx/cosHalf;
180 G4double sy = dy/cosHalf;
181
182 G4double sinCur = sinHalf;
183 G4double cosCur = cosHalf;
184 G4ThreeVectorList baseA(NSTEPS), baseB(NSTEPS);
185 for (G4int k=0; k<NSTEPS; ++k)
186 {
187 baseA[k].set(sx*cosCur,sy*sinCur,-dz);
188 baseB[k].set(sx*cosCur,sy*sinCur, dz);
189
190 G4double sinTmp = sinCur;
191 sinCur = sinCur*cosStep + cosCur*sinStep;
192 cosCur = cosCur*cosStep - sinTmp*sinStep;
193 }
194
195 std::vector<const G4ThreeVectorList *> polygons(2);
196 polygons[0] = &baseA;
197 polygons[1] = &baseB;
198 G4BoundingEnvelope benv(bmin, bmax, polygons);
199 exist = benv.CalculateExtent(pAxis, pVoxelLimit, pTransform, pMin, pMax);
200 return exist;
201}
202
203////////////////////////////////////////////////////////////////////////
204//
205// CreatePolyhedron
206//
207G4Polyhedron* G4UEllipticalTube::CreatePolyhedron() const
208{
209 // create cylinder with radius=1...
210 //
211 G4Polyhedron* eTube = new G4PolyhedronTube(0., 1., GetDz());
212
213 // apply non-uniform scaling...
214 //
215 eTube->Transform(G4Scale3D(GetDx(), GetDy(), 1.));
216 return eTube;
217}
218
219#endif // G4GEOM_USE_USOLIDS
std::vector< G4ThreeVector > G4ThreeVectorList
CLHEP::Hep3Vector G4ThreeVector
HepGeom::Scale3D G4Scale3D
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
void set(double x, double y, double z)
G4AffineTransform is a class for geometric affine transformations. It supports efficient arbitrary ro...
G4BoundingEnvelope is a helper class to facilitate calculation of the extent of a solid within the li...
G4VSolid is an abstract base class for solids, physical shapes that can be tracked through....
Definition G4VSolid.hh:80
G4VoxelLimits represents limitation/restrictions of space, where restrictions are only made perpendic...
HepPolyhedron & Transform(const G4Transform3D &t)
EAxis
Definition geomdefs.hh:54