Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:20

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file celeritas/ext/detail/GeantMaterialPropertyGetter.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <string>
0011 #include <G4Material.hh>
0012 
0013 #include "celeritas/io/ImportPhysicsVector.hh"
0014 #include "celeritas/io/ImportUnits.hh"
0015 
0016 #include "GeantProcessImporter.hh"
0017 
0018 namespace celeritas
0019 {
0020 namespace detail
0021 {
0022 //---------------------------------------------------------------------------//
0023 /*!
0024  * Retrieve and store optical material properties, if present.
0025  */
0026 struct GeantMaterialPropertyGetter
0027 {
0028     using MPT = G4MaterialPropertiesTable;
0029 
0030     MPT const& mpt;
0031 
0032     //! Get property for a single double
0033     bool operator()(double* dst, char const* name, ImportUnits q)
0034     {
0035         if (!mpt.ConstPropertyExists(name))
0036         {
0037             return false;
0038         }
0039         *dst = mpt.GetConstProperty(name) * native_value_from_clhep(q);
0040         return true;
0041     }
0042 
0043     //! Get property for a single double
0044     bool operator()(double* dst, std::string name, int comp, ImportUnits q)
0045     {
0046         // Geant4 10.6 and earlier require a const char* argument
0047         name += std::to_string(comp);
0048         return (*this)(dst, name.c_str(), q);
0049     }
0050 
0051     //! Get property for a physics vector
0052     bool
0053     operator()(ImportPhysicsVector* dst, std::string const& name, ImportUnits q)
0054     {
0055         // Geant4@10.7: G4MaterialPropertiesTable.GetProperty is not const
0056         // and <=10.6 require const char*
0057         auto const* g4vector = const_cast<MPT&>(mpt).GetProperty(name.c_str());
0058         if (!g4vector)
0059         {
0060             return false;
0061         }
0062         *dst = import_physics_vector(*g4vector, {ImportUnits::mev, q});
0063         return true;
0064     }
0065 };
0066 
0067 //---------------------------------------------------------------------------//
0068 }  // namespace detail
0069 }  // namespace celeritas