Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-01 10:03:33

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/ext/GeantImporter.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Config.hh"
0010 
0011 #include "celeritas/io/ImportData.hh"
0012 #include "celeritas/io/ImporterInterface.hh"
0013 
0014 #include "GeantSetup.hh"
0015 
0016 // Geant4 forward declarations
0017 class G4VPhysicalVolume;  // IWYU pragma: keep
0018 class G4ParticleDefinition;  // IWYU pragma: keep
0019 
0020 namespace celeritas
0021 {
0022 //---------------------------------------------------------------------------//
0023 //! DEPRECATED: Only import a subset of available Geant4 data
0024 struct GeantImportDataSelection
0025 {
0026     //! Bit flags for selecting particles and process types
0027     using Flags = unsigned int;
0028     enum : unsigned int
0029     {
0030         none = 0x0,
0031         dummy = 0x1,  //!< Dummy particles+processes
0032         em_basic = 0x2,  //!< Electron, positron, gamma
0033         em_ex = 0x4,  //!< Extended EM particles
0034         optical = 0x8,  //!< Optical particles and processes
0035         em = em_basic | em_ex,  //!< Any EM
0036         hadron = 0x10,  //!< Hadronic particles and processes
0037     };
0038 
0039     Flags particles = em | optical;
0040     bool materials = true;
0041     Flags processes = em | optical;
0042 
0043     // TODO expand/set reader flags automatically based on loaded processes
0044     bool reader_data = true;
0045 
0046     //! Linear (default) or spline interpolation (for grids that support it)
0047     inp::Interpolation interpolation{};
0048 };
0049 
0050 //---------------------------------------------------------------------------//
0051 /*!
0052  * Load problem data directly from Geant4.
0053  *
0054  * This can be used to circumvent ROOT as a serialization tool, whether to
0055  * simplify the toolchain or to integrate better with user frameworks. As much
0056  * data as possible is imported (subject to the data selection); downstream
0057  * Celeritas classes will validate the imported data as needed.
0058  *
0059  * \code
0060     GeantImporter import(GeantSetup("blah.gdml"));
0061     ImportData data = import();
0062    \endcode
0063  * or to import from an existing, initialized Geant4 state:
0064  * \code
0065     GeantImporter import(world_volume);
0066     ImportData data = import();
0067    \endcode
0068  */
0069 class GeantImporter final : public ImporterInterface
0070 {
0071   public:
0072     //!@{
0073     //! \name Type aliases
0074     using DataSelection = GeantImportDataSelection;
0075     using SPGeantGeo = GeantSetup::SPGeantGeo;
0076     //!@}
0077 
0078   public:
0079     // Construct from global Geant4 geometry, assuming physics is loaded
0080     GeantImporter();
0081 
0082     // Construct by capturing a GeantSetup object
0083     explicit GeantImporter(GeantSetup&& setup);
0084 
0085     // Fill data from Geant4
0086     ImportData operator()(DataSelection const& selection);
0087 
0088     //! Fill all available data from Geant4
0089     ImportData operator()() final { return (*this)(DataSelection{}); }
0090 
0091     //! Get the constructed geometry if using setup (may be null)
0092     SPGeantGeo const& geo_params() const { return setup_.geo_params(); }
0093 
0094   private:
0095     // Optional setup if celeritas handles initialization
0096     GeantSetup setup_;
0097 };
0098 
0099 //---------------------------------------------------------------------------//
0100 // INLINE DEFINITIONS
0101 //---------------------------------------------------------------------------//
0102 inline constexpr bool operator==(GeantImporter::DataSelection const& lhs,
0103                                  GeantImporter::DataSelection const& rhs)
0104 {
0105     // clang-format off
0106     return    lhs.particles == rhs.particles
0107            && lhs.materials == rhs.materials
0108            && lhs.processes == rhs.processes
0109            && lhs.reader_data == rhs.reader_data;
0110     // clang-format on
0111 }
0112 
0113 inline constexpr bool operator!=(GeantImporter::DataSelection const& lhs,
0114                                  GeantImporter::DataSelection const& rhs)
0115 {
0116     return !(lhs == rhs);
0117 }
0118 
0119 #if !CELERITAS_USE_GEANT4
0120 inline GeantImporter::GeantImporter()
0121 {
0122     CELER_NOT_CONFIGURED("Geant4");
0123 }
0124 
0125 inline GeantImporter::GeantImporter(GeantSetup&&)
0126 {
0127     CELER_NOT_CONFIGURED("Geant4");
0128 }
0129 
0130 inline ImportData GeantImporter::operator()(DataSelection const&)
0131 {
0132     CELER_ASSERT_UNREACHABLE();
0133 }
0134 #endif
0135 
0136 //---------------------------------------------------------------------------//
0137 }  // namespace celeritas