Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-01 08:41:03

0001 /*
0002  * NewSimpleNavigator.h
0003  *
0004  *  Created on: 17.09.2015
0005  *      Author: swenzel
0006  */
0007 
0008 #ifndef NAVIGATION_NEWSIMPLENAVIGATOR_H_
0009 #define NAVIGATION_NEWSIMPLENAVIGATOR_H_
0010 
0011 #include "VNavigator.h"
0012 #include "SimpleSafetyEstimator.h"
0013 
0014 namespace vecgeom {
0015 inline namespace VECGEOM_IMPL_NAMESPACE {
0016 
0017 // A very basic implementation of a navigator ( brute force which scales linearly with the number of daughters )
0018 template <bool MotherIsConvex = false>
0019 class NewSimpleNavigator : public VNavigatorHelper<class NewSimpleNavigator<MotherIsConvex>, MotherIsConvex> {
0020 
0021 private:
0022   VECCORE_ATT_DEVICE
0023   NewSimpleNavigator()
0024       : VNavigatorHelper<class NewSimpleNavigator<MotherIsConvex>, MotherIsConvex>(SimpleSafetyEstimator::Instance()) {
0025   } VECCORE_ATT_DEVICE virtual ~NewSimpleNavigator() {}
0026 
0027 public:
0028   VECGEOM_FORCE_INLINE
0029   VECCORE_ATT_HOST_DEVICE
0030   virtual bool CheckDaughterIntersections(LogicalVolume const *lvol, Vector3D<Precision> const &localpoint,
0031                                           Vector3D<Precision> const &localdir, NavigationState const *in_state,
0032                                           NavigationState * /*out_state*/, Precision &step,
0033                                           VPlacedVolume const *&hitcandidate) const override
0034   {
0035     // iterate over all daughters
0036     auto *daughters = lvol->GetDaughtersp();
0037     auto ndaughters = daughters->size();
0038     for (decltype(ndaughters) d = 0; d < ndaughters; ++d) {
0039       auto daughter = daughters->operator[](d);
0040       if (in_state && in_state->GetLastExited() == daughter) continue;
0041       Precision ddistance = daughter->DistanceToIn(localpoint, localdir, step);
0042       ddistance           = vecCore::math::Max(ddistance, 0.);
0043       const bool valid    = ddistance < step;
0044       hitcandidate        = valid ? daughter : hitcandidate;
0045       step                = valid ? ddistance : step;
0046     }
0047     return false;
0048   }
0049 
0050   VECGEOM_FORCE_INLINE
0051   VECCORE_ATT_HOST_DEVICE
0052   virtual bool CheckDaughterIntersections(LogicalVolume const *lvol, Vector3D<Precision> const &localpoint,
0053                                           Vector3D<Precision> const &localdir, VPlacedVolume const *blocked,
0054                                           Precision &step, VPlacedVolume const *&hitcandidate) const override
0055   {
0056     //  New Implementation JA 2021.03.18
0057     static const double kMinExitingCos = 1.e-3;
0058     VPlacedVolume const *excludedVol   = nullptr;
0059     if (blocked) {
0060       Vector3D<Precision> normal;
0061       blocked->Normal(localpoint, normal);
0062       if (normal.Dot(localdir) >= kMinExitingCos) {
0063         excludedVol = blocked;
0064       }
0065     }
0066 
0067     // iterate over all daughters
0068     auto *daughters = lvol->GetDaughtersp();
0069     auto ndaughters = daughters->size();
0070     for (decltype(ndaughters) d = 0; d < ndaughters; ++d) {
0071       auto daughter = daughters->operator[](d);
0072       if (daughter != excludedVol) {
0073         Precision ddistance = daughter->DistanceToIn(localpoint, localdir, step);
0074         const bool valid    = ddistance < step;
0075         hitcandidate        = valid ? daughter : hitcandidate;
0076         step                = valid ? ddistance : step;
0077       }
0078     }
0079     return false;
0080   }
0081 
0082 #ifndef VECCORE_CUDA
0083   static VNavigator *Instance()
0084   {
0085     static NewSimpleNavigator instance;
0086     return &instance;
0087   }
0088 #else
0089   VECCORE_ATT_DEVICE
0090   static VNavigator *Instance();
0091 #endif
0092 
0093   static constexpr const char *gClassNameString = "NewSimpleNavigator";
0094   typedef SimpleSafetyEstimator SafetyEstimator_t;
0095 }; // end of class
0096 } // namespace VECGEOM_IMPL_NAMESPACE
0097 } // namespace vecgeom
0098 
0099 #endif /* NAVIGATION_NEWSIMPLENAVIGATOR_H_ */