File indexing completed on 2025-01-18 10:13:59
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef NAVIGATION_VSAFETYESTIMATOR_H_
0009 #define NAVIGATION_VSAFETYESTIMATOR_H_
0010
0011 #include "VecGeom/base/Global.h"
0012 #include "VecGeom/base/Vector3D.h"
0013 #include "VecGeom/base/SOA3D.h"
0014 #include "VecGeom/base/Transformation3D.h"
0015 #include "VecGeom/navigation/NavigationState.h"
0016 #include "VecGeom/navigation/NavStatePool.h"
0017 #include "VecGeom/volumes/PlacedVolume.h"
0018 #include "VecGeom/volumes/LogicalVolume.h"
0019 #include "VecGeom/navigation/NavStateFwd.h"
0020
0021 namespace vecgeom {
0022 inline namespace VECGEOM_IMPL_NAMESPACE {
0023
0024
0025 template <typename T>
0026 class Vector3D;
0027
0028 class LogicalVolume;
0029 class Transformation3D;
0030 class VPlacedVolume;
0031
0032
0033
0034
0035
0036
0037 class VSafetyEstimator {
0038
0039 public:
0040
0041
0042
0043
0044 VECCORE_ATT_HOST_DEVICE
0045 virtual Precision ComputeSafety(Vector3D<Precision> const & ,
0046 NavigationState const & ) const = 0;
0047
0048 VECCORE_ATT_HOST_DEVICE
0049 virtual Precision ComputeSafetyForLocalPoint(Vector3D<Precision> const & ,
0050 VPlacedVolume const * ) const = 0;
0051
0052
0053 VECCORE_ATT_HOST_DEVICE
0054 virtual Precision ComputeSafetyToDaughtersForLocalPoint(Vector3D<Precision> const & ,
0055 LogicalVolume const * ) const = 0;
0056
0057
0058
0059
0060
0061
0062 using Real_v = vecgeom::VectorBackend::Real_v;
0063 using Bool_v = vecCore::Mask_v<Real_v>;
0064
0065 VECCORE_ATT_HOST_DEVICE
0066 virtual Real_v ComputeSafetyForLocalPoint(Vector3D<Real_v> const & , VPlacedVolume const * ,
0067 Bool_v ) const = 0;
0068
0069
0070
0071 virtual void ComputeVectorSafety(SOA3D<Precision> const & , NavStatePool &states,
0072 SOA3D<Precision> & , Precision * ) const = 0;
0073
0074
0075
0076 virtual void ComputeVectorSafety(SOA3D<Precision> const & , NavStatePool & ,
0077 Precision * ) const = 0;
0078
0079 private:
0080 virtual void ComputeSafetyForLocalPoints(SOA3D<Precision> const & , VPlacedVolume const * ,
0081 Precision * ) const = 0;
0082
0083 public:
0084 VECCORE_ATT_HOST_DEVICE
0085 virtual ~VSafetyEstimator() {}
0086
0087
0088 virtual const char *GetName() const = 0;
0089 };
0090
0091
0092
0093 template <typename Impl>
0094 class VSafetyEstimatorHelper : public VSafetyEstimator {
0095
0096 public:
0097 VECCORE_ATT_HOST_DEVICE
0098 virtual Precision ComputeSafety(Vector3D<Precision> const &globalpoint, NavigationState const &state) const override
0099 {
0100
0101 Transformation3D m;
0102 state.TopMatrix(m);
0103 Vector3D<Precision> localpoint = m.Transform(globalpoint);
0104
0105
0106 return ((Impl *)this)->Impl::ComputeSafetyForLocalPoint(localpoint, state.Top());
0107 }
0108
0109
0110
0111 virtual void ComputeVectorSafety(SOA3D<Precision> const & , NavStatePool & ,
0112 Precision * ) const override
0113 {
0114 assert(0 && "not implemented yet, requires access to new SIM interface");
0115 }
0116
0117 virtual void ComputeVectorSafety(SOA3D<Precision> const &globalpoints, NavStatePool &states,
0118 SOA3D<Precision> &localpointworkspace, Precision *safeties) const override
0119 {
0120
0121 auto np = globalpoints.size();
0122 for (auto i = decltype(np){0}; i < np; ++i) {
0123 Transformation3D m;
0124 states[i]->TopMatrix(m);
0125 localpointworkspace.set(i, m.Transform(globalpoints[i]));
0126 }
0127
0128 ((Impl *)this)->Impl::ComputeSafetyForLocalPoints(localpointworkspace, states[0]->Top(), safeties);
0129 }
0130
0131 static const char *GetClassName() { return Impl::gClassNameString; }
0132
0133 virtual const char *GetName() const override { return GetClassName(); }
0134 };
0135
0136 }
0137 }
0138
0139 #endif