Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:14:14

0001 /*
0002  * UnplacedCutTube.h
0003  *
0004  *  Created on: 03.11.2016
0005  *      Author: mgheata
0006  */
0007 
0008 #ifndef VECGEOM_VOLUMES_UNPLACEDCUTTUBE_H_
0009 #define VECGEOM_VOLUMES_UNPLACEDCUTTUBE_H_
0010 
0011 #include "VecGeom/base/Cuda.h"
0012 #include "VecGeom/base/Global.h"
0013 #include "VecGeom/base/AlignedBase.h"
0014 #include "VecGeom/volumes/UnplacedVolume.h"
0015 #include "VecGeom/volumes/CutTubeStruct.h"
0016 #include "VecGeom/volumes/kernel/CutTubeImplementation.h"
0017 #include "VecGeom/volumes/UnplacedVolumeImplHelper.h"
0018 
0019 namespace vecgeom {
0020 
0021 VECGEOM_DEVICE_FORWARD_DECLARE(class UnplacedCutTube;);
0022 VECGEOM_DEVICE_DECLARE_CONV(class, UnplacedCutTube);
0023 
0024 inline namespace VECGEOM_IMPL_NAMESPACE {
0025 
0026 class UnplacedCutTube : public SIMDUnplacedVolumeImplHelper<CutTubeImplementation>, public AlignedBase {
0027 
0028 private:
0029   CutTubeStruct<Precision> fCutTube; //> The cut tube data holder
0030 
0031 public:
0032   VECCORE_ATT_HOST_DEVICE
0033   UnplacedCutTube() : fCutTube() { ComputeBBox(); }
0034 
0035   VECCORE_ATT_HOST_DEVICE
0036   UnplacedCutTube(Precision const &rmin, Precision const &rmax, Precision const &z, Precision const &sphi,
0037                   Precision const &dphi, Vector3D<Precision> const &bottomNormal, Vector3D<Precision> const &topNormal)
0038       : fCutTube(rmin, rmax, z, sphi, dphi, bottomNormal, topNormal)
0039   {
0040     // Constructor
0041     if (bottomNormal.z() >= 0 || topNormal.z() <= 0) {
0042       Print();
0043 #ifndef VECCORE_CUDA
0044       throw std::runtime_error("Illegal normal direction for cut planes");
0045 #else
0046       printf("Illegal normal direction for cut planes");
0047 #endif
0048     }
0049     DetectConvexity();
0050     ComputeBBox();
0051   }
0052 
0053   VECCORE_ATT_HOST_DEVICE
0054   UnplacedCutTube(Precision const &rmin, Precision const &rmax, Precision const &z, Precision const &sphi,
0055                   Precision const &dphi, Precision const &bx, Precision const &by, Precision const &bz,
0056                   Precision const &tx, Precision const &ty, Precision const &tz)
0057       : fCutTube(rmin, rmax, z, sphi, dphi, Vector3D<Precision>(bx, by, bz), Vector3D<Precision>(tx, ty, tz))
0058   {
0059     // Constructor
0060     if (bz >= 0 || tz <= 0) {
0061       Print();
0062 #ifndef VECCORE_CUDA
0063       throw std::runtime_error("Illegal normal direction for cut planes");
0064 #else
0065       printf("Illegal normal direction for cut planes");
0066 #endif
0067     }
0068     DetectConvexity();
0069     ComputeBBox();
0070   }
0071 
0072   VECCORE_ATT_HOST_DEVICE
0073   virtual ~UnplacedCutTube() {}
0074 
0075   VECCORE_ATT_HOST_DEVICE
0076   VECGEOM_FORCE_INLINE
0077   TubeStruct<Precision> const &GetTubeStruct() const { return fCutTube.fTubeStruct; }
0078 
0079   VECCORE_ATT_HOST_DEVICE
0080   VECGEOM_FORCE_INLINE
0081   CutTubeStruct<Precision> const &GetStruct() const { return fCutTube; }
0082 
0083   VECCORE_ATT_HOST_DEVICE
0084   void DetectConvexity();
0085 
0086   VECCORE_ATT_HOST_DEVICE
0087   VECGEOM_FORCE_INLINE
0088   Precision rmin() const { return fCutTube.fTubeStruct.fRmin; }
0089 
0090   VECCORE_ATT_HOST_DEVICE
0091   VECGEOM_FORCE_INLINE
0092   Precision rmax() const { return fCutTube.fTubeStruct.fRmax; }
0093 
0094   VECCORE_ATT_HOST_DEVICE
0095   VECGEOM_FORCE_INLINE
0096   Precision z() const { return fCutTube.fDz; }
0097 
0098   VECCORE_ATT_HOST_DEVICE
0099   VECGEOM_FORCE_INLINE
0100   Precision sphi() const { return fCutTube.fTubeStruct.fSphi; }
0101 
0102   VECCORE_ATT_HOST_DEVICE
0103   VECGEOM_FORCE_INLINE
0104   Precision dphi() const { return fCutTube.fTubeStruct.fDphi; }
0105 
0106   VECGEOM_FORCE_INLINE
0107   void SetRMin(Precision const &_rmin) { fCutTube.fTubeStruct.SetRMin(_rmin); }
0108 
0109   VECGEOM_FORCE_INLINE
0110   void SetRMax(Precision const &_rmax) { fCutTube.fTubeStruct.SetRMax(_rmax); }
0111 
0112   VECGEOM_FORCE_INLINE
0113   void SetDz(Precision const &_z) { fCutTube.fTubeStruct.SetDz(_z); }
0114 
0115   VECGEOM_FORCE_INLINE
0116   void SetSPhi(Precision const &_sphi) { fCutTube.fTubeStruct.SetAndCheckSPhiAngle(_sphi); }
0117 
0118   VECGEOM_FORCE_INLINE
0119   void SetDPhi(Precision const &_dphi) { fCutTube.fTubeStruct.SetAndCheckDPhiAngle(_dphi); }
0120 
0121   VECCORE_ATT_HOST_DEVICE
0122   VECGEOM_FORCE_INLINE
0123   evolution::Wedge const &GetWedge() const { return fCutTube.fTubeStruct.fPhiWedge; }
0124 
0125   VECCORE_ATT_HOST_DEVICE
0126   VECGEOM_FORCE_INLINE
0127   Vector3D<Precision> BottomNormal() const { return fCutTube.fCutPlanes.GetNormal(0); }
0128 
0129   VECCORE_ATT_HOST_DEVICE
0130   VECGEOM_FORCE_INLINE
0131   Vector3D<Precision> TopNormal() const { return fCutTube.fCutPlanes.GetNormal(1); }
0132 
0133   VECCORE_ATT_HOST_DEVICE
0134   VECGEOM_FORCE_INLINE
0135   Precision ZlimitBottom(Precision rVal, Precision phiVal) const
0136   {
0137     return (-z() - (rVal / BottomNormal().z()) * (BottomNormal().x() * vecCore::math::Cos(phiVal) +
0138                                                   BottomNormal().y() * vecCore::math::Sin(phiVal)));
0139   }
0140 
0141   VECCORE_ATT_HOST_DEVICE
0142   VECGEOM_FORCE_INLINE
0143   Precision ZlimitTop(Precision rVal, Precision phiVal) const
0144   {
0145     return (z() - (rVal / TopNormal().z()) *
0146                       (TopNormal().x() * vecCore::math::Cos(phiVal) + TopNormal().y() * vecCore::math::Sin(phiVal)));
0147   }
0148 
0149   VECCORE_ATT_HOST_DEVICE
0150   VECGEOM_FORCE_INLINE
0151   Precision GetLateralArea(Precision rVal) const
0152   {
0153     return (2. * rVal * z() * dphi() -
0154             rVal * rVal *
0155                 (((TopNormal().x() / TopNormal().z() - BottomNormal().x() / BottomNormal().z()) *
0156                   (fCutTube.fSinPhi2 - fCutTube.fSinPhi1)) -
0157                  ((TopNormal().y() / TopNormal().z() - BottomNormal().y() / BottomNormal().z()) *
0158                   (fCutTube.fCosPhi2 - fCutTube.fCosPhi1))));
0159   }
0160 
0161   VECCORE_ATT_HOST_DEVICE
0162   VECGEOM_FORCE_INLINE
0163   Precision GetTopArea() const
0164   {
0165     return 0.5 * (fCutTube.fTubeStruct.fRmax2 - fCutTube.fTubeStruct.fRmin2) * dphi() / TopNormal().z();
0166   }
0167 
0168   VECCORE_ATT_HOST_DEVICE
0169   VECGEOM_FORCE_INLINE
0170   Precision GetBottomArea() const
0171   {
0172     return -0.5 * (fCutTube.fTubeStruct.fRmax2 - fCutTube.fTubeStruct.fRmin2) * dphi() / BottomNormal().z();
0173   }
0174 
0175   VECCORE_ATT_HOST_DEVICE
0176   VECGEOM_FORCE_INLINE
0177   Precision GetLateralPhi1Area() const
0178   {
0179     if (dphi() == kTwoPi) return 0.;
0180     return (0.5 * (rmax() - rmin()) *
0181             ((ZlimitTop(rmin(), sphi()) - ZlimitBottom(rmin(), sphi())) +
0182              (ZlimitTop(rmax(), sphi()) - ZlimitBottom(rmax(), sphi()))));
0183   }
0184 
0185   VECCORE_ATT_HOST_DEVICE
0186   VECGEOM_FORCE_INLINE
0187   Precision GetLateralPhi2Area() const
0188   {
0189     if (dphi() == kTwoPi) return 0.;
0190     return (0.5 * (rmax() - rmin()) *
0191             ((ZlimitTop(rmin(), sphi() + dphi()) - ZlimitBottom(rmin(), sphi() + dphi())) +
0192              (ZlimitTop(rmax(), sphi() + dphi()) - ZlimitBottom(rmax(), sphi() + dphi()))));
0193   }
0194 
0195   VECCORE_ATT_HOST_DEVICE
0196   void Extent(Vector3D<Precision> &aMin, Vector3D<Precision> &aMax) const override;
0197 
0198   Vector3D<Precision> SamplePointOnSurface() const override;
0199 
0200   Precision volume() const;
0201 
0202   Precision Capacity() const override { return volume(); }
0203 
0204   // VECCORE_ATT_HOST_DEVICE
0205   Precision SurfaceArea() const override
0206   {
0207     return (GetBottomArea() + GetTopArea() + GetLateralArea(rmin()) + GetLateralArea(rmax()) + GetLateralPhi1Area() +
0208             GetLateralPhi2Area());
0209   }
0210 
0211   VECCORE_ATT_HOST_DEVICE
0212   bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &normal) const override;
0213 
0214   VECCORE_ATT_HOST_DEVICE
0215   virtual void Print() const final;
0216   virtual void Print(std::ostream &os) const final;
0217 
0218   std::string GetEntityType() const { return "CutTube"; }
0219 
0220   virtual int MemorySize() const final { return sizeof(*this); }
0221 
0222 #ifndef VECCORE_CUDA
0223   virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0224 #endif
0225 
0226 #ifdef VECGEOM_CUDA_INTERFACE
0227   size_t DeviceSizeOf() const final { return DevicePtr<cuda::UnplacedCutTube>::SizeOf(); }
0228   DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const final;
0229   DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const final;
0230 #endif
0231 
0232   template <TranslationCode transCodeT, RotationCode rotCodeT>
0233   VECCORE_ATT_DEVICE
0234   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0235 #ifdef VECCORE_CUDA
0236                                const int id, const int copy_no, const int child_id,
0237 #endif
0238                                VPlacedVolume *const placement = NULL);
0239 
0240 private:
0241   VECCORE_ATT_DEVICE
0242   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0243                                            Transformation3D const *const transformation,
0244                                            const TranslationCode trans_code, const RotationCode rot_code,
0245 #ifdef VECCORE_CUDA
0246                                            const int id, const int copy_no, const int child_id,
0247 #endif
0248                                            VPlacedVolume *const placement = NULL) const final;
0249 };
0250 } // namespace VECGEOM_IMPL_NAMESPACE
0251 } // namespace vecgeom
0252 
0253 #endif // VECGEOM_VOLUMES_UNPLACEDCUTTUBE_H_