60 using namespace CLHEP;
77 if ( pDx > 0 && pDy > 0 && pDz > 0 )
82 fTalpha = std::tan(pAlpha);
83 fTthetaCphi = std::tan(pTheta)*std::cos(pPhi);
84 fTthetaSphi = std::tan(pTheta)*std::sin(pPhi);
88 std::ostringstream message;
89 message <<
"Invalid Length Parameters for Solid: " << GetName() <<
G4endl
90 <<
" pDx, pDy, pDz = "
91 << pDx <<
", " << pDy <<
", " << pDz;
92 G4Exception(
"G4Para::SetAllParameters()",
"GeomSolids0002",
107 if ((pDx<=0) || (pDy<=0) || (pDz<=0))
109 std::ostringstream message;
110 message <<
"Invalid Length Parameters for Solid: " <<
GetName() <<
G4endl
111 <<
" pDx, pDy, pDz = "
112 << pDx <<
", " << pDy <<
", " << pDz;
129 if (!( pt[0].
z()<0 && pt[0].
z()==pt[1].
z() && pt[0].
z()==pt[2].
z() &&
130 pt[0].
z()==pt[3].
z() && pt[4].
z()>0 && pt[4].
z()==pt[5].
z() &&
131 pt[4].
z()==pt[6].
z() && pt[4].
z()==pt[7].
z() &&
132 (pt[0].
z()+pt[4].
z())==0 &&
133 pt[0].y()==pt[1].y() && pt[2].y()==pt[3].y() &&
134 pt[4].y()==pt[5].y() && pt[6].y()==pt[7].y() &&
135 ( pt[0].y() + pt[2].y() + pt[4].y() + pt[6].y() ) == 0 &&
136 ( pt[0].
x() + pt[1].
x() + pt[4].
x() + pt[5].
x() ) == 0) )
138 std::ostringstream message;
139 message <<
"Invalid vertice coordinates for Solid: " <<
GetName();
143 fDx = ((pt[3]).
x()-(pt[2]).
x())*0.5;
144 fDy = ((pt[2]).y()-(pt[1]).y())*0.5;
146 fTalpha = ((pt[2]).
x()+(pt[3]).
x()-(pt[1]).
x()-(pt[0]).
x())*0.25/fDy ;
147 fTthetaCphi = ((pt[4]).
x()+fDy*fTalpha+fDx)/fDz ;
148 fTthetaSphi = ((pt[4]).y()+fDy)/fDz ;
160 fTalpha(0.), fTthetaCphi(0.), fTthetaSphi(0.)
176 :
G4CSGSolid(rhs), fDx(rhs.fDx), fDy(rhs.fDy), fDz(rhs.fDz),
177 fTalpha(rhs.fTalpha), fTthetaCphi(rhs.fTthetaCphi),
178 fTthetaSphi(rhs.fTthetaSphi)
190 if (
this == &rhs) {
return *
this; }
198 fDx = rhs.fDx; fDy = rhs.fDy; fDz = rhs.fDz;
199 fTalpha = rhs.fTalpha; fTthetaCphi = rhs.fTthetaCphi;
200 fTthetaSphi = rhs.fTthetaSphi;
232 std::min(-x0-x1-dx,-x0+x1-dx),x0-x1-dx),x0+x1-dx);
236 std::max(-x0-x1+dx,-x0+x1+dx),x0-x1+dx),x0+x1+dx);
242 pMin.
set(xmin,ymin,-dz);
243 pMax.
set(xmax,ymax, dz);
247 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
249 std::ostringstream message;
250 message <<
"Bad bounding box (min >= max) for solid: "
252 <<
"\npMin = " << pMin
253 <<
"\npMax = " << pMax;
276 if (
true)
return bbox.
CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
280 return exist = (pMin < pMax) ?
true :
false;
294 baseA[0].set(-x0-x1-dx,-y0-dy,-dz);
295 baseA[1].set(-x0-x1+dx,-y0-dy,-dz);
296 baseA[2].set(-x0+x1+dx,-y0+dy,-dz);
297 baseA[3].set(-x0+x1-dx,-y0+dy,-dz);
299 baseB[0].set(+x0-x1-dx, y0-dy, dz);
300 baseB[1].set(+x0-x1+dx, y0-dy, dz);
301 baseB[2].set(+x0+x1+dx, y0+dy, dz);
302 baseB[3].set(+x0+x1-dx, y0+dy, dz);
304 std::vector<const G4ThreeVectorList *> polygons(2);
305 polygons[0] = &baseA;
306 polygons[1] = &baseB;
322 yt1 = p.
y() - fTthetaSphi*p.
z();
323 yt = std::fabs(yt1) ;
327 xt = std::fabs( p.
x() - fTthetaCphi*p.
z() - fTalpha*yt1 );
359 G4int noSurfaces = 0;
367 newpx = p.
x()-fTthetaCphi*p.
z();
368 newpy = p.
y()-fTthetaSphi*p.
z();
370 calpha = 1/std::sqrt(1+fTalpha*fTalpha);
371 salpha = -calpha*fTalpha;
374 xshift = newpx - newpy*fTalpha;
377 distx = std::fabs(std::fabs(xshift)-fDx);
378 disty = std::fabs(std::fabs(newpy)-fDy);
379 distz = std::fabs(std::fabs(p.
z())-fDz);
381 tntheta = fTthetaCphi*calpha + fTthetaSphi*salpha;
382 cosntheta = 1/std::sqrt(1+tntheta*tntheta);
383 ycomp = 1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
394 if ( xshift >= 0.) {sumnorm += nX;}
395 else {sumnorm -= nX;}
400 if ( newpy >= 0.) {sumnorm += nY;}
401 else {sumnorm -= nY;}
406 if ( p.
z() >= 0.) {sumnorm += nZ;}
407 else {sumnorm -= nZ;}
409 if ( noSurfaces == 0 )
412 G4Exception(
"G4Para::SurfaceNormal(p)",
"GeomSolids1002",
415 norm = ApproxSurfaceNormal(p);
417 else if ( noSurfaces == 1 ) {norm = sumnorm;}
418 else {norm = sumnorm.
unit();}
439 newpx=p.
x()-fTthetaCphi*p.
z();
440 newpy=p.
y()-fTthetaSphi*p.
z();
442 calpha=1/std::sqrt(1+fTalpha*fTalpha);
443 salpha=-calpha*fTalpha;
445 xshift=newpx*calpha+newpy*salpha;
447 distx=std::fabs(std::fabs(xshift)-fDx*calpha);
448 disty=std::fabs(std::fabs(newpy)-fDy);
449 distz=std::fabs(std::fabs(p.
z())-fDz);
453 if (distx<distz) {side=
kNX;}
458 if (disty<distz) {side=
kNY;}
465 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha;
468 cosntheta=-1/std::sqrt(1+tntheta*tntheta);
472 cosntheta=1/std::sqrt(1+tntheta*tntheta);
474 norm=
G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta);
479 ycomp=-1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
483 ycomp=1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
534 smin=(-fDz-p.
z())/v.
z();
547 smin=(fDz-p.
z())/v.
z();
556 if (std::fabs(p.
z())<=fDz)
571 yt=p.
y()-fTthetaSphi*p.
z();
572 vy=v.
y()-fTthetaSphi*v.
z();
602 if (std::fabs(yt)<=fDy)
615 if (tmin>smin) smin=tmin;
616 if (tmax<smax) smax=tmax;
626 xt=p.
x()-fTthetaCphi*p.
z()-fTalpha*yt;
627 vx=v.
x()-fTthetaCphi*v.
z()-fTalpha*vy;
656 if (std::fabs(xt)<=fDx)
666 if (tmin>smin) smin=tmin;
667 if (tmax<smax) smax=tmax;
670 if (smax>0&&smin<smax)
696 G4double distz1,distz2,disty1,disty2,distx1,distx2;
712 trany=p.
y()-fTthetaSphi*p.
z();
716 cosy=1.0/std::sqrt(1.0+fTthetaSphi*fTthetaSphi);
717 disty1=(trany-fDy)*cosy;
718 disty2=(-fDy-trany)*cosy;
720 if (disty1>safe) safe=disty1;
721 if (disty2>safe) safe=disty2;
723 tranx=p.
x()-fTthetaCphi*p.
z()-fTalpha*trany;
724 cosx=1.0/std::sqrt(1.0+fTalpha*fTalpha+fTthetaCphi*fTthetaCphi);
725 distx1=(tranx-fDx)*cosx;
726 distx2=(-fDx-tranx)*cosx;
728 if (distx1>safe) safe=distx1;
729 if (distx2>safe) safe=distx2;
749 G4double ycomp,calpha,salpha,tntheta,cosntheta;
800 yt=p.
y()-fTthetaSphi*p.
z();
801 vy=v.
y()-fTthetaSphi*v.
z();
820 ycomp=1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
843 ycomp=-1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
854 xt=p.
x()-fTthetaCphi*p.
z()-fTalpha*yt;
855 vx=v.
x()-fTthetaCphi*v.
z()-fTalpha*vy;
873 calpha=1/std::sqrt(1+fTalpha*fTalpha);
874 salpha=-calpha*fTalpha;
875 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha;
876 cosntheta=1/std::sqrt(1+tntheta*tntheta);
877 *n=
G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta);
899 calpha=1/std::sqrt(1+fTalpha*fTalpha);
900 salpha=-calpha*fTalpha;
901 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha;
902 cosntheta=-1/std::sqrt(1+tntheta*tntheta);
903 *n=
G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta);
921 ycomp=-1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
925 ycomp=1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
929 calpha=1/std::sqrt(1+fTalpha*fTalpha);
930 salpha=-calpha*fTalpha;
931 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha;
932 cosntheta=-1/std::sqrt(1+tntheta*tntheta);
933 *n=
G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta);
936 calpha=1/std::sqrt(1+fTalpha*fTalpha);
937 salpha=-calpha*fTalpha;
938 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha;
939 cosntheta=1/std::sqrt(1+tntheta*tntheta);
940 *n=
G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta);
946 "Undefined side for valid surface normal to solid.");
961 G4double distz1,distz2,disty1,disty2,distx1,distx2;
974 G4cout.precision(oldprc) ;
975 G4Exception(
"G4Para::DistanceToOut(p)",
"GeomSolids1002",
993 trany=p.
y()-fTthetaSphi*p.
z();
997 cosy=1.0/std::sqrt(1.0+fTthetaSphi*fTthetaSphi);
998 disty1=(fDy-trany)*cosy;
999 disty2=(fDy+trany)*cosy;
1001 if (disty1<safe) safe=disty1;
1002 if (disty2<safe) safe=disty2;
1004 tranx=p.
x()-fTthetaCphi*p.
z()-fTalpha*trany;
1005 cosx=1.0/std::sqrt(1.0+fTalpha*fTalpha+fTthetaCphi*fTthetaCphi);
1006 distx1=(fDx-tranx)*cosx;
1007 distx2=(fDx+tranx)*cosx;
1009 if (distx1<safe) safe=distx1;
1010 if (distx2<safe) safe=distx2;
1031 return new G4Para(*
this);
1040 G4int oldprc = os.precision(16);
1041 os <<
"-----------------------------------------------------------\n"
1042 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
1043 <<
" ===================================================\n"
1044 <<
" Solid type: G4Para\n"
1045 <<
" Parameters: \n"
1046 <<
" half length X: " << fDx/
mm <<
" mm \n"
1047 <<
" half length Y: " << fDy/
mm <<
" mm \n"
1048 <<
" half length Z: " << fDz/
mm <<
" mm \n"
1049 <<
" std::tan(alpha) : " << fTalpha/
degree <<
" degrees \n"
1050 <<
" std::tan(theta)*std::cos(phi): " << fTthetaCphi/
degree
1052 <<
" std::tan(theta)*std::sin(phi): " << fTthetaSphi/
degree
1054 <<
"-----------------------------------------------------------\n";
1055 os.precision(oldprc);
1070 G4double lambda1, lambda2, chose, aOne, aTwo;
1079 w.
z()*v.
x() - w.
x()*v.
z(),
1080 w.
x()*v.
y() - w.
y()*v.
x());
1082 aOne = 0.5*Area.
mag();
1085 t.
z()*u.
x() - t.
x()*u.
z(),
1086 t.
x()*u.
y() - t.
y()*u.
x());
1088 aTwo = 0.5*Area.
mag();
1094 if( (chose>=0.) && (chose < aOne) )
1098 return (p2+lambda1*v+lambda2*w);
1105 return (p0+lambda1*t+lambda2*u);
1119 G4double chose, aOne, aTwo, aThree, aFour, aFive, aSix;
1122 -fDz*fTthetaSphi-fDy, -fDz);
1124 -fDz*fTthetaSphi-fDy, -fDz);
1126 -fDz*fTthetaSphi+fDy, -fDz);
1128 -fDz*fTthetaSphi+fDy, -fDz);
1130 +fDz*fTthetaSphi-fDy, +fDz);
1132 +fDz*fTthetaSphi-fDy, +fDz);
1134 +fDz*fTthetaSphi+fDy, +fDz);
1136 +fDz*fTthetaSphi+fDy, +fDz);
1140 One = GetPointOnPlane(pt[0],pt[1],pt[3],pt[2], aOne);
1141 Two = GetPointOnPlane(pt[4],pt[5],pt[7],pt[6], aTwo);
1142 Three = GetPointOnPlane(pt[6],pt[7],pt[3],pt[2], aThree);
1143 Four = GetPointOnPlane(pt[4],pt[5],pt[1],pt[0], aFour);
1144 Five = GetPointOnPlane(pt[0],pt[2],pt[6],pt[4], aFive);
1145 Six = GetPointOnPlane(pt[1],pt[3],pt[7],pt[5], aSix);
1149 if( (chose>=0.) && (chose<aOne) )
1151 else if(chose>=aOne && chose<aOne+aTwo)
1153 else if(chose>=aOne+aTwo && chose<aOne+aTwo+aThree)
1155 else if(chose>=aOne+aTwo+aThree && chose<aOne+aTwo+aThree+aFour)
1157 else if(chose>=aOne+aTwo+aThree+aFour && chose<aOne+aTwo+aThree+aFour+aFive)
1173 G4double phi = std::atan2(fTthetaSphi, fTthetaCphi);
1175 G4double theta = std::atan(std::sqrt(fTthetaCphi*fTthetaCphi
1176 +fTthetaSphi*fTthetaSphi));
void set(double x, double y, double z)
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=G4bool(false), G4bool *validNorm=0, G4ThreeVector *n=0) const
ThreeVector shoot(const G4int Ap, const G4int Af)
G4ThreeVector GetPointOnSurface() const
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
EInside Inside(const G4ThreeVector &p) const
static constexpr double mm
void SetAllParameters(G4double pDx, G4double pDy, G4double pDz, G4double pAlpha, G4double pTheta, G4double pPhi)
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
static const G4double kInfinity
CLHEP::Hep3Vector G4ThreeVector
std::vector< ExP01TrackerHit * > a
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
G4Para(const G4String &pName, G4double pDx, G4double pDy, G4double pDz, G4double pAlpha, G4double pTheta, G4double pPhi)
std::ostream & StreamInfo(std::ostream &os) const
G4Para & operator=(const G4Para &rhs)
virtual void AddSolid(const G4Box &)=0
G4Polyhedron * CreatePolyhedron() const
static double normal(HepRandomEngine *eptr)
G4GLOB_DLL std::ostream G4cout
static constexpr double degree
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
G4GeometryType GetEntityType() const
std::vector< G4ThreeVector > G4ThreeVectorList
G4double GetXHalfLength() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
void DescribeYourselfTo(G4VGraphicsScene &scene) const
G4double GetTanAlpha() const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4double GetZHalfLength() const
static const G4double alpha
G4CSGSolid & operator=(const G4CSGSolid &rhs)
void Extent(G4ThreeVector &pMin, G4ThreeVector &pMax) const
G4double GetYHalfLength() const