![]() |
|
|||
File indexing completed on 2025-02-22 10:31:30
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 celeritas/phys/PrimaryGeneratorOptions.hh 0007 //---------------------------------------------------------------------------// 0008 #pragma once 0009 0010 #include <algorithm> 0011 #include <functional> 0012 #include <random> 0013 0014 #include "corecel/io/StringEnumMapper.hh" 0015 #include "geocel/Types.hh" 0016 0017 #include "PDGNumber.hh" 0018 0019 namespace celeritas 0020 { 0021 //---------------------------------------------------------------------------// 0022 //! Distribution selection for sampling quantities in a \c PrimaryGenerator 0023 enum class DistributionSelection 0024 { 0025 delta, 0026 isotropic, 0027 box, 0028 size_ 0029 }; 0030 0031 //---------------------------------------------------------------------------// 0032 /*! 0033 * Distribution type and parameters. 0034 */ 0035 struct DistributionOptions 0036 { 0037 DistributionSelection distribution{DistributionSelection::size_}; 0038 std::vector<real_type> params; 0039 0040 //! Whether the options are valid 0041 explicit operator bool() const 0042 { 0043 return distribution != DistributionSelection::size_; 0044 } 0045 }; 0046 0047 //---------------------------------------------------------------------------// 0048 /*! 0049 * Primary generator options. 0050 * 0051 * TODO: distributions should be std::variant (see ORANGE input) 0052 * 0053 * - \c seed: RNG seed 0054 * - \c pdg: PDG numbers of the primaries. An equal number of primaries of each 0055 * type will be generated 0056 * - \c num_events: total number of events to generate 0057 * - \c primaries_per_event: number of primaries to generate in each event 0058 * - \c energy: energy distribution type and parameters 0059 * - \c position: spatial distribution type and parameters 0060 * - \c direction: angular distribution type and parameters 0061 */ 0062 struct PrimaryGeneratorOptions 0063 { 0064 unsigned int seed{}; 0065 std::vector<PDGNumber> pdg; 0066 size_type num_events{}; 0067 size_type primaries_per_event{}; 0068 DistributionOptions energy; 0069 DistributionOptions position; 0070 DistributionOptions direction; 0071 0072 //! Whether the options are valid 0073 explicit operator bool() const 0074 { 0075 return !pdg.empty() 0076 && std::all_of(pdg.begin(), 0077 pdg.end(), 0078 [](PDGNumber p) { return static_cast<bool>(p); }) 0079 && num_events > 0 && primaries_per_event > 0 && energy 0080 && position && direction; 0081 } 0082 }; 0083 0084 // TODO: move to PrimaryGenerator.hh 0085 0086 using PrimaryGeneratorEngine = std::mt19937; 0087 0088 //---------------------------------------------------------------------------// 0089 // FREE FUNCTIONS 0090 //---------------------------------------------------------------------------// 0091 0092 // Get a distribution name 0093 char const* to_cstring(DistributionSelection value); 0094 0095 // TODO: move these to PrimaryGenerator.hh 0096 //! \cond 0097 0098 // Return a distribution for sampling the energy 0099 std::function<real_type(PrimaryGeneratorEngine&)> 0100 make_energy_sampler(DistributionOptions options); 0101 0102 // Return a distribution for sampling the position 0103 std::function<Real3(PrimaryGeneratorEngine&)> 0104 make_position_sampler(DistributionOptions options); 0105 0106 // Return a distribution for sampling the direction 0107 std::function<Real3(PrimaryGeneratorEngine&)> 0108 make_direction_sampler(DistributionOptions options); 0109 0110 //! \endcond 0111 //---------------------------------------------------------------------------// 0112 } // namespace celeritas
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |