Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:09:16

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/user/DetectorSteps.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <vector>
0010 
0011 #include "corecel/Assert.hh"
0012 #include "corecel/Macros.hh"
0013 #include "corecel/cont/EnumArray.hh"
0014 #include "corecel/data/PinnedAllocator.hh"
0015 #include "celeritas/Quantities.hh"
0016 #include "celeritas/Types.hh"
0017 
0018 namespace celeritas
0019 {
0020 //---------------------------------------------------------------------------//
0021 template<Ownership W, MemSpace M>
0022 struct StepStateData;
0023 
0024 //---------------------------------------------------------------------------//
0025 /*!
0026  * CPU results for detector stepping at the beginning or end of a step.
0027  *
0028  * Since the volume has a one-to-one mapping to a DetectorId, we omit it. Since
0029  * multiple "touchable" (multi-level geometry instance) volumes can point to
0030  * the same detector, and the location in that hierarchy can be important, a
0031  * separate "volume instance IDs" multi-D level is available.
0032  */
0033 struct DetectorStepPointOutput
0034 {
0035     //// TYPES ////
0036 
0037     using Energy = units::MevEnergy;
0038     template<class T>
0039     using PinnedVec = std::vector<T, PinnedAllocator<T>>;
0040 
0041     //// DATA ////
0042 
0043     PinnedVec<real_type> time;
0044     PinnedVec<Real3> pos;
0045     PinnedVec<Real3> dir;
0046     PinnedVec<Energy> energy;
0047 
0048     PinnedVec<VolumeInstanceId> volume_instance_ids;
0049 };
0050 
0051 //---------------------------------------------------------------------------//
0052 /*!
0053  * CPU results for many in-detector tracks at a single step iteration.
0054  *
0055  * This convenience class can be used to postprocess the results from sensitive
0056  * detectors on CPU. The data members will be available based on the \c
0057  * selection of the \c StepInterface class that gathered the data.
0058  *
0059  * Unlike \c StepStateData, which leaves gaps for inactive or filtered
0060  * tracks, every entry of these vectors will be valid and correspond to a
0061  * single DetectorId.
0062  */
0063 struct DetectorStepOutput
0064 {
0065     //// TYPES ////
0066 
0067     using Energy = units::MevEnergy;
0068     template<class T>
0069     using PinnedVec = std::vector<T, PinnedAllocator<T>>;
0070 
0071     //// DATA ////
0072 
0073     // Pre- and post-step data
0074     EnumArray<StepPoint, DetectorStepPointOutput> points;
0075 
0076     // Detector ID and track ID are always set
0077     PinnedVec<DetectorId> detector;
0078     PinnedVec<TrackId> track_id;
0079 
0080     // Additional optional data
0081     PinnedVec<EventId> event_id;
0082     PinnedVec<TrackId> parent_id;
0083     PinnedVec<size_type> track_step_count;
0084     PinnedVec<real_type> step_length;
0085     PinnedVec<ParticleId> particle;
0086     PinnedVec<Energy> energy_deposition;
0087 
0088     // 2D size for volume instances
0089     size_type volume_instance_depth{0};
0090 
0091     //// METHODS ////
0092 
0093     //! Number of elements in the detector output.
0094     size_type size() const { return detector.size(); }
0095     //! Whether the size is nonzero
0096     explicit operator bool() const { return !detector.empty(); }
0097 };
0098 
0099 //---------------------------------------------------------------------------//
0100 // Copy state data for all steps inside detectors to the output.
0101 template<MemSpace M>
0102 void copy_steps(DetectorStepOutput* output,
0103                 StepStateData<Ownership::reference, M> const& state);
0104 
0105 template<>
0106 void copy_steps<MemSpace::host>(
0107     DetectorStepOutput*,
0108     StepStateData<Ownership::reference, MemSpace::host> const&);
0109 template<>
0110 void copy_steps<MemSpace::device>(
0111     DetectorStepOutput*,
0112     StepStateData<Ownership::reference, MemSpace::device> const&);
0113 
0114 //---------------------------------------------------------------------------//
0115 #if !CELER_USE_DEVICE
0116 template<>
0117 inline void copy_steps<MemSpace::device>(
0118     DetectorStepOutput*,
0119     StepStateData<Ownership::reference, MemSpace::device> const&)
0120 {
0121     CELER_NOT_CONFIGURED("CUDA or HIP");
0122 }
0123 
0124 #endif
0125 //---------------------------------------------------------------------------//
0126 }  // namespace celeritas