36 const double zPlane[],
37 const double rInner[],
38 const double rOuter[])
43 Init(phiStart, phiTotal, numZPlanes, zPlane, rInner, rOuter);
66 std::ostringstream message;
67 message <<
"Polycone " <<
GetName() <<
"cannot be converted" << std::endl
68 <<
"to Polycone with (Rmin,Rmaz,Z) parameters! Use GenericPolycone" ;
74 std::cout <<
"INFO: Converting polycone " <<
GetName() << std::endl
75 <<
"to optimized polycone with (Rmin,Rmaz,Z) parameters !"
82 for (
int i = 0; i < num; i++)
90 Init(phiStart, phiTotal, num, Z, R1, R2);
106 const double zPlane[],
107 const double rInner[],
108 const double rOuter[])
127 endPhi = phiStart+phiTotal;
144 double RMaxextent=rOuter[0];
145 for (
int j=1; j < numZPlanes; j++)
147 if (rOuter[j] > RMaxextent) RMaxextent=rOuter[j];
148 if (rInner[j]>rOuter[j])
150 std::ostringstream message;
151 message <<
"Cannot create Polycone with rInner > rOuter for the same Z"
153 <<
" rInner > rOuter for the same Z !" << std::endl
154 <<
" rMin[" << j <<
"] = " << rInner[j]
155 <<
" -- rMax[" << j <<
"] = " << rOuter[j];
161 double prevZ = zPlane[0], prevRmax = 0, prevRmin = 0;
163 if (zPlane[1] < zPlane[0])dirZ = -1;
167 for (i = 0; i < numZPlanes; i++)
169 if ((i < numZPlanes - 1) && (zPlane[i] == zPlane[i + 1]))
171 if ((rInner[i] > rOuter[i + 1])
172 || (rInner[i + 1] > rOuter[i]))
175 std::ostringstream message;
176 message <<
"Cannot create a Polycone with no contiguous segments."
178 <<
"Segments are not contiguous !" << std::endl
179 <<
" rMin[" << i <<
"] = " << rInner[i]
180 <<
" -- rMax[" << i + 1 <<
"] = " << rOuter[i + 1] << std::endl
181 <<
" rMin[" << i + 1 <<
"] = " << rInner[i + 1]
182 <<
" -- rMax[" << i <<
"] = " << rOuter[i];
190 double rMin = rInner[i];
191 double rMax = rOuter[i];
192 double z = zPlane[i];
196 if (((z > prevZ)&&(dirZ>0))||((z < prevZ)&&(dirZ<0)))
198 if (dirZ*(z-prevZ)< 0)
200 std::ostringstream message;
201 message <<
"Cannot create a Polycone with different Z directions.Use GenericPolycone."
203 <<
"ZPlane is changing direction !" << std::endl
204 <<
" zPlane[0] = " << zPlane[0]
205 <<
" -- zPlane[1] = " << zPlane[1] << std::endl
206 <<
" zPlane[" << i - 1 <<
"] = " << zPlane[i - 1]
207 <<
" -- rPlane[" << i <<
"] = " << zPlane[i];
215 double dz = (z - prevZ)*dirZ / 2;
217 bool tubular = (rMin == prevRmin && prevRmax == rMax);
223 solid =
new UTubs(
"", rMin, rMax, dz, phiStart, phiTotal);
227 solid =
new UCons(
"", prevRmin, prevRmax, rMin, rMax, dz, phiStart, phiTotal);
237 int zi =
fZs.size() - 1;
238 double shift =
fZs[zi - 1] + 0.5 * (
fZs[zi] -
fZs[zi - 1]);
241 section.
shift = shift;
243 section.
solid = solid;
246 if (rMax < RMaxextent) { section.
convex =
false;}
247 else { section.
convex =
true;}
251 if ((rMax<prevRmax)||(rMax < RMaxextent)||(prevRmax < RMaxextent))
252 { section.
convex =
false;}
263 else fZs.push_back(z);
281 double mxy = rz->
Amax();
284 double r = rz->
Amax();
288 if (rz->
Amin() < 0.0)
290 std::ostringstream message;
291 message <<
"Illegal input parameters - " <<
GetName() << std::endl
292 <<
" All R values must be >= 0 !";
353 int oldprc = os.precision(16);
354 os <<
"-----------------------------------------------------------\n"
355 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
356 <<
" ===================================================\n"
357 <<
" Solid type: UPolycone\n"
363 os <<
" number of Z planes: " << numPlanes <<
"\n"
365 for (i = 0; i < numPlanes; i++)
367 os <<
" Z plane " << i <<
": "
370 os <<
" Tangent distances to inner surface (Rmin): \n";
371 for (i = 0; i < numPlanes; i++)
373 os <<
" Z plane " << i <<
": "
376 os <<
" Tangent distances to outer surface (Rmax): \n";
377 for (i = 0; i < numPlanes; i++)
379 os <<
" Z plane " << i <<
": "
382 os <<
"-----------------------------------------------------------\n";
383 os.precision(oldprc);
477 double rMinPlus, rMaxPlus , rMinMinus, rMaxMinus;
481 double r2 = p.
x * p.
x + p.
y * p.
y;
487 rMaxPlus = tubs->
GetRMax()+ halfTolerance;
488 rMinPlus = tubs->
GetRMin() + halfTolerance;
489 rMinMinus = tubs->
GetRMin() - halfTolerance;
490 rMaxMinus = tubs->
GetRMax() - halfTolerance;
502 double ratio = (ps.
z + dz) / (2 * dz);
503 rMinPlus = rMin1 + (rMin2 - rMin1) * ratio + halfTolerance;
504 rMaxPlus = rMax1 + (rMax2 - rMax1) * ratio + halfTolerance;
505 rMinMinus = rMinPlus - 2*halfTolerance;
506 rMaxMinus = rMaxPlus - 2*halfTolerance;
512 if (ps.
z < -dz + halfTolerance || ps.
z > dz - halfTolerance)
524 if (r2 < rMinMinus * rMinMinus || r2 > rMaxPlus * rMaxPlus) {
527 if (r2 < rMinPlus * rMinPlus || r2 > rMaxMinus * rMaxMinus)
534 if (ps.
z < -dz + halfTolerance || ps.
z > dz - halfTolerance)
538 double phi = std::atan2(p.
y, p.
x);
547 if (ps.
z < -dz + halfTolerance || ps.
z > dz - halfTolerance)
549 if (r2 < rMinPlus * rMinPlus || r2 > rMaxMinus * rMaxMinus)
573 static const double htolerance = 0.5 *
fgTolerance;
582 if (index > 0 && p.
z -
fZs[index] < htolerance)
584 nextSection = index - 1;
589 nextSection = index + 1;
636 pb = p + idistance * v;
639 int increment = (v.z > 0) ? 1 : -1;
660 UVector3&
n,
bool& convex,
double )
const
675 if ( indexLow != indexHigh )
680 else{index=indexLow;}
683 else{index=indexLow;}
684 double totalDistance = 0;
685 int increment = (v.
z > 0) ? 1 : -1;
695 if (totalDistance != 0||(istep < 2))
697 pn = p + (totalDistance ) * v;
704 else pn.
z -= section.
shift;
709 {
int index1 = index;
710 if(( index > 0) && ( index <
fMaxSection )){index1 += increment;}
712 if((index == 0) && ( increment > 0 ))index1 += increment;
713 if((index ==
fMaxSection) && (increment<0 ))index1 += increment;
715 UVector3 pte = p+(totalDistance+distance)*v;
717 pte.
z -= section1.shift;
718 if (section1.solid->Inside(pte) ==
eOutside)
725 if((convexloc) && (section.
convex)) {convexloc=
true;}
726 else{convexloc=
false;}
729 totalDistance += distance;
739 pn = p + (totalDistance) * v;
743 double dz1 = std::fabs(pn.
z-
fZs[index]);
744 double dz2 = std::fabs(pn.
z-
fZs[index+1]);
745 if(dz1 < halfTolerance)convex=
false;
746 if(dz2 < halfTolerance)convex=
false;
752 if(index<=0){
if(std::fabs(pn.
z-
fZs[1]) < halfTolerance)convex=
false;}
760 return totalDistance;
770 double rho=std::sqrt(p.
x*p.
x+p.
y*p.
y);
772 double safeDown = p.
z-
fZs[index];
773 double safeUp =
fZs[index+1]-p.
z;
778 if (minSafety < 1e-6)
return 0;
782 double dz1 =
fZs[i] - p.
z;
783 double dz2 =
fZs[i+1] - p.
z;
785 if (safeR < 0.) { safeUp=dz1;
break; }
786 if (dz1 < dz2) { safeR = std::sqrt(safeR*safeR+dz1*dz1); }
787 else {safeR = std::sqrt(safeR*safeR+dz1*dz1); }
788 if (safeR < dz1) { safeUp = safeR;
break; }
789 if (safeR < dz2) { safeUp = safeR;
break; }
795 for (
int i = index - 1; i >= 0; --i)
797 double dz1 = p.
z-
fZs[i+1];
798 double dz2 = p.
z-
fZs[i];
800 if (safeR < 0.) { safeDown=dz1;
break; }
801 if(dz1 < dz2) { safeR = std::sqrt(safeR*safeR+dz1*dz1); }
802 else { safeR = std::sqrt(safeR*safeR+dz1*dz1); }
803 if (safeR < dz1) { safeDown = safeR;
break; }
804 if (safeR < dz2) { safeDown = safeR;
break; }
808 if (safeUp < minSafety) minSafety=safeUp;
809 if (safeDown < minSafety) minSafety=safeDown;
823 double zbase =
fZs[index + 1];
826 double dz =
fZs[i] - zbase;
827 if (dz >= minSafety)
break;
829 if (safety < minSafety) minSafety = safety;
832 zbase =
fZs[index - 1];
833 for (
int i = index - 1; i >= 0; --i)
835 double dz = zbase -
fZs[i];
836 if (dz >= minSafety)
break;
838 if (safety < minSafety) minSafety = safety;
851 if (index > 0 && p.
z -
fZs[index] < htolerance)
853 nextSection = index - 1;
858 nextSection = index + 1;
866 if(n.
Mag()<0.9)std::cout<<
"UPcon Norm 1 ="<<n<<
" res="<<res<<
" p="<<p<<
" name="<<
GetName()<<std::endl;
874 if(n.
Mag()<0.9)std::cout<<
"UPcon Norm 2 ="<<n<<
" res="<<res<<
" p="<<p<<
" name="<<
GetName()<<std::endl;
883 if(n.
Mag()<0.9)std::cout<<
"UPcon Norm 3 ="<<n<<std::endl;
899 if(n.
Mag()<0.9)std::cout<<
"UPcon Norm 4 ="<<n<<std::endl;
914 if(n.
Mag()<0.9)std::cout<<
"UPcon Norm 5 ="<<n<<std::endl;
921 if (pos !=
eSurface) index = nextSection;
923 if(n.
Mag()<0.9)std::cout<<
"UPcon Norm 6 ="<<n<<std::endl;
928 if(n.
Mag()<0.9)std::cout<<
"UPcon Norm 7 ="<<n<<std::endl;
937 aMin.
Set(-r, -r,
fZs.front());
938 aMax.
Set(r, r,
fZs.back());
967 double Area = 0, totArea = 0;
972 std::vector<double> areas;
973 std::vector<UVector3> points;
978 for (i = 0; i < numPlanes - 1; i++)
1003 areas.push_back(Area);
1010 totArea += (areas[0] + areas[numPlanes]);
1027 double fRmin2,
double fRmax2,
1028 double zOne,
double zTwo,
1029 double& totArea)
const
1033 double Aone, Atwo, Afive, phi, zRand, fDPhi, cosu, sinu;
1034 double rRand1, rmin, rmax, chose, rone, rtwo, qone, qtwo;
1035 double fDz = (zTwo - zOne) / 2., afDz = std::fabs(fDz);
1038 rone = (fRmax1 - fRmax2) / (2.*fDz);
1039 rtwo = (fRmin1 - fRmin2) / (2.*fDz);
1040 if (fRmax1 == fRmax2)
1046 qone = fDz * (fRmax1 + fRmax2) / (fRmax1 - fRmax2);
1048 if (fRmin1 == fRmin2)
1054 qtwo = fDz * (fRmin1 + fRmin2) / (fRmin1 - fRmin2);
1058 Afive = fDz * (fRmax1 - fRmin1 + fRmax2 - fRmin2);
1059 totArea = Aone + Atwo + 2.*Afive;
1062 cosu = std::cos(phi);
1063 sinu = std::sin(phi);
1071 if ((chose >= 0) && (chose < Aone))
1073 if (fRmax1 != fRmax2)
1076 point =
UVector3(rone * cosu * (qone - zRand),
1077 rone * sinu * (qone - zRand), zRand);
1081 point =
UVector3(fRmax1 * cosu, fRmax1 * sinu,
1086 else if (chose >= Aone && chose < Aone + Atwo)
1088 if (fRmin1 != fRmin2)
1091 point =
UVector3(rtwo * cosu * (qtwo - zRand),
1092 rtwo * sinu * (qtwo - zRand), zRand);
1097 point =
UVector3(fRmin1 * cosu, fRmin1 * sinu,
1101 else if ((chose >= Aone + Atwo + Afive) && (chose < Aone + Atwo + 2.*Afive))
1104 rmin = fRmin2 - ((zRand - fDz) / (2.*fDz)) * (fRmin1 - fRmin2);
1105 rmax = fRmax2 - ((zRand - fDz) / (2.*fDz)) * (fRmax1 - fRmax2);
1107 point =
UVector3(rRand1 * std::cos(startPhi),
1108 rRand1 * std::sin(startPhi), zRand);
1113 rmin = fRmin2 - ((zRand - fDz) / (2.*fDz)) * (fRmin1 - fRmin2);
1114 rmax = fRmax2 - ((zRand - fDz) / (2.*fDz)) * (fRmax1 - fRmax2);
1117 rRand1 * std::sin(
endPhi), zRand);
1121 return point + offset;
1131 double zOne,
double zTwo,
1132 double& totArea)
const
1134 double xRand, yRand, zRand, phi, cosphi, sinphi, chose,
1135 aOne, aTwo, aFou, rRand, fDz, fSPhi, fDPhi;
1136 fDz = std::fabs(0.5 * (zTwo - zOne));
1140 aOne = 2.*fDz * fDPhi * fRMax;
1141 aTwo = 2.*fDz * fDPhi * fRMin;
1142 aFou = 2.*fDz * (fRMax - fRMin);
1143 totArea = aOne + aTwo + 2.*aFou;
1145 cosphi = std::cos(phi);
1146 sinphi = std::sin(phi);
1153 if ((chose >= 0) && (chose < aOne))
1155 xRand = fRMax * cosphi;
1156 yRand = fRMax * sinphi;
1158 return UVector3(xRand, yRand, zRand + 0.5 * (zTwo + zOne));
1160 else if ((chose >= aOne) && (chose < aOne + aTwo))
1162 xRand = fRMin * cosphi;
1163 yRand = fRMin * sinphi;
1165 return UVector3(xRand, yRand, zRand + 0.5 * (zTwo + zOne));
1167 else if ((chose >= aOne + aTwo) && (chose < aOne + aTwo + aFou))
1169 xRand = rRand * std::cos(fSPhi + fDPhi);
1170 yRand = rRand * std::sin(fSPhi + fDPhi);
1172 return UVector3(xRand, yRand, zRand + 0.5 * (zTwo + zOne));
1177 xRand = rRand * std::cos(fSPhi + fDPhi);
1178 yRand = rRand * std::sin(fSPhi + fDPhi);
1180 return UVector3(xRand, yRand, zRand + 0.5 * (zTwo + zOne));
1190 double fRMin2,
double fRMax2,
1193 double xRand, yRand, phi, cosphi, sinphi, rRand1, rRand2, A1, Atot, rCh;
1195 cosphi = std::cos(phi);
1196 sinphi = std::sin(phi);
1198 if (fRMin1 == fRMin2)
1206 A1 = std::fabs(fRMin2 * fRMin2 - fRMin1 * fRMin1);
1208 if (fRMax1 == fRMax2)
1216 Atot = A1 + std::fabs(fRMax2 * fRMax2 - fRMax1 * fRMax1);
1225 xRand = rRand1 * cosphi;
1226 yRand = rRand1 * sinphi;
1228 return UVector3(xRand, yRand, zOne);
1238 double fRMin2,
double fRMax2,
1239 double zOne,
double zTwo,
1240 double& totArea)
const
1246 if ((fRMin1 == fRMin2) && (fRMax1 == fRMax2))
1250 return GetPointOnCone(fRMin1, fRMax1, fRMin2, fRMax2, zOne, zTwo, totArea);
1259 double Area = 0, totArea = 0, Achose1 = 0, Achose2 = 0, phi, cosphi, sinphi, rRand;
1264 cosphi = std::cos(phi);
1265 sinphi = std::sin(phi);
1271 std::vector<double> areas;
1272 std::vector<UVector3> points;
1277 for (i = 0; i < numPlanes - 1; i++)
1302 areas.push_back(Area);
1309 totArea += (areas[0] + areas[numPlanes]);
1312 if ((chose >= 0.) && (chose < areas[0]))
1314 return UVector3(rRand * cosphi, rRand * sinphi,
1318 for (i = 0; i < numPlanes - 1; i++)
1320 Achose1 += areas[i];
1321 Achose2 = (Achose1 + areas[i + 1]);
1322 if (chose >= Achose1 && chose < Achose2)
1337 return UVector3(rRand * cosphi, rRand * sinphi,
1347 : fStartAngle(0.), fOpeningAngle(0.), fNumZPlanes(0),
1348 fZValues(0), Rmin(0), Rmax(0)
1378 if (&right ==
this)
return *
this;
1418 if (
this == &source)
return *
this;
1467 bool isConvertible =
true;
1468 double Zmax = rz->
Bmax();
1473 std::vector<double> Z;
1474 std::vector<double> Rmin;
1475 std::vector<double> Rmax;
1477 int countPlanes = 1;
1484 double Zprev = Z[0];
1491 else if (Zprev ==
corners[numPlanes - 1].z)
1493 Rmin.push_back(
corners[numPlanes - 1].r);
1495 icurl = numPlanes - 1;
1505 int inextr = 0, inextl = 0;
1506 for (
int i = 0; i < numPlanes - 2; i++)
1509 inextl = (icurl <= 0) ? numPlanes - 1 : icurl - 1;
1529 Rmin.push_back(
corners[icurl].r);
1530 Rmax.push_back(Rmax[countPlanes - 2]);
1531 Rmax[countPlanes - 2] =
corners[icurl].
r;
1535 Rmin.push_back(
corners[inextl].r);
1536 Rmax.push_back(
corners[icurl].r);
1541 Rmin.push_back(
corners[inextl].r);
1542 Rmax.push_back(
corners[icurr].r + (Zleft -
corners[icurr].z) / difZr
1547 isConvertible =
false;
1550 icurl = (icurl == 0) ? numPlanes - 1 : icurl - 1;
1558 icurl = (icurl == 0) ? numPlanes - 1 : icurl - 1;
1560 Rmin.push_back(
corners[inextl].r);
1561 Rmax.push_back(
corners[inextr].r);
1565 Z.push_back(Zright);
1574 Rmin.push_back(
corners[icurr].r);
1575 Rmax.push_back(
corners[inextr].r);
1579 Rmin.push_back(
corners[inextr].r);
1580 Rmax.push_back(
corners[icurr].r);
1581 Rmax[countPlanes - 2] =
corners[inextr].
r;
1589 Rmax.push_back(
corners[inextr].r);
1590 Rmin.push_back(
corners[icurr].r);
1594 Rmax.push_back(
corners[inextr].r);
1595 Rmin.push_back(
corners[icurl].r + (Zright -
corners[icurl].z) / difZl
1602 isConvertible =
false;
1613 inextl = (icurl <= 0) ? numPlanes - 1 : icurl - 1;
1617 Rmax.push_back(
corners[inextr].r);
1618 Rmin.push_back(
corners[inextl].r);
1622 Rmax.push_back(
corners[inextr].r);
1623 Rmin.push_back(
corners[inextl].r);
1635 for (
int j = 0; j < countPlanes; j++)
1648 std::ostringstream message;
1649 message <<
"Polycone " <<
GetName() << std::endl
1650 <<
"cannot be converted to Polycone with (Rmin,Rmaz,Z) parameters!";
1652 Warning, 1,
"can not convert");
1660 for (
int j = 0; j < numPlanes; j++)
1670 return isConvertible;
1685 double* Z, *R1, *R2;
1687 Z =
new double[num];
1688 R1 =
new double[num];
1689 R2 =
new double[num];
1690 for (
int i = 0; i < num; i++)
double SafetyFromOutside(const UVector3 &p) const
double DistanceToIn(const UVector3 &p, const UVector3 &v, double aPstep=UUtils::kInfinity) const
std::vector< double > Rmin
static double frTolerance
std::vector< double > fZValues
UVector3 GetPointOnTubs(double fRMin, double fRMax, double zOne, double zTwo, double &totArea) const
bool NormalSection(int index, const UVector3 &p, UVector3 &n) const
int GetSection(double z) const
const std::string & GetName() const
static double fgTolerance
void CopyStuff(const UPolycone &source)
std::vector< UPolyconeSection > fSections
UVector3 GetPointOnCut(double fRMin1, double fRMax1, double fRMin2, double fRMax2, double zOne, double zTwo, double &totArea) const
double SafetyFromOutsideSection(int index, const double rho, const UVector3 &p) const
std::ostream & StreamInfo(std::ostream &os) const
UPolyconeHistorical & operator=(const UPolyconeHistorical &right)
virtual bool Normal(const UVector3 &aPoint, UVector3 &aNormal) const =0
virtual EnumInside Inside(const UVector3 &aPoint) const =0
VUSolid::EnumInside Inside(const UVector3 &p) const
std::vector< double > Rmax
bool Normal(const UVector3 &aPoint, UVector3 &aNormal) const
static int BinarySearch(const std::vector< T > &vec, T value)
static const double kInfinity
virtual double DistanceToIn(const UVector3 &aPoint, const UVector3 &aDirection, double aPstep=UUtils::kInfinity) const =0
static const double kTwoPi
UVector3 GetPointOnSurface() const
void Init(double phiStart, double phiTotal, int numZPlanes, const double zPlane[], const double rInner[], const double rOuter[])
UPolyconeHistorical * fOriginalParameters
UPolyconeSideRZ * corners
UGeometryType GetEntityType() const
double DistanceToIn(const UVector3 &aPoint, const UVector3 &aDirection, double aPstep=UUtils::kInfinity) const
static const G4double minSafety
double GetZHalfLength() const
void SetOriginalParameters()
VUSolid::EnumInside InsideSection(int index, const UVector3 &p) const
void Set(double xx, double yy, double zz)
double SafetyFromOutside(const UVector3 &aPoint, bool aAccurate=false) const
double SafetyFromInside(const UVector3 &aPoint, bool aAccurate=false) const
void Set(double dx, double dy, double dz)
std::string UGeometryType
EnumInside Inside(const UVector3 &aPoint) const
UVector3 GetPointOnRing(double fRMin, double fRMax, double fRMin2, double fRMax2, double zOne) const
UVector3 GetPointOnCone(double fRmin1, double fRmax1, double fRmin2, double fRmax2, double zOne, double zTwo, double &totArea) const
virtual double DistanceToOut(const UVector3 &aPoint, const UVector3 &aDirection, UVector3 &aNormalVector, bool &aConvex, double aPstep=UUtils::kInfinity) const =0
UPolycone & operator=(const UPolycone &source)
void Exception(const char *originOfException, const char *exceptionCode, ExceptionSeverity severity, int level, const char *description)
double SafetyFromInsideSection(int index, const double rho, const UVector3 &p) const
std::vector< double > fZs
UEnclosingCylinder * enclosingCylinder
void Extent(UVector3 &aMin, UVector3 &aMax) const
double Random(double min=0.0, double max=1.0)
double DistanceToOut(const UVector3 &aPoint, const UVector3 &aDirection, UVector3 &aNormalVector, bool &aConvex, double aPstep=UUtils::kInfinity) const
UPolycone(const std::string &name)
static const G4double pos
virtual double Capacity()=0