File indexing completed on 2025-01-30 10:26:27
0001 #ifndef VECGEOM_VOLUMES_UNPLACEDTUBE_H_
0002 #define VECGEOM_VOLUMES_UNPLACEDTUBE_H_
0003
0004 #include "VecGeom/base/Cuda.h"
0005 #include "VecGeom/base/Global.h"
0006 #include "VecGeom/base/AlignedBase.h"
0007 #include "VecGeom/volumes/UnplacedVolume.h"
0008 #include "VecGeom/volumes/TubeStruct.h"
0009 #include "VecGeom/volumes/kernel/TubeImplementation.h"
0010 #include "VecGeom/volumes/Wedge.h"
0011 #include "VecGeom/volumes/UnplacedVolumeImplHelper.h"
0012
0013 namespace vecgeom {
0014
0015 VECGEOM_DEVICE_FORWARD_DECLARE(class UnplacedTube;);
0016 VECGEOM_DEVICE_DECLARE_CONV(class, UnplacedTube);
0017 VECGEOM_DEVICE_DECLARE_CONV_TEMPLATE(class, SUnplacedTube, typename);
0018
0019 inline namespace VECGEOM_IMPL_NAMESPACE {
0020
0021
0022 class UnplacedTube : public VUnplacedVolume {
0023 private:
0024
0025 TubeStruct<Precision> fTube;
0026
0027 public:
0028 VECCORE_ATT_HOST_DEVICE
0029 UnplacedTube(Precision const &_rmin, Precision const &_rmax, Precision const &_z, Precision const &_sphi,
0030 Precision const &_dphi)
0031 : fTube(_rmin, _rmax, _z, _sphi, _dphi)
0032 {
0033 DetectConvexity();
0034 ComputeBBox();
0035 }
0036
0037 VECCORE_ATT_HOST_DEVICE
0038 TubeStruct<Precision> const &GetStruct() const { return fTube; }
0039
0040 VECCORE_ATT_HOST_DEVICE
0041 void DetectConvexity();
0042
0043 VECCORE_ATT_HOST_DEVICE
0044 VECGEOM_FORCE_INLINE
0045 Precision rmin() const { return fTube.fRmin; }
0046
0047 VECCORE_ATT_HOST_DEVICE
0048 VECGEOM_FORCE_INLINE
0049 Precision rmax() const { return fTube.fRmax; }
0050
0051 VECCORE_ATT_HOST_DEVICE
0052 VECGEOM_FORCE_INLINE
0053 Precision z() const { return fTube.fZ; }
0054
0055 VECCORE_ATT_HOST_DEVICE
0056 VECGEOM_FORCE_INLINE
0057 Precision sphi() const { return fTube.fSphi; }
0058
0059 VECCORE_ATT_HOST_DEVICE
0060 VECGEOM_FORCE_INLINE
0061 Precision dphi() const { return fTube.fDphi; }
0062
0063 VECGEOM_FORCE_INLINE
0064 void SetRMin(Precision const &_rmin) { fTube.SetRMin(_rmin); }
0065
0066 VECGEOM_FORCE_INLINE
0067 void SetRMax(Precision const &_rmax) { fTube.SetRMax(_rmax); }
0068
0069 VECGEOM_FORCE_INLINE
0070 void SetDz(Precision const &_z) { fTube.SetDz(_z); }
0071
0072 VECGEOM_FORCE_INLINE
0073 void SetSPhi(Precision const &_sphi) { fTube.SetAndCheckSPhiAngle(_sphi); }
0074
0075 VECGEOM_FORCE_INLINE
0076 void SetDPhi(Precision const &_dphi) { fTube.SetAndCheckDPhiAngle(_dphi); }
0077
0078 VECCORE_ATT_HOST_DEVICE
0079 VECGEOM_FORCE_INLINE
0080 evolution::Wedge const &GetWedge() const { return fTube.fPhiWedge; }
0081
0082 VECCORE_ATT_HOST_DEVICE
0083 VECGEOM_FORCE_INLINE
0084 Precision volume() const { return fTube.fZ * (fTube.fRmax2 - fTube.fRmin2) * fTube.fDphi; }
0085
0086 VECCORE_ATT_HOST_DEVICE
0087 void Extent(Vector3D<Precision> &aMin, Vector3D<Precision> &aMax) const override;
0088
0089 Vector3D<Precision> SamplePointOnSurface() const override;
0090
0091
0092 Precision Capacity() const override { return volume(); }
0093
0094
0095 Precision SurfaceArea() const override
0096 {
0097 return GetTopArea() + GetLateralPhiArea() + GetLateralROutArea() + GetLateralRInArea();
0098 }
0099
0100
0101 Precision GetTopArea() const
0102 {
0103 return 2 * 0.5 * (fTube.fRmax2 - fTube.fRmin2) * fTube.fDphi;
0104 }
0105
0106
0107 Precision GetLateralPhiArea() const
0108 {
0109
0110 return (fTube.fDphi < kTwoPi) ? 4. * fTube.fZ * (fTube.fRmax - fTube.fRmin) : 0.;
0111 }
0112
0113
0114 Precision GetLateralRInArea() const
0115 {
0116
0117 return 2. * fTube.fZ * fTube.fRmin * fTube.fDphi;
0118 }
0119
0120
0121 Precision GetLateralROutArea() const
0122 {
0123
0124 return 2. * fTube.fZ * fTube.fRmax * fTube.fDphi;
0125 }
0126
0127
0128
0129
0130 int ChooseSurface() const;
0131
0132 VECCORE_ATT_HOST_DEVICE
0133 bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &normal) const override;
0134
0135 VECCORE_ATT_HOST_DEVICE
0136 virtual void Print() const override;
0137
0138 virtual void Print(std::ostream &os) const override;
0139
0140 #ifndef VECCORE_CUDA
0141 virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0142 #endif
0143
0144 std::string GetEntityType() const { return "Tube"; }
0145
0146 #ifdef VECGEOM_CUDA_INTERFACE
0147 virtual size_t DeviceSizeOf() const override
0148 {
0149 return DevicePtr<cuda::SUnplacedTube<cuda::TubeTypes::UniversalTube>>::SizeOf();
0150 }
0151 virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0152 virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0153 #endif
0154 };
0155
0156 template <>
0157 struct Maker<UnplacedTube> {
0158 template <typename... ArgTypes>
0159 static UnplacedTube *MakeInstance(Precision const &_rmin, Precision const &_rmax, Precision const &_z,
0160 Precision const &_sphi, Precision const &_dphi);
0161 };
0162
0163
0164
0165 template <typename TubeType = TubeTypes::UniversalTube>
0166 class SUnplacedTube : public SIMDUnplacedVolumeImplHelper<TubeImplementation<TubeType>, UnplacedTube>,
0167 public AlignedBase {
0168 public:
0169 using Kernel = TubeImplementation<TubeType>;
0170 using BaseType_t = SIMDUnplacedVolumeImplHelper<TubeImplementation<TubeType>, UnplacedTube>;
0171 using BaseType_t::BaseType_t;
0172
0173 template <TranslationCode transCodeT, RotationCode rotCodeT>
0174 VECCORE_ATT_DEVICE
0175 static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0176 #ifdef VECCORE_CUDA
0177 const int id, const int copy_no, const int child_id,
0178 #endif
0179 VPlacedVolume *const placement = NULL);
0180
0181 #ifndef VECCORE_CUDA
0182 virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0183 Transformation3D const *const transformation,
0184 const TranslationCode trans_code, const RotationCode rot_code,
0185 VPlacedVolume *const placement = NULL) const override
0186 {
0187 return VolumeFactory::CreateByTransformation<SUnplacedTube<TubeType>>(volume, transformation, trans_code, rot_code,
0188 placement);
0189 }
0190
0191 #else
0192 VECCORE_ATT_DEVICE
0193 virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0194 Transformation3D const *const transformation,
0195 const TranslationCode trans_code, const RotationCode rot_code, const int id,
0196 const int copy_no, const int child_id,
0197 VPlacedVolume *const placement = NULL) const override
0198 {
0199 return VolumeFactory::CreateByTransformation<SUnplacedTube<TubeType>>(volume, transformation, trans_code, rot_code,
0200 id, copy_no, child_id, placement);
0201 }
0202 #endif
0203 };
0204
0205 using GenericUnplacedTube = SUnplacedTube<TubeTypes::UniversalTube>;
0206
0207 }
0208 }
0209
0210
0211
0212 #include "VecGeom/volumes/SpecializedTube.h"
0213
0214 #endif