42 #if !defined(G4GEOM_USE_UPOLYCONE)
53 using namespace CLHEP;
80 for (i=0; i<numZPlanes; i++)
82 if(rInner[i]>rOuter[i])
85 std::ostringstream message;
86 message <<
"Cannot create a Polycone with rInner > rOuter for the same Z"
88 <<
" rInner > rOuter for the same Z !" <<
G4endl
89 <<
" rMin[" << i <<
"] = " << rInner[i]
90 <<
" -- rMax[" << i <<
"] = " << rOuter[i];
91 G4Exception(
"G4Polycone::G4Polycone()",
"GeomSolids0002",
94 if (( i < numZPlanes-1) && ( zPlane[i] == zPlane[i+1] ))
96 if( (rInner[i] > rOuter[i+1])
97 ||(rInner[i+1] > rOuter[i]) )
100 std::ostringstream message;
101 message <<
"Cannot create a Polycone with no contiguous segments."
103 <<
" Segments are not contiguous !" <<
G4endl
104 <<
" rMin[" << i <<
"] = " << rInner[i]
105 <<
" -- rMax[" << i+1 <<
"] = " << rOuter[i+1] <<
G4endl
106 <<
" rMin[" << i+1 <<
"] = " << rInner[i+1]
107 <<
" -- rMax[" << i <<
"] = " << rOuter[i];
108 G4Exception(
"G4Polycone::G4Polycone()",
"GeomSolids0002",
126 Create( phiStart, phiTotal, rz );
146 Create( phiStart, phiTotal, rz );
155 std::ostringstream message;
156 message <<
"Polycone " <<
GetName() <<
"cannot be converted" <<
G4endl
157 <<
"to Polycone with (Rmin,Rmaz,Z) parameters!";
158 G4Exception(
"G4Polycone::G4Polycone()",
"GeomSolids0002",
164 <<
"to optimized polycone with (Rmin,Rmaz,Z) parameters !"
183 if (rz->
Amin() < 0.0)
185 std::ostringstream message;
186 message <<
"Illegal input parameters - " <<
GetName() <<
G4endl
187 <<
" All R values must be >= 0 !";
188 G4Exception(
"G4Polycone::Create()",
"GeomSolids0002",
198 std::ostringstream message;
199 message <<
"Illegal input parameters - " <<
GetName() <<
G4endl
200 <<
" R/Z cross section is zero or near zero: " << rzArea;
201 G4Exception(
"G4Polycone::Create()",
"GeomSolids0002",
208 std::ostringstream message;
209 message <<
"Illegal input parameters - " <<
GetName() <<
G4endl
210 <<
" Too few unique R/Z values !";
211 G4Exception(
"G4Polycone::Create()",
"GeomSolids0002",
217 std::ostringstream message;
218 message <<
"Illegal input parameters - " <<
GetName() <<
G4endl
219 <<
" R/Z segments cross !";
220 G4Exception(
"G4Polycone::Create()",
"GeomSolids0002",
230 if (phiTotal <= 0 || phiTotal >
twopi-1E-10)
247 endPhi = phiStart+phiTotal;
266 next->
r = iterRZ.
GetA();
267 next->
z = iterRZ.
GetB();
268 }
while( ++next, iterRZ.
Next() );
300 if (corner->
z > next->
z)
317 }
while( prev=corner, corner=next, corner >
corners );
346 :
G4VCSGfaceted(a), startPhi(0.), endPhi(0.), phiIsOpen(false),
347 numCorner(0), corners(0),original_parameters(0),
379 if (
this == &source)
return *
this;
548 G4int oldprc = os.precision(16);
549 os <<
"-----------------------------------------------------------\n"
550 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
551 <<
" ===================================================\n"
552 <<
" Solid type: G4Polycone\n"
555 <<
" ending phi angle : " <<
endPhi/
degree <<
" degrees \n";
559 os <<
" number of Z planes: " << numPlanes <<
"\n"
561 for (i=0; i<numPlanes; i++)
563 os <<
" Z plane " << i <<
": "
566 os <<
" Tangent distances to inner surface (Rmin): \n";
567 for (i=0; i<numPlanes; i++)
569 os <<
" Z plane " << i <<
": "
572 os <<
" Tangent distances to outer surface (Rmax): \n";
573 for (i=0; i<numPlanes; i++)
575 os <<
" Z plane " << i <<
": "
579 os <<
" number of RZ points: " <<
numCorner <<
"\n"
580 <<
" RZ values (corners): \n";
586 os <<
"-----------------------------------------------------------\n";
587 os.precision(oldprc);
605 G4double Aone, Atwo, Afive, phi, zRand, fDPhi, cosu, sinu;
606 G4double rRand1, rmin, rmax, chose, rone, rtwo, qone, qtwo;
607 G4double fDz=(zTwo-zOne)/2., afDz=std::fabs(fDz);
610 rone = (fRmax1-fRmax2)/(2.*fDz);
611 rtwo = (fRmin1-fRmin2)/(2.*fDz);
612 if(fRmax1==fRmax2){qone=0.;}
614 qone = fDz*(fRmax1+fRmax2)/(fRmax1-fRmax2);
616 if(fRmin1==fRmin2){qtwo=0.;}
618 qtwo = fDz*(fRmin1+fRmin2)/(fRmin1-fRmin2);
620 Aone = 0.5*fDPhi*(fRmax2 + fRmax1)*(
sqr(fRmin1-fRmin2)+
sqr(zTwo-zOne));
621 Atwo = 0.5*fDPhi*(fRmin2 + fRmin1)*(
sqr(fRmax1-fRmax2)+
sqr(zTwo-zOne));
622 Afive = fDz*(fRmax1-fRmin1+fRmax2-fRmin2);
623 totArea = Aone+Atwo+2.*Afive;
626 cosu = std::cos(phi);
627 sinu = std::sin(phi);
630 if( (startPhi == 0) && (
endPhi ==
twopi) ) { Afive = 0; }
632 if( (chose >= 0) && (chose < Aone) )
638 rone*sinu*(qone-zRand), zRand);
647 else if(chose >= Aone && chose < Aone + Atwo)
653 rtwo*sinu*(qtwo-zRand), zRand);
662 else if( (chose >= Aone + Atwo + Afive) && (chose < Aone + Atwo + 2.*Afive) )
665 rmin = fRmin2-((zRand-fDz)/(2.*fDz))*(fRmin1-fRmin2);
666 rmax = fRmax2-((zRand-fDz)/(2.*fDz))*(fRmax1-fRmax2);
669 rRand1*std::sin(startPhi), zRand);
674 rmin = fRmin2-((zRand-fDz)/(2.*fDz))*(fRmin1-fRmin2);
675 rmax = fRmax2-((zRand-fDz)/(2.*fDz))*(fRmax1-fRmax2);
678 rRand1*std::sin(
endPhi), zRand);
695 G4double xRand,yRand,zRand,phi,cosphi,sinphi,chose,
696 aOne,aTwo,aFou,rRand,fDz,fSPhi,fDPhi;
697 fDz = std::fabs(0.5*(zTwo-zOne));
701 aOne = 2.*fDz*fDPhi*fRMax;
702 aTwo = 2.*fDz*fDPhi*fRMin;
703 aFou = 2.*fDz*(fRMax-fRMin);
704 totArea = aOne+aTwo+2.*aFou;
706 cosphi = std::cos(phi);
707 sinphi = std::sin(phi);
714 if( (chose >= 0) && (chose < aOne) )
716 xRand = fRMax*cosphi;
717 yRand = fRMax*sinphi;
721 else if( (chose >= aOne) && (chose < aOne + aTwo) )
723 xRand = fRMin*cosphi;
724 yRand = fRMin*sinphi;
728 else if( (chose >= aOne+aTwo) && (chose <aOne+aTwo+aFou) )
730 xRand = rRand*std::cos(fSPhi+fDPhi);
731 yRand = rRand*std::sin(fSPhi+fDPhi);
738 xRand = rRand*std::cos(fSPhi+fDPhi);
739 yRand = rRand*std::sin(fSPhi+fDPhi);
754 G4double xRand,yRand,phi,cosphi,sinphi,rRand1,rRand2,A1,Atot,rCh;
756 cosphi = std::cos(phi);
757 sinphi = std::sin(phi);
761 rRand1 = fRMin1; A1=0.;
766 A1=std::fabs(fRMin2*fRMin2-fRMin1*fRMin1);
770 rRand2=fRMax1; Atot=A1;
775 Atot = A1+std::fabs(fRMax2*fRMax2-fRMax1*fRMax1);
779 if(rCh>A1) { rRand1=rRand2; }
781 xRand = rRand1*cosphi;
782 yRand = rRand1*sinphi;
801 if( (fRMin1 == fRMin2) && (fRMax1 == fRMax2) )
805 return GetPointOnCone(fRMin1,fRMax1,fRMin2,fRMax2,zOne,zTwo,totArea);
814 G4double Area=0,totArea=0,Achose1=0,Achose2=0,phi,cosphi,sinphi,rRand;
819 cosphi = std::cos(phi);
820 sinphi = std::sin(phi);
826 std::vector<G4double> areas;
827 std::vector<G4ThreeVector> points;
832 for(i=0; i<numPlanes-1; i++)
857 areas.push_back(Area);
864 totArea += (areas[0]+areas[numPlanes]);
867 if( (chose>=0.) && (chose<areas[0]) )
873 for (i=0; i<numPlanes-1; i++)
876 Achose2 = (Achose1+areas[i+1]);
877 if(chose>=Achose1 && chose<Achose2)
917 G4bool isConvertible=
true;
923 std::vector<G4double> Z;
924 std::vector<G4double> Rmin;
925 std::vector<G4double> Rmax;
938 Rmax.push_back (
corners[1].r);icurr=1;
940 else if (Zprev ==
corners[numPlanes-1].z)
942 Rmin.push_back(
corners[numPlanes-1].r);
954 G4int inextr=0, inextl=0;
955 for (
G4int i=0; i < numPlanes-2; i++)
958 inextl=(icurl <= 0)? numPlanes-1 : icurl-1;
960 if((
corners[inextr].z >= Zmax) & (
corners[inextl].
z >= Zmax)) {
break; }
975 Rmin.push_back(
corners[inextl].r);
976 Rmax.push_back(
corners[icurr].r);
980 Rmin.push_back(
corners[inextl].r);
989 Rmin.push_back(
corners[icurl].r);
990 Rmax.push_back(
corners[icurr].r);
994 Rmin.push_back(
corners[icurl].r);
1001 isConvertible=
false;
break;
1003 icurl=(icurl == 0)? numPlanes-1 : icurl-1;
1011 icurl=(icurl == 0)? numPlanes-1 : icurl-1;
1013 Rmin.push_back(
corners[inextl].r);
1014 Rmax.push_back(
corners[inextr].r);
1018 Z.push_back(Zright);
1027 Rmax.push_back(
corners[inextr].r);
1028 Rmin.push_back(
corners[icurr].r);
1032 Rmin.push_back(
corners[icurl].r + (Zright-
corners[icurl].z)/difZl
1034 Rmax.push_back(
corners[inextr].r);
1042 Rmax.push_back(
corners[inextr].r);
1043 Rmin.push_back (
corners[icurr].r);
1047 Rmax.push_back(
corners[inextr].r);
1055 isConvertible=
false;
break;
1065 inextl=(icurl <= 0)? numPlanes-1 : icurl-1;
1067 Rmax.push_back(
corners[inextr].r);
1068 Rmin.push_back(
corners[inextl].r);
1079 for(
G4int j=0; j < countPlanes; j++)
1093 std::ostringstream message;
1095 <<
"cannot be converted to Polycone with (Rmin,Rmaz,Z) parameters!";
1096 G4Exception(
"G4Polycone::SetOriginalParameters()",
"GeomSolids0002",
1104 for(
G4int j=0; j < numPlanes; j++)
1114 return isConvertible;
G4bool CrossesItself(G4double tolerance)
G4Polyhedron * CreatePolyhedron() const
ThreeVector shoot(const G4int Ap, const G4int Af)
G4VCSGfaceted & operator=(const G4VCSGfaceted &source)
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
G4bool fRebuildPolyhedron
G4Polyhedron * fpPolyhedron
static const G4double kInfinity
CLHEP::Hep3Vector G4ThreeVector
G4ThreeVector GetPointOnSurface() const
G4ThreeVector GetPointOnRing(G4double fRMin, G4double fRMax, G4double fRMin2, G4double fRMax2, G4double zOne) const
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
G4bool MustBeOutside(const G4ThreeVector &p) const
G4PolyconeSideRZ * corners
std::ostream & StreamInfo(std::ostream &os) const
G4ThreeVector GetPointOnCone(G4double fRmin1, G4double fRmax1, G4double fRmin2, G4double fRmax2, G4double zOne, G4double zTwo, G4double &totArea) const
G4GeometryType GetEntityType() const
G4ThreeVector GetPointOnCut(G4double fRMin1, G4double fRMax1, G4double fRMin2, G4double fRMax2, G4double zOne, G4double zTwo, G4double &totArea) const
G4bool RemoveDuplicateVertices(G4double tolerance)
G4bool RemoveRedundantVertices(G4double tolerance)
G4Polycone & operator=(const G4Polycone &source)
G4GLOB_DLL std::ostream G4cout
G4int NumVertices() const
static const double twopi
void SetOriginalParameters(G4PolyconeHistorical *pars)
EInside Inside(const G4ThreeVector &p) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
void CopyStuff(const G4Polycone &source)
G4EnclosingCylinder * enclosingCylinder
G4ThreeVector GetPointOnTubs(G4double fRMin, G4double fRMax, G4double zOne, G4double zTwo, G4double &totArea) const
static const double degree
G4bool BisectedBy(G4double a1, G4double b1, G4double a2, G4double b2, G4double tolerance)
G4Polycone(const G4String &name, G4double phiStart, G4double phiTotal, G4int numZPlanes, const G4double zPlane[], const G4double rInner[], const G4double rOuter[])
void Create(G4double phiStart, G4double phiTotal, G4ReduciblePolygon *rz)
G4PolyconeHistorical * original_parameters
virtual EInside Inside(const G4ThreeVector &p) const
G4bool ShouldMiss(const G4ThreeVector &p, const G4ThreeVector &v) const