Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:59

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   VECCORE_ATT_HOST_DEVICE
0066   virtual Real_v ComputeSafetyForLocalPoint(Vector3D<Real_v> const & /*localpoint*/, VPlacedVolume const * /*pvol*/,
0067                                             Bool_v /*m*/) const = 0;
0068 
0069   // interfaces to treat vectors/collections of points (uses the approach with intermediate storage and passing down the
0070   // loops to shapes)
0071   virtual void ComputeVectorSafety(SOA3D<Precision> const & /*globalpoints*/, NavStatePool &states,
0072                                    SOA3D<Precision> & /*workspace*/, Precision * /*safeties*/) const = 0;
0073 
0074   // interfaces to treat vectors/collections of points (uses the approach without intermediate storage; requires access
0075   // to new SIMD interface)
0076   virtual void ComputeVectorSafety(SOA3D<Precision> const & /*globalpoints*/, NavStatePool & /*states*/,
0077                                    Precision * /*safeties*/) const = 0;
0078 
0079 private:
0080   virtual void ComputeSafetyForLocalPoints(SOA3D<Precision> const & /*localpoints*/, VPlacedVolume const * /*pvol*/,
0081                                            Precision * /*safeties*/) const = 0;
0082 
0083 public:
0084   VECCORE_ATT_HOST_DEVICE
0085   virtual ~VSafetyEstimator() {}
0086 
0087   // get name of implementing class
0088   virtual const char *GetName() const = 0;
0089 }; // end class VSafetyEstimator
0090 
0091 //! template class providing a standard implementation for
0092 //! some interfaces in VSafetyEstimator (using the CRT pattern)
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     // calculate local point from global point
0101     Transformation3D m;
0102     state.TopMatrix(m);
0103     Vector3D<Precision> localpoint = m.Transform(globalpoint);
0104     // std::cerr << "##### " << localpoint << "\n";
0105     // "suck in" algorithm from Impl
0106     return ((Impl *)this)->Impl::ComputeSafetyForLocalPoint(localpoint, state.Top());
0107   }
0108 
0109   // interfaces to treat vectors/collections of points (uses the approach without intermediate storage; requires access
0110   // to new SIMD interface)
0111   virtual void ComputeVectorSafety(SOA3D<Precision> const & /*globalpoints*/, NavStatePool & /*states*/,
0112                                    Precision * /*safeties*/) 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     // calculate local point from global point
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     // "suck in" algorithm from Impl
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 }; // end class VSafetyEstimatorHelper
0135 
0136 } // namespace VECGEOM_IMPL_NAMESPACE
0137 } // namespace vecgeom
0138 
0139 #endif /* NAVIGATION_VSAFETYESTIMATOR_H_ */