From 20c235057e7f5880fd63d59e8927e1897977de92 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Mon, 7 Jul 2025 12:38:49 +0200 Subject: [PATCH 01/30] snapshot --- Plugins/Root/CMakeLists.txt | 1 + .../Plugins/Root/RootMaterialMapAccessor.hpp | 106 ++++++++++++++++++ Plugins/Root/src/RootMaterialMapAccessor.cpp | 40 +++++++ 3 files changed, 147 insertions(+) create mode 100644 Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp create mode 100644 Plugins/Root/src/RootMaterialMapAccessor.cpp diff --git a/Plugins/Root/CMakeLists.txt b/Plugins/Root/CMakeLists.txt index dbbdd2ec49d..8fe4f8a7f0f 100644 --- a/Plugins/Root/CMakeLists.txt +++ b/Plugins/Root/CMakeLists.txt @@ -1,4 +1,5 @@ set(library_sources + src/RootMaterialMapAccessor.cpp src/RootMaterialTrackAccessor.cpp src/TGeoCylinderDiscSplitter.cpp src/TGeoDetectorElement.cpp diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp new file mode 100644 index 00000000000..edcbaff7592 --- /dev/null +++ b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp @@ -0,0 +1,106 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 CERN for the benefit of the ACTS project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma once + +#include + +class TFile; + +namespace Acts { + +class Surface; +class GeometryContext; + +/// Simple payload class that can be wrapped for reading +/// and writing. +class RootMaterialMapAccessor { + public: + struct Config { + /// The name of the output surface tree + std::string folderSurfaceNameBase = "SurfaceMaterial"; + /// The name of the output volume tree + std::string folderVolumeNameBase = "VolumeMaterial"; + /// The volume identification string + std::string voltag = "_vol"; + /// The boundary identification string + std::string boutag = "_bou"; + /// The layer identification string + std::string laytag = "_lay"; + /// The approach identification string + std::string apptag = "_app"; + /// The sensitive identification string + std::string sentag = "_sen"; + /// The bin number tag + std::string ntag = "n"; + /// The value tag -> binning values: AxisZ, AxisR, AxisPhi, etc. + std::string vtag = "v"; + /// The option tag -> binning options: open, closed + std::string otag = "o"; + /// The range min tag: min value + std::string mintag = "min"; + /// The range max tag: max value + std::string maxtag = "max"; + /// The thickness tag + std::string ttag = "t"; + /// The x0 tag + std::string x0tag = "x0"; + /// The l0 tag + std::string l0tag = "l0"; + /// The A tag + std::string atag = "A"; + /// The Z tag + std::string ztag = "Z"; + /// The rho tag + std::string rhotag = "rho"; + }; + + /// @brief Constructor from config struct + /// /// @param cfg the configuration for the accessor + explicit RootMaterialMapAccessor(const Config& cfg) : m_cfg(cfg) {} + + /// @brief Destructor + ~RootMaterialMapAccessor() = default; + + /// Write the material to file + /// /// @param rFile the file to write to + /// @param gctx the geometry context + /// @param surface is the surface associated with the material + void write(TFile& rFile, const GeometryContext& gctx, + const Surface& surface) const; + + private: + /// @brief + /// @param rDirectory + /// @param binnedMaterial + void writeBinnedSurfaceMaterial(TDirectory& rDirectory, + const BinnedSurfaceMaterial& binnedMaterial); + + /// The configuration for the accessor + Config m_cfg; + + /// Central store for homogeneous material + std::unique_ptr m_hTree = nullptr; + /// geometry identifier + std::vector m_hGeoId; + /// thickness + std::vector m_ht; + /// X0 + std::vector m_hX0; + /// L0 + std::vector m_hL0; + /// A + std::vector m_hA; + /// Z + std::vector m_hZ + /// Rho + std::vector m_hRho; + +}; + +} // namespace Acts \ No newline at end of file diff --git a/Plugins/Root/src/RootMaterialMapAccessor.cpp b/Plugins/Root/src/RootMaterialMapAccessor.cpp new file mode 100644 index 00000000000..4d0ec7b1896 --- /dev/null +++ b/Plugins/Root/src/RootMaterialMapAccessor.cpp @@ -0,0 +1,40 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 CERN for the benefit of the ACTS project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#include "Acts/Plugins/Root/RootMaterialMapAccessor.hpp" + +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "Acts/Material/BinnedSurfaceMaterial.hpp" +#include "Acts/Material/HomogeneousSurfaceMaterial.hpp" +#include "Acts/Material/IGridSurfaceMaterial.hpp" +#include "Acts/Surfaces/Surface.hpp" + +void Acts::RootMaterialMapAccessor::write(TFile& rFile, + const GeometryContext& gctx, + const Surface& surface) const { + auto geoID = surface.geometryId(); + auto surfaceMaterial = surface.surfaceMaterial(); + if (surfaceMaterial == nullptr) { + return; + } + + auto homogeneousMaterial = + dynamic_cast(surfaceMaterial); + if (homogeneousMaterial != nullptr) { + + + } + + auto binnedMaterial = + dynamic_cast(surfaceMaterial); + if (binnedMaterial != nullptr) { + // writeBinnedMaterial(rFile, gctx, geoID, *binnedMaterial); + } + + return; +} From 3bf4216e0654116d2c9392d2650a3e2cb952d365 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Mon, 7 Jul 2025 13:45:14 +0200 Subject: [PATCH 02/30] snapshot --- .../Plugins/Root/RootMaterialMapAccessor.hpp | 83 +++++++++++++------ Plugins/Root/src/RootMaterialMapAccessor.cpp | 43 +++++++++- 2 files changed, 98 insertions(+), 28 deletions(-) diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp index edcbaff7592..8304f760e7d 100644 --- a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp +++ b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp @@ -10,12 +10,17 @@ #include +#include + class TFile; +class TDirectory; namespace Acts { class Surface; class GeometryContext; +class HomogeneousSurfaceMaterial; +class BinnedSurfaceMaterial; /// Simple payload class that can be wrapped for reading /// and writing. @@ -60,46 +65,76 @@ class RootMaterialMapAccessor { std::string rhotag = "rho"; }; + struct MaterialTreePayload { + std::vector hGeoId; + std::vector* hGeoIdPtr = &hGeoId; + /// thickness + std::vector ht; + std::vector* htPtr = &ht; + /// X0 + std::vector hX0; + std::vector* hX0Ptr = &hX0; + /// L0 + std::vector hL0; + std::vector* hL0Ptr = &hL0; + /// A + std::vector hA; + std::vector* hAPtr = &hA; + /// Z + std::vector hZ; + std::vector* hZPtr = &hZ; + /// Rho + std::vector hRho; + std::vector* hRhoPtr = &hRho; + }; + /// @brief Constructor from config struct - /// /// @param cfg the configuration for the accessor - explicit RootMaterialMapAccessor(const Config& cfg) : m_cfg(cfg) {} + /// @param cfg the configuration for the accessor + explicit RootMaterialMapAccessor(const Config& cfg) : cfg(cfg) {} /// @brief Destructor ~RootMaterialMapAccessor() = default; /// Write the material to file - /// /// @param rFile the file to write to + /// @param rFile the file to write to /// @param gctx the geometry context /// @param surface is the surface associated with the material - void write(TFile& rFile, const GeometryContext& gctx, - const Surface& surface) const; + void write(TFile& rFile, const GeometryContext& gctx, const Surface& surface); private: - /// @brief - /// @param rDirectory - /// @param binnedMaterial + /// @brief Write the homogeneous material to the file + /// @param homogeneousMaterial the homogeneous material to write + void writeHomogeneousMaterial( + const HomogeneousSurfaceMaterial& homogeneousMaterial); + + /// @brief Connect the homogeneous material tree for writing + /// @param rTree the tree to connect to + /// @param treePayload the payload to connect to the tree + void connectForWrite(TTree& rTree, MaterialTreePayload& treePayload); + + + /// @brief Connect the homogeneous material tree for writing + /// @param rTree the tree to connect to + /// @param treePayload the payload to connect to the tree + void connectForRead(const TTree& rTree, MaterialTreePayload& treePayload); + + /// @brief + /// @param rDirectory + /// @param binnedMaterial void writeBinnedSurfaceMaterial(TDirectory& rDirectory, const BinnedSurfaceMaterial& binnedMaterial); /// The configuration for the accessor Config m_cfg; - /// Central store for homogeneous material - std::unique_ptr m_hTree = nullptr; - /// geometry identifier - std::vector m_hGeoId; - /// thickness - std::vector m_ht; - /// X0 - std::vector m_hX0; - /// L0 - std::vector m_hL0; - /// A - std::vector m_hA; - /// Z - std::vector m_hZ - /// Rho - std::vector m_hRho; + /// The homogeneous material tree + std::unique_ptr m_hTree = nullptr; + MaterialTreePayload m_homogenousMaterialTreePayload; + + /// The globally indexed material tree + std::unique_ptr m_gTree = nullptr; + MaterialTreePayload m_globallyIndexedMaterialTreePayload; + }; diff --git a/Plugins/Root/src/RootMaterialMapAccessor.cpp b/Plugins/Root/src/RootMaterialMapAccessor.cpp index 4d0ec7b1896..1240df735dd 100644 --- a/Plugins/Root/src/RootMaterialMapAccessor.cpp +++ b/Plugins/Root/src/RootMaterialMapAccessor.cpp @@ -11,23 +11,24 @@ #include "Acts/Geometry/GeometryIdentifier.hpp" #include "Acts/Material/BinnedSurfaceMaterial.hpp" #include "Acts/Material/HomogeneousSurfaceMaterial.hpp" -#include "Acts/Material/IGridSurfaceMaterial.hpp" +#include "Acts/Material/GridSurfaceMaterial.hpp" #include "Acts/Surfaces/Surface.hpp" void Acts::RootMaterialMapAccessor::write(TFile& rFile, const GeometryContext& gctx, - const Surface& surface) const { + const Surface& surface) { auto geoID = surface.geometryId(); auto surfaceMaterial = surface.surfaceMaterial(); if (surfaceMaterial == nullptr) { return; } + auto homogeneousMaterial = dynamic_cast(surfaceMaterial); if (homogeneousMaterial != nullptr) { - - + writeHomogeneousMaterial(*homogeneousMaterial); + m_hGeoIdPtr->push_back(geoID.value()); } auto binnedMaterial = @@ -38,3 +39,37 @@ void Acts::RootMaterialMapAccessor::write(TFile& rFile, return; } + +void Acts::RootMaterialMapAccessor::connectForWrite( + TTree& rTree, MaterialTreePayload& treePayload) { + rTree.Branch("hGeoId", &treePayload.hGeoIdPtr); + rTree.Branch("ht", &treePayload.htPtr); + rTree.Branch("hX0", &treePayload.hX0Ptr); + rTree.Branch("hL0", &treePayload.hL0Ptr); + rTree.Branch("hA", &treePayload.hAPtr); + rTree.Branch("hZ", &treePayload.hZPtr); + rTree.Branch("hRho", &treePayload.hRhoPtr); +} + +void Acts::RootMaterialMapAccessor::connectForRead( + const TTree& rTree, MaterialTreePayload& treePayload) { + rTree.SetBranchAddress("hGeoId", &treePayload.hGeoIdPtr); + rTree.SetBranchAddress("ht", &treePayload.htPtr); + rTree.SetBranchAddress("hX0", &treePayload.hX0Ptr); + rTree.SetBranchAddress("hL0", &treePayload.hL0Ptr); + rTree.SetBranchAddress("hA", &treePayload.hAPtr); + rTree.SetBranchAddress("hZ", &treePayload.hZPtr); + rTree.SetBranchAddress("hRho", &treePayload.hRhoPtr); +} + +void Acts::RootMaterialMapAccessor::writeHomogeneousMaterial( + const HomogeneousSurfaceMaterial& homogeneousMaterial) { + if (m_hTree == nullptr) { + m_hTree = std::make_unique("HomogeneousMaterial", + "Homogeneous Material Tree"); + + + } + + +} From ea24b12344b06916c2f0e5f97f434226fff5f987 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Tue, 8 Jul 2025 11:15:00 +0200 Subject: [PATCH 03/30] snapshot --- .../Plugins/Root/RootMaterialMapAccessor.hpp | 124 +++++-- Plugins/Root/src/RootMaterialMapAccessor.cpp | 344 ++++++++++++++++-- Tests/UnitTests/Plugins/Root/CMakeLists.txt | 1 + .../Root/RootMaterialMapAccessorTests.cpp | 164 +++++++++ 4 files changed, 557 insertions(+), 76 deletions(-) create mode 100644 Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp index 8304f760e7d..4a49cc91ce9 100644 --- a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp +++ b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp @@ -8,25 +8,42 @@ #pragma once -#include +#include "Acts/Utilities/Logger.hpp" -#include +#include +#include +#include +#include +class TTree; class TFile; class TDirectory; namespace Acts { -class Surface; -class GeometryContext; +class GeometryIdentifier; +class ISurfaceMaterial; +class IVolumeMaterial; class HomogeneousSurfaceMaterial; +class MaterialSlab; class BinnedSurfaceMaterial; +using SurfaceMaterialMaps = + std::map>; +using VolumeMaterialMaps = + std::map>; +using DetectorMaterial = std::tuple; + /// Simple payload class that can be wrapped for reading /// and writing. class RootMaterialMapAccessor { public: struct Config { + bool indexedMaterial = false; + /// The name of the homogeneous material tree + std::string homogeneousMaterialTree = "HomogeneousMaterial"; + /// The name of the indexed material tree + std::string indexMaterialTreeName = "IndexedMaterial"; /// The name of the output surface tree std::string folderSurfaceNameBase = "SurfaceMaterial"; /// The name of the output volume tree @@ -47,6 +64,8 @@ class RootMaterialMapAccessor { std::string vtag = "v"; /// The option tag -> binning options: open, closed std::string otag = "o"; + /// The index tag + std::string itag = "i"; /// The range min tag: min value std::string mintag = "min"; /// The range max tag: max value @@ -66,76 +85,101 @@ class RootMaterialMapAccessor { }; struct MaterialTreePayload { - std::vector hGeoId; - std::vector* hGeoIdPtr = &hGeoId; + std::size_t index = 0; + /// geometry identifier + int64_t hGeoId; /// thickness - std::vector ht; - std::vector* htPtr = &ht; + float ht; /// X0 - std::vector hX0; - std::vector* hX0Ptr = &hX0; + float hX0; /// L0 - std::vector hL0; - std::vector* hL0Ptr = &hL0; + float hL0; /// A - std::vector hA; - std::vector* hAPtr = &hA; + float hA; /// Z - std::vector hZ; - std::vector* hZPtr = &hZ; + float hZ; /// Rho - std::vector hRho; - std::vector* hRhoPtr = &hRho; + float hRho; }; /// @brief Constructor from config struct /// @param cfg the configuration for the accessor - explicit RootMaterialMapAccessor(const Config& cfg) : cfg(cfg) {} + /// @param mLogger the logger to use, default is INFO level + explicit RootMaterialMapAccessor( + const Config& cfg, std::unique_ptr mLogger = getDefaultLogger( + "RootMaterialMapAccessor", Logging::INFO)) + : m_cfg(cfg), m_logger(std::move(mLogger)) {} /// @brief Destructor ~RootMaterialMapAccessor() = default; + /// Write the detector maps + /// @param rFile the file to write to + /// @param detectorMaterial the detector material maps + void write(TFile& rFile, const DetectorMaterial& detectorMaterial); + /// Write the material to file /// @param rFile the file to write to - /// @param gctx the geometry context - /// @param surface is the surface associated with the material - void write(TFile& rFile, const GeometryContext& gctx, const Surface& surface); + /// @param geoID the geometry identifier for the surface + /// @param surfaceMaterial is the surface associated with the material + void write(TFile& rFile, const GeometryIdentifier& geoID, + const ISurfaceMaterial& surfaceMaterial); - private: - /// @brief Write the homogeneous material to the file - /// @param homogeneousMaterial the homogeneous material to write - void writeHomogeneousMaterial( - const HomogeneousSurfaceMaterial& homogeneousMaterial); + /// Read the detector maps + /// @param rFile the file to read from + DetectorMaterial read(TFile& rFile); + private: /// @brief Connect the homogeneous material tree for writing /// @param rTree the tree to connect to /// @param treePayload the payload to connect to the tree void connectForWrite(TTree& rTree, MaterialTreePayload& treePayload); - /// @brief Connect the homogeneous material tree for writing /// @param rTree the tree to connect to /// @param treePayload the payload to connect to the tree - void connectForRead(const TTree& rTree, MaterialTreePayload& treePayload); - - /// @brief - /// @param rDirectory - /// @param binnedMaterial - void writeBinnedSurfaceMaterial(TDirectory& rDirectory, - const BinnedSurfaceMaterial& binnedMaterial); + void connectForRead(TTree& rTree, MaterialTreePayload& treePayload); + + /// Fill the material slab + /// @param payload the tree payload to fill + /// @param materialSlab the material slab to fill + void fillMaterialSlab(MaterialTreePayload& payload, + const MaterialSlab& materialSlab); + + /// @brief Fill the Binned Surface material as histograms - legacy mode + /// @param bsMaterial the binned surface material to write + void fillBinnedSurfaceMaterial(const BinnedSurfaceMaterial& bsMaterial); + + /// @brief Fill the Binned Surface material as histograms - indexed mode + /// @param payload the tree payload to fill + /// @param bsMaterial the binned surface material to write + void fillBinnedSurfaceMaterial(MaterialTreePayload& payload, + const BinnedSurfaceMaterial& bsMaterial); + + /// Read the a texture Surface material + /// @param rFile the file to read from + /// @param tdName the name of the texture directory + /// @param indexedMaterialTree the indexed material tree, if available + /// @return a shared pointer to the ISurfaceMaterial + std::shared_ptr readTextureSurfaceMaterial( + TFile& rFile, const std::string& tdName, TTree* indexedMaterialTree = nullptr); + + /// Read the a grid Surface material + const Logger& logger() const { return *m_logger; } /// The configuration for the accessor Config m_cfg; + /// The logger for this accessor + std::unique_ptr m_logger; + /// The homogeneous material tree - std::unique_ptr m_hTree = nullptr; + TTree* m_hTree = nullptr; MaterialTreePayload m_homogenousMaterialTreePayload; /// The globally indexed material tree - std::unique_ptr m_gTree = nullptr; - MaterialTreePayload m_globallyIndexedMaterialTreePayload; - - + TTree* m_gTree = nullptr; + MaterialTreePayload m_indexedMaterialTreePayload; }; } // namespace Acts \ No newline at end of file diff --git a/Plugins/Root/src/RootMaterialMapAccessor.cpp b/Plugins/Root/src/RootMaterialMapAccessor.cpp index 1240df735dd..abae333f52c 100644 --- a/Plugins/Root/src/RootMaterialMapAccessor.cpp +++ b/Plugins/Root/src/RootMaterialMapAccessor.cpp @@ -10,66 +10,338 @@ #include "Acts/Geometry/GeometryIdentifier.hpp" #include "Acts/Material/BinnedSurfaceMaterial.hpp" -#include "Acts/Material/HomogeneousSurfaceMaterial.hpp" #include "Acts/Material/GridSurfaceMaterial.hpp" +#include "Acts/Material/HomogeneousSurfaceMaterial.hpp" +#include "Acts/Material/Material.hpp" +#include "Acts/Material/MaterialSlab.hpp" #include "Acts/Surfaces/Surface.hpp" +#include "Acts/Utilities/Enumerate.hpp" -void Acts::RootMaterialMapAccessor::write(TFile& rFile, - const GeometryContext& gctx, - const Surface& surface) { - auto geoID = surface.geometryId(); - auto surfaceMaterial = surface.surfaceMaterial(); - if (surfaceMaterial == nullptr) { - return; - } +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void Acts::RootMaterialMapAccessor::write( + TFile& rFile, const GeometryIdentifier& geoID, + const ISurfaceMaterial& surfaceMaterial) { + /// Change to the file + rFile.cd(); + // Homogeneous surface material writing into one tree auto homogeneousMaterial = - dynamic_cast(surfaceMaterial); + dynamic_cast(&surfaceMaterial); if (homogeneousMaterial != nullptr) { - writeHomogeneousMaterial(*homogeneousMaterial); - m_hGeoIdPtr->push_back(geoID.value()); + if (m_hTree == nullptr) { + m_hTree = new TTree(m_cfg.homogeneousMaterialTree.c_str(), + "Homogeneous Material Tree"); + connectForWrite(*m_hTree, m_homogenousMaterialTreePayload); + } + fillMaterialSlab(m_homogenousMaterialTreePayload, + homogeneousMaterial->materialSlab()); + m_homogenousMaterialTreePayload.hGeoId = geoID.value(); + m_hTree->Fill(); + return; } - auto binnedMaterial = - dynamic_cast(surfaceMaterial); - if (binnedMaterial != nullptr) { - // writeBinnedMaterial(rFile, gctx, geoID, *binnedMaterial); + // Binned surface material writing + auto bsMaterial = + dynamic_cast(&surfaceMaterial); + if (bsMaterial != nullptr) { + // decode the geometryID + const auto gvolID = geoID.volume(); + const auto gbouID = geoID.boundary(); + const auto glayID = geoID.layer(); + const auto gappID = geoID.approach(); + const auto gsenID = geoID.sensitive(); + // create the directory + std::string tdName = m_cfg.folderSurfaceNameBase.c_str(); + tdName += m_cfg.voltag + std::to_string(gvolID); + tdName += m_cfg.boutag + std::to_string(gbouID); + tdName += m_cfg.laytag + std::to_string(glayID); + tdName += m_cfg.apptag + std::to_string(gappID); + tdName += m_cfg.sentag + std::to_string(gsenID); + // create a new directory + rFile.mkdir(tdName.c_str()); + rFile.cd(tdName.c_str()); + + // Boundary condistions + // Get the binning data + auto& binningData = bsMaterial->binUtility().binningData(); + // 1-D or 2-D maps + std::size_t binningBins = binningData.size(); + + // The bin number information + auto n = new TH1F(m_cfg.ntag.c_str(), "bins; bin", binningBins, -0.5, + binningBins - 0.5); + + // The binning value information + auto v = new TH1F(m_cfg.vtag.c_str(), "binning values; bin", binningBins, + -0.5, binningBins - 0.5); + + // The binning option information + auto o = new TH1F(m_cfg.otag.c_str(), "binning options; bin", binningBins, + -0.5, binningBins - 0.5); + + // The binning option information - range min + auto rmin = new TH1F(m_cfg.mintag.c_str(), "min; bin", binningBins, -0.5, + binningBins - 0.5); + + // The binning option information - range max + auto rmax = new TH1F(m_cfg.maxtag.c_str(), "max; bin", binningBins, -0.5, + binningBins - 0.5); + + // Now fill the histogram content + std::size_t b = 1; + for (auto bData : binningData) { + // Fill: nbins, value, option, min, max + n->SetBinContent(b, static_cast(binningData[b - 1].bins())); + v->SetBinContent(b, static_cast(binningData[b - 1].binvalue)); + o->SetBinContent(b, static_cast(binningData[b - 1].option)); + rmin->SetBinContent(b, binningData[b - 1].min); + rmax->SetBinContent(b, binningData[b - 1].max); + ++b; + } + n->Write(); + v->Write(); + o->Write(); + rmin->Write(); + rmax->Write(); + + // If compressed writing is not enabled, write the binned surface material + // as histograms + if (!m_cfg.indexedMaterial) { + fillBinnedSurfaceMaterial(*bsMaterial); + return; + } + + // Otherwise, write the binned surface material into the TTree + if (m_gTree == nullptr) { + // Back to file level + rFile.cd(); + m_gTree = new TTree(m_cfg.indexMaterialTreeName.c_str(), + "Indexed Material Tree"); + connectForWrite(*m_gTree, m_indexedMaterialTreePayload); + // Back to the directory + rFile.cd(tdName.c_str()); + } + fillBinnedSurfaceMaterial(m_indexedMaterialTreePayload, *bsMaterial); + return; } + // auto gridMaterial = dynamic_cast(surfaceMaterial); if (gridMaterial != nullptr) { + // writeGridMaterial(rFile, gctx, geoID, *gridMaterial); + // return; + //} + return; } +void Acts::RootMaterialMapAccessor::write( + TFile& rFile, const DetectorMaterial& detectorMaterial) { + auto [surfaceMaterials, volumeMaterials] = detectorMaterial; + for (const auto& [geoID, sMaterial] : surfaceMaterials) { + write(rFile, geoID, *sMaterial); + } +} + void Acts::RootMaterialMapAccessor::connectForWrite( TTree& rTree, MaterialTreePayload& treePayload) { - rTree.Branch("hGeoId", &treePayload.hGeoIdPtr); - rTree.Branch("ht", &treePayload.htPtr); - rTree.Branch("hX0", &treePayload.hX0Ptr); - rTree.Branch("hL0", &treePayload.hL0Ptr); - rTree.Branch("hA", &treePayload.hAPtr); - rTree.Branch("hZ", &treePayload.hZPtr); - rTree.Branch("hRho", &treePayload.hRhoPtr); + if (&treePayload == &m_homogenousMaterialTreePayload) { + rTree.Branch("hGeoId", &treePayload.hGeoId); + } + rTree.Branch(m_cfg.ttag.c_str(), &treePayload.ht); + rTree.Branch(m_cfg.x0tag.c_str(), &treePayload.hX0); + rTree.Branch(m_cfg.l0tag.c_str(), &treePayload.hL0); + rTree.Branch(m_cfg.atag.c_str(), &treePayload.hA); + rTree.Branch(m_cfg.ztag.c_str(), &treePayload.hZ); + rTree.Branch(m_cfg.rhotag.c_str(), &treePayload.hRho); } void Acts::RootMaterialMapAccessor::connectForRead( - const TTree& rTree, MaterialTreePayload& treePayload) { - rTree.SetBranchAddress("hGeoId", &treePayload.hGeoIdPtr); - rTree.SetBranchAddress("ht", &treePayload.htPtr); - rTree.SetBranchAddress("hX0", &treePayload.hX0Ptr); - rTree.SetBranchAddress("hL0", &treePayload.hL0Ptr); - rTree.SetBranchAddress("hA", &treePayload.hAPtr); - rTree.SetBranchAddress("hZ", &treePayload.hZPtr); - rTree.SetBranchAddress("hRho", &treePayload.hRhoPtr); + TTree& rTree, MaterialTreePayload& treePayload) { + if (&treePayload == &m_homogenousMaterialTreePayload) { + rTree.SetBranchAddress("hGeoId", &treePayload.hGeoId); + } + rTree.SetBranchAddress(m_cfg.ttag.c_str(), &treePayload.ht); + rTree.SetBranchAddress(m_cfg.x0tag.c_str(), &treePayload.hX0); + rTree.SetBranchAddress(m_cfg.l0tag.c_str(), &treePayload.hL0); + rTree.SetBranchAddress(m_cfg.atag.c_str(), &treePayload.hA); + rTree.SetBranchAddress(m_cfg.ztag.c_str(), &treePayload.hZ); + rTree.SetBranchAddress(m_cfg.rhotag.c_str(), &treePayload.hRho); } -void Acts::RootMaterialMapAccessor::writeHomogeneousMaterial( - const HomogeneousSurfaceMaterial& homogeneousMaterial) { - if (m_hTree == nullptr) { - m_hTree = std::make_unique("HomogeneousMaterial", - "Homogeneous Material Tree"); +void Acts::RootMaterialMapAccessor::fillMaterialSlab( + MaterialTreePayload& payload, const MaterialSlab& materialSlab) { + payload.ht = materialSlab.thickness(); + payload.hX0 = materialSlab.material().X0(); + payload.hL0 = materialSlab.material().L0(); + payload.hA = materialSlab.material().Ar(); + payload.hZ = materialSlab.material().Z(); + payload.hRho = materialSlab.material().massDensity(); +} +void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( + const BinnedSurfaceMaterial& bsMaterial) { + std::size_t bins0 = bsMaterial.binUtility().bins(0); + std::size_t bins1 = bsMaterial.binUtility().bins(1); + auto t = new TH2F(m_cfg.ttag.c_str(), "thickness [mm] ;b0 ;b1", bins0, -0.5, + bins0 - 0.5, bins1, -0.5, bins1 - 0.5); + auto x0 = new TH2F(m_cfg.x0tag.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, + bins0 - 0.5, bins1, -0.5, bins1 - 0.5); + auto l0 = new TH2F(m_cfg.l0tag.c_str(), "#Lambda_{0} [mm] ;b0 ;b1", bins0, + -0.5, bins0 - 0.5, bins1, -0.5, bins1 - 0.5); + auto A = new TH2F(m_cfg.atag.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, + bins0 - 0.5, bins1, -0.5, bins1 - 0.5); + auto Z = new TH2F(m_cfg.ztag.c_str(), "#Lambda_{0} [mm] ;b0 ;b1", bins0, -0.5, + bins0 - 0.5, bins1, -0.5, bins1 - 0.5); + auto rho = new TH2F(m_cfg.rhotag.c_str(), "#rho [g/mm^3] ;b0 ;b1", bins0, + -0.5, bins0 - 0.5, bins1, -0.5, bins1 - 0.5); + + // loop over the material and fill + const auto& materialMatrix = bsMaterial.fullMaterial(); + for (auto [b1, materialVector] : enumerate(materialMatrix)) { + for (auto [b0, mat] : enumerate(materialVector)) { + t->SetBinContent(b0 + 1, b1 + 1, mat.thickness()); + x0->SetBinContent(b0 + 1, b1 + 1, mat.material().X0()); + l0->SetBinContent(b0 + 1, b1 + 1, mat.material().L0()); + A->SetBinContent(b0 + 1, b1 + 1, mat.material().Ar()); + Z->SetBinContent(b0 + 1, b1 + 1, mat.material().Z()); + rho->SetBinContent(b0 + 1, b1 + 1, mat.material().massDensity()); + } + } + t->Write(); + x0->Write(); + l0->Write(); + A->Write(); + Z->Write(); + rho->Write(); +} + +void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( + MaterialTreePayload& payload, const BinnedSurfaceMaterial& bsMaterial) { + std::size_t bins0 = bsMaterial.binUtility().bins(0); + std::size_t bins1 = bsMaterial.binUtility().bins(1); + + auto idx = new TH2I(m_cfg.itag.c_str(), "indices; bin0; bin1", bins0, -0.5, + bins0 - 0.5, bins1, -0.5, bins1 - 0.5); + // loop over the material and fill + const auto& materialMatrix = bsMaterial.fullMaterial(); + for (auto [b1, materialVector] : enumerate(materialMatrix)) { + for (auto [b0, mat] : enumerate(materialVector)) { + idx->SetBinContent(b0 + b1 * bins0 + 1, payload.index++); + fillMaterialSlab(payload, mat); + m_gTree->Fill(); + } + } + idx->Write(); +} + +Acts::DetectorMaterial Acts::RootMaterialMapAccessor::read(TFile& rFile) { + Acts::DetectorMaterial detectorMaterial; + + auto& [surfaceMaterials, volumeMaterials] = detectorMaterial; + + TTree* homogeneousMaterialTree = + dynamic_cast(rFile.Get(m_cfg.homogeneousMaterialTree.c_str())); + + // Read homogeneous material tree + if (homogeneousMaterialTree != nullptr) { + connectForRead(*homogeneousMaterialTree, m_homogenousMaterialTreePayload); + for (int i = 0; i < homogeneousMaterialTree->GetEntries(); ++i) { + homogeneousMaterialTree->GetEntry(i); + Acts::GeometryIdentifier geoID(m_homogenousMaterialTreePayload.hGeoId); + Acts::MaterialSlab materialSlab(Acts::Material::fromMolarDensity( + m_homogenousMaterialTreePayload.hX0, + m_homogenousMaterialTreePayload.hL0, + m_homogenousMaterialTreePayload.hA, + m_homogenousMaterialTreePayload.hZ, + m_homogenousMaterialTreePayload.hRho), + m_homogenousMaterialTreePayload.ht); + auto homogeneousMaterial = + std::make_shared(materialSlab); + surfaceMaterials.emplace(geoID, homogeneousMaterial); + } } + // Read the binned surface material + TTree* indexedMaterialTree = + dynamic_cast(rFile.Get(m_cfg.indexMaterialTreeName.c_str())); + // Get the list of keys from the file + TList* tlist = rFile.GetListOfKeys(); + auto tIter = tlist->MakeIterator(); + tIter->Reset(); + + // Iterate over the keys in the file + while (TKey* key = static_cast(tIter->Next())) { + // Remember the directory + std::string tdName(key->GetName()); + + ACTS_VERBOSE("Processing directory: " << tdName); + + // volume + std::vector splitNames; + iter_split(splitNames, tdName, + boost::algorithm::first_finder(m_cfg.voltag)); + // Surface Material + if (splitNames[0] == m_cfg.folderSurfaceNameBase) { + // The surface material to be read in for this + std::shared_ptr sMaterial = nullptr; + + boost::split(splitNames, splitNames[1], boost::is_any_of("_")); + Acts::GeometryIdentifier::Value volID = std::stoi(splitNames[0]); + // boundary + iter_split(splitNames, tdName, + boost::algorithm::first_finder(m_cfg.boutag)); + boost::split(splitNames, splitNames[1], boost::is_any_of("_")); + Acts::GeometryIdentifier::Value bouID = std::stoi(splitNames[0]); + // layer + iter_split(splitNames, tdName, + boost::algorithm::first_finder(m_cfg.laytag)); + boost::split(splitNames, splitNames[1], boost::is_any_of("_")); + Acts::GeometryIdentifier::Value layID = std::stoi(splitNames[0]); + // approach + iter_split(splitNames, tdName, + boost::algorithm::first_finder(m_cfg.apptag)); + boost::split(splitNames, splitNames[1], boost::is_any_of("_")); + Acts::GeometryIdentifier::Value appID = std::stoi(splitNames[0]); + // sensitive + iter_split(splitNames, tdName, + boost::algorithm::first_finder(m_cfg.sentag)); + Acts::GeometryIdentifier::Value senID = std::stoi(splitNames[1]); + + // Reconstruct the geometry ID + auto geoID = Acts::GeometryIdentifier() + .withVolume(volID) + .withBoundary(bouID) + .withLayer(layID) + .withApproach(appID) + .withSensitive(senID); + + auto texturedSurfaceMaterial = + readTextureSurfaceMaterial(rFile, tdName, indexedMaterialTree); + surfaceMaterials.emplace(geoID, texturedSurfaceMaterial); + + } + } + + return detectorMaterial; } + +std::shared_ptr +Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( + TFile& rFile, const std::string& tdName, TTree* indexedMaterialTree) { + std::shared_ptr texturedSurfaceMaterial = + nullptr; + + return texturedSurfaceMaterial; +} \ No newline at end of file diff --git a/Tests/UnitTests/Plugins/Root/CMakeLists.txt b/Tests/UnitTests/Plugins/Root/CMakeLists.txt index ee3d12d7de8..2ed8f49319e 100644 --- a/Tests/UnitTests/Plugins/Root/CMakeLists.txt +++ b/Tests/UnitTests/Plugins/Root/CMakeLists.txt @@ -1,5 +1,6 @@ set(unittest_extra_libraries ActsPluginRoot) +add_unittest(RootMaterialMapAccessor RootMaterialMapAccessorTests.cpp) add_unittest(TGeoArb8Conversion TGeoArb8ConversionTests.cpp) add_unittest(TGeoBBoxConversion TGeoBBoxConversionTests.cpp) add_unittest(TGeoTrd1Conversion TGeoTrd1ConversionTests.cpp) diff --git a/Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp b/Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp new file mode 100644 index 00000000000..fe19c4e6a04 --- /dev/null +++ b/Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp @@ -0,0 +1,164 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 CERN for the benefit of the ACTS project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#include + +#include "Acts/Definitions/Algebra.hpp" +#include "Acts/Material/BinnedSurfaceMaterial.hpp" +#include "Acts/Material/HomogeneousSurfaceMaterial.hpp" +#include "Acts/Material/Material.hpp" +#include "Acts/Material/MaterialSlab.hpp" +#include "Acts/Plugins/Root/RootMaterialMapAccessor.hpp" +#include "Acts/Surfaces/PlaneSurface.hpp" +#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp" +#include "Acts/Utilities/BinUtility.hpp" + +#include +#include +#include + +#include "TFile.h" + +using namespace Acts; + +using IdentifiedMaterial = + std::tuple>; + +std::vector createHomogeneousSurfaceMaterial() { + std::size_t nMaterials = 100; + + std::vector homogeneousMaterials; + homogeneousMaterials.reserve(nMaterials); + for (std::size_t i = 0; i < nMaterials; ++i) { + // construct the material properties from arguments + Material mat = Material::fromMolarDensity( + 1. + i * 0.5, 2. + i * 0.5, 3. + i * 0.5, 4. + i * 0.5, 5. + i * 0.5); + MaterialSlab mp(mat, 0.1); + auto hMaterial = std::make_shared(mp); + auto geoID = GeometryIdentifier().withVolume(1).withSensitive(i + 1); + homogeneousMaterials.push_back({geoID, hMaterial}); + } + return homogeneousMaterials; +} + +std::vector createBinnedSurfaceMaterial() { + std::size_t nMaterials = 100; + + std::vector binnedMaterials; + binnedMaterials.reserve(nMaterials); + for (std::size_t i = 0; i < nMaterials; ++i) { + // construct the material properties from arguments + + BinUtility xyBinning(100, -1., 1., open, AxisDirection::AxisX); + xyBinning += BinUtility(50, -3., 3., open, AxisDirection::AxisY); + + std::vector> materialMatrix; + for (std::size_t j = 0; j < xyBinning.bins(1); ++j) { + std::vector materialRow; + for (std::size_t k = 0; k < xyBinning.bins(0); ++k) { + // Create a material slab with some arbitrary properties + Material mat = Material::fromMolarDensity( + i + j * 1. + k * 0.5, i + j * 2 + k * 0.5, i + j * 3. + k * 0.5, + i + j * 4. + k * 0.5, i + j * 5. + k * 0.5); + MaterialSlab mp(mat, 0.1); + materialRow.push_back(mp); + } + materialMatrix.push_back(materialRow); + } + auto binnedMaterial = + std::make_shared(xyBinning, materialMatrix); + auto geoID = GeometryIdentifier().withVolume(2).withSensitive(i + 1); + binnedMaterials.push_back({geoID, binnedMaterial}); + } + return binnedMaterials; +} + +BOOST_AUTO_TEST_SUITE(RootMaterialMapAccessorTests) + +BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorHomogeneousReadWrite) { + auto surfaceMaterials = createHomogeneousSurfaceMaterial(); + + auto rFile = + TFile::Open("RootMaterialMapAccessorHomogeneousTests.root", "RECREATE"); + rFile->cd(); + BOOST_REQUIRE(rFile != nullptr); + + // Create the accessor + Acts::RootMaterialMapAccessor::Config cfg; + Acts::RootMaterialMapAccessor accessor(cfg); + + for (const auto& [geoID, sMaterial] : surfaceMaterials) { + accessor.write(*rFile, geoID, *sMaterial); + } + + rFile->Write(); + rFile->Close(); + + // Let's read it back + auto iFile = + TFile::Open("RootMaterialMapAccessorHomogeneousTests.root", "READ"); + BOOST_REQUIRE(iFile != nullptr); + + auto [surfaceMapsRead, volumeMapsRead] = accessor.read(*iFile); + BOOST_REQUIRE_EQUAL(surfaceMapsRead.size(), surfaceMaterials.size()); + BOOST_REQUIRE_EQUAL(volumeMapsRead.size(), 0); + + Vector3 accessorPosition(0., 0., 0.); + + for (const auto& [geoID, sMaterial] : surfaceMaterials) { + auto it = surfaceMapsRead.find(geoID); + BOOST_REQUIRE(it != surfaceMapsRead.end()); + const auto& readMaterial = it->second; + BOOST_REQUIRE(readMaterial != nullptr); + const auto* hMaterial = + dynamic_cast(readMaterial.get()); + BOOST_REQUIRE(hMaterial != nullptr); + BOOST_CHECK_CLOSE(hMaterial->materialSlab(accessorPosition).material().X0(), + sMaterial->materialSlab(accessorPosition).material().X0(), 1e-6); + BOOST_CHECK_CLOSE(hMaterial->materialSlab(accessorPosition).material().L0(), + sMaterial->materialSlab(accessorPosition).material().L0(), 1e-6); + } +} + +BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorBinnrfReadWrite) { + auto surfaceMaterials = createBinnedSurfaceMaterial(); + + auto rFile = + TFile::Open("RootMaterialMapAccessorBinnedTests.root", "RECREATE"); + rFile->cd(); + BOOST_REQUIRE(rFile != nullptr); + + // Create the accessor + Acts::RootMaterialMapAccessor::Config cfg; + Acts::RootMaterialMapAccessor accessor(cfg); + + for (const auto& [geoID, sMaterial] : surfaceMaterials) { + accessor.write(*rFile, geoID, *sMaterial); + } + + rFile->Write(); + rFile->Close(); + + // Create the accessor - compressed writing + Acts::RootMaterialMapAccessor::Config cfgIndexed{true}; + Acts::RootMaterialMapAccessor accessorIndexed(cfgIndexed); + + rFile = + TFile::Open("RootMaterialMapAccessorBinnedIndexedTests.root", "RECREATE"); + rFile->cd(); + BOOST_REQUIRE(rFile != nullptr); + + for (const auto& [geoID, sMaterial] : surfaceMaterials) { + accessorIndexed.write(*rFile, geoID, *sMaterial); + } + + rFile->Write(); + rFile->Close(); +} + +BOOST_AUTO_TEST_SUITE_END() From c2507c04e2b777c27e763111197eaa441c55a69c Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Tue, 8 Jul 2025 13:37:40 +0200 Subject: [PATCH 04/30] next snapshot --- Plugins/Root/src/RootMaterialMapAccessor.cpp | 114 +++++++++++++++++- .../Root/RootMaterialMapAccessorTests.cpp | 55 ++++++++- 2 files changed, 164 insertions(+), 5 deletions(-) diff --git a/Plugins/Root/src/RootMaterialMapAccessor.cpp b/Plugins/Root/src/RootMaterialMapAccessor.cpp index abae333f52c..a695a7a2073 100644 --- a/Plugins/Root/src/RootMaterialMapAccessor.cpp +++ b/Plugins/Root/src/RootMaterialMapAccessor.cpp @@ -328,12 +328,10 @@ Acts::DetectorMaterial Acts::RootMaterialMapAccessor::read(TFile& rFile) { .withSensitive(senID); auto texturedSurfaceMaterial = - readTextureSurfaceMaterial(rFile, tdName, indexedMaterialTree); + readTextureSurfaceMaterial(rFile, tdName, indexedMaterialTree); surfaceMaterials.emplace(geoID, texturedSurfaceMaterial); - } } - return detectorMaterial; } @@ -343,5 +341,115 @@ Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( std::shared_ptr texturedSurfaceMaterial = nullptr; + // Construct the common names & get the common histograms + std::string nName = tdName + "/" + m_cfg.ntag; + std::string vName = tdName + "/" + m_cfg.vtag; + std::string oName = tdName + "/" + m_cfg.otag; + std::string minName = tdName + "/" + m_cfg.mintag; + std::string maxName = tdName + "/" + m_cfg.maxtag; + // Get the histograms + TH1F* n = dynamic_cast(rFile.Get(nName.c_str())); + TH1F* v = dynamic_cast(rFile.Get(vName.c_str())); + TH1F* o = dynamic_cast(rFile.Get(oName.c_str())); + TH1F* min = dynamic_cast(rFile.Get(minName.c_str())); + TH1F* max = dynamic_cast(rFile.Get(maxName.c_str())); + + // Now reconstruct the bin untilities + BinUtility bUtility; + for (int ib = 1; ib < n->GetNbinsX() + 1; ++ib) { + std::size_t nbins = static_cast(n->GetBinContent(ib)); + auto val = static_cast(v->GetBinContent(ib)); + auto opt = static_cast(o->GetBinContent(ib)); + float rmin = min->GetBinContent(ib); + float rmax = max->GetBinContent(ib); + bUtility += Acts::BinUtility(nbins, rmin, rmax, opt, val); + } + ACTS_VERBOSE("Created " << bUtility); + + /// Draw from histogram only source + if (indexedMaterialTree == nullptr) { + // Construct the names for histogram type storage + std::string tName = tdName + "/" + m_cfg.ttag; + std::string x0Name = tdName + "/" + m_cfg.x0tag; + std::string l0Name = tdName + "/" + m_cfg.l0tag; + std::string aName = tdName + "/" + m_cfg.atag; + std::string zName = tdName + "/" + m_cfg.ztag; + std::string rhoName = tdName + "/" + m_cfg.rhotag; + + // Get the histograms + TH2F* t = dynamic_cast(rFile.Get(tName.c_str())); + TH2F* x0 = dynamic_cast(rFile.Get(x0Name.c_str())); + TH2F* l0 = dynamic_cast(rFile.Get(l0Name.c_str())); + TH2F* A = dynamic_cast(rFile.Get(aName.c_str())); + TH2F* Z = dynamic_cast(rFile.Get(zName.c_str())); + TH2F* rho = dynamic_cast(rFile.Get(rhoName.c_str())); + + std::vector hists{n, v, o, min, max, t, x0, l0, A, Z, rho}; + + // Only go on when you have all histograms + if (std::ranges::all_of(hists, + [](const auto* hist) { return hist != nullptr; })) { + // Get the number of bins + int nbins0 = t->GetNbinsX(); + int nbins1 = t->GetNbinsY(); + + // The material matrix + MaterialSlabMatrix materialMatrix( + nbins1, MaterialSlabVector(nbins0, MaterialSlab::Nothing())); + + // Fill the matrix first + for (int ib0 = 1; ib0 <= nbins0; ++ib0) { + for (int ib1 = 1; ib1 <= nbins1; ++ib1) { + double dt = t->GetBinContent(ib0, ib1); + if (dt > 0.) { + double dx0 = x0->GetBinContent(ib0, ib1); + double dl0 = l0->GetBinContent(ib0, ib1); + double da = A->GetBinContent(ib0, ib1); + double dz = Z->GetBinContent(ib0, ib1); + double drho = rho->GetBinContent(ib0, ib1); + // Create material properties + const auto material = + Acts::Material::fromMassDensity(dx0, dl0, da, dz, drho); + materialMatrix[ib1 - 1][ib0 - 1] = Acts::MaterialSlab(material, dt); + } + } + } // Construct the binned material with the right bin utility + texturedSurfaceMaterial = std::make_shared( + bUtility, std::move(materialMatrix)); + } + } else { + // Construct the names for histogram type storage + std::string indexName = tdName + "/" + m_cfg.itag; + // Get the histograms + TH2I* ih = dynamic_cast(rFile.Get(indexName.c_str())); + // Get the number of bins + int nbins0 = ih->GetNbinsX(); + int nbins1 = ih->GetNbinsY(); + + // The material matrix + MaterialSlabMatrix materialMatrix( + nbins1, MaterialSlabVector(nbins0, MaterialSlab::Nothing())); + + // Fill the matrix first + for (int ib0 = 1; ib0 <= nbins0; ++ib0) { + for (int ib1 = 1; ib1 <= nbins1; ++ib1) { + int idx = static_cast(ih->GetBinContent(ib0, ib1)); + indexedMaterialTree->GetEntry(idx); + double dt = m_indexedMaterialTreePayload.ht; + double dx0 = m_indexedMaterialTreePayload.hX0; + double dl0 = m_indexedMaterialTreePayload.hL0; + double da = m_indexedMaterialTreePayload.hA; + double dz = m_indexedMaterialTreePayload.hZ; + double drho = m_indexedMaterialTreePayload.hRho; + // Create material properties + const auto material = + Acts::Material::fromMassDensity(dx0, dl0, da, dz, drho); + materialMatrix[ib1 - 1][ib0 - 1] = Acts::MaterialSlab(material, dt); + } + } // Construct the binned material with the right bin utility + texturedSurfaceMaterial = std::make_shared( + bUtility, std::move(materialMatrix)); + } + return texturedSurfaceMaterial; } \ No newline at end of file diff --git a/Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp b/Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp index fe19c4e6a04..32270be3c1b 100644 --- a/Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp +++ b/Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp @@ -119,9 +119,11 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorHomogeneousReadWrite) { dynamic_cast(readMaterial.get()); BOOST_REQUIRE(hMaterial != nullptr); BOOST_CHECK_CLOSE(hMaterial->materialSlab(accessorPosition).material().X0(), - sMaterial->materialSlab(accessorPosition).material().X0(), 1e-6); + sMaterial->materialSlab(accessorPosition).material().X0(), + 1e-6); BOOST_CHECK_CLOSE(hMaterial->materialSlab(accessorPosition).material().L0(), - sMaterial->materialSlab(accessorPosition).material().L0(), 1e-6); + sMaterial->materialSlab(accessorPosition).material().L0(), + 1e-6); } } @@ -144,6 +146,55 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorBinnrfReadWrite) { rFile->Write(); rFile->Close(); + // Let's read it back + auto iFile = TFile::Open("RootMaterialMapAccessorBinnedTests.root", "READ"); + BOOST_REQUIRE(iFile != nullptr); + auto [surfaceMapsRead, volumeMapsRead] = accessor.read(*iFile); + BOOST_REQUIRE_EQUAL(surfaceMapsRead.size(), surfaceMaterials.size()); + BOOST_REQUIRE_EQUAL(volumeMapsRead.size(), 0); + + // Compare + for (const auto& [refGeoID, refSMaterial] : surfaceMaterials) { + auto binnedReferenceMaterial = + dynamic_cast(refSMaterial.get()); + + BOOST_REQUIRE(binnedReferenceMaterial != nullptr); + + auto it = surfaceMapsRead.find(refGeoID); + BOOST_REQUIRE(it != surfaceMapsRead.end()); + const auto& readMaterial = it->second; + BOOST_REQUIRE(readMaterial != nullptr); + const auto* binnedMaterial = + dynamic_cast(readMaterial.get()); + BOOST_REQUIRE(binnedMaterial != nullptr); + + // Check the binning + BOOST_CHECK_EQUAL(binnedMaterial->binUtility().bins(0), + binnedReferenceMaterial->binUtility().bins(0)); + BOOST_CHECK_EQUAL(binnedMaterial->binUtility().bins(1), + binnedReferenceMaterial->binUtility().bins(1)); + + // Compare the material matrix + const auto& materialMatrix = binnedMaterial->fullMaterial(); + const auto& referenceMaterialMatrix = + binnedReferenceMaterial->fullMaterial(); + + BOOST_REQUIRE_EQUAL(materialMatrix.size(), referenceMaterialMatrix.size()); + for (std::size_t i = 0; i < materialMatrix.size(); ++i) { + BOOST_REQUIRE_EQUAL(materialMatrix[i].size(), + referenceMaterialMatrix[i].size()); + for (std::size_t j = 0; j < materialMatrix[i].size(); ++j) { + const auto& mat = materialMatrix[i][j]; + const auto& refMat = referenceMaterialMatrix[i][j]; + BOOST_CHECK_CLOSE(mat.material().X0(), refMat.material().X0(), 1e-6); + BOOST_CHECK_CLOSE(mat.material().L0(), refMat.material().L0(), 1e-6); + BOOST_CHECK_CLOSE(mat.material().Ar(), refMat.material().Ar(), 1e-6); + BOOST_CHECK_CLOSE(mat.material().Z(), refMat.material().Z(), 1e-6); + BOOST_CHECK_CLOSE(mat.thickness(), refMat.thickness(), 1e-6); + } + } + } + // Create the accessor - compressed writing Acts::RootMaterialMapAccessor::Config cfgIndexed{true}; Acts::RootMaterialMapAccessor accessorIndexed(cfgIndexed); From 4423ef66c4343cc4dc30b9c67ade59541e9877ed Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Tue, 8 Jul 2025 15:56:14 +0200 Subject: [PATCH 05/30] cleanup volume maps / surface maps --- .../Acts/Material/DetectorMaterialMaps.hpp | 28 +++ Core/include/Acts/Material/MaterialMapper.hpp | 9 +- Core/src/Material/MaterialMapper.cpp | 2 +- .../MaterialMapping/IMaterialWriter.hpp | 18 +- .../MappingMaterialDecorator.hpp | 4 +- .../MaterialMapping/MaterialMapping.hpp | 12 +- .../Io/Json/JsonMaterialWriter.hpp | 12 +- .../Io/Root/RootMaterialDecorator.hpp | 55 +----- .../Io/Root/RootMaterialWriter.hpp | 45 +---- .../Io/Root/src/RootMaterialDecorator.cpp | 170 ++-------------- Examples/Io/Root/src/RootMaterialWriter.cpp | 181 ++++-------------- Examples/Python/src/RootOutput.cpp | 10 +- .../Plugins/Json/JsonMaterialDecorator.hpp | 8 +- .../Plugins/Json/MaterialMapJsonConverter.hpp | 7 +- Plugins/Json/src/MaterialMapJsonConverter.cpp | 12 +- .../Plugins/Root/RootMaterialMapAccessor.hpp | 13 +- Plugins/Root/src/RootMaterialMapAccessor.cpp | 21 +- 17 files changed, 134 insertions(+), 473 deletions(-) create mode 100644 Core/include/Acts/Material/DetectorMaterialMaps.hpp diff --git a/Core/include/Acts/Material/DetectorMaterialMaps.hpp b/Core/include/Acts/Material/DetectorMaterialMaps.hpp new file mode 100644 index 00000000000..62f21e8eb67 --- /dev/null +++ b/Core/include/Acts/Material/DetectorMaterialMaps.hpp @@ -0,0 +1,28 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 CERN for the benefit of the ACTS project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "Acts/Material/ISurfaceMaterial.hpp" +#include "Acts/Material/IVolumeMaterial.hpp" + +#include +#include +#include + +namespace Acts { + + using SurfaceMaterialMaps = + std::map>; + using VolumeMaterialMaps = + std::map>; + using DetectorMaterialMaps = + std::pair; + +} // namespace Acts \ No newline at end of file diff --git a/Core/include/Acts/Material/MaterialMapper.hpp b/Core/include/Acts/Material/MaterialMapper.hpp index 53f8b99bf69..4381da022b3 100644 --- a/Core/include/Acts/Material/MaterialMapper.hpp +++ b/Core/include/Acts/Material/MaterialMapper.hpp @@ -10,6 +10,7 @@ #include "Acts/Geometry/GeometryContext.hpp" #include "Acts/MagneticField/MagneticFieldContext.hpp" +#include "Acts/Material/DetectorMaterialMaps.hpp" #include "Acts/Material/MaterialInteraction.hpp" #include "Acts/Material/MaterialInteractionAssignment.hpp" #include "Acts/Material/interface/IAssignmentFinder.hpp" @@ -24,14 +25,6 @@ namespace Acts { /// @brief material mapping procedure class MaterialMapper { public: - /// @brief The material maps - using SurfaceMaterialMaps = - std::map>; - using VolumeMaterialMaps = - std::map>; - using DetectorMaterialMaps = - std::pair; - /// @brief nested configuration struct struct Config { // The assignment finder diff --git a/Core/src/Material/MaterialMapper.cpp b/Core/src/Material/MaterialMapper.cpp index 2797d7e5f93..7ed4d08e53c 100644 --- a/Core/src/Material/MaterialMapper.cpp +++ b/Core/src/Material/MaterialMapper.cpp @@ -79,7 +79,7 @@ Acts::MaterialMapper::mapMaterial(State& state, const GeometryContext& gctx, return {mappedMaterial, unmappedMaterial}; } -Acts::MaterialMapper::DetectorMaterialMaps Acts::MaterialMapper::finalizeMaps( +Acts::DetectorMaterialMaps Acts::MaterialMapper::finalizeMaps( const State& state) const { // The final maps DetectorMaterialMaps detectorMaterialMaps; diff --git a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/IMaterialWriter.hpp b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/IMaterialWriter.hpp index 2596b537052..a64e1798cae 100644 --- a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/IMaterialWriter.hpp +++ b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/IMaterialWriter.hpp @@ -9,23 +9,7 @@ #pragma once #include "Acts/Geometry/GeometryIdentifier.hpp" - -#include -#include - -namespace Acts { - -class ISurfaceMaterial; -class IVolumeMaterial; - -using SurfaceMaterialMap = - std::map>; - -using VolumeMaterialMap = - std::map>; - -using DetectorMaterialMaps = std::pair; -} // namespace Acts +#include "Acts/Material/DetectorMaterialMaps.hpp" namespace ActsExamples { diff --git a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MappingMaterialDecorator.hpp b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MappingMaterialDecorator.hpp index 5f3bcca5936..9c2a87f0f76 100644 --- a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MappingMaterialDecorator.hpp +++ b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MappingMaterialDecorator.hpp @@ -41,7 +41,7 @@ class MappingMaterialDecorator : public IMaterialDecorator { public: using BinningMap = std::map>; - using VolumeMaterialMap = + using VolumeMaterialMaps = std::map>; MappingMaterialDecorator(const Acts::TrackingGeometry& tGeometry, @@ -276,7 +276,7 @@ class MappingMaterialDecorator : public IMaterialDecorator { private: BinningMap m_binningMap; - VolumeMaterialMap m_volumeMaterialMap; + VolumeMaterialMaps m_volumeMaterialMap; bool m_clearSurfaceMaterial{true}; bool m_clearVolumeMaterial{true}; diff --git a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MaterialMapping.hpp b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MaterialMapping.hpp index 713b9ad13e1..47c5a54aef1 100644 --- a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MaterialMapping.hpp +++ b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MaterialMapping.hpp @@ -13,6 +13,7 @@ #include "Acts/MagneticField/MagneticFieldContext.hpp" #include "Acts/Material/MaterialInteraction.hpp" #include "Acts/Material/SurfaceMaterialMapper.hpp" +#include "Acts/Material/DetectorMaterialMaps.hpp" #include "Acts/Material/VolumeMaterialMapper.hpp" #include "Acts/Utilities/Logger.hpp" #include "ActsExamples/Framework/DataHandle.hpp" @@ -32,18 +33,7 @@ #include namespace Acts { - class TrackingGeometry; -class ISurfaceMaterial; -class IVolumeMaterial; - -using SurfaceMaterialMap = - std::map>; - -using VolumeMaterialMap = - std::map>; - -using DetectorMaterialMaps = std::pair; } // namespace Acts namespace ActsExamples { diff --git a/Examples/Io/Json/include/ActsExamples/Io/Json/JsonMaterialWriter.hpp b/Examples/Io/Json/include/ActsExamples/Io/Json/JsonMaterialWriter.hpp index c59a5a2a909..01c203048ef 100644 --- a/Examples/Io/Json/include/ActsExamples/Io/Json/JsonMaterialWriter.hpp +++ b/Examples/Io/Json/include/ActsExamples/Io/Json/JsonMaterialWriter.hpp @@ -12,6 +12,7 @@ #include "Acts/Geometry/GeometryIdentifier.hpp" #include "Acts/Material/ISurfaceMaterial.hpp" #include "Acts/Material/IVolumeMaterial.hpp" +#include "Acts/Material/DetectorMaterialMaps.hpp" #include "Acts/Plugins/Json/MaterialMapJsonConverter.hpp" #include "Acts/Utilities/EnumBitwiseOperators.hpp" #include "Acts/Utilities/Logger.hpp" @@ -27,18 +28,7 @@ #include namespace Acts { - class TrackingGeometry; -class ISurfaceMaterial; -class IVolumeMaterial; - -using SurfaceMaterialMap = - std::map>; - -using VolumeMaterialMap = - std::map>; - -using DetectorMaterialMaps = std::pair; } // namespace Acts namespace ActsExamples { diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp index 7397a2ae255..94f0efc6a30 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp @@ -14,9 +14,11 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -26,17 +28,6 @@ class TFile; -namespace Acts { -class ISurfaceMaterial; -class IVolumeMaterial; - -using SurfaceMaterialMap = - std::map>; -using VolumeMaterialMap = - std::map>; -using DetectorMaterialMaps = std::pair; -} // namespace Acts - namespace ActsExamples { /// @class RootMaterialDecorator @@ -48,42 +39,8 @@ class RootMaterialDecorator : public Acts::IMaterialDecorator { /// Configuration of the Reader class Config { public: - /// The name of the output surface tree - std::string folderSurfaceNameBase = "SurfaceMaterial"; - /// The name of the output volume tree - std::string folderVolumeNameBase = "VolumeMaterial"; - /// The volume identification string - std::string voltag = "_vol"; - /// The boundary identification string - std::string boutag = "_bou"; - /// The layer identification string - std::string laytag = "_lay"; - /// The approach identification string - std::string apptag = "_app"; - /// The sensitive identification string - std::string sentag = "_sen"; - /// The bin number tag - std::string ntag = "n"; - /// The value tag -> binning values: AxisZ, AxisR, AxisPhi, etc. - std::string vtag = "v"; - /// The option tag -> binning options: open, closed - std::string otag = "o"; - /// The range min tag: min value - std::string mintag = "min"; - /// The range max tag: max value - std::string maxtag = "max"; - /// The thickness tag - std::string ttag = "t"; - /// The x0 tag - std::string x0tag = "x0"; - /// The l0 tag - std::string l0tag = "l0"; - /// The A tag - std::string atag = "A"; - /// The Z tag - std::string ztag = "Z"; - /// The rho tag - std::string rhotag = "rho"; + /// Accessor config + Acts::RootMaterialMapAccessor::Config accessorConfig; /// The name of the output file std::string fileName = "material-maps.root"; }; @@ -144,10 +101,10 @@ class RootMaterialDecorator : public Acts::IMaterialDecorator { TFile* m_inputFile{nullptr}; /// Surface based material - Acts::SurfaceMaterialMap m_surfaceMaterialMap; + Acts::SurfaceMaterialMaps m_surfaceMaterialMap; /// Volume based material - Acts::VolumeMaterialMap m_volumeMaterialMap; + Acts::VolumeMaterialMaps m_volumeMaterialMap; bool m_clearSurfaceMaterial{true}; diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp index a4c4a4675ee..ffc259a638f 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -35,11 +36,6 @@ class Layer; class TrackingGeometry; class TrackingVolume; -using SurfaceMaterialMap = - std::map>; -using VolumeMaterialMap = - std::map>; -using DetectorMaterialMaps = std::pair; } // namespace Acts namespace ActsExamples { @@ -68,43 +64,8 @@ class RootMaterialWriter : public IMaterialWriter { /// Steering to handle volume data bool processVolumes = true; - - /// The name of the output surface tree - std::string folderSurfaceNameBase = "SurfaceMaterial"; - /// The name of the output volume tree - std::string folderVolumeNameBase = "VolumeMaterial"; - /// The volume identification string - std::string voltag = "_vol"; - /// The boundary identification string - std::string boutag = "_bou"; - /// The layer identification string - std::string laytag = "_lay"; - /// The approach identification string - std::string apptag = "_app"; - /// The sensitive identification string - std::string sentag = "_sen"; - /// The bin number tag - std::string ntag = "n"; - /// The value tag -> binning values: AxisZ, AxisR, AxisPhi, etc. - std::string vtag = "v"; - /// The option tag -> binning options: open, closed - std::string otag = "o"; - /// The range min tag: min value - std::string mintag = "min"; - /// The range max tag: max value - std::string maxtag = "max"; - /// The thickness tag - std::string ttag = "t"; - /// The x0 tag - std::string x0tag = "x0"; - /// The l0 tag - std::string l0tag = "l0"; - /// The A tag - std::string atag = "A"; - /// The Z tag - std::string ztag = "Z"; - /// The rho tag - std::string rhotag = "rho"; + // The accessor configuration + Acts::RootMaterialMapAccessor::Config accessorConfig; /// The name of the output file std::string filePath = "material-maps.root"; /// The file mode diff --git a/Examples/Io/Root/src/RootMaterialDecorator.cpp b/Examples/Io/Root/src/RootMaterialDecorator.cpp index 2bbcedf1292..c283d334cae 100644 --- a/Examples/Io/Root/src/RootMaterialDecorator.cpp +++ b/Examples/Io/Root/src/RootMaterialDecorator.cpp @@ -54,9 +54,9 @@ ActsExamples::RootMaterialDecorator::RootMaterialDecorator( : m_cfg(config), m_logger{Acts::getDefaultLogger("RootMaterialDecorator", level)} { // Validate the configuration - if (m_cfg.folderSurfaceNameBase.empty()) { + if (m_cfg.accessorConfig.folderSurfaceNameBase.empty()) { throw std::invalid_argument("Missing surface folder name base"); - } else if (m_cfg.folderVolumeNameBase.empty()) { + } else if (m_cfg.accessorConfig.folderVolumeNameBase.empty()) { throw std::invalid_argument("Missing volume folder name base"); } else if (m_cfg.fileName.empty()) { throw std::invalid_argument("Missing file name"); @@ -68,6 +68,12 @@ ActsExamples::RootMaterialDecorator::RootMaterialDecorator( throw std::ios_base::failure("Could not open '" + m_cfg.fileName + "'"); } + Acts::RootMaterialMapAccessor accessor( + m_cfg.accessorConfig, m_logger->clone("RootMaterialMapAccessor")); + auto [surfaceMaps, volumeMaps] = accessor.read(*m_inputFile); + + m_surfaceMaterialMap = std::move(surfaceMaps); + // Get the list of keys from the file TList* tlist = m_inputFile->GetListOfKeys(); auto tIter = tlist->MakeIterator(); @@ -79,145 +85,7 @@ ActsExamples::RootMaterialDecorator::RootMaterialDecorator( std::string tdName(key->GetName()); ACTS_VERBOSE("Processing directory: " << tdName); - - // volume - std::vector splitNames; - iter_split(splitNames, tdName, - boost::algorithm::first_finder(m_cfg.voltag)); - // Surface Material - if (splitNames[0] == m_cfg.folderSurfaceNameBase) { - // The surface material to be read in for this - std::shared_ptr sMaterial = nullptr; - - boost::split(splitNames, splitNames[1], boost::is_any_of("_")); - Acts::GeometryIdentifier::Value volID = std::stoi(splitNames[0]); - // boundary - iter_split(splitNames, tdName, - boost::algorithm::first_finder(m_cfg.boutag)); - boost::split(splitNames, splitNames[1], boost::is_any_of("_")); - Acts::GeometryIdentifier::Value bouID = std::stoi(splitNames[0]); - // layer - iter_split(splitNames, tdName, - boost::algorithm::first_finder(m_cfg.laytag)); - boost::split(splitNames, splitNames[1], boost::is_any_of("_")); - Acts::GeometryIdentifier::Value layID = std::stoi(splitNames[0]); - // approach - iter_split(splitNames, tdName, - boost::algorithm::first_finder(m_cfg.apptag)); - boost::split(splitNames, splitNames[1], boost::is_any_of("_")); - Acts::GeometryIdentifier::Value appID = std::stoi(splitNames[0]); - // sensitive - iter_split(splitNames, tdName, - boost::algorithm::first_finder(m_cfg.sentag)); - Acts::GeometryIdentifier::Value senID = std::stoi(splitNames[1]); - - // Reconstruct the geometry ID - auto geoID = Acts::GeometryIdentifier() - .withVolume(volID) - .withBoundary(bouID) - .withLayer(layID) - .withApproach(appID) - .withSensitive(senID); - ACTS_VERBOSE("GeometryIdentifier re-constructed as " << geoID); - - // Construct the names - std::string nName = tdName + "/" + m_cfg.ntag; - std::string vName = tdName + "/" + m_cfg.vtag; - std::string oName = tdName + "/" + m_cfg.otag; - std::string minName = tdName + "/" + m_cfg.mintag; - std::string maxName = tdName + "/" + m_cfg.maxtag; - std::string tName = tdName + "/" + m_cfg.ttag; - std::string x0Name = tdName + "/" + m_cfg.x0tag; - std::string l0Name = tdName + "/" + m_cfg.l0tag; - std::string aName = tdName + "/" + m_cfg.atag; - std::string zName = tdName + "/" + m_cfg.ztag; - std::string rhoName = tdName + "/" + m_cfg.rhotag; - - // Get the histograms - TH1F* n = dynamic_cast(m_inputFile->Get(nName.c_str())); - TH1F* v = dynamic_cast(m_inputFile->Get(vName.c_str())); - TH1F* o = dynamic_cast(m_inputFile->Get(oName.c_str())); - TH1F* min = dynamic_cast(m_inputFile->Get(minName.c_str())); - TH1F* max = dynamic_cast(m_inputFile->Get(maxName.c_str())); - TH2F* t = dynamic_cast(m_inputFile->Get(tName.c_str())); - TH2F* x0 = dynamic_cast(m_inputFile->Get(x0Name.c_str())); - TH2F* l0 = dynamic_cast(m_inputFile->Get(l0Name.c_str())); - TH2F* A = dynamic_cast(m_inputFile->Get(aName.c_str())); - TH2F* Z = dynamic_cast(m_inputFile->Get(zName.c_str())); - TH2F* rho = dynamic_cast(m_inputFile->Get(rhoName.c_str())); - - std::vector hists{n, v, o, min, max, t, x0, l0, A, Z, rho}; - - // Only go on when you have all histograms - if (std::ranges::all_of( - hists, [](const auto* hist) { return hist != nullptr; })) { - // Get the number of bins - int nbins0 = t->GetNbinsX(); - int nbins1 = t->GetNbinsY(); - - // The material matrix - Acts::MaterialSlabMatrix materialMatrix( - nbins1, - Acts::MaterialSlabVector(nbins0, Acts::MaterialSlab::Nothing())); - - // We need binned material properties - if (nbins0 * nbins1 > 1) { - // Fill the matrix first - for (int ib0 = 1; ib0 <= nbins0; ++ib0) { - for (int ib1 = 1; ib1 <= nbins1; ++ib1) { - double dt = t->GetBinContent(ib0, ib1); - if (dt > 0.) { - double dx0 = x0->GetBinContent(ib0, ib1); - double dl0 = l0->GetBinContent(ib0, ib1); - double da = A->GetBinContent(ib0, ib1); - double dz = Z->GetBinContent(ib0, ib1); - double drho = rho->GetBinContent(ib0, ib1); - // Create material properties - const auto material = - Acts::Material::fromMassDensity(dx0, dl0, da, dz, drho); - materialMatrix[ib1 - 1][ib0 - 1] = - Acts::MaterialSlab(material, dt); - } - } - } - - // Now reconstruct the bin untilities - Acts::BinUtility bUtility; - for (int ib = 1; ib < n->GetNbinsX() + 1; ++ib) { - std::size_t nbins = static_cast(n->GetBinContent(ib)); - auto val = static_cast(v->GetBinContent(ib)); - auto opt = static_cast(o->GetBinContent(ib)); - float rmin = min->GetBinContent(ib); - float rmax = max->GetBinContent(ib); - bUtility += Acts::BinUtility(nbins, rmin, rmax, opt, val); - } - ACTS_VERBOSE("Created " << bUtility); - - // Construct the binned material with the right bin utility - sMaterial = std::make_shared( - bUtility, std::move(materialMatrix)); - - } else { - // Only homogeneous material present - double dt = t->GetBinContent(1, 1); - double dx0 = x0->GetBinContent(1, 1); - double dl0 = l0->GetBinContent(1, 1); - double da = A->GetBinContent(1, 1); - double dz = Z->GetBinContent(1, 1); - double drho = rho->GetBinContent(1, 1); - // Create and set the homogeneous surface material - const auto material = - Acts::Material::fromMassDensity(dx0, dl0, da, dz, drho); - sMaterial = std::make_shared( - Acts::MaterialSlab(material, dt)); - } - } - ACTS_VERBOSE("Successfully read Material for : " << geoID); - - // Insert into the new collection - m_surfaceMaterialMap.insert({geoID, std::move(sMaterial)}); - - } else if (splitNames[0] == m_cfg.folderVolumeNameBase) { + if (splitNames[0] == m_cfg.accessorConfig.folderVolumeNameBase) { // The volume material to be read in for this std::shared_ptr vMaterial = nullptr; // Volume key @@ -229,16 +97,16 @@ ActsExamples::RootMaterialDecorator::RootMaterialDecorator( ACTS_VERBOSE("GeometryIdentifier re-constructed as " << geoID); // Construct the names - std::string nName = tdName + "/" + m_cfg.ntag; - std::string vName = tdName + "/" + m_cfg.vtag; - std::string oName = tdName + "/" + m_cfg.otag; - std::string minName = tdName + "/" + m_cfg.mintag; - std::string maxName = tdName + "/" + m_cfg.maxtag; - std::string x0Name = tdName + "/" + m_cfg.x0tag; - std::string l0Name = tdName + "/" + m_cfg.l0tag; - std::string aName = tdName + "/" + m_cfg.atag; - std::string zName = tdName + "/" + m_cfg.ztag; - std::string rhoName = tdName + "/" + m_cfg.rhotag; + std::string nName = tdName + "/" + m_cfg.accessorConfig.ntag; + std::string vName = tdName + "/" + m_cfg.accessorConfig.vtag; + std::string oName = tdName + "/" + m_cfg.accessorConfig.otag; + std::string minName = tdName + "/" + m_cfg.accessorConfig.mintag; + std::string maxName = tdName + "/" + m_cfg.accessorConfig.maxtag; + std::string x0Name = tdName + "/" + m_cfg.accessorConfig.x0tag; + std::string l0Name = tdName + "/" + m_cfg.accessorConfig.l0tag; + std::string aName = tdName + "/" + m_cfg.accessorConfig.atag; + std::string zName = tdName + "/" + m_cfg.accessorConfig.ztag; + std::string rhoName = tdName + "/" + m_cfg.accessorConfig.rhotag; // Get the histograms TH1F* n = dynamic_cast(m_inputFile->Get(nName.c_str())); diff --git a/Examples/Io/Root/src/RootMaterialWriter.cpp b/Examples/Io/Root/src/RootMaterialWriter.cpp index f097d868b60..f55d1a99ca9 100644 --- a/Examples/Io/Root/src/RootMaterialWriter.cpp +++ b/Examples/Io/Root/src/RootMaterialWriter.cpp @@ -14,6 +14,7 @@ #include "Acts/Geometry/Layer.hpp" #include "Acts/Geometry/TrackingGeometry.hpp" #include "Acts/Geometry/TrackingVolume.hpp" +#include "Acts/Material/DetectorMaterialMaps.hpp" #include "Acts/Material/ISurfaceMaterial.hpp" #include "Acts/Material/IVolumeMaterial.hpp" #include "Acts/Material/InterpolatedMaterialMap.hpp" @@ -46,9 +47,9 @@ ActsExamples::RootMaterialWriter::RootMaterialWriter( : m_cfg(config), m_logger{Acts::getDefaultLogger("RootMaterialWriter", level)} { // Validate the configuration - if (m_cfg.folderSurfaceNameBase.empty()) { + if (m_cfg.accessorConfig.folderSurfaceNameBase.empty()) { throw std::invalid_argument("Missing surface folder name base"); - } else if (m_cfg.folderVolumeNameBase.empty()) { + } else if (m_cfg.accessorConfig.folderVolumeNameBase.empty()) { throw std::invalid_argument("Missing volume folder name base"); } else if (m_cfg.filePath.empty()) { throw std::invalid_argument("Missing file name"); @@ -66,129 +67,18 @@ void ActsExamples::RootMaterialWriter::writeMaterial( // Change to the output file m_outputFile->cd(); - auto& surfaceMaps = detMaterial.first; - for (auto& [key, value] : surfaceMaps) { - // Get the Surface material - const Acts::ISurfaceMaterial* sMaterial = value.get(); - - // get the geometry ID - Acts::GeometryIdentifier geoID = key; - // decode the geometryID - const auto gvolID = geoID.volume(); - const auto gbouID = geoID.boundary(); - const auto glayID = geoID.layer(); - const auto gappID = geoID.approach(); - const auto gsenID = geoID.sensitive(); - // create the directory - std::string tdName = m_cfg.folderSurfaceNameBase.c_str(); - tdName += m_cfg.voltag + std::to_string(gvolID); - tdName += m_cfg.boutag + std::to_string(gbouID); - tdName += m_cfg.laytag + std::to_string(glayID); - tdName += m_cfg.apptag + std::to_string(gappID); - tdName += m_cfg.sentag + std::to_string(gsenID); - // create a new directory - m_outputFile->mkdir(tdName.c_str()); - m_outputFile->cd(tdName.c_str()); - - ACTS_VERBOSE("Writing out map at " << tdName); - - std::size_t bins0 = 1, bins1 = 1; - // understand what sort of material you have in mind - const Acts::BinnedSurfaceMaterial* bsm = - dynamic_cast(sMaterial); - if (bsm != nullptr) { - // overwrite the bin numbers - bins0 = bsm->binUtility().bins(0); - bins1 = bsm->binUtility().bins(1); - - // Get the binning data - auto& binningData = bsm->binUtility().binningData(); - // 1-D or 2-D maps - std::size_t binningBins = binningData.size(); - - // The bin number information - TH1F* n = new TH1F(m_cfg.ntag.c_str(), "bins; bin", binningBins, -0.5, - binningBins - 0.5); - - // The binning value information - TH1F* v = new TH1F(m_cfg.vtag.c_str(), "binning values; bin", binningBins, - -0.5, binningBins - 0.5); - - // The binning option information - TH1F* o = new TH1F(m_cfg.otag.c_str(), "binning options; bin", - binningBins, -0.5, binningBins - 0.5); - - // The binning option information - TH1F* min = new TH1F(m_cfg.mintag.c_str(), "min; bin", binningBins, -0.5, - binningBins - 0.5); - - // The binning option information - TH1F* max = new TH1F(m_cfg.maxtag.c_str(), "max; bin", binningBins, -0.5, - binningBins - 0.5); + const auto& [surfaceMaps, volumeMaps] = detMaterial; - // Now fill the histogram content - std::size_t b = 1; - for (auto bData : binningData) { - // Fill: nbins, value, option, min, max - n->SetBinContent(b, static_cast(binningData[b - 1].bins())); - v->SetBinContent(b, static_cast(binningData[b - 1].binvalue)); - o->SetBinContent(b, static_cast(binningData[b - 1].option)); - min->SetBinContent(b, binningData[b - 1].min); - max->SetBinContent(b, binningData[b - 1].max); - ++b; - } - n->Write(); - v->Write(); - o->Write(); - min->Write(); - max->Write(); - } + // Write the surface material maps + Acts::RootMaterialMapAccessor accessor( + m_cfg.accessorConfig, m_logger->clone("RootMaterialMapAccessor")); - TH2F* t = new TH2F(m_cfg.ttag.c_str(), "thickness [mm] ;b0 ;b1", bins0, - -0.5, bins0 - 0.5, bins1, -0.5, bins1 - 0.5); - TH2F* x0 = new TH2F(m_cfg.x0tag.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, - bins0 - 0.5, bins1, -0.5, bins1 - 0.5); - TH2F* l0 = new TH2F(m_cfg.l0tag.c_str(), "#Lambda_{0} [mm] ;b0 ;b1", bins0, - -0.5, bins0 - 0.5, bins1, -0.5, bins1 - 0.5); - TH2F* A = new TH2F(m_cfg.atag.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, - bins0 - 0.5, bins1, -0.5, bins1 - 0.5); - TH2F* Z = new TH2F(m_cfg.ztag.c_str(), "#Lambda_{0} [mm] ;b0 ;b1", bins0, - -0.5, bins0 - 0.5, bins1, -0.5, bins1 - 0.5); - TH2F* rho = new TH2F(m_cfg.rhotag.c_str(), "#rho [g/mm^3] ;b0 ;b1", bins0, - -0.5, bins0 - 0.5, bins1, -0.5, bins1 - 0.5); - - // loop over the material and fill - if (bsm != nullptr) { - const auto& materialMatrix = bsm->fullMaterial(); - for (auto [b1, materialVector] : Acts::enumerate(materialMatrix)) { - for (auto [b0, mat] : Acts::enumerate(materialVector)) { - t->SetBinContent(b0 + 1, b1 + 1, mat.thickness()); - x0->SetBinContent(b0 + 1, b1 + 1, mat.material().X0()); - l0->SetBinContent(b0 + 1, b1 + 1, mat.material().L0()); - A->SetBinContent(b0 + 1, b1 + 1, mat.material().Ar()); - Z->SetBinContent(b0 + 1, b1 + 1, mat.material().Z()); - rho->SetBinContent(b0 + 1, b1 + 1, mat.material().massDensity()); - } - } - } else if (bins1 == 1 && bins0 == 1) { - // homogeneous surface - auto mat = sMaterial->materialSlab(Acts::Vector3{0, 0, 0}); - t->SetBinContent(1, 1, mat.thickness()); - x0->SetBinContent(1, 1, mat.material().X0()); - l0->SetBinContent(1, 1, mat.material().L0()); - A->SetBinContent(1, 1, mat.material().Ar()); - Z->SetBinContent(1, 1, mat.material().Z()); - rho->SetBinContent(1, 1, mat.material().massDensity()); - } - t->Write(); - x0->Write(); - l0->Write(); - A->Write(); - Z->Write(); - rho->Write(); + for (const auto& [geoId, sMap] : surfaceMaps) { + // Get the Surface material + accessor.write(*m_outputFile, geoId, *sMap); } - auto& volumeMaps = detMaterial.second; + // Write the volume material maps for (auto& [key, value] : volumeMaps) { // Get the Volume material const Acts::IVolumeMaterial* vMaterial = value.get(); @@ -203,8 +93,8 @@ void ActsExamples::RootMaterialWriter::writeMaterial( const auto gvolID = geoID.volume(); // create the directory - std::string tdName = m_cfg.folderVolumeNameBase.c_str(); - tdName += m_cfg.voltag + std::to_string(gvolID); + std::string tdName = m_cfg.accessorConfig.folderVolumeNameBase.c_str(); + tdName += m_cfg.accessorConfig.voltag + std::to_string(gvolID); // create a new directory m_outputFile->mkdir(tdName.c_str()); @@ -236,24 +126,26 @@ void ActsExamples::RootMaterialWriter::writeMaterial( std::size_t binningBins = binningData.size(); // The bin number information - TH1F* n = new TH1F(m_cfg.ntag.c_str(), "bins; bin", binningBins, -0.5, - binningBins - 0.5); + TH1F* n = new TH1F(m_cfg.accessorConfig.ntag.c_str(), "bins; bin", + binningBins, -0.5, binningBins - 0.5); // The binning value information - TH1F* v = new TH1F(m_cfg.vtag.c_str(), "binning values; bin", binningBins, - -0.5, binningBins - 0.5); + TH1F* v = + new TH1F(m_cfg.accessorConfig.vtag.c_str(), "binning values; bin", + binningBins, -0.5, binningBins - 0.5); // The binning option information - TH1F* o = new TH1F(m_cfg.otag.c_str(), "binning options; bin", - binningBins, -0.5, binningBins - 0.5); + TH1F* o = + new TH1F(m_cfg.accessorConfig.otag.c_str(), "binning options; bin", + binningBins, -0.5, binningBins - 0.5); // The binning option information - TH1F* min = new TH1F(m_cfg.mintag.c_str(), "min; bin", binningBins, -0.5, - binningBins - 0.5); + TH1F* min = new TH1F(m_cfg.accessorConfig.mintag.c_str(), "min; bin", + binningBins, -0.5, binningBins - 0.5); // The binning option information - TH1F* max = new TH1F(m_cfg.maxtag.c_str(), "max; bin", binningBins, -0.5, - binningBins - 0.5); + TH1F* max = new TH1F(m_cfg.accessorConfig.maxtag.c_str(), "max; bin", + binningBins, -0.5, binningBins - 0.5); // Now fill the histogram content std::size_t b = 1; @@ -273,16 +165,19 @@ void ActsExamples::RootMaterialWriter::writeMaterial( max->Write(); } - TH1F* x0 = new TH1F(m_cfg.x0tag.c_str(), "X_{0} [mm] ;gridPoint", points, - -0.5, points - 0.5); - TH1F* l0 = new TH1F(m_cfg.l0tag.c_str(), "#Lambda_{0} [mm] ;gridPoint", - points, -0.5, points - 0.5); - TH1F* A = new TH1F(m_cfg.atag.c_str(), "X_{0} [mm] ;gridPoint", points, - -0.5, points - 0.5); - TH1F* Z = new TH1F(m_cfg.ztag.c_str(), "#Lambda_{0} [mm] ;gridPoint", - points, -0.5, points - 0.5); - TH1F* rho = new TH1F(m_cfg.rhotag.c_str(), "#rho [g/mm^3] ;gridPoint", - points, -0.5, points - 0.5); + TH1F* x0 = new TH1F(m_cfg.accessorConfig.x0tag.c_str(), + "X_{0} [mm] ;gridPoint", points, -0.5, points - 0.5); + TH1F* l0 = + new TH1F(m_cfg.accessorConfig.l0tag.c_str(), + "#Lambda_{0} [mm] ;gridPoint", points, -0.5, points - 0.5); + TH1F* A = new TH1F(m_cfg.accessorConfig.atag.c_str(), + "X_{0} [mm] ;gridPoint", points, -0.5, points - 0.5); + TH1F* Z = + new TH1F(m_cfg.accessorConfig.ztag.c_str(), + "#Lambda_{0} [mm] ;gridPoint", points, -0.5, points - 0.5); + TH1F* rho = + new TH1F(m_cfg.accessorConfig.rhotag.c_str(), + "#rho [g/mm^3] ;gridPoint", points, -0.5, points - 0.5); // homogeneous volume if (points == 1) { auto mat = vMaterial->material({0, 0, 0}); diff --git a/Examples/Python/src/RootOutput.cpp b/Examples/Python/src/RootOutput.cpp index 7d5d9a2d69c..1c3220424eb 100644 --- a/Examples/Python/src/RootOutput.cpp +++ b/Examples/Python/src/RootOutput.cpp @@ -7,6 +7,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. #include "Acts/Plugins/Python/Utilities.hpp" +#include "Acts/Plugins/Root/RootMaterialMapAccessor.hpp" #include "ActsExamples/Io/Root/RootBFieldWriter.hpp" #include "ActsExamples/Io/Root/RootMaterialTrackWriter.hpp" #include "ActsExamples/Io/Root/RootMaterialWriter.hpp" @@ -156,13 +157,14 @@ void addRootOutput(Context& ctx) { .def("write", py::overload_cast( &Writer::write)); + auto ac = py::class_(w, "AccessorConfig") + .def(py::init<>()); + auto c = py::class_(w, "Config").def(py::init<>()); ACTS_PYTHON_STRUCT(c, processSensitives, processApproaches, - processRepresenting, processBoundaries, processVolumes, - folderSurfaceNameBase, folderVolumeNameBase, voltag, - boutag, laytag, apptag, sentag, ntag, vtag, otag, mintag, - maxtag, ttag, x0tag, l0tag, atag, ztag, rhotag, filePath, + processRepresenting, processBoundaries, accessorConfig, + filePath, fileMode); } diff --git a/Plugins/Json/include/Acts/Plugins/Json/JsonMaterialDecorator.hpp b/Plugins/Json/include/Acts/Plugins/Json/JsonMaterialDecorator.hpp index c38046468ce..f630c32b8a8 100644 --- a/Plugins/Json/include/Acts/Plugins/Json/JsonMaterialDecorator.hpp +++ b/Plugins/Json/include/Acts/Plugins/Json/JsonMaterialDecorator.hpp @@ -29,10 +29,10 @@ namespace Acts { /// from a json file class JsonMaterialDecorator : public IMaterialDecorator { public: - using SurfaceMaterialMap = + using SurfaceMaterialMaps = std::map>; - using VolumeMaterialMap = + using VolumeMaterialMaps = std::map>; JsonMaterialDecorator(const MaterialMapJsonConverter::Config& rConfig, @@ -53,8 +53,8 @@ class JsonMaterialDecorator : public IMaterialDecorator { private: MaterialMapJsonConverter::Config m_readerConfig; - SurfaceMaterialMap m_surfaceMaterialMap; - VolumeMaterialMap m_volumeMaterialMap; + SurfaceMaterialMaps m_surfaceMaterialMap; + VolumeMaterialMaps m_volumeMaterialMap; bool m_clearSurfaceMaterial{true}; bool m_clearVolumeMaterial{true}; diff --git a/Plugins/Json/include/Acts/Plugins/Json/MaterialMapJsonConverter.hpp b/Plugins/Json/include/Acts/Plugins/Json/MaterialMapJsonConverter.hpp index 9fdb3f7c284..00ce49cb9a4 100644 --- a/Plugins/Json/include/Acts/Plugins/Json/MaterialMapJsonConverter.hpp +++ b/Plugins/Json/include/Acts/Plugins/Json/MaterialMapJsonConverter.hpp @@ -13,6 +13,7 @@ #include "Acts/Geometry/TrackingGeometry.hpp" #include "Acts/Material/ISurfaceMaterial.hpp" #include "Acts/Material/IVolumeMaterial.hpp" +#include "Acts/Material/DetectorMaterialMaps.hpp" #include "Acts/Plugins/Json/ActsJson.hpp" #include "Acts/Plugins/Json/GeometryHierarchyMapJsonConverter.hpp" #include "Acts/Plugins/Json/ITrackingGeometryJsonDecorator.hpp" @@ -52,12 +53,6 @@ using TrackingVolumeAndMaterial = /// @brief read the material from Json class MaterialMapJsonConverter { public: - using SurfaceMaterialMap = - std::map>; - using VolumeMaterialMap = - std::map>; - using DetectorMaterialMaps = std::pair; - /// @class Config /// Configuration of the Converter class Config { diff --git a/Plugins/Json/src/MaterialMapJsonConverter.cpp b/Plugins/Json/src/MaterialMapJsonConverter.cpp index 51211ac2386..72f5079fb9b 100644 --- a/Plugins/Json/src/MaterialMapJsonConverter.cpp +++ b/Plugins/Json/src/MaterialMapJsonConverter.cpp @@ -251,7 +251,7 @@ Acts::MaterialMapJsonConverter::MaterialMapJsonConverter( nlohmann::json Acts::MaterialMapJsonConverter::materialMapsToJson( const DetectorMaterialMaps& maps, const IVolumeMaterialJsonDecorator* decorator) { - VolumeMaterialMap volumeMap = maps.second; + VolumeMaterialMaps volumeMap = maps.second; std::vector> mapVolumeInit; for (const auto& [key, value] : volumeMap) { @@ -261,7 +261,7 @@ nlohmann::json Acts::MaterialMapJsonConverter::materialMapsToJson( mapVolumeInit); nlohmann::json materialVolume = m_volumeMaterialConverter.toJson(hierarchyVolumeMap, decorator); - SurfaceMaterialMap surfaceMap = maps.first; + SurfaceMaterialMaps surfaceMap = maps.first; std::vector> mapSurfaceInit; for (const auto& [key, value] : surfaceMap) { @@ -277,13 +277,13 @@ nlohmann::json Acts::MaterialMapJsonConverter::materialMapsToJson( return materialMap; } -Acts::MaterialMapJsonConverter::DetectorMaterialMaps +Acts::DetectorMaterialMaps Acts::MaterialMapJsonConverter::jsonToMaterialMaps( const nlohmann::json& materialmap) { nlohmann::json materialVolume = materialmap["Volumes"]; GeometryHierarchyMap hierarchyVolumeMap = m_volumeMaterialConverter.fromJson(materialVolume); - VolumeMaterialMap volumeMap; + VolumeMaterialMaps volumeMap; for (std::size_t i = 0; i < hierarchyVolumeMap.size(); i++) { std::shared_ptr volumePointer( hierarchyVolumeMap.valueAt(i)); @@ -292,14 +292,14 @@ Acts::MaterialMapJsonConverter::jsonToMaterialMaps( nlohmann::json materialSurface = materialmap["Surfaces"]; GeometryHierarchyMap hierarchySurfaceMap = m_surfaceMaterialConverter.fromJson(materialSurface); - SurfaceMaterialMap surfaceMap; + SurfaceMaterialMaps surfaceMap; for (std::size_t i = 0; i < hierarchySurfaceMap.size(); i++) { std::shared_ptr surfacePointer( hierarchySurfaceMap.valueAt(i)); surfaceMap.insert({hierarchySurfaceMap.idAt(i), std::move(surfacePointer)}); } - Acts::MaterialMapJsonConverter::DetectorMaterialMaps maps = {surfaceMap, + Acts::DetectorMaterialMaps maps = {surfaceMap, volumeMap}; // Return the filled maps diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp index 4a49cc91ce9..2ec1524a87a 100644 --- a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp +++ b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp @@ -9,6 +9,7 @@ #pragma once #include "Acts/Utilities/Logger.hpp" +#include "Acts/Material/DetectorMaterialMaps.hpp" #include #include @@ -28,12 +29,6 @@ class HomogeneousSurfaceMaterial; class MaterialSlab; class BinnedSurfaceMaterial; -using SurfaceMaterialMaps = - std::map>; -using VolumeMaterialMaps = - std::map>; -using DetectorMaterial = std::tuple; - /// Simple payload class that can be wrapped for reading /// and writing. class RootMaterialMapAccessor { @@ -116,7 +111,7 @@ class RootMaterialMapAccessor { /// Write the detector maps /// @param rFile the file to write to /// @param detectorMaterial the detector material maps - void write(TFile& rFile, const DetectorMaterial& detectorMaterial); + void write(TFile& rFile, const DetectorMaterialMaps& detectorMaterial); /// Write the material to file /// @param rFile the file to write to @@ -127,7 +122,7 @@ class RootMaterialMapAccessor { /// Read the detector maps /// @param rFile the file to read from - DetectorMaterial read(TFile& rFile); + DetectorMaterialMaps read(TFile& rFile); private: /// @brief Connect the homogeneous material tree for writing @@ -156,7 +151,7 @@ class RootMaterialMapAccessor { void fillBinnedSurfaceMaterial(MaterialTreePayload& payload, const BinnedSurfaceMaterial& bsMaterial); - /// Read the a texture Surface material + /// Read the a texture Surface material /// @param rFile the file to read from /// @param tdName the name of the texture directory /// @param indexedMaterialTree the indexed material tree, if available diff --git a/Plugins/Root/src/RootMaterialMapAccessor.cpp b/Plugins/Root/src/RootMaterialMapAccessor.cpp index a695a7a2073..5941e0d37ca 100644 --- a/Plugins/Root/src/RootMaterialMapAccessor.cpp +++ b/Plugins/Root/src/RootMaterialMapAccessor.cpp @@ -145,8 +145,8 @@ void Acts::RootMaterialMapAccessor::write( } void Acts::RootMaterialMapAccessor::write( - TFile& rFile, const DetectorMaterial& detectorMaterial) { - auto [surfaceMaterials, volumeMaterials] = detectorMaterial; + TFile& rFile, const DetectorMaterialMaps& DetectorMaterialMaps) { + auto [surfaceMaterials, volumeMaterials] = DetectorMaterialMaps; for (const auto& [geoID, sMaterial] : surfaceMaterials) { write(rFile, geoID, *sMaterial); } @@ -237,7 +237,7 @@ void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( const auto& materialMatrix = bsMaterial.fullMaterial(); for (auto [b1, materialVector] : enumerate(materialMatrix)) { for (auto [b0, mat] : enumerate(materialVector)) { - idx->SetBinContent(b0 + b1 * bins0 + 1, payload.index++); + idx->SetBinContent(b0 + 1, b1 + 1, payload.index++); fillMaterialSlab(payload, mat); m_gTree->Fill(); } @@ -245,10 +245,10 @@ void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( idx->Write(); } -Acts::DetectorMaterial Acts::RootMaterialMapAccessor::read(TFile& rFile) { - Acts::DetectorMaterial detectorMaterial; +Acts::DetectorMaterialMaps Acts::RootMaterialMapAccessor::read(TFile& rFile) { + Acts::DetectorMaterialMaps DetectorMaterialMaps; - auto& [surfaceMaterials, volumeMaterials] = detectorMaterial; + auto& [surfaceMaterials, volumeMaterials] = DetectorMaterialMaps; TTree* homogeneousMaterialTree = dynamic_cast(rFile.Get(m_cfg.homogeneousMaterialTree.c_str())); @@ -259,7 +259,7 @@ Acts::DetectorMaterial Acts::RootMaterialMapAccessor::read(TFile& rFile) { for (int i = 0; i < homogeneousMaterialTree->GetEntries(); ++i) { homogeneousMaterialTree->GetEntry(i); Acts::GeometryIdentifier geoID(m_homogenousMaterialTreePayload.hGeoId); - Acts::MaterialSlab materialSlab(Acts::Material::fromMolarDensity( + Acts::MaterialSlab materialSlab(Acts::Material::fromMassDensity( m_homogenousMaterialTreePayload.hX0, m_homogenousMaterialTreePayload.hL0, m_homogenousMaterialTreePayload.hA, @@ -272,9 +272,12 @@ Acts::DetectorMaterial Acts::RootMaterialMapAccessor::read(TFile& rFile) { } } - // Read the binned surface material + // Read the binned surface material, if there - connect it to the payload TTree* indexedMaterialTree = dynamic_cast(rFile.Get(m_cfg.indexMaterialTreeName.c_str())); + if (indexedMaterialTree != nullptr) { + connectForRead(*indexedMaterialTree, m_indexedMaterialTreePayload); + } // Get the list of keys from the file TList* tlist = rFile.GetListOfKeys(); @@ -332,7 +335,7 @@ Acts::DetectorMaterial Acts::RootMaterialMapAccessor::read(TFile& rFile) { surfaceMaterials.emplace(geoID, texturedSurfaceMaterial); } } - return detectorMaterial; + return DetectorMaterialMaps; } std::shared_ptr From 2242550eb354886352299e88b53bee3028a90e78 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Tue, 8 Jul 2025 16:03:41 +0200 Subject: [PATCH 06/30] surface material i/o moved --- .../include/Acts/Material/DetectorMaterialMaps.hpp | 13 ++++++------- .../MaterialMapping/MaterialMapping.hpp | 2 +- .../ActsExamples/Io/Json/JsonMaterialWriter.hpp | 2 +- .../ActsExamples/Io/Root/RootMaterialDecorator.hpp | 4 ++-- Examples/Io/Root/src/RootMaterialDecorator.cpp | 4 ++++ Examples/Python/src/RootInput.cpp | 4 +--- Examples/Python/src/RootOutput.cpp | 5 ++--- .../Acts/Plugins/Json/MaterialMapJsonConverter.hpp | 2 +- Plugins/Json/src/MaterialMapJsonConverter.cpp | 6 ++---- .../Acts/Plugins/Root/RootMaterialMapAccessor.hpp | 14 ++++++++------ Plugins/Root/src/RootMaterialMapAccessor.cpp | 8 ++++---- 11 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Core/include/Acts/Material/DetectorMaterialMaps.hpp b/Core/include/Acts/Material/DetectorMaterialMaps.hpp index 62f21e8eb67..40357ae27a4 100644 --- a/Core/include/Acts/Material/DetectorMaterialMaps.hpp +++ b/Core/include/Acts/Material/DetectorMaterialMaps.hpp @@ -18,11 +18,10 @@ namespace Acts { - using SurfaceMaterialMaps = - std::map>; - using VolumeMaterialMaps = - std::map>; - using DetectorMaterialMaps = - std::pair; +using SurfaceMaterialMaps = + std::map>; +using VolumeMaterialMaps = + std::map>; +using DetectorMaterialMaps = std::pair; -} // namespace Acts \ No newline at end of file +} // namespace Acts diff --git a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MaterialMapping.hpp b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MaterialMapping.hpp index 47c5a54aef1..464dea08499 100644 --- a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MaterialMapping.hpp +++ b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MaterialMapping.hpp @@ -11,9 +11,9 @@ #include "Acts/Geometry/GeometryContext.hpp" #include "Acts/Geometry/GeometryIdentifier.hpp" #include "Acts/MagneticField/MagneticFieldContext.hpp" +#include "Acts/Material/DetectorMaterialMaps.hpp" #include "Acts/Material/MaterialInteraction.hpp" #include "Acts/Material/SurfaceMaterialMapper.hpp" -#include "Acts/Material/DetectorMaterialMaps.hpp" #include "Acts/Material/VolumeMaterialMapper.hpp" #include "Acts/Utilities/Logger.hpp" #include "ActsExamples/Framework/DataHandle.hpp" diff --git a/Examples/Io/Json/include/ActsExamples/Io/Json/JsonMaterialWriter.hpp b/Examples/Io/Json/include/ActsExamples/Io/Json/JsonMaterialWriter.hpp index 01c203048ef..e5141eee094 100644 --- a/Examples/Io/Json/include/ActsExamples/Io/Json/JsonMaterialWriter.hpp +++ b/Examples/Io/Json/include/ActsExamples/Io/Json/JsonMaterialWriter.hpp @@ -10,9 +10,9 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/Geometry/GeometryIdentifier.hpp" +#include "Acts/Material/DetectorMaterialMaps.hpp" #include "Acts/Material/ISurfaceMaterial.hpp" #include "Acts/Material/IVolumeMaterial.hpp" -#include "Acts/Material/DetectorMaterialMaps.hpp" #include "Acts/Plugins/Json/MaterialMapJsonConverter.hpp" #include "Acts/Utilities/EnumBitwiseOperators.hpp" #include "Acts/Utilities/Logger.hpp" diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp index 94f0efc6a30..995049bf30f 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp @@ -12,13 +12,13 @@ #include #include #include +#include #include #include -#include #include +#include #include #include -#include #include #include diff --git a/Examples/Io/Root/src/RootMaterialDecorator.cpp b/Examples/Io/Root/src/RootMaterialDecorator.cpp index c283d334cae..dec14343223 100644 --- a/Examples/Io/Root/src/RootMaterialDecorator.cpp +++ b/Examples/Io/Root/src/RootMaterialDecorator.cpp @@ -84,6 +84,10 @@ ActsExamples::RootMaterialDecorator::RootMaterialDecorator( // Remember the directory std::string tdName(key->GetName()); + std::vector splitNames; + iter_split(splitNames, tdName, + boost::algorithm::first_finder(m_cfg.accessorConfig.voltag)); + ACTS_VERBOSE("Processing directory: " << tdName); if (splitNames[0] == m_cfg.accessorConfig.folderVolumeNameBase) { // The volume material to be read in for this diff --git a/Examples/Python/src/RootInput.cpp b/Examples/Python/src/RootInput.cpp index b82c2d2f7a7..9c541670d67 100644 --- a/Examples/Python/src/RootInput.cpp +++ b/Examples/Python/src/RootInput.cpp @@ -82,9 +82,7 @@ void addRootInput(Context& ctx) { using Config = RootMaterialDecorator::Config; auto c = py::class_(rmd, "Config").def(py::init<>()); - ACTS_PYTHON_STRUCT(c, voltag, boutag, laytag, apptag, sentag, ntag, vtag, - otag, mintag, maxtag, ttag, x0tag, l0tag, atag, ztag, - rhotag, fileName); + ACTS_PYTHON_STRUCT(c, accessorConfig, fileName); } } diff --git a/Examples/Python/src/RootOutput.cpp b/Examples/Python/src/RootOutput.cpp index 1c3220424eb..fc878511088 100644 --- a/Examples/Python/src/RootOutput.cpp +++ b/Examples/Python/src/RootOutput.cpp @@ -158,14 +158,13 @@ void addRootOutput(Context& ctx) { &Writer::write)); auto ac = py::class_(w, "AccessorConfig") - .def(py::init<>()); + .def(py::init<>()); auto c = py::class_(w, "Config").def(py::init<>()); ACTS_PYTHON_STRUCT(c, processSensitives, processApproaches, processRepresenting, processBoundaries, accessorConfig, - filePath, - fileMode); + filePath, fileMode); } ACTS_PYTHON_DECLARE_WRITER(ActsExamples::RootSeedWriter, mex, diff --git a/Plugins/Json/include/Acts/Plugins/Json/MaterialMapJsonConverter.hpp b/Plugins/Json/include/Acts/Plugins/Json/MaterialMapJsonConverter.hpp index 00ce49cb9a4..357efbfdd62 100644 --- a/Plugins/Json/include/Acts/Plugins/Json/MaterialMapJsonConverter.hpp +++ b/Plugins/Json/include/Acts/Plugins/Json/MaterialMapJsonConverter.hpp @@ -11,9 +11,9 @@ #include "Acts/Geometry/GeometryContext.hpp" #include "Acts/Geometry/GeometryIdentifier.hpp" #include "Acts/Geometry/TrackingGeometry.hpp" +#include "Acts/Material/DetectorMaterialMaps.hpp" #include "Acts/Material/ISurfaceMaterial.hpp" #include "Acts/Material/IVolumeMaterial.hpp" -#include "Acts/Material/DetectorMaterialMaps.hpp" #include "Acts/Plugins/Json/ActsJson.hpp" #include "Acts/Plugins/Json/GeometryHierarchyMapJsonConverter.hpp" #include "Acts/Plugins/Json/ITrackingGeometryJsonDecorator.hpp" diff --git a/Plugins/Json/src/MaterialMapJsonConverter.cpp b/Plugins/Json/src/MaterialMapJsonConverter.cpp index 72f5079fb9b..0ce4ad148a8 100644 --- a/Plugins/Json/src/MaterialMapJsonConverter.cpp +++ b/Plugins/Json/src/MaterialMapJsonConverter.cpp @@ -277,8 +277,7 @@ nlohmann::json Acts::MaterialMapJsonConverter::materialMapsToJson( return materialMap; } -Acts::DetectorMaterialMaps -Acts::MaterialMapJsonConverter::jsonToMaterialMaps( +Acts::DetectorMaterialMaps Acts::MaterialMapJsonConverter::jsonToMaterialMaps( const nlohmann::json& materialmap) { nlohmann::json materialVolume = materialmap["Volumes"]; GeometryHierarchyMap hierarchyVolumeMap = @@ -299,8 +298,7 @@ Acts::MaterialMapJsonConverter::jsonToMaterialMaps( surfaceMap.insert({hierarchySurfaceMap.idAt(i), std::move(surfacePointer)}); } - Acts::DetectorMaterialMaps maps = {surfaceMap, - volumeMap}; + Acts::DetectorMaterialMaps maps = {surfaceMap, volumeMap}; // Return the filled maps return maps; diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp index 2ec1524a87a..ee10d8bbb6d 100644 --- a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp +++ b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp @@ -8,8 +8,8 @@ #pragma once -#include "Acts/Utilities/Logger.hpp" #include "Acts/Material/DetectorMaterialMaps.hpp" +#include "Acts/Utilities/Logger.hpp" #include #include @@ -82,7 +82,7 @@ class RootMaterialMapAccessor { struct MaterialTreePayload { std::size_t index = 0; /// geometry identifier - int64_t hGeoId; + std::int64_t hGeoId; /// thickness float ht; /// X0 @@ -101,8 +101,9 @@ class RootMaterialMapAccessor { /// @param cfg the configuration for the accessor /// @param mLogger the logger to use, default is INFO level explicit RootMaterialMapAccessor( - const Config& cfg, std::unique_ptr mLogger = getDefaultLogger( - "RootMaterialMapAccessor", Logging::INFO)) + const Config& cfg, + std::unique_ptr mLogger = + getDefaultLogger("RootMaterialMapAccessor", Logging::INFO)) : m_cfg(cfg), m_logger(std::move(mLogger)) {} /// @brief Destructor @@ -157,7 +158,8 @@ class RootMaterialMapAccessor { /// @param indexedMaterialTree the indexed material tree, if available /// @return a shared pointer to the ISurfaceMaterial std::shared_ptr readTextureSurfaceMaterial( - TFile& rFile, const std::string& tdName, TTree* indexedMaterialTree = nullptr); + TFile& rFile, const std::string& tdName, + TTree* indexedMaterialTree = nullptr); /// Read the a grid Surface material const Logger& logger() const { return *m_logger; } @@ -177,4 +179,4 @@ class RootMaterialMapAccessor { MaterialTreePayload m_indexedMaterialTreePayload; }; -} // namespace Acts \ No newline at end of file +} // namespace Acts diff --git a/Plugins/Root/src/RootMaterialMapAccessor.cpp b/Plugins/Root/src/RootMaterialMapAccessor.cpp index 5941e0d37ca..287d4e8b3b5 100644 --- a/Plugins/Root/src/RootMaterialMapAccessor.cpp +++ b/Plugins/Root/src/RootMaterialMapAccessor.cpp @@ -259,13 +259,13 @@ Acts::DetectorMaterialMaps Acts::RootMaterialMapAccessor::read(TFile& rFile) { for (int i = 0; i < homogeneousMaterialTree->GetEntries(); ++i) { homogeneousMaterialTree->GetEntry(i); Acts::GeometryIdentifier geoID(m_homogenousMaterialTreePayload.hGeoId); - Acts::MaterialSlab materialSlab(Acts::Material::fromMassDensity( - m_homogenousMaterialTreePayload.hX0, + Acts::MaterialSlab materialSlab( + Acts::Material::fromMassDensity(m_homogenousMaterialTreePayload.hX0, m_homogenousMaterialTreePayload.hL0, m_homogenousMaterialTreePayload.hA, m_homogenousMaterialTreePayload.hZ, m_homogenousMaterialTreePayload.hRho), - m_homogenousMaterialTreePayload.ht); + m_homogenousMaterialTreePayload.ht); auto homogeneousMaterial = std::make_shared(materialSlab); surfaceMaterials.emplace(geoID, homogeneousMaterial); @@ -455,4 +455,4 @@ Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( } return texturedSurfaceMaterial; -} \ No newline at end of file +} From 4d4233e2f37a01a43544f18ef88bbd9d8b0eec51 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Tue, 8 Jul 2025 17:03:21 +0200 Subject: [PATCH 07/30] checking against potential nullptr --- Plugins/Root/src/RootMaterialMapAccessor.cpp | 57 ++++++++++---------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/Plugins/Root/src/RootMaterialMapAccessor.cpp b/Plugins/Root/src/RootMaterialMapAccessor.cpp index 287d4e8b3b5..fb1d73bb904 100644 --- a/Plugins/Root/src/RootMaterialMapAccessor.cpp +++ b/Plugins/Root/src/RootMaterialMapAccessor.cpp @@ -425,33 +425,36 @@ Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( std::string indexName = tdName + "/" + m_cfg.itag; // Get the histograms TH2I* ih = dynamic_cast(rFile.Get(indexName.c_str())); - // Get the number of bins - int nbins0 = ih->GetNbinsX(); - int nbins1 = ih->GetNbinsY(); - - // The material matrix - MaterialSlabMatrix materialMatrix( - nbins1, MaterialSlabVector(nbins0, MaterialSlab::Nothing())); - - // Fill the matrix first - for (int ib0 = 1; ib0 <= nbins0; ++ib0) { - for (int ib1 = 1; ib1 <= nbins1; ++ib1) { - int idx = static_cast(ih->GetBinContent(ib0, ib1)); - indexedMaterialTree->GetEntry(idx); - double dt = m_indexedMaterialTreePayload.ht; - double dx0 = m_indexedMaterialTreePayload.hX0; - double dl0 = m_indexedMaterialTreePayload.hL0; - double da = m_indexedMaterialTreePayload.hA; - double dz = m_indexedMaterialTreePayload.hZ; - double drho = m_indexedMaterialTreePayload.hRho; - // Create material properties - const auto material = - Acts::Material::fromMassDensity(dx0, dl0, da, dz, drho); - materialMatrix[ib1 - 1][ib0 - 1] = Acts::MaterialSlab(material, dt); - } - } // Construct the binned material with the right bin utility - texturedSurfaceMaterial = std::make_shared( - bUtility, std::move(materialMatrix)); + + if (ih != nullptr) { + // Get the number of bins + int nbins0 = ih->GetNbinsX(); + int nbins1 = ih->GetNbinsY(); + + // The material matrix + MaterialSlabMatrix materialMatrix( + nbins1, MaterialSlabVector(nbins0, MaterialSlab::Nothing())); + + // Fill the matrix first + for (int ib0 = 1; ib0 <= nbins0; ++ib0) { + for (int ib1 = 1; ib1 <= nbins1; ++ib1) { + int idx = static_cast(ih->GetBinContent(ib0, ib1)); + indexedMaterialTree->GetEntry(idx); + double dt = m_indexedMaterialTreePayload.ht; + double dx0 = m_indexedMaterialTreePayload.hX0; + double dl0 = m_indexedMaterialTreePayload.hL0; + double da = m_indexedMaterialTreePayload.hA; + double dz = m_indexedMaterialTreePayload.hZ; + double drho = m_indexedMaterialTreePayload.hRho; + // Create material properties + const auto material = + Acts::Material::fromMassDensity(dx0, dl0, da, dz, drho); + materialMatrix[ib1 - 1][ib0 - 1] = Acts::MaterialSlab(material, dt); + } + } // Construct the binned material with the right bin utility + texturedSurfaceMaterial = std::make_shared( + bUtility, std::move(materialMatrix)); + } } return texturedSurfaceMaterial; From 3e2583ff1d60e17d4b73aeefb1da77b18dcbcfa9 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Tue, 8 Jul 2025 23:01:14 +0200 Subject: [PATCH 08/30] remove new operator usage --- Plugins/Root/src/RootMaterialMapAccessor.cpp | 56 ++++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/Plugins/Root/src/RootMaterialMapAccessor.cpp b/Plugins/Root/src/RootMaterialMapAccessor.cpp index fb1d73bb904..ce72982a280 100644 --- a/Plugins/Root/src/RootMaterialMapAccessor.cpp +++ b/Plugins/Root/src/RootMaterialMapAccessor.cpp @@ -193,37 +193,37 @@ void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( std::size_t bins0 = bsMaterial.binUtility().bins(0); std::size_t bins1 = bsMaterial.binUtility().bins(1); - auto t = new TH2F(m_cfg.ttag.c_str(), "thickness [mm] ;b0 ;b1", bins0, -0.5, - bins0 - 0.5, bins1, -0.5, bins1 - 0.5); - auto x0 = new TH2F(m_cfg.x0tag.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, - bins0 - 0.5, bins1, -0.5, bins1 - 0.5); - auto l0 = new TH2F(m_cfg.l0tag.c_str(), "#Lambda_{0} [mm] ;b0 ;b1", bins0, - -0.5, bins0 - 0.5, bins1, -0.5, bins1 - 0.5); - auto A = new TH2F(m_cfg.atag.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, - bins0 - 0.5, bins1, -0.5, bins1 - 0.5); - auto Z = new TH2F(m_cfg.ztag.c_str(), "#Lambda_{0} [mm] ;b0 ;b1", bins0, -0.5, - bins0 - 0.5, bins1, -0.5, bins1 - 0.5); - auto rho = new TH2F(m_cfg.rhotag.c_str(), "#rho [g/mm^3] ;b0 ;b1", bins0, - -0.5, bins0 - 0.5, bins1, -0.5, bins1 - 0.5); + TH2F t(m_cfg.ttag.c_str(), "thickness [mm] ;b0 ;b1", bins0, -0.5, bins0 - 0.5, + bins1, -0.5, bins1 - 0.5); + TH2F x0(m_cfg.x0tag.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, bins0 - 0.5, + bins1, -0.5, bins1 - 0.5); + TH2F l0(m_cfg.l0tag.c_str(), "#Lambda_{0} [mm] ;b0 ;b1", bins0, -0.5, + bins0 - 0.5, bins1, -0.5, bins1 - 0.5); + TH2F A(m_cfg.atag.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, bins0 - 0.5, + bins1, -0.5, bins1 - 0.5); + TH2F Z(m_cfg.ztag.c_str(), "#Lambda_{0} [mm] ;b0 ;b1", bins0, -0.5, + bins0 - 0.5, bins1, -0.5, bins1 - 0.5); + TH2F rho(m_cfg.rhotag.c_str(), "#rho [g/mm^3] ;b0 ;b1", bins0, -0.5, + bins0 - 0.5, bins1, -0.5, bins1 - 0.5); // loop over the material and fill const auto& materialMatrix = bsMaterial.fullMaterial(); for (auto [b1, materialVector] : enumerate(materialMatrix)) { for (auto [b0, mat] : enumerate(materialVector)) { - t->SetBinContent(b0 + 1, b1 + 1, mat.thickness()); - x0->SetBinContent(b0 + 1, b1 + 1, mat.material().X0()); - l0->SetBinContent(b0 + 1, b1 + 1, mat.material().L0()); - A->SetBinContent(b0 + 1, b1 + 1, mat.material().Ar()); - Z->SetBinContent(b0 + 1, b1 + 1, mat.material().Z()); - rho->SetBinContent(b0 + 1, b1 + 1, mat.material().massDensity()); + t.SetBinContent(b0 + 1, b1 + 1, mat.thickness()); + x0.SetBinContent(b0 + 1, b1 + 1, mat.material().X0()); + l0.SetBinContent(b0 + 1, b1 + 1, mat.material().L0()); + A.SetBinContent(b0 + 1, b1 + 1, mat.material().Ar()); + Z.SetBinContent(b0 + 1, b1 + 1, mat.material().Z()); + rho.SetBinContent(b0 + 1, b1 + 1, mat.material().massDensity()); } } - t->Write(); - x0->Write(); - l0->Write(); - A->Write(); - Z->Write(); - rho->Write(); + t.Write(); + x0.Write(); + l0.Write(); + A.Write(); + Z.Write(); + rho.Write(); } void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( @@ -231,18 +231,18 @@ void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( std::size_t bins0 = bsMaterial.binUtility().bins(0); std::size_t bins1 = bsMaterial.binUtility().bins(1); - auto idx = new TH2I(m_cfg.itag.c_str(), "indices; bin0; bin1", bins0, -0.5, - bins0 - 0.5, bins1, -0.5, bins1 - 0.5); + TH2I idx(m_cfg.itag.c_str(), "indices; bin0; bin1", bins0, -0.5, bins0 - 0.5, + bins1, -0.5, bins1 - 0.5); // loop over the material and fill const auto& materialMatrix = bsMaterial.fullMaterial(); for (auto [b1, materialVector] : enumerate(materialMatrix)) { for (auto [b0, mat] : enumerate(materialVector)) { - idx->SetBinContent(b0 + 1, b1 + 1, payload.index++); + idx.SetBinContent(b0 + 1, b1 + 1, payload.index++); fillMaterialSlab(payload, mat); m_gTree->Fill(); } } - idx->Write(); + idx.Write(); } Acts::DetectorMaterialMaps Acts::RootMaterialMapAccessor::read(TFile& rFile) { From ad2c8ddbd5ea58379b74677702ee9551140fda11 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Wed, 9 Jul 2025 06:21:03 +0200 Subject: [PATCH 09/30] remove SonarCloud issues --- Examples/Io/Root/src/RootMaterialWriter.cpp | 115 +++++++++---------- Plugins/Root/src/RootMaterialMapAccessor.cpp | 78 ++++++------- 2 files changed, 89 insertions(+), 104 deletions(-) diff --git a/Examples/Io/Root/src/RootMaterialWriter.cpp b/Examples/Io/Root/src/RootMaterialWriter.cpp index f55d1a99ca9..d5814430a79 100644 --- a/Examples/Io/Root/src/RootMaterialWriter.cpp +++ b/Examples/Io/Root/src/RootMaterialWriter.cpp @@ -108,84 +108,81 @@ void ActsExamples::RootMaterialWriter::writeMaterial( auto bvMaterial2D = dynamic_cast>*>(vMaterial); - std::size_t points = 1; + int points = 1; if (bvMaterial3D != nullptr || bvMaterial2D != nullptr) { // Get the binning data std::vector binningData; if (bvMaterial3D != nullptr) { binningData = bvMaterial3D->binUtility().binningData(); Acts::MaterialGrid3D grid = bvMaterial3D->getMapper().getGrid(); - points = grid.size(); + points = static_cast(grid.size()); } else { binningData = bvMaterial2D->binUtility().binningData(); Acts::MaterialGrid2D grid = bvMaterial2D->getMapper().getGrid(); - points = grid.size(); + points = static_cast(grid.size()); } // 2-D or 3-D maps - std::size_t binningBins = binningData.size(); + int bins = static_cast(binningData.size()); + float fBins = static_cast(bins); // The bin number information - TH1F* n = new TH1F(m_cfg.accessorConfig.ntag.c_str(), "bins; bin", - binningBins, -0.5, binningBins - 0.5); + TH1F n(m_cfg.accessorConfig.ntag.c_str(), "bins; bin", bins, -0.5, + fBins - 0.5); // The binning value information - TH1F* v = - new TH1F(m_cfg.accessorConfig.vtag.c_str(), "binning values; bin", - binningBins, -0.5, binningBins - 0.5); + TH1F v(m_cfg.accessorConfig.vtag.c_str(), "binning values; bin", bins, + -0.5, fBins - 0.5); // The binning option information - TH1F* o = - new TH1F(m_cfg.accessorConfig.otag.c_str(), "binning options; bin", - binningBins, -0.5, binningBins - 0.5); + TH1F o(m_cfg.accessorConfig.otag.c_str(), "binning options; bin", bins, + -0.5, fBins - 0.5); // The binning option information - TH1F* min = new TH1F(m_cfg.accessorConfig.mintag.c_str(), "min; bin", - binningBins, -0.5, binningBins - 0.5); + TH1F rmin(m_cfg.accessorConfig.mintag.c_str(), "min; bin", bins, -0.5, + fBins - 0.5); // The binning option information - TH1F* max = new TH1F(m_cfg.accessorConfig.maxtag.c_str(), "max; bin", - binningBins, -0.5, binningBins - 0.5); + TH1F rmax(m_cfg.accessorConfig.maxtag.c_str(), "max; bin", bins, -0.5, + fBins - 0.5); // Now fill the histogram content std::size_t b = 1; for (auto bData : binningData) { // Fill: nbins, value, option, min, max - n->SetBinContent(b, static_cast(binningData[b - 1].bins())); - v->SetBinContent(b, static_cast(binningData[b - 1].binvalue)); - o->SetBinContent(b, static_cast(binningData[b - 1].option)); - min->SetBinContent(b, binningData[b - 1].min); - max->SetBinContent(b, binningData[b - 1].max); + n.SetBinContent(b, static_cast(binningData[b - 1].bins())); + v.SetBinContent(b, static_cast(binningData[b - 1].binvalue)); + o.SetBinContent(b, static_cast(binningData[b - 1].option)); + rmin.SetBinContent(b, binningData[b - 1].min); + rmax.SetBinContent(b, binningData[b - 1].max); ++b; } - n->Write(); - v->Write(); - o->Write(); - min->Write(); - max->Write(); + n.Write(); + v.Write(); + o.Write(); + rmin.Write(); + rmax.Write(); } - TH1F* x0 = new TH1F(m_cfg.accessorConfig.x0tag.c_str(), - "X_{0} [mm] ;gridPoint", points, -0.5, points - 0.5); - TH1F* l0 = - new TH1F(m_cfg.accessorConfig.l0tag.c_str(), - "#Lambda_{0} [mm] ;gridPoint", points, -0.5, points - 0.5); - TH1F* A = new TH1F(m_cfg.accessorConfig.atag.c_str(), - "X_{0} [mm] ;gridPoint", points, -0.5, points - 0.5); - TH1F* Z = - new TH1F(m_cfg.accessorConfig.ztag.c_str(), - "#Lambda_{0} [mm] ;gridPoint", points, -0.5, points - 0.5); - TH1F* rho = - new TH1F(m_cfg.accessorConfig.rhotag.c_str(), - "#rho [g/mm^3] ;gridPoint", points, -0.5, points - 0.5); + float fPoints = static_cast(points); + TH1F x0(m_cfg.accessorConfig.x0tag.c_str(), "X_{0} [mm] ;gridPoint", points, + -0.5, fPoints - 0.5); + TH1F l0(m_cfg.accessorConfig.l0tag.c_str(), "#Lambda_{0} [mm] ;gridPoint", + points, -0.5, fPoints - 0.5); + TH1F A(m_cfg.accessorConfig.atag.c_str(), "X_{0} [mm] ;gridPoint", points, + -0.5, fPoints - 0.5); + TH1F Z(m_cfg.accessorConfig.ztag.c_str(), "#Lambda_{0} [mm] ;gridPoint", + points, -0.5, fPoints - 0.5); + TH1F rho(m_cfg.accessorConfig.rhotag.c_str(), "#rho [g/mm^3] ;gridPoint", + points, -0.5, fPoints - 0.5); // homogeneous volume if (points == 1) { auto mat = vMaterial->material({0, 0, 0}); - x0->SetBinContent(1, mat.X0()); - l0->SetBinContent(1, mat.L0()); - A->SetBinContent(1, mat.Ar()); - Z->SetBinContent(1, mat.Z()); - rho->SetBinContent(1, mat.massDensity()); + x0.SetBinContent(1, mat.X0()); + l0.SetBinContent(1, mat.L0()); + A.SetBinContent(1, mat.Ar()); + Z.SetBinContent(1, mat.Z()); + rho.SetBinContent(1, mat.massDensity()); } else { // 3d grid volume if (bvMaterial3D != nullptr) { @@ -193,11 +190,11 @@ void ActsExamples::RootMaterialWriter::writeMaterial( for (std::size_t point = 0; point < points; point++) { auto mat = Acts::Material(grid.at(point)); if (!mat.isVacuum()) { - x0->SetBinContent(point + 1, mat.X0()); - l0->SetBinContent(point + 1, mat.L0()); - A->SetBinContent(point + 1, mat.Ar()); - Z->SetBinContent(point + 1, mat.Z()); - rho->SetBinContent(point + 1, mat.massDensity()); + x0.SetBinContent(point + 1, mat.X0()); + l0.SetBinContent(point + 1, mat.L0()); + A.SetBinContent(point + 1, mat.Ar()); + Z.SetBinContent(point + 1, mat.Z()); + rho.SetBinContent(point + 1, mat.massDensity()); } } } @@ -207,20 +204,20 @@ void ActsExamples::RootMaterialWriter::writeMaterial( for (std::size_t point = 0; point < points; point++) { auto mat = Acts::Material(grid.at(point)); if (!mat.isVacuum()) { - x0->SetBinContent(point + 1, mat.X0()); - l0->SetBinContent(point + 1, mat.L0()); - A->SetBinContent(point + 1, mat.Ar()); - Z->SetBinContent(point + 1, mat.Z()); - rho->SetBinContent(point + 1, mat.massDensity()); + x0.SetBinContent(point + 1, mat.X0()); + l0.SetBinContent(point + 1, mat.L0()); + A.SetBinContent(point + 1, mat.Ar()); + Z.SetBinContent(point + 1, mat.Z()); + rho.SetBinContent(point + 1, mat.massDensity()); } } } } - x0->Write(); - l0->Write(); - A->Write(); - Z->Write(); - rho->Write(); + x0.Write(); + l0.Write(); + A.Write(); + Z.Write(); + rho.Write(); } } diff --git a/Plugins/Root/src/RootMaterialMapAccessor.cpp b/Plugins/Root/src/RootMaterialMapAccessor.cpp index ce72982a280..45b4f2f7d97 100644 --- a/Plugins/Root/src/RootMaterialMapAccessor.cpp +++ b/Plugins/Root/src/RootMaterialMapAccessor.cpp @@ -75,44 +75,38 @@ void Acts::RootMaterialMapAccessor::write( // Get the binning data auto& binningData = bsMaterial->binUtility().binningData(); // 1-D or 2-D maps - std::size_t binningBins = binningData.size(); + int bins = static_cast(binningData.size()); + float fBins = static_cast(bins); // The bin number information - auto n = new TH1F(m_cfg.ntag.c_str(), "bins; bin", binningBins, -0.5, - binningBins - 0.5); + TH1F n(m_cfg.ntag.c_str(), "bins; bin", bins, -0.5, fBins - 0.5); // The binning value information - auto v = new TH1F(m_cfg.vtag.c_str(), "binning values; bin", binningBins, - -0.5, binningBins - 0.5); + TH1F v(m_cfg.vtag.c_str(), "binning values; bin", bins, -0.5, fBins - 0.5); // The binning option information - auto o = new TH1F(m_cfg.otag.c_str(), "binning options; bin", binningBins, - -0.5, binningBins - 0.5); + TH1F o(m_cfg.otag.c_str(), "binning options; bin", bins, -0.5, fBins - 0.5); // The binning option information - range min - auto rmin = new TH1F(m_cfg.mintag.c_str(), "min; bin", binningBins, -0.5, - binningBins - 0.5); + TH1F rmin(m_cfg.mintag.c_str(), "min; bin", bins, -0.5, fBins - 0.5); // The binning option information - range max - auto rmax = new TH1F(m_cfg.maxtag.c_str(), "max; bin", binningBins, -0.5, - binningBins - 0.5); + TH1F rmax(m_cfg.maxtag.c_str(), "max; bin", bins, -0.5, fBins - 0.5); // Now fill the histogram content - std::size_t b = 1; - for (auto bData : binningData) { + for (auto [b, bData] : enumerate(binningData)) { // Fill: nbins, value, option, min, max - n->SetBinContent(b, static_cast(binningData[b - 1].bins())); - v->SetBinContent(b, static_cast(binningData[b - 1].binvalue)); - o->SetBinContent(b, static_cast(binningData[b - 1].option)); - rmin->SetBinContent(b, binningData[b - 1].min); - rmax->SetBinContent(b, binningData[b - 1].max); - ++b; + n.SetBinContent(b, static_cast(binningData[b - 1].bins())); + v.SetBinContent(b, static_cast(binningData[b - 1].binvalue)); + o.SetBinContent(b, static_cast(binningData[b - 1].option)); + rmin.SetBinContent(b, binningData[b - 1].min); + rmax.SetBinContent(b, binningData[b - 1].max); } - n->Write(); - v->Write(); - o->Write(); - rmin->Write(); - rmax->Write(); + n.Write(); + v.Write(); + o.Write(); + rmin.Write(); + rmax.Write(); // If compressed writing is not enabled, write the binned surface material // as histograms @@ -134,19 +128,11 @@ void Acts::RootMaterialMapAccessor::write( fillBinnedSurfaceMaterial(m_indexedMaterialTreePayload, *bsMaterial); return; } - - // auto gridMaterial = dynamic_cast(surfaceMaterial); if (gridMaterial != nullptr) { - // writeGridMaterial(rFile, gctx, geoID, *gridMaterial); - // return; - //} - - return; } void Acts::RootMaterialMapAccessor::write( TFile& rFile, const DetectorMaterialMaps& DetectorMaterialMaps) { - auto [surfaceMaterials, volumeMaterials] = DetectorMaterialMaps; + const auto& [surfaceMaterials, volumeMaterials] = DetectorMaterialMaps; for (const auto& [geoID, sMaterial] : surfaceMaterials) { write(rFile, geoID, *sMaterial); } @@ -190,21 +176,23 @@ void Acts::RootMaterialMapAccessor::fillMaterialSlab( void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( const BinnedSurfaceMaterial& bsMaterial) { - std::size_t bins0 = bsMaterial.binUtility().bins(0); - std::size_t bins1 = bsMaterial.binUtility().bins(1); - - TH2F t(m_cfg.ttag.c_str(), "thickness [mm] ;b0 ;b1", bins0, -0.5, bins0 - 0.5, - bins1, -0.5, bins1 - 0.5); - TH2F x0(m_cfg.x0tag.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, bins0 - 0.5, - bins1, -0.5, bins1 - 0.5); + int bins0 = static_cast(bsMaterial.binUtility().bins(0)); + int bins1 = static_cast(bsMaterial.binUtility().bins(1)); + float fBins0 = static_cast(bins0); + float fBins1 = static_cast(bins1); + + TH2F t(m_cfg.ttag.c_str(), "thickness [mm] ;b0 ;b1", bins0, -0.5, + fBins0 - 0.5, bins1, -0.5, fBins1 - 0.5); + TH2F x0(m_cfg.x0tag.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, fBins0 - 0.5, + bins1, -0.5, fBins1 - 0.5); TH2F l0(m_cfg.l0tag.c_str(), "#Lambda_{0} [mm] ;b0 ;b1", bins0, -0.5, - bins0 - 0.5, bins1, -0.5, bins1 - 0.5); - TH2F A(m_cfg.atag.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, bins0 - 0.5, - bins1, -0.5, bins1 - 0.5); + fBins0 - 0.5, bins1, -0.5, fBins1 - 0.5); + TH2F A(m_cfg.atag.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, fBins0 - 0.5, + bins1, -0.5, fBins1 - 0.5); TH2F Z(m_cfg.ztag.c_str(), "#Lambda_{0} [mm] ;b0 ;b1", bins0, -0.5, - bins0 - 0.5, bins1, -0.5, bins1 - 0.5); + fBins0 - 0.5, bins1, -0.5, fBins1 - 0.5); TH2F rho(m_cfg.rhotag.c_str(), "#rho [g/mm^3] ;b0 ;b1", bins0, -0.5, - bins0 - 0.5, bins1, -0.5, bins1 - 0.5); + fBins0 - 0.5, bins1, -0.5, fBins1 - 0.5); // loop over the material and fill const auto& materialMatrix = bsMaterial.fullMaterial(); From a31211e7efe078cb8184d163257fadff586b2b80 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Wed, 9 Jul 2025 06:27:49 +0200 Subject: [PATCH 10/30] int vs size --- Examples/Io/Root/src/RootMaterialWriter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/Io/Root/src/RootMaterialWriter.cpp b/Examples/Io/Root/src/RootMaterialWriter.cpp index d5814430a79..c1ca39486be 100644 --- a/Examples/Io/Root/src/RootMaterialWriter.cpp +++ b/Examples/Io/Root/src/RootMaterialWriter.cpp @@ -187,7 +187,7 @@ void ActsExamples::RootMaterialWriter::writeMaterial( // 3d grid volume if (bvMaterial3D != nullptr) { Acts::MaterialGrid3D grid = bvMaterial3D->getMapper().getGrid(); - for (std::size_t point = 0; point < points; point++) { + for (int point = 0; point < points; point++) { auto mat = Acts::Material(grid.at(point)); if (!mat.isVacuum()) { x0.SetBinContent(point + 1, mat.X0()); @@ -201,7 +201,7 @@ void ActsExamples::RootMaterialWriter::writeMaterial( // 2d grid volume else if (bvMaterial2D != nullptr) { Acts::MaterialGrid2D grid = bvMaterial2D->getMapper().getGrid(); - for (std::size_t point = 0; point < points; point++) { + for (int point = 0; point < points; point++) { auto mat = Acts::Material(grid.at(point)); if (!mat.isVacuum()) { x0.SetBinContent(point + 1, mat.X0()); From 390e10326c1b5ca4316a5d5cc8f1796642dac424 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Wed, 9 Jul 2025 06:48:42 +0200 Subject: [PATCH 11/30] fixing CI --- Examples/Io/Root/src/RootMaterialWriter.cpp | 4 +--- Plugins/Root/src/RootMaterialMapAccessor.cpp | 15 ++++++++------- .../Plugins/Root/RootMaterialMapAccessorTests.cpp | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Examples/Io/Root/src/RootMaterialWriter.cpp b/Examples/Io/Root/src/RootMaterialWriter.cpp index c1ca39486be..6748d31d616 100644 --- a/Examples/Io/Root/src/RootMaterialWriter.cpp +++ b/Examples/Io/Root/src/RootMaterialWriter.cpp @@ -147,15 +147,13 @@ void ActsExamples::RootMaterialWriter::writeMaterial( fBins - 0.5); // Now fill the histogram content - std::size_t b = 1; - for (auto bData : binningData) { + for (const auto& [b, bData] : enumerate(binningData)) { // Fill: nbins, value, option, min, max n.SetBinContent(b, static_cast(binningData[b - 1].bins())); v.SetBinContent(b, static_cast(binningData[b - 1].binvalue)); o.SetBinContent(b, static_cast(binningData[b - 1].option)); rmin.SetBinContent(b, binningData[b - 1].min); rmax.SetBinContent(b, binningData[b - 1].max); - ++b; } n.Write(); v.Write(); diff --git a/Plugins/Root/src/RootMaterialMapAccessor.cpp b/Plugins/Root/src/RootMaterialMapAccessor.cpp index 45b4f2f7d97..66632127777 100644 --- a/Plugins/Root/src/RootMaterialMapAccessor.cpp +++ b/Plugins/Root/src/RootMaterialMapAccessor.cpp @@ -96,11 +96,11 @@ void Acts::RootMaterialMapAccessor::write( // Now fill the histogram content for (auto [b, bData] : enumerate(binningData)) { // Fill: nbins, value, option, min, max - n.SetBinContent(b, static_cast(binningData[b - 1].bins())); - v.SetBinContent(b, static_cast(binningData[b - 1].binvalue)); - o.SetBinContent(b, static_cast(binningData[b - 1].option)); - rmin.SetBinContent(b, binningData[b - 1].min); - rmax.SetBinContent(b, binningData[b - 1].max); + n.SetBinContent(b + 1, static_cast(bData.bins())); + v.SetBinContent(b + 1, static_cast(bData.binvalue)); + o.SetBinContent(b + 1, static_cast(bData.option)); + rmin.SetBinContent(b + 1, bData.min); + rmax.SetBinContent(b + 1, bData.max); } n.Write(); v.Write(); @@ -219,8 +219,9 @@ void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( std::size_t bins0 = bsMaterial.binUtility().bins(0); std::size_t bins1 = bsMaterial.binUtility().bins(1); - TH2I idx(m_cfg.itag.c_str(), "indices; bin0; bin1", bins0, -0.5, bins0 - 0.5, - bins1, -0.5, bins1 - 0.5); + TH2I idx(m_cfg.itag.c_str(), "indices; bin0; bin1", bins0, -0.5, + static_cast(bins0) - 0.5, bins1, -0.5, + static_cast(bins1) - 0.5); // loop over the material and fill const auto& materialMatrix = bsMaterial.fullMaterial(); for (auto [b1, materialVector] : enumerate(materialMatrix)) { diff --git a/Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp b/Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp index 32270be3c1b..7acba84bc4a 100644 --- a/Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp +++ b/Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp @@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorHomogeneousReadWrite) { } } -BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorBinnrfReadWrite) { +BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorBinnedReadWrite) { auto surfaceMaterials = createBinnedSurfaceMaterial(); auto rFile = From f6c54e264a1298c5ce103b467f348c0bbc12e7a2 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Wed, 9 Jul 2025 08:42:03 +0200 Subject: [PATCH 12/30] make clang-tidy happy --- .../Acts/Plugins/Root/RootMaterialMapAccessor.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp index ee10d8bbb6d..2f39a0a36f4 100644 --- a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp +++ b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp @@ -82,19 +82,19 @@ class RootMaterialMapAccessor { struct MaterialTreePayload { std::size_t index = 0; /// geometry identifier - std::int64_t hGeoId; + std::int64_t hGeoId = 0; /// thickness - float ht; + float ht = 0.0f; /// X0 - float hX0; + float hX0 = 0.0f; /// L0 - float hL0; + float hL0 = 0.0f; /// A - float hA; + float hA = 0.0f; /// Z - float hZ; + float hZ = 0.0f; /// Rho - float hRho; + float hRho = 0.0f; }; /// @brief Constructor from config struct From 7b5936936d7ebb116317ae32ce94a6e8f7aed0d2 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Wed, 9 Jul 2025 08:55:35 +0200 Subject: [PATCH 13/30] more SonarCloud issues --- Plugins/Root/src/RootMaterialMapAccessor.cpp | 54 ++++++++++++-------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/Plugins/Root/src/RootMaterialMapAccessor.cpp b/Plugins/Root/src/RootMaterialMapAccessor.cpp index 66632127777..8c7c25a4fe9 100644 --- a/Plugins/Root/src/RootMaterialMapAccessor.cpp +++ b/Plugins/Root/src/RootMaterialMapAccessor.cpp @@ -75,8 +75,8 @@ void Acts::RootMaterialMapAccessor::write( // Get the binning data auto& binningData = bsMaterial->binUtility().binningData(); // 1-D or 2-D maps - int bins = static_cast(binningData.size()); - float fBins = static_cast(bins); + auto bins = static_cast(binningData.size()); + auto fBins = static_cast(bins); // The bin number information TH1F n(m_cfg.ntag.c_str(), "bins; bin", bins, -0.5, fBins - 0.5); @@ -96,11 +96,12 @@ void Acts::RootMaterialMapAccessor::write( // Now fill the histogram content for (auto [b, bData] : enumerate(binningData)) { // Fill: nbins, value, option, min, max - n.SetBinContent(b + 1, static_cast(bData.bins())); - v.SetBinContent(b + 1, static_cast(bData.binvalue)); - o.SetBinContent(b + 1, static_cast(bData.option)); - rmin.SetBinContent(b + 1, bData.min); - rmax.SetBinContent(b + 1, bData.max); + n.SetBinContent(static_cast(b) + 1, static_cast(bData.bins())); + v.SetBinContent(static_cast(b) + 1, + static_cast(bData.binvalue)); + o.SetBinContent(static_cast(b) + 1, static_cast(bData.option)); + rmin.SetBinContent(static_cast(b) + 1, bData.min); + rmax.SetBinContent(static_cast(b) + 1, bData.max); } n.Write(); v.Write(); @@ -136,6 +137,12 @@ void Acts::RootMaterialMapAccessor::write( for (const auto& [geoID, sMaterial] : surfaceMaterials) { write(rFile, geoID, *sMaterial); } + if (m_hTree != nullptr) { + m_hTree->Write(); + } + if (m_gTree != nullptr) { + m_gTree->Write(); + } } void Acts::RootMaterialMapAccessor::connectForWrite( @@ -176,10 +183,10 @@ void Acts::RootMaterialMapAccessor::fillMaterialSlab( void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( const BinnedSurfaceMaterial& bsMaterial) { - int bins0 = static_cast(bsMaterial.binUtility().bins(0)); - int bins1 = static_cast(bsMaterial.binUtility().bins(1)); - float fBins0 = static_cast(bins0); - float fBins1 = static_cast(bins1); + auto bins0 = static_cast(bsMaterial.binUtility().bins(0)); + auto bins1 = static_cast(bsMaterial.binUtility().bins(1)); + auto fBins0 = static_cast(bins0); + auto fBins1 = static_cast(bins1); TH2F t(m_cfg.ttag.c_str(), "thickness [mm] ;b0 ;b1", bins0, -0.5, fBins0 - 0.5, bins1, -0.5, fBins1 - 0.5); @@ -198,12 +205,18 @@ void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( const auto& materialMatrix = bsMaterial.fullMaterial(); for (auto [b1, materialVector] : enumerate(materialMatrix)) { for (auto [b0, mat] : enumerate(materialVector)) { - t.SetBinContent(b0 + 1, b1 + 1, mat.thickness()); - x0.SetBinContent(b0 + 1, b1 + 1, mat.material().X0()); - l0.SetBinContent(b0 + 1, b1 + 1, mat.material().L0()); - A.SetBinContent(b0 + 1, b1 + 1, mat.material().Ar()); - Z.SetBinContent(b0 + 1, b1 + 1, mat.material().Z()); - rho.SetBinContent(b0 + 1, b1 + 1, mat.material().massDensity()); + t.SetBinContent(static_cast(b0) + 1, static_cast(b1) + 1, + mat.thickness()); + x0.SetBinContent(static_cast(b0) + 1, static_cast(b1) + 1, + mat.material().X0()); + l0.SetBinContent(static_cast(b0) + 1, static_cast(b1) + 1, + mat.material().L0()); + A.SetBinContent(static_cast(b0) + 1, static_cast(b1) + 1, + mat.material().Ar()); + Z.SetBinContent(static_cast(b0) + 1, static_cast(b1) + 1, + mat.material().Z()); + rho.SetBinContent(static_cast(b0) + 1, static_cast(b1) + 1, + mat.material().massDensity()); } } t.Write(); @@ -226,7 +239,8 @@ void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( const auto& materialMatrix = bsMaterial.fullMaterial(); for (auto [b1, materialVector] : enumerate(materialMatrix)) { for (auto [b0, mat] : enumerate(materialVector)) { - idx.SetBinContent(b0 + 1, b1 + 1, payload.index++); + idx.SetBinContent(static_cast(b0) + 1, static_cast(b1) + 1, + payload.index++); fillMaterialSlab(payload, mat); m_gTree->Fill(); } @@ -349,7 +363,7 @@ Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( // Now reconstruct the bin untilities BinUtility bUtility; for (int ib = 1; ib < n->GetNbinsX() + 1; ++ib) { - std::size_t nbins = static_cast(n->GetBinContent(ib)); + auto nbins = static_cast(n->GetBinContent(ib)); auto val = static_cast(v->GetBinContent(ib)); auto opt = static_cast(o->GetBinContent(ib)); float rmin = min->GetBinContent(ib); @@ -427,7 +441,7 @@ Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( // Fill the matrix first for (int ib0 = 1; ib0 <= nbins0; ++ib0) { for (int ib1 = 1; ib1 <= nbins1; ++ib1) { - int idx = static_cast(ih->GetBinContent(ib0, ib1)); + auto idx = static_cast(ih->GetBinContent(ib0, ib1)); indexedMaterialTree->GetEntry(idx); double dt = m_indexedMaterialTreePayload.ht; double dx0 = m_indexedMaterialTreePayload.hX0; From 807538628932c248ba3929cc7a02a9aa6e1b4e32 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Wed, 9 Jul 2025 10:54:27 +0200 Subject: [PATCH 14/30] more SonarCloud issues --- Examples/Io/Root/src/RootMaterialWriter.cpp | 19 ++++--- Plugins/Root/src/RootMaterialMapAccessor.cpp | 57 ++++++++++---------- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/Examples/Io/Root/src/RootMaterialWriter.cpp b/Examples/Io/Root/src/RootMaterialWriter.cpp index 6748d31d616..b18b4345ef2 100644 --- a/Examples/Io/Root/src/RootMaterialWriter.cpp +++ b/Examples/Io/Root/src/RootMaterialWriter.cpp @@ -123,8 +123,8 @@ void ActsExamples::RootMaterialWriter::writeMaterial( } // 2-D or 3-D maps - int bins = static_cast(binningData.size()); - float fBins = static_cast(bins); + auto bins = static_cast(binningData.size()); + auto fBins = static_cast(bins); // The bin number information TH1F n(m_cfg.accessorConfig.ntag.c_str(), "bins; bin", bins, -0.5, @@ -149,11 +149,14 @@ void ActsExamples::RootMaterialWriter::writeMaterial( // Now fill the histogram content for (const auto& [b, bData] : enumerate(binningData)) { // Fill: nbins, value, option, min, max - n.SetBinContent(b, static_cast(binningData[b - 1].bins())); - v.SetBinContent(b, static_cast(binningData[b - 1].binvalue)); - o.SetBinContent(b, static_cast(binningData[b - 1].option)); - rmin.SetBinContent(b, binningData[b - 1].min); - rmax.SetBinContent(b, binningData[b - 1].max); + n.SetBinContent(static_cast(b), + static_cast(binningData[b - 1].bins())); + v.SetBinContent(static_cast(b), + static_cast(binningData[b - 1].binvalue)); + o.SetBinContent(static_cast(b), + static_cast(binningData[b - 1].option)); + rmin.SetBinContent(static_cast(b), binningData[b - 1].min); + rmax.SetBinContent(static_cast(b), binningData[b - 1].max); } n.Write(); v.Write(); @@ -162,7 +165,7 @@ void ActsExamples::RootMaterialWriter::writeMaterial( rmax.Write(); } - float fPoints = static_cast(points); + auto fPoints = static_cast(points); TH1F x0(m_cfg.accessorConfig.x0tag.c_str(), "X_{0} [mm] ;gridPoint", points, -0.5, fPoints - 0.5); TH1F l0(m_cfg.accessorConfig.l0tag.c_str(), "#Lambda_{0} [mm] ;gridPoint", diff --git a/Plugins/Root/src/RootMaterialMapAccessor.cpp b/Plugins/Root/src/RootMaterialMapAccessor.cpp index 8c7c25a4fe9..20917f85c15 100644 --- a/Plugins/Root/src/RootMaterialMapAccessor.cpp +++ b/Plugins/Root/src/RootMaterialMapAccessor.cpp @@ -232,15 +232,16 @@ void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( std::size_t bins0 = bsMaterial.binUtility().bins(0); std::size_t bins1 = bsMaterial.binUtility().bins(1); - TH2I idx(m_cfg.itag.c_str(), "indices; bin0; bin1", bins0, -0.5, - static_cast(bins0) - 0.5, bins1, -0.5, + TH2I idx(m_cfg.itag.c_str(), "indices; bin0; bin1", static_cast(bins0), + -0.5, static_cast(bins0) - 0.5, static_cast(bins1), -0.5, static_cast(bins1) - 0.5); // loop over the material and fill const auto& materialMatrix = bsMaterial.fullMaterial(); for (auto [b1, materialVector] : enumerate(materialMatrix)) { for (auto [b0, mat] : enumerate(materialVector)) { idx.SetBinContent(static_cast(b0) + 1, static_cast(b1) + 1, - payload.index++); + payload.index); + payload.index++; fillMaterialSlab(payload, mat); m_gTree->Fill(); } @@ -253,7 +254,7 @@ Acts::DetectorMaterialMaps Acts::RootMaterialMapAccessor::read(TFile& rFile) { auto& [surfaceMaterials, volumeMaterials] = DetectorMaterialMaps; - TTree* homogeneousMaterialTree = + auto homogeneousMaterialTree = dynamic_cast(rFile.Get(m_cfg.homogeneousMaterialTree.c_str())); // Read homogeneous material tree @@ -261,16 +262,16 @@ Acts::DetectorMaterialMaps Acts::RootMaterialMapAccessor::read(TFile& rFile) { connectForRead(*homogeneousMaterialTree, m_homogenousMaterialTreePayload); for (int i = 0; i < homogeneousMaterialTree->GetEntries(); ++i) { homogeneousMaterialTree->GetEntry(i); - Acts::GeometryIdentifier geoID(m_homogenousMaterialTreePayload.hGeoId); - Acts::MaterialSlab materialSlab( - Acts::Material::fromMassDensity(m_homogenousMaterialTreePayload.hX0, - m_homogenousMaterialTreePayload.hL0, - m_homogenousMaterialTreePayload.hA, - m_homogenousMaterialTreePayload.hZ, - m_homogenousMaterialTreePayload.hRho), + GeometryIdentifier geoID(m_homogenousMaterialTreePayload.hGeoId); + MaterialSlab materialSlab( + Material::fromMassDensity(m_homogenousMaterialTreePayload.hX0, + m_homogenousMaterialTreePayload.hL0, + m_homogenousMaterialTreePayload.hA, + m_homogenousMaterialTreePayload.hZ, + m_homogenousMaterialTreePayload.hRho), m_homogenousMaterialTreePayload.ht); auto homogeneousMaterial = - std::make_shared(materialSlab); + std::make_shared(materialSlab); surfaceMaterials.emplace(geoID, homogeneousMaterial); } } @@ -304,29 +305,29 @@ Acts::DetectorMaterialMaps Acts::RootMaterialMapAccessor::read(TFile& rFile) { std::shared_ptr sMaterial = nullptr; boost::split(splitNames, splitNames[1], boost::is_any_of("_")); - Acts::GeometryIdentifier::Value volID = std::stoi(splitNames[0]); + GeometryIdentifier::Value volID = std::stoi(splitNames[0]); // boundary iter_split(splitNames, tdName, boost::algorithm::first_finder(m_cfg.boutag)); boost::split(splitNames, splitNames[1], boost::is_any_of("_")); - Acts::GeometryIdentifier::Value bouID = std::stoi(splitNames[0]); + GeometryIdentifier::Value bouID = std::stoi(splitNames[0]); // layer iter_split(splitNames, tdName, boost::algorithm::first_finder(m_cfg.laytag)); boost::split(splitNames, splitNames[1], boost::is_any_of("_")); - Acts::GeometryIdentifier::Value layID = std::stoi(splitNames[0]); + GeometryIdentifier::Value layID = std::stoi(splitNames[0]); // approach iter_split(splitNames, tdName, boost::algorithm::first_finder(m_cfg.apptag)); boost::split(splitNames, splitNames[1], boost::is_any_of("_")); - Acts::GeometryIdentifier::Value appID = std::stoi(splitNames[0]); + GeometryIdentifier::Value appID = std::stoi(splitNames[0]); // sensitive iter_split(splitNames, tdName, boost::algorithm::first_finder(m_cfg.sentag)); - Acts::GeometryIdentifier::Value senID = std::stoi(splitNames[1]); + GeometryIdentifier::Value senID = std::stoi(splitNames[1]); // Reconstruct the geometry ID - auto geoID = Acts::GeometryIdentifier() + auto geoID = GeometryIdentifier() .withVolume(volID) .withBoundary(bouID) .withLayer(layID) @@ -383,12 +384,12 @@ Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( std::string rhoName = tdName + "/" + m_cfg.rhotag; // Get the histograms - TH2F* t = dynamic_cast(rFile.Get(tName.c_str())); - TH2F* x0 = dynamic_cast(rFile.Get(x0Name.c_str())); - TH2F* l0 = dynamic_cast(rFile.Get(l0Name.c_str())); - TH2F* A = dynamic_cast(rFile.Get(aName.c_str())); - TH2F* Z = dynamic_cast(rFile.Get(zName.c_str())); - TH2F* rho = dynamic_cast(rFile.Get(rhoName.c_str())); + auto t = dynamic_cast(rFile.Get(tName.c_str())); + auto x0 = dynamic_cast(rFile.Get(x0Name.c_str())); + auto l0 = dynamic_cast(rFile.Get(l0Name.c_str())); + auto A = dynamic_cast(rFile.Get(aName.c_str())); + auto Z = dynamic_cast(rFile.Get(zName.c_str())); + auto rho = dynamic_cast(rFile.Get(rhoName.c_str())); std::vector hists{n, v, o, min, max, t, x0, l0, A, Z, rho}; @@ -415,8 +416,8 @@ Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( double drho = rho->GetBinContent(ib0, ib1); // Create material properties const auto material = - Acts::Material::fromMassDensity(dx0, dl0, da, dz, drho); - materialMatrix[ib1 - 1][ib0 - 1] = Acts::MaterialSlab(material, dt); + Material::fromMassDensity(dx0, dl0, da, dz, drho); + materialMatrix[ib1 - 1][ib0 - 1] = MaterialSlab(material, dt); } } } // Construct the binned material with the right bin utility @@ -451,8 +452,8 @@ Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( double drho = m_indexedMaterialTreePayload.hRho; // Create material properties const auto material = - Acts::Material::fromMassDensity(dx0, dl0, da, dz, drho); - materialMatrix[ib1 - 1][ib0 - 1] = Acts::MaterialSlab(material, dt); + Material::fromMassDensity(dx0, dl0, da, dz, drho); + materialMatrix[ib1 - 1][ib0 - 1] = MaterialSlab(material, dt); } } // Construct the binned material with the right bin utility texturedSurfaceMaterial = std::make_shared( From 3deed01e9cd8d2c03b4dbdaf4568b2ba8b799ffe Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Wed, 9 Jul 2025 17:11:23 +0200 Subject: [PATCH 15/30] more SonarCloud issues fixed --- .../Io/Root/src/RootMaterialDecorator.cpp | 2 +- Plugins/Root/src/RootMaterialMapAccessor.cpp | 48 +++++++++---------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Examples/Io/Root/src/RootMaterialDecorator.cpp b/Examples/Io/Root/src/RootMaterialDecorator.cpp index dec14343223..8238aac815d 100644 --- a/Examples/Io/Root/src/RootMaterialDecorator.cpp +++ b/Examples/Io/Root/src/RootMaterialDecorator.cpp @@ -80,7 +80,7 @@ ActsExamples::RootMaterialDecorator::RootMaterialDecorator( tIter->Reset(); // Iterate over the keys in the file - while (TKey* key = static_cast(tIter->Next())) { + while (auto key = static_cast(tIter->Next())) { // Remember the directory std::string tdName(key->GetName()); diff --git a/Plugins/Root/src/RootMaterialMapAccessor.cpp b/Plugins/Root/src/RootMaterialMapAccessor.cpp index 20917f85c15..773edbb18cc 100644 --- a/Plugins/Root/src/RootMaterialMapAccessor.cpp +++ b/Plugins/Root/src/RootMaterialMapAccessor.cpp @@ -240,7 +240,7 @@ void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( for (auto [b1, materialVector] : enumerate(materialMatrix)) { for (auto [b0, mat] : enumerate(materialVector)) { idx.SetBinContent(static_cast(b0) + 1, static_cast(b1) + 1, - payload.index); + static_cast(payload.index)); payload.index++; fillMaterialSlab(payload, mat); m_gTree->Fill(); @@ -272,12 +272,12 @@ Acts::DetectorMaterialMaps Acts::RootMaterialMapAccessor::read(TFile& rFile) { m_homogenousMaterialTreePayload.ht); auto homogeneousMaterial = std::make_shared(materialSlab); - surfaceMaterials.emplace(geoID, homogeneousMaterial); + surfaceMaterials.try_emplace(geoID, homogeneousMaterial); } } // Read the binned surface material, if there - connect it to the payload - TTree* indexedMaterialTree = + auto indexedMaterialTree = dynamic_cast(rFile.Get(m_cfg.indexMaterialTreeName.c_str())); if (indexedMaterialTree != nullptr) { connectForRead(*indexedMaterialTree, m_indexedMaterialTreePayload); @@ -289,7 +289,7 @@ Acts::DetectorMaterialMaps Acts::RootMaterialMapAccessor::read(TFile& rFile) { tIter->Reset(); // Iterate over the keys in the file - while (TKey* key = static_cast(tIter->Next())) { + while (auto key = static_cast(tIter->Next())) { // Remember the directory std::string tdName(key->GetName()); @@ -336,7 +336,7 @@ Acts::DetectorMaterialMaps Acts::RootMaterialMapAccessor::read(TFile& rFile) { auto texturedSurfaceMaterial = readTextureSurfaceMaterial(rFile, tdName, indexedMaterialTree); - surfaceMaterials.emplace(geoID, texturedSurfaceMaterial); + surfaceMaterials.try_emplace(geoID, texturedSurfaceMaterial); } } return DetectorMaterialMaps; @@ -355,11 +355,11 @@ Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( std::string minName = tdName + "/" + m_cfg.mintag; std::string maxName = tdName + "/" + m_cfg.maxtag; // Get the histograms - TH1F* n = dynamic_cast(rFile.Get(nName.c_str())); - TH1F* v = dynamic_cast(rFile.Get(vName.c_str())); - TH1F* o = dynamic_cast(rFile.Get(oName.c_str())); - TH1F* min = dynamic_cast(rFile.Get(minName.c_str())); - TH1F* max = dynamic_cast(rFile.Get(maxName.c_str())); + auto n = dynamic_cast(rFile.Get(nName.c_str())); + auto v = dynamic_cast(rFile.Get(vName.c_str())); + auto o = dynamic_cast(rFile.Get(oName.c_str())); + auto min = dynamic_cast(rFile.Get(minName.c_str())); + auto max = dynamic_cast(rFile.Get(maxName.c_str())); // Now reconstruct the bin untilities BinUtility bUtility; @@ -367,8 +367,8 @@ Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( auto nbins = static_cast(n->GetBinContent(ib)); auto val = static_cast(v->GetBinContent(ib)); auto opt = static_cast(o->GetBinContent(ib)); - float rmin = min->GetBinContent(ib); - float rmax = max->GetBinContent(ib); + auto rmin = static_cast(min->GetBinContent(ib)); + auto rmax = static_cast(max->GetBinContent(ib)); bUtility += Acts::BinUtility(nbins, rmin, rmax, opt, val); } ACTS_VERBOSE("Created " << bUtility); @@ -409,11 +409,11 @@ Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( for (int ib1 = 1; ib1 <= nbins1; ++ib1) { double dt = t->GetBinContent(ib0, ib1); if (dt > 0.) { - double dx0 = x0->GetBinContent(ib0, ib1); - double dl0 = l0->GetBinContent(ib0, ib1); - double da = A->GetBinContent(ib0, ib1); - double dz = Z->GetBinContent(ib0, ib1); - double drho = rho->GetBinContent(ib0, ib1); + auto dx0 = static_cast(x0->GetBinContent(ib0, ib1)); + auto dl0 = static_cast(l0->GetBinContent(ib0, ib1)); + auto da = static_cast(A->GetBinContent(ib0, ib1)); + auto dz = static_cast(Z->GetBinContent(ib0, ib1)); + auto drho = static_cast(rho->GetBinContent(ib0, ib1)); // Create material properties const auto material = Material::fromMassDensity(dx0, dl0, da, dz, drho); @@ -428,7 +428,7 @@ Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( // Construct the names for histogram type storage std::string indexName = tdName + "/" + m_cfg.itag; // Get the histograms - TH2I* ih = dynamic_cast(rFile.Get(indexName.c_str())); + auto ih = dynamic_cast(rFile.Get(indexName.c_str())); if (ih != nullptr) { // Get the number of bins @@ -444,12 +444,12 @@ Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( for (int ib1 = 1; ib1 <= nbins1; ++ib1) { auto idx = static_cast(ih->GetBinContent(ib0, ib1)); indexedMaterialTree->GetEntry(idx); - double dt = m_indexedMaterialTreePayload.ht; - double dx0 = m_indexedMaterialTreePayload.hX0; - double dl0 = m_indexedMaterialTreePayload.hL0; - double da = m_indexedMaterialTreePayload.hA; - double dz = m_indexedMaterialTreePayload.hZ; - double drho = m_indexedMaterialTreePayload.hRho; + float dt = m_indexedMaterialTreePayload.ht; + float dx0 = m_indexedMaterialTreePayload.hX0; + float dl0 = m_indexedMaterialTreePayload.hL0; + float da = m_indexedMaterialTreePayload.hA; + float dz = m_indexedMaterialTreePayload.hZ; + float drho = m_indexedMaterialTreePayload.hRho; // Create material properties const auto material = Material::fromMassDensity(dx0, dl0, da, dz, drho); From a86122cded89f7b65234490b7d857c71c5ad9210 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Thu, 10 Jul 2025 09:10:38 +0200 Subject: [PATCH 16/30] chore-move-material-map-io-to-plugins --- .../Io/Root/RootMaterialDecorator.hpp | 2 + .../Io/Root/RootMaterialWriter.hpp | 7 +- .../Io/Root/src/RootMaterialDecorator.cpp | 9 +-- Examples/Io/Root/src/RootMaterialWriter.cpp | 8 +-- Examples/Python/src/RootInput.cpp | 2 +- Examples/Python/src/RootOutput.cpp | 13 +++- .../Plugins/Root/RootMaterialMapAccessor.hpp | 38 +++++++---- Plugins/Root/src/RootMaterialMapAccessor.cpp | 64 +++++++++---------- .../Root/RootMaterialMapAccessorTests.cpp | 29 +++++---- 9 files changed, 102 insertions(+), 70 deletions(-) diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp index 995049bf30f..36b9e5fafe2 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp @@ -41,6 +41,8 @@ class RootMaterialDecorator : public Acts::IMaterialDecorator { public: /// Accessor config Acts::RootMaterialMapAccessor::Config accessorConfig; + /// Accessor options + Acts::RootMaterialMapAccessor::Options accessorOptions; /// The name of the output file std::string fileName = "material-maps.root"; }; diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp index ffc259a638f..df5c4f1d44f 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp @@ -64,8 +64,13 @@ class RootMaterialWriter : public IMaterialWriter { /// Steering to handle volume data bool processVolumes = true; - // The accessor configuration + + /// The accessor configuration Acts::RootMaterialMapAccessor::Config accessorConfig; + + /// The accessor options + Acts::RootMaterialMapAccessor::Options accessorOptions; + /// The name of the output file std::string filePath = "material-maps.root"; /// The file mode diff --git a/Examples/Io/Root/src/RootMaterialDecorator.cpp b/Examples/Io/Root/src/RootMaterialDecorator.cpp index 8238aac815d..ac76ab9cf2c 100644 --- a/Examples/Io/Root/src/RootMaterialDecorator.cpp +++ b/Examples/Io/Root/src/RootMaterialDecorator.cpp @@ -54,9 +54,9 @@ ActsExamples::RootMaterialDecorator::RootMaterialDecorator( : m_cfg(config), m_logger{Acts::getDefaultLogger("RootMaterialDecorator", level)} { // Validate the configuration - if (m_cfg.accessorConfig.folderSurfaceNameBase.empty()) { + if (m_cfg.accessorOptions.folderSurfaceNameBase.empty()) { throw std::invalid_argument("Missing surface folder name base"); - } else if (m_cfg.accessorConfig.folderVolumeNameBase.empty()) { + } else if (m_cfg.accessorOptions.folderVolumeNameBase.empty()) { throw std::invalid_argument("Missing volume folder name base"); } else if (m_cfg.fileName.empty()) { throw std::invalid_argument("Missing file name"); @@ -70,7 +70,8 @@ ActsExamples::RootMaterialDecorator::RootMaterialDecorator( Acts::RootMaterialMapAccessor accessor( m_cfg.accessorConfig, m_logger->clone("RootMaterialMapAccessor")); - auto [surfaceMaps, volumeMaps] = accessor.read(*m_inputFile); + auto [surfaceMaps, volumeMaps] = + accessor.read(*m_inputFile, m_cfg.accessorOptions); m_surfaceMaterialMap = std::move(surfaceMaps); @@ -89,7 +90,7 @@ ActsExamples::RootMaterialDecorator::RootMaterialDecorator( boost::algorithm::first_finder(m_cfg.accessorConfig.voltag)); ACTS_VERBOSE("Processing directory: " << tdName); - if (splitNames[0] == m_cfg.accessorConfig.folderVolumeNameBase) { + if (splitNames[0] == m_cfg.accessorOptions.folderVolumeNameBase) { // The volume material to be read in for this std::shared_ptr vMaterial = nullptr; // Volume key diff --git a/Examples/Io/Root/src/RootMaterialWriter.cpp b/Examples/Io/Root/src/RootMaterialWriter.cpp index b18b4345ef2..396e1dcf376 100644 --- a/Examples/Io/Root/src/RootMaterialWriter.cpp +++ b/Examples/Io/Root/src/RootMaterialWriter.cpp @@ -47,9 +47,9 @@ ActsExamples::RootMaterialWriter::RootMaterialWriter( : m_cfg(config), m_logger{Acts::getDefaultLogger("RootMaterialWriter", level)} { // Validate the configuration - if (m_cfg.accessorConfig.folderSurfaceNameBase.empty()) { + if (m_cfg.accessorOptions.folderSurfaceNameBase.empty()) { throw std::invalid_argument("Missing surface folder name base"); - } else if (m_cfg.accessorConfig.folderVolumeNameBase.empty()) { + } else if (m_cfg.accessorOptions.folderVolumeNameBase.empty()) { throw std::invalid_argument("Missing volume folder name base"); } else if (m_cfg.filePath.empty()) { throw std::invalid_argument("Missing file name"); @@ -75,7 +75,7 @@ void ActsExamples::RootMaterialWriter::writeMaterial( for (const auto& [geoId, sMap] : surfaceMaps) { // Get the Surface material - accessor.write(*m_outputFile, geoId, *sMap); + accessor.write(*m_outputFile, geoId, *sMap, m_cfg.accessorOptions); } // Write the volume material maps @@ -93,7 +93,7 @@ void ActsExamples::RootMaterialWriter::writeMaterial( const auto gvolID = geoID.volume(); // create the directory - std::string tdName = m_cfg.accessorConfig.folderVolumeNameBase.c_str(); + std::string tdName = m_cfg.accessorOptions.folderVolumeNameBase.c_str(); tdName += m_cfg.accessorConfig.voltag + std::to_string(gvolID); // create a new directory diff --git a/Examples/Python/src/RootInput.cpp b/Examples/Python/src/RootInput.cpp index 9c541670d67..2e47065c1ff 100644 --- a/Examples/Python/src/RootInput.cpp +++ b/Examples/Python/src/RootInput.cpp @@ -82,7 +82,7 @@ void addRootInput(Context& ctx) { using Config = RootMaterialDecorator::Config; auto c = py::class_(rmd, "Config").def(py::init<>()); - ACTS_PYTHON_STRUCT(c, accessorConfig, fileName); + ACTS_PYTHON_STRUCT(c, accessorConfig, accessorOptions, fileName); } } diff --git a/Examples/Python/src/RootOutput.cpp b/Examples/Python/src/RootOutput.cpp index fc878511088..69445888940 100644 --- a/Examples/Python/src/RootOutput.cpp +++ b/Examples/Python/src/RootOutput.cpp @@ -160,11 +160,22 @@ void addRootOutput(Context& ctx) { auto ac = py::class_(w, "AccessorConfig") .def(py::init<>()); + ACTS_PYTHON_STRUCT(ac, voltag, boutag, laytag, apptag, sentag, ntag, vtag, + otag, itag, mintag, maxtag, ttag, x0tag, l0tag, atag, + ztag, rhotag); + + auto ao = py::class_(w, "AccessorOptions") + .def(py::init<>()); + + ACTS_PYTHON_STRUCT(ao, homogeneousMaterialTreeName, indexedMaterialTreeName, + folderSurfaceNameBase, folderVolumeNameBase, + indexedMaterial); + auto c = py::class_(w, "Config").def(py::init<>()); ACTS_PYTHON_STRUCT(c, processSensitives, processApproaches, processRepresenting, processBoundaries, accessorConfig, - filePath, fileMode); + accessorOptions, filePath, fileMode); } ACTS_PYTHON_DECLARE_WRITER(ActsExamples::RootSeedWriter, mex, diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp index 2f39a0a36f4..e0c49ce80f3 100644 --- a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp +++ b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp @@ -33,16 +33,10 @@ class BinnedSurfaceMaterial; /// and writing. class RootMaterialMapAccessor { public: + /// @brief Configuration for the accessor + /// Contains the tags used for writing and reading, tag names are + /// configuration, as they are not very likely to change. struct Config { - bool indexedMaterial = false; - /// The name of the homogeneous material tree - std::string homogeneousMaterialTree = "HomogeneousMaterial"; - /// The name of the indexed material tree - std::string indexMaterialTreeName = "IndexedMaterial"; - /// The name of the output surface tree - std::string folderSurfaceNameBase = "SurfaceMaterial"; - /// The name of the output volume tree - std::string folderVolumeNameBase = "VolumeMaterial"; /// The volume identification string std::string voltag = "_vol"; /// The boundary identification string @@ -79,6 +73,22 @@ class RootMaterialMapAccessor { std::string rhotag = "rho"; }; + /// @brief Options for writing the material maps + /// Folder names are optional as it allows to write more maps into one + /// file, e.g. for the same detector with different configurations. + struct Options { + /// The name of the homogeneous material tree + std::string homogeneousMaterialTreeName = "HomogeneousMaterial"; + /// The name of the indexed material tree + std::string indexedMaterialTreeName = "IndexedMaterial"; + /// The name of the output surface tree + std::string folderSurfaceNameBase = "SurfaceMaterial"; + /// The name of the output volume tree + std::string folderVolumeNameBase = "VolumeMaterial"; + /// Use an indexed material tree + bool indexedMaterial = false; + }; + struct MaterialTreePayload { std::size_t index = 0; /// geometry identifier @@ -112,18 +122,22 @@ class RootMaterialMapAccessor { /// Write the detector maps /// @param rFile the file to write to /// @param detectorMaterial the detector material maps - void write(TFile& rFile, const DetectorMaterialMaps& detectorMaterial); + /// @param options the options for writing + void write(TFile& rFile, const DetectorMaterialMaps& detectorMaterial, + const Options& options); /// Write the material to file /// @param rFile the file to write to /// @param geoID the geometry identifier for the surface /// @param surfaceMaterial is the surface associated with the material + /// @param options the options for writing void write(TFile& rFile, const GeometryIdentifier& geoID, - const ISurfaceMaterial& surfaceMaterial); + const ISurfaceMaterial& surfaceMaterial, const Options& options); /// Read the detector maps /// @param rFile the file to read from - DetectorMaterialMaps read(TFile& rFile); + /// @param options the options for reading + DetectorMaterialMaps read(TFile& rFile, const Options& options); private: /// @brief Connect the homogeneous material tree for writing diff --git a/Plugins/Root/src/RootMaterialMapAccessor.cpp b/Plugins/Root/src/RootMaterialMapAccessor.cpp index 773edbb18cc..99bc144f3ef 100644 --- a/Plugins/Root/src/RootMaterialMapAccessor.cpp +++ b/Plugins/Root/src/RootMaterialMapAccessor.cpp @@ -30,7 +30,7 @@ void Acts::RootMaterialMapAccessor::write( TFile& rFile, const GeometryIdentifier& geoID, - const ISurfaceMaterial& surfaceMaterial) { + const ISurfaceMaterial& surfaceMaterial, const Options& options) { /// Change to the file rFile.cd(); @@ -39,7 +39,7 @@ void Acts::RootMaterialMapAccessor::write( dynamic_cast(&surfaceMaterial); if (homogeneousMaterial != nullptr) { if (m_hTree == nullptr) { - m_hTree = new TTree(m_cfg.homogeneousMaterialTree.c_str(), + m_hTree = new TTree(options.homogeneousMaterialTreeName.c_str(), "Homogeneous Material Tree"); connectForWrite(*m_hTree, m_homogenousMaterialTreePayload); } @@ -61,7 +61,7 @@ void Acts::RootMaterialMapAccessor::write( const auto gappID = geoID.approach(); const auto gsenID = geoID.sensitive(); // create the directory - std::string tdName = m_cfg.folderSurfaceNameBase.c_str(); + std::string tdName = options.folderSurfaceNameBase.c_str(); tdName += m_cfg.voltag + std::to_string(gvolID); tdName += m_cfg.boutag + std::to_string(gbouID); tdName += m_cfg.laytag + std::to_string(glayID); @@ -111,7 +111,7 @@ void Acts::RootMaterialMapAccessor::write( // If compressed writing is not enabled, write the binned surface material // as histograms - if (!m_cfg.indexedMaterial) { + if (!options.indexedMaterial) { fillBinnedSurfaceMaterial(*bsMaterial); return; } @@ -120,7 +120,7 @@ void Acts::RootMaterialMapAccessor::write( if (m_gTree == nullptr) { // Back to file level rFile.cd(); - m_gTree = new TTree(m_cfg.indexMaterialTreeName.c_str(), + m_gTree = new TTree(options.indexedMaterialTreeName.c_str(), "Indexed Material Tree"); connectForWrite(*m_gTree, m_indexedMaterialTreePayload); // Back to the directory @@ -132,10 +132,11 @@ void Acts::RootMaterialMapAccessor::write( } void Acts::RootMaterialMapAccessor::write( - TFile& rFile, const DetectorMaterialMaps& DetectorMaterialMaps) { - const auto& [surfaceMaterials, volumeMaterials] = DetectorMaterialMaps; + TFile& rFile, const DetectorMaterialMaps& detectorMaterial, + const Options& options) { + const auto& [surfaceMaterials, volumeMaterials] = detectorMaterial; for (const auto& [geoID, sMaterial] : surfaceMaterials) { - write(rFile, geoID, *sMaterial); + write(rFile, geoID, *sMaterial, options); } if (m_hTree != nullptr) { m_hTree->Write(); @@ -201,7 +202,7 @@ void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( TH2F rho(m_cfg.rhotag.c_str(), "#rho [g/mm^3] ;b0 ;b1", bins0, -0.5, fBins0 - 0.5, bins1, -0.5, fBins1 - 0.5); - // loop over the material and fill + // Loop over the material matrix and fill the histograms const auto& materialMatrix = bsMaterial.fullMaterial(); for (auto [b1, materialVector] : enumerate(materialMatrix)) { for (auto [b0, mat] : enumerate(materialVector)) { @@ -235,7 +236,7 @@ void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( TH2I idx(m_cfg.itag.c_str(), "indices; bin0; bin1", static_cast(bins0), -0.5, static_cast(bins0) - 0.5, static_cast(bins1), -0.5, static_cast(bins1) - 0.5); - // loop over the material and fill + // lLop over the material matrix, record the index and fill the indexed tree const auto& materialMatrix = bsMaterial.fullMaterial(); for (auto [b1, materialVector] : enumerate(materialMatrix)) { for (auto [b0, mat] : enumerate(materialVector)) { @@ -249,13 +250,14 @@ void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( idx.Write(); } -Acts::DetectorMaterialMaps Acts::RootMaterialMapAccessor::read(TFile& rFile) { - Acts::DetectorMaterialMaps DetectorMaterialMaps; +Acts::DetectorMaterialMaps Acts::RootMaterialMapAccessor::read( + TFile& rFile, const Options& options) { + DetectorMaterialMaps detectorMaterial; - auto& [surfaceMaterials, volumeMaterials] = DetectorMaterialMaps; + auto& [surfaceMaterials, volumeMaterials] = detectorMaterial; - auto homogeneousMaterialTree = - dynamic_cast(rFile.Get(m_cfg.homogeneousMaterialTree.c_str())); + auto homogeneousMaterialTree = dynamic_cast( + rFile.Get(options.homogeneousMaterialTreeName.c_str())); // Read homogeneous material tree if (homogeneousMaterialTree != nullptr) { @@ -278,7 +280,7 @@ Acts::DetectorMaterialMaps Acts::RootMaterialMapAccessor::read(TFile& rFile) { // Read the binned surface material, if there - connect it to the payload auto indexedMaterialTree = - dynamic_cast(rFile.Get(m_cfg.indexMaterialTreeName.c_str())); + dynamic_cast(rFile.Get(options.indexedMaterialTreeName.c_str())); if (indexedMaterialTree != nullptr) { connectForRead(*indexedMaterialTree, m_indexedMaterialTreePayload); } @@ -300,7 +302,7 @@ Acts::DetectorMaterialMaps Acts::RootMaterialMapAccessor::read(TFile& rFile) { iter_split(splitNames, tdName, boost::algorithm::first_finder(m_cfg.voltag)); // Surface Material - if (splitNames[0] == m_cfg.folderSurfaceNameBase) { + if (splitNames[0] == options.folderSurfaceNameBase) { // The surface material to be read in for this std::shared_ptr sMaterial = nullptr; @@ -339,7 +341,7 @@ Acts::DetectorMaterialMaps Acts::RootMaterialMapAccessor::read(TFile& rFile) { surfaceMaterials.try_emplace(geoID, texturedSurfaceMaterial); } } - return DetectorMaterialMaps; + return detectorMaterial; } std::shared_ptr @@ -399,12 +401,10 @@ Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( // Get the number of bins int nbins0 = t->GetNbinsX(); int nbins1 = t->GetNbinsY(); - // The material matrix MaterialSlabMatrix materialMatrix( nbins1, MaterialSlabVector(nbins0, MaterialSlab::Nothing())); - - // Fill the matrix first + // Fill the matrix from the histogram content for (int ib0 = 1; ib0 <= nbins0; ++ib0) { for (int ib1 = 1; ib1 <= nbins1; ++ib1) { double dt = t->GetBinContent(ib0, ib1); @@ -429,31 +429,25 @@ Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( std::string indexName = tdName + "/" + m_cfg.itag; // Get the histograms auto ih = dynamic_cast(rFile.Get(indexName.c_str())); - if (ih != nullptr) { // Get the number of bins int nbins0 = ih->GetNbinsX(); int nbins1 = ih->GetNbinsY(); - // The material matrix MaterialSlabMatrix materialMatrix( nbins1, MaterialSlabVector(nbins0, MaterialSlab::Nothing())); - - // Fill the matrix first + // Fill the matrix from the tree entries for (int ib0 = 1; ib0 <= nbins0; ++ib0) { for (int ib1 = 1; ib1 <= nbins1; ++ib1) { auto idx = static_cast(ih->GetBinContent(ib0, ib1)); indexedMaterialTree->GetEntry(idx); - float dt = m_indexedMaterialTreePayload.ht; - float dx0 = m_indexedMaterialTreePayload.hX0; - float dl0 = m_indexedMaterialTreePayload.hL0; - float da = m_indexedMaterialTreePayload.hA; - float dz = m_indexedMaterialTreePayload.hZ; - float drho = m_indexedMaterialTreePayload.hRho; - // Create material properties - const auto material = - Material::fromMassDensity(dx0, dl0, da, dz, drho); - materialMatrix[ib1 - 1][ib0 - 1] = MaterialSlab(material, dt); + const auto material = Material::fromMassDensity( + m_indexedMaterialTreePayload.hX0, + m_indexedMaterialTreePayload.hL0, m_indexedMaterialTreePayload.hA, + m_indexedMaterialTreePayload.hZ, + m_indexedMaterialTreePayload.hRho); + materialMatrix[ib1 - 1][ib0 - 1] = + MaterialSlab(material, m_indexedMaterialTreePayload.ht); } } // Construct the binned material with the right bin utility texturedSurfaceMaterial = std::make_shared( diff --git a/Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp b/Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp index 7acba84bc4a..734f940effe 100644 --- a/Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp +++ b/Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp @@ -89,11 +89,12 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorHomogeneousReadWrite) { BOOST_REQUIRE(rFile != nullptr); // Create the accessor - Acts::RootMaterialMapAccessor::Config cfg; - Acts::RootMaterialMapAccessor accessor(cfg); + RootMaterialMapAccessor::Config cfg; + RootMaterialMapAccessor accessor(cfg); + RootMaterialMapAccessor::Options options; for (const auto& [geoID, sMaterial] : surfaceMaterials) { - accessor.write(*rFile, geoID, *sMaterial); + accessor.write(*rFile, geoID, *sMaterial, options); } rFile->Write(); @@ -104,7 +105,7 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorHomogeneousReadWrite) { TFile::Open("RootMaterialMapAccessorHomogeneousTests.root", "READ"); BOOST_REQUIRE(iFile != nullptr); - auto [surfaceMapsRead, volumeMapsRead] = accessor.read(*iFile); + auto [surfaceMapsRead, volumeMapsRead] = accessor.read(*iFile, options); BOOST_REQUIRE_EQUAL(surfaceMapsRead.size(), surfaceMaterials.size()); BOOST_REQUIRE_EQUAL(volumeMapsRead.size(), 0); @@ -136,11 +137,12 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorBinnedReadWrite) { BOOST_REQUIRE(rFile != nullptr); // Create the accessor - Acts::RootMaterialMapAccessor::Config cfg; - Acts::RootMaterialMapAccessor accessor(cfg); + RootMaterialMapAccessor::Config cfg; + RootMaterialMapAccessor accessor(cfg); + RootMaterialMapAccessor::Options options; for (const auto& [geoID, sMaterial] : surfaceMaterials) { - accessor.write(*rFile, geoID, *sMaterial); + accessor.write(*rFile, geoID, *sMaterial, options); } rFile->Write(); @@ -149,7 +151,7 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorBinnedReadWrite) { // Let's read it back auto iFile = TFile::Open("RootMaterialMapAccessorBinnedTests.root", "READ"); BOOST_REQUIRE(iFile != nullptr); - auto [surfaceMapsRead, volumeMapsRead] = accessor.read(*iFile); + auto [surfaceMapsRead, volumeMapsRead] = accessor.read(*iFile, options); BOOST_REQUIRE_EQUAL(surfaceMapsRead.size(), surfaceMaterials.size()); BOOST_REQUIRE_EQUAL(volumeMapsRead.size(), 0); @@ -195,9 +197,12 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorBinnedReadWrite) { } } - // Create the accessor - compressed writing - Acts::RootMaterialMapAccessor::Config cfgIndexed{true}; - Acts::RootMaterialMapAccessor accessorIndexed(cfgIndexed); + // Create the accessor - writing with indexed material + RootMaterialMapAccessor::Config cfgIndexed; + RootMaterialMapAccessor accessorIndexed(cfgIndexed); + + RootMaterialMapAccessor::Options optionsIndexed; + optionsIndexed.indexedMaterial = true; rFile = TFile::Open("RootMaterialMapAccessorBinnedIndexedTests.root", "RECREATE"); @@ -205,7 +210,7 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorBinnedReadWrite) { BOOST_REQUIRE(rFile != nullptr); for (const auto& [geoID, sMaterial] : surfaceMaterials) { - accessorIndexed.write(*rFile, geoID, *sMaterial); + accessorIndexed.write(*rFile, geoID, *sMaterial, optionsIndexed); } rFile->Write(); From 718352ffa180464d17e66a74d5f0a2497dfb6773 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Thu, 10 Jul 2025 09:17:58 +0200 Subject: [PATCH 17/30] Update Examples/Io/Root/src/RootMaterialDecorator.cpp Co-authored-by: Paul Gessinger --- Examples/Io/Root/src/RootMaterialDecorator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Io/Root/src/RootMaterialDecorator.cpp b/Examples/Io/Root/src/RootMaterialDecorator.cpp index ac76ab9cf2c..907e659d836 100644 --- a/Examples/Io/Root/src/RootMaterialDecorator.cpp +++ b/Examples/Io/Root/src/RootMaterialDecorator.cpp @@ -81,7 +81,7 @@ ActsExamples::RootMaterialDecorator::RootMaterialDecorator( tIter->Reset(); // Iterate over the keys in the file - while (auto key = static_cast(tIter->Next())) { + while (auto* key = static_cast(tIter->Next())) { // Remember the directory std::string tdName(key->GetName()); From 7658541b3f30e3322208e6d38adc0a0ac90d053f Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Thu, 10 Jul 2025 09:29:20 +0200 Subject: [PATCH 18/30] renaming to TrackingGeometryMaterial --- Core/include/Acts/Material/MaterialMapper.hpp | 4 ++-- ...rialMaps.hpp => TrackingGeometryMaterial.hpp} | 2 +- Core/src/Material/MaterialMapper.cpp | 4 ++-- .../MaterialMapping/IMaterialWriter.hpp | 4 ++-- .../MaterialMapping/MappingMaterialDecorator.hpp | 3 --- .../MaterialMapping/MaterialMapping.hpp | 2 +- .../MaterialMapping/src/CoreMaterialMapping.cpp | 2 +- .../MaterialMapping/src/MaterialMapping.cpp | 2 +- .../ActsExamples/Io/Json/JsonMaterialWriter.hpp | 4 ++-- Examples/Io/Json/src/JsonMaterialWriter.cpp | 2 +- .../Io/Root/RootMaterialDecorator.hpp | 4 ++-- .../ActsExamples/Io/Root/RootMaterialWriter.hpp | 6 +++--- Examples/Io/Root/src/RootMaterialWriter.cpp | 10 +++++----- .../Acts/Plugins/Json/JsonMaterialDecorator.hpp | 16 ++++++++++------ .../Plugins/Json/MaterialMapJsonConverter.hpp | 10 +++++----- Plugins/Json/src/MaterialMapJsonConverter.cpp | 6 +++--- .../Plugins/Root/RootMaterialMapAccessor.hpp | 6 +++--- Plugins/Root/src/RootMaterialMapAccessor.cpp | 6 +++--- 18 files changed, 47 insertions(+), 46 deletions(-) rename Core/include/Acts/Material/{DetectorMaterialMaps.hpp => TrackingGeometryMaterial.hpp} (90%) diff --git a/Core/include/Acts/Material/MaterialMapper.hpp b/Core/include/Acts/Material/MaterialMapper.hpp index 4381da022b3..39750ab7940 100644 --- a/Core/include/Acts/Material/MaterialMapper.hpp +++ b/Core/include/Acts/Material/MaterialMapper.hpp @@ -10,7 +10,7 @@ #include "Acts/Geometry/GeometryContext.hpp" #include "Acts/MagneticField/MagneticFieldContext.hpp" -#include "Acts/Material/DetectorMaterialMaps.hpp" +#include "Acts/Material/TrackingGeometryMaterial.hpp" #include "Acts/Material/MaterialInteraction.hpp" #include "Acts/Material/MaterialInteractionAssignment.hpp" #include "Acts/Material/interface/IAssignmentFinder.hpp" @@ -76,7 +76,7 @@ class MaterialMapper { const Options& options = Options{}) const; /// Finalize the maps - DetectorMaterialMaps finalizeMaps(const State& state) const; + TrackingGeometryMaterial finalizeMaps(const State& state) const; private: /// Access method to the logger diff --git a/Core/include/Acts/Material/DetectorMaterialMaps.hpp b/Core/include/Acts/Material/TrackingGeometryMaterial.hpp similarity index 90% rename from Core/include/Acts/Material/DetectorMaterialMaps.hpp rename to Core/include/Acts/Material/TrackingGeometryMaterial.hpp index 40357ae27a4..b4baf444151 100644 --- a/Core/include/Acts/Material/DetectorMaterialMaps.hpp +++ b/Core/include/Acts/Material/TrackingGeometryMaterial.hpp @@ -22,6 +22,6 @@ using SurfaceMaterialMaps = std::map>; using VolumeMaterialMaps = std::map>; -using DetectorMaterialMaps = std::pair; +using TrackingGeometryMaterial = std::pair; } // namespace Acts diff --git a/Core/src/Material/MaterialMapper.cpp b/Core/src/Material/MaterialMapper.cpp index 7ed4d08e53c..2f331479688 100644 --- a/Core/src/Material/MaterialMapper.cpp +++ b/Core/src/Material/MaterialMapper.cpp @@ -79,10 +79,10 @@ Acts::MaterialMapper::mapMaterial(State& state, const GeometryContext& gctx, return {mappedMaterial, unmappedMaterial}; } -Acts::DetectorMaterialMaps Acts::MaterialMapper::finalizeMaps( +Acts::TrackingGeometryMaterial Acts::MaterialMapper::finalizeMaps( const State& state) const { // The final maps - DetectorMaterialMaps detectorMaterialMaps; + TrackingGeometryMaterial detectorMaterialMaps; // The surface maps detectorMaterialMaps.first = m_cfg.surfaceMaterialAccumulater->finalizeMaterial( diff --git a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/IMaterialWriter.hpp b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/IMaterialWriter.hpp index a64e1798cae..4883c593df5 100644 --- a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/IMaterialWriter.hpp +++ b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/IMaterialWriter.hpp @@ -9,7 +9,7 @@ #pragma once #include "Acts/Geometry/GeometryIdentifier.hpp" -#include "Acts/Material/DetectorMaterialMaps.hpp" +#include "Acts/Material/TrackingGeometryMaterial.hpp" namespace ActsExamples { @@ -24,7 +24,7 @@ class IMaterialWriter { /// The single writer class /// /// @param detMaterial the detector material maps - virtual void writeMaterial(const Acts::DetectorMaterialMaps& detMaterial) = 0; + virtual void writeMaterial(const Acts::TrackingGeometryMaterial& detMaterial) = 0; }; } // namespace ActsExamples diff --git a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MappingMaterialDecorator.hpp b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MappingMaterialDecorator.hpp index 9c2a87f0f76..3b213e03ffb 100644 --- a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MappingMaterialDecorator.hpp +++ b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MappingMaterialDecorator.hpp @@ -41,9 +41,6 @@ class MappingMaterialDecorator : public IMaterialDecorator { public: using BinningMap = std::map>; - using VolumeMaterialMaps = - std::map>; - MappingMaterialDecorator(const Acts::TrackingGeometry& tGeometry, Acts::Logging::Level level, bool clearSurfaceMaterial = true, diff --git a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MaterialMapping.hpp b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MaterialMapping.hpp index 464dea08499..eaf77ab11de 100644 --- a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MaterialMapping.hpp +++ b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MaterialMapping.hpp @@ -11,7 +11,7 @@ #include "Acts/Geometry/GeometryContext.hpp" #include "Acts/Geometry/GeometryIdentifier.hpp" #include "Acts/MagneticField/MagneticFieldContext.hpp" -#include "Acts/Material/DetectorMaterialMaps.hpp" +#include "Acts/Material/TrackingGeometryMaterial.hpp" #include "Acts/Material/MaterialInteraction.hpp" #include "Acts/Material/SurfaceMaterialMapper.hpp" #include "Acts/Material/VolumeMaterialMapper.hpp" diff --git a/Examples/Algorithms/MaterialMapping/src/CoreMaterialMapping.cpp b/Examples/Algorithms/MaterialMapping/src/CoreMaterialMapping.cpp index e15a641bedc..f7d9f10da1b 100644 --- a/Examples/Algorithms/MaterialMapping/src/CoreMaterialMapping.cpp +++ b/Examples/Algorithms/MaterialMapping/src/CoreMaterialMapping.cpp @@ -36,7 +36,7 @@ CoreMaterialMapping::CoreMaterialMapping(const CoreMaterialMapping::Config& cfg, } CoreMaterialMapping::~CoreMaterialMapping() { - Acts::DetectorMaterialMaps detectorMaterial = + Acts::TrackingGeometryMaterial detectorMaterial = m_cfg.materialMapper->finalizeMaps(*m_mappingState); // Loop over the available writers and write the maps for (auto& imw : m_cfg.materiaMaplWriters) { diff --git a/Examples/Algorithms/MaterialMapping/src/MaterialMapping.cpp b/Examples/Algorithms/MaterialMapping/src/MaterialMapping.cpp index 7077f2f9104..11b423addd6 100644 --- a/Examples/Algorithms/MaterialMapping/src/MaterialMapping.cpp +++ b/Examples/Algorithms/MaterialMapping/src/MaterialMapping.cpp @@ -49,7 +49,7 @@ MaterialMapping::MaterialMapping(const MaterialMapping::Config& cfg, ProcessCode MaterialMapping::finalize() { ACTS_INFO("Finalizing material mappig output"); - Acts::DetectorMaterialMaps detectorMaterial; + Acts::TrackingGeometryMaterial detectorMaterial; if (m_cfg.materialSurfaceMapper && m_cfg.materialVolumeMapper) { // Finalize all the maps using the cached state diff --git a/Examples/Io/Json/include/ActsExamples/Io/Json/JsonMaterialWriter.hpp b/Examples/Io/Json/include/ActsExamples/Io/Json/JsonMaterialWriter.hpp index e5141eee094..58ca11b84f7 100644 --- a/Examples/Io/Json/include/ActsExamples/Io/Json/JsonMaterialWriter.hpp +++ b/Examples/Io/Json/include/ActsExamples/Io/Json/JsonMaterialWriter.hpp @@ -10,7 +10,7 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/Geometry/GeometryIdentifier.hpp" -#include "Acts/Material/DetectorMaterialMaps.hpp" +#include "Acts/Material/TrackingGeometryMaterial.hpp" #include "Acts/Material/ISurfaceMaterial.hpp" #include "Acts/Material/IVolumeMaterial.hpp" #include "Acts/Plugins/Json/MaterialMapJsonConverter.hpp" @@ -69,7 +69,7 @@ class JsonMaterialWriter : public IMaterialWriter { /// Write out the material map /// /// @param detMaterial is the SurfaceMaterial and VolumeMaterial maps - void writeMaterial(const Acts::DetectorMaterialMaps& detMaterial) override; + void writeMaterial(const Acts::TrackingGeometryMaterial& detMaterial) override; /// Write out the material map from Geometry /// diff --git a/Examples/Io/Json/src/JsonMaterialWriter.cpp b/Examples/Io/Json/src/JsonMaterialWriter.cpp index 55b6b686e98..43bcdeced4e 100644 --- a/Examples/Io/Json/src/JsonMaterialWriter.cpp +++ b/Examples/Io/Json/src/JsonMaterialWriter.cpp @@ -28,7 +28,7 @@ ActsExamples::JsonMaterialWriter::JsonMaterialWriter( ActsExamples::JsonMaterialWriter::~JsonMaterialWriter() = default; void ActsExamples::JsonMaterialWriter::writeMaterial( - const Acts::DetectorMaterialMaps& detMaterial) { + const Acts::TrackingGeometryMaterial& detMaterial) { // Evoke the converter auto jOut = m_converter->materialMapsToJson(detMaterial); // And write the file(s) diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp index 36b9e5fafe2..2fe5f425a4f 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include @@ -86,7 +86,7 @@ class RootMaterialDecorator : public Acts::IMaterialDecorator { } /// Return the maps - const Acts::DetectorMaterialMaps materialMaps() const { + const Acts::TrackingGeometryMaterial materialMaps() const { return {m_surfaceMaterialMap, m_volumeMaterialMap}; } diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp index df5c4f1d44f..0fd7da9bf6d 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp @@ -89,7 +89,7 @@ class RootMaterialWriter : public IMaterialWriter { /// Write out the material map /// /// @param detMaterial is the SurfaceMaterial and VolumeMaterial maps - void writeMaterial(const Acts::DetectorMaterialMaps& detMaterial) override; + void writeMaterial(const Acts::TrackingGeometryMaterial& detMaterial) override; /// Write out the material map from Geometry /// @@ -105,14 +105,14 @@ class RootMaterialWriter : public IMaterialWriter { /// @param tVolume The TrackingVolume for the material to be collected /// @param [in,out] detMatMap the map to be filled void collectMaterial(const Acts::TrackingVolume& tVolume, - Acts::DetectorMaterialMaps& detMatMap); + Acts::TrackingGeometryMaterial& detMatMap); /// Collect the material from the tracking geometry /// /// @param tLayer The TrackingVolume for the material to be collected /// @param [in,out] detMatMap the map to be filled void collectMaterial(const Acts::Layer& tLayer, - Acts::DetectorMaterialMaps& detMatMap); + Acts::TrackingGeometryMaterial& detMatMap); /// The config class Config m_cfg; diff --git a/Examples/Io/Root/src/RootMaterialWriter.cpp b/Examples/Io/Root/src/RootMaterialWriter.cpp index 396e1dcf376..2bfb4f110f4 100644 --- a/Examples/Io/Root/src/RootMaterialWriter.cpp +++ b/Examples/Io/Root/src/RootMaterialWriter.cpp @@ -14,7 +14,7 @@ #include "Acts/Geometry/Layer.hpp" #include "Acts/Geometry/TrackingGeometry.hpp" #include "Acts/Geometry/TrackingVolume.hpp" -#include "Acts/Material/DetectorMaterialMaps.hpp" +#include "Acts/Material/TrackingGeometryMaterial.hpp" #include "Acts/Material/ISurfaceMaterial.hpp" #include "Acts/Material/IVolumeMaterial.hpp" #include "Acts/Material/InterpolatedMaterialMap.hpp" @@ -63,7 +63,7 @@ ActsExamples::RootMaterialWriter::RootMaterialWriter( } void ActsExamples::RootMaterialWriter::writeMaterial( - const Acts::DetectorMaterialMaps& detMaterial) { + const Acts::TrackingGeometryMaterial& detMaterial) { // Change to the output file m_outputFile->cd(); @@ -231,7 +231,7 @@ ActsExamples::RootMaterialWriter::~RootMaterialWriter() { void ActsExamples::RootMaterialWriter::write( const Acts::TrackingGeometry& tGeometry) { // Create a detector material map and loop recursively through it - Acts::DetectorMaterialMaps detMatMap; + Acts::TrackingGeometryMaterial detMatMap; auto hVolume = tGeometry.highestTrackingVolume(); if (hVolume != nullptr) { collectMaterial(*hVolume, detMatMap); @@ -242,7 +242,7 @@ void ActsExamples::RootMaterialWriter::write( void ActsExamples::RootMaterialWriter::collectMaterial( const Acts::TrackingVolume& tVolume, - Acts::DetectorMaterialMaps& detMatMap) { + Acts::TrackingGeometryMaterial& detMatMap) { // If the volume has volume material, write that if (tVolume.volumeMaterialPtr() != nullptr && m_cfg.processVolumes) { detMatMap.second[tVolume.geometryId()] = tVolume.volumeMaterialPtr(); @@ -277,7 +277,7 @@ void ActsExamples::RootMaterialWriter::collectMaterial( } void ActsExamples::RootMaterialWriter::collectMaterial( - const Acts::Layer& tLayer, Acts::DetectorMaterialMaps& detMatMap) { + const Acts::Layer& tLayer, Acts::TrackingGeometryMaterial& detMatMap) { // If the representing surface has material, collect it const auto& rSurface = tLayer.surfaceRepresentation(); if (rSurface.surfaceMaterialSharedPtr() != nullptr && diff --git a/Plugins/Json/include/Acts/Plugins/Json/JsonMaterialDecorator.hpp b/Plugins/Json/include/Acts/Plugins/Json/JsonMaterialDecorator.hpp index f630c32b8a8..584a9ff64ac 100644 --- a/Plugins/Json/include/Acts/Plugins/Json/JsonMaterialDecorator.hpp +++ b/Plugins/Json/include/Acts/Plugins/Json/JsonMaterialDecorator.hpp @@ -29,12 +29,16 @@ namespace Acts { /// from a json file class JsonMaterialDecorator : public IMaterialDecorator { public: - using SurfaceMaterialMaps = - std::map>; - - using VolumeMaterialMaps = - std::map>; - + /// Constructor with configuration + /// @param rConfig the configuration for the material map reader + /// @param jFileName the json file name to read + /// @param level the logging level + /// @param clearSurfaceMaterial if true, clear the surface material before + /// decorating, this means if there is no material for a certain surface + /// within the json file, the surface WILL NOT have any material, eventually + /// assigned (proto-/)material will be cleared + /// @param clearVolumeMaterial if true, clear the volume material before + /// decorating, same as above, but for volumes JsonMaterialDecorator(const MaterialMapJsonConverter::Config& rConfig, const std::string& jFileName, Acts::Logging::Level level, diff --git a/Plugins/Json/include/Acts/Plugins/Json/MaterialMapJsonConverter.hpp b/Plugins/Json/include/Acts/Plugins/Json/MaterialMapJsonConverter.hpp index 357efbfdd62..bde15a861f4 100644 --- a/Plugins/Json/include/Acts/Plugins/Json/MaterialMapJsonConverter.hpp +++ b/Plugins/Json/include/Acts/Plugins/Json/MaterialMapJsonConverter.hpp @@ -11,7 +11,7 @@ #include "Acts/Geometry/GeometryContext.hpp" #include "Acts/Geometry/GeometryIdentifier.hpp" #include "Acts/Geometry/TrackingGeometry.hpp" -#include "Acts/Material/DetectorMaterialMaps.hpp" +#include "Acts/Material/TrackingGeometryMaterial.hpp" #include "Acts/Material/ISurfaceMaterial.hpp" #include "Acts/Material/IVolumeMaterial.hpp" #include "Acts/Plugins/Json/ActsJson.hpp" @@ -85,17 +85,17 @@ class MaterialMapJsonConverter { /// Destructor ~MaterialMapJsonConverter() = default; - /// Convert a json material map to a DetectorMaterialMaps + /// Convert a json material map to a TrackingGeometryMaterial /// /// @param materialmaps The json material - DetectorMaterialMaps jsonToMaterialMaps(const nlohmann::json& materialmaps); + TrackingGeometryMaterial jsonToMaterialMaps(const nlohmann::json& materialmaps); - /// Convert a DetectorMaterialMaps to json + /// Convert a TrackingGeometryMaterial to json /// /// @param maps The material map collection /// @param decorator nullptr or a decorator to add extra attributes nlohmann::json materialMapsToJson( - const DetectorMaterialMaps& maps, + const TrackingGeometryMaterial& maps, const IVolumeMaterialJsonDecorator* decorator = nullptr); /// Convert a tracking geometry to json. diff --git a/Plugins/Json/src/MaterialMapJsonConverter.cpp b/Plugins/Json/src/MaterialMapJsonConverter.cpp index 0ce4ad148a8..80c0985412b 100644 --- a/Plugins/Json/src/MaterialMapJsonConverter.cpp +++ b/Plugins/Json/src/MaterialMapJsonConverter.cpp @@ -249,7 +249,7 @@ Acts::MaterialMapJsonConverter::MaterialMapJsonConverter( /// Convert method /// nlohmann::json Acts::MaterialMapJsonConverter::materialMapsToJson( - const DetectorMaterialMaps& maps, + const TrackingGeometryMaterial& maps, const IVolumeMaterialJsonDecorator* decorator) { VolumeMaterialMaps volumeMap = maps.second; std::vector> @@ -277,7 +277,7 @@ nlohmann::json Acts::MaterialMapJsonConverter::materialMapsToJson( return materialMap; } -Acts::DetectorMaterialMaps Acts::MaterialMapJsonConverter::jsonToMaterialMaps( +Acts::TrackingGeometryMaterial Acts::MaterialMapJsonConverter::jsonToMaterialMaps( const nlohmann::json& materialmap) { nlohmann::json materialVolume = materialmap["Volumes"]; GeometryHierarchyMap hierarchyVolumeMap = @@ -298,7 +298,7 @@ Acts::DetectorMaterialMaps Acts::MaterialMapJsonConverter::jsonToMaterialMaps( surfaceMap.insert({hierarchySurfaceMap.idAt(i), std::move(surfacePointer)}); } - Acts::DetectorMaterialMaps maps = {surfaceMap, volumeMap}; + Acts::TrackingGeometryMaterial maps = {surfaceMap, volumeMap}; // Return the filled maps return maps; diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp index e0c49ce80f3..bca4fabf9b7 100644 --- a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp +++ b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp @@ -8,7 +8,7 @@ #pragma once -#include "Acts/Material/DetectorMaterialMaps.hpp" +#include "Acts/Material/TrackingGeometryMaterial.hpp" #include "Acts/Utilities/Logger.hpp" #include @@ -123,7 +123,7 @@ class RootMaterialMapAccessor { /// @param rFile the file to write to /// @param detectorMaterial the detector material maps /// @param options the options for writing - void write(TFile& rFile, const DetectorMaterialMaps& detectorMaterial, + void write(TFile& rFile, const TrackingGeometryMaterial& detectorMaterial, const Options& options); /// Write the material to file @@ -137,7 +137,7 @@ class RootMaterialMapAccessor { /// Read the detector maps /// @param rFile the file to read from /// @param options the options for reading - DetectorMaterialMaps read(TFile& rFile, const Options& options); + TrackingGeometryMaterial read(TFile& rFile, const Options& options); private: /// @brief Connect the homogeneous material tree for writing diff --git a/Plugins/Root/src/RootMaterialMapAccessor.cpp b/Plugins/Root/src/RootMaterialMapAccessor.cpp index 99bc144f3ef..b62e3931a13 100644 --- a/Plugins/Root/src/RootMaterialMapAccessor.cpp +++ b/Plugins/Root/src/RootMaterialMapAccessor.cpp @@ -132,7 +132,7 @@ void Acts::RootMaterialMapAccessor::write( } void Acts::RootMaterialMapAccessor::write( - TFile& rFile, const DetectorMaterialMaps& detectorMaterial, + TFile& rFile, const TrackingGeometryMaterial& detectorMaterial, const Options& options) { const auto& [surfaceMaterials, volumeMaterials] = detectorMaterial; for (const auto& [geoID, sMaterial] : surfaceMaterials) { @@ -250,9 +250,9 @@ void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( idx.Write(); } -Acts::DetectorMaterialMaps Acts::RootMaterialMapAccessor::read( +Acts::TrackingGeometryMaterial Acts::RootMaterialMapAccessor::read( TFile& rFile, const Options& options) { - DetectorMaterialMaps detectorMaterial; + TrackingGeometryMaterial detectorMaterial; auto& [surfaceMaterials, volumeMaterials] = detectorMaterial; From 4f20c6b8085b0a28aedba5f20e6365b8ac526dca Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Thu, 10 Jul 2025 09:54:22 +0200 Subject: [PATCH 19/30] next round of PR comments --- Core/include/Acts/Material/MaterialMapper.hpp | 2 +- .../Material/TrackingGeometryMaterial.hpp | 3 +- .../MaterialMapping/IMaterialWriter.hpp | 3 +- .../MaterialMapping/MaterialMapping.hpp | 2 +- .../Io/Json/JsonMaterialWriter.hpp | 5 +- .../Io/Root/RootMaterialDecorator.hpp | 8 +- .../Io/Root/RootMaterialTrackReader.hpp | 4 +- .../Io/Root/RootMaterialTrackWriter.hpp | 4 +- .../Io/Root/RootMaterialWriter.hpp | 9 +- .../Io/Root/src/RootMaterialDecorator.cpp | 32 ++--- Examples/Io/Root/src/RootMaterialWriter.cpp | 44 +++---- Examples/Python/src/RootOutput.cpp | 15 ++- .../Plugins/Json/MaterialMapJsonConverter.hpp | 5 +- Plugins/Json/src/MaterialMapJsonConverter.cpp | 3 +- Plugins/Root/CMakeLists.txt | 4 +- ...lMapAccessor.hpp => RootMaterialMapIO.hpp} | 64 +++++----- ...ckAccessor.hpp => RootMaterialTrackIO.hpp} | 6 +- ...lMapAccessor.cpp => RootMaterialMapIO.cpp} | 112 +++++++++--------- ...ckAccessor.cpp => RootMaterialTrackIO.cpp} | 10 +- Tests/UnitTests/Plugins/Root/CMakeLists.txt | 2 +- ...orTests.cpp => RootMaterialMapIOTests.cpp} | 36 +++--- 21 files changed, 193 insertions(+), 180 deletions(-) rename Plugins/Root/include/Acts/Plugins/Root/{RootMaterialMapAccessor.hpp => RootMaterialMapIO.hpp} (81%) rename Plugins/Root/include/Acts/Plugins/Root/{RootMaterialTrackAccessor.hpp => RootMaterialTrackIO.hpp} (97%) rename Plugins/Root/src/{RootMaterialMapAccessor.cpp => RootMaterialMapIO.cpp} (81%) rename Plugins/Root/src/{RootMaterialTrackAccessor.cpp => RootMaterialTrackIO.cpp} (97%) rename Tests/UnitTests/Plugins/Root/{RootMaterialMapAccessorTests.cpp => RootMaterialMapIOTests.cpp} (87%) diff --git a/Core/include/Acts/Material/MaterialMapper.hpp b/Core/include/Acts/Material/MaterialMapper.hpp index 39750ab7940..6a209b723d6 100644 --- a/Core/include/Acts/Material/MaterialMapper.hpp +++ b/Core/include/Acts/Material/MaterialMapper.hpp @@ -10,9 +10,9 @@ #include "Acts/Geometry/GeometryContext.hpp" #include "Acts/MagneticField/MagneticFieldContext.hpp" -#include "Acts/Material/TrackingGeometryMaterial.hpp" #include "Acts/Material/MaterialInteraction.hpp" #include "Acts/Material/MaterialInteractionAssignment.hpp" +#include "Acts/Material/TrackingGeometryMaterial.hpp" #include "Acts/Material/interface/IAssignmentFinder.hpp" #include "Acts/Material/interface/ISurfaceMaterialAccumulater.hpp" #include "Acts/Utilities/Logger.hpp" diff --git a/Core/include/Acts/Material/TrackingGeometryMaterial.hpp b/Core/include/Acts/Material/TrackingGeometryMaterial.hpp index b4baf444151..84d3aa2067d 100644 --- a/Core/include/Acts/Material/TrackingGeometryMaterial.hpp +++ b/Core/include/Acts/Material/TrackingGeometryMaterial.hpp @@ -22,6 +22,7 @@ using SurfaceMaterialMaps = std::map>; using VolumeMaterialMaps = std::map>; -using TrackingGeometryMaterial = std::pair; +using TrackingGeometryMaterial = + std::pair; } // namespace Acts diff --git a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/IMaterialWriter.hpp b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/IMaterialWriter.hpp index 4883c593df5..d33c637e00a 100644 --- a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/IMaterialWriter.hpp +++ b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/IMaterialWriter.hpp @@ -24,7 +24,8 @@ class IMaterialWriter { /// The single writer class /// /// @param detMaterial the detector material maps - virtual void writeMaterial(const Acts::TrackingGeometryMaterial& detMaterial) = 0; + virtual void writeMaterial( + const Acts::TrackingGeometryMaterial& detMaterial) = 0; }; } // namespace ActsExamples diff --git a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MaterialMapping.hpp b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MaterialMapping.hpp index eaf77ab11de..9db3bdae874 100644 --- a/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MaterialMapping.hpp +++ b/Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MaterialMapping.hpp @@ -11,9 +11,9 @@ #include "Acts/Geometry/GeometryContext.hpp" #include "Acts/Geometry/GeometryIdentifier.hpp" #include "Acts/MagneticField/MagneticFieldContext.hpp" -#include "Acts/Material/TrackingGeometryMaterial.hpp" #include "Acts/Material/MaterialInteraction.hpp" #include "Acts/Material/SurfaceMaterialMapper.hpp" +#include "Acts/Material/TrackingGeometryMaterial.hpp" #include "Acts/Material/VolumeMaterialMapper.hpp" #include "Acts/Utilities/Logger.hpp" #include "ActsExamples/Framework/DataHandle.hpp" diff --git a/Examples/Io/Json/include/ActsExamples/Io/Json/JsonMaterialWriter.hpp b/Examples/Io/Json/include/ActsExamples/Io/Json/JsonMaterialWriter.hpp index 58ca11b84f7..999d16c9c93 100644 --- a/Examples/Io/Json/include/ActsExamples/Io/Json/JsonMaterialWriter.hpp +++ b/Examples/Io/Json/include/ActsExamples/Io/Json/JsonMaterialWriter.hpp @@ -10,9 +10,9 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/Geometry/GeometryIdentifier.hpp" -#include "Acts/Material/TrackingGeometryMaterial.hpp" #include "Acts/Material/ISurfaceMaterial.hpp" #include "Acts/Material/IVolumeMaterial.hpp" +#include "Acts/Material/TrackingGeometryMaterial.hpp" #include "Acts/Plugins/Json/MaterialMapJsonConverter.hpp" #include "Acts/Utilities/EnumBitwiseOperators.hpp" #include "Acts/Utilities/Logger.hpp" @@ -69,7 +69,8 @@ class JsonMaterialWriter : public IMaterialWriter { /// Write out the material map /// /// @param detMaterial is the SurfaceMaterial and VolumeMaterial maps - void writeMaterial(const Acts::TrackingGeometryMaterial& detMaterial) override; + void writeMaterial( + const Acts::TrackingGeometryMaterial& detMaterial) override; /// Write out the material map from Geometry /// diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp index 2fe5f425a4f..77bb9e5032d 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp @@ -12,11 +12,11 @@ #include #include #include -#include #include #include #include -#include +#include +#include #include #include @@ -40,9 +40,9 @@ class RootMaterialDecorator : public Acts::IMaterialDecorator { class Config { public: /// Accessor config - Acts::RootMaterialMapAccessor::Config accessorConfig; + Acts::RootMaterialMapIO::Config accessorConfig; /// Accessor options - Acts::RootMaterialMapAccessor::Options accessorOptions; + Acts::RootMaterialMapIO::Options accessorOptions; /// The name of the output file std::string fileName = "material-maps.root"; }; diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackReader.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackReader.hpp index 23b81ccdeaa..abcbe969d64 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackReader.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackReader.hpp @@ -9,7 +9,7 @@ #pragma once #include "Acts/Material/MaterialInteraction.hpp" -#include "Acts/Plugins/Root/RootMaterialTrackAccessor.hpp" +#include "Acts/Plugins/Root/RootMaterialTrackIO.hpp" #include "Acts/Utilities/Logger.hpp" #include "ActsExamples/Framework/DataHandle.hpp" #include "ActsExamples/Framework/IReader.hpp" @@ -99,7 +99,7 @@ class RootMaterialTrackReader : public IReader { /// multiple entries corresponding to one event number) std::vector m_entryNumbers = {}; - Acts::RootMaterialTrackAccessor m_accessor; + Acts::RootMaterialTrackIO m_accessor; }; } // namespace ActsExamples diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackWriter.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackWriter.hpp index 2979ac3708c..2ada974d68f 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackWriter.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackWriter.hpp @@ -10,7 +10,7 @@ #include "ActsExamples/Framework/ProcessCode.hpp" #include "ActsExamples/Framework/WriterT.hpp" -#include +#include #include #include @@ -108,7 +108,7 @@ class RootMaterialTrackWriter /// The output tree name TTree* m_outputTree = nullptr; /// The read - write payload - Acts::RootMaterialTrackAccessor m_accessor; + Acts::RootMaterialTrackIO m_accessor; }; } // namespace ActsExamples diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp index 0fd7da9bf6d..cfc1220d344 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include @@ -66,10 +66,10 @@ class RootMaterialWriter : public IMaterialWriter { bool processVolumes = true; /// The accessor configuration - Acts::RootMaterialMapAccessor::Config accessorConfig; + Acts::RootMaterialMapIO::Config accessorConfig; /// The accessor options - Acts::RootMaterialMapAccessor::Options accessorOptions; + Acts::RootMaterialMapIO::Options accessorOptions; /// The name of the output file std::string filePath = "material-maps.root"; @@ -89,7 +89,8 @@ class RootMaterialWriter : public IMaterialWriter { /// Write out the material map /// /// @param detMaterial is the SurfaceMaterial and VolumeMaterial maps - void writeMaterial(const Acts::TrackingGeometryMaterial& detMaterial) override; + void writeMaterial( + const Acts::TrackingGeometryMaterial& detMaterial) override; /// Write out the material map from Geometry /// diff --git a/Examples/Io/Root/src/RootMaterialDecorator.cpp b/Examples/Io/Root/src/RootMaterialDecorator.cpp index 907e659d836..efff3156be2 100644 --- a/Examples/Io/Root/src/RootMaterialDecorator.cpp +++ b/Examples/Io/Root/src/RootMaterialDecorator.cpp @@ -68,8 +68,8 @@ ActsExamples::RootMaterialDecorator::RootMaterialDecorator( throw std::ios_base::failure("Could not open '" + m_cfg.fileName + "'"); } - Acts::RootMaterialMapAccessor accessor( - m_cfg.accessorConfig, m_logger->clone("RootMaterialMapAccessor")); + Acts::RootMaterialMapIO accessor(m_cfg.accessorConfig, + m_logger->clone("RootMaterialMapIO")); auto [surfaceMaps, volumeMaps] = accessor.read(*m_inputFile, m_cfg.accessorOptions); @@ -86,8 +86,9 @@ ActsExamples::RootMaterialDecorator::RootMaterialDecorator( std::string tdName(key->GetName()); std::vector splitNames; - iter_split(splitNames, tdName, - boost::algorithm::first_finder(m_cfg.accessorConfig.voltag)); + iter_split( + splitNames, tdName, + boost::algorithm::first_finder(m_cfg.accessorConfig.volumePrefix)); ACTS_VERBOSE("Processing directory: " << tdName); if (splitNames[0] == m_cfg.accessorOptions.folderVolumeNameBase) { @@ -102,16 +103,19 @@ ActsExamples::RootMaterialDecorator::RootMaterialDecorator( ACTS_VERBOSE("GeometryIdentifier re-constructed as " << geoID); // Construct the names - std::string nName = tdName + "/" + m_cfg.accessorConfig.ntag; - std::string vName = tdName + "/" + m_cfg.accessorConfig.vtag; - std::string oName = tdName + "/" + m_cfg.accessorConfig.otag; - std::string minName = tdName + "/" + m_cfg.accessorConfig.mintag; - std::string maxName = tdName + "/" + m_cfg.accessorConfig.maxtag; - std::string x0Name = tdName + "/" + m_cfg.accessorConfig.x0tag; - std::string l0Name = tdName + "/" + m_cfg.accessorConfig.l0tag; - std::string aName = tdName + "/" + m_cfg.accessorConfig.atag; - std::string zName = tdName + "/" + m_cfg.accessorConfig.ztag; - std::string rhoName = tdName + "/" + m_cfg.accessorConfig.rhotag; + std::string nName = tdName + "/" + m_cfg.accessorConfig.nBinsHistName; + std::string vName = tdName + "/" + m_cfg.accessorConfig.axisDirHistName; + std::string oName = + tdName + "/" + m_cfg.accessorConfig.axisBoundaryTypeHistName; + std::string minName = + tdName + "/" + m_cfg.accessorConfig.minRangeHistName; + std::string maxName = + tdName + "/" + m_cfg.accessorConfig.maxRangeHistName; + std::string x0Name = tdName + "/" + m_cfg.accessorConfig.x0HistName; + std::string l0Name = tdName + "/" + m_cfg.accessorConfig.l0HistName; + std::string aName = tdName + "/" + m_cfg.accessorConfig.aHistName; + std::string zName = tdName + "/" + m_cfg.accessorConfig.zHistName; + std::string rhoName = tdName + "/" + m_cfg.accessorConfig.rhoHistName; // Get the histograms TH1F* n = dynamic_cast(m_inputFile->Get(nName.c_str())); diff --git a/Examples/Io/Root/src/RootMaterialWriter.cpp b/Examples/Io/Root/src/RootMaterialWriter.cpp index 2bfb4f110f4..417bba1b1a4 100644 --- a/Examples/Io/Root/src/RootMaterialWriter.cpp +++ b/Examples/Io/Root/src/RootMaterialWriter.cpp @@ -14,13 +14,13 @@ #include "Acts/Geometry/Layer.hpp" #include "Acts/Geometry/TrackingGeometry.hpp" #include "Acts/Geometry/TrackingVolume.hpp" -#include "Acts/Material/TrackingGeometryMaterial.hpp" #include "Acts/Material/ISurfaceMaterial.hpp" #include "Acts/Material/IVolumeMaterial.hpp" #include "Acts/Material/InterpolatedMaterialMap.hpp" #include "Acts/Material/Material.hpp" #include "Acts/Material/MaterialGridHelper.hpp" #include "Acts/Material/MaterialSlab.hpp" +#include "Acts/Material/TrackingGeometryMaterial.hpp" #include "Acts/Surfaces/Surface.hpp" #include "Acts/Surfaces/SurfaceArray.hpp" #include "Acts/Utilities/BinUtility.hpp" @@ -70,8 +70,8 @@ void ActsExamples::RootMaterialWriter::writeMaterial( const auto& [surfaceMaps, volumeMaps] = detMaterial; // Write the surface material maps - Acts::RootMaterialMapAccessor accessor( - m_cfg.accessorConfig, m_logger->clone("RootMaterialMapAccessor")); + Acts::RootMaterialMapIO accessor(m_cfg.accessorConfig, + m_logger->clone("RootMaterialMapIO")); for (const auto& [geoId, sMap] : surfaceMaps) { // Get the Surface material @@ -94,7 +94,7 @@ void ActsExamples::RootMaterialWriter::writeMaterial( // create the directory std::string tdName = m_cfg.accessorOptions.folderVolumeNameBase.c_str(); - tdName += m_cfg.accessorConfig.voltag + std::to_string(gvolID); + tdName += m_cfg.accessorConfig.volumePrefix + std::to_string(gvolID); // create a new directory m_outputFile->mkdir(tdName.c_str()); @@ -127,24 +127,24 @@ void ActsExamples::RootMaterialWriter::writeMaterial( auto fBins = static_cast(bins); // The bin number information - TH1F n(m_cfg.accessorConfig.ntag.c_str(), "bins; bin", bins, -0.5, - fBins - 0.5); + TH1F n(m_cfg.accessorConfig.nBinsHistName.c_str(), "bins; bin", bins, + -0.5, fBins - 0.5); // The binning value information - TH1F v(m_cfg.accessorConfig.vtag.c_str(), "binning values; bin", bins, - -0.5, fBins - 0.5); + TH1F v(m_cfg.accessorConfig.axisDirHistName.c_str(), + "binning values; bin", bins, -0.5, fBins - 0.5); // The binning option information - TH1F o(m_cfg.accessorConfig.otag.c_str(), "binning options; bin", bins, - -0.5, fBins - 0.5); + TH1F o(m_cfg.accessorConfig.axisBoundaryTypeHistName.c_str(), + "binning options; bin", bins, -0.5, fBins - 0.5); // The binning option information - TH1F rmin(m_cfg.accessorConfig.mintag.c_str(), "min; bin", bins, -0.5, - fBins - 0.5); + TH1F rmin(m_cfg.accessorConfig.minRangeHistName.c_str(), "min; bin", bins, + -0.5, fBins - 0.5); // The binning option information - TH1F rmax(m_cfg.accessorConfig.maxtag.c_str(), "max; bin", bins, -0.5, - fBins - 0.5); + TH1F rmax(m_cfg.accessorConfig.maxRangeHistName.c_str(), "max; bin", bins, + -0.5, fBins - 0.5); // Now fill the histogram content for (const auto& [b, bData] : enumerate(binningData)) { @@ -166,16 +166,16 @@ void ActsExamples::RootMaterialWriter::writeMaterial( } auto fPoints = static_cast(points); - TH1F x0(m_cfg.accessorConfig.x0tag.c_str(), "X_{0} [mm] ;gridPoint", points, - -0.5, fPoints - 0.5); - TH1F l0(m_cfg.accessorConfig.l0tag.c_str(), "#Lambda_{0} [mm] ;gridPoint", + TH1F x0(m_cfg.accessorConfig.x0HistName.c_str(), "X_{0} [mm] ;gridPoint", points, -0.5, fPoints - 0.5); - TH1F A(m_cfg.accessorConfig.atag.c_str(), "X_{0} [mm] ;gridPoint", points, - -0.5, fPoints - 0.5); - TH1F Z(m_cfg.accessorConfig.ztag.c_str(), "#Lambda_{0} [mm] ;gridPoint", + TH1F l0(m_cfg.accessorConfig.l0HistName.c_str(), + "#Lambda_{0} [mm] ;gridPoint", points, -0.5, fPoints - 0.5); + TH1F A(m_cfg.accessorConfig.aHistName.c_str(), "X_{0} [mm] ;gridPoint", points, -0.5, fPoints - 0.5); - TH1F rho(m_cfg.accessorConfig.rhotag.c_str(), "#rho [g/mm^3] ;gridPoint", - points, -0.5, fPoints - 0.5); + TH1F Z(m_cfg.accessorConfig.zHistName.c_str(), + "#Lambda_{0} [mm] ;gridPoint", points, -0.5, fPoints - 0.5); + TH1F rho(m_cfg.accessorConfig.rhoHistName.c_str(), + "#rho [g/mm^3] ;gridPoint", points, -0.5, fPoints - 0.5); // homogeneous volume if (points == 1) { auto mat = vMaterial->material({0, 0, 0}); diff --git a/Examples/Python/src/RootOutput.cpp b/Examples/Python/src/RootOutput.cpp index 69445888940..c7354227b70 100644 --- a/Examples/Python/src/RootOutput.cpp +++ b/Examples/Python/src/RootOutput.cpp @@ -7,7 +7,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. #include "Acts/Plugins/Python/Utilities.hpp" -#include "Acts/Plugins/Root/RootMaterialMapAccessor.hpp" +#include "Acts/Plugins/Root/RootMaterialMapIO.hpp" #include "ActsExamples/Io/Root/RootBFieldWriter.hpp" #include "ActsExamples/Io/Root/RootMaterialTrackWriter.hpp" #include "ActsExamples/Io/Root/RootMaterialWriter.hpp" @@ -157,14 +157,17 @@ void addRootOutput(Context& ctx) { .def("write", py::overload_cast( &Writer::write)); - auto ac = py::class_(w, "AccessorConfig") + auto ac = py::class_(w, "AccessorConfig") .def(py::init<>()); - ACTS_PYTHON_STRUCT(ac, voltag, boutag, laytag, apptag, sentag, ntag, vtag, - otag, itag, mintag, maxtag, ttag, x0tag, l0tag, atag, - ztag, rhotag); + ACTS_PYTHON_STRUCT(ac, volumePrefix, portalPrefix, layerPrefix, + passivePrefix, sensitivePrefix, nBinsHistName, + axisDirHistName, axisBoundaryTypeHistName, indexHistName, + minRangeHistName, maxRangeHistName, thicknessHistName, + x0HistName, l0HistName, aHistName, zHistName, + rhoHistName); - auto ao = py::class_(w, "AccessorOptions") + auto ao = py::class_(w, "AccessorOptions") .def(py::init<>()); ACTS_PYTHON_STRUCT(ao, homogeneousMaterialTreeName, indexedMaterialTreeName, diff --git a/Plugins/Json/include/Acts/Plugins/Json/MaterialMapJsonConverter.hpp b/Plugins/Json/include/Acts/Plugins/Json/MaterialMapJsonConverter.hpp index bde15a861f4..026546a7f99 100644 --- a/Plugins/Json/include/Acts/Plugins/Json/MaterialMapJsonConverter.hpp +++ b/Plugins/Json/include/Acts/Plugins/Json/MaterialMapJsonConverter.hpp @@ -11,9 +11,9 @@ #include "Acts/Geometry/GeometryContext.hpp" #include "Acts/Geometry/GeometryIdentifier.hpp" #include "Acts/Geometry/TrackingGeometry.hpp" -#include "Acts/Material/TrackingGeometryMaterial.hpp" #include "Acts/Material/ISurfaceMaterial.hpp" #include "Acts/Material/IVolumeMaterial.hpp" +#include "Acts/Material/TrackingGeometryMaterial.hpp" #include "Acts/Plugins/Json/ActsJson.hpp" #include "Acts/Plugins/Json/GeometryHierarchyMapJsonConverter.hpp" #include "Acts/Plugins/Json/ITrackingGeometryJsonDecorator.hpp" @@ -88,7 +88,8 @@ class MaterialMapJsonConverter { /// Convert a json material map to a TrackingGeometryMaterial /// /// @param materialmaps The json material - TrackingGeometryMaterial jsonToMaterialMaps(const nlohmann::json& materialmaps); + TrackingGeometryMaterial jsonToMaterialMaps( + const nlohmann::json& materialmaps); /// Convert a TrackingGeometryMaterial to json /// diff --git a/Plugins/Json/src/MaterialMapJsonConverter.cpp b/Plugins/Json/src/MaterialMapJsonConverter.cpp index 80c0985412b..5d49b51779c 100644 --- a/Plugins/Json/src/MaterialMapJsonConverter.cpp +++ b/Plugins/Json/src/MaterialMapJsonConverter.cpp @@ -277,7 +277,8 @@ nlohmann::json Acts::MaterialMapJsonConverter::materialMapsToJson( return materialMap; } -Acts::TrackingGeometryMaterial Acts::MaterialMapJsonConverter::jsonToMaterialMaps( +Acts::TrackingGeometryMaterial +Acts::MaterialMapJsonConverter::jsonToMaterialMaps( const nlohmann::json& materialmap) { nlohmann::json materialVolume = materialmap["Volumes"]; GeometryHierarchyMap hierarchyVolumeMap = diff --git a/Plugins/Root/CMakeLists.txt b/Plugins/Root/CMakeLists.txt index 8fe4f8a7f0f..6ba8a43a1b1 100644 --- a/Plugins/Root/CMakeLists.txt +++ b/Plugins/Root/CMakeLists.txt @@ -1,6 +1,6 @@ set(library_sources - src/RootMaterialMapAccessor.cpp - src/RootMaterialTrackAccessor.cpp + src/RootMaterialMapIO.cpp + src/RootMaterialTrackIO.cpp src/TGeoCylinderDiscSplitter.cpp src/TGeoDetectorElement.cpp src/TGeoLayerBuilder.cpp diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIO.hpp similarity index 81% rename from Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp rename to Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIO.hpp index bca4fabf9b7..376517eec88 100644 --- a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapAccessor.hpp +++ b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIO.hpp @@ -31,46 +31,46 @@ class BinnedSurfaceMaterial; /// Simple payload class that can be wrapped for reading /// and writing. -class RootMaterialMapAccessor { +class RootMaterialMapIO { public: /// @brief Configuration for the accessor /// Contains the tags used for writing and reading, tag names are /// configuration, as they are not very likely to change. struct Config { /// The volume identification string - std::string voltag = "_vol"; + std::string volumePrefix = "_vol"; /// The boundary identification string - std::string boutag = "_bou"; + std::string portalPrefix = "_bou"; /// The layer identification string - std::string laytag = "_lay"; + std::string layerPrefix = "_lay"; /// The approach identification string - std::string apptag = "_app"; + std::string passivePrefix = "_app"; /// The sensitive identification string - std::string sentag = "_sen"; + std::string sensitivePrefix = "_sen"; /// The bin number tag - std::string ntag = "n"; - /// The value tag -> binning values: AxisZ, AxisR, AxisPhi, etc. - std::string vtag = "v"; - /// The option tag -> binning options: open, closed - std::string otag = "o"; - /// The index tag - std::string itag = "i"; - /// The range min tag: min value - std::string mintag = "min"; - /// The range max tag: max value - std::string maxtag = "max"; - /// The thickness tag - std::string ttag = "t"; - /// The x0 tag - std::string x0tag = "x0"; - /// The l0 tag - std::string l0tag = "l0"; - /// The A tag - std::string atag = "A"; - /// The Z tag - std::string ztag = "Z"; - /// The rho tag - std::string rhotag = "rho"; + std::string nBinsHistName = "n"; + /// The axis direction histogram name: AxisZ, AxisR, AxisPhi, etc. + std::string axisDirHistName = "axisDir"; + /// The axis boundary type hist name + std::string axisBoundaryTypeHistName = "o"; + /// The range histogram name: min value + std::string minRangeHistName = "min"; + /// The range histogram name: max value + std::string maxRangeHistName = "max"; + /// The thickness histogram name + std::string thicknessHistName = "t"; + /// The x0 histogram name + std::string x0HistName = "x0"; + /// The l0 histogram name + std::string l0HistName = "l0"; + /// The A histogram name + std::string aHistName = "A"; + /// The Z thisogram name + std::string zHistName = "Z"; + /// The rho thisogram name + std::string rhoHistName = "rho"; + /// The index histogram name + std::string indexHistName = "i"; }; /// @brief Options for writing the material maps @@ -110,14 +110,14 @@ class RootMaterialMapAccessor { /// @brief Constructor from config struct /// @param cfg the configuration for the accessor /// @param mLogger the logger to use, default is INFO level - explicit RootMaterialMapAccessor( + explicit RootMaterialMapIO( const Config& cfg, std::unique_ptr mLogger = - getDefaultLogger("RootMaterialMapAccessor", Logging::INFO)) + getDefaultLogger("RootMaterialMapIO", Logging::INFO)) : m_cfg(cfg), m_logger(std::move(mLogger)) {} /// @brief Destructor - ~RootMaterialMapAccessor() = default; + ~RootMaterialMapIO() = default; /// Write the detector maps /// @param rFile the file to write to diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackAccessor.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIO.hpp similarity index 97% rename from Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackAccessor.hpp rename to Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIO.hpp index 927bbc07616..647116efb78 100644 --- a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackAccessor.hpp +++ b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIO.hpp @@ -26,7 +26,7 @@ class TrackingVolume; /// Simple payload class that can be wrapped for reading /// and writing. -class RootMaterialTrackAccessor { +class RootMaterialTrackIO { public: struct Config { /// Whether to store pre- and post-step information @@ -42,10 +42,10 @@ class RootMaterialTrackAccessor { /// @brief Constructor from config struct /// /// @param cfg the configuration for the accessor - explicit RootMaterialTrackAccessor(const Config& cfg) : m_cfg(cfg) {} + explicit RootMaterialTrackIO(const Config& cfg) : m_cfg(cfg) {} /// @brief Destructor - ~RootMaterialTrackAccessor() = default; + ~RootMaterialTrackIO() = default; /// @brief sets the branch connection for reading from a file /// diff --git a/Plugins/Root/src/RootMaterialMapAccessor.cpp b/Plugins/Root/src/RootMaterialMapIO.cpp similarity index 81% rename from Plugins/Root/src/RootMaterialMapAccessor.cpp rename to Plugins/Root/src/RootMaterialMapIO.cpp index b62e3931a13..b69913e541c 100644 --- a/Plugins/Root/src/RootMaterialMapAccessor.cpp +++ b/Plugins/Root/src/RootMaterialMapIO.cpp @@ -6,7 +6,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -#include "Acts/Plugins/Root/RootMaterialMapAccessor.hpp" +#include "Acts/Plugins/Root/RootMaterialMapIO.hpp" #include "Acts/Geometry/GeometryIdentifier.hpp" #include "Acts/Material/BinnedSurfaceMaterial.hpp" @@ -28,7 +28,7 @@ #include #include -void Acts::RootMaterialMapAccessor::write( +void Acts::RootMaterialMapIO::write( TFile& rFile, const GeometryIdentifier& geoID, const ISurfaceMaterial& surfaceMaterial, const Options& options) { /// Change to the file @@ -62,11 +62,11 @@ void Acts::RootMaterialMapAccessor::write( const auto gsenID = geoID.sensitive(); // create the directory std::string tdName = options.folderSurfaceNameBase.c_str(); - tdName += m_cfg.voltag + std::to_string(gvolID); - tdName += m_cfg.boutag + std::to_string(gbouID); - tdName += m_cfg.laytag + std::to_string(glayID); - tdName += m_cfg.apptag + std::to_string(gappID); - tdName += m_cfg.sentag + std::to_string(gsenID); + tdName += m_cfg.volumePrefix + std::to_string(gvolID); + tdName += m_cfg.portalPrefix + std::to_string(gbouID); + tdName += m_cfg.layerPrefix + std::to_string(glayID); + tdName += m_cfg.passivePrefix + std::to_string(gappID); + tdName += m_cfg.sensitivePrefix + std::to_string(gsenID); // create a new directory rFile.mkdir(tdName.c_str()); rFile.cd(tdName.c_str()); @@ -79,19 +79,19 @@ void Acts::RootMaterialMapAccessor::write( auto fBins = static_cast(bins); // The bin number information - TH1F n(m_cfg.ntag.c_str(), "bins; bin", bins, -0.5, fBins - 0.5); + TH1F n(m_cfg.nBinsHistName.c_str(), "bins; bin", bins, -0.5, fBins - 0.5); // The binning value information - TH1F v(m_cfg.vtag.c_str(), "binning values; bin", bins, -0.5, fBins - 0.5); + TH1F v(m_cfg.axisDirHistName.c_str(), "binning values; bin", bins, -0.5, fBins - 0.5); // The binning option information - TH1F o(m_cfg.otag.c_str(), "binning options; bin", bins, -0.5, fBins - 0.5); + TH1F o(m_cfg.axisBoundaryTypeHistName.c_str(), "binning options; bin", bins, -0.5, fBins - 0.5); // The binning option information - range min - TH1F rmin(m_cfg.mintag.c_str(), "min; bin", bins, -0.5, fBins - 0.5); + TH1F rmin(m_cfg.minRangeHistName.c_str(), "min; bin", bins, -0.5, fBins - 0.5); // The binning option information - range max - TH1F rmax(m_cfg.maxtag.c_str(), "max; bin", bins, -0.5, fBins - 0.5); + TH1F rmax(m_cfg.maxRangeHistName.c_str(), "max; bin", bins, -0.5, fBins - 0.5); // Now fill the histogram content for (auto [b, bData] : enumerate(binningData)) { @@ -131,7 +131,7 @@ void Acts::RootMaterialMapAccessor::write( } } -void Acts::RootMaterialMapAccessor::write( +void Acts::RootMaterialMapIO::write( TFile& rFile, const TrackingGeometryMaterial& detectorMaterial, const Options& options) { const auto& [surfaceMaterials, volumeMaterials] = detectorMaterial; @@ -146,33 +146,33 @@ void Acts::RootMaterialMapAccessor::write( } } -void Acts::RootMaterialMapAccessor::connectForWrite( +void Acts::RootMaterialMapIO::connectForWrite( TTree& rTree, MaterialTreePayload& treePayload) { if (&treePayload == &m_homogenousMaterialTreePayload) { rTree.Branch("hGeoId", &treePayload.hGeoId); } - rTree.Branch(m_cfg.ttag.c_str(), &treePayload.ht); - rTree.Branch(m_cfg.x0tag.c_str(), &treePayload.hX0); - rTree.Branch(m_cfg.l0tag.c_str(), &treePayload.hL0); - rTree.Branch(m_cfg.atag.c_str(), &treePayload.hA); - rTree.Branch(m_cfg.ztag.c_str(), &treePayload.hZ); - rTree.Branch(m_cfg.rhotag.c_str(), &treePayload.hRho); + rTree.Branch(m_cfg.thicknessHistName.c_str(), &treePayload.ht); + rTree.Branch(m_cfg.x0HistName.c_str(), &treePayload.hX0); + rTree.Branch(m_cfg.l0HistName.c_str(), &treePayload.hL0); + rTree.Branch(m_cfg.aHistName.c_str(), &treePayload.hA); + rTree.Branch(m_cfg.zHistName.c_str(), &treePayload.hZ); + rTree.Branch(m_cfg.rhoHistName.c_str(), &treePayload.hRho); } -void Acts::RootMaterialMapAccessor::connectForRead( +void Acts::RootMaterialMapIO::connectForRead( TTree& rTree, MaterialTreePayload& treePayload) { if (&treePayload == &m_homogenousMaterialTreePayload) { rTree.SetBranchAddress("hGeoId", &treePayload.hGeoId); } - rTree.SetBranchAddress(m_cfg.ttag.c_str(), &treePayload.ht); - rTree.SetBranchAddress(m_cfg.x0tag.c_str(), &treePayload.hX0); - rTree.SetBranchAddress(m_cfg.l0tag.c_str(), &treePayload.hL0); - rTree.SetBranchAddress(m_cfg.atag.c_str(), &treePayload.hA); - rTree.SetBranchAddress(m_cfg.ztag.c_str(), &treePayload.hZ); - rTree.SetBranchAddress(m_cfg.rhotag.c_str(), &treePayload.hRho); + rTree.SetBranchAddress(m_cfg.thicknessHistName.c_str(), &treePayload.ht); + rTree.SetBranchAddress(m_cfg.x0HistName.c_str(), &treePayload.hX0); + rTree.SetBranchAddress(m_cfg.l0HistName.c_str(), &treePayload.hL0); + rTree.SetBranchAddress(m_cfg.aHistName.c_str(), &treePayload.hA); + rTree.SetBranchAddress(m_cfg.zHistName.c_str(), &treePayload.hZ); + rTree.SetBranchAddress(m_cfg.rhoHistName.c_str(), &treePayload.hRho); } -void Acts::RootMaterialMapAccessor::fillMaterialSlab( +void Acts::RootMaterialMapIO::fillMaterialSlab( MaterialTreePayload& payload, const MaterialSlab& materialSlab) { payload.ht = materialSlab.thickness(); payload.hX0 = materialSlab.material().X0(); @@ -182,24 +182,24 @@ void Acts::RootMaterialMapAccessor::fillMaterialSlab( payload.hRho = materialSlab.material().massDensity(); } -void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( +void Acts::RootMaterialMapIO::fillBinnedSurfaceMaterial( const BinnedSurfaceMaterial& bsMaterial) { auto bins0 = static_cast(bsMaterial.binUtility().bins(0)); auto bins1 = static_cast(bsMaterial.binUtility().bins(1)); auto fBins0 = static_cast(bins0); auto fBins1 = static_cast(bins1); - TH2F t(m_cfg.ttag.c_str(), "thickness [mm] ;b0 ;b1", bins0, -0.5, + TH2F t(m_cfg.thicknessHistName.c_str(), "thickness [mm] ;b0 ;b1", bins0, -0.5, fBins0 - 0.5, bins1, -0.5, fBins1 - 0.5); - TH2F x0(m_cfg.x0tag.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, fBins0 - 0.5, + TH2F x0(m_cfg.x0HistName.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, fBins0 - 0.5, bins1, -0.5, fBins1 - 0.5); - TH2F l0(m_cfg.l0tag.c_str(), "#Lambda_{0} [mm] ;b0 ;b1", bins0, -0.5, + TH2F l0(m_cfg.l0HistName.c_str(), "#Lambda_{0} [mm] ;b0 ;b1", bins0, -0.5, fBins0 - 0.5, bins1, -0.5, fBins1 - 0.5); - TH2F A(m_cfg.atag.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, fBins0 - 0.5, + TH2F A(m_cfg.aHistName.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, fBins0 - 0.5, bins1, -0.5, fBins1 - 0.5); - TH2F Z(m_cfg.ztag.c_str(), "#Lambda_{0} [mm] ;b0 ;b1", bins0, -0.5, + TH2F Z(m_cfg.zHistName.c_str(), "#Lambda_{0} [mm] ;b0 ;b1", bins0, -0.5, fBins0 - 0.5, bins1, -0.5, fBins1 - 0.5); - TH2F rho(m_cfg.rhotag.c_str(), "#rho [g/mm^3] ;b0 ;b1", bins0, -0.5, + TH2F rho(m_cfg.rhoHistName.c_str(), "#rho [g/mm^3] ;b0 ;b1", bins0, -0.5, fBins0 - 0.5, bins1, -0.5, fBins1 - 0.5); // Loop over the material matrix and fill the histograms @@ -228,12 +228,12 @@ void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( rho.Write(); } -void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( +void Acts::RootMaterialMapIO::fillBinnedSurfaceMaterial( MaterialTreePayload& payload, const BinnedSurfaceMaterial& bsMaterial) { std::size_t bins0 = bsMaterial.binUtility().bins(0); std::size_t bins1 = bsMaterial.binUtility().bins(1); - TH2I idx(m_cfg.itag.c_str(), "indices; bin0; bin1", static_cast(bins0), + TH2I idx(m_cfg.indexHistName.c_str(), "indices; bin0; bin1", static_cast(bins0), -0.5, static_cast(bins0) - 0.5, static_cast(bins1), -0.5, static_cast(bins1) - 0.5); // lLop over the material matrix, record the index and fill the indexed tree @@ -250,7 +250,7 @@ void Acts::RootMaterialMapAccessor::fillBinnedSurfaceMaterial( idx.Write(); } -Acts::TrackingGeometryMaterial Acts::RootMaterialMapAccessor::read( +Acts::TrackingGeometryMaterial Acts::RootMaterialMapIO::read( TFile& rFile, const Options& options) { TrackingGeometryMaterial detectorMaterial; @@ -300,7 +300,7 @@ Acts::TrackingGeometryMaterial Acts::RootMaterialMapAccessor::read( // volume std::vector splitNames; iter_split(splitNames, tdName, - boost::algorithm::first_finder(m_cfg.voltag)); + boost::algorithm::first_finder(m_cfg.volumePrefix)); // Surface Material if (splitNames[0] == options.folderSurfaceNameBase) { // The surface material to be read in for this @@ -310,22 +310,22 @@ Acts::TrackingGeometryMaterial Acts::RootMaterialMapAccessor::read( GeometryIdentifier::Value volID = std::stoi(splitNames[0]); // boundary iter_split(splitNames, tdName, - boost::algorithm::first_finder(m_cfg.boutag)); + boost::algorithm::first_finder(m_cfg.portalPrefix)); boost::split(splitNames, splitNames[1], boost::is_any_of("_")); GeometryIdentifier::Value bouID = std::stoi(splitNames[0]); // layer iter_split(splitNames, tdName, - boost::algorithm::first_finder(m_cfg.laytag)); + boost::algorithm::first_finder(m_cfg.layerPrefix)); boost::split(splitNames, splitNames[1], boost::is_any_of("_")); GeometryIdentifier::Value layID = std::stoi(splitNames[0]); // approach iter_split(splitNames, tdName, - boost::algorithm::first_finder(m_cfg.apptag)); + boost::algorithm::first_finder(m_cfg.passivePrefix)); boost::split(splitNames, splitNames[1], boost::is_any_of("_")); GeometryIdentifier::Value appID = std::stoi(splitNames[0]); // sensitive iter_split(splitNames, tdName, - boost::algorithm::first_finder(m_cfg.sentag)); + boost::algorithm::first_finder(m_cfg.sensitivePrefix)); GeometryIdentifier::Value senID = std::stoi(splitNames[1]); // Reconstruct the geometry ID @@ -345,17 +345,17 @@ Acts::TrackingGeometryMaterial Acts::RootMaterialMapAccessor::read( } std::shared_ptr -Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( +Acts::RootMaterialMapIO::readTextureSurfaceMaterial( TFile& rFile, const std::string& tdName, TTree* indexedMaterialTree) { std::shared_ptr texturedSurfaceMaterial = nullptr; // Construct the common names & get the common histograms - std::string nName = tdName + "/" + m_cfg.ntag; - std::string vName = tdName + "/" + m_cfg.vtag; - std::string oName = tdName + "/" + m_cfg.otag; - std::string minName = tdName + "/" + m_cfg.mintag; - std::string maxName = tdName + "/" + m_cfg.maxtag; + std::string nName = tdName + "/" + m_cfg.nBinsHistName; + std::string vName = tdName + "/" + m_cfg.axisDirHistName; + std::string oName = tdName + "/" + m_cfg.axisBoundaryTypeHistName; + std::string minName = tdName + "/" + m_cfg.minRangeHistName; + std::string maxName = tdName + "/" + m_cfg.maxRangeHistName; // Get the histograms auto n = dynamic_cast(rFile.Get(nName.c_str())); auto v = dynamic_cast(rFile.Get(vName.c_str())); @@ -378,12 +378,12 @@ Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( /// Draw from histogram only source if (indexedMaterialTree == nullptr) { // Construct the names for histogram type storage - std::string tName = tdName + "/" + m_cfg.ttag; - std::string x0Name = tdName + "/" + m_cfg.x0tag; - std::string l0Name = tdName + "/" + m_cfg.l0tag; - std::string aName = tdName + "/" + m_cfg.atag; - std::string zName = tdName + "/" + m_cfg.ztag; - std::string rhoName = tdName + "/" + m_cfg.rhotag; + std::string tName = tdName + "/" + m_cfg.thicknessHistName; + std::string x0Name = tdName + "/" + m_cfg.x0HistName; + std::string l0Name = tdName + "/" + m_cfg.l0HistName; + std::string aName = tdName + "/" + m_cfg.aHistName; + std::string zName = tdName + "/" + m_cfg.zHistName; + std::string rhoName = tdName + "/" + m_cfg.rhoHistName; // Get the histograms auto t = dynamic_cast(rFile.Get(tName.c_str())); @@ -426,7 +426,7 @@ Acts::RootMaterialMapAccessor::readTextureSurfaceMaterial( } } else { // Construct the names for histogram type storage - std::string indexName = tdName + "/" + m_cfg.itag; + std::string indexName = tdName + "/" + m_cfg.indexHistName; // Get the histograms auto ih = dynamic_cast(rFile.Get(indexName.c_str())); if (ih != nullptr) { diff --git a/Plugins/Root/src/RootMaterialTrackAccessor.cpp b/Plugins/Root/src/RootMaterialTrackIO.cpp similarity index 97% rename from Plugins/Root/src/RootMaterialTrackAccessor.cpp rename to Plugins/Root/src/RootMaterialTrackIO.cpp index 5bf1bd4c03f..e85defbfa41 100644 --- a/Plugins/Root/src/RootMaterialTrackAccessor.cpp +++ b/Plugins/Root/src/RootMaterialTrackIO.cpp @@ -6,7 +6,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -#include "Acts/Plugins/Root/RootMaterialTrackAccessor.hpp" +#include "Acts/Plugins/Root/RootMaterialTrackIO.hpp" #include "Acts/Surfaces/BoundaryTolerance.hpp" #include "Acts/Surfaces/Surface.hpp" @@ -15,7 +15,7 @@ #include #include -void Acts::RootMaterialTrackAccessor::connectForRead(TChain& materialChain) { +void Acts::RootMaterialTrackIO::connectForRead(TChain& materialChain) { materialChain.SetBranchAddress("event_id", &m_eventId); materialChain.SetBranchAddress("v_x", &m_vX); materialChain.SetBranchAddress("v_y", &m_vY); @@ -49,7 +49,7 @@ void Acts::RootMaterialTrackAccessor::connectForRead(TChain& materialChain) { } } -void Acts::RootMaterialTrackAccessor::connectForWrite(TTree& materialTree) { +void Acts::RootMaterialTrackIO::connectForWrite(TTree& materialTree) { // This sets the branch addresses for the material track // Set the branches materialTree.Branch("event_id", &m_eventId); @@ -99,7 +99,7 @@ void Acts::RootMaterialTrackAccessor::connectForWrite(TTree& materialTree) { } } -void Acts::RootMaterialTrackAccessor::write( +void Acts::RootMaterialTrackIO::write( const GeometryContext& gctx, std::uint32_t eventNum, const RecordedMaterialTrack& materialTrack) { m_eventId = eventNum; @@ -277,7 +277,7 @@ void Acts::RootMaterialTrackAccessor::write( } } -Acts::RecordedMaterialTrack Acts::RootMaterialTrackAccessor::read() const { +Acts::RecordedMaterialTrack Acts::RootMaterialTrackIO::read() const { Acts::RecordedMaterialTrack rmTrack; // Fill the position and momentum rmTrack.first.first = Acts::Vector3(m_vX, m_vY, m_vZ); diff --git a/Tests/UnitTests/Plugins/Root/CMakeLists.txt b/Tests/UnitTests/Plugins/Root/CMakeLists.txt index 2ed8f49319e..77a4f04ad29 100644 --- a/Tests/UnitTests/Plugins/Root/CMakeLists.txt +++ b/Tests/UnitTests/Plugins/Root/CMakeLists.txt @@ -1,6 +1,6 @@ set(unittest_extra_libraries ActsPluginRoot) -add_unittest(RootMaterialMapAccessor RootMaterialMapAccessorTests.cpp) +add_unittest(RootMaterialMapIO RootMaterialMapIOTests.cpp) add_unittest(TGeoArb8Conversion TGeoArb8ConversionTests.cpp) add_unittest(TGeoBBoxConversion TGeoBBoxConversionTests.cpp) add_unittest(TGeoTrd1Conversion TGeoTrd1ConversionTests.cpp) diff --git a/Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp b/Tests/UnitTests/Plugins/Root/RootMaterialMapIOTests.cpp similarity index 87% rename from Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp rename to Tests/UnitTests/Plugins/Root/RootMaterialMapIOTests.cpp index 734f940effe..c380d960612 100644 --- a/Tests/UnitTests/Plugins/Root/RootMaterialMapAccessorTests.cpp +++ b/Tests/UnitTests/Plugins/Root/RootMaterialMapIOTests.cpp @@ -13,7 +13,7 @@ #include "Acts/Material/HomogeneousSurfaceMaterial.hpp" #include "Acts/Material/Material.hpp" #include "Acts/Material/MaterialSlab.hpp" -#include "Acts/Plugins/Root/RootMaterialMapAccessor.hpp" +#include "Acts/Plugins/Root/RootMaterialMapIO.hpp" #include "Acts/Surfaces/PlaneSurface.hpp" #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp" #include "Acts/Utilities/BinUtility.hpp" @@ -78,20 +78,20 @@ std::vector createBinnedSurfaceMaterial() { return binnedMaterials; } -BOOST_AUTO_TEST_SUITE(RootMaterialMapAccessorTests) +BOOST_AUTO_TEST_SUITE(RootMaterialMapIOTests) -BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorHomogeneousReadWrite) { +BOOST_AUTO_TEST_CASE(RootMaterialMapIOHomogeneousReadWrite) { auto surfaceMaterials = createHomogeneousSurfaceMaterial(); auto rFile = - TFile::Open("RootMaterialMapAccessorHomogeneousTests.root", "RECREATE"); + TFile::Open("RootMaterialMapIOHomogeneousTests.root", "RECREATE"); rFile->cd(); BOOST_REQUIRE(rFile != nullptr); // Create the accessor - RootMaterialMapAccessor::Config cfg; - RootMaterialMapAccessor accessor(cfg); - RootMaterialMapAccessor::Options options; + RootMaterialMapIO::Config cfg; + RootMaterialMapIO accessor(cfg); + RootMaterialMapIO::Options options; for (const auto& [geoID, sMaterial] : surfaceMaterials) { accessor.write(*rFile, geoID, *sMaterial, options); @@ -102,7 +102,7 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorHomogeneousReadWrite) { // Let's read it back auto iFile = - TFile::Open("RootMaterialMapAccessorHomogeneousTests.root", "READ"); + TFile::Open("RootMaterialMapIOHomogeneousTests.root", "READ"); BOOST_REQUIRE(iFile != nullptr); auto [surfaceMapsRead, volumeMapsRead] = accessor.read(*iFile, options); @@ -128,18 +128,18 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorHomogeneousReadWrite) { } } -BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorBinnedReadWrite) { +BOOST_AUTO_TEST_CASE(RootMaterialMapIOBinnedReadWrite) { auto surfaceMaterials = createBinnedSurfaceMaterial(); auto rFile = - TFile::Open("RootMaterialMapAccessorBinnedTests.root", "RECREATE"); + TFile::Open("RootMaterialMapIOBinnedTests.root", "RECREATE"); rFile->cd(); BOOST_REQUIRE(rFile != nullptr); // Create the accessor - RootMaterialMapAccessor::Config cfg; - RootMaterialMapAccessor accessor(cfg); - RootMaterialMapAccessor::Options options; + RootMaterialMapIO::Config cfg; + RootMaterialMapIO accessor(cfg); + RootMaterialMapIO::Options options; for (const auto& [geoID, sMaterial] : surfaceMaterials) { accessor.write(*rFile, geoID, *sMaterial, options); @@ -149,7 +149,7 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorBinnedReadWrite) { rFile->Close(); // Let's read it back - auto iFile = TFile::Open("RootMaterialMapAccessorBinnedTests.root", "READ"); + auto iFile = TFile::Open("RootMaterialMapIOBinnedTests.root", "READ"); BOOST_REQUIRE(iFile != nullptr); auto [surfaceMapsRead, volumeMapsRead] = accessor.read(*iFile, options); BOOST_REQUIRE_EQUAL(surfaceMapsRead.size(), surfaceMaterials.size()); @@ -198,14 +198,14 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapAccessorBinnedReadWrite) { } // Create the accessor - writing with indexed material - RootMaterialMapAccessor::Config cfgIndexed; - RootMaterialMapAccessor accessorIndexed(cfgIndexed); + RootMaterialMapIO::Config cfgIndexed; + RootMaterialMapIO accessorIndexed(cfgIndexed); - RootMaterialMapAccessor::Options optionsIndexed; + RootMaterialMapIO::Options optionsIndexed; optionsIndexed.indexedMaterial = true; rFile = - TFile::Open("RootMaterialMapAccessorBinnedIndexedTests.root", "RECREATE"); + TFile::Open("RootMaterialMapIOBinnedIndexedTests.root", "RECREATE"); rFile->cd(); BOOST_REQUIRE(rFile != nullptr); From ff1ce44417919c505187585ff4cbbf96da52186d Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Thu, 10 Jul 2025 10:01:10 +0200 Subject: [PATCH 20/30] adding read-in test for indexed material --- .../Acts/Plugins/Root/RootMaterialMapIO.hpp | 8 +-- Plugins/Root/src/RootMaterialMapIO.cpp | 37 +++++++------ .../Plugins/Root/RootMaterialMapIOTests.cpp | 54 ++++++++++++++++--- 3 files changed, 73 insertions(+), 26 deletions(-) diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIO.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIO.hpp index 376517eec88..ca52bdd772b 100644 --- a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIO.hpp +++ b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIO.hpp @@ -110,10 +110,10 @@ class RootMaterialMapIO { /// @brief Constructor from config struct /// @param cfg the configuration for the accessor /// @param mLogger the logger to use, default is INFO level - explicit RootMaterialMapIO( - const Config& cfg, - std::unique_ptr mLogger = - getDefaultLogger("RootMaterialMapIO", Logging::INFO)) + explicit RootMaterialMapIO(const Config& cfg, + std::unique_ptr mLogger = + getDefaultLogger("RootMaterialMapIO", + Logging::INFO)) : m_cfg(cfg), m_logger(std::move(mLogger)) {} /// @brief Destructor diff --git a/Plugins/Root/src/RootMaterialMapIO.cpp b/Plugins/Root/src/RootMaterialMapIO.cpp index b69913e541c..686110c4bd7 100644 --- a/Plugins/Root/src/RootMaterialMapIO.cpp +++ b/Plugins/Root/src/RootMaterialMapIO.cpp @@ -28,9 +28,10 @@ #include #include -void Acts::RootMaterialMapIO::write( - TFile& rFile, const GeometryIdentifier& geoID, - const ISurfaceMaterial& surfaceMaterial, const Options& options) { +void Acts::RootMaterialMapIO::write(TFile& rFile, + const GeometryIdentifier& geoID, + const ISurfaceMaterial& surfaceMaterial, + const Options& options) { /// Change to the file rFile.cd(); @@ -82,16 +83,20 @@ void Acts::RootMaterialMapIO::write( TH1F n(m_cfg.nBinsHistName.c_str(), "bins; bin", bins, -0.5, fBins - 0.5); // The binning value information - TH1F v(m_cfg.axisDirHistName.c_str(), "binning values; bin", bins, -0.5, fBins - 0.5); + TH1F v(m_cfg.axisDirHistName.c_str(), "binning values; bin", bins, -0.5, + fBins - 0.5); // The binning option information - TH1F o(m_cfg.axisBoundaryTypeHistName.c_str(), "binning options; bin", bins, -0.5, fBins - 0.5); + TH1F o(m_cfg.axisBoundaryTypeHistName.c_str(), "binning options; bin", bins, + -0.5, fBins - 0.5); // The binning option information - range min - TH1F rmin(m_cfg.minRangeHistName.c_str(), "min; bin", bins, -0.5, fBins - 0.5); + TH1F rmin(m_cfg.minRangeHistName.c_str(), "min; bin", bins, -0.5, + fBins - 0.5); // The binning option information - range max - TH1F rmax(m_cfg.maxRangeHistName.c_str(), "max; bin", bins, -0.5, fBins - 0.5); + TH1F rmax(m_cfg.maxRangeHistName.c_str(), "max; bin", bins, -0.5, + fBins - 0.5); // Now fill the histogram content for (auto [b, bData] : enumerate(binningData)) { @@ -159,8 +164,8 @@ void Acts::RootMaterialMapIO::connectForWrite( rTree.Branch(m_cfg.rhoHistName.c_str(), &treePayload.hRho); } -void Acts::RootMaterialMapIO::connectForRead( - TTree& rTree, MaterialTreePayload& treePayload) { +void Acts::RootMaterialMapIO::connectForRead(TTree& rTree, + MaterialTreePayload& treePayload) { if (&treePayload == &m_homogenousMaterialTreePayload) { rTree.SetBranchAddress("hGeoId", &treePayload.hGeoId); } @@ -191,12 +196,12 @@ void Acts::RootMaterialMapIO::fillBinnedSurfaceMaterial( TH2F t(m_cfg.thicknessHistName.c_str(), "thickness [mm] ;b0 ;b1", bins0, -0.5, fBins0 - 0.5, bins1, -0.5, fBins1 - 0.5); - TH2F x0(m_cfg.x0HistName.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, fBins0 - 0.5, - bins1, -0.5, fBins1 - 0.5); + TH2F x0(m_cfg.x0HistName.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, + fBins0 - 0.5, bins1, -0.5, fBins1 - 0.5); TH2F l0(m_cfg.l0HistName.c_str(), "#Lambda_{0} [mm] ;b0 ;b1", bins0, -0.5, fBins0 - 0.5, bins1, -0.5, fBins1 - 0.5); - TH2F A(m_cfg.aHistName.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, fBins0 - 0.5, - bins1, -0.5, fBins1 - 0.5); + TH2F A(m_cfg.aHistName.c_str(), "X_{0} [mm] ;b0 ;b1", bins0, -0.5, + fBins0 - 0.5, bins1, -0.5, fBins1 - 0.5); TH2F Z(m_cfg.zHistName.c_str(), "#Lambda_{0} [mm] ;b0 ;b1", bins0, -0.5, fBins0 - 0.5, bins1, -0.5, fBins1 - 0.5); TH2F rho(m_cfg.rhoHistName.c_str(), "#rho [g/mm^3] ;b0 ;b1", bins0, -0.5, @@ -233,9 +238,9 @@ void Acts::RootMaterialMapIO::fillBinnedSurfaceMaterial( std::size_t bins0 = bsMaterial.binUtility().bins(0); std::size_t bins1 = bsMaterial.binUtility().bins(1); - TH2I idx(m_cfg.indexHistName.c_str(), "indices; bin0; bin1", static_cast(bins0), - -0.5, static_cast(bins0) - 0.5, static_cast(bins1), -0.5, - static_cast(bins1) - 0.5); + TH2I idx(m_cfg.indexHistName.c_str(), "indices; bin0; bin1", + static_cast(bins0), -0.5, static_cast(bins0) - 0.5, + static_cast(bins1), -0.5, static_cast(bins1) - 0.5); // lLop over the material matrix, record the index and fill the indexed tree const auto& materialMatrix = bsMaterial.fullMaterial(); for (auto [b1, materialVector] : enumerate(materialMatrix)) { diff --git a/Tests/UnitTests/Plugins/Root/RootMaterialMapIOTests.cpp b/Tests/UnitTests/Plugins/Root/RootMaterialMapIOTests.cpp index c380d960612..16a5d63d6c3 100644 --- a/Tests/UnitTests/Plugins/Root/RootMaterialMapIOTests.cpp +++ b/Tests/UnitTests/Plugins/Root/RootMaterialMapIOTests.cpp @@ -101,8 +101,7 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapIOHomogeneousReadWrite) { rFile->Close(); // Let's read it back - auto iFile = - TFile::Open("RootMaterialMapIOHomogeneousTests.root", "READ"); + auto iFile = TFile::Open("RootMaterialMapIOHomogeneousTests.root", "READ"); BOOST_REQUIRE(iFile != nullptr); auto [surfaceMapsRead, volumeMapsRead] = accessor.read(*iFile, options); @@ -131,8 +130,7 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapIOHomogeneousReadWrite) { BOOST_AUTO_TEST_CASE(RootMaterialMapIOBinnedReadWrite) { auto surfaceMaterials = createBinnedSurfaceMaterial(); - auto rFile = - TFile::Open("RootMaterialMapIOBinnedTests.root", "RECREATE"); + auto rFile = TFile::Open("RootMaterialMapIOBinnedTests.root", "RECREATE"); rFile->cd(); BOOST_REQUIRE(rFile != nullptr); @@ -204,8 +202,7 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapIOBinnedReadWrite) { RootMaterialMapIO::Options optionsIndexed; optionsIndexed.indexedMaterial = true; - rFile = - TFile::Open("RootMaterialMapIOBinnedIndexedTests.root", "RECREATE"); + rFile = TFile::Open("RootMaterialMapIOBinnedIndexedTests.root", "RECREATE"); rFile->cd(); BOOST_REQUIRE(rFile != nullptr); @@ -215,6 +212,51 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapIOBinnedReadWrite) { rFile->Write(); rFile->Close(); + + // Let's read it back + iFile = TFile::Open("RootMaterialMapIOBinnedIndexedTests.root", "READ"); + BOOST_REQUIRE(iFile != nullptr); + auto [surfaceMapsIndexedRead, volumeMapsIndexedRead] = + accessorIndexed.read(*iFile, optionsIndexed); + BOOST_REQUIRE_EQUAL(surfaceMapsIndexedRead.size(), surfaceMaterials.size()); + BOOST_REQUIRE_EQUAL(volumeMapsIndexedRead.size(), 0); + + // Compare + for (const auto& [refGeoID, refSMaterial] : surfaceMaterials) { + auto binnedReferenceMaterial = + dynamic_cast(refSMaterial.get()); + BOOST_REQUIRE(binnedReferenceMaterial != nullptr); + auto it = surfaceMapsIndexedRead.find(refGeoID); + BOOST_REQUIRE(it != surfaceMapsIndexedRead.end()); + const auto& readMaterial = it->second; + BOOST_REQUIRE(readMaterial != nullptr); + const auto* binnedMaterial = + dynamic_cast(readMaterial.get()); + BOOST_REQUIRE(binnedMaterial != nullptr); + // Check the binning + BOOST_CHECK_EQUAL(binnedMaterial->binUtility().bins(0), + binnedReferenceMaterial->binUtility().bins(0)); + BOOST_CHECK_EQUAL(binnedMaterial->binUtility().bins(1), + binnedReferenceMaterial->binUtility().bins(1)); + // Compare the material matrix + const auto& materialMatrix = binnedMaterial->fullMaterial(); + const auto& referenceMaterialMatrix = + binnedReferenceMaterial->fullMaterial(); + BOOST_REQUIRE_EQUAL(materialMatrix.size(), referenceMaterialMatrix.size()); + for (std::size_t i = 0; i < materialMatrix.size(); ++i) { + BOOST_REQUIRE_EQUAL(materialMatrix[i].size(), + referenceMaterialMatrix[i].size()); + for (std::size_t j = 0; j < materialMatrix[i].size(); ++j) { + const auto& mat = materialMatrix[i][j]; + const auto& refMat = referenceMaterialMatrix[i][j]; + BOOST_CHECK_CLOSE(mat.material().X0(), refMat.material().X0(), 1e-6); + BOOST_CHECK_CLOSE(mat.material().L0(), refMat.material().L0(), 1e-6); + BOOST_CHECK_CLOSE(mat.material().Ar(), refMat.material().Ar(), 1e-6); + BOOST_CHECK_CLOSE(mat.material().Z(), refMat.material().Z(), 1e-6); + BOOST_CHECK_CLOSE(mat.thickness(), refMat.thickness(), 1e-6); + } + } + } } BOOST_AUTO_TEST_SUITE_END() From 65227b4d9912487975c910bd7275043f1ab06b8f Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Thu, 10 Jul 2025 13:42:27 +0200 Subject: [PATCH 21/30] fix detector pytest --- Examples/Io/Root/src/RootMaterialDecorator.cpp | 5 ----- .../Acts/Plugins/Root/RootMaterialMapIO.hpp | 2 +- Plugins/Root/src/RootMaterialMapIO.cpp | 14 +++++++++----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Examples/Io/Root/src/RootMaterialDecorator.cpp b/Examples/Io/Root/src/RootMaterialDecorator.cpp index efff3156be2..f2d3ee7c364 100644 --- a/Examples/Io/Root/src/RootMaterialDecorator.cpp +++ b/Examples/Io/Root/src/RootMaterialDecorator.cpp @@ -236,11 +236,6 @@ ActsExamples::RootMaterialDecorator::RootMaterialDecorator( // Insert into the new collection m_volumeMaterialMap.insert({geoID, std::move(vMaterial)}); - - // Incorrect FolderName value - } else { - ACTS_ERROR( - "Invalid FolderName, does not match any entry in the root file"); } } } diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIO.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIO.hpp index ca52bdd772b..64cafa2f6c2 100644 --- a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIO.hpp +++ b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIO.hpp @@ -50,7 +50,7 @@ class RootMaterialMapIO { /// The bin number tag std::string nBinsHistName = "n"; /// The axis direction histogram name: AxisZ, AxisR, AxisPhi, etc. - std::string axisDirHistName = "axisDir"; + std::string axisDirHistName = "v"; /// The axis boundary type hist name std::string axisBoundaryTypeHistName = "o"; /// The range histogram name: min value diff --git a/Plugins/Root/src/RootMaterialMapIO.cpp b/Plugins/Root/src/RootMaterialMapIO.cpp index 686110c4bd7..73f1ae54cc2 100644 --- a/Plugins/Root/src/RootMaterialMapIO.cpp +++ b/Plugins/Root/src/RootMaterialMapIO.cpp @@ -341,6 +341,8 @@ Acts::TrackingGeometryMaterial Acts::RootMaterialMapIO::read( .withApproach(appID) .withSensitive(senID); + ACTS_VERBOSE("GeometryIdentifier re-constructed as " << geoID); + auto texturedSurfaceMaterial = readTextureSurfaceMaterial(rFile, tdName, indexedMaterialTree); surfaceMaterials.try_emplace(geoID, texturedSurfaceMaterial); @@ -365,8 +367,10 @@ Acts::RootMaterialMapIO::readTextureSurfaceMaterial( auto n = dynamic_cast(rFile.Get(nName.c_str())); auto v = dynamic_cast(rFile.Get(vName.c_str())); auto o = dynamic_cast(rFile.Get(oName.c_str())); - auto min = dynamic_cast(rFile.Get(minName.c_str())); - auto max = dynamic_cast(rFile.Get(maxName.c_str())); + auto minh = dynamic_cast(rFile.Get(minName.c_str())); + auto maxh = dynamic_cast(rFile.Get(maxName.c_str())); + + std::vector hists{n, v, o, minh, maxh}; // Now reconstruct the bin untilities BinUtility bUtility; @@ -374,8 +378,8 @@ Acts::RootMaterialMapIO::readTextureSurfaceMaterial( auto nbins = static_cast(n->GetBinContent(ib)); auto val = static_cast(v->GetBinContent(ib)); auto opt = static_cast(o->GetBinContent(ib)); - auto rmin = static_cast(min->GetBinContent(ib)); - auto rmax = static_cast(max->GetBinContent(ib)); + auto rmin = static_cast(minh->GetBinContent(ib)); + auto rmax = static_cast(maxh->GetBinContent(ib)); bUtility += Acts::BinUtility(nbins, rmin, rmax, opt, val); } ACTS_VERBOSE("Created " << bUtility); @@ -398,7 +402,7 @@ Acts::RootMaterialMapIO::readTextureSurfaceMaterial( auto Z = dynamic_cast(rFile.Get(zName.c_str())); auto rho = dynamic_cast(rFile.Get(rhoName.c_str())); - std::vector hists{n, v, o, min, max, t, x0, l0, A, Z, rho}; + std::vector hists{t, x0, l0, A, Z, rho}; // Only go on when you have all histograms if (std::ranges::all_of(hists, From 254a3527ea82df54b97a47ccf7a20b551feda009 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Thu, 10 Jul 2025 14:51:17 +0200 Subject: [PATCH 22/30] make pytest run --- Examples/Python/tests/test_writer.py | 24 +++++++++++------------- Plugins/Root/src/RootMaterialMapIO.cpp | 10 +++++++++- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Examples/Python/tests/test_writer.py b/Examples/Python/tests/test_writer.py index f3624f1ba7c..0092bb184d8 100644 --- a/Examples/Python/tests/test_writer.py +++ b/Examples/Python/tests/test_writer.py @@ -355,24 +355,22 @@ def test_csv_writer_interface(writer, conf_const, tmp_path, trk_geo): @pytest.mark.odd @pytest.mark.skipif(not dd4hepEnabled, reason="DD4hep not set up") def test_root_material_writer(tmp_path, assert_root_hash): - from acts.examples.dd4hep import DD4hepDetector + from acts.examples.odd import getOpenDataDetector - detector = DD4hepDetector( - xmlFileNames=[str(getOpenDataDetectorDirectory() / "xml/OpenDataDetector.xml")] - ) - trackingGeometry = detector.trackingGeometry() + with getOpenDataDetector() as detector: + trackingGeometry = detector.trackingGeometry() - out = tmp_path / "material.root" + out = tmp_path / "material.root" - assert not out.exists() + assert not out.exists() - rmw = RootMaterialWriter(level=acts.logging.WARNING, filePath=str(out)) - assert out.exists() - assert out.stat().st_size > 0 and out.stat().st_size < 500 - rmw.write(trackingGeometry) + rmw = RootMaterialWriter(level=acts.logging.WARNING, filePath=str(out)) + assert out.exists() + assert out.stat().st_size > 0 and out.stat().st_size < 500 + rmw.write(trackingGeometry) - assert out.stat().st_size > 1000 - assert_root_hash(out.name, out) + assert out.stat().st_size > 1000 + assert_root_hash(out.name, out) @pytest.mark.json diff --git a/Plugins/Root/src/RootMaterialMapIO.cpp b/Plugins/Root/src/RootMaterialMapIO.cpp index 73f1ae54cc2..2b7fb4f0f87 100644 --- a/Plugins/Root/src/RootMaterialMapIO.cpp +++ b/Plugins/Root/src/RootMaterialMapIO.cpp @@ -371,6 +371,14 @@ Acts::RootMaterialMapIO::readTextureSurfaceMaterial( auto maxh = dynamic_cast(rFile.Get(maxName.c_str())); std::vector hists{n, v, o, minh, maxh}; + if (std::ranges::any_of(hists, + [](const auto* hist) { return hist == nullptr; })) { + ACTS_ERROR( + "Failed to read all required histograms for textured surface " + "material from file: " + << rFile.GetName()); + return nullptr; + } // Now reconstruct the bin untilities BinUtility bUtility; @@ -402,7 +410,7 @@ Acts::RootMaterialMapIO::readTextureSurfaceMaterial( auto Z = dynamic_cast(rFile.Get(zName.c_str())); auto rho = dynamic_cast(rFile.Get(rhoName.c_str())); - std::vector hists{t, x0, l0, A, Z, rho}; + hists = {t, x0, l0, A, Z, rho}; // Only go on when you have all histograms if (std::ranges::all_of(hists, From 972bf7c5f74616709550cd67cdcf11be138b145c Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Thu, 10 Jul 2025 15:06:48 +0200 Subject: [PATCH 23/30] symmetrize RootIO with internal payloads --- .../Io/Root/RootMaterialDecorator.hpp | 2 +- .../Acts/Plugins/Root/RootMaterialTrackIO.hpp | 210 +++++----- Plugins/Root/src/RootMaterialTrackIO.cpp | 380 +++++++++--------- 3 files changed, 312 insertions(+), 280 deletions(-) diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp index 77bb9e5032d..8adab4a3e8c 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp @@ -86,7 +86,7 @@ class RootMaterialDecorator : public Acts::IMaterialDecorator { } /// Return the maps - const Acts::TrackingGeometryMaterial materialMaps() const { + Acts::TrackingGeometryMaterial materialMaps() const { return {m_surfaceMaterialMap, m_volumeMaterialMap}; } diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIO.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIO.hpp index 647116efb78..beb5f210707 100644 --- a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIO.hpp +++ b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIO.hpp @@ -75,6 +75,110 @@ class RootMaterialTrackIO { RecordedMaterialTrack read() const; private: + struct MateriaSummaryPayload { + /// start global x + float vX = 0; + /// start global y + float vY = 0; + /// start global z + float vZ = 0; + /// start global momentum x + float vPx = 0; + /// start global momentum y + float vPy = 0; + /// start global momentum z + float vPz = 0; + /// start phi direction + float vPhi = 0; + /// start eta direction + float vEta = 0; + /// thickness in X0/L0 + float tX0 = 0; + /// thickness in X0/L0 + float tL0 = 0; + }; + + struct MaterialStepPayload { + /// (pre-)step x position (optional) + std::vector stepXs; + /// (pre-)step y position (optional) + std::vector stepYs; + /// (pre-)step z position (optional) + std::vector stepZs; + /// (post-)step x position (optional) + std::vector stepXe; + /// (post-)step y position (optional) + std::vector stepYe; + /// (post-)step z position (optional) + std::vector stepZe; + + /// step x position + std::vector stepX; + std::vector* stepXPtr = &stepX; + /// step y position + std::vector stepY; + std::vector* stepYPtr = &stepY; + /// step z position + std::vector stepZ; + std::vector* stepZPtr = &stepZ; + /// step radial position + std::vector stepR; + /// step x direction + std::vector stepDx; + std::vector* stepDxPtr = &stepDx; + /// step y direction + std::vector stepDy; + std::vector* stepDyPtr = &stepDy; + /// step z direction + std::vector stepDz; + std::vector* stepDzPtr = &stepDz; + /// step length + std::vector stepLength; + std::vector* stepLengthPtr = &stepLength; + /// step material x0 + std::vector stepMatX0; + std::vector* stepMatX0Ptr = &stepMatX0; + /// step material l0 + std::vector stepMatL0; + std::vector* stepMatL0Ptr = &stepMatL0; + /// step material A + std::vector stepMatA; + std::vector* stepMatAPtr = &stepMatA; + /// step material Z + std::vector stepMatZ; + std::vector* stepMatZPtr = &stepMatZ; + /// step material rho + std::vector stepMatRho; + std::vector* stepMatRhoPtr = &stepMatRho; + }; + + struct MaterialSurfacePayload { + /// ID of the surface associated with the step + std::vector surfaceId; + std::vector* surfaceIdPtr = &surfaceId; + /// x position of the center of the surface associated with the step + std::vector surfaceX; + std::vector* surfaceXPtr = &surfaceX; + /// y position of the center of the surface associated with the step + std::vector surfaceY; + std::vector* surfaceYPtr = &surfaceY; + /// z position of the center of the surface associated with the step + std::vector surfaceZ; + std::vector* surfaceZPtr = &surfaceZ; + /// r position of the center of the surface associated with the step + std::vector surfaceR; + /// distance to the surface + std::vector surfaceDistance; + /// path correction when associating material to the given surface + std::vector surfacePathCorrection; + std::vector* surfacePathCorrectionPtr = &surfacePathCorrection; + }; + + struct MaterialVolumePayload { + /// ID of the volume associated with the step + std::vector volumeId; + }; + /// The configuration for the accessor Config m_cfg; @@ -85,101 +189,17 @@ class RootMaterialTrackIO { /// multiple entries corresponding to one event number) std::vector m_entryNumbers = {}; - /// start global x - float m_vX = 0; - /// start global y - float m_vY = 0; - /// start global z - float m_vZ = 0; - /// start global momentum x - float m_vPx = 0; - /// start global momentum y - float m_vPy = 0; - /// start global momentum z - float m_vPz = 0; - /// start phi direction - float m_vPhi = 0; - /// start eta direction - float m_vEta = 0; - /// thickness in X0/L0 - float m_tX0 = 0; - /// thickness in X0/L0 - float m_tL0 = 0; - - /// (pre-)step x position (optional) - std::vector m_stepXs; - /// (pre-)step y position (optional) - std::vector m_stepYs; - /// (pre-)step z position (optional) - std::vector m_stepZs; - /// (post-)step x position (optional) - std::vector m_stepXe; - /// (post-)step y position (optional) - std::vector m_stepYe; - /// (post-)step z position (optional) - std::vector m_stepZe; - - /// step x position - std::vector m_stepX; - std::vector* m_stepXPtr = &m_stepX; - /// step y position - std::vector m_stepY; - std::vector* m_stepYPtr = &m_stepY; - /// step z position - std::vector m_stepZ; - std::vector* m_stepZPtr = &m_stepZ; - /// step radial position - std::vector m_stepR; - /// step x direction - std::vector m_stepDx; - std::vector* m_stepDxPtr = &m_stepDx; - /// step y direction - std::vector m_stepDy; - std::vector* m_stepDyPtr = &m_stepDy; - /// step z direction - std::vector m_stepDz; - std::vector* m_stepDzPtr = &m_stepDz; - /// step length - std::vector m_stepLength; - std::vector* m_stepLengthPtr = &m_stepLength; - /// step material x0 - std::vector m_stepMatX0; - std::vector* m_stepMatX0Ptr = &m_stepMatX0; - /// step material l0 - std::vector m_stepMatL0; - std::vector* m_stepMatL0Ptr = &m_stepMatL0; - /// step material A - std::vector m_stepMatA; - std::vector* m_stepMatAPtr = &m_stepMatA; - /// step material Z - std::vector m_stepMatZ; - std::vector* m_stepMatZPtr = &m_stepMatZ; - /// step material rho - std::vector m_stepMatRho; - std::vector* m_stepMatRhoPtr = &m_stepMatRho; - - /// ID of the surface associated with the step - std::vector m_surfaceId; - std::vector* m_surfaceIdPtr = &m_surfaceId; - /// x position of the center of the surface associated with the step - std::vector m_surfaceX; - std::vector* m_surfaceXPtr = &m_surfaceX; - /// y position of the center of the surface associated with the step - std::vector m_surfaceY; - std::vector* m_surfaceYPtr = &m_surfaceY; - /// z position of the center of the surface associated with the step - std::vector m_surfaceZ; - std::vector* m_surfaceZPtr = &m_surfaceZ; - /// r position of the center of the surface associated with the step - std::vector m_surfaceR; - /// distance to the surface - std::vector m_surfaceDistance; - /// path correction when associating material to the given surface - std::vector m_surfacePathCorrection; - std::vector* m_surfacePathCorrectionPtr = &m_surfacePathCorrection; - - /// ID of the volume associated with the step - std::vector m_volumeId; + /// The material summary payload + MateriaSummaryPayload m_summaryPayload = {}; + + /// The material step payload + MaterialStepPayload m_stepPayload = {}; + + /// The material surface payload + MaterialSurfacePayload m_surfacePayload = {}; + + /// The material volume payload + MaterialVolumePayload m_volumePayload = {}; }; } // namespace Acts diff --git a/Plugins/Root/src/RootMaterialTrackIO.cpp b/Plugins/Root/src/RootMaterialTrackIO.cpp index e85defbfa41..0fc7a20d422 100644 --- a/Plugins/Root/src/RootMaterialTrackIO.cpp +++ b/Plugins/Root/src/RootMaterialTrackIO.cpp @@ -17,35 +17,36 @@ void Acts::RootMaterialTrackIO::connectForRead(TChain& materialChain) { materialChain.SetBranchAddress("event_id", &m_eventId); - materialChain.SetBranchAddress("v_x", &m_vX); - materialChain.SetBranchAddress("v_y", &m_vY); - materialChain.SetBranchAddress("v_z", &m_vZ); - materialChain.SetBranchAddress("v_px", &m_vPx); - materialChain.SetBranchAddress("v_py", &m_vPy); - materialChain.SetBranchAddress("v_pz", &m_vPz); - materialChain.SetBranchAddress("v_phi", &m_vPhi); - materialChain.SetBranchAddress("v_eta", &m_vEta); - materialChain.SetBranchAddress("t_X0", &m_tX0); - materialChain.SetBranchAddress("t_L0", &m_tL0); - materialChain.SetBranchAddress("mat_x", &m_stepXPtr); - materialChain.SetBranchAddress("mat_y", &m_stepYPtr); - materialChain.SetBranchAddress("mat_z", &m_stepZPtr); - materialChain.SetBranchAddress("mat_dx", &m_stepDxPtr); - materialChain.SetBranchAddress("mat_dy", &m_stepDyPtr); - materialChain.SetBranchAddress("mat_dz", &m_stepDzPtr); - materialChain.SetBranchAddress("mat_step_length", &m_stepLengthPtr); - materialChain.SetBranchAddress("mat_X0", &m_stepMatX0Ptr); - materialChain.SetBranchAddress("mat_L0", &m_stepMatL0Ptr); - materialChain.SetBranchAddress("mat_A", &m_stepMatAPtr); - materialChain.SetBranchAddress("mat_Z", &m_stepMatZPtr); - materialChain.SetBranchAddress("mat_rho", &m_stepMatRhoPtr); + materialChain.SetBranchAddress("v_x", &m_summaryPayload.vX); + materialChain.SetBranchAddress("v_y", &m_summaryPayload.vY); + materialChain.SetBranchAddress("v_z", &m_summaryPayload.vZ); + materialChain.SetBranchAddress("v_px", &m_summaryPayload.vPx); + materialChain.SetBranchAddress("v_py", &m_summaryPayload.vPy); + materialChain.SetBranchAddress("v_pz", &m_summaryPayload.vPz); + materialChain.SetBranchAddress("v_phi", &m_summaryPayload.vPhi); + materialChain.SetBranchAddress("v_eta", &m_summaryPayload.vEta); + materialChain.SetBranchAddress("t_X0", &m_summaryPayload.tX0); + materialChain.SetBranchAddress("t_L0", &m_summaryPayload.tL0); + materialChain.SetBranchAddress("mat_x", &m_stepPayload.stepXPtr); + materialChain.SetBranchAddress("mat_y", &m_stepPayload.stepYPtr); + materialChain.SetBranchAddress("mat_z", &m_stepPayload.stepZPtr); + materialChain.SetBranchAddress("mat_dx", &m_stepPayload.stepDxPtr); + materialChain.SetBranchAddress("mat_dy", &m_stepPayload.stepDyPtr); + materialChain.SetBranchAddress("mat_dz", &m_stepPayload.stepDzPtr); + materialChain.SetBranchAddress("mat_step_length", + &m_stepPayload.stepLengthPtr); + materialChain.SetBranchAddress("mat_X0", &m_stepPayload.stepMatX0Ptr); + materialChain.SetBranchAddress("mat_L0", &m_stepPayload.stepMatL0Ptr); + materialChain.SetBranchAddress("mat_A", &m_stepPayload.stepMatAPtr); + materialChain.SetBranchAddress("mat_Z", &m_stepPayload.stepMatZPtr); + materialChain.SetBranchAddress("mat_rho", &m_stepPayload.stepMatRhoPtr); if (m_cfg.surfaceInfo) { - materialChain.SetBranchAddress("sur_id", &m_surfaceIdPtr); - materialChain.SetBranchAddress("sur_x", &m_surfaceXPtr); - materialChain.SetBranchAddress("sur_y", &m_surfaceYPtr); - materialChain.SetBranchAddress("sur_z", &m_surfaceZPtr); + materialChain.SetBranchAddress("sur_id", &m_surfacePayload.surfaceIdPtr); + materialChain.SetBranchAddress("sur_x", &m_surfacePayload.surfaceXPtr); + materialChain.SetBranchAddress("sur_y", &m_surfacePayload.surfaceYPtr); + materialChain.SetBranchAddress("sur_z", &m_surfacePayload.surfaceZPtr); materialChain.SetBranchAddress("sur_pathCorrection", - &m_surfacePathCorrectionPtr); + &m_surfacePayload.surfacePathCorrectionPtr); } } @@ -53,49 +54,50 @@ void Acts::RootMaterialTrackIO::connectForWrite(TTree& materialTree) { // This sets the branch addresses for the material track // Set the branches materialTree.Branch("event_id", &m_eventId); - materialTree.Branch("v_x", &m_vX); - materialTree.Branch("v_y", &m_vY); - materialTree.Branch("v_z", &m_vZ); - materialTree.Branch("v_px", &m_vPx); - materialTree.Branch("v_py", &m_vPy); - materialTree.Branch("v_pz", &m_vPz); - materialTree.Branch("v_phi", &m_vPhi); - materialTree.Branch("v_eta", &m_vEta); - materialTree.Branch("t_X0", &m_tX0); - materialTree.Branch("t_L0", &m_tL0); - materialTree.Branch("mat_x", &m_stepX); - materialTree.Branch("mat_y", &m_stepY); - materialTree.Branch("mat_z", &m_stepZ); - materialTree.Branch("mat_r", &m_stepR); - materialTree.Branch("mat_dx", &m_stepDx); - materialTree.Branch("mat_dy", &m_stepDy); - materialTree.Branch("mat_dz", &m_stepDz); - materialTree.Branch("mat_step_length", &m_stepLength); - materialTree.Branch("mat_X0", &m_stepMatX0); - materialTree.Branch("mat_L0", &m_stepMatL0); - materialTree.Branch("mat_A", &m_stepMatA); - materialTree.Branch("mat_Z", &m_stepMatZ); - materialTree.Branch("mat_rho", &m_stepMatRho); + materialTree.Branch("v_x", &m_summaryPayload.vX); + materialTree.Branch("v_y", &m_summaryPayload.vY); + materialTree.Branch("v_z", &m_summaryPayload.vZ); + materialTree.Branch("v_px", &m_summaryPayload.vPx); + materialTree.Branch("v_py", &m_summaryPayload.vPy); + materialTree.Branch("v_pz", &m_summaryPayload.vPz); + materialTree.Branch("v_phi", &m_summaryPayload.vPhi); + materialTree.Branch("v_eta", &m_summaryPayload.vEta); + materialTree.Branch("t_X0", &m_summaryPayload.tX0); + materialTree.Branch("t_L0", &m_summaryPayload.tL0); + materialTree.Branch("mat_x", &m_stepPayload.stepX); + materialTree.Branch("mat_y", &m_stepPayload.stepY); + materialTree.Branch("mat_z", &m_stepPayload.stepZ); + materialTree.Branch("mat_r", &m_stepPayload.stepR); + materialTree.Branch("mat_dx", &m_stepPayload.stepDx); + materialTree.Branch("mat_dy", &m_stepPayload.stepDy); + materialTree.Branch("mat_dz", &m_stepPayload.stepDz); + materialTree.Branch("mat_step_length", &m_stepPayload.stepLength); + materialTree.Branch("mat_X0", &m_stepPayload.stepMatX0); + materialTree.Branch("mat_L0", &m_stepPayload.stepMatL0); + materialTree.Branch("mat_A", &m_stepPayload.stepMatA); + materialTree.Branch("mat_Z", &m_stepPayload.stepMatZ); + materialTree.Branch("mat_rho", &m_stepPayload.stepMatRho); if (m_cfg.prePostStepInfo) { - materialTree.Branch("mat_sx", &m_stepXs); - materialTree.Branch("mat_sy", &m_stepYs); - materialTree.Branch("mat_sz", &m_stepZs); - materialTree.Branch("mat_ex", &m_stepXe); - materialTree.Branch("mat_ey", &m_stepYe); - materialTree.Branch("mat_ez", &m_stepZe); + materialTree.Branch("mat_sx", &m_stepPayload.stepXs); + materialTree.Branch("mat_sy", &m_stepPayload.stepYs); + materialTree.Branch("mat_sz", &m_stepPayload.stepZs); + materialTree.Branch("mat_ex", &m_stepPayload.stepXe); + materialTree.Branch("mat_ey", &m_stepPayload.stepYe); + materialTree.Branch("mat_ez", &m_stepPayload.stepZe); } if (m_cfg.surfaceInfo) { - materialTree.Branch("sur_id", &m_surfaceId); - materialTree.Branch("sur_x", &m_surfaceX); - materialTree.Branch("sur_y", &m_surfaceY); - materialTree.Branch("sur_z", &m_surfaceZ); - materialTree.Branch("sur_r", &m_surfaceR); - materialTree.Branch("sur_distance", &m_surfaceDistance); - materialTree.Branch("sur_pathCorrection", &m_surfacePathCorrection); + materialTree.Branch("sur_id", &m_surfacePayload.surfaceId); + materialTree.Branch("sur_x", &m_surfacePayload.surfaceX); + materialTree.Branch("sur_y", &m_surfacePayload.surfaceY); + materialTree.Branch("sur_z", &m_surfacePayload.surfaceZ); + materialTree.Branch("sur_r", &m_surfacePayload.surfaceR); + materialTree.Branch("sur_distance", &m_surfacePayload.surfaceDistance); + materialTree.Branch("sur_pathCorrection", + &m_surfacePayload.surfacePathCorrection); } if (m_cfg.volumeInfo) { - materialTree.Branch("vol_id", &m_volumeId); + materialTree.Branch("vol_id", &m_volumePayload.volumeId); } } @@ -104,101 +106,101 @@ void Acts::RootMaterialTrackIO::write( const RecordedMaterialTrack& materialTrack) { m_eventId = eventNum; // Clearing the vector first - m_stepXs.clear(); - m_stepYs.clear(); - m_stepZs.clear(); - m_stepX.clear(); - m_stepY.clear(); - m_stepZ.clear(); - m_stepR.clear(); - m_stepXe.clear(); - m_stepYe.clear(); - m_stepZe.clear(); - m_stepDx.clear(); - m_stepDy.clear(); - m_stepDz.clear(); - m_stepLength.clear(); - m_stepMatX0.clear(); - m_stepMatL0.clear(); - m_stepMatA.clear(); - m_stepMatZ.clear(); - m_stepMatRho.clear(); + m_stepPayload.stepXs.clear(); + m_stepPayload.stepYs.clear(); + m_stepPayload.stepZs.clear(); + m_stepPayload.stepX.clear(); + m_stepPayload.stepY.clear(); + m_stepPayload.stepZ.clear(); + m_stepPayload.stepR.clear(); + m_stepPayload.stepXe.clear(); + m_stepPayload.stepYe.clear(); + m_stepPayload.stepZe.clear(); + m_stepPayload.stepDx.clear(); + m_stepPayload.stepDy.clear(); + m_stepPayload.stepDz.clear(); + m_stepPayload.stepLength.clear(); + m_stepPayload.stepMatX0.clear(); + m_stepPayload.stepMatL0.clear(); + m_stepPayload.stepMatA.clear(); + m_stepPayload.stepMatZ.clear(); + m_stepPayload.stepMatRho.clear(); - m_surfaceId.clear(); - m_surfaceX.clear(); - m_surfaceY.clear(); - m_surfaceZ.clear(); - m_surfaceR.clear(); - m_surfaceDistance.clear(); - m_surfacePathCorrection.clear(); + m_surfacePayload.surfaceId.clear(); + m_surfacePayload.surfaceX.clear(); + m_surfacePayload.surfaceY.clear(); + m_surfacePayload.surfaceZ.clear(); + m_surfacePayload.surfaceR.clear(); + m_surfacePayload.surfaceDistance.clear(); + m_surfacePayload.surfacePathCorrection.clear(); - m_volumeId.clear(); + m_volumePayload.volumeId.clear(); auto materialInteractions = materialTrack.second.materialInteractions; // Reserve the vector then std::size_t mints = materialInteractions.size(); - m_stepXs.reserve(mints); - m_stepYs.reserve(mints); - m_stepZs.reserve(mints); - m_stepX.reserve(mints); - m_stepY.reserve(mints); - m_stepZ.reserve(mints); - m_stepR.reserve(mints); - m_stepXe.reserve(mints); - m_stepYe.reserve(mints); - m_stepZe.reserve(mints); - m_stepDx.reserve(mints); - m_stepDy.reserve(mints); - m_stepDz.reserve(mints); - m_stepLength.reserve(mints); - m_stepMatX0.reserve(mints); - m_stepMatL0.reserve(mints); - m_stepMatA.reserve(mints); - m_stepMatZ.reserve(mints); - m_stepMatRho.reserve(mints); + m_stepPayload.stepXs.reserve(mints); + m_stepPayload.stepYs.reserve(mints); + m_stepPayload.stepZs.reserve(mints); + m_stepPayload.stepX.reserve(mints); + m_stepPayload.stepY.reserve(mints); + m_stepPayload.stepZ.reserve(mints); + m_stepPayload.stepR.reserve(mints); + m_stepPayload.stepXe.reserve(mints); + m_stepPayload.stepYe.reserve(mints); + m_stepPayload.stepZe.reserve(mints); + m_stepPayload.stepDx.reserve(mints); + m_stepPayload.stepDy.reserve(mints); + m_stepPayload.stepDz.reserve(mints); + m_stepPayload.stepLength.reserve(mints); + m_stepPayload.stepMatX0.reserve(mints); + m_stepPayload.stepMatL0.reserve(mints); + m_stepPayload.stepMatA.reserve(mints); + m_stepPayload.stepMatZ.reserve(mints); + m_stepPayload.stepMatRho.reserve(mints); - m_surfaceId.reserve(mints); - m_surfaceX.reserve(mints); - m_surfaceY.reserve(mints); - m_surfaceZ.reserve(mints); - m_surfaceR.reserve(mints); - m_surfaceDistance.reserve(mints); - m_surfacePathCorrection.reserve(mints); + m_surfacePayload.surfaceId.reserve(mints); + m_surfacePayload.surfaceX.reserve(mints); + m_surfacePayload.surfaceY.reserve(mints); + m_surfacePayload.surfaceZ.reserve(mints); + m_surfacePayload.surfaceR.reserve(mints); + m_surfacePayload.surfaceDistance.reserve(mints); + m_surfacePayload.surfacePathCorrection.reserve(mints); - m_volumeId.reserve(mints); + m_volumePayload.volumeId.reserve(mints); // reset the global counter if (m_cfg.recalculateTotals) { - m_tX0 = 0.; - m_tL0 = 0.; + m_summaryPayload.tX0 = 0.; + m_summaryPayload.tL0 = 0.; } else { - m_tX0 = materialTrack.second.materialInX0; - m_tL0 = materialTrack.second.materialInL0; + m_summaryPayload.tX0 = materialTrack.second.materialInX0; + m_summaryPayload.tL0 = materialTrack.second.materialInL0; } // set the track information at vertex - m_vX = materialTrack.first.first.x(); - m_vY = materialTrack.first.first.y(); - m_vZ = materialTrack.first.first.z(); - m_vPx = materialTrack.first.second.x(); - m_vPy = materialTrack.first.second.y(); - m_vPz = materialTrack.first.second.z(); - m_vPhi = VectorHelpers::phi(materialTrack.first.second); - m_vEta = VectorHelpers::eta(materialTrack.first.second); + m_summaryPayload.vX = materialTrack.first.first.x(); + m_summaryPayload.vY = materialTrack.first.first.y(); + m_summaryPayload.vZ = materialTrack.first.first.z(); + m_summaryPayload.vPx = materialTrack.first.second.x(); + m_summaryPayload.vPy = materialTrack.first.second.y(); + m_summaryPayload.vPz = materialTrack.first.second.z(); + m_summaryPayload.vPhi = VectorHelpers::phi(materialTrack.first.second); + m_summaryPayload.vEta = VectorHelpers::eta(materialTrack.first.second); // and now loop over the material for (const auto& mint : materialInteractions) { auto direction = mint.direction.normalized(); // The material step position information - m_stepX.push_back(mint.position.x()); - m_stepY.push_back(mint.position.y()); - m_stepZ.push_back(mint.position.z()); - m_stepR.push_back(VectorHelpers::perp(mint.position)); - m_stepDx.push_back(direction.x()); - m_stepDy.push_back(direction.y()); - m_stepDz.push_back(direction.z()); + m_stepPayload.stepX.push_back(mint.position.x()); + m_stepPayload.stepY.push_back(mint.position.y()); + m_stepPayload.stepZ.push_back(mint.position.z()); + m_stepPayload.stepR.push_back(VectorHelpers::perp(mint.position)); + m_stepPayload.stepDx.push_back(direction.x()); + m_stepPayload.stepDy.push_back(direction.y()); + m_stepPayload.stepDz.push_back(direction.z()); if (m_cfg.prePostStepInfo) { Acts::Vector3 prePos = @@ -206,42 +208,45 @@ void Acts::RootMaterialTrackIO::write( Acts::Vector3 posPos = mint.position + 0.5 * mint.pathCorrection * direction; - m_stepXs.push_back(prePos.x()); - m_stepYs.push_back(prePos.y()); - m_stepZs.push_back(prePos.z()); - m_stepXe.push_back(posPos.x()); - m_stepYe.push_back(posPos.y()); - m_stepZe.push_back(posPos.z()); + m_stepPayload.stepXs.push_back(prePos.x()); + m_stepPayload.stepYs.push_back(prePos.y()); + m_stepPayload.stepZs.push_back(prePos.z()); + m_stepPayload.stepXe.push_back(posPos.x()); + m_stepPayload.stepYe.push_back(posPos.y()); + m_stepPayload.stepZe.push_back(posPos.z()); } // Store surface information if (m_cfg.surfaceInfo) { const Acts::Surface* surface = mint.surface; if (mint.intersectionID.value() != 0) { - m_surfaceId.push_back(mint.intersectionID.value()); - m_surfacePathCorrection.push_back(mint.pathCorrection); - m_surfaceX.push_back(mint.intersection.x()); - m_surfaceY.push_back(mint.intersection.y()); - m_surfaceZ.push_back(mint.intersection.z()); - m_surfaceR.push_back(VectorHelpers::perp(mint.intersection)); - m_surfaceDistance.push_back((mint.position - mint.intersection).norm()); + m_surfacePayload.surfaceId.push_back(mint.intersectionID.value()); + m_surfacePayload.surfacePathCorrection.push_back(mint.pathCorrection); + m_surfacePayload.surfaceX.push_back(mint.intersection.x()); + m_surfacePayload.surfaceY.push_back(mint.intersection.y()); + m_surfacePayload.surfaceZ.push_back(mint.intersection.z()); + m_surfacePayload.surfaceR.push_back( + VectorHelpers::perp(mint.intersection)); + m_surfacePayload.surfaceDistance.push_back( + (mint.position - mint.intersection).norm()); } else if (surface != nullptr) { auto sfIntersection = surface ->intersect(gctx, mint.position, mint.direction, Acts::BoundaryTolerance::None()) .closest(); - m_surfaceId.push_back(surface->geometryId().value()); - m_surfacePathCorrection.push_back(1.0); - m_surfaceX.push_back(sfIntersection.position().x()); - m_surfaceY.push_back(sfIntersection.position().y()); - m_surfaceZ.push_back(sfIntersection.position().z()); + m_surfacePayload.surfaceId.push_back(surface->geometryId().value()); + m_surfacePayload.surfacePathCorrection.push_back(1.0); + m_surfacePayload.surfaceX.push_back(sfIntersection.position().x()); + m_surfacePayload.surfaceY.push_back(sfIntersection.position().y()); + m_surfacePayload.surfaceZ.push_back(sfIntersection.position().z()); } else { - m_surfaceId.push_back(Acts::GeometryIdentifier().value()); - m_surfaceX.push_back(0); - m_surfaceY.push_back(0); - m_surfaceZ.push_back(0); - m_surfacePathCorrection.push_back(1.0); + m_surfacePayload.surfaceId.push_back( + Acts::GeometryIdentifier().value()); + m_surfacePayload.surfaceX.push_back(0); + m_surfacePayload.surfaceY.push_back(0); + m_surfacePayload.surfaceZ.push_back(0); + m_surfacePayload.surfacePathCorrection.push_back(1.0); } } @@ -250,29 +255,29 @@ void Acts::RootMaterialTrackIO::write( Acts::GeometryIdentifier vlayerID; if (!mint.volume.empty()) { vlayerID = mint.volume.geometryId(); - m_volumeId.push_back(vlayerID.value()); + m_volumePayload.volumeId.push_back(vlayerID.value()); } else { vlayerID = vlayerID.withVolume(0) .withBoundary(0) .withLayer(0) .withApproach(0) .withSensitive(0); - m_volumeId.push_back(vlayerID.value()); + m_volumePayload.volumeId.push_back(vlayerID.value()); } } // the material information const auto& mprops = mint.materialSlab; - m_stepLength.push_back(mprops.thickness()); - m_stepMatX0.push_back(mprops.material().X0()); - m_stepMatL0.push_back(mprops.material().L0()); - m_stepMatA.push_back(mprops.material().Ar()); - m_stepMatZ.push_back(mprops.material().Z()); - m_stepMatRho.push_back(mprops.material().massDensity()); + m_stepPayload.stepLength.push_back(mprops.thickness()); + m_stepPayload.stepMatX0.push_back(mprops.material().X0()); + m_stepPayload.stepMatL0.push_back(mprops.material().L0()); + m_stepPayload.stepMatA.push_back(mprops.material().Ar()); + m_stepPayload.stepMatZ.push_back(mprops.material().Z()); + m_stepPayload.stepMatRho.push_back(mprops.material().massDensity()); // re-calculate if defined to do so if (m_cfg.recalculateTotals) { - m_tX0 += mprops.thicknessInX0(); - m_tL0 += mprops.thicknessInL0(); + m_summaryPayload.tX0 += mprops.thicknessInX0(); + m_summaryPayload.tL0 += mprops.thicknessInL0(); } } } @@ -280,43 +285,50 @@ void Acts::RootMaterialTrackIO::write( Acts::RecordedMaterialTrack Acts::RootMaterialTrackIO::read() const { Acts::RecordedMaterialTrack rmTrack; // Fill the position and momentum - rmTrack.first.first = Acts::Vector3(m_vX, m_vY, m_vZ); - rmTrack.first.second = Acts::Vector3(m_vPx, m_vPy, m_vPz); + rmTrack.first.first = Acts::Vector3(m_summaryPayload.vX, m_summaryPayload.vY, + m_summaryPayload.vZ); + rmTrack.first.second = Acts::Vector3( + m_summaryPayload.vPx, m_summaryPayload.vPy, m_summaryPayload.vPz); // Fill the individual steps - std::size_t msteps = m_stepLength.size(); + std::size_t msteps = m_stepPayload.stepLength.size(); rmTrack.second.materialInteractions.reserve(msteps); rmTrack.second.materialInX0 = 0.; rmTrack.second.materialInL0 = 0.; for (std::size_t is = 0; is < msteps; ++is) { - float s = m_stepLength[is]; + float s = m_stepPayload.stepLength[is]; if (s == 0.) { continue; } - float mX0 = m_stepMatX0[is]; - float mL0 = m_stepMatL0[is]; + float mX0 = m_stepPayload.stepMatX0[is]; + float mL0 = m_stepPayload.stepMatL0[is]; rmTrack.second.materialInX0 += s / mX0; rmTrack.second.materialInL0 += s / mL0; /// Fill the position & the material Acts::MaterialInteraction mInteraction; mInteraction.position = - Acts::Vector3(m_stepX[is], m_stepY[is], m_stepZ[is]); + Acts::Vector3(m_stepPayload.stepX[is], m_stepPayload.stepY[is], + m_stepPayload.stepZ[is]); mInteraction.direction = - Acts::Vector3(m_stepDx[is], m_stepDy[is], m_stepDz[is]); + Acts::Vector3(m_stepPayload.stepDx[is], m_stepPayload.stepDy[is], + m_stepPayload.stepDz[is]); mInteraction.materialSlab = Acts::MaterialSlab( - Acts::Material::fromMassDensity(mX0, mL0, m_stepMatA[is], - m_stepMatZ[is], m_stepMatRho[is]), + Acts::Material::fromMassDensity(mX0, mL0, m_stepPayload.stepMatA[is], + m_stepPayload.stepMatZ[is], + m_stepPayload.stepMatRho[is]), s); if (m_cfg.surfaceInfo) { // add the surface information to the interaction this allows the // mapping to be speed up - mInteraction.intersectionID = Acts::GeometryIdentifier(m_surfaceId[is]); - mInteraction.intersection = - Acts::Vector3(m_surfaceX[is], m_surfaceY[is], m_surfaceZ[is]); - mInteraction.pathCorrection = m_surfacePathCorrection[is]; + mInteraction.intersectionID = + Acts::GeometryIdentifier(m_surfacePayload.surfaceId[is]); + mInteraction.intersection = Acts::Vector3(m_surfacePayload.surfaceX[is], + m_surfacePayload.surfaceY[is], + m_surfacePayload.surfaceZ[is]); + mInteraction.pathCorrection = m_surfacePayload.surfacePathCorrection[is]; } else { mInteraction.intersectionID = Acts::GeometryIdentifier(); mInteraction.intersection = Acts::Vector3(0, 0, 0); From a59cb30eaef1ccf2c6de23817c1319dd1ebe22fb Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Thu, 10 Jul 2025 15:12:32 +0200 Subject: [PATCH 24/30] last fixable SonarCloud issue --- Plugins/Root/src/RootMaterialMapIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Root/src/RootMaterialMapIO.cpp b/Plugins/Root/src/RootMaterialMapIO.cpp index 2b7fb4f0f87..4107fe1a8c3 100644 --- a/Plugins/Root/src/RootMaterialMapIO.cpp +++ b/Plugins/Root/src/RootMaterialMapIO.cpp @@ -424,7 +424,7 @@ Acts::RootMaterialMapIO::readTextureSurfaceMaterial( // Fill the matrix from the histogram content for (int ib0 = 1; ib0 <= nbins0; ++ib0) { for (int ib1 = 1; ib1 <= nbins1; ++ib1) { - double dt = t->GetBinContent(ib0, ib1); + auto dt = static_cast(t->GetBinContent(ib0, ib1)); if (dt > 0.) { auto dx0 = static_cast(x0->GetBinContent(ib0, ib1)); auto dl0 = static_cast(l0->GetBinContent(ib0, ib1)); From 7ed2a46fbceb1115693a2c97dbddb21d405966bc Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Fri, 11 Jul 2025 15:35:15 +0200 Subject: [PATCH 25/30] renaming --- .../Io/Root/RootMaterialDecorator.hpp | 6 +-- .../Io/Root/RootMaterialTrackReader.hpp | 4 +- .../Io/Root/RootMaterialTrackWriter.hpp | 4 +- .../Io/Root/RootMaterialWriter.hpp | 6 +-- .../Io/Root/src/RootMaterialDecorator.cpp | 4 +- Examples/Io/Root/src/RootMaterialWriter.cpp | 4 +- Examples/Python/src/RootOutput.cpp | 6 +-- Plugins/Root/CMakeLists.txt | 4 +- .../Acts/Plugins/Root/RootMaterialMapIO.hpp | 8 ++-- .../Acts/Plugins/Root/RootMaterialTrackIO.hpp | 6 +-- Plugins/Root/src/RootMaterialMapIO.cpp | 20 +++++----- Plugins/Root/src/RootMaterialTrackIO.cpp | 10 ++--- Tests/UnitTests/Plugins/Root/CMakeLists.txt | 2 +- .../Plugins/Root/RootMaterialMapIOTests.cpp | 38 +++++++++---------- 14 files changed, 61 insertions(+), 61 deletions(-) diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp index 8adab4a3e8c..03f3cff55ae 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialDecorator.hpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include @@ -40,9 +40,9 @@ class RootMaterialDecorator : public Acts::IMaterialDecorator { class Config { public: /// Accessor config - Acts::RootMaterialMapIO::Config accessorConfig; + Acts::RootMaterialMapIo::Config accessorConfig; /// Accessor options - Acts::RootMaterialMapIO::Options accessorOptions; + Acts::RootMaterialMapIo::Options accessorOptions; /// The name of the output file std::string fileName = "material-maps.root"; }; diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackReader.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackReader.hpp index abcbe969d64..d333e10da2c 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackReader.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackReader.hpp @@ -9,7 +9,7 @@ #pragma once #include "Acts/Material/MaterialInteraction.hpp" -#include "Acts/Plugins/Root/RootMaterialTrackIO.hpp" +#include "Acts/Plugins/Root/RootMaterialTrackIo.hpp" #include "Acts/Utilities/Logger.hpp" #include "ActsExamples/Framework/DataHandle.hpp" #include "ActsExamples/Framework/IReader.hpp" @@ -99,7 +99,7 @@ class RootMaterialTrackReader : public IReader { /// multiple entries corresponding to one event number) std::vector m_entryNumbers = {}; - Acts::RootMaterialTrackIO m_accessor; + Acts::RootMaterialTrackIo m_accessor; }; } // namespace ActsExamples diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackWriter.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackWriter.hpp index 2ada974d68f..3cd68874010 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackWriter.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackWriter.hpp @@ -10,7 +10,7 @@ #include "ActsExamples/Framework/ProcessCode.hpp" #include "ActsExamples/Framework/WriterT.hpp" -#include +#include #include #include @@ -108,7 +108,7 @@ class RootMaterialTrackWriter /// The output tree name TTree* m_outputTree = nullptr; /// The read - write payload - Acts::RootMaterialTrackIO m_accessor; + Acts::RootMaterialTrackIo m_accessor; }; } // namespace ActsExamples diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp index cfc1220d344..096125382bd 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialWriter.hpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include @@ -66,10 +66,10 @@ class RootMaterialWriter : public IMaterialWriter { bool processVolumes = true; /// The accessor configuration - Acts::RootMaterialMapIO::Config accessorConfig; + Acts::RootMaterialMapIo::Config accessorConfig; /// The accessor options - Acts::RootMaterialMapIO::Options accessorOptions; + Acts::RootMaterialMapIo::Options accessorOptions; /// The name of the output file std::string filePath = "material-maps.root"; diff --git a/Examples/Io/Root/src/RootMaterialDecorator.cpp b/Examples/Io/Root/src/RootMaterialDecorator.cpp index f2d3ee7c364..9f981d58637 100644 --- a/Examples/Io/Root/src/RootMaterialDecorator.cpp +++ b/Examples/Io/Root/src/RootMaterialDecorator.cpp @@ -68,8 +68,8 @@ ActsExamples::RootMaterialDecorator::RootMaterialDecorator( throw std::ios_base::failure("Could not open '" + m_cfg.fileName + "'"); } - Acts::RootMaterialMapIO accessor(m_cfg.accessorConfig, - m_logger->clone("RootMaterialMapIO")); + Acts::RootMaterialMapIo accessor(m_cfg.accessorConfig, + m_logger->clone("RootMaterialMapIo")); auto [surfaceMaps, volumeMaps] = accessor.read(*m_inputFile, m_cfg.accessorOptions); diff --git a/Examples/Io/Root/src/RootMaterialWriter.cpp b/Examples/Io/Root/src/RootMaterialWriter.cpp index 417bba1b1a4..6aadc8e8067 100644 --- a/Examples/Io/Root/src/RootMaterialWriter.cpp +++ b/Examples/Io/Root/src/RootMaterialWriter.cpp @@ -70,8 +70,8 @@ void ActsExamples::RootMaterialWriter::writeMaterial( const auto& [surfaceMaps, volumeMaps] = detMaterial; // Write the surface material maps - Acts::RootMaterialMapIO accessor(m_cfg.accessorConfig, - m_logger->clone("RootMaterialMapIO")); + Acts::RootMaterialMapIo accessor(m_cfg.accessorConfig, + m_logger->clone("RootMaterialMapIo")); for (const auto& [geoId, sMap] : surfaceMaps) { // Get the Surface material diff --git a/Examples/Python/src/RootOutput.cpp b/Examples/Python/src/RootOutput.cpp index c7354227b70..56d4f7c0569 100644 --- a/Examples/Python/src/RootOutput.cpp +++ b/Examples/Python/src/RootOutput.cpp @@ -7,7 +7,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. #include "Acts/Plugins/Python/Utilities.hpp" -#include "Acts/Plugins/Root/RootMaterialMapIO.hpp" +#include "Acts/Plugins/Root/RootMaterialMapIo.hpp" #include "ActsExamples/Io/Root/RootBFieldWriter.hpp" #include "ActsExamples/Io/Root/RootMaterialTrackWriter.hpp" #include "ActsExamples/Io/Root/RootMaterialWriter.hpp" @@ -157,7 +157,7 @@ void addRootOutput(Context& ctx) { .def("write", py::overload_cast( &Writer::write)); - auto ac = py::class_(w, "AccessorConfig") + auto ac = py::class_(w, "AccessorConfig") .def(py::init<>()); ACTS_PYTHON_STRUCT(ac, volumePrefix, portalPrefix, layerPrefix, @@ -167,7 +167,7 @@ void addRootOutput(Context& ctx) { x0HistName, l0HistName, aHistName, zHistName, rhoHistName); - auto ao = py::class_(w, "AccessorOptions") + auto ao = py::class_(w, "AccessorOptions") .def(py::init<>()); ACTS_PYTHON_STRUCT(ao, homogeneousMaterialTreeName, indexedMaterialTreeName, diff --git a/Plugins/Root/CMakeLists.txt b/Plugins/Root/CMakeLists.txt index 6ba8a43a1b1..b602b08ee7d 100644 --- a/Plugins/Root/CMakeLists.txt +++ b/Plugins/Root/CMakeLists.txt @@ -1,6 +1,6 @@ set(library_sources - src/RootMaterialMapIO.cpp - src/RootMaterialTrackIO.cpp + src/RootMaterialMapIo.cpp + src/RootMaterialTrackIo.cpp src/TGeoCylinderDiscSplitter.cpp src/TGeoDetectorElement.cpp src/TGeoLayerBuilder.cpp diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIO.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIO.hpp index 64cafa2f6c2..71f87e6f0e9 100644 --- a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIO.hpp +++ b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIO.hpp @@ -31,7 +31,7 @@ class BinnedSurfaceMaterial; /// Simple payload class that can be wrapped for reading /// and writing. -class RootMaterialMapIO { +class RootMaterialMapIo { public: /// @brief Configuration for the accessor /// Contains the tags used for writing and reading, tag names are @@ -110,14 +110,14 @@ class RootMaterialMapIO { /// @brief Constructor from config struct /// @param cfg the configuration for the accessor /// @param mLogger the logger to use, default is INFO level - explicit RootMaterialMapIO(const Config& cfg, + explicit RootMaterialMapIo(const Config& cfg, std::unique_ptr mLogger = - getDefaultLogger("RootMaterialMapIO", + getDefaultLogger("RootMaterialMapIo", Logging::INFO)) : m_cfg(cfg), m_logger(std::move(mLogger)) {} /// @brief Destructor - ~RootMaterialMapIO() = default; + ~RootMaterialMapIo() = default; /// Write the detector maps /// @param rFile the file to write to diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIO.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIO.hpp index beb5f210707..03ca3b73966 100644 --- a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIO.hpp +++ b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIO.hpp @@ -26,7 +26,7 @@ class TrackingVolume; /// Simple payload class that can be wrapped for reading /// and writing. -class RootMaterialTrackIO { +class RootMaterialTrackIo { public: struct Config { /// Whether to store pre- and post-step information @@ -42,10 +42,10 @@ class RootMaterialTrackIO { /// @brief Constructor from config struct /// /// @param cfg the configuration for the accessor - explicit RootMaterialTrackIO(const Config& cfg) : m_cfg(cfg) {} + explicit RootMaterialTrackIo(const Config& cfg) : m_cfg(cfg) {} /// @brief Destructor - ~RootMaterialTrackIO() = default; + ~RootMaterialTrackIo() = default; /// @brief sets the branch connection for reading from a file /// diff --git a/Plugins/Root/src/RootMaterialMapIO.cpp b/Plugins/Root/src/RootMaterialMapIO.cpp index 4107fe1a8c3..9ff519a93b2 100644 --- a/Plugins/Root/src/RootMaterialMapIO.cpp +++ b/Plugins/Root/src/RootMaterialMapIO.cpp @@ -6,7 +6,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -#include "Acts/Plugins/Root/RootMaterialMapIO.hpp" +#include "Acts/Plugins/Root/RootMaterialMapIo.hpp" #include "Acts/Geometry/GeometryIdentifier.hpp" #include "Acts/Material/BinnedSurfaceMaterial.hpp" @@ -28,7 +28,7 @@ #include #include -void Acts::RootMaterialMapIO::write(TFile& rFile, +void Acts::RootMaterialMapIo::write(TFile& rFile, const GeometryIdentifier& geoID, const ISurfaceMaterial& surfaceMaterial, const Options& options) { @@ -136,7 +136,7 @@ void Acts::RootMaterialMapIO::write(TFile& rFile, } } -void Acts::RootMaterialMapIO::write( +void Acts::RootMaterialMapIo::write( TFile& rFile, const TrackingGeometryMaterial& detectorMaterial, const Options& options) { const auto& [surfaceMaterials, volumeMaterials] = detectorMaterial; @@ -151,7 +151,7 @@ void Acts::RootMaterialMapIO::write( } } -void Acts::RootMaterialMapIO::connectForWrite( +void Acts::RootMaterialMapIo::connectForWrite( TTree& rTree, MaterialTreePayload& treePayload) { if (&treePayload == &m_homogenousMaterialTreePayload) { rTree.Branch("hGeoId", &treePayload.hGeoId); @@ -164,7 +164,7 @@ void Acts::RootMaterialMapIO::connectForWrite( rTree.Branch(m_cfg.rhoHistName.c_str(), &treePayload.hRho); } -void Acts::RootMaterialMapIO::connectForRead(TTree& rTree, +void Acts::RootMaterialMapIo::connectForRead(TTree& rTree, MaterialTreePayload& treePayload) { if (&treePayload == &m_homogenousMaterialTreePayload) { rTree.SetBranchAddress("hGeoId", &treePayload.hGeoId); @@ -177,7 +177,7 @@ void Acts::RootMaterialMapIO::connectForRead(TTree& rTree, rTree.SetBranchAddress(m_cfg.rhoHistName.c_str(), &treePayload.hRho); } -void Acts::RootMaterialMapIO::fillMaterialSlab( +void Acts::RootMaterialMapIo::fillMaterialSlab( MaterialTreePayload& payload, const MaterialSlab& materialSlab) { payload.ht = materialSlab.thickness(); payload.hX0 = materialSlab.material().X0(); @@ -187,7 +187,7 @@ void Acts::RootMaterialMapIO::fillMaterialSlab( payload.hRho = materialSlab.material().massDensity(); } -void Acts::RootMaterialMapIO::fillBinnedSurfaceMaterial( +void Acts::RootMaterialMapIo::fillBinnedSurfaceMaterial( const BinnedSurfaceMaterial& bsMaterial) { auto bins0 = static_cast(bsMaterial.binUtility().bins(0)); auto bins1 = static_cast(bsMaterial.binUtility().bins(1)); @@ -233,7 +233,7 @@ void Acts::RootMaterialMapIO::fillBinnedSurfaceMaterial( rho.Write(); } -void Acts::RootMaterialMapIO::fillBinnedSurfaceMaterial( +void Acts::RootMaterialMapIo::fillBinnedSurfaceMaterial( MaterialTreePayload& payload, const BinnedSurfaceMaterial& bsMaterial) { std::size_t bins0 = bsMaterial.binUtility().bins(0); std::size_t bins1 = bsMaterial.binUtility().bins(1); @@ -255,7 +255,7 @@ void Acts::RootMaterialMapIO::fillBinnedSurfaceMaterial( idx.Write(); } -Acts::TrackingGeometryMaterial Acts::RootMaterialMapIO::read( +Acts::TrackingGeometryMaterial Acts::RootMaterialMapIo::read( TFile& rFile, const Options& options) { TrackingGeometryMaterial detectorMaterial; @@ -352,7 +352,7 @@ Acts::TrackingGeometryMaterial Acts::RootMaterialMapIO::read( } std::shared_ptr -Acts::RootMaterialMapIO::readTextureSurfaceMaterial( +Acts::RootMaterialMapIo::readTextureSurfaceMaterial( TFile& rFile, const std::string& tdName, TTree* indexedMaterialTree) { std::shared_ptr texturedSurfaceMaterial = nullptr; diff --git a/Plugins/Root/src/RootMaterialTrackIO.cpp b/Plugins/Root/src/RootMaterialTrackIO.cpp index 0fc7a20d422..3a7f70b5a89 100644 --- a/Plugins/Root/src/RootMaterialTrackIO.cpp +++ b/Plugins/Root/src/RootMaterialTrackIO.cpp @@ -6,7 +6,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -#include "Acts/Plugins/Root/RootMaterialTrackIO.hpp" +#include "Acts/Plugins/Root/RootMaterialTrackIo.hpp" #include "Acts/Surfaces/BoundaryTolerance.hpp" #include "Acts/Surfaces/Surface.hpp" @@ -15,7 +15,7 @@ #include #include -void Acts::RootMaterialTrackIO::connectForRead(TChain& materialChain) { +void Acts::RootMaterialTrackIo::connectForRead(TChain& materialChain) { materialChain.SetBranchAddress("event_id", &m_eventId); materialChain.SetBranchAddress("v_x", &m_summaryPayload.vX); materialChain.SetBranchAddress("v_y", &m_summaryPayload.vY); @@ -50,7 +50,7 @@ void Acts::RootMaterialTrackIO::connectForRead(TChain& materialChain) { } } -void Acts::RootMaterialTrackIO::connectForWrite(TTree& materialTree) { +void Acts::RootMaterialTrackIo::connectForWrite(TTree& materialTree) { // This sets the branch addresses for the material track // Set the branches materialTree.Branch("event_id", &m_eventId); @@ -101,7 +101,7 @@ void Acts::RootMaterialTrackIO::connectForWrite(TTree& materialTree) { } } -void Acts::RootMaterialTrackIO::write( +void Acts::RootMaterialTrackIo::write( const GeometryContext& gctx, std::uint32_t eventNum, const RecordedMaterialTrack& materialTrack) { m_eventId = eventNum; @@ -282,7 +282,7 @@ void Acts::RootMaterialTrackIO::write( } } -Acts::RecordedMaterialTrack Acts::RootMaterialTrackIO::read() const { +Acts::RecordedMaterialTrack Acts::RootMaterialTrackIo::read() const { Acts::RecordedMaterialTrack rmTrack; // Fill the position and momentum rmTrack.first.first = Acts::Vector3(m_summaryPayload.vX, m_summaryPayload.vY, diff --git a/Tests/UnitTests/Plugins/Root/CMakeLists.txt b/Tests/UnitTests/Plugins/Root/CMakeLists.txt index 77a4f04ad29..176b0ea33ad 100644 --- a/Tests/UnitTests/Plugins/Root/CMakeLists.txt +++ b/Tests/UnitTests/Plugins/Root/CMakeLists.txt @@ -1,6 +1,6 @@ set(unittest_extra_libraries ActsPluginRoot) -add_unittest(RootMaterialMapIO RootMaterialMapIOTests.cpp) +add_unittest(RootMaterialMapIo RootMaterialMapIoTests.cpp) add_unittest(TGeoArb8Conversion TGeoArb8ConversionTests.cpp) add_unittest(TGeoBBoxConversion TGeoBBoxConversionTests.cpp) add_unittest(TGeoTrd1Conversion TGeoTrd1ConversionTests.cpp) diff --git a/Tests/UnitTests/Plugins/Root/RootMaterialMapIOTests.cpp b/Tests/UnitTests/Plugins/Root/RootMaterialMapIOTests.cpp index 16a5d63d6c3..9b2806fd8b4 100644 --- a/Tests/UnitTests/Plugins/Root/RootMaterialMapIOTests.cpp +++ b/Tests/UnitTests/Plugins/Root/RootMaterialMapIOTests.cpp @@ -13,7 +13,7 @@ #include "Acts/Material/HomogeneousSurfaceMaterial.hpp" #include "Acts/Material/Material.hpp" #include "Acts/Material/MaterialSlab.hpp" -#include "Acts/Plugins/Root/RootMaterialMapIO.hpp" +#include "Acts/Plugins/Root/RootMaterialMapIo.hpp" #include "Acts/Surfaces/PlaneSurface.hpp" #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp" #include "Acts/Utilities/BinUtility.hpp" @@ -78,20 +78,20 @@ std::vector createBinnedSurfaceMaterial() { return binnedMaterials; } -BOOST_AUTO_TEST_SUITE(RootMaterialMapIOTests) +BOOST_AUTO_TEST_SUITE(RootMaterialMapIoTests) -BOOST_AUTO_TEST_CASE(RootMaterialMapIOHomogeneousReadWrite) { +BOOST_AUTO_TEST_CASE(RootMaterialMapIoHomogeneousReadWrite) { auto surfaceMaterials = createHomogeneousSurfaceMaterial(); auto rFile = - TFile::Open("RootMaterialMapIOHomogeneousTests.root", "RECREATE"); + TFile::Open("RootMaterialMapIoHomogeneousTests.root", "RECREATE"); rFile->cd(); BOOST_REQUIRE(rFile != nullptr); // Create the accessor - RootMaterialMapIO::Config cfg; - RootMaterialMapIO accessor(cfg); - RootMaterialMapIO::Options options; + RootMaterialMapIo::Config cfg; + RootMaterialMapIo accessor(cfg); + RootMaterialMapIo::Options options; for (const auto& [geoID, sMaterial] : surfaceMaterials) { accessor.write(*rFile, geoID, *sMaterial, options); @@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapIOHomogeneousReadWrite) { rFile->Close(); // Let's read it back - auto iFile = TFile::Open("RootMaterialMapIOHomogeneousTests.root", "READ"); + auto iFile = TFile::Open("RootMaterialMapIoHomogeneousTests.root", "READ"); BOOST_REQUIRE(iFile != nullptr); auto [surfaceMapsRead, volumeMapsRead] = accessor.read(*iFile, options); @@ -127,17 +127,17 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapIOHomogeneousReadWrite) { } } -BOOST_AUTO_TEST_CASE(RootMaterialMapIOBinnedReadWrite) { +BOOST_AUTO_TEST_CASE(RootMaterialMapIoBinnedReadWrite) { auto surfaceMaterials = createBinnedSurfaceMaterial(); - auto rFile = TFile::Open("RootMaterialMapIOBinnedTests.root", "RECREATE"); + auto rFile = TFile::Open("RootMaterialMapIoBinnedTests.root", "RECREATE"); rFile->cd(); BOOST_REQUIRE(rFile != nullptr); // Create the accessor - RootMaterialMapIO::Config cfg; - RootMaterialMapIO accessor(cfg); - RootMaterialMapIO::Options options; + RootMaterialMapIo::Config cfg; + RootMaterialMapIo accessor(cfg); + RootMaterialMapIo::Options options; for (const auto& [geoID, sMaterial] : surfaceMaterials) { accessor.write(*rFile, geoID, *sMaterial, options); @@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapIOBinnedReadWrite) { rFile->Close(); // Let's read it back - auto iFile = TFile::Open("RootMaterialMapIOBinnedTests.root", "READ"); + auto iFile = TFile::Open("RootMaterialMapIoBinnedTests.root", "READ"); BOOST_REQUIRE(iFile != nullptr); auto [surfaceMapsRead, volumeMapsRead] = accessor.read(*iFile, options); BOOST_REQUIRE_EQUAL(surfaceMapsRead.size(), surfaceMaterials.size()); @@ -196,13 +196,13 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapIOBinnedReadWrite) { } // Create the accessor - writing with indexed material - RootMaterialMapIO::Config cfgIndexed; - RootMaterialMapIO accessorIndexed(cfgIndexed); + RootMaterialMapIo::Config cfgIndexed; + RootMaterialMapIo accessorIndexed(cfgIndexed); - RootMaterialMapIO::Options optionsIndexed; + RootMaterialMapIo::Options optionsIndexed; optionsIndexed.indexedMaterial = true; - rFile = TFile::Open("RootMaterialMapIOBinnedIndexedTests.root", "RECREATE"); + rFile = TFile::Open("RootMaterialMapIoBinnedIndexedTests.root", "RECREATE"); rFile->cd(); BOOST_REQUIRE(rFile != nullptr); @@ -214,7 +214,7 @@ BOOST_AUTO_TEST_CASE(RootMaterialMapIOBinnedReadWrite) { rFile->Close(); // Let's read it back - iFile = TFile::Open("RootMaterialMapIOBinnedIndexedTests.root", "READ"); + iFile = TFile::Open("RootMaterialMapIoBinnedIndexedTests.root", "READ"); BOOST_REQUIRE(iFile != nullptr); auto [surfaceMapsIndexedRead, volumeMapsIndexedRead] = accessorIndexed.read(*iFile, optionsIndexed); From ab4b34eae3467289cfcf534789a2d71ae1736f2b Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Sat, 12 Jul 2025 06:48:50 +0200 Subject: [PATCH 26/30] break --- .../Plugins/Root/RootMaterialMapIoTests2.cpp | 262 ++++++++++++++++++ 1 file changed, 262 insertions(+) create mode 100644 Tests/UnitTests/Plugins/Root/RootMaterialMapIoTests2.cpp diff --git a/Tests/UnitTests/Plugins/Root/RootMaterialMapIoTests2.cpp b/Tests/UnitTests/Plugins/Root/RootMaterialMapIoTests2.cpp new file mode 100644 index 00000000000..9b2806fd8b4 --- /dev/null +++ b/Tests/UnitTests/Plugins/Root/RootMaterialMapIoTests2.cpp @@ -0,0 +1,262 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 CERN for the benefit of the ACTS project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#include + +#include "Acts/Definitions/Algebra.hpp" +#include "Acts/Material/BinnedSurfaceMaterial.hpp" +#include "Acts/Material/HomogeneousSurfaceMaterial.hpp" +#include "Acts/Material/Material.hpp" +#include "Acts/Material/MaterialSlab.hpp" +#include "Acts/Plugins/Root/RootMaterialMapIo.hpp" +#include "Acts/Surfaces/PlaneSurface.hpp" +#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp" +#include "Acts/Utilities/BinUtility.hpp" + +#include +#include +#include + +#include "TFile.h" + +using namespace Acts; + +using IdentifiedMaterial = + std::tuple>; + +std::vector createHomogeneousSurfaceMaterial() { + std::size_t nMaterials = 100; + + std::vector homogeneousMaterials; + homogeneousMaterials.reserve(nMaterials); + for (std::size_t i = 0; i < nMaterials; ++i) { + // construct the material properties from arguments + Material mat = Material::fromMolarDensity( + 1. + i * 0.5, 2. + i * 0.5, 3. + i * 0.5, 4. + i * 0.5, 5. + i * 0.5); + MaterialSlab mp(mat, 0.1); + auto hMaterial = std::make_shared(mp); + auto geoID = GeometryIdentifier().withVolume(1).withSensitive(i + 1); + homogeneousMaterials.push_back({geoID, hMaterial}); + } + return homogeneousMaterials; +} + +std::vector createBinnedSurfaceMaterial() { + std::size_t nMaterials = 100; + + std::vector binnedMaterials; + binnedMaterials.reserve(nMaterials); + for (std::size_t i = 0; i < nMaterials; ++i) { + // construct the material properties from arguments + + BinUtility xyBinning(100, -1., 1., open, AxisDirection::AxisX); + xyBinning += BinUtility(50, -3., 3., open, AxisDirection::AxisY); + + std::vector> materialMatrix; + for (std::size_t j = 0; j < xyBinning.bins(1); ++j) { + std::vector materialRow; + for (std::size_t k = 0; k < xyBinning.bins(0); ++k) { + // Create a material slab with some arbitrary properties + Material mat = Material::fromMolarDensity( + i + j * 1. + k * 0.5, i + j * 2 + k * 0.5, i + j * 3. + k * 0.5, + i + j * 4. + k * 0.5, i + j * 5. + k * 0.5); + MaterialSlab mp(mat, 0.1); + materialRow.push_back(mp); + } + materialMatrix.push_back(materialRow); + } + auto binnedMaterial = + std::make_shared(xyBinning, materialMatrix); + auto geoID = GeometryIdentifier().withVolume(2).withSensitive(i + 1); + binnedMaterials.push_back({geoID, binnedMaterial}); + } + return binnedMaterials; +} + +BOOST_AUTO_TEST_SUITE(RootMaterialMapIoTests) + +BOOST_AUTO_TEST_CASE(RootMaterialMapIoHomogeneousReadWrite) { + auto surfaceMaterials = createHomogeneousSurfaceMaterial(); + + auto rFile = + TFile::Open("RootMaterialMapIoHomogeneousTests.root", "RECREATE"); + rFile->cd(); + BOOST_REQUIRE(rFile != nullptr); + + // Create the accessor + RootMaterialMapIo::Config cfg; + RootMaterialMapIo accessor(cfg); + RootMaterialMapIo::Options options; + + for (const auto& [geoID, sMaterial] : surfaceMaterials) { + accessor.write(*rFile, geoID, *sMaterial, options); + } + + rFile->Write(); + rFile->Close(); + + // Let's read it back + auto iFile = TFile::Open("RootMaterialMapIoHomogeneousTests.root", "READ"); + BOOST_REQUIRE(iFile != nullptr); + + auto [surfaceMapsRead, volumeMapsRead] = accessor.read(*iFile, options); + BOOST_REQUIRE_EQUAL(surfaceMapsRead.size(), surfaceMaterials.size()); + BOOST_REQUIRE_EQUAL(volumeMapsRead.size(), 0); + + Vector3 accessorPosition(0., 0., 0.); + + for (const auto& [geoID, sMaterial] : surfaceMaterials) { + auto it = surfaceMapsRead.find(geoID); + BOOST_REQUIRE(it != surfaceMapsRead.end()); + const auto& readMaterial = it->second; + BOOST_REQUIRE(readMaterial != nullptr); + const auto* hMaterial = + dynamic_cast(readMaterial.get()); + BOOST_REQUIRE(hMaterial != nullptr); + BOOST_CHECK_CLOSE(hMaterial->materialSlab(accessorPosition).material().X0(), + sMaterial->materialSlab(accessorPosition).material().X0(), + 1e-6); + BOOST_CHECK_CLOSE(hMaterial->materialSlab(accessorPosition).material().L0(), + sMaterial->materialSlab(accessorPosition).material().L0(), + 1e-6); + } +} + +BOOST_AUTO_TEST_CASE(RootMaterialMapIoBinnedReadWrite) { + auto surfaceMaterials = createBinnedSurfaceMaterial(); + + auto rFile = TFile::Open("RootMaterialMapIoBinnedTests.root", "RECREATE"); + rFile->cd(); + BOOST_REQUIRE(rFile != nullptr); + + // Create the accessor + RootMaterialMapIo::Config cfg; + RootMaterialMapIo accessor(cfg); + RootMaterialMapIo::Options options; + + for (const auto& [geoID, sMaterial] : surfaceMaterials) { + accessor.write(*rFile, geoID, *sMaterial, options); + } + + rFile->Write(); + rFile->Close(); + + // Let's read it back + auto iFile = TFile::Open("RootMaterialMapIoBinnedTests.root", "READ"); + BOOST_REQUIRE(iFile != nullptr); + auto [surfaceMapsRead, volumeMapsRead] = accessor.read(*iFile, options); + BOOST_REQUIRE_EQUAL(surfaceMapsRead.size(), surfaceMaterials.size()); + BOOST_REQUIRE_EQUAL(volumeMapsRead.size(), 0); + + // Compare + for (const auto& [refGeoID, refSMaterial] : surfaceMaterials) { + auto binnedReferenceMaterial = + dynamic_cast(refSMaterial.get()); + + BOOST_REQUIRE(binnedReferenceMaterial != nullptr); + + auto it = surfaceMapsRead.find(refGeoID); + BOOST_REQUIRE(it != surfaceMapsRead.end()); + const auto& readMaterial = it->second; + BOOST_REQUIRE(readMaterial != nullptr); + const auto* binnedMaterial = + dynamic_cast(readMaterial.get()); + BOOST_REQUIRE(binnedMaterial != nullptr); + + // Check the binning + BOOST_CHECK_EQUAL(binnedMaterial->binUtility().bins(0), + binnedReferenceMaterial->binUtility().bins(0)); + BOOST_CHECK_EQUAL(binnedMaterial->binUtility().bins(1), + binnedReferenceMaterial->binUtility().bins(1)); + + // Compare the material matrix + const auto& materialMatrix = binnedMaterial->fullMaterial(); + const auto& referenceMaterialMatrix = + binnedReferenceMaterial->fullMaterial(); + + BOOST_REQUIRE_EQUAL(materialMatrix.size(), referenceMaterialMatrix.size()); + for (std::size_t i = 0; i < materialMatrix.size(); ++i) { + BOOST_REQUIRE_EQUAL(materialMatrix[i].size(), + referenceMaterialMatrix[i].size()); + for (std::size_t j = 0; j < materialMatrix[i].size(); ++j) { + const auto& mat = materialMatrix[i][j]; + const auto& refMat = referenceMaterialMatrix[i][j]; + BOOST_CHECK_CLOSE(mat.material().X0(), refMat.material().X0(), 1e-6); + BOOST_CHECK_CLOSE(mat.material().L0(), refMat.material().L0(), 1e-6); + BOOST_CHECK_CLOSE(mat.material().Ar(), refMat.material().Ar(), 1e-6); + BOOST_CHECK_CLOSE(mat.material().Z(), refMat.material().Z(), 1e-6); + BOOST_CHECK_CLOSE(mat.thickness(), refMat.thickness(), 1e-6); + } + } + } + + // Create the accessor - writing with indexed material + RootMaterialMapIo::Config cfgIndexed; + RootMaterialMapIo accessorIndexed(cfgIndexed); + + RootMaterialMapIo::Options optionsIndexed; + optionsIndexed.indexedMaterial = true; + + rFile = TFile::Open("RootMaterialMapIoBinnedIndexedTests.root", "RECREATE"); + rFile->cd(); + BOOST_REQUIRE(rFile != nullptr); + + for (const auto& [geoID, sMaterial] : surfaceMaterials) { + accessorIndexed.write(*rFile, geoID, *sMaterial, optionsIndexed); + } + + rFile->Write(); + rFile->Close(); + + // Let's read it back + iFile = TFile::Open("RootMaterialMapIoBinnedIndexedTests.root", "READ"); + BOOST_REQUIRE(iFile != nullptr); + auto [surfaceMapsIndexedRead, volumeMapsIndexedRead] = + accessorIndexed.read(*iFile, optionsIndexed); + BOOST_REQUIRE_EQUAL(surfaceMapsIndexedRead.size(), surfaceMaterials.size()); + BOOST_REQUIRE_EQUAL(volumeMapsIndexedRead.size(), 0); + + // Compare + for (const auto& [refGeoID, refSMaterial] : surfaceMaterials) { + auto binnedReferenceMaterial = + dynamic_cast(refSMaterial.get()); + BOOST_REQUIRE(binnedReferenceMaterial != nullptr); + auto it = surfaceMapsIndexedRead.find(refGeoID); + BOOST_REQUIRE(it != surfaceMapsIndexedRead.end()); + const auto& readMaterial = it->second; + BOOST_REQUIRE(readMaterial != nullptr); + const auto* binnedMaterial = + dynamic_cast(readMaterial.get()); + BOOST_REQUIRE(binnedMaterial != nullptr); + // Check the binning + BOOST_CHECK_EQUAL(binnedMaterial->binUtility().bins(0), + binnedReferenceMaterial->binUtility().bins(0)); + BOOST_CHECK_EQUAL(binnedMaterial->binUtility().bins(1), + binnedReferenceMaterial->binUtility().bins(1)); + // Compare the material matrix + const auto& materialMatrix = binnedMaterial->fullMaterial(); + const auto& referenceMaterialMatrix = + binnedReferenceMaterial->fullMaterial(); + BOOST_REQUIRE_EQUAL(materialMatrix.size(), referenceMaterialMatrix.size()); + for (std::size_t i = 0; i < materialMatrix.size(); ++i) { + BOOST_REQUIRE_EQUAL(materialMatrix[i].size(), + referenceMaterialMatrix[i].size()); + for (std::size_t j = 0; j < materialMatrix[i].size(); ++j) { + const auto& mat = materialMatrix[i][j]; + const auto& refMat = referenceMaterialMatrix[i][j]; + BOOST_CHECK_CLOSE(mat.material().X0(), refMat.material().X0(), 1e-6); + BOOST_CHECK_CLOSE(mat.material().L0(), refMat.material().L0(), 1e-6); + BOOST_CHECK_CLOSE(mat.material().Ar(), refMat.material().Ar(), 1e-6); + BOOST_CHECK_CLOSE(mat.material().Z(), refMat.material().Z(), 1e-6); + BOOST_CHECK_CLOSE(mat.thickness(), refMat.thickness(), 1e-6); + } + } + } +} + +BOOST_AUTO_TEST_SUITE_END() From d37fe264556ac045ed7b68abf03bc530dea298a9 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Sat, 12 Jul 2025 06:49:43 +0200 Subject: [PATCH 27/30] delete --- .../Plugins/Root/RootMaterialMapIOTests.cpp | 262 ------------------ 1 file changed, 262 deletions(-) delete mode 100644 Tests/UnitTests/Plugins/Root/RootMaterialMapIOTests.cpp diff --git a/Tests/UnitTests/Plugins/Root/RootMaterialMapIOTests.cpp b/Tests/UnitTests/Plugins/Root/RootMaterialMapIOTests.cpp deleted file mode 100644 index 9b2806fd8b4..00000000000 --- a/Tests/UnitTests/Plugins/Root/RootMaterialMapIOTests.cpp +++ /dev/null @@ -1,262 +0,0 @@ -// This file is part of the ACTS project. -// -// Copyright (C) 2016 CERN for the benefit of the ACTS project -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#include - -#include "Acts/Definitions/Algebra.hpp" -#include "Acts/Material/BinnedSurfaceMaterial.hpp" -#include "Acts/Material/HomogeneousSurfaceMaterial.hpp" -#include "Acts/Material/Material.hpp" -#include "Acts/Material/MaterialSlab.hpp" -#include "Acts/Plugins/Root/RootMaterialMapIo.hpp" -#include "Acts/Surfaces/PlaneSurface.hpp" -#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp" -#include "Acts/Utilities/BinUtility.hpp" - -#include -#include -#include - -#include "TFile.h" - -using namespace Acts; - -using IdentifiedMaterial = - std::tuple>; - -std::vector createHomogeneousSurfaceMaterial() { - std::size_t nMaterials = 100; - - std::vector homogeneousMaterials; - homogeneousMaterials.reserve(nMaterials); - for (std::size_t i = 0; i < nMaterials; ++i) { - // construct the material properties from arguments - Material mat = Material::fromMolarDensity( - 1. + i * 0.5, 2. + i * 0.5, 3. + i * 0.5, 4. + i * 0.5, 5. + i * 0.5); - MaterialSlab mp(mat, 0.1); - auto hMaterial = std::make_shared(mp); - auto geoID = GeometryIdentifier().withVolume(1).withSensitive(i + 1); - homogeneousMaterials.push_back({geoID, hMaterial}); - } - return homogeneousMaterials; -} - -std::vector createBinnedSurfaceMaterial() { - std::size_t nMaterials = 100; - - std::vector binnedMaterials; - binnedMaterials.reserve(nMaterials); - for (std::size_t i = 0; i < nMaterials; ++i) { - // construct the material properties from arguments - - BinUtility xyBinning(100, -1., 1., open, AxisDirection::AxisX); - xyBinning += BinUtility(50, -3., 3., open, AxisDirection::AxisY); - - std::vector> materialMatrix; - for (std::size_t j = 0; j < xyBinning.bins(1); ++j) { - std::vector materialRow; - for (std::size_t k = 0; k < xyBinning.bins(0); ++k) { - // Create a material slab with some arbitrary properties - Material mat = Material::fromMolarDensity( - i + j * 1. + k * 0.5, i + j * 2 + k * 0.5, i + j * 3. + k * 0.5, - i + j * 4. + k * 0.5, i + j * 5. + k * 0.5); - MaterialSlab mp(mat, 0.1); - materialRow.push_back(mp); - } - materialMatrix.push_back(materialRow); - } - auto binnedMaterial = - std::make_shared(xyBinning, materialMatrix); - auto geoID = GeometryIdentifier().withVolume(2).withSensitive(i + 1); - binnedMaterials.push_back({geoID, binnedMaterial}); - } - return binnedMaterials; -} - -BOOST_AUTO_TEST_SUITE(RootMaterialMapIoTests) - -BOOST_AUTO_TEST_CASE(RootMaterialMapIoHomogeneousReadWrite) { - auto surfaceMaterials = createHomogeneousSurfaceMaterial(); - - auto rFile = - TFile::Open("RootMaterialMapIoHomogeneousTests.root", "RECREATE"); - rFile->cd(); - BOOST_REQUIRE(rFile != nullptr); - - // Create the accessor - RootMaterialMapIo::Config cfg; - RootMaterialMapIo accessor(cfg); - RootMaterialMapIo::Options options; - - for (const auto& [geoID, sMaterial] : surfaceMaterials) { - accessor.write(*rFile, geoID, *sMaterial, options); - } - - rFile->Write(); - rFile->Close(); - - // Let's read it back - auto iFile = TFile::Open("RootMaterialMapIoHomogeneousTests.root", "READ"); - BOOST_REQUIRE(iFile != nullptr); - - auto [surfaceMapsRead, volumeMapsRead] = accessor.read(*iFile, options); - BOOST_REQUIRE_EQUAL(surfaceMapsRead.size(), surfaceMaterials.size()); - BOOST_REQUIRE_EQUAL(volumeMapsRead.size(), 0); - - Vector3 accessorPosition(0., 0., 0.); - - for (const auto& [geoID, sMaterial] : surfaceMaterials) { - auto it = surfaceMapsRead.find(geoID); - BOOST_REQUIRE(it != surfaceMapsRead.end()); - const auto& readMaterial = it->second; - BOOST_REQUIRE(readMaterial != nullptr); - const auto* hMaterial = - dynamic_cast(readMaterial.get()); - BOOST_REQUIRE(hMaterial != nullptr); - BOOST_CHECK_CLOSE(hMaterial->materialSlab(accessorPosition).material().X0(), - sMaterial->materialSlab(accessorPosition).material().X0(), - 1e-6); - BOOST_CHECK_CLOSE(hMaterial->materialSlab(accessorPosition).material().L0(), - sMaterial->materialSlab(accessorPosition).material().L0(), - 1e-6); - } -} - -BOOST_AUTO_TEST_CASE(RootMaterialMapIoBinnedReadWrite) { - auto surfaceMaterials = createBinnedSurfaceMaterial(); - - auto rFile = TFile::Open("RootMaterialMapIoBinnedTests.root", "RECREATE"); - rFile->cd(); - BOOST_REQUIRE(rFile != nullptr); - - // Create the accessor - RootMaterialMapIo::Config cfg; - RootMaterialMapIo accessor(cfg); - RootMaterialMapIo::Options options; - - for (const auto& [geoID, sMaterial] : surfaceMaterials) { - accessor.write(*rFile, geoID, *sMaterial, options); - } - - rFile->Write(); - rFile->Close(); - - // Let's read it back - auto iFile = TFile::Open("RootMaterialMapIoBinnedTests.root", "READ"); - BOOST_REQUIRE(iFile != nullptr); - auto [surfaceMapsRead, volumeMapsRead] = accessor.read(*iFile, options); - BOOST_REQUIRE_EQUAL(surfaceMapsRead.size(), surfaceMaterials.size()); - BOOST_REQUIRE_EQUAL(volumeMapsRead.size(), 0); - - // Compare - for (const auto& [refGeoID, refSMaterial] : surfaceMaterials) { - auto binnedReferenceMaterial = - dynamic_cast(refSMaterial.get()); - - BOOST_REQUIRE(binnedReferenceMaterial != nullptr); - - auto it = surfaceMapsRead.find(refGeoID); - BOOST_REQUIRE(it != surfaceMapsRead.end()); - const auto& readMaterial = it->second; - BOOST_REQUIRE(readMaterial != nullptr); - const auto* binnedMaterial = - dynamic_cast(readMaterial.get()); - BOOST_REQUIRE(binnedMaterial != nullptr); - - // Check the binning - BOOST_CHECK_EQUAL(binnedMaterial->binUtility().bins(0), - binnedReferenceMaterial->binUtility().bins(0)); - BOOST_CHECK_EQUAL(binnedMaterial->binUtility().bins(1), - binnedReferenceMaterial->binUtility().bins(1)); - - // Compare the material matrix - const auto& materialMatrix = binnedMaterial->fullMaterial(); - const auto& referenceMaterialMatrix = - binnedReferenceMaterial->fullMaterial(); - - BOOST_REQUIRE_EQUAL(materialMatrix.size(), referenceMaterialMatrix.size()); - for (std::size_t i = 0; i < materialMatrix.size(); ++i) { - BOOST_REQUIRE_EQUAL(materialMatrix[i].size(), - referenceMaterialMatrix[i].size()); - for (std::size_t j = 0; j < materialMatrix[i].size(); ++j) { - const auto& mat = materialMatrix[i][j]; - const auto& refMat = referenceMaterialMatrix[i][j]; - BOOST_CHECK_CLOSE(mat.material().X0(), refMat.material().X0(), 1e-6); - BOOST_CHECK_CLOSE(mat.material().L0(), refMat.material().L0(), 1e-6); - BOOST_CHECK_CLOSE(mat.material().Ar(), refMat.material().Ar(), 1e-6); - BOOST_CHECK_CLOSE(mat.material().Z(), refMat.material().Z(), 1e-6); - BOOST_CHECK_CLOSE(mat.thickness(), refMat.thickness(), 1e-6); - } - } - } - - // Create the accessor - writing with indexed material - RootMaterialMapIo::Config cfgIndexed; - RootMaterialMapIo accessorIndexed(cfgIndexed); - - RootMaterialMapIo::Options optionsIndexed; - optionsIndexed.indexedMaterial = true; - - rFile = TFile::Open("RootMaterialMapIoBinnedIndexedTests.root", "RECREATE"); - rFile->cd(); - BOOST_REQUIRE(rFile != nullptr); - - for (const auto& [geoID, sMaterial] : surfaceMaterials) { - accessorIndexed.write(*rFile, geoID, *sMaterial, optionsIndexed); - } - - rFile->Write(); - rFile->Close(); - - // Let's read it back - iFile = TFile::Open("RootMaterialMapIoBinnedIndexedTests.root", "READ"); - BOOST_REQUIRE(iFile != nullptr); - auto [surfaceMapsIndexedRead, volumeMapsIndexedRead] = - accessorIndexed.read(*iFile, optionsIndexed); - BOOST_REQUIRE_EQUAL(surfaceMapsIndexedRead.size(), surfaceMaterials.size()); - BOOST_REQUIRE_EQUAL(volumeMapsIndexedRead.size(), 0); - - // Compare - for (const auto& [refGeoID, refSMaterial] : surfaceMaterials) { - auto binnedReferenceMaterial = - dynamic_cast(refSMaterial.get()); - BOOST_REQUIRE(binnedReferenceMaterial != nullptr); - auto it = surfaceMapsIndexedRead.find(refGeoID); - BOOST_REQUIRE(it != surfaceMapsIndexedRead.end()); - const auto& readMaterial = it->second; - BOOST_REQUIRE(readMaterial != nullptr); - const auto* binnedMaterial = - dynamic_cast(readMaterial.get()); - BOOST_REQUIRE(binnedMaterial != nullptr); - // Check the binning - BOOST_CHECK_EQUAL(binnedMaterial->binUtility().bins(0), - binnedReferenceMaterial->binUtility().bins(0)); - BOOST_CHECK_EQUAL(binnedMaterial->binUtility().bins(1), - binnedReferenceMaterial->binUtility().bins(1)); - // Compare the material matrix - const auto& materialMatrix = binnedMaterial->fullMaterial(); - const auto& referenceMaterialMatrix = - binnedReferenceMaterial->fullMaterial(); - BOOST_REQUIRE_EQUAL(materialMatrix.size(), referenceMaterialMatrix.size()); - for (std::size_t i = 0; i < materialMatrix.size(); ++i) { - BOOST_REQUIRE_EQUAL(materialMatrix[i].size(), - referenceMaterialMatrix[i].size()); - for (std::size_t j = 0; j < materialMatrix[i].size(); ++j) { - const auto& mat = materialMatrix[i][j]; - const auto& refMat = referenceMaterialMatrix[i][j]; - BOOST_CHECK_CLOSE(mat.material().X0(), refMat.material().X0(), 1e-6); - BOOST_CHECK_CLOSE(mat.material().L0(), refMat.material().L0(), 1e-6); - BOOST_CHECK_CLOSE(mat.material().Ar(), refMat.material().Ar(), 1e-6); - BOOST_CHECK_CLOSE(mat.material().Z(), refMat.material().Z(), 1e-6); - BOOST_CHECK_CLOSE(mat.thickness(), refMat.thickness(), 1e-6); - } - } - } -} - -BOOST_AUTO_TEST_SUITE_END() From 899d50228fc447dc7d39230a86193e1a6547be22 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Sat, 12 Jul 2025 06:50:53 +0200 Subject: [PATCH 28/30] unbreak --- .../{RootMaterialMapIoTests2.cpp => RootMaterialMapIoTests.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Tests/UnitTests/Plugins/Root/{RootMaterialMapIoTests2.cpp => RootMaterialMapIoTests.cpp} (100%) diff --git a/Tests/UnitTests/Plugins/Root/RootMaterialMapIoTests2.cpp b/Tests/UnitTests/Plugins/Root/RootMaterialMapIoTests.cpp similarity index 100% rename from Tests/UnitTests/Plugins/Root/RootMaterialMapIoTests2.cpp rename to Tests/UnitTests/Plugins/Root/RootMaterialMapIoTests.cpp From b3a39cc85a22c51f0805b783e08bc0cf149d053e Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Sat, 12 Jul 2025 07:01:06 +0200 Subject: [PATCH 29/30] break --- .../Root/{RootMaterialMapIO.hpp => RootMaterialMapIoBreak.hpp} | 0 .../{RootMaterialTrackIO.hpp => RootMaterialTrackIoBreak.hpp} | 0 .../src/{RootMaterialMapIO.cpp => RootMaterialMapIoBreak.cpp} | 0 .../src/{RootMaterialTrackIO.cpp => RootMaterialTrackIoBreak.cpp} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename Plugins/Root/include/Acts/Plugins/Root/{RootMaterialMapIO.hpp => RootMaterialMapIoBreak.hpp} (100%) rename Plugins/Root/include/Acts/Plugins/Root/{RootMaterialTrackIO.hpp => RootMaterialTrackIoBreak.hpp} (100%) rename Plugins/Root/src/{RootMaterialMapIO.cpp => RootMaterialMapIoBreak.cpp} (100%) rename Plugins/Root/src/{RootMaterialTrackIO.cpp => RootMaterialTrackIoBreak.cpp} (100%) diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIO.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIoBreak.hpp similarity index 100% rename from Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIO.hpp rename to Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIoBreak.hpp diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIO.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIoBreak.hpp similarity index 100% rename from Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIO.hpp rename to Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIoBreak.hpp diff --git a/Plugins/Root/src/RootMaterialMapIO.cpp b/Plugins/Root/src/RootMaterialMapIoBreak.cpp similarity index 100% rename from Plugins/Root/src/RootMaterialMapIO.cpp rename to Plugins/Root/src/RootMaterialMapIoBreak.cpp diff --git a/Plugins/Root/src/RootMaterialTrackIO.cpp b/Plugins/Root/src/RootMaterialTrackIoBreak.cpp similarity index 100% rename from Plugins/Root/src/RootMaterialTrackIO.cpp rename to Plugins/Root/src/RootMaterialTrackIoBreak.cpp From c94bc8a10f4784105a38bf1813a832d1fd1a2172 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Sat, 12 Jul 2025 07:26:56 +0200 Subject: [PATCH 30/30] unbreak --- .../Root/{RootMaterialMapIoBreak.hpp => RootMaterialMapIo.hpp} | 0 .../{RootMaterialTrackIoBreak.hpp => RootMaterialTrackIo.hpp} | 0 .../src/{RootMaterialMapIoBreak.cpp => RootMaterialMapIo.cpp} | 0 .../src/{RootMaterialTrackIoBreak.cpp => RootMaterialTrackIo.cpp} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename Plugins/Root/include/Acts/Plugins/Root/{RootMaterialMapIoBreak.hpp => RootMaterialMapIo.hpp} (100%) rename Plugins/Root/include/Acts/Plugins/Root/{RootMaterialTrackIoBreak.hpp => RootMaterialTrackIo.hpp} (100%) rename Plugins/Root/src/{RootMaterialMapIoBreak.cpp => RootMaterialMapIo.cpp} (100%) rename Plugins/Root/src/{RootMaterialTrackIoBreak.cpp => RootMaterialTrackIo.cpp} (100%) diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIoBreak.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIo.hpp similarity index 100% rename from Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIoBreak.hpp rename to Plugins/Root/include/Acts/Plugins/Root/RootMaterialMapIo.hpp diff --git a/Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIoBreak.hpp b/Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIo.hpp similarity index 100% rename from Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIoBreak.hpp rename to Plugins/Root/include/Acts/Plugins/Root/RootMaterialTrackIo.hpp diff --git a/Plugins/Root/src/RootMaterialMapIoBreak.cpp b/Plugins/Root/src/RootMaterialMapIo.cpp similarity index 100% rename from Plugins/Root/src/RootMaterialMapIoBreak.cpp rename to Plugins/Root/src/RootMaterialMapIo.cpp diff --git a/Plugins/Root/src/RootMaterialTrackIoBreak.cpp b/Plugins/Root/src/RootMaterialTrackIo.cpp similarity index 100% rename from Plugins/Root/src/RootMaterialTrackIoBreak.cpp rename to Plugins/Root/src/RootMaterialTrackIo.cpp