Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:29:26

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2022-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 accel/SetupOptions.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <functional>
0011 #include <memory>
0012 #include <string>
0013 #include <unordered_set>
0014 #include <vector>
0015 
0016 #include "corecel/sys/Device.hh"
0017 #include "celeritas/Types.hh"
0018 #include "celeritas/global/ActionInterface.hh"
0019 
0020 class G4LogicalVolume;
0021 
0022 namespace celeritas
0023 {
0024 struct AlongStepFactoryInput;
0025 //---------------------------------------------------------------------------//
0026 /*!
0027  * Control options for initializing Celeritas SD callbacks.
0028  *
0029  * These affect only the \c HitManager construction that is responsible for
0030  * reconstructing CPU hits and sending directly to the Geant4 detectors.
0031  *
0032  * Various attributes on the step, track, and pre/post step points may be
0033  * available depending on the selected options.
0034  * - Disabling \c track will leave \c G4Step::GetTrack as \c nullptr
0035  * - Enabling \c locate_touchable will also set \c Material and \c
0036  *   MaterialCutsCouple
0037  * - Enabling \c track will set particle the \c Charge attribute on the
0038  *   pre-step
0039  * - Requested post-step data including \c GlobalTime, \c Position, \c
0040  *   KineticEnergy, and \c MomentumDirection will be copied to the \c Track
0041  *   when the combination of options is enabled
0042  * - Track and Parent IDs will \em never be a valid value since Celeritas track
0043  *   counters are independent from Geant4 track counters.
0044  */
0045 struct SDSetupOptions
0046 {
0047     struct StepPoint
0048     {
0049         bool global_time{false};
0050         bool position{false};
0051         bool direction{false};  //!< AKA momentum direction
0052         bool kinetic_energy{false};
0053     };
0054 
0055     //! Call back to Geant4 sensitive detectors
0056     bool enabled{false};
0057     //! Skip steps that do not deposit energy locally
0058     bool ignore_zero_deposition{true};
0059     //! Save energy deposition
0060     bool energy_deposition{true};
0061     //! Set TouchableHandle for PreStepPoint
0062     bool locate_touchable{false};
0063     //! Create a track with the dynamic particle type and post-step data
0064     bool track{false};
0065     //! Options for saving and converting beginning-of-step data
0066     StepPoint pre;
0067     //! Options for saving and converting end-of-step data
0068     StepPoint post;
0069 
0070     //! Manually list LVs that don't have an SD on the master thread
0071     std::unordered_set<G4LogicalVolume const*> force_volumes;
0072     //! List LVs that should *not* have automatic hit mapping
0073     std::unordered_set<G4LogicalVolume const*> skip_volumes;
0074 
0075     //! True if SD is enabled
0076     explicit operator bool() const { return this->enabled; }
0077 };
0078 
0079 //---------------------------------------------------------------------------//
0080 /*!
0081  * Control options for initializing Celeritas.
0082  *
0083  * The interface for the "along-step factory" (input parameters and output) is
0084  * described in \c AlongStepFactoryInterface .
0085  */
0086 struct SetupOptions
0087 {
0088     //!@{
0089     //! \name Type aliases
0090     using size_type = unsigned int;
0091     using real_type = double;
0092 
0093     using SPConstAction = std::shared_ptr<CoreStepActionInterface const>;
0094     using AlongStepFactory
0095         = std::function<SPConstAction(AlongStepFactoryInput const&)>;
0096     using IntAccessor = std::function<int()>;
0097     using VecString = std::vector<std::string>;
0098     //!@}
0099 
0100     //! Don't limit the number of steps
0101     static constexpr size_type no_max_steps()
0102     {
0103         return static_cast<size_type>(-1);
0104     }
0105 
0106     //!@{
0107     //! \name I/O
0108     //! GDML filename (optional: defaults to exporting existing Geant4)
0109     std::string geometry_file;
0110     //! Filename for JSON diagnostic output
0111     std::string output_file;
0112     //! Filename for ROOT dump of physics data
0113     std::string physics_output_file;
0114     //! Filename to dump a HepMC3 copy of offloaded tracks as events
0115     std::string offload_output_file;
0116     //!@}
0117 
0118     //!@{
0119     //! \name Celeritas stepper options
0120     //! Number of track "slots" to be transported simultaneously
0121     size_type max_num_tracks{};
0122     //! Maximum number of events in use
0123     size_type max_num_events{};
0124     //! Limit on number of step iterations before aborting
0125     size_type max_steps = no_max_steps();
0126     //! Maximum number of track initializers (primaries+secondaries)
0127     size_type initializer_capacity{};
0128     //! At least the average number of secondaries per track slot
0129     real_type secondary_stack_factor{3.0};
0130     //! Number of tracks to buffer before offloading (if unset: max num tracks)
0131     size_type auto_flush{};
0132     //!@}
0133 
0134     //!@{
0135     //! \name Track reordering options
0136     TrackOrder track_order{Device::num_devices() ? TrackOrder::init_charge
0137                                                  : TrackOrder::none};
0138     //!@}
0139 
0140     //! Set the number of streams (defaults to run manager # threads)
0141     IntAccessor get_num_streams;
0142 
0143     //!@{
0144     //! \name Stepping actions
0145     AlongStepFactory make_along_step;
0146     //!@}
0147 
0148     //!@{
0149     //! \name Field options
0150     short int max_field_substeps{100};
0151     //!@}
0152 
0153     //!@{
0154     //! \name Sensitive detector options
0155     SDSetupOptions sd;
0156     //!@}
0157 
0158     //!@{
0159     //! \name Physics options
0160     //! Ignore the following EM process names
0161     VecString ignore_processes;
0162     //!@}
0163 
0164     //!@{
0165     //! \name CUDA options
0166     size_type cuda_stack_size{};
0167     size_type cuda_heap_size{};
0168     //! Sync the GPU at every kernel for timing
0169     bool action_times{false};
0170     //! Launch all kernels on the default stream
0171     bool default_stream{false};
0172     //!@}
0173 
0174     //!@{
0175     //! \name Diagnostic setup
0176     //! Filename base for slot diagnostics
0177     std::string slot_diagnostic_prefix;
0178     //!@}
0179 };
0180 
0181 //---------------------------------------------------------------------------//
0182 // FREE FUNCTIONS
0183 //---------------------------------------------------------------------------//
0184 
0185 // Find volumes by name for SDSetupOptions
0186 std::unordered_set<G4LogicalVolume const*>
0187     FindVolumes(std::unordered_set<std::string>);
0188 
0189 //---------------------------------------------------------------------------//
0190 }  // namespace celeritas