Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Trd.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 G4Trd class
27//
28// 12.01.95 P.Kent: First version
29// 28.04.05 V.Grichine: new SurfaceNormal according to J.Apostolakis proposal
30// 25.05.17 E.Tcherniaev: complete revision, speed-up
31// --------------------------------------------------------------------
32
33#include "G4Trd.hh"
34
35#if !defined(G4GEOM_USE_UTRD)
36
37#include "G4GeomTools.hh"
38
39#include "G4VoxelLimits.hh"
40#include "G4AffineTransform.hh"
41#include "G4BoundingEnvelope.hh"
42#include "G4QuickRand.hh"
43
45
46#include "G4VGraphicsScene.hh"
47#include "G4AutoLock.hh"
48
49using namespace CLHEP;
50
51namespace
52{
54}
55
56//////////////////////////////////////////////////////////////////////////
57//
58// Constructor - set & check half widths
59
61 G4double pdx1, G4double pdx2,
62 G4double pdy1, G4double pdy2,
63 G4double pdz)
64 : G4CSGSolid(pName), halfCarTolerance(0.5*kCarTolerance),
65 fDx1(pdx1), fDx2(pdx2), fDy1(pdy1), fDy2(pdy2), fDz(pdz)
66{
67 CheckParameters();
68 MakePlanes();
69}
70
71//////////////////////////////////////////////////////////////////////////
72//
73// Fake default constructor - sets only member data and allocates memory
74// for usage restricted to object persistency
75//
76G4Trd::G4Trd( __void__& a )
77 : G4CSGSolid(a), halfCarTolerance(0.5*kCarTolerance),
78 fDx1(1.), fDx2(1.), fDy1(1.), fDy2(1.), fDz(1.)
79{
80 MakePlanes();
81}
82
83//////////////////////////////////////////////////////////////////////////
84//
85// Copy constructor
86
88 : G4CSGSolid(rhs), halfCarTolerance(rhs.halfCarTolerance),
89 fDx1(rhs.fDx1), fDx2(rhs.fDx2),
90 fDy1(rhs.fDy1), fDy2(rhs.fDy2), fDz(rhs.fDz),
91 fHx(rhs.fHx), fHy(rhs.fHy)
92{
93 for (G4int i=0; i<4; ++i) { fPlanes[i] = rhs.fPlanes[i]; }
94}
95
96//////////////////////////////////////////////////////////////////////////
97//
98// Assignment operator
99
101{
102 // Check assignment to self
103 //
104 if (this == &rhs) { return *this; }
105
106 // Copy base class data
107 //
109
110 // Copy data
111 //
112 halfCarTolerance = rhs.halfCarTolerance;
113 fDx1 = rhs.fDx1; fDx2 = rhs.fDx2;
114 fDy1 = rhs.fDy1; fDy2 = rhs.fDy2;
115 fDz = rhs.fDz;
116 fHx = rhs.fHx; fHy = rhs.fHy;
117 for (G4int i=0; i<4; ++i) { fPlanes[i] = rhs.fPlanes[i]; }
118
119 return *this;
120}
121
122//////////////////////////////////////////////////////////////////////////
123//
124// Set all parameters, as for constructor - set and check half-widths
125
127 G4double pdy1, G4double pdy2, G4double pdz)
128{
129 // Reset data of the base class
130 fCubicVolume = 0.;
131 fSurfaceArea = 0.;
132 fRebuildPolyhedron = true;
133
134 // Set parameters
135 fDx1 = pdx1; fDx2 = pdx2;
136 fDy1 = pdy1; fDy2 = pdy2;
137 fDz = pdz;
138
139 CheckParameters();
140 MakePlanes();
141}
142
143//////////////////////////////////////////////////////////////////////////
144//
145// Check dimensions
146
147void G4Trd::CheckParameters()
148{
149 G4double dmin = 2*kCarTolerance;
150 if ((fDx1 < 0 || fDx2 < 0 || fDy1 < 0 || fDy2 < 0 || fDz < dmin) ||
151 (fDx1 < dmin && fDx2 < dmin) ||
152 (fDy1 < dmin && fDy2 < dmin))
153 {
154 std::ostringstream message;
155 message << "Invalid (too small or negative) dimensions for Solid: "
156 << GetName()
157 << "\n X - " << fDx1 << ", " << fDx2
158 << "\n Y - " << fDy1 << ", " << fDy2
159 << "\n Z - " << fDz;
160 G4Exception("G4Trd::CheckParameters()", "GeomSolids0002",
161 FatalException, message);
162 }
163}
164
165//////////////////////////////////////////////////////////////////////////
166//
167// Set side planes
168
169void G4Trd::MakePlanes()
170{
171 G4double dx = fDx1 - fDx2;
172 G4double dy = fDy1 - fDy2;
173 G4double dz = 2*fDz;
174 fHx = std::sqrt(dy*dy + dz*dz);
175 fHy = std::sqrt(dx*dx + dz*dz);
176
177 // Set X planes at -Y & +Y
178 //
179 fPlanes[0].a = 0.;
180 fPlanes[0].b = -dz/fHx;
181 fPlanes[0].c = dy/fHx;
182 fPlanes[0].d = fPlanes[0].b*fDy1 + fPlanes[0].c*fDz;
183
184 fPlanes[1].a = fPlanes[0].a;
185 fPlanes[1].b = -fPlanes[0].b;
186 fPlanes[1].c = fPlanes[0].c;
187 fPlanes[1].d = fPlanes[0].d;
188
189 // Set Y planes at -X & +X
190 //
191 fPlanes[2].a = -dz/fHy;
192 fPlanes[2].b = 0.;
193 fPlanes[2].c = dx/fHy;
194 fPlanes[2].d = fPlanes[2].a*fDx1 + fPlanes[2].c*fDz;
195
196 fPlanes[3].a = -fPlanes[2].a;
197 fPlanes[3].b = fPlanes[2].b;
198 fPlanes[3].c = fPlanes[2].c;
199 fPlanes[3].d = fPlanes[2].d;
200}
201
202//////////////////////////////////////////////////////////////////////////
203//
204// Dispatch to parameterisation for replication mechanism dimension
205// computation & modification
206
208 const G4int n,
209 const G4VPhysicalVolume* pRep )
210{
211 p->ComputeDimensions(*this,n,pRep);
212}
213
214//////////////////////////////////////////////////////////////////////////
215//
216// Get bounding box
217
219{
225
226 G4double xmax = std::max(dx1,dx2);
227 G4double ymax = std::max(dy1,dy2);
228 pMin.set(-xmax,-ymax,-dz);
229 pMax.set( xmax, ymax, dz);
230
231 // Check correctness of the bounding box
232 //
233 if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
234 {
235 std::ostringstream message;
236 message << "Bad bounding box (min >= max) for solid: "
237 << GetName() << " !"
238 << "\npMin = " << pMin
239 << "\npMax = " << pMax;
240 G4Exception("G4Trd::BoundingLimits()", "GeomMgt0001", JustWarning, message);
241 DumpInfo();
242 }
243}
244
245//////////////////////////////////////////////////////////////////////////
246//
247// Calculate extent under transform and specified limit
248
250 const G4VoxelLimits& pVoxelLimit,
251 const G4AffineTransform& pTransform,
252 G4double& pMin, G4double& pMax ) const
253{
254 G4ThreeVector bmin, bmax;
255 G4bool exist;
256
257 // Check bounding box (bbox)
258 //
259 BoundingLimits(bmin,bmax);
260 G4BoundingEnvelope bbox(bmin,bmax);
261#ifdef G4BBOX_EXTENT
262 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
263#endif
264 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
265 {
266 return exist = pMin < pMax;
267 }
268
269 // Set bounding envelope (benv) and calculate extent
270 //
276
277 G4ThreeVectorList baseA(4), baseB(4);
278 baseA[0].set(-dx1,-dy1,-dz);
279 baseA[1].set( dx1,-dy1,-dz);
280 baseA[2].set( dx1, dy1,-dz);
281 baseA[3].set(-dx1, dy1,-dz);
282 baseB[0].set(-dx2,-dy2, dz);
283 baseB[1].set( dx2,-dy2, dz);
284 baseB[2].set( dx2, dy2, dz);
285 baseB[3].set(-dx2, dy2, dz);
286
287 std::vector<const G4ThreeVectorList *> polygons(2);
288 polygons[0] = &baseA;
289 polygons[1] = &baseB;
290
291 G4BoundingEnvelope benv(bmin,bmax,polygons);
292 exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
293 return exist;
294}
295
296//////////////////////////////////////////////////////////////////////////
297//
298// Return whether point inside/outside/on surface, using tolerance
299
301{
302 G4double dx = fPlanes[3].a*std::abs(p.x())+fPlanes[3].c*p.z()+fPlanes[3].d;
303 G4double dy = fPlanes[1].b*std::abs(p.y())+fPlanes[1].c*p.z()+fPlanes[1].d;
304 G4double dxy = std::max(dx,dy);
305
306 G4double dz = std::abs(p.z())-fDz;
307 G4double dist = std::max(dz,dxy);
308
309 return (dist > halfCarTolerance) ? kOutside :
310 ((dist > -halfCarTolerance) ? kSurface : kInside);
311}
312
313//////////////////////////////////////////////////////////////////////////
314//
315// Determine side where point is, and return corresponding normal
316
318{
319 G4int nsurf = 0; // number of surfaces where p is placed
320
321 // Check Z faces
322 //
323 G4double nz = 0;
324 G4double dz = std::abs(p.z()) - fDz;
325 if (std::abs(dz) <= halfCarTolerance)
326 {
327 nz = (p.z() < 0) ? -1 : 1;
328 ++nsurf;
329 }
330
331 // Check Y faces
332 //
333 G4double ny = 0;
334 G4double dy1 = fPlanes[0].b*p.y();
335 G4double dy2 = fPlanes[0].c*p.z() + fPlanes[0].d;
336 if (std::abs(dy2 + dy1) <= halfCarTolerance)
337 {
338 ny += fPlanes[0].b;
339 nz += fPlanes[0].c;
340 ++nsurf;
341 }
342 if (std::abs(dy2 - dy1) <= halfCarTolerance)
343 {
344 ny += fPlanes[1].b;
345 nz += fPlanes[1].c;
346 ++nsurf;
347 }
348
349 // Check X faces
350 //
351 G4double nx = 0;
352 G4double dx1 = fPlanes[2].a*p.x();
353 G4double dx2 = fPlanes[2].c*p.z() + fPlanes[2].d;
354 if (std::abs(dx2 + dx1) <= halfCarTolerance)
355 {
356 nx += fPlanes[2].a;
357 nz += fPlanes[2].c;
358 ++nsurf;
359 }
360 if (std::abs(dx2 - dx1) <= halfCarTolerance)
361 {
362 nx += fPlanes[3].a;
363 nz += fPlanes[3].c;
364 ++nsurf;
365 }
366
367 // Return normal
368 //
369 if (nsurf == 1)
370 {
371 return {nx,ny,nz};
372 }
373 if (nsurf != 0)
374 {
375 return G4ThreeVector(nx,ny,nz).unit(); // edge or corner
376 }
377
378 // Point is not on the surface
379 //
380#ifdef G4CSGDEBUG
381 std::ostringstream message;
382 G4long oldprc = message.precision(16);
383 message << "Point p is not on surface (!?) of solid: "
384 << GetName() << G4endl;
385 message << "Position:\n";
386 message << " p.x() = " << p.x()/mm << " mm\n";
387 message << " p.y() = " << p.y()/mm << " mm\n";
388 message << " p.z() = " << p.z()/mm << " mm";
389 G4cout.precision(oldprc) ;
390 G4Exception("G4Trd::SurfaceNormal(p)", "GeomSolids1002",
391 JustWarning, message );
392 DumpInfo();
393#endif
394 return ApproxSurfaceNormal(p);
395}
396
397//////////////////////////////////////////////////////////////////////////
398//
399// Algorithm for SurfaceNormal() following the original specification
400// for points not on the surface
401
402G4ThreeVector G4Trd::ApproxSurfaceNormal( const G4ThreeVector& p ) const
403{
404 G4double dist = -DBL_MAX;
405 G4int iside = 0;
406 for (G4int i=0; i<4; ++i)
407 {
408 G4double d = fPlanes[i].a*p.x() +
409 fPlanes[i].b*p.y() +
410 fPlanes[i].c*p.z() + fPlanes[i].d;
411 if (d > dist) { dist = d; iside = i; }
412 }
413
414 G4double distz = std::abs(p.z()) - fDz;
415 if (dist > distz)
416 {
417 return { fPlanes[iside].a, fPlanes[iside].b, fPlanes[iside].c };
418 }
419
420 return { 0, 0, (G4double)((p.z() < 0) ? -1 : 1) };
421}
422
423//////////////////////////////////////////////////////////////////////////
424//
425// Calculate distance to shape from outside
426// - return kInfinity if no intersection
427
429 const G4ThreeVector& v ) const
430{
431 // Z intersections
432 //
433 if ((std::abs(p.z()) - fDz) >= -halfCarTolerance && p.z()*v.z() >= 0)
434 {
435 return kInfinity;
436 }
437 G4double invz = (-v.z() == 0) ? DBL_MAX : -1./v.z();
438 G4double dz = (invz < 0) ? fDz : -fDz;
439 G4double tzmin = (p.z() + dz)*invz;
440 G4double tzmax = (p.z() - dz)*invz;
441
442 // Y intersections
443 //
444 G4double tmin0 = tzmin, tmax0 = tzmax;
445 G4double ya = fPlanes[0].b*v.y(), yb = fPlanes[0].c*v.z();
446 G4double yc = fPlanes[0].b*p.y(), yd = fPlanes[0].c*p.z()+fPlanes[0].d;
447 G4double cos0 = yb + ya;
448 G4double dis0 = yd + yc;
449 if (dis0 >= -halfCarTolerance)
450 {
451 if (cos0 >= 0) { return kInfinity; }
452 G4double tmp = -dis0/cos0;
453 if (tmin0 < tmp) { tmin0 = tmp; }
454 }
455 else if (cos0 > 0)
456 {
457 G4double tmp = -dis0/cos0;
458 if (tmax0 > tmp) { tmax0 = tmp; }
459 }
460
461 G4double tmin1 = tmin0, tmax1 = tmax0;
462 G4double cos1 = yb - ya;
463 G4double dis1 = yd - yc;
464 if (dis1 >= -halfCarTolerance)
465 {
466 if (cos1 >= 0) { return kInfinity; }
467 G4double tmp = -dis1/cos1;
468 if (tmin1 < tmp) { tmin1 = tmp; }
469 }
470 else if (cos1 > 0)
471 {
472 G4double tmp = -dis1/cos1;
473 if (tmax1 > tmp) { tmax1 = tmp; }
474 }
475
476 // X intersections
477 //
478 G4double tmin2 = tmin1, tmax2 = tmax1;
479 G4double xa = fPlanes[2].a*v.x(), xb = fPlanes[2].c*v.z();
480 G4double xc = fPlanes[2].a*p.x(), xd = fPlanes[2].c*p.z()+fPlanes[2].d;
481 G4double cos2 = xb + xa;
482 G4double dis2 = xd + xc;
483 if (dis2 >= -halfCarTolerance)
484 {
485 if (cos2 >= 0) { return kInfinity; }
486 G4double tmp = -dis2/cos2;
487 if (tmin2 < tmp) { tmin2 = tmp; }
488 }
489 else if (cos2 > 0)
490 {
491 G4double tmp = -dis2/cos2;
492 if (tmax2 > tmp) { tmax2 = tmp; }
493 }
494
495 G4double tmin3 = tmin2, tmax3 = tmax2;
496 G4double cos3 = xb - xa;
497 G4double dis3 = xd - xc;
498 if (dis3 >= -halfCarTolerance)
499 {
500 if (cos3 >= 0) { return kInfinity; }
501 G4double tmp = -dis3/cos3;
502 if (tmin3 < tmp) { tmin3 = tmp; }
503 }
504 else if (cos3 > 0)
505 {
506 G4double tmp = -dis3/cos3;
507 if (tmax3 > tmp) { tmax3 = tmp; }
508 }
509
510 // Find distance
511 //
512 G4double tmin = tmin3, tmax = tmax3;
513 if (tmax <= tmin + halfCarTolerance) { return kInfinity; // touch or no hit
514}
515 return (tmin < halfCarTolerance ) ? 0. : tmin;
516}
517
518//////////////////////////////////////////////////////////////////////////
519//
520// Calculate exact shortest distance to any boundary from outside
521// This is the best fast estimation of the shortest distance to trap
522// - returns 0 if point is inside
523
525{
526 G4double dx = fPlanes[3].a*std::abs(p.x())+fPlanes[3].c*p.z()+fPlanes[3].d;
527 G4double dy = fPlanes[1].b*std::abs(p.y())+fPlanes[1].c*p.z()+fPlanes[1].d;
528 G4double dxy = std::max(dx,dy);
529
530 G4double dz = std::abs(p.z())-fDz;
531 G4double dist = std::max(dz,dxy);
532
533 return (dist > 0) ? dist : 0.;
534}
535
536//////////////////////////////////////////////////////////////////////////
537//
538// Calculate distance to surface of shape from inside and
539// find normal at exit point, if required
540// - when leaving the surface, return 0
541
543 const G4bool calcNorm,
544 G4bool* validNorm, G4ThreeVector* n) const
545{
546 // Z intersections
547 //
548 if ((std::abs(p.z()) - fDz) >= -halfCarTolerance && p.z()*v.z() > 0)
549 {
550 if (calcNorm)
551 {
552 *validNorm = true;
553 n->set(0, 0, (p.z() < 0) ? -1 : 1);
554 }
555 return 0;
556 }
557 G4double vz = v.z();
558 G4double tmax = (vz == 0) ? DBL_MAX : (std::copysign(fDz,vz) - p.z())/vz;
559 G4int iside = (vz < 0) ? -4 : -2; // little trick: (-4+3)=-1, (-2+3)=+1
560
561 // Y intersections
562 //
563 G4int i = 0;
564 for ( ; i<2; ++i)
565 {
566 G4double cosa = fPlanes[i].b*v.y() + fPlanes[i].c*v.z();
567 if (cosa > 0)
568 {
569 G4double dist = fPlanes[i].b*p.y()+fPlanes[i].c*p.z()+fPlanes[i].d;
570 if (dist >= -halfCarTolerance)
571 {
572 if (calcNorm)
573 {
574 *validNorm = true;
575 n->set(0, fPlanes[i].b, fPlanes[i].c);
576 }
577 return 0;
578 }
579 G4double tmp = -dist/cosa;
580 if (tmax > tmp) { tmax = tmp; iside = i; }
581 }
582 }
583
584 // X intersections
585 //
586 for ( ; i<4; ++i)
587 {
588 G4double cosa = fPlanes[i].a*v.x()+fPlanes[i].c*v.z();
589 if (cosa > 0)
590 {
591 G4double dist = fPlanes[i].a*p.x()+fPlanes[i].c*p.z()+fPlanes[i].d;
592 if (dist >= -halfCarTolerance)
593 {
594 if (calcNorm)
595 {
596 *validNorm = true;
597 n->set(fPlanes[i].a, fPlanes[i].b, fPlanes[i].c);
598 }
599 return 0;
600 }
601 G4double tmp = -dist/cosa;
602 if (tmax > tmp) { tmax = tmp; iside = i; }
603 }
604 }
605
606 // Set normal, if required, and return distance
607 //
608 if (calcNorm)
609 {
610 *validNorm = true;
611 if (iside < 0)
612 {
613 n->set(0, 0, iside + 3); // (-4+3)=-1, (-2+3)=+1
614 }
615 else
616 {
617 n->set(fPlanes[iside].a, fPlanes[iside].b, fPlanes[iside].c);
618 }
619 }
620 return tmax;
621}
622
623//////////////////////////////////////////////////////////////////////////
624//
625// Calculate exact shortest distance to any boundary from inside
626// - returns 0 if point is outside
627
629{
630#ifdef G4CSGDEBUG
631 if( Inside(p) == kOutside )
632 {
633 std::ostringstream message;
634 G4long oldprc = message.precision(16);
635 message << "Point p is outside (!?) of solid: " << GetName() << G4endl;
636 message << "Position:\n";
637 message << " p.x() = " << p.x()/mm << " mm\n";
638 message << " p.y() = " << p.y()/mm << " mm\n";
639 message << " p.z() = " << p.z()/mm << " mm";
640 G4cout.precision(oldprc);
641 G4Exception("G4Trd::DistanceToOut(p)", "GeomSolids1002",
642 JustWarning, message );
643 DumpInfo();
644 }
645#endif
646 G4double dx = fPlanes[3].a*std::abs(p.x())+fPlanes[3].c*p.z()+fPlanes[3].d;
647 G4double dy = fPlanes[1].b*std::abs(p.y())+fPlanes[1].c*p.z()+fPlanes[1].d;
648 G4double dxy = std::max(dx,dy);
649
650 G4double dz = std::abs(p.z())-fDz;
651 G4double dist = std::max(dz,dxy);
652
653 return (dist < 0) ? -dist : 0.;
654}
655
656//////////////////////////////////////////////////////////////////////////
657//
658// GetEntityType
659
661{
662 return {"G4Trd"};
663}
664
665//////////////////////////////////////////////////////////////////////////
666//
667// IsFaceted
668
670{
671 return true;
672}
673
674//////////////////////////////////////////////////////////////////////////
675//
676// Make a clone of the object
677//
679{
680 return new G4Trd(*this);
681}
682
683//////////////////////////////////////////////////////////////////////////
684//
685// Stream object contents to an output stream
686
687std::ostream& G4Trd::StreamInfo( std::ostream& os ) const
688{
689 G4long oldprc = os.precision(16);
690 os << "-----------------------------------------------------------\n"
691 << " *** Dump for solid - " << GetName() << " ***\n"
692 << " ===================================================\n"
693 << " Solid type: G4Trd\n"
694 << " Parameters: \n"
695 << " half length X, surface -dZ: " << fDx1/mm << " mm \n"
696 << " half length X, surface +dZ: " << fDx2/mm << " mm \n"
697 << " half length Y, surface -dZ: " << fDy1/mm << " mm \n"
698 << " half length Y, surface +dZ: " << fDy2/mm << " mm \n"
699 << " half length Z : " << fDz/mm << " mm \n"
700 << "-----------------------------------------------------------\n";
701 os.precision(oldprc);
702
703 return os;
704}
705
706//////////////////////////////////////////////////////////////////////////
707//
708// Return a point randomly and uniformly selected on the solid surface
709
711{
712 G4double sbot = 4.*fDx1*fDy1; // area of bottom base
713 G4double stop = 4.*fDx2*fDy2; // area of top base
714 G4double sbase = sbot + stop;
715 G4double sxz = (fDx1 + fDx2)*fHx; // area of Y face
716 G4double syz = (fDy1 + fDy2)*fHy; // area of X face
717 G4double stotal = sbase + 2.*(sxz + syz);
718 G4double select = stotal*G4QuickRand();
719
721 G4double u = G4QuickRand();
722 G4double v = G4QuickRand();
723 if (select < sbase)
724 {
725 G4bool ifbottom = (select < sbot);
726 G4double x = (ifbottom) ? fDx1 : fDx2;
727 G4double y = (ifbottom) ? fDy1 : fDy2;
728 G4double z = (ifbottom) ? -fDz : fDz;
729 p.set((2.*u - 1.)*x, (2.*v - 1.)*y, z);
730 }
731 else if (select < sbase + 2.*sxz)
732 {
733 G4double ysign = (select < sbase + sxz) ? 1. : -1.;
734 if (ysign < 0.) { select -= sxz; }
735 if (u + v > 1.)
736 {
737 u = 1. - u;
738 v = 1. - v;
739 }
740 G4ThreeVector p0(-fDx1,-fDy1,-fDz);
741 G4ThreeVector p1( fDx2,-fDy2, fDz);
742 G4ThreeVector p2 = (select < sbase + fDx1*fHx) ?
743 G4ThreeVector( fDx1,-fDy1,-fDz) : G4ThreeVector(-fDx2,-fDy2, fDz);
744 p = p0*(1. - u - v) + p1*u + p2*v;
745 p.setY(ysign*p.y());
746 }
747 else
748 {
749 G4double xsign = (select < sbase + 2.*sxz + syz) ? 1. : -1.;
750 if (xsign < 0.) { select -= syz; }
751 if (u + v > 1.)
752 {
753 u = 1. - u;
754 v = 1. - v;
755 }
756 G4ThreeVector p0(-fDx1, fDy1,-fDz);
757 G4ThreeVector p1(-fDx2,-fDy2, fDz);
758 G4ThreeVector p2 = (select < sbase + 2.*sxz + fDy1*fHy) ?
759 G4ThreeVector(-fDx1,-fDy1,-fDz) : G4ThreeVector(-fDx2, fDy2, fDz);
760 p = p0*(1. - u - v) + p1*u + p2*v;
761 p.setX(xsign*p.x());
762 }
763 return p;
764}
765
766//////////////////////////////////////////////////////////////////////////
767//
768// Get volume
769
771{
772 if (fCubicVolume == 0)
773 {
774 G4AutoLock l(&trdMutex);
775 fCubicVolume = 2*fDz*((fDx1+fDx2)*(fDy1+fDy2) + (fDx2-fDx1)*(fDy2-fDy1)/3);
776 l.unlock();
777 }
778 return fCubicVolume;
779}
780
781//////////////////////////////////////////////////////////////////////////
782//
783// Get surface area
784
786{
787 if (fSurfaceArea == 0)
788 {
789 G4AutoLock l(&trdMutex);
790 fSurfaceArea = 4*(fDx1*fDy1+fDx2*fDy2)+2*(fDx1+fDx2)*fHx+2*(fDy1+fDy2)*fHy;
791 l.unlock();
792 }
793 return fSurfaceArea;
794}
795
796//////////////////////////////////////////////////////////////////////////
797//
798// Methods for visualisation
799
801{
802 scene.AddSolid (*this);
803}
804
806{
807 return new G4PolyhedronTrd2 (fDx1, fDx2, fDy1, fDy2, fDz);
808}
809
810#endif
G4TemplateAutoLock< G4Mutex > G4AutoLock
const G4double kCarTolerance
std::vector< G4ThreeVector > G4ThreeVectorList
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4double G4QuickRand(uint32_t seed=0)
#define G4MUTEX_INITIALIZER
std::mutex G4Mutex
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
long G4long
Definition G4Types.hh:87
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4String G4GeometryType
Definition G4VSolid.hh:70
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
double z() const
Hep3Vector unit() const
double x() const
void setY(double)
double y() const
void set(double x, double y, double z)
void setX(double)
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...
G4bool BoundingBoxVsVoxelLimits(const EAxis pAxis, const G4VoxelLimits &pVoxelLimits, const G4Transform3D &pTransform3D, G4double &pMin, G4double &pMax) const
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimits, const G4Transform3D &pTransform3D, G4double &pMin, G4double &pMax) const
G4double fSurfaceArea
Definition G4CSGSolid.hh:93
G4double fCubicVolume
Definition G4CSGSolid.hh:92
G4bool fRebuildPolyhedron
Definition G4CSGSolid.hh:94
G4CSGSolid(const G4String &pName)
Definition G4CSGSolid.cc:49
G4CSGSolid & operator=(const G4CSGSolid &rhs)
Definition G4CSGSolid.cc:89
void SetAllParameters(G4double pdx1, G4double pdx2, G4double pdy1, G4double pdy2, G4double pdz)
Definition G4Trd.cc:126
G4double GetXHalfLength2() const
std::ostream & StreamInfo(std::ostream &os) const override
Definition G4Trd.cc:687
G4Trd(const G4String &pName, G4double pdx1, G4double pdx2, G4double pdy1, G4double pdy2, G4double pdz)
Definition G4Trd.cc:60
G4double GetSurfaceArea() override
Definition G4Trd.cc:785
G4double b
Definition G4Trd.hh:233
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const override
Definition G4Trd.cc:249
void DescribeYourselfTo(G4VGraphicsScene &scene) const override
Definition G4Trd.cc:800
EInside Inside(const G4ThreeVector &p) const override
Definition G4Trd.cc:300
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const override
Definition G4Trd.cc:218
G4Trd & operator=(const G4Trd &rhs)
Definition G4Trd.cc:100
G4double GetYHalfLength2() const
G4double a
Definition G4Trd.hh:233
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const override
Definition G4Trd.cc:428
G4Polyhedron * CreatePolyhedron() const override
Definition G4Trd.cc:805
G4double GetXHalfLength1() const
G4double c
Definition G4Trd.hh:233
G4double d
Definition G4Trd.hh:233
G4ThreeVector GetPointOnSurface() const override
Definition G4Trd.cc:710
G4double GetYHalfLength1() const
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const override
Definition G4Trd.cc:542
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const override
Definition G4Trd.cc:317
G4bool IsFaceted() const override
Definition G4Trd.cc:669
G4double GetCubicVolume() override
Definition G4Trd.cc:770
G4GeometryType GetEntityType() const override
Definition G4Trd.cc:660
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep) override
Definition G4Trd.cc:207
G4double GetZHalfLength() const
G4VSolid * Clone() const override
Definition G4Trd.cc:678
virtual void AddSolid(const G4Box &)=0
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....
G4String GetName() const
G4VSolid(const G4String &name)
Definition G4VSolid.cc:59
void DumpInfo() const
G4double kCarTolerance
Definition G4VSolid.hh:418
G4VoxelLimits represents limitation/restrictions of space, where restrictions are only made perpendic...
EAxis
Definition geomdefs.hh:54
EInside
Definition geomdefs.hh:67
@ kInside
Definition geomdefs.hh:70
@ kOutside
Definition geomdefs.hh:68
@ kSurface
Definition geomdefs.hh:69
#define DBL_MAX
Definition templates.hh:62