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

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

#include <G4TwistTrapAlphaSide.hh>

Inheritance diagram for G4TwistTrapAlphaSide:

Public Member Functions

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

G4TwistTrapAlphaSide describes a twisted boundary surface for a trapezoid.

Definition at line 46 of file G4TwistTrapAlphaSide.hh.

Constructor & Destructor Documentation

◆ G4TwistTrapAlphaSide() [1/2]

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

55 : G4VTwistSurface(name)
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 ;
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 fDx4plus2 = fDx4 + fDx2 ;
82 fDx4minus2 = fDx4 - fDx2 ;
83 fDx3plus1 = fDx3 + fDx1 ;
84 fDx3minus1 = fDx3 - fDx1 ;
85 fDy2plus1 = fDy2 + fDy1 ;
86 fDy2minus1 = fDy2 - fDy1 ;
87
88 fa1md1 = 2*fDx2 - 2*fDx1 ;
89 fa2md2 = 2*fDx4 - 2*fDx3 ;
90
91 fPhiTwist = PhiTwist ; // dphi
92 fAngleSide = AngleSide ; // 0,90,180,270 deg
93
94 fdeltaX = 2 * fDz * std::tan(fTheta) * std::cos(fPhi);
95 // dx in surface equation
96 fdeltaY = 2 * fDz * std::tan(fTheta) * std::sin(fPhi);
97 // dy in surface equation
98
99 fRot.rotateZ( AngleSide ) ;
100
101 fTrans.set(0, 0, 0); // No Translation
102 fIsValidNorm = false;
103
104 SetCorners() ;
105 SetBoundaries() ;
106}
G4VTwistSurface(const G4String &name)
G4RotationMatrix fRot
G4ThreeVector fTrans
@ kYAxis
Definition geomdefs.hh:56
@ kZAxis
Definition geomdefs.hh:57

◆ ~G4TwistTrapAlphaSide()

G4TwistTrapAlphaSide::~G4TwistTrapAlphaSide ( )
overridedefault

Default destructor.

◆ G4TwistTrapAlphaSide() [2/2]

G4TwistTrapAlphaSide::G4TwistTrapAlphaSide ( __void__ & a)

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

Definition at line 112 of file G4TwistTrapAlphaSide.cc.

113 : G4VTwistSurface(a)
114{
115}

Member Function Documentation

◆ DistanceToSurface() [1/2]

G4int G4TwistTrapAlphaSide::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 176 of file G4TwistTrapAlphaSide.cc.

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

675{
676 const G4double ctol = 0.5 * kCarTolerance;
677
678 fCurStat.ResetfDone(kDontValidate, &gp);
679
680 if (fCurStat.IsDone())
681 {
682 for (G4int i=0; i<fCurStat.GetNXX(); ++i)
683 {
684 gxx[i] = fCurStat.GetXX(i);
685 distance[i] = fCurStat.GetDistance(i);
686 areacode[i] = fCurStat.GetAreacode(i);
687 }
688 return fCurStat.GetNXX();
689 }
690
691 // initialize
692 for (G4int i=0; i<G4VSURFACENXX; ++i)
693 {
694 distance[i] = kInfinity;
695 areacode[i] = sOutside;
696 gxx[i].set(kInfinity, kInfinity, kInfinity);
697 }
698
700 G4ThreeVector xx; // intersection point
701 G4ThreeVector xxonsurface ; // interpolated intersection point
702
703 // the surfacenormal at that surface point
704 //
705 G4double phiR = 0 ;
706 G4double uR = 0 ;
707
708 G4ThreeVector surfacenormal ;
709 G4double deltaX, uMax ;
710 G4double halfphi = 0.5*fPhiTwist ;
711
712 for ( G4int i = 1 ; i<20 ; ++i )
713 {
714 xxonsurface = SurfacePoint(phiR,uR) ;
715 surfacenormal = NormAng(phiR,uR) ;
716 distance[0] = DistanceToPlane(p,xxonsurface,surfacenormal,xx); // new XX
717 deltaX = ( xx - xxonsurface ).mag() ;
718
719#ifdef G4TWISTDEBUG
720 G4cout << "i = " << i << ", distance = " << distance[0]
721 << ", " << deltaX << G4endl
722 << "X = " << xx << G4endl ;
723#endif
724
725 // the new point xx is accepted and phi/psi replaced
726 //
727 GetPhiUAtX(xx, phiR, uR) ;
728
729 if ( deltaX <= ctol ) { break ; }
730 }
731
732 // check validity of solution ( valid phi,psi )
733
734 uMax = GetBoundaryMax(phiR) ;
735
736 if ( phiR > halfphi ) { phiR = halfphi ; }
737 if ( phiR < -halfphi ) { phiR = -halfphi ; }
738 if ( uR > uMax ) { uR = uMax ; }
739 if ( uR < -uMax ) { uR = -uMax ; }
740
741 xxonsurface = SurfacePoint(phiR,uR) ;
742 distance[0] = ( p - xx ).mag() ;
743 if ( distance[0] <= ctol ) { distance[0] = 0 ; }
744
745 // end of validity
746
747#ifdef G4TWISTDEBUG
748 G4cout << "refined solution " << phiR << " , " << uR << " , " << G4endl ;
749 G4cout << "distance = " << distance[0] << G4endl ;
750 G4cout << "X = " << xx << G4endl ;
751#endif
752
753 G4bool isvalid = true;
754 gxx[0] = ComputeGlobalPoint(xx);
755
756#ifdef G4TWISTDEBUG
757 G4cout << "intersection Point found: " << gxx[0] << G4endl ;
758 G4cout << "distance = " << distance[0] << G4endl ;
759#endif
760
761 fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
762 isvalid, 1, kDontValidate, &gp);
763 return 1;
764}
G4double DistanceToPlane(const G4ThreeVector &p, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx)
CurrentStatus fCurStat

◆ GetNormal()

G4ThreeVector G4TwistTrapAlphaSide::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 122 of file G4TwistTrapAlphaSide.cc.

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

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