ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UTrd.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4UTrd.cc
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/PH
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"
37 #include "G4VPVParameterisation.hh"
38 #include "G4BoundingEnvelope.hh"
39 
40 using namespace CLHEP;
41 
43 //
44 // Constructor - check & set half widths
45 //
46 G4UTrd::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 
55 //
56 // Fake default constructor - sets only member data and allocates memory
57 // for usage restricted to object persistency.
58 //
59 G4UTrd::G4UTrd( __void__& a )
60  : Base_t(a)
61 {
62 }
63 
65 //
66 // Destructor
67 //
68 G4UTrd::~G4UTrd()
69 {
70 }
71 
73 //
74 // Copy constructor
75 //
76 G4UTrd::G4UTrd(const G4UTrd& rhs)
77  : Base_t(rhs)
78 {
79 }
80 
82 //
83 // Assignment operator
84 //
85 G4UTrd& G4UTrd::operator = (const G4UTrd& rhs)
86 {
87  // Check assignment to self
88  //
89  if (this == &rhs) { return *this; }
90 
91  // Copy base class data
92  //
93  Base_t::operator=(rhs);
94 
95  return *this;
96 }
97 
99 //
100 // Accessors & modifiers
101 
102 G4double G4UTrd::GetXHalfLength1() const
103 {
104  return dx1();
105 }
106 G4double G4UTrd::GetXHalfLength2() const
107 {
108  return dx2();
109 }
110 G4double G4UTrd::GetYHalfLength1() const
111 {
112  return dy1();
113 }
114 G4double G4UTrd::GetYHalfLength2() const
115 {
116  return dy2();
117 }
118 G4double G4UTrd::GetZHalfLength() const
119 {
120  return dz();
121 }
122 
123 void G4UTrd::SetXHalfLength1(G4double val)
124 {
125  Base_t::SetXHalfLength1(val);
126  fRebuildPolyhedron = true;
127 }
128 void G4UTrd::SetXHalfLength2(G4double val)
129 {
130  Base_t::SetXHalfLength2(val);
131  fRebuildPolyhedron = true;
132 }
133 void G4UTrd::SetYHalfLength1(G4double val)
134 {
135  Base_t::SetYHalfLength1(val);
136  fRebuildPolyhedron = true;
137 }
138 void G4UTrd::SetYHalfLength2(G4double val)
139 {
140  Base_t::SetYHalfLength2(val);
141  fRebuildPolyhedron = true;
142 }
143 void G4UTrd::SetZHalfLength(G4double val)
144 {
145  Base_t::SetZHalfLength(val);
146  fRebuildPolyhedron = true;
147 }
148 void G4UTrd::SetAllParameters(G4double pdx1, G4double pdx2,
149  G4double pdy1, G4double pdy2, G4double pdz)
150 {
151  Base_t::SetAllParameters(pdx1, pdx2, pdy1, pdy2, pdz);
152  fRebuildPolyhedron = true;
153 }
154 
156 //
157 // Dispatch to parameterisation for replication mechanism dimension
158 // computation & modification.
159 //
160 void G4UTrd::ComputeDimensions( G4VPVParameterisation* p,
161  const G4int n,
162  const G4VPhysicalVolume* pRep)
163 {
164  p->ComputeDimensions(*(G4Trd*)this,n,pRep);
165 }
166 
168 //
169 // Make a clone of the object
170 
171 G4VSolid* G4UTrd::Clone() const
172 {
173  return new G4UTrd(*this);
174 }
175 
177 //
178 // Get bounding box
179 
180 void G4UTrd::BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const
181 {
182  static G4bool checkBBox = true;
183 
184  G4double dx1 = GetXHalfLength1();
185  G4double dx2 = GetXHalfLength2();
186  G4double dy1 = GetYHalfLength1();
187  G4double dy2 = GetYHalfLength2();
188  G4double dz = GetZHalfLength();
189 
190  G4double xmax = std::max(dx1,dx2);
191  G4double ymax = std::max(dy1,dy2);
192  pMin.set(-xmax,-ymax,-dz);
193  pMax.set( xmax, ymax, dz);
194 
195  // Check correctness of the bounding box
196  //
197  if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
198  {
199  std::ostringstream message;
200  message << "Bad bounding box (min >= max) for solid: "
201  << GetName() << " !"
202  << "\npMin = " << pMin
203  << "\npMax = " << pMax;
204  G4Exception("G4UTrd::BoundingLimits()", "GeomMgt0001",
205  JustWarning, message);
206  StreamInfo(G4cout);
207  }
208 
209  // Check consistency of bounding boxes
210  //
211  if (checkBBox)
212  {
213  U3Vector vmin, vmax;
214  Extent(vmin,vmax);
215  if (std::abs(pMin.x()-vmin.x()) > kCarTolerance ||
216  std::abs(pMin.y()-vmin.y()) > kCarTolerance ||
217  std::abs(pMin.z()-vmin.z()) > kCarTolerance ||
218  std::abs(pMax.x()-vmax.x()) > kCarTolerance ||
219  std::abs(pMax.y()-vmax.y()) > kCarTolerance ||
220  std::abs(pMax.z()-vmax.z()) > kCarTolerance)
221  {
222  std::ostringstream message;
223  message << "Inconsistency in bounding boxes for solid: "
224  << GetName() << " !"
225  << "\nBBox min: wrapper = " << pMin << " solid = " << vmin
226  << "\nBBox max: wrapper = " << pMax << " solid = " << vmax;
227  G4Exception("G4UTrd::BoundingLimits()", "GeomMgt0001",
228  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  BoundingLimits(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