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

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

#include <G4TwistBoxSide.hh>

Inheritance diagram for G4TwistBoxSide:

Public Member Functions

 G4TwistBoxSide (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)
 ~G4TwistBoxSide () 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
 G4TwistBoxSide (__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

G4TwistBoxSide describes a twisted boundary surface for a trapezoid.

Definition at line 45 of file G4TwistBoxSide.hh.

Constructor & Destructor Documentation

◆ G4TwistBoxSide() [1/2]

G4TwistBoxSide::G4TwistBoxSide ( 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 G4TwistBoxSide.cc.

53 : G4VTwistSurface(name)
54{
55
56
57 fAxis[0] = kYAxis; // in local coordinate system
58 fAxis[1] = kZAxis;
59 fAxisMin[0] = -kInfinity ; // Y 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 ; // box
66 fDx3 = pDx3 ;
67 fDx4 = pDx4 ; // box
68
69 // this is an overhead. But the parameter naming scheme fits to the other surfaces.
70
71 if ( fDx1 != fDx2 || fDx3 != fDx4 )
72 {
73 std::ostringstream message;
74 message << "TwistedTrapBoxSide is not used as a the side of a box: "
75 << GetName() << G4endl
76 << " Not a box !";
77 G4Exception("G4TwistBoxSide::G4TwistBoxSide()", "GeomSolids0002",
78 FatalException, message);
79 }
80
81 fDy1 = pDy1 ;
82 fDy2 = pDy2 ;
83
84 fDz = pDz ;
85
86 fAlph = pAlph ;
87 fTAlph = std::tan(fAlph) ;
88
89 fTheta = pTheta ;
90 fPhi = pPhi ;
91
92 // precalculate frequently used parameters
93
94 fDx4plus2 = fDx4 + fDx2 ;
95 fDx4minus2 = fDx4 - fDx2 ;
96 fDx3plus1 = fDx3 + fDx1 ;
97 fDx3minus1 = fDx3 - fDx1 ;
98 fDy2plus1 = fDy2 + fDy1 ;
99 fDy2minus1 = fDy2 - fDy1 ;
100
101 fa1md1 = 2*fDx2 - 2*fDx1 ;
102 fa2md2 = 2*fDx4 - 2*fDx3 ;
103
104
105 fPhiTwist = PhiTwist ; // dphi
106 fAngleSide = AngleSide ; // 0,90,180,270 deg
107
108 fdeltaX = 2*fDz * std::tan(fTheta) * std::cos(fPhi); // dx in surface equation
109 fdeltaY = 2*fDz * std::tan(fTheta) * std::sin(fPhi); // dy in surface equation
110
111 fRot.rotateZ( AngleSide ) ;
112
113 fTrans.set(0, 0, 0); // No Translation
114 fIsValidNorm = false;
115
116 SetCorners();
117 SetBoundaries();
118}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
#define G4endl
Definition G4ios.hh:67
G4VTwistSurface(const G4String &name)
const G4String & GetName() const
G4RotationMatrix fRot
G4ThreeVector fTrans
@ kYAxis
Definition geomdefs.hh:56
@ kZAxis
Definition geomdefs.hh:57

◆ ~G4TwistBoxSide()

G4TwistBoxSide::~G4TwistBoxSide ( )
overridedefault

Default destructor.

◆ G4TwistBoxSide() [2/2]

G4TwistBoxSide::G4TwistBoxSide ( __void__ & a)

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

Definition at line 124 of file G4TwistBoxSide.cc.

125 : G4VTwistSurface(a)
126{
127}

Member Function Documentation

◆ DistanceToSurface() [1/2]

G4int G4TwistBoxSide::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 187 of file G4TwistBoxSide.cc.

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

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

◆ GetNormal()

G4ThreeVector G4TwistBoxSide::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 133 of file G4TwistBoxSide.cc.

135{
136 // GetNormal returns a normal vector at a surface (or very close
137 // to surface) point at tmpxx.
138 // If isGlobal=true, it returns the normal in global coordinate.
139 //
140
141 G4ThreeVector xx;
142 if (isGlobal)
143 {
144 xx = ComputeLocalPoint(tmpxx);
145 if ((xx - fCurrentNormal.p).mag() < 0.5 * kCarTolerance)
146 {
148 }
149 }
150 else
151 {
152 xx = tmpxx;
153 if (xx == fCurrentNormal.p)
154 {
155 return fCurrentNormal.normal;
156 }
157 }
158
159 G4double phi ;
160 G4double u ;
161
162 GetPhiUAtX(xx,phi,u) ; // phi,u for point xx close to surface
163
164 G4ThreeVector normal = NormAng(phi,u) ; // the normal vector at phi,u
165
166#ifdef G4TWISTDEBUG
167 G4cout << "normal vector = " << normal << G4endl ;
168 G4cout << "phi = " << phi << " , u = " << u << G4endl ;
169#endif
170
171 // normal = normal/normal.mag() ;
172
173 if (isGlobal)
174 {
175 fCurrentNormal.normal = ComputeGlobalDirection(normal.unit());
176 }
177 else
178 {
179 fCurrentNormal.normal = normal.unit();
180 }
181 return fCurrentNormal.normal;
182}
Hep3Vector unit() const
G4ThreeVector ComputeGlobalDirection(const G4ThreeVector &lp) const
G4SurfCurNormal fCurrentNormal

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