Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:06

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 // G4Sphere
0027 //
0028 // Class description:
0029 //
0030 //   A G4Sphere is, in the general case, a section of a spherical shell,
0031 //   between specified phi and theta angles
0032 //
0033 //   The phi and theta segments are described by a starting angle,
0034 //   and the +ve delta angle for the shape.
0035 //   If the delta angle is >=2*pi, or >=pi the shape is treated as
0036 //   continuous in phi or theta respectively.
0037 //
0038 //   Theta must lie between 0-pi (incl).
0039 //
0040 //   Member Data:
0041 //
0042 //   fRmin  inner radius
0043 //   fRmax  outer radius
0044 //
0045 //   fSPhi  starting angle of the segment in radians
0046 //   fDPhi  delta angle of the segment in radians
0047 //
0048 //   fSTheta  starting angle of the segment in radians
0049 //   fDTheta  delta angle of the segment in radians
0050 //
0051 //
0052 //   Note:
0053 //      Internally fSPhi & fDPhi are adjusted so that fDPhi<=2PI,
0054 //      and fDPhi+fSPhi<=2PI. This enables simpler comparisons to be
0055 //      made with (say) Phi of a point.
0056 
0057 // 28.3.94 P.Kent: old C++ code converted to tolerant geometry
0058 // 17.9.96 V.Grichine: final modifications to commit
0059 // --------------------------------------------------------------------
0060 #ifndef G4SPHERE_HH
0061 #define G4SPHERE_HH
0062 
0063 #include "G4GeomTypes.hh"
0064 
0065 #if defined(G4GEOM_USE_USOLIDS)
0066 #define G4GEOM_USE_USPHERE 1
0067 #endif
0068 
0069 #if defined(G4GEOM_USE_USPHERE)
0070   #define G4USphere G4Sphere
0071   #include "G4USphere.hh"
0072 #else
0073 
0074 #include <CLHEP/Units/PhysicalConstants.h>
0075 #include "G4CSGSolid.hh"
0076 #include "G4Polyhedron.hh"
0077 
0078 class G4VisExtent;
0079 
0080 class G4Sphere : public G4CSGSolid
0081 {
0082   public:
0083 
0084     G4Sphere(const G4String& pName,
0085                    G4double pRmin, G4double pRmax,
0086                    G4double pSPhi, G4double pDPhi,
0087                    G4double pSTheta, G4double pDTheta);
0088       //
0089       // Constructs a sphere or sphere shell section
0090       // with the given name and dimensions
0091 
0092    ~G4Sphere() override;
0093       //
0094       // Destructor
0095 
0096     // Accessors
0097 
0098     inline G4double GetInnerRadius    () const;
0099     inline G4double GetOuterRadius    () const;
0100     inline G4double GetStartPhiAngle  () const;
0101     inline G4double GetDeltaPhiAngle  () const;
0102     inline G4double GetStartThetaAngle() const;
0103     inline G4double GetDeltaThetaAngle() const;
0104     inline G4double GetSinStartPhi    () const;
0105     inline G4double GetCosStartPhi    () const;
0106     inline G4double GetSinEndPhi      () const;
0107     inline G4double GetCosEndPhi      () const;
0108     inline G4double GetSinStartTheta  () const;
0109     inline G4double GetCosStartTheta  () const;
0110     inline G4double GetSinEndTheta    () const;
0111     inline G4double GetCosEndTheta    () const;
0112 
0113     // Modifiers
0114 
0115     inline void SetInnerRadius    (G4double newRMin);
0116     inline void SetOuterRadius    (G4double newRmax);
0117     inline void SetStartPhiAngle  (G4double newSphi, G4bool trig = true);
0118     inline void SetDeltaPhiAngle  (G4double newDphi);
0119     inline void SetStartThetaAngle(G4double newSTheta);
0120     inline void SetDeltaThetaAngle(G4double newDTheta);
0121 
0122     // Methods for solid
0123 
0124     G4double GetCubicVolume() override;
0125     G4double GetSurfaceArea() override;
0126 
0127     void ComputeDimensions(      G4VPVParameterisation* p,
0128                            const G4int n,
0129                            const G4VPhysicalVolume* pRep) override;
0130 
0131     void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
0132 
0133     G4bool CalculateExtent(const EAxis pAxis,
0134                            const G4VoxelLimits& pVoxelLimit,
0135                            const G4AffineTransform& pTransform,
0136                                  G4double& pmin, G4double& pmax) const override;
0137 
0138     EInside Inside(const G4ThreeVector& p) const override;
0139 
0140     G4ThreeVector SurfaceNormal( const G4ThreeVector& p) const override;
0141 
0142     G4double DistanceToIn(const G4ThreeVector& p,
0143                           const G4ThreeVector& v) const override;
0144 
0145     G4double DistanceToIn(const G4ThreeVector& p) const override;
0146 
0147     G4double DistanceToOut(const G4ThreeVector& p,
0148                            const G4ThreeVector& v,
0149                            const G4bool calcNorm = false,
0150                                  G4bool* validNorm = nullptr,
0151                                  G4ThreeVector* n = nullptr) const override;
0152 
0153     G4double DistanceToOut(const G4ThreeVector& p) const override;
0154 
0155     G4GeometryType GetEntityType() const override;
0156 
0157     G4ThreeVector GetPointOnSurface() const override;
0158 
0159     G4VSolid* Clone() const override;
0160 
0161     std::ostream& StreamInfo(std::ostream& os) const override;
0162 
0163     // Visualisation functions
0164 
0165     G4VisExtent   GetExtent          () const override;
0166     void          DescribeYourselfTo(G4VGraphicsScene& scene) const override;
0167     G4Polyhedron* CreatePolyhedron() const override;
0168 
0169     G4Sphere(__void__&);
0170       //
0171       // Fake default constructor for usage restricted to direct object
0172       // persistency for clients requiring preallocation of memory for
0173       // persistifiable objects.
0174 
0175     G4Sphere(const G4Sphere& rhs);
0176     G4Sphere& operator=(const G4Sphere& rhs);
0177       // Copy constructor and assignment operator.
0178 
0179 
0180   private:
0181 
0182     inline void Initialize();
0183       //
0184       // Reset relevant values to zero
0185 
0186     inline void CheckThetaAngles(G4double sTheta, G4double dTheta);
0187     inline void CheckSPhiAngle(G4double sPhi);
0188     inline void CheckDPhiAngle(G4double dPhi);
0189     inline void CheckPhiAngles(G4double sPhi, G4double dPhi);
0190       //
0191       // Reset relevant flags and angle values
0192 
0193     inline void InitializePhiTrigonometry();
0194     inline void InitializeThetaTrigonometry();
0195       //
0196       // Recompute relevant trigonometric values and cache them
0197 
0198     G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector& p) const;
0199       //
0200       // Algorithm for SurfaceNormal() following the original
0201       // specification for points not on the surface
0202 
0203   private:
0204 
0205     // Used by distanceToOut
0206     //
0207     enum ESide {kNull,kRMin,kRMax,kSPhi,kEPhi,kSTheta,kETheta};
0208 
0209     // used by normal
0210     //
0211     enum ENorm {kNRMin,kNRMax,kNSPhi,kNEPhi,kNSTheta,kNETheta};
0212 
0213     G4double fRminTolerance, fRmaxTolerance, kAngTolerance,
0214              kRadTolerance, fEpsilon = 2.e-11;
0215       //
0216       // Radial and angular tolerances
0217 
0218     G4double fRmin, fRmax, fSPhi, fDPhi, fSTheta, fDTheta;
0219       //
0220       // Radial and angular dimensions
0221 
0222     G4double sinCPhi, cosCPhi, cosHDPhi, cosHDPhiOT, cosHDPhiIT,
0223              sinSPhi, cosSPhi, sinEPhi, cosEPhi, hDPhi, cPhi, ePhi;
0224       //
0225       // Cached trigonometric values for Phi angle
0226 
0227     G4double sinSTheta, cosSTheta, sinETheta, cosETheta,
0228              tanSTheta, tanSTheta2, tanETheta, tanETheta2, eTheta;
0229       //
0230       // Cached trigonometric values for Theta angle
0231 
0232     G4bool fFullPhiSphere=false, fFullThetaSphere=false, fFullSphere=true;
0233       //
0234       // Flags for identification of section, shell or full sphere
0235 
0236     G4double halfCarTolerance, halfAngTolerance;
0237       //
0238       // Cached half tolerance values
0239 };
0240 
0241 #include "G4Sphere.icc"
0242 
0243 #endif
0244 
0245 #endif