62 #if !(defined(G4GEOM_USE_UTORUS) && defined(G4GEOM_USE_SYS_USOLIDS)) 
   80 using namespace CLHEP;
 
  119   halfAngTolerance = 0.5*kAngTolerance;
 
  127     std::ostringstream message;
 
  128     message << 
"Invalid swept radius for Solid: " << 
GetName() << 
G4endl 
  129             << 
"        pRtor = " << pRtor << 
", pRmax = " << pRmax;
 
  136   if ( pRmin < pRmax - 1.e2*kCarTolerance && pRmin >= 0 )
 
  138     if (pRmin >= 1.e2*kCarTolerance) { fRmin = pRmin ; }
 
  139     else                             { fRmin = 0.0   ; }
 
  144     std::ostringstream message;
 
  145     message << 
"Invalid values of radii for Solid: " << 
GetName() << 
G4endl 
  146             << 
"        pRmin = " << pRmin << 
", pRmax = " << pRmax;
 
  153   fRminTolerance = (fRmin)
 
  154                  ? 0.5*
std::max( kRadTolerance, fEpsilon*(fRtor-fRmin )) : 0;
 
  155   fRmaxTolerance = 0.5*
std::max( kRadTolerance, fEpsilon*(fRtor+fRmax) );
 
  162     if (pDPhi > 0)       { fDPhi = pDPhi ; }
 
  165       std::ostringstream message;
 
  166       message << 
"Invalid Z delta-Phi for Solid: " << 
GetName() << 
G4endl 
  167               << 
"        pDPhi = " << pDPhi;
 
  177   if (fSPhi < 0)  { fSPhi = 
twopi-std::fmod(std::fabs(fSPhi),
twopi) ; }
 
  178   else            { fSPhi = std::fmod(fSPhi,
twopi) ; }
 
  189   : 
G4CSGSolid(a), fRmin(0.), fRmax(0.), fRtor(0.), fSPhi(0.),
 
  190     fDPhi(0.), fRminTolerance(0.), fRmaxTolerance(0. ),
 
  191     kRadTolerance(0.), kAngTolerance(0.),
 
  192     halfCarTolerance(0.), halfAngTolerance(0.)
 
  208   : 
G4CSGSolid(rhs), fRmin(rhs.fRmin),fRmax(rhs.fRmax),
 
  209     fRtor(rhs.fRtor),fSPhi(rhs.fSPhi),fDPhi(rhs.fDPhi),
 
  210     fRminTolerance(rhs.fRminTolerance), fRmaxTolerance(rhs.fRmaxTolerance),
 
  211     kRadTolerance(rhs.kRadTolerance), kAngTolerance(rhs.kAngTolerance),
 
  212     halfCarTolerance(rhs.halfCarTolerance),
 
  213     halfAngTolerance(rhs.halfAngTolerance)
 
  225    if (
this == &rhs)  { 
return *
this; }
 
  233    fRmin = rhs.fRmin; fRmax = rhs.fRmax;
 
  234    fRtor = rhs.fRtor; fSPhi = rhs.fSPhi; fDPhi = rhs.fDPhi;
 
  235    fRminTolerance = rhs.fRminTolerance; fRmaxTolerance = rhs.fRmaxTolerance;
 
  236    kRadTolerance = rhs.kRadTolerance; kAngTolerance = rhs.kAngTolerance;
 
  237    halfCarTolerance = rhs.halfCarTolerance;
 
  238    halfAngTolerance = rhs.halfAngTolerance;
 
  265                                   std::vector<G4double>& roots )
 const 
  271   G4double Rtor2 = fRtor*fRtor, r2 = r*r  ;
 
  279   c[2] = 2*( (d + 2*pDotV*pDotV  - r2) + 2*Rtor2*v.
z()*v.
z());
 
  280   c[3] = 4*(pDotV*(d - r2) + 2*Rtor2*p.
z()*v.
z()) ;
 
  281   c[4] = (d-r2)*(d-r2) +4*Rtor2*(p.
z()*p.
z()-r2);
 
  285   num = torusEq.
FindRoots( c, 4, srd, si );
 
  287   for ( i = 0; i < num; i++ ) 
 
  289     if( si[i] == 0. )  { roots.push_back(srd[i]) ; }  
 
  292   std::sort(roots.begin() , roots.end() ) ;  
 
  305                                         G4bool IsDistanceToIn )
 const 
  314   std::vector<G4double> roots ;
 
  315   std::vector<G4double> rootsrefined ;
 
  316   TorusRootsJT(p,v,r,roots) ;
 
  322   for ( 
size_t k = 0 ; k<roots.size() ; k++ )
 
  326     if ( t < -halfCarTolerance )  { continue ; }  
 
  331       TorusRootsJT(ptmp,v,r,rootsrefined) ;
 
  332       if ( rootsrefined.size()==roots.size() )
 
  334         t = t + rootsrefined[k] ;
 
  340     G4double theta = std::atan2(ptmp.
y(),ptmp.
x());
 
  344       if ( theta < - halfAngTolerance )  { theta += 
twopi; }
 
  345       if ( (std::fabs(theta) < halfAngTolerance)
 
  346         && (std::fabs(fSPhi + fDPhi - 
twopi) < halfAngTolerance) )
 
  351     if ((fSPhi <= -
pi )&&(theta>halfAngTolerance)) { theta = theta-
twopi; }
 
  356     if ( (theta - fSPhi >= - halfAngTolerance)
 
  357       && (theta - (fSPhi + fDPhi) <=  halfAngTolerance) )
 
  362       if ( IsDistanceToIn == 
true )
 
  364         if (std::fabs(t) < halfCarTolerance )
 
  370                                    p.
y()*(1-fRtor/std::hypot(p.
x(),p.
y())),
 
  375           if ( r == 
GetRmin() )  { scal = -scal ; }
 
  376           if ( scal < 0 )  { 
return 0.0  ; }
 
  383       if ( IsDistanceToIn == 
false )
 
  385         if (std::fabs(t) < halfCarTolerance )
 
  390                                    p.
y()*(1-fRtor/std::hypot(p.
x(),p.
y())),
 
  395           if ( r == 
GetRmin() )  { scal = -scal ; }
 
  396           if ( scal > 0 )  { 
return 0.0  ; }
 
  402       if(  t > halfCarTolerance  )
 
  429     pMin.
set(-rext,-rext,-dz);
 
  430     pMax.
set( rext, rext, dz);
 
  439     pMin.
set(vmin.
x(),vmin.
y(),-dz);
 
  440     pMax.
set(vmax.
x(),vmax.
y(), dz);
 
  445   if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
 
  447     std::ostringstream message;
 
  448     message << 
"Bad bounding box (min >= max) for solid: " 
  450             << 
"\npMin = " << pMin
 
  451             << 
"\npMax = " << pMax;
 
  475   if (
true) 
return bbox.
CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
 
  479     return exist = (pMin < pMax) ? 
true : 
false;
 
  496   static const G4int NPHI  = 24; 
 
  497   static const G4int NDISK = 16; 
 
  498   static const G4double sinHalfDisk = std::sin(
pi/NDISK);
 
  499   static const G4double cosHalfDisk = std::cos(
pi/NDISK);
 
  500   static const G4double sinStepDisk = 2.*sinHalfDisk*cosHalfDisk;
 
  501   static const G4double cosStepDisk = 1. - 2.*sinHalfDisk*sinHalfDisk;
 
  507   G4double sinHalf = std::sin(0.5*ang);
 
  508   G4double cosHalf = std::cos(0.5*ang);
 
  509   G4double sinStep = 2.*sinHalf*cosHalf;
 
  510   G4double cosStep = 1. - 2.*sinHalf*sinHalf;
 
  514   for (
G4int k=0; k<NDISK+1; ++k) pols[k].resize(4);
 
  516   std::vector<const G4ThreeVectorList *> polygons;
 
  517   polygons.resize(NDISK+1);
 
  518   for (
G4int k=0; k<NDISK+1; ++k) polygons[k] = &pols[k];
 
  524   if ((rtor-rmin*sinHalfDisk)/cosHalf > (rtor+rmin*sinHalfDisk)) rmin = 0;
 
  528   for (
G4int k=0; k<NDISK; ++k)
 
  530     G4double rmincur = rtor + rmin*cosCurDisk;
 
  531     if (cosCurDisk < 0 && rmin > 0) rmincur /= cosHalf;
 
  532     rzmin[k].
set(rmincur,rmin*sinCurDisk);
 
  534     G4double rmaxcur = rtor + rmax*cosCurDisk;
 
  535     if (cosCurDisk > 0) rmaxcur /= cosHalf;
 
  536     rzmax[k].
set(rmaxcur,rmax*sinCurDisk);
 
  539     sinCurDisk = sinCurDisk*cosStepDisk + cosCurDisk*sinStepDisk;
 
  540     cosCurDisk = cosCurDisk*cosStepDisk - sinTmpDisk*sinStepDisk;
 
  549   G4double sinCur1 = 0, cosCur1 = 0, sinCur2 = 0, cosCur2 = 0;
 
  550   for (
G4int i=0; i<kphi+1; ++i)
 
  556       sinCur2 = sinCur1*cosHalf + cosCur1*sinHalf;
 
  557       cosCur2 = cosCur1*cosHalf - sinCur1*sinHalf;
 
  563       sinCur2 = (i == kphi) ? sinEnd : sinCur1*cosStep + cosCur1*sinStep;
 
  564       cosCur2 = (i == kphi) ? cosEnd : cosCur1*cosStep - sinCur1*sinStep;
 
  566     for (
G4int k=0; k<NDISK; ++k)
 
  568       G4double r1 = rzmin[k].
x(), r2 = rzmax[k].
x();
 
  569       G4double z1 = rzmin[k].
y(), z2 = rzmax[k].
y();
 
  570       pols[k][0].set(r1*cosCur1,r1*sinCur1,z1);
 
  571       pols[k][1].set(r2*cosCur1,r2*sinCur1,z2);
 
  572       pols[k][2].set(r2*cosCur2,r2*sinCur2,z2);
 
  573       pols[k][3].set(r1*cosCur2,r1*sinCur2,z1);
 
  575     pols[NDISK] = pols[0];
 
  580       DiskExtent(rint,rext,sinCur1,cosCur1,sinCur2,cosCur2,vmin,vmax);
 
  587     if (!benv.
CalculateExtent(pAxis,pVoxelLimit,pTransform,emin,emax)) 
continue;
 
  588     if (emin < pMin) pMin = emin;
 
  589     if (emax > pMax) pMax = 
emax;
 
  590     if (eminlim > pMin && emaxlim < pMax) 
break; 
 
  592   return (pMin < pMax);
 
  601   G4double r, pt2, pPhi, tolRMin, tolRMax ;
 
  607   r   = std::hypot(p.
x(),p.
y());
 
  608   pt2 = p.
z()*p.
z() + (r-fRtor)*(r-fRtor);
 
  610   if (fRmin) tolRMin = fRmin + fRminTolerance ;
 
  613   tolRMax = fRmax - fRmaxTolerance;
 
  615   if (pt2 >= tolRMin*tolRMin && pt2 <= tolRMax*tolRMax )
 
  617     if ( fDPhi == 
twopi || pt2 == 0 )  
 
  626       pPhi = std::atan2(p.
y(),p.
x()) ;
 
  628       if ( pPhi < -halfAngTolerance )  { pPhi += 
twopi ; }  
 
  631         if ( (std::fabs(pPhi) < halfAngTolerance)
 
  632             && (std::fabs(fSPhi + fDPhi - 
twopi) < halfAngTolerance) )
 
  636         if ( (pPhi >= fSPhi + halfAngTolerance)
 
  637             && (pPhi <= fSPhi + fDPhi - halfAngTolerance) )
 
  641           else if ( (pPhi >= fSPhi - halfAngTolerance)
 
  642                  && (pPhi <= fSPhi + fDPhi + halfAngTolerance) )
 
  649           if ( (pPhi <= fSPhi + 
twopi - halfAngTolerance)
 
  650             && (pPhi >= fSPhi + fDPhi  + halfAngTolerance) )  {;}
 
  660     tolRMin = fRmin - fRminTolerance ;
 
  661     tolRMax = fRmax + fRmaxTolerance ;
 
  663     if (tolRMin < 0 )  { tolRMin = 0 ; }
 
  665     if ( (pt2 >= tolRMin*tolRMin) && (pt2 <= tolRMax*tolRMax) )
 
  667       if ( (fDPhi == 
twopi) || (pt2 == 0) ) 
 
  673         pPhi = std::atan2(p.
y(),p.
x()) ;
 
  675         if ( pPhi < -halfAngTolerance )  { pPhi += 
twopi ; }  
 
  678           if ( (std::fabs(pPhi) < halfAngTolerance)
 
  679             && (std::fabs(fSPhi + fDPhi - 
twopi) < halfAngTolerance) )
 
  683           if ( (pPhi >= fSPhi - halfAngTolerance)
 
  684             && (pPhi <= fSPhi + fDPhi + halfAngTolerance) )
 
  691           if ( (pPhi <= fSPhi + 
twopi - halfAngTolerance)
 
  692             && (pPhi >= fSPhi + fDPhi  + halfAngTolerance) )  {;}
 
  712   G4int noSurfaces = 0;  
 
  720                                   1.0e-8*(fRtor+fRmax));
 
  721   const G4double dAngle = 10.0*kAngTolerance;
 
  726   rho = std::hypot(p.
x(),p.
y());
 
  727   pt  = std::hypot(p.
z(),rho-fRtor);
 
  729   G4double  distRMax = std::fabs(pt - fRmax);
 
  730   if(fRmin) distRMin = std::fabs(pt - fRmin);
 
  732   if( rho > delta && pt != 0.0 )
 
  734     G4double redFactor= (rho-fRtor)/rho;
 
  745       pPhi = std::atan2(p.
y(),p.
x());
 
  747       if(pPhi < fSPhi-delta)            { pPhi += 
twopi; }
 
  748       else if(pPhi > fSPhi+fDPhi+delta) { pPhi -= 
twopi; }
 
  750       distSPhi = std::fabs( pPhi - fSPhi );
 
  751       distEPhi = std::fabs(pPhi-fSPhi-fDPhi);
 
  754     nPe = 
G4ThreeVector(-std::sin(fSPhi+fDPhi),std::cos(fSPhi+fDPhi),0);
 
  756   if( distRMax <= delta )
 
  761   else if( fRmin && (distRMin <= delta) ) 
 
  770   if( (fDPhi < 
twopi) && (fRmin-delta <= pt) && (pt <= (fRmax+delta)) )
 
  772     if (distSPhi <= dAngle)
 
  777     if (distEPhi <= dAngle) 
 
  783   if ( noSurfaces == 0 )
 
  793         ed << 
" ERROR>  Surface Normal was called for Torus," 
  794            << 
" with point not on surface." << 
G4endl;
 
  798         ed << 
" ERROR>  Surface Normal has not found a surface, " 
  799            << 
" despite the point being on the surface. " <<
G4endl;
 
  810      ed << 
" Coordinates of point : " << p << 
G4endl;
 
  811      ed << 
" Parameters  of solid : " << G4endl << *
this << 
G4endl;
 
  815         G4Exception(
"G4Torus::SurfaceNormal(p)", 
"GeomSolids1002",
 
  817                     "Failing to find normal, even though point is on surface!");
 
  821         static const char* NameInside[3]= { 
"Inside", 
"Surface", 
"Outside" };
 
  822         ed << 
"  The point is " << NameInside[inIt] << 
" the solid. "<< 
G4endl;
 
  823         G4Exception(
"G4Torus::SurfaceNormal(p)", 
"GeomSolids1002",
 
  827      norm = ApproxSurfaceNormal(p);
 
  829   else if ( noSurfaces == 1 )  { norm = sumnorm; }
 
  830   else                         { norm = sumnorm.
unit(); }
 
  845   G4double distRMin,distRMax,distSPhi,distEPhi,distMin;
 
  847   rho = std::hypot(p.
x(),p.
y());
 
  848   pt  = std::hypot(p.
z(),rho-fRtor);
 
  851   G4cout << 
" G4Torus::ApproximateSurfaceNormal called for point " << p
 
  855   distRMax = std::fabs(pt - fRmax) ;
 
  859     distRMin = std::fabs(pt - fRmin) ;
 
  861     if (distRMin < distRMax)
 
  877   if ( (fDPhi < 
twopi) && rho )
 
  879     phi = std::atan2(p.
y(),p.
x()) ; 
 
  881     if (phi < 0)  { phi += 
twopi ; }
 
  883     if (fSPhi < 0 )  { distSPhi = std::fabs(phi-(fSPhi+
twopi))*rho ; }
 
  884     else             { distSPhi = std::fabs(phi-fSPhi)*rho ; }
 
  886     distEPhi = std::fabs(phi - fSPhi - fDPhi)*rho ;
 
  888     if (distSPhi < distEPhi) 
 
  890       if (distSPhi<distMin) side = kNSPhi ;
 
  894       if (distEPhi < distMin)  { side = kNEPhi ; }
 
  901                             -p.
y()*(1-fRtor/rho)/pt,
 
  906                             p.
y()*(1-fRtor/rho)/pt,
 
  913       norm = 
G4ThreeVector(-std::sin(fSPhi+fDPhi),std::cos(fSPhi+fDPhi),0) ;
 
  919                   "Undefined side for valid surface normal to solid.");
 
  960   G4double cPhi,sinCPhi=0.,cosCPhi=0.;  
 
  977     cPhi       = fSPhi + hDPhi ;
 
  978     sinCPhi    = std::sin(cPhi) ;
 
  979     cosCPhi    = std::cos(cPhi) ;
 
  986   if (fRmin > fRminTolerance) 
 
  988     tolORMin2 = (fRmin - fRminTolerance)*(fRmin - fRminTolerance) ;
 
  994   tolORMax2 = (fRmax + fRmaxTolerance)*(fRmax + fRmaxTolerance) ;
 
  998   snxt = SolveNumericJT(p,v,fRmax,
true);
 
 1002     sd[0] = SolveNumericJT(p,v,fRmin,
true);
 
 1003     if ( sd[0] < snxt )  { snxt = sd[0] ; }
 
 1018     sinSPhi = std::sin(fSPhi) ; 
 
 1019     cosSPhi = std::cos(fSPhi) ;
 
 1020     Comp    = v.
x()*sinSPhi - v.
y()*cosSPhi ;  
 
 1024       Dist = (p.
y()*cosSPhi - p.
x()*sinSPhi) ;
 
 1026       if (Dist < halfCarTolerance)
 
 1031           if ( sphi < 0 )  { sphi = 0 ; }
 
 1033           xi    = p.
x() + sphi*v.
x() ;
 
 1034           yi    = p.
y() + sphi*v.
y() ;
 
 1035           zi    = p.
z() + sphi*v.
z() ;
 
 1036           rhoi = std::hypot(xi,yi);
 
 1037           it2 = zi*zi + (rhoi-fRtor)*(rhoi-fRtor);
 
 1039           if ( it2 >= tolORMin2 && it2 <= tolORMax2 )
 
 1044             if ((yi*cosCPhi-xi*sinCPhi)<=0)  { snxt=sphi; }
 
 1050     sinEPhi=std::sin(ePhi);
 
 1051     cosEPhi=std::cos(ePhi);
 
 1052     Comp=-(v.
x()*sinEPhi-v.
y()*cosEPhi);
 
 1056       Dist = -(p.
y()*cosEPhi - p.
x()*sinEPhi) ;
 
 1058       if (Dist < halfCarTolerance )
 
 1064           if (sphi < 0 )  { sphi = 0 ; }
 
 1066           xi    = p.
x() + sphi*v.
x() ;
 
 1067           yi    = p.
y() + sphi*v.
y() ;
 
 1068           zi    = p.
z() + sphi*v.
z() ;
 
 1069           rhoi = std::hypot(xi,yi);
 
 1070           it2 = zi*zi + (rhoi-fRtor)*(rhoi-fRtor);
 
 1072           if (it2 >= tolORMin2 && it2 <= tolORMax2)
 
 1077             if ((yi*cosCPhi-xi*sinCPhi)>=0)  { snxt=sphi; }
 
 1083   if(snxt < halfCarTolerance)  { snxt = 0.0 ; }
 
 1098   G4double phiC, cosPhiC, sinPhiC, safePhi, ePhi, cosPsi ;
 
 1101   rho = std::hypot(p.
x(),p.
y());
 
 1102   pt  = std::hypot(p.
z(),rho-fRtor);
 
 1103   safe1 = fRmin - pt ;
 
 1104   safe2 = pt - fRmax ;
 
 1106   if (safe1 > safe2)  { safe = safe1; }
 
 1107   else                { safe = safe2; }
 
 1109   if ( fDPhi < 
twopi && rho )
 
 1111     phiC    = fSPhi + fDPhi*0.5 ;
 
 1112     cosPhiC = std::cos(phiC) ;
 
 1113     sinPhiC = std::sin(phiC) ;
 
 1114     cosPsi  = (p.
x()*cosPhiC + p.
y()*sinPhiC)/rho ;
 
 1116     if (cosPsi < std::cos(fDPhi*0.5) ) 
 
 1118       if ((p.
y()*cosPhiC - p.
x()*sinPhiC) <= 0 )
 
 1120         safePhi = std::fabs(p.
x()*std::sin(fSPhi) - p.
y()*std::cos(fSPhi)) ;
 
 1124         ePhi    = fSPhi + fDPhi ;
 
 1125         safePhi = std::fabs(p.
x()*std::sin(ePhi) - p.
y()*std::cos(ePhi)) ;
 
 1127       if (safePhi > safe)  { safe = safePhi ; }
 
 1130   if (safe < 0 )  { safe = 0 ; }
 
 1146   ESide    side = kNull, sidephi = kNull ;
 
 1151   G4double sinSPhi, cosSPhi, ePhi, sinEPhi, cosEPhi;
 
 1153   G4double pDistS, compS, pDistE, compE, sphi2, xi, yi, zi, vphi ;
 
 1171   G4double tolRMax = fRmax - fRmaxTolerance ;
 
 1173   G4double vDotNmax   = pDotV - fRtor*(v.
x()*p.
x() + v.
y()*p.
y())/rho ;
 
 1174   G4double pDotxyNmax = (1 - fRtor/rho) ;
 
 1176   if( (pt*pt > tolRMax*tolRMax) && (vDotNmax >= 0) )
 
 1182     if ( calcNorm && (pDotxyNmax >= -2.*fRmaxTolerance) ) 
 
 1185                           p.
y()*(1 - fRtor/rho)/pt,
 
 1193   snxt = SolveNumericJT(p,v,fRmax,
false);  
 
 1200     G4double tolRMin = fRmin + fRminTolerance ;
 
 1202     if ( (pt*pt < tolRMin*tolRMin) && (vDotNmax < 0) )
 
 1204       if (calcNorm)  { *validNorm = false ; } 
 
 1208     sd[0] = SolveNumericJT(p,v,fRmin,
false);
 
 1221   snxt = SolveNumericJT(p,v,fRmax,
false);  
 
 1226     sd[0] = SolveNumericJT(p,v,fRmin,
false);
 
 1234   if ( calcNorm && (snxt == 0.0) )
 
 1236     *validNorm = false ;    
 
 1244     sinSPhi = std::sin(fSPhi) ;
 
 1245     cosSPhi = std::cos(fSPhi) ;
 
 1246     ePhi    = fSPhi + fDPhi ;
 
 1247     sinEPhi = std::sin(ePhi) ;
 
 1248     cosEPhi = std::cos(ePhi) ;
 
 1249     cPhi    = fSPhi + fDPhi*0.5 ;
 
 1250     sinCPhi = std::sin(cPhi) ;
 
 1251     cosCPhi = std::cos(cPhi) ;
 
 1256     vphi = std::atan2(v.
y(),v.
x()) ;
 
 1258     if ( vphi < fSPhi - halfAngTolerance  )    { vphi += 
twopi; }
 
 1259     else if ( vphi > ePhi + halfAngTolerance ) { vphi -= 
twopi; }
 
 1261     if ( p.
x() || p.
y() ) 
 
 1263       pDistS = p.
x()*sinSPhi - p.
y()*cosSPhi ; 
 
 1264       pDistE = -p.
x()*sinEPhi + p.
y()*cosEPhi ;
 
 1268       compS   = -sinSPhi*v.
x() + cosSPhi*v.
y() ;
 
 1269       compE   = sinEPhi*v.
x() - cosEPhi*v.
y() ;
 
 1272       if( ( (fDPhi <= 
pi) && ( (pDistS <= halfCarTolerance)
 
 1273                             && (pDistE <= halfCarTolerance) ) )
 
 1274        || ( (fDPhi >  
pi) && !((pDistS >  halfCarTolerance)
 
 1275                             && (pDistE >  halfCarTolerance) ) )  )
 
 1281           sphi = pDistS/compS ;
 
 1283           if (sphi >= -halfCarTolerance)
 
 1285             xi = p.
x() + sphi*v.
x() ;
 
 1286             yi = p.
y() + sphi*v.
y() ;
 
 1295               if ( ((fSPhi-halfAngTolerance)<=vphi)
 
 1296                 && ((ePhi+halfAngTolerance)>=vphi) )
 
 1301             else if ( yi*cosCPhi-xi*sinCPhi >=0 )
 
 1322           sphi2 = pDistE/compE ;
 
 1328             xi = p.
x() + sphi2*v.
x() ;
 
 1329             yi = p.
y() + sphi2*v.
y() ;
 
 1336               if( !( (fSPhi-halfAngTolerance <= vphi)
 
 1337                   && (ePhi+halfAngTolerance >= vphi) ) )
 
 1345               if ( (yi*cosCPhi-xi*sinCPhi) >= 0)
 
 1367       vphi = std::atan2(v.
y(),v.
x());
 
 1369       if ( ( fSPhi-halfAngTolerance <= vphi ) && 
 
 1370            ( vphi <= ( ePhi+halfAngTolerance ) ) )
 
 1399         xi    = p.
x() + snxt*v.
x() ;
 
 1400         yi    = p.
y() + snxt*v.
y() ;
 
 1401         zi    = p.
z() + snxt*v.
z() ;
 
 1402         rhoi = std::hypot(xi,yi);
 
 1403         it = hypot(zi,rhoi-fRtor);
 
 1405         iDotxyNmax = (1-fRtor/rhoi) ;
 
 1406         if(iDotxyNmax >= -2.*fRmaxTolerance) 
 
 1409                               yi*(1-fRtor/rhoi)/it,
 
 1415           *validNorm = false ; 
 
 1420         *validNorm = false ;  
 
 1431           *validNorm = false ;
 
 1438           *n=
G4ThreeVector(-std::sin(fSPhi+fDPhi),std::cos(fSPhi+fDPhi),0);
 
 1443           *validNorm = false ;
 
 1453         std::ostringstream message;
 
 1454         G4int oldprc = message.precision(16);
 
 1455         message << 
"Undefined side for valid surface normal to solid." 
 1457                 << 
"Position:"  << G4endl << G4endl
 
 1458                 << 
"p.x() = "   << p.
x()/
mm << 
" mm" << G4endl
 
 1459                 << 
"p.y() = "   << p.
y()/
mm << 
" mm" << G4endl
 
 1460                 << 
"p.z() = "   << p.
z()/
mm << 
" mm" << G4endl << G4endl
 
 1461                 << 
"Direction:" << G4endl << G4endl
 
 1462                 << 
"v.x() = "   << v.
x() << G4endl
 
 1463                 << 
"v.y() = "   << v.
y() << G4endl
 
 1464                 << 
"v.z() = "   << v.
z() << G4endl << G4endl
 
 1465                 << 
"Proposed distance :" << G4endl << G4endl
 
 1466                 << 
"snxt = " << snxt/
mm << 
" mm" << 
G4endl;
 
 1467         message.precision(oldprc);
 
 1473   if ( snxt<halfCarTolerance )  { snxt=0 ; }
 
 1486   G4double safePhi,phiC,cosPhiC,sinPhiC,ePhi;
 
 1488   rho = std::hypot(p.
x(),p.
y());
 
 1489   pt  = std::hypot(p.
z(),rho-fRtor);
 
 1501      G4cout.precision(oldprc);
 
 1502      G4Exception(
"G4Torus::DistanceToOut(p)", 
"GeomSolids1002",
 
 1509     safeR1 = pt - fRmin ;
 
 1510     safeR2 = fRmax - pt ;
 
 1512     if (safeR1 < safeR2)  { safe = safeR1 ; }
 
 1513     else                  { safe = safeR2 ; }
 
 1524     phiC    = fSPhi + fDPhi*0.5 ;
 
 1525     cosPhiC = std::cos(phiC) ;
 
 1526     sinPhiC = std::sin(phiC) ;
 
 1528     if ((p.
y()*cosPhiC-p.
x()*sinPhiC)<=0)
 
 1530       safePhi = -(p.
x()*std::sin(fSPhi) - p.
y()*std::cos(fSPhi)) ;
 
 1534       ePhi    = fSPhi + fDPhi ;
 
 1535       safePhi = (p.
x()*std::sin(ePhi) - p.
y()*std::cos(ePhi)) ;
 
 1537     if (safePhi < safe)  { safe = safePhi ; }
 
 1539   if (safe < 0)  { safe = 0 ; }
 
 1567   G4int oldprc = os.precision(16);
 
 1568   os << 
"-----------------------------------------------------------\n" 
 1569      << 
"    *** Dump for solid - " << 
GetName() << 
" ***\n" 
 1570      << 
"    ===================================================\n" 
 1571      << 
" Solid type: G4Torus\n" 
 1572      << 
" Parameters: \n" 
 1573      << 
"    inner radius: " << fRmin/
mm << 
" mm \n" 
 1574      << 
"    outer radius: " << fRmax/
mm << 
" mm \n" 
 1575      << 
"    swept radius: " << fRtor/
mm << 
" mm \n" 
 1576      << 
"    starting phi: " << fSPhi/
degree << 
" degrees \n" 
 1577      << 
"    delta phi   : " << fDPhi/
degree << 
" degrees \n" 
 1578      << 
"-----------------------------------------------------------\n";
 
 1579   os.precision(oldprc);
 
 1590   G4double cosu, sinu,cosv, sinv, aOut, aIn, aSide, chose, phi, theta, rRand;
 
 1595   cosu   = std::cos(phi);    sinu = std::sin(phi);
 
 1596   cosv   = std::cos(theta);  sinv = std::sin(theta); 
 
 1600   aOut   = (fDPhi)*
twopi*fRtor*fRmax;
 
 1601   aIn    = (fDPhi)*
twopi*fRtor*fRmin;
 
 1602   aSide  = 
pi*(fRmax*fRmax-fRmin*fRmin);
 
 1604   if ((fSPhi == 0) && (fDPhi == 
twopi)){ aSide = 0; }
 
 1610                           (fRtor+fRmax*cosv)*sinu, fRmax*sinv);
 
 1612   else if( (chose >= aOut) && (chose < aOut + aIn) )
 
 1615                           (fRtor+fRmin*cosv)*sinu, fRmin*sinv);
 
 1617   else if( (chose >= aOut + aIn) && (chose < aOut + aIn + aSide) )
 
 1621                           (fRtor+rRand*cosv)*std::sin(fSPhi), rRand*sinv);
 
 1626     return G4ThreeVector ((fRtor+rRand*cosv)*std::cos(fSPhi+fDPhi),
 
 1627                           (fRtor+rRand*cosv)*std::sin(fSPhi+fDPhi), 
 
 1646 #endif // !defined(G4GEOM_USE_TORUS) || !defined(G4GEOM_USE_SYS_USOLIDS) 
void set(double x, double y, double z)
 
EInside Inside(const G4ThreeVector &p) const 
 
ThreeVector shoot(const G4int Ap, const G4int Af)
 
G4Polyhedron * CreatePolyhedron() const 
 
static constexpr double mm
 
static const G4double kInfinity
 
std::ostringstream G4ExceptionDescription
 
CLHEP::Hep3Vector G4ThreeVector
 
G4bool fRebuildPolyhedron
 
G4Torus & operator=(const G4Torus &rhs)
 
std::ostream & StreamInfo(std::ostream &os) const 
 
std::vector< ExP01TrackerHit * > a
 
G4double GetRadiusInRing(G4double rmin, G4double rmax) const 
 
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const 
 
G4double GetSinStartPhi() const 
 
virtual void AddSolid(const G4Box &)=0
 
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pmin, G4double &pmax) const 
 
static constexpr double twopi
 
G4double GetSinEndPhi() const 
 
void Extent(G4ThreeVector &pMin, G4ThreeVector &pMax) const 
 
G4GLOB_DLL std::ostream G4cout
 
static constexpr double degree
 
void set(double x, double y)
 
G4double GetCosEndPhi() const 
 
G4double GetRadialTolerance() const 
 
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimits, const G4Transform3D &pTransform3D, G4double &pMin, G4double &pMax) const 
 
G4bool BoundingBoxVsVoxelLimits(const EAxis pAxis, const G4VoxelLimits &pVoxelLimits, const G4Transform3D &pTransform3D, G4double &pMin, G4double &pMax) const 
 
G4Torus(const G4String &pName, G4double pRmin, G4double pRmax, G4double pRtor, G4double pSPhi, G4double pDPhi)
 
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const 
 
std::vector< G4ThreeVector > G4ThreeVectorList
 
G4ThreeVector GetPointOnSurface() const 
 
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
 
static const G4double emax
 
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const 
 
G4double GetCosStartPhi() const 
 
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
 
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=G4bool(false), G4bool *validNorm=0, G4ThreeVector *n=0) const 
 
T max(const T t1, const T t2)
brief Return the largest of the two arguments 
 
G4GeometryType GetEntityType() const 
 
static constexpr double pi
 
void SetAllParameters(G4double pRmin, G4double pRmax, G4double pRtor, G4double pSPhi, G4double pDPhi)
 
static constexpr double deg
 
G4double GetMaxExtent(const EAxis pAxis) const 
 
void DescribeYourselfTo(G4VGraphicsScene &scene) const 
 
G4CSGSolid & operator=(const G4CSGSolid &rhs)
 
G4int FindRoots(G4double *op, G4int degree, G4double *zeror, G4double *zeroi)
 
G4double GetAngularTolerance() const 
 
G4double GetMinExtent(const EAxis pAxis) const 
 
static G4GeometryTolerance * GetInstance()