Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
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 //
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  : Base_t(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  : Base_t(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  : Base_t(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  Base_t::operator=(rhs);
96 
97  return *this;
98 }
99 
101 //
102 // Accessors & modifiers
103 
104 G4double G4UTrd::GetXHalfLength1() const
105 {
106  return dx1();
107 }
108 G4double G4UTrd::GetXHalfLength2() const
109 {
110  return dx2();
111 }
112 G4double G4UTrd::GetYHalfLength1() const
113 {
114  return dy1();
115 }
116 G4double G4UTrd::GetYHalfLength2() const
117 {
118  return dy2();
119 }
120 G4double G4UTrd::GetZHalfLength() const
121 {
122  return dz();
123 }
124 
125 void G4UTrd::SetXHalfLength1(G4double val)
126 {
127  Base_t::SetXHalfLength1(val);
128  fRebuildPolyhedron = true;
129 }
130 void G4UTrd::SetXHalfLength2(G4double val)
131 {
132  Base_t::SetXHalfLength2(val);
133  fRebuildPolyhedron = true;
134 }
135 void G4UTrd::SetYHalfLength1(G4double val)
136 {
137  Base_t::SetYHalfLength1(val);
138  fRebuildPolyhedron = true;
139 }
140 void G4UTrd::SetYHalfLength2(G4double val)
141 {
142  Base_t::SetYHalfLength2(val);
143  fRebuildPolyhedron = true;
144 }
145 void G4UTrd::SetZHalfLength(G4double val)
146 {
147  Base_t::SetZHalfLength(val);
148  fRebuildPolyhedron = true;
149 }
150 void G4UTrd::SetAllParameters(G4double pdx1, G4double pdx2,
151  G4double pdy1, G4double pdy2, G4double pdz)
152 {
153  Base_t::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::BoundingLimits(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::BoundingLimits()", "GeomMgt0001",
207  JustWarning, message);
208  StreamInfo(G4cout);
209  }
210 
211  // Check consistency of bounding boxes
212  //
213  if (checkBBox)
214  {
215  U3Vector vmin, vmax;
216  Extent(vmin,vmax);
217  if (std::abs(pMin.x()-vmin.x()) > kCarTolerance ||
218  std::abs(pMin.y()-vmin.y()) > kCarTolerance ||
219  std::abs(pMin.z()-vmin.z()) > kCarTolerance ||
220  std::abs(pMax.x()-vmax.x()) > kCarTolerance ||
221  std::abs(pMax.y()-vmax.y()) > kCarTolerance ||
222  std::abs(pMax.z()-vmax.z()) > kCarTolerance)
223  {
224  std::ostringstream message;
225  message << "Inconsistency in bounding boxes for solid: "
226  << GetName() << " !"
227  << "\nBBox min: wrapper = " << pMin << " solid = " << vmin
228  << "\nBBox max: wrapper = " << pMax << " solid = " << vmax;
229  G4Exception("G4UTrd::BoundingLimits()", "GeomMgt0001",
230  JustWarning, message);
231  checkBBox = false;
232  }
233  }
234 }
235 
237 //
238 // Calculate extent under transform and specified limit
239 
240 G4bool
241 G4UTrd::CalculateExtent(const EAxis pAxis,
242  const G4VoxelLimits& pVoxelLimit,
243  const G4AffineTransform& pTransform,
244  G4double& pMin, G4double& pMax) const
245 {
246  G4ThreeVector bmin, bmax;
247  G4bool exist;
248 
249  // Check bounding box (bbox)
250  //
251  BoundingLimits(bmin,bmax);
252  G4BoundingEnvelope bbox(bmin,bmax);
253 #ifdef G4BBOX_EXTENT
254  if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
255 #endif
256  if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
257  {
258  return exist = (pMin < pMax) ? true : false;
259  }
260 
261  // Set bounding envelope (benv) and calculate extent
262  //
263  G4double dx1 = GetXHalfLength1();
264  G4double dx2 = GetXHalfLength2();
265  G4double dy1 = GetYHalfLength1();
266  G4double dy2 = GetYHalfLength2();
267  G4double dz = GetZHalfLength();
268 
269  G4ThreeVectorList baseA(4), baseB(4);
270  baseA[0].set(-dx1,-dy1,-dz);
271  baseA[1].set( dx1,-dy1,-dz);
272  baseA[2].set( dx1, dy1,-dz);
273  baseA[3].set(-dx1, dy1,-dz);
274  baseB[0].set(-dx2,-dy2, dz);
275  baseB[1].set( dx2,-dy2, dz);
276  baseB[2].set( dx2, dy2, dz);
277  baseB[3].set(-dx2, dy2, dz);
278 
279  std::vector<const G4ThreeVectorList *> polygons(2);
280  polygons[0] = &baseA;
281  polygons[1] = &baseB;
282 
283  G4BoundingEnvelope benv(bmin,bmax,polygons);
284  exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
285  return exist;
286 }
287 
289 //
290 // Create polyhedron for visualization
291 //
292 G4Polyhedron* G4UTrd::CreatePolyhedron() const
293 {
294  return new G4PolyhedronTrd2(GetXHalfLength1(),
295  GetXHalfLength2(),
296  GetYHalfLength1(),
297  GetYHalfLength2(),
298  GetZHalfLength());
299 }
300 
301 #endif // G4GEOM_USE_USOLIDS
void set(double x, double y, double z)
T max(const T t1, const T t2)
brief Return the largest of the two arguments
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
const char * p
Definition: xmltok.h:285
void message(RunManager *runmanager)
Definition: ts_scorers.cc:72
double z() const
const G4double kCarTolerance
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
std::vector< G4ThreeVector > G4ThreeVectorList
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
EAxis
Definition: geomdefs.hh:54
Definition: G4Trd.hh:72
G4GLOB_DLL std::ostream G4cout
double x() const
Char_t n[5]
double y() const