200   G4bool IsParallel = false ;
 
  201   G4bool IsConverged =  false ;
 
  243   G4bool        tmpisvalid  = false ;
 
  245   std::vector<Intersection> xbuf ;
 
  252   G4double phixz = fPhiTwist * ( p.
x() * v.
z() - p.
z() * v.
x() ) ;
 
  253   G4double phiyz = fPhiTwist * ( p.
y() * v.
z() - p.
z() * v.
y() ) ;
 
  259     if ( std::fabs(p.
z()) <= L ) {     
 
  261       phi = p.
z() * fPhiTwist / 
L ;  
 
  263       u = (2*(fdeltaY*phi*v.
x() - fPhiTwist*p.
y()*v.
x() - fdeltaX*phi*v.
y()
 
  264               + fPhiTwist*p.
x()*v.
y()) + (fDy2plus1*fPhiTwist
 
  265               + 2*fDy2minus1*phi)*(v.
x()*std::cos(phi) + v.
y()*std::sin(phi)))
 
  266         / (2.* fPhiTwist*(v.
y()*std::cos(phi) - v.
x()*std::sin(phi)));
 
  274       xbuf.push_back(xbuftmp) ;  
 
  285                                      areacode[0], isvalid[0],
 
  286                                      0, validate, &gp, &gv);
 
  302     c[8] = -3600*(-2*phiyz + fDy2plus1*fPhiTwist*v.
z()) ;
 
  303     c[7] = -7200*(phixz - 2*fDz*v.
y() + (fdeltaY + fDy2minus1)*v.
z()) ;
 
  304     c[6] = 120*(-52*phiyz - 120*fDz*v.
x() + 60*fdeltaX*v.
z() + 11*fDy2plus1*fPhiTwist*v.
z()) ;
 
  305     c[5] = 240*(16*phixz - 52*fDz*v.
y() + 26*fdeltaY*v.
z() + 11*fDy2minus1*v.
z()) ;
 
  306     c[4] = 12*(127*phiyz + 640*fDz*v.
x() - 320*fdeltaX*v.
z() + 4*fDy2plus1*fPhiTwist*v.
z()) ;
 
  307     c[3] = -404*phixz + 3048*fDz*v.
y() - 1524*fdeltaY*v.
z() + 96*fDy2minus1*v.
z() ;
 
  308     c[2] = -72*phiyz + 404*(-2*fDz*v.
x() + fdeltaX*v.
z()) ;
 
  309     c[1] = 12*(phixz - 12*fDz*v.
y() + 6*fdeltaY*v.
z()) ;
 
  310     c[0] = 24*fDz*v.
x() - 12*fdeltaX*v.
z() ;
 
  314     G4cout << 
"coef = " << c[0] << 
" "  
  329     for (
G4int i = 0 ; i<num ; i++ ) {  
 
  332         G4cout << 
"Solution " << i << 
" : " << srd[i] << 
G4endl ;
 
  334         phi = std::fmod(srd[i] , pihalf)  ;
 
  336         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()) ;
 
  344         xbuf.push_back(xbuftmp) ;  
 
  347         G4cout << 
"solution " << i << 
" = " << phi << 
" , " << u  << 
G4endl ;
 
  366   for ( 
size_t k = 0 ; k<xbuf.size() ; k++ ) {
 
  369     G4cout << 
"Solution " << k << 
" : "  
  370            << 
"reconstructed phiR = " << xbuf[k].phi
 
  371            << 
", uR = " << xbuf[k].u << 
G4endl ; 
 
  377     IsConverged = false ;   
 
  379     for ( 
G4int i = 1 ; i<maxint ; i++ ) {
 
  381       xxonsurface = SurfacePoint(phi,u) ;
 
  382       surfacenormal = NormAng(phi,u) ;
 
  384       deltaX = ( tmpxx - xxonsurface ).mag() ; 
 
  385       theta = std::fabs(std::acos(v*surfacenormal) - pihalf) ;
 
  386       if ( theta < 0.001 ) { 
 
  395       G4cout << 
"Step i = " << i << 
", distance = " << tmpdist << 
", " << deltaX << 
G4endl ;
 
  399       GetPhiUAtX(tmpxx, phi, u) ; 
 
  402       G4cout << 
"approximated phi = " << phi << 
", u = " << u << 
G4endl ; 
 
  405       if ( deltaX <= factor*ctol ) { IsConverged = true ; break ; }
 
  411     if ( std::fabs(tmpdist)<ctol ) tmpdist = 0 ; 
 
  415     G4cout << 
"refined solution "  << phi << 
" , " << u  <<  
G4endl ;
 
  425         tmpareacode = GetAreaCode(tmpxx);
 
  427           if (tmpdist >= 0) tmpisvalid = 
true;
 
  430         tmpareacode = GetAreaCode(tmpxx, 
false);
 
  432           if (tmpdist >= 0) tmpisvalid = 
true;
 
  435         G4Exception(
"G4TwistTrapParallelSide::DistanceToSurface()",
 
  437                     "Feature NOT implemented !");
 
  449     xbuf[k].distance = tmpdist ;
 
  450     xbuf[k].areacode = tmpareacode ;
 
  451     xbuf[k].isvalid = tmpisvalid ;
 
  460   G4cout << G4endl << 
"list xbuf after sorting : " << 
G4endl ;
 
  466   xbuf.erase( std::unique(xbuf.begin(), xbuf.end() , 
EqualIntersection ) , xbuf.end() ) ;
 
  471   G4int nxxtmp = xbuf.size() ;
 
  473   if ( nxxtmp<2 || IsParallel  ) {
 
  489     xbuf.push_back(xbuftmp) ;  
 
  505     xbuf.push_back(xbuftmp) ;  
 
  507     for ( 
size_t k = nxxtmp ; k<xbuf.size() ; k++ ) {
 
  510       G4cout << 
"Solution " << k << 
" : "  
  511              << 
"reconstructed phiR = " << xbuf[k].phi
 
  512              << 
", uR = " << xbuf[k].u << 
G4endl ; 
 
  518       IsConverged = false ;   
 
  520       for ( 
G4int i = 1 ; i<maxint ; i++ ) {
 
  522         xxonsurface = SurfacePoint(phi,u) ;
 
  523         surfacenormal = NormAng(phi,u) ;
 
  525         deltaX = ( tmpxx - xxonsurface ).mag() ; 
 
  526         theta = std::fabs(std::acos(v*surfacenormal) - pihalf) ;
 
  527         if ( theta < 0.001 ) { 
 
  535         G4cout << 
"Step i = " << i << 
", distance = " << tmpdist << 
", " << deltaX << 
G4endl ;
 
  539         GetPhiUAtX(tmpxx, phi, u) ; 
 
  542         G4cout << 
"approximated phi = " << phi << 
", u = " << u << 
G4endl ; 
 
  545         if ( deltaX <= factor*ctol ) { IsConverged = true ; break ; }
 
  551       if ( std::fabs(tmpdist)<ctol ) tmpdist = 0 ; 
 
  555       G4cout << 
"refined solution "  << phi << 
" , " << u  <<  
G4endl ;
 
  565           tmpareacode = GetAreaCode(tmpxx);
 
  567             if (tmpdist >= 0) tmpisvalid = 
true;
 
  570           tmpareacode = GetAreaCode(tmpxx, 
false);
 
  572             if (tmpdist >= 0) tmpisvalid = 
true;
 
  575           G4Exception(
"G4TwistedBoxSide::DistanceToSurface()",
 
  577                       "Feature NOT implemented !");
 
  589       xbuf[k].distance = tmpdist ;
 
  590       xbuf[k].areacode = tmpareacode ;
 
  591       xbuf[k].isvalid = tmpisvalid ;
 
  604   xbuf.erase( std::unique(xbuf.begin(), xbuf.end() , 
EqualIntersection ) , xbuf.end() ) ;
 
  607   G4cout << G4endl << 
"list xbuf after sorting : " << 
G4endl ;
 
  613   for ( 
size_t i = 0 ; i<xbuf.size() ; i++ ) {
 
  615     distance[i] = xbuf[i].distance;
 
  617     areacode[i] = xbuf[i].areacode ;
 
  618     isvalid[i]  = xbuf[i].isvalid ;
 
  621                                      isvalid[i], nxx, validate, &gp, &gv);
 
  624     G4cout << 
"element Nr. " << i 
 
  625            << 
", local Intersection = " << xbuf[i].xx 
 
  626            << 
", distance = " << xbuf[i].distance 
 
  627            << 
", u = " << xbuf[i].u 
 
  628            << 
", phi = " << xbuf[i].phi 
 
  629            << 
", isvalid = " << xbuf[i].isvalid 
 
  637   G4cout << 
"G4TwistTrapParallelSide finished " << 
G4endl ;
 
  638   G4cout << nxx << 
" possible physical solutions found" << 
G4endl ;
 
  639   for ( 
G4int k= 0 ; k< nxx ; k++ ) {
 
  640     G4cout << 
"global intersection Point found: " << gxx[k] << 
G4endl ;
 
void set(double x, double y, double z)
 
G4int GetAreacode(G4int i) const 
 
static const G4double kInfinity
 
G4ThreeVector ComputeLocalDirection(const G4ThreeVector &gp) const 
 
G4double DistanceToPlaneWithV(const G4ThreeVector &p, const G4ThreeVector &v, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx)
 
static const G4int sOutside
 
G4ThreeVector ComputeGlobalPoint(const G4ThreeVector &lp) const 
 
G4GLOB_DLL std::ostream G4cout
 
G4bool IsOutside(G4int areacode) 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 
 
G4bool IsInside(G4int areacode, G4bool testbitmode=false) const 
 
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
 
G4ThreeVector GetXX(G4int i) const 
 
G4bool EqualIntersection(const Intersection &a, const Intersection &b)
 
static constexpr double pi
 
G4ThreeVector ComputeLocalPoint(const G4ThreeVector &gp) const 
 
static constexpr double L
 
G4bool DistanceSort(const Intersection &a, const Intersection &b)
 
G4int FindRoots(G4double *op, G4int degree, G4double *zeror, G4double *zeroi)
 
CurrentStatus fCurStatWithV
 
void ResetfDone(EValidate validate, const G4ThreeVector *p, const G4ThreeVector *v=0)