Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-29 09:13:54

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 geocel/GeoOpticalIdMap.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <vector>
0010 #include <G4MaterialTable.hh>
0011 
0012 #include "geocel/Types.hh"
0013 
0014 namespace celeritas
0015 {
0016 //---------------------------------------------------------------------------//
0017 
0018 //! Opaque index to a material with optical properties
0019 using OptMatId = OpaqueId<struct OpticalMaterial_, unsigned int>;
0020 
0021 //---------------------------------------------------------------------------//
0022 /*!
0023  * Construct optical material IDs and map from a geometry material ID.
0024  *
0025  * This construct a material -> optical material mapping based on whether the
0026  * \c RINDEX table is present on a Geant4 material.
0027  *
0028  * As a reminder, \em geometry materials correspond to \c G4Material and
0029  * \em physics materials correspond to \c G4MaterialCutsCouple .
0030  *
0031  * \todo Use GeantGeoParams (or an upcoming GeantModel) to translate geometry
0032  * IDs: the G4Material's "index" can be offset from the GeantGeoParams material
0033  * if the geometry has been reloaded.
0034  *
0035  * \todo This class is a physics-specific mapping and should live in celeritas
0036  */
0037 class GeoOpticalIdMap
0038 {
0039   public:
0040     //! Construct without optical materials
0041     GeoOpticalIdMap() = default;
0042 
0043     // Construct from underlying Geant4 objects
0044     explicit GeoOpticalIdMap(G4MaterialTable const&);
0045 
0046     // Return the optical ID corresponding to a geo ID
0047     inline OptMatId operator[](GeoMatId) const;
0048 
0049     //! True if no optical materials are present
0050     bool empty() const { return geo_to_opt_.empty(); }
0051 
0052     //! Number of geometry materials
0053     GeoMatId::size_type num_geo() const { return geo_to_opt_.size(); }
0054 
0055     //! Number of optical materials
0056     OptMatId::size_type num_optical() const { return num_optical_; }
0057 
0058   private:
0059     std::vector<OptMatId> geo_to_opt_;
0060     OptMatId::size_type num_optical_{};
0061 };
0062 
0063 //---------------------------------------------------------------------------//
0064 // INLINE DEFINITIONS
0065 //---------------------------------------------------------------------------//
0066 /*!
0067  * Return the optical ID corresponding to a geo ID.
0068  *
0069  * The result \em may be a "null" ID if there's no associated optical physics.
0070  */
0071 OptMatId GeoOpticalIdMap::operator[](GeoMatId m) const
0072 {
0073     CELER_EXPECT(!this->empty());
0074     CELER_EXPECT(m < this->num_geo());
0075 
0076     return geo_to_opt_[m.get()];
0077 }
0078 
0079 //---------------------------------------------------------------------------//
0080 }  // namespace celeritas