Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:57

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 // G4PolyhedraSide
0027 //
0028 // Class description:
0029 //
0030 //   Class implementing a face that represents one segmented side
0031 //   of a polyhedra:
0032 //
0033 //   G4PolyhedraSide( const G4PolyhedraSideRZ* prevRZ,
0034 //                    const G4PolyhedraSideRZ* tail,
0035 //                    const G4PolyhedraSideRZ* head,
0036 //                    const G4PolyhedraSideRZ* nextRZ,
0037 //                          G4int numSide,
0038 //                          G4double phiStart, G4double phiTotal, 
0039 //                          G4bool phiIsOpen, G4bool isAllBehind = false )
0040 //
0041 //   Values for r1,z1 and r2,z2 should be specified in clockwise
0042 //   order in (r,z).
0043 
0044 // Author: David C. Williams (davidw@scipp.ucsc.edu)
0045 // --------------------------------------------------------------------
0046 
0047 #ifndef G4PolyhedraSide_hh
0048 #define G4PolyhedraSide_hh
0049 
0050 #include "G4VCSGface.hh"
0051 
0052 class G4IntersectingCone;
0053 
0054 struct G4PolyhedraSideRZ
0055 {
0056   G4double r, z;  // start of vector
0057 };
0058 
0059 // ----------------------------------------------------------------------------
0060 // MT-specific utility code 
0061 
0062 #include "G4GeomSplitter.hh"
0063 
0064 // The class G4PhSideData is introduced to encapsulate the
0065 // fields of the class G4PolyhedraSide that may not be read-only.
0066 //
0067 class G4PhSideData
0068 {
0069   public:
0070 
0071     void initialize()
0072     {
0073       fPhix = 0.; fPhiy = 0.; fPhiz = 0.; fPhik = 0.;
0074     }
0075 
0076     G4double fPhix=0., fPhiy=0., fPhiz=0., fPhik=0.;   // Cached values for phi
0077 };
0078 
0079 // The type G4PhSideManager is introduced to encapsulate the methods used
0080 // by both the master thread and worker threads to allocate memory space
0081 // for the fields encapsulated by the class G4PhSideData.
0082 //
0083 using G4PhSideManager = G4GeomSplitter<G4PhSideData>;
0084 
0085 //
0086 // ----------------------------------------------------------------------------
0087 
0088 class G4PolyhedraSide : public G4VCSGface
0089 {
0090 
0091   public:
0092 
0093     G4PolyhedraSide( const G4PolyhedraSideRZ* prevRZ,
0094                      const G4PolyhedraSideRZ* tail,
0095                      const G4PolyhedraSideRZ* head,
0096                      const G4PolyhedraSideRZ* nextRZ,
0097                            G4int numSide,
0098                            G4double phiStart, G4double phiTotal, 
0099                            G4bool phiIsOpen, G4bool isAllBehind = false );
0100     ~G4PolyhedraSide() override;
0101   
0102     G4PolyhedraSide( const G4PolyhedraSide& source );
0103     G4PolyhedraSide& operator=( const G4PolyhedraSide& source );
0104   
0105     G4bool Intersect( const G4ThreeVector& p, const G4ThreeVector& v,  
0106                             G4bool outgoing, G4double surfTolerance,
0107                             G4double& distance, G4double& distFromSurface,
0108                             G4ThreeVector& normal, G4bool& allBehind ) override;
0109 
0110     G4double Distance( const G4ThreeVector& p, G4bool outgoing ) override;
0111   
0112     EInside Inside( const G4ThreeVector &p, G4double tolerance, 
0113                           G4double *bestDistance ) override;
0114   
0115     G4ThreeVector Normal( const G4ThreeVector& p,
0116                                 G4double* bestDistance ) override;
0117 
0118     G4double Extent( const G4ThreeVector axis ) override;
0119   
0120     void CalculateExtent( const EAxis axis, 
0121                           const G4VoxelLimits &voxelLimit,
0122                           const G4AffineTransform& tranform,
0123                                 G4SolidExtentList& extentList ) override;
0124 
0125     G4VCSGface* Clone() override { return new G4PolyhedraSide( *this ); }
0126 
0127     // Methods used for GetPointOnSurface()
0128 
0129     G4double SurfaceTriangle( const G4ThreeVector& p1,
0130                               const G4ThreeVector& p2,
0131                               const G4ThreeVector& p3,
0132                               G4ThreeVector* p4 );
0133     G4ThreeVector GetPointOnPlane( const G4ThreeVector& p0, const G4ThreeVector& p1, 
0134                                    const G4ThreeVector& p2, const G4ThreeVector& p3,
0135                                    G4double* Area );
0136     G4double SurfaceArea() override;
0137     G4ThreeVector GetPointOnFace() override;  
0138 
0139     G4PolyhedraSide(__void__&);
0140       // Fake default constructor for usage restricted to direct object
0141       // persistency for clients requiring preallocation of memory for
0142       // persistifiable objects.
0143 
0144     inline G4int GetInstanceID() const  { return instanceID; }
0145       // Returns the instance ID.
0146 
0147     static const G4PhSideManager& GetSubInstanceManager();
0148       // Returns the private data instance manager.
0149 
0150     //
0151     // A couple internal data structures
0152     //
0153     struct sG4PolyhedraSideVec;         // Secret recipe for allowing
0154     friend struct sG4PolyhedraSideVec;  // protected nested structures
0155 
0156     using G4PolyhedraSideEdge = struct sG4PolyhedraSideEdge
0157     {
0158       G4ThreeVector  normal;       // Unit normal to this edge
0159       G4ThreeVector  corner[2];    // The two corners of this phi edge
0160       G4ThreeVector  cornNorm[2];  // The normals of these corners
0161     };
0162   
0163     using G4PolyhedraSideVec = struct sG4PolyhedraSideVec
0164     {
0165       G4ThreeVector  normal,   // Normal (point out of the shape)
0166                      center,   // Point in center of side
0167                      surfPhi,  // Unit vector on surface pointing along phi
0168                      surfRZ;   // Unit vector on surface pointing along R/Z
0169       G4PolyhedraSideEdge* edges[2];  // The phi boundary edges to this side 
0170                                       //     [0]=low phi [1]=high phi
0171       G4ThreeVector edgeNorm[2];      // RZ edge normals [i] at {r[i],z[i]}
0172     };
0173 
0174   protected:
0175 
0176     G4bool IntersectSidePlane( const G4ThreeVector& p, const G4ThreeVector& v,
0177                                const G4PolyhedraSideVec& vec,
0178                                      G4double normSign, 
0179                                      G4double surfTolerance,
0180                                      G4double &distance,
0181                                      G4double &distFromSurface );
0182 
0183     G4int LineHitsSegments( const G4ThreeVector& p,
0184                             const G4ThreeVector& v,
0185                                   G4int* i1, G4int* i2 );
0186 
0187     G4int ClosestPhiSegment( G4double phi );
0188   
0189     G4int PhiSegment( G4double phi );
0190 
0191     G4double GetPhi( const G4ThreeVector& p );
0192 
0193     G4double DistanceToOneSide( const G4ThreeVector& p,
0194                                 const G4PolyhedraSideVec& vec,
0195                                       G4double* normDist );
0196 
0197     G4double DistanceAway( const G4ThreeVector& p,
0198                            const G4PolyhedraSideVec& vec,
0199                                  G4double* normDist );
0200              
0201     void CopyStuff( const G4PolyhedraSide& source );
0202 
0203   protected:
0204 
0205     G4int numSide = 0;    // Number sides
0206     G4double r[2], z[2];  // r, z parameters, in specified order
0207     G4double startPhi,    // Start phi (0 to 2pi), if phiIsOpen
0208              deltaPhi,    // Delta phi (0 to 2pi), if phiIsOpen
0209              endPhi;      // End phi (>startPhi), if phiIsOpen
0210     G4bool phiIsOpen = false; // True if there is a phi slice
0211     G4bool allBehind = false; // True if the entire solid is "behind" this face
0212   
0213     G4IntersectingCone* cone = nullptr; // Our intersecting cone
0214   
0215     G4PolyhedraSideVec* vecs = nullptr; // Vector set for each facet of our face
0216     G4PolyhedraSideEdge* edges = nullptr; // The edges belong to vecs
0217     G4double    lenRZ,      // RZ length of each side
0218                 lenPhi[2];  // Phi dimensions of each side
0219     G4double    edgeNorm;   // Normal in RZ/Phi space to each side
0220 
0221   private:
0222 
0223     G4double kCarTolerance;      // Geometrical surface thickness
0224     G4double fSurfaceArea = 0.0; // Surface Area 
0225 
0226     G4int instanceID;
0227       // This field is used as instance ID.
0228     G4GEOM_DLL static G4PhSideManager subInstanceManager;
0229       // This field helps to use the class G4PhSideManager introduced above.
0230 };
0231 
0232 #endif