Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:53:48

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