Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-28 09:32:45

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 // Introduce Intermediate class ( so that we can do typecasting )
0022 class UnplacedTube : public VUnplacedVolume {
0023 private:
0024   // tube defining parameters
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   VECGEOM_FORCE_INLINE
0039   virtual ESolidType GetType() const override { return ESolidType::tube; }
0040 
0041   VECCORE_ATT_HOST_DEVICE
0042   TubeStruct<Precision> const &GetStruct() const { return fTube; }
0043 
0044   VECCORE_ATT_HOST_DEVICE
0045   void DetectConvexity();
0046 
0047   VECCORE_ATT_HOST_DEVICE
0048   VECGEOM_FORCE_INLINE
0049   Precision rmin() const { return fTube.fRmin; }
0050 
0051   VECCORE_ATT_HOST_DEVICE
0052   VECGEOM_FORCE_INLINE
0053   Precision rmax() const { return fTube.fRmax; }
0054 
0055   VECCORE_ATT_HOST_DEVICE
0056   VECGEOM_FORCE_INLINE
0057   Precision z() const { return fTube.fZ; }
0058 
0059   VECCORE_ATT_HOST_DEVICE
0060   VECGEOM_FORCE_INLINE
0061   Precision sphi() const { return fTube.fSphi; }
0062 
0063   VECCORE_ATT_HOST_DEVICE
0064   VECGEOM_FORCE_INLINE
0065   Precision dphi() const { return fTube.fDphi; }
0066 
0067   VECGEOM_FORCE_INLINE
0068   void SetRMin(Precision const &_rmin) { fTube.SetRMin(_rmin); }
0069 
0070   VECGEOM_FORCE_INLINE
0071   void SetRMax(Precision const &_rmax) { fTube.SetRMax(_rmax); }
0072 
0073   VECGEOM_FORCE_INLINE
0074   void SetDz(Precision const &_z) { fTube.SetDz(_z); }
0075 
0076   VECGEOM_FORCE_INLINE
0077   void SetSPhi(Precision const &_sphi) { fTube.SetAndCheckSPhiAngle(_sphi); /*weird name*/ }
0078 
0079   VECGEOM_FORCE_INLINE
0080   void SetDPhi(Precision const &_dphi) { fTube.SetAndCheckDPhiAngle(_dphi); /*weird name*/ }
0081 
0082   VECCORE_ATT_HOST_DEVICE
0083   VECGEOM_FORCE_INLINE
0084   evolution::Wedge const &GetWedge() const { return fTube.fPhiWedge; }
0085 
0086   VECCORE_ATT_HOST_DEVICE
0087   VECGEOM_FORCE_INLINE
0088   Precision volume() const { return fTube.fZ * (fTube.fRmax2 - fTube.fRmin2) * fTube.fDphi; }
0089 
0090   VECCORE_ATT_HOST_DEVICE
0091   void Extent(Vector3D<Precision> &aMin, Vector3D<Precision> &aMax) const override;
0092 
0093   Vector3D<Precision> SamplePointOnSurface() const override;
0094 
0095   // VECCORE_ATT_HOST_DEVICE
0096   Precision Capacity() const override { return volume(); }
0097 
0098   // VECCORE_ATT_HOST_DEVICE
0099   Precision SurfaceArea() const override
0100   {
0101     return GetTopArea() + GetLateralPhiArea() + GetLateralROutArea() + GetLateralRInArea();
0102   }
0103 
0104   // VECCORE_ATT_HOST_DEVICE
0105   Precision GetTopArea() const
0106   { // Abhijit:: this is top and bottom circular area of tube
0107     return 2 * 0.5 * (fTube.fRmax2 - fTube.fRmin2) * fTube.fDphi;
0108   }
0109 
0110   // VECCORE_ATT_HOST_DEVICE
0111   Precision GetLateralPhiArea() const
0112   { // Abhijit:: this is vertical Phi_start and phi_end opening
0113     // factor of 2 since fZ is half length
0114     return (fTube.fDphi < kTwoPi) ? 4. * fTube.fZ * (fTube.fRmax - fTube.fRmin) : 0.;
0115   }
0116 
0117   // VECCORE_ATT_HOST_DEVICE
0118   Precision GetLateralRInArea() const
0119   { // Abhijit:: this is Inner surface of tube along Z
0120     // factor of 2 since fZ is half length
0121     return 2. * fTube.fZ * fTube.fRmin * fTube.fDphi;
0122   }
0123 
0124   // VECCORE_ATT_HOST_DEVICE
0125   Precision GetLateralROutArea() const
0126   { // Abhijit:: this is Outer surface of tube along Z
0127     // factor of 2 since fZ is half length
0128     return 2. * fTube.fZ * fTube.fRmax * fTube.fDphi;
0129   }
0130 
0131   //  This computes where the random point would be placed
0132   // 1::rTop, 2::rBot, 3::phiLeft, 4::phiRight, 5::zIn, 6::zOut
0133   // VECCORE_ATT_HOST_DEVICE
0134   int ChooseSurface() const;
0135 
0136   VECCORE_ATT_HOST_DEVICE
0137   bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &normal) const override;
0138 
0139   VECCORE_ATT_HOST_DEVICE
0140   virtual void Print() const override;
0141 
0142   virtual void Print(std::ostream &os) const override;
0143 
0144 #ifndef VECCORE_CUDA
0145   virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0146 #endif
0147 
0148   std::string GetEntityType() const { return "Tube"; }
0149 
0150 #ifdef VECGEOM_CUDA_INTERFACE
0151   virtual size_t DeviceSizeOf() const override
0152   {
0153     return DevicePtr<cuda::SUnplacedTube<cuda::TubeTypes::UniversalTube>>::SizeOf();
0154   }
0155   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0156   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0157 #endif
0158 };
0159 
0160 template <>
0161 struct Maker<UnplacedTube> {
0162   template <typename... ArgTypes>
0163   static UnplacedTube *MakeInstance(Precision const &_rmin, Precision const &_rmax, Precision const &_z,
0164                                     Precision const &_sphi, Precision const &_dphi);
0165 };
0166 
0167 // this class finishes the implementation
0168 
0169 template <typename TubeType = TubeTypes::UniversalTube>
0170 class SUnplacedTube : public UnplacedVolumeImplHelper<TubeImplementation<TubeType>, UnplacedTube>, public AlignedBase {
0171 public:
0172   using Kernel     = TubeImplementation<TubeType>;
0173   using BaseType_t = UnplacedVolumeImplHelper<TubeImplementation<TubeType>, UnplacedTube>;
0174   using BaseType_t::BaseType_t;
0175 
0176   VECCORE_ATT_DEVICE
0177   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0178 #ifdef VECCORE_CUDA
0179                                const int id, const int copy_no, const int child_id,
0180 #endif
0181                                VPlacedVolume *const placement = NULL);
0182 
0183 #ifndef VECCORE_CUDA
0184   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0185                                            Transformation3D const *const transformation,
0186                                            VPlacedVolume *const placement = NULL) const override
0187   {
0188     return VolumeFactory::CreateByTransformation<SUnplacedTube<TubeType>>(volume, transformation, placement);
0189   }
0190 
0191 #else
0192   VECCORE_ATT_DEVICE
0193   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0194                                            Transformation3D const *const transformation, const int id,
0195                                            const int copy_no, const int child_id,
0196                                            VPlacedVolume *const placement = NULL) const override
0197   {
0198     return VolumeFactory::CreateByTransformation<SUnplacedTube<TubeType>>(volume, transformation, id, copy_no, child_id,
0199                                                                           placement);
0200   }
0201 #endif
0202 };
0203 
0204 using GenericUnplacedTube = SUnplacedTube<TubeTypes::UniversalTube>;
0205 
0206 } // namespace VECGEOM_IMPL_NAMESPACE
0207 } // namespace vecgeom
0208 
0209 // we include this header here because SpecializedTube
0210 // implements the Create function of SUnplacedTube<> (and to avoid a circular dependency)
0211 #include "VecGeom/volumes/SpecializedTube.h"
0212 
0213 #endif // VECGEOM_VOLUMES_UNPLACEDTUBE_H_