Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-01 09:11:50

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 // G4Polyhedra
0027 //
0028 // Class description:
0029 //
0030 // Class implementing a CSG-like type "PGON" Geant 3.21 volume,
0031 // inherited from class G4VCSGfaceted:
0032 //
0033 //   G4Polyhedra( const G4String& name,
0034 //                G4double phiStart,         - initial phi starting angle
0035 //                G4double phiTotal,         - total phi angle
0036 //                G4int numSide,             - number sides
0037 //                G4int numZPlanes,          - number of z planes
0038 //                const G4double zPlane[],   - position of z planes
0039 //                const G4double rInner[],   - tangent distance to inner surface
0040 //                const G4double rOuter[]  ) - tangent distance to outer surface
0041 //
0042 //   G4Polyhedra( const G4String& name,
0043 //                G4double phiStart,    - initial phi starting angle
0044 //                G4double phiTotal,    - total phi angle
0045 //                G4int    numSide,     - number sides
0046 //                G4int    numRZ,       - number corners in r,z space
0047 //                const G4double r[],   - r coordinates of these corners
0048 //                const G4double z[] )  - z coordinates of these corners
0049 
0050 // Author: David C. Williams (UCSC), 1998 - First implementation
0051 // --------------------------------------------------------------------
0052 #ifndef G4POLYHEDRA_HH
0053 #define G4POLYHEDRA_HH
0054 
0055 #include "G4GeomTypes.hh"
0056 
0057 #if defined(G4GEOM_USE_USOLIDS)
0058 #define G4GEOM_USE_UPOLYHEDRA 1
0059 #endif
0060 
0061 #if defined(G4GEOM_USE_UPOLYHEDRA)
0062   #define G4UPolyhedra G4Polyhedra
0063   #include "G4UPolyhedra.hh"
0064 #else
0065 
0066 #include "G4VCSGfaceted.hh"
0067 #include "G4PolyhedraSide.hh"
0068 #include "G4PolyhedraHistorical.hh"
0069 #include "G4Polyhedron.hh"
0070 
0071 class G4EnclosingCylinder;
0072 class G4ReduciblePolygon;
0073 
0074 /**
0075  * @brief G4Polyhedra represents a composed closed polyhedra (PGON) made of
0076  * planar sizes along the Z axis, with or without cut in Phi.
0077  */
0078 
0079 class G4Polyhedra : public G4VCSGfaceted
0080 {
0081   public:
0082 
0083     /**
0084      * Constructs a polyhedra, given its parameters.
0085      *  @param[in] name The solid name.
0086      *  @param[in] phiStart Initial Phi starting angle.
0087      *  @param[in] phiTotal Total Phi angle.
0088      *  @param[in] numSide Number of sides.
0089      *  @param[in] numZPlanes Number of Z planes.
0090      *  @param[in] zPlane Position of Z planes.
0091      *  @param[in] rInner Tangent distance to inner surface.
0092      *  @param[in] rOuter Tangent distance to outer surface.
0093      */
0094     G4Polyhedra(const G4String& name,
0095                       G4double phiStart,   // initial phi starting angle
0096                       G4double phiTotal,   // total phi angle
0097                       G4int numSide,       // number sides
0098                       G4int numZPlanes,    // number of z planes
0099                 const G4double zPlane[],   // position of z planes
0100                 const G4double rInner[],   // tangent distance to inner surface
0101                 const G4double rOuter[] ); // tangent distance to outer surface
0102 
0103     /**
0104      * Alternative constructor of a polyhedra, given corners coordinates.
0105      *  @param[in] name The solid name.
0106      *  @param[in] phiStart Initial Phi starting angle.
0107      *  @param[in] phiTotal Total Phi angle.
0108      *  @param[in] numSide Number of sides.
0109      *  @param[in] numRZ Number of corners in r,Z space.
0110      *  @param[in] r r coordinates of corners.
0111      *  @param[in] z Z coordinates of corners.
0112      */
0113     G4Polyhedra(const G4String& name,
0114                       G4double phiStart,   // initial phi starting angle
0115                       G4double phiTotal,   // total phi angle
0116                       G4int    numSide,    // number sides
0117                       G4int    numRZ,      // number corners in r,z space
0118                 const G4double r[],        // r coordinates of these corners
0119                 const G4double z[] );      // z coordinates of these corners
0120 
0121     /**
0122      * Destructor.
0123      */
0124     ~G4Polyhedra() override;
0125 
0126     /**
0127      * Accessors.
0128      */
0129     inline G4int GetNumSide()        const;
0130     inline G4double GetStartPhi()    const;
0131     inline G4double GetEndPhi()      const;
0132     inline G4double GetSinStartPhi() const;
0133     inline G4double GetCosStartPhi() const;
0134     inline G4double GetSinEndPhi()   const;
0135     inline G4double GetCosEndPhi()   const;
0136     inline G4bool IsOpen()           const;
0137     inline G4bool IsGeneric()        const;
0138     inline G4int GetNumRZCorner()    const;
0139     inline G4PolyhedraSideRZ GetCorner( const G4int index ) const;
0140 
0141     /**
0142      * Returns internal scaled parameters.
0143      */
0144     inline G4PolyhedraHistorical* GetOriginalParameters() const;
0145 
0146     /**
0147      * Sets internal parameters. Parameters 'Rmin' and 'Rmax' in input must
0148      * be scaled first by a factor computed as 'cos(0.5*phiTotal/theNumSide)',
0149      * if not already scaled.
0150      */
0151     inline void SetOriginalParameters(G4PolyhedraHistorical* pars);
0152 
0153     /**
0154      * Concrete implementations of the expected query interfaces for
0155      * solids, as defined in G4VSolid. Remaining functions are concretely
0156      * defined in the base class G4VCSGfaceted.
0157      */
0158     EInside Inside( const G4ThreeVector& p ) const override;
0159     G4double DistanceToIn( const G4ThreeVector& p,
0160                            const G4ThreeVector& v ) const override;
0161     G4double DistanceToIn( const G4ThreeVector& p ) const override;
0162 
0163     /**
0164      * Computes the bounding limits of the solid.
0165      *  @param[out] pMin The minimum bounding limit point.
0166      *  @param[out] pMax The maximum bounding limit point.
0167      */
0168     void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
0169 
0170     /**
0171      * Calculates the minimum and maximum extent of the solid, when under the
0172      * specified transform, and within the specified limits.
0173      *  @param[in] pAxis The axis along which compute the extent.
0174      *  @param[in] pVoxelLimit The limiting space dictated by voxels.
0175      *  @param[in] pTransform The internal transformation applied to the solid.
0176      *  @param[out] pMin The minimum extent value.
0177      *  @param[out] pMax The maximum extent value.
0178      *  @returns True if the solid is intersected by the extent region.
0179      */
0180     G4bool CalculateExtent(const EAxis pAxis,
0181                            const G4VoxelLimits& pVoxelLimit,
0182                            const G4AffineTransform& pTransform,
0183                                  G4double& pmin, G4double& pmax) const override;
0184 
0185     /**
0186      * Dispatch method for parameterisation replication mechanism and
0187      * dimension computation.
0188      */
0189     void ComputeDimensions(G4VPVParameterisation* p,
0190                            const G4int n,
0191                            const G4VPhysicalVolume* pRep) override;
0192 
0193     /**
0194      * Returns the type ID, "G4Polyhedra" of the solid.
0195      */
0196     G4GeometryType GetEntityType() const override;
0197 
0198     /**
0199      * Returns true as the solid has only planar faces.
0200      */
0201     G4bool IsFaceted () const override;
0202 
0203     /**
0204      * Makes a clone of the object for use in multi-treading.
0205      *  @returns A pointer to the new cloned allocated solid.
0206      */
0207     G4VSolid* Clone() const override;
0208 
0209     /**
0210      * Returning an estimation of the solid volume (capacity) and
0211      * surface area, in internal units.
0212      */
0213     G4double GetCubicVolume() override;
0214     G4double GetSurfaceArea() override;
0215 
0216     /**
0217      * Returns a random point located and uniformly distributed on the
0218      * surface of the solid.
0219      */
0220     G4ThreeVector GetPointOnSurface() const override;
0221 
0222     /**
0223      * Streams the object contents to an output stream.
0224      */
0225     std::ostream& StreamInfo( std::ostream& os ) const override;
0226 
0227     /**
0228      * Returns a pointer to a generated polyhedron used for visualisation.
0229      */
0230     G4Polyhedron* CreatePolyhedron() const override;
0231 
0232     /**
0233      * Clears all parameters and rebuild the shape, for use in divisions.
0234      */
0235     G4bool Reset();
0236 
0237     /**
0238      * Fake default constructor for usage restricted to direct object
0239      * persistency for clients requiring preallocation of memory for
0240      * persistifiable objects.
0241      */
0242     G4Polyhedra(__void__&);
0243 
0244     /**
0245      * Copy constructor and assignment operator.
0246      */
0247     G4Polyhedra( const G4Polyhedra& source );
0248     G4Polyhedra& operator=( const G4Polyhedra& source );
0249 
0250   private:
0251 
0252     /**
0253      * Sets internal parameters for the generic constructor.
0254      */
0255     void SetOriginalParameters(G4ReduciblePolygon* rz);
0256 
0257     /**
0258      * Generates the shape and is called by each constructor,
0259      * after the conversion of the arguments.
0260      */
0261     void Create( G4double phiStart,           // initial phi starting angle
0262                  G4double phiTotal,           // total phi angle
0263                  G4int    numSide,            // number sides
0264                  G4ReduciblePolygon* rz );    // rz coordinates
0265 
0266     /**
0267      * Copy parameters from other solid or reset them.
0268      * Used in copy constructor and assignment operator.
0269      */
0270     void CopyStuff( const G4Polyhedra& source );
0271     void DeleteStuff();
0272 
0273     /**
0274      * Sets the vector of surface elements. Auxiliary method used for
0275      * sampling random points on surface.
0276      */
0277     void SetSurfaceElements() const;
0278 
0279   private:
0280 
0281     G4int numSide = 0;    // Number of sides
0282     G4double startPhi;    // Starting phi value (0 < phiStart < 2pi)
0283     G4double endPhi;      // end phi value (0 < endPhi-phiStart < 2pi)
0284     G4bool phiIsOpen = false;   // true if there is a phi segment
0285     G4bool genericPgon = false; // true if created through 2nd generic ctor
0286     G4int numCorner = 0;  // number RZ points
0287     G4PolyhedraSideRZ* corners = nullptr;  // our corners
0288     G4PolyhedraHistorical* original_parameters = nullptr; // original input pars
0289 
0290     G4EnclosingCylinder* enclosingCylinder = nullptr;
0291 
0292     struct surface_element { G4double area=0.; G4int i0=0, i1=0, i2=0; };
0293     mutable std::vector<surface_element>* fElements = nullptr;
0294 };
0295 
0296 #include "G4Polyhedra.icc"
0297 
0298 #endif
0299 
0300 #endif