Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:21:12

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 accel/SetupOptions.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <functional>
0010 #include <memory>
0011 #include <string>
0012 #include <unordered_set>
0013 #include <vector>
0014 
0015 #include "celeritas/Types.hh"
0016 #include "celeritas/global/ActionInterface.hh"
0017 #include "celeritas/inp/Physics.hh"
0018 
0019 class G4LogicalVolume;
0020 
0021 namespace celeritas
0022 {
0023 namespace inp
0024 {
0025 struct FrameworkInput;
0026 struct GeantSd;
0027 }
0028 
0029 class CoreParams;
0030 struct AlongStepFactoryInput;
0031 //---------------------------------------------------------------------------//
0032 /*!
0033  * Control options for initializing Celeritas SD callbacks.
0034  *
0035  * By default, Celeritas connects to Geant4 sensitive detectors so that it
0036  * reconstructs full-fidelity hits with all available step information.
0037  * - If your problem has no SDs, you must set \c enabled to \c false.
0038  * - By default, steps that do not deposit energy do not generate any hits.
0039  * - To improve performance and memory usage, determine what quantities (time,
0040  *   position, direction, touchable, ...) are required by your setup's
0041  *   sensitive detectors and set all other attributes to \c false.
0042  * - Reconstructing the full geometry status using \c locate_touchable is the
0043  *   most expensive detector option. Disable it unless your SDs require (e.g.)
0044  *   the volume's copy number to locate a detector submodule.
0045  * - Some reconstructed track attributes (such as post-step material) are
0046  *   currently never set because they are rarely used in practice. Contact the
0047  *   Celeritas team or submit a pull request to add this functionality.
0048  *
0049  * Various attributes on the step, track, and pre/post step points may be
0050  * available depending on the selected options.
0051  * - Disabling \c track will leave \c G4Step::GetTrack as \c nullptr .
0052  * - Enabling \c track will set the \c Charge attribute on the
0053  *   pre-step.
0054  * - Requested post-step data including \c GlobalTime, \c Position, \c
0055  *   KineticEnergy, and \c MomentumDirection will be copied to the \c Track
0056  *   when the combination of options is enabled.
0057  * - Some pre-step properties (\c Material and \c MaterialCutsCouple, and
0058  *   sensitive detector) are always updated. Post-step values for those are not
0059  *   set.
0060  * - Track and Parent IDs will \em never be a valid value since Celeritas track
0061  *   counters are independent from Geant4 track counters. Similarly, special
0062  *   Geant4 user-defined \c UserInformation and \c AuxiliaryTrackInformation
0063  *   are never set.
0064  *
0065  * The \c force_volumes option can be used for unusual cases (i.e., when using
0066  * a custom run manager) that do not define SDs on the "master" thread.
0067  * Similarly, the \c skip_volumes option allows optimized GPU-defined SDs to be
0068  * used in place of a Geant4 callback. For both options, the \c
0069  * FindVolumes helper function can be used to determine LV pointers from
0070  * the volume names.
0071  *
0072  * \note These setup options affect only the \c GeantSd construction that is
0073  * responsible for reconstructing CPU hits and sending directly to the Geant4
0074  * detectors. It does not change the underlying physics.
0075  *
0076  * \note This class will be replaced in v1.0
0077  *       by \c celeritas::inp::SensitiveDetector .
0078  */
0079 struct SDSetupOptions
0080 {
0081     struct StepPoint
0082     {
0083         bool global_time{true};
0084         bool position{true};
0085         bool direction{true};  //!< AKA momentum direction
0086         bool kinetic_energy{true};
0087     };
0088 
0089     //! Call back to Geant4 sensitive detectors
0090     bool enabled{true};
0091     //! Skip steps that do not deposit energy locally
0092     bool ignore_zero_deposition{true};
0093     //! Save energy deposition
0094     bool energy_deposition{true};
0095     //! Save physical step length
0096     bool step_length{true};
0097     //! Set TouchableHandle for PreStepPoint
0098     bool locate_touchable{true};
0099     //! Set TouchableHandle for PostStepPoint
0100     bool locate_touchable_post{true};
0101     //! Create a track with the dynamic particle type and post-step data
0102     bool track{true};
0103     //! Options for saving and converting beginning-of-step data
0104     StepPoint pre;
0105     //! Options for saving and converting end-of-step data
0106     StepPoint post;
0107 
0108     //! Manually list LVs that don't have an SD on the master thread
0109     std::unordered_set<G4LogicalVolume const*> force_volumes;
0110     //! List LVs that should *not* have automatic hit mapping
0111     std::unordered_set<G4LogicalVolume const*> skip_volumes;
0112 
0113     //! True if SD is enabled
0114     explicit operator bool() const { return this->enabled; }
0115 };
0116 
0117 //---------------------------------------------------------------------------//
0118 /*!
0119  * Control options for initializing Celeritas.
0120  *
0121  * The interface for the "along-step factory" (input parameters and output) is
0122  * described in \c AlongStepFactoryInterface .
0123  *
0124  * \note This class will be replaced in v1.0
0125  *       by \c celeritas::inp::FrameworkInput .
0126  */
0127 struct SetupOptions
0128 {
0129     //!@{
0130     //! \name Type aliases
0131     using size_type = unsigned int;
0132     using real_type = double;
0133 
0134     using SPConstAction = std::shared_ptr<CoreStepActionInterface const>;
0135     using AlongStepFactory
0136         = std::function<SPConstAction(AlongStepFactoryInput const&)>;
0137     using IntAccessor = std::function<int()>;
0138     using VecString = std::vector<std::string>;
0139     //!@}
0140 
0141     //! Don't limit the number of steps
0142     static constexpr size_type no_max_steps()
0143     {
0144         return static_cast<size_type>(-1);
0145     }
0146 
0147     //!@{
0148     //! \name I/O
0149 
0150     //! GDML filename (optional: defaults to exporting existing Geant4)
0151     std::string geometry_file;
0152     //! Filename for JSON diagnostic output, empty to disable
0153     std::string output_file{"celeritas.out.json"};
0154     //! Filename for ROOT dump of physics data
0155     std::string physics_output_file;
0156     //! Filename to dump a ROOT/HepMC3 copy of offloaded tracks as events
0157     std::string offload_output_file;
0158     //! Filename to dump a GDML file for debugging inside frameworks
0159     std::string geometry_output_file;
0160     //!@}
0161 
0162     //!@{
0163     //! \name Celeritas stepper options
0164 
0165     //! Number of track "slots" to be transported simultaneously
0166     size_type max_num_tracks{};
0167     //! Maximum number of events in use (DEPRECATED: remove in v0.7)
0168     size_type max_num_events{};
0169     //! Limit on number of steps per track before killing
0170     size_type max_steps = no_max_steps();
0171     //! Limit on number of step iterations before aborting
0172     size_type max_step_iters = no_max_steps();
0173     //! Maximum number of track initializers (primaries+secondaries)
0174     size_type initializer_capacity{};
0175     //! At least the average number of secondaries per track slot
0176     real_type secondary_stack_factor{3.0};
0177     //! Number of tracks to buffer before offloading (if unset: max num tracks)
0178     size_type auto_flush{};
0179     //!@}
0180 
0181     //!@{
0182     //! \name Track reordering options
0183     TrackOrder track_order{TrackOrder::size_};
0184     //!@}
0185 
0186     //! Set the number of streams (defaults to run manager # threads)
0187     IntAccessor get_num_streams;
0188 
0189     //!@{
0190     //! \name Stepping actions
0191 
0192     AlongStepFactory make_along_step;
0193     //!@}
0194 
0195     //!@{
0196     //! \name Field options
0197 
0198     size_type max_field_substeps{10};
0199     //!@}
0200 
0201     //! Sensitive detector options
0202     SDSetupOptions sd;
0203 
0204     //!@{
0205     //! \name Physics options
0206 
0207     //! Do not use Celeritas physics for the given Geant4 process names
0208     VecString ignore_processes;
0209     //! Physics grid interpolation options
0210     inp::Interpolation interpolation{};
0211     //!@}
0212 
0213     //!@{
0214     //! \name CUDA options
0215 
0216     //! Per-thread stack size (may be needed for VecGeom) [B]
0217     size_type cuda_stack_size{};
0218     //! Dynamic heap size (may be needed for VecGeom) [B]
0219     size_type cuda_heap_size{};
0220     //! Sync the GPU at every kernel for timing
0221     bool action_times{false};
0222     //! Launch all kernels on the default stream for debugging (REMOVED)
0223     bool default_stream{false};
0224     //!@}
0225 
0226     //!@{
0227     //! \name Diagnostic setup
0228 
0229     //! Filename base for slot diagnostics
0230     std::string slot_diagnostic_prefix;
0231 
0232     //! Add additional diagnostic user actions [EXPERIMENTAL]
0233     std::function<void(CoreParams const&)> add_user_actions;
0234 
0235     //!@}
0236 
0237     explicit inline operator bool() const
0238     {
0239         return max_num_tracks > 0 && static_cast<bool>(make_along_step);
0240     }
0241 };
0242 
0243 //---------------------------------------------------------------------------//
0244 // FREE FUNCTIONS
0245 //---------------------------------------------------------------------------//
0246 
0247 // Find volumes by name for SDSetupOptions
0248 std::unordered_set<G4LogicalVolume const*>
0249     FindVolumes(std::unordered_set<std::string>);
0250 
0251 // Convert SD options for forward compatibility
0252 inp::GeantSd to_inp(SDSetupOptions const& so);
0253 
0254 // Construct a framework input
0255 inp::FrameworkInput to_inp(SetupOptions const& so);
0256 
0257 //---------------------------------------------------------------------------//
0258 }  // namespace celeritas