Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-09 09:08:48

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 // G4CutTubs
0027 //
0028 // Class description:
0029 //
0030 // G4CutTubs is a tube with possible cuts in +-Z.
0031 //
0032 // G4CutTubs(pName,pRMin,pRMax,pDZ,pSPhi,pEPhi,pLowNorm,pHighNorm)
0033 //           pName,pRMin,pRMax,pDZ,pSPhi,pEPhi are the same as for G4Tubs,
0034 //           pLowNorm=Outside Normal at -Z
0035 //           pHighNorm=Outside Normal at +Z.
0036 
0037 // Author: Tatiana Nikitina (CERN), 31.10.2011
0038 //         Implementation adapted from G4Tubs and TGEo/Ctube implementations.
0039 // --------------------------------------------------------------------
0040 #ifndef G4CUTTUBS_HH
0041 #define G4CUTTUBS_HH
0042 
0043 #include "G4GeomTypes.hh"
0044 
0045 #if defined(G4GEOM_USE_USOLIDS)
0046 #define G4GEOM_USE_UCTUBS 1
0047 #endif
0048 
0049 #if defined(G4GEOM_USE_UCTUBS)
0050   #define G4UCutTubs G4CutTubs
0051   #include "G4UCutTubs.hh"
0052 #else
0053 
0054 #include "G4CSGSolid.hh"
0055 #include "G4Polyhedron.hh"
0056 
0057 /**
0058  * @brief G4CutTubs is a tube with possible cuts in +-Z.
0059  */
0060 
0061 class G4CutTubs : public G4CSGSolid
0062 {
0063   public:
0064 
0065     /**
0066      * Constructs a tube with the given name and dimensions.
0067      *  @param[in] pName The name of the solid.
0068      *  @param[in] pRmin Inner radius.
0069      *  @param[in] pRmax Outer radius.
0070      *  @param[in] pDZ Half length in Z.
0071      *  @param[in] pSPhi Starting angle of the segment in radians.
0072      *  @param[in] pDPhi Delta angle of the segment in radians.
0073      *  @param[in] pLowNorm Outside normal vector at -Z.
0074      *  @param[in] pHighNorm Outside normal vector at +Z.
0075      */
0076     G4CutTubs( const G4String& pName,
0077                      G4double pRMin,
0078                      G4double pRMax,
0079                      G4double pDz,
0080                      G4double pSPhi,
0081                      G4double pDPhi,
0082                      G4ThreeVector pLowNorm,
0083                      G4ThreeVector pHighNorm );
0084 
0085     /**
0086      * Default destructor.
0087      */
0088     ~G4CutTubs() override = default;
0089 
0090     /**
0091      * Accessors.
0092      */
0093     inline G4double GetInnerRadius   () const;
0094     inline G4double GetOuterRadius   () const;
0095     inline G4double GetZHalfLength   () const;
0096     inline G4double GetStartPhiAngle () const;
0097     inline G4double GetDeltaPhiAngle () const;
0098     inline G4double GetSinStartPhi   () const;
0099     inline G4double GetCosStartPhi   () const;
0100     inline G4double GetSinEndPhi     () const;
0101     inline G4double GetCosEndPhi     () const;
0102     inline G4ThreeVector GetLowNorm  () const;
0103     inline G4ThreeVector GetHighNorm () const;
0104 
0105     /**
0106      * Modifiers.
0107      */
0108     inline void SetInnerRadius   (G4double newRMin);
0109     inline void SetOuterRadius   (G4double newRMax);
0110     inline void SetZHalfLength   (G4double newDz);
0111     inline void SetStartPhiAngle (G4double newSPhi, G4bool trig=true);
0112     inline void SetDeltaPhiAngle (G4double newDPhi);
0113 
0114     /**
0115      * Returning an estimation of the solid volume (capacity) and
0116      * surface area, in internal units.
0117      */
0118     G4double GetCubicVolume() override;
0119     G4double GetSurfaceArea() override;
0120 
0121     /**
0122      * Computes the bounding limits of the solid.
0123      *  @param[out] pMin The minimum bounding limit point.
0124      *  @param[out] pMax The maximum bounding limit point.
0125      */
0126     void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
0127 
0128     /**
0129      * Calculates the minimum and maximum extent of the solid, when under the
0130      * specified transform, and within the specified limits.
0131      *  @param[in] pAxis The axis along which compute the extent.
0132      *  @param[in] pVoxelLimit The limiting space dictated by voxels.
0133      *  @param[in] pTransform The internal transformation applied to the solid.
0134      *  @param[out] pMin The minimum extent value.
0135      *  @param[out] pMax The maximum extent value.
0136      *  @returns True if the solid is intersected by the extent region.
0137      */
0138     G4bool CalculateExtent(const EAxis pAxis,
0139                            const G4VoxelLimits& pVoxelLimit,
0140                            const G4AffineTransform& pTransform,
0141                                  G4double& pmin, G4double& pmax) const override;
0142 
0143     /**
0144      * Concrete implementations of the expected query interfaces for
0145      * solids, as defined in the base class G4VSolid.
0146      */
0147     EInside Inside( const G4ThreeVector& p ) const override;
0148     G4ThreeVector SurfaceNormal( 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     G4double DistanceToOut(const G4ThreeVector& p, const G4ThreeVector& v,
0153                            const G4bool calcNorm = false,
0154                                  G4bool* validNorm = nullptr,
0155                                  G4ThreeVector* n = nullptr) const override;
0156     G4double DistanceToOut(const G4ThreeVector& p) const override;
0157 
0158     /**
0159      * Returns the type ID, "G4CutTubs" of the solid.
0160      */
0161     G4GeometryType GetEntityType() const override;
0162 
0163     /**
0164      * Returns a random point located and uniformly distributed on the
0165      * surface of the solid.
0166      */
0167     G4ThreeVector GetPointOnSurface() const override;
0168 
0169     /**
0170      * Makes a clone of the object for use in multi-treading.
0171      *  @returns A pointer to the new cloned allocated solid.
0172      */
0173     G4VSolid* Clone() const override;
0174 
0175     /**
0176      * Streams the object contents to an output stream.
0177      */
0178     std::ostream& StreamInfo( std::ostream& os ) const override;
0179 
0180     /**
0181      * Methods for creating graphical representations (i.e. for visualisation).
0182      */
0183     void DescribeYourselfTo ( G4VGraphicsScene& scene ) const override;
0184     G4Polyhedron* CreatePolyhedron () const override;
0185 
0186     /**
0187      * Fake default constructor for usage restricted to direct object
0188      * persistency for clients requiring preallocation of memory for
0189      * persistifiable objects.
0190      */
0191     G4CutTubs(__void__&);
0192 
0193     /**
0194      * Copy constructor and assignment operator.
0195      */
0196     G4CutTubs(const G4CutTubs& rhs) = default;
0197     G4CutTubs& operator=(const G4CutTubs& rhs);
0198 
0199   protected:
0200 
0201     /**
0202      * Resets relevant values to zero.
0203      */
0204     inline void Initialize();
0205 
0206     /**
0207      * Reset relevant flags and angle values.
0208      */
0209     inline void CheckSPhiAngle(G4double sPhi);
0210     inline void CheckDPhiAngle(G4double dPhi);
0211     inline void CheckPhiAngles(G4double sPhi, G4double dPhi);
0212 
0213     /**
0214      * Recomputes relevant trigonometric values and caches them.
0215      */
0216     inline void InitializeTrigonometry();
0217 
0218     /**
0219      * Algorithm for SurfaceNormal() following the original specification
0220      * for points not on the surface.
0221      */
0222     G4ThreeVector ApproxSurfaceNormal( const G4ThreeVector& p ) const;
0223 
0224     /**
0225      * Checks if the cutted planes are crossing.
0226      *  @returns True if the solid is ill defined.
0227      */
0228     G4bool IsCrossingCutPlanes() const;
0229 
0230     /**
0231      * Gets the Z value of the point "p" on the cut plane.
0232      */
0233     G4double GetCutZ(const G4ThreeVector& p) const;
0234 
0235   private:
0236 
0237     /** Radial and angular tolerances. */
0238     G4double kRadTolerance, kAngTolerance;
0239 
0240     /** Radial and angular dimensions. */
0241     G4double fRMin, fRMax, fDz, fSPhi, fDPhi;
0242     mutable G4double fZMin, fZMax;
0243 
0244     /** Cached trigonometric values. */
0245     G4double sinCPhi, cosCPhi, cosHDPhi, cosHDPhiOT, cosHDPhiIT,
0246              sinSPhi, cosSPhi, sinEPhi, cosEPhi;
0247 
0248     /** Flag for identification of section or full tube. */
0249     G4bool fPhiFullCutTube = false;
0250 
0251     /** Cached half tolerance values. */
0252     G4double halfCarTolerance, halfRadTolerance, halfAngTolerance;
0253 
0254     /** Normals of Cut at -/+ Dz. */
0255     G4ThreeVector fLowNorm, fHighNorm;
0256 };
0257 
0258 #include "G4CutTubs.icc"
0259 
0260 #endif
0261 
0262 #endif