Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-14 09:07:40

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 // G4Cons
0027 //
0028 // Class description:
0029 //
0030 // A G4Cons is, in the general case, a Phi segment of a cone, with
0031 // half-length fDz, inner and outer radii specified at -fDz and +fDz.
0032 // The Phi segment is described by a starting fSPhi angle, and the
0033 // +fDPhi delta angle for the shape.
0034 // If the delta angle is >=2*pi, the shape is treated as continuous
0035 // in Phi.
0036 //
0037 //  Member Data:
0038 //
0039 //  fRmin1  inside radius at  -fDz
0040 //  fRmin2  inside radius at  +fDz
0041 //  fRmax1  outside radius at -fDz
0042 //  fRmax2  outside radius at +fDz
0043 //  fDz  half length in z
0044 //
0045 //  fSPhi  starting angle of the segment in radians
0046 //  fDPhi  delta angle of the segment in radians
0047 //
0048 //  fPhiFullCone   Boolean variable used for indicate the Phi Section
0049 //
0050 // Note:
0051 //    Internally fSPhi & fDPhi are adjusted so that fDPhi<=2PI,
0052 //    and fDPhi+fSPhi<=2PI. This enables simpler comparisons to be
0053 //    made with (say) Phi of a point.
0054 
0055 // Author: Paul Kent (CERN), 19.3.1994 - Code converted to tolerant geometry
0056 // --------------------------------------------------------------------
0057 #ifndef G4CONS_HH
0058 #define G4CONS_HH
0059 
0060 #include "G4GeomTypes.hh"
0061 
0062 #if defined(G4GEOM_USE_USOLIDS)
0063 #define G4GEOM_USE_UCONS 1
0064 #endif
0065 
0066 #if defined(G4GEOM_USE_UCONS)
0067   #define G4UCons G4Cons
0068   #include "G4UCons.hh"
0069 #else
0070 
0071 #include <CLHEP/Units/PhysicalConstants.h>
0072 
0073 #include "G4CSGSolid.hh"
0074 #include "G4Polyhedron.hh"
0075 
0076 /**
0077  * @brief G4Cons is, in the general case, a Phi segment of a cone, with
0078  * half-length fDz, inner and outer radii specified at -fDz and +fDz.
0079  * The Phi segment is described by a starting fSPhi angle, and the
0080  * +fDPhi delta angle for the shape.
0081  * If the delta angle is >=2*pi, the shape is treated as continuous in Phi.
0082  */
0083 
0084 class G4Cons : public G4CSGSolid
0085 {
0086   public:
0087 
0088     /**
0089      * Constructs a cone with the given name and dimensions.
0090      *  @param[in] pName The name of the solid.
0091      *  @param[in] pRmin1 Inside radius at -fDz.
0092      *  @param[in] pRmax1 Outside radius at -fDz
0093      *  @param[in] pRmin2 Inside radius at +fDz.
0094      *  @param[in] pRmax2 Outside radius at +fDz
0095      *  @param[in] pDZ Half length in Z.
0096      *  @param[in] pSPhi Starting angle of the segment in radians.
0097      *  @param[in] pDPhi Delta angle of the segment in radians.
0098      */
0099     G4Cons(const G4String& pName,
0100                  G4double pRmin1, G4double pRmax1,
0101                  G4double pRmin2, G4double pRmax2,
0102                  G4double pDz,
0103                  G4double pSPhi, G4double pDPhi);
0104 
0105     /**
0106      * Default destructor.
0107      */
0108     ~G4Cons() override = default;
0109 
0110     /**
0111      * Accessors.
0112      */
0113     inline G4double GetInnerRadiusMinusZ() const;
0114     inline G4double GetOuterRadiusMinusZ() const;
0115     inline G4double GetInnerRadiusPlusZ()  const;
0116     inline G4double GetOuterRadiusPlusZ()  const;
0117     inline G4double GetZHalfLength()       const;
0118     inline G4double GetStartPhiAngle()     const;
0119     inline G4double GetDeltaPhiAngle()     const;
0120     inline G4double GetSinStartPhi()       const;
0121     inline G4double GetCosStartPhi()       const;
0122     inline G4double GetSinEndPhi()         const;
0123     inline G4double GetCosEndPhi()         const;
0124 
0125     /**
0126      * Modifiers.
0127      */
0128     inline void SetInnerRadiusMinusZ (G4double Rmin1 );
0129     inline void SetOuterRadiusMinusZ (G4double Rmax1 );
0130     inline void SetInnerRadiusPlusZ  (G4double Rmin2 );
0131     inline void SetOuterRadiusPlusZ  (G4double Rmax2 );
0132     inline void SetZHalfLength       (G4double newDz );
0133     inline void SetStartPhiAngle     (G4double newSPhi, G4bool trig=true);
0134     inline void SetDeltaPhiAngle     (G4double newDPhi);
0135 
0136     /**
0137      * Returning an estimation of the solid volume (capacity) and
0138      * surface area, in internal units.
0139      */
0140     G4double GetCubicVolume() override;
0141     G4double GetSurfaceArea() override;
0142 
0143     /**
0144      * Dispatch method for parameterisation replication mechanism and
0145      * dimension computation.
0146      */
0147     void ComputeDimensions(G4VPVParameterisation* p,
0148                            const G4int n,
0149                            const G4VPhysicalVolume* pRep) override;
0150 
0151     /**
0152      * Computes the bounding limits of the solid.
0153      *  @param[out] pMin The minimum bounding limit point.
0154      *  @param[out] pMax The maximum bounding limit point.
0155      */
0156     void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
0157 
0158     /**
0159      * Calculates the minimum and maximum extent of the solid, when under the
0160      * specified transform, and within the specified limits.
0161      *  @param[in] pAxis The axis along which compute the extent.
0162      *  @param[in] pVoxelLimit The limiting space dictated by voxels.
0163      *  @param[in] pTransform The internal transformation applied to the solid.
0164      *  @param[out] pMin The minimum extent value.
0165      *  @param[out] pMax The maximum extent value.
0166      *  @returns True if the solid is intersected by the extent region.
0167      */
0168     G4bool CalculateExtent(const EAxis pAxis,
0169                            const G4VoxelLimits& pVoxelLimit,
0170                            const G4AffineTransform& pTransform,
0171                                  G4double& pMin, G4double& pMax) const override;
0172 
0173     /**
0174      * Concrete implementations of the expected query interfaces for
0175      * solids, as defined in the base class G4VSolid.
0176      */
0177     EInside Inside( const G4ThreeVector& p ) const override;
0178     G4ThreeVector SurfaceNormal( const G4ThreeVector& p ) const override;
0179     G4double DistanceToIn (const G4ThreeVector& p,
0180                            const G4ThreeVector& v) const override;
0181     G4double DistanceToIn (const G4ThreeVector& p) const override;
0182     G4double DistanceToOut(const G4ThreeVector& p,
0183                            const G4ThreeVector& v,
0184                            const G4bool calcNorm = false,
0185                                  G4bool* validNorm = nullptr,
0186                                  G4ThreeVector* n = nullptr) const override;
0187     G4double DistanceToOut(const G4ThreeVector& p) const override;
0188 
0189     /**
0190      * Returns the type ID, "G4Cons" of the solid.
0191      */
0192     G4GeometryType GetEntityType() const override;
0193 
0194     /**
0195      * Returns a random point located and uniformly distributed on the
0196      * surface of the solid.
0197      */
0198     G4ThreeVector GetPointOnSurface() const override;
0199 
0200     /**
0201      * Makes a clone of the object for use in multi-treading.
0202      *  @returns A pointer to the new cloned allocated solid.
0203      */
0204     G4VSolid* Clone() const override;
0205 
0206     /**
0207      * Streams the object contents to an output stream.
0208      */
0209     std::ostream& StreamInfo(std::ostream& os) const override;
0210 
0211     /**
0212      * Methods for creating graphical representations (i.e. for visualisation).
0213      */
0214     void DescribeYourselfTo( G4VGraphicsScene& scene ) const override;
0215     G4Polyhedron* CreatePolyhedron() const override;
0216 
0217     /**
0218      * Fake default constructor for usage restricted to direct object
0219      * persistency for clients requiring preallocation of memory for
0220      * persistifiable objects.
0221      */
0222     G4Cons(__void__&);
0223 
0224     /**
0225      * Copy constructor and assignment operator.
0226      */
0227     G4Cons(const G4Cons& rhs) = default;
0228     G4Cons& operator=(const G4Cons& rhs);
0229 
0230   private:
0231 
0232     /**
0233      * Resets relevant values to zero.
0234      */
0235     inline void Initialize();
0236 
0237     /**
0238      * Reset relevant flags and angle values.
0239      */
0240     inline void CheckSPhiAngle(G4double sPhi);
0241     inline void CheckDPhiAngle(G4double dPhi);
0242     inline void CheckPhiAngles(G4double sPhi, G4double dPhi);
0243 
0244     /**
0245      * Recomputes relevant trigonometric values and cache them.
0246      */
0247     inline void InitializeTrigonometry();
0248 
0249     /**
0250      * Algorithm for SurfaceNormal() following the original specification
0251      * for points not on the surface.
0252      */
0253     G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector& p) const;
0254 
0255   private:
0256 
0257     /** Radial and angular tolerances. */
0258     G4double kRadTolerance, kAngTolerance;
0259 
0260     /** Radial and angular dimensions. */
0261     G4double fRmin1, fRmin2, fRmax1, fRmax2, fDz, fSPhi, fDPhi;
0262 
0263     /** Cached trigonometric values. */
0264     G4double sinCPhi, cosCPhi, cosHDPhi, cosHDPhiOT, cosHDPhiIT,
0265              sinSPhi, cosSPhi, sinEPhi, cosEPhi;
0266 
0267     /** Flag for identification of section or full cone. */
0268     G4bool fPhiFullCone = false;
0269 
0270     /** Cached half tolerance values. */
0271     G4double halfCarTolerance, halfRadTolerance, halfAngTolerance;
0272 };
0273 
0274 #include "G4Cons.icc"
0275 
0276 #endif
0277 
0278 #endif