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/SimpleCaloData.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Assert.hh"
0011 #include "corecel/Macros.hh"
0012 #include "corecel/data/Collection.hh"
0013 #include "corecel/sys/ThreadId.hh"
0014 #include "celeritas/Quantities.hh"
0015 #include "celeritas/Types.hh"
0016 
0017 namespace celeritas
0018 {
0019 //---------------------------------------------------------------------------//
0020 //! Number of detectors being tallied.
0021 template<Ownership W, MemSpace M>
0022 struct SimpleCaloParamsData
0023 {
0024     DetectorId::size_type num_detectors{0};
0025 
0026     explicit CELER_FUNCTION operator bool() const { return num_detectors > 0; }
0027 
0028     template<Ownership W2, MemSpace M2>
0029     SimpleCaloParamsData& operator=(SimpleCaloParamsData<W2, M2>& other)
0030     {
0031         CELER_EXPECT(other);
0032         num_detectors = other.num_detectors;
0033         return *this;
0034     }
0035 };
0036 
0037 //---------------------------------------------------------------------------//
0038 /*!
0039  * Accumulated calorimeter data for a set of tracks.
0040  *
0041  * This should be specific to a single StreamId but will be integrated over all
0042  * tracks on that stream. Depending on whether the goal is to obtain a
0043  * statistical average of energy deposition, or to find energy deposition for a
0044  * particular event, the detector data can be reset at the end of each event,
0045  * at the end of a batch of events, or at the end of the simulation.
0046  */
0047 template<Ownership W, MemSpace M>
0048 struct SimpleCaloStateData
0049 {
0050     //// TYPES ////
0051 
0052     template<class T>
0053     using DetItems = celeritas::Collection<T, W, M, DetectorId>;
0054     using EnergyUnits = units::Mev;
0055 
0056     //// DATA ////
0057 
0058     // Energy indexed by detector ID
0059     DetItems<real_type> energy_deposition;
0060 
0061     // Number of track slots (unused during calculation)
0062     size_type num_track_slots{};
0063 
0064     //// METHODS ////
0065 
0066     //! Number of states
0067     CELER_FUNCTION size_type size() const { return num_track_slots; }
0068 
0069     //! True if constructed
0070     explicit CELER_FUNCTION operator bool() const
0071     {
0072         return !energy_deposition.empty() && num_track_slots > 0;
0073     }
0074 
0075     //! Assign from another set of states
0076     template<Ownership W2, MemSpace M2>
0077     SimpleCaloStateData& operator=(SimpleCaloStateData<W2, M2>& other)
0078     {
0079         energy_deposition = other.energy_deposition;
0080         num_track_slots = other.num_track_slots;
0081         return *this;
0082     }
0083 };
0084 
0085 //---------------------------------------------------------------------------//
0086 // HELPER FUNCTIONS
0087 //---------------------------------------------------------------------------//
0088 // Resize based on the number of detectors
0089 template<MemSpace M>
0090 void resize(SimpleCaloStateData<Ownership::value, M>* state,
0091             HostCRef<SimpleCaloParamsData> const& params,
0092             StreamId,
0093             size_type num_track_slots);
0094 
0095 //---------------------------------------------------------------------------//
0096 }  // namespace celeritas