Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-17 09:13:58

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