Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-10 09:29:33

0001 /// @file UnplacedTorus2.h
0002 
0003 #ifndef VECGEOM_VOLUMES_UNPLACEDTORUS2_H_
0004 #define VECGEOM_VOLUMES_UNPLACEDTORUS2_H_
0005 
0006 #include "VecGeom/base/Cuda.h"
0007 #include "VecGeom/base/Global.h"
0008 #include "VecGeom/base/AlignedBase.h"
0009 #include "VecGeom/base/Array.h"
0010 #include "VecGeom/volumes/UnplacedVolume.h"
0011 #include "VecGeom/volumes/UnplacedTube.h"
0012 #include "VecGeom/volumes/TorusStruct2.h"
0013 #include "VecGeom/volumes/kernel/TorusImplementation2.h"
0014 #include "VecGeom/volumes/Wedge.h"
0015 #include "VecGeom/volumes/UnplacedVolumeImplHelper.h"
0016 
0017 namespace vecgeom {
0018 
0019 VECGEOM_DEVICE_FORWARD_DECLARE(class UnplacedTorus2;);
0020 VECGEOM_DEVICE_DECLARE_CONV(class, UnplacedTorus2);
0021 // VECGEOM_DEVICE_DECLARE_CONV_TEMPLATE(class, SIMDUnplacedTorus, typename);  // maybe needed w/TorusTypes
0022 
0023 inline namespace VECGEOM_IMPL_NAMESPACE {
0024 
0025 // Introduce Intermediate class ( so that we can do typecasting )
0026 class UnplacedTorus2 : public UnplacedVolumeImplHelper<TorusImplementation2>, public AlignedBase {
0027 private:
0028   // tube defining parameters
0029   TorusStruct2<Precision> fTorus;
0030 
0031   // cached values
0032   Precision fAlongPhi1x, fAlongPhi1y, fAlongPhi2x, fAlongPhi2y;
0033 
0034   VECCORE_ATT_HOST_DEVICE
0035   static void GetAlongVectorToPhiSector(Precision phi, Precision &x, Precision &y)
0036   {
0037     x = std::cos(phi);
0038     y = std::sin(phi);
0039   }
0040 
0041   VECCORE_ATT_HOST_DEVICE
0042   void calculateCached()
0043   {
0044     fTorus.fRmin2 = fTorus.fRmin * fTorus.fRmin;
0045     fTorus.fRmax2 = fTorus.fRmax * fTorus.fRmax;
0046     fTorus.fRtor2 = fTorus.fRtor * fTorus.fRtor;
0047 
0048     GetAlongVectorToPhiSector(fTorus.fSphi, fAlongPhi1x, fAlongPhi1y);
0049     GetAlongVectorToPhiSector(fTorus.fSphi + fTorus.fDphi, fAlongPhi2x, fAlongPhi2y);
0050   }
0051 
0052 public:
0053   VECCORE_ATT_HOST_DEVICE
0054   UnplacedTorus2(Precision const &_rmin, Precision const &_rmax, Precision const &_rtor, Precision const &_sphi,
0055                  Precision const &_dphi)
0056       : fTorus(_rmin, _rmax, _rtor, _sphi, _dphi)
0057   {
0058     calculateCached();
0059 
0060     DetectConvexity();
0061     ComputeBBox();
0062   }
0063 
0064   VECCORE_ATT_HOST_DEVICE
0065   VECGEOM_FORCE_INLINE
0066   virtual ESolidType GetType() const override { return ESolidType::torus; }
0067 
0068   VECCORE_ATT_HOST_DEVICE
0069   TorusStruct2<Precision> const &GetStruct() const { return fTorus; }
0070 
0071   VECCORE_ATT_HOST_DEVICE
0072   void DetectConvexity();
0073 
0074   VECCORE_ATT_HOST_DEVICE
0075   VECGEOM_FORCE_INLINE
0076   Precision rmin() const { return fTorus.fRmin; }
0077 
0078   VECCORE_ATT_HOST_DEVICE
0079   VECGEOM_FORCE_INLINE
0080   Precision rmax() const { return fTorus.fRmax; }
0081 
0082   VECCORE_ATT_HOST_DEVICE
0083   VECGEOM_FORCE_INLINE
0084   Precision rtor() const { return fTorus.fRtor; }
0085 
0086   VECCORE_ATT_HOST_DEVICE
0087   VECGEOM_FORCE_INLINE
0088   Precision sphi() const { return fTorus.fSphi; }
0089 
0090   VECCORE_ATT_HOST_DEVICE
0091   VECGEOM_FORCE_INLINE
0092   Precision dphi() const { return fTorus.fDphi; }
0093 
0094   VECCORE_ATT_HOST_DEVICE
0095   VECGEOM_FORCE_INLINE
0096   Precision rmin2() const { return fTorus.fRmin2; }
0097 
0098   VECCORE_ATT_HOST_DEVICE
0099   VECGEOM_FORCE_INLINE
0100   Precision rmax2() const { return fTorus.fRmax2; }
0101 
0102   VECCORE_ATT_HOST_DEVICE
0103   VECGEOM_FORCE_INLINE
0104   Precision rtor2() const { return fTorus.fRtor2; }
0105 
0106   VECCORE_ATT_HOST_DEVICE
0107   VECGEOM_FORCE_INLINE
0108   evolution::Wedge const &GetWedge() const { return fTorus.fPhiWedge; }
0109 
0110   VECCORE_ATT_HOST_DEVICE
0111   VECGEOM_FORCE_INLINE
0112   Precision alongPhi1x() const { return fAlongPhi1x; }
0113 
0114   VECCORE_ATT_HOST_DEVICE
0115   VECGEOM_FORCE_INLINE
0116   Precision alongPhi1y() const { return fAlongPhi1y; }
0117 
0118   VECCORE_ATT_HOST_DEVICE
0119   VECGEOM_FORCE_INLINE
0120   Precision alongPhi2x() const { return fAlongPhi2x; }
0121 
0122   VECCORE_ATT_HOST_DEVICE
0123   VECGEOM_FORCE_INLINE
0124   Precision alongPhi2y() const { return fAlongPhi2y; }
0125 
0126   VECCORE_ATT_HOST_DEVICE
0127   VECGEOM_FORCE_INLINE
0128   Precision volume() const
0129   {
0130     return fTorus.fDphi * kPi * fTorus.fRtor * (fTorus.fRmax * fTorus.fRmax - fTorus.fRmin * fTorus.fRmin);
0131   }
0132 
0133   VECCORE_ATT_HOST_DEVICE
0134   void SetRMin(Precision arg)
0135   {
0136     fTorus.fRmin = arg;
0137     calculateCached();
0138   }
0139   VECCORE_ATT_HOST_DEVICE
0140   void SetRMax(Precision arg)
0141   {
0142     fTorus.fRmax = arg;
0143     calculateCached();
0144   }
0145   VECCORE_ATT_HOST_DEVICE
0146   void SetRTor(Precision arg)
0147   {
0148     fTorus.fRtor = arg;
0149     calculateCached();
0150   }
0151   VECCORE_ATT_HOST_DEVICE
0152   void SetSPhi(Precision arg)
0153   {
0154     fTorus.fSphi = arg;
0155     calculateCached();
0156   }
0157   VECCORE_ATT_HOST_DEVICE
0158   void SetDPhi(Precision arg)
0159   {
0160     fTorus.fDphi = arg;
0161     calculateCached();
0162   }
0163 
0164   // VECCORE_ATT_HOST_DEVICE
0165   Precision SurfaceArea() const override
0166   {
0167     Precision surfaceArea = fTorus.fDphi * kTwoPi * fTorus.fRtor * (fTorus.fRmax + fTorus.fRmin);
0168     if (fTorus.fDphi < kTwoPi) {
0169       surfaceArea = surfaceArea + kTwoPi * (fTorus.fRmax * fTorus.fRmax - fTorus.fRmin * fTorus.fRmin);
0170     }
0171     return surfaceArea;
0172   }
0173 
0174   Precision Capacity() const override { return volume(); }
0175 
0176   VECCORE_ATT_HOST_DEVICE
0177   bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &norm) const override;
0178 
0179   VECCORE_ATT_HOST_DEVICE
0180   VECGEOM_FORCE_INLINE
0181   GenericUnplacedTube const &GetBoundingTube() const { return fTorus.fBoundingTube; }
0182 
0183   VECCORE_ATT_HOST_DEVICE
0184   VECGEOM_FORCE_INLINE
0185   void Extent(Vector3D<Precision> &min, Vector3D<Precision> &max) const override { GetBoundingTube().Extent(min, max); }
0186 
0187   Vector3D<Precision> SamplePointOnSurface() const override;
0188 
0189   virtual int MemorySize() const override { return sizeof(*this); }
0190 
0191   VECCORE_ATT_HOST_DEVICE
0192   virtual void Print() const final;
0193 
0194   virtual void Print(std::ostream &os) const final;
0195 
0196   std::string GetEntityType() const { return "Torus"; }
0197 
0198 #ifndef VECCORE_CUDA
0199   virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0200 #endif
0201 
0202   VECCORE_ATT_DEVICE
0203   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0204 #ifdef VECCORE_CUDA
0205                                const int id, const int copy_no, const int child_id,
0206 #endif
0207                                VPlacedVolume *const placement = NULL);
0208 
0209 #ifdef VECGEOM_CUDA_INTERFACE
0210   virtual size_t DeviceSizeOf() const override { return DevicePtr<cuda::UnplacedTorus2>::SizeOf(); }
0211   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0212   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0213 #endif
0214 
0215 private:
0216 #ifndef VECCORE_CUDA
0217   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0218                                            Transformation3D const *const transformation,
0219                                            VPlacedVolume *const placement = NULL) const override;
0220 
0221 #else
0222   __device__ virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0223                                                       Transformation3D const *const transformation, const int id,
0224                                                       const int copy_no, const int child_id,
0225                                                       VPlacedVolume *const placement = NULL) const override;
0226 
0227 #endif
0228 };
0229 
0230 } // namespace VECGEOM_IMPL_NAMESPACE
0231 } // namespace vecgeom
0232 
0233 #endif // VECGEOM_VOLUMES_UNPLACEDTORUS2_H_