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