Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4EllipticalTube.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// G4EllipticalTube implementation
27//
28// Author: David C. Williams (UCSC), 29.03.2000 - First implementation
29// Evgueni Tcherniaev (CERN), 23.12.2019 - Revised
30// --------------------------------------------------------------------
31
32#include "G4EllipticalTube.hh"
33
34#if !(defined(G4GEOM_USE_UELLIPTICALTUBE) && defined(G4GEOM_USE_SYS_USOLIDS))
35
36#include "G4GeomTools.hh"
37#include "G4AffineTransform.hh"
38#include "G4VoxelLimits.hh"
39#include "G4BoundingEnvelope.hh"
40#include "G4QuickRand.hh"
41
42#include "G4VGraphicsScene.hh"
43#include "G4VisExtent.hh"
44
45#include "G4AutoLock.hh"
46
47namespace
48{
49 G4Mutex polyhedronMutex = G4MUTEX_INITIALIZER;
50 G4Mutex eltubeMutex = G4MUTEX_INITIALIZER;
51}
52
53using namespace CLHEP;
54
55//////////////////////////////////////////////////////////////////////////
56//
57// Constructor
58
60 G4double Dx,
61 G4double Dy,
62 G4double Dz )
63 : G4VSolid(name), fDx(Dx), fDy(Dy), fDz(Dz)
64{
65 CheckParameters();
66 fSurfaceArea = GetCachedSurfaceArea();
67}
68
69//////////////////////////////////////////////////////////////////////////
70//
71// Fake default constructor - sets only member data and allocates memory
72// for usage restricted to object persistency.
73
75 : G4VSolid(a), halfTolerance(0.), fDx(0.), fDy(0.), fDz(0.),
76 fRsph(0.), fDDx(0.), fDDy(0.), fSx(0.), fSy(0.), fR(0.),
77 fQ1(0.), fQ2(0.), fScratch(0.)
78{
79}
80
81//////////////////////////////////////////////////////////////////////////
82//
83// Destructor
84
86{
87 delete fpPolyhedron; fpPolyhedron = nullptr;
88}
89
90//////////////////////////////////////////////////////////////////////////
91//
92// Copy constructor
93
95 : G4VSolid(rhs), halfTolerance(rhs.halfTolerance),
96 fDx(rhs.fDx), fDy(rhs.fDy), fDz(rhs.fDz),
97 fCubicVolume(rhs.fCubicVolume), fSurfaceArea(rhs.fSurfaceArea),
98 fRsph(rhs.fRsph), fDDx(rhs.fDDx), fDDy(rhs.fDDy),
99 fSx(rhs.fSx), fSy(rhs.fSy), fR(rhs.fR),
100 fQ1(rhs.fQ1), fQ2(rhs.fQ2), fScratch(rhs.fScratch)
101{
102}
103
104//////////////////////////////////////////////////////////////////////////
105//
106// Assignment operator
107
109{
110 // Check assignment to self
111 //
112 if (this == &rhs) { return *this; }
113
114 // Copy base class data
115 //
117
118 // Copy data
119 //
120 halfTolerance = rhs.halfTolerance;
121 fDx = rhs.fDx;
122 fDy = rhs.fDy;
123 fDz = rhs.fDz;
124 fCubicVolume = rhs.fCubicVolume;
125 fSurfaceArea = rhs.fSurfaceArea;
126
127 fRsph = rhs.fRsph;
128 fDDx = rhs.fDDx;
129 fDDy = rhs.fDDy;
130 fSx = rhs.fSx;
131 fSy = rhs.fSy;
132 fR = rhs.fR;
133 fQ1 = rhs.fQ1;
134 fQ2 = rhs.fQ2;
135 fScratch = rhs.fScratch;
136
137 fRebuildPolyhedron = false;
138 delete fpPolyhedron; fpPolyhedron = nullptr;
139
140 return *this;
141}
142
143//////////////////////////////////////////////////////////////////////////
144//
145// Check dimensions
146
147void G4EllipticalTube::CheckParameters()
148{
149 // Check dimensions
150 //
151 halfTolerance = 0.5*kCarTolerance; // half tolerance
152 G4double dmin = 2*kCarTolerance;
153 if (fDx < dmin || fDy < dmin || fDz < dmin)
154 {
155 std::ostringstream message;
156 message << "Invalid (too small or negative) dimensions for Solid: "
157 << GetName()
158 << "\n Dx = " << fDx
159 << "\n Dy = " << fDy
160 << "\n Dz = " << fDz;
161 G4Exception("G4EllipticalTube::CheckParameters()", "GeomSolids0002",
162 FatalException, message);
163 }
164
165 // Set pre-calculatated values
166 //
167 halfTolerance = 0.5*kCarTolerance; // half tolerance
168 fRsph = std::sqrt(fDx * fDx + fDy * fDy + fDz * fDz); // radius of surrounding sphere
169 fDDx = fDx * fDx; // X semi-axis squared
170 fDDy = fDy * fDy; // Y semi-axis squared
171
172 fR = std::min(fDx, fDy); // resulting radius, after scaling elipse to circle
173 fSx = fR / fDx; // X scale factor
174 fSy = fR / fDy; // Y scale factor
175
176 fQ1 = 0.5 / fR; // distance approxiamtion dist = Q1 * (x^2 + y^2) - Q2
177 fQ2 = 0.5 * (fR + halfTolerance * halfTolerance / fR);
178 fScratch = 2. * fR * fR * DBL_EPSILON; // scratch within calculation error thickness
179 // fScratch = (B * B / A) * (2. + halfTolerance / A) * halfTolerance; // alternative
180}
181
182//////////////////////////////////////////////////////////////////////////
183//
184// Get bounding box
185
187 G4ThreeVector& pMax ) const
188{
189 pMin.set(-fDx,-fDy,-fDz);
190 pMax.set( fDx, fDy, fDz);
191}
192
193//////////////////////////////////////////////////////////////////////////
194//
195// Calculate extent under transform and specified limit
196
197G4bool
199 const G4VoxelLimits& pVoxelLimit,
200 const G4AffineTransform& pTransform,
201 G4double& pMin, G4double& pMax ) const
202{
203 G4ThreeVector bmin, bmax;
204 G4bool exist;
205
206 // Check bounding box (bbox)
207 //
208 BoundingLimits(bmin,bmax);
209 G4BoundingEnvelope bbox(bmin,bmax);
210#ifdef G4BBOX_EXTENT
211 return bbox.CalculateExtent(pAxis,pVoxelLimit, pTransform, pMin, pMax);
212#endif
213 if (bbox.BoundingBoxVsVoxelLimits(pAxis, pVoxelLimit, pTransform, pMin, pMax))
214 {
215 return exist = pMin < pMax;
216 }
217
218 G4double dx = fDx;
219 G4double dy = fDy;
220 G4double dz = fDz;
221
222 // Set bounding envelope (benv) and calculate extent
223 //
224 const G4int NSTEPS = 24; // number of steps for whole circle
225 G4double ang = twopi/NSTEPS;
226
227 G4double sinHalf = std::sin(0.5*ang);
228 G4double cosHalf = std::cos(0.5*ang);
229 G4double sinStep = 2.*sinHalf*cosHalf;
230 G4double cosStep = 1. - 2.*sinHalf*sinHalf;
231 G4double sx = dx/cosHalf;
232 G4double sy = dy/cosHalf;
233
234 G4double sinCur = sinHalf;
235 G4double cosCur = cosHalf;
236 G4ThreeVectorList baseA(NSTEPS),baseB(NSTEPS);
237 for (G4int k=0; k<NSTEPS; ++k)
238 {
239 baseA[k].set(sx*cosCur,sy*sinCur,-dz);
240 baseB[k].set(sx*cosCur,sy*sinCur, dz);
241
242 G4double sinTmp = sinCur;
243 sinCur = sinCur*cosStep + cosCur*sinStep;
244 cosCur = cosCur*cosStep - sinTmp*sinStep;
245 }
246
247 std::vector<const G4ThreeVectorList *> polygons(2);
248 polygons[0] = &baseA;
249 polygons[1] = &baseB;
250 G4BoundingEnvelope benv(bmin, bmax, polygons);
251 exist = benv.CalculateExtent(pAxis, pVoxelLimit, pTransform, pMin, pMax);
252 return exist;
253}
254
255//////////////////////////////////////////////////////////////////////////
256//
257// Determine where is point: inside, outside or on surface
258//
259
261{
262 G4double x = p.x() * fSx;
263 G4double y = p.y() * fSy;
264 G4double distR = fQ1 * (x * x + y * y) - fQ2;
265 G4double distZ = std::abs(p.z()) - fDz;
266 G4double dist = std::max(distR, distZ);
267
268 if (dist > halfTolerance) { return kOutside; }
269 return (dist > -halfTolerance) ? kSurface : kInside;
270}
271
272//////////////////////////////////////////////////////////////////////////
273//
274// Return unit normal at surface closest to p
275
277{
278 G4ThreeVector norm(0, 0, 0);
279 G4int nsurf = 0;
280
281 // check lateral surface
282 G4double x = p.x() * fSx;
283 G4double y = p.y() * fSy;
284 G4double distR = fQ1 * (x * x + y * y) - fQ2;
285 if (std::abs(distR) <= halfTolerance)
286 {
287 norm = G4ThreeVector(p.x() * fDDy, p.y() * fDDx, 0.).unit();
288 ++nsurf;
289 }
290
291 // check lateral bases
292 G4double distZ = std::abs(p.z()) - fDz;
293 if (std::abs(distZ) <= halfTolerance)
294 {
295 norm.setZ(p.z() < 0 ? -1. : 1.);
296 ++nsurf;
297 }
298
299 // return normal
300 if (nsurf == 1)
301 {
302 return norm;
303 }
304 if (nsurf > 1)
305 {
306 return norm.unit(); // edge
307 }
308
309 // Point is not on the surface
310 //
311#ifdef G4SPECDEBUG
312 std::ostringstream message;
313 G4long oldprc = message.precision(16);
314 message << "Point p is not on surface (!?) of solid: "
315 << GetName() << G4endl;
316 message << "Position:\n";
317 message << " p.x() = " << p.x()/mm << " mm\n";
318 message << " p.y() = " << p.y()/mm << " mm\n";
319 message << " p.z() = " << p.z()/mm << " mm";
320 G4cout.precision(oldprc);
321 G4Exception("G4EllipticalTube::SurfaceNormal(p)", "GeomSolids1002",
322 JustWarning, message );
323 DumpInfo();
324#endif
325 return ApproxSurfaceNormal(p);
326}
327
328//////////////////////////////////////////////////////////////////////////
329//
330// Find surface nearest to point and return corresponding normal.
331// The algorithm is similar to the algorithm used in Inside().
332// This method normally should not be called.
333
335G4EllipticalTube::ApproxSurfaceNormal( const G4ThreeVector& p ) const
336{
337 G4double x = p.x() * fSx;
338 G4double y = p.y() * fSy;
339 G4double distR = fQ1 * (x * x + y * y) - fQ2;
340 G4double distZ = std::abs(p.z()) - fDz;
341 if (distR > distZ && (x * x + y * y) > 0)
342 {
343 return G4ThreeVector(p.x() * fDDy, p.y() * fDDx, 0.).unit();
344 }
345 return {0, 0, (p.z() < 0 ? -1. : 1.)};
346}
347
348//////////////////////////////////////////////////////////////////////////
349//
350// Calculate distance to shape from outside, along normalised vector,
351// return kInfinity if no intersection, or distance < halfTolerance
352
354 const G4ThreeVector& v ) const
355{
356 G4double offset = 0.;
357 G4ThreeVector pcur = p;
358
359 // Check if point is flying away
360 //
361 G4double safex = std::abs(pcur.x()) - fDx;
362 G4double safey = std::abs(pcur.y()) - fDy;
363 G4double safez = std::abs(pcur.z()) - fDz;
364
365 if (safez >= -halfTolerance && pcur.z() * v.z() >= 0.) { return kInfinity; }
366 if (safey >= -halfTolerance && pcur.y() * v.y() >= 0.) { return kInfinity; }
367 if (safex >= -halfTolerance && pcur.x() * v.x() >= 0.) { return kInfinity; }
368
369 // Relocate point, if required
370 //
371 G4double Dmax = 32. * fRsph;
372 if (std::max(std::max(safex, safey), safez) > Dmax)
373 {
374 offset = (1. - 1.e-08) * pcur.mag() - 2. * fRsph;
375 pcur += offset * v;
376 G4double dist = DistanceToIn(pcur, v);
377 return (dist == kInfinity) ? kInfinity : dist + offset;
378 }
379
380 // Scale elliptical tube to cylinder
381 //
382 G4double px = pcur.x() * fSx;
383 G4double py = pcur.y() * fSy;
384 G4double pz = pcur.z();
385 G4double vx = v.x() * fSx;
386 G4double vy = v.y() * fSy;
387 G4double vz = v.z();
388
389 // Set coefficients of quadratic equation: A t^2 + 2B t + C = 0
390 //
391 G4double rr = px * px + py * py;
392 G4double A = vx * vx + vy * vy;
393 G4double B = px * vx + py * vy;
394 G4double C = rr - fR * fR;
395 G4double D = B * B - A * C;
396
397 // Check if point is flying away relative to lateral surface
398 //
399 G4double distR = fQ1 * rr - fQ2;
400 G4bool parallelToZ = (A < DBL_EPSILON || std::abs(vz) >= 1.);
401 if (distR >= -halfTolerance && (B >= 0. || parallelToZ)) { return kInfinity; }
402
403 // Find intersection with Z planes
404 //
405 G4double invz = (vz == 0) ? DBL_MAX : -1./vz;
406 G4double dz = std::copysign(fDz, invz);
407 G4double tzmin = (pz - dz) * invz;
408 G4double tzmax = (pz + dz) * invz;
409
410 // Solve qudratic equation. There are two cases special where D <= 0:
411 // 1) trajectory parallel to Z axis (A = 0, B = 0, C - any, D = 0)
412 // 2) touch (D = 0) or no intersection (D < 0) with lateral surface
413 //
414 if (parallelToZ)
415 {
416 return (tzmin<halfTolerance) ? offset : tzmin + offset; // 1)
417 }
418 if (D <= A * A * fScratch) { return kInfinity; } // 2)
419
420 // Find roots of quadratic equation
421 G4double tmp = -B - std::copysign(std::sqrt(D), B);
422 G4double t1 = tmp / A;
423 G4double t2 = C / tmp;
424 G4double trmin = std::min(t1, t2);
425 G4double trmax = std::max(t1, t2);
426
427 // Return distance
428 G4double tin = std::max(tzmin, trmin);
429 G4double tout = std::min(tzmax, trmax);
430
431 if (tout <= tin + halfTolerance) { return kInfinity; } // touch or no hit
432
433 return (tin<halfTolerance) ? offset : tin + offset;
434}
435
436//////////////////////////////////////////////////////////////////////////
437//
438// Estimate distance to the surface from outside,
439// returns 0 if point is inside
440
442{
443 // safety distance to bounding box
444 G4double distX = std::abs(p.x()) - fDx;
445 G4double distY = std::abs(p.y()) - fDy;
446 G4double distZ = std::abs(p.z()) - fDz;
447 G4double distB = std::max(std::max(distX, distY), distZ);
448 // return (distB < 0) ? 0 : distB;
449
450 // safety distance to lateral surface
451 G4double x = p.x() * fSx;
452 G4double y = p.y() * fSy;
453 G4double distR = std::sqrt(x * x + y * y) - fR;
454
455 // return SafetyToIn
456 G4double dist = std::max(distB, distR);
457 return (dist < 0) ? 0 : dist;
458}
459
460//////////////////////////////////////////////////////////////////////////
461//
462// Calculate distance to shape from inside and find normal
463// at exit point, if required
464// - when leaving the surface, return 0
465
467 const G4ThreeVector& v,
468 const G4bool calcNorm,
469 G4bool* validNorm,
470 G4ThreeVector* n ) const
471{
472 // Check if point flying away relative to Z planes
473 //
474 G4double pz = p.z();
475 G4double vz = v.z();
476 G4double distZ = std::abs(pz) - fDz;
477 if (distZ >= -halfTolerance && pz * vz > 0)
478 {
479 if (calcNorm)
480 {
481 *validNorm = true;
482 n->set(0, 0, (pz < 0) ? -1. : 1.);
483 }
484 return 0.;
485 }
486 G4double tzmax = (vz == 0) ? DBL_MAX : (std::copysign(fDz, vz) - pz) / vz;
487
488 // Scale elliptical tube to cylinder
489 //
490 G4double px = p.x() * fSx;
491 G4double py = p.y() * fSy;
492 G4double vx = v.x() * fSx;
493 G4double vy = v.y() * fSy;
494
495 // Check if point is flying away relative to lateral surface
496 //
497 G4double rr = px * px + py * py;
498 G4double B = px * vx + py * vy;
499 G4double distR = fQ1 * rr - fQ2;
500 if (distR >= -halfTolerance && B > 0.)
501 {
502 if (calcNorm)
503 {
504 *validNorm = true;
505 *n = G4ThreeVector(px * fDDy, py * fDDx, 0.).unit();
506 }
507 return 0.;
508 }
509
510 // Just in case check if point is outside, normally it should never be
511 //
512 if (std::max(distZ, distR) > halfTolerance)
513 {
514#ifdef G4SPECDEBUG
515 std::ostringstream message;
516 G4long oldprc = message.precision(16);
517 message << "Point p is outside (!?) of solid: "
518 << GetName() << G4endl;
519 message << "Position: " << p << G4endl;;
520 message << "Direction: " << v;
521 G4cout.precision(oldprc);
522 G4Exception("G4EllipticalTube::DistanceToOut(p,v)", "GeomSolids1002",
523 JustWarning, message );
524 DumpInfo();
525#endif
526 if (calcNorm)
527 {
528 *validNorm = true;
529 *n = ApproxSurfaceNormal(p);
530 }
531 return 0.;
532 }
533
534 // Set coefficients of quadratic equation: A t^2 + 2B t + C = 0
535 //
536 G4double A = vx * vx + vy * vy;
537 G4double C = rr - fR * fR;
538 G4double D = B * B - A * C;
539
540 // Solve qudratic equation. There are two special cases where D <= 0:
541 // 1) trajectory parallel to Z axis (A = 0, B = 0, C - any, D = 0)
542 // 2) touch (D = 0) or no intersection (D < 0) with lateral surface
543 //
544 G4bool parallelToZ = (A < DBL_EPSILON || std::abs(vz) >= 1.);
545 if (parallelToZ) // 1)
546 {
547 if (calcNorm)
548 {
549 *validNorm = true;
550 n->set(0, 0, (vz < 0) ? -1. : 1.);
551 }
552 return tzmax;
553 }
554 if (D <= A * A * fScratch) // 2)
555 {
556 if (calcNorm)
557 {
558 *validNorm = true;
559 *n = G4ThreeVector(px * fDDy, py * fDDx, 0.).unit();
560 }
561 return 0.;
562 }
563
564 // Find roots of quadratic equation
565 G4double tmp = -B - std::copysign(std::sqrt(D), B);
566 G4double t1 = tmp / A;
567 G4double t2 = C / tmp;
568 G4double trmax = std::max(t1, t2);
569
570 // Return distance
571 G4double tmax = std::min(tzmax, trmax);
572
573 // Set normal, if required, and return distance
574 //
575 if (calcNorm)
576 {
577 *validNorm = true;
578 G4ThreeVector pnew = p + tmax * v;
579 if (tmax == tzmax)
580 {
581 n->set(0, 0, (pnew.z() < 0) ? -1. : 1.);
582 }
583 else
584 {
585 *n = G4ThreeVector(pnew.x() * fDDy, pnew.y() * fDDx, 0.).unit();
586 }
587 }
588 return tmax;
589}
590
591//////////////////////////////////////////////////////////////////////////
592//
593// Estimate distance to the surface from inside,
594// returns 0 if point is outside
595//
596
598{
599#ifdef G4SPECDEBUG
600 if( Inside(p) == kOutside )
601 {
602 std::ostringstream message;
603 G4long oldprc = message.precision(16);
604 message << "Point p is outside (!?) of solid: " << GetName() << "\n"
605 << "Position:\n"
606 << " p.x() = " << p.x()/mm << " mm\n"
607 << " p.y() = " << p.y()/mm << " mm\n"
608 << " p.z() = " << p.z()/mm << " mm";
609 message.precision(oldprc) ;
610 G4Exception("G4ElliptocalTube::DistanceToOut(p)", "GeomSolids1002",
611 JustWarning, message);
612 DumpInfo();
613 }
614#endif
615 // safety distance to Z-bases
616 G4double distZ = fDz - std::abs(p.z());
617
618 // safety distance lateral surface
619 G4double x = p.x() * fSx;
620 G4double y = p.y() * fSy;
621 G4double distR = fR - std::sqrt(x * x + y * y);
622
623 // return SafetyToOut
624 G4double dist = std::min(distZ, distR);
625 return (dist < 0) ? 0 : dist;
626}
627
628//////////////////////////////////////////////////////////////////////////
629//
630// GetEntityType
631
633{
634 return {"G4EllipticalTube"};
635}
636
637//////////////////////////////////////////////////////////////////////////
638//
639// Make a clone of the object
640
642{
643 return new G4EllipticalTube(*this);
644}
645
646//////////////////////////////////////////////////////////////////////////
647//
648// Return cached surface area
649
650G4double G4EllipticalTube::GetCachedSurfaceArea() const
651{
652 G4ThreadLocalStatic G4double cached_Dx = 0;
653 G4ThreadLocalStatic G4double cached_Dy = 0;
654 G4ThreadLocalStatic G4double cached_Dz = 0;
655 G4ThreadLocalStatic G4double cached_area = 0;
656 if (cached_Dx != fDx || cached_Dy != fDy || cached_Dz != fDz)
657 {
658 cached_Dx = fDx;
659 cached_Dy = fDy;
660 cached_Dz = fDz;
661 cached_area = 2.*(pi*fDx*fDy + G4GeomTools::EllipsePerimeter(fDx, fDy)*fDz);
662 }
663 return cached_area;
664}
665
666//////////////////////////////////////////////////////////////////////////
667//
668// Return volume
669
671{
672 if (fCubicVolume == 0)
673 {
674 G4AutoLock l(&eltubeMutex);
675 fCubicVolume = twopi * fDx * fDy * fDz;
676 l.unlock();
677 }
678 return fCubicVolume;
679}
680
681//////////////////////////////////////////////////////////////////////////
682//
683// Return surface area
684
686{
687 if(fSurfaceArea == 0)
688 {
689 G4AutoLock l(&eltubeMutex);
690 fSurfaceArea = GetCachedSurfaceArea();
691 l.unlock();
692 }
693 return fSurfaceArea;
694}
695
696//////////////////////////////////////////////////////////////////////////
697//
698// Stream object contents to output stream
699
700std::ostream& G4EllipticalTube::StreamInfo(std::ostream& os) const
701{
702 G4long oldprc = os.precision(16);
703 os << "-----------------------------------------------------------\n"
704 << " *** Dump for solid - " << GetName() << " ***\n"
705 << " ===================================================\n"
706 << " Solid type: G4EllipticalTube\n"
707 << " Parameters: \n"
708 << " length Z: " << fDz/mm << " mm \n"
709 << " lateral surface equation: \n"
710 << " (X / " << fDx << ")^2 + (Y / " << fDy << ")^2 = 1 \n"
711 << "-----------------------------------------------------------\n";
712 os.precision(oldprc);
713
714 return os;
715}
716
717
718//////////////////////////////////////////////////////////////////////////
719//
720// Pick up a random point on the surface
721
723{
724 // Pick random point on selected surface
725 //
726 G4double sbase = pi * fDx * fDy; // base area
727 G4double select = fSurfaceArea * G4QuickRand();
728 G4double x, y, z;
729 if (select < 2. * sbase)
730 { // base (ellipse)
731 G4double phi = CLHEP::twopi * G4QuickRand();
732 G4double rho = std::sqrt(G4QuickRand());
733 x = rho * std::cos(phi);
734 y = rho * std::sin(phi);
735 z = (select < sbase) ? fDz : -fDz;
736 }
737 else
738 { // lateral surface (rejection sampling)
739 G4double s_max = std::max(fDx, fDy);
740 for (auto i = 0; i < 10000; ++i)
741 {
742 G4double phi = CLHEP::twopi * G4QuickRand();
743 x = std::cos(phi);
744 y = std::sin(phi);
745 G4double ss = sqr(fDy * x) + sqr(fDx * y);
746 if (sqr(s_max*G4QuickRand()) <= ss) { break; }
747 }
748 z = (2. * G4QuickRand() - 1.) * fDz;
749 }
750 return { fDx * x, fDy * y, z };
751}
752
753
754//////////////////////////////////////////////////////////////////////////
755//
756// CreatePolyhedron
757
759{
760 // create cylinder with radius=1...
761 //
762 G4Polyhedron* eTube = new G4PolyhedronTube(0., 1., fDz);
763
764 // apply non-uniform scaling...
765 //
766 eTube->Transform(G4Scale3D(fDx, fDy, 1.));
767 return eTube;
768}
769
770//////////////////////////////////////////////////////////////////////////
771//
772// GetPolyhedron
773
775{
776 if (fpPolyhedron == nullptr ||
777 fRebuildPolyhedron ||
778 fpPolyhedron->GetNumberOfRotationStepsAtTimeOfCreation() !=
779 fpPolyhedron->GetNumberOfRotationSteps())
780 {
781 G4AutoLock l(&polyhedronMutex);
782 delete fpPolyhedron;
783 fpPolyhedron = CreatePolyhedron();
784 fRebuildPolyhedron = false;
785 l.unlock();
786 }
787 return fpPolyhedron;
788}
789
790//////////////////////////////////////////////////////////////////////////
791//
792// DescribeYourselfTo
793
795{
796 scene.AddSolid (*this);
797}
798
799//////////////////////////////////////////////////////////////////////////
800//
801// GetExtent
802
804{
805 return { -fDx, fDx, -fDy, fDy, -fDz, fDz };
806}
807
808#endif // !defined(G4GEOM_USE_UELLIPTICALTUBE) || !defined(G4GEOM_USE_SYS_USOLIDS)
G4TemplateAutoLock< G4Mutex > G4AutoLock
const G4double kCarTolerance
std::vector< G4ThreeVector > G4ThreeVectorList
G4double C(G4double temp)
G4double B(G4double temperature)
G4double D(G4double temp)
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4ThreadLocal T * G4GeomSplitter< T >::offset
G4double G4QuickRand(uint32_t seed=0)
#define G4MUTEX_INITIALIZER
std::mutex G4Mutex
CLHEP::Hep3Vector G4ThreeVector
HepGeom::Scale3D G4Scale3D
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
const G4double A[17]
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
double z() const
Hep3Vector unit() const
double x() const
double y() const
void setZ(double)
double mag() 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...
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
G4ThreeVector GetPointOnSurface() const override
G4EllipticalTube & operator=(const G4EllipticalTube &rhs)
G4double GetSurfaceArea() override
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const override
EInside Inside(const G4ThreeVector &p) const override
G4Polyhedron * CreatePolyhedron() const override
G4GeometryType GetEntityType() const override
G4VisExtent GetExtent() const override
std::ostream & StreamInfo(std::ostream &os) const override
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const override
G4Polyhedron * GetPolyhedron() const override
G4VSolid * Clone() const override
~G4EllipticalTube() override
void DescribeYourselfTo(G4VGraphicsScene &scene) const override
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pmin, G4double &pmax) const override
G4EllipticalTube(const G4String &name, G4double Dx, G4double Dy, G4double Dz)
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const override
G4double GetCubicVolume() override
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const override
static G4double EllipsePerimeter(G4double a, G4double b)
virtual void AddSolid(const G4Box &)=0
G4String GetName() const
G4VSolid(const G4String &name)
Definition G4VSolid.cc:59
void DumpInfo() const
G4double kCarTolerance
Definition G4VSolid.hh:418
G4VSolid & operator=(const G4VSolid &rhs)
Definition G4VSolid.cc:108
G4VoxelLimits represents limitation/restrictions of space, where restrictions are only made perpendic...
HepPolyhedron & Transform(const G4Transform3D &t)
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
T sqr(const T &x)
Definition templates.hh:128
#define DBL_EPSILON
Definition templates.hh:66
#define DBL_MAX
Definition templates.hh:62
#define G4ThreadLocalStatic
Definition tls.hh:76