Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-25 08:38:08

0001 /// \file UnplacedSphere.h
0002 /// \author Raman Sehgal (raman.sehgal@cern.ch)
0003 
0004 #ifndef VECGEOM_VOLUMES_UNPLACEDSPHERE_H_
0005 #define VECGEOM_VOLUMES_UNPLACEDSPHERE_H_
0006 
0007 #include "VecGeom/base/Cuda.h"
0008 #include "VecGeom/base/Global.h"
0009 #include "VecGeom/base/AlignedBase.h"
0010 #include "VecGeom/volumes/UnplacedVolume.h"
0011 #include "VecGeom/volumes/SphereStruct.h"
0012 #include "VecGeom/volumes/kernel/SphereImplementation.h"
0013 #include "VecGeom/volumes/UnplacedVolumeImplHelper.h"
0014 
0015 namespace vecgeom {
0016 
0017 VECGEOM_DEVICE_FORWARD_DECLARE(class UnplacedSphere;);
0018 VECGEOM_DEVICE_DECLARE_CONV(class, UnplacedSphere);
0019 
0020 inline namespace VECGEOM_IMPL_NAMESPACE {
0021 
0022 class UnplacedSphere : public UnplacedVolumeImplHelper<SphereImplementation>, public AlignedBase {
0023 
0024 private:
0025   SphereStruct<Precision> fSphere;
0026 
0027 public:
0028   VECCORE_ATT_HOST_DEVICE
0029   VECGEOM_FORCE_INLINE
0030   virtual ESolidType GetType() const override { return ESolidType::sphere; }
0031 
0032   VECCORE_ATT_HOST_DEVICE
0033   SphereStruct<Precision> const &GetStruct() const { return fSphere; }
0034 
0035   VECCORE_ATT_HOST_DEVICE
0036   VECGEOM_FORCE_INLINE
0037   evolution::Wedge const &GetWedge() const { return fSphere.fPhiWedge; }
0038 
0039   VECCORE_ATT_HOST_DEVICE
0040   VECGEOM_FORCE_INLINE
0041   ThetaCone const &GetThetaCone() const { return fSphere.fThetaCone; }
0042 
0043   VECCORE_ATT_HOST_DEVICE
0044   UnplacedSphere(Precision pRmin, Precision pRmax, Precision pSPhi = 0., Precision pDPhi = kTwoPi,
0045                  Precision pSTheta = 0., Precision pDTheta = kPi);
0046 
0047   // specialized constructor for orb like instantiation
0048   VECCORE_ATT_HOST_DEVICE
0049   UnplacedSphere(Precision pR);
0050 
0051   VECCORE_ATT_HOST_DEVICE
0052   VECGEOM_FORCE_INLINE
0053   Precision GetInsideRadius() const { return fSphere.fRmin; }
0054 
0055   VECCORE_ATT_HOST_DEVICE
0056   VECGEOM_FORCE_INLINE
0057   Precision GetInnerRadius() const { return fSphere.fRmin; }
0058 
0059   VECCORE_ATT_HOST_DEVICE
0060   VECGEOM_FORCE_INLINE
0061   Precision GetOuterRadius() const { return fSphere.fRmax; }
0062 
0063   VECCORE_ATT_HOST_DEVICE
0064   VECGEOM_FORCE_INLINE
0065   Precision GetStartPhiAngle() const { return fSphere.fSPhi; }
0066 
0067   VECCORE_ATT_HOST_DEVICE
0068   VECGEOM_FORCE_INLINE
0069   Precision GetDeltaPhiAngle() const { return fSphere.fDPhi; }
0070 
0071   VECCORE_ATT_HOST_DEVICE
0072   VECGEOM_FORCE_INLINE
0073   Precision GetStartThetaAngle() const { return fSphere.fSTheta; }
0074 
0075   VECCORE_ATT_HOST_DEVICE
0076   VECGEOM_FORCE_INLINE
0077   Precision GetDeltaThetaAngle() const { return fSphere.fDTheta; }
0078 
0079   // Functions to get Tolerance
0080   VECCORE_ATT_HOST_DEVICE
0081   VECGEOM_FORCE_INLINE
0082   Precision GetFRminTolerance() const { return fSphere.fRminTolerance; }
0083 
0084   VECCORE_ATT_HOST_DEVICE
0085   VECGEOM_FORCE_INLINE
0086   Precision GetMKTolerance() const { return fSphere.mkTolerance; }
0087 
0088   VECCORE_ATT_HOST_DEVICE
0089   VECGEOM_FORCE_INLINE
0090   Precision GetAngTolerance() const { return fSphere.kAngTolerance; }
0091 
0092   VECCORE_ATT_HOST_DEVICE
0093   VECGEOM_FORCE_INLINE
0094   bool IsFullSphere() const { return fSphere.fFullSphere; }
0095 
0096   VECCORE_ATT_HOST_DEVICE
0097   VECGEOM_FORCE_INLINE
0098   bool IsFullPhiSphere() const { return fSphere.fFullPhiSphere; }
0099 
0100   VECCORE_ATT_HOST_DEVICE
0101   VECGEOM_FORCE_INLINE
0102   bool IsFullThetaSphere() const { return fSphere.fFullThetaSphere; }
0103 
0104   // All angle related functions
0105   VECCORE_ATT_HOST_DEVICE
0106   VECGEOM_FORCE_INLINE
0107   Precision GetHDPhi() const { return fSphere.hDPhi; }
0108 
0109   VECCORE_ATT_HOST_DEVICE
0110   VECGEOM_FORCE_INLINE
0111   Precision GetCPhi() const { return fSphere.cPhi; }
0112 
0113   VECCORE_ATT_HOST_DEVICE
0114   VECGEOM_FORCE_INLINE
0115   Precision GetEPhi() const { return fSphere.ePhi; }
0116 
0117   VECCORE_ATT_HOST_DEVICE
0118   VECGEOM_FORCE_INLINE
0119   Precision GetSinCPhi() const { return fSphere.sinCPhi; }
0120 
0121   VECCORE_ATT_HOST_DEVICE
0122   VECGEOM_FORCE_INLINE
0123   Precision GetCosCPhi() const { return fSphere.cosCPhi; }
0124 
0125   VECCORE_ATT_HOST_DEVICE
0126   VECGEOM_FORCE_INLINE
0127   Precision GetSinSPhi() const { return fSphere.sinSPhi; }
0128 
0129   VECCORE_ATT_HOST_DEVICE
0130   VECGEOM_FORCE_INLINE
0131   Precision GetCosSPhi() const { return fSphere.cosSPhi; }
0132 
0133   VECCORE_ATT_HOST_DEVICE
0134   VECGEOM_FORCE_INLINE
0135   Precision GetSinEPhi() const { return fSphere.sinEPhi; }
0136 
0137   VECCORE_ATT_HOST_DEVICE
0138   VECGEOM_FORCE_INLINE
0139   Precision GetCosEPhi() const { return fSphere.cosEPhi; }
0140 
0141   VECCORE_ATT_HOST_DEVICE
0142   VECGEOM_FORCE_INLINE
0143   Precision GetETheta() const { return fSphere.eTheta; }
0144 
0145   VECCORE_ATT_HOST_DEVICE
0146   VECGEOM_FORCE_INLINE
0147   Precision GetSinSTheta() const { return fSphere.sinSTheta; }
0148 
0149   VECCORE_ATT_HOST_DEVICE
0150   VECGEOM_FORCE_INLINE
0151   Precision GetCosSTheta() const { return fSphere.cosSTheta; }
0152 
0153   VECCORE_ATT_HOST_DEVICE
0154   VECGEOM_FORCE_INLINE
0155   Precision GetTanSTheta() const { return fSphere.tanSTheta; }
0156 
0157   VECCORE_ATT_HOST_DEVICE
0158   VECGEOM_FORCE_INLINE
0159   Precision GetTanETheta() const { return fSphere.tanETheta; }
0160 
0161   VECCORE_ATT_HOST_DEVICE
0162   VECGEOM_FORCE_INLINE
0163   Precision GetFabsTanSTheta() const { return fSphere.fabsTanSTheta; }
0164 
0165   VECCORE_ATT_HOST_DEVICE
0166   VECGEOM_FORCE_INLINE
0167   Precision GetFabsTanETheta() const { return fSphere.fabsTanETheta; }
0168 
0169   VECCORE_ATT_HOST_DEVICE
0170   VECGEOM_FORCE_INLINE
0171   Precision GetTanSTheta2() const { return fSphere.tanSTheta2; }
0172 
0173   VECCORE_ATT_HOST_DEVICE
0174   VECGEOM_FORCE_INLINE
0175   Precision GetTanETheta2() const { return fSphere.tanETheta2; }
0176 
0177   VECCORE_ATT_HOST_DEVICE
0178   VECGEOM_FORCE_INLINE
0179   Precision GetSinETheta() const { return fSphere.sinETheta; }
0180 
0181   VECCORE_ATT_HOST_DEVICE
0182   VECGEOM_FORCE_INLINE
0183   Precision GetCosETheta() const { return fSphere.cosETheta; }
0184 
0185   VECCORE_ATT_HOST_DEVICE
0186   VECGEOM_FORCE_INLINE
0187   Precision GetCosHDPhiOT() const { return fSphere.cosHDPhiOT; }
0188 
0189   VECCORE_ATT_HOST_DEVICE
0190   VECGEOM_FORCE_INLINE
0191   Precision GetCosHDPhiIT() const { return fSphere.cosHDPhiIT; }
0192 
0193   VECCORE_ATT_HOST_DEVICE
0194   VECGEOM_FORCE_INLINE
0195   void SetInsideRadius(Precision newRmin) { fSphere.SetInsideRadius(newRmin); }
0196 
0197   VECCORE_ATT_HOST_DEVICE
0198   VECGEOM_FORCE_INLINE
0199   void SetInnerRadius(Precision newRmin) { SetInsideRadius(newRmin); }
0200 
0201   VECCORE_ATT_HOST_DEVICE
0202   VECGEOM_FORCE_INLINE
0203   void SetOuterRadius(Precision newRmax) { fSphere.SetOuterRadius(newRmax); }
0204 
0205   VECCORE_ATT_HOST_DEVICE
0206   VECGEOM_FORCE_INLINE
0207   void SetStartPhiAngle(Precision newSPhi, bool compute = true) { fSphere.SetStartPhiAngle(newSPhi, compute); }
0208 
0209   VECCORE_ATT_HOST_DEVICE
0210   VECGEOM_FORCE_INLINE
0211   void SetDeltaPhiAngle(Precision newDPhi) { fSphere.SetDeltaPhiAngle(newDPhi); }
0212 
0213   VECCORE_ATT_HOST_DEVICE
0214   VECGEOM_FORCE_INLINE
0215   void SetStartThetaAngle(Precision newSTheta) { fSphere.SetStartThetaAngle(newSTheta); }
0216 
0217   VECCORE_ATT_HOST_DEVICE
0218   VECGEOM_FORCE_INLINE
0219   void SetDeltaThetaAngle(Precision newDTheta) { fSphere.SetDeltaThetaAngle(newDTheta); }
0220 
0221   // Old access functions
0222   VECCORE_ATT_HOST_DEVICE
0223   VECGEOM_FORCE_INLINE
0224   Precision GetRmin() const { return fSphere.fRmin; }
0225 
0226   VECCORE_ATT_HOST_DEVICE
0227   VECGEOM_FORCE_INLINE
0228   Precision GetRmax() const { return fSphere.fRmax; }
0229 
0230   VECCORE_ATT_HOST_DEVICE
0231   VECGEOM_FORCE_INLINE
0232   Precision GetSPhi() const { return fSphere.fSPhi; }
0233 
0234   VECCORE_ATT_HOST_DEVICE
0235   VECGEOM_FORCE_INLINE
0236   Precision GetDPhi() const { return fSphere.fDPhi; }
0237 
0238   VECCORE_ATT_HOST_DEVICE
0239   VECGEOM_FORCE_INLINE
0240   Precision GetSTheta() const { return fSphere.fSTheta; }
0241 
0242   VECCORE_ATT_HOST_DEVICE
0243   VECGEOM_FORCE_INLINE
0244   Precision GetDTheta() const { return fSphere.fDTheta; }
0245 
0246   VECCORE_ATT_HOST_DEVICE
0247   void CalcCapacity();
0248 
0249   VECCORE_ATT_HOST_DEVICE
0250   void CalcSurfaceArea();
0251 
0252   VECCORE_ATT_HOST_DEVICE
0253   void DetectConvexity();
0254 
0255   Precision Capacity() const override { return fSphere.fCubicVolume; }
0256 
0257   // VECCORE_ATT_HOST_DEVICE
0258   Precision SurfaceArea() const override { return fSphere.fSurfaceArea; }
0259 
0260   VECCORE_ATT_HOST_DEVICE
0261   void Extent(Vector3D<Precision> &, Vector3D<Precision> &) const override;
0262 
0263   VECCORE_ATT_HOST_DEVICE
0264   bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &normal) const override
0265   {
0266     bool valid;
0267     normal = SphereImplementation::Normal<Precision>(fSphere, point, valid);
0268     return valid;
0269   }
0270 
0271 #ifndef VECCORE_CUDA
0272 
0273   Vector3D<Precision> SamplePointOnSurface() const override;
0274 
0275   std::string GetEntityType() const;
0276 
0277 #ifdef VECGEOM_ROOT
0278   TGeoShape const *ConvertToRoot(char const *label = "") const;
0279 #endif
0280 #ifdef VECGEOM_GEANT4
0281   G4VSolid const *ConvertToGeant4(char const *label = "") const;
0282 #endif
0283 #endif // VECCORE_CUDA
0284 
0285   void GetParametersList(int aNumber, Precision *aArray) const;
0286 
0287   std::ostream &StreamInfo(std::ostream &os) const;
0288 
0289   // VECCORE_ATT_HOST_DEVICE
0290   // Precision sqr(Precision x) {return x*x;};
0291 
0292 public:
0293   virtual int MemorySize() const final { return sizeof(*this); }
0294 
0295   VECCORE_ATT_HOST_DEVICE
0296   virtual void Print() const final;
0297 
0298   // VECCORE_ATT_HOST_DEVICE
0299   virtual void Print(std::ostream &os) const final;
0300 
0301 #ifndef VECCORE_CUDA
0302   virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0303 #endif
0304 
0305 #ifndef VECCORE_CUDA
0306 
0307   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0308                                VPlacedVolume *const placement = NULL);
0309 
0310   static VPlacedVolume *CreateSpecializedVolume(LogicalVolume const *const volume,
0311                                                 Transformation3D const *const transformation,
0312                                                 VPlacedVolume *const placement = NULL);
0313 
0314 #else
0315 
0316   VECCORE_ATT_DEVICE
0317   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0318                                const int id, const int copy_no, const int child_id,
0319                                VPlacedVolume *const placement = NULL);
0320 
0321   VECCORE_ATT_DEVICE static VPlacedVolume *CreateSpecializedVolume(LogicalVolume const *const volume,
0322                                                                    Transformation3D const *const transformation,
0323                                                                    const int id, const int copy_no, const int child_id,
0324                                                                    VPlacedVolume *const placement = NULL);
0325 
0326 #endif
0327 
0328 #ifdef VECGEOM_CUDA_INTERFACE
0329   virtual size_t DeviceSizeOf() const override { return DevicePtr<cuda::UnplacedSphere>::SizeOf(); }
0330   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0331   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0332 #endif
0333 
0334 private:
0335 #ifndef VECCORE_CUDA
0336 
0337   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0338                                            Transformation3D const *const transformation,
0339                                            VPlacedVolume *const placement = NULL) const override
0340   {
0341     return CreateSpecializedVolume(volume, transformation, placement);
0342   }
0343 
0344 #else
0345 
0346   VECCORE_ATT_DEVICE virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0347                                                               Transformation3D const *const transformation,
0348                                                               const int id, const int copy_no, const int child_id,
0349                                                               VPlacedVolume *const placement = NULL) const override
0350   {
0351     return CreateSpecializedVolume(volume, transformation, id, copy_no, child_id, placement);
0352   }
0353 
0354 #endif
0355 };
0356 
0357 template <>
0358 struct Maker<UnplacedSphere> {
0359   template <typename... ArgTypes>
0360   static UnplacedSphere *MakeInstance(Precision pRmin, Precision pRmax, Precision pSPhi, Precision pDPhi,
0361                                       Precision pSTheta, Precision pDTheta);
0362 };
0363 } // namespace VECGEOM_IMPL_NAMESPACE
0364 } // namespace vecgeom
0365 
0366 #endif // VECGEOM_VOLUMES_UNPLACEDSPHERE_H_