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" ;
76 std::cout <<
"INFO: Converting polycone " <<
GetName() << std::endl
77 <<
"to optimized polycone with (Rmin,Rmaz,Z) parameters !"
84 for (
int i = 0; i < num; i++)
92 Init(phiStart, phiTotal, num, Z, R1, R2);
108 const double zPlane[],
109 const double rInner[],
110 const double rOuter[])
129 endPhi = phiStart+phiTotal;
143 double RMaxextent=rOuter[0];
144 for (
int j=1; j < numZPlanes; j++)
146 if (rOuter[j] > RMaxextent) RMaxextent=rOuter[j];
147 if (rInner[j]>rOuter[j])
149 std::ostringstream message;
150 message <<
"Cannot create Polycone with rInner > rOuter for the same Z"
152 <<
" rInner > rOuter for the same Z !" << std::endl
153 <<
" rMin[" << j <<
"] = " << rInner[j]
154 <<
" -- rMax[" << j <<
"] = " << rOuter[j];
160 double prevZ = 0, prevRmax = 0, prevRmin = 0;
162 if (zPlane[1] < zPlane[0])dirZ = -1;
166 for (i = 0; i < numZPlanes; i++)
168 if ((i < numZPlanes - 1) && (zPlane[i] == zPlane[i + 1]))
170 if ((rInner[i] > rOuter[i + 1])
171 || (rInner[i + 1] > rOuter[i]))
174 std::ostringstream message;
175 message <<
"Cannot create a Polycone with no contiguous segments."
177 <<
" Segments are not contiguous !" << std::endl
178 <<
" rMin[" << i <<
"] = " << rInner[i]
179 <<
" -- rMax[" << i + 1 <<
"] = " << rOuter[i + 1] << std::endl
180 <<
" rMin[" << i + 1 <<
"] = " << rInner[i + 1]
181 <<
" -- rMax[" << i <<
"] = " << rOuter[i];
189 double rMin = rInner[i];
190 double rMax = rOuter[i];
191 double z = zPlane[i];
199 std::ostringstream message;
200 message <<
"Cannot create a Polycone with different Z directions.Use GenericPolycone."
202 <<
" ZPlane is changing direction !" << std::endl
203 <<
" zPlane[0] = " << zPlane[0]
204 <<
" -- zPlane[1] = " << zPlane[1] << std::endl
205 <<
" zPlane[" << i - 1 <<
"] = " << zPlane[i - 1]
206 <<
" -- rPlane[" << i <<
"] = " << zPlane[i];
214 double dz = (z - prevZ) / 2;
216 bool tubular = (rMin == prevRmin && prevRmax == rMax);
222 solid =
new UTubs(
"", rMin, rMax, dz, phiStart, phiTotal);
226 solid =
new UCons(
"", prevRmin, prevRmax, rMin, rMax, dz, phiStart, phiTotal);
236 int zi =
fZs.size() - 1;
237 double shift =
fZs[zi - 1] + 0.5 * (
fZs[zi] -
fZs[zi - 1]);
240 section.
shift = shift;
242 section.
solid = solid;
245 if (rMax < RMaxextent) { section.
convex =
false;}
246 else { section.
convex =
true;}
250 if ((rMax<prevRmax)||(rMax < RMaxextent)||(prevRmax < RMaxextent))
251 { section.
convex =
false;}
262 else fZs.push_back(z);
280 double mxy = rz->
Amax();
283 double r = rz->
Amax();
287 if (rz->
Amin() < 0.0)
289 std::ostringstream message;
290 message <<
"Illegal input parameters - " <<
GetName() << std::endl
291 <<
" All R values must be >= 0 !";
363 int oldprc = os.precision(16);
364 os <<
"-----------------------------------------------------------\n"
365 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
366 <<
" ===================================================\n"
367 <<
" Solid type: UPolycone3\n"
373 os <<
" number of Z planes: " << numPlanes <<
"\n"
375 for (i = 0; i < numPlanes; i++)
377 os <<
" Z plane " << i <<
": "
380 os <<
" Tangent distances to inner surface (Rmin): \n";
381 for (i = 0; i < numPlanes; i++)
383 os <<
" Z plane " << i <<
": "
386 os <<
" Tangent distances to outer surface (Rmax): \n";
387 for (i = 0; i < numPlanes; i++)
389 os <<
" Z plane " << i <<
": "
392 os <<
"-----------------------------------------------------------\n";
393 os.precision(oldprc);
406 double rMinPlus, rMaxPlus;
413 rMinPlus = tubs->
GetRMin() + halfTolerance;
414 rMaxPlus = tubs->
GetRMax() + halfTolerance;
427 double ratio = (ps.
z + dz) / (2 * dz);
428 rMinPlus = rMin1 + (rMin2 - rMin1) * ratio + halfTolerance;
429 rMaxPlus = rMax1 + (rMax2 - rMax1) * ratio + halfTolerance;
435 double r2 = p.
x * p.
x + p.
y * p.
y;
437 if (r2 < rMinMinus * rMinMinus || r2 > rMaxPlus * rMaxPlus)
return eOutside;
438 if (r2 < rMinPlus * rMinPlus || r2 > rMaxMinus * rMaxMinus)
return eSurface;
442 if (ps.
z < -dz + halfTolerance || ps.
z > dz - halfTolerance)
447 if (r2 < 1e-10)
return eInside;
449 double phi = std::atan2(p.
y, p.
x);
456 if (ps.
z < -dz + halfTolerance || ps.
z > dz - halfTolerance)
477 static const double htolerance = 0.5 *
fgTolerance;
486 if (index > 0 && p.
z -
fZs[index] < htolerance)
488 nextSection = index - 1;
493 nextSection = index + 1;
541 pb = p + idistance * v;
544 int increment = (v.z > 0) ? 1 : -1;
564 UVector3&
n,
bool& convex,
double )
const
574 double totalDistance = 0;
575 int increment = (v.
z > 0) ? 1 : -1;
581 if (totalDistance != 0)
583 pn = p + (totalDistance ) * v;
591 else pn.
z -= section.
shift;
594 if ((convexloc) && (section.
convex)) { convexloc =
true; }
595 else { convexloc =
false; }
597 totalDistance += distance;
607 pn = p + (totalDistance) * v;
608 double dz1 = std::fabs(pn.
z-
fZs[index]);
609 double dz2 = std::fabs(pn.
z-
fZs[index+1]);
611 if((dz1 < halfTolerance) && (index>0)) convex =
false;
612 if((dz2 < halfTolerance) && (index<
fMaxSection)) convex =
false;
615 return totalDistance;
625 if (minSafety < 1e-6)
return 0;
627 double zbase =
fZs[index + 1];
630 double dz =
fZs[i] - zbase;
631 if (dz >= minSafety)
break;
633 if (safety < minSafety) minSafety = safety;
638 zbase =
fZs[index - 1];
639 for (
int i = index - 1; i >= 0; --i)
641 double dz = zbase -
fZs[i];
642 if (dz >= minSafety)
break;
644 if (safety < minSafety) minSafety = safety;
658 if (minSafety < 1e-6)
return minSafety;
660 double zbase =
fZs[index + 1];
663 double dz =
fZs[i] - zbase;
664 if (dz >= minSafety)
break;
666 if (safety < minSafety) minSafety = safety;
669 zbase =
fZs[index - 1];
670 for (
int i = index - 1; i >= 0; --i)
672 double dz = zbase -
fZs[i];
673 if (dz >= minSafety)
break;
675 if (safety < minSafety) minSafety = safety;
688 if (index > 0 && p.
z -
fZs[index] < htolerance)
690 nextSection = index - 1;
695 nextSection = index + 1;
754 if (pos !=
eSurface) index = nextSection;
768 aMin.
Set(-r, -r,
fZs.front());
769 aMax.
Set(r, r,
fZs.back());
797 double Area = 0, totArea = 0;
802 std::vector<double> areas;
803 std::vector<UVector3> points;
808 for (i = 0; i < numPlanes - 1; i++)
833 areas.push_back(Area);
840 totArea += (areas[0] + areas[numPlanes]);
857 double fRmin2,
double fRmax2,
858 double zOne,
double zTwo,
859 double& totArea)
const
863 double Aone, Atwo, Afive, phi, zRand, fDPhi, cosu, sinu;
864 double rRand1, rmin, rmax, chose, rone, rtwo, qone, qtwo;
865 double fDz = (zTwo - zOne) / 2., afDz = std::fabs(fDz);
868 rone = (fRmax1 - fRmax2) / (2.*fDz);
869 rtwo = (fRmin1 - fRmin2) / (2.*fDz);
870 if (fRmax1 == fRmax2)
876 qone = fDz * (fRmax1 + fRmax2) / (fRmax1 - fRmax2);
878 if (fRmin1 == fRmin2)
884 qtwo = fDz * (fRmin1 + fRmin2) / (fRmin1 - fRmin2);
888 Afive = fDz * (fRmax1 - fRmin1 + fRmax2 - fRmin2);
889 totArea = Aone + Atwo + 2.*Afive;
892 cosu = std::cos(phi);
893 sinu = std::sin(phi);
901 if ((chose >= 0) && (chose < Aone))
903 if (fRmax1 != fRmax2)
906 point =
UVector3(rone * cosu * (qone - zRand),
907 rone * sinu * (qone - zRand), zRand);
911 point =
UVector3(fRmax1 * cosu, fRmax1 * sinu,
916 else if (chose >= Aone && chose < Aone + Atwo)
918 if (fRmin1 != fRmin2)
921 point =
UVector3(rtwo * cosu * (qtwo - zRand),
922 rtwo * sinu * (qtwo - zRand), zRand);
927 point =
UVector3(fRmin1 * cosu, fRmin1 * sinu,
931 else if ((chose >= Aone + Atwo + Afive) && (chose < Aone + Atwo + 2.*Afive))
934 rmin = fRmin2 - ((zRand - fDz) / (2.*fDz)) * (fRmin1 - fRmin2);
935 rmax = fRmax2 - ((zRand - fDz) / (2.*fDz)) * (fRmax1 - fRmax2);
937 point =
UVector3(rRand1 * std::cos(startPhi),
938 rRand1 * std::sin(startPhi), zRand);
943 rmin = fRmin2 - ((zRand - fDz) / (2.*fDz)) * (fRmin1 - fRmin2);
944 rmax = fRmax2 - ((zRand - fDz) / (2.*fDz)) * (fRmax1 - fRmax2);
947 rRand1 * std::sin(
endPhi), zRand);
951 return point + offset;
961 double zOne,
double zTwo,
962 double& totArea)
const
964 double xRand, yRand, zRand, phi, cosphi, sinphi, chose,
965 aOne, aTwo, aFou, rRand, fDz, fSPhi, fDPhi;
966 fDz = std::fabs(0.5 * (zTwo - zOne));
970 aOne = 2.*fDz * fDPhi * fRMax;
971 aTwo = 2.*fDz * fDPhi * fRMin;
972 aFou = 2.*fDz * (fRMax - fRMin);
973 totArea = aOne + aTwo + 2.*aFou;
975 cosphi = std::cos(phi);
976 sinphi = std::sin(phi);
983 if ((chose >= 0) && (chose < aOne))
985 xRand = fRMax * cosphi;
986 yRand = fRMax * sinphi;
988 return UVector3(xRand, yRand, zRand + 0.5 * (zTwo + zOne));
990 else if ((chose >= aOne) && (chose < aOne + aTwo))
992 xRand = fRMin * cosphi;
993 yRand = fRMin * sinphi;
995 return UVector3(xRand, yRand, zRand + 0.5 * (zTwo + zOne));
997 else if ((chose >= aOne + aTwo) && (chose < aOne + aTwo + aFou))
999 xRand = rRand * std::cos(fSPhi + fDPhi);
1000 yRand = rRand * std::sin(fSPhi + fDPhi);
1002 return UVector3(xRand, yRand, zRand + 0.5 * (zTwo + zOne));
1007 xRand = rRand * std::cos(fSPhi + fDPhi);
1008 yRand = rRand * std::sin(fSPhi + fDPhi);
1010 return UVector3(xRand, yRand, zRand + 0.5 * (zTwo + zOne));
1020 double fRMin2,
double fRMax2,
1023 double xRand, yRand, phi, cosphi, sinphi, rRand1, rRand2, A1, Atot, rCh;
1025 cosphi = std::cos(phi);
1026 sinphi = std::sin(phi);
1028 if (fRMin1 == fRMin2)
1036 A1 = std::fabs(fRMin2 * fRMin2 - fRMin1 * fRMin1);
1038 if (fRMax1 == fRMax2)
1046 Atot = A1 + std::fabs(fRMax2 * fRMax2 - fRMax1 * fRMax1);
1055 xRand = rRand1 * cosphi;
1056 yRand = rRand1 * sinphi;
1058 return UVector3(xRand, yRand, zOne);
1068 double fRMin2,
double fRMax2,
1069 double zOne,
double zTwo,
1070 double& totArea)
const
1076 if ((fRMin1 == fRMin2) && (fRMax1 == fRMax2))
1080 return GetPointOnCone(fRMin1, fRMax1, fRMin2, fRMax2, zOne, zTwo, totArea);
1089 double Area = 0, totArea = 0, Achose1 = 0, Achose2 = 0, phi, cosphi, sinphi, rRand;
1094 cosphi = std::cos(phi);
1095 sinphi = std::sin(phi);
1101 std::vector<double> areas;
1102 std::vector<UVector3> points;
1107 for (i = 0; i < numPlanes - 1; i++)
1132 areas.push_back(Area);
1139 totArea += (areas[0] + areas[numPlanes]);
1142 if ((chose >= 0.) && (chose < areas[0]))
1144 return UVector3(rRand * cosphi, rRand * sinphi,
1148 for (i = 0; i < numPlanes - 1; i++)
1150 Achose1 += areas[i];
1151 Achose2 = (Achose1 + areas[i + 1]);
1152 if (chose >= Achose1 && chose < Achose2)
1167 return UVector3(rRand * cosphi, rRand * sinphi,
1177 : fStartAngle(0.), fOpeningAngle(0.), fNumZPlanes(0),
1178 fZValues(0), Rmin(0), Rmax(0)
1208 if (&right ==
this)
return *
this;
1248 if (
this == &source)
return *
this;
1297 bool isConvertible =
true;
1298 double Zmax = rz->
Bmax();
1303 std::vector<double> Z;
1304 std::vector<double> Rmin;
1305 std::vector<double> Rmax;
1307 int countPlanes = 1;
1314 double Zprev = Z[0];
1321 else if (Zprev ==
corners[numPlanes - 1].z)
1323 Rmin.push_back(
corners[numPlanes - 1].r);
1325 icurl = numPlanes - 1;
1335 int inextr = 0, inextl = 0;
1336 for (
int i = 0; i < numPlanes - 2; i++)
1339 inextl = (icurl <= 0) ? numPlanes - 1 : icurl - 1;
1359 Rmin.push_back(
corners[icurl].r);
1360 Rmax.push_back(Rmax[countPlanes - 2]);
1361 Rmax[countPlanes - 2] =
corners[icurl].
r;
1365 Rmin.push_back(
corners[inextl].r);
1366 Rmax.push_back(
corners[icurl].r);
1371 Rmin.push_back(
corners[inextl].r);
1372 Rmax.push_back(
corners[icurr].r + (Zleft -
corners[icurr].z) / difZr
1377 isConvertible =
false;
1380 icurl = (icurl == 0) ? numPlanes - 1 : icurl - 1;
1388 icurl = (icurl == 0) ? numPlanes - 1 : icurl - 1;
1390 Rmin.push_back(
corners[inextl].r);
1391 Rmax.push_back(
corners[inextr].r);
1395 Z.push_back(Zright);
1404 Rmin.push_back(
corners[icurr].r);
1405 Rmax.push_back(
corners[inextr].r);
1409 Rmin.push_back(
corners[inextr].r);
1410 Rmax.push_back(
corners[icurr].r);
1411 Rmax[countPlanes - 2] =
corners[inextr].
r;
1419 Rmax.push_back(
corners[inextr].r);
1420 Rmin.push_back(
corners[icurr].r);
1424 Rmax.push_back(
corners[inextr].r);
1425 Rmin.push_back(
corners[icurl].r + (Zright -
corners[icurl].z) / difZl
1432 isConvertible =
false;
1443 inextl = (icurl <= 0) ? numPlanes - 1 : icurl - 1;
1447 Rmax.push_back(
corners[inextr].r);
1448 Rmin.push_back(
corners[inextl].r);
1452 Rmax.push_back(
corners[inextr].r);
1453 Rmin.push_back(
corners[inextl].r);
1465 for (
int j = 0; j < countPlanes; j++)
1478 std::ostringstream message;
1479 message <<
"Polycone " <<
GetName() << std::endl
1480 <<
"cannot be converted to Polycone with (Rmin,Rmaz,Z) parameters!";
1482 Warning, 1,
"can not convert");
1490 for (
int j = 0; j < numPlanes; j++)
1500 return isConvertible;
1515 double* Z, *R1, *R2;
1517 Z =
new double[num];
1518 R1 =
new double[num];
1519 R2 =
new double[num];
1520 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
double SafetyFromInsideSection(int index, const UVector3 &p) 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
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
double SafetyFromOutsideSection(int index, const UVector3 &p) const
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
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)
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