Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:11:40

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/optical/DetectorData.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Types.hh"
0010 #include "corecel/data/Collection.hh"
0011 #include "geocel/Types.hh"
0012 #include "celeritas/Quantities.hh"
0013 
0014 namespace celeritas
0015 {
0016 namespace optical
0017 {
0018 //---------------------------------------------------------------------------//
0019 /*!
0020  * A single hit of a photon track on a sensitive detector.
0021  */
0022 struct DetectorHit
0023 {
0024     using Energy = units::MevEnergy;
0025 
0026     DetectorId detector{};
0027     PrimaryId primary{};
0028     Energy energy;
0029     real_type time{};
0030     Real3 position{};
0031     VolumeInstanceId volume_instance;
0032     VolumeUniqueInstanceId unique_instance;
0033     size_type num_steps{};
0034     real_type path_length{};
0035 
0036     //! An actual hit has a valid detector
0037     explicit CELER_CONSTEXPR_FUNCTION operator bool() const
0038     {
0039         return static_cast<bool>(detector);
0040     }
0041 };
0042 
0043 //---------------------------------------------------------------------------//
0044 /*!
0045  * State buffer for storing detector hits.
0046  *
0047  * Detector hits is large enough to store a hit for every track at the end of a
0048  * step. Stored hits may be invalid if the track is not in a detector region.
0049  */
0050 template<Ownership W, MemSpace M>
0051 struct DetectorStateData
0052 {
0053     //!@{
0054     //! \name Type aliases
0055     template<class T>
0056     using StateItems = StateCollection<T, W, M>;
0057     //!@}
0058 
0059     StateItems<DetectorHit> detector_hits;
0060 
0061     //! Whether data is assigned and valid
0062     explicit CELER_FUNCTION operator bool() const
0063     {
0064         return !detector_hits.empty();
0065     }
0066 
0067     //! State size
0068     CELER_FUNCTION size_type size() const { return detector_hits.size(); }
0069 
0070     //! Assign from another set of data
0071     template<Ownership W2, MemSpace M2>
0072     DetectorStateData<W, M>& operator=(DetectorStateData<W2, M2>& other)
0073     {
0074         CELER_EXPECT(other);
0075         detector_hits = other.detector_hits;
0076         return *this;
0077     }
0078 };
0079 
0080 //---------------------------------------------------------------------------//
0081 // INLINE DEFINITIONS
0082 //---------------------------------------------------------------------------//
0083 /*!
0084  * Resize the state in host code.
0085  */
0086 template<MemSpace M>
0087 inline void resize(DetectorStateData<Ownership::value, M>* state,
0088                    size_type size)
0089 {
0090     CELER_EXPECT(state);
0091     CELER_EXPECT(size > 0);
0092 
0093     resize(&state->detector_hits, size);
0094 
0095     CELER_ENSURE(*state);
0096 }
0097 
0098 //---------------------------------------------------------------------------//
0099 }  // namespace optical
0100 }  // namespace celeritas