Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2023-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/SimpleCalo.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <vector>
0011 
0012 #include "corecel/Types.hh"
0013 #include "corecel/cont/Span.hh"
0014 #include "corecel/data/Collection.hh"
0015 #include "corecel/data/StreamStore.hh"
0016 #include "corecel/io/Label.hh"
0017 #include "corecel/io/OutputInterface.hh"
0018 #include "celeritas/Quantities.hh"
0019 
0020 #include "SimpleCaloData.hh"
0021 #include "StepInterface.hh"
0022 
0023 namespace celeritas
0024 {
0025 //---------------------------------------------------------------------------//
0026 class GeoParamsInterface;
0027 
0028 //---------------------------------------------------------------------------//
0029 /*!
0030  * Accumulate energy deposition in volumes.
0031  *
0032  * \todo Add a "begin run" interface to set up the stream store, rather than
0033  * passing in number of streams at construction time.
0034  */
0035 class SimpleCalo final : public StepInterface, public OutputInterface
0036 {
0037   public:
0038     //!@{
0039     //! \name Type aliases
0040     using VecLabel = std::vector<Label>;
0041     using EnergyUnits = units::Mev;
0042     template<MemSpace M>
0043     using DetectorRef
0044         = celeritas::Collection<real_type, Ownership::reference, M, DetectorId>;
0045     using VecReal = std::vector<real_type>;
0046     //!@}
0047 
0048   public:
0049     // Construct with all requirements
0050     SimpleCalo(std::string output_label,
0051                VecLabel labels,
0052                GeoParamsInterface const& geo,
0053                size_type max_streams);
0054 
0055     //! Construct with default label
0056     SimpleCalo(VecLabel labels,
0057                GeoParamsInterface const& geo,
0058                size_type max_streams)
0059         : SimpleCalo{"simple_calo", std::move(labels), geo, max_streams}
0060     {
0061     }
0062 
0063     //!@{
0064     //! \name Step interface
0065     // Map volume names to detector IDs and exclude tracks with no deposition
0066     Filters filters() const final;
0067     // Save energy deposition and pre-step volume
0068     StepSelection selection() const final;
0069     // Process CPU-generated hits
0070     void process_steps(HostStepState) final;
0071     // Process device-generated hits
0072     void process_steps(DeviceStepState) final;
0073     //!@}
0074 
0075     //!@{
0076     //! \name Output interface
0077     // Category of data to write
0078     Category category() const final { return Category::result; }
0079     // Key for the entry inside the category.
0080     std::string_view label() const final { return output_label_; }
0081     // Write output to the given JSON object
0082     void output(JsonPimpl*) const final;
0083     //!@}
0084 
0085     //// ACCESSORS ////
0086 
0087     //! Number of distinct sensitive volumes
0088     DetectorId::size_type num_detectors() const { return volume_ids_.size(); }
0089 
0090     // Get tallied stream-local data (throw if not available) [EnergyUnits]
0091     template<MemSpace M>
0092     DetectorRef<M> const& energy_deposition(StreamId) const;
0093 
0094     // Get accumulated energy deposition over all streams and host/device
0095     VecReal calc_total_energy_deposition() const;
0096 
0097     //// MUTATORS ////
0098 
0099     // Reset energy deposition to zero, usually at the start of an event
0100     void clear();
0101 
0102   private:
0103     using StoreT = StreamStore<SimpleCaloParamsData, SimpleCaloStateData>;
0104 
0105     std::string output_label_;
0106     VecLabel volume_labels_;
0107     std::vector<VolumeId> volume_ids_;
0108     StoreT store_;
0109 };
0110 
0111 //---------------------------------------------------------------------------//
0112 }  // namespace celeritas