Back to home page

EIC code displayed by LXR

 
 

    


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

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/StepDiagnostic.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <memory>
0010 #include <vector>
0011 
0012 #include "corecel/data/StreamStore.hh"
0013 #include "corecel/io/OutputInterface.hh"
0014 #include "celeritas/global/ActionInterface.hh"
0015 #include "celeritas/global/CoreTrackData.hh"
0016 
0017 #include "ParticleTallyData.hh"
0018 
0019 namespace celeritas
0020 {
0021 //---------------------------------------------------------------------------//
0022 class ParticleParams;
0023 
0024 //---------------------------------------------------------------------------//
0025 /*!
0026  * Tally number of steps taken by each particle type.
0027  *
0028  * This adds an \c step-diagnostic entry to the \c result category of the
0029  * main Celeritas output that bins the total number of steps taken by a track,
0030  * grouped by particle type. The result is an integral over all events.
0031  */
0032 class StepDiagnostic final : public CoreStepActionInterface,
0033                              public OutputInterface
0034 {
0035   public:
0036     //!@{
0037     //! \name Type aliases
0038     using SPConstParticle = std::shared_ptr<ParticleParams const>;
0039     using VecVecCount = std::vector<std::vector<size_type>>;
0040     //!@}
0041 
0042   public:
0043     // Construct and add to core params
0044     static std::shared_ptr<StepDiagnostic>
0045     make_and_insert(CoreParams const& core, size_type max_bins);
0046 
0047     //! Construct with particle data
0048     StepDiagnostic(ActionId id,
0049                    SPConstParticle particle,
0050                    size_type max_bins,
0051                    size_type num_streams);
0052 
0053     //! Default destructor
0054     ~StepDiagnostic() final;
0055 
0056     //!@{
0057     //! \name ExplicitAction interface
0058 
0059     // Launch kernel with host data
0060     void step(CoreParams const&, CoreStateHost&) const final;
0061     // Launch kernel with device data
0062     void step(CoreParams const&, CoreStateDevice&) const final;
0063     //! ID of the action
0064     ActionId action_id() const final { return id_; }
0065     //! Short name for the action
0066     std::string_view label() const final { return "step-diagnostic"; }
0067     // Description of the action for user interaction
0068     std::string_view description() const final;
0069     //! Dependency ordering of the action
0070     StepActionOrder order() const final { return StepActionOrder::user_post; }
0071     //!@}
0072 
0073     //!@{
0074     //! \name Output interface
0075 
0076     //! Category of data to write
0077     Category category() const final { return Category::result; }
0078     // Write output to the given JSON object
0079     void output(JsonPimpl*) const final;
0080     //!@}
0081 
0082     // Get the diagnostic results accumulated over all streams
0083     VecVecCount calc_steps() const;
0084 
0085     // Size of diagnostic state data (number of bins times number of particles)
0086     size_type state_size() const;
0087 
0088     // Reset diagnostic results
0089     void clear();
0090 
0091   private:
0092     using StoreT = StreamStore<ParticleTallyParamsData, ParticleTallyStateData>;
0093 
0094     ActionId id_;
0095     size_type num_streams_;
0096     mutable StoreT store_;
0097 };
0098 
0099 //---------------------------------------------------------------------------//
0100 }  // namespace celeritas