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;
141 double RMaxextent=rOuter[0];
142 for (
int j=1; j < numZPlanes; j++)
144 if (rOuter[j] > RMaxextent) RMaxextent=rOuter[j];
145 if (rInner[j]>rOuter[j])
147 std::ostringstream message;
148 message <<
"Cannot create Polycone with rInner > rOuter for the same Z"
150 <<
" rInner > rOuter for the same Z !" << std::endl
151 <<
" rMin[" << j <<
"] = " << rInner[j]
152 <<
" -- rMax[" << j <<
"] = " << rOuter[j];
158 double prevZ = 0, prevRmax = 0, prevRmin = 0;
160 if (zPlane[1] < zPlane[0])dirZ = -1;
164 for (i = 0; i < numZPlanes; i++)
166 if ((i < numZPlanes - 1) && (zPlane[i] == zPlane[i + 1]))
168 if ((rInner[i] > rOuter[i + 1])
169 || (rInner[i + 1] > rOuter[i]))
172 std::ostringstream message;
173 message <<
"Cannot create a Polycone with no contiguous segments."
175 <<
"Segments are not contiguous !" << std::endl
176 <<
" rMin[" << i <<
"] = " << rInner[i]
177 <<
" -- rMax[" << i + 1 <<
"] = " << rOuter[i + 1] << std::endl
178 <<
" rMin[" << i + 1 <<
"] = " << rInner[i + 1]
179 <<
" -- rMax[" << i <<
"] = " << rOuter[i];
187 double rMin = rInner[i];
188 double rMax = rOuter[i];
189 double z = zPlane[i];
197 std::ostringstream message;
198 message <<
"Cannot create a Polycone with different Z directions.Use GenericPolycone."
200 <<
"ZPlane is changing direction !" << std::endl
201 <<
" zPlane[0] = " << zPlane[0]
202 <<
" -- zPlane[1] = " << zPlane[1] << std::endl
203 <<
" zPlane[" << i - 1 <<
"] = " << zPlane[i - 1]
204 <<
" -- rPlane[" << i <<
"] = " << zPlane[i];
212 double dz = (z - prevZ) / 2;
214 bool tubular = (rMin == prevRmin && prevRmax == rMax);
220 solid =
new UTubs(
"", rMin, rMax, dz, phiStart, phiTotal);
224 solid =
new UCons(
"", prevRmin, prevRmax, rMin, rMax, dz, phiStart, phiTotal);
234 int zi =
fZs.size() - 1;
235 double shift =
fZs[zi - 1] + 0.5 * (
fZs[zi] -
fZs[zi - 1]);
238 section.
shift = shift;
240 section.
solid = solid;
243 if (rMax < RMaxextent) { section.
convex =
false;}
244 else { section.
convex =
true;}
248 if ((rMax<prevRmax)||(rMax < RMaxextent)||(prevRmax < RMaxextent))
249 { section.
convex =
false;}
260 else fZs.push_back(z);
278 double mxy = rz->
Amax();
281 double r = rz->
Amax();
285 if (rz->
Amin() < 0.0)
287 std::ostringstream message;
288 message <<
"Illegal input parameters - " <<
GetName() << std::endl
289 <<
" All R values must be >= 0 !";
361 int oldprc = os.precision(16);
362 os <<
"-----------------------------------------------------------\n"
363 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
364 <<
" ===================================================\n"
365 <<
" Solid type: UPolycone3\n"
371 os <<
" number of Z planes: " << numPlanes <<
"\n"
373 for (i = 0; i < numPlanes; i++)
375 os <<
" Z plane " << i <<
": "
378 os <<
" Tangent distances to inner surface (Rmin): \n";
379 for (i = 0; i < numPlanes; i++)
381 os <<
" Z plane " << i <<
": "
384 os <<
" Tangent distances to outer surface (Rmax): \n";
385 for (i = 0; i < numPlanes; i++)
387 os <<
" Z plane " << i <<
": "
390 os <<
"-----------------------------------------------------------\n";
391 os.precision(oldprc);
404 double rMinPlus, rMaxPlus;
411 rMinPlus = tubs->
GetRMin() + halfTolerance;
412 rMaxPlus = tubs->
GetRMax() + halfTolerance;
425 double ratio = (ps.
z + dz) / (2 * dz);
426 rMinPlus = rMin1 + (rMin2 - rMin1) * ratio + halfTolerance;
427 rMaxPlus = rMax1 + (rMax2 - rMax1) * ratio + halfTolerance;
433 double r2 = p.
x * p.
x + p.
y * p.
y;
435 if (r2 < rMinMinus * rMinMinus || r2 > rMaxPlus * rMaxPlus)
return eOutside;
436 if (r2 < rMinPlus * rMinPlus || r2 > rMaxMinus * rMaxMinus)
return eSurface;
440 if (ps.
z < -dz + halfTolerance || ps.
z > dz - halfTolerance)
445 if (r2 < 1e-10)
return eInside;
447 double phi = std::atan2(p.
y, p.
x);
454 if (ps.
z < -dz + halfTolerance || ps.
z > dz - halfTolerance)
475 static const double htolerance = 0.5 *
fgTolerance;
484 if (index > 0 && p.
z -
fZs[index] < htolerance)
486 nextSection = index - 1;
491 nextSection = index + 1;
539 pb = p + idistance * v;
542 int increment = (v.z > 0) ? 1 : -1;
562 UVector3&
n,
bool& convex,
double )
const
577 if ( indexLow != indexHigh )
582 else{index=indexLow;}
585 else{index=indexLow;}
586 double totalDistance = 0;
587 int increment = (v.
z > 0) ? 1 : -1;
596 if (totalDistance != 0)
598 pn = p + (totalDistance ) * v;
605 else pn.
z -= section.
shift;
610 {
int index1 = index;
611 if(( index > 0) && ( index <
fMaxSection )){index1 += increment;}
613 if((index == 0) && ( increment > 0 ))index1 += increment;
614 if((index ==
fMaxSection) && (increment<0 ))index1 += increment;
616 UVector3 pte = p+(totalDistance+distance)*v;
618 pte.
z -= section1.shift;
619 if (section1.solid->Inside(pte) ==
eOutside)
626 if((convexloc) && (section.
convex)) {convexloc=
true;}
627 else{convexloc=
false;}
630 totalDistance += distance;
640 pn = p + (totalDistance) * v;
644 double dz1 = std::fabs(pn.
z-
fZs[index]);
645 double dz2 = std::fabs(pn.
z-
fZs[index+1]);
646 if(dz1 < halfTolerance)convex=
false;
647 if(dz2 < halfTolerance)convex=
false;
653 if(index<=0){
if(std::fabs(pn.
z-
fZs[1]) < halfTolerance)convex=
false;}
657 return totalDistance;
665 double rho=std::sqrt(p.
x*p.
x+p.
y*p.
y);
667 double safeDown = p.
z-
fZs[index];
668 double safeUp =
fZs[index+1]-p.
z;
670 double minSafety =safeR;
673 if (minSafety < 1e-6)
return 0;
677 double dz1 =
fZs[i] - p.
z;
678 double dz2 =
fZs[i+1] - p.
z;
680 if (safeR < 0.) { safeUp=dz1;
break; }
681 if (dz1 < dz2) { safeR = std::sqrt(safeR*safeR+dz1*dz1); }
682 else {safeR = std::sqrt(safeR*safeR+dz1*dz1); }
683 if (safeR < dz1) { safeUp = safeR;
break; }
684 if (safeR < dz2) { safeUp = safeR;
break; }
690 for (
int i = index - 1; i >= 0; --i)
692 double dz1 = p.
z-
fZs[i+1];
693 double dz2 = p.
z-
fZs[i];
695 if (safeR < 0.) { safeDown=dz1;
break; }
696 if(dz1 < dz2) { safeR = std::sqrt(safeR*safeR+dz1*dz1); }
697 else { safeR = std::sqrt(safeR*safeR+dz1*dz1); }
698 if (safeR < dz1) { safeDown = safeR;
break; }
699 if (safeR < dz2) { safeDown = safeR;
break; }
703 if (safeUp < minSafety) minSafety=safeUp;
704 if (safeDown < minSafety) minSafety=safeDown;
716 if (minSafety < 1e-6)
return minSafety;
718 double zbase =
fZs[index + 1];
721 double dz =
fZs[i] - zbase;
722 if (dz >= minSafety)
break;
724 if (safety < minSafety) minSafety = safety;
727 zbase =
fZs[index - 1];
728 for (
int i = index - 1; i >= 0; --i)
730 double dz = zbase -
fZs[i];
731 if (dz >= minSafety)
break;
733 if (safety < minSafety) minSafety = safety;
746 if (index > 0 && p.
z -
fZs[index] < htolerance)
748 nextSection = index - 1;
753 nextSection = index + 1;
812 if (pos !=
eSurface) index = nextSection;
826 aMin.
Set(-r, -r,
fZs.front());
827 aMax.
Set(r, r,
fZs.back());
855 double Area = 0, totArea = 0;
860 std::vector<double> areas;
861 std::vector<UVector3> points;
866 for (i = 0; i < numPlanes - 1; i++)
891 areas.push_back(Area);
898 totArea += (areas[0] + areas[numPlanes]);
915 double fRmin2,
double fRmax2,
916 double zOne,
double zTwo,
917 double& totArea)
const
921 double Aone, Atwo, Afive, phi, zRand, fDPhi, cosu, sinu;
922 double rRand1, rmin, rmax, chose, rone, rtwo, qone, qtwo;
923 double fDz = (zTwo - zOne) / 2., afDz = std::fabs(fDz);
926 rone = (fRmax1 - fRmax2) / (2.*fDz);
927 rtwo = (fRmin1 - fRmin2) / (2.*fDz);
928 if (fRmax1 == fRmax2)
934 qone = fDz * (fRmax1 + fRmax2) / (fRmax1 - fRmax2);
936 if (fRmin1 == fRmin2)
942 qtwo = fDz * (fRmin1 + fRmin2) / (fRmin1 - fRmin2);
946 Afive = fDz * (fRmax1 - fRmin1 + fRmax2 - fRmin2);
947 totArea = Aone + Atwo + 2.*Afive;
950 cosu = std::cos(phi);
951 sinu = std::sin(phi);
959 if ((chose >= 0) && (chose < Aone))
961 if (fRmax1 != fRmax2)
964 point =
UVector3(rone * cosu * (qone - zRand),
965 rone * sinu * (qone - zRand), zRand);
969 point =
UVector3(fRmax1 * cosu, fRmax1 * sinu,
974 else if (chose >= Aone && chose < Aone + Atwo)
976 if (fRmin1 != fRmin2)
979 point =
UVector3(rtwo * cosu * (qtwo - zRand),
980 rtwo * sinu * (qtwo - zRand), zRand);
985 point =
UVector3(fRmin1 * cosu, fRmin1 * sinu,
989 else if ((chose >= Aone + Atwo + Afive) && (chose < Aone + Atwo + 2.*Afive))
992 rmin = fRmin2 - ((zRand - fDz) / (2.*fDz)) * (fRmin1 - fRmin2);
993 rmax = fRmax2 - ((zRand - fDz) / (2.*fDz)) * (fRmax1 - fRmax2);
995 point =
UVector3(rRand1 * std::cos(startPhi),
996 rRand1 * std::sin(startPhi), zRand);
1001 rmin = fRmin2 - ((zRand - fDz) / (2.*fDz)) * (fRmin1 - fRmin2);
1002 rmax = fRmax2 - ((zRand - fDz) / (2.*fDz)) * (fRmax1 - fRmax2);
1005 rRand1 * std::sin(
endPhi), zRand);
1009 return point + offset;
1019 double zOne,
double zTwo,
1020 double& totArea)
const
1022 double xRand, yRand, zRand, phi, cosphi, sinphi, chose,
1023 aOne, aTwo, aFou, rRand, fDz, fSPhi, fDPhi;
1024 fDz = std::fabs(0.5 * (zTwo - zOne));
1028 aOne = 2.*fDz * fDPhi * fRMax;
1029 aTwo = 2.*fDz * fDPhi * fRMin;
1030 aFou = 2.*fDz * (fRMax - fRMin);
1031 totArea = aOne + aTwo + 2.*aFou;
1033 cosphi = std::cos(phi);
1034 sinphi = std::sin(phi);
1041 if ((chose >= 0) && (chose < aOne))
1043 xRand = fRMax * cosphi;
1044 yRand = fRMax * sinphi;
1046 return UVector3(xRand, yRand, zRand + 0.5 * (zTwo + zOne));
1048 else if ((chose >= aOne) && (chose < aOne + aTwo))
1050 xRand = fRMin * cosphi;
1051 yRand = fRMin * sinphi;
1053 return UVector3(xRand, yRand, zRand + 0.5 * (zTwo + zOne));
1055 else if ((chose >= aOne + aTwo) && (chose < aOne + aTwo + aFou))
1057 xRand = rRand * std::cos(fSPhi + fDPhi);
1058 yRand = rRand * std::sin(fSPhi + fDPhi);
1060 return UVector3(xRand, yRand, zRand + 0.5 * (zTwo + zOne));
1065 xRand = rRand * std::cos(fSPhi + fDPhi);
1066 yRand = rRand * std::sin(fSPhi + fDPhi);
1068 return UVector3(xRand, yRand, zRand + 0.5 * (zTwo + zOne));
1078 double fRMin2,
double fRMax2,
1081 double xRand, yRand, phi, cosphi, sinphi, rRand1, rRand2, A1, Atot, rCh;
1083 cosphi = std::cos(phi);
1084 sinphi = std::sin(phi);
1086 if (fRMin1 == fRMin2)
1094 A1 = std::fabs(fRMin2 * fRMin2 - fRMin1 * fRMin1);
1096 if (fRMax1 == fRMax2)
1104 Atot = A1 + std::fabs(fRMax2 * fRMax2 - fRMax1 * fRMax1);
1113 xRand = rRand1 * cosphi;
1114 yRand = rRand1 * sinphi;
1116 return UVector3(xRand, yRand, zOne);
1126 double fRMin2,
double fRMax2,
1127 double zOne,
double zTwo,
1128 double& totArea)
const
1134 if ((fRMin1 == fRMin2) && (fRMax1 == fRMax2))
1138 return GetPointOnCone(fRMin1, fRMax1, fRMin2, fRMax2, zOne, zTwo, totArea);
1147 double Area = 0, totArea = 0, Achose1 = 0, Achose2 = 0, phi, cosphi, sinphi, rRand;
1152 cosphi = std::cos(phi);
1153 sinphi = std::sin(phi);
1159 std::vector<double> areas;
1160 std::vector<UVector3> points;
1165 for (i = 0; i < numPlanes - 1; i++)
1190 areas.push_back(Area);
1197 totArea += (areas[0] + areas[numPlanes]);
1200 if ((chose >= 0.) && (chose < areas[0]))
1202 return UVector3(rRand * cosphi, rRand * sinphi,
1206 for (i = 0; i < numPlanes - 1; i++)
1208 Achose1 += areas[i];
1209 Achose2 = (Achose1 + areas[i + 1]);
1210 if (chose >= Achose1 && chose < Achose2)
1225 return UVector3(rRand * cosphi, rRand * sinphi,
1235 : fStartAngle(0.), fOpeningAngle(0.), fNumZPlanes(0),
1236 fZValues(0), Rmin(0), Rmax(0)
1266 if (&right ==
this)
return *
this;
1306 if (
this == &source)
return *
this;
1355 bool isConvertible =
true;
1356 double Zmax = rz->
Bmax();
1361 std::vector<double> Z;
1362 std::vector<double> Rmin;
1363 std::vector<double> Rmax;
1365 int countPlanes = 1;
1372 double Zprev = Z[0];
1379 else if (Zprev ==
corners[numPlanes - 1].z)
1381 Rmin.push_back(
corners[numPlanes - 1].r);
1383 icurl = numPlanes - 1;
1393 int inextr = 0, inextl = 0;
1394 for (
int i = 0; i < numPlanes - 2; i++)
1397 inextl = (icurl <= 0) ? numPlanes - 1 : icurl - 1;
1417 Rmin.push_back(
corners[icurl].r);
1418 Rmax.push_back(Rmax[countPlanes - 2]);
1419 Rmax[countPlanes - 2] =
corners[icurl].
r;
1423 Rmin.push_back(
corners[inextl].r);
1424 Rmax.push_back(
corners[icurl].r);
1429 Rmin.push_back(
corners[inextl].r);
1430 Rmax.push_back(
corners[icurr].r + (Zleft -
corners[icurr].z) / difZr
1435 isConvertible =
false;
1438 icurl = (icurl == 0) ? numPlanes - 1 : icurl - 1;
1446 icurl = (icurl == 0) ? numPlanes - 1 : icurl - 1;
1448 Rmin.push_back(
corners[inextl].r);
1449 Rmax.push_back(
corners[inextr].r);
1453 Z.push_back(Zright);
1462 Rmin.push_back(
corners[icurr].r);
1463 Rmax.push_back(
corners[inextr].r);
1467 Rmin.push_back(
corners[inextr].r);
1468 Rmax.push_back(
corners[icurr].r);
1469 Rmax[countPlanes - 2] =
corners[inextr].
r;
1477 Rmax.push_back(
corners[inextr].r);
1478 Rmin.push_back(
corners[icurr].r);
1482 Rmax.push_back(
corners[inextr].r);
1483 Rmin.push_back(
corners[icurl].r + (Zright -
corners[icurl].z) / difZl
1490 isConvertible =
false;
1501 inextl = (icurl <= 0) ? numPlanes - 1 : icurl - 1;
1505 Rmax.push_back(
corners[inextr].r);
1506 Rmin.push_back(
corners[inextl].r);
1510 Rmax.push_back(
corners[inextr].r);
1511 Rmin.push_back(
corners[inextl].r);
1523 for (
int j = 0; j < countPlanes; j++)
1536 std::ostringstream message;
1537 message <<
"Polycone " <<
GetName() << std::endl
1538 <<
"cannot be converted to Polycone with (Rmin,Rmaz,Z) parameters!";
1540 Warning, 1,
"can not convert");
1548 for (
int j = 0; j < numPlanes; j++)
1558 return isConvertible;
1573 double* Z, *R1, *R2;
1575 Z =
new double[num];
1576 R1 =
new double[num];
1577 R2 =
new double[num];
1578 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
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