Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // This file is part of VecGeom and is distributed under the
0002 // conditions in the file LICENSE.txt in the top directory.
0003 // For the full list of authors see CONTRIBUTORS.txt and `git log`.
0004 
0005 /// Declaration of the unplaced ellipsoid shape
0006 /// @file volumes/UnplacedEllipsoid.h
0007 /// @author Evgueni Tcherniaev
0008 
0009 #ifndef VECGEOM_VOLUMES_UNPLACEDELLIPSOID_H_
0010 #define VECGEOM_VOLUMES_UNPLACEDELLIPSOID_H_
0011 
0012 #include "VecGeom/base/Cuda.h"
0013 #include "VecGeom/base/Global.h"
0014 #include "VecGeom/base/AlignedBase.h"
0015 #include "VecGeom/base/Vector3D.h"
0016 #include "VecGeom/volumes/UnplacedVolume.h"
0017 #include "VecGeom/volumes/EllipsoidStruct.h"
0018 #include "VecGeom/volumes/kernel/EllipsoidImplementation.h"
0019 #include "VecGeom/volumes/UnplacedVolumeImplHelper.h"
0020 
0021 namespace vecgeom {
0022 
0023 VECGEOM_DEVICE_FORWARD_DECLARE(class UnplacedEllipsoid;);
0024 VECGEOM_DEVICE_DECLARE_CONV(class, UnplacedEllipsoid);
0025 
0026 inline namespace VECGEOM_IMPL_NAMESPACE {
0027 
0028 /// Class for ellipsoid shape primitive
0029 ///
0030 /// Ellipsoid shape is limited by a quadratic surface given by the equation:
0031 ///
0032 /// (x/dx)^2 + (y/dy)^2 + (z/dz)^2 = 1
0033 ///
0034 /// where dx, dy and dz are lengths of the semi-axes. The shape is centered at the origin
0035 /// and and optionally may have cuts in z.
0036 ///
0037 class UnplacedEllipsoid : public SIMDUnplacedVolumeImplHelper<EllipsoidImplementation>, public AlignedBase {
0038 
0039 private:
0040   EllipsoidStruct<Precision> fEllipsoid;
0041 
0042   /// Check correctness of the parameters and set the data members
0043   VECCORE_ATT_HOST_DEVICE
0044   void CheckParameters();
0045 
0046   /// Compute area of lateral surface
0047   VECCORE_ATT_HOST_DEVICE
0048   Precision LateralSurfaceArea() const;
0049 
0050 public:
0051   /// Default constructor
0052   VECCORE_ATT_HOST_DEVICE
0053   UnplacedEllipsoid();
0054 
0055   /// Constructor
0056   /// @param dx Length of x semi-axis
0057   /// @param dy Length of y semi-axis
0058   /// @param dz Length of z semi-axis
0059   /// @param zBottomCut Bottom cut in z, shape lies above this plane
0060   /// @param zTopCut Top cut in z, shape lies below this plane
0061   VECCORE_ATT_HOST_DEVICE
0062   UnplacedEllipsoid(Precision dx, Precision dy, Precision dz, Precision zBottomCut = 0., Precision zTopCut = 0.);
0063 
0064   /// Getter for the structure storing ellipsoid data
0065   VECCORE_ATT_HOST_DEVICE
0066   EllipsoidStruct<Precision> const &GetStruct() const { return fEllipsoid; }
0067 
0068   /// Getter for x semi-axis
0069   VECCORE_ATT_HOST_DEVICE
0070   VECGEOM_FORCE_INLINE
0071   Precision GetDx() const { return fEllipsoid.fDx; }
0072 
0073   /// Getter for y semi-axis
0074   VECCORE_ATT_HOST_DEVICE
0075   VECGEOM_FORCE_INLINE
0076   Precision GetDy() const { return fEllipsoid.fDy; }
0077 
0078   /// Getter for z semi-axis
0079   VECCORE_ATT_HOST_DEVICE
0080   VECGEOM_FORCE_INLINE
0081   Precision GetDz() const { return fEllipsoid.fDz; }
0082 
0083   /// Getter for bottom cut in z, return -dz if the cut is not set
0084   VECCORE_ATT_HOST_DEVICE
0085   VECGEOM_FORCE_INLINE
0086   Precision GetZBottomCut() const { return fEllipsoid.fZBottomCut; }
0087 
0088   /// Getter for top cut in z, return +dz if the cut is not set
0089   VECCORE_ATT_HOST_DEVICE
0090   VECGEOM_FORCE_INLINE
0091   Precision GetZTopCut() const { return fEllipsoid.fZTopCut; }
0092 
0093   /// Set ellipsoid dimensions
0094   /// @param dx Length of x semi-axis
0095   /// @param dy Length of y semi-axis
0096   /// @param dy Length of z semi-axis
0097   VECCORE_ATT_HOST_DEVICE
0098   VECGEOM_FORCE_INLINE
0099   void SetSemiAxes(Precision dx, Precision dy, Precision dz)
0100   {
0101     fEllipsoid.fDx = dx;
0102     fEllipsoid.fDy = dy;
0103     fEllipsoid.fDz = dz;
0104     CheckParameters();
0105   };
0106 
0107   /// Set cuts in z
0108   /// @param zBottomCut Bottom cut in z, shape lies above this plane
0109   /// @param zTopCut Top cut in z, shape lies below this plane
0110   VECCORE_ATT_HOST_DEVICE
0111   VECGEOM_FORCE_INLINE
0112   void SetZCuts(Precision zBottomCut, Precision zTopCut)
0113   {
0114     fEllipsoid.fZBottomCut = zBottomCut;
0115     fEllipsoid.fZTopCut    = zTopCut;
0116     CheckParameters();
0117   };
0118 
0119   VECCORE_ATT_HOST_DEVICE
0120   void Extent(Vector3D<Precision> &, Vector3D<Precision> &) const override;
0121 
0122   Precision Capacity() const override { return fEllipsoid.fCubicVolume; }
0123 
0124   Precision SurfaceArea() const override { return fEllipsoid.fSurfaceArea; }
0125 
0126   Vector3D<Precision> SamplePointOnSurface() const override;
0127 
0128   VECCORE_ATT_HOST_DEVICE
0129   virtual bool Normal(Vector3D<Precision> const &p, Vector3D<Precision> &normal) const override
0130   {
0131     bool valid;
0132     normal = EllipsoidImplementation::NormalKernel(fEllipsoid, p, valid);
0133     return valid;
0134   }
0135 
0136   /// Return type of the solid as a string
0137   std::string GetEntityType() const { return "Ellipsoid"; }
0138 
0139   /// Dump volume parameters to an output stream
0140   std::ostream &StreamInfo(std::ostream &os) const;
0141 
0142 public:
0143   virtual int MemorySize() const final { return sizeof(*this); }
0144 
0145   VECCORE_ATT_HOST_DEVICE
0146   virtual void Print() const override;
0147 
0148   virtual void Print(std::ostream &os) const override;
0149 
0150 #ifndef VECCORE_CUDA
0151   virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0152 #endif
0153 
0154 #ifdef VECGEOM_CUDA_INTERFACE
0155   virtual size_t DeviceSizeOf() const override { return DevicePtr<cuda::UnplacedEllipsoid>::SizeOf(); }
0156   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0157   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0158 #endif
0159 
0160   /// Templated factory for creating a placed volume
0161 #ifndef VECCORE_CUDA
0162   template <TranslationCode trans_code, RotationCode rot_code>
0163   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0164                                VPlacedVolume *const placement = NULL);
0165 
0166   VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume, Transformation3D const *const transformation,
0167                                    const TranslationCode trans_code, const RotationCode rot_code,
0168                                    VPlacedVolume *const placement) const override;
0169 #else
0170   template <TranslationCode trans_code, RotationCode rot_code>
0171   VECCORE_ATT_DEVICE
0172   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0173                                const int id, const int copy_no, const int child_id,
0174                                VPlacedVolume *const placement = NULL);
0175   VECCORE_ATT_DEVICE VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0176                                                       Transformation3D const *const transformation,
0177                                                       const TranslationCode trans_code, const RotationCode rot_code,
0178                                                       const int id, const int copy_no, const int child_id,
0179                                                       VPlacedVolume *const placement) const override;
0180 
0181 #endif
0182 };
0183 } // namespace VECGEOM_IMPL_NAMESPACE
0184 } // namespace vecgeom
0185 
0186 #endif