File indexing completed on 2025-10-14 08:01:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include "ActsExamples/Io/Root/RootMuonSpacePointReader.hpp"
0018
0019 #include "Acts/Definitions/Units.hpp"
0020 #include "Acts/Utilities/UnitVectors.hpp"
0021 #include "ActsExamples/Io/Root/RootUtility.hpp"
0022 using namespace Acts;
0023 using namespace Acts::UnitLiterals;
0024
0025 namespace ActsExamples {
0026
0027 RootMuonSpacePointReader::RootMuonSpacePointReader(const Config& config,
0028 Acts::Logging::Level level)
0029 : m_cfg{config},
0030 m_logger{getDefaultLogger("RootMuonSpacePointReader", level)} {
0031 if (m_cfg.outputSpacePoints.empty()) {
0032 throw std::invalid_argument(
0033 "RootMuonSpacePointReader() - Space points must not be empty");
0034 }
0035 m_outputContainer.initialize(m_cfg.outputSpacePoints);
0036 if (!m_file || m_file->IsZombie()) {
0037 throw std::invalid_argument(
0038 "RootMuonSpacePointReader() - Failed to open '" + m_cfg.filePath + "'");
0039 }
0040 if (m_reader.GetTree() == nullptr) {
0041 throw std::invalid_argument("Failed to load TTree '" + m_cfg.treeName +
0042 "'");
0043 }
0044
0045
0046 {
0047
0048
0049 m_eventRanges.resize(m_reader.GetEntries());
0050 m_reader.GetTree()->SetEstimate(m_eventRanges.size() + 1);
0051
0052 m_reader.GetTree()->Draw("event_id", "", "goff");
0053 const auto nEntries = static_cast<std::uint32_t>(m_eventRanges.size());
0054 RootUtility::stableSort(nEntries, m_reader.GetTree()->GetV1(),
0055 m_eventRanges.data(), false);
0056 }
0057 }
0058
0059 RootMuonSpacePointReader::~RootMuonSpacePointReader() = default;
0060
0061 std::pair<std::size_t, std::size_t> RootMuonSpacePointReader::availableEvents()
0062 const {
0063 return std::make_pair(0u, m_reader.GetEntries());
0064 }
0065
0066 ProcessCode RootMuonSpacePointReader::read(
0067 const ActsExamples::AlgorithmContext& context) {
0068 std::lock_guard guard{m_mutex};
0069
0070 MuonSpacePointContainer outSpacePoints{};
0071
0072 auto entry = m_eventRanges.at(context.eventNumber);
0073 m_reader.SetEntry(entry);
0074 for (std::size_t spIdx = 0; spIdx < m_bucketId->size(); ++spIdx) {
0075 auto bucketIdx = static_cast<std::size_t>(m_bucketId->at(spIdx));
0076
0077 if (bucketIdx + 1 != outSpacePoints.size()) {
0078 outSpacePoints.emplace_back();
0079 }
0080 MuonSpacePoint& newSp{outSpacePoints.back().emplace_back()};
0081 newSp.setGeometryId(GeometryIdentifier{m_geometryId->at(spIdx)});
0082 newSp.setId(MuonSpacePoint::MuonId{m_muonId->at(spIdx)});
0083
0084 Vector3 position{m_localPositionX->at(spIdx), m_localPositionY->at(spIdx),
0085 m_localPositionZ->at(spIdx)};
0086 Vector3 sensorDir{makeDirectionFromPhiTheta<double>(
0087 m_sensorDirectionPhi->at(spIdx) * 1._degree,
0088 m_sensorDirectionTheta->at(spIdx) * 1._degree)};
0089 Vector3 toNext{makeDirectionFromPhiTheta<double>(
0090 m_toNextSensorPhi->at(spIdx) * 1._degree,
0091 m_toNextSensorTheta->at(spIdx) * 1._degree)};
0092
0093 newSp.defineCoordinates(std::move(position), std::move(sensorDir),
0094 std::move(toNext));
0095
0096 newSp.setRadius(m_driftR->at(spIdx));
0097 newSp.setTime(m_time->at(spIdx));
0098 newSp.setCovariance(m_covLoc0->at(spIdx), m_covLoc1->at(spIdx),
0099 m_covT->at(spIdx));
0100 ACTS_VERBOSE("Loaded new space point " << newSp);
0101 }
0102
0103 m_outputContainer(context, std::move(outSpacePoints));
0104
0105 return ProcessCode::SUCCESS;
0106 }
0107
0108 }