Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-04 09:27:52

0001 /*
0002  * VSafetyEstimator.h
0003  *
0004  *  Created on: 28.08.2015
0005  *      Author: swenzel
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 // some forward declarations
0025 template <typename T>
0026 class Vector3D;
0027 // class NavigationState;
0028 class LogicalVolume;
0029 class Transformation3D;
0030 class VPlacedVolume;
0031 
0032 //! base class defining basic interface for safety estimators;
0033 //! safety estimators calculate the safety of a track in a logical volume containing other objects
0034 //! sub classes implement optimized algorithms for logical volumes
0035 //
0036 // safety estimators can be called standalone or be used from the navigators
0037 class VSafetyEstimator {
0038 
0039 public:
0040   //! computes the safety of a point given in global coordinates for a geometry location specified
0041   //! by the navigationstate
0042   //! this function is a convenience interface to ComputeSafetyForLocalPoint and will usually be implemented in terms of
0043   //! the latter
0044   VECCORE_ATT_HOST_DEVICE
0045   virtual Precision ComputeSafety(Vector3D<Precision> const & /*globalpoint*/,
0046                                   NavigationState const & /*state*/) const = 0;
0047 
0048   VECCORE_ATT_HOST_DEVICE
0049   virtual Precision ComputeSafetyForLocalPoint(Vector3D<Precision> const & /*localpoint*/,
0050                                                VPlacedVolume const * /*pvol*/) const = 0;
0051 
0052   // estimate just the safety to daughters for a local point with respect to a logical volume
0053   VECCORE_ATT_HOST_DEVICE
0054   virtual Precision ComputeSafetyToDaughtersForLocalPoint(Vector3D<Precision> const & /*localpoint*/,
0055                                                           LogicalVolume const * /*lvol*/) const = 0;
0056 
0057   // in addition useful to offer an explicit SIMD interface
0058   // which could be used from other clients (such as VNavigator when it treats basket data)
0059   // the mask is supposed to indicate which lane needs a safety result since often the track is
0060   // on a boundary where the safety is zero anyway
0061 
0062   using Real_v = vecgeom::VectorBackend::Real_v;
0063   using Bool_v = vecCore::Mask_v<Real_v>;
0064 
0065 public:
0066   VECCORE_ATT_HOST_DEVICE
0067   virtual ~VSafetyEstimator() {}
0068 
0069   // get name of implementing class
0070   virtual const char *GetName() const = 0;
0071 }; // end class VSafetyEstimator
0072 
0073 //! template class providing a standard implementation for
0074 //! some interfaces in VSafetyEstimator (using the CRT pattern)
0075 template <typename Impl>
0076 class VSafetyEstimatorHelper : public VSafetyEstimator {
0077 
0078 public:
0079   VECCORE_ATT_HOST_DEVICE
0080   virtual Precision ComputeSafety(Vector3D<Precision> const &globalpoint, NavigationState const &state) const override
0081   {
0082     // calculate local point from global point
0083     Transformation3D m;
0084     state.TopMatrix(m);
0085     Vector3D<Precision> localpoint = m.Transform(globalpoint);
0086     // std::cerr << "##### " << localpoint << "\n";
0087     // "suck in" algorithm from Impl
0088     return ((Impl *)this)->Impl::ComputeSafetyForLocalPoint(localpoint, state.Top());
0089   }
0090 
0091   static const char *GetClassName() { return Impl::gClassNameString; }
0092 
0093   virtual const char *GetName() const override { return GetClassName(); }
0094 }; // end class VSafetyEstimatorHelper
0095 
0096 } // namespace VECGEOM_IMPL_NAMESPACE
0097 } // namespace vecgeom
0098 
0099 #endif /* NAVIGATION_VSAFETYESTIMATOR_H_ */