Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-02 09:06: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 // G4VTwistedFaceted
0027 //
0028 // Class description:
0029 //
0030 // G4VTwistedFaceted is a base class for twisted boxoids:
0031 // G4TwistedTrd, G4TwistedTrap and G4TwistedBox
0032 
0033 // Author: Oliver Link (CERN), 27.10.2004 - Created
0034 // --------------------------------------------------------------------
0035 #ifndef G4VTWISTEDFACETED_HH
0036 #define G4VTWISTEDFACETED_HH 1
0037 
0038 #include "G4VSolid.hh"
0039 #include "G4TwoVector.hh"
0040 #include "G4TwistTrapAlphaSide.hh"
0041 #include "G4TwistTrapParallelSide.hh"
0042 #include "G4TwistBoxSide.hh"
0043 #include "G4TwistTrapFlatSide.hh"
0044 
0045 class G4SolidExtentList;
0046 class G4ClippablePolygon;
0047 
0048 /**
0049  * @brief G4VTwistedFaceted is a base class for twisted boxoids:
0050  * G4TwistedTrd, G4TwistedTrap and G4TwistedBox.
0051  */
0052 
0053 class G4VTwistedFaceted: public G4VSolid
0054 {
0055   public:
0056 
0057     /**
0058      * Constructs a faceted solid, given its parameters.
0059      *  @param[in] pName The solid name.
0060      *  @param[in] pPhiTwist Twist angle.
0061      *  @param[in] pDz Half-length along Z axis.
0062      *  @param[in] pTheta Polar angle of the line joining the centres of the
0063      *             faces at -/+pDz.
0064      *  @param[in] pPhi Azimuthal angle of the line joining the centres of the
0065      *             faces at -/+pDz.
0066      *  @param[in] pDy1 Half Y length at -pDz.
0067      *  @param[in] pDx1 Half X length at -pDz, y=-pDy1.
0068      *  @param[in] pDx2 Half X length at -pDz, y=+pDy1.
0069      *  @param[in] pDy2 Half Y length at +pDz.
0070      *  @param[in] pDx3 Half X length at +pDz, y=-pDy2.
0071      *  @param[in] pDx4 Half X length at +pDz, y=+pDy2.
0072      *  @param[in] pAlph Angle with respect to the Y axis from centre of side.
0073      */
0074     G4VTwistedFaceted(const G4String& pname,    // Name of instance
0075                             G4double PhiTwist,  // twist angle
0076                             G4double pDz,       // half z lenght
0077                             G4double pTheta,  // direction between end planes
0078                             G4double pPhi,    // defined by polar & azim. angles
0079                             G4double pDy1,    // half y length at -pDz
0080                             G4double pDx1,    // half x length at -pDz,-pDy
0081                             G4double pDx2,    // half x length at -pDz,+pDy
0082                             G4double pDy2,    // half y length at +pDz
0083                             G4double pDx3,    // half x length at +pDz,-pDy
0084                             G4double pDx4,    // half x length at +pDz,+pDy
0085                             G4double pAlph ); // tilt angle at +pDz
0086 
0087     /**
0088      * Destructor.
0089      */
0090     ~G4VTwistedFaceted() override;
0091 
0092     /**
0093      * Dispatch method for parameterisation replication mechanism and
0094      * dimension computation.
0095      */
0096     void ComputeDimensions(G4VPVParameterisation*,
0097                            const G4int,
0098                            const G4VPhysicalVolume*  ) override;
0099 
0100     /**
0101      * Computes the bounding limits of the solid.
0102      *  @param[out] pMin The minimum bounding limit point.
0103      *  @param[out] pMax The maximum bounding limit point.
0104      */
0105     void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const override;
0106 
0107     /**
0108      * Calculates the minimum and maximum extent of the solid, when under the
0109      * specified transform, and within the specified limits.
0110      *  @param[in] pAxis The axis along which compute the extent.
0111      *  @param[in] pVoxelLimit The limiting space dictated by voxels.
0112      *  @param[in] pTransform The internal transformation applied to the solid.
0113      *  @param[out] pMin The minimum extent value.
0114      *  @param[out] pMax The maximum extent value.
0115      *  @returns True if the solid is intersected by the extent region.
0116      */
0117     G4bool CalculateExtent(const EAxis              pAxis,
0118                            const G4VoxelLimits&     pVoxelLimit,
0119                            const G4AffineTransform& pTransform,
0120                                  G4double&          pMin,
0121                                  G4double&          pMax ) const override;
0122 
0123     /**
0124      * Concrete implementations of the expected query interfaces for
0125      * solids, as defined in the base class G4VSolid.
0126      */
0127     G4double DistanceToIn (const G4ThreeVector& p,
0128                            const G4ThreeVector& v ) const override;
0129     G4double DistanceToIn (const G4ThreeVector& p ) const override;
0130     G4double DistanceToOut(const G4ThreeVector& p,
0131                            const G4ThreeVector& v,
0132                            const G4bool         calcnorm  = false,
0133                                  G4bool* validnorm = nullptr,
0134                                  G4ThreeVector*  n = nullptr ) const override;
0135     G4double DistanceToOut(const G4ThreeVector& p) const override;
0136     EInside Inside (const G4ThreeVector& p) const override;
0137     G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const override;
0138 
0139     /**
0140      * Returns a random point located and uniformly distributed on the
0141      * surface of the solid.
0142      */
0143     G4ThreeVector GetPointOnSurface() const override;
0144 
0145     /**
0146      * Returning an estimation of the solid volume (capacity) and
0147      * surface area, in internal units.
0148      */
0149     G4double GetCubicVolume() override;
0150     G4double GetSurfaceArea() override;
0151 
0152     /**
0153      * Methods for creating graphical representations (i.e. for visualisation).
0154      */
0155     void DescribeYourselfTo (G4VGraphicsScene& scene) const override;
0156     G4Polyhedron* CreatePolyhedron () const override;
0157     G4Polyhedron* GetPolyhedron () const override;
0158     G4VisExtent GetExtent () const override;
0159 
0160     /**
0161      * Streams the object contents to an output stream.
0162      */
0163     std::ostream& StreamInfo(std::ostream& os) const override;
0164 
0165     /**
0166      * Accessors.
0167      */
0168     inline G4double GetTwistAngle() const { return fPhiTwist; }
0169     inline G4double GetDx1   () const { return fDx1   ; }
0170     inline G4double GetDx2   () const { return fDx2   ; }
0171     inline G4double GetDx3   () const { return fDx3   ; }
0172     inline G4double GetDx4   () const { return fDx4   ; }
0173     inline G4double GetDy1   () const { return fDy1   ; }
0174     inline G4double GetDy2   () const { return fDy2   ; }
0175     inline G4double GetDz    () const { return fDz    ; }
0176     inline G4double GetPhi   () const { return fPhi   ; }
0177     inline G4double GetTheta () const { return fTheta ; }
0178     inline G4double GetAlpha () const { return fAlph  ; }
0179     inline G4double Xcoef(G4double u, G4double phi, G4double ftg) const;
0180     inline G4double GetValueA(G4double phi) const;
0181     inline G4double GetValueB(G4double phi) const;
0182     inline G4double GetValueD(G4double phi) const;
0183 
0184     /**
0185      * Returns the type ID, "G4VTwistedFaceted" of the solid.
0186      */
0187     G4GeometryType GetEntityType() const override;
0188 
0189     /**
0190      * Fake default constructor for usage restricted to direct object
0191      * persistency for clients requiring preallocation of memory for
0192      * persistifiable objects.
0193      */
0194     G4VTwistedFaceted(__void__&);
0195 
0196     /**
0197      * Copy constructor and assignment operator.
0198      */
0199     G4VTwistedFaceted(const G4VTwistedFaceted& rhs);
0200     G4VTwistedFaceted& operator=(const G4VTwistedFaceted& rhs);
0201 
0202   protected:
0203 
0204     mutable G4bool fRebuildPolyhedron = false;
0205     mutable G4Polyhedron* fpPolyhedron = nullptr;  // polyhedron for vis
0206 
0207     G4double fCubicVolume = 0.0; // volume of the solid
0208     G4double fSurfaceArea = 0.0; // area of the solid
0209 
0210   private:
0211 
0212     /**
0213      * Utility used for computing the surface area.
0214      */
0215     G4double GetLateralFaceArea(const G4TwoVector& p1,
0216                                 const G4TwoVector& p2,
0217                                 const G4TwoVector& p3,
0218                                 const G4TwoVector& p4) const;
0219 
0220     /**
0221      * Utility used in constructor for creating the surfaces.
0222      */
0223     void CreateSurfaces();
0224 
0225   private:
0226 
0227     G4double fTheta;
0228     G4double fPhi ;
0229 
0230     G4double fDy1;
0231     G4double fDx1;
0232     G4double fDx2;
0233 
0234     G4double fDy2;
0235     G4double fDx3;
0236     G4double fDx4;
0237 
0238     G4double fDz;        // Half-length along the z axis
0239 
0240     G4double fDx ;       // maximum side in x
0241     G4double fDy ;       // maximum side in y
0242 
0243     G4double fAlph ;
0244     G4double fTAlph ;    // std::tan(fAlph)
0245 
0246     G4double fdeltaX ;
0247     G4double fdeltaY ;
0248 
0249     G4double fPhiTwist;  // twist angle ( dphi in surface equation)
0250 
0251     G4VTwistSurface* fLowerEndcap ;  // surface of -ve z
0252     G4VTwistSurface* fUpperEndcap ;  // surface of +ve z
0253 
0254     G4VTwistSurface* fSide0 ;    // Twisted Side at phi = 0 deg
0255     G4VTwistSurface* fSide90 ;   // Twisted Side at phi = 90 deg
0256     G4VTwistSurface* fSide180 ;  // Twisted Side at phi = 180 deg
0257     G4VTwistSurface* fSide270 ;  // Twisted Side at phi = 270 deg
0258 
0259 };
0260 
0261 //=====================================================================
0262 
0263 inline
0264 G4double G4VTwistedFaceted::GetValueA(G4double phi) const
0265 {
0266   return ( fDx4 + fDx2  + ( fDx4 - fDx2 ) * ( 2 * phi ) / fPhiTwist  ) ;
0267 }
0268 
0269 inline
0270 G4double G4VTwistedFaceted::GetValueD(G4double phi) const
0271 {
0272   return ( fDx3 + fDx1  + ( fDx3 - fDx1 ) * ( 2 * phi ) / fPhiTwist  ) ;
0273 }
0274 
0275 inline
0276 G4double G4VTwistedFaceted::GetValueB(G4double phi) const
0277 {
0278   return ( fDy2 + fDy1  + ( fDy2 - fDy1 ) * ( 2 * phi ) / fPhiTwist ) ;
0279 }
0280 
0281 inline
0282 G4double G4VTwistedFaceted::Xcoef(G4double u, G4double phi, G4double ftg) const
0283 {
0284   return GetValueA(phi)/2. + (GetValueD(phi)-GetValueA(phi))/4.
0285     - u*( ( GetValueD(phi)-GetValueA(phi) ) / ( 2 * GetValueB(phi) ) - ftg );
0286 }
0287 
0288 #endif