Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-26 09:15:39

0001 /*
0002  * VSimpleSafetyEstimator.h
0003  *
0004  *  Created on: 28.08.2015
0005  *      Author: swenzel
0006  */
0007 
0008 #ifndef NAVIGATION_SIMPLESAFETYESTIMATOR_H_
0009 #define NAVIGATION_SIMPLESAFETYESTIMATOR_H_
0010 
0011 #include "VecGeom/navigation/VSafetyEstimator.h"
0012 //#include "VecGeom/base/Array.h"
0013 
0014 namespace vecgeom {
0015 inline namespace VECGEOM_IMPL_NAMESPACE {
0016 
0017 //! a simple safety estimator based on a brute force (O(N)) approach
0018 class SimpleSafetyEstimator : public VSafetyEstimatorHelper<SimpleSafetyEstimator> {
0019 
0020 public:
0021   static constexpr const char *gClassNameString = "SimpleSafetyEstimator";
0022 
0023   // estimate just the safety to daughters for a local point with respect to a logical volume
0024   // TODO: use this function in other interfaces to avoid code duplication
0025   VECCORE_ATT_HOST_DEVICE
0026   virtual Precision ComputeSafetyToDaughtersForLocalPoint(Vector3D<Precision> const &localpoint,
0027                                                           LogicalVolume const *lvol) const override
0028   {
0029     // safety to daughters
0030     double safety(kInfLength);
0031     auto daughters       = lvol->GetDaughtersp();
0032     auto numberdaughters = daughters->size();
0033     for (decltype(numberdaughters) d = 0; d < numberdaughters; ++d) {
0034       VPlacedVolume const *daughter = daughters->operator[](d);
0035       double tmp                    = daughter->SafetyToIn(localpoint);
0036       safety                        = Min(safety, tmp);
0037     }
0038     return safety;
0039   }
0040 
0041   VECGEOM_FORCE_INLINE
0042   VECCORE_ATT_HOST_DEVICE
0043   virtual Precision ComputeSafetyForLocalPoint(Vector3D<Precision> const &localpoint,
0044                                                VPlacedVolume const *pvol) const override
0045   {
0046     // safety to mother
0047     double safety = pvol->SafetyToOut(localpoint);
0048 
0049     // safety to daughters
0050     auto daughters       = pvol->GetLogicalVolume()->GetDaughtersp();
0051     auto numberdaughters = daughters->size();
0052     for (decltype(numberdaughters) d = 0; d < numberdaughters; ++d) {
0053       VPlacedVolume const *daughter = daughters->operator[](d);
0054       double tmp                    = daughter->SafetyToIn(localpoint);
0055       safety                        = Min(safety, tmp);
0056     }
0057     return safety;
0058   }
0059 
0060 #ifndef VECCORE_CUDA
0061   static VSafetyEstimator *Instance()
0062   {
0063     static SimpleSafetyEstimator instance;
0064     return &instance;
0065   }
0066 #else
0067   VECCORE_ATT_DEVICE
0068   static VSafetyEstimator *Instance();
0069 #endif
0070 
0071 }; // end class
0072 }
0073 } // end namespaces
0074 
0075 #endif /* NAVIGATION_SIMPLESAFETYESTIMATOR_H_ */