Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 08:18:04

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/GeantSetup.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <memory>
0010 #include <string>
0011 
0012 #include "corecel/Config.hh"
0013 
0014 #include "corecel/Assert.hh"
0015 
0016 #include "GeantPhysicsOptions.hh"
0017 
0018 // Geant4 forward declarations
0019 class G4VPhysicalVolume;
0020 class G4RunManager;
0021 
0022 namespace celeritas
0023 {
0024 class GeantGeoParams;
0025 
0026 //---------------------------------------------------------------------------//
0027 /*!
0028  * Construct a Geant 4 run manager and populate internal Geant4 physics.
0029  *
0030  * This is usually passed directly into \c GeantImporter . It hides Geant4
0031  * implementation details (including header files) from the rest of the code.
0032  * It is safe to include even when Geant4 is unavailable!
0033  *
0034  * The setup is targeted specifically for physics that Celeritas supports.
0035  *
0036  * \todo This is a hot mess; it needs to be unified with inp/setup and not
0037  * passed around by moving it.
0038  */
0039 class GeantSetup
0040 {
0041   public:
0042     //!@{
0043     //! \name Type aliases
0044     using Options = GeantPhysicsOptions;
0045     using SPGeantGeo = std::shared_ptr<GeantGeoParams>;
0046     //!@}
0047 
0048   public:
0049     // Construct from a GDML file and physics options
0050     GeantSetup(std::string const& gdml_filename, Options options);
0051 
0052     // Default constructor
0053     GeantSetup() = default;
0054 
0055     // Terminate run on destruction
0056     ~GeantSetup();
0057 
0058     //! Prevent copying but allow moving
0059     CELER_DEFAULT_MOVE_DELETE_COPY(GeantSetup);
0060 
0061     //! Get the constructed geometry
0062     SPGeantGeo const& geo_params() const { return geo_; }
0063 
0064     //! True if we own a run manager
0065     explicit operator bool() const { return static_cast<bool>(run_manager_); }
0066 
0067   private:
0068     struct RMDeleter
0069     {
0070         void operator()(G4RunManager*) const;
0071     };
0072     using RMUniquePtr = std::unique_ptr<G4RunManager, RMDeleter>;
0073 
0074     RMUniquePtr run_manager_{nullptr};
0075     SPGeantGeo geo_;
0076 };
0077 
0078 //---------------------------------------------------------------------------//
0079 // INLINE DEFINITIONS
0080 #if !CELERITAS_USE_GEANT4
0081 inline GeantSetup::GeantSetup(std::string const&, Options)
0082 {
0083     CELER_NOT_CONFIGURED("Geant4");
0084 }
0085 
0086 inline GeantSetup::~GeantSetup() = default;
0087 
0088 inline void GeantSetup::RMDeleter::operator()(G4RunManager*) const
0089 {
0090     CELER_ASSERT_UNREACHABLE();
0091 }
0092 #endif
0093 
0094 //---------------------------------------------------------------------------//
0095 }  // namespace celeritas