File indexing completed on 2025-01-18 10:14:16
0001
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
0022
0023 inline namespace VECGEOM_IMPL_NAMESPACE {
0024
0025
0026 class UnplacedTorus2 : public LoopUnplacedVolumeImplHelper<TorusImplementation2>, public AlignedBase {
0027 private:
0028
0029 TorusStruct2<Precision> fTorus;
0030 Wedge fPhiWedge;
0031
0032
0033 Precision fRmin2, fRmax2, fRtor2, fAlongPhi1x, fAlongPhi1y, fAlongPhi2x, fAlongPhi2y;
0034 Precision fTolIrmin2, fTolOrmin2, fTolIrmax2, fTolOrmax2;
0035
0036 GenericUnplacedTube fBoundingTube;
0037
0038 VECCORE_ATT_HOST_DEVICE
0039 static void GetAlongVectorToPhiSector(Precision phi, Precision &x, Precision &y)
0040 {
0041 x = std::cos(phi);
0042 y = std::sin(phi);
0043 }
0044
0045 VECCORE_ATT_HOST_DEVICE
0046 void calculateCached()
0047 {
0048 fRmin2 = fTorus.fRmin * fTorus.fRmin;
0049 fRmax2 = fTorus.fRmax * fTorus.fRmax;
0050 fRtor2 = fTorus.fRtor * fTorus.fRtor;
0051
0052 fTolOrmin2 = (fTorus.fRmin - kTolerance) * (fTorus.fRmin - kTolerance);
0053 fTolIrmin2 = (fTorus.fRmin + kTolerance) * (fTorus.fRmin + kTolerance);
0054
0055 fTolOrmax2 = (fTorus.fRmax + kTolerance) * (fTorus.fRmax + kTolerance);
0056 fTolIrmax2 = (fTorus.fRmax - kTolerance) * (fTorus.fRmax - kTolerance);
0057
0058 GetAlongVectorToPhiSector(fTorus.fSphi, fAlongPhi1x, fAlongPhi1y);
0059 GetAlongVectorToPhiSector(fTorus.fSphi + fTorus.fDphi, fAlongPhi2x, fAlongPhi2y);
0060 }
0061
0062 public:
0063 VECCORE_ATT_HOST_DEVICE
0064 UnplacedTorus2(Precision const &_rmin, Precision const &_rmax, Precision const &_rtor, Precision const &_sphi,
0065 Precision const &_dphi)
0066 : fTorus(_rmin, _rmax, _rtor, _sphi, _dphi), fPhiWedge(_dphi, _sphi), fBoundingTube(0, 1, 1, 0, _dphi)
0067 {
0068 calculateCached();
0069
0070 fBoundingTube = GenericUnplacedTube(fTorus.fRtor - fTorus.fRmax - kTolerance,
0071 fTorus.fRtor + fTorus.fRmax + kTolerance, fTorus.fRmax, _sphi, _dphi);
0072
0073 DetectConvexity();
0074 ComputeBBox();
0075 }
0076
0077 VECCORE_ATT_HOST_DEVICE
0078 TorusStruct2<Precision> const &GetStruct() const { return fTorus; }
0079
0080 VECCORE_ATT_HOST_DEVICE
0081 void DetectConvexity();
0082
0083 VECCORE_ATT_HOST_DEVICE
0084 VECGEOM_FORCE_INLINE
0085 Precision rmin() const { return fTorus.fRmin; }
0086
0087 VECCORE_ATT_HOST_DEVICE
0088 VECGEOM_FORCE_INLINE
0089 Precision rmax() const { return fTorus.fRmax; }
0090
0091 VECCORE_ATT_HOST_DEVICE
0092 VECGEOM_FORCE_INLINE
0093 Precision rtor() const { return fTorus.fRtor; }
0094
0095 VECCORE_ATT_HOST_DEVICE
0096 VECGEOM_FORCE_INLINE
0097 Precision sphi() const { return fTorus.fSphi; }
0098
0099 VECCORE_ATT_HOST_DEVICE
0100 VECGEOM_FORCE_INLINE
0101 Precision dphi() const { return fTorus.fDphi; }
0102
0103 VECCORE_ATT_HOST_DEVICE
0104 VECGEOM_FORCE_INLINE
0105 Precision rmin2() const { return fRmin2; }
0106
0107 VECCORE_ATT_HOST_DEVICE
0108 VECGEOM_FORCE_INLINE
0109 Precision rmax2() const { return fRmax2; }
0110
0111 VECCORE_ATT_HOST_DEVICE
0112 VECGEOM_FORCE_INLINE
0113 Precision rtor2() const { return fRtor2; }
0114
0115 VECCORE_ATT_HOST_DEVICE
0116 VECGEOM_FORCE_INLINE
0117 Wedge const &GetWedge() const { return fPhiWedge; }
0118
0119 VECCORE_ATT_HOST_DEVICE
0120 VECGEOM_FORCE_INLINE
0121 Precision alongPhi1x() const { return fAlongPhi1x; }
0122
0123 VECCORE_ATT_HOST_DEVICE
0124 VECGEOM_FORCE_INLINE
0125 Precision alongPhi1y() const { return fAlongPhi1y; }
0126
0127 VECCORE_ATT_HOST_DEVICE
0128 VECGEOM_FORCE_INLINE
0129 Precision alongPhi2x() const { return fAlongPhi2x; }
0130
0131 VECCORE_ATT_HOST_DEVICE
0132 VECGEOM_FORCE_INLINE
0133 Precision alongPhi2y() const { return fAlongPhi2y; }
0134
0135 VECCORE_ATT_HOST_DEVICE
0136 VECGEOM_FORCE_INLINE
0137 Precision tolOrmin2() const { return fTolOrmin2; }
0138
0139 VECCORE_ATT_HOST_DEVICE
0140 VECGEOM_FORCE_INLINE
0141 Precision tolIrmin2() const { return fTolIrmin2; }
0142
0143 VECCORE_ATT_HOST_DEVICE
0144 VECGEOM_FORCE_INLINE
0145 Precision tolOrmax2() const { return fTolOrmax2; }
0146
0147 VECCORE_ATT_HOST_DEVICE
0148 VECGEOM_FORCE_INLINE
0149 Precision tolIrmax2() const { return fTolIrmax2; }
0150
0151 VECCORE_ATT_HOST_DEVICE
0152 VECGEOM_FORCE_INLINE
0153 Precision volume() const
0154 {
0155 return fTorus.fDphi * kPi * fTorus.fRtor * (fTorus.fRmax * fTorus.fRmax - fTorus.fRmin * fTorus.fRmin);
0156 }
0157
0158 VECCORE_ATT_HOST_DEVICE
0159 void SetRMin(Precision arg)
0160 {
0161 fTorus.fRmin = arg;
0162 calculateCached();
0163 }
0164 VECCORE_ATT_HOST_DEVICE
0165 void SetRMax(Precision arg)
0166 {
0167 fTorus.fRmax = arg;
0168 calculateCached();
0169 }
0170 VECCORE_ATT_HOST_DEVICE
0171 void SetRTor(Precision arg)
0172 {
0173 fTorus.fRtor = arg;
0174 calculateCached();
0175 }
0176 VECCORE_ATT_HOST_DEVICE
0177 void SetSPhi(Precision arg)
0178 {
0179 fTorus.fSphi = arg;
0180 calculateCached();
0181 }
0182 VECCORE_ATT_HOST_DEVICE
0183 void SetDPhi(Precision arg)
0184 {
0185 fTorus.fDphi = arg;
0186 calculateCached();
0187 }
0188
0189
0190 Precision SurfaceArea() const override
0191 {
0192 Precision surfaceArea = fTorus.fDphi * kTwoPi * fTorus.fRtor * (fTorus.fRmax + fTorus.fRmin);
0193 if (fTorus.fDphi < kTwoPi) {
0194 surfaceArea = surfaceArea + kTwoPi * (fTorus.fRmax * fTorus.fRmax - fTorus.fRmin * fTorus.fRmin);
0195 }
0196 return surfaceArea;
0197 }
0198
0199 Precision Capacity() const override { return volume(); }
0200
0201 VECCORE_ATT_HOST_DEVICE
0202 bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &norm) const override;
0203
0204 VECCORE_ATT_HOST_DEVICE
0205 VECGEOM_FORCE_INLINE
0206 GenericUnplacedTube const &GetBoundingTube() const { return fBoundingTube; }
0207
0208 VECCORE_ATT_HOST_DEVICE
0209 VECGEOM_FORCE_INLINE
0210 void Extent(Vector3D<Precision> &min, Vector3D<Precision> &max) const override { GetBoundingTube().Extent(min, max); }
0211
0212 Vector3D<Precision> SamplePointOnSurface() const override;
0213
0214 virtual int MemorySize() const override { return sizeof(*this); }
0215
0216 VECCORE_ATT_HOST_DEVICE
0217 virtual void Print() const final;
0218
0219 virtual void Print(std::ostream &os) const final;
0220
0221 std::string GetEntityType() const { return "Torus"; }
0222
0223 #ifndef VECCORE_CUDA
0224 virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0225 #endif
0226
0227 template <TranslationCode transCodeT, RotationCode rotCodeT>
0228 VECCORE_ATT_DEVICE
0229 static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0230 #ifdef VECCORE_CUDA
0231 const int id, const int copy_no, const int child_id,
0232 #endif
0233 VPlacedVolume *const placement = NULL);
0234
0235 #ifdef VECGEOM_CUDA_INTERFACE
0236 virtual size_t DeviceSizeOf() const override { return DevicePtr<cuda::UnplacedTorus2>::SizeOf(); }
0237 virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0238 virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0239 #endif
0240
0241 private:
0242 #ifndef VECCORE_CUDA
0243 virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0244 Transformation3D const *const transformation,
0245 const TranslationCode trans_code, const RotationCode rot_code,
0246 VPlacedVolume *const placement = NULL) const override;
0247
0248 #else
0249 __device__ virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0250 Transformation3D const *const transformation,
0251 const TranslationCode trans_code, const RotationCode rot_code,
0252 const int id, const int copy_no, const int child_id,
0253 VPlacedVolume *const placement = NULL) const override;
0254
0255 #endif
0256 };
0257
0258 }
0259 }
0260
0261 #endif