Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4UTrd.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 G4UTrd wrapper class
27//
28// 13.09.13 G.Cosmo, CERN
29// --------------------------------------------------------------------
30
31#include "G4Trd.hh"
32#include "G4UTrd.hh"
33
34#if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
35
36#include "G4AffineTransform.hh"
38#include "G4BoundingEnvelope.hh"
39
40using namespace CLHEP;
41
42/////////////////////////////////////////////////////////////////////////
43//
44// Constructor - check & set half widths
45//
46G4UTrd::G4UTrd(const G4String& pName,
47 G4double pdx1, G4double pdx2,
48 G4double pdy1, G4double pdy2,
49 G4double pdz)
50 : Base_t(pName, pdx1, pdx2, pdy1, pdy2, pdz)
51{
52}
53
54//////////////////////////////////////////////////////////////////////////
55//
56// Copy constructor
57//
58G4UTrd::G4UTrd(const G4UTrd& rhs)
59 : Base_t(rhs)
60{
61}
62
63//////////////////////////////////////////////////////////////////////////
64//
65// Assignment operator
66//
67G4UTrd& G4UTrd::operator = (const G4UTrd& rhs)
68{
69 // Check assignment to self
70 //
71 if (this == &rhs) { return *this; }
72
73 // Copy base class data
74 //
75 Base_t::operator=(rhs);
76
77 return *this;
78}
79
80//////////////////////////////////////////////////////////////////////////
81//
82// Accessors & modifiers
83
84G4double G4UTrd::GetXHalfLength1() const
85{
86 return dx1();
87}
88G4double G4UTrd::GetXHalfLength2() const
89{
90 return dx2();
91}
92G4double G4UTrd::GetYHalfLength1() const
93{
94 return dy1();
95}
96G4double G4UTrd::GetYHalfLength2() const
97{
98 return dy2();
99}
100G4double G4UTrd::GetZHalfLength() const
101{
102 return dz();
103}
104
105void G4UTrd::SetXHalfLength1(G4double val)
106{
107 Base_t::SetXHalfLength1(val);
108 fRebuildPolyhedron = true;
109}
110void G4UTrd::SetXHalfLength2(G4double val)
111{
112 Base_t::SetXHalfLength2(val);
113 fRebuildPolyhedron = true;
114}
115void G4UTrd::SetYHalfLength1(G4double val)
116{
117 Base_t::SetYHalfLength1(val);
118 fRebuildPolyhedron = true;
119}
120void G4UTrd::SetYHalfLength2(G4double val)
121{
122 Base_t::SetYHalfLength2(val);
123 fRebuildPolyhedron = true;
124}
125void G4UTrd::SetZHalfLength(G4double val)
126{
127 Base_t::SetZHalfLength(val);
128 fRebuildPolyhedron = true;
129}
130void G4UTrd::SetAllParameters(G4double pdx1, G4double pdx2,
131 G4double pdy1, G4double pdy2, G4double pdz)
132{
133 Base_t::SetAllParameters(pdx1, pdx2, pdy1, pdy2, pdz);
134 fRebuildPolyhedron = true;
135}
136
137/////////////////////////////////////////////////////////////////////////
138//
139// Dispatch to parameterisation for replication mechanism dimension
140// computation & modification.
141//
142void G4UTrd::ComputeDimensions( G4VPVParameterisation* p,
143 const G4int n,
144 const G4VPhysicalVolume* pRep)
145{
146 p->ComputeDimensions(*(G4Trd*)this,n,pRep);
147}
148
149//////////////////////////////////////////////////////////////////////////
150//
151// Make a clone of the object
152
153G4VSolid* G4UTrd::Clone() const
154{
155 return new G4UTrd(*this);
156}
157
158//////////////////////////////////////////////////////////////////////////
159//
160// Get bounding box
161
162void G4UTrd::BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const
163{
164 static G4bool checkBBox = true;
165
166 G4double dx1 = GetXHalfLength1();
167 G4double dx2 = GetXHalfLength2();
168 G4double dy1 = GetYHalfLength1();
169 G4double dy2 = GetYHalfLength2();
170 G4double dz = GetZHalfLength();
171
172 G4double xmax = std::max(dx1,dx2);
173 G4double ymax = std::max(dy1,dy2);
174 pMin.set(-xmax,-ymax,-dz);
175 pMax.set( xmax, ymax, dz);
176
177 // Check correctness of the bounding box
178 //
179 if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
180 {
181 std::ostringstream message;
182 message << "Bad bounding box (min >= max) for solid: "
183 << GetName() << " !"
184 << "\npMin = " << pMin
185 << "\npMax = " << pMax;
186 G4Exception("G4UTrd::BoundingLimits()", "GeomMgt0001",
187 JustWarning, message);
188 StreamInfo(G4cout);
189 }
190
191 // Check consistency of bounding boxes
192 //
193 if (checkBBox)
194 {
195 U3Vector vmin, vmax;
196 Extent(vmin,vmax);
197 if (std::abs(pMin.x()-vmin.x()) > kCarTolerance ||
198 std::abs(pMin.y()-vmin.y()) > kCarTolerance ||
199 std::abs(pMin.z()-vmin.z()) > kCarTolerance ||
200 std::abs(pMax.x()-vmax.x()) > kCarTolerance ||
201 std::abs(pMax.y()-vmax.y()) > kCarTolerance ||
202 std::abs(pMax.z()-vmax.z()) > kCarTolerance)
203 {
204 std::ostringstream message;
205 message << "Inconsistency in bounding boxes for solid: "
206 << GetName() << " !"
207 << "\nBBox min: wrapper = " << pMin << " solid = " << vmin
208 << "\nBBox max: wrapper = " << pMax << " solid = " << vmax;
209 G4Exception("G4UTrd::BoundingLimits()", "GeomMgt0001",
210 JustWarning, message);
211 checkBBox = false;
212 }
213 }
214}
215
216//////////////////////////////////////////////////////////////////////////
217//
218// Calculate extent under transform and specified limit
219
220G4bool
221G4UTrd::CalculateExtent(const EAxis pAxis,
222 const G4VoxelLimits& pVoxelLimit,
223 const G4AffineTransform& pTransform,
224 G4double& pMin, G4double& pMax) const
225{
226 G4ThreeVector bmin, bmax;
227 G4bool exist;
228
229 // Check bounding box (bbox)
230 //
231 BoundingLimits(bmin,bmax);
232 G4BoundingEnvelope bbox(bmin,bmax);
233#ifdef G4BBOX_EXTENT
234 if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
235#endif
236 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
237 {
238 return exist = pMin < pMax;
239 }
240
241 // Set bounding envelope (benv) and calculate extent
242 //
243 G4double dx1 = GetXHalfLength1();
244 G4double dx2 = GetXHalfLength2();
245 G4double dy1 = GetYHalfLength1();
246 G4double dy2 = GetYHalfLength2();
247 G4double dz = GetZHalfLength();
248
249 G4ThreeVectorList baseA(4), baseB(4);
250 baseA[0].set(-dx1,-dy1,-dz);
251 baseA[1].set( dx1,-dy1,-dz);
252 baseA[2].set( dx1, dy1,-dz);
253 baseA[3].set(-dx1, dy1,-dz);
254 baseB[0].set(-dx2,-dy2, dz);
255 baseB[1].set( dx2,-dy2, dz);
256 baseB[2].set( dx2, dy2, dz);
257 baseB[3].set(-dx2, dy2, dz);
258
259 std::vector<const G4ThreeVectorList *> polygons(2);
260 polygons[0] = &baseA;
261 polygons[1] = &baseB;
262
263 G4BoundingEnvelope benv(bmin,bmax,polygons);
264 exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
265 return exist;
266}
267
268//////////////////////////////////////////////////////////////////////////
269//
270// Create polyhedron for visualization
271//
272G4Polyhedron* G4UTrd::CreatePolyhedron() const
273{
274 return new G4PolyhedronTrd2(GetXHalfLength1(),
275 GetXHalfLength2(),
276 GetYHalfLength1(),
277 GetYHalfLength2(),
278 GetZHalfLength());
279}
280
281#endif // G4GEOM_USE_USOLIDS
const G4double kCarTolerance
std::vector< G4ThreeVector > G4ThreeVectorList
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4GLOB_DLL std::ostream G4cout
double z() const
double x() const
double y() const
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...
G4Trd is a trapezoid with the X and Y dimensions varying along Z.
Definition G4Trd.hh:65
G4VPVParameterisation ia an abstract base class for Parameterisation, able to compute the transformat...
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
G4VPhysicalVolume is an abstract base class for the representation of a positioned volume....
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...
EAxis
Definition geomdefs.hh:54