Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4IntersectingCone Class Reference

#include <G4IntersectingCone.hh>

Public Member Functions

 G4IntersectingCone (const G4double r[2], const G4double z[2])
 
virtual ~G4IntersectingCone ()
 
G4int LineHitsCone (const G4ThreeVector &p, const G4ThreeVector &v, G4double *s1, G4double *s2)
 
G4bool HitOn (const G4double r, const G4double z)
 
G4double RLo () const
 
G4double RHi () const
 
G4double ZLo () const
 
G4double ZHi () const
 
 G4IntersectingCone (__void__ &)
 

Protected Member Functions

G4int LineHitsCone1 (const G4ThreeVector &p, const G4ThreeVector &v, G4double *s1, G4double *s2)
 
G4int LineHitsCone2 (const G4ThreeVector &p, const G4ThreeVector &v, G4double *s1, G4double *s2)
 

Protected Attributes

G4double zLo
 
G4double zHi
 
G4double rLo
 
G4double rHi
 
G4bool type1 = false
 
G4double A
 
G4double B
 

Detailed Description

Definition at line 42 of file G4IntersectingCone.hh.

Constructor & Destructor Documentation

◆ G4IntersectingCone() [1/2]

G4IntersectingCone::G4IntersectingCone ( const G4double r[2],
const G4double z[2] )

Definition at line 37 of file G4IntersectingCone.cc.

39{
40 const G4double halfCarTolerance
42
43 // What type of cone are we?
44 //
45 type1 = (std::abs(z[1]-z[0]) > std::abs(r[1]-r[0]));
46
47 if (type1) // tube like
48 {
49 B = (r[1] - r[0]) / (z[1] - z[0]);
50 A = (r[0]*z[1] - r[1]*z[0]) / (z[1] -z[0]);
51 }
52 else // disk like
53 {
54 B = (z[1] - z[0]) / (r[1] - r[0]);
55 A = (z[0]*r[1] - z[1]*r[0]) / (r[1] - r[0]);
56 }
57
58 // Calculate extent
59 //
60 rLo = std::min(r[0], r[1]) - halfCarTolerance;
61 rHi = std::max(r[0], r[1]) + halfCarTolerance;
62 zLo = std::min(z[0], z[1]) - halfCarTolerance;
63 zHi = std::max(z[0], z[1]) + halfCarTolerance;
64}
double G4double
Definition G4Types.hh:83
G4double GetSurfaceTolerance() const
static G4GeometryTolerance * GetInstance()

◆ ~G4IntersectingCone()

G4IntersectingCone::~G4IntersectingCone ( )
virtualdefault

◆ G4IntersectingCone() [2/2]

G4IntersectingCone::G4IntersectingCone ( __void__ & )

Definition at line 69 of file G4IntersectingCone.cc.

70 : zLo(0.), zHi(0.), rLo(0.), rHi(0.), A(0.), B(0.)
71{
72}

Member Function Documentation

◆ HitOn()

G4bool G4IntersectingCone::HitOn ( const G4double r,
const G4double z )

Definition at line 83 of file G4IntersectingCone.cc.

85{
86 //
87 // Be careful! The inequalities cannot be "<=" and ">=" here without
88 // punching a tiny hole in our shape!
89 //
90 if (type1)
91 {
92 if (z < zLo || z > zHi) return false;
93 }
94 else
95 {
96 if (r < rLo || r > rHi) return false;
97 }
98
99 return true;
100}

Referenced by G4PolyconeSide::PointOnCone().

◆ LineHitsCone()

G4int G4IntersectingCone::LineHitsCone ( const G4ThreeVector & p,
const G4ThreeVector & v,
G4double * s1,
G4double * s2 )

Definition at line 107 of file G4IntersectingCone.cc.

110{
111 if (type1)
112 {
113 return LineHitsCone1( p, v, s1, s2 );
114 }
115 else
116 {
117 return LineHitsCone2( p, v, s1, s2 );
118 }
119}
G4int LineHitsCone1(const G4ThreeVector &p, const G4ThreeVector &v, G4double *s1, G4double *s2)
G4int LineHitsCone2(const G4ThreeVector &p, const G4ThreeVector &v, G4double *s1, G4double *s2)

Referenced by G4PolyconeSide::Intersect(), and G4PolyhedraSide::LineHitsSegments().

◆ LineHitsCone1()

G4int G4IntersectingCone::LineHitsCone1 ( const G4ThreeVector & p,
const G4ThreeVector & v,
G4double * s1,
G4double * s2 )
protected

Definition at line 179 of file G4IntersectingCone.cc.

182{
183 static const G4double EPS = DBL_EPSILON; // Precision constant,
184 // originally it was 1E-6
185 G4double x0 = p.x(), y0 = p.y(), z0 = p.z();
186 G4double tx = v.x(), ty = v.y(), tz = v.z();
187
188 // Value of radical can be inaccurate due to loss of precision
189 // if to calculate the coefficiets a,b,c like the following:
190 // G4double a = tx*tx + ty*ty - sqr(B*tz);
191 // G4double b = 2*( x0*tx + y0*ty - B*(A + B*z0)*tz);
192 // G4double c = x0*x0 + y0*y0 - sqr(A + B*z0);
193 //
194 // For more accurate calculation of radical the coefficients
195 // are splitted in two components, radial and along z-axis
196 //
197 G4double ar = tx*tx + ty*ty;
198 G4double az = sqr(B*tz);
199 G4double br = 2*(x0*tx + y0*ty);
200 G4double bz = 2*B*(A + B*z0)*tz;
201 G4double cr = x0*x0 + y0*y0;
202 G4double cz = sqr(A + B*z0);
203
204 // Instead radical = b*b - 4*a*c
205 G4double arcz = 4*ar*cz;
206 G4double azcr = 4*az*cr;
207 G4double radical = (br*br - 4*ar*cr) + ((std::max(arcz,azcr) - 2*bz*br) + std::min(arcz,azcr));
208
209 // Find the coefficients
210 G4double a = ar - az;
211 G4double b = br - bz;
212 G4double c = cr - cz;
213
214 if (radical < -EPS*std::fabs(b)) { return 0; } // No solution
215
216 if (radical < EPS*std::fabs(b))
217 {
218 //
219 // The radical is roughly zero: check for special, very rare, cases
220 //
221 if (std::fabs(a) > 1/kInfinity)
222 {
223 if(B==0.) { return 0; }
224 if ( std::fabs(x0*ty - y0*tx) < std::fabs(EPS/B) )
225 {
226 *s1 = -0.5*b/a;
227 return 1;
228 }
229 return 0;
230 }
231 }
232 else
233 {
234 radical = std::sqrt(radical);
235 }
236
237 if (a > 1/kInfinity)
238 {
239 G4double sa, sb, q = -0.5*( b + (b < 0 ? -radical : +radical) );
240 sa = q/a;
241 sb = c/q;
242 if (sa < sb) { *s1 = sa; *s2 = sb; } else { *s1 = sb; *s2 = sa; }
243 if (A + B*(z0+(*s1)*tz) < 0) { return 0; }
244 return 2;
245 }
246 else if (a < -1/kInfinity)
247 {
248 G4double sa, sb, q = -0.5*( b + (b < 0 ? -radical : +radical) );
249 sa = q/a;
250 sb = c/q;
251 *s1 = (B*tz > 0)^(sa > sb) ? sb : sa;
252 return 1;
253 }
254 else if (std::fabs(b) < 1/kInfinity)
255 {
256 return 0;
257 }
258 else
259 {
260 *s1 = -c/b;
261 if (A + B*(z0+(*s1)*tz) < 0) { return 0; }
262 return 1;
263 }
264}
double z() const
double x() const
double y() const
#define EPS
T sqr(const T &x)
Definition templates.hh:128
#define DBL_EPSILON
Definition templates.hh:66

Referenced by LineHitsCone().

◆ LineHitsCone2()

G4int G4IntersectingCone::LineHitsCone2 ( const G4ThreeVector & p,
const G4ThreeVector & v,
G4double * s1,
G4double * s2 )
protected

Definition at line 289 of file G4IntersectingCone.cc.

292{
293 static const G4double EPS = DBL_EPSILON; // Precision constant,
294 // originally it was 1E-6
295 G4double x0 = p.x(), y0 = p.y(), z0 = p.z();
296 G4double tx = v.x(), ty = v.y(), tz = v.z();
297
298 // Special case which might not be so rare: B = 0 (precisely)
299 //
300 if (B==0)
301 {
302 if (std::fabs(tz) < 1/kInfinity) { return 0; }
303
304 *s1 = (A-z0)/tz;
305 return 1;
306 }
307
308 // Value of radical can be inaccurate due to loss of precision
309 // if to calculate the coefficiets a,b,c like the following:
310 // G4double a = tz*tz - B2*(tx*tx + ty*ty);
311 // G4double b = 2*( (z0-A)*tz - B2*(x0*tx + y0*ty) );
312 // G4double c = sqr(z0-A) - B2*( x0*x0 + y0*y0 );
313 //
314 // For more accurate calculation of radical the coefficients
315 // are splitted in two components, radial and along z-axis
316 //
317 G4double B2 = B*B;
318
319 G4double az = tz*tz;
320 G4double ar = B2*(tx*tx + ty*ty);
321 G4double bz = 2*(z0-A)*tz;
322 G4double br = 2*B2*(x0*tx + y0*ty);
323 G4double cz = sqr(z0-A);
324 G4double cr = B2*(x0*x0 + y0*y0);
325
326 // Instead radical = b*b - 4*a*c
327 G4double arcz = 4*ar*cz;
328 G4double azcr = 4*az*cr;
329 G4double radical = (br*br - 4*ar*cr) + ((std::max(arcz,azcr) - 2*bz*br) + std::min(arcz,azcr));
330
331 // Find the coefficients
332 G4double a = az - ar;
333 G4double b = bz - br;
334 G4double c = cz - cr;
335
336 if (radical < -EPS*std::fabs(b)) { return 0; } // No solution
337
338 if (radical < EPS*std::fabs(b))
339 {
340 //
341 // The radical is roughly zero: check for special, very rare, cases
342 //
343 if (std::fabs(a) > 1/kInfinity)
344 {
345 if ( std::fabs(x0*ty - y0*tx) < std::fabs(EPS/B) )
346 {
347 *s1 = -0.5*b/a;
348 return 1;
349 }
350 return 0;
351 }
352 }
353 else
354 {
355 radical = std::sqrt(radical);
356 }
357
358 if (a < -1/kInfinity)
359 {
360 G4double sa, sb, q = -0.5*( b + (b < 0 ? -radical : +radical) );
361 sa = q/a;
362 sb = c/q;
363 if (sa < sb) { *s1 = sa; *s2 = sb; } else { *s1 = sb; *s2 = sa; }
364 if ((z0 + (*s1)*tz - A)/B < 0) { return 0; }
365 return 2;
366 }
367 else if (a > 1/kInfinity)
368 {
369 G4double sa, sb, q = -0.5*( b + (b < 0 ? -radical : +radical) );
370 sa = q/a;
371 sb = c/q;
372 *s1 = (tz*B > 0)^(sa > sb) ? sb : sa;
373 return 1;
374 }
375 else if (std::fabs(b) < 1/kInfinity)
376 {
377 return 0;
378 }
379 else
380 {
381 *s1 = -c/b;
382 if ((z0 + (*s1)*tz - A)/B < 0) { return 0; }
383 return 1;
384 }
385}

Referenced by LineHitsCone().

◆ RHi()

G4double G4IntersectingCone::RHi ( ) const
inline

Definition at line 55 of file G4IntersectingCone.hh.

55{ return rHi; }

◆ RLo()

G4double G4IntersectingCone::RLo ( ) const
inline

Definition at line 54 of file G4IntersectingCone.hh.

54{ return rLo; }

◆ ZHi()

G4double G4IntersectingCone::ZHi ( ) const
inline

Definition at line 57 of file G4IntersectingCone.hh.

57{ return zHi; }

Referenced by G4PolyconeSide::Extent(), and G4PolyhedraSide::Extent().

◆ ZLo()

G4double G4IntersectingCone::ZLo ( ) const
inline

Definition at line 56 of file G4IntersectingCone.hh.

56{ return zLo; }

Referenced by G4PolyconeSide::Extent(), and G4PolyhedraSide::Extent().

Member Data Documentation

◆ A

G4double G4IntersectingCone::A
protected

Definition at line 72 of file G4IntersectingCone.hh.

Referenced by G4IntersectingCone(), LineHitsCone1(), and LineHitsCone2().

◆ B

G4double G4IntersectingCone::B
protected

Definition at line 72 of file G4IntersectingCone.hh.

Referenced by G4IntersectingCone(), LineHitsCone1(), and LineHitsCone2().

◆ rHi

G4double G4IntersectingCone::rHi
protected

Definition at line 68 of file G4IntersectingCone.hh.

Referenced by G4IntersectingCone(), HitOn(), and RHi().

◆ rLo

G4double G4IntersectingCone::rLo
protected

Definition at line 68 of file G4IntersectingCone.hh.

Referenced by G4IntersectingCone(), and RLo().

◆ type1

G4bool G4IntersectingCone::type1 = false
protected

Definition at line 70 of file G4IntersectingCone.hh.

Referenced by G4IntersectingCone(), HitOn(), and LineHitsCone().

◆ zHi

G4double G4IntersectingCone::zHi
protected

Definition at line 67 of file G4IntersectingCone.hh.

Referenced by G4IntersectingCone(), HitOn(), and ZHi().

◆ zLo

G4double G4IntersectingCone::zLo
protected

Definition at line 67 of file G4IntersectingCone.hh.

Referenced by G4IntersectingCone(), and ZLo().


The documentation for this class was generated from the following files: