Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 09:40:41

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 UnplacedVolumeImplHelper<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   VECCORE_ATT_HOST_DEVICE
0065   VECGEOM_FORCE_INLINE
0066   virtual ESolidType GetType() const override { return ESolidType::ellipsoid; }
0067 
0068   /// Getter for the structure storing ellipsoid data
0069   VECCORE_ATT_HOST_DEVICE
0070   EllipsoidStruct<Precision> const &GetStruct() const { return fEllipsoid; }
0071 
0072   /// Getter for x semi-axis
0073   VECCORE_ATT_HOST_DEVICE
0074   VECGEOM_FORCE_INLINE
0075   Precision GetDx() const { return fEllipsoid.fDx; }
0076 
0077   /// Getter for y semi-axis
0078   VECCORE_ATT_HOST_DEVICE
0079   VECGEOM_FORCE_INLINE
0080   Precision GetDy() const { return fEllipsoid.fDy; }
0081 
0082   /// Getter for z semi-axis
0083   VECCORE_ATT_HOST_DEVICE
0084   VECGEOM_FORCE_INLINE
0085   Precision GetDz() const { return fEllipsoid.fDz; }
0086 
0087   /// Getter for bottom cut in z, return -dz if the cut is not set
0088   VECCORE_ATT_HOST_DEVICE
0089   VECGEOM_FORCE_INLINE
0090   Precision GetZBottomCut() const { return fEllipsoid.fZBottomCut; }
0091 
0092   /// Getter for top cut in z, return +dz if the cut is not set
0093   VECCORE_ATT_HOST_DEVICE
0094   VECGEOM_FORCE_INLINE
0095   Precision GetZTopCut() const { return fEllipsoid.fZTopCut; }
0096 
0097   /// Set ellipsoid dimensions
0098   /// @param dx Length of x semi-axis
0099   /// @param dy Length of y semi-axis
0100   /// @param dy Length of z semi-axis
0101   VECCORE_ATT_HOST_DEVICE
0102   VECGEOM_FORCE_INLINE
0103   void SetSemiAxes(Precision dx, Precision dy, Precision dz)
0104   {
0105     fEllipsoid.fDx = dx;
0106     fEllipsoid.fDy = dy;
0107     fEllipsoid.fDz = dz;
0108     CheckParameters();
0109   };
0110 
0111   /// Set cuts in z
0112   /// @param zBottomCut Bottom cut in z, shape lies above this plane
0113   /// @param zTopCut Top cut in z, shape lies below this plane
0114   VECCORE_ATT_HOST_DEVICE
0115   VECGEOM_FORCE_INLINE
0116   void SetZCuts(Precision zBottomCut, Precision zTopCut)
0117   {
0118     fEllipsoid.fZBottomCut = zBottomCut;
0119     fEllipsoid.fZTopCut    = zTopCut;
0120     CheckParameters();
0121   };
0122 
0123   VECCORE_ATT_HOST_DEVICE
0124   void Extent(Vector3D<Precision> &, Vector3D<Precision> &) const override;
0125 
0126   Precision Capacity() const override { return fEllipsoid.fCubicVolume; }
0127 
0128   Precision SurfaceArea() const override { return fEllipsoid.fSurfaceArea; }
0129 
0130   Vector3D<Precision> SamplePointOnSurface() const override;
0131 
0132   VECCORE_ATT_HOST_DEVICE
0133   virtual bool Normal(Vector3D<Precision> const &p, Vector3D<Precision> &normal) const override
0134   {
0135     bool valid;
0136     normal = EllipsoidImplementation::NormalKernel(fEllipsoid, p, valid);
0137     return valid;
0138   }
0139 
0140   /// Return type of the solid as a string
0141   std::string GetEntityType() const { return "Ellipsoid"; }
0142 
0143   /// Dump volume parameters to an output stream
0144   std::ostream &StreamInfo(std::ostream &os) const;
0145 
0146 public:
0147   virtual int MemorySize() const final { return sizeof(*this); }
0148 
0149   VECCORE_ATT_HOST_DEVICE
0150   virtual void Print() const override;
0151 
0152   virtual void Print(std::ostream &os) const override;
0153 
0154 #ifndef VECCORE_CUDA
0155   virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0156 #endif
0157 
0158 #ifdef VECGEOM_CUDA_INTERFACE
0159   virtual size_t DeviceSizeOf() const override { return DevicePtr<cuda::UnplacedEllipsoid>::SizeOf(); }
0160   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0161   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0162 #endif
0163 
0164   /// Templated factory for creating a placed volume
0165 #ifndef VECCORE_CUDA
0166   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0167                                VPlacedVolume *const placement = NULL);
0168 
0169   VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume, Transformation3D const *const transformation,
0170                                    VPlacedVolume *const placement) const override;
0171 #else
0172   VECCORE_ATT_DEVICE
0173   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0174                                const int id, const int copy_no, const int child_id,
0175                                VPlacedVolume *const placement = NULL);
0176   VECCORE_ATT_DEVICE VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0177                                                       Transformation3D const *const transformation, const int id,
0178                                                       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