Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-28 10:34:59

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       Precision ddistance = daughter->DistanceToIn(localpoint, localdir, step);
0041       // The daughter just exited is refused only where the ray leaves it; a non-convex one can be re-entered.
0042       if (ddistance <= 0. && in_state && in_state->GetLastExited() == daughter) continue;
0043       ddistance        = Max(ddistance, Precision(0.));
0044       const bool valid = ddistance < step;
0045       hitcandidate     = valid ? daughter : hitcandidate;
0046       step             = valid ? ddistance : step;
0047     }
0048     return false;
0049   }
0050 
0051   VECGEOM_FORCE_INLINE
0052   VECCORE_ATT_HOST_DEVICE
0053   virtual bool CheckDaughterIntersections(LogicalVolume const *lvol, Vector3D<Precision> const &localpoint,
0054                                           Vector3D<Precision> const &localdir, VPlacedVolume const *blocked,
0055                                           Precision &step, VPlacedVolume const *&hitcandidate) const override
0056   {
0057     //  New Implementation JA 2021.03.18
0058     static const double kMinExitingCos = 1.e-3;
0059     VPlacedVolume const *excludedVol   = nullptr;
0060     if (blocked) {
0061       Vector3D<Precision> normal;
0062       blocked->Normal(localpoint, normal);
0063       if (normal.Dot(localdir) >= kMinExitingCos) {
0064         excludedVol = blocked;
0065       }
0066     }
0067 
0068     // iterate over all daughters
0069     auto *daughters = lvol->GetDaughtersp();
0070     auto ndaughters = daughters->size();
0071     for (decltype(ndaughters) d = 0; d < ndaughters; ++d) {
0072       auto daughter = daughters->operator[](d);
0073       if (daughter != excludedVol) {
0074         Precision ddistance = daughter->DistanceToIn(localpoint, localdir, step);
0075         const bool valid    = ddistance < step;
0076         hitcandidate        = valid ? daughter : hitcandidate;
0077         step                = valid ? ddistance : step;
0078       }
0079     }
0080     return false;
0081   }
0082 
0083 #ifndef VECCORE_CUDA
0084   static VNavigator *Instance()
0085   {
0086     static NewSimpleNavigator instance;
0087     return &instance;
0088   }
0089 #else
0090   VECCORE_ATT_DEVICE
0091   static VNavigator *Instance();
0092 #endif
0093 
0094   static constexpr const char *gClassNameString = "NewSimpleNavigator";
0095   typedef SimpleSafetyEstimator SafetyEstimator_t;
0096 }; // end of class
0097 } // namespace VECGEOM_IMPL_NAMESPACE
0098 } // namespace vecgeom
0099 
0100 #endif /* NAVIGATION_NEWSIMPLENAVIGATOR_H_ */