Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:54:41

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/GeantMaterialPropertyGetter.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <string>
0010 #include <G4Material.hh>
0011 
0012 #include "celeritas/inp/Grid.hh"
0013 #include "celeritas/io/ImportUnits.hh"
0014 
0015 #include "GeantProcessImporter.hh"
0016 
0017 namespace celeritas
0018 {
0019 namespace detail
0020 {
0021 //---------------------------------------------------------------------------//
0022 /*!
0023  * Retrieve and store optical material properties, if present.
0024  */
0025 struct GeantMaterialPropertyGetter
0026 {
0027     using MPT = G4MaterialPropertiesTable;
0028 
0029     MPT const& mpt;
0030 
0031     //! Get property for a single double
0032     bool operator()(double* dst, char const* name, ImportUnits q)
0033     {
0034         if (!mpt.ConstPropertyExists(name))
0035         {
0036             return false;
0037         }
0038         *dst = mpt.GetConstProperty(name) * native_value_from_clhep(q);
0039         return true;
0040     }
0041 
0042     //! Get property for a single double
0043     bool operator()(double* dst, std::string name, int comp, ImportUnits q)
0044     {
0045         // Geant4 10.6 and earlier require a const char* argument
0046         name += std::to_string(comp);
0047         return (*this)(dst, name.c_str(), q);
0048     }
0049 
0050     //! Get property for a physics vector
0051     bool
0052     operator()(inp::Grid* dst, std::string const& name, Array<ImportUnits, 2> q)
0053     {
0054         // Geant4@10.7: G4MaterialPropertiesTable.GetProperty is not const
0055         // and <=10.6 require const char*
0056         auto const* g4vector = const_cast<MPT&>(mpt).GetProperty(name.c_str());
0057         if (!g4vector)
0058         {
0059             return false;
0060         }
0061         *dst = import_physics_vector(*g4vector, q);
0062         return true;
0063     }
0064 };
0065 
0066 //---------------------------------------------------------------------------//
0067 }  // namespace detail
0068 }  // namespace celeritas