Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-11 09:40:23

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Material/TrackingGeometryMaterial.hpp"
0012 #include "Acts/Utilities/Logger.hpp"
0013 
0014 #include <map>
0015 #include <memory>
0016 #include <string>
0017 #include <tuple>
0018 
0019 class TTree;
0020 class TFile;
0021 class TDirectory;
0022 
0023 namespace Acts {
0024 class GeometryIdentifier;
0025 class ISurfaceMaterial;
0026 class IVolumeMaterial;
0027 class HomogeneousSurfaceMaterial;
0028 class MaterialSlab;
0029 class BinnedSurfaceMaterial;
0030 }  // namespace Acts
0031 
0032 namespace ActsPlugins {
0033 
0034 /// Simple payload class that can be wrapped for reading
0035 /// and writing.
0036 class RootMaterialMapIo {
0037  public:
0038   /// @brief Configuration for the accessor
0039   /// Contains the tags used for writing and reading, tag names are
0040   /// configuration, as they are not very likely to change.
0041   struct Config {
0042     /// The volume identification string
0043     std::string volumePrefix = "_vol";
0044     /// The boundary identification string
0045     std::string portalPrefix = "_bou";
0046     /// The layer identification string
0047     std::string layerPrefix = "_lay";
0048     /// The approach identification string
0049     std::string passivePrefix = "_app";
0050     /// The sensitive identification string
0051     std::string sensitivePrefix = "_sen";
0052     /// The bin number tag
0053     std::string nBinsHistName = "n";
0054     /// The axis direction histogram name: AxisZ, AxisR, AxisPhi, etc.
0055     std::string axisDirHistName = "v";
0056     /// The axis boundary type hist name
0057     std::string axisBoundaryTypeHistName = "o";
0058     /// The range histogram name: min value
0059     std::string minRangeHistName = "min";
0060     /// The range histogram name: max value
0061     std::string maxRangeHistName = "max";
0062     /// The thickness histogram name
0063     std::string thicknessHistName = "t";
0064     /// The x0 histogram name
0065     std::string x0HistName = "x0";
0066     /// The l0 histogram name
0067     std::string l0HistName = "l0";
0068     /// The A histogram name
0069     std::string aHistName = "A";
0070     /// The Z thisogram name
0071     std::string zHistName = "Z";
0072     /// The rho thisogram name
0073     std::string rhoHistName = "rho";
0074     /// The index histogram name
0075     std::string indexHistName = "i";
0076   };
0077 
0078   /// @brief Options for writing the material maps
0079   /// Folder names are optional as it allows to write more maps into one
0080   /// file, e.g. for the same detector with different configurations.
0081   struct Options {
0082     /// The name of the homogeneous material tree
0083     std::string homogeneousMaterialTreeName = "HomogeneousMaterial";
0084     /// The name of the indexed material tree
0085     std::string indexedMaterialTreeName = "IndexedMaterial";
0086     /// The name of the output surface tree
0087     std::string folderSurfaceNameBase = "SurfaceMaterial";
0088     /// The name of the output volume tree
0089     std::string folderVolumeNameBase = "VolumeMaterial";
0090     /// Use an indexed material tree
0091     bool indexedMaterial = false;
0092   };
0093 
0094   struct MaterialTreePayload {
0095     std::size_t index = 0;
0096     /// geometry identifier
0097     std::int64_t hGeoId = 0;
0098     /// thickness
0099     float ht = 0.0f;
0100     /// X0
0101     float hX0 = 0.0f;
0102     /// L0
0103     float hL0 = 0.0f;
0104     /// A
0105     float hA = 0.0f;
0106     /// Z
0107     float hZ = 0.0f;
0108     /// Rho
0109     float hRho = 0.0f;
0110   };
0111 
0112   /// @brief Constructor from config struct
0113   /// @param cfg the configuration for the accessor
0114   /// @param mLogger the logger to use, default is INFO level
0115   explicit RootMaterialMapIo(const Config& cfg,
0116                              std::unique_ptr<const Acts::Logger> mLogger =
0117                                  Acts::getDefaultLogger("RootMaterialMapIo",
0118                                                         Acts::Logging::INFO))
0119       : m_cfg(cfg), m_logger(std::move(mLogger)) {}
0120 
0121   /// @brief Destructor
0122   ~RootMaterialMapIo() = default;
0123 
0124   /// Write the detector maps
0125   /// @param rFile the file to write to
0126   /// @param detectorMaterial the detector material maps
0127   /// @param options the options for writing
0128   void write(TFile& rFile,
0129              const Acts::TrackingGeometryMaterial& detectorMaterial,
0130              const Options& options);
0131 
0132   /// Write the material to file
0133   /// @param rFile the file to write to
0134   /// @param geoID the geometry identifier for the surface
0135   /// @param surfaceMaterial is the surface associated with the material
0136   /// @param options the options for writing
0137   void write(TFile& rFile, const Acts::GeometryIdentifier& geoID,
0138              const Acts::ISurfaceMaterial& surfaceMaterial,
0139              const Options& options);
0140 
0141   /// Read the detector maps
0142   /// @param rFile the file to read from
0143   /// @param options the options for reading
0144   Acts::TrackingGeometryMaterial read(TFile& rFile, const Options& options);
0145   /// @return TrackingGeometryMaterial with material read from file
0146 
0147  private:
0148   /// @brief Connect the homogeneous material tree for writing
0149   /// @param rTree the tree to connect to
0150   /// @param treePayload the payload to connect to the tree
0151   void connectForWrite(TTree& rTree, MaterialTreePayload& treePayload);
0152 
0153   /// @brief Connect the homogeneous material tree for writing
0154   /// @param rTree the tree to connect to
0155   /// @param treePayload the payload to connect to the tree
0156   void connectForRead(TTree& rTree, MaterialTreePayload& treePayload);
0157 
0158   /// Fill the material slab
0159   /// @param payload the tree payload to fill
0160   /// @param materialSlab the material slab to fill
0161   void fillMaterialSlab(MaterialTreePayload& payload,
0162                         const Acts::MaterialSlab& materialSlab);
0163 
0164   /// @brief Fill the Binned Surface material as histograms - legacy mode
0165   /// @param bsMaterial the binned surface material to write
0166   void fillBinnedSurfaceMaterial(const Acts::BinnedSurfaceMaterial& bsMaterial);
0167 
0168   /// @brief Fill the Binned Surface material as histograms - indexed mode
0169   /// @param payload the tree payload to fill
0170   /// @param bsMaterial the binned surface material to write
0171   void fillBinnedSurfaceMaterial(MaterialTreePayload& payload,
0172                                  const Acts::BinnedSurfaceMaterial& bsMaterial);
0173 
0174   /// Read the a texture Surface material
0175   /// @param rFile the file to read from
0176   /// @param tdName the name of the texture directory
0177   /// @param indexedMaterialTree the indexed material tree, if available
0178   /// @return a shared pointer to the ISurfaceMaterial
0179   std::shared_ptr<const Acts::ISurfaceMaterial> readTextureSurfaceMaterial(
0180       TFile& rFile, const std::string& tdName,
0181       TTree* indexedMaterialTree = nullptr);
0182 
0183   /// Read the a grid Surface material
0184   const Acts::Logger& logger() const { return *m_logger; }
0185 
0186   /// The configuration for the accessor
0187   Config m_cfg;
0188 
0189   /// The logger for this accessor
0190   std::unique_ptr<const Acts::Logger> m_logger;
0191 
0192   /// The homogeneous material tree
0193   TTree* m_hTree = nullptr;
0194   MaterialTreePayload m_homogenousMaterialTreePayload;
0195 
0196   /// The globally indexed material tree
0197   TTree* m_gTree = nullptr;
0198   MaterialTreePayload m_indexedMaterialTreePayload;
0199 };
0200 
0201 }  // namespace ActsPlugins