Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-08 10:11:15

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/detail/GeantSurfacePhysicsHelper.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <ostream>
0010 #include <G4LogicalSurface.hh>
0011 #include <G4OpticalSurface.hh>
0012 
0013 #include "corecel/inp/Grid.hh"
0014 #include "geocel/GeantGeoParams.hh"
0015 #include "geocel/Types.hh"
0016 
0017 #include "GeantMaterialPropertyGetter.hh"
0018 
0019 namespace celeritas
0020 {
0021 namespace detail
0022 {
0023 //---------------------------------------------------------------------------//
0024 /*!
0025  * Helper class to load optical surface properties.
0026  *
0027  * Used by \c GeantSurfacePhysicsLoader .
0028  */
0029 class GeantSurfacePhysicsHelper
0030 {
0031   public:
0032     // Construct with SurfaceId; this expects a valid GeantGeoParams
0033     explicit GeantSurfacePhysicsHelper(SurfaceId sid);
0034 
0035     //! True if optical surface properties are attached
0036     explicit operator bool() const { return surface_ != nullptr; }
0037 
0038     // Get optical surface id
0039     SurfaceId surface_id() const { return sid_; }
0040 
0041     // Get Geant4 optical surface
0042     G4OpticalSurface const& surface() const;
0043 
0044     // Access the raw property getter for this surface
0045     GeantMaterialPropertyGetter const& property_getter() const
0046     {
0047         CELER_ASSERT(*this);
0048         return get_property_;
0049     }
0050 
0051     // Populate Grid optical property from name, in [MeV, unitless]
0052     bool get_property(inp::Grid& dst, std::string const& name) const;
0053 
0054   private:
0055     SurfaceId sid_;
0056     G4OpticalSurface const* surface_;
0057     GeantMaterialPropertyGetter get_property_;
0058 };
0059 
0060 //---------------------------------------------------------------------------//
0061 // INLINE DEFINITIONS
0062 //---------------------------------------------------------------------------//
0063 /*!
0064  * Construct with valid SurfaceId. A GeantGeoParams in a valid state is also
0065  * required.
0066  */
0067 GeantSurfacePhysicsHelper::GeantSurfacePhysicsHelper(SurfaceId sid) : sid_(sid)
0068 {
0069     CELER_EXPECT(sid_);
0070     auto geo = celeritas::global_geant_geo().lock();
0071     CELER_ASSERT(geo);
0072     auto const* g4log_surf = geo->id_to_geant(sid);
0073     CELER_ASSERT(g4log_surf);
0074     auto* g4surf_prop = g4log_surf->GetSurfaceProperty();
0075     CELER_ASSERT(g4surf_prop);
0076     surface_ = dynamic_cast<G4OpticalSurface*>(g4surf_prop);
0077     if (surface_)
0078     {
0079         // The surface may not be an optical surface, or it might have no
0080         // properties
0081         get_property_ = GeantMaterialPropertyGetter{
0082             surface_->GetMaterialPropertiesTable(), surface_->GetName()};
0083     }
0084 }
0085 
0086 //---------------------------------------------------------------------------//
0087 /*!
0088  * Get Geant4 optical surface.
0089  */
0090 G4OpticalSurface const& GeantSurfacePhysicsHelper::surface() const
0091 {
0092     CELER_ASSERT(*this);
0093     return *surface_;
0094 }
0095 
0096 //---------------------------------------------------------------------------//
0097 /*!
0098  * Get mev-to-unitless grid property from material properties table.
0099  *
0100  * \note Currently all imported parameters are in [energy] vs. [unitless], and
0101  * therefore units are abstracted from the function call. The grids currently
0102  * pulled by this helper are:
0103  * - Reflectivity
0104  * - Transmittance
0105  * - Efficiency
0106  * - Specular spike
0107  * - Specular lobe
0108  * - Backscatter
0109  * - Surface refractive index
0110  */
0111 bool GeantSurfacePhysicsHelper::get_property(inp::Grid& dst,
0112                                              std::string const& name) const
0113 {
0114     auto loaded
0115         = get_property_(dst, name, {ImportUnits::mev, ImportUnits::unitless});
0116     return loaded;
0117 }
0118 
0119 //---------------------------------------------------------------------------//
0120 // FREE FUNCTIONS
0121 //---------------------------------------------------------------------------//
0122 //! Write surface name and surface id to a stream
0123 inline std::ostream& operator<<(std::ostream& os,
0124                                 GeantSurfacePhysicsHelper const& helper)
0125 {
0126     os << helper.property_getter()
0127        << " (surface id=" << helper.surface_id().unchecked_get() << ")";
0128     return os;
0129 }
0130 
0131 //---------------------------------------------------------------------------//
0132 }  // namespace detail
0133 }  // namespace celeritas