87 fTAlph = std::tan(fAlph) ;
93 fDx4plus2 = fDx4 + fDx2 ;
94 fDx4minus2 = fDx4 - fDx2 ;
95 fDx3plus1 = fDx3 + fDx1 ;
96 fDx3minus1 = fDx3 - fDx1 ;
97 fDy2plus1 = fDy2 + fDy1 ;
98 fDy2minus1 = fDy2 - fDy1 ;
100 fa1md1 = 2*fDx2 - 2*fDx1 ;
101 fa2md2 = 2*fDx4 - 2*fDx3 ;
103 fPhiTwist = PhiTwist ;
104 fAngleSide = AngleSide ;
106 fdeltaX = 2 * fDz * std::tan(fTheta) * std::cos(fPhi) ;
107 fdeltaY = 2 * fDz * std::tan(fTheta) * std::sin(fPhi) ;
124 :
G4VTwistSurface(a), fTheta(0.), fPhi(0.), fDy1(0.), fDx1(0.), fDx2(0.),
125 fDy2(0.), fDx3(0.), fDx4(0.), fDz(0.), fAlph(0.), fTAlph(0.), fPhiTwist(0.),
126 fAngleSide(0.), fdeltaX(0.), fdeltaY(0.), fDx4plus2(0.), fDx4minus2(0.),
127 fDx3plus1(0.), fDx3minus1(0.), fDy2plus1(0.), fDy2minus1(0.), fa1md1(0.),
167 GetPhiUAtX(xx,phi,u) ;
199 static const G4double pihalf = pi/2 ;
201 G4bool IsParallel = false ;
202 G4bool IsConverged = false ;
222 distance[i] = kInfinity;
225 gxx[i].
set(kInfinity, kInfinity, kInfinity);
244 G4bool tmpisvalid = false ;
246 std::vector<Intersection> xbuf ;
253 G4double phixz = fPhiTwist * ( p.
x() * v.
z() - p.
z() * v.
x() ) ;
254 G4double phiyz = fPhiTwist * ( p.
y() * v.
z() - p.
z() * v.
y() ) ;
260 if ( std::fabs(p.
z()) <= L ) {
262 phi = p.
z() * fPhiTwist / L ;
264 u = (2*(fdeltaY*phi*v.
x() - fPhiTwist*p.
y()*v.
x() - fdeltaX*phi*v.
y() + fPhiTwist*p.
x()*v.
y()) + (fDy2plus1*fPhiTwist + 2*fDy2minus1*phi)*(v.
x()*std::cos(phi) + v.
y()*std::sin(phi)))/(2.* fPhiTwist*(v.
y()*std::cos(phi) - v.
x()*std::sin(phi))) ;
272 xbuf.push_back(xbuftmp) ;
278 distance[0] = kInfinity;
279 gxx[0].
set(kInfinity,kInfinity,kInfinity);
283 areacode[0], isvalid[0],
284 0, validate, &gp, &gv);
300 c[8] = -3600*(-2*phiyz + fDy2plus1*fPhiTwist*v.
z()) ;
301 c[7] = -7200*(phixz - 2*fDz*v.
y() + (fdeltaY + fDy2minus1)*v.
z()) ;
302 c[6] = 120*(-52*phiyz - 120*fDz*v.
x() + 60*fdeltaX*v.
z() + 11*fDy2plus1*fPhiTwist*v.
z()) ;
303 c[5] = 240*(16*phixz - 52*fDz*v.
y() + 26*fdeltaY*v.
z() + 11*fDy2minus1*v.
z()) ;
304 c[4] = 12*(127*phiyz + 640*fDz*v.
x() - 320*fdeltaX*v.
z() + 4*fDy2plus1*fPhiTwist*v.
z()) ;
305 c[3] = -404*phixz + 3048*fDz*v.
y() - 1524*fdeltaY*v.
z() + 96*fDy2minus1*v.
z() ;
306 c[2] = -72*phiyz + 404*(-2*fDz*v.
x() + fdeltaX*v.
z()) ;
307 c[1] = 12*(phixz - 12*fDz*v.
y() + 6*fdeltaY*v.
z()) ;
308 c[0] = 24*fDz*v.
x() - 12*fdeltaX*v.
z() ;
312 G4cout <<
"coef = " << c[0] <<
" "
327 for (
G4int i = 0 ; i<num ; i++ ) {
330 G4cout <<
"Solution " << i <<
" : " << srd[i] <<
G4endl ;
332 phi = std::fmod(srd[i] , pihalf) ;
334 u = (1/std::cos(phi)*(2*phixz + 4*fDz*phi*v.
x() - 2*fdeltaX*phi*v.
z() + (fDy2plus1*fPhiTwist + 2*fDy2minus1*phi)*v.
z()* std::sin(phi)))/(2.*fPhiTwist*v.
z()) ;
342 xbuf.push_back(xbuftmp) ;
345 G4cout <<
"solution " << i <<
" = " << phi <<
" , " << u <<
G4endl ;
364 for (
size_t k = 0 ; k<xbuf.size() ; k++ ) {
367 G4cout <<
"Solution " << k <<
" : "
368 <<
"reconstructed phiR = " << xbuf[k].phi
369 <<
", uR = " << xbuf[k].u <<
G4endl ;
375 IsConverged = false ;
377 for (
G4int i = 1 ; i<maxint ; i++ ) {
379 xxonsurface = SurfacePoint(phi,u) ;
380 surfacenormal = NormAng(phi,u) ;
382 deltaX = ( tmpxx - xxonsurface ).mag() ;
383 theta = std::fabs(std::acos(v*surfacenormal) - pihalf) ;
384 if ( theta < 0.001 ) {
393 G4cout <<
"Step i = " << i <<
", distance = " << tmpdist <<
", " << deltaX <<
G4endl ;
397 GetPhiUAtX(tmpxx, phi, u) ;
400 G4cout <<
"approximated phi = " << phi <<
", u = " << u <<
G4endl ;
403 if ( deltaX <= factor*ctol ) { IsConverged = true ; break ; }
409 if ( std::fabs(tmpdist)<ctol ) tmpdist = 0 ;
413 G4cout <<
"refined solution " << phi <<
" , " << u <<
G4endl ;
423 tmpareacode = GetAreaCode(tmpxx);
425 if (tmpdist >= 0) tmpisvalid =
true;
428 tmpareacode = GetAreaCode(tmpxx,
false);
430 if (tmpdist >= 0) tmpisvalid =
true;
433 G4Exception(
"G4TwistTrapParallelSide::DistanceToSurface()",
435 "Feature NOT implemented !");
447 xbuf[k].distance = tmpdist ;
448 xbuf[k].areacode = tmpareacode ;
449 xbuf[k].isvalid = tmpisvalid ;
464 xbuf.erase( std::unique(xbuf.begin(), xbuf.end() ,
EqualIntersection ) , xbuf.end() ) ;
469 G4int nxxtmp = xbuf.size() ;
471 if ( nxxtmp<2 || IsParallel ) {
487 xbuf.push_back(xbuftmp) ;
503 xbuf.push_back(xbuftmp) ;
505 for (
size_t k = nxxtmp ; k<xbuf.size() ; k++ ) {
508 G4cout <<
"Solution " << k <<
" : "
509 <<
"reconstructed phiR = " << xbuf[k].phi
510 <<
", uR = " << xbuf[k].u <<
G4endl ;
516 IsConverged = false ;
518 for (
G4int i = 1 ; i<maxint ; i++ ) {
520 xxonsurface = SurfacePoint(phi,u) ;
521 surfacenormal = NormAng(phi,u) ;
523 deltaX = ( tmpxx - xxonsurface ).mag() ;
524 theta = std::fabs(std::acos(v*surfacenormal) - pihalf) ;
525 if ( theta < 0.001 ) {
533 G4cout <<
"Step i = " << i <<
", distance = " << tmpdist <<
", " << deltaX <<
G4endl ;
537 GetPhiUAtX(tmpxx, phi, u) ;
540 G4cout <<
"approximated phi = " << phi <<
", u = " << u <<
G4endl ;
543 if ( deltaX <= factor*ctol ) { IsConverged = true ; break ; }
549 if ( std::fabs(tmpdist)<ctol ) tmpdist = 0 ;
553 G4cout <<
"refined solution " << phi <<
" , " << u <<
G4endl ;
563 tmpareacode = GetAreaCode(tmpxx);
565 if (tmpdist >= 0) tmpisvalid =
true;
568 tmpareacode = GetAreaCode(tmpxx,
false);
570 if (tmpdist >= 0) tmpisvalid =
true;
573 G4Exception(
"G4TwistedBoxSide::DistanceToSurface()",
575 "Feature NOT implemented !");
587 xbuf[k].distance = tmpdist ;
588 xbuf[k].areacode = tmpareacode ;
589 xbuf[k].isvalid = tmpisvalid ;
602 xbuf.erase( std::unique(xbuf.begin(), xbuf.end() ,
EqualIntersection ) , xbuf.end() ) ;
611 for (
size_t i = 0 ; i<xbuf.size() ; i++ ) {
613 distance[i] = xbuf[i].distance;
615 areacode[i] = xbuf[i].areacode ;
616 isvalid[i] = xbuf[i].isvalid ;
619 isvalid[i], nxx, validate, &gp, &gv);
622 G4cout <<
"element Nr. " << i
623 <<
", local Intersection = " << xbuf[i].xx
624 <<
", distance = " << xbuf[i].distance
625 <<
", u = " << xbuf[i].u
626 <<
", phi = " << xbuf[i].phi
627 <<
", isvalid = " << xbuf[i].isvalid
635 G4cout <<
"G4TwistTrapParallelSide finished " <<
G4endl ;
636 G4cout << nxx <<
" possible physical solutions found" <<
G4endl ;
637 for (
G4int k= 0 ; k< nxx ; k++ ) {
638 G4cout <<
"global intersection Point found: " << gxx[k] <<
G4endl ;
676 distance[i] = kInfinity;
678 gxx[i].
set(kInfinity, kInfinity, kInfinity);
695 for (
G4int i = 1 ; i<maxint ; i++ ) {
697 xxonsurface = SurfacePoint(phiR,uR) ;
698 surfacenormal = NormAng(phiR,uR) ;
700 deltaX = ( xx - xxonsurface ).mag() ;
703 G4cout <<
"i = " << i <<
", distance = " << distance[0] <<
", " << deltaX <<
G4endl ;
708 GetPhiUAtX(xx, phiR, uR) ;
710 if ( deltaX <= ctol ) { break ; }
717 G4double uMax = GetBoundaryMax(phiR) ;
718 G4double uMin = GetBoundaryMin(phiR) ;
720 if ( phiR > halfphi ) phiR = halfphi ;
721 if ( phiR < -halfphi ) phiR = -halfphi ;
722 if ( uR > uMax ) uR = uMax ;
723 if ( uR < uMin ) uR = uMin ;
725 xxonsurface = SurfacePoint(phiR,uR) ;
726 distance[0] = ( p - xx ).mag() ;
727 if ( distance[0] <= ctol ) { distance[0] = 0 ; }
732 G4cout <<
"refined solution " << phiR <<
" , " << uR <<
" , " <<
G4endl ;
741 G4cout <<
"intersection Point found: " << gxx[0] <<
G4endl ;
764 GetPhiUAtX(xx, phi,yprime ) ;
766 G4double fXAxisMax = GetBoundaryMax(phi) ;
767 G4double fXAxisMin = GetBoundaryMin(phi) ;
771 G4cout <<
"GetAreaCode: yprime = " << yprime <<
G4endl ;
772 G4cout <<
"Intervall is " << fXAxisMin <<
" to " << fXAxisMax <<
G4endl ;
787 if (yprime < fXAxisMin + ctol) {
789 if (yprime <= fXAxisMin - ctol) isoutside =
true;
791 }
else if (yprime > fXAxisMax - ctol) {
793 if (yprime >= fXAxisMax + ctol) isoutside =
true;
803 if (xx.
z() <=
fAxisMin[zaxis] - ctol) isoutside =
true;
805 }
else if (xx.
z() >
fAxisMax[zaxis] - ctol) {
810 if (xx.
z() >=
fAxisMax[zaxis] + ctol) isoutside =
true;
817 G4int tmpareacode = areacode & (~sInside);
818 areacode = tmpareacode;
827 if (yprime < fXAxisMin ) {
829 }
else if (yprime > fXAxisMax) {
852 G4Exception(
"G4TwistTrapParallelSide::GetAreaCode()",
854 "Feature NOT implemented !");
862void G4TwistTrapParallelSide::SetCorners()
873 x = -fdeltaX/2. + (-fDx2 + fDy1*fTAlph)*std::cos(fPhiTwist/2.) + fDy1*std::sin(fPhiTwist/2.) ;
874 y = -fdeltaY/2. + fDy1*std::cos(fPhiTwist/2.) + (fDx2 - fDy1*fTAlph)*std::sin(fPhiTwist/2.) ;
881 x = -fdeltaX/2. + (fDx2 + fDy1*fTAlph)*std::cos(fPhiTwist/2.) + fDy1*std::sin(fPhiTwist/2.) ;
882 y = -fdeltaY/2. + fDy1*std::cos(fPhiTwist/2.) - (fDx2 + fDy1*fTAlph)*std::sin(fPhiTwist/2.) ;
888 x = fdeltaX/2. + (fDx4 + fDy2*fTAlph)*std::cos(fPhiTwist/2.) - fDy2*std::sin(fPhiTwist/2.) ;
889 y = fdeltaY/2. + fDy2*std::cos(fPhiTwist/2.) + (fDx4 + fDy2*fTAlph)*std::sin(fPhiTwist/2.) ;
895 x = fdeltaX/2. + (-fDx4 + fDy2*fTAlph)*std::cos(fPhiTwist/2.) - fDy2*std::sin(fPhiTwist/2.) ;
896 y = fdeltaY/2. + fDy2*std::cos(fPhiTwist/2.) + (-fDx4 + fDy2*fTAlph)*std::sin(fPhiTwist/2.) ;
903 G4Exception(
"G4TwistTrapParallelSide::SetCorners()",
905 "Method NOT implemented !");
912void G4TwistTrapParallelSide::SetBoundaries()
923 direction = direction.
unit();
929 direction = direction.
unit();
935 direction = direction.
unit();
941 direction = direction.
unit();
947 G4Exception(
"G4TwistTrapParallelSide::SetCorners()",
949 "Feature NOT implemented !");
965 phi = p.
z()/(2*fDz)*fPhiTwist ;
967 u = ((-(fdeltaX*phi) + fPhiTwist*p.
x())* std::cos(phi) + (-(fdeltaY*phi) + fPhiTwist*p.
y())*std::sin(phi))/fPhiTwist ;
988 GetPhiUAtX( tmpp, phi, u ) ;
1019 for ( i = 0 ; i<
n ; i++ ) {
1021 z = -fDz+i*(2.*fDz)/(n-1) ;
1022 phi = z*fPhiTwist/(2*fDz) ;
1023 umin = GetBoundaryMin(phi) ;
1024 umax = GetBoundaryMax(phi) ;
1026 for ( j = 0 ; j<k ; j++ ) {
1028 nnode =
GetNode(i,j,k,n,iside) ;
1029 u = umax - j*(umax-umin)/(k-1) ;
1030 p = SurfacePoint(phi,u,
true) ;
1032 xyz[nnode][0] = p.
x() ;
1033 xyz[nnode][1] = p.
y() ;
1034 xyz[nnode][2] = p.
z() ;
1036 if ( i<n-1 && j<k-1 ) {
1038 nface =
GetFace(i,j,k,n,iside) ;
G4bool DistanceSort(const Intersection &a, const Intersection &b)
G4bool EqualIntersection(const Intersection &a, const Intersection &b)
G4DLLIMPORT std::ostream G4cout
void set(double x, double y, double z)
HepRotation inverse() const
HepRotation & rotateZ(double delta)
G4int FindRoots(G4double *op, G4int degree, G4double *zeror, G4double *zeroi)
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)
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)
virtual ~G4TwistTrapParallelSide()
G4int GetAreacode(G4int i) const
G4double GetDistance(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=0)
G4bool IsValid(G4int i) const
G4ThreeVector GetXX(G4int i) const
void ResetfDone(EValidate validate, const G4ThreeVector *p, const G4ThreeVector *v=0)
static const G4int sC0Min1Min
static const G4int sC0Min1Max
G4double DistanceToPlane(const G4ThreeVector &p, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx)
G4int GetNode(G4int i, G4int j, G4int m, G4int n, G4int iside)
static const G4int sOutside
G4ThreeVector ComputeGlobalDirection(const G4ThreeVector &lp) const
static const G4int sAxisMax
static const G4int sAxis0
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)
G4ThreeVector ComputeLocalDirection(const G4ThreeVector &gp) const
static const G4int sAxisMin
static const G4int sC0Max1Max
static const G4int sAxis1
G4bool IsInside(G4int areacode, G4bool testbitmode=false) const
virtual void SetBoundary(const G4int &axiscode, const G4ThreeVector &direction, const G4ThreeVector &x0, const G4int &boundarytype)
G4ThreeVector ComputeLocalPoint(const G4ThreeVector &gp) const
void SetCorner(G4int areacode, G4double x, G4double y, G4double z)
G4ThreeVector GetCorner(G4int areacode) const
static const G4int sBoundary
static const G4int sAxisZ
G4bool IsOutside(G4int areacode) const
static const G4int sCorner
static const G4int sC0Max1Min
static const G4int sInside
CurrentStatus fCurStatWithV
static const G4int sAxisX
G4double DistanceToPlaneWithV(const G4ThreeVector &p, const G4ThreeVector &v, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx)
G4ThreeVector ComputeGlobalPoint(const G4ThreeVector &lp) const
G4SurfCurNormal fCurrentNormal
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)