File indexing completed on 2025-09-17 08:03:04
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Io/Root/RootMaterialTrackWriter.hpp"
0010
0011 #include "Acts/Geometry/GeometryIdentifier.hpp"
0012 #include "Acts/Geometry/TrackingVolume.hpp"
0013 #include "Acts/Material/Material.hpp"
0014 #include "Acts/Material/MaterialInteraction.hpp"
0015 #include "Acts/Material/MaterialSlab.hpp"
0016 #include "Acts/Surfaces/CylinderBounds.hpp"
0017 #include "Acts/Surfaces/RadialBounds.hpp"
0018 #include "Acts/Surfaces/Surface.hpp"
0019 #include "Acts/Surfaces/SurfaceBounds.hpp"
0020 #include "Acts/Utilities/Intersection.hpp"
0021 #include "Acts/Utilities/Logger.hpp"
0022 #include "Acts/Utilities/VectorHelpers.hpp"
0023 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0024
0025 #include <cstddef>
0026 #include <ios>
0027 #include <stdexcept>
0028
0029 #include <TFile.h>
0030 #include <TTree.h>
0031
0032 namespace ActsExamples {
0033
0034 RootMaterialTrackWriter::RootMaterialTrackWriter(
0035 const RootMaterialTrackWriter::Config& config, Acts::Logging::Level level)
0036 : WriterT(config.inputMaterialTracks, "RootMaterialTrackWriter", level),
0037 m_cfg(config),
0038 m_accessor({config.prePostStep, config.storeSurface, config.storeVolume,
0039 config.recalculateTotals}) {
0040
0041 if (m_cfg.inputMaterialTracks.empty()) {
0042 throw std::invalid_argument("Missing input collection");
0043 } else if (m_cfg.treeName.empty()) {
0044 throw std::invalid_argument("Missing tree name");
0045 }
0046
0047
0048 m_outputFile = TFile::Open(m_cfg.filePath.c_str(), m_cfg.fileMode.c_str());
0049 if (m_outputFile == nullptr) {
0050 throw std::ios_base::failure("Could not open '" + m_cfg.filePath + "'");
0051 }
0052
0053 m_outputFile->cd();
0054 m_outputTree =
0055 new TTree(m_cfg.treeName.c_str(), "TTree from RootMaterialTrackWriter");
0056 if (m_outputTree == nullptr) {
0057 throw std::bad_alloc();
0058 }
0059
0060 m_accessor.connectForWrite(*m_outputTree);
0061 }
0062
0063 RootMaterialTrackWriter::~RootMaterialTrackWriter() {
0064 if (m_outputFile != nullptr) {
0065 m_outputFile->Close();
0066 }
0067 }
0068
0069 ProcessCode RootMaterialTrackWriter::finalize() {
0070
0071 ACTS_INFO("Writing ROOT output File : " << m_cfg.filePath);
0072
0073 m_outputFile->cd();
0074 m_outputTree->Write();
0075 m_outputFile->Close();
0076
0077 return ProcessCode::SUCCESS;
0078 }
0079
0080 ProcessCode RootMaterialTrackWriter::writeT(
0081 const AlgorithmContext& ctx,
0082 const std::unordered_map<std::size_t, Acts::RecordedMaterialTrack>&
0083 materialTracks) {
0084
0085 std::lock_guard<std::mutex> lock(m_writeMutex);
0086
0087 for (auto& [idTrack, mtrack] : materialTracks) {
0088
0089 m_accessor.write(ctx.geoContext, ctx.eventNumber, mtrack);
0090 m_outputTree->Fill();
0091 }
0092
0093 return ProcessCode::SUCCESS;
0094 }
0095
0096 }