Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:32

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2022-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file celeritas/user/DetectorSteps.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <vector>
0011 
0012 #include "corecel/Assert.hh"
0013 #include "corecel/Macros.hh"
0014 #include "corecel/cont/EnumArray.hh"
0015 #include "corecel/data/PinnedAllocator.hh"
0016 #include "celeritas/Quantities.hh"
0017 #include "celeritas/Types.hh"
0018 
0019 namespace celeritas
0020 {
0021 //---------------------------------------------------------------------------//
0022 template<Ownership W, MemSpace M>
0023 struct StepStateData;
0024 
0025 //---------------------------------------------------------------------------//
0026 /*!
0027  * CPU results for detector stepping at the beginning or end of a step.
0028  *
0029  * Since the volume has a one-to-one mapping to a DetectorId, we omit it.
0030  */
0031 struct DetectorStepPointOutput
0032 {
0033     using Energy = units::MevEnergy;
0034 
0035     template<class T>
0036     using vector = std::vector<T, PinnedAllocator<T>>;
0037 
0038     vector<real_type> time;
0039     vector<Real3> pos;
0040     vector<Real3> dir;
0041     vector<Energy> energy;
0042 };
0043 
0044 //---------------------------------------------------------------------------//
0045 /*!
0046  * CPU results for many in-detector tracks at a single step iteration.
0047  *
0048  * This convenience class can be used to postprocess the results from sensitive
0049  * detectors on CPU. The data members will be available based on the \c
0050  * selection of the \c StepInterface class that gathered the data.
0051  *
0052  * Unlike \c StepStateData, which leaves gaps for inactive or filtered
0053  * tracks, every entry of these vectors will be valid and correspond to a
0054  * single DetectorId.
0055  */
0056 struct DetectorStepOutput
0057 {
0058     using Energy = units::MevEnergy;
0059 
0060     // Pre- and post-step data
0061     EnumArray<StepPoint, DetectorStepPointOutput> points;
0062 
0063     template<class T>
0064     using vector = std::vector<T, PinnedAllocator<T>>;
0065 
0066     // Detector ID and track ID are always set
0067     vector<DetectorId> detector;
0068     vector<TrackId> track_id;
0069 
0070     // Additional optional data
0071     vector<EventId> event_id;
0072     vector<TrackId> parent_id;
0073     vector<size_type> track_step_count;
0074     vector<real_type> step_length;
0075     vector<ParticleId> particle;
0076     vector<Energy> energy_deposition;
0077 
0078     //! Number of elements in the detector output.
0079     size_type size() const { return detector.size(); }
0080     //! Whether the size is nonzero
0081     explicit operator bool() const { return !detector.empty(); }
0082 };
0083 
0084 //---------------------------------------------------------------------------//
0085 // Copy state data for all steps inside detectors to the output.
0086 template<MemSpace M>
0087 void copy_steps(DetectorStepOutput* output,
0088                 StepStateData<Ownership::reference, M> const& state);
0089 
0090 template<>
0091 void copy_steps<MemSpace::host>(
0092     DetectorStepOutput*,
0093     StepStateData<Ownership::reference, MemSpace::host> const&);
0094 template<>
0095 void copy_steps<MemSpace::device>(
0096     DetectorStepOutput*,
0097     StepStateData<Ownership::reference, MemSpace::device> const&);
0098 
0099 //---------------------------------------------------------------------------//
0100 #if !CELER_USE_DEVICE
0101 template<>
0102 inline void copy_steps<MemSpace::device>(
0103     DetectorStepOutput*,
0104     StepStateData<Ownership::reference, MemSpace::device> const&)
0105 {
0106     CELER_NOT_CONFIGURED("CUDA or HIP");
0107 }
0108 
0109 #endif
0110 //---------------------------------------------------------------------------//
0111 }  // namespace celeritas