Back to home page

EIC code displayed by LXR

 
 

    


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

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