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

G4TwistTrapParallelSide describes a twisted boundary surface for a trapezoid. More...

#include <G4TwistTrapParallelSide.hh>

Inheritance diagram for G4TwistTrapParallelSide:

Public Member Functions

 G4TwistTrapParallelSide (const G4String &name, G4double PhiTwist, G4double pDz, G4double pTheta, G4double pPhi, G4double pDy1, G4double pDx1, G4double pDx2, G4double pDy2, G4double pDx3, G4double pDx4, G4double pAlph, G4double AngleSide)
 ~G4TwistTrapParallelSide () override=default
G4ThreeVector GetNormal (const G4ThreeVector &p, G4bool isGlobal=false) override
G4int DistanceToSurface (const G4ThreeVector &gp, const G4ThreeVector &gv, G4ThreeVector gxx[], G4double distance[], G4int areacode[], G4bool isvalid[], EValidate validate=kValidateWithTol) override
G4int DistanceToSurface (const G4ThreeVector &gp, G4ThreeVector gxx[], G4double distance[], G4int areacode[]) override
 G4TwistTrapParallelSide (__void__ &)
Public Member Functions inherited from G4VTwistSurface
 G4VTwistSurface (const G4String &name)
 G4VTwistSurface (const G4String &name, const G4RotationMatrix &rot, const G4ThreeVector &tlate, G4int handedness, const EAxis axis0, const EAxis axis1, G4double axis0min=-kInfinity, G4double axis1min=-kInfinity, G4double axis0max=kInfinity, G4double axis1max=kInfinity)
virtual ~G4VTwistSurface ()=default
virtual G4int AmIOnLeftSide (const G4ThreeVector &me, const G4ThreeVector &vec, G4bool withTol=true)
virtual G4double DistanceToBoundary (G4int areacode, G4ThreeVector &xx, const G4ThreeVector &p)
virtual G4double DistanceToIn (const G4ThreeVector &gp, const G4ThreeVector &gv, G4ThreeVector &gxxbest)
virtual G4double DistanceToOut (const G4ThreeVector &gp, const G4ThreeVector &gv, G4ThreeVector &gxxbest)
virtual G4double DistanceTo (const G4ThreeVector &gp, G4ThreeVector &gxx)
virtual void GetBoundaryParameters (const G4int &areacode, G4ThreeVector &d, G4ThreeVector &x0, G4int &boundarytype) const
virtual G4ThreeVector GetBoundaryAtPZ (G4int areacode, const G4ThreeVector &p) const
G4double DistanceToPlaneWithV (const G4ThreeVector &p, const G4ThreeVector &v, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx)
G4double DistanceToPlane (const G4ThreeVector &p, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx)
G4double DistanceToPlane (const G4ThreeVector &p, const G4ThreeVector &x0, const G4ThreeVector &t1, const G4ThreeVector &t2, G4ThreeVector &xx, G4ThreeVector &n)
G4double DistanceToLine (const G4ThreeVector &p, const G4ThreeVector &x0, const G4ThreeVector &d, G4ThreeVector &xx)
G4bool IsAxis0 (G4int areacode) const
G4bool IsAxis1 (G4int areacode) const
G4bool IsOutside (G4int areacode) const
G4bool IsInside (G4int areacode, G4bool testbitmode=false) const
G4bool IsBoundary (G4int areacode, G4bool testbitmode=false) const
G4bool IsCorner (G4int areacode, G4bool testbitmode=false) const
G4bool IsValidNorm () const
G4bool IsSameBoundary (G4VTwistSurface *surface1, G4int areacode1, G4VTwistSurface *surface2, G4int areacode2) const
G4int GetAxisType (G4int areacode, G4int whichaxis) const
G4ThreeVector ComputeGlobalPoint (const G4ThreeVector &lp) const
G4ThreeVector ComputeLocalPoint (const G4ThreeVector &gp) const
G4ThreeVector ComputeGlobalDirection (const G4ThreeVector &lp) const
G4ThreeVector ComputeLocalDirection (const G4ThreeVector &gp) const
void SetAxis (G4int i, const EAxis axis)
void SetNeighbours (G4VTwistSurface *ax0min, G4VTwistSurface *ax1min, G4VTwistSurface *ax0max, G4VTwistSurface *ax1max)
G4int GetNode (G4int i, G4int j, G4int m, G4int n, G4int iside)
G4int GetFace (G4int i, G4int j, G4int m, G4int n, G4int iside)
G4int GetEdgeVisibility (G4int i, G4int j, G4int m, G4int n, G4int number, G4int orientation)
const G4StringGetName () const
void DebugPrint () const
 G4VTwistSurface (__void__ &)

Additional Inherited Members

Public Types inherited from G4VTwistSurface
enum  EValidate { kDontValidate = 0 , kValidateWithTol = 1 , kValidateWithoutTol = 2 , kUninitialized = 3 }
Static Public Attributes inherited from G4VTwistSurface
static const G4int sOutside = 0x00000000
static const G4int sInside = 0x10000000
static const G4int sBoundary = 0x20000000
static const G4int sCorner = 0x40000000
static const G4int sC0Min1Min = 0x40000101
static const G4int sC0Max1Min = 0x40000201
static const G4int sC0Max1Max = 0x40000202
static const G4int sC0Min1Max = 0x40000102
static const G4int sAxisMin = 0x00000101
static const G4int sAxisMax = 0x00000202
static const G4int sAxisX = 0x00000404
static const G4int sAxisY = 0x00000808
static const G4int sAxisZ = 0x00000C0C
static const G4int sAxisRho = 0x00001010
static const G4int sAxisPhi = 0x00001414
static const G4int sAxis0 = 0x0000FF00
static const G4int sAxis1 = 0x000000FF
static const G4int sSizeMask = 0x00000303
static const G4int sAxisMask = 0x0000FCFC
static const G4int sAreaMask = 0XF0000000
Protected Member Functions inherited from G4VTwistSurface
G4VTwistSurface ** GetNeighbours ()
G4int GetNeighbours (G4int areacode, G4VTwistSurface *surfaces[])
G4ThreeVector GetCorner (G4int areacode) const
void GetBoundaryAxis (G4int areacode, EAxis axis[]) const
void GetBoundaryLimit (G4int areacode, G4double limit[]) const
virtual void SetBoundary (const G4int &axiscode, const G4ThreeVector &direction, const G4ThreeVector &x0, const G4int &boundarytype)
void SetCorner (G4int areacode, G4double x, G4double y, G4double z)
Protected Attributes inherited from G4VTwistSurface
EAxis fAxis [2]
G4double fAxisMin [2]
G4double fAxisMax [2]
CurrentStatus fCurStatWithV
CurrentStatus fCurStat
G4RotationMatrix fRot
G4ThreeVector fTrans
G4int fHandedness
G4SurfCurNormal fCurrentNormal
G4bool fIsValidNorm
G4double kCarTolerance

Detailed Description

G4TwistTrapParallelSide describes a twisted boundary surface for a trapezoid.

Definition at line 46 of file G4TwistTrapParallelSide.hh.

Constructor & Destructor Documentation

◆ G4TwistTrapParallelSide() [1/2]

G4TwistTrapParallelSide::G4TwistTrapParallelSide ( const G4String & name,
G4double PhiTwist,
G4double pDz,
G4double pTheta,
G4double pPhi,
G4double pDy1,
G4double pDx1,
G4double pDx2,
G4double pDy2,
G4double pDx3,
G4double pDx4,
G4double pAlph,
G4double AngleSide )

Constructs a trapezoid twisted boundary surface, given its parameters.

Parameters
[in]nameThe surface name.
[in]PhiTwistThe twist angle.
[in]pDzHalf z length.
[in]pThetaDirection between end planes - polar angle.
[in]pPhiDirection between end planes - azimuthal angle.
[in]pDy1Half y length at -pDz.
[in]pDx1Half x length at -pDz,-pDy.
[in]pDx2Half x length at -pDz,+pDy.
[in]pDy2Half y length at +pDz.
[in]pDx3Half x length at +pDz,-pDy.
[in]pDx4Half x length at +pDz,+pDy.
[in]pAlphTilt angle at +pDz.
[in]AngleSideParity.

Definition at line 40 of file G4TwistTrapParallelSide.cc.

54 : G4VTwistSurface(name)
55{
56
57 fAxis[0] = kXAxis; // in local coordinate system
58 fAxis[1] = kZAxis;
59 fAxisMin[0] = -kInfinity ; // X Axis boundary
60 fAxisMax[0] = kInfinity ; // depends on z !!
61 fAxisMin[1] = -pDz ; // Z Axis boundary
62 fAxisMax[1] = pDz ;
63
64 fDx1 = pDx1 ;
65 fDx2 = pDx2 ;
66 fDx3 = pDx3 ;
67 fDx4 = pDx4 ;
68
69 fDy1 = pDy1 ;
70 fDy2 = pDy2 ;
71
72 fDz = pDz ;
73
74 fAlph = pAlph ;
75 fTAlph = std::tan(fAlph) ;
76
77 fTheta = pTheta ;
78 fPhi = pPhi ;
79
80 // precalculate frequently used parameters
81 //
82 fDx4plus2 = fDx4 + fDx2 ;
83 fDx4minus2 = fDx4 - fDx2 ;
84 fDx3plus1 = fDx3 + fDx1 ;
85 fDx3minus1 = fDx3 - fDx1 ;
86 fDy2plus1 = fDy2 + fDy1 ;
87 fDy2minus1 = fDy2 - fDy1 ;
88
89 fa1md1 = 2*fDx2 - 2*fDx1 ;
90 fa2md2 = 2*fDx4 - 2*fDx3 ;
91
92 fPhiTwist = PhiTwist ; // dphi
93 fAngleSide = AngleSide ; // 0,90,180,270 deg
94
95 fdeltaX = 2*fDz*std::tan(fTheta)*std::cos(fPhi); // dx in surface equation
96 fdeltaY = 2*fDz*std::tan(fTheta)*std::sin(fPhi); // dy in surface equation
97
98 fRot.rotateZ( AngleSide ) ;
99
100 fTrans.set(0, 0, 0); // No Translation
101 fIsValidNorm = false;
102
103 SetCorners() ;
104 SetBoundaries() ;
105}
G4VTwistSurface(const G4String &name)
G4RotationMatrix fRot
G4ThreeVector fTrans
@ kXAxis
Definition geomdefs.hh:55
@ kZAxis
Definition geomdefs.hh:57

◆ ~G4TwistTrapParallelSide()

G4TwistTrapParallelSide::~G4TwistTrapParallelSide ( )
overridedefault

Default destructor.

◆ G4TwistTrapParallelSide() [2/2]

G4TwistTrapParallelSide::G4TwistTrapParallelSide ( __void__ & a)

Fake default constructor for usage restricted to direct object persistency for clients requiring preallocation of memory for persistifiable objects.

Definition at line 110 of file G4TwistTrapParallelSide.cc.

111 : G4VTwistSurface(a)
112{
113}

Member Function Documentation

◆ DistanceToSurface() [1/2]

G4int G4TwistTrapParallelSide::DistanceToSurface ( const G4ThreeVector & gp,
const G4ThreeVector & gv,
G4ThreeVector gxx[],
G4double distance[],
G4int areacode[],
G4bool isvalid[],
EValidate validate = kValidateWithTol )
overridevirtual

Returns the distance to surface, given point 'gp' and direction 'gv'.

Parameters
[in]gpThe point from where computing the distance.
[in]gvThe direction along which computing the distance.
[out]gxxVector of global points based on number of solutions.
[out]distanceThe distance vector based on number of solutions.
[out]areacodeThe location vector based on number of solutions.
[out]isvalidValidity vector based on number of solutions.
[in]validateAdopted validation criteria.
Returns
The number of solutions.

Implements G4VTwistSurface.

Definition at line 172 of file G4TwistTrapParallelSide.cc.

179{
180 static const G4double pihalf = pi/2 ;
181 const G4double ctol = 0.5 * kCarTolerance;
182
183 G4bool IsParallel = false ;
184 G4bool IsConverged = false ;
185
186 G4int nxx = 0 ; // number of physical solutions
187
188 fCurStatWithV.ResetfDone(validate, &gp, &gv);
189
190 if (fCurStatWithV.IsDone())
191 {
192 for (G4int i=0; i<fCurStatWithV.GetNXX(); ++i)
193 {
194 gxx[i] = fCurStatWithV.GetXX(i);
195 distance[i] = fCurStatWithV.GetDistance(i);
196 areacode[i] = fCurStatWithV.GetAreacode(i);
197 isvalid[i] = fCurStatWithV.IsValid(i);
198 }
199 return fCurStatWithV.GetNXX();
200 }
201
202 // initialize
203 for (G4int i=0; i<G4VSURFACENXX ; ++i)
204 {
205 distance[i] = kInfinity;
206 areacode[i] = sOutside;
207 isvalid[i] = false;
208 gxx[i].set(kInfinity, kInfinity, kInfinity);
209 }
210
213
214#ifdef G4TWISTDEBUG
215 G4cout << "Local point p = " << p << G4endl ;
216 G4cout << "Local direction v = " << v << G4endl ;
217#endif
218
219 G4double phi,u ; // parameters
220
221 // temporary variables
222
223 G4double tmpdist = kInfinity ;
224 G4ThreeVector tmpxx;
225 G4int tmpareacode = sOutside ;
226 G4bool tmpisvalid = false ;
227
228 std::vector<Intersection> xbuf ;
229 Intersection xbuftmp ;
230
231 // prepare some variables for the intersection finder
232
233 G4double L = 2*fDz ;
234
235 G4double phixz = fPhiTwist * ( p.x() * v.z() - p.z() * v.x() ) ;
236 G4double phiyz = fPhiTwist * ( p.y() * v.z() - p.z() * v.y() ) ;
237
238 // special case vz = 0
239
240 if ( v.z() == 0. )
241 {
242 if ( std::fabs(p.z()) <= L ) // intersection possible in z
243 {
244 phi = p.z() * fPhiTwist / L ; // phi is determined by the z-position
245
246 u = (2*(fdeltaY*phi*v.x() - fPhiTwist*p.y()*v.x() - fdeltaX*phi*v.y()
247 + fPhiTwist*p.x()*v.y()) + (fDy2plus1*fPhiTwist
248 + 2*fDy2minus1*phi)*(v.x()*std::cos(phi) + v.y()*std::sin(phi)))
249 / (2.* fPhiTwist*(v.y()*std::cos(phi) - v.x()*std::sin(phi)));
250
251 xbuftmp.phi = phi ;
252 xbuftmp.u = u ;
253 xbuftmp.areacode = sOutside ;
254 xbuftmp.distance = kInfinity ;
255 xbuftmp.isvalid = false ;
256
257 xbuf.push_back(xbuftmp) ; // store it to xbuf
258 }
259 else // no intersection possible
260 {
261 distance[0] = kInfinity;
262 gxx[0].set(kInfinity,kInfinity,kInfinity);
263 isvalid[0] = false ;
264 areacode[0] = sOutside ;
265 fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0],
266 areacode[0], isvalid[0],
267 0, validate, &gp, &gv);
268
269 return 0;
270 } // end std::fabs(p.z() <= L
271 } // end v.z() == 0
272 else // general solution for non-zero vz
273 {
274 G4double c[9],srd[8],si[8] ;
275
276 c[8] = -3600*(-2*phiyz + fDy2plus1*fPhiTwist*v.z()) ;
277 c[7] = -7200*(phixz - 2*fDz*v.y() + (fdeltaY + fDy2minus1)*v.z()) ;
278 c[6] = 120*(-52*phiyz - 120*fDz*v.x() + 60*fdeltaX*v.z()
279 + 11*fDy2plus1*fPhiTwist*v.z()) ;
280 c[5] = 240*(16*phixz - 52*fDz*v.y() + 26*fdeltaY*v.z()
281 + 11*fDy2minus1*v.z()) ;
282 c[4] = 12*(127*phiyz + 640*fDz*v.x() - 320*fdeltaX*v.z()
283 + 4*fDy2plus1*fPhiTwist*v.z()) ;
284 c[3] = -404*phixz + 3048*fDz*v.y() - 1524*fdeltaY*v.z()
285 + 96*fDy2minus1*v.z() ;
286 c[2] = -72*phiyz + 404*(-2*fDz*v.x() + fdeltaX*v.z()) ;
287 c[1] = 12*(phixz - 12*fDz*v.y() + 6*fdeltaY*v.z()) ;
288 c[0] = 24*fDz*v.x() - 12*fdeltaX*v.z() ;
289
290
291#ifdef G4TWISTDEBUG
292 G4cout << "coef = " << c[0] << " "
293 << c[1] << " "
294 << c[2] << " "
295 << c[3] << " "
296 << c[4] << " "
297 << c[5] << " "
298 << c[6] << " "
299 << c[7] << " "
300 << c[8] << G4endl ;
301#endif
302
303 G4JTPolynomialSolver trapEq ;
304 G4int num = trapEq.FindRoots(c,8,srd,si);
305
306 for (G4int i = 0 ; i<num ; ++i ) // loop over all mathematical solutions
307 {
308 if ( si[i]==0.0 ) // only real solutions
309 {
310#ifdef G4TWISTDEBUG
311 G4cout << "Solution " << i << " : " << srd[i] << G4endl ;
312#endif
313 phi = std::fmod(srd[i] , pihalf) ;
314 u = (1/std::cos(phi)*(2*phixz + 4*fDz*phi*v.x()
315 - 2*fdeltaX*phi*v.z() + (fDy2plus1*fPhiTwist
316 + 2*fDy2minus1*phi)*v.z()* std::sin(phi)))/(2.*fPhiTwist*v.z()) ;
317
318 xbuftmp.phi = phi ;
319 xbuftmp.u = u ;
320 xbuftmp.areacode = sOutside ;
321 xbuftmp.distance = kInfinity ;
322 xbuftmp.isvalid = false ;
323
324 xbuf.push_back(xbuftmp) ; // store it to xbuf
325
326#ifdef G4TWISTDEBUG
327 G4cout << "solution " << i << " = " << phi << " , " << u << G4endl ;
328#endif
329
330 } // end if real solution
331 } // end loop i
332 } // end general case
333
334 nxx = (G4int)xbuf.size() ; // save the number of solutions
335
336 G4ThreeVector xxonsurface ; // point on surface
337 G4ThreeVector surfacenormal ; // normal vector
338 G4double deltaX ; // distance between intersection point and point on surface
339 G4double theta ; // angle between track and surfacenormal
340 G4double factor ; // a scaling factor
341 G4int maxint = 30 ; // number of iterations
342
343
344 for (auto & k : xbuf)
345 {
346#ifdef G4TWISTDEBUG
347 G4cout << "Solution " << k << " : "
348 << "reconstructed phiR = " << xbuf[k].phi
349 << ", uR = " << xbuf[k].u << G4endl ;
350#endif
351
352 phi = k.phi ; // get the stored values for phi and u
353 u = k.u ;
354
355 IsConverged = false ; // no convergence at the beginning
356
357 for ( G4int i = 1 ; i<maxint ; ++i )
358 {
359 xxonsurface = SurfacePoint(phi,u) ;
360 surfacenormal = NormAng(phi,u) ;
361 tmpdist = DistanceToPlaneWithV(p, v, xxonsurface, surfacenormal, tmpxx);
362 deltaX = ( tmpxx - xxonsurface ).mag() ;
363 theta = std::fabs(std::acos(v*surfacenormal) - pihalf) ;
364 if ( theta < 0.001 )
365 {
366 factor = 50 ;
367 IsParallel = true ;
368 }
369 else
370 {
371 factor = 1 ;
372 }
373
374#ifdef G4TWISTDEBUG
375 G4cout << "Step i = " << i << ", distance = "
376 << tmpdist << ", " << deltaX << G4endl ;
377 G4cout << "X = " << tmpxx << G4endl ;
378#endif
379
380 GetPhiUAtX(tmpxx, phi, u); // new point xx is accepted and phi/u replaced
381
382#ifdef G4TWISTDEBUG
383 G4cout << "approximated phi = " << phi << ", u = " << u << G4endl ;
384#endif
385
386 if ( deltaX <= factor*ctol ) { IsConverged = true ; break ; }
387 } // end iterative loop (i)
388
389 if ( std::fabs(tmpdist)<ctol ) { tmpdist = 0 ; }
390
391#ifdef G4TWISTDEBUG
392 G4cout << "refined solution " << phi << " , " << u << G4endl ;
393 G4cout << "distance = " << tmpdist << G4endl ;
394 G4cout << "local X = " << tmpxx << G4endl ;
395#endif
396
397 tmpisvalid = false ; // init
398
399 if ( IsConverged )
400 {
401 if (validate == kValidateWithTol)
402 {
403 tmpareacode = GetAreaCode(tmpxx);
404 if (!IsOutside(tmpareacode))
405 {
406 if (tmpdist >= 0) { tmpisvalid = true; }
407 }
408 }
409 else if (validate == kValidateWithoutTol)
410 {
411 tmpareacode = GetAreaCode(tmpxx, false);
412 if (IsInside(tmpareacode))
413 {
414 if (tmpdist >= 0) { tmpisvalid = true; }
415 }
416 }
417 else // kDontValidate
418 {
419 G4Exception("G4TwistTrapParallelSide::DistanceToSurface()",
420 "GeomSolids0001", FatalException,
421 "Feature NOT implemented !");
422 }
423 }
424 else
425 {
426 tmpdist = kInfinity; // no convergence after 10 steps
427 tmpisvalid = false ; // solution is not vaild
428 }
429
430 // store the found values
431 k.xx = tmpxx ;
432 k.distance = tmpdist ;
433 k.areacode = tmpareacode ;
434 k.isvalid = tmpisvalid ;
435 } // end loop over physical solutions (variable k)
436
437 std::sort(xbuf.begin() , xbuf.end(), DistanceSort ) ; // sorting
438
439#ifdef G4TWISTDEBUG
440 G4cout << G4endl << "list xbuf after sorting : " << G4endl ;
441 G4cout << G4endl << G4endl ;
442#endif
443
444 // erase identical intersection (within kCarTolerance)
445 xbuf.erase(std::unique(xbuf.begin(),xbuf.end(),EqualIntersection),xbuf.end());
446
447
448 // add guesses
449
450 auto nxxtmp = (G4int)xbuf.size() ;
451
452 if ( nxxtmp<2 || IsParallel )
453 {
454 // positive end
455#ifdef G4TWISTDEBUG
456 G4cout << "add guess at +z/2 .. " << G4endl ;
457#endif
458
459 phi = fPhiTwist/2 ;
460 u = 0 ;
461
462 xbuftmp.phi = phi ;
463 xbuftmp.u = u ;
464 xbuftmp.areacode = sOutside ;
465 xbuftmp.distance = kInfinity ;
466 xbuftmp.isvalid = false ;
467
468 xbuf.push_back(xbuftmp) ; // store it to xbuf
469
470#ifdef G4TWISTDEBUG
471 G4cout << "add guess at -z/2 .. " << G4endl ;
472#endif
473
474 phi = -fPhiTwist/2 ;
475 u = 0 ;
476
477 xbuftmp.phi = phi ;
478 xbuftmp.u = u ;
479 xbuftmp.areacode = sOutside ;
480 xbuftmp.distance = kInfinity ;
481 xbuftmp.isvalid = false ;
482
483 xbuf.push_back(xbuftmp) ; // store it to xbuf
484
485 for ( std::size_t k = nxxtmp ; k<xbuf.size() ; ++k )
486 {
487#ifdef G4TWISTDEBUG
488 G4cout << "Solution " << k << " : "
489 << "reconstructed phiR = " << xbuf[k].phi
490 << ", uR = " << xbuf[k].u << G4endl ;
491#endif
492
493 phi = xbuf[k].phi ; // get the stored values for phi and u
494 u = xbuf[k].u ;
495
496 IsConverged = false ; // no convergence at the beginning
497
498 for ( G4int i = 1 ; i<maxint ; ++i )
499 {
500 xxonsurface = SurfacePoint(phi,u) ;
501 surfacenormal = NormAng(phi,u) ;
502 tmpdist = DistanceToPlaneWithV(p, v, xxonsurface, surfacenormal, tmpxx);
503 deltaX = ( tmpxx - xxonsurface ).mag() ;
504 theta = std::fabs(std::acos(v*surfacenormal) - pihalf) ;
505 if ( theta < 0.001 )
506 {
507 factor = 50 ;
508 }
509 else
510 {
511 factor = 1 ;
512 }
513
514#ifdef G4TWISTDEBUG
515 G4cout << "Step i = " << i << ", distance = "
516 << tmpdist << ", " << deltaX << G4endl ;
517 G4cout << "X = " << tmpxx << G4endl ;
518#endif
519
520 GetPhiUAtX(tmpxx, phi, u) ; // new point xx accepted and phi/u replaced
521
522#ifdef G4TWISTDEBUG
523 G4cout << "approximated phi = " << phi << ", u = " << u << G4endl ;
524#endif
525
526 if ( deltaX <= factor*ctol ) { IsConverged = true ; break ; }
527 } // end iterative loop (i)
528
529 if ( std::fabs(tmpdist)<ctol ) { tmpdist = 0 ; }
530
531#ifdef G4TWISTDEBUG
532 G4cout << "refined solution " << phi << " , " << u << G4endl ;
533 G4cout << "distance = " << tmpdist << G4endl ;
534 G4cout << "local X = " << tmpxx << G4endl ;
535#endif
536
537 tmpisvalid = false ; // init
538
539 if ( IsConverged )
540 {
541 if (validate == kValidateWithTol)
542 {
543 tmpareacode = GetAreaCode(tmpxx);
544 if (!IsOutside(tmpareacode))
545 {
546 if (tmpdist >= 0) { tmpisvalid = true; }
547 }
548 }
549 else if (validate == kValidateWithoutTol)
550 {
551 tmpareacode = GetAreaCode(tmpxx, false);
552 if (IsInside(tmpareacode))
553 {
554 if (tmpdist >= 0) { tmpisvalid = true; }
555 }
556 }
557 else // kDontValidate
558 {
559 G4Exception("G4TwistedBoxSide::DistanceToSurface()",
560 "GeomSolids0001", FatalException,
561 "Feature NOT implemented !");
562 }
563
564 }
565 else
566 {
567 tmpdist = kInfinity; // no convergence after 10 steps
568 tmpisvalid = false ; // solution is not vaild
569 }
570
571 // store the found values
572 xbuf[k].xx = tmpxx ;
573 xbuf[k].distance = tmpdist ;
574 xbuf[k].areacode = tmpareacode ;
575 xbuf[k].isvalid = tmpisvalid ;
576
577 } // end loop over physical solutions
578 } // end less than 2 solutions
579
580 // sort again
581 std::sort(xbuf.begin() , xbuf.end(), DistanceSort ) ; // sorting
582
583 // erase identical intersection (within kCarTolerance)
584 xbuf.erase(std::unique(xbuf.begin(),xbuf.end(),EqualIntersection),xbuf.end());
585
586#ifdef G4TWISTDEBUG
587 G4cout << G4endl << "list xbuf after sorting : " << G4endl ;
588 G4cout << G4endl << G4endl ;
589#endif
590
591 nxx = (G4int)xbuf.size() ; // determine number of solutions again.
592
593 for ( G4int i = 0 ; i<(G4int)xbuf.size() ; ++i )
594 {
595 distance[i] = xbuf[i].distance;
596 gxx[i] = ComputeGlobalPoint(xbuf[i].xx);
597 areacode[i] = xbuf[i].areacode ;
598 isvalid[i] = xbuf[i].isvalid ;
599
600 fCurStatWithV.SetCurrentStatus(i, gxx[i], distance[i], areacode[i],
601 isvalid[i], nxx, validate, &gp, &gv);
602#ifdef G4TWISTDEBUG
603 G4cout << "element Nr. " << i
604 << ", local Intersection = " << xbuf[i].xx
605 << ", distance = " << xbuf[i].distance
606 << ", u = " << xbuf[i].u
607 << ", phi = " << xbuf[i].phi
608 << ", isvalid = " << xbuf[i].isvalid
609 << G4endl ;
610#endif
611 } // end for( i ) loop
612
613#ifdef G4TWISTDEBUG
614 G4cout << "G4TwistTrapParallelSide finished " << G4endl ;
615 G4cout << nxx << " possible physical solutions found" << G4endl ;
616 for ( G4int k= 0 ; k< nxx ; ++k )
617 {
618 G4cout << "global intersection Point found: " << gxx[k] << G4endl ;
619 G4cout << "distance = " << distance[k] << G4endl ;
620 G4cout << "isvalid = " << isvalid[k] << G4endl ;
621 }
622#endif
623
624 return nxx ;
625}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define G4VSURFACENXX
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
double z() const
double x() const
double y() const
void set(double x, double y, double z)
G4int FindRoots(G4double *op, G4int degree, G4double *zeror, G4double *zeroi)
static const G4int sOutside
G4ThreeVector ComputeLocalDirection(const G4ThreeVector &gp) const
G4bool IsInside(G4int areacode, G4bool testbitmode=false) const
G4ThreeVector ComputeLocalPoint(const G4ThreeVector &gp) const
G4bool IsOutside(G4int areacode) const
CurrentStatus fCurStatWithV
G4double DistanceToPlaneWithV(const G4ThreeVector &p, const G4ThreeVector &v, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx)
G4ThreeVector ComputeGlobalPoint(const G4ThreeVector &lp) const
const G4double pi

◆ DistanceToSurface() [2/2]

G4int G4TwistTrapParallelSide::DistanceToSurface ( const G4ThreeVector & gp,
G4ThreeVector gxx[],
G4double distance[],
G4int areacode[] )
overridevirtual

Returns the safety distance to surface, given point 'gp'.

Parameters
[in]gpThe point from where computing the safety distance.
[out]gxxVector of global points based on number of solutions.
[out]distanceThe distance vector based on number of solutions.
[out]areacodeThe location vector based on number of solutions.
Returns
The number of solutions.

Implements G4VTwistSurface.

Definition at line 630 of file G4TwistTrapParallelSide.cc.

634{
635 const G4double ctol = 0.5 * kCarTolerance;
636
637 fCurStat.ResetfDone(kDontValidate, &gp);
638
639 if (fCurStat.IsDone())
640 {
641 for (G4int i=0; i<fCurStat.GetNXX(); ++i)
642 {
643 gxx[i] = fCurStat.GetXX(i);
644 distance[i] = fCurStat.GetDistance(i);
645 areacode[i] = fCurStat.GetAreacode(i);
646 }
647 return fCurStat.GetNXX();
648 }
649
650 // initialize
651 for (G4int i=0; i<G4VSURFACENXX; ++i)
652 {
653 distance[i] = kInfinity;
654 areacode[i] = sOutside;
655 gxx[i].set(kInfinity, kInfinity, kInfinity);
656 }
657
659 G4ThreeVector xx; // intersection point
660 G4ThreeVector xxonsurface ; // interpolated intersection point
661
662 // the surfacenormal at that surface point
663 G4double phiR = 0 ; //
664 G4double uR = 0 ;
665
666 G4ThreeVector surfacenormal ;
667 G4double deltaX ;
668
669 G4int maxint = 20 ;
670
671 for ( G4int i = 1 ; i<maxint ; ++i )
672 {
673 xxonsurface = SurfacePoint(phiR,uR) ;
674 surfacenormal = NormAng(phiR,uR) ;
675 distance[0] = DistanceToPlane(p, xxonsurface, surfacenormal, xx); // new XX
676 deltaX = ( xx - xxonsurface ).mag() ;
677
678#ifdef G4TWISTDEBUG
679 G4cout << "i = " << i << ", distance = "
680 << distance[0] << ", " << deltaX << G4endl ;
681 G4cout << "X = " << xx << G4endl ;
682#endif
683
684 // the new point xx is accepted and phi/psi replaced
685 GetPhiUAtX(xx, phiR, uR) ;
686
687 if ( deltaX <= ctol ) { break ; }
688 }
689
690 // check validity of solution ( valid phi,psi )
691
692 G4double halfphi = 0.5*fPhiTwist ;
693 G4double uMax = GetBoundaryMax(phiR) ;
694 G4double uMin = GetBoundaryMin(phiR) ;
695
696 if ( phiR > halfphi ) { phiR = halfphi ; }
697 if ( phiR < -halfphi ) { phiR = -halfphi ; }
698 if ( uR > uMax ) { uR = uMax ; }
699 if ( uR < uMin ) { uR = uMin ; }
700
701 xxonsurface = SurfacePoint(phiR,uR) ;
702 distance[0] = ( p - xx ).mag() ;
703 if ( distance[0] <= ctol ) { distance[0] = 0 ; }
704
705 // end of validity
706
707#ifdef G4TWISTDEBUG
708 G4cout << "refined solution " << phiR << " , " << uR << " , " << G4endl ;
709 G4cout << "distance = " << distance[0] << G4endl ;
710 G4cout << "X = " << xx << G4endl ;
711#endif
712
713 G4bool isvalid = true;
714 gxx[0] = ComputeGlobalPoint(xx);
715
716#ifdef G4TWISTDEBUG
717 G4cout << "intersection Point found: " << gxx[0] << G4endl ;
718 G4cout << "distance = " << distance[0] << G4endl ;
719#endif
720
721 fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
722 isvalid, 1, kDontValidate, &gp);
723 return 1;
724}
G4double DistanceToPlane(const G4ThreeVector &p, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx)
CurrentStatus fCurStat

◆ GetNormal()

G4ThreeVector G4TwistTrapParallelSide::GetNormal ( const G4ThreeVector & p,
G4bool isGlobal = false )
overridevirtual

Returns a normal vector at a surface (or very close to the surface) point at 'p'.

Parameters
[in]pThe point where computing the normal.
[in]isGlobalIf true, it returns the normal in global coordinates.
Returns
The normal vector.

Implements G4VTwistSurface.

Definition at line 118 of file G4TwistTrapParallelSide.cc.

120{
121 // GetNormal returns a normal vector at a surface (or very close
122 // to surface) point at tmpxx.
123 // If isGlobal=true, it returns the normal in global coordinate.
124 //
125
126 G4ThreeVector xx;
127 if (isGlobal)
128 {
129 xx = ComputeLocalPoint(tmpxx);
130 if ((xx - fCurrentNormal.p).mag() < 0.5 * kCarTolerance)
131 {
133 }
134 }
135 else
136 {
137 xx = tmpxx;
138 if (xx == fCurrentNormal.p)
139 {
140 return fCurrentNormal.normal;
141 }
142 }
143
144 G4double phi ;
145 G4double u ;
146
147 GetPhiUAtX(xx,phi,u) ; // phi,u for point xx close to surface
148
149 G4ThreeVector normal = NormAng(phi,u) ; // the normal vector at phi,u
150
151#ifdef G4TWISTDEBUG
152 G4cout << "normal vector = " << normal << G4endl ;
153 G4cout << "phi = " << phi << " , u = " << u << G4endl ;
154#endif
155
156 // normal = normal/normal.mag() ;
157
158 if (isGlobal)
159 {
160 fCurrentNormal.normal = ComputeGlobalDirection(normal.unit());
161 }
162 else
163 {
164 fCurrentNormal.normal = normal.unit();
165 }
166 return fCurrentNormal.normal;
167}
Hep3Vector unit() const
G4ThreeVector ComputeGlobalDirection(const G4ThreeVector &lp) const
G4SurfCurNormal fCurrentNormal

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