Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:14:15

0001 /// \file UnplacedGenTrap.h
0002 /// \author: swenzel
0003 ///  Modified and completed: mihaela.gheata@cern.ch
0004 
0005 #ifndef VECGEOM_VOLUMES_UNPLACEDGENTRAP_H_
0006 #define VECGEOM_VOLUMES_UNPLACEDGENTRAP_H_
0007 
0008 #include "VecGeom/base/Cuda.h"
0009 #include "VecGeom/base/Global.h"
0010 #include "VecGeom/base/AlignedBase.h"
0011 #include "VecGeom/volumes/GenTrapStruct.h"
0012 #include "VecGeom/volumes/UnplacedVolume.h"
0013 #include "VecGeom/volumes/SecondOrderSurfaceShell.h"
0014 #include "VecGeom/volumes/kernel/GenTrapImplementation.h"
0015 #include "VecGeom/volumes/UnplacedVolumeImplHelper.h"
0016 
0017 namespace vecgeom {
0018 
0019 VECGEOM_DEVICE_FORWARD_DECLARE(class UnplacedGenTrap;);
0020 VECGEOM_DEVICE_DECLARE_CONV(class, UnplacedGenTrap);
0021 
0022 inline namespace VECGEOM_IMPL_NAMESPACE {
0023 
0024 /**
0025  * A generic trap:
0026  * see TGeoArb8 or UGenericTrap
0027  */
0028 class UnplacedGenTrap : public SIMDUnplacedVolumeImplHelper<GenTrapImplementation>, public AlignedBase {
0029 
0030 public:
0031   using Vertex_t = Vector3D<Precision>;
0032 
0033   GenTrapStruct<Precision> fGenTrap; /** The generic trapezoid structure */
0034 
0035 public:
0036   /** @brief UnplacedGenTrap dummy constructor */
0037   VECCORE_ATT_HOST_DEVICE
0038   UnplacedGenTrap() : fGenTrap() {}
0039 
0040   /** @brief UnplacedGenTrap constructor
0041    * @param verticesx X positions of vertices in array form
0042    * @param verticesy Y positions of vertices in array form
0043    * @param halfzheight The half-height of the GenTrap
0044    */
0045   VECCORE_ATT_HOST_DEVICE
0046   UnplacedGenTrap(const Precision verticesx[], const Precision verticesy[], Precision halfzheight)
0047       : fGenTrap(verticesx, verticesy, halfzheight)
0048   {
0049     fGlobalConvexity = !fGenTrap.fIsTwisted;
0050     ComputeBBox();
0051   }
0052 
0053   /** @brief UnplacedGenTrap destructor */
0054   VECCORE_ATT_HOST_DEVICE
0055   virtual ~UnplacedGenTrap() {}
0056 
0057   VECCORE_ATT_HOST_DEVICE
0058   bool Initialize(const Precision verticesx[], const Precision verticesy[], Precision halfzheight)
0059   {
0060     return fGenTrap.Initialize(verticesx, verticesy, halfzheight);
0061   }
0062 
0063   /** @brief Getter for the generic trapezoid structure */
0064   VECCORE_ATT_HOST_DEVICE
0065   GenTrapStruct<Precision> const &GetStruct() const { return fGenTrap; }
0066 
0067   /** @brief Getter for the surface shell */
0068   VECCORE_ATT_HOST_DEVICE
0069   VECGEOM_FORCE_INLINE
0070   SecondOrderSurfaceShell<4> const &GetShell() const { return (fGenTrap.fSurfaceShell); }
0071 
0072   /** @brief Getter for the half-height */
0073   VECCORE_ATT_HOST_DEVICE
0074   VECGEOM_FORCE_INLINE
0075   Precision GetDZ() const { return (fGenTrap.fDz); }
0076 
0077   /** @brief Setter for the half-height */
0078   VECCORE_ATT_HOST_DEVICE
0079   VECGEOM_FORCE_INLINE
0080   void SetDZ(Precision dz) { fGenTrap.fDz = dz; }
0081 
0082   /** @brief Getter for the twist angle of a face */
0083   VECCORE_ATT_HOST_DEVICE
0084   VECGEOM_FORCE_INLINE
0085   Precision GetTwist(int i) const { return (fGenTrap.fTwist[i]); }
0086 
0087   /** @brief Getter for one of the 8 vertices in Vector3D<Precision> form */
0088   VECCORE_ATT_HOST_DEVICE
0089   VECGEOM_FORCE_INLINE
0090   Vertex_t const &GetVertex(int i) const { return fGenTrap.fVertices[i]; }
0091 
0092   /** @brief Getter for the array of X coordinates of vertices */
0093   VECCORE_ATT_HOST_DEVICE
0094   VECGEOM_FORCE_INLINE
0095   const Precision *GetVerticesX() const { return fGenTrap.fVerticesX; }
0096 
0097   /** @brief Getter for the array of Y coordinates of vertices */
0098   VECCORE_ATT_HOST_DEVICE
0099   VECGEOM_FORCE_INLINE
0100   const Precision *GetVerticesY() const { return fGenTrap.fVerticesY; }
0101 
0102   /** @brief Getter for the list of vertices */
0103   VECCORE_ATT_HOST_DEVICE
0104   VECGEOM_FORCE_INLINE
0105   const Vertex_t *GetVertices() const { return fGenTrap.fVertices; }
0106 
0107   /** @brief Computes if this gentrap is twisted */
0108   VECCORE_ATT_HOST_DEVICE
0109   bool ComputeIsTwisted() { return fGenTrap.ComputeIsTwisted(); }
0110 
0111   /** @brief Computes if the top and bottom quadrilaterals are convex (mandatory) */
0112   VECCORE_ATT_HOST_DEVICE
0113   bool ComputeIsConvexQuadrilaterals() { return fGenTrap.ComputeIsConvexQuadrilaterals(); }
0114 
0115   /** @brief Getter for the planarity of lateral surfaces */
0116   VECCORE_ATT_HOST_DEVICE
0117   VECGEOM_FORCE_INLINE
0118   bool IsPlanar() const { return (!fGenTrap.fIsTwisted); }
0119 
0120   /** @brief Getter for the global convexity of the trapezoid */
0121   VECCORE_ATT_HOST_DEVICE
0122   VECGEOM_FORCE_INLINE
0123   bool IsDegenerated(int i) const { return (fGenTrap.fDegenerated[i]); }
0124 
0125   /** @brief Computes if opposite segments are crossing, making a malformed shape */
0126   // This can become a general utility
0127   VECCORE_ATT_HOST_DEVICE
0128   bool SegmentsCrossing(Vertex_t pa, Vertex_t pb, Vertex_t pc, Vertex_t pd) const
0129   {
0130     return fGenTrap.SegmentsCrossing(pa, pb, pc, pd);
0131   }
0132 
0133   /** @brief Computes and sets the bounding box dimensions/origin */
0134   VECCORE_ATT_HOST_DEVICE
0135   void ComputeBoundingBox() { fGenTrap.ComputeBoundingBox(); }
0136 
0137   /** @brief Memory size in bytes */
0138   virtual int MemorySize() const final { return sizeof(*this); }
0139 
0140   /** @brief Print parameters of the trapezoid */
0141   VECCORE_ATT_HOST_DEVICE
0142   virtual void Print() const final { fGenTrap.Print(); }
0143 
0144   /** @brief Print parameters of the trapezoid to stream */
0145   virtual void Print(std::ostream &os) const final;
0146 
0147 #ifndef VECCORE_CUDA
0148   virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0149 #endif
0150 
0151 #ifdef VECGEOM_CUDA_INTERFACE
0152   /** @brief Size of object on the device */
0153   size_t DeviceSizeOf() const final { return DevicePtr<cuda::UnplacedGenTrap>::SizeOf(); }
0154   /** @brief Copy to GPU interface function */
0155   DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const final;
0156   /** @brief Copy to GPU implementation */
0157   DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const final;
0158 #endif
0159 
0160   /** @brief Interface method for computing capacity */
0161   Precision Capacity() const override { return volume(); }
0162 
0163   /** @brief Implementation of capacity computation */
0164   Precision volume() const;
0165 
0166   /** @brief Implementation of surface area computation */
0167   Precision SurfaceArea() const override;
0168 
0169   /** @brief Compute normal vector to surface */
0170   VECCORE_ATT_HOST_DEVICE
0171   bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &normal) const override;
0172 
0173   /** @brief Computes the extent on X/Y/Z of the trapezoid */
0174   VECCORE_ATT_HOST_DEVICE
0175   void Extent(Vertex_t &amin, Vertex_t &amax) const override { return fGenTrap.Extent(amin, amax); }
0176 
0177   /** @brief Generates randomly a point on the surface */
0178   Vertex_t SamplePointOnSurface() const override;
0179 
0180   /** @brief Get type name */
0181   std::string GetEntityType() const { return "GenTrap"; }
0182 
0183   /** @brief Templated factory for creating a placed volume */
0184   template <TranslationCode transCodeT, RotationCode rotCodeT>
0185   VECCORE_ATT_DEVICE
0186   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0187 #ifdef VECCORE_CUDA
0188                                const int id, const int copy_no, const int child_id,
0189 #endif
0190                                VPlacedVolume *const placement = NULL);
0191 
0192   /*
0193     // Is this still needed?
0194     VECCORE_ATT_DEVICE
0195     static VPlacedVolume *CreateSpecializedVolume(LogicalVolume const *const volume,
0196                                                   Transformation3D const *const transformation,
0197                                                   const TranslationCode trans_code, const RotationCode rot_code,
0198   #ifdef VECCORE_CUDA
0199                                                   const int id,
0200   #endif
0201                                                   VPlacedVolume *const placement = NULL);
0202   */
0203   /** @brief Stream trapezoid information in the Geant4 style */
0204   std::ostream &StreamInfo(std::ostream &os) const;
0205 
0206 private:
0207   /** @brief Factory for specializing the volume */
0208   VECCORE_ATT_DEVICE
0209   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0210                                            Transformation3D const *const transformation,
0211                                            const TranslationCode trans_code, const RotationCode rot_code,
0212 #ifdef VECCORE_CUDA
0213                                            const int id, const int copy_no, const int child_id,
0214 #endif
0215                                            VPlacedVolume *const placement = NULL) const final;
0216 
0217 }; // end of class declaration
0218 } // namespace VECGEOM_IMPL_NAMESPACE
0219 } // namespace vecgeom
0220 
0221 #endif // VECGEOM_VOLUMES_UNPLACEDGENTRAP_H_