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

#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)
 
virtual ~G4TwistTrapAlphaSide ()
 
virtual G4ThreeVector GetNormal (const G4ThreeVector &xx, G4bool isGlobal=false)
 
virtual G4int DistanceToSurface (const G4ThreeVector &gp, const G4ThreeVector &gv, G4ThreeVector gxx[], G4double distance[], G4int areacode[], G4bool isvalid[], EValidate validate=kValidateWithTol)
 
virtual G4int DistanceToSurface (const G4ThreeVector &gp, G4ThreeVector gxx[], G4double distance[], G4int areacode[])
 
 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 axis1, const EAxis axis2, G4double axis0min=-kInfinity, G4double axis1min=-kInfinity, G4double axis0max=kInfinity, G4double axis1max=kInfinity)
 
virtual ~G4VTwistSurface ()
 
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 G4int DistanceToSurface (const G4ThreeVector &gp, const G4ThreeVector &gv, G4ThreeVector gxx[], G4double distance[], G4int areacode[], G4bool isvalid[], EValidate validate=kValidateWithTol)=0
 
virtual G4int DistanceToSurface (const G4ThreeVector &gp, G4ThreeVector gxx[], G4double distance[], G4int areacode[])=0
 
void DebugPrint () const
 
virtual G4ThreeVector GetNormal (const G4ThreeVector &xx, G4bool isGlobal)=0
 
virtual G4String GetName () const
 
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)
 
virtual G4ThreeVector SurfacePoint (G4double, G4double, G4bool isGlobal=false)=0
 
virtual G4double GetBoundaryMin (G4double)=0
 
virtual G4double GetBoundaryMax (G4double)=0
 
virtual G4double GetSurfaceArea ()=0
 
virtual void GetFacets (G4int m, G4int n, G4double xyz[][3], G4int faces[][4], G4int iside)=0
 
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)
 
 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 G4int GetAreaCode (const G4ThreeVector &xx, G4bool withtol=true)=0
 
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

Definition at line 41 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 
)

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}
void set(double x, double y, double z)
HepRotation & rotateZ(double delta)
Definition: Rotation.cc:87
G4double fAxisMax[2]
G4RotationMatrix fRot
G4ThreeVector fTrans
G4double fAxisMin[2]
@ kYAxis
Definition: geomdefs.hh:56
@ kZAxis
Definition: geomdefs.hh:57

◆ ~G4TwistTrapAlphaSide()

G4TwistTrapAlphaSide::~G4TwistTrapAlphaSide ( )
virtual

Definition at line 125 of file G4TwistTrapAlphaSide.cc.

126{
127}

◆ G4TwistTrapAlphaSide() [2/2]

G4TwistTrapAlphaSide::G4TwistTrapAlphaSide ( __void__ &  a)

Definition at line 112 of file G4TwistTrapAlphaSide.cc.

113 : G4VTwistSurface(a), fTheta(0.), fPhi(0.), fDy1(0.), fDx1(0.), fDx2(0.),
114 fDy2(0.), fDx3(0.), fDx4(0.), fDz(0.), fAlph(0.), fTAlph(0.), fPhiTwist(0.),
115 fAngleSide(0.), fDx4plus2(0.), fDx4minus2(0.), fDx3plus1(0.), fDx3minus1(0.),
116 fDy2plus1(0.), fDy2minus1(0.), fa1md1(0.), fa2md2(0.), fdeltaX(0.),
117 fdeltaY(0.)
118{
119}

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 
)
virtual

Implements G4VTwistSurface.

Definition at line 188 of file G4TwistTrapAlphaSide.cc.

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

Implements G4VTwistSurface.

Definition at line 684 of file G4TwistTrapAlphaSide.cc.

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

◆ GetNormal()

G4ThreeVector G4TwistTrapAlphaSide::GetNormal ( const G4ThreeVector xx,
G4bool  isGlobal = false 
)
virtual

Implements G4VTwistSurface.

Definition at line 134 of file G4TwistTrapAlphaSide.cc.

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