Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-13 08:57:26

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 // G4GenericTrap
0027 //
0028 // Class description:
0029 //
0030 // G4GenericTrap is a solid which represents an arbitrary trapezoid with
0031 // up to 8 vertices standing on two parallel planes perpendicular to Z axis.
0032 //
0033 // Parameters in the constructor:
0034 // - name               - solid name
0035 // - halfZ              - the solid half length in Z
0036 // - vertices           - the (x,y) coordinates of vertices:
0037 //                        o first four points: vertices[i], i<4
0038 //                          are the vertices sitting on the -halfZ plane;
0039 //                        o last four points: vertices[i], i>=4
0040 //                          are the vertices sitting on the +halfZ plane.
0041 //
0042 //   The order of defining the vertices of the solid is the following:
0043 //      - point 0 is connected with points 1,3,4
0044 //      - point 1 is connected with points 0,2,5
0045 //      - point 2 is connected with points 1,3,6
0046 //      - point 3 is connected with points 0,2,7
0047 //      - point 4 is connected with points 0,5,7
0048 //      - point 5 is connected with points 1,4,6
0049 //      - point 6 is connected with points 2,5,7
0050 //      - point 7 is connected with points 3,4,6
0051 // Points can be identical in order to create shapes with less than
0052 // 8 vertices.
0053 
0054 // Authors:
0055 //   Tatiana Nikitina, CERN; Ivana Hrivnacova, IPN Orsay
0056 //   Adapted from Root Arb8 implementation, author Andrei Gheata, CERN
0057 //
0058 //   27.05.2024 - Evgueni Tcherniaev, complete revision, speed up
0059 // -------------------------------------------------------------------
0060 #ifndef G4GENERICTRAP_HH
0061 #define G4GENERICTRAP_HH
0062 
0063 #include "G4GeomTypes.hh"
0064 
0065 #if defined(G4GEOM_USE_USOLIDS)
0066 #define G4GEOM_USE_UGENERICTRAP 1
0067 #endif
0068 
0069 #if defined(G4GEOM_USE_UGENERICTRAP)
0070   #define G4UGenericTrap G4GenericTrap
0071   #include "G4UGenericTrap.hh"
0072 #else
0073 
0074 #include <vector>
0075 
0076 #include "globals.hh"
0077 #include "G4TwoVector.hh"
0078 #include "G4VSolid.hh"
0079 
0080 class G4GenericTrap : public G4VSolid
0081 {
0082   public:
0083 
0084     // Constructor
0085     G4GenericTrap(const G4String& name, G4double halfZ,
0086                   const std::vector<G4TwoVector>& vertices);
0087 
0088     // Fake default constructor for usage restricted to direct object
0089     // persistency for clients requiring preallocation of memory for
0090     // persistifiable objects.
0091     G4GenericTrap(__void__&);
0092 
0093     // Copy constructor and assignment operator
0094     G4GenericTrap(const G4GenericTrap& rhs);
0095     G4GenericTrap& operator=(const G4GenericTrap& rhs);
0096 
0097     // Destructor
0098     ~G4GenericTrap() override;
0099 
0100     // Accessors
0101     inline G4double    GetZHalfLength() const;
0102     inline G4int       GetNofVertices() const;
0103     inline G4TwoVector GetVertex(G4int index) const;
0104     inline const std::vector<G4TwoVector>& GetVertices() const;
0105     inline G4double    GetTwistAngle(G4int index) const;
0106     inline G4bool      IsTwisted() const;
0107     inline G4int       GetVisSubdivisions() const;
0108     inline void        SetVisSubdivisions(G4int subdiv);
0109 
0110     // Solid methods
0111     EInside Inside(const G4ThreeVector& p) const override;
0112     G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const override;
0113     G4double DistanceToIn(const G4ThreeVector& p,
0114                           const G4ThreeVector& v) const override;
0115     G4double DistanceToIn(const G4ThreeVector& p) const override;
0116     G4double DistanceToOut(const G4ThreeVector& p,
0117                            const G4ThreeVector& v,
0118                            const G4bool calcNorm = false,
0119                                  G4bool* validNorm = nullptr,
0120                                  G4ThreeVector* n = nullptr) const override;
0121     G4double DistanceToOut(const G4ThreeVector& p) const override;
0122     void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
0123     G4bool CalculateExtent(const EAxis pAxis,
0124                            const G4VoxelLimits& pVoxelLimit,
0125                            const G4AffineTransform& pTransform,
0126                                  G4double& pmin, G4double& pmax) const override;
0127 
0128     G4GeometryType GetEntityType() const override;
0129 
0130     G4bool IsFaceted () const override;
0131 
0132     G4VSolid* Clone() const override;
0133 
0134     std::ostream& StreamInfo(std::ostream& os) const override;
0135 
0136     G4ThreeVector GetPointOnSurface() const override ;
0137 
0138     G4double GetCubicVolume() override;
0139     G4double GetSurfaceArea() override;
0140 
0141     // Visualisation functions
0142     void DescribeYourselfTo(G4VGraphicsScene& scene) const override;
0143     G4VisExtent GetExtent() const override;
0144     G4Polyhedron* CreatePolyhedron() const override;
0145     G4Polyhedron* GetPolyhedron () const override;
0146 
0147   private:
0148 
0149     // Internal methods
0150     void CheckParameters(G4double halfZ, const std::vector<G4TwoVector>& vertices);
0151     void ComputeLateralSurfaces();
0152     void ComputeBoundingBox();
0153     void ComputeScratchLength();
0154     G4double GetLateralFaceArea(G4int iface) const;
0155     G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector& p) const;
0156 
0157     void WarningSignA(const G4String& method, const G4String& icase, G4double A,
0158                       const G4ThreeVector& p, const G4ThreeVector& v) const;
0159     void WarningSignB(const G4String& method, const G4String& icase, G4double f, G4double B,
0160                       const G4ThreeVector& p, const G4ThreeVector& v) const;
0161     void WarningDistanceToIn(G4int k, const G4ThreeVector& p, const G4ThreeVector& v,
0162                              G4double tmin, G4double tmax,
0163                              const G4double ttin[2], const G4double ttout[2]) const;
0164     void WarningDistanceToOut(const G4ThreeVector& p,
0165                               const G4ThreeVector& v,
0166                               G4double tout) const;
0167 
0168   private:
0169 
0170   struct G4GenericTrapPlane // Ax + By + Cz + D = 0
0171     {
0172       G4double A = 0.;
0173       G4double B = 0.;
0174       G4double C = 0.;
0175       G4double D = 0.;
0176     };
0177     struct G4GenericTrapSurface // Axz + Byz + Czz + Dx + Ey + Fz + G = 0
0178     {
0179       G4double A = 0.;
0180       G4double B = 0.;
0181       G4double C = 0.;
0182       G4double D = 0.;
0183       G4double E = 0.;
0184       G4double F = 0.;
0185       G4double G = 0.;
0186     };
0187 
0188     // Data members
0189     G4double                 halfTolerance = 0.;
0190     G4double                 fScratch = 0.;
0191     G4double                 fDz = 0.;
0192     std::vector<G4TwoVector> fVertices = {0.,0.,0.,0.,0.,0.,0.,0.};
0193     G4TwoVector              fDelta[4];
0194     G4bool                   fIsTwisted = false;
0195     G4double                 fTwist[5] = {0.};
0196     G4ThreeVector            fMinBBox{0.};
0197     G4ThreeVector            fMaxBBox{0.};
0198     G4int                    fVisSubdivisions = 0;
0199     G4GenericTrapPlane       fPlane[8];
0200     G4GenericTrapSurface     fSurf[4];
0201     mutable G4double         fArea[4] = {0.};
0202     mutable G4bool           fRebuildPolyhedron = false;
0203     mutable G4Polyhedron*    fpPolyhedron = nullptr;
0204 
0205     // Surface and Volume
0206     G4double                 fSurfaceArea = 0.;
0207     G4double                 fCubicVolume = 0.;
0208 };
0209 
0210 #include "G4GenericTrap.icc"
0211 
0212 #endif // defined(G4GEOM_USE_UGENERICTRAP)
0213 
0214 #endif // G4GENERICTRAP_HH