Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-28 07:19:01

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 // G4Trap
0027 //
0028 // Class description:
0029 //
0030 // A G4Trap is a general trapezoid: The faces perpendicular to the
0031 // z planes are trapezia, and their centres are not necessarily on
0032 // a line parallel to the z axis.
0033 //
0034 // Note that of the 11 parameters described below, only 9 are really
0035 // independent - a check for planarity is made in the calculation of the
0036 // equation for each plane. If the planes are not parallel, a call to
0037 // G4Exception is made.
0038 //
0039 //      pDz     Half-length along the z-axis
0040 //      pTheta  Polar angle of the line joining the centres of the faces
0041 //              at -/+pDz
0042 //      pPhi    Azimuthal angle of the line joining the centre of the face at
0043 //              -pDz to the centre of the face at +pDz
0044 //      pDy1    Half-length along y of the face at -pDz
0045 //      pDx1    Half-length along x of the side at y=-pDy1 of the face at -pDz
0046 //      pDx2    Half-length along x of the side at y=+pDy1 of the face at -pDz
0047 //      pAlp1   Angle with respect to the y axis from the centre of the side
0048 //              at y=-pDy1 to the centre at y=+pDy1 of the face at -pDz
0049 //
0050 //      pDy2    Half-length along y of the face at +pDz
0051 //      pDx3    Half-length along x of the side at y=-pDy2 of the face at +pDz
0052 //      pDx4    Half-length along x of the side at y=+pDy2 of the face at +pDz
0053 //      pAlp2   Angle with respect to the y axis from the centre of the side
0054 //              at y=-pDy2 to the centre at y=+pDy2 of the face at +pDz
0055 //
0056 //
0057 // Member Data:
0058 //
0059 //      fDz     Half-length along the z axis
0060 //      fTthetaCphi = std::tan(pTheta)*std::cos(pPhi)
0061 //      fTthetaSphi = std::tan(pTheta)*std::sin(pPhi)
0062 //      These combinations are suitable for creation of the trapezoid corners
0063 //
0064 //      fDy1    Half-length along y of the face at -fDz
0065 //      fDx1    Half-length along x of the side at y=-fDy1 of the face at -fDz
0066 //      fDx2    Half-length along x of the side at y=+fDy1 of the face at -fDz
0067 //      fTalpha1   Tan of Angle with respect to the y axis from the centre of
0068 //                 the side at y=-fDy1 to the centre at y=+fDy1 of the face
0069 //                 at -fDz
0070 //
0071 //      fDy2    Half-length along y of the face at +fDz
0072 //      fDx3    Half-length along x of the side at y=-fDy2 of the face at +fDz
0073 //      fDx4    Half-length along x of the side at y=+fDy2 of the face at +fDz
0074 //      fTalpha2   Tan of Angle with respect to the y axis from the centre of
0075 //                 the side at y=-fDy2 to the centre at y=+fDy2 of the face
0076 //                 at +fDz
0077 //
0078 //      TrapSidePlane fPlanes[4]   Plane equations of the faces not at +/-fDz
0079 //                                 NOTE: order is important !!!
0080 
0081 // Author: Paul Kent, 23.03.1994 - Code converted to tolerant geometry
0082 // --------------------------------------------------------------------
0083 #ifndef G4TRAP_HH
0084 #define G4TRAP_HH
0085 
0086 #include "G4Types.hh"
0087 
0088 struct TrapSidePlane
0089 {
0090     G4double a,b,c,d;    // Normal unit vector (a,b,c)  and offset (d)
0091         // => Ax+By+Cz+D=0
0092 };
0093 
0094 #include "G4GeomTypes.hh"
0095 
0096 #if defined(G4GEOM_USE_USOLIDS)
0097 #define G4GEOM_USE_UTRAP 1
0098 #endif
0099 
0100 #if defined(G4GEOM_USE_UTRAP)
0101   #define G4UTrap G4Trap
0102   #include "G4UTrap.hh"
0103 #else
0104 
0105 #include "G4CSGSolid.hh"
0106 
0107 /**
0108  * @brief G4Trap is a general trapezoid: the faces perpendicular to the Z
0109  * planes are trapezia, and their centres are not necessarily on a line parallel
0110  * to the Z axis. A check for planarity is made in the calculation of the
0111  * equation for each plane. If the planes are not parallel, a call to
0112  * G4Exception is made.
0113  */
0114 
0115 class G4Trap : public G4CSGSolid
0116 {
0117   public:
0118 
0119     /**
0120      * The most general constructor for G4Trap which prepares plane
0121      * equations and corner coordinates from parameters.
0122      *  @param[in] pName The name of the solid.
0123      *  @param[in] pDz Half-length along the Z-axis.
0124      *  @param[in] pTheta Polar angle of the line joining the centres
0125      *             of the faces at -/+pDz.
0126      *  @param[in] pPhi Azimuthal angle of the line joining the centre
0127      *             of the face at -pDz to the centre of the face at +pDz.
0128      *  @param[in] pDy1 Half-length along Y of the face at -pDz.
0129      *  @param[in] pDx1 Half-length along X of the side at y=-pDy1
0130      *             of the face at -pDz.
0131      *  @param[in] pDx2 Half-length along X of the side at y=+pDy1
0132      *             of the face at -pDz.
0133      *  @param[in] pAlp1 Angle with respect to the Y axis from the centre of the
0134      *             side at y=-pDy1 to the centre at y=+pDy1 of the face at -pDz.
0135      *  @param[in] pDy2 Half-length along Y of the face at +pDz.
0136      *  @param[in] pDx3 Half-length along X of the side at y=-pDy2
0137      *             of the face at +pDz.
0138      *  @param[in] pDx4 Half-length along X of the side at y=+pDy2
0139      *             of the face at +pDz.
0140      *  @param[in] pAlp2 Angle with respect to the Y axis from the centre of the
0141      *             side at y=-pDy2 to the centre at y=+pDy2 of the face at +pDz.
0142      */
0143     G4Trap( const G4String& pName,
0144                   G4double pDz,
0145                   G4double pTheta, G4double pPhi,
0146                   G4double pDy1, G4double pDx1, G4double pDx2,
0147                   G4double pAlp1,
0148                   G4double pDy2, G4double pDx3, G4double pDx4,
0149                   G4double pAlp2 );
0150 
0151     /**
0152      * Prepares plane equations and parameters from corner coordinates.
0153      *  @param[in] pName The name of the solid.
0154      *  @param[in] pt Points of the 8 vertices.
0155      */
0156     G4Trap( const G4String& pName,
0157             const G4ThreeVector pt[8] ) ;
0158 
0159     /**
0160      * Constructor for Right Angular Wedge from STEP (assumes pLTX<=pX).
0161      *  @param[in] pName The name of the solid.
0162      *  @param[in] pZ Length along Z.
0163      *  @param[in] pY Length along Y.
0164      *  @param[in] pX Length along X at the wider side.
0165      *  @param[in] pLTX Length along X at the narrower side (plTX<=pX).
0166      */
0167     G4Trap( const G4String& pName,
0168                   G4double pZ,
0169                   G4double pY,
0170                   G4double pX, G4double pLTX );
0171 
0172     /**
0173      * Constructor for G4Trd.
0174      *  @param[in] pName The name of the solid.
0175      *  @param[in] pDx1 Half-length along X at the surface positioned at -dz.
0176      *  @param[in] pDx2 Half-length along X at the surface positioned at +dz.
0177      *  @param[in] pDy1 Half-length along Y at the surface positioned at -dz.
0178      *  @param[in] pDy2 Half-length along Y at the surface positioned at +dz.
0179      *  @param[in] pDz Half-length along Z axis.
0180      */
0181     G4Trap( const G4String& pName,
0182                   G4double pDx1,  G4double pDx2,
0183                   G4double pDy1,  G4double pDy2,
0184                   G4double pDz );
0185 
0186     /**
0187      * Constructor for G4Para.
0188      *  @param[in] pName The name of the solid.
0189      *  @param[in] pDx Half-length in X.
0190      *  @param[in] pDy Half-length in Y.
0191      *  @param[in] pDz Half-length in Z.
0192      *  @param[in] pAlpha Angle formed by the Y axis and the plane joining the
0193      *             centre of the faces parallel to the Z-X plane at -dy and +dy.
0194      *  @param[in] pTheta Polar angle of the line joining the centres of the
0195      *             faces at -dz and +dz in Z.
0196      *  @param[in] pPhi Azimuthal angle of the line joining the centres of
0197      *             the faces at -dz and +dz in Z.
0198      */
0199      G4Trap(const G4String& pName,
0200                   G4double pDx, G4double pDy, G4double pDz,
0201                   G4double pAlpha, G4double pTheta, G4double pPhi );
0202 
0203     /**
0204      * Constructor for "nominal" G4Trap whose parameters are to be set
0205      * by a G4VPVParamaterisation later on.
0206      *  @param[in] pName The name of the solid.
0207      */
0208      G4Trap( const G4String& pName );
0209 
0210     /**
0211      * Default destructor.
0212      */
0213      ~G4Trap() override = default;
0214 
0215     /**
0216      * Accessors. Returning the coordinates of a unit vector along a straight
0217      * line joining centers of -/+fDz planes.
0218      */
0219     inline G4double GetZHalfLength()  const;
0220     inline G4double GetYHalfLength1() const;
0221     inline G4double GetXHalfLength1() const;
0222     inline G4double GetXHalfLength2() const;
0223     inline G4double GetTanAlpha1()    const;
0224     inline G4double GetYHalfLength2() const;
0225     inline G4double GetXHalfLength3() const;
0226     inline G4double GetXHalfLength4() const;
0227     inline G4double GetTanAlpha2()    const;
0228 
0229     /**
0230      * More accessors.
0231      */
0232     inline TrapSidePlane GetSidePlane( G4int n ) const;
0233     inline G4ThreeVector GetSymAxis() const;
0234 
0235     /**
0236      * Accessors obtaining (re)computed values of the original parameters.
0237      */
0238     inline G4double GetPhi() const;
0239     inline G4double GetTheta() const;
0240     inline G4double GetAlpha1() const;
0241     inline G4double GetAlpha2() const;   
0242    
0243     /**
0244      * Sets all parameters, as for constructor. Checks and sets half-widths
0245      * as well as angles. Makes a final check of co-planarity.
0246      */
0247     void SetAllParameters ( G4double pDz,
0248                             G4double pTheta,
0249                             G4double pPhi,
0250                             G4double pDy1,
0251                             G4double pDx1,
0252                             G4double pDx2,
0253                             G4double pAlp1,
0254                             G4double pDy2,
0255                             G4double pDx3,
0256                             G4double pDx4,
0257                             G4double pAlp2 );
0258 
0259     /**
0260      * Returning an estimation of the solid volume (capacity) and
0261      * surface area, in internal units.
0262      */
0263     G4double GetCubicVolume() override;
0264     G4double GetSurfaceArea() override;
0265 
0266     /**
0267      * Dispatch method for parameterisation replication mechanism and
0268      * dimension computation.
0269      */
0270     void ComputeDimensions( G4VPVParameterisation* p,
0271                             const G4int n,
0272                             const G4VPhysicalVolume* pRep ) override;
0273 
0274     /**
0275      * Computes the bounding limits of the solid.
0276      *  @param[out] pMin The minimum bounding limit point.
0277      *  @param[out] pMax The maximum bounding limit point.
0278      */
0279     void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
0280 
0281     /**
0282      * Calculates the minimum and maximum extent of the solid, when under the
0283      * specified transform, and within the specified limits.
0284      *  @param[in] pAxis The axis along which compute the extent.
0285      *  @param[in] pVoxelLimit The limiting space dictated by voxels.
0286      *  @param[in] pTransform The internal transformation applied to the solid.
0287      *  @param[out] pMin The minimum extent value.
0288      *  @param[out] pMax The maximum extent value.
0289      *  @returns True if the solid is intersected by the extent region.
0290      */
0291     G4bool CalculateExtent(const EAxis pAxis,
0292                            const G4VoxelLimits& pVoxelLimit,
0293                            const G4AffineTransform& pTransform,
0294                                  G4double& pMin, G4double& pMax) const override;
0295 
0296     /**
0297      * Concrete implementations of the expected query interfaces for
0298      * solids, as defined in the base class G4VSolid.
0299      */
0300     EInside Inside( const G4ThreeVector& p ) const override;
0301     G4ThreeVector SurfaceNormal( const G4ThreeVector& p ) const override;
0302     G4double DistanceToIn(const G4ThreeVector& p,
0303                           const G4ThreeVector& v) const override;
0304     G4double DistanceToIn( const G4ThreeVector& p ) const override;
0305     G4double DistanceToOut(const G4ThreeVector& p, const G4ThreeVector& v,
0306                            const G4bool calcNorm = false,
0307                                  G4bool* validNorm = nullptr,
0308                                  G4ThreeVector* n = nullptr) const override;
0309     G4double DistanceToOut( const G4ThreeVector& p ) const override;
0310 
0311     /**
0312      * Returns the type ID, "G4Trap" of the solid.
0313      */
0314     G4GeometryType GetEntityType() const override;
0315 
0316     /**
0317      * Returns a random point located and uniformly distributed on the
0318      * surface of the solid.
0319      */
0320     G4ThreeVector GetPointOnSurface() const override;
0321 
0322     /**
0323      * Returns true as the solid has only planar faces.
0324      */
0325     G4bool IsFaceted() const override;
0326 
0327     /**
0328      * Makes a clone of the object for use in multi-treading.
0329      *  @returns A pointer to the new cloned allocated solid.
0330      */
0331     G4VSolid* Clone() const override;
0332 
0333     /**
0334      * Streams the object contents to an output stream.
0335      */
0336     std::ostream& StreamInfo( std::ostream& os ) const override;
0337 
0338     /**
0339      * Methods for creating graphical representations (i.e. for visualisation).
0340      */
0341     void DescribeYourselfTo (G4VGraphicsScene& scene) const override;
0342     G4Polyhedron* CreatePolyhedron () const override;
0343 
0344     /**
0345      * Fake default constructor for usage restricted to direct object
0346      * persistency for clients requiring preallocation of memory for
0347      * persistifiable objects.
0348      */
0349     G4Trap(__void__&);
0350 
0351     /**
0352      * Copy constructor and assignment operator.
0353      */
0354     G4Trap(const G4Trap& rhs);
0355     G4Trap& operator=(const G4Trap& rhs);
0356 
0357   protected:
0358 
0359     /**
0360      * Internal methods for checking and building planes.
0361      * Computing the vertices and setting side planes, checking for planarity.
0362      */
0363     void MakePlanes();
0364     void MakePlanes( const G4ThreeVector pt[8] );
0365 
0366     /**
0367      * Calculates the coefficents of the plane p1->p2->p3->p4->p1
0368      * where the ThreeVectors 1-4 are in anti-clockwise order when viewed
0369      * from infront of the plane (i.e. from normal direction).
0370      *  @return true if the points are co-planar, false otherwise.
0371      */
0372     G4bool MakePlane( const G4ThreeVector& p1,
0373                       const G4ThreeVector& p2,
0374                       const G4ThreeVector& p3,
0375                       const G4ThreeVector& p4,
0376                             TrapSidePlane& plane ) ;
0377     /**
0378      * Recomputes parameters using planes.
0379      */
0380     void SetCachedValues();
0381 
0382   private:
0383 
0384     /**
0385      * Checks the input parameters.
0386      */
0387     void CheckParameters();
0388 
0389     /**
0390      * Computes the coordinates of the trap vertices from planes.
0391      */
0392     void GetVertices(G4ThreeVector pt[8]) const;
0393 
0394     /**
0395      * Algorithm for SurfaceNormal() following the original specification
0396      * for points not on the surface.
0397      */
0398     G4ThreeVector ApproxSurfaceNormal( const G4ThreeVector& p ) const;
0399 
0400   private:
0401 
0402     G4double halfCarTolerance;
0403     G4double fDz,fTthetaCphi,fTthetaSphi;
0404     G4double fDy1,fDx1,fDx2,fTalpha1;
0405     G4double fDy2,fDx3,fDx4,fTalpha2;
0406     TrapSidePlane fPlanes[4];
0407     G4double fAreas[6];
0408     G4int fTrapType;
0409 };
0410 
0411 #include "G4Trap.icc"
0412 
0413 #endif
0414 
0415 #endif