Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:53:37

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file celeritas/ext/detail/LevelTouchableUpdater.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <memory>
0010 #include <vector>
0011 
0012 #include "geocel/GeantGeoUtils.hh"
0013 #include "celeritas/Types.hh"
0014 #include "celeritas/Units.hh"
0015 #include "celeritas/geo/GeoFwd.hh"
0016 #include "celeritas/user/DetectorSteps.hh"
0017 
0018 #include "TouchableUpdaterInterface.hh"
0019 
0020 class G4Navigator;
0021 class G4LogicalVolume;
0022 class G4VPhysicalVolume;
0023 class G4NavigationHistory;
0024 
0025 namespace celeritas
0026 {
0027 //---------------------------------------------------------------------------//
0028 namespace detail
0029 {
0030 //---------------------------------------------------------------------------//
0031 /*!
0032  * Update a Geant4 "touchable" using volume instances at each level.
0033  */
0034 class LevelTouchableUpdater final : public TouchableUpdaterInterface
0035 {
0036   public:
0037     //!@{
0038     //! \name Type aliases
0039     using SpanVolInst = Span<VolumeInstanceId const>;
0040     using SPConstGeo = std::shared_ptr<GeoParams const>;
0041     //!@}
0042 
0043   public:
0044     // Get a slice of volume instances from the output
0045     inline static SpanVolInst volume_instances(DetectorStepOutput const& out,
0046                                                size_type step_index,
0047                                                StepPoint step_point);
0048 
0049     // Construct with the geometry
0050     explicit LevelTouchableUpdater(SPConstGeo);
0051 
0052     // Destroy pointers
0053     ~LevelTouchableUpdater() final;
0054 
0055     // Update from a particular detector step
0056     bool operator()(DetectorStepOutput const& out,
0057                     size_type step_index,
0058                     StepPoint step_point,
0059                     GeantTouchableBase* touchable) final;
0060 
0061     // Initialize from a span of volume instances
0062     bool operator()(SpanVolInst ids, GeantTouchableBase* touchable);
0063 
0064   private:
0065     // Geometry for doing G4PV translation
0066     SPConstGeo geo_;
0067     // Temporary storage for physical volumes
0068     std::vector<GeantPhysicalInstance> phys_inst_;
0069     // Temporary history
0070     std::unique_ptr<G4NavigationHistory> nav_hist_;
0071 };
0072 
0073 //---------------------------------------------------------------------------//
0074 /*!
0075  * Get a slice of volume instances from the output.
0076  */
0077 auto LevelTouchableUpdater::volume_instances(DetectorStepOutput const& out,
0078                                              size_type i,
0079                                              StepPoint sp) -> SpanVolInst
0080 {
0081     CELER_EXPECT(i < out.size());
0082     CELER_EXPECT(out.volume_instance_depth > 0);
0083     CELER_EXPECT(!out.points[sp].volume_instance_ids.empty());
0084     auto ids = make_span(out.points[sp].volume_instance_ids);
0085     auto const depth = out.volume_instance_depth;
0086     CELER_EXPECT(ids.size() >= (i + 1) * depth);
0087     return ids.subspan(i * depth, depth);
0088 }
0089 
0090 //---------------------------------------------------------------------------//
0091 }  // namespace detail
0092 }  // namespace celeritas