Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 08:29:42

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsPlugins/Json/JsonMaterialDecorator.hpp"
0010 
0011 namespace Acts {
0012 
0013 JsonMaterialDecorator::JsonMaterialDecorator(
0014     const MaterialMapJsonConverter::Config& rConfig,
0015     const std::string& jFileName, Acts::Logging::Level level)
0016     : m_readerConfig(rConfig),
0017       m_logger{getDefaultLogger("JsonMaterialDecorator", level)} {
0018   // the material reader
0019   Acts::MaterialMapJsonConverter jmConverter(rConfig, level);
0020 
0021   ACTS_VERBOSE("Reading JSON material description from: " << jFileName);
0022   std::ifstream ifj(jFileName.c_str());
0023   if (!ifj.good()) {
0024     throw std::runtime_error{"Unable to open input JSON material file: " +
0025                              jFileName};
0026   }
0027   nlohmann::json jin;
0028 
0029   if (jFileName.find(".cbor") != std::string::npos) {
0030     std::vector<std::uint8_t> iCbor((std::istreambuf_iterator<char>(ifj)),
0031                                     std::istreambuf_iterator<char>());
0032     jin = nlohmann::json::from_cbor(iCbor);
0033   } else {
0034     ifj >> jin;
0035   }
0036 
0037   auto maps = jmConverter.jsonToMaterialMaps(jin);
0038   m_surfaceMaterialMap = maps.first;
0039   m_volumeMaterialMap = maps.second;
0040   ACTS_VERBOSE("JSON material description read complete");
0041 }
0042 
0043 void JsonMaterialDecorator::decorate(Surface& surface) const {
0044   ACTS_VERBOSE("Processing surface: " << surface.geometryId());
0045   // Try to find the surface in the map
0046   auto sMaterial = m_surfaceMaterialMap.find(surface.geometryId());
0047   if (sMaterial != m_surfaceMaterialMap.end()) {
0048     ACTS_VERBOSE("-> Found material for surface, assigning");
0049     surface.assignSurfaceMaterial(sMaterial->second);
0050   }
0051 }
0052 
0053 /// Decorate a TrackingVolume
0054 ///
0055 /// @param volume the non-cost volume that is decorated
0056 void JsonMaterialDecorator::decorate(TrackingVolume& volume) const {
0057   ACTS_VERBOSE("Processing volume: " << volume.geometryId());
0058   // Clear the material if registered to do so
0059   // Try to find the volume in the map
0060   auto vMaterial = m_volumeMaterialMap.find(volume.geometryId());
0061   if (vMaterial != m_volumeMaterialMap.end()) {
0062     ACTS_VERBOSE("-> Found material for volume, assigning");
0063     volume.assignVolumeMaterial(vMaterial->second);
0064   }
0065 }
0066 }  // namespace Acts