Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #ifndef VECGEOM_VOLUMES_UNPLACEDBOX_H_
0002 #define VECGEOM_VOLUMES_UNPLACEDBOX_H_
0003 
0004 #include "VecGeom/base/Cuda.h"
0005 #include "VecGeom/base/Global.h"
0006 #include "VecGeom/base/AlignedBase.h"
0007 #include "VecGeom/base/Vector3D.h"
0008 #include "VecGeom/volumes/UnplacedVolume.h"
0009 #include "VecGeom/volumes/BoxStruct.h" // the pure box struct
0010 #include "VecGeom/volumes/kernel/BoxImplementation.h"
0011 #include "VecGeom/volumes/UnplacedVolumeImplHelper.h"
0012 
0013 namespace vecgeom {
0014 
0015 VECGEOM_DEVICE_FORWARD_DECLARE(class UnplacedBox;);
0016 VECGEOM_DEVICE_DECLARE_CONV(class, UnplacedBox);
0017 
0018 inline namespace VECGEOM_IMPL_NAMESPACE {
0019 
0020 class UnplacedBox : public SIMDUnplacedVolumeImplHelper<BoxImplementation>, public AlignedBase {
0021 
0022 private:
0023   BoxStruct<Precision> fBox;
0024 
0025 public:
0026   using Kernel = BoxImplementation;
0027   UnplacedBox(Vector3D<Precision> const &dim) : fBox(dim) { ComputeBBox(); }
0028   UnplacedBox(char const *, Vector3D<Precision> const &dim) : fBox(dim) { ComputeBBox(); }
0029 
0030   VECCORE_ATT_HOST_DEVICE
0031   UnplacedBox(const Precision dx, const Precision dy, const Precision dz) : fBox(dx, dy, dz)
0032   {
0033     fGlobalConvexity = true;
0034     ComputeBBox();
0035   }
0036   UnplacedBox(char const *, const Precision dx, const Precision dy, const Precision dz) : fBox(dx, dy, dz)
0037   {
0038     fGlobalConvexity = true;
0039     ComputeBBox();
0040   }
0041 
0042   VECCORE_ATT_HOST_DEVICE
0043   BoxStruct<Precision> const &GetStruct() const { return fBox; }
0044 
0045   VECCORE_ATT_HOST_DEVICE
0046   VECGEOM_FORCE_INLINE
0047   Vector3D<Precision> const &dimensions() const { return fBox.fDimensions; }
0048 
0049   VECCORE_ATT_HOST_DEVICE
0050   VECGEOM_FORCE_INLINE
0051   Precision x() const { return dimensions().x(); }
0052 
0053   VECCORE_ATT_HOST_DEVICE
0054   VECGEOM_FORCE_INLINE
0055   Precision y() const { return dimensions().y(); }
0056 
0057   VECCORE_ATT_HOST_DEVICE
0058   VECGEOM_FORCE_INLINE
0059   Precision z() const { return dimensions().z(); }
0060 
0061   void SetX(Precision xx) { fBox.fDimensions[0] = xx; }
0062   void SetY(Precision yy) { fBox.fDimensions[1] = yy; }
0063   void SetZ(Precision zz) { fBox.fDimensions[2] = zz; }
0064 
0065   Precision Capacity() const override { return 8.0 * x() * y() * z(); }
0066 
0067   // VECCORE_ATT_HOST_DEVICE
0068   Precision SurfaceArea() const override
0069   {
0070     // factor 8 because x(),... are half-lengths
0071     return 8.0 * (x() * y() + y() * z() + x() * z());
0072   }
0073 
0074   VECCORE_ATT_HOST_DEVICE
0075   void Extent(Vector3D<Precision> &aMin, Vector3D<Precision> &aMax) const override
0076   {
0077     // Returns the full 3D cartesian extent of the volume
0078     aMin = -fBox.fDimensions;
0079     aMax = fBox.fDimensions;
0080   }
0081 
0082   Vector3D<Precision> SamplePointOnSurface() const override;
0083 
0084   VECCORE_ATT_HOST_DEVICE
0085   virtual bool Normal(Vector3D<Precision> const &p, Vector3D<Precision> &normal) const override
0086   {
0087     bool valid;
0088     normal = BoxImplementation::NormalKernel(fBox, p, valid);
0089     return valid;
0090   }
0091 
0092   VECCORE_ATT_HOST_DEVICE
0093   virtual void Print() const override;
0094 
0095   virtual void Print(std::ostream &os) const override;
0096 
0097 #ifndef VECCORE_CUDA
0098   virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0099 #endif
0100 
0101 #ifdef VECGEOM_CUDA_INTERFACE
0102   virtual size_t DeviceSizeOf() const override { return DevicePtr<cuda::UnplacedBox>::SizeOf(); }
0103   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0104   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0105 #endif
0106 
0107 #ifndef VECCORE_CUDA
0108   // this is the function called from the VolumeFactory
0109   // this may be specific to the shape
0110   template <TranslationCode trans_code, RotationCode rot_code>
0111   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0112                                VPlacedVolume *const placement = NULL);
0113 
0114   VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume, Transformation3D const *const transformation,
0115                                    const TranslationCode trans_code, const RotationCode rot_code,
0116                                    VPlacedVolume *const placement) const override;
0117 #else
0118   template <TranslationCode trans_code, RotationCode rot_code>
0119   VECCORE_ATT_DEVICE
0120   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0121                                const int id, const int copy_no, const int child_id,
0122                                VPlacedVolume *const placement = NULL);
0123   VECCORE_ATT_DEVICE VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0124                                                       Transformation3D const *const transformation,
0125                                                       const TranslationCode trans_code, const RotationCode rot_code,
0126                                                       const int id, const int copy_no, const int child_id,
0127                                                       VPlacedVolume *const placement) const override;
0128 
0129 #endif
0130 };
0131 } // namespace VECGEOM_IMPL_NAMESPACE
0132 } // namespace vecgeom
0133 
0134 #endif