63 #if !defined(G4GEOM_USE_USPHERE) 
   80 using namespace CLHEP;
 
   99   : 
G4CSGSolid(pName), fEpsilon(2.e-11), fSPhi(0.0),
 
  100     fFullPhiSphere(true), fFullThetaSphere(true)
 
  106   halfAngTolerance = 0.5*kAngTolerance;
 
  110   if ( (pRmin >= pRmax) || (pRmax < 1.1*kRadTolerance) || (pRmin < 0) )
 
  112     std::ostringstream message;
 
  113     message << 
"Invalid radii for Solid: " << 
GetName() << 
G4endl 
  114             << 
"        pRmin = " << pRmin << 
", pRmax = " << pRmax;
 
  115     G4Exception(
"G4Sphere::G4Sphere()", 
"GeomSolids0002",
 
  118   fRmin=pRmin; fRmax=pRmax;
 
  119   fRminTolerance = (fRmin) ? 
std::max( kRadTolerance, fEpsilon*fRmin ) : 0;
 
  120   fRmaxTolerance = 
std::max( kRadTolerance, fEpsilon*fRmax );
 
  124   CheckPhiAngles(pSPhi, pDPhi);
 
  125   CheckThetaAngles(pSTheta, pDTheta);
 
  134   : 
G4CSGSolid(a), fRminTolerance(0.), fRmaxTolerance(0.),
 
  135     kAngTolerance(0.), kRadTolerance(0.), fEpsilon(0.),
 
  136     fRmin(0.), fRmax(0.), fSPhi(0.), fDPhi(0.), fSTheta(0.),
 
  137     fDTheta(0.), sinCPhi(0.), cosCPhi(0.), cosHDPhiOT(0.), cosHDPhiIT(0.),
 
  138     sinSPhi(0.), cosSPhi(0.), sinEPhi(0.), cosEPhi(0.), hDPhi(0.), cPhi(0.),
 
  139     ePhi(0.), sinSTheta(0.), cosSTheta(0.), sinETheta(0.), cosETheta(0.),
 
  140     tanSTheta(0.), tanSTheta2(0.), tanETheta(0.), tanETheta2(0.), eTheta(0.),
 
  141     fFullPhiSphere(false), fFullThetaSphere(false), fFullSphere(true),
 
  142     halfCarTolerance(0.), halfAngTolerance(0.)
 
  159   : 
G4CSGSolid(rhs), fRminTolerance(rhs.fRminTolerance),
 
  160     fRmaxTolerance(rhs.fRmaxTolerance), kAngTolerance(rhs.kAngTolerance),
 
  161     kRadTolerance(rhs.kRadTolerance), fEpsilon(rhs.fEpsilon),
 
  162     fRmin(rhs.fRmin), fRmax(rhs.fRmax), fSPhi(rhs.fSPhi), fDPhi(rhs.fDPhi),
 
  163     fSTheta(rhs.fSTheta), fDTheta(rhs.fDTheta),
 
  164     sinCPhi(rhs.sinCPhi), cosCPhi(rhs.cosCPhi),
 
  165     cosHDPhiOT(rhs.cosHDPhiOT), cosHDPhiIT(rhs.cosHDPhiIT),
 
  166     sinSPhi(rhs.sinSPhi), cosSPhi(rhs.cosSPhi),
 
  167     sinEPhi(rhs.sinEPhi), cosEPhi(rhs.cosEPhi),
 
  168     hDPhi(rhs.hDPhi), cPhi(rhs.cPhi), ePhi(rhs.ePhi),
 
  169     sinSTheta(rhs.sinSTheta), cosSTheta(rhs.cosSTheta),
 
  170     sinETheta(rhs.sinETheta), cosETheta(rhs.cosETheta),
 
  171     tanSTheta(rhs.tanSTheta), tanSTheta2(rhs.tanSTheta2),
 
  172     tanETheta(rhs.tanETheta), tanETheta2(rhs.tanETheta2), eTheta(rhs.eTheta),
 
  173     fFullPhiSphere(rhs.fFullPhiSphere), fFullThetaSphere(rhs.fFullThetaSphere),
 
  174     fFullSphere(rhs.fFullSphere),
 
  175     halfCarTolerance(rhs.halfCarTolerance),
 
  176     halfAngTolerance(rhs.halfAngTolerance)
 
  188    if (
this == &rhs)  { 
return *
this; }
 
  196    fRminTolerance = rhs.fRminTolerance; fRmaxTolerance = rhs.fRmaxTolerance;
 
  197    kAngTolerance = rhs.kAngTolerance; kRadTolerance = rhs.kRadTolerance;
 
  198    fEpsilon = rhs.fEpsilon; fRmin = rhs.fRmin; fRmax = rhs.fRmax;
 
  199    fSPhi = rhs.fSPhi; fDPhi = rhs.fDPhi; fSTheta = rhs.fSTheta;
 
  200    fDTheta = rhs.fDTheta; sinCPhi = rhs.sinCPhi; cosCPhi = rhs.cosCPhi;
 
  201    cosHDPhiOT = rhs.cosHDPhiOT; cosHDPhiIT = rhs.cosHDPhiIT;
 
  202    sinSPhi = rhs.sinSPhi; cosSPhi = rhs.cosSPhi;
 
  203    sinEPhi = rhs.sinEPhi; cosEPhi = rhs.cosEPhi;
 
  204    hDPhi = rhs.hDPhi; cPhi = rhs.cPhi; ePhi = rhs.ePhi;
 
  205    sinSTheta = rhs.sinSTheta; cosSTheta = rhs.cosSTheta;
 
  206    sinETheta = rhs.sinETheta; cosETheta = rhs.cosETheta;
 
  207    tanSTheta = rhs.tanSTheta; tanSTheta2 = rhs.tanSTheta2;
 
  208    tanETheta = rhs.tanETheta; tanETheta2 = rhs.tanETheta2;
 
  209    eTheta = rhs.eTheta; fFullPhiSphere = rhs.fFullPhiSphere;
 
  210    fFullThetaSphere = rhs.fFullThetaSphere; fFullSphere = rhs.fFullSphere;
 
  211    halfCarTolerance = rhs.halfCarTolerance;
 
  212    halfAngTolerance = rhs.halfAngTolerance;
 
  242     pMin.
set(-rmax,-rmax,-rmax);
 
  243     pMax.
set( rmax, rmax, rmax);
 
  256     if (stheta > 
halfpi) rhomax = rmax*sinStart;
 
  257     if (etheta < 
halfpi) rhomax = rmax*sinEnd;
 
  267     pMin.
set(xymin.
x(),xymin.
y(),zmin);
 
  268     pMax.
set(xymax.
x(),xymax.
y(),zmax);
 
  273   if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
 
  275     std::ostringstream message;
 
  276     message << 
"Bad bounding box (min >= max) for solid: " 
  278             << 
"\npMin = " << pMin
 
  279             << 
"\npMax = " << pMax;
 
  312   G4double rho,rho2,rad2,tolRMin,tolRMax;
 
  316   const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
 
  317   const G4double halfRminTolerance = fRminTolerance*0.5;
 
  318   const G4double Rmax_minus = fRmax - halfRmaxTolerance;
 
  319   const G4double Rmin_plus  = (fRmin > 0) ? fRmin+halfRminTolerance : 0;
 
  321   rho2 = p.
x()*p.
x() + p.
y()*p.
y() ;
 
  322   rad2 = rho2 + p.
z()*p.
z() ;
 
  327   tolRMax = Rmax_minus;
 
  335     if ( (!fFullPhiSphere) || (!fFullThetaSphere) )
 
  345   if ( (rad2 <= Rmax_minus*Rmax_minus) && (rad2 >= Rmin_plus*Rmin_plus) )
 
  351     tolRMax = fRmax + halfRmaxTolerance;                  
 
  352     tolRMin = 
std::max(fRmin-halfRminTolerance, 0.);      
 
  353     if ( (rad2 <= tolRMax*tolRMax) && (rad2 >= tolRMin*tolRMin) )
 
  365   if ( !fFullPhiSphere && rho2 )  
 
  367     pPhi = std::atan2(p.
y(),p.
x()) ;
 
  369     if      ( pPhi < fSPhi - halfAngTolerance  ) { pPhi += 
twopi; }
 
  370     else if ( pPhi > ePhi + halfAngTolerance )   { pPhi -= 
twopi; }
 
  372     if ( (pPhi < fSPhi - halfAngTolerance)
 
  373       || (pPhi > ePhi + halfAngTolerance) )      { 
return in = 
kOutside; }
 
  377       if ( (pPhi < fSPhi + halfAngTolerance)
 
  378         || (pPhi > ePhi - halfAngTolerance) )    { in = 
kSurface; }     
 
  384   if ( (rho2 || p.
z()) && (!fFullThetaSphere) )
 
  386     rho    = std::sqrt(rho2);
 
  387     pTheta = std::atan2(rho,p.
z());
 
  391       if ( ((fSTheta > 0.0) && (pTheta < fSTheta + halfAngTolerance))
 
  392         || ((eTheta < pi) && (pTheta > eTheta - halfAngTolerance)) )
 
  394         if ( (( (fSTheta>0.0)&&(pTheta>=fSTheta-halfAngTolerance) )
 
  395              || (fSTheta == 0.0) )
 
  396           && ((eTheta==
pi)||(pTheta <= eTheta + halfAngTolerance) ) )
 
  408         if ( ((fSTheta > 0.0)&&(pTheta < fSTheta - halfAngTolerance))
 
  409            ||((eTheta < pi  )&&(pTheta > eTheta + halfAngTolerance)) )
 
  426   G4int noSurfaces = 0;  
 
  427   G4double rho, rho2, radius, pTheta, pPhi=0.;
 
  434   rho2 = p.
x()*p.
x()+p.
y()*p.
y();
 
  435   radius = std::sqrt(rho2+p.
z()*p.
z());
 
  436   rho  = std::sqrt(rho2);
 
  438   G4double    distRMax = std::fabs(radius-fRmax);
 
  439   if (fRmin)  distRMin = std::fabs(radius-fRmin);
 
  441   if ( rho && !fFullSphere )
 
  443     pPhi = std::atan2(p.
y(),p.
x());
 
  445     if (pPhi < fSPhi-halfAngTolerance)     { pPhi += 
twopi; }
 
  446     else if (pPhi > ePhi+halfAngTolerance) { pPhi -= 
twopi; }
 
  448   if ( !fFullPhiSphere )
 
  452       distSPhi = std::fabs( pPhi-fSPhi ); 
 
  453       distEPhi = std::fabs( pPhi-ePhi ); 
 
  463   if ( !fFullThetaSphere )
 
  467       pTheta     = std::atan2(rho,p.
z());
 
  468       distSTheta = std::fabs(pTheta-fSTheta); 
 
  469       distETheta = std::fabs(pTheta-eTheta);
 
  472                           -cosSTheta*p.
y()/rho,
 
  493   if( radius )  { nR = 
G4ThreeVector(p.
x()/radius,p.
y()/radius,p.
z()/radius); }
 
  495   if( distRMax <= halfCarTolerance )
 
  500   if( fRmin && (distRMin <= halfCarTolerance) )
 
  505   if( !fFullPhiSphere )   
 
  507     if (distSPhi <= halfAngTolerance)
 
  512     if (distEPhi <= halfAngTolerance) 
 
  518   if ( !fFullThetaSphere )
 
  520     if ((distSTheta <= halfAngTolerance) && (fSTheta > 0.))
 
  523       if ((radius <= halfCarTolerance) && fFullPhiSphere)  { sumnorm += nZ;  }
 
  524       else                                                 { sumnorm += nTs; }
 
  526     if ((distETheta <= halfAngTolerance) && (eTheta < 
pi)) 
 
  529       if ((radius <= halfCarTolerance) && fFullPhiSphere)  { sumnorm -= nZ;  }
 
  530       else                                                 { sumnorm += nTe; }
 
  531       if(sumnorm.
z() == 0.)  { sumnorm += nZ; }
 
  534   if ( noSurfaces == 0 )
 
  537     G4Exception(
"G4Sphere::SurfaceNormal(p)", 
"GeomSolids1002",
 
  540      norm = ApproxSurfaceNormal(p);
 
  542   else if ( noSurfaces == 1 )  { norm = sumnorm; }
 
  543   else                         { norm = sumnorm.
unit(); }
 
  557   G4double rho,rho2,radius,pPhi,pTheta;
 
  558   G4double distRMin,distRMax,distSPhi,distEPhi,
 
  559            distSTheta,distETheta,distMin;
 
  561   rho2=p.
x()*p.
x()+p.
y()*p.
y();
 
  562   radius=std::sqrt(rho2+p.
z()*p.
z());
 
  569   distRMax=std::fabs(radius-fRmax);
 
  572     distRMin=std::fabs(radius-fRmin);
 
  574     if (distRMin<distRMax)
 
  596   pPhi = std::atan2(p.
y(),p.
x());
 
  597   if (pPhi<0) { pPhi += 
twopi; }
 
  599   if (!fFullPhiSphere && rho)
 
  603       distSPhi=std::fabs(pPhi-(fSPhi+
twopi))*rho;
 
  607       distSPhi=std::fabs(pPhi-fSPhi)*rho;
 
  610     distEPhi=std::fabs(pPhi-fSPhi-fDPhi)*rho;
 
  614     if (distSPhi<distEPhi)
 
  616       if (distSPhi<distMin)
 
  624       if (distEPhi<distMin)
 
  636   if (!fFullThetaSphere && radius)
 
  638     pTheta=std::atan2(rho,p.
z());
 
  639     distSTheta=std::fabs(pTheta-fSTheta)*radius;
 
  640     distETheta=std::fabs(pTheta-fSTheta-fDTheta)*radius;
 
  644     if (distSTheta<distETheta)
 
  646       if (distSTheta<distMin)
 
  648         distMin = distSTheta ;
 
  654       if (distETheta<distMin)
 
  656         distMin = distETheta ;
 
  678                          -cosSTheta*std::sin(pPhi),
 
  683                           cosETheta*std::sin(pPhi),
 
  690                   "Undefined side for valid surface normal to solid.");
 
  730   G4double rho2, rad2, pDotV2d, pDotV3d, pTheta ;
 
  731   G4double tolSTheta=0., tolETheta=0. ;
 
  734   const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
 
  735   const G4double halfRminTolerance = fRminTolerance*0.5;
 
  736   const G4double tolORMin2 = (fRmin>halfRminTolerance)
 
  737                ? (fRmin-halfRminTolerance)*(fRmin-halfRminTolerance) : 0;
 
  739                (fRmin+halfRminTolerance)*(fRmin+halfRminTolerance);
 
  741                (fRmax+halfRmaxTolerance)*(fRmax+halfRmaxTolerance);
 
  743                (fRmax-halfRmaxTolerance)*(fRmax-halfRmaxTolerance);
 
  747   G4double xi, yi, zi, rhoi, rhoi2, radi2, iTheta ;
 
  764   rho2 = p.
x()*p.
x() + p.
y()*p.
y() ;
 
  765   rad2 = rho2 + p.
z()*p.
z() ;
 
  766   pTheta = std::atan2(std::sqrt(rho2),p.
z()) ;
 
  768   pDotV2d = p.
x()*v.
x() + p.
y()*v.
y() ;
 
  769   pDotV3d = pDotV2d + p.
z()*v.
z() ;
 
  773   if (!fFullThetaSphere)
 
  775     tolSTheta = fSTheta - halfAngTolerance ;
 
  776     tolETheta = eTheta + halfAngTolerance ;
 
  780     if ((rad2!=0.0) || (fRmin!=0.0))
 
  786       G4double vTheta = std::atan2(std::sqrt(v.
x()*v.
x()+v.
y()*v.
y()),v.
z()) ;
 
  787       if ( (vTheta < tolSTheta) || (vTheta > tolETheta) )
 
  809   c = rad2 - fRmax*fRmax ;
 
  811   if (c > fRmaxTolerance*fRmax)
 
  816     d2 = pDotV3d*pDotV3d - c ;
 
  820       sd = -pDotV3d - std::sqrt(d2) ;
 
  826           G4double fTerm = sd-std::fmod(sd,dRmax);
 
  829         xi   = p.
x() + sd*v.
x() ;
 
  830         yi   = p.
y() + sd*v.
y() ;
 
  831         rhoi = std::sqrt(xi*xi + yi*yi) ;
 
  833         if (!fFullPhiSphere && rhoi)    
 
  835           cosPsi = (xi*cosCPhi + yi*sinCPhi)/rhoi ;
 
  837           if (cosPsi >= cosHDPhiOT)
 
  839             if (!fFullThetaSphere)   
 
  841               zi = p.
z() + sd*v.
z() ;
 
  846               iTheta = std::atan2(rhoi,zi) ;
 
  847               if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
 
  860           if (!fFullThetaSphere)    
 
  862             zi = p.
z() + sd*v.
z() ;
 
  867             iTheta = std::atan2(rhoi,zi) ;
 
  868             if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
 
  890     d2 = pDotV3d*pDotV3d - c ;
 
  892     if ( (rad2 > tolIRMax2)
 
  893       && ( (d2 >= fRmaxTolerance*fRmax) && (pDotV3d < 0) ) )
 
  900         cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
 
  902         if (cosPsi>=cosHDPhiIT)
 
  906           if ( !fFullThetaSphere )
 
  908             if ( (pTheta >= tolSTheta + kAngTolerance)
 
  909               && (pTheta <= tolETheta - kAngTolerance) )
 
  922         if ( !fFullThetaSphere )
 
  924           if ( (pTheta >= tolSTheta + kAngTolerance)
 
  925             && (pTheta <= tolETheta - kAngTolerance) )
 
  945     c  = rad2 - fRmin*fRmin ;
 
  946     d2 = pDotV3d*pDotV3d - c ;
 
  951     if ( (c > -halfRminTolerance) && (rad2 < tolIRMin2)
 
  954       if ( !fFullPhiSphere )
 
  959         cosPsi = (p.
x()*cosCPhi+p.
y()*sinCPhi)/std::sqrt(rho2) ;
 
  960         if (cosPsi >= cosHDPhiIT)
 
  964           if ( !fFullThetaSphere )
 
  966             if ( (pTheta >= tolSTheta + kAngTolerance)
 
  967               && (pTheta <= tolETheta - kAngTolerance) )
 
  980         if ( !fFullThetaSphere )
 
  982           if ( (pTheta >= tolSTheta + kAngTolerance)
 
  983             && (pTheta <= tolETheta - kAngTolerance) )
 
  998         sd = -pDotV3d + std::sqrt(d2) ;
 
  999         if ( sd >= halfRminTolerance )  
 
 1001           xi   = p.
x() + sd*v.
x() ;
 
 1002           yi   = p.
y() + sd*v.
y() ;
 
 1003           rhoi = std::sqrt(xi*xi+yi*yi) ;
 
 1005           if ( !fFullPhiSphere && rhoi )   
 
 1007             cosPsi = (xi*cosCPhi + yi*sinCPhi)/rhoi ;
 
 1009             if (cosPsi >= cosHDPhiOT)
 
 1011               if ( !fFullThetaSphere )  
 
 1013                 zi = p.
z() + sd*v.
z() ;
 
 1018                 iTheta = std::atan2(rhoi,zi) ;
 
 1019                 if ( (iTheta >= tolSTheta) && (iTheta<=tolETheta) )
 
 1032             if ( !fFullThetaSphere )   
 
 1034               zi = p.
z() + sd*v.
z() ;
 
 1039               iTheta = std::atan2(rhoi,zi) ;
 
 1040               if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
 
 1064   if ( !fFullPhiSphere )
 
 1069     Comp = v.
x()*sinSPhi - v.
y()*cosSPhi ;
 
 1073       Dist = p.
y()*cosSPhi - p.
x()*sinSPhi ;
 
 1075       if (Dist < halfCarTolerance)
 
 1083             xi    = p.
x() + sd*v.
x() ;
 
 1084             yi    = p.
y() + sd*v.
y() ;
 
 1085             zi    = p.
z() + sd*v.
z() ;
 
 1086             rhoi2 = xi*xi + yi*yi   ;
 
 1087             radi2 = rhoi2 + zi*zi   ;
 
 1098           if ( (radi2 <= tolORMax2)
 
 1099             && (radi2 >= tolORMin2)
 
 1100             && ((yi*cosCPhi-xi*sinCPhi) <= 0) )
 
 1106             if ( !fFullThetaSphere )
 
 1108               iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
 
 1109               if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
 
 1114                 if ((yi*cosCPhi-xi*sinCPhi) <= 0)
 
 1132     Comp = -( v.
x()*sinEPhi-v.
y()*cosEPhi ) ;
 
 1136       Dist = -(p.
y()*cosEPhi-p.
x()*sinEPhi) ;
 
 1137       if ( Dist < halfCarTolerance )
 
 1145             xi    = p.
x() + sd*v.
x() ;
 
 1146             yi    = p.
y() + sd*v.
y() ;
 
 1147             zi    = p.
z() + sd*v.
z() ;
 
 1148             rhoi2 = xi*xi + yi*yi   ;
 
 1149             radi2 = rhoi2 + zi*zi   ;
 
 1160           if ( (radi2 <= tolORMax2)
 
 1161             && (radi2 >= tolORMin2)
 
 1162             && ((yi*cosCPhi-xi*sinCPhi) >= 0) )
 
 1168             if ( !fFullThetaSphere )
 
 1170               iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
 
 1171               if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
 
 1176                 if ((yi*cosCPhi-xi*sinCPhi) >= 0)
 
 1194   if ( !fFullThetaSphere )
 
 1219       dist2STheta = rho2 - p.
z()*p.
z()*tanSTheta2 ;
 
 1227       dist2ETheta=rho2-p.
z()*p.
z()*tanETheta2;
 
 1233     if ( pTheta < tolSTheta )
 
 1238       t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
 
 1239       t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
 
 1243         c  = dist2STheta/t1 ;
 
 1250           zi = p.
z() + sd*v.
z();
 
 1252           if ( (sd < 0) || (zi*(fSTheta - 
halfpi) > 0) )
 
 1256           if ((sd >= 0) && (sd < snxt))
 
 1258             xi    = p.
x() + sd*v.
x();
 
 1259             yi    = p.
y() + sd*v.
y();
 
 1260             zi    = p.
z() + sd*v.
z();
 
 1261             rhoi2 = xi*xi + yi*yi;
 
 1262             radi2 = rhoi2 + zi*zi;
 
 1263             if ( (radi2 <= tolORMax2)
 
 1264               && (radi2 >= tolORMin2)
 
 1265               && (zi*(fSTheta - 
halfpi) <= 0) )
 
 1267               if ( !fFullPhiSphere && rhoi2 )  
 
 1269                 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
 
 1270                 if (cosPsi >= cosHDPhiOT)
 
 1289         t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
 
 1290         t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
 
 1294           c  = dist2ETheta/t1 ;
 
 1302             if ( (sd >= 0) && (sd < snxt) )
 
 1304               xi    = p.
x() + sd*v.
x() ;
 
 1305               yi    = p.
y() + sd*v.
y() ;
 
 1306               zi    = p.
z() + sd*v.
z() ;
 
 1307               rhoi2 = xi*xi + yi*yi   ;
 
 1308               radi2 = rhoi2 + zi*zi   ;
 
 1310               if ( (radi2 <= tolORMax2)
 
 1311                 && (radi2 >= tolORMin2)
 
 1312                 && (zi*(eTheta - 
halfpi) <= 0) )
 
 1314                 if (!fFullPhiSphere && rhoi2)   
 
 1316                   cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
 
 1317                   if (cosPsi >= cosHDPhiOT)
 
 1332     else if ( pTheta > tolETheta ) 
 
 1338       t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
 
 1339       t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
 
 1343         c  = dist2ETheta/t1 ;
 
 1350           zi = p.
z() + sd*v.
z();
 
 1352           if ( (sd < 0) || (zi*(eTheta - 
halfpi) > 0) )
 
 1356           if ( (sd >= 0) && (sd < snxt) )
 
 1358             xi    = p.
x() + sd*v.
x() ;
 
 1359             yi    = p.
y() + sd*v.
y() ;
 
 1360             zi    = p.
z() + sd*v.
z() ;
 
 1361             rhoi2 = xi*xi + yi*yi   ;
 
 1362             radi2 = rhoi2 + zi*zi   ;
 
 1364             if ( (radi2 <= tolORMax2)
 
 1365               && (radi2 >= tolORMin2) 
 
 1366               && (zi*(eTheta - 
halfpi) <= 0) )
 
 1368               if (!fFullPhiSphere && rhoi2)  
 
 1370                 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
 
 1371                 if (cosPsi >= cosHDPhiOT)
 
 1390         t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
 
 1391         t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
 
 1395           c  = dist2STheta/t1 ;
 
 1403             if ( (sd >= 0) && (sd < snxt) )
 
 1405               xi    = p.
x() + sd*v.
x() ;
 
 1406               yi    = p.
y() + sd*v.
y() ;
 
 1407               zi    = p.
z() + sd*v.
z() ;
 
 1408               rhoi2 = xi*xi + yi*yi   ;
 
 1409               radi2 = rhoi2 + zi*zi   ;
 
 1411               if ( (radi2 <= tolORMax2)
 
 1412                 && (radi2 >= tolORMin2)
 
 1413                 && (zi*(fSTheta - 
halfpi) <= 0) )
 
 1415                 if (!fFullPhiSphere && rhoi2)   
 
 1417                   cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
 
 1418                   if (cosPsi >= cosHDPhiOT)
 
 1433     else if ( (pTheta < tolSTheta + kAngTolerance)
 
 1434            && (fSTheta > halfAngTolerance) )
 
 1440       t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
 
 1441       if ( (t2>=0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta<
halfpi)
 
 1442         || (t2<0  && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta>
halfpi)
 
 1443         || (v.
z()<0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta==
halfpi) )
 
 1445         if (!fFullPhiSphere && rho2)  
 
 1447           cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
 
 1448           if (cosPsi >= cosHDPhiIT)
 
 1461       t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
 
 1465         c  = dist2STheta/t1 ;
 
 1472           if ( (sd >= halfCarTolerance) && (sd < snxt) && (fSTheta < halfpi) )
 
 1474             xi    = p.
x() + sd*v.
x() ;
 
 1475             yi    = p.
y() + sd*v.
y() ;
 
 1476             zi    = p.
z() + sd*v.
z() ;
 
 1477             rhoi2 = xi*xi + yi*yi   ;
 
 1478             radi2 = rhoi2 + zi*zi   ;
 
 1480             if ( (radi2 <= tolORMax2)
 
 1481               && (radi2 >= tolORMin2)
 
 1482               && (zi*(fSTheta - halfpi) <= 0) )
 
 1484               if ( !fFullPhiSphere && rhoi2 )    
 
 1486                 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
 
 1487                 if ( cosPsi >= cosHDPhiOT )
 
 1501     else if ((pTheta > tolETheta-kAngTolerance) && (eTheta < 
pi-kAngTolerance))
 
 1508       t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
 
 1510       if (   ((t2<0) && (eTheta < 
halfpi)
 
 1511           && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
 
 1512         ||   ((t2>=0) && (eTheta > 
halfpi)
 
 1513           && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
 
 1514         ||   ((v.
z()>0) && (eTheta == 
halfpi)
 
 1515           && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))  )
 
 1517         if (!fFullPhiSphere && rho2)   
 
 1519           cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
 
 1520           if (cosPsi >= cosHDPhiIT)
 
 1533       t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
 
 1537         c  = dist2ETheta/t1 ;
 
 1545           if ( (sd >= halfCarTolerance)
 
 1546             && (sd < snxt) && (eTheta > 
halfpi) )
 
 1548             xi    = p.
x() + sd*v.
x() ;
 
 1549             yi    = p.
y() + sd*v.
y() ;
 
 1550             zi    = p.
z() + sd*v.
z() ;
 
 1551             rhoi2 = xi*xi + yi*yi   ;
 
 1552             radi2 = rhoi2 + zi*zi   ;
 
 1554             if ( (radi2 <= tolORMax2)
 
 1555               && (radi2 >= tolORMin2)
 
 1556               && (zi*(eTheta - 
halfpi) <= 0) )
 
 1558               if (!fFullPhiSphere && rhoi2)   
 
 1560                 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
 
 1561                 if (cosPsi >= cosHDPhiOT)
 
 1580       t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
 
 1581       t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
 
 1585         c  = dist2STheta/t1 ;
 
 1593           if ((sd >= 0) && (sd < snxt))
 
 1595             xi    = p.
x() + sd*v.
x() ;
 
 1596             yi    = p.
y() + sd*v.
y() ;
 
 1597             zi    = p.
z() + sd*v.
z() ;
 
 1598             rhoi2 = xi*xi + yi*yi   ;
 
 1599             radi2 = rhoi2 + zi*zi   ;
 
 1601             if ( (radi2 <= tolORMax2)
 
 1602               && (radi2 >= tolORMin2)
 
 1603               && (zi*(fSTheta - 
halfpi) <= 0) )
 
 1605               if (!fFullPhiSphere && rhoi2)   
 
 1607                 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
 
 1608                 if (cosPsi >= cosHDPhiOT)
 
 1621       t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
 
 1622       t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
 
 1626         c  = dist2ETheta/t1 ;
 
 1634           if ((sd >= 0) && (sd < snxt))
 
 1636             xi    = p.
x() + sd*v.
x() ;
 
 1637             yi    = p.
y() + sd*v.
y() ;
 
 1638             zi    = p.
z() + sd*v.
z() ;
 
 1639             rhoi2 = xi*xi + yi*yi   ;
 
 1640             radi2 = rhoi2 + zi*zi   ;
 
 1642             if ( (radi2 <= tolORMax2)
 
 1643               && (radi2 >= tolORMin2)
 
 1644               && (zi*(eTheta - 
halfpi) <= 0) )
 
 1646               if (!fFullPhiSphere && rhoi2)   
 
 1648                 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
 
 1649                 if ( cosPsi >= cosHDPhiOT )
 
 1677   G4double safe=0.0,safeRMin,safeRMax,safePhi,safeTheta;
 
 1681   rho2=p.
x()*p.
x()+p.
y()*p.
y();
 
 1682   rds=std::sqrt(rho2+p.
z()*p.
z());
 
 1683   rho=std::sqrt(rho2);
 
 1692     if (safeRMin>safeRMax)
 
 1709   if (!fFullPhiSphere && rho)
 
 1713     cosPsi=(p.
x()*cosCPhi+p.
y()*sinCPhi)/rho;
 
 1714     if (cosPsi<std::cos(hDPhi))
 
 1718       if ((p.
y()*cosCPhi-p.
x()*sinCPhi)<=0)
 
 1720         safePhi=std::fabs(p.
x()*sinSPhi-p.
y()*cosSPhi);
 
 1724         safePhi=std::fabs(p.
x()*sinEPhi-p.
y()*cosEPhi);
 
 1726       if (safePhi>safe)  { safe=safePhi; }
 
 1732   if ((rds!=0.0) && (!fFullThetaSphere))
 
 1734     pTheta=std::acos(p.
z()/rds);
 
 1735     if (pTheta<0)  { pTheta+=
pi; }
 
 1736     dTheta1=fSTheta-pTheta;
 
 1737     dTheta2=pTheta-eTheta;
 
 1738     if (dTheta1>dTheta2)
 
 1742         safeTheta=rds*std::sin(dTheta1);
 
 1743         if (safe<=safeTheta)
 
 1753         safeTheta=rds*std::sin(dTheta2);
 
 1754         if (safe<=safeTheta)
 
 1762   if (safe<0)  { safe=0; }
 
 1779   ESide side=kNull,sidephi=kNull,sidetheta=kNull;  
 
 1781   const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
 
 1782   const G4double halfRminTolerance = fRminTolerance*0.5;
 
 1783   const G4double Rmax_plus  = fRmax + halfRmaxTolerance;
 
 1784   const G4double Rmin_minus = (fRmin) ? fRmin-halfRminTolerance : 0;
 
 1790   G4double pDistS,compS,pDistE,compE,sphi2,vphi;
 
 1792   G4double rho2,rad2,pDotV2d,pDotV3d;
 
 1799   G4double dist2STheta, dist2ETheta, distTheta;
 
 1804   rho2 = p.
x()*p.
x()+p.
y()*p.
y();
 
 1805   rad2 = rho2+p.
z()*p.
z();
 
 1807   pDotV2d = p.
x()*v.
x()+p.
y()*v.
y();
 
 1808   pDotV3d = pDotV2d+p.
z()*v.
z();
 
 1826   if( (rad2 <= Rmax_plus*Rmax_plus) && (rad2 >= Rmin_minus*Rmin_minus) )
 
 1828     c = rad2 - fRmax*fRmax;
 
 1830     if (c < fRmaxTolerance*fRmax) 
 
 1841       d2 = pDotV3d*pDotV3d - c;
 
 1843       if( (c >- fRmaxTolerance*fRmax)       
 
 1844        && ((pDotV3d >=0) || (d2 < 0)) )     
 
 1856         snxt = -pDotV3d+std::sqrt(d2);    
 
 1867       c  = rad2 - fRmin*fRmin;
 
 1868       d2 = pDotV3d*pDotV3d - c;
 
 1870       if (c >- fRminTolerance*fRmin) 
 
 1872         if ( (c < fRminTolerance*fRmin)              
 
 1873           && (d2 >= fRminTolerance*fRmin) && (pDotV3d < 0) )
 
 1875           if(calcNorm)  { *validNorm = 
false; }  
 
 1882             sd = -pDotV3d-std::sqrt(d2);
 
 1897   if ( !fFullThetaSphere )
 
 1924       if( std::fabs(tanSTheta) > 5./kAngTolerance ) 
 
 1928           if ( std::fabs( p.
z() ) <= halfRmaxTolerance )
 
 1937           stheta    = -p.
z()/v.
z();
 
 1938           sidetheta = kSTheta;
 
 1943         t1          = 1-v.
z()*v.
z()*(1+tanSTheta2);
 
 1944         t2          = pDotV2d-p.
z()*v.
z()*tanSTheta2;  
 
 1945         dist2STheta = rho2-p.
z()*p.
z()*tanSTheta2;     
 
 1947         distTheta = std::sqrt(rho2)-p.
z()*tanSTheta;
 
 1949         if( std::fabs(t1) < halfAngTolerance ) 
 
 1953             if(std::fabs(distTheta) < halfRmaxTolerance) 
 
 1955               if( (fSTheta < 
halfpi) && (p.
z() > 0.) )
 
 1957                 if( calcNorm )  { *validNorm = 
false; }
 
 1960               else if( (fSTheta > 
halfpi) && (p.
z() <= 0) )
 
 1967                     rhoSecTheta = std::sqrt(rho2*(1+tanSTheta2));
 
 1971                                         std::sin(fSTheta)  );
 
 1978             stheta    = -0.5*dist2STheta/t2;
 
 1979             sidetheta = kSTheta;
 
 1984           if( std::fabs(distTheta) < halfRmaxTolerance )
 
 1986             if( (fSTheta > 
halfpi) && (t2 >= 0.) ) 
 
 1993                   rhoSecTheta = std::sqrt(rho2*(1+tanSTheta2));
 
 1997                                       std::sin(fSTheta)  );
 
 2003             else if( (fSTheta < 
halfpi) && (t2 < 0.) && (p.
z() >=0.) ) 
 
 2005               if( calcNorm )  { *validNorm = 
false; }
 
 2021               if ( ((std::fabs(
s) < halfRmaxTolerance) && (t2 < 0.))
 
 2022                ||  (sd < 0.)  || ( (sd > 0.) && (p.
z() + sd*v.
z() > 0.) )     ) 
 
 2026               if( (sd > halfRmaxTolerance) && (p.
z() + sd*v.
z() <= 0.) )  
 
 2029                 sidetheta = kSTheta;
 
 2036               if ( ( (std::fabs(sd) < halfRmaxTolerance) && (t2 >= 0.) )
 
 2037                 || (sd < 0.) || ( (sd > 0.) && (p.
z() + sd*v.
z() < 0.) )   )
 
 2041               if( (sd > halfRmaxTolerance) && (p.
z() + sd*v.
z() >= 0.) )  
 
 2044                 sidetheta = kSTheta;
 
 2053       if( std::fabs(tanETheta) > 5./kAngTolerance ) 
 
 2057           if ( std::fabs( p.
z() ) <= halfRmaxTolerance )
 
 2071             sidetheta = kETheta;
 
 2077         t1          = 1-v.
z()*v.
z()*(1+tanETheta2);
 
 2078         t2          = pDotV2d-p.
z()*v.
z()*tanETheta2;  
 
 2079         dist2ETheta = rho2-p.
z()*p.
z()*tanETheta2;     
 
 2081         distTheta = std::sqrt(rho2)-p.
z()*tanETheta;
 
 2083         if( std::fabs(t1) < halfAngTolerance ) 
 
 2087             if(std::fabs(distTheta) < halfRmaxTolerance) 
 
 2089               if( (eTheta > 
halfpi) && (p.
z() < 0.) )
 
 2091                 if( calcNorm )  { *validNorm = 
false; }
 
 2094               else if ( (eTheta < 
halfpi) && (p.
z() >= 0) )
 
 2101                     rhoSecTheta = std::sqrt(rho2*(1+tanETheta2));
 
 2111             sd = -0.5*dist2ETheta/t2;
 
 2116               sidetheta = kETheta;
 
 2122           if ( std::fabs(distTheta) < halfRmaxTolerance )
 
 2124             if( (eTheta < 
halfpi) && (t2 >= 0.) ) 
 
 2131                     rhoSecTheta = std::sqrt(rho2*(1+tanETheta2));
 
 2140             else if ( (eTheta > 
halfpi)
 
 2141                    && (t2 < 0.) && (p.
z() <=0.) ) 
 
 2143               if( calcNorm )  { *validNorm = 
false; }
 
 2150           if ( (d2 <halfRmaxTolerance) && (d2 > -halfRmaxTolerance) )
 
 2162               if( ((std::fabs(sd) < halfRmaxTolerance) && (t2 < 0.))
 
 2167               if( sd > halfRmaxTolerance )  
 
 2172                   sidetheta = kETheta;
 
 2180               if ( ((std::fabs(sd) < halfRmaxTolerance) && (t2 >= 0.))
 
 2182                 || ( (sd > 0.) && (p.
z() + sd*v.
z() > halfRmaxTolerance) ) )
 
 2186               if ( ( sd>halfRmaxTolerance )
 
 2187                 && ( p.
z()+sd*v.
z() <= halfRmaxTolerance ) )
 
 2192                   sidetheta = kETheta;
 
 2205   if ( !fFullPhiSphere )
 
 2207     if ( p.
x() || p.
y() ) 
 
 2211       pDistS=p.
x()*sinSPhi-p.
y()*cosSPhi;
 
 2212       pDistE=-p.
x()*sinEPhi+p.
y()*cosEPhi;
 
 2216       compS   = -sinSPhi*v.
x()+cosSPhi*v.
y() ;
 
 2217       compE   =  sinEPhi*v.
x()-cosEPhi*v.
y() ;
 
 2220       if ( (pDistS <= 0) && (pDistE <= 0) )
 
 2226           sphi = pDistS/compS ;
 
 2227           xi   = p.
x()+sphi*v.
x() ;
 
 2228           yi   = p.
y()+sphi*v.
y() ;
 
 2234             vphi = std::atan2(v.
y(),v.
x());
 
 2236             if ( ( (fSPhi-halfAngTolerance) <= vphi)
 
 2237               && ( (ePhi+halfAngTolerance)  >= vphi) )
 
 2242           else if ( ( yi*cosCPhi - xi*sinCPhi ) >= 0 )
 
 2249             if ( pDistS > -halfCarTolerance)  { sphi = 0; } 
 
 2256           sphi2=pDistE/compE ;
 
 2259             xi = p.
x()+sphi2*v.
x() ;
 
 2260             yi = p.
y()+sphi2*v.
y() ;
 
 2269               vphi = std::atan2(v.
y(),v.
x()) ;
 
 2271               if( !((fSPhi-halfAngTolerance <= vphi)
 
 2272                   &&(fSPhi+fDPhi+halfAngTolerance >= vphi)) )
 
 2275                 if ( pDistE <= -halfCarTolerance )  { sphi = sphi2; }
 
 2276                 else                                { sphi = 0.0;   }
 
 2279             else if ((yi*cosCPhi-xi*sinCPhi)>=0) 
 
 2282               if ( pDistE <= -halfCarTolerance )
 
 2294       else if ((pDistS >= 0) && (pDistE >= 0)) 
 
 2296         if ( pDistS <= pDistE )
 
 2306           if ( (compS < 0) && (compE < 0) )  { sphi = 0; }
 
 2314           if ( (compS >= 0) && (compE >= 0) ) { sphi = 
kInfinity; }
 
 2318       else if ( (pDistS > 0) && (pDistE < 0) )
 
 2326             sphi = pDistE/compE ;
 
 2327             xi   = p.
x() + sphi*v.
x() ;
 
 2328             yi   = p.
y() + sphi*v.
y() ;
 
 2335               vphi = std::atan2(v.
y(),v.
x());
 
 2337               if ( ( (fSPhi-halfAngTolerance) <= vphi)
 
 2338                 && ( (ePhi+halfAngTolerance)  >= vphi) )
 
 2343             else if ( ( yi*cosCPhi - xi*sinCPhi ) <= 0 )
 
 2350               if ( pDistE > -halfCarTolerance )  { sphi = 0.; }
 
 2364               sphi = pDistE/compE ;
 
 2365               xi   = p.
x() + sphi*v.
x() ;
 
 2366               yi   = p.
y() + sphi*v.
y() ;
 
 2374                 vphi = std::atan2(v.
y(),v.
x());
 
 2376                 if ( ( (fSPhi-halfAngTolerance) <= vphi)
 
 2377                   && ( (ePhi+halfAngTolerance)  >= vphi) )
 
 2382               else if ( ( yi*cosCPhi - xi*sinCPhi) <= 0 )
 
 2410             xi=p.
x()+sphi*v.
x();
 
 2411             yi=p.
y()+sphi*v.
y();
 
 2418               vphi = std::atan2(v.
y(),v.
x()) ;
 
 2420               if ( ( (fSPhi-halfAngTolerance) <= vphi)
 
 2421                 && ( (ePhi+halfAngTolerance)  >= vphi) )
 
 2426             else if ( ( yi*cosCPhi - xi*sinCPhi ) >= 0 )
 
 2433               if ( pDistS > -halfCarTolerance )  { sphi = 0; }
 
 2447               sphi = pDistS/compS ;
 
 2448               xi   = p.
x()+sphi*v.
x() ;
 
 2449               yi   = p.
y()+sphi*v.
y() ;
 
 2457                 vphi = std::atan2(v.
y(),v.
x()) ;
 
 2459                 if ( ( (fSPhi-halfAngTolerance) <= vphi)
 
 2460                   && ( (ePhi+halfAngTolerance)  >= vphi) )
 
 2465               else if ( ( yi*cosCPhi - xi*sinCPhi ) >= 0 )
 
 2492       if ( v.
x() || v.
y() )
 
 2494         vphi = std::atan2(v.
y(),v.
x()) ;
 
 2495         if ((fSPhi-halfAngTolerance < vphi) && (vphi < ePhi+halfAngTolerance))
 
 2527         xi=p.
x()+snxt*v.
x();
 
 2528         yi=p.
y()+snxt*v.
y();
 
 2529         zi=p.
z()+snxt*v.
z();
 
 2544         else  { *validNorm=
false; }
 
 2553         else  { *validNorm=
false; }
 
 2562         else if ( fSTheta > 
halfpi )
 
 2564           xi = p.
x() + snxt*v.
x();
 
 2565           yi = p.
y() + snxt*v.
y();
 
 2569             rhoSecTheta = std::sqrt(rho2*(1+tanSTheta2));
 
 2571                                -tanSTheta/std::sqrt(1+tanSTheta2));
 
 2579         else  { *validNorm=
false; }  
 
 2588         else if ( eTheta < 
halfpi )
 
 2590           xi=p.
x()+snxt*v.
x();
 
 2591           yi=p.
y()+snxt*v.
y();
 
 2595             rhoSecTheta = std::sqrt(rho2*(1+tanETheta2));
 
 2597                                -tanETheta/std::sqrt(1+tanETheta2) );
 
 2605         else  { *validNorm=
false; }   
 
 2611         std::ostringstream message;
 
 2612         G4int oldprc = message.precision(16);
 
 2613         message << 
"Undefined side for valid surface normal to solid." 
 2615                 << 
"Position:"  << G4endl << G4endl
 
 2616                 << 
"p.x() = "   << p.
x()/
mm << 
" mm" << G4endl
 
 2617                 << 
"p.y() = "   << p.
y()/
mm << 
" mm" << G4endl
 
 2618                 << 
"p.z() = "   << p.
z()/
mm << 
" mm" << G4endl << G4endl
 
 2619                 << 
"Direction:" << G4endl << G4endl
 
 2620                 << 
"v.x() = "   << v.
x() << G4endl
 
 2621                 << 
"v.y() = "   << v.
y() << G4endl
 
 2622                 << 
"v.z() = "   << v.
z() << G4endl << G4endl
 
 2623                 << 
"Proposed distance :" << G4endl << G4endl
 
 2624                 << 
"snxt = "    << snxt/
mm << 
" mm" << 
G4endl;
 
 2625         message.precision(oldprc);
 
 2635     std::ostringstream message;
 
 2636     G4int oldprc = message.precision(16);
 
 2637     message << 
"Logic error: snxt = kInfinity  ???" << G4endl
 
 2638             << 
"Position:"  << G4endl << G4endl
 
 2639             << 
"p.x() = "   << p.
x()/
mm << 
" mm" << G4endl
 
 2640             << 
"p.y() = "   << p.
y()/
mm << 
" mm" << G4endl
 
 2641             << 
"p.z() = "   << p.
z()/
mm << 
" mm" << G4endl << G4endl
 
 2642             << 
"Rp = "<< std::sqrt( p.
x()*p.
x()+p.
y()*p.
y()+p.
z()*p.
z() )/
mm 
 2643             << 
" mm" << G4endl << G4endl
 
 2644             << 
"Direction:" << G4endl << G4endl
 
 2645             << 
"v.x() = "   << v.
x() << G4endl
 
 2646             << 
"v.y() = "   << v.
y() << G4endl
 
 2647             << 
"v.z() = "   << v.
z() << G4endl << G4endl
 
 2648             << 
"Proposed distance :" << G4endl << G4endl
 
 2649             << 
"snxt = "    << snxt/
mm << 
" mm" << 
G4endl;
 
 2650     message.precision(oldprc);
 
 2664   G4double safe=0.0,safeRMin,safeRMax,safePhi,safeTheta;
 
 2667   rho2=p.
x()*p.
x()+p.
y()*p.
y();
 
 2668   rds=std::sqrt(rho2+p.
z()*p.
z());
 
 2669   rho=std::sqrt(rho2);
 
 2681      G4cout.precision(old_prc) ;
 
 2683                  "GeomSolids1002", 
JustWarning, 
"Point p is outside !?" );
 
 2689   safeRMax = fRmax-rds;
 
 2693      safeRMin = rds-fRmin;
 
 2694      safe = 
std::min( safeRMin, safeRMax ); 
 
 2699   if ( !fFullPhiSphere )
 
 2703         if ((p.
y()*cosCPhi-p.
x()*sinCPhi)<=0)
 
 2705            safePhi=-(p.
x()*sinSPhi-p.
y()*cosSPhi);
 
 2709            safePhi=(p.
x()*sinEPhi-p.
y()*cosEPhi);
 
 2724   if ( !fFullThetaSphere )
 
 2728        pTheta=std::acos(p.
z()/rds);
 
 2729        if (pTheta<0) { pTheta+=
pi; }
 
 2731        { dTheta1=pTheta-fSTheta;}
 
 2733        { dTheta2=eTheta-pTheta;}
 
 2735        safeTheta=rds*std::sin(
std::min(dTheta1, dTheta2) );
 
 2742     safe = 
std::min( safe, safeTheta );
 
 2745   if (safe<0.0) { safe=0; }
 
 2775   G4int oldprc = os.precision(16);
 
 2776   os << 
"-----------------------------------------------------------\n" 
 2777      << 
"    *** Dump for solid - " << 
GetName() << 
" ***\n" 
 2778      << 
"    ===================================================\n" 
 2779      << 
" Solid type: G4Sphere\n" 
 2780      << 
" Parameters: \n" 
 2781      << 
"    inner radius: " << fRmin/
mm << 
" mm \n" 
 2782      << 
"    outer radius: " << fRmax/
mm << 
" mm \n" 
 2783      << 
"    starting phi of segment  : " << fSPhi/
degree << 
" degrees \n" 
 2784      << 
"    delta phi of segment     : " << fDPhi/
degree << 
" degrees \n" 
 2785      << 
"    starting theta of segment: " << fSTheta/
degree << 
" degrees \n" 
 2786      << 
"    delta theta of segment   : " << fDTheta/
degree << 
" degrees \n" 
 2787      << 
"-----------------------------------------------------------\n";
 
 2788   os.precision(oldprc);
 
 2799   G4double zRand, aOne, aTwo, aThr, aFou, aFiv, chose, phi, sinphi, cosphi;
 
 2800   G4double height1, height2, slant1, slant2, costheta, sintheta, rRand;
 
 2802   height1 = (fRmax-fRmin)*cosSTheta;
 
 2803   height2 = (fRmax-fRmin)*cosETheta;
 
 2804   slant1  = std::sqrt(
sqr((fRmax - fRmin)*sinSTheta) + height1*height1);
 
 2805   slant2  = std::sqrt(
sqr((fRmax - fRmin)*sinETheta) + height2*height2);
 
 2808   aOne = fRmax*fRmax*fDPhi*(cosSTheta-cosETheta);
 
 2809   aTwo = fRmin*fRmin*fDPhi*(cosSTheta-cosETheta);
 
 2810   aThr = fDPhi*((fRmax + fRmin)*sinSTheta)*slant1;
 
 2811   aFou = fDPhi*((fRmax + fRmin)*sinETheta)*slant2;
 
 2812   aFiv = 0.5*fDTheta*(fRmax*fRmax-fRmin*fRmin);
 
 2815   cosphi = std::cos(phi); 
 
 2816   sinphi = std::sin(phi);
 
 2818   sintheta = std::sqrt(1.-
sqr(costheta));
 
 2820   if(fFullPhiSphere) { aFiv = 0; }
 
 2821   if(fSTheta == 0)   { aThr=0; }
 
 2822   if(eTheta == 
pi) { aFou = 0; }
 
 2823   if(fSTheta == 
halfpi) { aThr = 
pi*(fRmax*fRmax-fRmin*fRmin); }
 
 2824   if(eTheta == 
halfpi)  { aFou = 
pi*(fRmax*fRmax-fRmin*fRmin); }
 
 2827   if( (chose>=0.) && (chose<aOne) )
 
 2830                          fRmax*sintheta*sinphi, fRmax*costheta);
 
 2832   else if( (chose>=aOne) && (chose<aOne+aTwo) )
 
 2835                          fRmin*sintheta*sinphi, fRmin*costheta);
 
 2837   else if( (chose>=aOne+aTwo) && (chose<aOne+aTwo+aThr) )
 
 2843                            tanSTheta*zRand*sinphi,zRand);
 
 2850   else if( (chose>=aOne+aTwo+aThr) && (chose<aOne+aTwo+aThr+aFou) )
 
 2856                              tanETheta*zRand*sinphi,zRand);
 
 2863   else if( (chose>=aOne+aTwo+aThr+aFou) && (chose<aOne+aTwo+aThr+aFou+aFiv) )
 
 2866                          rRand*sintheta*sinSPhi,rRand*costheta);
 
 2871                          rRand*sintheta*sinEPhi,rRand*costheta);
 
 2887     fSurfaceArea = fDPhi*(rsq+Rsq)*(cosSTheta - cosETheta);
 
 2894       G4double acos1=std::acos( std::pow(sinSTheta,2) * std::cos(fDPhi)
 
 2895                               + std::pow(cosSTheta,2));
 
 2907       G4double acos2=std::acos( std::pow(sinETheta,2) * std::cos(fDPhi)
 
 2908                               + std::pow(cosETheta,2));
 
 2928   return G4VisExtent(-fRmax, fRmax,-fRmax, fRmax,-fRmax, fRmax );
 
void set(double x, double y, double z)
 
G4double GetCosStartTheta() const 
 
ThreeVector shoot(const G4int Ap, const G4int Af)
 
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const 
 
static constexpr double mm
 
static const G4double kInfinity
 
G4double GetSinStartPhi() const 
 
CLHEP::Hep3Vector G4ThreeVector
 
G4double GetCosEndTheta() const 
 
G4double GetRadiusInRing(G4double rmin, G4double rmax) const 
 
G4double GetSinEndTheta() const 
 
G4Polyhedron * CreatePolyhedron() const 
 
virtual void AddSolid(const G4Box &)=0
 
G4double GetSinStartTheta() const 
 
G4double GetDeltaPhiAngle() const 
 
G4Sphere(const G4String &pName, G4double pRmin, G4double pRmax, G4double pSPhi, G4double pDPhi, G4double pSTheta, G4double pDTheta)
 
static constexpr double twopi
 
G4ThreeVector GetPointOnSurface() const 
 
G4GLOB_DLL std::ostream G4cout
 
G4double GetStartThetaAngle() const 
 
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pmin, G4double &pmax) const 
 
static constexpr double degree
 
G4double GetRadialTolerance() const 
 
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=G4bool(false), G4bool *validNorm=0, G4ThreeVector *n=0) const 
 
EInside Inside(const G4ThreeVector &p) const 
 
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimits, const G4Transform3D &pTransform3D, G4double &pMin, G4double &pMax) const 
 
G4GeometryType GetEntityType() const 
 
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const 
 
G4double GetInnerRadius() const 
 
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
 
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const 
 
G4Sphere & operator=(const G4Sphere &rhs)
 
T max(const T t1, const T t2)
brief Return the largest of the two arguments 
 
std::ostream & StreamInfo(std::ostream &os) const 
 
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
 
T min(const T t1, const T t2)
brief Return the smallest of the two arguments 
 
G4double GetCosStartPhi() const 
 
G4VisExtent GetExtent() const 
 
G4double GetSurfaceArea()
 
G4double GetSinEndPhi() const 
 
static constexpr double pi
 
void Extent(G4ThreeVector &pMin, G4ThreeVector &pMax) const 
 
static constexpr double halfpi
 
G4double GetOuterRadius() const 
 
G4CSGSolid & operator=(const G4CSGSolid &rhs)
 
G4double GetDeltaThetaAngle() const 
 
G4double GetAngularTolerance() const 
 
static G4GeometryTolerance * GetInstance()
 
G4double GetCosEndPhi() const 
 
void DescribeYourselfTo(G4VGraphicsScene &scene) const