Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4CylindricalSurface Class Reference

#include <G4CylindricalSurface.hh>

+ Inheritance diagram for G4CylindricalSurface:

Public Member Functions

 G4CylindricalSurface ()
 
 G4CylindricalSurface (const G4Vector3D &o, const G4Vector3D &a, G4double r)
 
virtual ~G4CylindricalSurface ()
 
G4int operator== (const G4CylindricalSurface &c) const
 
G4String GetEntityType () const
 
virtual const char * NameOf () const
 
virtual void PrintOn (std::ostream &os=G4cout) const
 
virtual G4double HowNear (const G4Vector3D &x) const
 
virtual G4Vector3D Normal (const G4Vector3D &p) const
 
virtual G4Vector3D SurfaceNormal (const G4Point3D &p) const
 
virtual G4int Inside (const G4Vector3D &x) const
 
virtual G4int WithinBoundary (const G4Vector3D &x) const
 
virtual G4double Scale () const
 
G4int Intersect (const G4Ray &ry)
 
G4Vector3D GetAxis () const
 
G4double GetRadius () const
 
void SetRadius (G4double r)
 
- Public Member Functions inherited from G4Surface
 G4Surface ()
 
virtual ~G4Surface ()
 
G4int operator== (const G4Surface &s)
 
virtual G4String GetEntityType () const
 
virtual const char * Name () const
 
virtual G4int MyType () const
 
void SetBoundaries (G4CurveVector *)
 
virtual G4double HowNear (const G4Vector3D &x) const
 
virtual G4double ClosestDistanceToPoint (const G4Point3D &Pt)
 
G4Vector3D GetOrigin () const
 
G4double GetDistance () const
 
void SetDistance (G4double Dist)
 
G4int IsActive () const
 
void SetActive (G4int act)
 
void Deactivate ()
 
void SetSameSense (G4int sameSense0)
 
G4int GetSameSense () const
 
G4BoundingBox3DGetBBox ()
 
const G4Point3DGetClosestHit () const
 
void SetNextNode (G4Surface *)
 
G4SurfaceGetNextNode ()
 
virtual void Reset ()
 
virtual G4int Intersect (const G4Ray &)
 
virtual G4Vector3D Normal (const G4Vector3D &p) const
 
virtual void CalcBBox ()
 
virtual G4double GetUHit () const
 
virtual G4double GetVHit () const
 
virtual G4Point3D Evaluation (const G4Ray &G4Rayref)
 
virtual G4int Evaluate (register const G4Ray &Rayref)
 
virtual void Project ()
 
virtual void CalcNormal ()
 
virtual G4int IsConvex () const
 
virtual G4int GetConvex () const
 
virtual G4int GetNumberOfPoints () const
 
virtual const G4Point3DGetPoint (G4int Count) const
 
virtual G4RayNorm ()
 
virtual G4Vector3D SurfaceNormal (const G4Point3D &Pt) const =0
 
- Public Member Functions inherited from G4STEPEntity
 G4STEPEntity ()
 
virtual ~G4STEPEntity ()
 
virtual G4String GetEntityType () const =0
 

Protected Attributes

G4Vector3D axis
 
G4double radius
 
- Protected Attributes inherited from G4Surface
G4BoundingBox3Dbbox
 
G4Point3D closest_hit
 
G4Surfacenext
 
G4SurfaceBoundary surfaceBoundary
 
G4double kCarTolerance
 
G4double kAngTolerance
 
G4int Intersected
 
G4Vector3D origin
 
G4int Type
 
G4int AdvancedFace
 
G4int active
 
G4double distance
 
G4double uhit
 
G4double vhit
 
G4int sameSense
 

Additional Inherited Members

- Static Public Member Functions inherited from G4Surface
static void Project (G4double &Coord, const G4Point3D &Pt, const G4Plane &Pl)
 
- Protected Member Functions inherited from G4Surface
virtual void InitBounded ()
 

Detailed Description

Definition at line 48 of file G4CylindricalSurface.hh.

Constructor & Destructor Documentation

◆ G4CylindricalSurface() [1/2]

G4CylindricalSurface::G4CylindricalSurface ( )

Definition at line 40 of file G4CylindricalSurface.cc.

40 : G4Surface()
41{
42 // default constructor
43 // default axis is ( 1.0, 0.0, 0.0 ), default radius is 1.0
44
45 axis = G4Vector3D( 1.0, 0.0, 0.0 );
46 radius = 1.0;
47}
HepGeom::Vector3D< G4double > G4Vector3D
Definition: G4Vector3D.hh:35

◆ G4CylindricalSurface() [2/2]

G4CylindricalSurface::G4CylindricalSurface ( const G4Vector3D o,
const G4Vector3D a,
G4double  r 
)

Definition at line 50 of file G4CylindricalSurface.cc.

53 : G4Surface()
54{
55 // Normal constructor
56 // require axis to be a unit vector
57
58 G4double amag = a.mag();
59 if ( amag != 0.0 )
60 {
61 axis = a * (1/ amag); // this makes the axis a unit vector
62 }
63 else
64 {
65 std::ostringstream message;
66 message << "Axis has zero length." << G4endl
67 << "Default axis ( 1.0, 0.0, 0.0 ) is used.";
68 G4Exception("G4CylindricalSurface::G4CylindricalSurface()",
69 "GeomSolids1001", JustWarning, message);
70
71 axis = G4Vector3D( 1.0, 0.0, 0.0 );
72 }
73
74 // Require radius to be non-negative
75 //
76 if ( r >= 0.0 )
77 {
78 radius = r;
79 }
80 else
81 {
82 std::ostringstream message;
83 message << "Negative radius." << G4endl
84 << "Default radius of 1.0 is used.";
85 G4Exception("G4CylindricalSurface::G4CylindricalSurface()",
86 "GeomSolids1001", JustWarning, message);
87
88 radius = 1.0;
89 }
90
91 origin =o;
92}
@ JustWarning
double G4double
Definition: G4Types.hh:64
#define G4endl
Definition: G4ios.hh:52
G4Vector3D origin
Definition: G4Surface.hh:197
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

◆ ~G4CylindricalSurface()

G4CylindricalSurface::~G4CylindricalSurface ( )
virtual

Definition at line 95 of file G4CylindricalSurface.cc.

96{
97}

Member Function Documentation

◆ GetAxis()

G4Vector3D G4CylindricalSurface::GetAxis ( ) const
inline

Referenced by Intersect().

◆ GetEntityType()

G4String G4CylindricalSurface::GetEntityType ( ) const
inlinevirtual

Reimplemented from G4Surface.

◆ GetRadius()

G4double G4CylindricalSurface::GetRadius ( ) const
inline

Referenced by Intersect().

◆ HowNear()

G4double G4CylindricalSurface::HowNear ( const G4Vector3D x) const
virtual

Reimplemented from G4Surface.

Definition at line 241 of file G4CylindricalSurface.cc.

242{
243 // Distance from the point x to the infinite G4CylindricalSurface.
244 // The distance will be positive if the point is Inside the
245 // G4CylindricalSurface, negative if the point is outside.
246 // Note that this may not be correct for a bounded cylindrical object
247 // subclassed to G4CylindricalSurface.
248
249 G4Vector3D d = x - origin;
250 G4double dA = d * axis;
251 G4double rds = std::sqrt( d.mag2() - dA*dA );
252 G4double hownear = std::fabs( radius - rds );
253
254 return hownear;
255}

Referenced by Inside(), and WithinBoundary().

◆ Inside()

G4int G4CylindricalSurface::Inside ( const G4Vector3D x) const
virtual

Definition at line 868 of file G4CylindricalSurface.cc.

869{
870 // Return 0 if point x is outside G4CylindricalSurface, 1 if Inside.
871 // Outside means that the distance to the G4CylindricalSurface would
872 // be negative. Use the HowNear function to calculate this distance.
873
874 if ( HowNear( x ) >= -0.5*kCarTolerance )
875 { return 1; }
876 else
877 { return 0; }
878}
virtual G4double HowNear(const G4Vector3D &x) const
G4double kCarTolerance
Definition: G4Surface.hh:192

Referenced by Intersect().

◆ Intersect()

G4int G4CylindricalSurface::Intersect ( const G4Ray ry)
virtual

Reimplemented from G4Surface.

Definition at line 128 of file G4CylindricalSurface.cc.

129{
130 // Distance along a Ray (straight line with G4ThreeVec) to leave or enter
131 // a G4CylindricalSurface. The input variable which_way should be set
132 // to +1 to indicate leaving a G4CylindricalSurface, -1 to indicate
133 // entering a G4CylindricalSurface.
134 // p is the point of intersection of the Ray with the G4CylindricalSurface.
135 // If the G4Vector3D of the Ray is opposite to that of the Normal to
136 // the G4CylindricalSurface at the intersection point, it will not leave
137 // the G4CylindricalSurface.
138 // Similarly, if the G4Vector3D of the Ray is along that of the Normal
139 // to the G4CylindricalSurface at the intersection point, it will not enter
140 // the G4CylindricalSurface.
141 // This method is called by all finite shapes sub-classed to
142 // G4CylindricalSurface.
143 // Use the virtual function table to check if the intersection point
144 // is within the boundary of the finite shape.
145 // A negative result means no intersection.
146 // If no valid intersection point is found, set the distance
147 // and intersection point to large numbers.
148
149 G4int which_way=1;
150
151 if(!Inside(ry.GetStart())) { which_way = -1; }
152
153 distance = kInfinity;
154 G4Vector3D lv ( kInfinity, kInfinity, kInfinity );
155
156 closest_hit = lv;
157
158 // Origin and G4Vector3D unit vector of Ray.
159 //
160 G4Vector3D x = ry.GetStart();
161 G4Vector3D dhat = ry.GetDir();
162
163 // Axis unit vector of the G4CylindricalSurface.
164 //
165 G4Vector3D ahat = GetAxis();
166 G4int isoln = 0,
167 maxsoln = 2;
168
169 // Array of solutions in distance along the Ray.
170 //
171 G4double sol[2];
172 sol[0] = -1.0;
173 sol[1] = -1.0 ;
174
175 // Calculate the two solutions (quadratic equation)
176 //
177 G4Vector3D d = x - GetOrigin();
178 G4double radiu = GetRadius();
179
180 G4double dsq = d * d;
181 G4double da = d * ahat;
182 G4double dasq = da * da;
183 G4double rsq = radiu * radiu;
184 G4double qsq = dsq - dasq;
185 G4double dira = dhat * ahat;
186 G4double a = 1.0 - dira * dira;
187
188 if ( a <= 0.0 ) { return 0; }
189
190 G4double b = 2. * ( d * dhat - da * dira );
191 G4double c = rsq - qsq;
192 G4double radical = b * b + 4. * a * c;
193
194 if ( radical < 0.0 ) { return 0; }
195
196 G4double root = std::sqrt( radical );
197 sol[0] = ( - b + root ) / ( 2. * a );
198 sol[1] = ( - b - root ) / ( 2. * a );
199
200 // Order the possible solutions by increasing distance along the Ray
201 //
202 sort_double( sol, isoln, maxsoln-1 );
203
204 // Now loop over each positive solution, keeping the first one (smallest
205 // distance along the Ray) which is within the boundary of the sub-shape
206 // and which also has the correct G4Vector3D with respect to the Normal to
207 // the G4CylindricalSurface at the intersection point
208 //
209 for ( isoln = 0; isoln < maxsoln; isoln++ )
210 {
211 if ( sol[isoln] >= kCarTolerance*0.5 )
212 {
213 if ( sol[isoln] >= kInfinity ) // quit if too large
214 { return 0; }
215
216 distance = sol[isoln];
218 G4double tmp = dhat * (Normal( closest_hit ));
219
220 if ((tmp * which_way) >= 0.0 )
221 {
222 if ( WithinBoundary( closest_hit ) == 1 )
223 {
225 }
226 }
227 return 1;
228 }
229 }
230
231 // Get here only if there was no solution within the boundary, Reset
232 // distance and intersection point to large numbers
233 //
234 distance = kInfinity;
235 closest_hit = lv;
236
237 return 0;
238}
void sort_double(G4double[], G4int, G4int)
Definition: G4Sort.cc:39
int G4int
Definition: G4Types.hh:66
G4Vector3D GetAxis() const
virtual G4int Inside(const G4Vector3D &x) const
virtual G4Vector3D Normal(const G4Vector3D &p) const
G4double GetRadius() const
virtual G4int WithinBoundary(const G4Vector3D &x) const
G4Point3D GetPoint(G4double i) const
const G4Vector3D & GetDir() const
const G4Point3D & GetStart() const
G4double distance
Definition: G4Surface.hh:203
G4Vector3D GetOrigin() const
G4Point3D closest_hit
Definition: G4Surface.hh:186

◆ NameOf()

const char * G4CylindricalSurface::NameOf ( ) const
virtual

Definition at line 117 of file G4CylindricalSurface.cc.

118{
119 return "G4CylindricalSurface";
120}

◆ Normal()

G4Vector3D G4CylindricalSurface::Normal ( const G4Vector3D p) const
virtual

Reimplemented from G4Surface.

Definition at line 840 of file G4CylindricalSurface.cc.

841{
842 // return the Normal unit vector to the G4CylindricalSurface
843 // at a point p on (or nearly on) the G4CylindricalSurface
844
845 G4Vector3D n = ( p - origin ) - ( ( p - origin ) * axis ) * axis;
846 G4double nmag = n.mag();
847
848 if ( nmag != 0.0 ) { n = n * (1/nmag); }
849
850 return n;
851}

Referenced by Intersect().

◆ operator==()

G4int G4CylindricalSurface::operator== ( const G4CylindricalSurface c) const
inline

◆ PrintOn()

void G4CylindricalSurface::PrintOn ( std::ostream &  os = G4cout) const
virtual

Definition at line 122 of file G4CylindricalSurface.cc.

123{
124 os << "G4CylindricalSurface surface with origin: " << origin << "\t"
125 << "radius: " << radius << "\tand axis " << axis << "\n";
126}

◆ Scale()

G4double G4CylindricalSurface::Scale ( ) const
virtual

Definition at line 893 of file G4CylindricalSurface.cc.

894{
895 // Returns the radius of a G4CylindricalSurface unless it is zero, in which
896 // case returns the arbitrary number 1.0.
897 // This is ok since derived finite-sized classes will overwrite this.
898 // Used for Scale-invariant tests of surface thickness.
899
900 if ( radius == 0.0 )
901 { return 1.0; }
902 else
903 { return radius; }
904}

Referenced by WithinBoundary().

◆ SetRadius()

void G4CylindricalSurface::SetRadius ( G4double  r)

Definition at line 942 of file G4CylindricalSurface.cc.

943{
944 // Reset the radius of the G4CylindricalSurface
945 // Require radius to be non-negative
946
947 if ( r >= 0.0 ) { radius = r; }
948 else // Use old value (do not change radius) if out of the range,
949 { // but print warning message
950 std::ostringstream message;
951 message << "Negative radius." << G4endl
952 << "Default radius of " << radius << " is used.";
953 G4Exception("G4CylindricalSurface::SetRadius()",
954 "GeomSolids1001", JustWarning, message);
955 }
956}

◆ SurfaceNormal()

G4Vector3D G4CylindricalSurface::SurfaceNormal ( const G4Point3D p) const
virtual

Implements G4Surface.

Definition at line 854 of file G4CylindricalSurface.cc.

855{
856 // return the Normal unit vector to the G4CylindricalSurface at a point
857 // p on (or nearly on) the G4CylindricalSurface
858
859 G4Vector3D n = ( p - origin ) - ( ( p - origin ) * axis ) * axis;
860 G4double nmag = n.mag();
861
862 if ( nmag != 0.0 ) { n = n * (1/nmag); }
863
864 return n;
865}

◆ WithinBoundary()

G4int G4CylindricalSurface::WithinBoundary ( const G4Vector3D x) const
virtual

Definition at line 881 of file G4CylindricalSurface.cc.

882{
883 // return 1 if point x is on the G4CylindricalSurface, otherwise return zero
884 // base this on the surface precision factor
885
886 if ( std::fabs( HowNear( x ) / Scale() ) <= SURFACE_PRECISION )
887 { return 1; }
888 else
889 { return 0; }
890}
#define SURFACE_PRECISION
Definition: G4Globals.hh:47
virtual G4double Scale() const

Referenced by Intersect().

Member Data Documentation

◆ axis

G4Vector3D G4CylindricalSurface::axis
protected

◆ radius

G4double G4CylindricalSurface::radius
protected

Definition at line 180 of file G4CylindricalSurface.hh.

Referenced by G4CylindricalSurface(), HowNear(), PrintOn(), Scale(), and SetRadius().


The documentation for this class was generated from the following files: