Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:09:32

0001 // SPDX-FileCopyrightText: 2023 CERN
0002 // SPDX-License-Identifier: Apache-2.0
0003 //---------------------------------------------------------------------------//
0004 /*!
0005  * \file geocel/vg/detail/SurfNavigator.hh
0006  * \brief Navigation methods using the surface model.
0007  *
0008  * Original source:
0009  * https://github.com/apt-sim/AdePT/blob/e03b856523164fb13f9f030d52297db96c8a2c8d/base/inc/AdePT/SurfNavigator.h
0010  */
0011 //---------------------------------------------------------------------------//
0012 #pragma once
0013 
0014 #include <VecGeom/base/Config.h>
0015 #include <VecGeom/base/Global.h>
0016 #include <VecGeom/base/Vector3D.h>
0017 #include <VecGeom/navigation/NavStateIndex.h>
0018 #include <VecGeom/surfaces/Navigator.h>
0019 
0020 #ifdef VECGEOM_ENABLE_CUDA
0021 #    include <VecGeom/backend/cuda/Interface.h>
0022 #endif
0023 #include "corecel/Macros.hh"
0024 
0025 namespace celeritas
0026 {
0027 namespace detail
0028 {
0029 //---------------------------------------------------------------------------//
0030 class SurfNavigator
0031 {
0032   public:
0033     using Precision = vecgeom::Precision;
0034     using Vector3D = vecgeom::Vector3D<vecgeom::Precision>;
0035     using VPlacedVolumePtr_t = vecgeom::VPlacedVolume const*;
0036     using SurfData = vgbrep::SurfData<Precision>;
0037 
0038     static constexpr Precision kBoundaryPush = 10 * vecgeom::kTolerance;
0039 
0040     // Locates the point in the geometry volume tree
0041     CELER_FUNCTION static VPlacedVolumePtr_t
0042     LocatePointIn(VPlacedVolumePtr_t vol,
0043                   Vector3D const& point,
0044                   vecgeom::NavStateIndex& path,
0045                   bool top)
0046     {
0047         return vgbrep::protonav::LocatePointIn(vol, point, path, top);
0048     }
0049 
0050     // Computes the isotropic safety from the globalpoint.
0051     CELER_FUNCTION static Precision
0052     ComputeSafety(Vector3D const& globalpoint,
0053                   vecgeom::NavStateIndex const& state)
0054     {
0055         int closest_surf = 0;
0056         return vgbrep::protonav::ComputeSafety(
0057             globalpoint, state, closest_surf);
0058     }
0059 
0060     // Computes a step from the globalpoint (which must be in the current
0061     // volume) into globaldir, taking step_limit into account. If a volume is
0062     // hit, the function calls out_state.SetBoundaryState(true) and relocates
0063     // the state to the next volume.
0064     //
0065     // The surface model does automatic relocation, so this function does it as
0066     // well.
0067     CELER_FUNCTION static Precision
0068     ComputeStepAndNextVolume(Vector3D const& globalpoint,
0069                              Vector3D const& globaldir,
0070                              Precision step_limit,
0071                              vecgeom::NavStateIndex const& in_state,
0072                              vecgeom::NavStateIndex& out_state,
0073                              [[maybe_unused]] Precision push = 0)
0074     {
0075         if (step_limit <= 0)
0076         {
0077             in_state.CopyTo(&out_state);
0078             out_state.SetBoundaryState(false);
0079             return step_limit;
0080         }
0081 
0082         int exit_surf = 0;
0083         auto step = vgbrep::protonav::ComputeStepAndHit(
0084             globalpoint, globaldir, in_state, out_state, exit_surf, step_limit);
0085         return step;
0086     }
0087 
0088     // Computes a step from the globalpoint (which must be in the current
0089     // volume) into globaldir, taking step_limit into account. If a volume is
0090     // hit, the function calls out_state.SetBoundaryState(true) and relocates
0091     // the state to the next volume.
0092     CELER_FUNCTION static Precision
0093     ComputeStepAndPropagatedState(Vector3D const& globalpoint,
0094                                   Vector3D const& globaldir,
0095                                   Precision step_limit,
0096                                   vecgeom::NavStateIndex const& in_state,
0097                                   vecgeom::NavStateIndex& out_state,
0098                                   Precision push = 0)
0099     {
0100         return ComputeStepAndNextVolume(
0101             globalpoint, globaldir, step_limit, in_state, out_state, push);
0102     }
0103 
0104     // Relocate a state that was returned from ComputeStepAndNextVolume: the
0105     // surface model does this computation within ComputeStepAndNextVolume, so
0106     // the relocation does nothing
0107     CELER_FUNCTION static void
0108     RelocateToNextVolume(Vector3D const& /*globalpoint*/,
0109                          Vector3D const& /*globaldir*/,
0110                          vecgeom::NavStateIndex& /*state*/)
0111     {
0112     }
0113 };
0114 
0115 //---------------------------------------------------------------------------//
0116 }  // namespace detail
0117 }  // End namespace celeritas