Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-08 09:27:58

0001 /// \file BVHSafetyEstimator.h
0002 /// \author Guilherme Amadio
0003 
0004 #ifndef VECGEOM_NAVIGATION_BVHSAFETYESTIMATOR_H_
0005 #define VECGEOM_NAVIGATION_BVHSAFETYESTIMATOR_H_
0006 
0007 #include "VecGeom/management/BVHManager.h"
0008 #include "VecGeom/navigation/VSafetyEstimator.h"
0009 
0010 namespace vecgeom {
0011 inline namespace VECGEOM_IMPL_NAMESPACE {
0012 
0013 /**
0014  * @brief Safety estimator class using the bounding volume hierarchy of each
0015  * logical volume for acceleration.
0016  */
0017 
0018 class BVHSafetyEstimator : public VSafetyEstimatorHelper<BVHSafetyEstimator> {
0019 private:
0020   /** Constructor. Private since this is a singleton class accessed only via the @c Instance() static method. */
0021   VECCORE_ATT_DEVICE
0022   BVHSafetyEstimator() : VSafetyEstimatorHelper<BVHSafetyEstimator>() {}
0023 
0024 public:
0025   static constexpr const char *gClassNameString = "BVHSafetyEstimator";
0026 
0027 #ifndef VECCORE_CUDA
0028   /** Return instance of this singleton class. */
0029   static VSafetyEstimator *Instance()
0030   {
0031     static BVHSafetyEstimator instance;
0032     return &instance;
0033   }
0034 #else
0035   // If used on device, this needs to be implemented in a .cu file rather than in this header
0036   // This hack is used also by NewSimpleNavigator, implemented in LogicalVolume.cpp
0037   // This is now implemented in BVHManager.cu
0038   VECCORE_ATT_DEVICE
0039   static VSafetyEstimator *Instance();
0040 #endif
0041 
0042   VECCORE_ATT_HOST_DEVICE
0043   static Precision CandidateSafetyToIn(int aItemIndex, int index, Vector3D<Precision> localpoint)
0044   {
0045 #ifdef VECCORE_CUDA_DEVICE_COMPILATION
0046     return vecgeom::globaldevicegeomdata::gDeviceLogicalVolumes[aItemIndex].GetDaughters()[index]->SafetyToIn(
0047         localpoint);
0048 #else
0049     return GeoManager::Instance().FindLogicalVolume(aItemIndex)->GetDaughters()[index]->SafetyToIn(localpoint);
0050 #endif
0051   };
0052 
0053   /**
0054    * Compute safety of a point given in the local coordinates of the placed volume @p pvol.
0055    * @param[in] localpoint Point in the local coordinates of the placed volume.
0056    * @param[in] pvol Placed volume.
0057    */
0058   VECCORE_ATT_HOST_DEVICE
0059   Precision ComputeSafetyForLocalPoint(Vector3D<Precision> const &localpoint, VPlacedVolume const *pvol) const final
0060   {
0061     Precision safety = pvol->SafetyToOut(localpoint);
0062 
0063     if (safety > 0.0 && pvol->GetDaughters().size() > 0)
0064       safety = BVHManager::GetBVH(pvol->GetLogicalVolume())->ComputeSafety<BVHSafetyEstimator>(localpoint, safety);
0065     return safety;
0066   }
0067 
0068   /**
0069    * Compute safety of a point given in the local coordinates of the logical volume @p lvol against
0070    * all its child volumes. Uses the bounding volume hierarchy associated with the logical volume
0071    * for acceleration.
0072    * @param[in] localpoint Point in the local coordinates of the placed volume.
0073    * @param[in] lvol Logical volume.
0074    */
0075   VECCORE_ATT_HOST_DEVICE
0076   Precision ComputeSafetyToDaughtersForLocalPoint(Vector3D<Precision> const &localpoint,
0077                                                   LogicalVolume const *lvol) const final
0078   {
0079     return BVHManager::GetBVH(lvol)->ComputeSafety<BVHSafetyEstimator>(localpoint, kInfLength);
0080   }
0081 };
0082 
0083 } // namespace VECGEOM_IMPL_NAMESPACE
0084 } // namespace vecgeom
0085 
0086 #endif