Back to home page

EIC code displayed by LXR

 
 

    


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

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/GeantOpticalMatHelper.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <ostream>
0010 #include <G4Material.hh>
0011 
0012 #include "celeritas/Types.hh"
0013 
0014 #include "GeantMaterialPropertyGetter.hh"
0015 
0016 namespace celeritas
0017 {
0018 namespace detail
0019 {
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * Helper class providing access to an optical material and its properties.
0023  *
0024  * Analogous to \c GeantSurfacePhysicsHelper but for optical materials
0025  * identified by \c OptMatId .
0026  */
0027 class GeantOpticalMatHelper
0028 {
0029   public:
0030     // Construct with optical material ID and corresponding G4Material pointer
0031     inline GeantOpticalMatHelper(OptMatId opt_mat_id,
0032                                  G4Material const* material);
0033 
0034     //! True if this helper is fully constructed and valid
0035     explicit operator bool() const { return material_ != nullptr; }
0036 
0037     // Get optical material ID
0038     OptMatId opt_mat_id() const { return opt_mat_id_; }
0039 
0040     // Get G4Material
0041     inline G4Material const& material() const;
0042 
0043     // Access the property getter for this material
0044     GeantMaterialPropertyGetter const& property_getter() const
0045     {
0046         CELER_ASSERT(*this);
0047         return getter_;
0048     }
0049 
0050   private:
0051     OptMatId opt_mat_id_;
0052     G4Material const* material_;
0053     GeantMaterialPropertyGetter getter_;
0054 };
0055 
0056 //---------------------------------------------------------------------------//
0057 // INLINE DEFINITIONS
0058 //---------------------------------------------------------------------------//
0059 /*!
0060  * Construct with optical material ID and G4Material pointer.
0061  *
0062  * The material pointer must not be null.
0063  */
0064 GeantOpticalMatHelper::GeantOpticalMatHelper(OptMatId opt_mat_id,
0065                                              G4Material const* material)
0066     : opt_mat_id_{opt_mat_id}
0067     , material_{material}
0068     , getter_{material->GetMaterialPropertiesTable(),
0069               material->GetName().c_str()}
0070 {
0071     CELER_EXPECT(opt_mat_id_);
0072     CELER_EXPECT(material_);
0073 }
0074 
0075 //---------------------------------------------------------------------------//
0076 /*!
0077  * Get the G4Material for this optical material.
0078  */
0079 G4Material const& GeantOpticalMatHelper::material() const
0080 {
0081     CELER_ASSERT(*this);
0082     return *material_;
0083 }
0084 
0085 //---------------------------------------------------------------------------//
0086 // FREE FUNCTIONS
0087 //---------------------------------------------------------------------------//
0088 //! Write material name and optical id to a stream
0089 inline std::ostream& operator<<(std::ostream& os,
0090                                 GeantOpticalMatHelper const& helper)
0091 {
0092     os << helper.property_getter()
0093        << " (optical id=" << helper.opt_mat_id().unchecked_get() << ")";
0094     return os;
0095 }
0096 
0097 //---------------------------------------------------------------------------//
0098 }  // namespace detail
0099 }  // namespace celeritas