Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-14 08:01:14

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 // This file is part of the ACTS project.
0010 //
0011 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0012 //
0013 // This Source Code Form is subject to the terms of the Mozilla Public
0014 // License, v. 2.0. If a copy of the MPL was not distributed with this
0015 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
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   // Sort the entry numbers of the events
0046   {
0047     // necessary to guarantee that m_inputChain->GetV1() is valid for the
0048     // entire range
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     // The space point buckets are ordered sequentially
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 }  // namespace ActsExamples