Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/Geant4/G4PolyconeSide.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4PolyconeSide
0027 //
0028 // Class description:
0029 //
0030 // Class implementing a face that represents one conical side of a polycone:
0031 //
0032 //   G4PolyconeSide( const G4PolyconeSideRZ* prevRZ,
0033 //                   const G4PolyconeSideRZ* tail,
0034 //                   const G4PolyconeSideRZ* head,
0035 //                   const G4PolyconeSideRZ* nextRZ,
0036 //                         G4double phiStart, G4double deltaPhi, 
0037 //                         G4bool phiIsOpen, G4bool isAllBehind=false )
0038 //
0039 // Values for r1,z1 and r2,z2 should be specified in clockwise order in (r,z).
0040 
0041 // Author: David C. Williams (UCSC), 1998 - Created
0042 // --------------------------------------------------------------------
0043 #ifndef G4POLYCONESIDE_HH
0044 #define G4POLYCONESIDE_HH
0045 
0046 #include "G4VCSGface.hh"
0047 
0048 class G4IntersectingCone;
0049 
0050 struct G4PolyconeSideRZ
0051 {
0052   G4double r, z;  // start of vector
0053 };
0054 
0055 // ----------------------------------------------------------------------------
0056 // MT-specific utility code 
0057 
0058 #include "G4GeomSplitter.hh"
0059 
0060 // The class G4PlSideData is introduced to encapsulate the
0061 // fields of the class G4PolyconeSide that may not be read-only.
0062 //
0063 class G4PlSideData
0064 {
0065   public:
0066 
0067     void initialize()
0068     {
0069       fPhix = 0.; fPhiy = 0.; fPhiz = 0.; fPhik = 0.;
0070     }
0071 
0072     G4double fPhix=0., fPhiy=0., fPhiz=0., fPhik=0.;   // Cached values for phi
0073 };
0074 
0075 // The type G4PlSideManager is introduced to 
0076 // encapsulate the methods used by both the master thread and 
0077 // worker threads to allocate memory space for the fields encapsulated
0078 // by the class G4PlSideData.
0079 //
0080 using G4PlSideManager = G4GeomSplitter<G4PlSideData>;
0081 
0082 //
0083 // ----------------------------------------------------------------------------
0084 
0085 /**
0086  * @brief G4PolyconeSide is a utility class implementing a face that
0087  * represents one conical side of a polycone.
0088  */
0089 
0090 class G4PolyconeSide : public G4VCSGface
0091 {
0092   public:
0093 
0094     /**
0095      * Constructor for the conical side of a polycone.
0096      *  @param[in] prevRZ Pointer to previous r,Z section.
0097      *  @param[in] tail Pointer to r,Z tail of section.
0098      *  @param[in] head Pointer to r,Z head of section.
0099      *  @param[in] nextRZ Pointer to next r,Z section.
0100      *  @param[in] phiStart Initial Phi starting angle.
0101      *  @param[in] deltaPhi Total Phi angle.
0102      *  @param[in] phiIsOpen Flag indicating if it is a Phi section.
0103      *  @param[in] isAllBehind Indicating if entire surface is behind normal.
0104      */
0105     G4PolyconeSide( const G4PolyconeSideRZ* prevRZ,
0106                     const G4PolyconeSideRZ* tail,
0107                     const G4PolyconeSideRZ* head,
0108                     const G4PolyconeSideRZ* nextRZ,
0109                           G4double phiStart, G4double deltaPhi, 
0110                           G4bool phiIsOpen, G4bool isAllBehind = false );
0111 
0112     /**
0113      * Destructor.
0114      */
0115     ~G4PolyconeSide() override;
0116   
0117     /**
0118      * Copy constructor and assignment operator.
0119      */
0120     G4PolyconeSide( const G4PolyconeSide& source );
0121     G4PolyconeSide& operator=( const G4PolyconeSide& source );
0122   
0123     /**
0124      * Determines the distance along a line to the face.
0125      *  @param[in] p Position.
0126      *  @param[in] v Direction (assumed to be a unit vector).
0127      *  @param[in] outgoing Flag true, to consider only inside surfaces;
0128      *             false, to consider only outside surfaces.
0129      *  @param[in] surfTolerance Minimum distance from the surface.
0130      *  @param[out] distance Distance to intersection.
0131      *  @param[out] distFromSurface Distance from surface (along surface normal),
0132      *              < 0 if the point is in front of the surface.
0133      *  @param[out] normal Normal of surface at intersection point.
0134      *  @param[out] allBehind Flag, true, if entire surface is behind normal.
0135      *  @returns true if there is an intersection, false otherwise.
0136      */
0137     G4bool Intersect(const G4ThreeVector& p, const G4ThreeVector& v,  
0138                            G4bool outgoing, G4double surfTolerance,
0139                            G4double& distance, G4double &distFromSurface,
0140                            G4ThreeVector& normal, G4bool& isAllBehind) override;
0141 
0142     /**
0143      * Determines the distance of a point from either the inside or outside
0144      * surfaces of the face.
0145      *  @param[in] p Position.
0146      *  @param[in] outgoing Flag, true, to consider only inside surfaces
0147      *             or false, to consider only outside surfaces.
0148      *  @returns The distance to the closest surface satisfying requirements
0149      *           or kInfinity if no such surface exists.
0150      */
0151     G4double Distance( const G4ThreeVector& p, G4bool outgoing ) override;
0152   
0153     /**
0154      * Determines whether a point is inside, outside, or on the surface of
0155      * the face.
0156      *  @param[in] p Position.
0157      *  @param[in] tolerance Tolerance defining the bounds of the "kSurface",
0158      *             nominally equal to kCarTolerance/2.
0159      *  @param[out] bestDistance Distance to the closest surface (in or out).
0160      *  @returns kInside if the point is closest to the inside surface;
0161      *           kOutside if the point is closest to the outside surface;
0162      *           kSurface if the point is withing tolerance of the surface.
0163      */
0164     EInside Inside( const G4ThreeVector& p, G4double tolerance, 
0165                           G4double* bestDistance ) override;
0166   
0167     /**
0168      * Returns the normal of surface closest to the point.
0169      *  @param[in] p Position.
0170      *  @param[out] bestDistance Distance to the closest surface (in or out).
0171      *  @returns The normal of the surface nearest the point.
0172      */
0173     G4ThreeVector Normal( const G4ThreeVector& p,
0174                                 G4double* bestDistance ) override;
0175 
0176     /**
0177      * Returns the face extent along the axis.
0178      *  @param[in] axis Unit vector defining the direction.
0179      *  @returns The largest point along the given axis of the face's extent.
0180      */
0181     G4double Extent( const G4ThreeVector axis ) override;
0182 
0183     /**
0184      * Calculates the extent of the face for the voxel navigator.
0185      *  @param[in] axis The axis in which to check the shapes 3D extent against.
0186      *  @param[in] voxelLimit Limits along x, y, and/or z axes.
0187      *  @param[in] tranform A coordinate transformation on which to apply to
0188      *             the shape before testing.
0189      *  @param[out] extentList The list of (voxel) extents along the axis.
0190      */
0191     void CalculateExtent( const EAxis axis, 
0192                           const G4VoxelLimits& voxelLimit,
0193                           const G4AffineTransform& tranform,
0194                                 G4SolidExtentList& extentList ) override;
0195 
0196     /**
0197      * Method invoked by the copy constructor or the assignment operator.
0198      * Its purpose is to return a pointer to a duplicate copy of the face.
0199      */
0200     inline G4VCSGface* Clone() override { return new G4PolyconeSide( *this ); }
0201 
0202     /**
0203      * Returning an estimation of the face surface area, in internal units.
0204      */
0205     G4double SurfaceArea() override;
0206 
0207     /**
0208      * Returns a random point located and uniformly distributed on the face.
0209      */
0210     G4ThreeVector GetPointOnFace() override;
0211   
0212     /**
0213      * Fake default constructor for usage restricted to direct object
0214      * persistency for clients requiring preallocation of memory for
0215      * persistifiable objects.
0216      */
0217     G4PolyconeSide(__void__&);
0218 
0219     /**
0220      * Returns the instance ID.
0221      */
0222     inline G4int GetInstanceID() const  { return instanceID; }
0223 
0224     /**
0225      * Returns the private data instance manager.
0226      */
0227     static const G4PlSideManager& GetSubInstanceManager();
0228 
0229   private:
0230 
0231     /**
0232      * Calculates the distance of a point from the conical surface, including
0233      * the effect of any phi segmentation.
0234      *  @param[in] p The point to check.
0235      *  @param[in] opposite If true, check the opposite hemisphere (see below).
0236      *  @param[out] distOutside Additional distance outside the edges of surface.
0237      *  @param[out] rzNorm If negative, the point is inside.
0238      *  @returns The distance from the conical plane, if extrapolated beyond
0239      *           edges, signed by whether the point is in inside or outside
0240      *           the shape.
0241      */
0242     G4double DistanceAway( const G4ThreeVector& p, G4bool opposite,
0243                                  G4double& distOutside,
0244                                  G4double* rzNorm = nullptr );
0245       
0246     /**
0247      * Special version of DistanceAway() for Inside. Opposite parameter is not
0248      * used, instead use sign of rx for choosing the side.
0249      *  @param[in] p The point to check.
0250      *  @param[out] distOutside Additional distance outside the edges of surface.
0251      *  @param[out] edgeRZnorm If negative, the point is inside.
0252      *  @returns The distance from the conical plane.
0253      */
0254     G4double DistanceAway( const G4ThreeVector& p, G4double& distOutside,
0255                                  G4double* edgeRZnorm );
0256 
0257     /**
0258      * Decides if a point is on a cone and returns the 'normal' if it is.
0259      *  @returns true if the point is on the cone.
0260      */
0261     G4bool PointOnCone( const G4ThreeVector& hit, G4double normSign,
0262                         const G4ThreeVector& p,
0263                         const G4ThreeVector& v, G4ThreeVector& normal );
0264 
0265     /**
0266      * Copies parameters from other object; used in copy constructor and
0267      * assignment operator.
0268      */
0269     void CopyStuff( const G4PolyconeSide& source );
0270   
0271     /**
0272      * Decides the point at which two 2-dimensional lines intersect.
0273      * It is assumed that the lines are *not* parallel.
0274      */
0275     static void FindLineIntersect( G4double x1, G4double y1,
0276                                    G4double tx1, G4double ty1,
0277                                    G4double x2, G4double y2,
0278                                    G4double tx2, G4double ty2,
0279                                    G4double& x, G4double& y );
0280 
0281     /**
0282      * Calculates Phi for a given 3-vector (point 'p'), if not already cached
0283      * for the same point, in the attempt to avoid consecutive computation of
0284      * the same quantity.
0285      */
0286     G4double GetPhi( const G4ThreeVector& p );
0287 
0288   private:
0289 
0290     G4double r[2], z[2]; // r, z parameters, in specified order
0291     G4double startPhi,   // Start phi (0 to 2pi), if phiIsOpen
0292              deltaPhi;   // Delta phi (0 to 2pi), if phiIsOpen
0293     G4bool phiIsOpen = false; // True if there is a phi slice
0294     G4bool allBehind = false; // True if the entire solid is "behind" this face
0295   
0296     G4IntersectingCone* cone = nullptr;  // Our intersecting utility class
0297   
0298     G4double rNorm, zNorm;  // Normal to surface in r,z space
0299     G4double rS, zS;        // Unit vector along surface in r,z space
0300     G4double length;        // Length of face in r,z space
0301     G4double prevRS,
0302              prevZS;        // Unit vector along previous polyconeSide
0303     G4double nextRS,
0304              nextZS;        // Unit vector along next polyconeSide
0305   
0306     G4double rNormEdge[2],
0307              zNormEdge[2];  // Normal to edges
0308 
0309     G4int ncorners = 0;
0310     G4ThreeVector* corners = nullptr; // The coordinates of the corners
0311                                       // (if phiIsOpen)
0312 
0313     G4double kCarTolerance;       // Geometrical surface thickness
0314     G4double fSurfaceArea = 0.0;  // Used for surface calculation 
0315 
0316     G4int instanceID;
0317       // This field is used as instance ID.
0318     G4GEOM_DLL static G4PlSideManager subInstanceManager;
0319       // This field helps to use the class G4PlSideManager introduced above.
0320 };
0321 
0322 #endif