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