Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-03 09:29:42

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/kernel/GenTrapImplementation.h"
0014 #include "VecGeom/volumes/UnplacedVolumeImplHelper.h"
0015 #include <VecGeom/management/Logger.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 UnplacedVolumeImplHelper<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.IsPlanar();
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   VECCORE_ATT_HOST_DEVICE
0064   VECGEOM_FORCE_INLINE
0065   virtual ESolidType GetType() const override { return ESolidType::gentrap; }
0066 
0067   /** @brief Getter for the generic trapezoid structure */
0068   VECCORE_ATT_HOST_DEVICE
0069   GenTrapStruct<Precision> const &GetStruct() const { return fGenTrap; }
0070 
0071   /** @brief Getter for the half-height */
0072   VECCORE_ATT_HOST_DEVICE
0073   VECGEOM_FORCE_INLINE
0074   Precision GetDZ() const { return (fGenTrap.fDz); }
0075 
0076   /** @brief Setter for the half-height */
0077   VECCORE_ATT_HOST_DEVICE
0078   VECGEOM_FORCE_INLINE
0079   void SetDZ(Precision dz) { fGenTrap.fDz = dz; }
0080 
0081   /** @brief Getter for the twist angle of a face */
0082   VECCORE_ATT_HOST_DEVICE
0083   VECGEOM_FORCE_INLINE
0084   Precision GetTwist(int i) const { return (fGenTrap.GetTwist(i)); }
0085 
0086   /** @brief Getter for one of the 8 vertices in Vector3D<Precision> form */
0087   VECCORE_ATT_HOST_DEVICE
0088   VECGEOM_FORCE_INLINE
0089   Vertex_t const &GetVertex(int i) const { return fGenTrap.fVertices[i]; }
0090 
0091   /** @brief Getter for the array of X coordinates of vertices */
0092   VECCORE_ATT_HOST_DEVICE
0093   const Precision *GetVerticesX() const
0094   {
0095     static bool printed_once{false};
0096     auto vertx = new Precision[8];
0097     for (auto i = 0; i < 8; ++i)
0098       vertx[i] = fGenTrap.fVertices[i].x();
0099     if (!printed_once) {
0100       VECGEOM_LOG(warning)
0101           << "GetVerticesX is deprecated and you now own the allocated array. Use GetVertices instead.";
0102       printed_once = true;
0103     }
0104     return vertx;
0105   }
0106 
0107   /** @brief Getter for the array of Y coordinates of vertices */
0108   VECCORE_ATT_HOST_DEVICE
0109   const Precision *GetVerticesY() const
0110   {
0111     static bool printed_once{false};
0112     auto verty = new Precision[8];
0113     for (auto i = 0; i < 8; ++i)
0114       verty[i] = fGenTrap.fVertices[i].y();
0115     if (!printed_once) {
0116       VECGEOM_LOG(warning)
0117           << "GetVerticesY is deprecated and you now own the allocated array. Use GetVertices instead.";
0118       printed_once = true;
0119     }
0120     return verty;
0121   }
0122 
0123   /** @brief Getter for the list of vertices */
0124   VECCORE_ATT_HOST_DEVICE
0125   VECGEOM_FORCE_INLINE
0126   const Vertex_t *GetVertices() const { return fGenTrap.fVertices; }
0127 
0128   /** @brief Computes if this gentrap is twisted */
0129   VECCORE_ATT_HOST_DEVICE
0130   bool ComputeIsTwisted() { return fGenTrap.ComputeTwistedFaces() > 0; }
0131 
0132   /** @brief Computes if the top and bottom quadrilaterals are convex (mandatory) */
0133   VECCORE_ATT_HOST_DEVICE
0134   bool ComputeIsConvexQuadrilaterals() { return fGenTrap.ComputeIsConvexQuadrilaterals(); }
0135 
0136   /** @brief Getter for the planarity of lateral surfaces */
0137   VECCORE_ATT_HOST_DEVICE
0138   VECGEOM_FORCE_INLINE
0139   bool IsPlanar() const { return (fGenTrap.IsPlanar()); }
0140 
0141   /** @brief Getter for the global convexity of the trapezoid */
0142   VECCORE_ATT_HOST_DEVICE
0143   VECGEOM_FORCE_INLINE
0144   bool IsDegenerated(int i) const { return (fGenTrap.IsDegenerated(i)); }
0145 
0146   /** @brief Computes if opposite segments are crossing, making a malformed shape */
0147   // This can become a general utility
0148   VECCORE_ATT_HOST_DEVICE
0149   bool SegmentsCrossing(Vertex_t pa, Vertex_t pb, Vertex_t pc, Vertex_t pd) const
0150   {
0151     return fGenTrap.SegmentsCrossing(pa, pb, pc, pd);
0152   }
0153 
0154   /** @brief Computes and sets the bounding box dimensions/origin */
0155   VECCORE_ATT_HOST_DEVICE
0156   void ComputeBoundingBox() { fGenTrap.ComputeBoundingBox(); }
0157 
0158   /** @brief Memory size in bytes */
0159   virtual int MemorySize() const final { return sizeof(*this); }
0160 
0161   /** @brief Print parameters of the trapezoid */
0162   VECCORE_ATT_HOST_DEVICE
0163   virtual void Print() const final { fGenTrap.Print(); }
0164 
0165   /** @brief Print parameters of the trapezoid to stream */
0166   virtual void Print(std::ostream &os) const final;
0167 
0168 #ifndef VECCORE_CUDA
0169   virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0170 #endif
0171 
0172 #ifdef VECGEOM_CUDA_INTERFACE
0173   /** @brief Size of object on the device */
0174   size_t DeviceSizeOf() const final { return DevicePtr<cuda::UnplacedGenTrap>::SizeOf(); }
0175   /** @brief Copy to GPU interface function */
0176   DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const final;
0177   /** @brief Copy to GPU implementation */
0178   DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const final;
0179 #endif
0180 
0181   /** @brief Interface method for computing capacity */
0182   Precision Capacity() const override { return volume(); }
0183 
0184   /** @brief Implementation of capacity computation */
0185   Precision volume() const;
0186 
0187   /** @brief Implementation of surface area computation */
0188   Precision SurfaceArea() const override;
0189 
0190   /** @brief Compute normal vector to surface */
0191   VECCORE_ATT_HOST_DEVICE
0192   bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &normal) const override;
0193 
0194   /** @brief Computes the extent on X/Y/Z of the trapezoid */
0195   VECCORE_ATT_HOST_DEVICE
0196   void Extent(Vertex_t &amin, Vertex_t &amax) const override { return fGenTrap.Extent(amin, amax); }
0197 
0198   /** @brief Generates randomly a point on the surface */
0199   Vertex_t SamplePointOnSurface() const override;
0200 
0201   /** @brief Get type name */
0202   std::string GetEntityType() const { return "GenTrap"; }
0203 
0204   /** @brief Templated factory for creating a placed volume */
0205   VECCORE_ATT_DEVICE
0206   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0207 #ifdef VECCORE_CUDA
0208                                const int id, const int copy_no, const int child_id,
0209 #endif
0210                                VPlacedVolume *const placement = NULL);
0211 
0212   /** @brief Stream trapezoid information in the Geant4 style */
0213   std::ostream &StreamInfo(std::ostream &os) const;
0214 
0215 private:
0216   /** @brief Factory for specializing the volume */
0217   VECCORE_ATT_DEVICE
0218   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0219                                            Transformation3D const *const transformation,
0220 #ifdef VECCORE_CUDA
0221                                            const int id, const int copy_no, const int child_id,
0222 #endif
0223                                            VPlacedVolume *const placement = NULL) const final;
0224 
0225 }; // end of class declaration
0226 } // namespace VECGEOM_IMPL_NAMESPACE
0227 } // namespace vecgeom
0228 
0229 #endif // VECGEOM_VOLUMES_UNPLACEDGENTRAP_H_