Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-29 09:13:53

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 geocel/DetectorParams.hh
0006 //! \sa test/geocel/Detector.test.cc
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <vector>
0011 
0012 #include "corecel/Assert.hh"
0013 #include "corecel/cont/LabelIdMultiMap.hh"
0014 #include "corecel/cont/Span.hh"
0015 #include "corecel/data/ParamsDataInterface.hh"
0016 #include "corecel/data/ParamsDataStore.hh"
0017 
0018 #include "DetectorData.hh"
0019 #include "inp/Model.hh"
0020 
0021 namespace celeritas
0022 {
0023 class VolumeParams;
0024 
0025 //---------------------------------------------------------------------------//
0026 /*!
0027  * Map Geant4 sensitive detectors to distinct detector IDs.
0028  */
0029 class DetectorParams final : public ParamsDataInterface<DetectorParamsData>
0030 {
0031   public:
0032     //!@{
0033     //! \name Type aliases
0034     using SpanVol = Span<VolumeId const>;
0035     using DetectorMap = LabelIdMultiMap<DetectorId>;
0036     //!@}
0037 
0038   public:
0039     //! Construct without detectors or volumes
0040     DetectorParams() = default;
0041 
0042     // Construct from detector input and volume params reference
0043     DetectorParams(inp::Detectors detectors, VolumeParams const& volumes);
0044 
0045     //! Whether detector mapping is disabled (no volumes specified)
0046     bool empty() const { return !static_cast<bool>(mirror_); }
0047 
0048     //! Number of detectors
0049     DetectorId::size_type num_detectors() const
0050     {
0051         return detectors_.detectors.size();
0052     }
0053 
0054     //! Get detector metadata
0055     DetectorMap const& detector_labels() const { return det_labels_; }
0056 
0057     // Find the detector ID for a given volume, if any
0058     inline DetectorId detector_id(VolumeId vol_id) const;
0059 
0060     // Find all volumes assigned to a detector.
0061     inline SpanVol volume_ids(DetectorId det_id) const;
0062 
0063     //!@{
0064     //! \name Data interface
0065 
0066     //! Access sensitive detector properties on the host
0067     HostRef const& host_ref() const final { return mirror_.host_ref(); }
0068     //! Access sensitive detector properties on the device
0069     DeviceRef const& device_ref() const final { return mirror_.device_ref(); }
0070     //!@}
0071 
0072   private:
0073     ParamsDataStore<DetectorParamsData> mirror_;
0074     inp::Detectors detectors_;
0075     DetectorMap det_labels_;
0076 };
0077 
0078 //---------------------------------------------------------------------------//
0079 // INLINE DEFINITIONS
0080 //---------------------------------------------------------------------------//
0081 /*!
0082  * Find the detector ID for a given volume, if any.
0083  */
0084 DetectorId DetectorParams::detector_id(VolumeId vol_id) const
0085 {
0086     return host_ref().detector_ids[vol_id];
0087 }
0088 
0089 //---------------------------------------------------------------------------//
0090 /*!
0091  * Find all volumes assigned to a detector.
0092  */
0093 auto DetectorParams::volume_ids(DetectorId det_id) const -> SpanVol
0094 {
0095     CELER_EXPECT(det_id < this->num_detectors());
0096     return make_span(detectors_.detectors[det_id.get()].volumes);
0097 }
0098 
0099 //---------------------------------------------------------------------------//
0100 }  // namespace celeritas