File indexing completed on 2026-11-08 10:11:15
0001
0002
0003
0004
0005
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
0026
0027
0028
0029 class GeantSurfacePhysicsHelper
0030 {
0031 public:
0032
0033 explicit GeantSurfacePhysicsHelper(SurfaceId sid);
0034
0035
0036 explicit operator bool() const { return surface_ != nullptr; }
0037
0038
0039 SurfaceId surface_id() const { return sid_; }
0040
0041
0042 G4OpticalSurface const& surface() const;
0043
0044
0045 GeantMaterialPropertyGetter const& property_getter() const
0046 {
0047 CELER_ASSERT(*this);
0048 return get_property_;
0049 }
0050
0051
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
0062
0063
0064
0065
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
0080
0081 get_property_ = GeantMaterialPropertyGetter{
0082 surface_->GetMaterialPropertiesTable(), surface_->GetName()};
0083 }
0084 }
0085
0086
0087
0088
0089
0090 G4OpticalSurface const& GeantSurfacePhysicsHelper::surface() const
0091 {
0092 CELER_ASSERT(*this);
0093 return *surface_;
0094 }
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
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
0121
0122
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 }
0133 }