Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:53:37

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 
0025 //---------------------------------------------------------------------------//
0026 /*!
0027  * Construct a Geant 4 run manager and populate internal Geant4 physics.
0028  *
0029  * This is usually passed directly into \c GeantImporter . It hides Geant4
0030  * implementation details (including header files) from the rest of the code.
0031  * It is safe to include even when Geant4 is unavailable!
0032  *
0033  * The setup is targeted specifically for physics that Celeritas supports.
0034  */
0035 class GeantSetup
0036 {
0037   public:
0038     //!@{
0039     //! \name Type aliases
0040     using Options = GeantPhysicsOptions;
0041     //!@}
0042 
0043   public:
0044     // Construct from a GDML file and physics options
0045     GeantSetup(std::string const& gdml_filename, Options options);
0046 
0047     // Default constructor
0048     GeantSetup() = default;
0049 
0050     // Terminate run on destruction
0051     ~GeantSetup();
0052 
0053     //! Prevent copying but allow moving
0054     CELER_DEFAULT_MOVE_DELETE_COPY(GeantSetup);
0055 
0056     // Get the world detector volume
0057     inline G4VPhysicalVolume const* world() const;
0058 
0059     //! True if we own a run manager
0060     explicit operator bool() const { return static_cast<bool>(run_manager_); }
0061 
0062   private:
0063     struct RMDeleter
0064     {
0065         void operator()(G4RunManager*) const;
0066     };
0067     using RMUniquePtr = std::unique_ptr<G4RunManager, RMDeleter>;
0068 
0069     RMUniquePtr run_manager_{nullptr};
0070     G4VPhysicalVolume* world_{nullptr};
0071 };
0072 
0073 //---------------------------------------------------------------------------//
0074 // FREE FUNCTIONS
0075 
0076 //---------------------------------------------------------------------------//
0077 // INLINE DEFINITIONS
0078 //---------------------------------------------------------------------------//
0079 /*!
0080  * Get the world detector volume.
0081  */
0082 G4VPhysicalVolume const* GeantSetup::world() const
0083 {
0084     CELER_EXPECT(*this);
0085     return world_;
0086 }
0087 
0088 #if !CELERITAS_USE_GEANT4
0089 inline GeantSetup::GeantSetup(std::string const&, Options)
0090 {
0091     CELER_NOT_CONFIGURED("Geant4");
0092 }
0093 
0094 inline GeantSetup::~GeantSetup() = default;
0095 
0096 inline void GeantSetup::RMDeleter::operator()(G4RunManager*) const
0097 {
0098     CELER_ASSERT_UNREACHABLE();
0099 }
0100 #endif
0101 
0102 //---------------------------------------------------------------------------//
0103 }  // namespace celeritas